Mallard 0.8.0
Unstructured, GPU accelerated, high-order finite volume CFD solver
Mallard website
Loading...
Searching...
No Matches
mixture.h
Go to the documentation of this file.
1
12#ifndef MIXTURE_H
13#define MIXTURE_H
14
15#include <map>
16#include <string>
17#include <vector>
18
19#include <Kokkos_Core.hpp>
20#include <toml.hpp>
21
22#include "common.h"
23#include "log.h"
24#include "mechanism.h"
25#include "reactor.h"
26#include "state.h"
27#include "thermo.h"
28#include "transport.h"
29
33 double inv_rho;
34 KOKKOS_INLINE_FUNCTION double operator()(const uint32_t k) const { return static_cast<double>(rhoY[k]) * inv_rho; }
35};
36
45struct Mixture {
47 chemistry::TransportTable<> transport; // empty for inviscid runs
49 bool viscous = false;
50
57 void cell_state(const rtype * U, const CellSpecies & rhoY, const rtype T_guess, rtype * W, rtype & gamma, rtype & e0,
58 rtype & T) const {
59 constexpr uint8_t E = N_DIM + 1;
60 const double rho = static_cast<double>(U[0]);
61 W[0] = U[0];
62 double u2 = 0.0;
63 FOR_I_DIM {
64 W[1 + i] = U[1 + i] / U[0];
65 u2 += static_cast<double>(U[1 + i]) * static_cast<double>(U[1 + i]);
66 }
67 const double e = static_cast<double>(U[E]) / rho - 0.5 * u2 / (rho * rho);
68 const PartialDensities y{rhoY, 1.0 / rho};
69 const double T_cell = thermo.T_from_e(e, y, static_cast<double>(T_guess));
70 const double R = thermo.gas_constant(y);
71 const double cv = thermo.cp_mass(T_cell, y) - R;
72 W[E] = static_cast<rtype>(rho * R * T_cell);
73 gamma = static_cast<rtype>((cv + R) / cv);
74 e0 = static_cast<rtype>(e - cv * T_cell);
75 T = static_cast<rtype>(T_cell);
76 }
77};
78
84 public:
91 static MixtureModel from_input(const toml::value & input);
92
93 const chemistry::Mechanism & mechanism() const { return mech; }
94 const Mixture & device() const { return gas; }
95 bool viscous() const { return gas.viscous; }
96 uint32_t n_species() const { return gas.n_species; }
97 std::vector<std::string> species_names() const { return mech.species_names(); }
98
106 std::vector<double> mass_fractions(const toml::value & table, const std::string & where) const;
107
112 static bool composition_varies(const toml::value & table);
113
115 std::vector<double> mass_fractions_from_mole(const std::vector<double> & X) const;
116
118 std::vector<double> mole_fractions(const std::vector<double> & Y) const;
119
121 double gas_constant(const std::vector<double> & Y) const;
122
124 double energy(double T, const std::vector<double> & Y) const;
125
127 void surrogates(double T, const std::vector<double> & Y, double & gamma, double & e0) const;
128
133 void conservatives(double p, double T, const rtype * u, const std::vector<double> & Y, rtype * U,
134 rtype * rhoY) const;
135
137 logging::Items summary() const;
138
139 private:
142 Mixture gas;
143 std::string transport_name;
144};
145
151chemistry::ReactorOptions reactor_options(const toml::value & input);
152
153#endif // MIXTURE_H
Host side of the mixture gas model: the mechanism, a host copy of the thermodynamics for setup,...
Definition mixture.h:83
std::vector< double > mole_fractions(const std::vector< double > &Y) const
Mole fractions from mass fractions.
Definition mixture.cpp:127
bool viscous() const
Definition mixture.h:95
void conservatives(double p, double T, const rtype *u, const std::vector< double > &Y, rtype *U, rtype *rhoY) const
Conservatives and partial densities at pressure p, temperature T, velocity u and mass fractions Y.
Definition mixture.cpp:156
void surrogates(double T, const std::vector< double > &Y, double &gamma, double &e0) const
Frozen gamma and energy offset e0 = e - cv T at T.
Definition mixture.cpp:148
std::vector< double > mass_fractions(const toml::value &table, const std::string &where) const
Mass fractions from a table of the input holding X (mole fractions) or Y, by species name; normalized...
Definition mixture.cpp:78
uint32_t n_species() const
Definition mixture.h:96
std::vector< double > mass_fractions_from_mole(const std::vector< double > &X) const
Mass fractions from mole fractions.
Definition mixture.cpp:116
static bool composition_varies(const toml::value &table)
Whether the X or Y of a table varies in space: some value is an expression (a string) or a balance sp...
Definition mixture.cpp:105
double energy(double T, const std::vector< double > &Y) const
Internal energy per unit mass at T [J/kg].
Definition mixture.cpp:142
const Mixture & device() const
Definition mixture.h:94
std::vector< std::string > species_names() const
Definition mixture.h:97
static MixtureModel from_input(const toml::value &input)
From the [physics] table: mechanism and optional phase; for type = "navier_stokes" the transport mode...
Definition mixture.cpp:18
double gas_constant(const std::vector< double > &Y) const
Gas constant of a composition [J/(kg K)].
Definition mixture.cpp:138
const chemistry::Mechanism & mechanism() const
Definition mixture.h:93
logging::Items summary() const
Display lines for the run log.
Definition mixture.cpp:167
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,...
Gas-phase mechanisms read from Cantera YAML files.
chemistry::ReactorOptions reactor_options(const toml::value &input)
Chemistry integrator options from the optional [chemistry] table: rtol, atol (on mass fractions),...
Definition mixture.cpp:178
std::vector< std::pair< std::string, std::string > > Items
Key-value lines of a setup section, in display order.
Definition log.h:27
Adiabatic constant-volume reactor: the chemistry of one cell over a splitting step,...
Conservative state: the flow block and the species partial densities.
The partial densities of one cell, in any layout.
Definition state.h:40
Device side of the mixture gas model, captured by value in kernels.
Definition mixture.h:45
uint32_t n_species
Definition mixture.h:48
bool viscous
Definition mixture.h:49
chemistry::ThermoTable thermo
Definition mixture.h:46
KOKKOS_INLINE_FUNCTION void cell_state(const rtype *U, const CellSpecies &rhoY, const rtype T_guess, rtype *W, rtype &gamma, rtype &e0, rtype &T) const
State of a cell from its conservatives U and contiguous partial densities rhoY: W = [rho,...
Definition mixture.h:57
chemistry::TransportTable transport
Definition mixture.h:47
Mass fractions of a cell from its partial densities.
Definition mixture.h:31
CellSpecies rhoY
Definition mixture.h:32
KOKKOS_INLINE_FUNCTION double operator()(const uint32_t k) const
Definition mixture.h:34
double inv_rho
Definition mixture.h:33
One ideal-gas phase of a Cantera YAML file: its elements, species and reactions.
Definition mechanism.h:145
std::vector< std::string > species_names() const
Definition mechanism.cpp:622
Definition reactor.h:27
Species thermodynamics of a mechanism on the device, in double precision in every build: per species ...
Definition thermo.h:43
KOKKOS_INLINE_FUNCTION double gas_constant(const F_Y &y) const
Mixture gas constant R_u sum_k Y_k / W_k [J/(kg K)].
Definition thermo.h:117
KOKKOS_INLINE_FUNCTION double cp_mass(const double T, const F_Y &y) const
Mixture cp [J/(kg K)].
Definition thermo.h:125
KOKKOS_INLINE_FUNCTION double T_from_e(const double e, const F_Y &y, const double T_guess) const
Temperature at which the mixture has internal energy e: Newton from T_guess (300 K if outside the bra...
Definition thermo.h:161
Transport properties of a mechanism's mixtures on the device, in double precision in every build: Wil...
Definition transport.h:87
SlotArray< double, Space > X
Definition teno_setup.cpp:478
Device tables of species thermodynamics and thermally perfect mixture properties.
Species transport fits and mixture-averaged transport properties on the device.