teqp 0.22.0
Loading...
Searching...
No Matches
squarewell.hpp
Go to the documentation of this file.
1#ifndef squarewell_h
2#define squarewell_h
3
4#include <valarray>
5#include <map>
6
7namespace teqp{
8namespace squarewell{
9
10#include "teqp/types.hpp"
11
32private:
33
34 const double m_pi = 3.1415926535897932384626433;
35
36 double __factorial(int i) const{ return tgamma(i+1); }
37
38 const double lambda;
39
40 const std::map<int, std::valarray<double>> phivals = {
41 {1, {-1320.19, 5124.1, -8145.37, 6895.8, -3381.42, 968.739, -151.255, 9.98592}},
42 {2, {1049.76, -4023.29, 6305.95, -5265.42, 2553.84, -727.3, 113.631, -7.56266}}
43 };
44 const std::map<int, std::valarray<double>> thetavals = {
45 {3, {0.0, -945.597, 1326.61, -471.688, 0.0, 23.2271, -2.63477, 0.0}},
46 {4, {0.0, 4131.09,-10501.1,8909.18,-2521.96,-16.7882,19.5315,-1.27373}}
47 };
48
49 const std::map<int, std::valarray<double>> gammanvals = {
50 {1, {0, -59.0464, 26.098, 26.4454, 7.40136, 11.0743, -5.49152, 0.781823, -0.0319751, 0.827621, 0.605635, -0.254959, 0.0377111, -0.00210896 , 0.0000452328}},
51 {2, {0, 214.316, -88.1394, 273.3, 95.9759, 71.1228, -40.2656, 5.94069, -0.23842, -2.17558, -1.29255, 0.554993, -0.0857543, 0.00492511, -0.000107067 }},
52 {3, {0, -225.479, 88.8202, 250.472, 90.2606, 57.0274, -33.2376, 4.99527, -0.195714, 1.84677, 0.99813, -0.440314, 0.0708793, -0.00416274, 0.0000917291 }},
53 {4, {0, 65.0504, -25.096, 74.3095, 26.2153, 18.4397, -10.0891, 1.50243, -0.057694, -1.87154, -1.01682, 0.445247, -0.0725107, 0.00427862, -0.0000949723}}
54 };
55
56 template<typename GType>
57 double Rn(const GType &gn, double lambda_) const{
58 auto o = gn[3];
59 for (auto j = 4; j < 9; ++j){
60 o += gn[j]*pow(pow(lambda_,3)-1, j-2);
61 }
62 return o;
63 }
64
65 template<typename GType>
66 double Qn(const GType &gn, double lambda_) const{
67 auto o = gn[9];
68 for (auto j = 10; j < 15; ++j){
69 o += gn[j]*pow(pow(lambda_,3)-1, j-7);
70 }
71 return o;
72 }
73
74 double gamman(int n, double lambda_) const{
75 const auto& gn = gammanvals.at(n);
76 return gn[1]*lambda_ + gn[2]*pow(lambda_,2) + Rn(gn, lambda_)/Qn(gn, lambda_);
77 }
78
79 double phii(int i, double lambda_) const{
80 const auto& phivalsi = phivals.at(i);
81 double o = 0.0;
82 for (auto n = 0; n < 8; ++n){
83 o += phivalsi[n]*pow(lambda_, n);
84 }
85 return o;
86 };
87
88 double P1(double lambda_) const{return pow(lambda_,6) - 18*pow(lambda_,4) + 32*pow(lambda_,3) - 15;}
89 double P2(double lambda_) const{return -2*pow(lambda_,6) + 36*pow(lambda_,4) - 32*pow(lambda_,3) - 18*pow(lambda_,2) + 16;}
90 double P3(double lambda_) const{return 6*pow(lambda_,6) - 18*pow(lambda_,4) + 18*pow(lambda_,2)-6;}
91 double P4(double lambda_) const{return 32*pow(lambda_,3) - 18*pow(lambda_,2) - 48;}
92 double P5(double lambda_) const{return 5*pow(lambda_,6) - 32*pow(lambda_,3) + 18*pow(lambda_,2) + 26;};
93
94 double a2i(int i, double lambda_) const{ return -2*m_pi/(3*__factorial(i))*(pow(lambda_, 3)-1); };
95
96 double a31(double lambda_) const{ return -pow(m_pi/6, 2)*(P1(std::min(lambda_, 2.0)));};
97
98 double a32(double lambda_) const {
99 if (lambda_ <= 2)
100 return pow(m_pi/6,2)*(P2(lambda_) - P1(lambda_)/2);
101 else
102 return pow(m_pi/6,2)*(-17/2 + P4(lambda_));
103 }
104
105 double a33(double lambda_) const {
106 if (lambda_ <= 2)
107 return pow(m_pi/6,2)*(P2(lambda_) - P1(lambda_)/6 - P3(lambda_));
108 else
109 return pow(m_pi/6,2)*(-17/6 + P4(lambda_) - P5(lambda_));
110 }
111
112 auto a34(double lambda_) const{
113 if (lambda_ <= 2)
114 return pow(m_pi/6,2)*(-P1(lambda_)/24 + 7*P2(lambda_)/12 - 3*P3(lambda_)/2);
115 else
116 return pow(m_pi/6,2)*(-17/24 + 7*P4(lambda_)/12 - 3*P5(lambda_)/2);
117 }
118
119 double xi2(double lambda_) const{ return a32(lambda_)/a2i(2, lambda_); }
120 double xi3(double lambda_) const{ return a33(lambda_)/a2i(3, lambda_); }
121 double xi4(double lambda_) const{ return a34(lambda_)/a2i(4, lambda_); }
122
123 template<typename RhoType>
124 auto Ki(int i, const RhoType & rhostar, double lambda_) const{
125 const auto & thetai = thetavals.at(i);
126 RhoType num = 0.0;
127 for (auto n = 1; n < 5; ++n){
128 num += thetai[n]*pow(lambda_, n);
129 }
130 num *= powi(rhostar, 2);
131 RhoType den = 0;
132 for (auto n = 5; n < 8; ++n){
133 den += thetai[n]*pow(lambda_, n-4);
134 }
135 den = 1.0 + rhostar*den;
136 return forceeval(num/den);
137 }
138
139 template<typename RhoType>
140 auto Chi(const RhoType & rhostar, double lambda_) const { return forceeval(a2i(2, lambda_)*rhostar*(1.0-powi(rhostar,2)/1.5129)); }
141
142 template<typename RhoType>
143 auto aHS(const RhoType & rhostar) const{
144 return forceeval(-3.0*m_pi*rhostar*(m_pi*rhostar-8.0)/powi(forceeval(m_pi*rhostar-6.0), 2));
145 }
146
147 template<typename RhoType>
148 auto get_a1(const RhoType & rhostar, double lambda_) const{
149 RhoType o = a2i(1, lambda_)*powi(rhostar, 2-1) + a31(lambda_)*powi(rhostar, 3-1);
150 for (auto i = 1; i < 5; ++i){
151 o = o + gamman(i, lambda_)*powi(rhostar, i+2);
152 }
153 return forceeval(o);
154 }
155
156 template<typename RhoType>
157 auto get_a2(const RhoType & rhostar, double lambda_) const{
158 return forceeval(Chi(rhostar, lambda_)*exp(xi2(lambda_)*rhostar + phii(1, lambda_)*powi(rhostar,3) + phii(2,lambda_)*powi(rhostar,4)));
159 }
160
161 template<typename RhoType>
162 auto get_a3(const RhoType & rhostar, double lambda_) const {
163 return forceeval(a2i(3, lambda_)*rhostar*exp(xi3(lambda_)*rhostar + Ki(3, rhostar, lambda_)));
164 }
165
166 template<typename RhoType>
167 auto get_a4(const RhoType & rhostar, double lambda_) const {
168 return forceeval(a2i(4, lambda_)*rhostar*exp(xi4(lambda_)*rhostar + Ki(4, rhostar, lambda_)));
169 }
170
171public:
172 EspindolaHeredia2009(double lambda) : lambda(lambda){};
173
174 // We are in "simulation units", so R is 1.0, and T and rho are T^* and rho^*
175 template<typename MoleFracType>
176 double R(const MoleFracType &) const { return 1.0; }
177
179 auto get_lambda() const {
180 return lambda;
181 }
182
188 template<typename TType, typename RhoType, typename MoleFracType>
189 auto alphar(const TType& Tstar,
190 const RhoType& rhostar,
191 const MoleFracType& /*molefrac*/) const
192 {
193 auto a1 = get_a1(rhostar, lambda);
194 auto a2 = get_a2(rhostar, lambda);
195 auto a3 = get_a3(rhostar, lambda);
196 auto a4 = get_a4(rhostar, lambda);
197
198 return forceeval(aHS(rhostar)
199 + a1/Tstar
200 + a2/pow(Tstar, 2)
201 + a3/pow(Tstar, 3)
202 + a4/pow(Tstar, 4));
203 }
204};
205
206}
207}
208
209#endif /* squarewell_h */
auto alphar(const TType &Tstar, const RhoType &rhostar, const MoleFracType &) const
auto get_lambda() const
Return the lambda parameter.
double R(const MoleFracType &) const
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