Line data Source code
1 : #ifndef MODEL_GAS_THERMO_CPCONSTANT_H_
2 : #define MODEL_GAS_THERMO_CPCONSTANT_H_
3 :
4 : #include <vector>
5 : #include <memory>
6 : #include <cmath>
7 : #include "IO/ParmParse.H"
8 : #include "Model/Gas/Thermo/Thermo.H"
9 :
10 : namespace Model {
11 : namespace Gas {
12 : namespace Thermo {
13 :
14 : class CpConstant : public Thermo {
15 : public:
16 : static constexpr const char* name = "cpconstant";
17 8 : const char* model_name() const override { return name; }
18 :
19 : private:
20 : int nspecies = 1;
21 : std::vector<double> cp_moles;
22 : std::vector<double> h0;
23 : std::vector<double> s0;
24 : std::vector<double> Tref;
25 :
26 : public:
27 8 : CpConstant() {} ;
28 8 : CpConstant(int a_nspecies, IO::ParmParse& pp, std::string name) : CpConstant()
29 : {
30 8 : nspecies = a_nspecies;
31 8 : pp.queryclass(name, *this);
32 8 : }
33 :
34 16 : ~CpConstant() override = default;
35 :
36 8 : static void Parse(CpConstant & value, IO::ParmParse & pp)
37 : {
38 : // heat capacity in moles (one per species)
39 16 : pp.queryarr_required("cp_moles",value.cp_moles,Unit::Energy()/Unit::Amount()/Unit::Temperature());
40 : // molar enthalpy (one per species)
41 16 : pp.queryarr_required("h0",value.h0,Unit::Energy()/Unit::Amount());
42 : // molar entropy (one per species)
43 16 : pp.queryarr_required("s0",value.s0, Unit::Energy()/Unit::Amount()/Unit::Temperature());
44 : // reference temperature (one per species)
45 16 : pp.queryarr_required("Tref",value.Tref, Unit::Temperature());
46 :
47 56 : Util::Assert(INFO, TEST(value.cp_moles.size() == (size_t)value.nspecies));
48 56 : Util::Assert(INFO, TEST(value.h0.size() == (size_t)value.nspecies));
49 56 : Util::Assert(INFO, TEST(value.s0.size() == (size_t)value.nspecies));
50 56 : Util::Assert(INFO, TEST(value.Tref.size() == (size_t)value.nspecies));
51 8 : }
52 :
53 : public:
54 463376096 : double cp_mol(double /*T*/, Set::Patch<const Set::Scalar>& X, int i, int j, int k) const override {
55 : // Specific heat (constant pressure), J/(kmol-K)
56 463376096 : double cp = 0.0;
57 926752192 : for (int n=0; n<nspecies; ++n) cp += X(i,j,k,n) * cp_moles[n];
58 463376096 : return cp;
59 : }
60 0 : double enthalpy_mol(double T, Set::Patch<const Set::Scalar>& X, int i, int j, int k) const override {
61 : // Specific enthalpy, J/kmol)
62 0 : double h = 0.0;
63 0 : for (int n=0; n<nspecies; ++n) h += X(i,j,k,n) * (cp_moles[n] * (T - Tref[n]) + h0[n]);
64 0 : return h;
65 : }
66 0 : double entropy_mol(double T, Set::Patch<const Set::Scalar>& X, int i, int j, int k) const override {
67 : // specific entropy, J/(kmol-K)
68 0 : double s = 0.0;
69 0 : for (int n=0; n<nspecies; ++n) s += X(i,j,k,n) * (cp_moles[n] * log(T / Tref[n]) + s0[n]);
70 0 : return s;
71 : }
72 :
73 : }; // class CpConstant
74 :
75 : } // namespace Thermo
76 : } // namespace Gas
77 : } // namespace Model
78 :
79 : #endif
|