Cantera  2.1.2
Water.cpp
Go to the documentation of this file.
1 //! @file Water.cpp
2 #include "Water.h"
4 
5 using namespace Cantera;
6 
7 namespace tpx
8 {
9 static const double Tmn=273.16;
10 static const double Tmx=1600.0;
11 static const double M=18.016;
12 static const double Tc=647.286;
13 static const double Pc=22.089e6;
14 static const double Roc=317.0;
15 static const double To=273.16;
16 static const double R=461.51;
17 static const double E=4.8E-3;
18 static const double Ta=1000.0;
19 static const double tauc=1.544912;
20 static const double Tp=338.15;
21 static const double aww=0.01;
22 static const double Roa1=634.0;
23 static const double Roaj=1000.0;
24 static const double u0=2375470.875;
25 static const double s0=6697.356635;
26 
27 static const double A[10][7]= {{
28  2.9492937E-2,-5.1985860E-3,
29  6.8335354E-3,-1.5641040E-4,
30  -6.3972405E-3, -3.9661401E-3, -6.9048554E-4
31  },
32  {
33  -1.3213917E-4,7.7779182E-6, -2.6149751E-5,-7.2546108E-7,
34  2.6409282E-5, 1.5453061E-5,2.7407416E-6
35  },
36  {
37  2.7464632E-7,-3.3301902E-8,6.5326396E-8,-9.2734289E-9,
38  -4.7740374E-8,-2.9142470E-8,-5.1028070E-9
39  },
40  {
41  -3.6093828E-10, -1.6254622E-11, -2.6181978E-11, 4.3125840E-12,
42  5.6323130E-11, 2.9568796E-11,3.9636085E-12
43  },
44  {3.4218431E-13, -1.7731074E-13,0,0,0,0,0},
45  {-2.4450042E-16, 1.2748742E-16,0,0,0,0,0},
46  {1.5518535E-19, 1.3746153E-19,0,0,0,0,0},
47  {5.9728487E-24,1.5597836E-22, 0,0,0,0,0},
48  {
49  -4.1030848E-1, 3.3731180E-1, -1.3746678E-1, 6.7874983E-3,
50  1.3687317E-1, 7.984797E-2, 1.3041253E-2
51  },
52  {
53  -4.1605860E-4, -2.0988866E-4,-7.3396848E-4,1.0401717E-5,
54  6.4581880E-4, 3.9917570E-4, 7.1531353E-5
55  }
56 };
57 
58 static const double F[]= {-7.4192420, 2.9721E-1,-1.155286E-1,8.685635E-3,
59  1.0940980E-3, -4.39993E-3, 2.5206580E-3, -5.2186840E-4
60  };
61 
62 static const double D[]= {3.6711257,-2.8512396E1,2.2265240E2,-8.8243852E2,
63  2.0002765E3,-2.6122557E3,1.8297674E3,-5.3350520E2
64  };
65 
66 static const double G[]= {4.6E4,1.011249E3,8.3893E-1,-2.19989E-4,2.466619E-7,
67  -9.704700E-11
68  };
69 
70 static const double taua[] = {1.544912, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5};
71 
72 inline double water::C(int i)
73 {
74  double tau = Ta/T;
75  return (i == 0 ? R*T : R*T*(tau - tauc)*pow(tau - taua[i],i-1));
76 }
77 
78 inline double water::Cprime(int i)
79 {
80  double tau = Ta/T;
81  return (i == 0 ? R : (i == 1 ? -R*tauc :
82  -R*pow(tau - taua[i],i-2)*(tauc*(tau - taua[i])
83  + (i-1)*tau*(tau - tauc))));
84 }
85 
86 inline double water::I(int j)
87 {
88  double factor, sum, rho_aj;
89  rho_aj = (j == 0 ? Roa1 : Roaj);
90  sum = 0.0;
91  factor = Rho - rho_aj;
92  for (int i=7; i>0; i--) {
93  sum += A[i][j];
94  sum *= factor;
95  }
96  sum += A[0][j];
97  sum += (exp(-E*Rho)*(A[8][j] + A[9][j]*Rho));
98  return Rho*sum;
99 }
100 
101 inline double water::H(int j)
102 {
103  double factor, sum, rho_aj;
104  rho_aj = (j == 0 ? Roa1 : Roaj);
105  sum = 0.0;
106  factor = Rho - rho_aj;
107  for (int i=6; i>0; i--) {
108  sum += (A[i][j] + Rho*(i+1)*A[i+1][j]);
109  sum *= factor;
110  }
111  sum += (A[0][j] + Rho*A[1][j]);
112  sum += (exp(-E*Rho)*((1.0 - Rho*E)*A[8][j]
113  + Rho*(2.0 - Rho*E)*A[9][j]));
114  sum += A[7][j]*pow(factor,7);
115  return Rho*Rho*sum;
116 }
117 
118 double water::up()
119 {
120  double sum = 0.0;
121  int i;
122  for (i=0; i<7; i++) {
123  sum += (C(i) - T*Cprime(i))*I(i);
124  }
125  for (i=1; i<6; i++) {
126  sum += G[i]*(pow(T,i) - pow(To,i))/double(i);
127  }
128  sum += G[0]*log(T/To) + u0;
129  return sum + m_energy_offset;
130 }
131 
132 double water::sp()
133 {
134  double sum = 0.0;
135  int i;
136  for (i=2; i<6; i++) {
137  sum += G[i]*(pow(T,i-1) - pow(To,i-1))/double(i-1);
138  }
139  sum += G[1]*log(T/To);
140  sum -= G[0]*(1.0/T - 1.0/To);
141  sum += s0 - R*log(Rho);
142  for (i=0; i<7; i++) {
143  sum -= Cprime(i)*I(i);
144  }
145  return sum + m_entropy_offset;
146 }
147 
148 double water::Pp()
149 {
150  double P = Rho*R*T;
151  for (int i=0; i<7; i++) {
152  P += C(i)*H(i);
153  }
154  return P;
155 }
156 
157 double water::Psat()
158 {
159  double log, sum=0;
160  if ((T < Tmn) || (T > Tc)) {
161  throw TPX_Error("water::Psat",
162  "Temperature out of range. T = " + fp2str(T));
163  }
164  for (int i=1; i<=8; i++) {
165  sum += F[i-1]*pow(aww*(T-Tp),double(i-1)); // DGG mod
166  }
167  log = (Tc/T-1)*sum;
168  return exp(log)*Pc;
169 }
170 
171 /*
172 double water::dPsatdT(){
173  double log, sum1=0, sum2=0;
174  int i;
175  if ((T < Tmn) || (T > Tc))
176  set_Err(TempError); // Error("water::dPsatdT",TempError,T);
177  for (i=1;i<=8;i++)
178  sum1 += F[i-1]*pow(a*(T-Tp),double(i-1));
179  for (i=2;i<=8;i++)
180  sum2 += F[i-1]*a*(i-1)*pow(a*(T-Tp),double(i-2));
181  log = (Tc/T-1)*sum2 - Tc*sum1/(T*T);
182  return log*Psat();
183 }
184 */
185 
186 double water::ldens()
187 {
188  double sum=0;
189  int i;
190  if ((T < Tmn) || (T >= Tc)) {
191  throw TPX_Error("water::ldens",
192  "Temperature out of range. T = " + fp2str(T));
193  }
194  for (i=0; i<8; i++) {
195  sum+=D[i]*pow(1.0 - T/Tc, double(i+1)/3.0);
196  }
197  return Roc*(1+sum);
198 }
199 
200 double water::Tcrit()
201 {
202  return Tc;
203 }
204 double water::Pcrit()
205 {
206  return Pc;
207 }
208 double water::Vcrit()
209 {
210  return 1.0/Roc;
211 }
212 double water::Tmin()
213 {
214  return Tmn;
215 }
216 double water::Tmax()
217 {
218  return Tmx;
219 }
220 char* water::name()
221 {
222  return (char*) m_name.c_str();
223 }
224 char* water::formula()
225 {
226  return (char*) m_formula.c_str();
227 }
228 double water::MolWt()
229 {
230  return M;
231 }
232 
233 }
std::string fp2str(const double x, const std::string &fmt)
Convert a double into a c++ string.
Definition: stringUtils.cpp:29
Contains declarations for string manipulation functions within Cantera.