This program was contributed by Siarhei Uzunbajakau, CEM Books, 2025.
Introduction
Problem definition
This tutorial illustrates application of the FE_Nedelec and FE_RaviartThomas
finite elements to problems in electromagnetics. To this end, we will compute
the magnetic field induced by a coil with a magnetic core and compare the
result to an exact closed-form analytical expression of the magnetic field. We
will repeat the comparison on a set of progressively refined meshes and observe
that the $L^2$ error norm decreases with the size of mesh cells. We will
also vary the degree of the finite elements and observe that the higher-degree
finite elements imply faster convergence of the $L^2$ error norms. Experimenting
with boundary conditions is suggested as a possibility for extension.
The first figure below illustrates a cross section of the coil. The second
figure illustrates the corresponding problem domain, coordinate system, and the
relevant notations. The coil consists of two spherical shells. The inner shell,
depicted in green, is the magnetic core. The walls of the core are
filled with a soft magnetic material of permeability $\mu_1$. The magnetic
material is assumed to be homogeneous, linear, lossless, and isotropic. The
permeability of the rest of the space (the ball-shaped space inside the core and
the space outside the core) equals to that of the free space, $\mu_0$. The
permeability of the entire space can be expressed as
\f{equation}{
\mu = \left\{
\begin{aligned}
& \mu_0 &\text{if } \text{ } & r < a_1\\
& \mu_1 &\text{if } \text{ } & a_1 \le r \le b_1\\
& \mu_0 &\text{if } \text{ } & r > b_1.
\end{aligned}
\right.
\f}
The outer shell, depicted in blue, contains the current-carrying windings of
the coil. The windings are modeled by a prescribed free-current density. The
prescribed free-current density fills all the space available in the wall of
the shell. In the figure below, however, only three cross sections of the
free-current density are shown. The free-current density is the highest on the
equator and equals zero at the two poles. It can be described as
\f[
\vec{J}_f = \left\{
\begin{aligned}
& 0 &&\text{if }&& r < a_2\\
& K_0 (-y\hat{i} + x\hat{j})&&\text{if }&& a_2 \le r \le b_2\\
& 0 &&\text{if }&& r > b_2\\
\end{aligned}
\right.
\f]
in the Cartesian coordinate system.
@htmlonly
@endhtmlonly
There is no consensus in the literature on what to call a magnetic field.
On this page we adopt the nomenclature from @cite griffiths2017b. Consequently,
we call a magnetic field the vector quantity $\vec{B}$ such that the Ampere's
law in free space in static approximation reads
\f[
\begin{equation}
\vec{\nabla} \times\vec{B} = \mu_0\vec{J},
\end{equation}
\f]
where $\vec{J}$ is the total current density, free plus bound.
Problem domain and coordinate systems
We adopt the Cartesian coordinate system, the coordinates being $x$, $y$, and
$z$, as shown in the figure below. We denote the corresponding unitary basis
vectors as $\hat{i}$, $\hat{j}$, and $\hat{k}$. The problem domain consists
of a ball centered at the origin and four spherical shells around it.
The spheres $\Gamma_{I1}$ and $\Gamma_{I2}$ are interfaces between the magnetic
material and free space. Strictly speaking, the magnetic field induced by the
coil extends to infinity. Therefore, the problem we would like to solve
is unbounded. As the mesh needs to have finite dimensions, we truncate the
space with the sphere $\Gamma_{R1}$. This sphere will represent infinity.
We denote the spherical coordinates as $r$, $\theta$, and $\phi$, with $\theta$
and $\phi$ being polar and azimuthal angles, respectively. The figure below
illustrates the basis vectors of the spherical coordinate system, $\hat{r}$,
$\hat{\theta}$, and $\hat{\phi}$.
@htmlonly
@endhtmlonly
Exact solution
The problem of a permeable spherical shell exposed to a uniform magnetic field
is ubiquitous in the literature on electromagnetics. The problem of the magnetic
field generated by a spherical coil can be found in the literature as well.
Remarkably, the magnetic field inside the coil is uniform. Due to this fact one
can combine the solution to these two problems to get the exact closed-form
analytical expressions for the magnetic field generated by the coil described
above. The exact solution presented below is a combination of the solutions to
the problems of permeable shell and spherical coil. The derivation of the
equations presented below can be found in @cite uzunbajakau2024b.
We express the magnetic field induced by the coil as a sum of the magnetic
field induced by the free-current density in free space, $\vec{B}_J$,
and the magnetic field induced by the magnetization of the magnetic core,
$\vec{B}_{\mu}$,
\f[
\vec{B} = \vec{B}_J +\vec{B}_{\mu}.
\f]
It is convenient to express the term $\vec{B}_J$ in a spherical coordinate
system,
\f[
\vec{B}_J = \left\{
\begin{aligned}
& \frac{1}{2} (b_2^2-a_2^2) \vec{F}_1(\theta)
&&\text{if }&& r \le a_2\\
& \frac{1}{2} (b_2^2-r^2) \vec{F}_1(\theta) +
\frac{1}{5} (r^5-a_2^5) \vec{F}_2(r, \theta)
&& \text{if } && a_2 \le r \le b_2\\
& \frac{1}{5} (b_2^5-a_2^5) \vec{F}_2(r, \theta) &&\text{if }&& r \ge b_2,\\
\end{aligned}
\right.
\f]
where
\f[
\begin{aligned}
&\vec{F}_1(\theta) = \dfrac{2}{3}\mu_0
K_0\big(\cos(\theta)\hat{r}-\sin(\theta)\hat{\theta}\big), \\
&\vec{F}_2(r, \theta) = \dfrac{2}{3}\mu_0 K_0
\frac{1}{r^3}\big(\cos(\theta)\hat{r}+\frac{1}{2}\sin(\theta)\hat{\theta}\big).
\end{aligned}
\f]
We, however, need to program in the Cartesian coordinate system. The expressions
above can be converted into the Cartesian coordinate system by invoking the
following identities:
\f[
r = \sqrt{x^2+y^2+z^2},
\f]
\f[
\cos(\theta) = \frac{z}{r},
\f]
\f[
\sin(\theta) = \frac{\sqrt{x^2+y^2}}{r},
\f]
\f[
\cos(\phi) = \frac{x}{\sqrt{x^2+y^2}},
\f]
\f[
\sin(\phi) = \frac{y}{\sqrt{x^2+y^2}},
\f]
\f[
\hat{r} = \frac{1}{r} (x\hat{i}+y\hat{j}+z\hat{k}),
\f]
and
\f[
\hat{\theta}= \cos(\theta)\cos{\phi}\hat{i} + \cos(\theta)\sin{\phi}\hat{j} - \sin(\theta) \hat{k}.
\f]
The magnetic field induced by the magnetic core can be expressed in Cartesian
coordinates as
\f[
\vec{B}_{\mu} = - \mu\vec{\nabla} \Psi - \mu_0 H_0 \hat{k},
\f]
where
\f[
H_0 = \frac{1}{3} K_0 (b_2^2-a_2^2),
\f]
\f{equation}{
\mu = \left\{
\begin{aligned}
& \mu_0 &\text{if } \text{ } & r < a_1\\
& \mu_1 &\text{if } \text{ } & a_1 \le r \le b_1\\
& \mu_0 &\text{if } \text{ } & r > b_1,
\end{aligned}
\right.
\f}
and
\f{equation}{
\vec{\nabla} \Psi = \left\{
\begin{aligned}
&\delta_1 \hat{k} &\text{if } \text{ } & r \le a_1\\
&-3\gamma_1\frac{xz}{r^5}\hat{i} -3\gamma_1\frac{yz}{r^5}\hat{j} +
\bigg(\beta_1 + \gamma_1\frac{1}{r^3} - 3\gamma_1\frac{z^2}{r^5} \bigg)\hat{k}
&\text{if } \text{ } & a_1 \le r \le b_1\\
&-3\alpha_1\frac{xz}{r^5}\hat{i} -3\alpha_1\frac{yz}{r^5}\hat{j} +
\bigg(-H_0 + \alpha_1\frac{1}{r^3} - 3\alpha_1\frac{z^2}{r^5} \bigg)\hat{k}
&\text{if } \text{ } & r \ge b_1.
\end{aligned}
\right.
\f}
The following constants were used in the last equation:
\f{equation}{
\begin{aligned}
&\Omega = \frac{(\mu_r - 1)}{(\mu_r + 2)} \frac{a_1^3}{b_1^3}, \\
&\gamma_1 = \frac{-3b_1^3 H_0 \Omega}{(2\mu_r+1)-2 (\mu_r-1) \Omega}, \\
&\beta_1 = \frac{(2\mu_r+1) \gamma_1}{(\mu_r-1)a_1^3}, \\
&\alpha_1 = \frac{-b_1^3 H_0+2\mu_r\gamma_1-\mu_r b_1^3\beta_1}{2}, \\
&\delta_1 = \frac{\mu_r a_1^3\beta_1-2\mu_r\gamma_1}{a_1^3}.
\end{aligned}
\f}
The relative permeability in the last five equations is computed as
\f[
\mu_r = \frac{\mu_1}{\mu_0}.
\f]
Boundary value problems
Magnetic vector potential - A
Ampere's law in static approximation can be written in terms of the
auxiliary vector field $\vec{H}$ as
\f[
\vec{\nabla}\times\vec{H} = \vec{J}_f,
\f]
where $\vec{J}_f$ is the free current and $\vec{H}$ is given by
\f{equation}{
\begin{array}{ll}
\vec{H} = \dfrac{1}{\mu}\vec{B} & \text{(constitutive relation)}.
\end{array}
\f}
We introduce the magnetic vector potential, $\vec{A}$, as
\f{equation}{
\begin{array}{ll}
\vec{B} = \vec{\nabla}\times\vec{A} &
\text{(definition of magnetic vector potential)}.
\end{array}
\f}
By combining the last three equations we arrive at
\f[
\vec{\nabla}\times\bigg(\dfrac{1}{\mu} \vec{\nabla}\times\vec{A}\bigg) =
\vec{J}_f,
\f]
which is the curl-curl partial differential equation we would like to solve.
There are, however, two subtleties we need to address before solving any
curl-curl equations: the gauge and compatibility condition.
Gauge
The Helmholtz decomposition theorem suggests that any vector field studied in
electromagnetics, say $\vec{A}$, can be represented as a sum of a conservative
and a solenoidal vector field,
\f[
\vec{A} =
\underbrace{- \vec{\nabla} V}_{\text{conservative}} +
\underbrace{\vec{\nabla} \times \vec{W}}_{\text{solenoidal}} =
\vec{C} + \vec{S}.
\f]
The curl of a conservative vector field always equals zero (conservative fields
are curl free),
\f[
\vec{\nabla} \times \vec{C} =
-\vec{\nabla} \times \big( \vec{\nabla} V \big) = 0.
\f]
Consequently, any vector field derived by adding a conservative vector field to
a solution to the curl-curl equation is also a solution,
\f[
\vec{\nabla}\times\bigg(\dfrac{1}{\mu} \vec{\nabla}\times\Big(\vec{A}
- \vec{\nabla} V'\Big)\bigg) =
\vec{\nabla}\times\bigg(\dfrac{1}{\mu} \vec{\nabla}\times\vec{A}\bigg).
\f]
We can restrict this freedom by specifying the divergence of the solution.
Indeed, the divergence of a solenoidal vector field always equals zero (solenoidal
fields are divergence free),
\f[
\vec{\nabla} \cdot \vec{S} =
\vec{\nabla} \cdot \big(\vec{\nabla} \times \vec{W}\big) = 0.
\f]
Then the divergence of a solution can be expressed as
\f[
\vec{\nabla} \cdot \vec{A} =
\vec{\nabla} \cdot \big(\vec{C} + \vec{S}\big) =
\vec{\nabla} \cdot \vec{C}.
\f]
By specifying the divergence of the solution, we specify the divergence of the
conservative part of the solution, and, thus, we specify the conservative part
of the solution itself. In short: the magnetic vector potential consists of
conservative and solenoidal components; the curl-curl equation fixes the
solenoidal component, the gauge fixes the conservative component. For example,
the Coulomb gauge,
\f[
\vec{\nabla} \cdot \vec{A} = 0,
\f]
specifies that there is no conservative component in $\vec{A}$. That is, the
Coulomb gauge selects a purely solenoidal solution. We are interested in the
magnetic field, $\vec{B}$. In the realm of classical electromagnetics, the
magnetic vector potential, $\vec{A}$, has an instrumental value - we just use
it to compute the magnetic field, $\vec{B}$. The magnetic vector potential is
a useful mathematical tool but it has no physical meaning as it cannot be
measured. On the contrary, the magnetic field, $\vec{B}$, can be measured and,
as a consequence, has a distinctive physical meaning. From a physical
perspective, there are (infinitely) many magnetic vector potentials that lead
to the same physically measurable magnetic field and for a physicist, it doesn't
matter which of these potentials we choose. But from a mathematical perspective,
we need to pick one to make the problem well-posed. A gauge is a way to pick
one. Because the magnetic field is computed as
\f[
\vec{B} = \vec{\nabla}\times\vec{A} =
\vec{\nabla}\times\big(\vec{C} + \vec{S} \big) =
\vec{\nabla}\times\vec{S},
\f]
we are interested in the solenoidal part of the solution. Which conservative
component of the solution is brought by the gauge is not important.
A good question is: how to enforce the gauge? The literature suggests that the
best approach is not to gauge the magnetic vector potential explicitly. Instead,
one should invoke an advanced linear solver (tree-cotree splitting, domain
decomposition, geometric multigrid, algebraic multigrid, etc.). For example,
in @cite manges1995a it is suggested that the tree-cotree splitting can be used
us a gauge. The hypre AMS utilizes a more modern approach @cite hypre1998b. It
can solve positive semidefinite linear systems yielded by the ungauged curl-curl
equation. In general, if a solver is able to choose one solution out of many
ungauged solutions, we can claim that such solution is implicitly gauged by
the linear solver. The linear solver will not communicate to us which gauge has
been applied, i.e., the conservative part of the solution will be fixed, but we
will not be able to tell what it is, exactly. We will call such gauge an
implicit gauge. An implicit gauge is good enough for our purpose.
We will use the CG solver which is the next best choice to the advanced linear
solvers mentioned above. The CG solver is designed to handle symmetric positive
definite matrices. This means that all eigenvalues of the system matrix are
expected to be positive. On the other hand, the curl-curl equation above
being augmented with proper boundary conditions will always yield a symmetric
positive semidefinite matrix. The last means that most of the eigenvalues of
the system matrix will be positive but some of them will be zero. We elevate
the zero eigenvalues above zero just a bit by adding a very small gauging
term, $\eta^2\vec{A}$, to the partial differential equation,
\f[
\vec{\nabla}\times\bigg(\dfrac{1}{\mu} \vec{\nabla}\times\vec{A}\bigg) +
\eta^2\vec{A} = \vec{J}_f,
\f]
so all eigenvalues become positive. Formally, the system matrix with
elevated eigenvalues is symmetric positive definite. We can feed it to
the CG solver. The partial differential equation is different now. We can
expect a different solution. Moreover, $\eta^2 \vec{A}$ belongs to the
$H(\text{curl})$ function space, while the rest of the terms of the partial
differential equation belong to the $H(\text{div})$ function space, see the
Bossavit's diagram below. They exhibit different behavior on interfaces
between dissimilar materials. Strictly speaking, we destroy the compatibility
between the two sides of the curl-curl equation by adding the gauging term.
However, by choosing the parameter $\eta^2$ to be small enough we can make
these horrible crimes insignificant. In practice, we need to set $\eta^2$
to zero. If the CG solver chokes, we will increase $\eta^2$ just a bit. Setting
$\eta^2=\dfrac{10^{-6}}{\mu_0}$ can save the day. The $\eta^2$-trick is an
implicit gauge: it helps the CG solver to select one solution out of many,
but it is impossible to predict what the conservative part of the solution
will look like. The last is not important for the problem we would like to
solve because, as mentioned above, the vector potential $\vec{A}$ has no
physical reality and all choices of a gauge (including the implicit gauge used here)
lead to the same physical fields.
Compatibility condition
To solve the curl-curl equation numerically, we need to feed to the solver the
right-hand side of the equation, $\vec{J}_f$. Whatever we do, we will end up
feeding to the solver a discretized version of $\vec{J}_f$ which will be a
combination of conservative and solenoidal vector fields even if the problem
we would like to solve specifies a closed-form analytical expression of a purely
solenoidal $\vec{J}_f$. The conservative component will be added implicitly by
discretization. On the other hand, the left-hand side of the curl-curl equation
is purely solenoidal as the curl of any vector field is always solenoidal
(assume $\eta^2 = 0$ for a moment). Therefore, the two sides of the equation
will be somewhat incompatible: pure solenoidal vector field on the left-hand
side and a combination of a conservative and solenoidal vector fields on the
right-hand side. As a consequence, we cannot expect that we can get the norm
of the residual to zero. In other words, the linear solver cannot converge
to a solution that has zero residual. In practice, this means that CG will
either not converge at all, or terminate only after an unreasonably large
number of iterations. To make the two sides of the equation compatible, we derive
the free-current density from a current vector potential, $\vec{T}$, as
\f[
\vec{J}_f = \vec{\nabla}\times\vec{T}.
\f]
Consequently, the curl-curl equation becomes
\f[
\vec{\nabla}\times\bigg(\dfrac{1}{\mu} \vec{\nabla}\times\vec{A}\bigg) +
\eta^2\vec{A} = \vec{\nabla}\times\vec{T}.
\f]
This equation contains purely solenoidal vector fields on both sides if $\eta^2=0$.
Now, however, we need to convert $\vec{J}_f$ into $\vec{T}$. There are a number
of ways of doing so. One of them is solving another curl-curl equation as
discussed below. For now we assume that $\vec{T}$ is known.
Boundary and interface conditions
Even if the magnetic vector potential is gauged and the compatibility issue
is solved, one still needs to set up the boundary conditions to pick up one
solution out of many gauged vector potentials that satisfy the curl-curl
equation. Moreover, the behavior of the magnetic field on interfaces between
dissimilar materials is defined by the Maxwell's equations. Consequently, the
behavior of the magnetic vector potential on interfaces is defined by the
Maxwell's equations as well. For this reason, we need to add the interface
conditions next to the boundary conditions to ensure the correct behavior of
the current vector potential on interfaces. The curl-curl partial differential
equation augmented with the boundary and interface conditions constitutes the
boundary value problem. We compose the following boundary value problem for the
problem discussed above:
\f{equation}{
\begin{array}{lrcll}
\text{ } & \vec{\nabla}\times\bigg(\dfrac{1}{\mu} \vec{\nabla}\times\vec{A}\bigg)
+ \eta^2 \vec{A} = \vec{\nabla}\times\vec{T} & \text{in} & \Omega & \text{(i)},\\
\text{(n)}& \dfrac{1}{\mu}\hat{n}\times\bigg(\vec{\nabla}\times\vec{A}\bigg) +
\gamma \hat{n}\times\bigg(\hat{n}\times\vec{A}\bigg)
=0 &\text{on} & \Gamma_{R1} & \text{(ii)}, \\
\text{(e)}&\hat{n}\times\vec{A}_{+} =
\hat{n}\times\vec{A}_{-}&\text{on}&\Gamma_{I1}\cup\Gamma_{I2}&\text{(iii)},\\
\text{(n)}&\dfrac{1}{\mu}_{+}\hat{n}\times \bigg( \vec{\nabla} \times \vec{A}_{+} \bigg) -
\dfrac{1}{\mu}_{-}\hat{n}\times \bigg( \vec{\nabla} \times \vec{A}_{-} \bigg) = 0
& \text{on} & \Gamma_{I1}\cup\Gamma_{I2} & \text{(iv)},
\end{array}
\f}
where
\f[
\gamma = \frac{1}{\mu r}.
\f]
In this boundary value problem the vector $\hat{n}$ is the unit vector normal
to the surface on which the boundary or interface condition is defined. By
convention, $\hat{n}$ always points outside a closed surface. The subscript
"+" refers to the space immediately next to the interface in the direction
of vector $\hat{n}$. The subscript "-" refers to the space immediately next
to the interface in the direction opposite to $\hat{n}$.
Equation (i) in the boundary value problem has been discussed above and needs
no further comments.
The surface $\Gamma_{R1}$ represents infinity. As most problems in magnetics,
the problem we would like to solve is unbounded. That is to say, the magnetic
field as well as the magnetic vector potential extend to infinity. A
straightforward modeling of an unbounded domain by means of finite elements is
impossible as such modeling will require an infinite amount of cells. To
overcome this unfortunate predicament, we artificially truncate the unbounded
problem domain with the surface $\Gamma_{R1}$. This truncation will introduce a
simulation error. We, however, will try to minimize this error by making the
interior of the artificial surface $\Gamma_{R1}$ as spacious as possible.
The magnetic field induced by the coil vanishes at infinity, so does the
magnetic vector potential. For this reason, the homogeneous Dirichlet,
\f{equation}{
\begin{array}{ll}
\hat{n} \times \vec{A} = 0 & \text{(Dirichlet)},
\end{array}
\f}
and homogeneous Neumann,
\f{equation}{
\begin{array}{ll}
\dfrac{1}{\mu}\hat{n}\times\bigg(\vec{\nabla}\times\vec{A}\bigg) = 0 &
\text{(Neumann)},
\end{array}
\f}
boundary conditions are used on $\Gamma_{R1}$ most often. For this approach to be
efficient, one needs to choose the radius of the sphere $\Gamma_{R1}$ large enough so that
the tangential component of the magnetic vector potential (Dirichlet) or the
tangential component of the magnetic field (Neumann) is negligibly small on
$\Gamma_{R1}$. There is, however, a more efficient approach.
The first term of the multipole expansion of magnetic vector potential is
the magnetic vector potential of a magnetic dipole moment unless the source
of the magnetic field is explicitly configured as a higher-order multipole.
For this reason, the magnetic vector potential induced by the coil looks more
like that of a magnetic dipole at a sufficient distance. If a magnetic dipole
is placed at the center of a sphere, the magnetic vector potential induced by
the dipole on the sphere satisfies the following identity:
\f[
\hat{n} \times \bigg( \vec{\nabla}\times \vec{A} \bigg) = - \frac{1}{r}
\hat{n} \times \bigg( \hat{n} \times \vec{A} \bigg).
\f]
Note that this is a purely geometric statement. It does not depend on how we
choose our coordinate system. Consequently, the identity given by the last
equation is true for a magnetic dipole of any orientation as long as it is
situated at the center of the sphere. By multiplying the last equation by
$\dfrac{1}{\mu}$ and rearranging the terms we arrive into
\f{equation}{
\begin{array}{ll}
\dfrac{1}{\mu}\hat{n}\times\bigg(\vec{\nabla}\times\vec{A}\bigg) +
\dfrac{1}{\mu r}\hat{n}\times\bigg(\hat{n}\times\vec{A}\bigg)
=0 & \text{(Robin)},
\end{array}
\f}
which is, essentially, the Robin boundary condition (ii) in the boundary value
problem above. The Robin boundary condition in the current context is also called
the first-order asymptotic boundary condition, first-order ABC for short.
The Robin boundary condition is expected to be superior to both Dirichlet and
Neumann boundary conditions as it allows to reach the same level of simulation
error with a sphere $\Gamma_{R1}$ of a smaller radius.
All three boundary conditions, Dirichlet, Neumann, and Robin, guarantee the
uniqueness of the curl of the solution, $\vec{\nabla}\times\vec{A}$. The
uniqueness of the solution itself, $\vec{A}$, can only be guaranteed if
one of the boundary conditions is applied in combination with a gauge, see the
discussion above. The program uses the Robin boundary condition by default,
but can easily be switched to Dirichlet or Robin boundary conditions.
The behavior of the magnetic field on the interfaces between dissimilar
materials can be described by
\f{equation}{
\begin{array}{ll}
\hat{n}\cdot\vec{B}_+ = \hat{n}\cdot\vec{B}_- ,\\
\hat{n}\times\vec{H}_+ - \hat{n}\times\vec{H}_- = \vec{K}_f,
\end{array}
\f}
where $\vec{K}_f$ is a surface free-current density that can be present on an
interface. No free currents flow on the surface of the magnetic core of the coil
described above. Therefore, we set $\vec{K}_f = 0$. Then by substituting the
constitutive relation for the magnetic field and the definition of the magnetic
vector potential, see above, into the last two equations we get
\f{equation}{
\begin{array}{ll}
\hat{n}\cdot\bigg(\vec{\nabla}\times\vec{A}_+\bigg) =
\hat{n}\cdot\bigg(\vec{\nabla}\times\vec{A}_-\bigg) &\text{(condition A)},\\
\hat{n}\times\bigg(\dfrac{1}{\mu_+}\vec{\nabla}\times\vec{A}_+\bigg) -
\hat{n}\times\bigg(\dfrac{1}{\mu_-}\vec{\nabla}\times\vec{A}_-\bigg) = 0.
\end{array}
\f}
Next, we simply replace the first condition with another condition
and rearrange the terms of the second condition:
\f{equation}{
\begin{array}{ll}
\hat{n}\times\vec{A}_+ = \hat{n}\times\vec{A}_- & \text{(condition B)}, \\
\dfrac{1}{\mu_+}\hat{n}\times\bigg(\vec{\nabla}\times\vec{A}_+\bigg) -
\dfrac{1}{\mu_-}\hat{n}\times\bigg(\vec{\nabla}\times\vec{A}_-\bigg) = 0,
\end{array}
\f}
The last two equations are identical to equations (iii) and (iv) in the boundary
value problem above. These are the interface conditions that must be observed on
the inner and outer surfaces of the magnetic core, $\Gamma_{I1}\cup\Gamma_{I2}$.
We have replaced condition A with condition B. This replacement deserves an
explanation. The are two reasons for this replacement. The first reason is the
following. A magnetic flux through an infinitesimally small closed loop must be
infinitesimally small even if an interface between dissimilar magnetic materials
passes through the loop. We can guarantee this only if we require that
condition B holds. Condition A will not do. The second reason is the
uniqueness of the curl of the solution. If we include condition A into the
boundary value problem above, the uniqueness of the curl of the solution,
$\vec{\nabla}\times\vec{A}$, cannot be guaranteed. It is possible
to guarantee it if condition B is included instead. A good question is:
does this replacement disturb the behavior of the magnetic field on the
interfaces? Not at all. Consider the following. The normal component
of the curl, $\hat{n}\cdot\big(\vec{\nabla}\times\vec{A}\big)$, is defined by
the derivatives of the tangential components of the vector potential. If two
vector potentials, $\vec{A}_-$ and $\vec{A}_+$, have the same tangential
components on the interface, i.e., condition B, the derivatives of these
tangential components along the interface will be the same as well. Therefore,
condition B implicitly implies condition A and, thus, the replacement is
justified. We can conclude that condition B is more restrictive than
condition A, so the behavior of the magnetic vector potential on the
interfaces is observed. Note, that the interface conditions (iii) and (iv)
in the boundary value problem above have absolutely no influence on the
uniqueness of the solution regardless which boundary condition, Dirichlet,
Neumann, or Robin, is used.
It remains to comment on the labels (e) and (n) in the boundary value problem
above. They label (e)ssential and (n)atural boundary and interface conditions.
How to sort conditions in these two categories and why it is important to do
so is discussed below in the section on variational formulations.
Current vector potential - T
To be able to solve the boundary value problem above, we need to convert the
free current density, $\vec{J}_f$, into current vector potential, $\vec{T}$. We
define the current vector potential as
\f[
\vec{J}_f = \vec{\nabla}\times\vec{T}.
\f]
By taking the curl of the last equation and rearranging the terms we arrive into
\f[
\vec{\nabla}\times\bigg(\vec{\nabla}\times\vec{T}\bigg)
= \vec{\nabla}\times\vec{J}_f.
\f]
We will compute the current vector potential by solving this equation. As soon
as there are curls of vector fields on both sides of the equation, the
compatibility condition is observed. We add to this equation a gauging term,
\f[
\vec{\nabla}\times\bigg(\vec{\nabla}\times\vec{T}\bigg) + \eta^2 \vec{T}
= \vec{\nabla}\times\vec{J}_f.
\f]
The discussion on the gauging term in the preceding section is valid in the
current context as well.
The current vector potential is computed in free space, i.e., $\mu = \mu_0$
everywhere. For this reason, there is no need for interface conditions as
there are no interfaces in free space.
We still need to apply a boundary condition to the surface $\Gamma_{R1}$.
It is beneficial to apply the homogeneous Dirichlet boundary condition as it
allows to nullify the integral $I_{b3-2}$ in the recipe for calculating the
magnetic vector potential, see below. Consequently, we can neglect this
integral when programming and this makes the code more efficient.
We compose a boundary value problem by combining the curl-curl equation for
the current vector potential with the Dirichlet boundary condition:
\f{equation}{
\begin{array}{lrcll}
\text{ } & \vec{\nabla}\times\bigg(\vec{\nabla}\times\vec{T}\bigg)
+ \eta^2 \vec{T} = \vec{\nabla}\times\vec{J}_f & \text{in} & \Omega &
\text{(i)},\\
\text{(e)}& \hat{n}\times\vec{T} = 0 &\text{on} & \Gamma_{R1} & \text{(ii)}.
\end{array}
\f}
Variational formulations
Magnetic vector potential
The problem of solving the boundary value problem for the magnetic vector
potential can be replaced by the problem of minimizing the following
functional:
\f{equation}{
\begin{aligned}
&F(\vec{A}) =
\iiint_{\Omega}\frac{1}{\mu}\bigg|\vec{\nabla}\times\vec{A}\bigg|^2 dV +
\iint_{\Gamma_{R1}} \gamma \bigg|\hat{n}\times\vec{A}\bigg|^2 dS +
\eta^2 \iiint_{\Omega}\mid\vec{A}\mid^2 dV
-2\iiint_{\Omega} \vec{T} \cdot \bigg( \vec{\nabla} \times\vec{A} \bigg) dV
+2\iint_{\Gamma_{R1}} \vec{T} \cdot \bigg(\hat{n}\times\vec{A}\bigg) dS.
\end{aligned}
\f}
Any magnetic vector potential that minimizes this functional will satisfy
the curl-curl equation (i), the boundary condition (ii) and the interface
condition (iv). On the other hand, this functional is invariant to the
interface condition (iii). This can be verified as follows: The
first variation of the functional at the minimum vanishes,
\f[
\delta F(\vec{A}) = 0.
\f]
We can express the first variation and deduce that the identities given by
equations (i), (ii), and (iv) in the boundary value problem must be satisfied
for the last equation to be true. The interface condition (iii), however,
is not needed for the last equation to be satisfied. The boundary and
interface conditions that are needed to drive the first variation of the
functional to zero are called natural and are labeled by (n) in the boundary
value problem. If a condition is not natural, it is essential. We label
essential conditions by (e).
The natural conditions are enforced by minimization of the functional. The
essential boundary and interface conditions must be enforced by other means.
The interface condition (iii) in the boundary value problem above is enforced
by choosing the finite elements wisely. The FE_Nedelec finite elements ensure
continuity of the tangential component of the vector field they model on the
faces of the cells. Therefore, if we construct the mesh such that all interfaces
are made of cell faces, i.e., no interface runs through a cell, and choose the
FE_Nedelec finite elements to model the magnetic vector potential, the
interface condition (iii) will be enforced automatically. The Dirichlet boundary
condition is essential. It is enforced by constraining the degrees of freedom
in the system of linear equations. This can be done by invoking the deal.II
function VectorTools::project_boundary_values_curl_conforming_l2(). The other
two boundary conditions, Neumann and Robin, are natural.
Note that the homogeneous Neumann boundary condition is embedded into the
first integral of the functional. This integral is present in all functionals
related to the curl-curl equation, even in the most minimalistic ones.
Therefore, application of no boundary condition is quite impossible: the
homogeneous Neumann boundary condition,
\f[
\frac{1}{\mu}\hat{n}\times\bigg(\vec{\nabla}\times\vec{A}\bigg) = 0,
\f]
will be applied implicitly by default as a result of the functional
minimization.
We can switch between the three boundary conditions as the following.
- The functional above as it is corresponds to a boundary value problem with
Robin boundary condition, i.e., the boundary value problem given above.
- To switch to Neumann boundary condition, we need to discard the second
integral from the functional. Such functional will correspond to the boundary
value problem above with equation (ii) replaced by the Neumann boundary
condition.
- To switch to Dirichlet boundary condition, we use the functional with
discarded second integral and use
VectorTools::project_boundary_values_curl_conforming_l2() to constrain the
system of linear equations. Such configuration will correspond to the
boundary value problem above with equation (ii) replaced by the Dirichlet
boundary condition.
In general, we need to sort all boundary and interface conditions into two
categories, natural and essential. The reason for doing so is simple: we need to
know which conditions are not taken care of by the functional (the essential
conditions), so we can take care of them by other means (choice of finite
elements, restricting dofs). Interrogating the first variation of the functional
as discussed above is a common method of sorting the conditions. A more detailed
discussion on boundary conditions can be found in step-22.
(@dealiiVideoLectureSeeAlso{21.5,21.55,21.6,21.65})
Next, we need to convert the functional above into a numerical recipe that can
be programmed into a computer. To do so, we note that the final result, i.e., the
magnetic vector potential computed by the finite element method, is represented
as a sum,
\f[
\vec{A}(\vec{r}) = \sum_{j=0}^{m-1} c_j \vec{N}_j(\vec{r}),
\f]
where $c_j$ are the degrees of freedom and $\vec{N}_j$ are the vector-valued
shape functions of the FE_Nedelec finite elements. We convert the functional into a
multivariate function by substituting the last equation into the functional,
\f[
f(c_0, c_1, ..., c_{m-1}) = F\bigg(\sum_{j=0}^{m-1} c_j \vec{N}_j\bigg).
\f]
Then we compose the system of linear equations by computing the partial
derivatives of the multivariate function:
\f{equation}{
\begin{array}{lr}
\dfrac{\partial}{\partial c_0} f(c_0, c_1, ..., c_{m-1})& = 0, \\
\dfrac{\partial}{\partial c_1} f(c_0, c_1, ..., c_{m-1})& = 0, \\
... & \\
\dfrac{\partial}{\partial c_{m-1}} f(c_0, c_1, ..., c_{m-1})& = 0.
\end{array}
\f}
This system of linear equations can be written in matrix form as
\f[
\boldsymbol{A} \boldsymbol{c} = \boldsymbol{b},
\f]
where $\boldsymbol{c}$ is a column vector filled with the degrees of freedom,
\f[
\boldsymbol{c} = [c_0, c_1, ... c_{m-1}]^T.
\f]
The system matrix and the right-hand side column vector are computed as
\f{equation}{
\begin{aligned}
& A_{ij} =
\underbrace{\iiint_{\Omega}\frac{1}{\mu}
\bigg(\vec{\nabla}\times\vec{N}_i\bigg) \cdot
\bigg(\vec{\nabla}\times\vec{N}_j\bigg) dV}_{I_{a1}}
+
\underbrace{\iint_{\Gamma_{R1}} \gamma
\bigg(\hat{n}\times \vec{N}_i \bigg) \cdot
\bigg(\hat{n}\times \vec{N}_j \bigg) dS}_{I_{a2}}
+
\underbrace{\eta^2\iiint_{\Omega} \vec{N}_i \cdot \vec{N}_j dV}_{I_{a3}}
\end{aligned}
\f}
and
\f{equation}{
b_i =
\underbrace{\iiint_{\Omega}\vec{T}\cdot\bigg(\vec{\nabla}\times\vec{N}_i\bigg) dV
}_{I_{b3-1}} -
\underbrace{\iint_{\Gamma_{R1}}\vec{T}\cdot\bigg(\hat{n}\times\vec{N}_i\bigg)dS
}_{I_{b3-2} = 0}.
\f}
The last two equations are implemented by the computer code. The integral $I_{b3-2}$
equals zero as the tangential component of the current vector potential,
$\hat{n} \times \vec{T}$, is forced to zero on the boundary $\Gamma_{R1}$ by
the Dirichlet boundary condition. We will neglect this integral in the computer
code.
Current vector potential
The problem of solving the boundary value problem
for the current vector potential can be replaced by the problem of minimizing
the following functional:
\f{equation}{
\begin{aligned}
&F(\vec{T}) =
\iiint_{\Omega}\bigg|\vec{\nabla}\times\vec{T}\bigg|^2 dV
+ \eta^2 \iiint_{\Omega}\mid\vec{T}\mid^2 dV
-2\iiint_{\Omega} \vec{J}_f \cdot \bigg( \vec{\nabla} \times\vec{T} \bigg) dV
+2\iint_{\Gamma_{R1}} \vec{J}_f \cdot \bigg(\hat{n}\times\vec{T}\bigg) dS,
\end{aligned}
\f}
and constraining the system of linear equations with a help of
VectorTools::project_boundary_values_curl_conforming_l2().
This functional is minimized by solving a system of linear equations with the
following system matrix and right-hand side column vector:
\f{equation}{
\begin{aligned}
& A_{ij} =
\underbrace{\iiint_{\Omega}
\bigg(\vec{\nabla}\times\vec{N}_i\bigg) \cdot
\bigg(\vec{\nabla}\times\vec{N}_j\bigg) dV}_{I_{a1}}
+
\underbrace{\eta^2\iiint_{\Omega} \vec{N}_i \cdot \vec{N}_j dV}_{I_{a3}},
\end{aligned}
\f}
\f{equation}{
b_i =
\underbrace{\iiint_{\Omega}\vec{J}_f\cdot\bigg(\vec{\nabla}\times\vec{N}_i\bigg) dV
}_{I_{b3-1}} -
\underbrace{\iint_{\Gamma_{R1}}\vec{J}_f\cdot\bigg(\hat{n}\times\vec{N}_i\bigg)dS
}_{I_{b3-2}=0}.
\f}
Here again, the integral $I_{b3-2}$ equals zero as the free-current density,
$\vec{J}_f$, equals zero at the boundary $\Gamma_{R1}$ by definition of the
problem. We will neglect this integral in the computer code.
Converting potentials into fields
As discussed above, we are interested in the magnetic field induced by the coil.
For this reason, we convert the numerically computed vector potential into magnetic
field as
\f[
\vec{B} = \vec{\nabla} \times \vec{A}.
\f]
The problem of computing this equation can be replaced by the problem of
minimizing the following functional:
\f[
F(\vec{B}) = \iiint_{\Omega} \big| \vec{B} \big|^2 dV -
2 \iiint_{\Omega} \bigg( \vec{\nabla} \times \vec{A} \bigg) \cdot \vec{B} dV.
\f]
This functional is minimized by solving a system of linear equations with the
system matrix
\f[
A_{ij} = \underbrace{\iiint_{\Omega} \vec{N}_i \cdot \vec{N}_j dV}_{I_a}
\f]
and right-hand side column vector
\f[
b_i = \underbrace{\iiint_{\Omega} \bigg( \vec{\nabla} \times \vec{A} \bigg)
\cdot \vec{N}_i dS}_{I_b}.
\f]
This time, however, $\vec{N}_i$ are the shape functions of the FE_RaviartThomas
finite elements. The vector field $\vec{A}$ in the last equation is the numerically
computed magnetic vector potential, i.e., a linear combination of the shape
functions of the FE_Nedelec finite elements.
It is informative to verify the quality of the computed current vector potential,
$\vec{T}$. We can do this by converting it back into the free-current
density, $\vec{J}_f$, and comparing the result to the closed-form analytical
expression given by the definition of the problem, see above. The current vector
potential relates to the free-current density as
\f[
\vec{J}_f = \vec{\nabla} \times \vec{T}.
\f]
This equation is, essentially, the same as the equation for converting
$\vec{A}$ into $\vec{B}$, see the first equation of this section. Consequently,
we can simply adapt the equations for the functional, system matrix, and the
right-hand side given above by making the following substitutions:
\f{equation}{
\begin{array}{lcr}
\vec{A} \rightarrow \vec{T} &\text{ and }& \vec{B} \rightarrow \vec{J}_f.
\end{array}
\f}
The two conversions, $\vec{A}$ into $\vec{B}$ and $\vec{T}$ into $\vec{J}_f$,
can be done by the same piece of code. We will call it a projector from
$H(\text{curl})$ to $H(\text{div})$.
Selecting finite elements
The preceding sections leave an impression that we are going to model $\vec{A}$
and $\vec{T}$ by the FE_Nedelec finite elements, while $\vec{B}$ and $\vec{J}_f$
by the FE_RaviartThomas finite elements. It makes sense to discuss how this
kind of choice can be made.
The simplest method of assigning a particular type of finite elements to a
physical quantity studied in electromagnetics is a contemplation of the Bossavit's
diagram. It is presented below. The Bossavit's diagram describes the relations
between physical quantities as they are given by Maxwell's equations and
constitutive relations. Most equations derived from Maxwell's equations
can be captured by this diagram.
@htmlonly
@endhtmlonly
Let us consider assigning the correct type of finite elements to the magnetic
vector potential, $\vec{A}$. First, we contemplate the Bossavit's diagram and
observe that $\vec{A}$ belongs to the $H(\text{curl})$ function space. Second,
we look at the table below and conclude that the physical quantities that belong
to the $H(\text{curl})$ function space are modeled by the FE_Nedelec finite
elements. Therefore, we need to model the magnetic vector potential, $\vec{A}$,
by the FE_Nedelec finite elements. The same assigning procedure can be applied
to the rest of the physical quantities, $\vec{B}$, $\vec{T}$, and $\vec{J}_f$.
|Funct. space |Finite elements |
|-----------------|-------------------|
|$H(\text{grad})$ | FE_Q |
|$H(\text{curl})$ | FE_Nedelec |
|$H(\text{div})$ | FE_RaviartThomas |
|$L^2$ | FE_DGQ |
Alternatively, one of the types of the finite elements listed in the table can
be assigned to a physical quantity by considering the behavior of the physical
quantity on the interfaces between dissimilar materials. Let us consider the
magnetic field $\vec{B}$ as an example. The normal component of the magnetic
field is continuous on interfaces. On the contrary, the tangential component is
discontinuous, see the first figure on this page. This type of behavior can be
modeled by the FE_RaviartThomas finite elements as they guarantee the continuity
of the normal component of the vector field on the faces of mesh cells.
Mesh
The mesh is, essentially, a discretization of the problem domain shown above.
The mesh is constructed such that all spherical surfaces of the problem domain
are delineated by cell faces. That is, no spherical surface runs through a mesh
cell. The figure below illustrates the mesh. The main elements of the mesh are
listed below.
- The cube with a side of $2d_1$ in the middle of the mesh. The purpose of
this cube is instrumental. This is the only way to construct a mesh that has
spherical interfaces and contains no tetrahedral cells as the cells around the
origin must be hexahedral.
- The spherical shell nr.1. This shell represents the magnetic core. The
permeability of this region is $\mu_1$. The permeability outside this region
is $\mu_0$.
- The spherical shell nr.2. This region contains the free current. There is no
free current outside this region.
- Sphere nr.1. The $L^2$ error norms are computed inside the region delineated
by this surface.
- Sphere nr.2. The boundary of the problem domain. Represents infinity. The
boundary condition is applied to this surface.
The program uses four meshes created with a help of gmsh. Each mesh has a
different degree of refinement. The degree of refinement in each mesh is
defined by a number of mesh nodes on the transfinite lines, $r$. The figure
below illustrates a mesh with $r=5$. The program uses four meshes with the
amount of nodes on the transfinite lines in the interval $r = [6, 9]$.
Note that this tutorial uses only globally refined meshes. There are no
non-conforming cells, hanging nodes, and hanging node constrains in this
tutorial. We will use constrains only for the purpose of enforcing the
Dirichlet boundary condition.
@htmlonly
@endhtmlonly
Overview of the program
The program runs in a loop. In each iteration of the loop a different parameter
$r$ (the mesh refinement parameter, i.e., the amount of nodes on transfinite
lines) is assumed. Each iteration consists of four stages:
- The current vector potential, $\vec{T}$, is computed given the closed-form
analytical expression for the free-current density, $\vec{J}_f$, see above.
No error norms are computed. The mesh is loaded at this stage. This mesh is
simply reused at all other stages.
- The current vector potential computed at the preceding stage, $\vec{T}$, is
converted numerically back into free-current density, $\vec{J}_f$, for
verification. The $L^2$ error norm is computed by comparing the numerical
result with the closed-form analytical expression. The $L^2$ error norm is
saved in a convergence table `table_Jf`.
- The magnetic vector potential, $\vec{A}$, is computed given the current vector
potential computed at the first stage, $\vec{T}$. No error norms are computed
at this stage.
- The magnetic vector potential computed at the preceding stage, $\vec{A}$, is
converted into magnetic field, $\vec{B}$. The $L^2$ norm is computed by
comparing the numerical result with the closed-form analytical solution. The
$L^2$ error norm is saved in a convergence table `table_B`.
The first stage is implemented by the code contained in the name space
`SolverT`. The third stage is implemented by the code contained in the name
space `SolverA`. The second and the fourth stages are implemented by the code
contained in the name space `ProjectorHcurlToHdiv`. The name space
`ExactSolutions` contains exact closed-form analytical expressions for
$\vec{B}$ and $\vec{J}_f$.
No error norms are computed at the first and the third stages. Computing error
norms at these stages makes no sense as we apply implicit gauges and the
conservative portion of the solution is unknown. We can, however, judge the
quality of the simulations at these two stages indirectly by evaluating the
quality of the simulations at the second and the fourth stages.