Skip to content

Magnetostatics.jl

A Julia package for computing magnetostatic fields from current sources.

Overview

Magnetostatics.jl provides solvers and analytical models for computing magnetic fields produced by steady-state current distributions.

Methods

Analytical Models

Exact solutions for specific geometries:

  • HarrisSheet: Harris current sheet model (Bx(z)=B0tanh(z/L)).

  • AsymmetricHarrisSheet: Asymmetric current sheet (Bx(z)=B1+B22+B1B22tanh(z/L)).

  • ForceFreeHarrisSheet: Force-free sheet (Bx(z)=B0tanh(z/L), By(z)=B0sech(z/L)).

  • BifurcatedHarrisSheet: Double-peaked current sheet (Bx(z)=B02[tanh((zd)/L)+tanh((z+d)/L)]).

  • FadeevIsland: 2D magnetic island equilibrium (Ay(x,z)=B0Lln[cosh(z/L)+ϵcos(x/Lx)]).

  • Dipole: Magnetic dipole field.

  • CurrentLoop: Analytics for circular current loops using elliptic integrals.

  • getB_mirror: Two-coil magnetic mirror configuration.

  • getB_bottle: Magnetic bottle configuration (mirror + central coil).

  • getB_tokamak_coil: Tokamak field from 16 toroidal coils + plasma current.

  • getB_tokamak_profile: Tokamak field from safety factor q-profile.

  • getB_zpinch: Z-pinch wire field.

Numerical Solvers

General-purpose solvers for arbitrary geometries:

  • BiotSavart: Numerical integration of the Biot-Savart law for arbitrary wire geometries.

  • FFTSolver: Spectral method for computing B from a volumetric current density J on a uniform grid with periodic boundaries.

  • VectorPotential: Computes the magnetic vector potential A for wires, current loops, and dipoles.

  • PoissonSolver: Finite-difference Poisson solver (∇²A = −μ₀J) on a Cartesian grid with Dirichlet boundary conditions, supporting anisotropic grid spacing via LinearSolve.jl.

Quick Start

julia
using Magnetostatics
using StaticArrays

# Create a circular current loop and discretize it into wire segments
loop = CurrentLoop(1.0, 1.0, [0, 0, 0], [0, 0, 1])
wire = discretize_loop(loop, 100)

# Compute B at a point using the Biot-Savart solver
B = solve(BiotSavart(), wire, SVector(0.0, 0.0, 0.5))

# Compare with the analytical solution
B_exact = getB_loop(SVector(0.0, 0.0, 0.5), loop)

Contents