A Julia package for computing magnetostatic fields from current sources or potentials.
Magnetostatics.jl provides solvers and analytical models for computing magnetic fields produced by steady-state current distributions or potentials. The package includes:
- Biot-Savart solver — numerical integration of the Biot-Savart law for arbitrary wire geometries.
- FFT solver — spectral method for computing B from a volumetric current density J on a uniform grid with periodic boundaries.
- Vector Potential solver — computes the magnetic vector potential A for wires, current loops, and dipoles.
- Magnetosphere models — planetary dipoles, magnetopause shielding, magnetotail, and interplanetary magnetic field (IMF) components.
- Tokamaks — analytical magnetic field models for toroidal/poloidal coils, central solenoids, and q-profile based configurations.
- Analytical fields — closed-form models for Harris current sheets (asymmetric, force-free), magnetic dipoles, mirrors, pinches, and circular current loops.
To install Magnetostatics.jl, run the following command in the Julia REPL:
using Pkg
Pkg.add("Magnetostatics")using Magnetostatics
# Create a circular current loop and discretize it into wire segments
loop = CurrentLoop(1.0, 1.0, [0.0, 0.0, 0.0], [0.0, 0.0, 1.0])
wire = discretize_loop(loop, 100)
# Compute B at a point using the Biot-Savart solver
B = solve(BiotSavart(), wire, [0.0, 0.0, 0.5])
# Compare with the analytical solution
B_exact = getB_loop([0.0, 0.0, 0.5], loop)For more detailed information on the API and usage, please refer to the documentation.