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