Cantera  2.1.2
CarbonDioxide.cpp
Go to the documentation of this file.
1 /**
2  * @file CarbonDioxide.cpp representation of substance Carbon Dioxide.
3  *
4  * Values and functions are from "Thermodynamic Properties in SI" by W.C.
5  * Reynolds AUTHOR: me@rebeccahhunt.com: GCEP, Stanford University
6  */
7 
8 #include "CarbonDioxide.h"
10 
11 using namespace Cantera;
12 
13 namespace tpx
14 {
15 
16 /*
17  * Carbon Dioxide constants
18  */
19 static const double Tmn = 216.54; // [K] minimum temperature for which calculations are valid
20 static const double Tmx = 1500.0; // [K] maximum temperature for which calculations are valid
21 static const double Tc=304.21; // [K] critical temperature
22 static const double Roc=464.00; // [kg/m^3] critical density
23 static const double To=216.54; // [K] reference Temperature
24 static const double R=188.918; // [] gas constant for CO2 J/kg/K
25 static const double Gamma=5.0E-6; // [??]
26 static const double u0=3.2174105E5; // [] internal energy at To
27 static const double s0=2.1396056E3; // [] entropy at To
28 static const double Tp=250; // [K] ??
29 static const double Pc=7.38350E6; // [Pa] critical pressure
30 static const double M=44.01; // [kg/kmol] molar density
31 
32 // array Acarbdi is used by the function named Pp
33 static const double Acarbdi[]= {
34  2.2488558E-1,
35  -1.3717965E2,
36  -1.4430214E4,
37  -2.9630491E6,
38  -2.0606039E8,
39  4.5554393E-5,
40  7.7042840E-2,
41  4.0602371E1,
42  4.0029509E-7,
43  -3.9436077E-4,
44  1.2115286E-10,
45  1.0783386E-7,
46  4.3962336E-11,
47  -3.6505545E4,
48  1.9490511E7,
49  -2.9186718E9,
50  2.4358627E-2,
51  -3.7546530E1,
52  1.1898141E4
53 };
54 
55 // array F is used by the function named Psat
56 static const double F[]= {
57  -6.5412610,
58  -2.7914636E-1,
59  -3.4716202,
60  -3.4989637,
61  -1.9770948E1,
62  1.3922839E2,
63  -2.7670389E2,
64  -7.0510251E3
65 };
66 
67 // array D is used by the function ldens
68 static const double D[]= {
69  4.6400009E2,
70  6.7938129E2,
71  1.4776836E3,
72  -3.1267676E3,
73  3.6397656E3,
74  -1.3437098E3
75 };
76 
77 // array G is used by the function sp
78 static const double G[]= {
79  8.726361E3,
80  1.840040E2,
81  1.914025,
82  -1.667825E-3,
83  7.305950E-7,
84  -1.255290E-10,
85 };
86 
87 double CarbonDioxide::C(int j,double Tinverse, double T2inverse, double T3inverse, double T4inverse)
88 {
89  switch (j) {
90  case 0 :
91  return Acarbdi[0]*T +
92  Acarbdi[1] +
93  Acarbdi[2] * Tinverse +
94  Acarbdi[3] * T2inverse +
95  Acarbdi[4] * T3inverse ;
96  case 1 :
97  return Acarbdi[5] *T +
98  Acarbdi[6] +
99  Acarbdi[7] * Tinverse ;
100  case 2 :
101  return Acarbdi[8]*T + Acarbdi[9];
102  case 3 :
103  return Acarbdi[10]*T + Acarbdi[11];
104  case 4 :
105  return Acarbdi[12];
106  case 5 :
107  return Acarbdi[13] *T2inverse +
108  Acarbdi[14] *T3inverse +
109  Acarbdi[15] *T4inverse;
110  case 6 :
111  return Acarbdi[16] *T2inverse +
112  Acarbdi[17] *T3inverse +
113  Acarbdi[18] *T4inverse;
114  default :
115  return 0.0;
116  }
117 }
118 
119 inline double CarbonDioxide::Cprime(int j, double T2inverse, double T3inverse, double T4inverse)
120 {
121  switch (j) {
122  case 0 :
123  return Acarbdi[0] +
124  - Acarbdi[2] * T2inverse +
125  -2 * Acarbdi[3] * T3inverse +
126  -3 * Acarbdi[4] * T4inverse ;
127  case 1 :
128  return Acarbdi[5] -
129  Acarbdi[7] * T2inverse;
130  case 2 :
131  return Acarbdi[8] ;
132  case 3 :
133  return Acarbdi[10] ;
134  case 4 :
135  return 0;
136  case 5 :
137  return
138  -2 *Acarbdi[13] *T3inverse +
139  -3 *Acarbdi[14] *T4inverse +
140  -4 *Acarbdi[15]* pow(T,-5);
141  case 6 :
142  return
143  -2 *Acarbdi[16] *T3inverse +
144  -3 *Acarbdi[17] *T4inverse +
145  -4 *Acarbdi[18] *pow(T,-5);
146  default :
147  return 0.0;
148  }
149 }
150 
151 inline double CarbonDioxide::I(int j, double ergho, double Gamma)
152 {
153  switch (j) {
154 
155  case 0:
156  return Rho;
157  case 1:
158  return pow(Rho, 2)/2;
159  case 2:
160  return pow(Rho, 3)/ 3;
161  case 3:
162  return pow(Rho, 4)/ 4;
163  case 4:
164  return pow(Rho, 5)/ 5;
165  case 5:
166  return (1 - ergho) / double(2 * Gamma);
167  case 6:
168  return (1 - ergho * double(Gamma * pow(Rho,2) + double(1)))/ double(2 * Gamma * Gamma);
169  default:
170  return 0.0;
171  }
172 }
173 
174 double CarbonDioxide::H(int i, double egrho)
175 {
176  if (i < 5) {
177  return pow(Rho,i+2);
178  } else if (i == 5) {
179  return pow(Rho,3)*egrho;
180  } else if (i == 6) {
181  return pow(Rho,5)*egrho;
182  } else {
183  return 0;
184  }
185 }
186 
187 double CarbonDioxide::up()
188 {
189  double Tinverse = 1.0/T;
190  double T2inverse = pow(T, -2);
191  double T3inverse = pow(T, -3);
192  double T4inverse = pow(T, -4);
193  double egrho = exp(-Gamma*Rho*Rho);
194 
195  double sum = 0.0;
196 
197  // Equation C-6 integrated
198  sum += G[0]*log(T/To);
199  int i;
200  for (i=1; i<=5; i++) {
201  sum += G[i]*(pow(T,i) - pow(To,i))/double(i);
202  }
203 
204  for (i=0; i<=6; i++) {
205  sum += I(i,egrho, Gamma) *
206  (C(i, Tinverse, T2inverse, T3inverse, T4inverse) - T*Cprime(i,T2inverse, T3inverse, T4inverse));
207  }
208 
209  sum += u0;
210  return sum + m_energy_offset;
211 }
212 
213 double CarbonDioxide::sp()
214 {
215  //double Tinverse = 1.0/T;
216  double T2inverse = pow(T, -2);
217  double T3inverse = pow(T, -3);
218  double T4inverse = pow(T, -4);
219  double egrho = exp(-Gamma*Rho*Rho);
220 
221  double sum = 0.0;
222 
223  for (int i=2; i<=5; i++) {
224  sum += G[i]*(pow(T,i-1) - pow(To,i-1))/double(i-1);
225  }
226 
227  sum += G[1]*log(T/To);
228  sum -= G[0]*(1.0/T - 1.0/To);
229 
230 
231  for (int i=0; i<=6; i++) {
232  sum -= Cprime(i,T2inverse, T3inverse, T4inverse)*I(i,egrho,Gamma);
233  }
234 
235  sum += s0 - R*log(Rho);
236 
237  return sum + m_entropy_offset;
238 }
239 
240 double CarbonDioxide::Pp()
241 {
242  double Tinverse = pow(T,-1);
243  double T2inverse = pow(T, -2);
244  double T3inverse = pow(T, -3);
245  double T4inverse = pow(T, -4);
246  double egrho = exp(-Gamma*Rho*Rho);
247 
248  double P = Rho*R*T;
249 
250  // when i=0 we are on second sum of equation (where rho^2)
251  for (int i=0; i<=6; i++) {
252  P += C(i,Tinverse, T2inverse, T3inverse, T4inverse)*H(i,egrho);
253  }
254  return P;
255 }
256 
257 double CarbonDioxide::Psat()
258 {
259  double log, sum=0,P;
260  if ((T < Tmn) || (T > Tc)) {
261  throw TPX_Error("CarbonDixoide::Psat",
262  "Temperature out of range. T = " + fp2str(T));
263  }
264  for (int i=1; i<=8; i++) {
265  sum += F[i-1] * pow((T/Tp -1),double(i-1));
266  }
267 
268  log = ((Tc/T)-1)*sum;
269  P=exp(log)*Pc;
270 
271  //cout << "Psat is returning " << P << " at T " << T << " and Pc " << Pc << " and Tp " << Tp << endl;
272  return P;
273 
274 }
275 
276 double CarbonDioxide::ldens()
277 {
278  double xx=1-(T/Tc), sum=0;
279  if ((T < Tmn) || (T > Tc)) {
280  throw TPX_Error("CarbonDixoide::ldens",
281  "Temperature out of range. T = " + fp2str(T));
282  }
283  for (int i=1; i<=6; i++) {
284  sum+=D[i-1]*pow(xx,double(i-1)/3.0);
285  }
286 
287  return sum;
288 }
289 
290 // The following functions allow users to get the properties of CarbonDioxide
291 // that are not dependent on the state
292 
293 double CarbonDioxide::Tcrit()
294 {
295  return Tc;
296 }
297 double CarbonDioxide::Pcrit()
298 {
299  return Pc;
300 }
301 double CarbonDioxide::Vcrit()
302 {
303  return 1.0/Roc;
304 }
305 double CarbonDioxide::Tmin()
306 {
307  return Tmn;
308 }
309 double CarbonDioxide::Tmax()
310 {
311  return Tmx;
312 }
313 char* CarbonDioxide::name()
314 {
315  return (char*) m_name.c_str() ;
316 }
317 char* CarbonDioxide::formula()
318 {
319  return (char*) m_formula.c_str();
320 }
321 double CarbonDioxide::MolWt()
322 {
323  return M;
324 }
325 
326 }
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.