Cantera  2.0
Nasa9Poly1.cpp
Go to the documentation of this file.
1 /**
2  * @file Nasa9Poly1.cpp
3  * Definitions for a single-species standard state object derived
4  * from
5  * \link Cantera::SpeciesThermoInterpType SpeciesThermoInterpType\endlink
6  * based
7  * on the NASA 9 coefficient temperature polynomial form applied to one temperature region
8  * (see \ref spthermo and class \link Cantera::Nasa9Poly1 Nasa9Poly1\endlink).
9  *
10  * This parameterization has one NASA temperature region.
11  */
12 // Copyright 2007 Sandia National Laboratories
13 
15 
16 namespace Cantera
17 {
18 
19 
20 // The NASA 9 polynomial parameterization for one temperature range.
21 /*
22  * This parameterization expresses the heat capacity via a
23  * 7 coefficient polynomial.
24  *
25  * Note that this is the form used in the
26  * 2002 NASA equilibrium program
27  *
28  * "NASA Glenn Coefficients for Calculating Thermodynamic
29  * Properties of Individual Species,"
30  * B. J. McBride, M. J. Zehe, S. Gordon
31  * NASA/TP-2002-211556, Sept. 2002
32  *
33  *
34  * Nine coefficients \f$(a_0,\dots,a_6)\f$ are used to represent
35  * \f$ C_p^0(T)\f$, \f$ H^0(T)\f$, and \f$ S^0(T) \f$ as
36  * polynomials in \f$ T \f$ :
37  * \f[
38  * \frac{C_p^0(T)}{R} = a_0 T^{-2} + a_1 T^{-1} + a_2 + a_3 T
39  * + a_4 T^2 + a_5 T^3 + a_6 T^4
40  * \f]
41  *
42  * \f[
43  * \frac{H^0(T)}{RT} = - a_0 T^{-2} + a_1 \frac{\ln(T)}{T} + a_2
44  * + a_3 T + a_4 T^2 + a_5 T^3 + a_6 T^4 + \frac{a_7}{T}
45  * \f]
46  *
47  * \f[
48  * \frac{s^0(T)}{R} = - \frac{a_0}{2} T^{-2} - a_1 T^{-1} + a_2 \ln(T)
49  + + a_3 T \frac{a_4}{2} T^2 + \frac{a_5}{3} T^3 + \frac{a_6}{4} T^4 + a_8
50  * \f]
51  *
52  * The standard state is assumed to be the ideal gas at the
53  * standard pressure of 1 bar, for gases.
54  * For condensed species, the standard state is the
55  * pure crystalline or liquid substance at the standard
56  * pressure of 1 atm.
57  *
58  * These NASA representations may have more than 2 temperature regions.
59  *
60  * @ingroup spthermo
61  */
62 
63 
64 //! Empty constructor
66  : m_lowT(0.0), m_highT(0.0),
67  m_Pref(1.0E5), m_index(0), m_coeff(vector_fp(9)) {}
68 
69 
70 // constructor used in templated instantiations
71 /*
72  * @param n Species index
73  * @param tlow Minimum temperature
74  * @param thigh Maximum temperature
75  * @param pref reference pressure (Pa).
76  * @param coeffs Vector of coefficients used to set the
77  * parameters for the standard state.
78  */
79 Nasa9Poly1::Nasa9Poly1(size_t n, doublereal tlow, doublereal thigh,
80  doublereal pref,
81  const doublereal* coeffs) :
82  m_lowT(tlow),
83  m_highT(thigh),
84  m_Pref(pref),
85  m_index(n),
86  m_coeff(vector_fp(9))
87 {
88  std::copy(coeffs, coeffs + 9, m_coeff.begin());
89 }
90 
91 // copy constructor
92 /*
93  * @param b object to be copied
94  */
96  m_lowT(b.m_lowT),
97  m_highT(b.m_highT),
98  m_Pref(b.m_Pref),
99  m_index(b.m_index),
100  m_coeff(vector_fp(9))
101 {
102  std::copy(b.m_coeff.begin(),
103  b.m_coeff.begin() + 9,
104  m_coeff.begin());
105 }
106 
107 // assignment operator
108 /*
109  * @param b object to be copied
110  */
112 {
113  if (&b != this) {
114  m_lowT = b.m_lowT;
115  m_highT = b.m_highT;
116  m_Pref = b.m_Pref;
117  m_index = b.m_index;
118  std::copy(b.m_coeff.begin(),
119  b.m_coeff.begin() + 9,
120  m_coeff.begin());
121  }
122  return *this;
123 }
124 
125 // Destructor
127 {
128 }
129 
130 // duplicator
133 {
134  Nasa9Poly1* np = new Nasa9Poly1(*this);
135  return (SpeciesThermoInterpType*) np;
136 }
137 
138 // Returns the minimum temperature that the thermo
139 // parameterization is valid
140 doublereal Nasa9Poly1::minTemp() const
141 {
142  return m_lowT;
143 }
144 
145 // Returns the maximum temperature that the thermo
146 // parameterization is valid
147 doublereal Nasa9Poly1::maxTemp() const
148 {
149  return m_highT;
150 }
151 
152 // Returns the reference pressure (Pa)
153 doublereal Nasa9Poly1::refPressure() const
154 {
155  return m_Pref;
156 }
157 
158 // Returns an integer representing the type of parameterization
160 {
161  return NASA9;
162 }
163 
164 // Returns an integer representing the species index
166 {
167  return m_index;
168 }
169 
170 // Update the properties for this species, given a temperature polynomial
171 /*
172  * This method is called with a pointer to an array containing the functions of
173  * temperature needed by this parameterization, and three pointers to arrays where the
174  * computed property values should be written. This method updates only one value in
175  * each array.
176  *
177  * Temperature Polynomial:
178  * tt[0] = t;
179  * tt[1] = t*t;
180  * tt[2] = t*t*t;
181  * tt[3] = t*t*t*t;
182  * tt[4] = 1.0/t;
183  * tt[5] = 1.0/(t*t);
184  * tt[6] = std::log(t);
185  *
186  * @param tt vector of temperature polynomials
187  * @param cp_R Vector of Dimensionless heat capacities.
188  * (length m_kk).
189  * @param h_RT Vector of Dimensionless enthalpies.
190  * (length m_kk).
191  * @param s_R Vector of Dimensionless entropies.
192  * (length m_kk).
193  */
194 void Nasa9Poly1::updateProperties(const doublereal* tt,
195  doublereal* cp_R, doublereal* h_RT,
196  doublereal* s_R) const
197 {
198 
199  doublereal ct0 = m_coeff[0] * tt[5]; // a0 / (T^2)
200  doublereal ct1 = m_coeff[1] * tt[4]; // a1 / T
201  doublereal ct2 = m_coeff[2]; // a2
202  doublereal ct3 = m_coeff[3] * tt[0]; // a3 * T
203  doublereal ct4 = m_coeff[4] * tt[1]; // a4 * T^2
204  doublereal ct5 = m_coeff[5] * tt[2]; // a5 * T^3
205  doublereal ct6 = m_coeff[6] * tt[3]; // a6 * T^4
206 
207 
208  doublereal cpdivR = ct0 + ct1 + ct2 + ct3 + ct4 + ct5 + ct6;
209  doublereal hdivRT = -ct0 + tt[6]*ct1 + ct2 + 0.5*ct3 + OneThird*ct4
210  + 0.25*ct5 + 0.2*ct6 + m_coeff[7] * tt[4];
211  doublereal sdivR = -0.5*ct0 - ct1 + tt[6]*ct2 + ct3 + 0.5*ct4
212  + OneThird*ct5 + 0.25*ct6 + m_coeff[8];
213 
214  // return the computed properties in the location in the output
215  // arrays for this species
216  cp_R[m_index] = cpdivR;
217  h_RT[m_index] = hdivRT;
218  s_R[m_index] = sdivR;
219  //writelog("NASA9poly1: for species "+int2str(m_index)+", h_RT = "+
220  // fp2str(h)+"\n");
221 }
222 
223 
224 // Compute the reference-state property of one species
225 /*
226  * Given temperature T in K, this method updates the values of
227  * the non-dimensional heat capacity at constant pressure,
228  * enthalpy, and entropy, at the reference pressure, Pref
229  * of one of the species. The species index is used
230  * to reference into the cp_R, h_RT, and s_R arrays.
231  *
232  * Temperature Polynomial:
233  * tt[0] = t;
234  * tt[1] = t*t;
235  * tt[2] = t*t*t;
236  * tt[3] = t*t*t*t;
237  * tt[4] = 1.0/t;
238  * tt[5] = 1.0/(t*t);
239  * tt[6] = std::log(t);
240  *
241  * @param temp Temperature (Kelvin)
242  * @param cp_R Vector of Dimensionless heat capacities.
243  * (length m_kk).
244  * @param h_RT Vector of Dimensionless enthalpies.
245  * (length m_kk).
246  * @param s_R Vector of Dimensionless entropies.
247  * (length m_kk).
248  */
249 void Nasa9Poly1::updatePropertiesTemp(const doublereal temp,
250  doublereal* cp_R, doublereal* h_RT,
251  doublereal* s_R) const
252 {
253  double tPoly[7];
254  tPoly[0] = temp;
255  tPoly[1] = temp * temp;
256  tPoly[2] = tPoly[1] * temp;
257  tPoly[3] = tPoly[2] * temp;
258  tPoly[4] = 1.0 / temp;
259  tPoly[5] = tPoly[4] / temp;
260  tPoly[6] = std::log(temp);
261  updateProperties(tPoly, cp_R, h_RT, s_R);
262 }
263 
264 //This utility function reports back the type of
265 // parameterization and all of the parameters for the
266 // species, index.
267 /*
268  * All parameters are output variables
269  *
270  * @param n Species index
271  * @param type Integer type of the standard type
272  * @param tlow output - Minimum temperature
273  * @param thigh output - Maximum temperature
274  * @param pref output - reference pressure (Pa).
275  * @param coeffs Vector of coefficients used to set the
276  * parameters for the standard state.
277  */
278 void Nasa9Poly1::reportParameters(size_t& n, int& type,
279  doublereal& tlow, doublereal& thigh,
280  doublereal& pref,
281  doublereal* const coeffs) const
282 {
283  n = m_index;
284  type = NASA9;
285  tlow = m_lowT;
286  thigh = m_highT;
287  pref = m_Pref;
288  coeffs[0] = 1;
289  coeffs[1] = m_lowT;
290  coeffs[2] = m_highT;
291  for (int i = 0; i < 9; i++) {
292  coeffs[i+3] = m_coeff[i];
293  }
294 
295 }
296 
297 // Modify parameters for the standard state
298 /*
299  * @param coeffs Vector of coefficients used to set the
300  * parameters for the standard state.
301  */
302 void Nasa9Poly1::modifyParameters(doublereal* coeffs)
303 {
304  for (int i = 0; i < 9; i++) {
305  m_coeff[i] = coeffs[i];
306  }
307 }
308 
309 
310 }
311