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