Nasa9PolyMultiTempRegion.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "global.h"
00021 #include "ctexceptions.h"
00022 #include "Nasa9PolyMultiTempRegion.h"
00023
00024 using namespace std;
00025
00026 namespace Cantera {
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion() :
00078 m_lowT(0.0),
00079 m_highT (0.0),
00080 m_Pref(0.0),
00081 m_index (0),
00082 m_numTempRegions(0),
00083 m_currRegion(0)
00084 {
00085 }
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097 Nasa9PolyMultiTempRegion::
00098 Nasa9PolyMultiTempRegion(std::vector<Cantera::Nasa9Poly1 *> ®ionPts) :
00099 m_lowT(0.0),
00100 m_highT (0.0),
00101 m_Pref(0.0),
00102 m_index(0),
00103 m_numTempRegions(0),
00104 m_currRegion(0)
00105 {
00106 m_numTempRegions = regionPts.size();
00107
00108
00109 m_regionPts = regionPts;
00110 m_lowerTempBounds.resize(m_numTempRegions);
00111 m_lowT = m_regionPts[0]->minTemp();
00112 m_highT = m_regionPts[m_numTempRegions-1]->maxTemp();
00113 m_Pref = m_regionPts[0]->refPressure();
00114 m_index = m_regionPts[0]->speciesIndex();
00115 for (int i = 0; i < m_numTempRegions; i++) {
00116 m_lowerTempBounds[i] = m_regionPts[i]->minTemp();
00117 if (m_regionPts[i]->speciesIndex() != m_index) {
00118 throw CanteraError("Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion",
00119 "m_index inconsistency");
00120 }
00121 if (fabs(m_regionPts[i]->refPressure() - m_Pref) > 0.0001) {
00122 throw CanteraError("Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion",
00123 "refPressure inconsistency");
00124 }
00125 if (i > 0) {
00126 if (m_lowerTempBounds[i-1] >= m_lowerTempBounds[i]) {
00127 throw CanteraError("Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion",
00128 "minTemp bounds inconsistency");
00129 }
00130 if (fabs(m_regionPts[i-1]->maxTemp() - m_lowerTempBounds[i]) > 0.0001) {
00131 throw CanteraError("Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion",
00132 "Temp bounds inconsistency");
00133 }
00134 }
00135 }
00136 }
00137
00138
00139
00140
00141
00142 Nasa9PolyMultiTempRegion::
00143 Nasa9PolyMultiTempRegion(const Nasa9PolyMultiTempRegion& b) :
00144 m_lowT (b.m_lowT),
00145 m_highT (b.m_highT),
00146 m_Pref (b.m_Pref),
00147 m_index (b.m_index),
00148 m_numTempRegions(b.m_numTempRegions),
00149 m_lowerTempBounds (b.m_lowerTempBounds),
00150 m_currRegion(b.m_currRegion)
00151 {
00152 m_regionPts.resize(m_numTempRegions);
00153 for (int i = 0; i < m_numTempRegions; i++) {
00154 Nasa9Poly1 * dptr = b.m_regionPts[i];
00155 m_regionPts[i] = new Nasa9Poly1(*dptr);
00156 }
00157 }
00158
00159
00160
00161
00162
00163 Nasa9PolyMultiTempRegion&
00164 Nasa9PolyMultiTempRegion::operator=(const Nasa9PolyMultiTempRegion& b) {
00165 if (&b != this) {
00166 for (int i = 0; i < m_numTempRegions; i++) {
00167 delete m_regionPts[i];
00168 m_regionPts[i] = 0;
00169 }
00170 m_lowT = b.m_lowT;
00171 m_highT = b.m_highT;
00172 m_Pref = b.m_Pref;
00173 m_index = b.m_index;
00174 m_numTempRegions = b.m_numTempRegions;
00175 m_lowerTempBounds = b.m_lowerTempBounds;
00176 m_currRegion = b.m_currRegion;
00177 m_regionPts.resize(m_numTempRegions);
00178 for (int i = 0; i < m_numTempRegions; i++) {
00179 m_regionPts[i] = new Nasa9Poly1(*(b.m_regionPts[i]));
00180 }
00181 }
00182 return *this;
00183 }
00184
00185
00186 Nasa9PolyMultiTempRegion::~Nasa9PolyMultiTempRegion() {
00187 for (int i = 0; i < m_numTempRegions; i++) {
00188 delete m_regionPts[i];
00189 m_regionPts[i] = 0;
00190 }
00191 }
00192
00193
00194 SpeciesThermoInterpType *
00195 Nasa9PolyMultiTempRegion::duplMyselfAsSpeciesThermoInterpType() const {
00196 Nasa9PolyMultiTempRegion* np = new Nasa9PolyMultiTempRegion(*this);
00197 return (SpeciesThermoInterpType *) np;
00198 }
00199
00200
00201
00202 doublereal Nasa9PolyMultiTempRegion::minTemp() const {
00203 return m_lowT;
00204 }
00205
00206
00207
00208 doublereal Nasa9PolyMultiTempRegion::maxTemp() const {
00209 return m_highT;
00210 }
00211
00212
00213 doublereal Nasa9PolyMultiTempRegion::refPressure() const {
00214 return m_Pref;
00215 }
00216
00217
00218 int Nasa9PolyMultiTempRegion::reportType() const {
00219 return NASA9MULTITEMP;
00220 }
00221
00222
00223
00224 int Nasa9PolyMultiTempRegion::speciesIndex() const {
00225 return m_index;
00226 }
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253 void Nasa9PolyMultiTempRegion::updateProperties(const doublereal* tt,
00254 doublereal* cp_R,
00255 doublereal* h_RT,
00256 doublereal* s_R) const {
00257
00258
00259 #ifdef DEBUG_HKM
00260 double temp = tt[0];
00261 if (temp < m_regionPts[m_currRegion]->minTemp() ) {
00262 if (m_currRegion != 0) {
00263 throw CanteraError("Nasa9PolyMultiTempRegion::updateProperties",
00264 "region problem");
00265 }
00266 }
00267 if (temp > m_regionPts[m_currRegion]->maxTemp() ) {
00268 if (m_currRegion != m_numTempRegions - 1) {
00269 throw CanteraError("Nasa9PolyMultiTempRegion::updateProperties",
00270 "region problem");
00271 }
00272 }
00273 #endif
00274 (m_regionPts[m_currRegion])->updateProperties(tt, cp_R, h_RT, s_R);
00275 }
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303 void Nasa9PolyMultiTempRegion::updatePropertiesTemp(const doublereal temp,
00304 doublereal* cp_R, doublereal* h_RT,
00305 doublereal* s_R) const {
00306 double tPoly[7];
00307 tPoly[0] = temp;
00308 tPoly[1] = temp * temp;
00309 tPoly[2] = tPoly[1] * temp;
00310 tPoly[3] = tPoly[2] * temp;
00311 tPoly[4] = 1.0 / temp;
00312 tPoly[5] = tPoly[4] / temp;
00313 tPoly[6] = std::log(temp);
00314
00315 m_currRegion = 0;
00316 for (int i = 1; i < m_numTempRegions; i++) {
00317 if (temp < m_lowerTempBounds[i]) {
00318 break;
00319 }
00320 m_currRegion++;
00321 }
00322
00323 updateProperties(tPoly, cp_R, h_RT, s_R);
00324 }
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340 void Nasa9PolyMultiTempRegion::reportParameters(int &n, int &type,
00341 doublereal &tlow, doublereal &thigh,
00342 doublereal &pref,
00343 doublereal* const coeffs) const {
00344 n = m_index;
00345 type = NASA9MULTITEMP;
00346 tlow = m_lowT;
00347 thigh = m_highT;
00348 pref = m_Pref;
00349 double ctmp[12];
00350 coeffs[0] = m_numTempRegions;
00351 int index = 1;
00352 int n_tmp = 0;;
00353 int type_tmp = 0;
00354 double pref_tmp = 0.0;
00355 for (int iReg = 0; iReg < m_numTempRegions; iReg++) {
00356 m_regionPts[iReg]->reportParameters(n_tmp, type_tmp,
00357 coeffs[index], coeffs[index+1],
00358 pref_tmp, ctmp);
00359 for (int i = 0; i < 9; i++) {
00360 coeffs[index+2+i] = ctmp[3+i];
00361 }
00362 index += 11;
00363 }
00364
00365 }
00366
00367
00368
00369
00370
00371
00372 void Nasa9PolyMultiTempRegion::modifyParameters(doublereal* coeffs) {
00373 int index = 3;
00374 for (int iReg = 0; iReg < m_numTempRegions; iReg++) {
00375 m_regionPts[iReg]->modifyParameters(coeffs + index);
00376 index += 11;
00377 }
00378 }
00379
00380
00381 }
00382