teqp 0.22.0
Loading...
Searching...
No Matches
johnson.hpp
Go to the documentation of this file.
1#pragma once
2
11private:
12
13 const double MY_PI = EIGEN_PI;
14
15 const std::vector<std::tuple<int, double>> c_dhBH {
16 {-2, 0.011117524},
17 {-1, -0.076383859},
18 { 0, 1.080142248},
19 { 1, 0.000693129}
20 };
21 const double c_ln_dhBH = -0.063920968;
22
23 const std::vector<std::tuple<int, double>> c_Delta_B2_hBH {
24 {-7, -0.58544978},
25 {-6, 0.43102052},
26 {-5, 0.87361369},
27 {-4, -4.13749995},
28 {-3, 2.90616279},
29 {-2, -7.02181962},
30 { 0, 0.02459877}
31 };
32
33 const std::vector<std::tuple<int, int, double>> c_Cij = {
34 { 0, 2, 2.01546797},
35 { 0, 3, -28.17881636},
36 { 0, 4, 28.28313847},
37 { 0, 5, -10.42402873},
38 {-1, 2, -19.58371655},
39 {-1, 3, 75.62340289},
40 {-1, 4, -120.70586598},
41 {-1, 5, 93.92740328},
42 {-1, 6, -27.37737354},
43 {-2, 2, 29.34470520},
44 {-2, 3, -112.3535693},
45 {-2, 4, 170.64908980 },
46 {-2, 5, -123.06669187},
47 {-2, 6, 34.42288969 },
48 {-4, 2, -13.37031968},
49 {-4, 3, 65.38059570},
50 {-4, 4, -115.09233113},
51 {-4, 5, 88.91973082},
52 {-4, 6, -25.62099890}
53 };
54
55 const double gamma = 1.92907278;
56
57 // Form of Eq. 29
58 template<typename TTYPE>
59 auto get_dhBH(const TTYPE& Tstar) const {
60 TTYPE summer = c_ln_dhBH*log(Tstar);
61 for (auto [i, C_i] : c_dhBH){
62 summer += C_i*pow(Tstar, i/2.0);
63 }
64 return forceeval(summer);
65 }
66
67 template<typename TTYPE>
68 auto get_d_dhBH_d1T(const TTYPE& Tstar) const {
69 TTYPE summer = c_ln_dhBH;
70 for (auto [i, C_i] : c_dhBH){
71 summer += (i/2.0)*C_i*pow(Tstar, i/2.0);
72 }
73 return forceeval(-Tstar*summer);
74 }
75
76 // Form of Eq. 29
77 template<typename TTYPE>
78 auto get_DeltaB2hBH(const TTYPE& Tstar) const {
79 TTYPE summer = 0.0;
80 for (auto [i, C_i] : c_Delta_B2_hBH){
81 summer += C_i*pow(Tstar, i/2.0);
82 }
83 return forceeval(summer);
84 }
85
86 template<typename TTYPE>
87 auto get_d_DeltaB2hBH_d1T(const TTYPE& Tstar) const {
88 TTYPE summer = 0.0;
89 for (auto [i, C_i] : c_Delta_B2_hBH){
90 summer += (i/2.0)*C_i*pow(Tstar, i/2.0);
91 }
92 return forceeval(-Tstar*summer);
93 }
94
95 // Eq. 5 from K-N
96 template<typename TTYPE, typename RHOTYPE>
97 auto get_ahs(const TTYPE& Tstar, const RHOTYPE& rhostar) const {
98 auto zeta = MY_PI/6.0*rhostar*pow(get_dhBH(Tstar), 3);
99 return forceeval(Tstar*(5.0/3.0*log(1.0-zeta) + zeta*(34.0-33.0*zeta+4.0*POW2(zeta))/(6.0*POW2(1.0-zeta))));
100 }
101
102 // Eq. 4 from K-N
103 template<typename TTYPE, typename RHOTYPE>
104 auto get_zhs(const TTYPE& Tstar, const RHOTYPE& rhostar) const {
105 std::common_type_t<TTYPE, RHOTYPE> zeta = MY_PI/6.0*rhostar*POW3(get_dhBH(Tstar));
106 return forceeval((1.0+zeta+zeta**zeta-2.0/3.0*POW3(zeta)*(1+zeta))/POW3(1.0-zeta));
107 }
108
109 // Eq. 30 from K-N
110 template<typename TTYPE, typename RHOTYPE>
111 auto get_a(const TTYPE& Tstar, const RHOTYPE& rhostar) const{
112 std::common_type_t<TTYPE, RHOTYPE> summer = 0.0;
113 for (auto [i, j, Cij] : c_Cij){
114 summer += Cij*pow(Tstar, i/2.0)*powi(rhostar, j);
115 }
116 return forceeval(get_ahs(Tstar, rhostar) + exp(-gamma*POW2(rhostar))*rhostar*Tstar*get_DeltaB2hBH(Tstar)+summer);
117 }
118
119public:
120 // We are in "simulation units", so R is 1.0, and T and rho that go into alphar are actually T^* and rho^*
121 template<typename MoleFracType>
122 double R(const MoleFracType &) const { return 1.0; }
123
124 template<typename TTYPE, typename RHOTYPE, typename MoleFracType>
125 auto alphar(const TTYPE& Tstar, const RHOTYPE& rhostar, const MoleFracType& /*molefrac*/) const {
126 return forceeval(get_a(Tstar, rhostar)/Tstar);
127 }
128};
129
130};
131
133
141
142private:
143 template<typename T>
144 auto POW2(const T& x) const -> T{
145 return x*x;
146 }
147
148 template<typename T>
149 auto POW3(const T& x) const -> T{
150 return POW2(x)*x;
151 }
152
153 template<typename T>
154 auto POW4(const T& x) const -> T{
155 return POW2(x)*POW2(x);
156 }
157
158 const double gamma = 3.0;
159 const std::vector<double> x {
160 0.0, // placeholder for i=0 term since C++ uses 0-based indexing
161 0.8623085097507421,
162 2.976218765822098,
163 -8.402230115796038,
164 0.1054136629203555,
165 -0.8564583828174598,
166 1.582759470107601,
167 0.7639421948305453,
168 1.753173414312048,
169 2.798291772190376e03,
170 -4.8394220260857657e-2,
171 0.9963265197721935,
172 -3.698000291272493e01,
173 2.084012299434647e01,
174 8.305402124717285e01,
175 -9.574799715203068e02,
176 -1.477746229234994e02,
177
178 6.398607852471505e01,
179 1.603993673294834e01,
180 6.805916615864377e01,
181 -2.791293578795945e03,
182 -6.245128304568454,
183 -8.116836104958410e03,
184 1.488735559561229e01,
185 -1.059346754655084e04,
186 -1.131607632802822e02,
187 -8.867771540418822e03,
188 -3.986982844450543e01,
189 -4.689270299917261e03,
190 2.593535277438717e02,
191 -2.694523589434903e03,
192 -7.218487631550215e02,
193 1.721802063863269e02
194 };
195
196 // Table 5
197 template<typename TTYPE>
198 auto get_ai(const int i, const TTYPE& Tstar) const -> TTYPE{
199 switch(i){
200 case 1:
201 return x[1]*Tstar + x[2]*sqrt(Tstar) + x[3] + x[4]/Tstar + x[5]/POW2(Tstar);
202 case 2:
203 return x[6]*Tstar + x[7] + x[8]/Tstar + x[9]/POW2(Tstar);
204 case 3:
205 return x[10]*Tstar + x[11] + x[12]/Tstar;
206 case 4:
207 return x[13];
208 case 5:
209 return x[14]/Tstar + x[15]/POW2(Tstar);
210 case 6:
211 return x[16]/Tstar;
212 case 7:
213 return x[17]/Tstar + x[18]/POW2(Tstar);
214 case 8:
215 return x[19]/POW2(Tstar);
216 default:
217 throw teqp::InvalidArgument("i is not possible in get_ai");
218 }
219 }
220
221 // Table 6
222 template<typename TTYPE>
223 auto get_bi(const int i, const TTYPE& Tstar) const -> TTYPE{
224 switch(i){
225 case 1:
226 return x[20]/POW2(Tstar) + x[21]/POW3(Tstar);
227 case 2:
228 return x[22]/POW2(Tstar) + x[23]/POW4(Tstar);
229 case 3:
230 return x[24]/POW2(Tstar) + x[25]/POW3(Tstar);
231 case 4:
232 return x[26]/POW2(Tstar) + x[27]/POW4(Tstar);
233 case 5:
234 return x[28]/POW2(Tstar) + x[29]/POW3(Tstar);
235 case 6:
236 return x[30]/POW2(Tstar) + x[31]/POW3(Tstar) + x[32]/POW4(Tstar);
237 default:
238 throw teqp::InvalidArgument("i is not possible in get_bi");
239 }
240 }
241
242 // Table 7
243 template<typename FTYPE, typename RHOTYPE>
244 auto get_Gi(const int i, const FTYPE& F, const RHOTYPE& rhostar) const -> RHOTYPE{
245 if (i == 1){
246 return forceeval((1.0-F)/(2.0*gamma));
247 }
248 else{
249 // Recursive definition of the other terms;
250 return forceeval(-(F*powi(rhostar, 2*(i-1)) - 2.0*(i-1)*get_Gi(i-1, F, rhostar))/(2.0*gamma));
251 }
252 }
253
254 template<typename TTYPE, typename RHOTYPE>
255 auto get_alphar(const TTYPE& Tstar, const RHOTYPE& rhostar) const{
256 std::common_type_t<TTYPE, RHOTYPE> summer = 0.0;
257 auto F = exp(-gamma*POW2(rhostar));
258 for (int i = 1; i <= 8; ++i){
259 summer += get_ai(i, Tstar)*powi(rhostar, i)/static_cast<double>(i);
260 }
261 for (int i = 1; i <= 6; ++i){
262 summer += get_bi(i, Tstar)*get_Gi(i, F, rhostar);
263 }
264 return forceeval(summer);
265 }
266
267public:
268 // We are in "simulation units", so R is 1.0, and T and rho that
269 // go into alphar are actually T^* and rho^*
270 template<typename MoleFracType>
271 double R(const MoleFracType &) const { return 1.0; }
272
273 template<typename TTYPE, typename RHOTYPE, typename MoleFracType>
274 auto alphar(const TTYPE& Tstar, const RHOTYPE& rhostar, const MoleFracType& /*molefrac*/) const {
275 return forceeval(get_alphar(Tstar, rhostar)/Tstar);
276 }
277};
278
279};
auto alphar(const TTYPE &Tstar, const RHOTYPE &rhostar, const MoleFracType &) const
Definition johnson.hpp:274
double R(const MoleFracType &) const
Definition johnson.hpp:271
auto alphar(const TTYPE &Tstar, const RHOTYPE &rhostar, const MoleFracType &) const
Definition johnson.hpp:125
auto POW2(const A &x)
auto POW3(const A &x)
T powi(const T &x, int n)
From Ulrich Deiters.
Definition types.hpp:139
auto pow(const double &x, const double &e)
Definition types.hpp:195
auto forceeval(T &&expr)
Definition types.hpp:52