Logbook  (07-04-2025)
Static problems
1.2.3 Magnetic wire (mwr/)

Classes:

1) BatchMWR
2) SolverMWR
3) ExactSolutionMWR_A
4) ExactSolutionMWR_H
5) ExactSolutionMWR_B
6) SettingsMWR

Files:

1) mwr/src/main.cpp
2) mwr/include/solver.hpp
3) mwr/src/solver.cpp
4) mwr/include/exact_solution.hpp
5) mwr/src/exact_solution.cpp
6) mwr/src/static_scalar_input.cpp
7) mwr/include/settings.hpp

List of all shared classes


Introduction

In the most general case, a three-dimensional problem formulated in terms of the vector magnetic potential, \(\vec{A}\), is described by the curl-curl partial differential equation,

\[ \vec{\nabla} \times \bigg( \dfrac{1}{\mu} \vec{\nabla} \times \vec{A} \bigg) = \vec{J}_f. \]

If, however, a problem exhibits a translation symmetry and the magnetic vector potential is expected to have the following form:

\[ \vec{A}(x,y) = 0\hat{i} + 0 \hat{j} + A(x,y) \hat{k}, \]

the curl-curl equation can be replaced by the following div-grad equation:

\[ - \vec{\nabla} \cdot \bigg( \dfrac{1}{\mu} \vec{\nabla} A \bigg) = J_f, \]

see Section 3.4.1 Scalar planar problem.

This numerical experiment illustrates the application of the StaticScalarSolver::Solver to a problem formulated in terms of the two-dimensional planar magnetic vector potential, \(A\). To this end, we will obtain numerical solutions to a problem on a set of progressively refined meshes and compare the result to the closed-form analytical solution.

Implementation

The problem

The following problem is solved in this numerical experiment (Section 6.2.1. Isolated magnetic wire with current).

An infinitely long straight wire caries current. The cross section of the wire is a disk of a radius of \(a\) meters. The current is distributed uniformly within the wire. The permeabilities of the materials inside and outside the wire are \(\mu\) and \(\mu_0\), respectively. The material outside the wire fills all available space.

We would like to calculate the current vector potential \(A\), auxiliary field \(\vec{H}\), and magnetic field \(\vec{B}\).

The problem domain is unbounded. We truncate it to a disk of a radius \(b\) centered at the origin. The figure below illustrates the wire and the corresponding problem domain.

The following two closed-form analytical solutions to this problem can be obtained by invoking the Ampere's law:

