include/pops/physics/bricks/hyperbolic.hpp Source File

adc_cpp: include/pops/physics/bricks/hyperbolic.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
hyperbolic.hpp
Go to the documentation of this file.
1#pragma once
2
6#include <pops/physics/fluids/euler.hpp> // Euler: reused as the CompressibleFlux hyperbolic brick
7
8#include <cmath>
9
17
18namespace pops {
19
28 static constexpr int n_vars = 1;
30 Real B0 = 1;
31 POPS_HD Real velocity(const Aux& a, int dir) const {
32 return (dir == 0) ? (-a.grad_y / B0) : (a.grad_x / B0);
33 }
34 POPS_HD StateVec<1> flux(const StateVec<1>& u, const Aux& a, int dir) const {
35 StateVec<1> f{};
36 f[0] = u[0] * velocity(a, dir);
37 return f;
38 }
39 POPS_HD Real max_wave_speed(const StateVec<1>&, const Aux& a, int dir) const {
40 const Real d = velocity(a, dir);
41 return d < 0 ? -d : d;
42 }
44 POPS_HD StateVec<1> eigenvalues(const StateVec<1>&, const Aux& a, int dir) const {
45 StateVec<1> e{};
46 e[0] = velocity(a, dir);
47 return e;
48 }
49 // Scalar: primitive variables = conservative (transported density).
51 POPS_HD Prim to_primitive(const StateVec<1>& u) const { return u; }
52 POPS_HD StateVec<1> to_conservative(const Prim& p) const { return p; }
59};
60
82 static constexpr int n_vars = 1;
84 Real B0 = 1;
86 POPS_HD Real velocity(const Aux& a, int dir) const {
87 return (dir == 0) ? (-a.grad_y / B0) : (a.grad_x / B0);
88 }
89 POPS_HD StateVec<1> flux(const StateVec<1>& u, const Aux& a, int dir) const {
90 StateVec<1> f{};
91 f[0] = u[0] * velocity(a, dir);
92 return f;
93 }
94 POPS_HD Real max_wave_speed(const StateVec<1>&, const Aux& a, int dir) const {
95 const Real d = velocity(a, dir);
96 return d < 0 ? -d : d;
97 }
99 POPS_HD StateVec<1> eigenvalues(const StateVec<1>&, const Aux& a, int dir) const {
100 StateVec<1> e{};
101 e[0] = velocity(a, dir);
102 return e;
103 }
104 // Scalar: primitive variables = conservative (transported density).
106 POPS_HD Prim to_primitive(const StateVec<1>& u) const { return u; }
107 POPS_HD StateVec<1> to_conservative(const Prim& p) const { return p; }
113 }
114};
115
119
128 static constexpr int n_vars = 3;
142 return (vacuum_floor > Real(0) && rho < vacuum_floor) ? vacuum_floor : rho;
143 }
144 POPS_HD StateVec<3> flux(const StateVec<3>& u, const Aux&, int dir) const {
145 const Real rho = u[0];
146 const Real vn = (dir == 0 ? u[1] : u[2]) / velocity_rho(rho);
147 const Real p = cs2 * rho;
148 StateVec<3> f{};
149 f[0] = (dir == 0 ? u[1] : u[2]);
150 f[1] = u[1] * vn + (dir == 0 ? p : Real(0));
151 f[2] = u[2] * vn + (dir == 1 ? p : Real(0));
152 return f;
153 }
157 Prim p{};
158 p[0] = u[0];
159 const Real rho_v = velocity_rho(u[0]);
160 p[1] = u[1] / rho_v;
161 p[2] = u[2] / rho_v;
162 return p;
163 }
166 StateVec<3> u{};
167 u[0] = p[0];
168 u[1] = p[0] * p[1];
169 u[2] = p[0] * p[2];
170 return u;
171 }
172 POPS_HD Real max_wave_speed(const StateVec<3>& u, const Aux&, int dir) const {
173 const Prim p = to_primitive(u);
174 const Real vn = (dir == 0 ? p[1] : p[2]);
175 const Real a = vn < 0 ? -vn : vn;
176 return a + std::sqrt(cs2);
177 }
179 POPS_HD StateVec<3> eigenvalues(const StateVec<3>& u, const Aux&, int dir) const {
180 const Prim p = to_primitive(u);
181 const Real vn = (dir == 0 ? p[1] : p[2]);
182 const Real c = std::sqrt(cs2);
183 StateVec<3> e{};
184 e[0] = vn - c;
185 e[1] = vn;
186 e[2] = vn + c;
187 return e;
188 }
190 POPS_HD void wave_speeds(const StateVec<3>& u, const Aux&, int dir, Real& smin, Real& smax) const {
191 const Prim p = to_primitive(u);
192 const Real vn = (dir == 0 ? p[1] : p[2]);
193 const Real c = std::sqrt(cs2);
194 smin = vn - c;
195 smax = vn + c;
196 }
199 {"rho", "rho_u", "rho_v"},
200 3,
202 }
209};
210
246 const Real rho = u[0];
247 const Real inv_rho =
248 Real(1) / velocity_rho(rho); // quasi-vacuum floored (ADC-77; bit-identical if off)
249 const Real mr = u[1], mth = u[2]; // rho v_r, rho v_theta (local basis (e_r, e_theta))
250 const Real p = cs2 * rho;
251 const Real inv_r = Real(1) / r;
252 StateVec<3> s{};
253 s[0] = Real(0);
254 s[1] = (mth * mth * inv_rho + p) * inv_r; // (rho v_theta^2 + p)/r: centrifugal + pressure
255 s[2] = -(mr * mth * inv_rho) * inv_r; // -(rho v_r v_theta)/r: cross curvature
256 return s;
257 }
258};
259
260} // namespace pops
2D compressible Euler model (ideal gas): pure HYPERBOLIC brick satisfying the HyperbolicPhysicalModel...
Definition amr_hierarchy.hpp:29
double Real
Definition types.hpp:30
Pointwise types of the physics layer: StateVec<N> (conserved state) and Aux (auxiliary fields from th...
POINTWISE auxiliary fields shared with the physics: single coupling channel.
Definition state.hpp:123
Real grad_y
Definition state.hpp:126
Real grad_x
Definition state.hpp:125
2D compressible Euler for an ideal gas: HYPERBOLIC brick (HyperbolicModel concept).
Definition euler.hpp:34
Scalar advection by the E x B drift in POLAR coordinates (r, theta) – "annular polar grid" effort,...
Definition hyperbolic.hpp:81
static VariableSet conservative_vars()
Definition hyperbolic.hpp:108
Real B0
Definition hyperbolic.hpp:84
POPS_HD StateVec< 1 > eigenvalues(const StateVec< 1 > &, const Aux &a, int dir) const
Spectrum: one wave, the drift speed in direction dir.
Definition hyperbolic.hpp:99
static VariableSet primitive_vars()
Definition hyperbolic.hpp:111
POPS_HD StateVec< 1 > to_conservative(const Prim &p) const
Definition hyperbolic.hpp:107
POPS_HD Real max_wave_speed(const StateVec< 1 > &, const Aux &a, int dir) const
Definition hyperbolic.hpp:94
POPS_HD StateVec< 1 > flux(const StateVec< 1 > &u, const Aux &a, int dir) const
Definition hyperbolic.hpp:89
POPS_HD Real velocity(const Aux &a, int dir) const
PHYSICAL component of the drift velocity in direction index dir (0 = r, 1 = theta).
Definition hyperbolic.hpp:86
POPS_HD Prim to_primitive(const StateVec< 1 > &u) const
Definition hyperbolic.hpp:106
static constexpr int n_vars
Definition hyperbolic.hpp:82
Scalar advection by the E x B drift: v = (-d_y phi, d_x phi)/B0 (divergence-free).
Definition hyperbolic.hpp:27
static VariableSet primitive_vars()
Definition hyperbolic.hpp:56
POPS_HD Real velocity(const Aux &a, int dir) const
Definition hyperbolic.hpp:31
POPS_HD StateVec< 1 > flux(const StateVec< 1 > &u, const Aux &a, int dir) const
Definition hyperbolic.hpp:34
static VariableSet conservative_vars()
Definition hyperbolic.hpp:53
Real B0
Definition hyperbolic.hpp:30
POPS_HD Real max_wave_speed(const StateVec< 1 > &, const Aux &a, int dir) const
Definition hyperbolic.hpp:39
static constexpr int n_vars
Definition hyperbolic.hpp:28
POPS_HD StateVec< 1 > eigenvalues(const StateVec< 1 > &, const Aux &a, int dir) const
Spectrum: one wave, the drift speed in direction dir.
Definition hyperbolic.hpp:44
POPS_HD Prim to_primitive(const StateVec< 1 > &u) const
Definition hyperbolic.hpp:51
POPS_HD StateVec< 1 > to_conservative(const Prim &p) const
Definition hyperbolic.hpp:52
ISOTHERMAL Euler flux in POLAR geometry (ring r, theta), 3 variables (rho, rho v_r,...
Definition hyperbolic.hpp:241
POPS_HD StateVec< 3 > polar_geom_source(const StateVec< 3 > &u, Real r) const
Definition hyperbolic.hpp:245
ISOTHERMAL Euler flux (p = cs2 rho), 3 variables (rho, rho u, rho v).
Definition hyperbolic.hpp:127
POPS_HD Real max_wave_speed(const StateVec< 3 > &u, const Aux &, int dir) const
Definition hyperbolic.hpp:172
POPS_HD StateVec< 3 > eigenvalues(const StateVec< 3 > &u, const Aux &, int dir) const
Full spectrum: (v_dir - c, v_dir, v_dir + c), c = sqrt(cs2).
Definition hyperbolic.hpp:179
Real cs2
Definition hyperbolic.hpp:131
static VariableSet primitive_vars()
Definition hyperbolic.hpp:203
static constexpr int n_vars
Definition hyperbolic.hpp:128
POPS_HD StateVec< 3 > to_conservative(const Prim &p) const
Primitive -> conservative: (rho, u, v) -> (rho, rho u, rho v).
Definition hyperbolic.hpp:165
POPS_HD Real velocity_rho(Real rho) const
rho clamped from below by vacuum_floor for the velocity division ONLY.
Definition hyperbolic.hpp:141
POPS_HD StateVec< 3 > flux(const StateVec< 3 > &u, const Aux &, int dir) const
Definition hyperbolic.hpp:144
Real vacuum_floor
Quasi-vacuum density floor (ADC-77).
Definition hyperbolic.hpp:138
static VariableSet conservative_vars()
Definition hyperbolic.hpp:197
POPS_HD void wave_speeds(const StateVec< 3 > &u, const Aux &, int dir, Real &smin, Real &smax) const
Signed speeds (HLL/HLLC): v_dir -+ c_s.
Definition hyperbolic.hpp:190
POPS_HD Prim to_primitive(const StateVec< 3 > &u) const
Conservative -> primitive: (rho, rho u, rho v) -> (rho, u, v).
Definition hyperbolic.hpp:156
Conserved state vector of fixed size, known at compile time.
Definition state.hpp:29
A model's variable set: kind (cons/prim), names, size, canonical roles (optional, parallel to names; ...
Definition variables.hpp:58
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).