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