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