include/pops/physics/fluids/euler.hpp Source FileΒΆ

adc_cpp: include/pops/physics/fluids/euler.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
euler.hpp
Go to the documentation of this file.
1#pragma once
2
8
12
13#include <cmath>
14
15namespace pops {
16
34struct Euler {
36 using Prim = StateVec<4>;
37 using Aux = pops::Aux;
38 static constexpr int n_vars = 4;
39
40 Real gamma = 1.4;
41
43 POPS_HD Real pressure(const State& u) const {
44 const Real rho = u[0];
45 const Real ke = Real(0.5) * (u[1] * u[1] + u[2] * u[2]) / rho;
46 return (gamma - Real(1)) * (u[3] - ke);
47 }
49 POPS_HD Real sound_speed(const State& u) const { return std::sqrt(gamma * pressure(u) / u[0]); }
50
52 POPS_HD Prim to_primitive(const State& u) const {
53 const Real rho = u[0];
54 Prim p{};
55 p[0] = rho;
56 p[1] = u[1] / rho;
57 p[2] = u[2] / rho;
58 p[3] = pressure(u);
59 return p;
60 }
63 const Real rho = p[0];
64 State u{};
65 u[0] = rho;
66 u[1] = rho * p[1];
67 u[2] = rho * p[2];
68 u[3] = p[3] / (gamma - Real(1)) + Real(0.5) * rho * (p[1] * p[1] + p[2] * p[2]);
69 return u;
70 }
71
82 POPS_HD void wave_speeds(const State& u, const Aux&, int dir, Real& smin, Real& smax) const {
83 const Prim p = to_primitive(u);
84 const Real vn = (dir == 0 ? p[1] : p[2]);
85 const Real c = std::sqrt(gamma * p[3] / p[0]);
86 smin = vn - c;
87 smax = vn + c;
88 }
89
91 POPS_HD State flux(const State& u, const Aux&, int dir) const {
92 const Real rho = u[0];
93 const Real vn = (dir == 0 ? u[1] : u[2]) / rho; // velocity normal to the face
94 const Real p = pressure(u);
95 State f{};
96 f[0] = rho * vn;
97 f[1] = u[1] * vn + (dir == 0 ? p : Real(0));
98 f[2] = u[2] * vn + (dir == 1 ? p : Real(0));
99 f[3] = (u[3] + p) * vn;
100 return f;
101 }
102
105 POPS_HD State eigenvalues(const State& u, const Aux&, int dir) const {
106 const Prim p = to_primitive(u);
107 const Real vn = (dir == 0 ? p[1] : p[2]);
108 const Real c = std::sqrt(gamma * p[3] / p[0]);
109 State e{};
110 e[0] = vn - c;
111 e[1] = vn;
112 e[2] = vn;
113 e[3] = vn + c;
114 return e;
115 }
116
118 POPS_HD Real max_wave_speed(const State& u, const Aux&, int dir) const {
119 const Prim p = to_primitive(u);
120 const Real vn = (dir == 0 ? p[1] : p[2]);
121 const Real a = vn < 0 ? -vn : vn; // |v_dir| device-safe
122 return a + std::sqrt(gamma * p[3] / p[0]);
123 }
124
140};
141
142} // namespace pops
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
2D compressible Euler for an ideal gas: HYPERBOLIC brick (HyperbolicModel concept).
Definition euler.hpp:34
POPS_HD State eigenvalues(const State &u, const Aux &, int dir) const
Full spectrum in direction dir: (v_dir - c, v_dir, v_dir, v_dir + c).
Definition euler.hpp:105
POPS_HD Real max_wave_speed(const State &u, const Aux &, int dir) const
Maximum wave speed |v_dir| + c (Rusanov estimate), computed in primitive variables.
Definition euler.hpp:118
static constexpr int n_vars
number of conserved variables
Definition euler.hpp:38
static VariableSet conservative_vars()
Variable descriptor (hyperbolic model contract; host introspection metadata).
Definition euler.hpp:126
POPS_HD Prim to_primitive(const State &u) const
Conservative -> primitive: (rho, rho u, rho v, E) -> (rho, u, v, p).
Definition euler.hpp:52
POPS_HD State to_conservative(const Prim &p) const
Primitive -> conservative: (rho, u, v, p) -> (rho, rho u, rho v, E).
Definition euler.hpp:62
POPS_HD Real sound_speed(const State &u) const
Sound speed c = sqrt(gamma p / rho).
Definition euler.hpp:49
POPS_HD void wave_speeds(const State &u, const Aux &, int dir, Real &smin, Real &smax) const
Extreme signed wave speeds in direction dir: v_dir - c and v_dir + c.
Definition euler.hpp:82
POPS_HD Real pressure(const State &u) const
Ideal-gas pressure p = (gamma-1)(E - 1/2 rho |v|^2).
Definition euler.hpp:43
POPS_HD State flux(const State &u, const Aux &, int dir) const
Compressible convective flux in direction dir.
Definition euler.hpp:91
Real gamma
adiabatic index of the ideal gas
Definition euler.hpp:40
static VariableSet primitive_vars()
Definition euler.hpp:133
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).