Mallard 0.8.0
Unstructured, GPU accelerated, high-order finite volume CFD solver
Mallard website
Loading...
Searching...
No Matches
physics.h
Go to the documentation of this file.
1
12#ifndef PHYSICS_H
13#define PHYSICS_H
14
15#include <string>
16#include <unordered_map>
17
18#include <Kokkos_Core.hpp>
19#include <toml.hpp>
20
21#include "common.h"
22#include "log.h"
23
24enum class PhysicsType {
25 EULER,
27};
28
29static const std::unordered_map<std::string, PhysicsType> PHYSICS_TYPES = {
30 {"euler", PhysicsType::EULER},
31 {"navier_stokes", PhysicsType::NAVIER_STOKES}
32};
33
34static const std::unordered_map<PhysicsType, std::string> PHYSICS_NAMES = {
35 {PhysicsType::EULER, "euler"},
36 {PhysicsType::NAVIER_STOKES, "navier_stokes"}
37};
38
39enum class ViscosityModel {
40 NONE,
44};
45
54struct Euler {
56 rtype R = 287.0;
57 rtype cp = 1004.5;
58 rtype cv = 717.5;
60 rtype mu_ref = 0.0; // Viscosity (constant) or at T_mu_ref (Sutherland, power law)
61 rtype T_mu_ref = 273.15_r;
62 rtype S_mu = 110.4_r; // Sutherland temperature
63 rtype n_mu = 0.75_r; // Power-law exponent
64 rtype Pr = 0.72_r;
65
70
74 static Euler from_input(const toml::value & input);
75
77 logging::Items summary() const;
78
83
86
91 rtype viscosity(const rtype T) const {
92 switch (viscosity_model) {
94 return mu_ref;
96 return mu_ref * Kokkos::pow(T / T_mu_ref, 1.5_r) * (T_mu_ref + S_mu) / (T + S_mu);
98 return mu_ref * Kokkos::pow(T / T_mu_ref, n_mu);
99 default:
100 return 0.0;
101 }
102 }
103
108 rtype conductivity(const rtype mu) const { return mu * cp / Pr; }
109
111 rtype get_gamma() const { return gamma; }
112
114 rtype get_energy_from_temperature(const rtype T) const { return cv * T; }
115
117 rtype get_temperature_from_energy(const rtype e) const { return e / cv; }
118
121 return p / (R * T);
122 }
123
126 return p / (rho * R);
127 }
128
131 return rho * R * T;
132 }
133
136 return (gamma - 1.0_r) * rho * e;
137 }
138
141 return Kokkos::sqrt(gamma * p / rho);
142 }
143
149 const rtype * conservatives) const {
150 const rtype rho = conservatives[0];
151 rtype u[N_DIM];
152 FOR_I_DIM u[i] = conservatives[1 + i] / rho;
153 const rtype e = conservatives[N_DIM + 1] / rho - 0.5_r * dot<N_DIM>(u, u);
155 FOR_I_DIM primitives[i] = u[i];
156 primitives[N_DIM] = p;
157 primitives[N_DIM + 1] = get_temperature_from_energy(e);
158 primitives[N_DIM + 2] = e + p / rho;
159 }
160
165 void compute_W_from_conservatives(rtype * W, const rtype * conservatives) const {
166 const rtype rho = conservatives[0];
167 W[0] = rho;
168 FOR_I_DIM W[1 + i] = conservatives[1 + i] / rho;
169 W[N_DIM + 1] = (gamma - 1.0_r) * (conservatives[N_DIM + 1] - 0.5_r * rho * dot<N_DIM>(W + 1, W + 1));
170 }
171
176 void compute_conservatives_from_W(rtype * conservatives, const rtype * W) const {
177 conservatives[0] = W[0];
178 FOR_I_DIM conservatives[1 + i] = W[0] * W[1 + i];
179 conservatives[N_DIM + 1] = W[N_DIM + 1] / (gamma - 1.0_r) + 0.5_r * W[0] * dot<N_DIM>(W + 1, W + 1);
180 }
181};
182
183#endif // PHYSICS_H
Common header file.
KOKKOS_INLINE_FUNCTION rtype dot(const rtype *a, const rtype *b)
Compute the dot product of two arrays.
Definition common_math.h:32
float rtype
Definition common_typedef.h:39
#define N_DIM
Definition common_typedef.h:28
#define FOR_I_DIM
Definition common_typedef.h:32
Console output: rank-0 info lines, aligned sections and tables, warnings and errors on stderr,...
std::vector< std::pair< std::string, std::string > > Items
Key-value lines of a setup section, in display order.
Definition log.h:27
ViscosityModel
Definition physics.h:39
PhysicsType
Definition physics.h:24
Calorically perfect gas, inviscid (Euler) or viscous and heat conducting (Navier-Stokes,...
Definition physics.h:54
rtype gamma
Definition physics.h:55
rtype cv
Definition physics.h:58
KOKKOS_INLINE_FUNCTION void compute_W_from_conservatives(rtype *W, const rtype *conservatives) const
Conservatives -> W = [rho, u, p].
Definition physics.h:165
KOKKOS_INLINE_FUNCTION rtype conductivity(const rtype mu) const
Thermal conductivity for dynamic viscosity mu.
Definition physics.h:108
KOKKOS_INLINE_FUNCTION rtype get_gamma() const
Definition physics.h:111
rtype R
Definition physics.h:56
KOKKOS_INLINE_FUNCTION rtype get_sound_speed_from_pressure_density(const rtype p, const rtype rho) const
Definition physics.h:140
KOKKOS_INLINE_FUNCTION bool is_viscous() const
Definition physics.h:85
KOKKOS_INLINE_FUNCTION rtype get_pressure_from_density_temperature(const rtype rho, const rtype T) const
Definition physics.h:130
KOKKOS_INLINE_FUNCTION rtype get_energy_from_temperature(const rtype T) const
Definition physics.h:114
KOKKOS_INLINE_FUNCTION rtype get_pressure_from_density_energy(const rtype rho, const rtype e) const
Definition physics.h:135
KOKKOS_INLINE_FUNCTION void compute_conservatives_from_W(rtype *conservatives, const rtype *W) const
W = [rho, u, p] -> conservatives.
Definition physics.h:176
KOKKOS_INLINE_FUNCTION rtype get_density_from_pressure_temperature(const rtype p, const rtype T) const
Definition physics.h:120
KOKKOS_INLINE_FUNCTION PhysicsType get_type() const
Definition physics.h:80
KOKKOS_INLINE_FUNCTION rtype get_temperature_from_energy(const rtype e) const
Definition physics.h:117
logging::Items summary() const
Display lines for the run log.
Definition physics.cpp:70
rtype T_mu_ref
Definition physics.h:61
rtype mu_ref
Definition physics.h:60
ViscosityModel viscosity_model
Definition physics.h:59
static Euler from_reference(rtype gamma, rtype p_ref, rtype T_ref, rtype rho_ref)
Construct from gamma and a reference state (p_ref = rho_ref * R * T_ref).
Definition physics.cpp:19
KOKKOS_INLINE_FUNCTION rtype viscosity(const rtype T) const
Dynamic viscosity at temperature T.
Definition physics.h:91
static Euler from_input(const toml::value &input)
Construct from the [physics] table of an input file.
Definition physics.cpp:28
rtype Pr
Definition physics.h:64
rtype cp
Definition physics.h:57
rtype S_mu
Definition physics.h:62
rtype n_mu
Definition physics.h:63
KOKKOS_INLINE_FUNCTION void compute_primitives_from_conservatives(rtype *primitives, const rtype *conservatives) const
Conservatives [rho, rho u, rho E] -> primitives [u, p, T, h].
Definition physics.h:148
KOKKOS_INLINE_FUNCTION rtype get_temperature_from_density_pressure(const rtype rho, const rtype p) const
Definition physics.h:125