Cantera  2.5.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
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 
11 // This file is part of Cantera. See License.txt in the top-level directory or
12 // at https://cantera.org/license.txt for license and copyright information.
13 
14 #ifndef CT_SHOMATEPOLY1_H
15 #define CT_SHOMATEPOLY1_H
16 
18 
19 namespace Cantera
20 {
21 //! The Shomate polynomial parameterization for one temperature range for one
22 //! species
23 /*!
24  * Seven coefficients \f$(A,\dots,G)\f$ are used to represent
25  * \f$ c_p^0(T)\f$, \f$ h^0(T)\f$, and \f$ s^0(T) \f$ as
26  * polynomials in the temperature, \f$ T \f$ :
27  *
28  * \f[
29  * \tilde{c}_p^0(T) = A + B t + C t^2 + D t^3 + \frac{E}{t^2}
30  * \f]
31  * \f[
32  * \tilde{h}^0(T) = A t + \frac{B t^2}{2} + \frac{C t^3}{3}
33  * + \frac{D t^4}{4} - \frac{E}{t} + F.
34  * \f]
35  * \f[
36  * \tilde{s}^0(T) = A\ln t + B t + \frac{C t^2}{2}
37  * + \frac{D t^3}{3} - \frac{E}{2t^2} + G.
38  * \f]
39  *
40  * In the above expressions, the thermodynamic polynomials are expressed in
41  * dimensional units, but the temperature,\f$ t \f$, is divided by 1000. The
42  * following dimensions are assumed in the above expressions:
43  *
44  * - \f$ \tilde{c}_p^0(T)\f$ = Heat Capacity (J/gmol*K)
45  * - \f$ \tilde{h}^0(T) \f$ = standard Enthalpy (kJ/gmol)
46  * - \f$ \tilde{s}^0(T) \f$= standard Entropy (J/gmol*K)
47  * - \f$ t \f$= temperature (K) / 1000.
48  *
49  * For more information about Shomate polynomials, see the NIST website,
50  * http://webbook.nist.gov/
51  *
52  * Before being used within Cantera, the dimensions must be adjusted to those
53  * used by Cantera (i.e., Joules and kmol).
54  *
55  * @ingroup spthermo
56  */
58 {
59 public:
60  ShomatePoly() : m_coeff(7), m_coeff5_orig(0.0) {}
61 
62  //! Constructor with all input data
63  /*!
64  * @param tlow Minimum temperature
65  * @param thigh Maximum temperature
66  * @param pref reference pressure (Pa).
67  * @param coeffs Vector of coefficients, [A,B,C,D,E,F,G], used to set
68  * the parameters for the species standard state.
69  *
70  * See the class description for the polynomial representation of the
71  * thermo functions in terms of \f$ A, \dots, G \f$.
72  */
73  ShomatePoly(double tlow, double thigh, double pref, const double* coeffs) :
74  SpeciesThermoInterpType(tlow, thigh, pref),
75  m_coeff(7)
76  {
77  for (size_t i = 0; i < 7; i++) {
78  m_coeff[i] = coeffs[i] * 1000 / GasConstant;
79  }
80  m_coeff5_orig = m_coeff[5];
81  }
82 
83  //! Set array of 7 polynomial coefficients. Input values are assumed to be
84  //! on a kJ/mol basis.
85  void setParameters(const vector_fp& coeffs) {
86  if (coeffs.size() != 7) {
87  throw CanteraError("ShomatePoly::setParameters", "Array must "
88  "contain 7 coefficients, but {} were given.", coeffs.size());
89  }
90  for (size_t i = 0; i < 7; i++) {
91  m_coeff[i] = coeffs[i] * 1000 / GasConstant;
92  }
93  m_coeff5_orig = m_coeff[5];
94  }
95 
96  virtual int reportType() const {
97  return SHOMATE;
98  }
99 
100  virtual size_t temperaturePolySize() const { return 6; }
101 
102  virtual void updateTemperaturePoly(double T, double* T_poly) const {
103  doublereal tt = 1.e-3*T;
104  T_poly[0] = tt;
105  T_poly[1] = tt * tt;
106  T_poly[2] = T_poly[1] * tt;
107  T_poly[3] = 1.0/T_poly[1];
108  T_poly[4] = std::log(tt);
109  T_poly[5] = 1.0/tt;
110  }
111 
112  /*!
113  * @copydoc SpeciesThermoInterpType::updateProperties
114  *
115  * Form of the temperature polynomial:
116  * - `t` is T/1000.
117  * - `t[0] = t`
118  * - `t[1] = t*t`
119  * - `t[2] = t[1]*t`
120  * - `t[3] = 1.0/t[1]`
121  * - `t[4] = log(t)`
122  * - `t[5] = 1.0/t;
123  */
124  virtual void updateProperties(const doublereal* tt,
125  doublereal* cp_R, doublereal* h_RT,
126  doublereal* s_R) const {
127  doublereal A = m_coeff[0];
128  doublereal Bt = m_coeff[1]*tt[0];
129  doublereal Ct2 = m_coeff[2]*tt[1];
130  doublereal Dt3 = m_coeff[3]*tt[2];
131  doublereal Etm2 = m_coeff[4]*tt[3];
132  doublereal Ftm1 = m_coeff[5]*tt[5];
133  doublereal G = m_coeff[6];
134 
135  *cp_R = A + Bt + Ct2 + Dt3 + Etm2;
136  *h_RT = A + 0.5*Bt + 1.0/3.0*Ct2 + 0.25*Dt3 - Etm2 + Ftm1;
137  *s_R = A*tt[4] + Bt + 0.5*Ct2 + 1.0/3.0*Dt3 - 0.5*Etm2 + G;
138  }
139 
140  virtual void updatePropertiesTemp(const doublereal temp,
141  doublereal* cp_R, doublereal* h_RT,
142  doublereal* s_R) const {
143  double tPoly[6];
144  updateTemperaturePoly(temp, tPoly);
145  updateProperties(tPoly, cp_R, h_RT, s_R);
146  }
147 
148  virtual void reportParameters(size_t& n, int& type,
149  doublereal& tlow, doublereal& thigh,
150  doublereal& pref,
151  doublereal* const coeffs) const {
152  n = 0;
153  type = SHOMATE;
154  tlow = m_lowT;
155  thigh = m_highT;
156  pref = m_Pref;
157  for (int i = 0; i < 7; i++) {
158  coeffs[i] = m_coeff[i] * GasConstant / 1000;
159  }
160  }
161 
162  virtual doublereal reportHf298(doublereal* const h298 = 0) const {
163  double cp_R, h_RT, s_R;
164  updatePropertiesTemp(298.15, &cp_R, &h_RT, &s_R);
165  return h_RT * GasConstant * 298.15;
166  }
167 
168  virtual void modifyOneHf298(const size_t k, const doublereal Hf298New) {
169  doublereal hnow = reportHf298();
170  doublereal delH = Hf298New - hnow;
171  m_coeff[5] += delH / (1e3 * GasConstant);
172  }
173 
174  virtual void resetHf298() {
175  m_coeff[5] = m_coeff5_orig;
176  }
177 
178 protected:
179  //! Array of coefficients
181  double m_coeff5_orig;
182 };
183 
184 //! The Shomate polynomial parameterization for two temperature ranges for one
185 //! species
186 /*!
187  * Seven coefficients \f$(A,\dots,G)\f$ are used to represent
188  * \f$ c_p^0(T)\f$, \f$ h^0(T)\f$, and \f$ s^0(T) \f$ as
189  * polynomials in the temperature, \f$ T \f$, in one temperature region:
190  *
191  * \f[
192  * \tilde{c}_p^0(T) = A + B t + C t^2 + D t^3 + \frac{E}{t^2}
193  * \f]
194  * \f[
195  * \tilde{h}^0(T) = A t + \frac{B t^2}{2} + \frac{C t^3}{3}
196  * + \frac{D t^4}{4} - \frac{E}{t} + F.
197  * \f]
198  * \f[
199  * \tilde{s}^0(T) = A\ln t + B t + \frac{C t^2}{2}
200  * + \frac{D t^3}{3} - \frac{E}{2t^2} + G.
201  * \f]
202  *
203  * In the above expressions, the thermodynamic polynomials are expressed
204  * in dimensional units, but the temperature,\f$ t \f$, is divided by 1000. The
205  * following dimensions are assumed in the above expressions:
206  *
207  * - \f$ \tilde{c}_p^0(T)\f$ = Heat Capacity (J/gmol*K)
208  * - \f$ \tilde{h}^0(T) \f$ = standard Enthalpy (kJ/gmol)
209  * - \f$ \tilde{s}^0(T) \f$= standard Entropy (J/gmol*K)
210  * - \f$ t \f$= temperature (K) / 1000.
211  *
212  * For more information about Shomate polynomials, see the NIST website,
213  * http://webbook.nist.gov/
214  *
215  * Before being used within Cantera, the dimensions must be adjusted to those
216  * used by Cantera (i.e., Joules and kmol).
217  *
218  * This function uses two temperature regions, each with a Shomate polynomial
219  * representation to represent the thermo functions. There are 15 coefficients,
220  * therefore, in this representation. The first coefficient is the midrange
221  * temperature.
222  *
223  * @ingroup spthermo
224  */
226 {
227 public:
228  ShomatePoly2() : m_midT(0.0) {}
229 
230  //! Constructor with all input data
231  /*!
232  * @param tlow Minimum temperature
233  * @param thigh Maximum temperature
234  * @param pref reference pressure (Pa).
235  * @param coeffs Vector of coefficients used to set the parameters for the
236  * standard state. [Tmid, 7 low-T coeffs, 7 high-T coeffs]
237  */
238  ShomatePoly2(double tlow, double thigh, double pref, const double* coeffs) :
239  SpeciesThermoInterpType(tlow, thigh, pref),
240  m_midT(coeffs[0]),
241  msp_low(tlow, coeffs[0], pref, coeffs+1),
242  msp_high(coeffs[0], thigh, pref, coeffs+8)
243  {
244  }
245 
246  virtual void setMinTemp(double Tmin) {
248  msp_low.setMinTemp(Tmin);
249  }
250 
251  virtual void setMaxTemp(double Tmax) {
253  msp_high.setMaxTemp(Tmax);
254  }
255 
256  virtual void setRefPressure(double Pref) {
258  msp_low.setRefPressure(Pref);
259  msp_high.setRefPressure(Pref);
260  }
261 
262  /*!
263  * @param Tmid Temperature [K] at the boundary between the low and high
264  * temperature polynomials
265  * @param low Vector of 7 coefficients for the low temperature polynomial
266  * @param high Vector of 7 coefficients for the high temperature polynomial
267  */
268  void setParameters(double Tmid, const vector_fp& low, const vector_fp& high) {
269  m_midT = Tmid;
270  msp_low.setMaxTemp(Tmid);
271  msp_high.setMinTemp(Tmid);
272  msp_low.setParameters(low);
273  msp_high.setParameters(high);
274  }
275 
276  virtual int reportType() const {
277  return SHOMATE2;
278  }
279 
280  virtual size_t temperaturePolySize() const { return 7; }
281 
282  virtual void updateTemperaturePoly(double T, double* T_poly) const {
283  msp_low.updateTemperaturePoly(T, T_poly);
284  }
285 
286  //! @copydoc ShomatePoly::updateProperties
287  virtual void updateProperties(const doublereal* tt,
288  doublereal* cp_R, doublereal* h_RT,
289  doublereal* s_R) const {
290  double T = 1000 * tt[0];
291  if (T <= m_midT) {
292  msp_low.updateProperties(tt, cp_R, h_RT, s_R);
293  } else {
294  msp_high.updateProperties(tt, cp_R, h_RT, s_R);
295  }
296  }
297 
298  virtual void updatePropertiesTemp(const doublereal temp,
299  doublereal* cp_R,
300  doublereal* h_RT,
301  doublereal* s_R) const {
302  if (temp <= m_midT) {
303  msp_low.updatePropertiesTemp(temp, cp_R, h_RT, s_R);
304  } else {
305  msp_high.updatePropertiesTemp(temp, cp_R, h_RT, s_R);
306  }
307  }
308 
309  virtual size_t nCoeffs() const { return 15; }
310 
311  virtual void reportParameters(size_t& n, int& type,
312  doublereal& tlow, doublereal& thigh,
313  doublereal& pref,
314  doublereal* const coeffs) const {
315  msp_low.reportParameters(n, type, tlow, coeffs[0], pref, coeffs + 1);
316  msp_high.reportParameters(n, type, coeffs[0], thigh, pref, coeffs + 8);
317  type = SHOMATE2;
318  }
319 
320  virtual doublereal reportHf298(doublereal* const h298 = 0) const {
321  doublereal h;
322  if (298.15 <= m_midT) {
323  h = msp_low.reportHf298(h298);
324  } else {
325  h = msp_high.reportHf298(h298);
326  }
327  if (h298) {
328  *h298 = h;
329  }
330  return h;
331  }
332 
333  virtual void modifyOneHf298(const size_t k, const doublereal Hf298New) {
334  doublereal h298now = reportHf298(0);
335  doublereal delH = Hf298New - h298now;
336  double h = msp_low.reportHf298(0);
337  double hnew = h + delH;
338  msp_low.modifyOneHf298(k, hnew);
339  h = msp_high.reportHf298(0);
340  hnew = h + delH;
341  msp_high.modifyOneHf298(k, hnew);
342  }
343 
344  virtual void resetHf298() {
347  }
348 
349 protected:
350  //! Midrange temperature (kelvin)
351  doublereal m_midT;
352  //! Shomate polynomial for the low temperature region.
354  //! Shomate polynomial for the high temperature region.
356 };
357 }
358 
359 #endif
Pure Virtual Base class for individual species reference state thermodynamic managers and text for th...
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:61
The Shomate polynomial parameterization for two temperature ranges for one species.
Definition: ShomatePoly.h:226
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:298
ShomatePoly msp_low
Shomate polynomial for the low temperature region.
Definition: ShomatePoly.h:353
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:282
virtual void setRefPressure(double Pref)
Set the reference pressure [Pa].
Definition: ShomatePoly.h:256
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:287
ShomatePoly2(double tlow, double thigh, double pref, const double *coeffs)
Constructor with all input data.
Definition: ShomatePoly.h:238
virtual void resetHf298()
Restore the original heat of formation for this species.
Definition: ShomatePoly.h:344
void setParameters(double Tmid, const vector_fp &low, const vector_fp &high)
Definition: ShomatePoly.h:268
ShomatePoly msp_high
Shomate polynomial for the high temperature region.
Definition: ShomatePoly.h:355
virtual void reportParameters(size_t &n, int &type, doublereal &tlow, doublereal &thigh, doublereal &pref, doublereal *const coeffs) const
This utility function returns the type of parameterization and all of the parameters for the species.
Definition: ShomatePoly.h:311
virtual void setMinTemp(double Tmin)
Set the minimum temperature at which the thermo parameterization is valid.
Definition: ShomatePoly.h:246
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:333
doublereal m_midT
Midrange temperature (kelvin)
Definition: ShomatePoly.h:351
virtual size_t temperaturePolySize() const
Number of terms in the temperature polynomial for this parameterization.
Definition: ShomatePoly.h:280
virtual void setMaxTemp(double Tmax)
Set the maximum temperature at which the thermo parameterization is valid.
Definition: ShomatePoly.h:251
virtual int reportType() const
Returns an integer representing the type of parameterization.
Definition: ShomatePoly.h:276
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:320
virtual size_t nCoeffs() const
This utility function returns the number of coefficients for a given type of species parameterization...
Definition: ShomatePoly.h:309
The Shomate polynomial parameterization for one temperature range for one species.
Definition: ShomatePoly.h:58
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:140
vector_fp m_coeff
Array of coefficients.
Definition: ShomatePoly.h:180
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:102
void setParameters(const vector_fp &coeffs)
Set array of 7 polynomial coefficients.
Definition: ShomatePoly.h:85
ShomatePoly(double tlow, double thigh, double pref, const double *coeffs)
Constructor with all input data.
Definition: ShomatePoly.h:73
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:124
virtual void resetHf298()
Restore the original heat of formation for this species.
Definition: ShomatePoly.h:174
virtual void reportParameters(size_t &n, int &type, doublereal &tlow, doublereal &thigh, doublereal &pref, doublereal *const coeffs) const
This utility function returns the type of parameterization and all of the parameters for the species.
Definition: ShomatePoly.h:148
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:168
virtual size_t temperaturePolySize() const
Number of terms in the temperature polynomial for this parameterization.
Definition: ShomatePoly.h:100
virtual int reportType() const
Returns an integer representing the type of parameterization.
Definition: ShomatePoly.h:96
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:162
Abstract Base class for the thermodynamic manager for an individual species' reference state.
virtual void setRefPressure(double Pref)
Set the reference pressure [Pa].
doublereal m_lowT
lowest valid temperature
virtual void setMinTemp(double Tmin)
Set the minimum temperature at which the thermo parameterization is valid.
doublereal m_highT
Highest valid temperature.
virtual void setMaxTemp(double Tmax)
Set the maximum temperature at which the thermo parameterization is valid.
doublereal m_Pref
Reference state pressure.
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:180
const double GasConstant
Universal Gas Constant [J/kmol/K].
Definition: ct_defs.h:109
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:264
#define SHOMATE
Two regions of Shomate Polynomials.
#define SHOMATE2
Two regions of Shomate Polynomials.