| Cantera 3.0.0

Loading...
Searching...
No Matches
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
17#include "cantera/thermo/SpeciesThermoInterpType.h"
18#include "cantera/base/AnyMap.h"
19
20 namespace 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 */
58 class ShomatePoly : public SpeciesThermoInterpType
59{
60 public:
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<double>& 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 int reportType() const override {
98 return SHOMATE;
99 }
100
101 size_t temperaturePolySize() const override { return 6; }
102
103 void updateTemperaturePoly(double T, double* T_poly) const override {
104 double 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 void updateProperties(const double* tt, double* cp_R, double* h_RT,
126 double* s_R) const override {
127 double A = m_coeff[0];
128 double Bt = m_coeff[1]*tt[0];
129 double Ct2 = m_coeff[2]*tt[1];
130 double Dt3 = m_coeff[3]*tt[2];
131 double Etm2 = m_coeff[4]*tt[3];
132 double Ftm1 = m_coeff[5]*tt[5];
133 double 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 void updatePropertiesTemp(const double temp, double* cp_R, double* h_RT,
141 double* s_R) const override {
142 double tPoly[6];
143 updateTemperaturePoly(temp, tPoly);
144 updateProperties(tPoly, cp_R, h_RT, s_R);
145 }
146
147 void reportParameters(size_t& n, int& type, double& tlow, double& thigh,
148 double& pref, double* const coeffs) const override {
149 n = 0;
150 type = SHOMATE;
151 tlow = m_lowT;
152 thigh = m_highT;
153 pref = m_Pref;
154 for (int i = 0; i < 7; i++) {
155 coeffs[i] = m_coeff[i] * GasConstant / 1000;
156 }
157 }
158
159 void getParameters(AnyMap& thermo) const override {
160 // ShomatePoly is only used as an embedded model within ShomatePoly2, so
161 // all that needs to be added here are the polynomial coefficients
162 vector<double> dimensioned_coeffs(m_coeff.size());
163 for (size_t i = 0; i < m_coeff.size(); i++) {
164 dimensioned_coeffs[i] = m_coeff[i] * GasConstant / 1000;
165 }
166 thermo["data"].asVector<vector<double>>().push_back(dimensioned_coeffs);
167 }
168
169 double reportHf298(double* const h298=nullptr) const override {
170 double cp_R, h_RT, s_R;
171 updatePropertiesTemp(298.15, &cp_R, &h_RT, &s_R);
172 return h_RT * GasConstant * 298.15;
173 }
174
175 void modifyOneHf298(const size_t k, const double Hf298New) override {
176 double hnow = reportHf298();
177 double delH = Hf298New - hnow;
178 m_coeff[5] += delH / (1e3 * GasConstant);
179 }
180
181 void resetHf298() override {
182 m_coeff[5] = m_coeff5_orig;
183 }
184
185 protected:
186 //! Array of coefficients
187 vector<double> m_coeff;
188 double m_coeff5_orig;
189};
190
191//! The Shomate polynomial parameterization for two temperature ranges for one
192//! species
193/*!
194 * Seven coefficients @f$ (A,\dots,G) @f$ are used to represent
195 * @f$ c_p^0(T) @f$, @f$ h^0(T) @f$, and @f$ s^0(T) @f$ as
196 * polynomials in the temperature, @f$ T @f$, in one temperature region:
197 *
198 * @f[
199 * \tilde{c}_p^0(T) = A + B t + C t^2 + D t^3 + \frac{E}{t^2}
200 * @f]
201 * @f[
202 * \tilde{h}^0(T) = A t + \frac{B t^2}{2} + \frac{C t^3}{3}
203 * + \frac{D t^4}{4} - \frac{E}{t} + F.
204 * @f]
205 * @f[
206 * \tilde{s}^0(T) = A\ln t + B t + \frac{C t^2}{2}
207 * + \frac{D t^3}{3} - \frac{E}{2t^2} + G.
208 * @f]
209 *
210 * In the above expressions, the thermodynamic polynomials are expressed
211 * in dimensional units, but the temperature,@f$ t @f$, is divided by 1000. The
212 * following dimensions are assumed in the above expressions:
213 *
214 * - @f$ \tilde{c}_p^0(T) @f$ = Heat Capacity (J/gmol*K)
215 * - @f$ \tilde{h}^0(T) @f$ = standard Enthalpy (kJ/gmol)
216 * - @f$ \tilde{s}^0(T) @f$= standard Entropy (J/gmol*K)
217 * - @f$ t @f$= temperature (K) / 1000.
218 *
219 * For more information about Shomate polynomials, see the NIST website,
220 * http://webbook.nist.gov/
221 *
222 * Before being used within Cantera, the dimensions must be adjusted to those
223 * used by %Cantera (for example, Joules and kmol).
224 *
225 * This function uses two temperature regions, each with a Shomate polynomial
226 * representation to represent the thermo functions. There are 15 coefficients,
227 * therefore, in this representation. The first coefficient is the midrange
228 * temperature.
229 *
230 * @ingroup spthermo
231 */
232 class ShomatePoly2 : public SpeciesThermoInterpType
233{
234 public:
235 ShomatePoly2() : m_midT(0.0) {}
236
237 //! Constructor with all input data
238 /*!
239 * @param tlow Minimum temperature
240 * @param thigh Maximum temperature
241 * @param pref reference pressure (Pa).
242 * @param coeffs Vector of coefficients used to set the parameters for the
243 * standard state. [Tmid, 7 low-T coeffs, 7 high-T coeffs]
244 */
245 ShomatePoly2(double tlow, double thigh, double pref, const double* coeffs) :
246 SpeciesThermoInterpType(tlow, thigh, pref),
247 m_midT(coeffs[0]),
248 msp_low(tlow, coeffs[0], pref, coeffs+1),
249 msp_high(coeffs[0], thigh, pref, coeffs+8)
250 {
251 }
252
253 void setMinTemp(double Tmin) override {
254 SpeciesThermoInterpType::setMinTemp(Tmin);
255 msp_low.setMinTemp(Tmin);
256 }
257
258 void setMaxTemp(double Tmax) override {
259 SpeciesThermoInterpType::setMaxTemp(Tmax);
260 msp_high.setMaxTemp(Tmax);
261 }
262
263 void setRefPressure(double Pref) override {
264 SpeciesThermoInterpType::setRefPressure(Pref);
265 msp_low.setRefPressure(Pref);
266 msp_high.setRefPressure(Pref);
267 }
268
269 /**
270 * @param Tmid Temperature [K] at the boundary between the low and high
271 * temperature polynomials
272 * @param low Vector of 7 coefficients for the low temperature polynomial
273 * @param high Vector of 7 coefficients for the high temperature polynomial
274 */
275 void setParameters(double Tmid, const vector<double>& low, const vector<double>& high) {
276 m_midT = Tmid;
277 msp_low.setMaxTemp(Tmid);
278 msp_high.setMinTemp(Tmid);
279 msp_low.setParameters(low);
280 msp_high.setParameters(high);
281 }
282
283 int reportType() const override {
284 return SHOMATE2;
285 }
286
287 size_t temperaturePolySize() const override{ return 7; }
288
289 void updateTemperaturePoly(double T, double* T_poly) const override {
290 msp_low.updateTemperaturePoly(T, T_poly);
291 }
292
293 //! @copydoc ShomatePoly::updateProperties
294 void updateProperties(const double* tt, double* cp_R, double* h_RT,
295 double* s_R) const override {
296 double T = 1000 * tt[0];
297 if (T <= m_midT) {
298 msp_low.updateProperties(tt, cp_R, h_RT, s_R);
299 } else {
300 msp_high.updateProperties(tt, cp_R, h_RT, s_R);
301 }
302 }
303
304 void updatePropertiesTemp(const double temp, double* cp_R, double* h_RT,
305 double* s_R) const override {
306 if (temp <= m_midT) {
307 msp_low.updatePropertiesTemp(temp, cp_R, h_RT, s_R);
308 } else {
309 msp_high.updatePropertiesTemp(temp, cp_R, h_RT, s_R);
310 }
311 }
312
313 size_t nCoeffs() const override { return 15; }
314
315 void reportParameters(size_t& n, int& type, double& tlow, double& thigh,
316 double& pref, double* const coeffs) const override {
317 msp_low.reportParameters(n, type, tlow, coeffs[0], pref, coeffs + 1);
318 msp_high.reportParameters(n, type, coeffs[0], thigh, pref, coeffs + 8);
319 type = SHOMATE2;
320 }
321
322 void getParameters(AnyMap& thermo) const override {
323 SpeciesThermoInterpType::getParameters(thermo);
324 thermo["model"] = "Shomate";
325 vector<double> Tranges {m_lowT, m_midT, m_highT};
326 thermo["temperature-ranges"].setQuantity(Tranges, "K");
327 thermo["data"] = vector<vector<double>>();
328 msp_low.getParameters(thermo);
329 msp_high.getParameters(thermo);
330 }
331
332 double reportHf298(double* const h298=nullptr) const override {
333 double h;
334 if (298.15 <= m_midT) {
335 h = msp_low.reportHf298(h298);
336 } else {
337 h = msp_high.reportHf298(h298);
338 }
339 if (h298) {
340 *h298 = h;
341 }
342 return h;
343 }
344
345 void modifyOneHf298(const size_t k, const double Hf298New) override {
346 double h298now = reportHf298(0);
347 double delH = Hf298New - h298now;
348 double h = msp_low.reportHf298(0);
349 double hnew = h + delH;
350 msp_low.modifyOneHf298(k, hnew);
351 h = msp_high.reportHf298(0);
352 hnew = h + delH;
353 msp_high.modifyOneHf298(k, hnew);
354 }
355
356 void resetHf298() override {
357 msp_low.resetHf298();
358 msp_high.resetHf298();
359 }
360
361 protected:
362 //! Midrange temperature (kelvin)
363 double m_midT;
364 //! Shomate polynomial for the low temperature region.
365 ShomatePoly msp_low;
366 //! Shomate polynomial for the high temperature region.
367 ShomatePoly msp_high;
368};
369}
370
371#endif
AnyMap.h
SpeciesThermoInterpType.h
Pure Virtual Base class for individual species reference state thermodynamic managers and text for th...
Cantera::AnyMap
A map of string keys to values whose type can vary at runtime.
Definition AnyMap.h:427
Cantera::CanteraError
Base class for exceptions thrown by Cantera classes.
Definition ctexceptions.h:66
Cantera::ShomatePoly2
The Shomate polynomial parameterization for two temperature ranges for one species.
Definition ShomatePoly.h:233
Cantera::ShomatePoly2::setMinTemp
void setMinTemp(double Tmin) override
Set the minimum temperature at which the thermo parameterization is valid.
Definition ShomatePoly.h:253
Cantera::ShomatePoly2::reportType
int reportType() const override
Returns an integer representing the type of parameterization.
Definition ShomatePoly.h:283
Cantera::ShomatePoly2::msp_low
ShomatePoly msp_low
Shomate polynomial for the low temperature region.
Definition ShomatePoly.h:365
Cantera::ShomatePoly2::temperaturePolySize
size_t temperaturePolySize() const override
Number of terms in the temperature polynomial for this parameterization.
Definition ShomatePoly.h:287
Cantera::ShomatePoly2::getParameters
void getParameters(AnyMap &thermo) const override
Store the parameters of the species thermo object such that an identical species thermo object could ...
Definition ShomatePoly.h:322
Cantera::ShomatePoly2::nCoeffs
size_t nCoeffs() const override
This utility function returns the number of coefficients for a given type of species parameterization...
Definition ShomatePoly.h:313
Cantera::ShomatePoly2::updateTemperaturePoly
void updateTemperaturePoly(double T, double *T_poly) const override
Given the temperature T, compute the terms of the temperature polynomial T_poly.
Definition ShomatePoly.h:289
Cantera::ShomatePoly2::reportParameters
void reportParameters(size_t &n, int &type, double &tlow, double &thigh, double &pref, double *const coeffs) const override
This utility function returns the type of parameterization and all of the parameters for the species.
Definition ShomatePoly.h:315
Cantera::ShomatePoly2::setParameters
void setParameters(double Tmid, const vector< double > &low, const vector< double > &high)
Definition ShomatePoly.h:275
Cantera::ShomatePoly2::ShomatePoly2
ShomatePoly2(double tlow, double thigh, double pref, const double *coeffs)
Constructor with all input data.
Definition ShomatePoly.h:245
Cantera::ShomatePoly2::setRefPressure
void setRefPressure(double Pref) override
Set the reference pressure [Pa].
Definition ShomatePoly.h:263
Cantera::ShomatePoly2::msp_high
ShomatePoly msp_high
Shomate polynomial for the high temperature region.
Definition ShomatePoly.h:367
Cantera::ShomatePoly2::updateProperties
void updateProperties(const double *tt, double *cp_R, double *h_RT, double *s_R) const override
Update the properties for this species, given a temperature polynomial.
Definition ShomatePoly.h:294
Cantera::ShomatePoly2::reportHf298
double reportHf298(double *const h298=nullptr) const override
Report the 298 K Heat of Formation of the standard state of one species (J kmol-1)
Definition ShomatePoly.h:332
Cantera::ShomatePoly2::resetHf298
void resetHf298() override
Restore the original heat of formation for this species.
Definition ShomatePoly.h:356
Cantera::ShomatePoly2::setMaxTemp
void setMaxTemp(double Tmax) override
Set the maximum temperature at which the thermo parameterization is valid.
Definition ShomatePoly.h:258
Cantera::ShomatePoly2::m_midT
double m_midT
Midrange temperature (kelvin)
Definition ShomatePoly.h:363
Cantera::ShomatePoly2::modifyOneHf298
void modifyOneHf298(const size_t k, const double Hf298New) override
Modify the value of the 298 K Heat of Formation of one species in the phase (J kmol-1)
Definition ShomatePoly.h:345
Cantera::ShomatePoly2::updatePropertiesTemp
void updatePropertiesTemp(const double temp, double *cp_R, double *h_RT, double *s_R) const override
Compute the reference-state property of one species.
Definition ShomatePoly.h:304
Cantera::ShomatePoly
The Shomate polynomial parameterization for one temperature range for one species.
Definition ShomatePoly.h:59
Cantera::ShomatePoly::m_coeff
vector< double > m_coeff
Array of coefficients.
Definition ShomatePoly.h:187
Cantera::ShomatePoly::reportType
int reportType() const override
Returns an integer representing the type of parameterization.
Definition ShomatePoly.h:97
Cantera::ShomatePoly::setParameters
void setParameters(const vector< double > &coeffs)
Set array of 7 polynomial coefficients.
Definition ShomatePoly.h:86
Cantera::ShomatePoly::temperaturePolySize
size_t temperaturePolySize() const override
Number of terms in the temperature polynomial for this parameterization.
Definition ShomatePoly.h:101
Cantera::ShomatePoly::getParameters
void getParameters(AnyMap &thermo) const override
Store the parameters of the species thermo object such that an identical species thermo object could ...
Definition ShomatePoly.h:159
Cantera::ShomatePoly::updateTemperaturePoly
void updateTemperaturePoly(double T, double *T_poly) const override
Given the temperature T, compute the terms of the temperature polynomial T_poly.
Definition ShomatePoly.h:103
Cantera::ShomatePoly::ShomatePoly
ShomatePoly(double tlow, double thigh, double pref, const double *coeffs)
Constructor with all input data.
Definition ShomatePoly.h:74
Cantera::ShomatePoly::reportParameters
void reportParameters(size_t &n, int &type, double &tlow, double &thigh, double &pref, double *const coeffs) const override
This utility function returns the type of parameterization and all of the parameters for the species.
Definition ShomatePoly.h:147
Cantera::ShomatePoly::updateProperties
void updateProperties(const double *tt, double *cp_R, double *h_RT, double *s_R) const override
Update the properties for this species, given a temperature polynomial.
Definition ShomatePoly.h:125
Cantera::ShomatePoly::reportHf298
double reportHf298(double *const h298=nullptr) const override
Report the 298 K Heat of Formation of the standard state of one species (J kmol-1)
Definition ShomatePoly.h:169
Cantera::ShomatePoly::resetHf298
void resetHf298() override
Restore the original heat of formation for this species.
Definition ShomatePoly.h:181
Cantera::ShomatePoly::modifyOneHf298
void modifyOneHf298(const size_t k, const double Hf298New) override
Modify the value of the 298 K Heat of Formation of one species in the phase (J kmol-1)
Definition ShomatePoly.h:175
Cantera::ShomatePoly::updatePropertiesTemp
void updatePropertiesTemp(const double temp, double *cp_R, double *h_RT, double *s_R) const override
Compute the reference-state property of one species.
Definition ShomatePoly.h:140
Cantera::SpeciesThermoInterpType
Abstract Base class for the thermodynamic manager for an individual species' reference state.
Definition SpeciesThermoInterpType.h:113
Cantera::SpeciesThermoInterpType::m_Pref
double m_Pref
Reference state pressure.
Definition SpeciesThermoInterpType.h:288
Cantera::SpeciesThermoInterpType::setRefPressure
virtual void setRefPressure(double Pref)
Set the reference pressure [Pa].
Definition SpeciesThermoInterpType.h:153
Cantera::SpeciesThermoInterpType::getParameters
virtual void getParameters(AnyMap &thermo) const
Store the parameters of the species thermo object such that an identical species thermo object could ...
Definition SpeciesThermoInterpType.cpp:58
Cantera::SpeciesThermoInterpType::m_lowT
double m_lowT
lowest valid temperature
Definition SpeciesThermoInterpType.h:284
Cantera::SpeciesThermoInterpType::setMinTemp
virtual void setMinTemp(double Tmin)
Set the minimum temperature at which the thermo parameterization is valid.
Definition SpeciesThermoInterpType.h:132
Cantera::SpeciesThermoInterpType::m_highT
double m_highT
Highest valid temperature.
Definition SpeciesThermoInterpType.h:286
Cantera::SpeciesThermoInterpType::setMaxTemp
virtual void setMaxTemp(double Tmax)
Set the maximum temperature at which the thermo parameterization is valid.
Definition SpeciesThermoInterpType.h:143
Cantera::GasConstant
const double GasConstant
Universal Gas Constant [J/kmol/K].
Definition ct_defs.h:120
Cantera
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564
SHOMATE
#define SHOMATE
Two regions of Shomate Polynomials.
Definition speciesThermoTypes.h:27
SHOMATE2
#define SHOMATE2
Two regions of Shomate Polynomials.
Definition speciesThermoTypes.h:30