Cantera  2.0
NasaPoly1.h
Go to the documentation of this file.
1 
2 /**
3  * @file NasaPoly1.h
4  * Header for a single-species standard state object derived
5  * from \link Cantera::SpeciesThermoInterpType SpeciesThermoInterpType\endlink based
6  * on the NASA temperature polynomial form applied to one temperature region
7  * (see \ref spthermo and class \link Cantera::NasaPoly1 NasaPoly1\endlink).
8  *
9  * This parameterization has one NASA temperature region.
10  */
11 
12 
13 #ifndef CT_NASAPOLY1_H
14 #define CT_NASAPOLY1_H
15 // Copyright 2001 California Institute of Technology
16 
17 
18 #include "cantera/base/global.h"
20 
21 namespace Cantera
22 {
23 
24 /**
25  * The NASA polynomial parameterization for one temperature range.
26  * This parameterization expresses the heat capacity as a
27  * fourth-order polynomial. Note that this is the form used in the
28  * 1971 NASA equilibrium program and by the Chemkin software
29  * package, but differs from the form used in the more recent NASA
30  * equilibrium program.
31  *
32  * Seven coefficients \f$(a_0,\dots,a_6)\f$ are used to represent
33  * \f$ c_p^0(T)\f$, \f$ h^0(T)\f$, and \f$ s^0(T) \f$ as
34  * polynomials in \f$ T \f$ :
35  * \f[
36  * \frac{c_p(T)}{R} = a_0 + a_1 T + a_2 T^2 + a_3 T^3 + a_4 T^4
37  * \f]
38  * \f[
39  * \frac{h^0(T)}{RT} = a_0 + \frac{a_1}{2} T + \frac{a_2}{3} T^2
40  * + \frac{a_3}{4} T^3 + \frac{a_4}{5} T^4 + \frac{a_5}{T}.
41  * \f]
42  * \f[
43  * \frac{s^0(T)}{R} = a_0\ln T + a_1 T + \frac{a_2}{2} T^2
44  + \frac{a_3}{3} T^3 + \frac{a_4}{4} T^4 + a_6.
45  * \f]
46  *
47  * This class is designed specifically for use by class NasaThermo.
48  * @ingroup spthermo
49  */
51 {
52 
53 public:
54 
55  //! Empty constructor
57  : m_lowT(0.0), m_highT(0.0),
58  m_Pref(0.0), m_index(0), m_coeff(7, 0.0) {}
59 
60 
61  //! constructor used in templated instantiations
62  /*!
63  * @param n Species index
64  * @param tlow Minimum temperature
65  * @param thigh Maximum temperature
66  * @param pref reference pressure (Pa).
67  * @param coeffs Vector of coefficients used to set the
68  * parameters for the standard state.
69  */
70  NasaPoly1(size_t n, doublereal tlow, doublereal thigh, doublereal pref,
71  const doublereal* coeffs) :
72  m_lowT(tlow),
73  m_highT(thigh),
74  m_Pref(pref),
75  m_index(n),
76  m_coeff(vector_fp(7)) {
77  std::copy(coeffs, coeffs + 7, m_coeff.begin());
78  }
79 
80  //! copy constructor
81  /*!
82  * @param b object to be copied
83  */
84  NasaPoly1(const NasaPoly1& b) :
85  m_lowT(b.m_lowT),
86  m_highT(b.m_highT),
87  m_Pref(b.m_Pref),
88  m_index(b.m_index),
89  m_coeff(vector_fp(7)) {
90  std::copy(b.m_coeff.begin(),
91  b.m_coeff.begin() + 7,
92  m_coeff.begin());
93  }
94 
95  //! assignment operator
96  /*!
97  * @param b object to be copied
98  */
100  if (&b != this) {
101  m_lowT = b.m_lowT;
102  m_highT = b.m_highT;
103  m_Pref = b.m_Pref;
104  m_index = b.m_index;
105  std::copy(b.m_coeff.begin(),
106  b.m_coeff.begin() + 7,
107  m_coeff.begin());
108  }
109  return *this;
110  }
111 
112  //! Destructor
113  virtual ~NasaPoly1() {}
114 
115  //! duplicator
116  virtual SpeciesThermoInterpType*
118  NasaPoly1* np = new NasaPoly1(*this);
119  return (SpeciesThermoInterpType*) np;
120  }
121 
122  //! Returns the minimum temperature that the thermo
123  //! parameterization is valid
124  virtual doublereal minTemp() const {
125  return m_lowT;
126  }
127 
128  //! Returns the maximum temperature that the thermo
129  //! parameterization is valid
130  virtual doublereal maxTemp() const {
131  return m_highT;
132  }
133 
134  //! Returns the reference pressure (Pa)
135  virtual doublereal refPressure() const {
136  return m_Pref;
137  }
138 
139  //! Returns an integer representing the type of parameterization
140  virtual int reportType() const {
141  return NASA1;
142  }
143 
144  //! Returns an integer representing the species index
145  virtual size_t speciesIndex() const {
146  return m_index;
147  }
148 
149  //! Update the properties for this species, given a temperature polynomial
150  /*!
151  * This method is called with a pointer to an array containing the functions of
152  * temperature needed by this parameterization, and three pointers to arrays where the
153  * computed property values should be written. This method updates only one value in
154  * each array.
155  *
156  * Temperature Polynomial:
157  * tt[0] = t;
158  * tt[1] = t*t;
159  * tt[2] = m_t[1]*t;
160  * tt[3] = m_t[2]*t;
161  * tt[4] = 1.0/t;
162  * tt[5] = std::log(t);
163  *
164  * @param tt vector of temperature polynomials
165  * @param cp_R Vector of Dimensionless heat capacities.
166  * (length m_kk).
167  * @param h_RT Vector of Dimensionless enthalpies.
168  * (length m_kk).
169  * @param s_R Vector of Dimensionless entropies.
170  * (length m_kk).
171  */
172  virtual void updateProperties(const doublereal* tt,
173  doublereal* cp_R, doublereal* h_RT, doublereal* s_R) const {
174 
175  doublereal ct0 = m_coeff[2]; // a0
176  doublereal ct1 = m_coeff[3]*tt[0]; // a1 * T
177  doublereal ct2 = m_coeff[4]*tt[1]; // a2 * T^2
178  doublereal ct3 = m_coeff[5]*tt[2]; // a3 * T^3
179  doublereal ct4 = m_coeff[6]*tt[3]; // a4 * T^4
180 
181  doublereal cp, h, s;
182  cp = ct0 + ct1 + ct2 + ct3 + ct4;
183  h = ct0 + 0.5*ct1 + OneThird*ct2 + 0.25*ct3 + 0.2*ct4
184  + m_coeff[0]*tt[4]; // last term is a5/T
185  s = ct0*tt[5] + ct1 + 0.5*ct2 + OneThird*ct3
186  +0.25*ct4 + m_coeff[1]; // last term is a6
187 
188  // return the computed properties in the location in the output
189  // arrays for this species
190  cp_R[m_index] = cp;
191  h_RT[m_index] = h;
192  s_R[m_index] = s;
193  //writelog("NASA1: for species "+int2str(m_index)+", h_RT = "+
194  // fp2str(h)+"\n");
195  }
196 
197 
198  //! Compute the reference-state property of one species
199  /*!
200  * Given temperature T in K, this method updates the values of
201  * the non-dimensional heat capacity at constant pressure,
202  * enthalpy, and entropy, at the reference pressure, Pref
203  * of one of the species. The species index is used
204  * to reference into the cp_R, h_RT, and s_R arrays.
205  *
206  * @param temp Temperature (Kelvin)
207  * @param cp_R Vector of Dimensionless heat capacities.
208  * (length m_kk).
209  * @param h_RT Vector of Dimensionless enthalpies.
210  * (length m_kk).
211  * @param s_R Vector of Dimensionless entropies.
212  * (length m_kk).
213  */
214  virtual void updatePropertiesTemp(const doublereal temp,
215  doublereal* cp_R, doublereal* h_RT,
216  doublereal* s_R) const {
217  double tPoly[6];
218  tPoly[0] = temp;
219  tPoly[1] = temp * temp;
220  tPoly[2] = tPoly[1] * temp;
221  tPoly[3] = tPoly[2] * temp;
222  tPoly[4] = 1.0 / temp;
223  tPoly[5] = std::log(temp);
224  updateProperties(tPoly, cp_R, h_RT, s_R);
225  }
226 
227  //!This utility function reports back the type of
228  //! parameterization and all of the parameters for the
229  //! species, index.
230  /*!
231  * All parameters are output variables
232  *
233  * @param n Species index
234  * @param type Integer type of the standard type
235  * @param tlow output - Minimum temperature
236  * @param thigh output - Maximum temperature
237  * @param pref output - reference pressure (Pa).
238  * @param coeffs Vector of coefficients used to set the
239  * parameters for the standard state.
240  */
241  virtual void reportParameters(size_t& n, int& type,
242  doublereal& tlow, doublereal& thigh,
243  doublereal& pref,
244  doublereal* const coeffs) const {
245  n = m_index;
246  type = NASA1;
247  tlow = m_lowT;
248  thigh = m_highT;
249  pref = m_Pref;
250  coeffs[5] = m_coeff[0];
251  coeffs[6] = m_coeff[1];
252  for (int i = 2; i < 7; i++) {
253  coeffs[i-2] = m_coeff[i];
254  }
255  }
256 
257  //! Modify parameters for the standard state
258  /*!
259  * @param coeffs Vector of coefficients used to set the
260  * parameters for the standard state.
261  */
262  virtual void modifyParameters(doublereal* coeffs) {
263  m_coeff[0] = coeffs[5];
264  m_coeff[1] = coeffs[6];
265  for (int i = 0; i < 5; i++) {
266  m_coeff[i+2] = coeffs[i];
267  }
268  }
269 
270 #ifdef H298MODIFY_CAPABILITY
271 
272  virtual doublereal reportHf298(doublereal* const h298 = 0) const {
273  double tt[6];
274  double temp = 298.15;
275  tt[0] = temp;
276  tt[1] = temp * temp;
277  tt[2] = tt[1] * temp;
278  tt[3] = tt[2] * temp;
279  tt[4] = 1.0 / temp;
280  //tt[5] = std::log(temp);
281  doublereal ct0 = m_coeff[2]; // a0
282  doublereal ct1 = m_coeff[3]*tt[0]; // a1 * T
283  doublereal ct2 = m_coeff[4]*tt[1]; // a2 * T^2
284  doublereal ct3 = m_coeff[5]*tt[2]; // a3 * T^3
285  doublereal ct4 = m_coeff[6]*tt[3]; // a4 * T^4
286 
287  double h_RT = ct0 + 0.5*ct1 + OneThird*ct2 + 0.25*ct3 + 0.2*ct4
288  + m_coeff[0]*tt[4]; // last t
289 
290  double h = h_RT * GasConstant * temp;
291  if (h298) {
292  h298[m_index] = h;
293  }
294  return h;
295  }
296 
297  virtual void modifyOneHf298(const int k, const doublereal Hf298New) {
298  if (k != m_index) {
299  return;
300  }
301  double hcurr = reportHf298(0);
302  double delH = Hf298New - hcurr;
303  m_coeff[0] += (delH) / GasConstant;
304  }
305 
306 #endif
307 
308 protected:
309  //! lowest valid temperature
310  doublereal m_lowT;
311  //! highest valid temperature
312  doublereal m_highT;
313  //! standard-state pressure
314  doublereal m_Pref;
315  //! species index
316  size_t m_index;
317  //! array of polynomial coefficients
319 
320 };
321 
322 }
323 #endif
324