Alamo
Gas.H
Go to the documentation of this file.
1#ifndef MODEL_GAS_H_
2#define MODEL_GAS_H_
3
4#include <vector>
5#include <cmath>
6#include <memory>
9#include "Model/Gas/EOS/CPG.H"
10#include "Util/Util.H"
11#include "Set/Base.H"
12#include "Set/Set.H"
13#include "IO/ParmParse.H"
14
15namespace Model {
16namespace Gas {
17
18class Gas {
19protected:
20public:
22 std::vector<double> MW; // Species molecular weights, kg/kmol
25 EOS::EOS *eos = nullptr;
26
27public:
28 virtual ~Gas() {
29 delete thermo;
30 delete transport;
31 delete eos;
32 }
33
34 static void Parse(Gas & value, IO::ParmParse & pp)
35 {
36 // number of species
37 pp.queryarr_required("mw",value.MW,Unit::Mass()/Unit::Amount());
38 value.nspecies = value.MW.size();
39
40 delete value.thermo;
41 value.thermo = nullptr;
42 // thermo model
43 pp.select<Thermo::CpConstant>("thermo", value.thermo, value.nspecies);
44
45 delete value.transport;
46 value.transport = nullptr;
47 // transport model
48 pp.select<Transport::Mixture_Averaged>("transport", value.transport, value.nspecies, value.MW, value.thermo);
49
50 delete value.eos;
51 value.eos = nullptr;
52 // eos model
53 pp.select<EOS::CPG>("eos", value.eos, &value);
54 }
55
56public:
57 // Thermodynamic quantities
58 double cp_mol(double T, Set::Patch<const Set::Scalar>& X, int i, int j, int k) const;
59 double enthalpy_mol(double T, Set::Patch<const Set::Scalar>& X, int i, int j, int k) const;
60 double entropy_mol(double T, Set::Patch<const Set::Scalar>& X, int i, int j, int k) const;
61
62 // Transport quantities
63 double dynamic_viscosity(double T, Set::Patch<const Set::Scalar>& X, int i, int j, int k) const;
64 double thermal_conductivity(double T, Set::Patch<const Set::Scalar>& X, int i, int j, int k) const;
65 void diffusion_coeffs(Set::Patch<Set::Scalar>& DKM, double T, double P, Set::Patch<const Set::Scalar>& X, int i, int j, int k);
66
67 // EOS
68 double ComputeT(
69 double density, double momentumx, double momentumy, double E, double Tguess,
70 Set::Patch<const Set::Scalar>& X, int i, int j, int k, double rtol=1e-12) const;
71 double ComputeT(
72 double pressure, double density,
73 Set::Patch<const Set::Scalar>& X, int i, int j, int k) const;
74 double ComputeP(double density, double T, Set::Patch<const Set::Scalar>& X, int i, int j, int k) const;
75 double ComputeE(
76 double density, double momentumx, double momentumy, double T,
77 Set::Patch<const Set::Scalar>& X, int i, int j, int k) const;
78
79// Universal methods inherent to Gas
80public:
83 Set::Patch<Set::Scalar>& mass_fraction_mf,
84 Set::Patch<Set::Scalar>& mole_fraction_mf,
85 const int i, const int j, const int k)
86 {
87 // In place update for mass and mole fractions
88 // This needs to be called before any other functions if cell composition
89 // has changed, since they are dependent on mole fraction
90 double density = 0.0;
91 double moles = 0.0;
92 for (int n=0; n<nspecies; ++n) {
93 density += density_mf(i,j,k,n);
94 moles += density_mf(i,j,k,n) / MW[n];
95 }
96 for (int n=0; n<nspecies; ++n) {
97 mass_fraction_mf(i,j,k,n) = density_mf(i,j,k,n) / density;
98 mole_fraction_mf(i,j,k,n) = density_mf(i,j,k,n) / MW[n] / moles;
99 }
100 }
101 double GetMW(Set::Patch<const Set::Scalar>& X, int i, int j, int k) const {
102 // Molecular weight, kg/kmol
103 double mw = 0.0;
104 for (int n=0; n<nspecies; ++n) mw += X(i,j,k,n) * MW[n];
105 return mw;
106 }
107 double ComputeD(Set::Patch<const Set::Scalar>& rhoY, int i, int j, int k) const {
108 // Mixture density kg/m^3
109 double rho = 0.0;
110 for (int n=0; n<nspecies; ++n) rho += rhoY(i,j,k,n);
111 return rho;
112 }
113 double R(Set::Patch<const Set::Scalar>& X, int i, int j, int k) const {
114 // Specific gas constant, J/(kg-K)
115 return Set::Constant::Rg/GetMW(X, i, j, k);
116 }
117 double cp_mass(double T, Set::Patch<const Set::Scalar>& X, int i, int j, int k) const {
118 // Specific heat (constant pressure), J/(kg-K)
119 return cp_mol(T, X, i, j, k) / GetMW(X, i, j, k);
120 }
121 double cv_mol(double T, Set::Patch<const Set::Scalar>& X, int i, int j, int k) const {
122 // Specific heat (constant volume), J/(kmol-K)
123 return cp_mol(T, X, i, j, k) - Set::Constant::Rg;
124 }
125 double cv_mass(double T, Set::Patch<const Set::Scalar>& X, int i, int j, int k) const {
126 // Specific heat (constant volume), J/(kg-K)
127 return cv_mol(T, X, i, j, k) / GetMW(X, i, j, k);
128 }
129 double gamma(double T, Set::Patch<const Set::Scalar>& X, int i, int j, int k) const {
130 // Specific heat ratio
131 return cp_mol(T, X, i, j, k) / cv_mol(T, X, i, j, k);
132 }
133 double enthalpy_mass(double T, Set::Patch<const Set::Scalar>& X, int i, int j, int k) const {
134 // Specific enthalpy, J/kg
135 return enthalpy_mol(T, X, i, j, k) / GetMW(X, i, j, k);
136 }
137 double entropy_mass(double T, Set::Patch<const Set::Scalar>& X, int i, int j, int k) const {
138 // Specific entropy, J/(kg-K)
139 return entropy_mol(T, X, i, j, k) / GetMW(X, i, j, k);
140 }
141
142}; // class Gas
143
144} // namespace Gas
145} // namespace Model
146
147#endif
#define X(name)
void select(std::string name, PTRTYPE *&ic_eta, Args &&... args)
Definition ParmParse.H:1056
int queryarr_required(std::string name, std::vector< T > &value)
Definition ParmParse.H:643
double R(Set::Patch< const Set::Scalar > &X, int i, int j, int k) const
Definition Gas.H:113
std::vector< double > MW
Definition Gas.H:22
double ComputeP(double density, double T, Set::Patch< const Set::Scalar > &X, int i, int j, int k) const
Definition Gas.cpp:66
double ComputeT(double density, double momentumx, double momentumy, double E, double Tguess, Set::Patch< const Set::Scalar > &X, int i, int j, int k, double rtol=1e-12) const
Definition Gas.cpp:52
Thermo::Thermo * thermo
Definition Gas.H:23
double GetMW(Set::Patch< const Set::Scalar > &X, int i, int j, int k) const
Definition Gas.H:101
void ComputeLocalFractions(Set::Patch< const Set::Scalar > &density_mf, Set::Patch< Set::Scalar > &mass_fraction_mf, Set::Patch< Set::Scalar > &mole_fraction_mf, const int i, const int j, const int k)
Definition Gas.H:81
double gamma(double T, Set::Patch< const Set::Scalar > &X, int i, int j, int k) const
Definition Gas.H:129
virtual ~Gas()
Definition Gas.H:28
double entropy_mol(double T, Set::Patch< const Set::Scalar > &X, int i, int j, int k) const
Definition Gas.cpp:28
void diffusion_coeffs(Set::Patch< Set::Scalar > &DKM, double T, double P, Set::Patch< const Set::Scalar > &X, int i, int j, int k)
Definition Gas.cpp:45
double dynamic_viscosity(double T, Set::Patch< const Set::Scalar > &X, int i, int j, int k) const
Definition Gas.cpp:35
double cv_mass(double T, Set::Patch< const Set::Scalar > &X, int i, int j, int k) const
Definition Gas.H:125
double ComputeD(Set::Patch< const Set::Scalar > &rhoY, int i, int j, int k) const
Definition Gas.H:107
double thermal_conductivity(double T, Set::Patch< const Set::Scalar > &X, int i, int j, int k) const
Definition Gas.cpp:40
double cp_mol(double T, Set::Patch< const Set::Scalar > &X, int i, int j, int k) const
Definition Gas.cpp:18
double cv_mol(double T, Set::Patch< const Set::Scalar > &X, int i, int j, int k) const
Definition Gas.H:121
EOS::EOS * eos
Definition Gas.H:25
double entropy_mass(double T, Set::Patch< const Set::Scalar > &X, int i, int j, int k) const
Definition Gas.H:137
double ComputeE(double density, double momentumx, double momentumy, double T, Set::Patch< const Set::Scalar > &X, int i, int j, int k) const
Definition Gas.cpp:71
double cp_mass(double T, Set::Patch< const Set::Scalar > &X, int i, int j, int k) const
Definition Gas.H:117
double enthalpy_mol(double T, Set::Patch< const Set::Scalar > &X, int i, int j, int k) const
Definition Gas.cpp:23
static void Parse(Gas &value, IO::ParmParse &pp)
Definition Gas.H:34
double enthalpy_mass(double T, Set::Patch< const Set::Scalar > &X, int i, int j, int k) const
Definition Gas.H:133
Transport::Transport * transport
Definition Gas.H:24
int nspecies
Definition Gas.H:21
Set::Scalar Rg
Definition Set.cpp:14
Eigen::Matrix< amrex::Real, AMREX_SPACEDIM, 1 > Vector
Definition Base.H:19
static Unit Amount()
Definition Unit.H:203
static Unit Mass()
Definition Unit.H:200