NasaPoly1.h Source File#

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