include/pops/runtime/config/dispatch_tags.hpp Source FileΒΆ

adc_cpp: include/pops/runtime/config/dispatch_tags.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
dispatch_tags.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <stdexcept>
4#include <string>
5
25
26namespace pops {
27
32struct LimiterTag {
33 const char* name;
35};
36
38inline constexpr LimiterTag kLimiters[] = {
39 {"none", 1}, {"minmod", 2}, {"vanleer", 2}, {"weno5", 3}};
40
54
56inline constexpr RiemannTag kRiemanns[] = {{"rusanov", false, false, false, true},
57 {"hll", true, false, false, true},
58 {"hllc", false, true, false, false},
59 {"roe", false, false, true, false}};
60
65inline int limiter_n_ghost(const std::string& lim) {
66 for (const LimiterTag& t : kLimiters)
67 if (lim == t.name)
68 return t.n_ghost;
69 return 2; // MUSCL fallback (historical allocation)
70}
71
72namespace detail {
74constexpr bool ct_str_eq(const char* a, const char* b) {
75 while (*a != '\0' && *b != '\0') {
76 if (*a != *b)
77 return false;
78 ++a;
79 ++b;
80 }
81 return *a == *b;
82}
83} // namespace detail
84
88constexpr int limiter_n_ghost_ct(const char* lim) {
89 for (const LimiterTag& t : kLimiters)
90 if (detail::ct_str_eq(lim, t.name))
91 return t.n_ghost;
92 return -1;
93}
94
99inline void validate_limiter(const std::string& lim, const char* ctx = "System") {
100 for (const LimiterTag& t : kLimiters)
101 if (lim == t.name)
102 return;
103 throw std::runtime_error(std::string(ctx) + ": unknown limiter '" + lim + "'");
104}
105
111inline void validate_riemann(const std::string& riem, bool polar = false,
112 const char* ctx = "System") {
113 if (polar) {
114 // Polar: wired fluxes = those of kRiemanns with polar_ok (rusanov + hll since the audit
115 // settlement; hll keeps its model.wave_speeds capability gate at the call-site). HLLC/Roe and
116 // unknown tags -> single polar message.
117 for (const RiemannTag& t : kRiemanns)
118 if (riem == t.name && t.polar_ok)
119 return;
120 throw std::runtime_error(
121 std::string(ctx) + ": Riemann flux '" + riem +
122 "' unsupported (polar -> 'rusanov' | 'hll' (signed wave speeds); HLLC/Roe "
123 "assume n_vars==4 (Euler with energy), not applicable to scalar ExB or the polar "
124 "isothermal fluid)");
125 }
126 for (const RiemannTag& t : kRiemanns)
127 if (riem == t.name)
128 return;
129 throw std::runtime_error(std::string(ctx) + ": unknown Riemann flux '" + riem +
130 "' (rusanov|hll|hllc|roe)");
131}
132
138[[noreturn]] inline void throw_registry_dispatch_mismatch(const char* ctx, const char* kind,
139 const std::string& tag) {
140 throw std::runtime_error(std::string(ctx) + ": registry/dispatch inconsistency -- " + kind +
141 " '" + tag + "' valid but not routed (add the case to the dispatch)");
142}
143
144} // namespace pops
constexpr bool ct_str_eq(const char *a, const char *b)
COMPILE-TIME C string equality (no constexpr <cstring> guaranteed everywhere).
Definition dispatch_tags.hpp:74
Definition amr_hierarchy.hpp:29
constexpr LimiterTag kLimiters[]
SINGLE SOURCE of the wired limiters (order = display priority: none < minmod < vanleer < weno5).
Definition dispatch_tags.hpp:38
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 validate_limiter(const std::string &lim, const char *ctx="System")
Validates a LIMITER tag against kLimiters.
Definition dispatch_tags.hpp:99
constexpr RiemannTag kRiemanns[]
SINGLE SOURCE of the wired Riemann fluxes (order = message "(rusanov|hll|hllc|roe)").
Definition dispatch_tags.hpp:56
int limiter_n_ghost(const std::string &lim)
Halo width required by the limiter lim (source: kLimiters).
Definition dispatch_tags.hpp:65
Tag of a reconstruction LIMITER: user-facing name + halo width (n_ghost) required by its stencil.
Definition dispatch_tags.hpp:32
int n_ghost
Definition dispatch_tags.hpp:34
const char * name
Definition dispatch_tags.hpp:33
Tag of a Riemann FLUX: name + model CAPABILITY needs (DOCUMENTARY: the real guard is an if constexpr ...
Definition dispatch_tags.hpp:47
const char * name
Definition dispatch_tags.hpp:48
bool needs_hllc_struct
Definition dispatch_tags.hpp:50
bool needs_roe_diss
Definition dispatch_tags.hpp:51
bool needs_wave_speeds
Definition dispatch_tags.hpp:49
bool polar_ok
Definition dispatch_tags.hpp:52