Cantera  2.5.1
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 
19 
20 using namespace std;
21 
22 namespace Cantera
23 {
24 
25 Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion()
26  : m_currRegion(0)
27 {
28 }
29 
30 Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion(vector<Nasa9Poly1*>& regionPts) :
31  m_currRegion(0)
32 {
33  // From now on, we own these pointers
34  for (Nasa9Poly1* region : regionPts) {
35  m_regionPts.emplace_back(region);
36  }
37  m_lowerTempBounds.resize(regionPts.size());
38  m_lowT = m_regionPts[0]->minTemp();
39  m_highT = m_regionPts[m_regionPts.size()-1]->maxTemp();
40  m_Pref = m_regionPts[0]->refPressure();
41  for (size_t i = 0; i < m_regionPts.size(); i++) {
42  m_lowerTempBounds[i] = m_regionPts[i]->minTemp();
43  if (fabs(m_regionPts[i]->refPressure() - m_Pref) > 0.0001) {
44  throw CanteraError("Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion",
45  "refPressure inconsistency");
46  }
47  if (i > 0) {
48  if (m_lowerTempBounds[i-1] >= m_lowerTempBounds[i]) {
49  throw CanteraError("Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion",
50  "minTemp bounds inconsistency");
51  }
52  if (fabs(m_regionPts[i-1]->maxTemp() - m_lowerTempBounds[i]) > 0.0001) {
53  throw CanteraError("Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion",
54  "Temp bounds inconsistency");
55  }
56  }
57  }
58 }
59 
60 Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion(double tlow, double thigh, double pref,
61  const double* coeffs)
62  : SpeciesThermoInterpType(tlow, thigh, pref)
63 {
64  size_t regions = static_cast<size_t>(coeffs[0]);
65 
66  for (size_t i=0; i<regions; i++) {
67  Nasa9Poly1* poly = new Nasa9Poly1(coeffs[11*i+1], coeffs[11*i+2],
68  pref, coeffs + 11*i + 3);
69  m_regionPts.emplace_back(poly);
70  }
71 
72  m_lowerTempBounds.resize(regions);
73  for (size_t i = 0; i < m_regionPts.size(); i++) {
74  m_lowerTempBounds[i] = m_regionPts[i]->minTemp();
75  if (i > 0) {
76  if (m_lowerTempBounds[i-1] >= m_lowerTempBounds[i]) {
77  throw CanteraError("Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion",
78  "minTemp bounds inconsistency");
79  }
80  if (fabs(m_regionPts[i-1]->maxTemp() - m_lowerTempBounds[i]) > 0.0001) {
81  throw CanteraError("Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion",
82  "Temp bounds inconsistency");
83  }
84  }
85  }
86 }
87 
88 void Nasa9PolyMultiTempRegion::setParameters(const std::map<double, vector_fp>& regions)
89 {
90  m_regionPts.clear();
91  m_lowerTempBounds.clear();
92  for (const auto& region : regions) {
93  m_lowerTempBounds.push_back(region.first);
94  Nasa9Poly1* poly = new Nasa9Poly1;
95  poly->setRefPressure(refPressure());
96  poly->setMinTemp(region.first);
97  poly->setParameters(region.second);
98  if (!m_regionPts.empty()) {
99  m_regionPts.back()->setMaxTemp(region.first);
100  }
101  m_regionPts.emplace_back(poly);
102  }
103  m_regionPts.back()->setMaxTemp(maxTemp());
104 }
105 
106 Nasa9PolyMultiTempRegion::~Nasa9PolyMultiTempRegion()
107 {
108 }
109 
111 {
112  return NASA9MULTITEMP;
113 }
114 
115 void Nasa9PolyMultiTempRegion::updateTemperaturePoly(double T, double* T_poly) const
116 {
117  T_poly[0] = T;
118  T_poly[1] = T * T;
119  T_poly[2] = T_poly[1] * T;
120  T_poly[3] = T_poly[2] * T;
121  T_poly[4] = 1.0 / T;
122  T_poly[5] = T_poly[4] / T;
123  T_poly[6] = std::log(T);
124 }
125 
127  doublereal* cp_R,
128  doublereal* h_RT,
129  doublereal* s_R) const
130 {
131  m_currRegion = 0;
132  for (size_t i = 1; i < m_regionPts.size(); i++) {
133  if (tt[0] < m_lowerTempBounds[i]) {
134  break;
135  }
136  m_currRegion++;
137  }
138 
139  m_regionPts[m_currRegion]->updateProperties(tt, cp_R, h_RT, s_R);
140 }
141 
143  doublereal* cp_R, doublereal* h_RT,
144  doublereal* s_R) const
145 {
146  // Now find the region
147  m_currRegion = 0;
148  for (size_t i = 1; i < m_regionPts.size(); i++) {
149  if (temp < m_lowerTempBounds[i]) {
150  break;
151  }
152  m_currRegion++;
153  }
154 
155  m_regionPts[m_currRegion]->updatePropertiesTemp(temp, cp_R, h_RT, s_R);
156 }
157 
159 {
160  return 11*m_regionPts.size() + 1;
161 }
162 
164  doublereal& tlow, doublereal& thigh,
165  doublereal& pref,
166  doublereal* const coeffs) const
167 {
168  n = 0;
169  type = NASA9MULTITEMP;
170  tlow = m_lowT;
171  thigh = m_highT;
172  pref = m_Pref;
173  double ctmp[12];
174  coeffs[0] = double(m_regionPts.size());
175  int index = 1;
176  size_t n_tmp = 0;
177  int type_tmp = 0;
178  double pref_tmp = 0.0;
179  for (size_t iReg = 0; iReg < m_regionPts.size(); iReg++) {
180  m_regionPts[iReg]->reportParameters(n_tmp, type_tmp,
181  coeffs[index], coeffs[index+1],
182  pref_tmp, ctmp);
183  for (int i = 0; i < 9; i++) {
184  coeffs[index+2+i] = ctmp[3+i];
185  }
186  index += 11;
187  }
188 }
189 
190 }
Header for a single-species standard state object derived from SpeciesThermoInterpType based on the N...
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:61
The NASA 9 polynomial parameterization for one temperature range.
Definition: Nasa9Poly1.h:62
void setParameters(const vector_fp &coeffs)
Set the array of 9 polynomial coefficients.
Definition: Nasa9Poly1.cpp:32
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 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)
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.cpp:264
#define NASA9MULTITEMP
9 coefficient NASA Polynomials in multiple temperature regions This is implemented in the class Nasa9...