include/pops/runtime/program/external_riemann_brick.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
|
external_riemann_brick.hpp
Go to the documentation of this file.
5// `external_brick.hpp` owns the HOST IDENTITY catalog: `POPS_REGISTER_BRICK` records a brick's id +
7// requirement-carrying `riemann.User(id)` descriptor. This header owns the NUMERICAL half: how the
11// The flux of an external brick is a `NumericalFlux` policy (numerics/fv/numerical_flux.hpp) living
12// in a SEPARATE `.so`, so it can never be a compile-time template parameter of the host's pre-built
16// `build_block<Limiter, UserFlux>(...)` -- the user flux is a compile-time template parameter inside
17// the `.so`, fully inlined, exactly like a native flux's `build_block` leaf. The host dlopens the
18// `.so`, resolves that entry-point function pointer ONCE at install time, and calls it; the per-cell
19// kernel then runs the statically-instantiated `UserFlux` functor with NO string comparison on the
20// hot path. The only string is the limiter (a 4-way `if` resolved once per install, mirroring the
23// ABI (flat double arrays, component-major c*n*n + j*n + i, like System::copy_state): identical to
24// the AOT compiled block (compiled_block_abi.hpp) so the host marshals an external brick the same
30#include <pops/runtime/builders/compiled/compiled_block_abi.hpp> // compiled_block::{make_grid,...}
31#include <pops/runtime/builders/block/block_builder.hpp> // build_block<Limiter, Flux>, block_n_ghost
46// COMPILE-TIME template parameter of build_block (the same leaf the native string ladder routes to),
47// so it is fully inlined; the only runtime branch is the limiter (resolved ONCE here, not per cell).
68// One explicit residual R = -div F(U) + S evaluated with the external flux @p Flux on @p Model. Same
69// marshaling as compiled_block::residual (flat arrays, local single-grid mesh, aux from the host) --
92// manifest, and resolve the typed entry-point function pointers ONCE. After construction the brick
94// statically-instantiated flux, never a per-cell string lookup. The manifest is also registered in
95// the process catalog (BrickRegistry) so the brick's id + requirements are visible to a later host
98// This is the C++ counterpart of pops.lib.load_cpp_library: the Python path surfaces the descriptor
99// (requirements/capabilities) for the board/install layer; this path resolves the numerical entry
100// point for a host that drives the brick from C++. A brick `.so` not exporting the expected symbols
104 // Function-pointer type of the brick's residual entry point (POPS_DEFINE_EXTERNAL_RIEMANN_BRICK).
108 // dlopen @p so_path, read + register its manifest, and resolve the entry points for brick @p id.
109 // Throws std::runtime_error if the library cannot be opened, does not export pops_brick_manifest /
110 // pops_brick_residual (not an pops external Riemann brick), or does not register @p id as a riemann
123 // The .so's static initializers already ran POPS_REGISTER_BRICK against the registry of the .so's
124 // OWN image; reading its manifest and re-registering here makes the ids visible in THIS image's
150 // The resolved residual entry point: a direct call into the `.so`'s statically-instantiated flux.
159 // Minimal manifest reader: parse the {"bricks":[{"id","category","requirements",...}]} the `.so`
160 // exports and register each entry. A header-only sibling of lib.py's _register_manifest; it accepts
161 // exactly the JSON to_json() emits (flat string fields, no nesting). A malformed manifest throws.
166 // to_json() emits {"bricks":[{...},{...}]}: skip past the array's '[' (the top-level object's '{'
167 // precedes it), then read each {...} brick record until the array closes. An empty array ([]) or a
192 // Extracts the value of "key":"value" from one manifest record (the fields to_json() emits are flat
193 // quoted strings; this is a targeted reader, not a general JSON parser). It skips backslash-escaped
219// Defines the static-dispatch ABI of an external Riemann brick `.so`: registers its identity in the
221// struct MyRiemann { template <class M> POPS_HD typename M::State operator()(...) const {...} };
234// The emitted pops_brick_residual instantiates build_block<Limiter, Flux> at the .so's compile time:
236// pops_brick_naux let the host size its marshaling arrays (same role as pops_compiled_nvars/_naux).
238// ABI WARNING: the brick `.so` MUST be compiled against the SAME Kokkos backend and version (and the
240// runtime. A mismatched `.so` may dlopen yet fail unpredictably. There is no load-time Kokkos-ABI
Builds the closures of a block (time advance + residual + Poisson contribution) from a COMPILED model...
Field distributed over a level: decomposition (BoxArray) + distribution (DistributionMapping) + ncomp...
Definition multifab.hpp:33
void register_brick(const BrickManifestEntry &entry)
Definition external_brick.hpp:132
const BrickManifestEntry * lookup(const std::string &id) const
Definition external_brick.hpp:144
static BrickRegistry & instance()
Definition external_brick.hpp:125
Definition external_riemann_brick.hpp:102
~ExternalBrickHandle()
Definition external_riemann_brick.hpp:145
ResidualFn residual() const
Definition external_riemann_brick.hpp:151
ExternalBrickHandle(const ExternalBrickHandle &)=delete
const std::string & id() const
Definition external_riemann_brick.hpp:156
void(*)(const double *, double *, const double *, int, double, double, int, const char *, int, double) ResidualFn
Definition external_riemann_brick.hpp:106
ExternalBrickHandle & operator=(const ExternalBrickHandle &)=delete
const std::string & requirements() const
Definition external_riemann_brick.hpp:154
ExternalBrickHandle(const std::string &so_path, const std::string &id)
Definition external_riemann_brick.hpp:112
C ABI of an AOT-COMPILED block: a model generated by the DSL, compiled ahead-of-time into a ....
SINGLE registry of spatial scheme tags (limiters + Riemann fluxes): shared source of truth for ALL di...
PORTABLE dynamic loading: dlopen/dlsym/dlclose (POSIX) <-> LoadLibraryW/ GetProcAddress/FreeLibrary (...
LocalGrid make_grid(int n, double dx, double dy, bool periodic, const double *aux_in, int naux)
naux = width of the aux channel the model READS (aux_comps<Model>(), >= 3).
Definition compiled_block_abi.hpp:54
void extract(const MultiFab &mf, double *out, int n, int nv)
Copies the INTERIOR of fab(0) (nv components) into the component-major flat array out.
Definition compiled_block_abi.hpp:112
void fill_interior(MultiFab &mf, const double *in, int n, int nv)
Copies nv components of the component-major flat array in into the INTERIOR of fab(0) (without touchi...
Definition compiled_block_abi.hpp:100
std::string last_error()
Last error message (best-effort, for diagnostics).
Definition dynlib.hpp:87
handle open(const std::string &path)
Opens a dynamic library (path in UTF-8). Returns a null handle on failure.
Definition dynlib.hpp:48
void * sym(handle h, const char *name)
Resolves name in h. Returns nullptr if absent.
Definition dynlib.hpp:62
BlockClosures external_make_block(const Model &m, const std::string &lim, const GridContext &ctx, bool recon_prim, Real pos_floor)
Definition external_riemann_brick.hpp:50
void external_residual(const double *U, double *R, const double *aux_in, int n, double dx, double dy, bool periodic, const std::string &lim, bool recon_prim, double pos_floor)
Definition external_riemann_brick.hpp:73
Definition cache_manager.hpp:37
std::string json_unescape(const std::string &s)
Definition external_brick.hpp:68
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
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_limiter(const std::string &lim, const char *ctx="System")
Validates a LIMITER tag against kLimiters.
Definition dispatch_tags.hpp:99
Interface reconstruction policies: MUSCL limiters and WENO5-Z.
std::function< void(MultiFab &, MultiFab &)> rhs_into
R <- -div F + S (Poisson frozen)
Definition grid_context.hpp:66
Mesh + transport BC + aux shared by a block closures.
Definition grid_context.hpp:41
Local single-grid mesh rebuilt inside the .so + aux filled from the System array.
Definition compiled_block_abi.hpp:40
Definition external_brick.hpp:110
std::string capabilities
Definition external_brick.hpp:114
std::string category
Definition external_brick.hpp:112
std::string requirements
Definition external_brick.hpp:113
Generated by