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_magnetostaticand C++ BEM (set_BEMcpp)Operator-split SNES per timestep on
(q_A, q_B, \varphi)with field-split preconditioninginit_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_baseStereographic LLG with mixed unknowns
(q_A, q_B, phi)and magnetostatics.Inherits the adaptive time loop from
Z_sim_dynamic_stereo_baseand 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(includingdemag),NeumannBC,printout,path_dirs. Optional:projection_pole,sigma2_floor.- Raises:
ValueError – If
demagis missing fromenergy_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, andcfl_settings. See Configuration reference in the manual.- Raises:
ValueError – On invalid configuration keys or values.
FileNotFoundError – If required
path_dirsentries are missing.KeyError – If a required
path_dirskey 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_starton restart.
Notes
Checkpoint
phimatches the writer’s BEM/partition. After remesh the live BEM differs, so any loadedphiis only a warm start and is immediately re-equilibrated via_refresh_demag_state_from_current_q(). Wheninit_dynamicalready 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
.bpoutput files.
- close_output(target: str)[source]¶
Close VTX/XDMF writers opened by
open_output()fortarget.
- write_output(target: str)[source]¶
Update and write the field bundle for
targetat timeself.t.Populates derived fields (
mag,demag, atlas masks, etc.) then writes to BP/XDMF writers registered fortarget.
- 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
.xdmfpath.
- set_magnetostatics(interfaces: list[dict], surface_tag: int)[source]¶
Wire the magnetostatic helper and interface facet measures.
- Parameters:
interfaces (list[dict]) – Interface definitions with
tagkeys.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)withh_demag = -grad(phi).- Return type:
tuple[dolfinx.fem.Function, dolfinx.fem.Function]
See also
Module overview: Zmag_bins.Zmag_dynamic_stereo_demag