LCOV - code coverage report
Current view: top level - src/Model/Gas - Gas.H (source / functions) Coverage Total Hit
Test: coverage_merged.info Lines: 100.0 % 35 35
Test Date: 2026-06-29 14:20:01 Functions: 100.0 % 8 8

            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              :     double Rg;
      23              :     std::vector<double> MW;      // Species molecular weights, kg/kmol
      24              :     Thermo::Thermo<Thermo::CpConstant> thermo;
      25              :     Transport::Transport<Transport::Mixture_Averaged> transport;
      26              :     EOS::EOS<EOS::CPG> eos;
      27              : 
      28              : public:
      29            8 :     Gas() 
      30            8 :     {
      31            8 :         this->Rg = Set::Constant::Rg;
      32            8 :     }
      33              :     Gas(IO::ParmParse& pp, std::string name) : Gas()
      34              :     {
      35              :         pp.queryclass(name, *this);
      36              :     }
      37              : 
      38            8 :     static void Parse(Gas & value, IO::ParmParse & pp)
      39              :     {
      40              :         // number of species
      41           16 :         pp.queryarr_required("mw",value.MW,Unit::Mass()/Unit::Amount());
      42            8 :         value.nspecies = value.MW.size();
      43              : 
      44              :         // thermo model
      45           16 :         pp.select<Thermo::CpConstant>("thermo", value.thermo, value.nspecies);
      46              : 
      47              :         // transport model
      48           16 :         pp.select<Transport::Mixture_Averaged>("transport", value.transport, value.nspecies, value.MW, value.thermo);
      49              : 
      50              :         // eos model
      51           16 :         pp.select<EOS::CPG>("eos", value.eos);
      52            8 :     }
      53              :     
      54              : public:
      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
      78              : public:
      79     19924848 :     void ComputeLocalFractions(
      80              :             Set::Patch<const Set::Scalar>& density_mf,
      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     19924848 :         double density = 0.0;
      89     19924848 :         double moles = 0.0;
      90     39849696 :         for (int n=0; n<nspecies; ++n) {
      91     19924848 :             density += density_mf(i,j,k,n);
      92     19924848 :             moles += density_mf(i,j,k,n) / MW[n];
      93              :         }
      94     39849696 :         for (int n=0; n<nspecies; ++n) {
      95     39849696 :             mass_fraction_mf(i,j,k,n) = density_mf(i,j,k,n) / density;
      96     39849696 :             mole_fraction_mf(i,j,k,n) = density_mf(i,j,k,n) / MW[n] / moles;
      97              :         }
      98     19924848 :     }
      99    251612896 :     double GetMW(Set::Patch<const Set::Scalar>& X, int i, int j, int k) const {
     100              :         // Molecular weight, kg/kmol
     101    251612896 :         double mw = 0.0;
     102    503225792 :         for (int n=0; n<nspecies; ++n) mw += X(i,j,k,n) * MW[n];
     103    251612896 :         return mw;
     104              :     }
     105     39827448 :     double ComputeD(Set::Patch<const Set::Scalar>& rhoY, int i, int j, int k) const {
     106              :         // Mixture density kg/m^3
     107     39827448 :         double rho = 0.0;
     108     79654896 :         for (int n=0; n<nspecies; ++n) rho += rhoY(i,j,k,n);
     109     39827448 :         return rho;
     110              :     }
     111    251612896 :     double R(Set::Patch<const Set::Scalar>& X, int i, int j, int k) const { 
     112              :         // Specific gas constant, J/(kg-K)
     113    251612896 :         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    231688048 :     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    231688048 :         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    231688048 :     double gamma(double T, Set::Patch<const Set::Scalar>& X, int i, int j, int k) const  {
     128              :         // Specific heat ratio
     129    231688048 :         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
        

Generated by: LCOV version 2.0-1