Electrostatics & magnetostatics
Overview
Not every field is a displacement or a temperature. Two of the classic scalar problems of physics are the electric potential $\phi$ in a region of dielectric and the magnetic scalar potential $\psi$ in a region of permeable material. Both obey the same equation — Laplace's equation — so the solve(Physics(), …) pattern from Solving with physics carries over unchanged: name the physics, supply a material with the right coefficient, and read back a scalar field.
The shared structure is the point of the chapter. Electrostatics solves $\nabla \cdot (\varepsilon \nabla \phi) = 0$ for the potential in volts; magnetostatics solves $\nabla \cdot (\mu \nabla \psi) = 0$ for the magnetic scalar potential in amperes. Switch the marker and the coefficient, and the rest of the code is identical.
Electrostatics: the electric potential
A static electric field in a charge-free region is the gradient of a scalar potential, $\mathbf{E} = -\nabla\phi$, and the divergence of the displacement $\varepsilon\mathbf{E}$ vanishes. With a constant permittivity that collapses to Laplace's equation.
Rasmah.Electrostatics — Type
ElectrostaticsSolves for the electric potential $\phi$ from the material's permittivity $\varepsilon$, via the Laplace equation $\nabla \cdot (\varepsilon \nabla \phi) = 0$.
Theory
In a region with no free charge the electric potential obeys Laplace's equation: the divergence of the electric displacement $\mathbf{D} = \varepsilon \mathbf{E}$ is zero, and $\mathbf{E} = -\nabla \phi$. With a constant permittivity this is $\nabla^2 \phi = 0$ — the same scalar Poisson problem as steady heat conduction, with $\phi$ (volts) in the role of temperature and $\varepsilon$ in the role of conductivity. The electric field is the gradient of the solved potential.
Solving
solve(Electrostatics(), mesh, material; fixed, loads, …) returns the potential as a QuantityVector of dimension voltage. fixed = face => v pins the potential on a face; loads = face => q imposes a surface charge density.
The material supplies the permittivity $\varepsilon$ (here via relative_permittivity).
Magnetostatics: the scalar potential
Where there is no current, the magnetic field $\mathbf{H}$ is irrotational and so is the gradient of a scalar potential, $\mathbf{H} = -\nabla\psi$. The divergence-free flux $\mu\mathbf{H}$ then gives the same Laplace equation.
Rasmah.Magnetostatics — Type
MagnetostaticsSolves for the magnetic scalar potential $\psi$ from the material's permeability $\mu$, via $\nabla \cdot (\mu \nabla \psi) = 0$.
Theory
In a current-free region the magnetic field $\mathbf{H}$ is irrotational, so it is the gradient of a scalar potential, $\mathbf{H} = -\nabla \psi$. Combined with the divergence-free condition $\nabla \cdot \mathbf{B} = 0$ for the flux density $\mathbf{B} = \mu \mathbf{H}$, this gives Laplace's equation for $\psi$. It is the same scalar Poisson problem as electrostatics, with $\psi$ (amperes) in place of $\phi$ and $\mu$ in place of $\varepsilon$.
Solving
solve(Magnetostatics(), mesh, material; fixed, loads, …) returns the scalar potential as a QuantityVector of dimension current. fixed = face => v pins the potential on a face; loads = face => q imposes a magnetic source.
A worked example: a parallel-plate capacitor
A unit slab of dielectric between two plates held at $0$ and $1$ volt has the exact solution $\phi(x) = x$ — a linear ramp, hence a uniform field $E = -1$ V/m. Solve it and check the mid-plane potential is $0.5$:
m = tetrahedralize_box(1.0, 1.0, 1.0, 4, 4, 4)
left = nodes_in_box(m, [0.0, 0.0, 0.0], [0.0, 1.0, 1.0])
right = nodes_in_box(m, [1.0, 0.0, 0.0], [1.0, 1.0, 1.0])
mid = nodes_in_box(m, [0.5, 0.0, 0.0], [0.5, 1.0, 1.0])
dielectric = Material(youngs_modulus = 1e9, poisson_ratio = 0.3,
relative_permittivity = 4.0)
φ = solve(Electrostatics(), m, dielectric; fixed = (left => 0.0, right => 1.0))125-element QuantityVector{Float64}:
0.0 m^2·kg/(s^3·A)
0.24999999999999914 m^2·kg/(s^3·A)
0.49999999999999856 m^2·kg/(s^3·A)
0.7499999999999991 m^2·kg/(s^3·A)
1.0 m^2·kg/(s^3·A)
0.0 m^2·kg/(s^3·A)
0.249999999999999 m^2·kg/(s^3·A)
0.49999999999999833 m^2·kg/(s^3·A)
0.7499999999999989 m^2·kg/(s^3·A)
1.0 m^2·kg/(s^3·A)
⋮
0.249999999999999 m^2·kg/(s^3·A)
0.4999999999999984 m^2·kg/(s^3·A)
0.7499999999999989 m^2·kg/(s^3·A)
1.0 m^2·kg/(s^3·A)
0.0 m^2·kg/(s^3·A)
0.2499999999999992 m^2·kg/(s^3·A)
0.49999999999999867 m^2·kg/(s^3·A)
0.7499999999999992 m^2·kg/(s^3·A)
1.0 m^2·kg/(s^3·A)all(isapprox(φ[i], 0.5u"V"; atol = 1e-12) for i in mid.ids)trueColour the slab by potential — a smooth linear ramp across the gap:
vtk(m; field = φ, fieldname = "potential", edges = false)The magnetic case is the same solve with $\psi$ in amperes and the permeability in place of the permittivity:
iron = Material(youngs_modulus = 1e9, poisson_ratio = 0.3,
relative_permeability = 200.0)
ψ = solve(Magnetostatics(), m, iron; fixed = (left => 0.0, right => 1.0))125-element QuantityVector{Float64}:
0.0 A
0.25000000000000044 A
0.5000000000000007 A
0.7500000000000008 A
1.0 A
0.0 A
0.25000000000000056 A
0.500000000000001 A
0.750000000000001 A
1.0 A
⋮
0.2500000000000004 A
0.5000000000000009 A
0.7500000000000008 A
1.0 A
0.0 A
0.25000000000000033 A
0.5000000000000004 A
0.7500000000000006 A
1.0 Aall(isapprox(ψ[i], 0.5u"A"; atol = 1e-12) for i in mid.ids)trueThe two solutions are numerically identical — the only difference is the physical meaning of the field and the coefficient that feeds it.
Next steps
Electrostatics and magnetostatics are single scalar fields. When they couple to each other — or to displacement and temperature — see the coupled-multiphysics chapter, and for the time-dependent electromagnetic equations, the wave chapter.
