Cantera  2.1.2
Heptane.cpp
Go to the documentation of this file.
1 /**
2  * @file Heptane.cpp representation of substance Heptane.
3  *
4  * Values and functions are from "Thermodynamic Properties in SI" by W.C.
5  * Reynolds. AUTHOR: jrh@stanford.edu: GCEP, Stanford University
6  */
7 
8 #include "Heptane.h"
10 
11 using namespace Cantera;
12 
13 namespace tpx
14 {
15 
16 // Heptane constants
17 static const double Tmn = 182.56; // [K] minimum temperature for which calculations are valid
18 static const double Tmx = 1000.0; // [K] maximum temperature for which calculations are valid
19 static const double Tc=537.68; // [K] critical temperature
20 static const double Roc=197.60; // [kg/m^3] critical density
21 static const double To=300; // [K] reference Temperature
22 static const double R=82.99504; // [J/(kg*K)] gas constant (for this substance)
23 static const double Gamma=9.611604E-6; // [??]
24 static const double u0=3.4058439E5; // [] internal energy at To
25 static const double s0=1.1080254E3; // [] entropy at To
26 static const double Tp=400; // [K] ??
27 static const double Pc=2.6199E6; // [Pa] critical pressure
28 static const double M=100.20; // [kg/kmol] molar density
29 
30 // array Ahept is used by the function Pp
31 static const double Ahept[]= {
32  2.246032E-3,
33  2.082990E2,
34  5.085746E7,
35  3.566396E9,
36  1.622168E9,
37  1.065237E-5,
38  5.987922E-1,
39  7.736602,
40  1.929386E5,
41  5.291379E-9
42 };
43 
44 // array F is used by Psat
45 static const double F[]= {
46  -7.2298764,
47  3.8607475E-1,
48  -3.4216472,
49  4.6274432E-1,
50  -9.7926124,
51  -4.2058094E1,
52  7.5468678E1,
53  3.1758992E2
54 };
55 
56 // array D is used by the function ldens
57 static const double D[]= {
58  1.9760405E2,
59  8.9451237E2,
60  -1.1462908E3,
61  1.7996947E3,
62  -1.7250843E3,
63  9.7088329E2
64 };
65 
66 // array G is used by the function sp
67 static const double G[]= {
68  1.1925213E5,
69  -7.7231363E2,
70  7.4463527,
71  -3.0888167E-3,
72  0.0,
73  0.0
74 };
75 
76 double Heptane::C(int j,double Tinverse, double T2inverse, double T3inverse, double T4inverse)
77 {
78  switch (j) {
79  case 0 :
80  return Ahept[0] * R * T -
81  Ahept[1] -
82  Ahept[2] * T2inverse +
83  Ahept[3] * T3inverse -
84  Ahept[4] * T4inverse;
85  case 1 :
86  return Ahept[5] * R * T -
87  Ahept[6] -
88  Ahept[7] * Tinverse;
89  case 2 :
90  return Ahept[9] * (Ahept[6] + Ahept[7] * Tinverse);
91  case 3 :
92  return Ahept[8] * T2inverse;
93  default :
94  return 0.0;
95  }
96 }
97 
98 inline double Heptane::Cprime(int j, double T2inverse, double T3inverse, double T4inverse)
99 {
100  switch (j) {
101  case 0 :
102  return Ahept[0] * R -
103  -2 * Ahept[2] * T3inverse +
104  -3 * Ahept[3] * T4inverse -
105  -4 * Ahept[4] * pow(T, -5.0);
106  case 1 :
107  return Ahept[5] * R -
108  -1 * Ahept[7] * T2inverse;
109  case 2 :
110  return Ahept[9] * (-1 * Ahept[7] * T2inverse);
111  case 3 :
112  return -2 * Ahept[8] * T3inverse;
113  default :
114  return 0.0;
115  }
116 }
117 
118 inline double Heptane::I(int j, double ergho, double Gamma)
119 {
120  switch (j) {
121  case 0:
122  return Rho;
123  case 1:
124  return Rho * Rho / 2;
125  case 2:
126  return pow(Rho, 5.0)/ 5;
127  case 3:
128  return 1 / Gamma - (Gamma * Rho * Rho + 2) * ergho / (2 * Gamma);
129  default:
130  return 0.0;
131  }
132 }
133 
134 double Heptane::H(int i, double egrho)
135 {
136  if (i < 2) {
137  return pow(Rho,i+2);
138  } else if (i == 2) {
139  return pow(Rho,6.0);
140  } else if (i == 3) {
141  return pow(Rho,3) * (1 + Gamma * Rho * Rho) * egrho;
142  } else {
143  return 0;
144  }
145 }
146 
147 double Heptane::up()
148 {
149  double Tinverse = 1.0/T;
150  double T2inverse = pow(T, -2);
151  double T3inverse = pow(T, -3);
152  double T4inverse = pow(T, -4);
153  double egrho = exp(-Gamma*Rho*Rho);
154 
155  double sum = 0.0;
156  int i;
157  for (i=1; i<=5; i++) {
158  sum += G[i]*(pow(T,i) - pow(To,i))/double(i);
159  }
160 
161  sum += G[0]*log(T/To);
162 
163  for (i=0; i<=6; i++) {
164  sum += (C(i, Tinverse, T2inverse, T3inverse, T4inverse) - T*Cprime(i,T2inverse, T3inverse, T4inverse))*I(i,egrho, Gamma);
165  }
166 
167  sum += u0;
168 
169  return sum + m_energy_offset;
170 }
171 
172 double Heptane::sp()
173 {
174  double T2inverse = pow(T, -2);
175  double T3inverse = pow(T, -3);
176  double T4inverse = pow(T, -4);
177  double egrho = exp(-Gamma*Rho*Rho);
178 
179  double sum = 0.0;
180 
181  for (int i=2; i<=5; i++) {
182  sum += G[i]*(pow(T,i-1) - pow(To,i-1))/double(i-1);
183  }
184 
185  sum += G[1]*log(T/To);
186  sum -= G[0]*(1.0/T - 1.0/To);
187 
188  for (int i=0; i<=6; i++) {
189  sum -= Cprime(i,T2inverse, T3inverse, T4inverse)*I(i,egrho, Gamma);
190  }
191 
192  sum += s0 - R*log(Rho);
193 
194  return sum + m_entropy_offset;
195 }
196 
197 double Heptane::Pp()
198 {
199  double Tinverse = pow(T,-1);
200  double T2inverse = pow(T, -2);
201  double T3inverse = pow(T, -3);
202  double T4inverse = pow(T, -4);
203  double egrho = exp(-Gamma*Rho*Rho);
204 
205  double P = Rho*R*T;
206 
207  for (int i=0; i<=3; i++) {
208  P += C(i,Tinverse, T2inverse, T3inverse, T4inverse)*H(i,egrho);
209  }
210 
211  return P;
212 }
213 
214 double Heptane::Psat()
215 {
216  double log, sum=0;
217  if ((T < Tmn) || (T > Tc)) {
218  throw TPX_Error("Heptane::Psat",
219  "Temperature out of range. T = " + fp2str(T));
220  }
221  for (int i=1; i<=8; i++) {
222  sum += F[i-1] * pow((T/Tp -1),double(i-1));
223  }
224 
225  log = ((Tc/T)-1)*sum;
226  return exp(log)*Pc;
227 }
228 
229 double Heptane::ldens()
230 {
231  double xx=1-(T/Tc), sum=0;
232  if ((T < Tmn) || (T > Tc)) {
233  throw TPX_Error("Heptane::ldens",
234  "Temperature out of range. T = " + fp2str(T));
235  }
236  for (int i=1; i<=6; i++) {
237  sum+=D[i-1]*pow(xx,double(i-1)/3.0);
238  }
239 
240  return sum;
241 }
242 
243 // The following functions allow users to get the properties of Heptane that
244 // are not dependent on the state
245 
246 double Heptane::Tcrit()
247 {
248  return Tc;
249 }
250 double Heptane::Pcrit()
251 {
252  return Pc;
253 }
254 double Heptane::Vcrit()
255 {
256  return 1.0/Roc;
257 }
258 double Heptane::Tmin()
259 {
260  return Tmn;
261 }
262 double Heptane::Tmax()
263 {
264  return Tmx;
265 }
266 char* Heptane::name()
267 {
268  return (char*) m_name.c_str();
269 }
270 char* Heptane::formula()
271 {
272  return (char*) m_formula.c_str();
273 }
274 double Heptane::MolWt()
275 {
276  return M;
277 }
278 }
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.