13#ifndef CHEMISTRY_TRANSPORT_H
14#define CHEMISTRY_TRANSPORT_H
23#include <Kokkos_Core.hpp>
64 std::vector<std::array<double, 9>>
cstar;
86template <
typename MemorySpace = Kokkos::DefaultExecutionSpace::memory_space>
90 Kokkos::View<double *, MemorySpace>
W;
92 Kokkos::View<double *[5], Kokkos::LayoutRight, MemorySpace>
visc;
93 Kokkos::View<double *[5], Kokkos::LayoutRight, MemorySpace>
cond;
94 Kokkos::View<double **[5], Kokkos::LayoutRight, MemorySpace>
diff;
95 Kokkos::View<double **, Kokkos::LayoutRight, MemorySpace>
wilke_w;
96 Kokkos::View<double **, Kokkos::LayoutRight, MemorySpace>
wilke_d;
98 Kokkos::View<double **[9], Kokkos::LayoutRight, MemorySpace>
cstar;
99 Kokkos::View<double **, Kokkos::LayoutRight, MemorySpace>
log_eps;
101 static constexpr double TINY = 1.0e-20;
104 static double poly(
const double *
c,
const double L) {
105 return c[0] +
L * (
c[1] +
L * (
c[2] +
L * (
c[3] +
L *
c[4])));
110 const double s = Kokkos::sqrt(Kokkos::sqrt(T)) *
poly(&
visc(k, 0), Kokkos::log(T));
116 return Kokkos::sqrt(T) *
poly(&
cond(k, 0), Kokkos::log(T));
122 return T * Kokkos::sqrt(T) *
poly(&
diff(k,
j, 0), Kokkos::log(T)) / p;
138 template <
typename F_Y>
140 const F_Y & y,
double & mu,
double &
lambda,
double *
D,
141 double *
DT =
nullptr)
const {
142 const double L = Kokkos::log(T);
143 const double sqrt_T = Kokkos::sqrt(T);
147 auto Y = [&](
const uint32_t k) {
return Kokkos::fmax(0.0, y(k)); };
150 const double inv_n = 1.0 / n;
158 const double f = 1.0 +
D[k] /
D[
j] *
wilke_w(k,
j);
161 mu +=
X(k) *
D[k] *
D[k] / sum;
172 if (
j == k)
continue;
173 const double f = 1.0 +
D[k] /
D[
j] *
wilke_w(k,
j);
176 DT[k] = (15.0 / 4.0) *
D[k] *
D[k] /
W(k) / (1.0 + 1.065 * sum /
X(k));
203 const double *
c = &
cstar(k,
j, 0);
205 for (
int m = 7;
m >= 0;
m--) C = C *
log_ts +
c[
m];
207 const double f = (1.2 * C - 1.0) /
D_kj / (
W(k) +
W(
j));
208 const double s = f * (Y(k) *
DT[
j] - Y(
j) *
DT[k]);
218 double sum = 0.0,
others = 0.0;
220 if (
j == k)
continue;
241template <
typename MemorySpace = Kokkos::DefaultExecutionSpace::memory_space>
243 const std::vector<double> &
lewis = {},
244 const bool thermal_diffusion =
false) {
250 table.W = Kokkos::View<double *, MemorySpace>(
"transport_W", n);
251 table.inv_Lewis = Kokkos::View<double *, MemorySpace>(
"transport_inv_Lewis", n);
252 table.visc = Kokkos::View<double *[5], Kokkos::LayoutRight, MemorySpace>(
"transport_visc", n);
253 table.cond = Kokkos::View<double *[5], Kokkos::LayoutRight, MemorySpace>(
"transport_cond", n);
254 table.diff = Kokkos::View<double **[5], Kokkos::LayoutRight, MemorySpace>(
"transport_diff", n, n);
255 table.wilke_w = Kokkos::View<double **, Kokkos::LayoutRight, MemorySpace>(
"transport_wilke_w", n, n);
256 table.wilke_d = Kokkos::View<double **, Kokkos::LayoutRight, MemorySpace>(
"transport_wilke_d", n, n);
257 auto h_W = Kokkos::create_mirror_view(table.W);
258 auto h_inv_Le = Kokkos::create_mirror_view(table.inv_Lewis);
259 auto h_visc = Kokkos::create_mirror_view(table.visc);
260 auto h_cond = Kokkos::create_mirror_view(table.cond);
261 auto h_diff = Kokkos::create_mirror_view(table.diff);
262 auto h_ww = Kokkos::create_mirror_view(table.wilke_w);
263 auto h_wd = Kokkos::create_mirror_view(table.wilke_d);
266 h_W(k) = mechanism.
species[k].molecular_weight;
268 for (
size_t c = 0;
c < 5;
c++) {
273 for (
size_t c = 0;
c < 5;
c++) {
282 h_wd(k,
j) = 1.0 / (std::sqrt(8.0) * std::sqrt(1.0 +
h_W(k) /
h_W(
j)));
285 Kokkos::deep_copy(table.W,
h_W);
286 Kokkos::deep_copy(table.inv_Lewis,
h_inv_Le);
287 Kokkos::deep_copy(table.visc,
h_visc);
288 Kokkos::deep_copy(table.cond,
h_cond);
289 Kokkos::deep_copy(table.diff,
h_diff);
290 Kokkos::deep_copy(table.wilke_w,
h_ww);
291 Kokkos::deep_copy(table.wilke_d,
h_wd);
292 if (thermal_diffusion) {
294 throw std::invalid_argument(
"Thermal diffusion needs the mixture-averaged transport model.");
297 table.thermal_diffusion =
true;
298 table.cstar = Kokkos::View<double **[9], Kokkos::LayoutRight, MemorySpace>(
"transport_cstar", n, n);
299 table.log_eps = Kokkos::View<double **, Kokkos::LayoutRight, MemorySpace>(
"transport_log_eps", n, n);
300 auto h_cstar = Kokkos::create_mirror_view(table.cstar);
301 auto h_log_eps = Kokkos::create_mirror_view(table.log_eps);
305 for (
size_t c = 0;
c < 9;
c++) {
312 Kokkos::deep_copy(table.cstar,
h_cstar);
313 Kokkos::deep_copy(table.log_eps,
h_log_eps);
KOKKOS_INLINE_FUNCTION rtype dot(const rtype *a, const rtype *b)
Compute the dot product of two arrays.
Definition common_math.h:32
Gas-phase mechanisms read from Cantera YAML files.
constexpr double BOLTZMANN
Definition mechanism.h:25
TransportFits fit_transport(const Mechanism &mechanism)
Fit the transport properties of every species of a mechanism.
Definition transport.cpp:352
TransportTable< MemorySpace > make_transport_table(const Mechanism &mechanism, const TransportModel model, const std::vector< double > &lewis={}, const bool thermal_diffusion=false)
The transport table of a mechanism for a model.
Definition transport.h:242
TransportModel
Definition transport.h:29
ThermalDiffusionFits fit_thermal_diffusion(const Mechanism &mechanism)
Fit the thermal diffusion data of a mechanism.
Definition transport.cpp:441
One ideal-gas phase of a Cantera YAML file: its elements, species and reactions.
Definition mechanism.h:145
std::vector< Species > species
Definition mechanism.h:149
uint32_t n_species() const
Definition mechanism.h:152
Pair data of Cantera's mixture-averaged thermal diffusion: its fit of the reduced collision integral ...
Definition transport.h:63
std::vector< std::array< double, 9 > > cstar
Definition transport.h:64
std::vector< double > well_depth
Definition transport.h:65
Pure-species transport fits of a mechanism, as Cantera computes them for its mixture-averaged model: ...
Definition transport.h:44
std::vector< std::array< double, 5 > > viscosity
Definition transport.h:45
std::vector< std::array< double, 5 > > conductivity
Definition transport.h:46
std::vector< std::array< double, 5 > > diffusion
Definition transport.h:47
Transport properties of a mechanism's mixtures on the device, in double precision in every build: Wil...
Definition transport.h:87
static KOKKOS_INLINE_FUNCTION double poly(const double *c, const double L)
Definition transport.h:104
KOKKOS_INLINE_FUNCTION double species_conductivity(const uint32_t k, const double T) const
Definition transport.h:115
Kokkos::View< double *, MemorySpace > inv_Lewis
Definition transport.h:91
Kokkos::View< double *, MemorySpace > W
Definition transport.h:90
static constexpr double TINY
Definition transport.h:101
Kokkos::View< double *[5], Kokkos::LayoutRight, MemorySpace > visc
Definition transport.h:92
KOKKOS_INLINE_FUNCTION void properties(const double T, const double p, const double rho, const double cp, const F_Y &y, double &mu, double &lambda, double *D, double *DT=nullptr) const
Mixture viscosity mu [Pa s], conductivity lambda [W/(m K)] and species diffusion coefficients D [m^2/...
Definition transport.h:139
Kokkos::View< double **, Kokkos::LayoutRight, MemorySpace > wilke_d
Definition transport.h:96
Kokkos::View< double *[5], Kokkos::LayoutRight, MemorySpace > cond
Definition transport.h:93
TransportModel model
Definition transport.h:89
uint32_t n_species
Definition transport.h:88
Kokkos::View< double **, Kokkos::LayoutRight, MemorySpace > log_eps
Definition transport.h:99
bool thermal_diffusion
Definition transport.h:97
Kokkos::View< double **, Kokkos::LayoutRight, MemorySpace > wilke_w
Definition transport.h:95
KOKKOS_INLINE_FUNCTION double species_viscosity(const uint32_t k, const double T) const
Definition transport.h:109
KOKKOS_INLINE_FUNCTION double binary_diffusion(const uint32_t k, const uint32_t j, const double T, const double p) const
Binary diffusion coefficient D_kj [m^2/s] at T and p.
Definition transport.h:121
Kokkos::View< double **[5], Kokkos::LayoutRight, MemorySpace > diff
Definition transport.h:94
Kokkos::View< double **[9], Kokkos::LayoutRight, MemorySpace > cstar
Definition transport.h:98
SlotArray< double, Space > X
Definition teno_setup.cpp:478
CellSetup< ExecSpace > c
Definition teno_setup.cpp:1810
@ DT
Definition time_integrator.h:55