Cantera  2.2.1
ShomatePoly.h
Go to the documentation of this file.
1 /**
2  * @file ShomatePoly.h
3  * Header for a single-species standard state object derived
5  * on the Shomate temperature polynomial form applied to one temperature region
8  * Shomate polynomial expressions.
9  */
10 // Copyright 2001 California Institute of Technology
11
12 #ifndef CT_SHOMATEPOLY1_H
13 #define CT_SHOMATEPOLY1_H
14
17
18 namespace Cantera
19 {
20 //! The Shomate polynomial parameterization for one temperature range
21 //! for one species
22 /*!
23  * Seven coefficients \f$(A,\dots,G)\f$ are used to represent
24  * \f$c_p^0(T)\f$, \f$h^0(T)\f$, and \f$s^0(T) \f$ as
25  * polynomials in the temperature, \f$T \f$ :
26  *
27  * \f[
28  * \tilde{c}_p^0(T) = A + B t + C t^2 + D t^3 + \frac{E}{t^2}
29  * \f]
30  * \f[
31  * \tilde{h}^0(T) = A t + \frac{B t^2}{2} + \frac{C t^3}{3}
32  + \frac{D t^4}{4} - \frac{E}{t} + F.
33  * \f]
34  * \f[
35  * \tilde{s}^0(T) = A\ln t + B t + \frac{C t^2}{2}
36  + \frac{D t^3}{3} - \frac{E}{2t^2} + G.
37  * \f]
38  *
39  * In the above expressions, the thermodynamic polynomials are expressed
40  * in dimensional units, but the temperature,\f$t \f$, is divided by 1000. The
41  * following dimensions are assumed in the above expressions:
42  *
43  * - \f$\tilde{c}_p^0(T)\f$ = Heat Capacity (J/gmol*K)
44  * - \f$\tilde{h}^0(T) \f$ = standard Enthalpy (kJ/gmol)
45  * - \f$\tilde{s}^0(T) \f$= standard Entropy (J/gmol*K)
46  * - \f$t \f$= temperature (K) / 1000.
47  *
49  * http://webbook.nist.gov/
50  *
51  * Before being used within Cantera, the dimensions must be adjusted to those
52  * used by Cantera (i.e., Joules and kmol).
53  *
54  * @ingroup spthermo
55  */
57 {
58 public:
59  //! Empty constructor
61
62  //! Constructor used in templated instantiations
63  /*!
64  * @param n Species index
65  * @param tlow Minimum temperature
66  * @param thigh Maximum temperature
67  * @param pref reference pressure (Pa).
68  * @param coeffs Vector of coefficients used to set the
69  * parameters for the standard state for species n.
70  * There are 7 coefficients for the Shomate polynomial:
71  * - c = \f$A \f$
72  * - c = \f$B \f$
73  * - c = \f$C \f$
74  * - c = \f$D \f$
75  * - c = \f$E \f$
76  * - c = \f$F \f$
77  * - c = \f$G \f$
78  *
79  * See the class description for the polynomial representation of the
80  * thermo functions in terms of \f$A, \dots, G \f$.
81  *
82  * @deprecated Use the alternate constructor which does not take the
83  * species index. To be removed after Cantera 2.2.
84  */
85  ShomatePoly(size_t n, doublereal tlow, doublereal thigh, doublereal pref,
86  const doublereal* coeffs) :
87  SpeciesThermoInterpType(n, tlow, thigh, pref),
88  m_coeff(coeffs, coeffs + 7)
89  {
90  }
91
92  //! Normal constructor
93  /*!
94  * @param tlow Minimum temperature
95  * @param thigh Maximum temperature
96  * @param pref reference pressure (Pa).
97  * @param coeffs Vector of coefficients, [A,B,C,D,E,F,G], used to set
98  * the parameters for the species standard state.
99  *
100  * See the class description for the polynomial representation of the
101  * thermo functions in terms of \f$A, \dots, G \f$.
102  */
103  ShomatePoly(double tlow, double thigh, double pref, const double* coeffs) :
104  SpeciesThermoInterpType(tlow, thigh, pref),
105  m_coeff(coeffs, coeffs + 7)
106  {
107  }
108
109  //! copy constructor
110  /*!
111  * @param b object to be copied
112  */
115  m_coeff(b.m_coeff)
116  {
117  }
118
119  //! Assignment operator
120  /*!
121  * @param b
122  */
124  if (&b != this) {
125  SpeciesThermoInterpType::operator=(b);
126  m_coeff = b.m_coeff;
127  }
128  return *this;
129  }
130
131  virtual SpeciesThermoInterpType*
132  duplMyselfAsSpeciesThermoInterpType() const {
133  ShomatePoly* sp = new ShomatePoly(*this);
134  return (SpeciesThermoInterpType*) sp;
135  }
136
137  virtual int reportType() const {
138  return SHOMATE;
139  }
140
141  virtual size_t temperaturePolySize() const { return 7; }
142
143  virtual void updateTemperaturePoly(double T, double* T_poly) const {
144  doublereal tt = 1.e-3*T;
145  T_poly = tt;
146  T_poly = tt * tt;
147  T_poly = T_poly * tt;
148  T_poly = 1.0/T_poly;
149  T_poly = std::log(tt);
150  T_poly = 1.0/GasConstant;
151  T_poly = 1.0/(GasConstant * T);
152  }
153
154  //! Update the properties for this species, given a temperature polynomial
155  /*!
156  * This method is called with a pointer to an array containing the
157  * functions of temperature needed by this parameterization, and three
158  * pointers to arrays where the computed property values should be
159  * written. This method updates only one value in each array.
160  *
161  * - tt is T/1000.
162  * - m_t = tt
163  * - m_t = tt*tt
164  * - m_t = m_t*tt
165  * - m_t = 1.0/m_t
166  * - m_t = log(tt)
167  * - m_t = 1.0/GasConstant
168  * - m_t = 1.0/(GasConstant * T)
169  *
170  * @param tt Vector of temperature polynomials
171  * @param cp_R Vector of Dimensionless heat capacities. (length m_kk).
172  * @param h_RT Vector of Dimensionless enthalpies. (length m_kk).
173  * @param s_R Vector of Dimensionless entropies. (length m_kk).
174  */
175  virtual void updateProperties(const doublereal* tt,
176  doublereal* cp_R, doublereal* h_RT,
177  doublereal* s_R) const {
178
179  doublereal A = m_coeff;
180  doublereal Bt = m_coeff*tt;
181  doublereal Ct2 = m_coeff*tt;
182  doublereal Dt3 = m_coeff*tt;
183  doublereal Etm2 = m_coeff*tt;
184  doublereal F = m_coeff;
185  doublereal G = m_coeff;
186
187  doublereal cp, h, s;
188  cp = A + Bt + Ct2 + Dt3 + Etm2;
189  h = tt*(A + 0.5*Bt + 1.0/3.0*Ct2 + 0.25*Dt3 - Etm2) + F;
190  s = A*tt + Bt + 0.5*Ct2 + 1.0/3.0*Dt3 - 0.5*Etm2 + G;
191
192  /*
193  * Shomate polynomials parameterizes assuming units of
194  * J/(gmol*K) for cp_r and s_R and kJ/(gmol) for h.
195  * However, Cantera assumes default MKS units of
196  * J/(kmol*K). This requires us to multiply cp and s
197  * by 1.e3 and h by 1.e6, before we then nondimensionalize
198  * the results by dividing by (GasConstant * T),
199  * where GasConstant has units of J/(kmol * K).
200  */
201  cp_R[m_index] = 1.e3 * cp * tt;
202  h_RT[m_index] = 1.e6 * h * tt;
203  s_R[m_index] = 1.e3 * s * tt;
204  }
205
206  virtual void updatePropertiesTemp(const doublereal temp,
207  doublereal* cp_R, doublereal* h_RT,
208  doublereal* s_R) const {
209  double tPoly;
210  updateTemperaturePoly(temp, tPoly);
211  updateProperties(tPoly, cp_R, h_RT, s_R);
212  }
213
214  virtual void reportParameters(size_t& n, int& type,
215  doublereal& tlow, doublereal& thigh,
216  doublereal& pref,
217  doublereal* const coeffs) const {
218  n = m_index;
219  type = SHOMATE;
220  tlow = m_lowT;
221  thigh = m_highT;
222  pref = m_Pref;
223  for (int i = 0; i < 7; i++) {
224  coeffs[i] = m_coeff[i];
225  }
226  }
227
228  //! Modify parameters for the standard state
229  /*!
230  * @param coeffs Vector of coefficients used to set the
231  * parameters for the standard state.
232  */
233  virtual void modifyParameters(doublereal* coeffs) {
234  if (m_coeff.size() != 7) {
235  throw CanteraError("modifyParameters",
236  "modifying something that hasn't been initialized");
237  }
238  std::copy(coeffs, coeffs + 7, m_coeff.begin());
239  }
240
241  virtual doublereal reportHf298(doublereal* const h298 = 0) const {
242  double tPoly;
243  updateTemperaturePoly(298.15, tPoly);
244  doublereal A = m_coeff;
245  doublereal Bt = m_coeff*tPoly;
246  doublereal Ct2 = m_coeff*tPoly;
247  doublereal Dt3 = m_coeff*tPoly;
248  doublereal Etm2 = m_coeff*tPoly;
249  doublereal F = m_coeff;
250
251  doublereal h = tPoly*(A + 0.5*Bt + 1.0/3.0*Ct2 + 0.25*Dt3 - Etm2) + F;
252
253  double hh = 1.e6 * h;
254  if (h298) {
255  h298[m_index] = 1.e6 * h;
256  }
257  return hh;
258  }
259
260  virtual void modifyOneHf298(const size_t k, const doublereal Hf298New) {
261  doublereal hnow = reportHf298();
262  doublereal delH = Hf298New - hnow;
263  m_coeff += delH / 1.0E6;
264  }
265
266 protected:
267  //! Array of coefficients
269 };
270
271 //! The Shomate polynomial parameterization for two temperature ranges
272 //! for one species
273 /*!
274  * Seven coefficients \f$(A,\dots,G)\f$ are used to represent
275  * \f$c_p^0(T)\f$, \f$h^0(T)\f$, and \f$s^0(T) \f$ as
276  * polynomials in the temperature, \f$T \f$, in one temperature region:
277  *
278  * \f[
279  * \tilde{c}_p^0(T) = A + B t + C t^2 + D t^3 + \frac{E}{t^2}
280  * \f]
281  * \f[
282  * \tilde{h}^0(T) = A t + \frac{B t^2}{2} + \frac{C t^3}{3}
283  + \frac{D t^4}{4} - \frac{E}{t} + F.
284  * \f]
285  * \f[
286  * \tilde{s}^0(T) = A\ln t + B t + \frac{C t^2}{2}
287  + \frac{D t^3}{3} - \frac{E}{2t^2} + G.
288  * \f]
289  *
290  * In the above expressions, the thermodynamic polynomials are expressed
291  * in dimensional units, but the temperature,\f$t \f$, is divided by 1000. The
292  * following dimensions are assumed in the above expressions:
293  *
294  * - \f$\tilde{c}_p^0(T)\f$ = Heat Capacity (J/gmol*K)
295  * - \f$\tilde{h}^0(T) \f$ = standard Enthalpy (kJ/gmol)
296  * - \f$\tilde{s}^0(T) \f$= standard Entropy (J/gmol*K)
297  * - \f$t \f$= temperature (K) / 1000.
298  *
300  * http://webbook.nist.gov/
301  *
302  * Before being used within Cantera, the dimensions must be adjusted to those
303  * used by Cantera (i.e., Joules and kmol).
304  *
305  * This function uses two temperature regions, each with a Shomate polynomial
306  * representation to represent the thermo functions. There are 15 coefficients,
307  * therefore, in this representation. The first coefficient is the midrange
308  * temperature.
309  *
310  * @ingroup spthermo
311  */
313 {
314 public:
315  //! Empty constructor
317  : m_midT(0.0)
318  {
319  m_coeff.resize(15);
320  }
321
322  //! Constructor used in templated instantiations
323  /*!
324  * @param n Species index
325  * @param tlow Minimum temperature
326  * @param thigh Maximum temperature
327  * @param pref reference pressure (Pa).
328  * @param coeffs Vector of coefficients used to set the
329  * parameters for the standard state.
330  * There are 15 coefficients for the 2-zone Shomate polynomial.
331  * The first coefficient is the value of Tmid. The next 7
332  * coefficients are the low temperature range Shomate coefficients.
333  * The last 7 are the high temperature range Shomate coefficients.
334  * @deprecated Use the constructor that does not require the species index.
335  * To be removed after Cantera 2.2.
336  */
337  ShomatePoly2(size_t n, doublereal tlow, doublereal thigh, doublereal pref,
338  const doublereal* coeffs) :
339  SpeciesThermoInterpType(n, tlow, thigh, pref),
340  m_midT(coeffs),
341  msp_low(n, tlow, coeffs, pref, coeffs+1),
342  msp_high(n, coeffs, thigh, pref, coeffs+8),
343  m_coeff(coeffs, coeffs + 15)
344  {
345  }
346
347  //! Normal constructor
348  /*!
349  * @param tlow Minimum temperature
350  * @param thigh Maximum temperature
351  * @param pref reference pressure (Pa).
352  * @param coeffs Vector of coefficients used to set the parameters for the
353  * standard state. [Tmid, 7 low-T coeffs, 7 high-T coeffs]
354  */
355  ShomatePoly2(double tlow, double thigh, double pref, const double* coeffs) :
356  SpeciesThermoInterpType(tlow, thigh, pref),
357  m_midT(coeffs),
358  msp_low(tlow, coeffs, pref, coeffs+1),
359  msp_high(coeffs, thigh, pref, coeffs+8),
360  m_coeff(coeffs, coeffs + 15)
361  {
362  }
363
364  //! Copy constructor
365  /*!
366  * @param b object to be copied.
367  */
370  m_midT(b.m_midT),
371  msp_low(b.msp_low),
372  msp_high(b.msp_high),
373  m_coeff(b.m_coeff)
374  {
375  }
376
377  //! Assignment operator
378  /*!
379  * @param b object to be copied.
380  */
382  if (&b != this) {
383  SpeciesThermoInterpType::operator=(b);
384  m_midT = b.m_midT;
385  m_coeff = b.m_coeff;
386  msp_low = b.msp_low;
387  msp_high = b.msp_high;
388  }
389  return *this;
390  }
391
392  virtual SpeciesThermoInterpType*
393  duplMyselfAsSpeciesThermoInterpType() const {
394  ShomatePoly2* sp = new ShomatePoly2(*this);
395  return (SpeciesThermoInterpType*) sp;
396  }
397
398  virtual int reportType() const {
399  return SHOMATE2;
400  }
401
402  virtual void setIndex(size_t index) {
404  msp_low.setIndex(index);
405  msp_high.setIndex(index);
406  }
407
408  virtual size_t temperaturePolySize() const { return 7; }
409
410  virtual void updateTemperaturePoly(double T, double* T_poly) const {
411  msp_low.updateTemperaturePoly(T, T_poly);
412  }
413
414  //! Update the properties for this species, given a temperature polynomial
415  /*!
416  * This method is called with a pointer to an array containing the
417  * functions of temperature needed by this parameterization, and three
418  * pointers to arrays where the computed property values should be
419  * written. This method updates only one value in each array.
420  *
421  * Temperature Polynomial:
422  * - tt = t
423  * - tt = t*t
424  * - tt = m_t*t
425  * - tt = m_t*t
426  * - tt = 1.0/t
427  * - tt = std::log(t)
428  *
429  * @param tt vector of temperature polynomials
430  * @param cp_R Vector of Dimensionless heat capacities. (length m_kk).
431  * @param h_RT Vector of Dimensionless enthalpies. (length m_kk).
432  * @param s_R Vector of Dimensionless entropies. (length m_kk).
433  */
434  virtual void updateProperties(const doublereal* tt,
435  doublereal* cp_R, doublereal* h_RT,
436  doublereal* s_R) const {
437  double T = 1000 * tt;
438  if (T <= m_midT) {
439  msp_low.updateProperties(tt, cp_R, h_RT, s_R);
440  } else {
441  msp_high.updateProperties(tt, cp_R, h_RT, s_R);
442  }
443  }
444
445  virtual void updatePropertiesTemp(const doublereal temp,
446  doublereal* cp_R,
447  doublereal* h_RT,
448  doublereal* s_R) const {
449  if (temp <= m_midT) {
450  msp_low.updatePropertiesTemp(temp, cp_R, h_RT, s_R);
451  } else {
452  msp_high.updatePropertiesTemp(temp, cp_R, h_RT, s_R);
453  }
454  }
455
456  virtual void reportParameters(size_t& n, int& type,
457  doublereal& tlow, doublereal& thigh,
458  doublereal& pref,
459  doublereal* const coeffs) const {
460  n = m_index;
461  type = SHOMATE2;
462  tlow = m_lowT;
463  thigh = m_highT;
464  pref = m_Pref;
465  for (int i = 0; i < 15; i++) {
466  coeffs[i] = m_coeff[i];
467  }
468  }
469
470  //! Modify parameters for the standard state
471  /*!
472  * Here, we take the tact that we will just regenerate the object.
473  *
474  * @param coeffs Vector of coefficients used to set the
475  * parameters for the standard state.
476  */
477  virtual void modifyParameters(doublereal* coeffs) {
478  std::copy(coeffs, coeffs + 15, m_coeff.begin());
479  m_midT = coeffs;
480  msp_low = ShomatePoly(m_index, m_lowT, m_midT, m_Pref, coeffs+1);
481  msp_high = ShomatePoly(m_index, m_midT, m_highT, m_Pref, coeffs+8);
482  }
483
484  virtual doublereal reportHf298(doublereal* const h298 = 0) const {
485  doublereal h;
486  if (298.15 <= m_midT) {
487  h = msp_low.reportHf298(h298);
488  } else {
489  h = msp_high.reportHf298(h298);
490  }
491  if (h298) {
492  h298[m_index] = h;
493  }
494  return h;
495  }
496
497  virtual void modifyOneHf298(const size_t k, const doublereal Hf298New) {
498  if (k != m_index) {
499  return;
500  }
501
502  doublereal h298now = reportHf298(0);
503  doublereal delH = Hf298New - h298now;
504  double h = msp_low.reportHf298(0);
505  double hnew = h + delH;
506  msp_low.modifyOneHf298(k, hnew);
507  h = msp_high.reportHf298(0);
508  hnew = h + delH;
509  msp_high.modifyOneHf298(k, hnew);
510  }
511
512 protected:
513  //! Midrange temperature (kelvin)
514  doublereal m_midT;
515  //! Shomate polynomial for the low temperature region.
517  //! Shomate polynomial for the high temperature region.
519  //! Array of the original coefficients.
521 };
522 }
523
524 #endif
doublereal m_midT
Midrange temperature (kelvin)
Definition: ShomatePoly.h:514
virtual size_t temperaturePolySize() const
Number of terms in the temperature polynomial for this parameterization.
Definition: ShomatePoly.h:408
Pure Virtual Base class for the thermodynamic manager for an individual species' reference state...
ShomatePoly2(size_t n, doublereal tlow, doublereal thigh, doublereal pref, const doublereal *coeffs)
Constructor used in templated instantiations.
Definition: ShomatePoly.h:337
#define SHOMATE
Two regions of Shomate Polynomials.
virtual void modifyOneHf298(const size_t k, const doublereal Hf298New)
Modify the value of the 298 K Heat of Formation of one species in the phase (J kmol-1) ...
Definition: ShomatePoly.h:497
vector_fp m_coeff
Array of coefficients.
Definition: ShomatePoly.h:268
virtual void modifyParameters(doublereal *coeffs)
Modify parameters for the standard state.
Definition: ShomatePoly.h:233
ShomatePoly()
Empty constructor.
Definition: ShomatePoly.h:60
virtual void reportParameters(size_t &n, int &type, doublereal &tlow, doublereal &thigh, doublereal &pref, doublereal *const coeffs) const
This utility function reports back the type of parameterization and all of the parameters for the spe...
Definition: ShomatePoly.h:214
virtual void updateProperties(const doublereal *tt, doublereal *cp_R, doublereal *h_RT, doublereal *s_R) const
Update the properties for this species, given a temperature polynomial.
Definition: ShomatePoly.h:175
ShomatePoly(size_t n, doublereal tlow, doublereal thigh, doublereal pref, const doublereal *coeffs)
Constructor used in templated instantiations.
Definition: ShomatePoly.h:85
vector_fp m_coeff
Array of the original coefficients.
Definition: ShomatePoly.h:520
virtual doublereal reportHf298(doublereal *const h298=0) const
Report the 298 K Heat of Formation of the standard state of one species (J kmol-1) ...
Definition: ShomatePoly.h:241
ShomatePoly(const ShomatePoly &b)
copy constructor
Definition: ShomatePoly.h:113
ShomatePoly msp_high
Shomate polynomial for the high temperature region.
Definition: ShomatePoly.h:518
virtual int reportType() const
Returns an integer representing the type of parameterization.
Definition: ShomatePoly.h:398
Pure Virtual Base class for individual species reference state thermodynamic managers and text for th...
virtual void updateTemperaturePoly(double T, double *T_poly) const
Given the temperature T, compute the terms of the temperature polynomial T_poly.
Definition: ShomatePoly.h:143
virtual void modifyOneHf298(const size_t k, const doublereal Hf298New)
Modify the value of the 298 K Heat of Formation of one species in the phase (J kmol-1) ...
Definition: ShomatePoly.h:260
ShomatePoly2(const ShomatePoly2 &b)
Copy constructor.
Definition: ShomatePoly.h:368
The Shomate polynomial parameterization for one temperature range for one species.
Definition: ShomatePoly.h:56
The Shomate polynomial parameterization for two temperature ranges for one species.
Definition: ShomatePoly.h:312
virtual void updateTemperaturePoly(double T, double *T_poly) const
Given the temperature T, compute the terms of the temperature polynomial T_poly.
Definition: ShomatePoly.h:410
doublereal m_highT
Highest valid temperature.
virtual void modifyParameters(doublereal *coeffs)
Modify parameters for the standard state.
Definition: ShomatePoly.h:477
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:99
ShomatePoly msp_low
Shomate polynomial for the low temperature region.
Definition: ShomatePoly.h:516
#define SHOMATE2
Two regions of Shomate Polynomials.
doublereal m_lowT
lowest valid temperature
ShomatePoly2(double tlow, double thigh, double pref, const double *coeffs)
Normal constructor.
Definition: ShomatePoly.h:355
virtual void updatePropertiesTemp(const doublereal temp, doublereal *cp_R, doublereal *h_RT, doublereal *s_R) const
Compute the reference-state property of one species.
Definition: ShomatePoly.h:445
virtual void reportParameters(size_t &n, int &type, doublereal &tlow, doublereal &thigh, doublereal &pref, doublereal *const coeffs) const
This utility function reports back the type of parameterization and all of the parameters for the spe...
Definition: ShomatePoly.h:456
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
Definition: ct_defs.h:157
virtual int reportType() const
Returns an integer representing the type of parameterization.
Definition: ShomatePoly.h:137
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:64
ShomatePoly & operator=(const ShomatePoly &b)
Assignment operator.
Definition: ShomatePoly.h:123
virtual void setIndex(size_t index)
Definition: ShomatePoly.h:402
virtual void updateProperties(const doublereal *tt, doublereal *cp_R, doublereal *h_RT, doublereal *s_R) const
Update the properties for this species, given a temperature polynomial.
Definition: ShomatePoly.h:434
doublereal m_Pref
Reference state pressure.
ShomatePoly2()
Empty constructor.
Definition: ShomatePoly.h:316
virtual size_t temperaturePolySize() const
Number of terms in the temperature polynomial for this parameterization.
Definition: ShomatePoly.h:141
virtual void updatePropertiesTemp(const doublereal temp, doublereal *cp_R, doublereal *h_RT, doublereal *s_R) const
Compute the reference-state property of one species.
Definition: ShomatePoly.h:206
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
virtual doublereal reportHf298(doublereal *const h298=0) const
Report the 298 K Heat of Formation of the standard state of one species (J kmol-1) ...
Definition: ShomatePoly.h:484
ShomatePoly2 & operator=(const ShomatePoly2 &b)
Assignment operator.
Definition: ShomatePoly.h:381
ShomatePoly(double tlow, double thigh, double pref, const double *coeffs)
Normal constructor.
Definition: ShomatePoly.h:103