include/pops/runtime/builders/block/block_seam.hpp Source FileΒΆ

adc_cpp: include/pops/runtime/builders/block/block_seam.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_seam.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <pops/core/state/variables.hpp> // VariableSet (block descriptor carried in BuiltBlock)
4#include <pops/runtime/builders/block/block_builder.hpp> // make_block + makers + BlockClosures + NewtonOptions/Report
5#include <pops/runtime/builders/block/block_builder_polar.hpp> // make_block_polar + polar makers + PolarGridContext
6#include <pops/runtime/builders/factory/model_factory.hpp> // dispatch_model_for + resolve_implicit_components + ModelSpec
7
8#include <functional>
9#include <string>
10#include <utility>
11#include <vector>
12
29
30namespace pops::detail {
31
35struct BuiltBlock {
36 int ncomp = 1;
39 std::function<Real(const MultiFab&)> max_speed;
40 std::function<void(const MultiFab&, MultiFab&)> add_poisson_rhs;
41 std::function<Real(const MultiFab&)> src_freq, stab_dt; // optional step bounds (model traits)
42 std::function<void(const double*, double*)> prim_to_cons, cons_to_prim; // System::CellConvert
44 0; // aux_comps<Model>() (Cartesian); unused on the polar path (no ensure_aux_width)
45};
46
51 std::string name;
52 std::string limiter;
53 std::string riemann;
55 bool imex;
57 std::string method;
58 std::vector<std::string> implicit_vars;
59 std::vector<std::string> implicit_roles;
61 NewtonReport* nreport; // non-owning (report lives in System::Impl::newton_reports_)
64};
65
72template <class TR, class MakeFn>
74 MakeFn make) {
75 BuiltBlock out;
76 dispatch_model_for(model, std::move(tr), [&](auto m) {
77 using M = decltype(m);
78 out.ncomp = M::n_vars;
79 out.cons_vs = M::conservative_vars(); // names + physical ROLES (single source of truth)
80 out.prim_vs = M::primitive_vars();
81 // AUX WIDTH of the composed model (n_aux > 3 for a magnetized brick reading B_z): returned so
82 // add_block widens the SHARED channel host-side (ensure_aux_width preserves the aux ADDRESS captured
83 // by the closures, so applying it after make_block is equivalent).
84 out.aux_width = aux_comps<M>();
85 const std::vector<int> impl_components =
87 out.clo = make(m, impl_components, a);
88 out.max_speed = make_max_speed(m, a.ctx);
91 out.stab_dt = make_stability_dt(m, a.ctx);
92 auto conv = make_cell_convert(m);
93 out.prim_to_cons = std::move(conv.first);
94 out.cons_to_prim = std::move(conv.second);
95 });
96 return out;
97}
98
101template <class TR>
102BuiltBlock build_block_for(TR tr, const ModelSpec& model, const BlockBuildArgs& a) {
104 std::move(tr), model, a, [](auto m, const std::vector<int>& impl, const BlockBuildArgs& aa) {
105 return make_block(m, aa.limiter, aa.riemann, aa.ctx, aa.imex, aa.recon_prim, aa.method,
106 impl, aa.nopts, aa.nreport, aa.positivity_floor, aa.wave_speed_cache);
107 });
108}
109
110// Per-transport seam functions (defined in python/system_<transport>.cpp). The TR construction matches
111// dispatch_transport's branches VERBATIM (ExBVelocity{B0} / CompressibleFlux{gamma} /
112// IsothermalFlux{cs2, vacuum_floor}).
114
115// Isothermal (3-var fluid) carries two reachable fluxes (rusanov + hll; hllc/roe need 4-var + pressure)
116// x 4 limiters x 15 models -- the post-split long pole -- so it is FLUX-SUBDIVIDED like compressible
117// (ADC-342): one .cpp per reachable flux. System dispatches on the riemann string; an unsupported flux
118// (incl. hllc/roe) is caught by the shared validate_riemann + the registry throw.
121
122// Compressible (Euler, 4-var + pressure) is the heaviest transport: all four fluxes are valid, so it is
123// FLUX-SUBDIVIDED into one .cpp per flux (ADC-335) -- each instantiates only its flux's build_block
124// leaves, so they compile in parallel. System dispatches on the riemann string to the right one (every
125// flux is valid for Euler, so no capability rejection to reproduce; an unknown flux is caught by the
126// shared validate_riemann + the registry throw, same wording as make_block).
131
132// Polar (ring) seam: VERBATIM polar visitor body (make_block_polar + polar makers). IMEX is rejected on
133// the ring by add_block before this is called. @p aux is &System::Impl::aux (the polar makers read it).
134BuiltBlock build_block_polar(const ModelSpec& model, const std::string& limiter,
135 const std::string& riemann, const PolarGridContext& pctx,
136 bool recon_prim, const std::string& method, Real positivity_floor,
137 const MultiFab* aux);
138
139} // namespace pops::detail
Builds the closures of a block (time advance + residual + Poisson contribution) from a COMPILED model...
POLAR counterpart of block_builder.hpp: builds a block's closures (time advance + residual + Poisson ...
Field distributed over a level: decomposition (BoxArray) + distribution (DistributionMapping) + ncomp...
Definition multifab.hpp:33
Assemble a CompositeModel from a ModelSpec (bricks + parameters).
Definition cluster.hpp:37
BuiltBlock build_block_compressible_roe(const ModelSpec &model, const BlockBuildArgs &a)
BuiltBlock build_block_isothermal_hll(const ModelSpec &model, const BlockBuildArgs &a)
BuiltBlock build_block_compressible_hllc(const ModelSpec &model, const BlockBuildArgs &a)
BuiltBlock build_block_for_make(TR tr, const ModelSpec &model, const BlockBuildArgs &a, MakeFn make)
VERBATIM Cartesian visitor body of the former dispatch_model lambda (system.cpp), with the transport ...
Definition block_seam.hpp:73
BuiltBlock build_block_compressible_hll(const ModelSpec &model, const BlockBuildArgs &a)
POPS_COLD_FN void dispatch_model_for(const ModelSpec &m, TR tr, Visitor &&visitor)
Same as dispatch_model but with the transport brick ALREADY chosen (tr).
Definition model_factory.hpp:196
POPS_COLD_FN std::vector< int > resolve_implicit_components(const std::string &block, const VariableSet &cons, const std::vector< std::string > &names, const std::vector< std::string > &roles)
Resolves the IMPLICIT MASK of a block (add_block: implicit_vars / implicit_roles) into a list of cons...
Definition model_factory.hpp:213
BuiltBlock build_block_exb(const ModelSpec &model, const BlockBuildArgs &a)
BuiltBlock build_block_isothermal_rusanov(const ModelSpec &model, const BlockBuildArgs &a)
BuiltBlock build_block_polar(const ModelSpec &model, const std::string &limiter, const std::string &riemann, const PolarGridContext &pctx, bool recon_prim, const std::string &method, Real positivity_floor, const MultiFab *aux)
BuiltBlock build_block_compressible_rusanov(const ModelSpec &model, const BlockBuildArgs &a)
BuiltBlock build_block_for(TR tr, const ModelSpec &model, const BlockBuildArgs &a)
Per-transport seam body: the full make_block dispatcher (all fluxes).
Definition block_seam.hpp:102
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
double Real
Definition types.hpp:30
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
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
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
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
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
Compiled block closures, frozen at add time.
Definition grid_context.hpp:61
Mesh + transport BC + aux shared by a block closures.
Definition grid_context.hpp:41
Brick composition of a block plus parameters.
Definition model_spec.hpp:27
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
POLAR mesh + transport BC + aux shared by a block's closures (counterpart of GridContext).
Definition block_builder_polar.hpp:49
A model's variable set: kind (cons/prim), names, size, canonical roles (optional, parallel to names; ...
Definition variables.hpp:58
The non-model inputs of a Cartesian block build (a thin bundle so the seam signature stays fixed).
Definition block_seam.hpp:50
bool wave_speed_cache
Definition block_seam.hpp:63
std::string limiter
Definition block_seam.hpp:52
std::string method
Definition block_seam.hpp:57
bool recon_prim
Definition block_seam.hpp:56
std::vector< std::string > implicit_vars
Definition block_seam.hpp:58
std::string name
Definition block_seam.hpp:51
GridContext ctx
Definition block_seam.hpp:54
std::vector< std::string > implicit_roles
Definition block_seam.hpp:59
NewtonReport * nreport
Definition block_seam.hpp:61
std::string riemann
Definition block_seam.hpp:53
NewtonOptions nopts
Definition block_seam.hpp:60
bool imex
Definition block_seam.hpp:55
Real positivity_floor
Definition block_seam.hpp:62
Everything System::add_block reads back from the (former) dispatch_model visitor.
Definition block_seam.hpp:35
int ncomp
Definition block_seam.hpp:36
VariableSet prim_vs
Definition block_seam.hpp:37
VariableSet cons_vs
Definition block_seam.hpp:37
int aux_width
Definition block_seam.hpp:43
std::function< void(const double *, double *)> cons_to_prim
Definition block_seam.hpp:42
std::function< void(const MultiFab &, MultiFab &)> add_poisson_rhs
Definition block_seam.hpp:40
std::function< void(const double *, double *)> prim_to_cons
Definition block_seam.hpp:42
std::function< Real(const MultiFab &)> max_speed
Definition block_seam.hpp:39
BlockClosures clo
Definition block_seam.hpp:38
std::function< Real(const MultiFab &)> src_freq
Definition block_seam.hpp:41
std::function< Real(const MultiFab &)> stab_dt
Definition block_seam.hpp:41
Descriptor of a model's variables (Vars).