# Dipole Sources¶ Jupyter Notebook

Electric point dipole sources, along with plane waves, are one of the most commonly employed kinds of sources in electromagnetic computations. The emission of light due to physical processes such as electron-hole pair recombination in a quantum dot or radiative decay of a molecule exited state can be modelled as a point like dipole source. Therefore, it is important to understand how these kinds of sources can be utilized in **JCMsuite**.

This post will cover the following examples,

- The analytical expression for the electric and magnetic fields of an electric dipole in a homogeneous medium.
- Plots of the near fields for an electric dipole in a homogeneous medium calculated analytically and numerically.
- Utilizing a point dipole source in
**JCMsuite**. - The effect that a nanoscale scattering object can have on the near fields of an electric dipole.

## Dipole in a Homogeneous Medium¶

The electric and magnetic fields of an oscillating electric point dipole in a homogeneous background are given by,

\begin{equation} \mathrm{\mathbf{E}} = \frac{1}{4\pi\epsilon_{\mathrm{0}}} \left[\frac{\omega^{2}}{c^{2}r}\left(\mathbf{n}\times\mathbf{p}\right)\times\mathbf{n} + \left(\frac{1}{r^{3}} - \frac{i\omega}{cr^{3}}\right)\left(3\mathbf{n}\left[\mathbf{n}\cdot\mathbf{p}\right]-\mathbf{p}\right)\right]e^{i\omega{r}/c}e^{-i\omega{t}}, \\ \mathrm{\mathbf{B}} = \frac{1}{4\pi\epsilon_{\mathrm{0}}} \frac{\omega^{2}}{c^{3}r}\left(\mathbf{n}\times\mathbf{p}\right) \left(1 - \frac{c}{i\omega r}\right)e^{i\omega{r}/c}e^{-i\omega{t}}. \end{equation}Where $\omega$ is the angular frequency of the oscillation, $\mathbf{p}$ is the polarization vector of the dipole, $r$ is the distance to the dipole position, $\mathbf{n}$ is the normalised position vector, $t$ is time and $\epsilon_{0}$ and $c$ are the permittivity of free space and the speed of light in vacuum, respectively.

As an example, we take a dipole polarized along the $x$ axis, oscillating with an angular frequency $\omega$ = 1e15 rad/s. The strength of the polarization is set to $|\mathbf{p}|$ = $e/\omega$, where $e$ is the elementary charge. Close to the source, the electric and magnetic fields look like this:

```
%matplotlib notebook
import os
from IPython.display import Video
# use scripts.dipole_near_field_visualization to generate videos
# e.g.
# vis = DipoleNearFieldVisualization(case='analytical')
# vis.to_file()
Video(os.path.join("videos", "near_fields_analytical.mp4"), embed=True, width=1000, html_attributes='loop autoplay muted')
```

The $x$ component of the electric field is most intense along the $x$ axis and the sign remains constant when moving through the origin, meaning that the field is radial. While the $y$ component of the magnetic field is strongest along the $y$ axis and changes sign when passing through the origin. This describes a field that is circulating around the polarization axis ($x$ axis in this case).

## Dipole Sources in JCMsuite¶

To simulate the same physical model using **JCMsuite**, we construct a layout containing a homogeneous background material and include a `PointSource`

in the `sources.jcm`

file. Here we must be careful to choose the correct value for the strength. **JCMsuite** describes point sources via their associated electric current density. for time harmonic fields, this is related to the polarization via,

Therefore, since our polarization was chosen to be $|\mathbf{p}|$ = $e/\omega$, the strength of the current density will simply be $|\mathbf{j}|$ = $e$ with a phase offset of $-i$ (since $1/i = -i$).

This leads to the following entry in our `sources.jcm`

input file,

```
SourceBag {
Source {
ElectricCurrentDensity {
PointSource {
Omega = 1e15
Position = [0 0 0]
Strength = [-1.602176634e-19j 0 0]
}
}
}
}
```

Once we have solved Maxwell's equations using this source, we can then use the `ExportFields`

post process to obtain the spatial electric and magnetic field distributions. This yields precisely the same results as for evaluating our analytical formula above:

```
# use scripts.dipole_near_field_visualization to generate videos
# e.g.
# vis = DipoleNearFieldVisualization(case='numerical')
# vis.to_file()
Video(os.path.join("videos", "near_fields_numerical.mp4"), embed=True, width=1000, html_attributes='loop autoplay muted')
```

Of course, the advantage to a solving the system numerically is that we are not restricted to simplistic setups such as the case of a homogeneous medium. As an example, we place a high dielectric scatterer in the shape of a cylinder in the near field of the dipole source dipole source:

```
# use scripts.dipole_near_field_visualization to generate videos
# e.g.
# vis = DipoleNearFieldVisualization(case='numerical_scatterer')
# vis.to_file()
Video(os.path.join("videos", "near_fields_numerical_scatterer.mp4"), embed=True, width=1000, html_attributes='loop autoplay muted')
```