Theory and Algorithms

This section provides a theoretical background on the computational methods used in the em-app package. It covers the core algorithm for magnetic field calculation, the role of the mtflib library in multipole expansions, and the fundamental principles from Maxwell’s equations.

Core Algorithm: The Biot-Savart Law

The primary method for calculating the magnetic field in this package is the Biot-Savart law. This law describes the magnetic field B generated by a constant electric current. For a one-dimensional wire carrying a current I, the magnetic field at a point r is given by the line integral:

\[\mathbf{B}(\mathbf{r}) = \frac{\mu_0 I}{4\pi} \int_C \frac{d\mathbf{l}' \times (\mathbf{r} - \mathbf{r}')}{|\mathbf{r} - \mathbf{r}'|^3}\]

where: - \(\mu_0\) is the permeability of free space. - \(I\) is the current. - \(d\mathbf{l}'\) is a vector representing an infinitesimal segment of the wire. - \(\mathbf{r}'\) is the position vector of the segment \(d\mathbf{l}'\). - \(\mathbf{r}\) is the point where the magnetic field is being calculated.

In em-app, complex current sources (like RingCoil or RectangularCoil) are discretized into a finite number of straight-line segments. The total magnetic field is then calculated by summing the contributions from each segment, approximating the integral numerically.

Multipole Expansion using mtflib

For points far from the source, calculating the magnetic field using the full Biot-Savart law can be computationally expensive. In these cases, a multipole expansion provides an accurate and efficient approximation. This expansion represents the complex magnetic field as a sum of simpler fields arising from multipoles (monopole, dipole, quadrupole, etc.).

The em-app package leverages the mtflib library to facilitate these calculations. mtflib allows for the representation of physical quantities, such as vector components and positions, as multivariate Taylor series objects. When operations are performed on these objects, the result is also a Taylor series.

This has two main advantages:

  1. Automatic Differentiation: The derivatives of the field (gradient, divergence, curl) can be computed automatically and with high precision.

  2. Field Approximation: The Taylor series itself is a power series representation of the field around a certain point. This is closely related to the multipole expansion, allowing for efficient field calculations at a distance.

By initializing calculations with mtf.initialize_mtf(), users can compute not just the value of the magnetic field but also its spatial derivatives, which are essential for understanding the field’s local structure.

Maxwell’s Equations and Field Properties

The behavior of electric and magnetic fields is governed by Maxwell’s equations. In their differential form, they are:

  1. Gauss’s Law for Electricity: \(\nabla \cdot \mathbf{E} = \frac{\rho}{\varepsilon_0}\)

  2. Gauss’s Law for Magnetism: \(\nabla \cdot \mathbf{B} = 0\)

  3. Faraday’s Law of Induction: \(\nabla \times \mathbf{E} = -\frac{\partial \mathbf{B}}{\partial t}\)

  4. Ampère-Maxwell Law: \(\nabla \times \mathbf{B} = \mu_0 \left( \mathbf{J} + \varepsilon_0 \frac{\partial \mathbf{E}}{\partial t} \right)\)

From these fundamental equations, we can derive key properties of the magnetic field in magnetostatics (the study of steady currents).

### Divergence-Free Magnetic Field

In magnetostatics, we assume that the fields are not changing in time (\(\frac{\partial}{\partial t} = 0\)). Gauss’s Law for Magnetism, \(\nabla \cdot \mathbf{B} = 0\), holds universally. This means that the magnetic field is divergence-free.

Physically, this implies that there are no magnetic monopoles (isolated north or south poles). Magnetic field lines always form closed loops.

### Curl of the Magnetic Field

In magnetostatics, the Ampère-Maxwell Law simplifies to:

\[\nabla \times \mathbf{B} = \mu_0 \mathbf{J}\]

This equation states that the curl of the magnetic field is proportional to the current density J. The curl measures the “rotation” of the field at a point.

In a region of space where there are no current sources (\(\mathbf{J} = 0\)), the equation further simplifies to:

\[\nabla \times \mathbf{B} = 0\]

This means that in a source-free region, the magnetic field is curl-free. A curl-free vector field can be expressed as the gradient of a scalar potential, which simplifies many calculations. The em-app package allows for the direct computation of the curl and divergence of the field, enabling users to verify these fundamental properties.