\[ \begin{equation} \vec{B} = \left\{ \begin{aligned} \text{ }\text{ }\text{ } & \frac{1}{2} \mu r J_f \hat{\phi} & r < a \\ \text{ }\text{ }\text{ } & \frac{1}{2} \mu_0 \frac{a^2}{r} J_f \hat{\phi} & r > a \end{aligned} \right. \end{equation} \]

and

\[ \begin{equation} \vec{H} = \left\{ \begin{aligned} \text{ }\text{ }\text{ } & \frac{1}{2} J_f \hat{\phi} & r < a \\ \text{ }\text{ }\text{ } & \frac{1}{2} \frac{a^2}{r} J_f \hat{\phi} & r > a, \end{aligned} \right. \end{equation} \]

where

\[ r = \sqrt{x^2+y^2}. \]

To derive a closed-form expression for the magnetic vector potential we note that

\[ \hat{\phi} = -\sin(\phi)\hat{i} + \cos(\phi)\hat{j}= -\frac{y}{\sqrt{x^2+y^2}} \hat{i} + \frac{x}{\sqrt{x^2+y^2}} \hat{j.} \]

Therefore, the magnetic field can be expressed in the Cartesian coordinates as

\[ \begin{equation} \vec{B} = \left\{ \begin{aligned} \text{ }\text{ }\text{ } &-\frac{1}{2} \mu J_f (y\hat{i}-x\hat{j}) & r < a \\ \text{ }\text{ }\text{ } &-\frac{1}{2} \mu_0 J_f a^2 \bigg( \frac{y}{x^2+y^2}\hat{i}- \frac{x}{x^2+y^2}\hat{j} \bigg) & r > a. \end{aligned} \right. \end{equation} \]

The vector magnetic potential relates to the magnetic field as

\[ \vec{B} = \vec{\nabla}\overset{V}{\times} A = \frac{\partial A}{\partial y} \hat{i} - \frac{\partial A}{\partial x} \hat{j}. \]

By observing the last two equations we conclude that the magnetic vector potential must have the following form:

\[ \begin{equation} A = \left\{ \begin{aligned} \text{ }\text{ }\text{ } & -\frac{1}{4} \mu J_f (x^2 + y^2) + C_1 & r \le a \\ \text{ }\text{ }\text{ } & -\frac{1}{4} \mu_0 J_f a^2 \ln\bigg[\frac{x^2+y^2}{a^2}\bigg] + C_2& r \ge a, \end{aligned} \right. \end{equation} \]

where \(C_1\) and \(C_2\) are some constants. We have to choose the two constants such that the two expressions for \(A\), one for \( r \le a \) and one for \( r \ge a \), are equal if \(r = a\). Furthermore, the magnetic vector potential is infinite at infinity. This is not very convenient. We, however, can add a constant to the expression of the vector potential such that the potential equals zero at a particular circle concentric with the origin. We choose the boundary of the problem domain, \(\Gamma_{D1}\), to be this circle. That is, we need to choose the constants \(C_1\) and \(C_2\) such that \(A=0\) if \(r=b\). It is easy to verify that with such chosen constants \(C_1\) and \(C_2\) the expression for the magnetic vector potential above becomes

\[ \begin{equation} A = \left\{ \begin{aligned} \text{ }\text{ }\text{ } & -\frac{1}{4} \mu J_f (x^2 + y^2) + \frac{1}{4} \mu_0 J_f a^2 \ln\bigg[\frac{b^2}{a^2}e^{\mu_r}\bigg]& r \le a \\ \text{ }\text{ }\text{ } & -\frac{1}{4} \mu_0 J_f a^2 \ln\bigg[\frac{x^2+y^2}{a^2}e^{\mu_r}\bigg]+ \frac{1}{4} \mu_0 J_f a^2 \ln\bigg[\frac{b^2}{a^2}e^{\mu_r}\bigg] & r \ge a. \end{aligned} \right. \end{equation} \]

It is easy to verity that this vector potential is continuous on a circle of a radius of \(a\) and equals zero at the circle of a radius of \(b\). The last suggests that we can apply the homogeneous Dirichlet boundary condition, \(A=0\), to the outer boundary.

The mesh

The figure below illustrates the mesh (r=5).

The Dirichlet boundary condition

\[ A = 0 \]

is applied to the outer boundary.

The boundary value problem

The following boundary value problem is solved in this numerical experiment:

\begin{equation} \begin{array}{lrcll} \text{ }&- \vec{\nabla} \cdot \big(\dfrac{1}{\mu} \vec{\nabla} A \big)= J_f & \text{in} & \Omega & \text{(i)},\\ \text{(e)} & A = 0 & \text{on} & \Gamma_{D1} & \text{(ii)},\\ \text{(e)} & A_{+} = A_{-} & \text{on} & \Gamma_{I1} & \text{(iii)},\\ \text{(n)}&\dfrac{1}{\mu_{+}}\hat{n}\cdot\vec{\nabla} A_{+}-\dfrac{1}{\mu_{-}}\hat{n}\cdot\vec{\nabla}A_{-}=0&\text{on}&\Gamma_{I1}&\text{(iv)}. \end{array} \end{equation}

First, a class template (SolverMWR) derived from StaticScalarSolver::Solver is used to obtain the numerical solution, \(A\). After that, the numerical solution is fed to objects derived from the class templates StaticScalarSolver::ProjectAzToHxy and StaticScalarSolver::ProjectAzToBxy to calculate the auxiliary vector field \(\vec{H}\) and magnetic field \(\vec{B}\) as

\[ \vec{H} = - \vec{\nabla} \Theta \]

and

\[ \vec{B} = - \mu \vec{\nabla} \Theta, \]

respectively.

The program

The MWR experiment is implemented in accordance with the base code structure. The build process generates one executable file: mwr-circle. To rebuild it change into mwr/build/Release directory and execute the following:

user@computer .../mwr/build/Release$ ./clean
user@computer .../mwr/build/Release$ ./build

Then the executable file must be executed again. This can be done by changing into the mwr/bin/Release directory and executing mwr-circle,

user@computer .../mwr/build/Release$ cd ../../bin/Release
user@computer .../mwr/bin/Release$ ./mwr-circle

This will generate various files in the mwr/bin/Release/Data directory. Among the generated files there are vtu files that can be viewed with a help of ParaView software package of the Kitware, Inc. The data files in tex and txt format contain the convergence tables. The mwr/bin/Release/Data directory also contains circle.gpi file. It can be used to visualize the calculated potential along the \(x\) axis.

Note that executable files require a set of meshes to be present in the mwr/gmsh/data directory. If they are missing, they can be generated anew. This can be done by changing into mwr/gmsh directory and executing the following:

user@computer .../mwr/gmsh$ ./clean
user@computer .../mwr/gmsh$ ./build

This will generate a set of globally refined meshes in mwr/gmsh/data.

The SettingsMWR class allows switching on three useful features: printing time tables on the computer screen, logging convergence data of the conjugate gradient solver, and saving the exact solution into the vtk files next to the numerical solution.

Simulation results

The experiment was executed under the following conditions: \(a = 0.5[m]\), \(b=1.0[m]\), \(\mu = 4.0 \mu_0\).

Magnetic vector potential

The figure below illustrates a plot of the magnetic vector potential, \(A\), the output of an object of the SolverMWR type.

The corresponding convergence table is presented below.

p r cells dofs \(\|e\|_{L^2}/\mu_0\) \(\alpha_{L^2}\) \(\|e\|_{H^1}/\mu_0\) \(\alpha_{H^1}\)
1 5 320 337 1.03e-03 - 4.83e-02 -
1 6 500 521 6.72e-04 1.91 3.93e-02 0.93
1 7 720 745 4.73e-04 1.92 3.30e-02 0.94
1 8 980 1009 3.52e-04 1.93 2.85e-02 0.95
2 5 320 1313 1.34e-05 - 6.94e-04 -
2 6 500 2041 6.89e-06 2.97 4.47e-04 1.97
2 7 720 2929 4.00e-06 2.98 3.11e-04 1.98
2 8 980 3977 2.53e-06 2.99 2.29e-04 1.99
3 5 320 2929 1.18e-06 - 4.35e-05 -
3 6 500 4561 4.84e-07 3.99 2.22e-05 3.01
3 7 720 6553 2.34e-07 4.00 1.28e-05 3.02
3 8 980 8905 1.26e-07 4.00 8.04e-06 3.02

The following notations were used in the table header:

  • p - the degree of the interpolating Lagrange polynomials that constitute the shape functions.
  • r - the number of nodes on transfinite lines, see discussion in here.
  • cells - the total amount of active cells.
  • dofs - the amount of degrees of freedom in the active cells.
  • \(\|e\|_{L^2} / \mu_0\) - the normalized \(L^2\) error norm.
  • \(\|e\|_{H^1} / \mu_0\) - the normalized \(H^1\) error norm.
  • \(\alpha_{L^2}\) - the order of convergence of the \(L^2\) error norm.
  • \(\alpha_{H^1}\) - the order of convergence of the \(H^1\) error norm.

Auxiliary H-field

The figure below illustrates a plot of the calculated auxiliary H-field, \(\vec{H}\), the output of an object of the StaticScalarSolver::ProjectAzToHxy type.

The corresponding convergence table is presented below.

p r cells dofs \(\|e\|_{L^2}\) \(\alpha_{L^2}\)
1 5 320 656 6.49e-03 -
1 6 500 1020 4.70e-03 1.44
1 7 720 1464 3.59e-03 1.48
1 8 980 1988 2.86e-03 1.47
2 5 320 2592 7.49e-04 -
2 6 500 4040 4.85e-04 1.94
2 7 720 5808 3.40e-04 1.95
2 8 980 7896 2.51e-04 1.96
3 5 320 5808 2.70e-05 -
3 6 500 9060 1.37e-05 3.05
3 7 720 13032 7.82e-06 3.06
3 8 980 17724 4.87e-06 3.07

The following notations were used in the table header:

  • p - the degree of the FE_Q finite elements that were used to model the magnetic vector potential, \(A\). The degree of the FE_Nedelec finite elements that were used to model \(\vec{H}\) field equals \(p-1\).
  • r - the number of nodes on transfinite lines, see discussion in here.
  • cells - the total amount of active cells.
  • dofs - the amount of degrees of freedom in the active cells.
  • \(\|e\|_{L^2}\) - the \(L^2\) error norm.
  • \(\|e\|_{H^1}\) - the \(H^1\) error norm.
  • \(\alpha_{L^2}\) - the order of convergence of the \(L^2\) error norm.
  • \(\alpha_{H^1}\) - the order of convergence of the \(H^1\) error norm.

Magnetic field

The figure below illustrates a plot of the calculated magnetic field, \(\vec{B}\), the output of an object of the StaticScalarSolver::ProjectAzToBxy type.

The corresponding convergence table is presented below.

p r cells dofs \(\|e\|_{L^2}/\mu_0\) \(\alpha_{L^2}\)
1 5 320 656 4.83e-02 -
1 6 500 1020 3.93e-02 0.93
1 7 720 1464 3.30e-02 0.94
1 8 980 1988 2.85e-02 0.95
2 5 320 2592 6.94e-04 -
2 6 500 4040 4.47e-04 1.97
2 7 720 5808 3.11e-04 1.98
2 8 980 7896 2.29e-04 1.99
3 5 320 5808 4.35e-05 -
3 6 500 9060 2.22e-05 3.01
3 7 720 13032 1.28e-05 3.02
3 8 980 17724 8.04e-06 3.02

The following notations were used in the table header:

  • p - the degree of the FE_Q finite elements that were used to model the magnetic vector potential, \(A\). The degree of the FE_RaviartThomas finite elements that were used to model the magnetic field, \(\vec{B}\), equals \(p-1\).
  • r - the number of nodes on transfinite lines, see discussion in here.
  • cells - the total amount of active cells.
  • dofs - the amount of degrees of freedom in the active cells.
  • \(\|e\|_{L^2} / \mu_0\) - the normalized \(L^2\) error norm.
  • \(\|e\|_{H^1}\) - the \(H^1\) error norm.
  • \(\alpha_{L^2}\) - the order of convergence of the normalized \(L^2\) error norm.
  • \(\alpha_{H^1}\) - the order of convergence of the \(H^1\) error norm.