Dynamic solver factory¶
Zmag_bins.Zmag_dynamic_stereo_solvers is the recommended entry point for
time-dependent stereographic LLG. It selects the implementation and exposes a uniform API
via attribute forwarding.
from Zmag_bins.Zmag_dynamic_stereo_solvers import create_stereo_solver
sim = create_stereo_solver(args_init_sim, model="demag") # or "nodemag"
sim.set_mesh(...)
sim.init_dynamic(args_init_dyn)
sim.solve_problem() # defined on Z_sim_dynamic_stereo_base
sim.impl is the underlying Z_sim_dynamic_stereo_demag
or Z_sim_dynamic_stereo_nodemag instance.
Exports¶
StereoDemagSolver,StereoNoDemagSolver— validation + delegation wrapperscreate_stereo_solver()— factoryZ_sim_dynamic_stereo_demag,Z_sim_dynamic_stereo_nodemag— concrete classes
Shared timestep control, checkpoints, and the main loop are documented in Shared base module. Model-specific FEM spaces and SNES forms are in Demag dynamic solver and Nodemag dynamic solver.
Factory and thin wrappers for stereographic dynamic solvers.
create_stereo_solver() is the recommended entry point. Wrappers forward attribute
access to StereoSolverBase.impl.
- class Zmag_bins.Zmag_dynamic_stereo_solvers.StereoSolverBase(args_init_sim: dict[str, Any])[source]¶
Bases:
ABCAbstract facade over dynamic stereographic solver implementations.
Deep-copies
args_init_simand forwards attributes toimpl.- __init__(args_init_sim: dict[str, Any])[source]¶
Deep-copy initialization dict and construct the concrete solver.
- Parameters:
args_init_sim (dict) – Simulation setup dictionary for the underlying class.
- property impl¶
Underlying
Z_sim_dynamic_stereo_*instance.
- class Zmag_bins.Zmag_dynamic_stereo_solvers.StereoDemagSolver(args_init_sim: dict[str, Any])[source]¶
Bases:
StereoSolverBaseWrapper for
Z_sim_dynamic_stereo_demag.Requires
demaginenergy_terms.
- class Zmag_bins.Zmag_dynamic_stereo_solvers.StereoNoDemagSolver(args_init_sim: dict[str, Any])[source]¶
Bases:
StereoSolverBaseWrapper for
Z_sim_dynamic_stereo_nodemag.Strips
demagfromenergy_termsif present.
- Zmag_bins.Zmag_dynamic_stereo_solvers.create_stereo_solver(args_init_sim: dict[str, Any], model: str = 'demag') StereoSolverBase[source]¶
Build a stereographic dynamic solver wrapper.
- Parameters:
args_init_sim (dict) – Simulation setup dictionary.
model (str) –
"demag"or"nodemag".
- Returns:
StereoSolverBase
Delegating wrapper around the concrete solver.
- Raises:
ValueError – If
modelis unrecognized.
- class Zmag_bins.Zmag_dynamic_stereo_solvers.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.- class NonlinearSNESProblem_qAqB(sim, F_expr)[source]¶
Bases:
objectSNES nonlinear problem wrapper for qA/qB/phi system.
- __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.
- close_output(target: str)[source]¶
Close VTX/XDMF writers opened by
open_output()fortarget.
- compute_energy()[source]¶
Evaluate the atlas-weighted micromagnetic energy.
- Returns:
numpy.ndarray
[exchange, uniaxial, cubic, demag, zeeman, total](inactive terms are zero).
- 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.
- 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.
- 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]
- 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]
- 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.
- 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\).
- 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.
- 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
- 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_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.
- class Zmag_bins.Zmag_dynamic_stereo_solvers.Z_sim_dynamic_stereo_nodemag(args_init_sim: dict)[source]¶
Bases:
Z_sim_dynamic_stereo_baseStereographic LLG with mixed unknowns
(q_A, q_B)only.Shares the base-class time loop and atlas with the demag variant but omits
V_phiand magnetostatics.- class NonlinearSNESProblem_qAqB(sim, F_expr)[source]¶
Bases:
objectSNES nonlinear problem wrapper for the mixed qA/qB system.
- __init__(args_init_sim: dict) None[source]¶
Initialize no-demag solver configuration and chart basis.
- Parameters:
args_init_sim (dict) – See class docstring. Raises
ValueErrorif no energy terms remain after removingdemag.
- compute_energy()[source]¶
Evaluate atlas-weighted energy without a demag term.
- Returns:
numpy.ndarray
Energy components followed by
total.
- init_dynamic(args_init_dyn: dict)[source]¶
Configure time integration, SNES, BDF history, ramps, and I/O for
(q_A, q_B).Same contract as the demag solver except magnetostatics, demag continuation, and demag-only outputs are absent.
- Parameters:
args_init_dyn (dict) – Dynamic configuration dictionary (requires
cfl_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.
- open_output(target: str, filename: str)[source]¶
Open BP (VTX) and optional XDMF time-series writers for a field target.
- Parameters:
target (str) – Field name (see FEATURE_MATRIX.md). Demag-only targets raise in nodemag.
filename (str) – Base path for
.bpoutput (XDMF uses parallel.xdmfnaming).
- read_checkpoint_demag(filename)[source]¶
Not supported in nodemag.
- Raises:
ValueError –
Always raised. –
- read_checkpoint_time(run_dir, filename)[source]¶
Read restart step/time/dt from checkpoint energies table.
- set_magnetostatics(interfaces: list[dict], surface_tag: int)[source]¶
Ignored in nodemag; present so shared drivers can call the demag API safely.
- solve_magnetostatics(step)[source]¶
Write restart magnetization checkpoint when resuming from a saved state.
- solve_weak_form(max_outer_override=None)[source]¶
Advance one timestep on
(q_A,q_B)with q-only outer fixed-point and SNES.Called from
solve_problem()inside each retry attempt. Acceptance gates (residual, thermo, closure) run in the base class after this returns.- Parameters:
max_outer_override (int, optional) – Cap outer-split iterations.
- Returns:
q_defect,converged, outer-iteration metadata.- Return type:
dict