include/pops/runtime/builders/block/block_builder.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
|
block_builder.hpp
Go to the documentation of this file.
3#include <pops/core/foundation/cold.hpp> // POPS_COLD_FN: COLD block-builder no-optimize attribute (ADC-337)
6#include <pops/mesh/execution/for_each.hpp> // for_each_cell (projection ponctuelle post-pas, ADC-177)
13#include <pops/numerics/spatial/embedded_boundary/operator.hpp> // assemble_rhs_eb (cut-cell EB) + detail::DiscLevelSet (T5-PR2)
16#include <pops/runtime/config/dispatch_tags.hpp> // UNIQUE registry of tags (validate_limiter/riemann, limiter_n_ghost)
17#include <pops/runtime/context/grid_context.hpp> // GridContext + BlockClosures (shared lightweight header)
18#include <pops/numerics/spatial/embedded_boundary/domain.hpp> // detail::DiscDomain (built-in level-set domain instance)
45// GridContext and BlockClosures: defined in pops/runtime/grid_context.hpp (lightweight header, also
46// included by system.hpp to expose grid_context() / install_block() without pulling in the numerics).
308// The transport residual of a block goes through BlockRhsEval (assemble_rhs, full cartesian). The two
309// evaluators below SUBSTITUTE the disc operator for assemble_rhs, reading the System geometry BY
310// POINTER (stable address of an Impl member) at step time -- so the add_block / set_disc_domain order
486 // SHARED scratch of the HLL wave speed cache (opt-in): a single MultiFab for the explicit advance and
487 // rhs_into (never called concurrently). nullptr when the option is OFF -> BlockRhsEval keeps the
488 // per-face path (bit-identical). Allocated at the real layout on the first call (cf. BlockRhsEval).
495 // CARTESIAN ONLY: we do NOT build an embedded-boundary advance (advance_masked / advance_eb stay
496 // empty) -> an embedded-boundary geometry mode on this block throws an EXPLICIT error at step time
543 // FLUX-ONLY residual R <- -div F(U) (ADC-425): the SAME RhsInto path on SourceFreeModel<Model> (the
544 // canonical zero-source adapter the IMEX explicit half-step already uses, state_access.hpp), so the
545 // flux / ghost / geometry / positivity handling is bit-identical to rhs_into -- only the model's
546 // default/composite source is dropped. A compiled time Program's hyperbolic stage reads it so a
549 // concurrent), but a flux-only RHS can interleave with them, so it keeps the per-face path. The
550 // residual is identical either way with limiter='none'; the HLL wave-speed cache -- rejected on the
551 // aot/production backends compiled Programs use -- is the only path where cached cell-center speeds
552 // differ from the per-face reconstruction, so for a compiled Program the cache is a perf scratch,
557 // evaluates m.source per cell (the SAME source term assemble_rhs / rhs_into add) with no numerical-flux
558 // dispatch, so it is bit-identical to the source half of rhs_into and flux-template agnostic (a
559 // zero-flux model adapter could not zero HLL/Roe, which recombine via wave_speeds). A compiled time
560 // Program's source stage reads it so a Lie/Strang split assembles "the default source but no flux"
561 // without the -div F base leaking in (spec: rhs flux=False is source-only). No Limiter/Flux: the
567 // (HasPointwiseProjection, cf. core/physical_model.hpp) ; vide sinon -> le stepper ne l'interroge
582// Per-flux limiter ladders, split out of make_block (ADC-335) so each flux's build_block leaves can be
583// instantiated in their OWN translation unit (python/system_compressible_<flux>.cpp). Each body is the
584// VERBATIM content of make_block's old `if (riem == "<flux>")` branch (same capability if-constexpr,
585// same limiter ladder, same throws) -> bit-identical. make_block (below) is now a thin riem dispatcher
586// that calls these; it stays the entry point for the non-subdivided callers (exb/isothermal seams, the
587// .so/AOT loader path). The flux string is implied by which helper is called -> validation moves to the
619 // HLL (Harten-Lax-van Leer, 2 waves): less diffusive than Rusanov (dissipation ~ signed |sR-sL|
620 // instead of symmetric 2*max|v|), but does NOT require pressure (unlike HLLC/Roe) -- only SIGNED
621 // wave speeds model.wave_speeds. Available as soon as a model exposes its signed eigenvalues (the
622 // DSL emits wave_speeds as soon as a primitive 'p' is declared, even cold isothermal p=0 -> c=0 ->
623 // HLL degenerates to upwind, still less diffusive than Rusanov at the contact). Does NOT REQUIRE
625 // wave speeds but no pressure, where hllc/roe are rejected. Gated on the presence of wave_speeds
733 // CENTRALIZED VALIDATION (registry dispatch_tags.hpp) BEFORE the dispatch: same tag acceptances /
760 // SINGLE source: limiter_n_ghost(lim) (registry dispatch_tags.hpp). The default 2 (MUSCL) for an
762 // static_asserts below (this TU sees BOTH the registry AND the types) guarantee that the kLimiters
764 static_assert(limiter_n_ghost_ct("none") == NoSlope::n_ghost, "kLimiters[none].n_ghost drifted");
769 static_assert(limiter_n_ghost_ct("weno5") == Weno5::n_ghost, "kLimiters[weno5].n_ghost drifted");
842std::function<Real(const MultiFab&)> make_source_frequency(const Model& m, const GridContext& ctx) {
874std::pair<std::function<void(const double*, double*)>, std::function<void(const double*, double*)>>
BoxArray: the set of boxes tiling a level (disjoint, covering).
ConstArray4 const_array() const
READ handle (POD device-copyable) over this Fab. Valid as long as the Fab lives.
Definition fab2d.hpp:96
Array4 array()
WRITE handle (POD device-copyable) over this Fab. Valid as long as the Fab lives.
Definition fab2d.hpp:91
Field distributed over a level: decomposition (BoxArray) + distribution (DistributionMapping) + ncomp...
Definition multifab.hpp:33
Fab2D & fab(int li)
Local fab at index li (0 <= li < local_size()), for writing.
Definition multifab.hpp:67
const DistributionMapping & dmap() const
GLOBAL distribution (owner rank per box).
Definition multifab.hpp:58
const BoxArray & box_array() const
GLOBAL decomposition of the level (all boxes, all ranks).
Definition multifab.hpp:56
const Box2D & box(int li) const
VALID box of local fab li.
Definition multifab.hpp:71
int local_size() const
Number of fabs OWNED by this rank (bound on local indices).
Definition multifab.hpp:65
POPS_COLD_FN: opt out the COLD host factories from the optimizer (ADC-337, P1-B).
HLLC capability: the model provides the CONTACT wave speed and the STAR STATE on side k.
Definition numerical_flux.hpp:142
OPTIONAL extension of a PhysicalModel: primitive variables + cons<->prim conversions.
Definition physical_model.hpp:167
Roe capability: the model provides its FULL Roe dissipation d = |A_roe(UL, UR)| (UR - UL) – Roe avera...
Definition numerical_flux.hpp:156
OPTIONAL trait: local source frequency mu [1/s] (bound dt <= cfl / max mu, without h).
Definition physical_model.hpp:137
OPTIONAL trait: direct admissible step per cell (bound dt <= min stability_dt, without cfl).
Definition physical_model.hpp:143
OPTIONAL trait: stability speed lambda* replacing max_wave_speed in the block CFL.
Definition physical_model.hpp:131
SINGLE registry of spatial scheme tags (limiters + Riemann fluxes): shared source of truth for ALL di...
Generic EMBEDDED-BOUNDARY / LEVEL-SET DOMAIN contract (ADC-327).
for_each_cell and reductions: the parallelism SEAM over the cells of a Box2D; sync_host / sync_device...
Geometry: index-space (Box2D) <-> Cartesian physical-space mapping; PolarGeometry: SIBLING for a glob...
Block grid context plus closures, shared between System (which installs them) and block_builder....
Implicit / IMEX block step as a named CONTRACT.
MultiFab: a field DISTRIBUTED over a level (equivalent of AMReX's MultiFab).
POPS_HD DiscLevelSet disc_level_set(const DiscDomain &d)
Builds the disc level set callable from a DiscDomain (sugar: disc_level_set(d)).
Definition operator.hpp:122
Definition amr_hierarchy.hpp:29
int block_n_ghost(const std::string &lim)
Number of ghosts required by the spatial scheme lim (single source: Limiter::n_ghost).
Definition block_builder.hpp:759
std::function< Real(const MultiFab &)> make_stability_dt(const Model &m, const GridContext &ctx)
Closure of the block min admissible step (bound dt <= stability_dt * substeps / stride,...
Definition block_builder.hpp:852
void throw_registry_dispatch_mismatch(const char *ctx, const char *kind, const std::string &tag)
DEFENSE-IN-DEPTH guard: reached only if a VALID tag (already accepted by validate_*) is routed by NO ...
Definition dispatch_tags.hpp:138
void validate_riemann(const std::string &riem, bool polar=false, const char *ctx="System")
Validates a Riemann FLUX tag against kRiemanns.
Definition dispatch_tags.hpp:111
constexpr int limiter_n_ghost_ct(const char *lim)
COMPILE-TIME variant of limiter_n_ghost (const char* literal): -1 if unknown.
Definition dispatch_tags.hpp:88
void for_each_cell(const Box2D &b, F f)
Applies f to EACH cell (i, j) of box b (bounds inclusive), via Kokkos::parallel_for (Serial / OpenMP ...
Definition for_each.hpp:138
void max_wave_speed_hotspot_mf(const Model &model, const MultiFab &U, const MultiFab &aux, int nx, Real &w_out, int &i_out, int &j_out)
dt_hotspot diagnostic (ADC-182): the cell (GLOBAL indices) that dominates the block's transport CFL b...
Definition wave_speed.hpp:109
POPS_HD Aux load_aux(const ConstArray4 &a, int i, int j)
load_aux<NComp>: reads NComp components of the auxiliary from an Array4 at (i,j).
Definition state_access.hpp:141
POPS_COLD_FN BlockClosures make_block_hll(const Model &m, const std::string &lim, const GridContext &ctx, bool imex, bool recon_prim, const std::string &method, const std::vector< int > &implicit_components, const NewtonOptions &newton_opts, NewtonReport *newton_report, Real pos_floor, bool wave_speed_cache)
Definition block_builder.hpp:612
void backward_euler_source(const Model &model, const MultiFab &aux, MultiFab &U, Real dt, const NewtonOptions &opts, const ImplicitMask< Model::n_vars > &mask={}, NewtonReport *report=nullptr)
Definition implicit_stepper.hpp:486
void validate_limiter(const std::string &lim, const char *ctx="System")
Validates a LIMITER tag against kLimiters.
Definition dispatch_tags.hpp:99
void saxpy(MultiFab &y, Real a, const MultiFab &x)
y <- y + a x over ALL components of the valid cells. Identical layouts required.
Definition mf_arith.hpp:102
Real min_stability_dt_mf(const Model &model, const MultiFab &U, const MultiFab &aux)
Global min of the declared admissible step (HasStabilityDt trait), via max(1/dt) (cf.
Definition wave_speed.hpp:222
POPS_COLD_FN BlockClosures make_block(const Model &m, const std::string &lim, const std::string &riem, const GridContext &ctx, bool imex, bool recon_prim, const std::string &method="ssprk2", const std::vector< int > &implicit_components={}, const NewtonOptions &newton_opts={}, NewtonReport *newton_report=nullptr, Real pos_floor=Real(0), bool wave_speed_cache=false)
Definition block_builder.hpp:726
Real max_source_frequency_mf(const Model &model, const MultiFab &U, const MultiFab &aux)
Global max of the source frequency (HasSourceFrequency trait). 0 if the source does not constrain.
Definition wave_speed.hpp:209
int limiter_n_ghost(const std::string &lim)
Halo width required by the limiter lim (source: kLimiters).
Definition dispatch_tags.hpp:65
void lincomb(MultiFab &z, Real a, const MultiFab &x, Real b, const MultiFab &y)
z <- a x + b y over ALL components of the valid cells. Identical layouts; aliasing safe.
Definition mf_arith.hpp:133
POPS_COLD_FN BlockClosures make_block_roe(const Model &m, const std::string &lim, const GridContext &ctx, bool imex, bool recon_prim, const std::string &method, const std::vector< int > &implicit_components, const NewtonOptions &newton_opts, NewtonReport *newton_report, Real pos_floor)
Definition block_builder.hpp:691
POPS_COLD_FN BlockClosures build_block(const Model &m, const GridContext &ctx, bool imex, bool recon_prim, const std::string &method="ssprk2", const std::vector< int > &implicit_components={}, const NewtonOptions &newton_opts={}, NewtonReport *newton_report=nullptr, Real pos_floor=Real(0), bool wave_speed_cache=false)
Closures (advance + residual) for a frozen spatial scheme (Limiter x Flux).
Definition block_builder.hpp:475
std::function< void(const MultiFab &, MultiFab &)> make_poisson_rhs(const Model &m)
Block contribution to the Poisson right-hand side: rhs += elliptic_rhs(U) (host loop).
Definition block_builder.hpp:861
POPS_COLD_FN ImplicitMask< N > make_implicit_mask(const std::vector< int > &implicit_components)
Builds the device-clean POD implicit mask of an N-variable model from a list of component indices (em...
Definition block_builder.hpp:444
std::function< Real(const MultiFab &)> make_max_speed(const Model &m, const GridContext &ctx)
Closure of the speed used by the block CFL step.
Definition block_builder.hpp:831
Real max_stability_speed_mf(const Model &model, const MultiFab &U, const MultiFab &aux)
Global max of the STABILITY speed (HasStabilitySpeed trait) – counterpart of max_wave_speed_mf.
Definition wave_speed.hpp:197
std::function< Real(const MultiFab &)> make_source_frequency(const Model &m, const GridContext &ctx)
Closure of the block max source frequency (bound dt <= cfl * substeps / (stride * mu)).
Definition block_builder.hpp:842
POPS_COLD_FN BlockClosures make_block_rusanov(const Model &m, const std::string &lim, const GridContext &ctx, bool imex, bool recon_prim, const std::string &method, const std::vector< int > &implicit_components, const NewtonOptions &newton_opts, NewtonReport *newton_report, Real pos_floor)
Dispatch of the spatial scheme (limiter x Riemann flux) -> compiled closures.
Definition block_builder.hpp:590
POPS_COLD_FN BlockClosures make_block_hllc(const Model &m, const std::string &lim, const GridContext &ctx, bool imex, bool recon_prim, const std::string &method, const std::vector< int > &implicit_components, const NewtonOptions &newton_opts, NewtonReport *newton_report, Real pos_floor)
Definition block_builder.hpp:655
void fill_ghosts(MultiFab &mf, const Box2D &domain, const BCRec &bc)
COMPLETE ghost filling: fill_boundary (interior + periodic, periodicity deduced from bc) THEN fill_ph...
Definition physical_bc.hpp:227
std::pair< std::function< void(const double *, double *)>, std::function< void(const double *, double *)> > make_cell_convert(const Model &m)
PER-CELL (one cell) cons <-> prim conversions of the MODEL, type-erased over arrays of Model::n_vars ...
Definition block_builder.hpp:875
Real max_wave_speed_mf(const Model &model, const MultiFab &U, const MultiFab &aux)
max_wave_speed_mf: global max of the wave speed over the whole MultiFab (CFL).
Definition wave_speed.hpp:66
Single-interface numerical flux policies: Rusanov, HLL, HLLC, Roe.
CUT-CELL / EMBEDDED BOUNDARY (EB) spatial operator: R = -div_eb F + S on a disc, in CONSERVATIVE fini...
PHYSICAL boundary conditions at the domain edge (BCType, BCRec, fill_physical_bc, fill_ghosts).
Interface reconstruction policies: MUSCL limiters and WENO5-Z.
Cartesian spatial operator: assembles R(U, aux) = -div F + S over the cells of a level.
WRITE POD handle (raw pointer + strides) over a Fab2D buffer, indexed by (i, j, c) IN GLOBAL INDICES ...
Definition fab2d.hpp:29
POINTWISE auxiliary fields shared with the physics: single coupling channel.
Definition state.hpp:123
POPS_HD int nx() const
Width (direction 0). POPS_HD (called from Geometry::dx() in a device kernel).
Definition box2d.hpp:50
READ-only handle (const counterpart of Array4): same layout and same contract (POD device-copyable,...
Definition fab2d.hpp:44
Definition time_steppers.hpp:39
void take_step(RhsEval &&rhs, MultiFab &U, Real dt, Scratch &s) const
Definition time_steppers.hpp:48
Mesh + transport BC + aux shared by a block closures.
Definition grid_context.hpp:41
const MultiFab * domain_mask
0/1 domain mask (Impl::domain_mask_); NOT owned
Definition grid_context.hpp:46
const detail::DiscDomain * eb_domain
level-set domain descriptor (Impl::eb_domain_); NOT owned
Definition grid_context.hpp:47
MultiFab * aux
System aux (phi, grad phi); NOT owned.
Definition grid_context.hpp:45
Definition implicit_stepper.hpp:84
Options of the local Newton of the implicit source (backward-Euler).
Definition implicit_stepper.hpp:114
AGGREGATED report (whole block, all substeps of one advance) of the implicit-source Newton.
Definition implicit_stepper.hpp:165
SourceFreeModel<M>: adapter that cancels the source of M (explicit IMEX half-step).
Definition state_access.hpp:50
CUT-CELL / EB EXPLICIT advance: n substeps of the Stepper stepper on the EB transport residual.
Definition block_builder.hpp:372
Real pos_floor
Zhang-Shu positivity limiter (<= 0: inactive, bit-identical)
Definition block_builder.hpp:377
const DiscDomain * eb_domain
Definition block_builder.hpp:375
void operator()(MultiFab &U, Real dt, int n) const
Definition block_builder.hpp:378
MASKED EXPLICIT advance: n substeps of the Stepper stepper on the MASKED transport residual.
Definition block_builder.hpp:356
Real pos_floor
Zhang-Shu positivity limiter (<= 0: inactive, bit-identical)
Definition block_builder.hpp:361
void operator()(MultiFab &U, Real dt, int n) const
Definition block_builder.hpp:362
EXPLICIT advance: n substeps of the Stepper stepper (SSPRK2 by default, SSPRK3 optional) on the trans...
Definition block_builder.hpp:88
Real pos_floor
Zhang-Shu positivity limiter (<= 0: inactive, bit-identical)
Definition block_builder.hpp:92
void operator()(MultiFab &U, Real dt, int n) const
Definition block_builder.hpp:94
std::shared_ptr< MultiFab > ws_cache
HLL wave speed cache (opt-in); nullptr -> per-face path.
Definition block_builder.hpp:93
CUT-CELL / EB IMEX advance: EB EXPLICIT half-step (source-free transport) + stiff IMPLICIT source.
Definition block_builder.hpp:416
void operator()(MultiFab &U, Real dt, int n) const
Definition block_builder.hpp:425
Real pos_floor
Zhang-Shu positivity limiter (<= 0: inactive)
Definition block_builder.hpp:424
ImplicitMask< Model::n_vars > mask_impl
Definition block_builder.hpp:421
MASKED IMEX advance: MASKED EXPLICIT half-step (source-free transport) + stiff IMPLICIT source.
Definition block_builder.hpp:391
ImplicitMask< Model::n_vars > mask_impl
Definition block_builder.hpp:396
Real pos_floor
Zhang-Shu positivity limiter (<= 0: inactive)
Definition block_builder.hpp:399
void operator()(MultiFab &U, Real dt, int n) const
Definition block_builder.hpp:400
IMEX-RK ARS(2,2,2) advance (Ascher, Ruuth, Spiteri 1997; "Implicit-explicit Runge-Kutta methods for t...
Definition block_builder.hpp:164
void operator()(MultiFab &U, Real dt, int n) const
Definition block_builder.hpp:171
Real pos_floor
Zhang-Shu positivity limiter (<= 0: inactive)
Definition block_builder.hpp:170
IMEX advance: per substep, EXPLICIT half-step (source-free transport) + stiff IMPLICIT source.
Definition block_builder.hpp:106
Real pos_floor
Zhang-Shu positivity limiter (<= 0: inactive)
Definition block_builder.hpp:113
void operator()(MultiFab &U, Real dt, int n) const
Definition block_builder.hpp:114
CUT-CELL / EB transport residual (CutCell mode): fill_ghosts then assemble_rhs_eb on the level set of...
Definition block_builder.hpp:340
void operator()(MultiFab &U, MultiFab &R) const
Definition block_builder.hpp:346
Real pos_floor
Zhang-Shu positivity limiter (<= 0: inactive, bit-identical)
Definition block_builder.hpp:345
MASKED transport residual (Staircase mode): fill_ghosts then assemble_rhs_masked on the cell-centered...
Definition block_builder.hpp:319
void operator()(MultiFab &U, MultiFab &R) const
Definition block_builder.hpp:325
Real pos_floor
Zhang-Shu positivity limiter (<= 0: inactive, bit-identical)
Definition block_builder.hpp:324
Residual functor -div F + S (fill_ghosts then assemble_rhs), passed TO THE TimeStepper as RhsEval.
Definition block_builder.hpp:57
std::shared_ptr< MultiFab > ws_cache
Per-cell wave speed scratch (HLL cache, opt-in).
Definition block_builder.hpp:65
Real pos_floor
Zhang-Shu positivity limiter (<= 0: inactive, bit-identical)
Definition block_builder.hpp:61
void operator()(MultiFab &U, MultiFab &R) const
Definition block_builder.hpp:66
CIRCLE / DISC level-set domain: the canonical instance of the contract and the SINGLE SOURCE of truth...
Definition domain.hpp:69
Frozen residual (fill_ghosts + assemble_rhs) installed as the block's rhs_into.
Definition block_builder.hpp:212
void operator()(const MultiFab &U, Real &w, int &i, int &j) const
Definition block_builder.hpp:215
Block max source frequency functor (HasSourceFrequency trait, bound dt <= cfl/mu without h).
Definition block_builder.hpp:795
Real operator()(const MultiFab &U) const
Definition block_builder.hpp:798
Block max wave speed functor (max_wave_speed_mf, reduction over the seam).
Definition block_builder.hpp:778
Real operator()(const MultiFab &U) const
Definition block_builder.hpp:781
Block max STABILITY speed functor (HasStabilitySpeed trait): replaces MaxSpeed in the CFL when the mo...
Definition block_builder.hpp:787
Real operator()(const MultiFab &U) const
Definition block_builder.hpp:790
Block min admissible step functor (HasStabilityDt trait; 0 = no cell constrains it).
Definition block_builder.hpp:803
Real operator()(const MultiFab &U) const
Definition block_builder.hpp:806
Foncteur HOTE de la projection ponctuelle : for_each_cell du kernel sur les cellules VALIDES de chaqu...
Definition block_builder.hpp:243
void operator()(MultiFab &U) const
Definition block_builder.hpp:246
Poisson contribution functor: rhs += elliptic_rhs(U) (pure HOST loop, no device kernel).
Definition block_builder.hpp:811
void operator()(const MultiFab &U, MultiFab &rhs) const
Definition block_builder.hpp:813
Kernel device de la PROJECTION PONCTUELLE post-pas (ADC-177) : U(i, j) <- m.project(U(i,...
Definition block_builder.hpp:225
POPS_HD void operator()(int i, int j) const
Definition block_builder.hpp:230
Definition block_builder.hpp:255
std::shared_ptr< MultiFab > ws_cache
HLL wave speed cache (opt-in); nullptr -> per-face path.
Definition block_builder.hpp:260
Real pos_floor
Zhang-Shu positivity limiter (<= 0: inactive, bit-identical)
Definition block_builder.hpp:259
void operator()(MultiFab &U, MultiFab &R) const
Definition block_builder.hpp:261
SOURCE-ONLY residual R <- S(U, aux) installed as the block's source_only closure (ADC-430).
Definition block_builder.hpp:294
void operator()(MultiFab &U, MultiFab &R) const
Definition block_builder.hpp:297
SOURCE-ONLY residual kernel R(i,j) <- m.source(U(i,j), aux(i,j)): the EXACT source term of AssembleRh...
Definition block_builder.hpp:273
POPS_HD void operator()(int i, int j) const
Definition block_builder.hpp:278
Time integrators as first-class OBJECTS with a take_step method: TimeStepper concept,...
Base scalar types and the POPS_HD macro (host+device portability).
Generated by