Maxwell equations in 3D — patched Nédélec-II / BDM1 example
Why a new Maxwell example?
The wave tutorials The wave equation — 2A: conservative anisotropic membrane and The wave equation — 2C: co-energy and localized damping work in two spatial dimensions. This is an intentionally tiny genuine 3D test: a homogeneous sphere, just two vector unknowns, no sources, no feedback controllers, and four weak-form bricks. It exercises the corrected intrinsic vector finite elements in the pinned SCRIMP GetFEM 5.5 image, not ordinary componentwise CG vector elements.
This example is new, independent of the published
COMPEL_2025/Maxwell_2D.py research script (which is
not modified), and of the 2D Nédélec-independent
wave benchmark.
A normalized Maxwell system
Let \(\Omega\) be the unit ball in \(\mathbb R^3\), filled with a homogeneous, isotropic, lossless material with dimensionless \(\varepsilon=\mu=1\). The electric field \(E\) and the magnetic induction \(B\) satisfy
without free currents or sources. Initially,
The electric field has nonzero curl and zero divergence initially. It is an exact low-order edge-element-type polynomial and excites a nontrivial magnetic field.
The true 3D domain and both co-energy/state declarations come directly from the executable:
model.set_domain(S.Domain("Ball", {"R": 1., "h": float(mesh_size)}))
if model.domain.get_dim()[0] != 3:
raise RuntimeError("Maxwell requires a genuine 3D volume mesh")
E = S.State("E", "Electric field", "vector-field")
B = S.State("B", "Magnetic induction", "vector-field")
model.add_state(E)
model.add_state(B)
model.add_costate(S.CoState("e_E", "Electric field", E, substituted=True))
model.add_costate(S.CoState("e_B", "Magnetic induction", B, substituted=True))
The coupling uses the homogeneous natural boundary closure of the weak form, namely zero magnetic tangential boundary work, not an explicitly imposed electric PEC trace and not a driven port. The discrete model closes the boundary power balance by construction. This small demonstration does not claim strong boundary-trace or electromagnetic eigenmode accuracy.
Compatible 3D spaces and their GetFEM patches
We use the SCRIMP-patched pair on genuine tetrahedra:
On each tetrahedron, both fields have local polynomial shape functions in \([P_1]^3\); the Nédélec-II edge DOFs impose tangential continuity, while BDM1 face DOFs impose normal continuity. In particular \(\operatorname{curl} E_h\) is piecewise constant and belongs to the divergence-free subspace of BDM1, compatible with Maxwell’s magnetic Gauss law.
Important distinction: the original accepted
baseline at source commit daac18cb used
GetFEM’s built-in lowest Nédélec
FEM_NEDELEC(3) with built-in RT0. It
did not exercise SCRIMP’s new element patches.
The current tutorial now explicitly uses
FEM_NEDELEC2(3,1) (patch 0004) and
tetrahedral FEM_BDMK(3,1) (patch 0001).
These FE names use the new SCRIMP shortcuts
S.FEM("E", 1, "NED2") and
S.FEM("B", 1, "BDM"). Additional
shortcuts NED1 / NEDELEC1 and
NED2 / NEDELEC2 are mapped by
scrimp/fem.py to the corresponding
GetFEM constructors. The number in
NED1 or NED2 is the family
(1st/2nd kind), while the numeric argument
is the polynomial order k. Patch 0004
supports only k=1 or 2.
# Nedelec0/RT0. NED2 k=1 -> FEM_NEDELEC2(3,1) (patch 0004),
# BDM k=1 -> FEM_BDMK(3,1) (tetrahedral DoF patch 0001).
# curl([P1]^3) is constant and is contained in BDM1;
# exact div(curl(E)) = 0 is preserved by the mass equation.
fem_E = S.FEM("E", 1, "NED2")
fem_B = S.FEM("B", 1, "BDM")
# S.FEM has a legacy silent CG fallback on native AssertionError.
# Retain these exact objects to detect it after registration.
for fem, expected_type, expected_order in (
(fem_E, "NED2", 1),
(fem_B, "BDM", 1),
):
model.add_FEM(fem)
assert_patched_intrinsic_fem(fem, expected_type, expected_order)
A strict post-registration guard retains both
original S.FEM objects and verifies that
their type and order are unchanged after
DPHS.add_FEM(), and that the actual GetFEM
MeshFem has vector dimension 3 and
nonzero degrees of freedom. This is important:
SCRIMP’s existing FEM adapter mutates the
original type/order to CG/1 on GetFEM’s
AssertionError fallback. A silent
replacement is thus explicitly detected,
without relying on the Python binding’s
version-dependent MeshFem.fem() layout.
This runtime guard is not yet a complete
proof of Maxwell numerical correctness.
A skew-adjoint discrete Maxwell interconnection
The weak formulation is deliberately minimal:
The GetFEM generic weak-form language does
not supply a portable built-in 3D Curl in
this image. The canonical example defines
the operator explicitly from the 3x3 gradient
tensor, without imposing an ad hoc
stencil or swapping the curl orientation:
CURL3 = (
"[Grad(v)(3,2)-Grad(v)(2,3);"
"Grad(v)(1,3)-Grad(v)(3,1);"
"Grad(v)(2,1)-Grad(v)(1,2)]"
)
There are only four variational bricks: two mass blocks and the two mutually opposite curl couplings. They are skew-adjoint in the discrete GetFEM mass inner products.
for brick in (
S.Brick("M_E", "E.Test_E", [1], dt=True, position="flow"),
S.Brick("M_B", "B.Test_B", [1], dt=True, position="flow"),
S.Brick("C^T", "B.Curl3(Test_E)", [1], position="effort"),
S.Brick("-C", "-Curl3(E).Test_B", [1], position="effort"),
):
model.add_brick(brick)
The original electromagnetic Hamiltonian is
The semidiscrete identity follows by
testing the first equation with E_h
and the second with B_h:
The initial data and CN integration are explicitly defined in the runnable source, including the absence of any unnecessary algebraic DAE projection:
# zero magnetic field; curl E=[0,0,2] triggers nontrivial dynamics.
model.set_initial_value("E", "[-y, x, 0.]")
model.set_initial_value("B", "[0., 0., 0.]")
model.set_time_scheme(
# Both states carry a positive mass: this is an ODE, NOT a DAE.
# The algebraic initializer requires algebraic unknowns;
# a pseudo-TS or artificial DAE spin-up would be wrong here.
init_step=False,
ts_type="cn", ts_adapt_type="none",
ts_exact_final_time="matchstep",
t_0=0., t_f=float(final_time),
dt=float(time_step), dt_save=float(time_step),
ksp_type="gmres", pc_type="lu",
pc_factor_mat_solver_type=factor_solver,
)
model.solve()
The original two positive electromagnetic energy terms are likewise the canonical GetFEM Hamiltonian, not recomputed from an invented displacement field:
model.hamiltonian.set_name("3D electromagnetic energy")
model.hamiltonian.add_term(S.Term("Electric", "0.5*E.E", [1]))
model.hamiltonian.add_term(S.Term("Magnetic", "0.5*B.B", [1]))
return model
The fixed Crank–Nicolson scheme has the corresponding exact quadratic discrete identity:
Both variables are differential, so there is no algebraic DAE initial projection or pseudo-time spin-up. Initial data are projected into their exact native finite-element spaces.
How to run and qualify this 3D example
We separate a source contract from
real native numerical acceptance.
The qualification runner uses the same
pinned GetFEM/PETSc/MUMPS Docker image
as the 2D examples. It checks
10 fixed CN steps at h=0.7,
dt=0.02, t_f=0.2,
on MPI 1 and MPI 2:
cd ~/Simulations/scrimp
git pull --ff-only
conda activate scrimp
SCRIMP_DOCKER_NO_SUDO=1 \
SCRIMP_V130_DAE_IMAGE=scrimp-mpi:v1.3.0-rc3 \
bash scripts/run-v130-maxwell3d-pilot.sh
The runner will only print
PASS_MAXWELL3D_MUMPS_MPI1_MPI2 if all
native checks succeed. It saves even
failed traces to
sandbox/outputs/v130-maxwell3d-*.zip.
The physical gates include the
presence of a genuine 3D mesh,
real patched Nédélec-II/BDM1 spaces, exact ten-step
fixed CN integration, positive initial
electromagnetic energy, nontrivial magnetic
excitation, and agreement between GetFEM
Hamiltonian values and independent
electric/magnetic volume quadratures.
Every-step and cumulative energy defects
must be below 1e-9 times the
physical energy scale. All MPI rank traces
and MPI1/MPI2 results are compared.
The divergence of B is independently
measured by GetFEM’s squared L2 norm
and checked against the compatible
discrete Gauss law. Its initial value is
zero and, for the compatible Nédélec-II k1
and BDM1 spaces, the discrete curl maps into
the divergence-free BDM subspace. This is an
actual additional acceptance gate,
not a claim of convergence of all
Maxwell constraints. The electric Gauss
law and electromagnetic boundary-mode
accuracy are outside this minimal pilot.
After a native PASS, the archive contains
true complete FE histories (rank*.npz),
original energy/diagnostic values, JSON
acceptance metadata, and two genuine
3D ParaView PVD time series for E
and B (11 VTU snapshots each).
Open mumps_mpi1/pv/E/E.pvd and
mumps_mpi1/pv/B/B.pvd in ParaView;
view the 3D vectors with a cut plane,
glyphs, or streamlines.
Native patched Nédélec-II / BDM1 qualification — PASS, 25 November 2026
The patched pair, not just the historical native-element baseline,
has now passed the complete native Maxwell 3D pilot.
The original archive is
v130-maxwell3d-3687b11e-gSQ8jeC3.zip,
source
3687b11e473813c103cd4e9c02f82812677853d7,
Docker scrimp-mpi:v1.3.0-rc3.
The summary.json status is
PASS_MAXWELL3D_MUMPS_MPI1_MPI2,
with an empty error list.
Both MPI configurations used genuine
FEM_NEDELEC2(3,1) for E
and FEM_BDMK(3,1) for B.
Check |
MUMPS MPI1 |
MUMPS MPI2 |
|---|---|---|
Tetrahedra / VTK points |
110 / 58 |
110 / 58 |
Nédélec-II k1 |
444 |
444 |
BDM1 |
825 |
825 |
Total FE DOFs |
1,269 |
1,269 |
CN steps / physical gates |
10/10, 9/9 PASS |
10/10, 9/9 PASS |
Maximum cumulative energy defect |
|
|
Maximum L2 norm of div(B) |
|
|
Original native VTU and PVD |
22 VTU, 2 PVD |
22 VTU, 2 PVD |
Automatic PNG/SVG/GIF |
PASS |
PASS |
At final time, original GetFEM quadratures
give
H_E(0.2)=0.436003804787049
and
H_B(0.2)=0.25824828616211315
for MPI1. The total electromagnetic
Hamiltonian is conserved with a maximum
defect 4.11e-15, while about
37.20% of the initial electric energy
is stored magnetically at t=0.2.
The independent GetFEM magnetic-divergence
integral \(\int_{\Omega}(\operatorname{div} B)^2\,\mathrm dx\) remains
at most 4.2153e-28 on MPI1.
The maximum coefficient difference between
full MPI1 and MPI2 FE histories
(11 times, 1,269 unknowns) is
2.1094237467877974e-15.
Each MPI2 rank saved an identical
trajectory, with its SHA256 verified.
All five graphics are generated from
the same run by
examples/maxwell_3d.py --export,
including the 11-frame native magnetic
GIF. The integrated renderer is
therefore qualified in MPI1 and MPI2,
not just source-tested. The true vector
VTU exports and original time samples
have been independently inspected.
The earlier source commit daac18cb
was a valid separate baseline using
GetFEM native Nédélec0/RT0 (497 DOFs),
not a test of either patched family.
Neither the new or the old qualification
establishes mesh/time convergence,
electric Gauss-law validity, explicit PEC
boundary conditions, cavity eigenmodes,
or SuperLU_DIST acceptance.
Figures and animation generated by the example itself
The same Python executable now creates its
own scientific figures and animation whenever
--export --output /artifacts is requested.
No separate notebook, rendering script or
vtk Python package is needed: the existing
matplotlib stack and the standard library
read the original GetFEM 3D VTU/PVD.
The energy curves are drawn from the
independently assembled native GetFEM
H_E, H_B and H arrays, not from
resampled nodal magnitudes.
For a complete run:
python -m examples.maxwell_3d --check --export --output ./maxwell_results
The output folder contains:
pv/E/E.pvdandpv/B/B.pvd: original GetFEM vector time series, with one native VTU per accepted CN state.visuals/maxwell3d_echange_energie.pngand.svg: electric, magnetic and total Hamiltonian over the original FE time samples.visuals/maxwell3d_vecteurs_E_tfinal.pngandmaxwell3d_vecteurs_B_tfinal.png: 3D final-time arrows at the authentic exported VTK nodal coordinates.visuals/maxwell3d_B_3D_animation.gif: all saved states of the true magnetic induction, with fixed camera and fixed vector scale (including the initially zero field).visuals/provenance.jsonandREADME.txt: original FE trajectory SHA256, true tetrahedral/point counts, number of frames and scientific rendering caveats.
Important numerical distinction: the VTK arrows are visualizations of the native GetFEM vector field values at nodes, not the edge or face degrees of freedom of the Nédélec-II/BDM1 spaces. The mesh outline is extracted from the true boundary faces of the tetrahedra; no synthetic field, reconstructed displacement or time interpolation is used.
The ParaView exports still involve all MPI ranks, but only rank 0 creates PNG/SVG/GIF files. The native pilot verifies the generated files, the entire GIF frame count and provenance against the original FE states; any rendering failure is retained as an explicit unqualified pilot rather than hidden.
Qualification scope: the original
Nédélec0/RT0 physics baseline passed
at daac18cb. Both the current
patched Nédélec-II/BDM1 model and its
integrated plotting passed separately
at 3687b11e on MPI1 and MPI2.
These are distinct archived proofs.
Historical baseline Maxwell 3D qualification — PASS, 25 November 2026
This historical PASS belongs exclusively to
the earlier built-in Nédélec0 + RT0 pair.
The current patched Nédélec-II k1 + BDM1
variant and its integrated visual outputs
were separately accepted in the native
archive v130-maxwell3d-3687b11e-gSQ8jeC3.zip.
Do not interchange their FE histories or DOF counts.
The earlier GetFEM/PETSc/MUMPS MPI1 and MPI2 pilot
passed nine out of nine physical gates,
using the original two-field Nédélec/RT0
model at h=0.7, dt=0.02, tf=0.2.
The full evidence is the archive
v130-maxwell3d-daac18cb-FCPngFrH.zip,
source commit
daac18cb36fbc404fcf5c4fe4f2f69121b2ee530,
Docker image scrimp-mpi:v1.3.0-rc3
(revision
1d6d0c90115213298047b28237a7f38087563a35).
Check |
MUMPS MPI1 |
MUMPS MPI2 |
|---|---|---|
Real tetrahedra |
110 |
110 |
Baseline DOFs, native Nédélec0 E / RT0 B |
222 / 275 |
222 / 275 |
CN steps accepted |
10/10 |
10/10 |
Scientific gates |
9/9 PASS |
9/9 PASS |
Hamiltonian initial |
|
|
Hamiltonian final |
|
|
Final magnetic energy |
|
|
Maximum cumulative energy defect |
|
|
Maximum L2 norm of magnetic divergence |
|
|
The two full FE state histories have
11 time samples x 497 coefficients.
The maximum absolute coefficient
difference MPI1/MPI2 is
4.440892098500626e-16. The MPI2 rank0
and rank1 binary histories are identical.
The saved state SHA256 values agree with
the original metadata.
Electromagnetic energy transfer: from
H_E(0)=0.6942520909491595, H_B(0)=0,
we obtain H_E(0.2)=0.4359826378118022
and H_B(0.2)=0.2582694531373567,
so 37.20% of the original energy moves
from electric to magnetic storage, with
no dissipative loss. The independent GetFEM
volume quadratures of electric and magnetic
energy add to H to within
5.55e-17 on MPI1; the full-step and
cumulative total Hamiltonian remains
constant at machine precision.
The magnetic Gauss law is checked by an
independent real GetFEM volume integral
of (div B)^2, with
||div B||_L2 <= 4.7e-15 over all saved
times. This is a tested constraint for
the discrete field, not a claim that
the electric Gauss law was tested.
VTK verification beyond XML: all 44 VTU files (2 fields x 11 times x 2 MPI configurations) were opened with a genuine VTK unstructured-grid reader. Every file contains 58 3D points, 110 native tetrahedral cells (VTK type 10) and a finite vector field with three components. Mesh geometry matches across the eleven times and the two MPI configurations. The 4 PVD catalogs contain the corresponding 11 timestamps. At final time the nodal magnetic-vector norm ranges from about 0.367 to 0.375.
Limitations: these results qualify only the original native Nédélec0/RT0 3D Maxwell port-Hamiltonian baseline at one mesh size and one time step. It establishes neither mesh/time convergence, electric Gauss-law accuracy, explicit PEC boundary traces, cavity-mode correctness nor a SuperLU_DIST qualification. The boundary remains the documented natural zero-work closure, not an imposed PEC wall.