Cantera 2.6.0
Nasa9PolyMultiTempRegion.cpp
Go to the documentation of this file.
1/**
2 * @file Nasa9PolyMultiTempRegion.cpp
3 * Definitions for a single-species standard state object derived
4 * from \link Cantera::SpeciesThermoInterpType
5 * SpeciesThermoInterpType\endlink based
6 * on the NASA 9 coefficient temperature polynomial form
7 * applied to one temperature region
8 * (see \ref spthermo and class
9 * \link Cantera::Nasa9Poly1 Nasa9Poly1\endlink).
10 *
11 * This parameterization has one NASA temperature region.
12 */
13
14// This file is part of Cantera. See License.txt in the top-level directory or
15// at https://cantera.org/license.txt for license and copyright information.
16
20#include "cantera/base/AnyMap.h"
21
22using namespace std;
23
24namespace Cantera
25{
26
27Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion()
28 : m_currRegion(0)
29{
30}
31
32Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion(vector<Nasa9Poly1*>& regionPts) :
33 m_currRegion(0)
34{
35 // From now on, we own these pointers
36 for (Nasa9Poly1* region : regionPts) {
37 m_regionPts.emplace_back(region);
38 }
39 m_lowerTempBounds.resize(regionPts.size());
40 m_lowT = m_regionPts[0]->minTemp();
41 m_highT = m_regionPts[m_regionPts.size()-1]->maxTemp();
42 m_Pref = m_regionPts[0]->refPressure();
43 for (size_t i = 0; i < m_regionPts.size(); i++) {
44 m_lowerTempBounds[i] = m_regionPts[i]->minTemp();
45 if (fabs(m_regionPts[i]->refPressure() - m_Pref) > 0.0001) {
46 throw CanteraError("Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion",
47 "refPressure inconsistency");
48 }
49 if (i > 0) {
50 if (m_lowerTempBounds[i-1] >= m_lowerTempBounds[i]) {
51 throw CanteraError("Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion",
52 "minTemp bounds inconsistency");
53 }
54 if (fabs(m_regionPts[i-1]->maxTemp() - m_lowerTempBounds[i]) > 0.0001) {
55 throw CanteraError("Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion",
56 "Temp bounds inconsistency");
57 }
58 }
59 }
60}
61
62Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion(double tlow, double thigh, double pref,
63 const double* coeffs)
64 : SpeciesThermoInterpType(tlow, thigh, pref)
65{
66 size_t regions = static_cast<size_t>(coeffs[0]);
67
68 for (size_t i=0; i<regions; i++) {
69 Nasa9Poly1* poly = new Nasa9Poly1(coeffs[11*i+1], coeffs[11*i+2],
70 pref, coeffs + 11*i + 3);
71 m_regionPts.emplace_back(poly);
72 }
73
74 m_lowerTempBounds.resize(regions);
75 for (size_t i = 0; i < m_regionPts.size(); i++) {
76 m_lowerTempBounds[i] = m_regionPts[i]->minTemp();
77 if (i > 0) {
78 if (m_lowerTempBounds[i-1] >= m_lowerTempBounds[i]) {
79 throw CanteraError("Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion",
80 "minTemp bounds inconsistency");
81 }
82 if (fabs(m_regionPts[i-1]->maxTemp() - m_lowerTempBounds[i]) > 0.0001) {
83 throw CanteraError("Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion",
84 "Temp bounds inconsistency");
85 }
86 }
87 }
88}
89
90void Nasa9PolyMultiTempRegion::setParameters(const std::map<double, vector_fp>& regions)
91{
92 m_regionPts.clear();
93 m_lowerTempBounds.clear();
94 for (const auto& region : regions) {
95 m_lowerTempBounds.push_back(region.first);
96 Nasa9Poly1* poly = new Nasa9Poly1;
98 poly->setMinTemp(region.first);
99 poly->setParameters(region.second);
100 if (!m_regionPts.empty()) {
101 m_regionPts.back()->setMaxTemp(region.first);
102 }
103 m_regionPts.emplace_back(poly);
104 }
105 m_regionPts.back()->setMaxTemp(maxTemp());
106}
107
108Nasa9PolyMultiTempRegion::~Nasa9PolyMultiTempRegion()
109{
110}
111
113{
114 return NASA9MULTITEMP;
115}
116
117void Nasa9PolyMultiTempRegion::updateTemperaturePoly(double T, double* T_poly) const
118{
119 T_poly[0] = T;
120 T_poly[1] = T * T;
121 T_poly[2] = T_poly[1] * T;
122 T_poly[3] = T_poly[2] * T;
123 T_poly[4] = 1.0 / T;
124 T_poly[5] = T_poly[4] / T;
125 T_poly[6] = std::log(T);
126}
127
129 doublereal* cp_R,
130 doublereal* h_RT,
131 doublereal* s_R) const
132{
133 m_currRegion = 0;
134 for (size_t i = 1; i < m_regionPts.size(); i++) {
135 if (tt[0] < m_lowerTempBounds[i]) {
136 break;
137 }
138 m_currRegion++;
139 }
140
141 m_regionPts[m_currRegion]->updateProperties(tt, cp_R, h_RT, s_R);
142}
143
145 doublereal* cp_R, doublereal* h_RT,
146 doublereal* s_R) const
147{
148 // Now find the region
149 m_currRegion = 0;
150 for (size_t i = 1; i < m_regionPts.size(); i++) {
151 if (temp < m_lowerTempBounds[i]) {
152 break;
153 }
154 m_currRegion++;
155 }
156
157 m_regionPts[m_currRegion]->updatePropertiesTemp(temp, cp_R, h_RT, s_R);
158}
159
161{
162 return 11*m_regionPts.size() + 1;
163}
164
166 doublereal& tlow, doublereal& thigh,
167 doublereal& pref,
168 doublereal* const coeffs) const
169{
170 n = 0;
171 type = NASA9MULTITEMP;
172 tlow = m_lowT;
173 thigh = m_highT;
174 pref = m_Pref;
175 double ctmp[12];
176 coeffs[0] = double(m_regionPts.size());
177 int index = 1;
178 size_t n_tmp = 0;
179 int type_tmp = 0;
180 double pref_tmp = 0.0;
181 for (size_t iReg = 0; iReg < m_regionPts.size(); iReg++) {
182 m_regionPts[iReg]->reportParameters(n_tmp, type_tmp,
183 coeffs[index], coeffs[index+1],
184 pref_tmp, ctmp);
185 for (int i = 0; i < 9; i++) {
186 coeffs[index+2+i] = ctmp[3+i];
187 }
188 index += 11;
189 }
190}
191
193{
194 thermo["model"] = "NASA9";
196 auto T_ranges = m_lowerTempBounds;
197 T_ranges.push_back(m_highT);
198 thermo["temperature-ranges"].setQuantity(T_ranges, "K");
199 thermo["data"] = std::vector<vector_fp>();
200 for (const auto& region : m_regionPts) {
201 region->getParameters(thermo);
202 }
203}
204
205}
Header for a single-species standard state object derived from SpeciesThermoInterpType based on the N...
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 NASA 9 polynomial parameterization for one temperature range.
Definition: Nasa9Poly1.h:63
void setParameters(const vector_fp &coeffs)
Set the array of 9 polynomial coefficients.
Definition: Nasa9Poly1.cpp:33
virtual int reportType() const
Returns an integer representing the type of parameterization.
vector_fp m_lowerTempBounds
Lower boundaries of each temperature regions.
void setParameters(const std::map< double, vector_fp > &regions)
Set the array of polynomial coefficients for each temperature region.
virtual void getParameters(AnyMap &thermo) const
Store the parameters of the species thermo object such that an identical species thermo object could ...
virtual void updatePropertiesTemp(const doublereal temp, doublereal *cp_R, doublereal *h_RT, doublereal *s_R) const
Compute the reference-state property of one species.
virtual size_t nCoeffs() const
This utility function returns the number of coefficients for a given type of species parameterization...
virtual void reportParameters(size_t &n, int &type, doublereal &tlow, doublereal &thigh, doublereal &pref, doublereal *const coeffs) const
This utility function reports back the type of parameterization and all of the parameters for the spe...
std::vector< std::unique_ptr< Nasa9Poly1 > > m_regionPts
Individual temperature region objects.
virtual void updateTemperaturePoly(double T, double *T_poly) const
Given the temperature T, compute the terms of the temperature polynomial T_poly.
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.
Abstract Base class for the thermodynamic manager for an individual species' reference state.
virtual doublereal maxTemp() const
Returns the maximum temperature that the thermo parameterization is valid.
virtual void setRefPressure(double Pref)
Set the reference pressure [Pa].
virtual doublereal refPressure() const
Returns 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.
doublereal m_Pref
Reference state pressure.
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
Namespace for the Cantera kernel.
Definition: AnyMap.h:29
Contains const definitions for types of species reference-state thermodynamics managers (see Species ...
#define NASA9MULTITEMP
9 coefficient NASA Polynomials in multiple temperature regions This is implemented in the class Nasa9...