Line data Source code
1 : #ifndef MODEL_GAS_H_
2 : #define MODEL_GAS_H_
3 :
4 : #include <vector>
5 : #include <cmath>
6 : #include <memory>
7 : #include "Model/Gas/Thermo/CpConstant.H"
8 : #include "Model/Gas/Transport/Mixture_Averaged.H"
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 :
15 : namespace Model {
16 : namespace Gas {
17 :
18 : class Gas {
19 : protected:
20 : public:
21 : int nspecies;
22 : std::vector<double> MW; // Species molecular weights, kg/kmol
23 : Thermo::Thermo *thermo = nullptr;
24 : Transport::Transport *transport = nullptr;
25 : EOS::EOS *eos = nullptr;
26 :
27 : public:
28 8 : virtual ~Gas() {
29 8 : delete thermo;
30 8 : delete transport;
31 8 : delete eos;
32 8 : }
33 :
34 8 : static void Parse(Gas & value, IO::ParmParse & pp)
35 : {
36 : // number of species
37 16 : pp.queryarr_required("mw",value.MW,Unit::Mass()/Unit::Amount());
38 8 : value.nspecies = value.MW.size();
39 :
40 8 : delete value.thermo;
41 8 : value.thermo = nullptr;
42 : // thermo model
43 16 : pp.select<Thermo::CpConstant>("thermo", value.thermo, value.nspecies);
44 :
45 8 : delete value.transport;
46 8 : value.transport = nullptr;
47 : // transport model
48 16 : pp.select<Transport::Mixture_Averaged>("transport", value.transport, value.nspecies, value.MW, value.thermo);
49 :
50 8 : delete value.eos;
51 8 : value.eos = nullptr;
52 : // eos model
53 16 : pp.select<EOS::CPG>("eos", value.eos, &value);
54 8 : }
55 :
56 : public:
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
80 : public:
81 19924848 : void ComputeLocalFractions(
82 : Set::Patch<const Set::Scalar>& density_mf,
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 19924848 : double density = 0.0;
91 19924848 : double moles = 0.0;
92 39849696 : for (int n=0; n<nspecies; ++n) {
93 19924848 : density += density_mf(i,j,k,n);
94 19924848 : moles += density_mf(i,j,k,n) / MW[n];
95 : }
96 39849696 : for (int n=0; n<nspecies; ++n) {
97 39849696 : mass_fraction_mf(i,j,k,n) = density_mf(i,j,k,n) / density;
98 39849696 : mole_fraction_mf(i,j,k,n) = density_mf(i,j,k,n) / MW[n] / moles;
99 : }
100 19924848 : }
101 251612896 : double GetMW(Set::Patch<const Set::Scalar>& X, int i, int j, int k) const {
102 : // Molecular weight, kg/kmol
103 251612896 : double mw = 0.0;
104 503225792 : for (int n=0; n<nspecies; ++n) mw += X(i,j,k,n) * MW[n];
105 251612896 : return mw;
106 : }
107 39827448 : double ComputeD(Set::Patch<const Set::Scalar>& rhoY, int i, int j, int k) const {
108 : // Mixture density kg/m^3
109 39827448 : double rho = 0.0;
110 79654896 : for (int n=0; n<nspecies; ++n) rho += rhoY(i,j,k,n);
111 39827448 : return rho;
112 : }
113 251612896 : double R(Set::Patch<const Set::Scalar>& X, int i, int j, int k) const {
114 : // Specific gas constant, J/(kg-K)
115 251612896 : 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 231688048 : 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 231688048 : 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 231688048 : double gamma(double T, Set::Patch<const Set::Scalar>& X, int i, int j, int k) const {
130 : // Specific heat ratio
131 231688048 : 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
|