Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 T2inverse = pow(T, -2);
216  double T3inverse = pow(T, -3);
217  double T4inverse = pow(T, -4);
218  double egrho = exp(-Gamma*Rho*Rho);
219 
220  double sum = 0.0;
221 
222  for (int i=2; i<=5; i++) {
223  sum += G[i]*(pow(T,i-1) - pow(To,i-1))/double(i-1);
224  }
225 
226  sum += G[1]*log(T/To);
227  sum -= G[0]*(1.0/T - 1.0/To);
228 
229 
230  for (int i=0; i<=6; i++) {
231  sum -= Cprime(i,T2inverse, T3inverse, T4inverse)*I(i,egrho,Gamma);
232  }
233 
234  sum += s0 - R*log(Rho);
235 
236  return sum + m_entropy_offset;
237 }
238 
239 double CarbonDioxide::Pp()
240 {
241  double Tinverse = pow(T,-1);
242  double T2inverse = pow(T, -2);
243  double T3inverse = pow(T, -3);
244  double T4inverse = pow(T, -4);
245  double egrho = exp(-Gamma*Rho*Rho);
246 
247  double P = Rho*R*T;
248 
249  // when i=0 we are on second sum of equation (where rho^2)
250  for (int i=0; i<=6; i++) {
251  P += C(i,Tinverse, T2inverse, T3inverse, T4inverse)*H(i,egrho);
252  }
253  return P;
254 }
255 
256 double CarbonDioxide::Psat()
257 {
258  double log, sum=0,P;
259  if ((T < Tmn) || (T > Tc)) {
260  throw TPX_Error("CarbonDixoide::Psat",
261  "Temperature out of range. T = " + fp2str(T));
262  }
263  for (int i=1; i<=8; i++) {
264  sum += F[i-1] * pow((T/Tp -1),double(i-1));
265  }
266 
267  log = ((Tc/T)-1)*sum;
268  P=exp(log)*Pc;
269  return P;
270 
271 }
272 
273 double CarbonDioxide::ldens()
274 {
275  double xx=1-(T/Tc), sum=0;
276  if ((T < Tmn) || (T > Tc)) {
277  throw TPX_Error("CarbonDixoide::ldens",
278  "Temperature out of range. T = " + fp2str(T));
279  }
280  for (int i=1; i<=6; i++) {
281  sum+=D[i-1]*pow(xx,double(i-1)/3.0);
282  }
283 
284  return sum;
285 }
286 
287 // The following functions allow users to get the properties of CarbonDioxide
288 // that are not dependent on the state
289 
290 double CarbonDioxide::Tcrit()
291 {
292  return Tc;
293 }
294 double CarbonDioxide::Pcrit()
295 {
296  return Pc;
297 }
298 double CarbonDioxide::Vcrit()
299 {
300  return 1.0/Roc;
301 }
302 double CarbonDioxide::Tmin()
303 {
304  return Tmn;
305 }
306 double CarbonDioxide::Tmax()
307 {
308  return Tmx;
309 }
310 double CarbonDioxide::MolWt()
311 {
312  return M;
313 }
314 
315 }
std::string fp2str(const double x, const std::string &fmt)
Convert a double into a c++ string.
Definition: stringUtils.cpp:28
Contains declarations for string manipulation functions within Cantera.