Overview
Problem Statement
We investigate the distribution of the longitudinal magnetic field component along the axis of a multi-coil solenoid.
Five concentric current-carrying coils are arranged inside an iron yoke. The entire assembly possesses axial symmetry. We need to find the distribution of the longitudinal magnetic field component along the axis of the system and the integral of this component.
Schematically, the domain under investigation appears as follows:

The magnetic permeability values of all materials are known throughout the domain. The coils are characterized by their number of turns and current. The three-dimensional geometry is shown below.

Mathematical Formulation
The fundamental mathematical model used to simulate nearly all macroscopic electromagnetic phenomena is the Maxwell equations system, which relates the electric and magnetic field components, medium parameters (electrical conductivity, magnetic and dielectric permittivity), and external sources of electromagnetic fields in the form of a system of vector differential equations:
where is the magnetic field intensity, is the external current density vector, is the electric field intensity, is the specific electrical conductivity of the medium, is the dielectric permittivity of the medium, is the magnetic flux density (related to the field intensity by , where is the magnetic permeability coefficient).
The task of magnetostatics refers to modeling the magnetic field created by a stationary (constant) electric current with a known distribution density . Such fields are described by two equations from the full Maxwell system:
Description of Stationary Magnetic Fields Using the Vector Potential
We represent as the curl of some vector-valued function , called the vector potential: .
With this representation of , Gauss’s equation becomes the identity , and the vector potential can be obtained from Ampère’s equation, where :
In the axisymmetric case, the current density vector has only one non-zero component , and both and the magnetic permeability are independent of the coordinate: , . In this case, the magnetic field is completely determined by only one component of the vector potential , satisfying the two-dimensional equation
or in cylindrical coordinates:
We perform the variable substitution
and transform the resulting equation:
Substituting these relations into the original equation and simplifying yields the following elliptic equation:
The field can be obtained from the following relations:
Boundary Conditions
For the problem under consideration, the following boundary conditions are appropriate:
- Axis condition:
- Remote boundary condition (field decays):
The weak form will have a different appearance in this case, but after the variable substitution, the form reduces to that obtained above.
Finite Element Mesh
When constructing the finite element mesh, several important considerations must be addressed:
- The domain must be partitioned into multiple physical groups;
- The mesh refinement in the solenoid axis region must be significantly higher than outside the solenoid.
We use the open-source GMSH package for mesh generation.

Numerical Simulation
To solve the equation on the constructed mesh, we use the FEniCS computational platform for solving partial differential equations via the finite element method.
Weak Form Formulation
We introduce a test function , where (square-integrable functions with square-integrable gradient and zero value on the Dirichlet boundary).
Multiplying the original equation by
and integrating over the domain
Using Green’s formula and accounting for the zero value of the test function on the domain boundary, we obtain the weak form equation:
Note that when deriving the three-dimensional axisymmetric case, the weight appears:
After integrating over :
Basis
To approximate the function , and consequently , we use a first-order continuous Galerkin functional space, which means applying piecewise-linear continuous basis functions on triangular elements.
Considering the form of the equation for the longitudinal field component
numerical computation requires excluding the axis itself: . This can be achieved in two ways:
- Use a zeroth-order discontinuous Galerkin space to approximate the field, i.e., describe the solution with piecewise-constant functions on each finite element.
- When computing the field, exclude elements located on the axis. In this case, the same basis used for approximating the vector potential can be used to approximate the field.
For the current problem, the first variant was chosen since the mesh in the axis region is sufficiently fine, meaning piecewise-constant functions will describe the field with adequate accuracy. Additionally, the first approach does not require additional modifications to the approximation algorithm, significantly simplifying the final solution.
Software Implementation
When programmatically describing the variational form, we must account for the variation of physical parameters within the computational domain. For this purpose, each parameter (magnetic permeability and current) will be defined as piecewise-constant functions:
J = fem.Function(Q)
J.x.array[:] = 0.0
J.x.array[nbsn] = fem.Constant(data.mesh, (nbsn_n * nbsn_i) / nbsn_s)
J.x.array[nbti] = fem.Constant(data.mesh, (nbti_n * nbti_i) / nbti_s)
J.x.array[comp] = fem.Constant(data.mesh, (comp_n * comp_i) / comp_s)
mu0 = 4 * np.pi * 1e-7
mu = fem.Function(Q)
mu.x.array[air] = fem.Constant(data.mesh, mu0)
mu.x.array[iron] = fem.Constant(data.mesh, mu0 * 1000.0)
mu.x.array[nbsn] = fem.Constant(data.mesh, mu0)
mu.x.array[nbti] = fem.Constant(data.mesh, mu0)
mu.x.array[comp] = fem.Constant(data.mesh, mu0)
where is the zeroth-order discontinuous Galerkin space:
Q = fem.functionspace(data.mesh, ('DG', 0))
The variational form, in this case, takes the simplest form:
u = ufl.TrialFunction(V)
v = ufl.TestFunction(V)
a = (1.0 / (mu*r)) * ufl.dot(ufl.grad(u), ufl.grad(v)) * ufl.dx
L = J * v * ufl.dx
where is the first-order continuous Galerkin functional space:
V = fem.functionspace(data.mesh, ('CG', 1))
The distribution of the longitudinal component is interpolated onto the space :
Bz = fem.Function(Q)
Bz.interpolate(fem.Expression((1.0 / r) * ufl.grad(uh)[1],
Q.element.interpolation_points))
To compute the integral of the longitudinal component along the solenoid axis, we must declare a measure that includes first-order elements (line segments) located on the axis. In our case, such elements belong to the 8th physical group (this group was defined using GMSH during mesh generation). The integral is then computed as follows:
dz = ufl.Measure("ds", domain=data.mesh, subdomain_data=data.facet_tags)
I = fem.assemble_scalar(fem.form(Bz * dz(8)))
Result
As a result of measuring the magnetic field distribution, the integral of the longitudinal component on the solenoid axis is obtained:
Vector Potential
The figure below shows the distribution of the r-weighted vector potential value :

Longitudinal Component of Magnetic Flux Density
The following figure shows the distribution of the longitudinal component of magnetic flux density :

Field distribution along the axis:

Verification
To verify the correctness of the obtained result, we present the residual norm of the weak form:
Additionally, we verify the correctness of global physical integrals, specifically the magnetic energy value (field method)
and compare it with the magnetic energy computed via the vector potential (source method)
After reducing the above expressions to cylindrical coordinates, we obtain