Module: src/fem/maxwell Version: 1.2 Date: 2026-08-14 Purpose: Core usage patterns for BELFEM's electromagnetic Maxwell module
Revision History:
⚠️ Critical mistakes to avoid:
The Mistake: building the magnetic kernel on a mesh with no edges.
Why it fails: the H-φ formulation places edge DOFs (edge_h) on conductor regions. A mesh read from file contains nodes and elements, but no edges. Edges must be created before the DOF manager can attach edge_h to them.
Correct approach: create the mesh edges before building the kernel and its field. Faces are needed only for higher-order face_h DOFs:
Mesh has no create_elements() or create_facets(); those belong to ProtoMesh. The factory performs this step through MaxwellFactory::create_edges_and_faces_on_mesh(). It restricts edge creation to conductor groups and creates faces only when max_element_order() > 1.
The Mistake:
Why it's wrong:
Correct approach:
There is no Kernel::solve(). The Controller drives the solve (§4.2).
Impact: Incomplete physics, wrong results.
The Mistake:
Why it fails: the thin-shell formulation scales matrices by thickness δ (see Alves et al. 2022b). A block's thickness defaults to BELFEM_QUIET_NAN (cl_Block.hpp), so a block without an explicit thickness has no usable value.
Correct approach: in the factory path, the deck's layers section supplies the thicknesses. ThinShellFactory then sets the domain type and thickness for each layer block. A hand-built mesh must set both:
Typical values:
The Mistake: running an HTS deck with the class-default nonlinear tolerance, 1e-6 (mRelativeEpsilonTarget in cl_FEM_Controller.hpp).
Why it's wrong (from Messe et al. 2023, Section 2.7):
Correct approach (from Messe et al. 2023): the tolerance is a deck key read by Controller::set_params(). The solver and controller have no C++ setter for it:
What the iteration does. SolverAlgorithm has three values: Direct, NewtonRaphson, and Picard. There is no separate quasi-Newton stage between them.
The deck key algorithm defaults to Picard, and the run stays on Picard. With algorithm : Newton, each timestep starts with Picard and switches to Newton-Raphson when the residual drops below tolerance switch (default 1e-4, mEpsilonSwitch). The code cites Messe et al. 2023, Eq. 13 for this handoff. The keys and their guidance are in the input file reference, §4.2 and §4.5.
Impact: Spurious current oscillations, non-physical hot spots, non-convergence.
The Mistake: constructing a MaxwellPostprocessor by hand with a type that does not match the domain — e.g. Conductor (no J/Jc) for an HTS block.
Why it's wrong:
Correct approach: don't construct postprocessors manually. The factory's create_postprocessors() step derives one postprocessor per domain from the topology domain types in the deck (cl_MaxwellFactory.cpp, create_postprocessors), so a thinshell over an HTS layer automatically gets ThinShellSuperConductor with J/Jc. If you must construct one, match the real signature — MaxwellPostprocessor( Kernel *, Map< id_t, DomainType >, Map< id_t, string >, MaxwellPostprocessorType, bool ) (cl_MaxwellPostprocessor.hpp) — and match the type to the domain.
Type mapping:
| Block DomainType | Postprocessor Type | Has J/Jc? |
|---|---|---|
| Air | Air | No |
| Ferro | Ferro | No |
| Conductor (metal) | Conductor | No |
| Conductor (HTS) | SuperConductor | Yes |
| ThinShell (metal) | ThinShellConductor | No |
| ThinShell (HTS) | ThinShellSuperConductor | Yes |
| Edge-coating wall (metal) | SideConnector | No |
The Pattern (from Messe et al. 2023):
BELFEM uses static condensation (NOT Lagrange multipliers) for interface coupling.
Why (Messe et al. 2023):
What you need to know:
If implementing custom interfaces:
The rule: quadrilateral and hexahedral elements in a Maxwell problem must be perfectly rectangular, meaning axis-aligned or rigidly rotated rectangles/bricks. Trapezoidal, sheared, or otherwise distorted quads/hexes silently break the edge-element convergence theory.
Why (Monk 2003, §6.1 and §8.2–8.3; Falk et al. 2011; Arnold et al. 2001/2002/2005):
What to do:
Full mechanism and literature trail: src/fem/interpolation/doc/nedelec.md, §6.6.
BELFEM is driven by a plain-text input.conf deck, read by the belfem executable from the working directory. The deck decides whether the run is magnetic-only or coupled h-ɸ/T. The complete key-by-key contract is the input file reference; the shipped decks under examples/ are working starting points. A minimal 3-D thin-shell deck looks like this:
Run it from the deck's directory:
The defaults this leaves in place — Picard iteration, BDF1 time stepping, Anderson off — are the validated baseline (Messe et al. 2023, §4); treat every departure as deliberate (see the input file reference, §4.5).
Problem: Electromagnetic field simulation in regions with:
Solution: Mixed formulation
Conductors (H-formulation, Messe et al. 2023, Eq. 6-8, Arsenault et al. 2023, Eq. 5-7):
Where:
The equation above assumes a conductor with constant permeability μ₀. The code also supports a variable-μ branch. Under Newton-Raphson, IWG_Maxwell::link_to_group binds h_newton_mu0 when the conductor material's mu is constant and h_newton_mu when it is not. Picard uses h_picard in both cases.
Air/Ferro (φ-formulation):
Where:
Weak form (conductor):
Where w = edge test functions (Nédélec H(curl) basis)
Weak form (air/ferro):
Where w = nodal test functions (Lagrange C⁰ basis)
| Domain | Primary Variable | DOF Type | Mesh Entity |
|---|---|---|---|
| Conductor | H (magnetic field) | edge_h (+ face_h when higher order) | Edges (+ faces) |
| Air | φ (scalar potential) | phi | Nodes |
| Buffer | φ (scalar potential) | phi (uses the Air DOF table) | Nodes |
| Ferro | φ (scalar potential) | phi | Nodes |
| ThinShell | H + φ (coupled) | edge_h + phi (from neighbors) | Facets |
Key insight (Arsenault et al. 2023):
| Formulation | BELFEM Choice | Why? |
|---|---|---|
| A-φ (vector potential) | ❌ NOT used | Requires gauge fixing, more DOFs |
| T-Ω (current potential) | ❌ NOT used | Limited to simply-connected regions |
| H-φ (BELFEM's choice) | ✅ USED | Natural for conductor/air split, no gauge |
References:
MaxwellFactory handles the complete workflow:
The built driver is src/executables/belfem.cpp. A custom driver follows the same shape. The excerpt below is its magnetic-only and fully coupled path:
belfem runs this loop when there is no thermal kernel or when tControl->is_fullycoupled() is true. A thermal run that is not fully coupled uses a segregated loop instead.
That loop calls initialize_magnetic() / solve_magnetic(). It then iterates initialize_thermal() / solve_thermal() until the thermal time catches up, and writes tExodusFile (<label>.e-s), iv_results.csv and memdump.hdf5, just as the loop above does. See belfem.cpp for the full branch.
There is no short manual equivalent of create_magnetic_kernel(). In addition to the kernel and field, it creates the cuts, thin shells, gauge pins, materials, and postprocessors.
MaxwellFactory::create_magnetic_kernel() (cl_MaxwellFactory.cpp) is the reference for the required order of operations. A custom setup must preserve the same constraints:
| Constraint | Reason in the code |
|---|---|
| Create edges (and faces for face_h) on the mesh before the kernel | §1.1; the factory does it in create_edges_and_faces_on_mesh() |
| Select the kernel's blocks in KernelParameters before constructing the Kernel | the constructor partitions the mesh over the selected blocks; the factory selects air, buffer, conductor, ferro and thin-shell blocks, and excludes coils |
| Pass block and sideset types with IWG::set_blocks( ids, types ) / IWG::set_sidesets( ids, types ) before Kernel::create_field() | create_field() calls IWG::initialize() immediately, and IWG_Maxwell::initialize() builds the per-block DOF tables from those types. select_blocks() stores IDs only and assigns no types. Factory: set_block_types_in_magnetic_equation() |
| Call DofManager::set_solver( SolverParameters ) before DofManager::initialize() | initialize() asserts "set solver first". The factory calls configure_solver() right after create_field() |
| Decide ownership explicitly | Kernel borrows its KernelParameters and its mesh unless claim_parameter_ownership() / claim_mesh_ownership() is called; the factory claims both. create_field() does not take ownership of the IWG |
The maxwell::FieldList class organizes DOFs by domain type:
Problem setup:
Resulting DOF structure:
DOF counts (example 10k element mesh):
Use higher-order when:
Avoid when:
There is no per-material kernel to call. The 26-variant h_metal/h_hts family this section once tabulated was collapsed: mt_maxwell_h.hpp exports iteration-scheme kernels only (h_picard, h_newton_mu0, h_newton_mu, h_ghost, h_side_connector*), and the material behavior — metal vs. HTS, power-law vs. piecewise resistivity, defects, temperature coupling — is resolved inside them through the Calculator's material interface (compute_rho, compute_mu, compute_drhodb, …).
Selection therefore happens in the deck, not in C++:
Temperature coupling follows from giving the deck a thermal solver section, which makes belfem select the coupled h-ɸ/T problem. See doc/input_file_reference.md §5 for every material key. Defects and the piecewise law are also deck keys: defect { file ; label ; } and resistivity type : piecewise. They are not kernel variants.
Problem: Imposing transport current I_transport through a conductor loop.
Traditional approach (wrong):
BELFEM approach (Alves et al. 2022b, Alves et al. 2024, Schnaubelt et al. 2023):
Factory handles automatically — the deck names the cut algorithm and the transport current, and the factory generates the cuts:
There is no public manual cut API. Cut generation runs inside create_magnetic_kernel() through the private MaxwellFactory::create_cuts().
On the master rank, it calls mesh::Topology::run(), then synchronize_maps(). It reads homology { algorithm } and passes the mesh, topology, and thin-shell data to a mesh::CutFactory. Its run() method produces the cut sidesets.
Worker ranks receive the maps through synchronize_maps(). Topology itself exposes run(), the group and map accessors, and synchronize_maps(). It has no cohomology or cut methods.
See: src/homology/doc/ for cohomology theory.
When modeling a fraction (half / quarter) of a magnet, each mirror plane carries one of two conditions. Which one applies is decided by how the current mirrors across the plane:
| Current across plane | Field on plane | Condition | BC needed |
|---|---|---|---|
| inverts (anti-symmetric source) | tangential — flux runs parallel | B·n = 0 ("magnetic wall") | none |
| preserved (symmetric source) | normal — flux crosses perpendicular | B×n = 0 | must be imposed |
Key point — the magnetic wall (anti-symmetry) needs no boundary condition. In the scalar-φ region the weak form ∫ ∇w · μ∇φ has B·n = 0 as its natural boundary condition, so an anti-symmetry plane is obtained for free simply by adding no term (deactivating the sideset). Only the flux-normal B×n = 0 symmetry plane is non-natural and must be actively enforced. That is why the module ships only mt_maxwell_symmetry.cpp (symmetry_phi, h_symmetry) with no anti-symmetry counterpart — none is required.
Example — cosθ dipole quadrant. The current is symmetric across the mid-plane (x-axis) and anti-symmetric across the pole plane (y-axis):
Implementation notes:
See Section 20 of ../../kernel/doc/dof_manager_usage_guide.md for full theory.
There is no thin-shell kernel. A shell block is assembled by the same h_picard / h_newton_mu0 / h_newton_mu kernels as a bulk conductor (mt_maxwell_h.cpp); Conductor and ThinShell share one case in IWG_Maxwell::link_to_group. What makes it a shell is the function-pointer dispatch bound at construction in calculator::MaxwellData (cl_FEM_Calculator.cpp, anchor tIsThinShell):
The normal part comes from the volume elements on either side through compute_hn (cl_FEM_Calculator.hpp): on a φ-region ( air, ferro ) the side's trace is -grad phi, on an h-conductor ( DomainType::Conductor, e.g. the solder annulus of corc_solder ) it is the conductor's own Nédélec trace E * q averaged over the facet rule ( compute_h_trace ); the two traces are averaged and the average is projected onto the facet normal:
Skipping that last line leaves an O(|H_t|) tangential contamination, the same order as the tape's own field. The routine is evaluated once per element, at k == 0, which is exact for flat linear shells and is guarded by an assert on element_is_linear().
Critical insight: The normal field is imposed from the surrounding air/ferro region; the tangential field is solved from edge DOFs.
A 3-D thin shell with a closed outer rim (a closed side curve, in the code) and no terminal on the rim is accepted as of 2026-10-08. For example, a tape can be fed through copper leads, with the terminals on bulk-conductor faces. The rim nodes remain single-valued, as required by the free-edge condition. Three limits apply:
The facet alignment, patch relation, and block-side guard in MaxwellFactory::fix_facet_masters run only in 3-D. In 2-D, the per-block element numbering of the mesh provides a uniform master side along the tape.
Postprocessors are created by the factory, not by the user: MaxwellFactory::create_postprocessors() pushes one MaxwellPostprocessor per domain kind onto the field's postprocessor list, deriving the type from the topology domain types. The controller runs them each saved timestep (run() / initialize() — the class interface has no separate process()-style entry points), and the results land as node fields on the mesh, which the controller writes into the Exodus results file:
The real constructor signature, for the rare case that a custom driver builds one directly (cl_MaxwellPostprocessor.hpp):
The types, from cl_MaxwellPostprocessor.hpp:
The factory selects them from the deck's topology section; a thinshell whose layer stack contains an HTS material gets ThinShellSuperConductor automatically.
Alongside the node fields, the contributing h-domain kernels accumulate each element's ohmic dissipation into one mesh-wide global. BELFEM writes it to the Exodus results file as the global variable dotQ:
dotQ is a power, not an energy. The dot is the point of the name: it is a rate, in watts, at one instant. An AC loss per cycle is its time integral, and nothing in BELFEM takes that integral — integrate the per-timestep values from the Exodus file downstream.
Scope. One scalar for the whole mesh. There is no per-element, per-block or per-domain breakdown, so a run cannot attribute loss separately to the tape, the stabilizer or the former.
Lifecycle. Accumulated per integration point, added to the global per element, then summed across ranks:
| Stage | Where |
|---|---|
| created, value 0 | MaxwellFactory::create_magnetic_kernel() — create_global_variable( "dotQ", 0 ) |
| zeroed before every assembly | Controller::reset_dotQ() |
| accumulated per element | save_dotQ() in mt_maxwell_h.hpp |
| summed over MPI ranks | Controller::collect_dotQ() — rank 0 collects and sums; no-op on one rank |
reset_dotQ() and collect_dotQ() bracket each compute_jacobian_and_rhs(). The value written for a timestep therefore comes from that timestep's last assembly; it is not an average over the nonlinear iterations.
Which kernels contribute. Five of the six h-kernels:
| Kernel | Contributes | Why |
|---|---|---|
| h_picard() | yes | volumetric rho \|j\|^2 |
| h_newton_mu0() / h_newton_mu() | yes | same term in the Newton branches |
| h_side_connector() / h_side_connector_newton() | yes | edge-coating wall elements |
| h_ghost() | no | its rho enters a Nitsche stabilization coefficient, not a dissipation term — a penalty is not a loss |
The phi-domain kernels (mt_maxwell_phi.cpp) contribute nothing, correctly: that domain is non-conducting.
Note — the resistivity clamp, and why it does not bite. The kernels obtain rho through MaxwellData::compute_rho(), which clamps it to [ gRhoMin, gRhoMax ] and supplies the same clamped value to every consumer (stiffness, Joule source, element mean). The defaults are 0 and 1e10 Ohm*m, set in Communicator::set_globals(), whose own comment calls them a no-op — and the material layer guarantees it. All three HTS laws put the power-law channel in parallel with the normal-state channel: rho_powerlaw() and rho_riva() return the parallel combination explicitly, and rho_piecewise() returns the unbounded power-law branch only below its flux-flow knee, rhon above it. So rho <= rhon always, however far over-critical an iterate drives |j|. A deep Newton excursion cannot reach gRhoMax — the parallel combination forbids it.
This is deliberate, not a coincidence of magnitudes. The riva channel is evaluated in log10 space behind an explicit overflow early-out, and the source says why: "past this cap 1/ρPL vanishes to machine precision against any physical ρn — the caller takes the fully-normal branch" (powerlaws.hpp, grep that sentence). Past the cap the helper returns false and rho_riva() returns rhon outright. rho_powerlaw() reaches the same place by arithmetic: if rhoPL overflows, 1/(1/rhon + 1/rhoPL) tends to rhon.
The upper bound can therefore only fire if a material's own normal-state rho( T ) exceeds 1e10 Ohm*m — no shipped material does, though a user plugin material could — or if an executable narrows the window, which none in this tree does; a deck cannot touch it at all. The lower bound sits at zero, so it can only trip on a negative resistivity, which is a material defect worth surfacing rather than a guard doing its job.
The consequence for dotQ is a real but latent one: where the clamp does fire, dissipation is silently capped and dotQ becomes a lower bound. The calculator records that it happened (rho_clamped()), but the flag is not propagated to dotQ, so a reported value carries no indication either way. With stock materials and stock bounds, treat dotQ as unclamped.
No measured cost breakdown for the Maxwell module is published here. The shares of factorization, assembly, and postprocessing depend on the deck, so measure them on the deck in question.
The controller's timestep footer reports iteration time and, where measured, postprocessing and eigenvalue-analysis times.
1. Solver selection (from Messe et al. 2023): the deck selects the solver. There is no runtime fallback switch:
Avoid iterative solvers (GMRES, BiCGSTAB) for HTS work. The E-J nonlinearity ill-conditions the system, so direct solvers are the validated path.
2. Material evaluation happens inside the calculator. The kernels never call a material directly. They obtain rho through MaxwellData::compute_rho(), which is bound per group to one of these paths (cl_FEM_Calculator.hpp):
Material::rho( T, B, beta ) is not the E-J law. On a superconductor such as YBCO (a Metal subclass), it returns the Kohler normal-state value, not the resistivity assembled by the kernels. MaxwellData evaluates these quantities at each integration point and caches intermediate values (b, |j|, beta) through its is_current() flags.
3. Reuse calculators: a Calculator is created once per group (its constructors take a Group *), and the element loop relinks it. This is what IWG_Maxwell::compute_mkf() does:
4. MPI partitioning: partitioning is automatic. Nothing in src/ calls Mesh::partition().
In the factory path, rank 0 reads the mesh (new Mesh( path, 0, false, false )), broadcasts the mesh dimension, and each worker creates an empty new Mesh( dim, 0 ). The Kernel constructor then partitions on the master (Kernel::partition_mesh(), which calls graph::metis_partition) and runs the mesh::Distributor on every rank. See "Mesh Distribution (MPI)" in the mesh usage guide (src/mesh/doc/mesh_usage_guide.md).
Maxwell module is NOT thread-safe:
MPI usage:
Run with mpirun -np <ranks> belfem — Open MPI only (see MPI support).
New material behavior goes into the material classes (src/physics/materials/) and the Calculator's material interface — not into new kernels; the iteration-scheme kernels in mt_maxwell_h.hpp are material-agnostic. The material side is documented in src/physics/materials/doc/materials_usage_guide.md, and the HTS resistivity laws in src/physics/materials/doc/resistivity_laws.md.
Use manufactured solutions:
Primary references (literature/papers/fem):
Last updated: 2026-10-22