include/pops/runtime/builders/compiled/compiled_block_abi.hpp Source FileΒΆ

adc_cpp: include/pops/runtime/builders/compiled/compiled_block_abi.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
compiled_block_abi.hpp
Go to the documentation of this file.
1#pragma once
2
4
8#include <pops/mesh/execution/for_each.hpp> // device_fence: barrier before host read (unified memory)
12
13#include <pops/core/model/physical_model.hpp> // aux_comps<Model>: aux channel width of the generated model
14#include <pops/core/state/variables.hpp> // roles_meta<Model>: conservative/primitive role CSV (manifest)
15#include <pops/runtime/config/runtime_params.hpp> // RuntimeParams: RUNTIME params (P7-b) carried by the ABI
16#include <pops/runtime/module_capabilities.hpp> // kAbiVersion: per-artifact ABI revision (manifest)
17
18#include <string>
19#include <type_traits>
20#include <utility>
21
36
38
40struct LocalGrid {
47 MultiFab aux; // naux comp (phi, grad phi, [B_z, T_e...]), 1 ghost
48};
49
54inline LocalGrid make_grid(int n, double dx, double dy, bool periodic, const double* aux_in,
55 int naux) {
56 Box2D dom = Box2D::from_extents(n, n);
57 Geometry geom{dom, 0.0, dx * n, 0.0, dy * n};
59 DistributionMapping dm(ba.size(), 1); // single-rank .so (prototype CPU block)
60 BCRec bc;
61 if (!periodic)
62 bc.xlo = bc.xhi = bc.ylo = bc.yhi = BCType::Foextrap;
63 MultiFab aux(ba, dm, naux, 1);
64 aux.set_val(0.0);
65 if (aux_in) { // aux interior from the array, then ghosts (same BCs as the System)
66 Array4 a = aux.fab(0).array();
67 const std::size_t nn = static_cast<std::size_t>(n) * n;
68 for (int c = 0; c < naux; ++c)
69 for (int j = 0; j < n; ++j)
70 for (int i = 0; i < n; ++i)
71 a(i, j, c) =
72 aux_in[static_cast<std::size_t>(c) * nn + static_cast<std::size_t>(j) * n + i];
73 if (periodic)
74 fill_boundary(aux, dom, Periodicity{true, true});
75 else
76 fill_ghosts(aux, dom, bc);
77 // ADC-369: per-field aux HALO override. The marshaled aux_in carries an APPEND-ONLY tail of
78 // 2*naux doubles AFTER the naux*nn valid cells: (type, value) per component (type 0 = none/inherit,
79 // 1 = Foextrap, 2 = Dirichlet -- pops::BCType). For each declared component, re-fill ITS physical-face
80 // ghosts with the field's own policy (aux_halo_override keeps periodic faces periodic, so a periodic
81 // domain is a no-op). The tail is appended by the System marshaling; an all-zero tail is bit-identical.
82 const std::size_t tail = static_cast<std::size_t>(naux) * nn;
83 for (int c = 0; c < naux; ++c) {
84 const int t = static_cast<int>(aux_in[tail + static_cast<std::size_t>(2) * c]);
85 if (t == static_cast<int>(BCType::Foextrap) || t == static_cast<int>(BCType::Dirichlet))
87 aux, dom,
89 bc, AuxHaloPolicy{static_cast<BCType>(t),
90 static_cast<Real>(
91 aux_in[tail + static_cast<std::size_t>(2) * c + 1])}),
92 c);
93 }
94 }
95 return LocalGrid{dom, geom, ba, dm, bc, periodic, std::move(aux)};
96}
97
100inline void fill_interior(MultiFab& mf, const double* in, int n, int nv) {
101 Array4 a = mf.fab(0).array();
102 const std::size_t nn = static_cast<std::size_t>(n) * n;
103 for (int c = 0; c < nv; ++c)
104 for (int j = 0; j < n; ++j)
105 for (int i = 0; i < n; ++i)
106 a(i, j, c) = in[static_cast<std::size_t>(c) * nn + static_cast<std::size_t>(j) * n + i];
107}
108
112inline void extract(const MultiFab& mf, double* out, int n, int nv) {
113 device_fence(); // assemble_rhs / advance have launched ASYNC kernels; wait before the host
114 // read of the unified memory (otherwise race -> partial result on GPU).
115 const ConstArray4 a = mf.fab(0).const_array();
116 const std::size_t nn = static_cast<std::size_t>(n) * n;
117 for (int c = 0; c < nv; ++c)
118 for (int j = 0; j < n; ++j)
119 for (int i = 0; i < n; ++i)
120 out[static_cast<std::size_t>(c) * nn + static_cast<std::size_t>(j) * n + i] = a(i, j, c);
121}
122
126template <class B, class = void>
127struct HasRuntimeParams : std::false_type {};
128template <class B>
129struct HasRuntimeParams<B, std::void_t<decltype(std::declval<B&>().params)>>
130 : std::is_same<std::decay_t<decltype(std::declval<B&>().params)>, RuntimeParams> {};
131
134template <class B>
135inline void apply_runtime_params(B& b, const RuntimeParams& rp) {
136 if constexpr (HasRuntimeParams<B>::value)
137 b.params = rp;
138}
139
145template <class Model>
146Model make_model_with_params(const double* pvals, int npar) {
147 Model model{};
148 if (pvals && npar > 0) {
149 RuntimeParams rp;
150 rp.count = npar > kMaxRuntimeParams ? kMaxRuntimeParams : npar;
151 for (int k = 0; k < rp.count; ++k)
152 rp.values[k] = static_cast<Real>(pvals[k]);
153 apply_runtime_params(model.hyp, rp);
154 apply_runtime_params(model.src, rp);
155 apply_runtime_params(model.ell, rp);
156 }
157 return model;
158}
159
162template <class B>
163inline int brick_nparams(const B& b) {
164 if constexpr (HasRuntimeParams<B>::value)
165 return b.params.count;
166 else {
167 (void)b;
168 return 0;
169 }
170}
171
175template <class Model>
176inline RuntimeParams model_params(const Model& model) {
177 if constexpr (HasRuntimeParams<std::decay_t<decltype(model.hyp)>>::value)
178 return model.hyp.params;
179 else if constexpr (HasRuntimeParams<std::decay_t<decltype(model.src)>>::value)
180 return model.src.params;
181 else if constexpr (HasRuntimeParams<std::decay_t<decltype(model.ell)>>::value)
182 return model.ell.params;
183 else {
184 (void)model;
185 return RuntimeParams{};
186 }
187}
188
192template <class Model>
193inline int model_nparams() {
194 Model model{};
195 int a = brick_nparams(model.hyp), b = brick_nparams(model.src), c = brick_nparams(model.ell);
196 int m = a > b ? a : b;
197 return m > c ? m : c;
198}
199
203template <class Model>
204void model_param_defaults(double* out) {
205 Model model{};
206 const RuntimeParams rp = model_params(model);
207 for (int k = 0; k < rp.count; ++k)
208 out[k] = static_cast<double>(rp.values[k]);
209}
210
216template <class Model>
217void residual(const double* U, double* R, const double* aux_in, int n, double dx, double dy,
218 bool periodic, const std::string& lim, const std::string& riem, bool recon_prim,
219 const double* pvals = nullptr, int npar = 0, double pos_floor = 0) {
220 LocalGrid lg = make_grid(n, dx, dy, periodic, aux_in, aux_comps<Model>());
221 MultiFab Umf(lg.ba, lg.dm, Model::n_vars, block_n_ghost(lim)),
222 Rmf(lg.ba, lg.dm, Model::n_vars, 0);
223 fill_interior(Umf, U, n, Model::n_vars);
224 const GridContext ctx{lg.dom, lg.bc, lg.geom, &lg.aux};
225 Model model =
226 make_model_with_params<Model>(pvals, npar); // P7-b: runtime params (no-op if const)
227 BlockClosures clo = make_block(model, lim, riem, ctx, /*imex=*/false, recon_prim, "ssprk2", {},
228 {}, nullptr, static_cast<Real>(pos_floor));
229 clo.rhs_into(Umf, Rmf);
230 extract(Rmf, R, n, Model::n_vars);
231}
232
234template <class Model>
235void advance(double* U, const double* aux_in, int n, double dx, double dy, bool periodic,
236 const std::string& lim, const std::string& riem, bool recon_prim, bool imex, double dt,
237 int nsub, const double* pvals = nullptr, int npar = 0, double pos_floor = 0) {
238 LocalGrid lg = make_grid(n, dx, dy, periodic, aux_in, aux_comps<Model>());
239 // block_n_ghost(lim): 3 for weno5 (5-point stencil), 2 MUSCL otherwise. cf. residual above.
240 MultiFab Umf(lg.ba, lg.dm, Model::n_vars, block_n_ghost(lim));
241 fill_interior(Umf, U, n, Model::n_vars);
242 const GridContext ctx{lg.dom, lg.bc, lg.geom, &lg.aux};
243 Model model =
244 make_model_with_params<Model>(pvals, npar); // P7-b: runtime params (no-op if const)
245 BlockClosures clo = make_block(model, lim, riem, ctx, imex, recon_prim, "ssprk2", {}, {}, nullptr,
246 static_cast<Real>(pos_floor));
247 clo.advance(Umf, dt, nsub);
248 extract(Umf, U, n, Model::n_vars);
249}
250
252template <class Model>
253double max_speed(const double* U, const double* aux_in, int n, double dx, double dy, bool periodic,
254 const double* pvals = nullptr, int npar = 0) {
255 LocalGrid lg = make_grid(n, dx, dy, periodic, aux_in, aux_comps<Model>());
256 MultiFab Umf(lg.ba, lg.dm, Model::n_vars, 2);
257 fill_interior(Umf, U, n, Model::n_vars);
258 const GridContext ctx{lg.dom, lg.bc, lg.geom, &lg.aux};
259 Model model =
260 make_model_with_params<Model>(pvals, npar); // P7-b: runtime params (no-op if const)
261 return make_max_speed(model, ctx)(Umf);
262}
263
268template <class Model>
269void to_conservative(const double* P, double* U, int n, const double* pvals = nullptr,
270 int npar = 0) {
271 constexpr int NV = Model::n_vars;
272 const std::size_t nn = static_cast<std::size_t>(n) * n;
273 Model model =
274 make_model_with_params<Model>(pvals, npar); // P7-b: runtime params (no-op if const)
275 for (std::size_t k = 0; k < nn; ++k) {
276 if constexpr (HasPrimitiveVars<Model>) {
277 typename Model::Prim p{};
278 for (int c = 0; c < NV; ++c)
279 p[c] = static_cast<Real>(P[static_cast<std::size_t>(c) * nn + k]);
280 const typename Model::State u = model.to_conservative(p);
281 for (int c = 0; c < NV; ++c)
282 U[static_cast<std::size_t>(c) * nn + k] = static_cast<double>(u[c]);
283 } else {
284 for (int c = 0; c < NV; ++c)
285 U[static_cast<std::size_t>(c) * nn + k] = P[static_cast<std::size_t>(c) * nn + k];
286 }
287 }
288}
289
293template <class Model>
294void to_primitive(const double* U, double* P, int n, const double* pvals = nullptr, int npar = 0) {
295 constexpr int NV = Model::n_vars;
296 const std::size_t nn = static_cast<std::size_t>(n) * n;
297 Model model =
298 make_model_with_params<Model>(pvals, npar); // P7-b: runtime params (no-op if const)
299 for (std::size_t k = 0; k < nn; ++k) {
300 if constexpr (HasPrimitiveVars<Model>) {
301 typename Model::State u{};
302 for (int c = 0; c < NV; ++c)
303 u[c] = static_cast<Real>(U[static_cast<std::size_t>(c) * nn + k]);
304 const typename Model::Prim p = model.to_primitive(u);
305 for (int c = 0; c < NV; ++c)
306 P[static_cast<std::size_t>(c) * nn + k] = static_cast<double>(p[c]);
307 } else {
308 for (int c = 0; c < NV; ++c)
309 P[static_cast<std::size_t>(c) * nn + k] = U[static_cast<std::size_t>(c) * nn + k];
310 }
311 }
312}
313
320template <class Model>
321void pointwise_project(double* U, const double* aux_in, int n, const double* pvals = nullptr,
322 int npar = 0) {
323 if constexpr (HasPointwiseProjection<Model>) {
324 constexpr int NV = Model::n_vars;
325 constexpr int naux = aux_comps<Model>();
326 const std::size_t nn = static_cast<std::size_t>(n) * n;
327 Model model =
328 make_model_with_params<Model>(pvals, npar); // P7-b : params runtime (no-op si const)
329 for (std::size_t k = 0; k < nn; ++k) {
330 typename Model::State u{};
331 for (int c = 0; c < NV; ++c)
332 u[c] = static_cast<Real>(U[static_cast<std::size_t>(c) * nn + k]);
333 Aux a{};
334 if (aux_in) {
335 a.phi = static_cast<Real>(aux_in[k]);
336 a.grad_x = static_cast<Real>(aux_in[nn + k]);
337 a.grad_y = static_cast<Real>(aux_in[2 * nn + k]);
338 // Champs extra canoniques depuis la SOURCE UNIQUE POPS_AUX_FIELDS (cf. native_loader) : une
339 // composante n'est lue que si le modele la consomme (naux) -- le System marshale toujours au
340 // moins naux composantes (ensure_aux_width a l'ajout du bloc).
341#define POPS_AUX_MARSHAL(name, idx) \
342 if constexpr (naux > (idx)) \
343 a.name = static_cast<Real>(aux_in[(idx) * nn + k]);
345#undef POPS_AUX_MARSHAL
346 // Champs aux NOMMES (aux_field, ADC-70) : composantes a partir de kAuxNamedBase, miroir de
347 // load_aux (borne deroulee et clampee a kAuxMaxExtra, jamais d'acces hors tableau).
348 if constexpr (naux > kAuxNamedBase) {
349 constexpr int n_extra =
351 for (int x = 0; x < n_extra; ++x)
352 a.extra[x] =
353 static_cast<Real>(aux_in[static_cast<std::size_t>(kAuxNamedBase + x) * nn + k]);
354 }
355 }
356 const typename Model::State p = model.project(u, a);
357 for (int c = 0; c < NV; ++c)
358 U[static_cast<std::size_t>(c) * nn + k] = static_cast<double>(p[c]);
359 }
360 } else {
361 (void)U;
362 (void)aux_in;
363 (void)n;
364 (void)pvals;
365 (void)npar;
366 }
367}
368
370template <class Model>
371void poisson_rhs(const double* U, double* rhs_out, int n, const double* pvals = nullptr,
372 int npar = 0) {
373 Box2D dom = Box2D::from_extents(n, n);
374 BoxArray ba = BoxArray::from_domain(dom, n);
375 DistributionMapping dm(ba.size(), 1);
376 MultiFab Umf(ba, dm, Model::n_vars, 2), rhsmf(ba, dm, 1, 0);
377 fill_interior(Umf, U, n, Model::n_vars);
378 rhsmf.set_val(0.0);
379 Model model =
380 make_model_with_params<Model>(pvals, npar); // P7-b: runtime params (no-op if const)
381 make_poisson_rhs(model)(Umf, rhsmf);
382 const ConstArray4 r = rhsmf.fab(0).const_array();
383 const std::size_t nn = static_cast<std::size_t>(n) * n;
384 (void)nn;
385 for (int j = 0; j < n; ++j)
386 for (int i = 0; i < n; ++i)
387 rhs_out[static_cast<std::size_t>(j) * n + i] = r(i, j, 0);
388}
389
393inline std::string csv_to_json_array(const std::string& csv) {
394 std::string out = "[";
395 std::size_t start = 0;
396 bool first = true;
397 while (start <= csv.size()) {
398 std::size_t comma = csv.find(',', start);
399 const std::string tok =
400 csv.substr(start, comma == std::string::npos ? std::string::npos : comma - start);
401 if (!tok.empty()) {
402 if (!first)
403 out += ',';
404 out += '"' + tok + '"';
405 first = false;
406 }
407 if (comma == std::string::npos)
408 break;
409 start = comma + 1;
410 }
411 out += ']';
412 return out;
413}
414
417template <class Model>
418std::string model_cons_roles_csv() {
419 if constexpr (requires { Model::conservative_vars(); })
420 return roles_csv(Model::conservative_vars());
421 else
422 return std::string{};
423}
424
430 return "pops_model_nvars,pops_compiled_naux,pops_compiled_nparams,pops_compiled_param_defaults,"
431 "pops_compiled_residual,pops_compiled_residual_p,pops_compiled_advance,"
432 "pops_compiled_advance_p,pops_compiled_max_speed,pops_compiled_max_speed_p,"
433 "pops_compiled_poisson_rhs,pops_compiled_poisson_rhs_p,pops_compiled_to_conservative,"
434 "pops_compiled_to_conservative_p,pops_compiled_to_primitive,pops_compiled_to_primitive_p,"
435 "pops_compiled_has_projection,pops_compiled_project_p,pops_compiled_manifest";
436}
437
454template <class Model>
456 const std::string roles = csv_to_json_array(model_cons_roles_csv<Model>());
457 const std::string entrypoints = csv_to_json_array(compiled_native_entrypoints_csv());
458 std::string out = "{";
459 out += "\"abi_version\":" + std::to_string(kAbiVersion);
460 out += ",\"n_vars\":" + std::to_string(Model::n_vars);
461 out += ",\"n_aux\":" + std::to_string(aux_comps<Model>());
462 out += ",\"n_params\":" + std::to_string(model_nparams<Model>());
463 out += ",\"ghost_depth\":" + std::to_string(block_n_ghost("weno5"));
464 // Layouts / platforms emitted AUTHORITATIVELY by the artifact (Spec 5 sec.13.12, #36), not a
465 // Python overlay. Artifact-honest for the AOT compiled-block route: it runs a single uniform grid
466 // (supports_uniform) on ONE rank (the make_grid DistributionMapping is single-rank -> supports_mpi
467 // false; an AMR hierarchy uses a different loader -> supports_amr false). supports_gpu is the .so's
468 // OWN device-backend token (kHasGpuBackend: Kokkos AND CUDA/HIP), so a CUDA-built .so reports true.
469 out += ",\"supports_uniform\":true";
470 out += ",\"supports_amr\":false";
471 out += ",\"supports_mpi\":false";
472 out += std::string(",\"supports_gpu\":") + (pops::detail::kHasGpuBackend ? "true" : "false");
473 out += ",\"supports_stride\":false";
474 out += ",\"supports_partial_imex_mask\":false";
475 out += ",\"supports_named_fields\":true";
476 out += ",\"roles\":" + roles;
477 out += ",\"native_entrypoints\":" + entrypoints;
478 out += "}";
479 return out;
480}
481
482} // namespace pops::compiled_block
483
501#define POPS_DEFINE_COMPILED_BLOCK(MODEL) \
502 extern "C" int pops_model_nvars() { \
503 return MODEL::n_vars; \
504 } \
505 extern "C" int pops_compiled_naux() { \
506 return pops::aux_comps<MODEL>(); \
507 } \
508 extern "C" int pops_compiled_nparams() { \
509 return pops::compiled_block::model_nparams<MODEL>(); \
510 } \
511 extern "C" void pops_compiled_param_defaults(double* out) { \
512 pops::compiled_block::model_param_defaults<MODEL>(out); \
513 } \
514 extern "C" void pops_compiled_residual(const double* U, double* R, const double* aux, int n, \
515 double dx, double dy, int periodic, const char* lim, \
516 const char* riem, int recon_prim) { \
517 pops::compiled_block::residual<MODEL>(U, R, aux, n, dx, dy, periodic != 0, lim, riem, \
518 recon_prim != 0); \
519 } \
520 extern "C" void pops_compiled_residual_p(const double* U, double* R, const double* aux, int n, \
521 double dx, double dy, int periodic, const char* lim, \
522 const char* riem, int recon_prim, const double* pvals, \
523 int npar, double pos_floor) { \
524 pops::compiled_block::residual<MODEL>(U, R, aux, n, dx, dy, periodic != 0, lim, riem, \
525 recon_prim != 0, pvals, npar, pos_floor); \
526 } \
527 extern "C" void pops_compiled_advance(double* U, const double* aux, int n, double dx, double dy, \
528 int periodic, const char* lim, const char* riem, \
529 int recon_prim, int imex, double dt, int nsub) { \
530 pops::compiled_block::advance<MODEL>(U, aux, n, dx, dy, periodic != 0, lim, riem, \
531 recon_prim != 0, imex != 0, dt, nsub); \
532 } \
533 extern "C" void pops_compiled_advance_p( \
534 double* U, const double* aux, int n, double dx, double dy, int periodic, const char* lim, \
535 const char* riem, int recon_prim, int imex, double dt, int nsub, const double* pvals, \
536 int npar, double pos_floor) { \
537 pops::compiled_block::advance<MODEL>(U, aux, n, dx, dy, periodic != 0, lim, riem, \
538 recon_prim != 0, imex != 0, dt, nsub, pvals, npar, \
539 pos_floor); \
540 } \
541 extern "C" double pops_compiled_max_speed(const double* U, const double* aux, int n, double dx, \
542 double dy, int periodic) { \
543 return pops::compiled_block::max_speed<MODEL>(U, aux, n, dx, dy, periodic != 0); \
544 } \
545 extern "C" double pops_compiled_max_speed_p(const double* U, const double* aux, int n, double dx, \
546 double dy, int periodic, const double* pvals, \
547 int npar) { \
548 return pops::compiled_block::max_speed<MODEL>(U, aux, n, dx, dy, periodic != 0, pvals, npar); \
549 } \
550 extern "C" void pops_compiled_poisson_rhs(const double* U, double* rhs, int n) { \
551 pops::compiled_block::poisson_rhs<MODEL>(U, rhs, n); \
552 } \
553 extern "C" void pops_compiled_poisson_rhs_p(const double* U, double* rhs, int n, \
554 const double* pvals, int npar) { \
555 pops::compiled_block::poisson_rhs<MODEL>(U, rhs, n, pvals, npar); \
556 } \
557 extern "C" void pops_compiled_to_conservative(const double* P, double* U, int n) { \
558 pops::compiled_block::to_conservative<MODEL>(P, U, n); \
559 } \
560 extern "C" void pops_compiled_to_conservative_p(const double* P, double* U, int n, \
561 const double* pvals, int npar) { \
562 pops::compiled_block::to_conservative<MODEL>(P, U, n, pvals, npar); \
563 } \
564 extern "C" void pops_compiled_to_primitive(const double* U, double* P, int n) { \
565 pops::compiled_block::to_primitive<MODEL>(U, P, n); \
566 } \
567 extern "C" void pops_compiled_to_primitive_p(const double* U, double* P, int n, \
568 const double* pvals, int npar) { \
569 pops::compiled_block::to_primitive<MODEL>(U, P, n, pvals, npar); \
570 } \
571 extern "C" int pops_compiled_has_projection() { \
572 return pops::HasPointwiseProjection<MODEL> ? 1 : 0; \
573 } \
574 extern "C" void pops_compiled_project_p(double* U, const double* aux, int n, const double* pvals, \
575 int npar) { \
576 pops::compiled_block::pointwise_project<MODEL>(U, aux, n, pvals, npar); \
577 } \
578 /* Spec 5 sec.13.12 (#36): per-artifact NativeManifest JSON computed at THIS .so's compile time \
579 from the model traits. A function-local static built once (valid for the process); a loader \
580 reads it by dlsym. An old .so without this symbol falls back gracefully (the reader returns \
581 None). */ \
582 extern "C" const char* pops_compiled_manifest() { \
583 static const std::string manifest = pops::compiled_block::compiled_manifest_json<MODEL>(); \
584 return manifest.c_str(); \
585 }
Builds the closures of a block (time advance + residual + Poisson contribution) from a COMPILED model...
BoxArray: the set of boxes tiling a level (disjoint, covering).
Ordered list of boxes tiling a level.
Definition box_array.hpp:22
int size() const
Number of boxes in the tiling.
Definition box_array.hpp:42
static BoxArray from_domain(const Box2D &domain, int max_grid_size)
Tile the domain into tiles of at most max_grid_size per direction, distributed evenly.
Definition box_array.hpp:30
Owning MPI rank of each box, indexed by GLOBAL box index (parallel to a BoxArray).
Definition distribution_mapping.hpp:19
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
void set_val(Real v)
Fills all cells (valid + ghosts) of every local fab with v.
Definition multifab.hpp:85
#define POPS_AUX_MARSHAL(name, idx)
Trait OPTIONNEL : PROJECTION PONCTUELLE post-pas U -> project(U, aux) (ADC-177).
Definition physical_model.hpp:154
OPTIONAL extension of a PhysicalModel: primitive variables + cons<->prim conversions.
Definition physical_model.hpp:167
DistributionMapping: maps each box (by global index) to its owning MPI rank.
fill_boundary: INTRA-level halo exchange (fills ghosts from neighbors).
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...
Authoritative STATIC capability facts of the built _pops module (Spec 5 sec.13.12 / sec....
MultiFab: a field DISTRIBUTED over a level (equivalent of AMReX's MultiFab).
Definition compiled_block_abi.hpp:37
void pointwise_project(double *U, const double *aux_in, int n, const double *pvals=nullptr, int npar=0)
PROJECTION PONCTUELLE post-pas (ADC-177) : U(k) <- model.project(U(k), aux(k)) sur les n*n cellules,...
Definition compiled_block_abi.hpp:321
void residual(const double *U, double *R, const double *aux_in, int n, double dx, double dy, bool periodic, const std::string &lim, const std::string &riem, bool recon_prim, const double *pvals=nullptr, int npar=0, double pos_floor=0)
Residual -div F + S of the production path (assemble_rhs<Limiter, Flux>) on the generated model.
Definition compiled_block_abi.hpp:217
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 apply_runtime_params(B &b, const RuntimeParams &rp)
Writes rp into the params member of brick b if it has one (P7-b); otherwise no-op.
Definition compiled_block_abi.hpp:135
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
double max_speed(const double *U, const double *aux_in, int n, double dx, double dy, bool periodic, const double *pvals=nullptr, int npar=0)
Max wave speed of the block (for the CFL step on the System side) via make_max_speed on the generated...
Definition compiled_block_abi.hpp:253
std::string model_cons_roles_csv()
The conservative-role CSV of Model, or an empty string if the model declares no roles.
Definition compiled_block_abi.hpp:418
int brick_nparams(const B &b)
Number of runtime parameters the params member of a brick b carries (0 if the brick has none).
Definition compiled_block_abi.hpp:163
RuntimeParams model_params(const Model &model)
params block (full RuntimeParams) of the model: the FIRST brick that carries one (all carry the same ...
Definition compiled_block_abi.hpp:176
int model_nparams()
Number of runtime parameters declared by Model (P7-b): max of the params.count of its 3 bricks (each ...
Definition compiled_block_abi.hpp:193
Model make_model_with_params(const double *pvals, int npar)
Builds a Model (CompositeModel<Hyp, Src, Ell>) and injects the npar runtime parameter values pvals in...
Definition compiled_block_abi.hpp:146
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
void poisson_rhs(const double *U, double *rhs_out, int n, const double *pvals=nullptr, int npar=0)
Elliptic right-hand side f(U) of the block (the System adds it to its Poisson sum).
Definition compiled_block_abi.hpp:371
std::string csv_to_json_array(const std::string &csv)
A JSON array literal ["a","b",...] from a comma-separated CSV (empty CSV -> []).
Definition compiled_block_abi.hpp:393
void to_conservative(const double *P, double *U, int n, const double *pvals=nullptr, int npar=0)
PRIMITIVE -> CONSERVATIVE conversion cell by cell (M.to_conservative) on component-major flat arrays ...
Definition compiled_block_abi.hpp:269
void model_param_defaults(double *out)
Writes the DECLARATION values of Model's runtime parameters into out (at least model_nparams<Model>()...
Definition compiled_block_abi.hpp:204
std::string compiled_manifest_json()
The per-artifact NativeManifest of Model as a JSON string (Spec 5 sec.13.12, criterion #36).
Definition compiled_block_abi.hpp:455
void to_primitive(const double *U, double *P, int n, const double *pvals=nullptr, int npar=0)
CONSERVATIVE -> PRIMITIVE conversion cell by cell (M.to_primitive).
Definition compiled_block_abi.hpp:294
std::string compiled_native_entrypoints_csv()
The native entrypoint symbols a POPS_DEFINE_COMPILED_BLOCK .so exports, as a CSV.
Definition compiled_block_abi.hpp:429
void advance(double *U, const double *aux_in, int n, double dx, double dy, bool periodic, const std::string &lim, const std::string &riem, bool recon_prim, bool imex, double dt, int nsub, const double *pvals=nullptr, int npar=0, double pos_floor=0)
Advances by nsub substeps (explicit SSPRK2, or ForwardEuler + implicit source if imex).
Definition compiled_block_abi.hpp:235
constexpr bool kHasGpuBackend
True iff this translation unit is compiled for a real GPU device backend.
Definition module_capabilities.hpp:60
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
double Real
Definition types.hpp:30
BCRec aux_halo_override(const BCRec &shared, const AuxHaloPolicy &p)
Builds the effective override BCRec for a per-field aux halo: starts from the SHARED aux BC shared (s...
Definition physical_bc.hpp:204
constexpr int kAbiVersion
Discrete, monotonic ABI revision of the module capability contract.
Definition module_capabilities.hpp:32
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
void device_fence()
Device barrier: waits for in-flight kernels to finish before a HOST access to unified memory.
Definition kokkos_env.hpp:43
constexpr int kAuxMaxExtra
Definition state.hpp:100
void fill_boundary(MultiFab &mf, const Box2D &domain, Periodicity per={})
BLOCKING halo exchange: begin then end immediately (no overlap).
Definition fill_boundary.hpp:333
void fill_physical_bc(MultiFab &mf, const Box2D &domain, const BCRec &bc)
Fills the physical-face ghosts of ALL components per bc (historical entry point, bit-identical).
Definition physical_bc.hpp:176
std::string roles_csv(const VariableSet &vs)
CSV of a VariableSet's roles (role_name, separator ',').
Definition variables.hpp:172
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
constexpr int kMaxRuntimeParams
Maximum number of runtime parameters per DSL block.
Definition runtime_params.hpp:32
constexpr int kAuxNamedBase
Definition state.hpp:154
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
BCType
Boundary condition type for a face: Periodic (handled by fill_boundary), Foextrap (zero gradient,...
Definition physical_bc.hpp:25
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
PHYSICAL boundary conditions at the domain edge (BCType, BCRec, fill_physical_bc, fill_ghosts).
C++20 concepts defining the contract of the physics layer.
RuntimeParams: carrier for the RUNTIME PARAMETERS of a DSL model (P7-b).
#define POPS_AUX_FIELDS(X)
SINGLE SOURCE of the layout of the EXTRA aux fields (X-macro).
Definition state.hpp:92
WRITE POD handle (raw pointer + strides) over a Fab2D buffer, indexed by (i, j, c) IN GLOBAL INDICES ...
Definition fab2d.hpp:29
Per-field aux halo policy (ADC-369): a UNIFORM boundary policy for ONE model-named aux component,...
Definition physical_bc.hpp:195
POINTWISE auxiliary fields shared with the physics: single coupling channel.
Definition state.hpp:123
Real phi
Definition state.hpp:124
Boundary conditions for the FOUR faces of the domain (type + associated Dirichlet value).
Definition physical_bc.hpp:29
BCType yhi
Definition physical_bc.hpp:31
BCType xlo
Definition physical_bc.hpp:30
BCType ylo
Definition physical_bc.hpp:31
BCType xhi
Definition physical_bc.hpp:30
Compiled block closures, frozen at add time.
Definition grid_context.hpp:61
std::function< void(MultiFab &, Real, int)> advance
(U, dt, n): n substeps of dt/n
Definition grid_context.hpp:62
std::function< void(MultiFab &, MultiFab &)> rhs_into
R <- -div F + S (Poisson frozen)
Definition grid_context.hpp:66
2D integer index space, cell-centered.
Definition box2d.hpp:37
static Box2D from_extents(int nx, int ny)
Box [0, nx-1] x [0, ny-1] covering nx*ny cells from the index origin.
Definition box2d.hpp:42
READ-only handle (const counterpart of Array4): same layout and same contract (POD device-copyable,...
Definition fab2d.hpp:44
Cartesian geometry of a level: index domain + physical bounds [xlo, xhi] x [ylo, yhi].
Definition geometry.hpp:20
Mesh + transport BC + aux shared by a block closures.
Definition grid_context.hpp:41
Per-direction periodicity: halo wrapping in x and/or y during the exchange (false = open edge,...
Definition fill_boundary.hpp:37
FLAT carrier (fixed size, by value) of the runtime parameter values of a block.
Definition runtime_params.hpp:38
Real values[kMaxRuntimeParams]
Definition runtime_params.hpp:40
int count
Definition runtime_params.hpp:39
Detects (SFINAE) whether a brick B exposes a params member of type pops::RuntimeParams (DSL bricks ca...
Definition compiled_block_abi.hpp:127
Local single-grid mesh rebuilt inside the .so + aux filled from the System array.
Definition compiled_block_abi.hpp:40
MultiFab aux
Definition compiled_block_abi.hpp:47
BoxArray ba
Definition compiled_block_abi.hpp:43
BCRec bc
Definition compiled_block_abi.hpp:45
Geometry geom
Definition compiled_block_abi.hpp:42
DistributionMapping dm
Definition compiled_block_abi.hpp:44
bool periodic
Definition compiled_block_abi.hpp:46
Box2D dom
Definition compiled_block_abi.hpp:41
Descriptor of a model's variables (Vars).