include/pops/runtime/amr_system.hpp Source File¶
|
adc_cpp 0.3.0
Model-free C++23 core for coupled hyperbolic-elliptic systems on adaptive (AMR) meshes, with MPI and GPU (Kokkos) backends
|
amr_system.hpp
Go to the documentation of this file.
3#include <pops/mesh/layout/patch_box.hpp> // PatchBox: index-space signature of a fine patch (patch_boxes())
5#include <pops/numerics/time/integrators/implicit_stepper.hpp> // NewtonOptions (Newton options of the IMEX source)
6#include <pops/runtime/export.hpp> // POPS_EXPORT: set_compiled_block resolved by the native AMR loader
7#include <pops/runtime/facade_options.hpp> // SourceStageOptions / CoupledSourceProgram (facade PODs, ADC-214)
42// amr_dsl_block.hpp). set_compiled_block stores a DEFERRED runtime-block BUILDER which, given the
43// SHARED layout materialized at lazy build, returns the type-erased AmrRuntimeBlock of the compiled
46// to weigh down this public header (read by bindings.cpp and the loaders) with amr_runtime.hpp: only
52// set_block_elliptic_field): a std::function with an incomplete-type parameter is legal as long as it is
53// only INSTANTIATED with a concrete callable in the TUs that include the full definition (the native AMR
100 // has_state. ADDED AT THE END OF THE STRUCT: the offsets of the preceding fields are unchanged, so an
101 // older mono-block .so loader (which COPIES bp into its own layout then does not read these fields)
106 // Schur-CONDENSED SOURCE STAGE (amr-schur path, counterpart of System::set_source_stage). ADDED AT THE
107 // END OF THE STRUCT (append-only, same reason as has_state: an older .so loader does not read these
124 // Settings of the condensed stage TRANSPORTED by the ABI (audit wave 3, append-only like has_state).
130 // NEWTON OPTIONS of the IMEX source on the MONO-BLOCK path (wave 3: mono-block AMR options wired).
131 // ADDED AT THE END OF THE STRUCT (append-only, same reason as has_state / schur_*: an older .so loader
132 // does not read this field and falls back to the historical Newton with 2 frozen iters). DEFAULT {} =
134 // bit-identical. Consumed by build_amr_compiled (the mono-block closure passes it to cpl->step).
136 // TEMPORAL METHOD of the block, transported as an INTEGER by the flat ABI (0 == kEuler, historical
137 // before, 1 == kSsprk3). ADDED AT THE END OF THE STRUCT (append-only, same reason as has_state /
138 // schur_* / newton_options: an older .so loader does not read this field and falls back SILENTLY
141 // Zhang-Shu positivity floor (ADC-259): Density-role face-state + C/F-ghost-mean floor on the AMR
143 // newton_options / time_method: an older flat-ABI .so loader does not read this field and falls
144 // back SILENTLY to 0 -- inactive, bit-identical). Consumed by build_amr_compiled (mono-block ->
162 // patches. Mirror of n_patches (same box_array(), the COUNT becomes the BOXES). The .so loader that
163 // builds this struct is guarded by pops_native_abi_key: a .so generated BEFORE this addition must be
164 // recompiled (the guard already diagnoses it clearly); the tail addition makes it purely additive.
167 // ADDED AT THE TAIL (AMR StabilityPolicy, audit 2026-06, additive like patch_boxes): OPTIONAL step
168 // bounds of the block, evaluated on the COARSE level by AmrSystem::step_cfl mono-block. EMPTY if
169 // the model does not declare the HasSourceFrequency / HasStabilityDt traits (bit-identical). The
174 // ADDED AT THE TAIL (IO v1, parity with System::set_clock): restoration of the macro-step counter of
175 // the MONO-BLOCK engine (the AmrCouplerMP coupler carries the regrid-cadence phase in a step_state;
176 // this hook writes it at restart). EMPTY is never the case (the builder always populates it); the
177 // pops_native_abi_key guard forces regeneration of older .so files (purely additive tail addition).
180 // ADDED AT THE TAIL (mono-rank AMR checkpoint/restart, ADC-65; additive like set_macro_step): FULL
181 // CONSERVATIVE state per level (all components) + phi (warm-start) + imposition of a SAVED fine
182 // hierarchy. The mono-block coupler (AmrCouplerMP) carries them; the builder always populates them
194 // ADDED AT THE TAIL (ADC-319, MPI ownership diagnostic; additive like the fields above): COARSE-level
195 // (base) box counts. coarse_local_boxes = cpl->coarse().local_size() (level-0 fabs OWNED by this rank);
196 // coarse_total_boxes = cpl->coarse().box_array().size() (total base boxes, all ranks). They reveal
197 // whether distribute_coarse actually distributes the base across ranks (local < total) or replicates
198 // it (local == total on every rank). The pops_native_abi_key guard forces regeneration of older .so
202 // ADDED AT THE TAIL (np>1 mono-block AMR checkpoint, ADC-509; additive like the fields above): the
203 // GLOBAL (all_reduce_sum gather) counterparts of level_state / level_potential. Under MPI np>1 the
204 // per-level fabs are distributed (round-robin fine patches, optionally distributed coarse), so a
205 // bit-identical checkpoint must GATHER them onto every rank before rank 0 writes -- exactly like
206 // System::state_global / potential_global. The pops_native_abi_key guard forces regeneration of
508 POPS_EXPORT void set_block_elliptic_field(const std::string& block_name, const std::string& field,
Single block carried on an AMR hierarchy, composed at runtime.
Definition amr_system.hpp:245
void set_level_potential(int k, const std::vector< double > &p)
restores phi of level k
void set_clock(double t, int macro_step)
RESTORES the AMR clock (t, macro_step) – parity with System::set_clock.
std::vector< double > level_potential_global(int k)
np>1 gather (all ranks call)
~AmrSystem()
void add_block(const std::string &name, const ModelSpec &model, const std::string &limiter="minmod", const std::string &riemann="rusanov", const std::string &recon="conservative", const std::string &time="explicit", int substeps=1, int stride=1, const std::vector< std::string > &implicit_vars={}, const std::vector< std::string > &implicit_roles={}, const NewtonOptions &newton={}, bool newton_diagnostics=false, double positivity_floor=0.0)
Adds a block carried on the AMR.
void set_source_stage(const std::string &name, const std::string &kind, double theta, double alpha, const SourceStageOptions &opts={})
Enables the Schur-CONDENSED SOURCE STAGE (amr-schur path) on block name.
AmrSystem(AmrSystem &&) noexcept
void disable_profiling()
void add_dt_bound(const std::string &label, std::function< double()> fn)
GLOBAL time-step bound (AMR counterpart of System::add_dt_bound): fn() evaluated ONCE per step_cfl (h...
bool is_profiling() const
int coarse_total_boxes()
std::vector< std::string > block_names() const
Names of the blocks in add order (parity with System::block_names): the IO facade iterates over them ...
std::vector< double > level_potential(int k)
Potential phi of level k, flat nf*nf row-major.
void set_hierarchy(const std::vector< PatchBox > &boxes)
Imposes the SAVED fine hierarchy (at restart) instead of Berger-Rigoutsos clustering: boxes are the p...
std::vector< double > potential()
Electrostatic potential phi of the COARSE LEVEL (base), n*n row-major.
void enable_profiling()
POPS_EXPORT void set_block_elliptic_field(const std::string &block_name, const std::string &field, std::function< void(const MultiFab &, MultiFab &)> rhs)
Attaches named field's RHS closure (rhs += elliptic_field_rhs(U)) to block block_name.
int n_vars()
number of conserved components (MONO-BLOCK; multi-block: block_n_vars)
std::vector< double > level_state(int k)
FULL conservative state of level k, flat component-major c*nf*nf + j*nf + i (nf = n << k; zeros outsi...
void add_native_block(const std::string &name, const std::string &so_path, const std::string &limiter="minmod", const std::string &riemann="rusanov", const std::string &recon="conservative", const std::string &time="explicit", double gamma=1.4, int substeps=1, double positivity_floor=0.0)
Wires a NATIVE AMR block from a .so loader generated by the DSL (backend "production",...
void set_time_scheme(const std::string &scheme)
Chooses the time-splitting policy of the condensed source stage: "lie" (default, H(dt) S(dt)) or "str...
std::vector< double > named_field_values(const std::string &field)
Solved potential of named field on the COARSE level, n*n row-major (read-back).
void set_density(const std::string &name, const std::vector< double > &rho)
Sets the initial density on the coarse level (component 0), n*n row-major.
std::vector< double > level_state_global(int k)
MONO-BLOCK, np>1 gather (all ranks call)
int n_blocks() const
number of blocks (1 = mono-block AmrCouplerMP; >= 2 = AmrRuntime)
AmrSystem & operator=(const AmrSystem &)=delete
void set_block_level_state(const std::string &name, int k, const std::vector< double > &s)
POPS_EXPORT void set_compiled_block(int ncomp, double gamma, int substeps, std::function< AmrCompiledHooks(const AmrBuildParams &)> mono_builder, AmrCompiledBlockBuilder multi_builder={}, const std::string &name=std::string(), bool recon_prim=false, bool imex=false, int stride=1, const std::vector< std::string > &implicit_vars={}, const std::vector< std::string > &implicit_roles={}, double pos_floor=0.0)
Registers a COMPILED block (add_compiled_model path, header amr_dsl_block.hpp).
std::vector< double > block_level_state(const std::string &name, int k)
void reset_profiling()
std::string profile_report() const
void set_conservative_state(const std::string &name, const std::vector< double > &U)
Sets the FULL INITIAL CONSERVATIVE STATE (all components) on the coarse level, then prolongs it to th...
std::vector< double > density()
coarse density of the 1st block (component 0), n*n row-major
std::vector< double > density(const std::string &name)
coarse density of the named block, n*n
void set_level_state(int k, const std::vector< double > &s)
restores the state of level k (as is)
POPS_EXPORT void register_elliptic_field(const std::string &field, int phi_comp, int gx_comp, int gy_comp)
void set_magnetic_field(const std::vector< double > &bz)
Sets the magnetic field B_z(x, y) of the coarse level (n*n row-major), required by the Schur-condense...
SourceNewtonReport newton_report(const std::string &name)
int n_levels()
AMR CHECKPOINT / RESTART (ADC-65 single-block single-rank; ADC-509 multi-block + np>1): per-level STA...
void set_refinement(double threshold, const std::string &variable=std::string(), const std::string &role=std::string())
Refines the cells where the SELECTED conserved variable exceeds threshold.
std::vector< double > block_level_state_global(const std::string &name, int k)
np>1 gather (all ranks call)
std::string last_dt_bound() const
ACTIVE bound of the last step_cfl: "transport:<block>" | "source_frequency:<block>" | "stability_dt:<...
void add_coupled_source(const CoupledSourceProgram &prog, double frequency=0.0, const std::string &label="coupled_source")
Registers an inter-species COUPLED SOURCE (compiled pops.dsl.CoupledSource, flat bytecode ABI P5),...
int coarse_local_boxes()
COARSE-level (base) box counts, MPI ownership diagnostic (ADC-319).
void set_phi_refinement(double grad_threshold)
Adds to the regrid criterion the PHI tag on |grad phi| (D4 of the design docs/AMR_REGRID_UNION_TAGS_D...
AmrSystem(const AmrSystem &)=delete
double step_cfl(double cfl)
Advances at dt = cfl * coarse_dx / max wave speed.
double mass(const std::string &name)
mass of the named block on the coarse (conserved PER BLOCK)
std::vector< PatchBox > patch_boxes()
Index-space signatures of the current fine patches: one PatchBox (level, ilo, jlo,...
double time() const
void advance(double dt, int nsteps)
void set_aux_field_component(int comp, const std::vector< double > &field)
Sets a model-NAMED aux field (ADC-291) at shared-channel component comp (>= kAuxNamedBase) from a coa...
AmrSystem(const AmrSystemConfig &cfg)
int macro_step() const
MACRO-STEP counter (0-indexed; incremented by step / advance / step_cfl), parity with System::macro_s...
int block_n_vars(const std::string &name)
MULTI-BLOCK per-BLOCK per-level checkpoint accessors (ADC-509).
void set_poisson(const std::string &rhs="charge_density", const std::string &solver="geometric_mg", const std::string &bc="auto", const std::string &wall="none", double wall_radius=0.0)
Configures the coarse Poisson (cf.
int nx() const
void set_aux_field_halo_component(int comp, int bc_type, double value)
Declares a per-field aux HALO policy (ADC-369) for the NAMED component comp (>= kAuxNamedBase): bc_ty...
Field distributed over a level: decomposition (BoxArray) + distribution (DistributionMapping) + ncomp...
Definition multifab.hpp:33
POPS_EXPORT: force DEFAULT VISIBILITY on an out-of-line symbol, even when the unit is compiled with -...
OPTIONS PODs for the public facades (System / AmrSystem), grouping the long families of HOMOGENEOUS p...
Implicit / IMEX block step as a named CONTRACT.
Flat specification of a model: chosen bricks plus their parameters.
Definition amr_hierarchy.hpp:29
std::function< AmrRuntimeBlock(const detail::SharedAmrLayout &layout, const std::string &name, const std::vector< double > &density, bool has_density, double gamma, int substeps, bool recon_prim, bool imex, int stride, const std::vector< std::string > &implicit_vars, const std::vector< std::string > &implicit_roles, double pos_floor)> AmrCompiledBlockBuilder
DEFERRED builder of a COMPILED block on the multi-block hierarchy: receives the SHARED layout (create...
Definition amr_system.hpp:227
PatchBox: index-space footprint of an AMR fine patch, exposed read-only to Python.
PHYSICAL boundary conditions at the domain edge (BCType, BCRec, fill_physical_bc, fill_ghosts).
Frozen parameters passed to the deferred build of the compiled path (add_compiled_model).
Definition amr_system.hpp:84
double schur_theta
theta-scheme of the condensed stage (0.5 = Crank-Nicolson)
Definition amr_system.hpp:110
double refine_threshold
1e30 => no refinement
Definition amr_system.hpp:92
std::function< bool(Real, Real)> wall
conductive wall predicate (empty = none)
Definition amr_system.hpp:94
int coarse_max_grid
tile size of the distributed coarse (0 => n/2)
Definition amr_system.hpp:98
int schur_krylov_max_iters
iteration budget (<= 0 = default 400)
Definition amr_system.hpp:126
BCRec poisson_bc
coarse Poisson BC (resolved by set_poisson)
Definition amr_system.hpp:93
std::vector< double > state
ncomp*n*n, component-major c*n*n + j*n + i; ncomp == Model::n_vars
Definition amr_system.hpp:105
bool imex
time == "imex": stiff implicit source (backward_euler)
Definition amr_system.hpp:91
std::map< int, std::vector< double > > named_aux
Model-NAMED aux fields (ADC-291): component (>= kAuxNamedBase) -> coarse base-level field (n*n row-ma...
Definition amr_system.hpp:119
bool distribute_coarse
distributed multi-box coarse (AMR strong-scaling)
Definition amr_system.hpp:97
bool schur
true: GLOBAL condensed source stage (instead of local explicit/imex)
Definition amr_system.hpp:109
double schur_alpha
electrostatic coupling constant of the condensed stage
Definition amr_system.hpp:111
std::vector< double > density
initial coarse density (component 0), n*n
Definition amr_system.hpp:96
std::map< int, AuxHaloPolicy > named_aux_bc
Per-field aux HALO policies (ADC-369): component -> uniform boundary policy, seeded onto the engine a...
Definition amr_system.hpp:123
double schur_krylov_tol
tolerance of the coarse Krylov solve (<= 0 = default 1e-10)
Definition amr_system.hpp:125
std::vector< double > bz_field
coarse B_z(x,y) field, n*n row-major (required by the condensed stage)
Definition amr_system.hpp:115
bool recon_prim
recon == "primitive" (frozen by add_compiled_model)
Definition amr_system.hpp:90
bool schur_strang
true: Strang splitting H(dt/2) S(dt) H(dt/2); false: Lie H(dt) S(dt)
Definition amr_system.hpp:112
Type-erased closures of a compiled AMR block, produced by amr_dsl_block::build_amr_compiled and insta...
Definition amr_system.hpp:153
std::function< void(const std::vector< PatchBox > &)> set_hierarchy
imposes the saved fine patches
Definition amr_system.hpp:193
std::function< int()> n_vars
conserved components of the block
Definition amr_system.hpp:185
std::function< void(int, const std::vector< double > &)> set_level_state
restores the state of level k
Definition amr_system.hpp:188
std::function< void(double)> step
one macro-step (periodic regrid included)
Definition amr_system.hpp:155
std::function< std::vector< double >(int)> level_potential
phi of level k (nf*nf row-major)
Definition amr_system.hpp:189
std::function< std::vector< PatchBox >()> patch_boxes
index-space signatures of the fine patches
Definition amr_system.hpp:166
std::function< std::vector< double >(int)> level_potential_global
level k phi, gathered
Definition amr_system.hpp:209
std::function< int()> coarse_total_boxes
global coarse box count (identical on all ranks)
Definition amr_system.hpp:201
std::function< int()> n_levels
number of levels (>= 1)
Definition amr_system.hpp:184
std::function< void(int, const std::vector< double > &)> set_level_potential
restores phi of level k
Definition amr_system.hpp:191
std::function< std::vector< double >(int)> level_state
full state of level k (c*nf*nf+j*nf+i)
Definition amr_system.hpp:186
std::function< std::vector< double >()> potential
coarse-level phi, n*n row-major
Definition amr_system.hpp:160
std::function< std::vector< double >()> density
coarse density, n*n row-major
Definition amr_system.hpp:159
std::function< double()> max_speed
max wave speed (CFL step)
Definition amr_system.hpp:156
std::function< std::vector< double >(int)> level_state_global
level k state, gathered
Definition amr_system.hpp:208
std::function< double()> stability_dt
coarse min of the admissible step (0 = does not constrain)
Definition amr_system.hpp:173
std::function< int()> n_patches
number of fine patches
Definition amr_system.hpp:158
std::function< int()> coarse_local_boxes
per-rank owned coarse (level-0) fab count
Definition amr_system.hpp:200
std::function< void(int)> set_macro_step
restores the cadence (regrid) phase of the mono-block
Definition amr_system.hpp:179
std::shared_ptr< void > coupler_holder
keeps the AmrCouplerMP<Model> alive
Definition amr_system.hpp:154
std::function< double()> source_frequency
coarse max of mu [1/s] (0 = does not constrain)
Definition amr_system.hpp:171
Type-erased closures of ONE AMR block, placed on the shared hierarchy.
Definition amr_runtime.hpp:98
AMR mesh and cadence (per-block physical parameters live in the ModelSpec).
Definition amr_system.hpp:61
int regrid_every
re-refinement every N steps (0 = never after init)
Definition amr_system.hpp:64
bool distribute_coarse
OWNERSHIP POLICY of the coarse level (cf.
Definition amr_system.hpp:75
int coarse_max_grid
Coarse tile size when distribute_coarse=true (BoxArray::from_domain).
Definition amr_system.hpp:78
Report of the implicit (IMEX) source Newton of a block, AGGREGATED over the levels and substeps of th...
Definition amr_system.hpp:327
double failed_j
j of the same cell (-1 if none)
Definition amr_system.hpp:335
bool converged
no cell failed on the last advance
Definition amr_system.hpp:329
double max_residual
max over cells/levels/substeps of ||F||_inf at the Newton exit
Definition amr_system.hpp:330
double failed_i
i of ONE faulty cell (-1 if none; max index encoded)
Definition amr_system.hpp:334
double n_failed
count (cells x levels x substeps) failed (non-finite / pivot / non-convergence)
Definition amr_system.hpp:333
double max_iters_used
max over cells/levels/substeps of the iterations consumed
Definition amr_system.hpp:331
double failed_comp
conserved component of the worst residual of that cell (-1 unknown)
Definition amr_system.hpp:336
bool enabled
a report was computed (at least one IMEX advance played)
Definition amr_system.hpp:328
Boundary conditions for the FOUR faces of the domain (type + associated Dirichlet value).
Definition physical_bc.hpp:29
BYTECODE description of a generic inter-species COUPLED SOURCE (cf.
Definition facade_options.hpp:77
Options of the local Newton of the implicit source (backward-Euler).
Definition implicit_stepper.hpp:114
Settings of the Schur-condensed SOURCE STAGE (cf.
Definition facade_options.hpp:48
Generated by