include/pops/numerics/spatial/primitives/positivity.hpp Source File

adc_cpp: include/pops/numerics/spatial/primitives/positivity.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
positivity.hpp
Go to the documentation of this file.
1
11
12#pragma once
13
16#include <pops/core/state/variables.hpp> // VariableRole, VariableSet: Density-role resolution
17#include <pops/mesh/storage/fab2d.hpp> // ConstArray4: face-state source cell read
18
19#include <stdexcept> // positivity_comp: model without Density role -> clear error
20
21namespace pops {
22
41template <class Model>
42POPS_HD inline void zhang_shu_scale(typename Model::State& s, const ConstArray4& u, int i, int j,
43 Real floor, int pos_comp) {
44 if (!(floor > Real(0)))
45 return; // strict opt-in: floor <= 0 -> no effect
46 if (!(s[pos_comp] < floor))
47 return; // face already above the floor
48 for (int c = 0; c < Model::n_vars; ++c)
49 s[c] = u(i, j, c); // order-1 fallback: face = average
50}
51
52namespace detail {
57template <class Model>
58inline int positivity_comp(Real pos_floor) {
59 if (!(pos_floor > Real(0)))
60 return 0;
61 if constexpr (requires { Model::conservative_vars(); }) {
62 const int c = Model::conservative_vars().index_of(VariableRole::Density);
63 if (c >= 0)
64 return c;
65 throw std::runtime_error(
66 "positivity_floor > 0: the model does not expose the Density role (scaling target)");
67 } else {
68 throw std::runtime_error(
69 "positivity_floor > 0: model without VariableSet introspection (conservative_vars)");
70 }
71}
72} // namespace detail
73
74} // namespace pops
Fab2D: single-grid data on a Box2D (in-house equivalent of AMReX's FArrayBox); Array4 / ConstArray4: ...
int positivity_comp(Real pos_floor)
Component of the Density role for the positivity limiter (HOST, resolved once per spatial operator ca...
Definition positivity.hpp:58
Definition amr_hierarchy.hpp:29
double Real
Definition types.hpp:30
POPS_HD void zhang_shu_scale(typename Model::State &s, const ConstArray4 &u, int i, int j, Real floor, int pos_comp)
zhang_shu_scale: POSITIVITY limiter on a reconstructed face state – LOCAL ORDER-1 FALLBACK (vacuum-ro...
Definition positivity.hpp:42
Pointwise types of the physics layer: StateVec<N> (conserved state) and Aux (auxiliary fields from th...
READ-only handle (const counterpart of Array4): same layout and same contract (POD device-copyable,...
Definition fab2d.hpp:44
Base scalar types and the POPS_HD macro (host+device portability).
#define POPS_HD
Definition types.hpp:25
Descriptor of a model's variables (Vars).