Demag dynamic solver

Z_sim_dynamic_stereo_demag subclasses Z_sim_dynamic_stereo_base and adds mixed finite elements for (q_A, q_B, \varphi) plus magnetostatics/BEM.

Responsibilities

  • Build mixed spaces and the weak form in Stereographic formulation

  • Couple to Z_sim_magnetostatic and C++ BEM (set_BEMcpp)

  • Operator-split SNES per timestep on (q_A, q_B, \varphi) with field-split preconditioning

  • init_dynamic, write_checkpoint, demag-specific output targets (see Output targets)

Typical call sequence

set_mesh → set_materials → set_external_field → set_magnetostatics → set_BEMcpp → initialize q_A/q_B → init_dynamic → solve_problem.

Configuration keys: Configuration reference. Workflow example: Getting started.

class Zmag_bins.Zmag_dynamic_stereo_demag.Z_sim_dynamic_stereo_demag(args_init_sim: dict)[source]

Bases: Z_sim_dynamic_stereo_base

Stereographic LLG with mixed unknowns (q_A, q_B, phi) and magnetostatics.

Inherits the adaptive time loop from Z_sim_dynamic_stereo_base and adds Fredkin–Koehler magnetostatics plus optional C++ BEM acceleration.

__init__(args_init_sim: dict) → None[source]

Initialize demag solver configuration and stereographic chart basis.

Parameters:

args_init_sim (dict) – Requires alpha, energy_terms (including demag), NeumannBC, printout, path_dirs. Optional: projection_pole, sigma2_floor.

Raises:

ValueError – If demag is missing from energy_terms.

init_dynamic(args_init_dyn: dict)[source]

Configure time integration, SNES, BDF history, ramps, and I/O.

Call after mesh setup, materials, chart initialization, magnetostatics, and BEM assembly.

Parameters:

args_init_dyn (dict) – Requires t_start, dt, step_start, step_end, first_run, checkpoint_every, write_target, and cfl_settings. See Configuration reference in the manual.

Raises:
  • ValueError – On invalid configuration keys or values.

  • FileNotFoundError – If required path_dirs entries are missing.

  • KeyError – If a required path_dirs key is absent.

compute_energy()[source]

Evaluate the atlas-weighted micromagnetic energy.

Returns:

  • numpy.ndarray

  • [exchange, uniaxial, cubic, demag, zeeman, total] (inactive terms are zero).

solve_weak_form(max_outer_override=None)[source]

Advance one timestep: BDF shift, atlas update, outer split, and SNES on (q_A,q_B,phi).

Called from solve_problem() inside each retry attempt. Residual/thermo/closure gates run in the base class after this returns.

Parameters:

max_outer_override (int, optional) – Cap operator-split iterations.

Returns:

Defects and convergence metadata (iters, q_defect, phi_defect, …).

Return type:

dict

solve_magnetostatics(step)[source]

Restart hook: optionally warm-start demag from checkpoint, then reconcile.

Parameters:

step (int) – Current step; triggers reload when step == step_start on restart.

Notes

Checkpoint phi matches the writer’s BEM/partition. After remesh the live BEM differs, so any loaded phi is only a warm start and is immediately re-equilibrated via _refresh_demag_state_from_current_q(). When init_dynamic already reconciled after atlas restore, this hook skips the redundant load.

open_output(target: str, filename: str)[source]

Open BP (VTX) and optional XDMF writers for a named output field.

Parameters:
  • target (str) – One of mag, qA, qB, phi, demag, heff, atlas masks/weights, etc. (see FEATURE_MATRIX.md).

  • filename (str) – Base path for .bp output files.

close_output(target: str)[source]

Close VTX/XDMF writers opened by open_output() for target.

write_output(target: str)[source]

Update and write the field bundle for target at time self.t.

Populates derived fields (mag, demag, atlas masks, etc.) then writes to BP/XDMF writers registered for target.

write_checkpoint(filename)[source]

Write ADIOS checkpoint plus npz chart histories.

Parameters:

filename (str) – Path ending in .bp; npz companions use the same stem.

write_phi1_boundary(filename)[source]

Export boundary potential phi1 (Neumann data + BEM) to a BP checkpoint.

Parameters:

filename (str)

write_xdmf_checkpoint(target: str, filename: str)[source]

Export a single-time XDMF snapshot.

Parameters:
  • target (str) – mag, phi, demag, heff, chart_ind, q_norm, qA, qB, etc.

  • filename (str) – Output .xdmf path.

set_magnetostatics(interfaces: list[dict], surface_tag: int)[source]

Wire the magnetostatic helper and interface facet measures.

Parameters:
  • interfaces (list[dict]) – Interface definitions with tag keys.

  • surface_tag (int) – Exterior boundary tag for Dirichlet data on \(\varphi\).

set_BEMcpp(BEM_dir: str, cpp_backend: str | None = None)[source]

Assemble the BEM operator for the Laplace subproblem.

Parameters:
  • BEM_dir (str) – BEM data directory for bem_assembler.bem_assembler.BEMAssembler.

  • cpp_backend (str, optional) – Optional backend preset.

read_checkpoint_demag(filename)[source]

Restore magnetostatic potential and demagnetizing field from checkpoint.

Parameters:

filename (str)

Returns:

(phi, h_demag) with h_demag = -grad(phi).

Return type:

tuple[dolfinx.fem.Function, dolfinx.fem.Function]

read_checkpoint_mesh(mpi_comm, filename)[source]

Restore distributed mesh and meshtags from an ADIOS BP file.

Returns:

(domain, boundary_facets, cell_tags, facet_tags).

Return type:

tuple

read_checkpoint_time(run_dir, filename)[source]

Parse energies log and locate latest checkpoint_timestep_*.bp.

Returns:

(step_start, t_start, dt).

Return type:

tuple[int, float, float]

See also

Module overview: Zmag_bins.Zmag_dynamic_stereo_demag