Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 // Copyright 2007 Sandia National Laboratories
14 
17 
18 using namespace std;
19 
20 namespace Cantera
21 {
22 Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion() :
23  m_numTempRegions(0),
24  m_currRegion(0)
25 {
26 }
27 
28 Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion(vector<Nasa9Poly1*>& regionPts) :
29  m_numTempRegions(0),
30  m_currRegion(0)
31 {
32  m_numTempRegions = regionPts.size();
33  // Do a shallow copy of the pointers. From now on, we will
34  // own these pointers and be responsible for deleting them.
35  m_regionPts = regionPts;
37  m_lowT = m_regionPts[0]->minTemp();
38  m_highT = m_regionPts[m_numTempRegions-1]->maxTemp();
39  m_Pref = m_regionPts[0]->refPressure();
40  m_index = m_regionPts[0]->speciesIndex();
41  for (size_t i = 0; i < m_numTempRegions; i++) {
42  m_lowerTempBounds[i] = m_regionPts[i]->minTemp();
43  if (m_regionPts[i]->speciesIndex() != m_index) {
44  throw CanteraError("Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion",
45  "m_index inconsistency");
46  }
47  if (fabs(m_regionPts[i]->refPressure() - m_Pref) > 0.0001) {
48  throw CanteraError("Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion",
49  "refPressure inconsistency");
50  }
51  if (i > 0) {
52  if (m_lowerTempBounds[i-1] >= m_lowerTempBounds[i]) {
53  throw CanteraError("Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion",
54  "minTemp bounds inconsistency");
55  }
56  if (fabs(m_regionPts[i-1]->maxTemp() - m_lowerTempBounds[i]) > 0.0001) {
57  throw CanteraError("Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion",
58  "Temp bounds inconsistency");
59  }
60  }
61  }
62 }
63 
66  m_numTempRegions(b.m_numTempRegions),
67  m_lowerTempBounds(b.m_lowerTempBounds),
68  m_currRegion(b.m_currRegion)
69 {
71  for (size_t i = 0; i < m_numTempRegions; i++) {
72  Nasa9Poly1* dptr = b.m_regionPts[i];
73  m_regionPts[i] = new Nasa9Poly1(*dptr);
74  }
75 }
76 
79 {
80  if (&b != this) {
81  SpeciesThermoInterpType::operator=(b);
82  for (size_t i = 0; i < m_numTempRegions; i++) {
83  delete m_regionPts[i];
84  m_regionPts[i] = 0;
85  }
86  m_numTempRegions = b.m_numTempRegions;
89  m_regionPts.resize(m_numTempRegions);
90  for (size_t i = 0; i < m_numTempRegions; i++) {
91  m_regionPts[i] = new Nasa9Poly1(*(b.m_regionPts[i]));
92  }
93  }
94  return *this;
95 }
96 
98 {
99  for (size_t i = 0; i < m_numTempRegions; i++) {
100  delete m_regionPts[i];
101  m_regionPts[i] = 0;
102  }
103 }
104 
106 Nasa9PolyMultiTempRegion::duplMyselfAsSpeciesThermoInterpType() const
107 {
108  return new Nasa9PolyMultiTempRegion(*this);
109 }
110 
112 {
113  return NASA9MULTITEMP;
114 }
115 
118  for (size_t i = 0; i < m_numTempRegions; i++) {
119  m_regionPts[i]->setIndex(index);
120  }
121 }
122 
123 void Nasa9PolyMultiTempRegion::updateTemperaturePoly(double T, double* T_poly) const
124 {
125  T_poly[0] = T;
126  T_poly[1] = T * T;
127  T_poly[2] = T_poly[1] * T;
128  T_poly[3] = T_poly[2] * T;
129  T_poly[4] = 1.0 / T;
130  T_poly[5] = T_poly[4] / T;
131  T_poly[6] = std::log(T);
132 }
133 
135  doublereal* cp_R,
136  doublereal* h_RT,
137  doublereal* s_R) const
138 {
139  m_currRegion = 0;
140  for (size_t i = 1; i < m_numTempRegions; i++) {
141  if (tt[0] < m_lowerTempBounds[i]) {
142  break;
143  }
144  m_currRegion++;
145  }
146 
147  m_regionPts[m_currRegion]->updateProperties(tt, cp_R, h_RT, s_R);
148 }
149 
151  doublereal* cp_R, doublereal* h_RT,
152  doublereal* s_R) const
153 {
154  // Now find the region
155  m_currRegion = 0;
156  for (size_t i = 1; i < m_numTempRegions; i++) {
157  if (temp < m_lowerTempBounds[i]) {
158  break;
159  }
160  m_currRegion++;
161  }
162 
163  m_regionPts[m_currRegion]->updatePropertiesTemp(temp, cp_R, h_RT, s_R);
164 }
165 
167  doublereal& tlow, doublereal& thigh,
168  doublereal& pref,
169  doublereal* const coeffs) const
170 {
171  n = m_index;
172  type = NASA9MULTITEMP;
173  tlow = m_lowT;
174  thigh = m_highT;
175  pref = m_Pref;
176  double ctmp[12];
177  coeffs[0] = double(m_numTempRegions);
178  int index = 1;
179  size_t n_tmp = 0;
180  int type_tmp = 0;
181  double pref_tmp = 0.0;
182  for (size_t iReg = 0; iReg < m_numTempRegions; iReg++) {
183  m_regionPts[iReg]->reportParameters(n_tmp, type_tmp,
184  coeffs[index], coeffs[index+1],
185  pref_tmp, ctmp);
186  for (int i = 0; i < 9; i++) {
187  coeffs[index+2+i] = ctmp[3+i];
188  }
189  index += 11;
190  }
191 
192 }
193 
195 {
196  int index = 3;
197  for (size_t iReg = 0; iReg < m_numTempRegions; iReg++) {
198  m_regionPts[iReg]->modifyParameters(coeffs + index);
199  index += 11;
200  }
201 }
202 
203 }
size_t m_numTempRegions
Number of temperature regions.
Pure Virtual Base class for the thermodynamic manager for an individual species' reference state...
virtual size_t speciesIndex() const
Returns an integer representing the species index.
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.
virtual int reportType() const
Returns an integer representing the type of parameterization.
virtual doublereal refPressure() const
Returns the reference pressure (Pa)
virtual doublereal maxTemp() const
Returns the maximum temperature that the thermo parameterization is valid.
#define NASA9MULTITEMP
9 coefficient NASA Polynomials in multiple temperature regions This is implemented in the class Nasa9...
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.
doublereal m_highT
Highest valid temperature.
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:99
doublereal m_lowT
lowest valid temperature
The NASA 9 polynomial parameterization for one temperature range.
Definition: Nasa9Poly1.h:71
Nasa9PolyMultiTempRegion & operator=(const Nasa9PolyMultiTempRegion &b)
Assignment operator.
doublereal m_Pref
Reference state pressure.
The NASA 9 polynomial parameterization for a single species encompassing multiple temperature regions...
virtual void modifyParameters(doublereal *coeffs)
Modify parameters for the standard state.
virtual void updatePropertiesTemp(const doublereal temp, doublereal *cp_R, doublereal *h_RT, doublereal *s_R) const
Compute the reference-state property of one species.
std::vector< Nasa9Poly1 * > m_regionPts
pointers to the objects
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
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...