Cantera  2.5.1
NasaPoly1.h
Go to the documentation of this file.
1 /**
2  * @file NasaPoly1.h
3  * Header for a single-species standard state object derived
4  * from \link Cantera::SpeciesThermoInterpType SpeciesThermoInterpType\endlink based
5  * on the NASA temperature polynomial form applied to one temperature region
6  * (see \ref spthermo and class \link Cantera::NasaPoly1 NasaPoly1\endlink).
7  *
8  * This parameterization has one NASA temperature region.
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_NASAPOLY1_H
15 #define CT_NASAPOLY1_H
16 
18 
19 namespace Cantera
20 {
21 /**
22  * The NASA polynomial parameterization for one temperature range. This
23  * parameterization expresses the heat capacity as a fourth-order polynomial.
24  * Note that this is the form used in the 1971 NASA equilibrium program and by
25  * the Chemkin software package, but differs from the form used in the more
26  * recent NASA equilibrium program.
27  *
28  * Seven coefficients \f$(a_0,\dots,a_6)\f$ are used to represent
29  * \f$ c_p^0(T)\f$, \f$ h^0(T)\f$, and \f$ s^0(T) \f$ as
30  * polynomials in \f$ T \f$ :
31  * \f[
32  * \frac{c_p(T)}{R} = a_0 + a_1 T + a_2 T^2 + a_3 T^3 + a_4 T^4
33  * \f]
34  * \f[
35  * \frac{h^0(T)}{RT} = a_0 + \frac{a_1}{2} T + \frac{a_2}{3} T^2
36  * + \frac{a_3}{4} T^3 + \frac{a_4}{5} T^4 + \frac{a_5}{T}.
37  * \f]
38  * \f[
39  * \frac{s^0(T)}{R} = a_0\ln T + a_1 T + \frac{a_2}{2} T^2
40  * + \frac{a_3}{3} T^3 + \frac{a_4}{4} T^4 + a_6.
41  * \f]
42  *
43  * @ingroup spthermo
44  */
46 {
47 public:
48  NasaPoly1() : m_coeff(7), m_coeff5_orig(0.0) {}
49 
50  //! Constructor with all input data
51  /*!
52  * @param tlow Minimum temperature
53  * @param thigh Maximum temperature
54  * @param pref reference pressure (Pa).
55  * @param coeffs Vector of coefficients used to set the parameters for the
56  * standard state, in the order [a0,a1,a2,a3,a4,a5,a6]
57  */
58  NasaPoly1(double tlow, double thigh, double pref, const double* coeffs)
59  : SpeciesThermoInterpType(tlow, thigh, pref)
60  , m_coeff(coeffs, coeffs+7)
61  {
62  m_coeff5_orig = m_coeff[5];
63  }
64 
65  //! Set array of 7 polynomial coefficients
66  void setParameters(const vector_fp& coeffs) {
67  if (coeffs.size() != 7) {
68  throw CanteraError("NasaPoly1::setParameters", "Array must contain "
69  "7 coefficients, but {} were given.", coeffs.size());
70  }
71  m_coeff = coeffs;
72  m_coeff5_orig = m_coeff[5];
73  }
74 
75  virtual int reportType() const {
76  return NASA1;
77  }
78 
79  virtual size_t temperaturePolySize() const { return 6; }
80 
81  virtual void updateTemperaturePoly(double T, double* T_poly) const {
82  T_poly[0] = T;
83  T_poly[1] = T * T;
84  T_poly[2] = T_poly[1] * T;
85  T_poly[3] = T_poly[2] * T;
86  T_poly[4] = 1.0 / T;
87  T_poly[5] = std::log(T);
88  }
89 
90  /*!
91  * @copydoc SpeciesThermoInterpType::updateProperties
92  *
93  * Temperature Polynomial:
94  * tt[0] = t;
95  * tt[1] = t*t;
96  * tt[2] = m_t[1]*t;
97  * tt[3] = m_t[2]*t;
98  * tt[4] = 1.0/t;
99  * tt[5] = std::log(t);
100  */
101  virtual void updateProperties(const doublereal* tt,
102  doublereal* cp_R, doublereal* h_RT, doublereal* s_R) const {
103  doublereal ct0 = m_coeff[0]; // a0
104  doublereal ct1 = m_coeff[1]*tt[0]; // a1 * T
105  doublereal ct2 = m_coeff[2]*tt[1]; // a2 * T^2
106  doublereal ct3 = m_coeff[3]*tt[2]; // a3 * T^3
107  doublereal ct4 = m_coeff[4]*tt[3]; // a4 * T^4
108 
109  doublereal cp, h, s;
110  cp = ct0 + ct1 + ct2 + ct3 + ct4;
111  h = ct0 + 0.5*ct1 + 1.0/3.0*ct2 + 0.25*ct3 + 0.2*ct4
112  + m_coeff[5]*tt[4]; // last term is a5/T
113  s = ct0*tt[5] + ct1 + 0.5*ct2 + 1.0/3.0*ct3
114  +0.25*ct4 + m_coeff[6]; // last term is a6
115 
116  // return the computed properties for this species
117  *cp_R = cp;
118  *h_RT = h;
119  *s_R = s;
120  }
121 
122  virtual void updatePropertiesTemp(const doublereal temp,
123  doublereal* cp_R, doublereal* h_RT,
124  doublereal* s_R) const {
125  double tPoly[6];
126  updateTemperaturePoly(temp, tPoly);
127  updateProperties(tPoly, cp_R, h_RT, s_R);
128  }
129 
130  virtual void reportParameters(size_t& n, int& type,
131  doublereal& tlow, doublereal& thigh,
132  doublereal& pref,
133  doublereal* const coeffs) const {
134  n = 0;
135  type = NASA1;
136  tlow = m_lowT;
137  thigh = m_highT;
138  pref = m_Pref;
139  std::copy(m_coeff.begin(), m_coeff.end(), coeffs);
140  }
141 
142  virtual doublereal reportHf298(doublereal* const h298 = 0) const {
143  double tt[6];
144  double temp = 298.15;
145  updateTemperaturePoly(temp, tt);
146  doublereal ct0 = m_coeff[0]; // a0
147  doublereal ct1 = m_coeff[1]*tt[0]; // a1 * T
148  doublereal ct2 = m_coeff[2]*tt[1]; // a2 * T^2
149  doublereal ct3 = m_coeff[3]*tt[2]; // a3 * T^3
150  doublereal ct4 = m_coeff[4]*tt[3]; // a4 * T^4
151 
152  double h_RT = ct0 + 0.5*ct1 + 1.0/3.0*ct2 + 0.25*ct3 + 0.2*ct4
153  + m_coeff[5]*tt[4]; // last t
154 
155  double h = h_RT * GasConstant * temp;
156  if (h298) {
157  *h298 = h;
158  }
159  return h;
160  }
161 
162  virtual void modifyOneHf298(const size_t k, const doublereal Hf298New) {
163  double hcurr = reportHf298(0);
164  double delH = Hf298New - hcurr;
165  m_coeff[5] += (delH) / GasConstant;
166  }
167 
168  virtual void resetHf298() {
169  m_coeff[5] = m_coeff5_orig;
170  }
171 
172 protected:
173  //! array of polynomial coefficients, stored in the order [a0, ..., a6]
175 
176  double m_coeff5_orig;
177 };
178 
179 }
180 #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 NASA polynomial parameterization for one temperature range.
Definition: NasaPoly1.h:46
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: NasaPoly1.h:122
vector_fp m_coeff
array of polynomial coefficients, stored in the order [a0, ..., a6]
Definition: NasaPoly1.h:174
virtual void updateTemperaturePoly(double T, double *T_poly) const
Given the temperature T, compute the terms of the temperature polynomial T_poly.
Definition: NasaPoly1.h:81
void setParameters(const vector_fp &coeffs)
Set array of 7 polynomial coefficients.
Definition: NasaPoly1.h:66
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: NasaPoly1.h:101
virtual void resetHf298()
Restore the original heat of formation for this species.
Definition: NasaPoly1.h:168
NasaPoly1(double tlow, double thigh, double pref, const double *coeffs)
Constructor with all input data.
Definition: NasaPoly1.h:58
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: NasaPoly1.h:130
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: NasaPoly1.h:162
virtual size_t temperaturePolySize() const
Number of terms in the temperature polynomial for this parameterization.
Definition: NasaPoly1.h:79
virtual int reportType() const
Returns an integer representing the type of parameterization.
Definition: NasaPoly1.h:75
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: NasaPoly1.h:142
Abstract Base class for the thermodynamic manager for an individual species' reference state.
doublereal m_lowT
lowest valid temperature
doublereal m_highT
Highest valid temperature.
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 NASA1
7 coefficient NASA Polynomials This is implemented in the class NasaPoly1 in NasaPoly1....