Cantera  2.3.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 http://www.cantera.org/license.txt for license and copyright information.
16 
19 
20 using namespace std;
21 
22 namespace Cantera
23 {
24 Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion() :
25  m_currRegion(0)
26 {
27  warn_deprecated("Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion()",
28  "Default constructor to be removed after Cantera 2.3.");
29 }
30 
31 Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion(vector<Nasa9Poly1*>& regionPts) :
32  m_currRegion(0)
33 {
34  // From now on, we own these pointers
35  for (Nasa9Poly1* region : regionPts) {
36  m_regionPts.emplace_back(region);
37  }
38  m_lowerTempBounds.resize(regionPts.size());
39  m_lowT = m_regionPts[0]->minTemp();
40  m_highT = m_regionPts[m_regionPts.size()-1]->maxTemp();
41  m_Pref = m_regionPts[0]->refPressure();
42  for (size_t i = 0; i < m_regionPts.size(); i++) {
43  m_lowerTempBounds[i] = m_regionPts[i]->minTemp();
44  if (fabs(m_regionPts[i]->refPressure() - m_Pref) > 0.0001) {
45  throw CanteraError("Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion",
46  "refPressure inconsistency");
47  }
48  if (i > 0) {
49  if (m_lowerTempBounds[i-1] >= m_lowerTempBounds[i]) {
50  throw CanteraError("Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion",
51  "minTemp bounds inconsistency");
52  }
53  if (fabs(m_regionPts[i-1]->maxTemp() - m_lowerTempBounds[i]) > 0.0001) {
54  throw CanteraError("Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion",
55  "Temp bounds inconsistency");
56  }
57  }
58  }
59 }
60 
63  m_lowerTempBounds(b.m_lowerTempBounds),
64  m_currRegion(b.m_currRegion)
65 {
66  m_regionPts.resize(b.m_regionPts.size());
67  for (size_t i = 0; i < m_regionPts.size(); i++) {
68  m_regionPts[i].reset(new Nasa9Poly1(*b.m_regionPts[i]));
69  }
70 }
71 
72 Nasa9PolyMultiTempRegion&
73 Nasa9PolyMultiTempRegion::operator=(const Nasa9PolyMultiTempRegion& b)
74 {
75  if (&b != this) {
77  m_lowerTempBounds = b.m_lowerTempBounds;
78  m_currRegion = b.m_currRegion;
79  m_regionPts.resize(b.m_regionPts.size());
80  for (size_t i = 0; i < m_regionPts.size(); i++) {
81  m_regionPts[i].reset(new Nasa9Poly1(*b.m_regionPts[i]));
82  }
83  }
84  return *this;
85 }
86 
87 Nasa9PolyMultiTempRegion::~Nasa9PolyMultiTempRegion()
88 {
89 }
90 
91 SpeciesThermoInterpType*
93 {
94  return new Nasa9PolyMultiTempRegion(*this);
95 }
96 
98 {
99  return NASA9MULTITEMP;
100 }
101 
102 void Nasa9PolyMultiTempRegion::updateTemperaturePoly(double T, double* T_poly) const
103 {
104  T_poly[0] = T;
105  T_poly[1] = T * T;
106  T_poly[2] = T_poly[1] * T;
107  T_poly[3] = T_poly[2] * T;
108  T_poly[4] = 1.0 / T;
109  T_poly[5] = T_poly[4] / T;
110  T_poly[6] = std::log(T);
111 }
112 
114  doublereal* cp_R,
115  doublereal* h_RT,
116  doublereal* s_R) const
117 {
118  m_currRegion = 0;
119  for (size_t i = 1; i < m_regionPts.size(); i++) {
120  if (tt[0] < m_lowerTempBounds[i]) {
121  break;
122  }
123  m_currRegion++;
124  }
125 
126  m_regionPts[m_currRegion]->updateProperties(tt, cp_R, h_RT, s_R);
127 }
128 
130  doublereal* cp_R, doublereal* h_RT,
131  doublereal* s_R) const
132 {
133  // Now find the region
134  m_currRegion = 0;
135  for (size_t i = 1; i < m_regionPts.size(); i++) {
136  if (temp < m_lowerTempBounds[i]) {
137  break;
138  }
139  m_currRegion++;
140  }
141 
142  m_regionPts[m_currRegion]->updatePropertiesTemp(temp, cp_R, h_RT, s_R);
143 }
144 
146  doublereal& tlow, doublereal& thigh,
147  doublereal& pref,
148  doublereal* const coeffs) const
149 {
150  n = 0;
151  type = NASA9MULTITEMP;
152  tlow = m_lowT;
153  thigh = m_highT;
154  pref = m_Pref;
155  double ctmp[12];
156  coeffs[0] = double(m_regionPts.size());
157  int index = 1;
158  size_t n_tmp = 0;
159  int type_tmp = 0;
160  double pref_tmp = 0.0;
161  for (size_t iReg = 0; iReg < m_regionPts.size(); iReg++) {
162  m_regionPts[iReg]->reportParameters(n_tmp, type_tmp,
163  coeffs[index], coeffs[index+1],
164  pref_tmp, ctmp);
165  for (int i = 0; i < 9; i++) {
166  coeffs[index+2+i] = ctmp[3+i];
167  }
168  index += 11;
169  }
170 }
171 
173 {
174  warn_deprecated("Nasa9PolyMultiTempRegion::modifyParameters", "To be "
175  "removed after Cantera 2.3. Use MultiSpeciesThermo::modifySpecies instead.");
176  int index = 3;
177  for (size_t iReg = 0; iReg < m_regionPts.size(); iReg++) {
178  m_regionPts[iReg]->modifyParameters(coeffs + index);
179  index += 11;
180  }
181 }
182 
183 }
virtual void updatePropertiesTemp(const doublereal temp, doublereal *cp_R, doublereal *h_RT, doublereal *s_R) const
Compute the reference-state property of one species.
Abstract Base class for the thermodynamic manager for an individual species&#39; reference state...
virtual int reportType() const
Returns an integer representing the type of parameterization.
Header for a single-species standard state object derived from SpeciesThermoInterpType based on the N...
vector_fp m_lowerTempBounds
Lower boundaries of each temperature regions.
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Definition: global.cpp:54
STL namespace.
virtual SpeciesThermoInterpType * duplMyselfAsSpeciesThermoInterpType() const
#define NASA9MULTITEMP
9 coefficient NASA Polynomials in multiple temperature regions This is implemented in the class Nasa9...
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.
doublereal m_highT
Highest valid temperature.
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:65
doublereal m_lowT
lowest valid temperature
virtual doublereal refPressure() const
Returns the reference pressure (Pa)
virtual void updateTemperaturePoly(double T, double *T_poly) const
Given the temperature T, compute the terms of the temperature polynomial T_poly.
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...
The NASA 9 polynomial parameterization for one temperature range.
Definition: Nasa9Poly1.h:61
virtual doublereal maxTemp() const
Returns the maximum temperature that the thermo parameterization is valid.
doublereal m_Pref
Reference state pressure.
Namespace for the Cantera kernel.
Definition: application.cpp:29
The NASA 9 polynomial parameterization for a single species encompassing multiple temperature regions...
virtual void modifyParameters(doublereal *coeffs)
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
std::vector< std::unique_ptr< Nasa9Poly1 > > m_regionPts
Individual temperature region objects.
SpeciesThermoInterpType & operator=(const SpeciesThermoInterpType &b)