include/pops/runtime/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
|
system.hpp
Go to the documentation of this file.
3#include <pops/core/state/variables.hpp> // VariableSet (role-bearing descriptor carried by each block)
4#include <pops/numerics/time/integrators/implicit_stepper.hpp> // NewtonOptions (options of the IMEX source Newton)
5#include <pops/runtime/export.hpp> // POPS_EXPORT (methods resolved by the native loader through dlopen)
6#include <pops/runtime/facade_options.hpp> // SourceStageOptions / CoupledSourceProgram (facade PODs, ADC-214)
7#include <pops/runtime/context/grid_context.hpp> // GridContext + BlockClosures (AOT-compiled block seam)
9#include <pops/runtime/config/runtime_params.hpp> // RuntimeParams (compiled-Program runtime params, ADC-510)
54 // --- opt-in geometry (Phase 1): "cartesian" (default, bit-identical) | "polar" (global ring) ---
62 // Number of boxes of the ring, split in theta (each box covers the whole radius [0, nr-1] and one
64 // polar transport (assemble_rhs_polar + collective fill_ghosts) runs multi-box. CONSTRAINTS (cf.
65 // PolarMesh / check_geometry): 1 <= theta_boxes <= ntheta AND theta_boxes divides ntheta. INERT in
66 // cartesian (the cartesian split goes through AmrSystem / the historical mono-box MPI multi-box).
266 POPS_EXPORT void install_block(const std::string& name, int ncomp, const VariableSet& cons_vars,
591 POPS_EXPORT void set_block_elliptic_field(const std::string& block_name, const std::string& field,
Field distributed over a level: decomposition (BoxArray) + distribution (DistributionMapping) + ncomp...
Definition multifab.hpp:33
Coupled multi-species system, composed at runtime from generic bricks.
Definition system.hpp:89
POPS_EXPORT std::vector< double > program_cache_global(int node_id) const
GLOBAL (collective, MPI-safe) gather of slot node_id's cached MultiFab into a component-major buffer ...
std::vector< double > density_global(const std::string &name) const
comp0, ny*nx global
POPS_EXPORT std::vector< double > history_global(const std::string &name, int slot) const
GLOBAL (collective, MPI-safe) gather of slot slot (0 = current, k = k macro-steps back) of history na...
POPS_EXPORT void restore_program_cache(int node_id, int ncomp, int ngrow, int last_update_step, double accumulated_dt, const std::string &name, const std::vector< double > &values)
RESTORE (restart) slot node_id from a GLOBAL component-major buffer (same layout as program_cache_glo...
SourceNewtonReport newton_report(const std::string &name) const
double step_adaptive(double cfl)
Advances one MULTIRATE macro-step: the slowest block sets the macro-step, each block that is faster i...
POPS_EXPORT Real cfl_min_dx() const
The MIN physical cell size of the grid (Cartesian min(dx, dy); polar min(dr, r_min*dtheta)) – the SAM...
void set_electron_temperature_from(const std::string &name)
Designates a COMPRESSIBLE fluid block (4 var) as the source of the electron temperature T_e: the T_e ...
POPS_EXPORT MultiFab & read_history(const std::string &name, int lag)
The history slot lag macro-steps back (lag 0 = the current slot, lag 1 = the previous step's stored v...
double block_gamma(const std::string &name) const
Adiabatic index (gamma) of the block, read by the inter-species couplings (collision,...
POPS_EXPORT void set_history_initialized(const std::string &name, bool initialized)
Mark history name initialized (or not) after a restart: a restored, already-stored ring must read at ...
POPS_EXPORT void block_neg_div_flux_into(int b, MultiFab &U, MultiFab &R)
R <- -div F(U) for block b – the SAME flux divergence as block_rhs_into but WITHOUT the model's defau...
POPS_EXPORT void set_program_block_map(const std::vector< int > &prog_to_sys)
void set_source_stage(const std::string &name, const std::string &kind, double theta, double alpha, const SourceStageOptions &opts={})
Enables a Schur-condensed SOURCE STAGE on block name (EXPLICIT / IMPLICIT splitting,...
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, bool evolve=true, 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, bool wave_speed_cache=false)
Adds an equation block (one species).
System(const SystemConfig &cfg)
std::vector< double > state_global(const std::string &name) const
U, ncomp*ny*nx global.
std::vector< std::string > variable_names(const std::string &name, const std::string &kind="conservative") const
Variable names of a block (introspection): kind = "conservative" | "primitive".
POPS_EXPORT RuntimeParams program_params(int prog_block) const
Block prog_block's CURRENT RuntimeParams (a device-clean by-value copy: trivially copyable,...
void set_clock(double t, int macro_step)
RESTORES the clock (t, macro_step) – reserved for the RESTART (sim.restart).
POPS_EXPORT void set_block_elliptic_field(const std::string &block_name, const std::string &field, std::function< void(const MultiFab &, MultiFab &)> rhs)
Attach named field's RHS closure (+= elliptic_field_rhs(U)) to block block_name.
POPS_EXPORT std::map< std::string, Real > program_diagnostics() const
All recorded diagnostics (name -> last recorded value).
POPS_EXPORT int macro_step() const
MACRO-STEP counter (0-indexed; incremented by step / step_cfl / step_adaptive).
std::vector< double > eval_rhs(const std::string &name)
-div F + S, size ncomp*n*n
POPS_EXPORT void register_elliptic_field(const std::string &field, int phi_comp, int gx_comp, int gy_comp)
Register named field's aux output components (where its solved phi / centered grad land).
POPS_EXPORT void seed_program_params(int prog_block, const std::vector< double > &defaults)
Seed block prog_block's RuntimeParams to its DECLARATION defaults (count values, the ....
std::vector< double > disc_mask() const
void add_coupled_source(const CoupledSourceProgram &prog, double frequency=0.0, const std::string &label="coupled_source")
Adds a GENERIC inter-species COUPLED SOURCE described by a BYTECODE (pops.dsl.CoupledSource,...
void add_dynamic_block(const std::string &name, const std::string &so_path, int substeps=1, const std::vector< std::string > &names={}, const std::string &recon="none")
Adds a block whose model is LOADED AT RUNTIME from a shared library (.so) generated by the DSL (emit_...
std::string last_dt_bound() const
Name of the ACTIVE bound (the one that set dt) of the last step_cfl: "transport:<block>",...
void reset_profiling()
POPS_EXPORT std::string program_cache_name(int node_id) const
The scheduled node name of slot node_id ("fields_from_state"), or "node_<id>" if it was stored withou...
POPS_EXPORT int program_cache_ncomp(int node_id) const
The component count of slot node_id's cached value.
POPS_EXPORT std::vector< std::string > history_names() const
void set_disc_domain(double cx, double cy, double R, const std::string &mode="none")
Sets the TRANSPORT DOMAIN as a DISC centered at (cx, cy) with radius R (T2 work, CONTRACT inert by de...
POPS_EXPORT void set_program_cadence(int substeps, int stride)
Set the compiled-Program macro-step cadence (ADC-411): SYSTEM-level substeps and stride around the in...
void add_collision(const std::string &a, const std::string &b, double rate)
Adds an inter-species COLLISION / friction (operator-split): force k (u_a - u_b) on the momentum,...
void add_compiled_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", int substeps=1, const std::vector< std::string > &names={}, double positivity_floor=0.0)
Adds a block whose model is COMPILED AOT from a .so generated by the DSL (dsl.compile_aot / compile_o...
POPS_EXPORT GridContext grid_context()
REAL mesh + BC + aux of the System (aux not owned)
void advance(double dt, int nsteps)
std::array< double, 3 > dt_hotspot(const std::string &name)
Diagnostic (ADC-182): {w, i, j} of the GLOBAL cell that dominates the transport CFL bound of the bloc...
POPS_EXPORT void set_block_dt_bounds(const std::string &name, std::function< Real(const MultiFab &)> source_frequency, std::function< Real(const MultiFab &)> stability_dt)
Installs the optional STEP BOUNDS of a block (after install_block): reduction of the max source frequ...
void enable_profiling()
POPS_EXPORT void block_source_into(int b, MultiFab &U, MultiFab &R)
R <- S(U, aux) for block b – the model's default/composite SOURCE only, WITHOUT the flux divergence (...
POPS_EXPORT void ensure_aux_width(int ncomp)
Guarantees that the SHARED aux channel has at least ncomp components.
POPS_EXPORT void install_block(const std::string &name, int ncomp, const VariableSet &cons_vars, const VariableSet &prim_vars, double gamma, BlockClosures closures, std::function< Real(const MultiFab &)> max_speed, std::function< void(const MultiFab &, MultiFab &)> poisson_rhs, int substeps, bool evolve, int stride=1)
Installs a block from already-built closures (cf.
void set_epsilon_anisotropic_field(const std::vector< double > &eps_x, const std::vector< double > &eps_y)
Sets an ANISOTROPIC permittivity eps_x(x), eps_y(x), two n*n row-major fields (> 0),...
std::vector< double > density(const std::string &name) const
ny*nx row-major (j slow, i fast)
POPS_EXPORT void solve_fields_from_state(const std::string &field, int block_idx, const MultiFab &U_stage)
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, double epsilon=1.0, double abs_tol=0.0)
Configures the shared Poisson.
POPS_EXPORT MultiFab & block_state(int b)
The conservative state MultiFab of block b (zero-copy, non-owning reference).
POPS_EXPORT void solve_fields_from_state(int block_idx, const MultiFab &U_stage)
Per-stage field solve (ADC-409): SAME elliptic solve + aux derivation as solve_fields(),...
void set_state(const std::string &name, const std::vector< double > &u)
POPS_EXPORT int history_depth(const std::string &name) const
Ring depth (max lag + 1) of history name.
std::vector< std::string > block_names() const
Block names, in the order of addition.
std::vector< double > get_primitive_state(const std::string &name)
Reads the CONSERVATIVE state of the block and converts it to PRIMITIVE variables via the model conver...
void disable_profiling()
std::vector< std::array< int, 4 > > local_boxes(const std::string &name) const
(ilo,jlo,ihi,jhi) per local fab
POPS_EXPORT runtime::program::CacheManager & program_cache()
POPS_EXPORT int history_ncomp(const std::string &name) const
Component count of the slots of history name (the block's ncomp).
POPS_EXPORT double program_cache_accumulated_dt(int node_id) const
The accumulated skipped dt of slot node_id (accumulate_dt policy). 0 if none.
int ny() const
Extent of the SLOW axis of the field (rows of the (ny, nx) row-major array returned by density / pote...
POPS_EXPORT Real block_max_speed(int b, const MultiFab &U) const
The maximum |wave speed| of block b evaluated on U – the SAME per-block reduction step_cfl reads (Blo...
std::string profile_report() const
~System()
void set_aux_field_component(int comp, const std::vector< double > &field)
Sets a NAMED aux field (ADC-70 phase 1) on the canonical component comp (>= kAuxNamedBase = 5),...
POPS_EXPORT void rotate_histories()
Shift every history ring buffer one step (slot k <- slot k-1, for k = depth-1 .
void set_reaction_field(const std::vector< double > &kappa)
Enables a REACTION term kappa(x) >= 0: the system Poisson operator goes from div(eps grad phi) = f to...
POPS_EXPORT void record_program_diagnostic(const std::string &name, Real value)
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, bool evolve=true, int stride=1, double positivity_floor=0.0)
Adds a block whose model is compiled into a NATIVE LOADER .so generated by the DSL (dsl....
POPS_EXPORT int program_cache_last_update_step(int node_id) const
The macro step at slot node_id's last recompute.
POPS_EXPORT void solve_fields()
solves Poisson then derives aux = (phi, grad phi); exported
std::vector< double > local_state(const std::string &name, int li) const
U of fab li, flat (ncomp*bny*bnx)
POPS_EXPORT void set_block_conversion(const std::string &name, CellConvert prim_to_cons, CellConvert cons_to_prim)
Installs the pointwise cons <-> prim conversions of a block (after install_block).
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...
void set_time_scheme(const std::string &scheme)
Time SPLITTING POLICY of the macro-step (hyperbolic transport H + source stage S):
std::vector< std::string > variable_roles(const std::string &name, const std::string &kind="conservative") const
PHYSICAL roles of the variables of a block (parallel to variable_names): "density",...
POPS_EXPORT const std::vector< int > & program_block_map() const
The installed program-index -> system-index map (empty = identity). Read by ProgramContext.
std::function< void(const double *in, double *out)> CellConvert
Type-erasure of the POINTWISE (one cell) cons <-> prim conversion of a block: in/out are arrays of nc...
Definition system.hpp:421
std::vector< double > get_state(const std::string &name)
U, ncomp*n*n (component-major)
void add_ionization(const std::string &electron, const std::string &ion, const std::string &neutral, double rate)
Adds an IONIZATION coupling (operator-split): rate k n_e n_g; a neutral becomes an ion and an electro...
POPS_EXPORT void set_block_ghosts(const std::string &name, int n_ghost)
Guarantees that the state U of block name carries at least n_ghost ghosts (width of the spatial stenc...
POPS_EXPORT runtime::program::Profiler & profiler()
The System-owned Profiler (a non-owning reference; lives as long as the System).
POPS_EXPORT void set_program_params(int prog_block, const std::vector< double > &values)
void add_thermal_exchange(const std::string &a, const std::string &b, double rate)
Adds an inter-species THERMAL EXCHANGE (operator-split): heat flux k (T_a - T_b) on the energy,...
POPS_EXPORT void block_rhs_into(int b, MultiFab &U, MultiFab &R)
R <- -div F(U) + S(U, aux) for block b (the block's frozen-Poisson residual closure).
POPS_EXPORT Real program_diagnostic(const std::string &name) const
The recorded value of diagnostic name.
bool is_profiling() const
void set_block_params(const std::string &name, const std::vector< double > &values)
Changes the values of the RUNTIME parameters of an AOT block (add_compiled_block) WITHOUT recompiling...
void set_epsilon_field(const std::vector< double > &eps)
Sets a VARIABLE permittivity eps(x), n*n row-major field (> 0), at the cell CENTER.
void set_primitive_state(const std::string &name, const std::vector< double > &prim)
Initializes the state of a block from its PRIMITIVE variables (rho, u, v, p ...): prim is a flat ncom...
System(System &&) noexcept
double mass(const std::string &name) const
POPS_EXPORT MultiFab & register_history(const std::string &name, int lag)
void set_potential(const std::vector< double > &phi)
RESTORES the potential phi (IO v1, reserved for restart): without it the multigrid would restart from...
POPS_EXPORT MultiFab alloc_scalar_field(int n_comp, int n_ghost)
A fresh scalar field co-distributed with the System mesh: block 0's BoxArray and DistributionMapping,...
int n_vars(const std::string &name) const
POPS_EXPORT void install_program_step(std::function< void(double)> step)
static std::string abi_key()
ABI key of the module (compiler + C++ standard + signature of the pops headers, frozen at compilation...
double step_cfl(double cfl)
Advances one step at dt = cfl * h / max wave speed of the system.
POPS_EXPORT void block_project(int b, MultiFab &u)
Apply block b's post-step positivity projection to u in place (ADC-177): U <- project(U,...
POPS_EXPORT void store_history(const std::string &name, const MultiFab &value)
Copy value (valid cells) into the CURRENT slot [0] of history name and mark it initialized.
int n_species() const
POPS_EXPORT int program_cache_ngrow(int node_id) const
The ghost-cell width of slot node_id's cached value (1 for the aux, the block-state width for a held ...
int nx() const
POPS_EXPORT std::string installed_program_hash() const
IR hash of the installed compiled Program (the string returned by the .so's pops_program_hash),...
void step(double dt)
solve_fields, then advances each block according to its scheme
POPS_EXPORT std::vector< int > program_cache_nodes() const
double time() const
POPS_EXPORT void solve_fields_from_blocks(const std::vector< const MultiFab * > &U_stages)
Coupled multi-block field solve (Spec 3 criterion 24, ADC-457): SAME elliptic solve + aux derivation ...
std::string poisson_solver() const
Configured field (Poisson) solver token, e.g.
void set_geometry_mode(const std::string &mode)
Sets ONLY the disc transport mode (without (re)defining the disc): "none" | "staircase" | "cutcell".
void add_dt_bound(const std::string &label, std::function< double()> fn)
Adds a GLOBAL time-step bound, evaluated ONCE per step (host) by step_cfl / step_adaptive: dt <= fn()...
void set_density(const std::string &name, const std::vector< double > &rho)
Sets the density of a species (component 0), n*n row-major array.
POPS_EXPORT bool history_initialized(const std::string &name) const
Whether history name has been stored at least once (the cold-start fill already happened).
void set_magnetic_field(const std::vector< double > &bz)
Sets an out-of-plane magnetic field B_z(x, y) SHARED by the blocks, n*n row-major.
POPS_EXPORT void restore_history(const std::string &name, int slot, const std::vector< double > &values)
RESTORE (restart) slot slot of history name from a GLOBAL component-major buffer (same layout as hist...
POPS_EXPORT void install_program(const std::string &so_path)
Load a generated problem.so and install its compiled time Program.
std::vector< double > aux_field_component(int comp) const
Reads a NAMED aux field (component comp >= kAuxNamedBase): valid cells of the aux channel,...
Definition cache_manager.hpp:48
Definition profiler.hpp:27
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...
Block grid context plus closures, shared between System (which installs them) and block_builder....
Implicit / IMEX block step as a named CONTRACT.
Flat specification of a model: chosen bricks plus their parameters.
Definition amr_hierarchy.hpp:29
RuntimeParams: carrier for the RUNTIME PARAMETERS of a DSL model (P7-b).
BYTECODE description of a generic inter-species COUPLED SOURCE (cf.
Definition facade_options.hpp:77
Mesh + transport BC + aux shared by a block closures.
Definition grid_context.hpp:41
FLAT carrier (fixed size, by value) of the runtime parameter values of a block.
Definition runtime_params.hpp:38
Settings of the Schur-condensed SOURCE STAGE (cf.
Definition facade_options.hpp:48
Mesh and domain shared by all blocks (physical parameters are per block, in the ModelSpec).
Definition system.hpp:50
std::string geometry
geometry choice (carried by pops.CartesianMesh / pops.PolarMesh)
Definition system.hpp:55
bool periodic
periodic domain, otherwise free outflow in transport (cartesian)
Definition system.hpp:53
int n
cells per direction (n x n domain) – for polar: n_r = n_theta = n
Definition system.hpp:51
int theta_boxes
boxes of the theta split of polar transport (1 = mono-box)
Definition system.hpp:69
Report of the implicit source Newton (IMEX) of a block, AGGREGATED over the substeps of the LAST adva...
Definition system.hpp:165
bool converged
no failed cell on the last advance
Definition system.hpp:167
double failed_comp
conservative component of the worst residual of that cell (-1 unknown)
Definition system.hpp:174
double failed_i
i of ONE faulty cell (-1 if none; max index encoded)
Definition system.hpp:172
double max_residual
max over cells/substeps of ||F||_inf at the Newton exit
Definition system.hpp:168
bool enabled
a report was computed (at least one IMEX advance played)
Definition system.hpp:166
double failed_j
j of the same cell (-1 if none)
Definition system.hpp:173
double n_failed
number of (cells x substeps) failed (non-finite / pivot / non-convergence)
Definition system.hpp:171
double max_iters_used
max over cells/substeps of the iterations consumed
Definition system.hpp:169
A model's variable set: kind (cons/prim), names, size, canonical roles (optional, parallel to names; ...
Definition variables.hpp:58
Descriptor of a model's variables (Vars).
Generated by