00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef CT_SHOMATETHERMO_H
00015 #define CT_SHOMATETHERMO_H
00016
00017 #include "SpeciesThermoMgr.h"
00018 #include "ShomatePoly.h"
00019 #include "speciesThermoTypes.h"
00020
00021 namespace Cantera {
00022
00023
00024
00025
00026
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 class ShomateThermo : public SpeciesThermo {
00065
00066 public:
00067
00068
00069
00070
00071
00072 const int ID;
00073
00074
00075 ShomateThermo() :
00076 ID(SHOMATE),
00077 m_tlow_max(0.0),
00078 m_thigh_min(1.e30),
00079 m_p0(-1.0),
00080 m_ngroups(0)
00081 { m_t.resize(7); }
00082
00083
00084 virtual ~ShomateThermo() {}
00085
00086
00087
00088
00089
00090 ShomateThermo(const ShomateThermo &right) :
00091 ID(SHOMATE),
00092 m_tlow_max(0.0),
00093 m_thigh_min(1.e30),
00094 m_p0(-1.0),
00095 m_ngroups(0)
00096 {
00097 *this = operator=(right);
00098 }
00099
00100
00101
00102
00103
00104 ShomateThermo& operator=(const ShomateThermo &right) {
00105 if (&right == this) return *this;
00106
00107 m_high = right.m_high;
00108 m_low = right.m_low;
00109 m_index = right.m_index;
00110 m_tmid = right.m_tmid;
00111 m_tlow_max = right.m_tlow_max;
00112 m_thigh_min = right.m_thigh_min;
00113 m_tlow = right.m_tlow;
00114 m_thigh = right.m_thigh;
00115 m_p0 = right.m_p0;
00116 m_ngroups = right.m_ngroups;
00117 m_t = right.m_t;
00118 m_group_map = right.m_group_map;
00119 m_posInGroup_map = right.m_posInGroup_map;
00120
00121 return *this;
00122 }
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134 virtual SpeciesThermo *duplMyselfAsSpeciesThermo() const {
00135 ShomateThermo *st = new ShomateThermo(*this);
00136 return (SpeciesThermo *) st;
00137 }
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165 virtual void install(string name, int index, int type,
00166 const doublereal* c,
00167 doublereal minTemp, doublereal maxTemp,
00168 doublereal refPressure) {
00169 int imid = int(c[0]);
00170 int igrp = m_index[imid];
00171 if (igrp == 0) {
00172 vector<ShomatePoly> v;
00173 m_high.push_back(v);
00174 m_low.push_back(v);
00175 m_tmid.push_back(c[0]);
00176 m_index[imid] = igrp = static_cast<int>(m_high.size());
00177 m_ngroups++;
00178 }
00179 m_group_map[index] = igrp;
00180 m_posInGroup_map[index] = (int) m_low[igrp-1].size();
00181 doublereal tlow = minTemp;
00182 doublereal tmid = c[0];
00183 doublereal thigh = maxTemp;
00184
00185 const doublereal* clow = c + 1;
00186 const doublereal* chigh = c + 8;
00187 m_high[igrp-1].push_back(ShomatePoly(index, tmid, thigh,
00188 refPressure, chigh));
00189 m_low[igrp-1].push_back(ShomatePoly(index, tlow, tmid,
00190 refPressure, clow));
00191 if (tlow > m_tlow_max) m_tlow_max = tlow;
00192 if (thigh < m_thigh_min) m_thigh_min = thigh;
00193
00194 if ((int) m_tlow.size() < index + 1) {
00195 m_tlow.resize(index + 1, tlow);
00196 m_thigh.resize(index + 1, thigh);
00197 }
00198 m_tlow[index] = tlow;
00199 m_thigh[index] = thigh;
00200
00201 if (m_p0 < 0.0) {
00202 m_p0 = refPressure;
00203 } else if (fabs(m_p0 - refPressure) > 0.1) {
00204 string logmsg = " WARNING ShomateThermo: New Species, " + name
00205 + ", has a different reference pressure, "
00206 + fp2str(refPressure) + ", than existing reference pressure, " + fp2str(m_p0) + "\n";
00207 writelog(logmsg);
00208 logmsg = " This may become a fatal error in the future \n";
00209 writelog(logmsg);
00210 }
00211 m_p0 = refPressure;
00212
00213 }
00214
00215
00216
00217
00218
00219
00220
00221 virtual void install_STIT(SpeciesThermoInterpType *stit_ptr) {
00222 throw CanteraError("install_STIT", "not implemented");
00223 }
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236 virtual void update_one(int k, doublereal t, doublereal* cp_R,
00237 doublereal* h_RT, doublereal* s_R) const {
00238
00239 doublereal tt = 1.e-3*t;
00240 m_t[0] = tt;
00241 m_t[1] = tt*tt;
00242 m_t[2] = m_t[1]*tt;
00243 m_t[3] = 1.0/m_t[1];
00244 m_t[4] = log(tt);
00245 m_t[5] = 1.0/GasConstant;
00246 m_t[6] = 1.0/(GasConstant * t);
00247
00248 int grp = m_group_map[k];
00249 int pos = m_posInGroup_map[k];
00250 const vector<ShomatePoly> &mlg = m_low[grp-1];
00251 const ShomatePoly *nlow = &(mlg[pos]);
00252
00253 doublereal tmid = nlow->maxTemp();
00254 if (t < tmid) {
00255 nlow->updateProperties(&m_t[0], cp_R, h_RT, s_R);
00256 } else {
00257 const vector<ShomatePoly> &mhg = m_high[grp-1];
00258 const ShomatePoly *nhigh = &(mhg[pos]);
00259 nhigh->updateProperties(&m_t[0], cp_R, h_RT, s_R);
00260 }
00261 }
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278 virtual void update(doublereal t, doublereal* cp_R,
00279 doublereal* h_RT, doublereal* s_R) const {
00280 int i;
00281
00282 doublereal tt = 1.e-3*t;
00283 m_t[0] = tt;
00284 m_t[1] = tt*tt;
00285 m_t[2] = m_t[1]*tt;
00286 m_t[3] = 1.0/m_t[1];
00287 m_t[4] = log(tt);
00288 m_t[5] = 1.0/GasConstant;
00289 m_t[6] = 1.0/(GasConstant * t);
00290
00291 vector<ShomatePoly>::const_iterator _begin, _end;
00292 for (i = 0; i != m_ngroups; i++) {
00293 if (t > m_tmid[i]) {
00294 _begin = m_high[i].begin();
00295 _end = m_high[i].end();
00296 }
00297 else {
00298 _begin = m_low[i].begin();
00299 _end = m_low[i].end();
00300 }
00301 for (; _begin != _end; ++_begin) {
00302 _begin->updateProperties(&m_t[0], cp_R, h_RT, s_R);
00303 }
00304 }
00305 }
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317 virtual doublereal minTemp(int k=-1) const {
00318 if (k < 0)
00319 return m_tlow_max;
00320 else
00321 return m_tlow[k];
00322 }
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334 virtual doublereal maxTemp(int k=-1) const {
00335 if (k < 0)
00336 return m_thigh_min;
00337 else
00338 return m_thigh[k];
00339 }
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354 virtual doublereal refPressure(int k=-1) const {
00355 return m_p0;
00356 }
00357
00358
00359
00360
00361
00362
00363
00364 virtual int reportType(int index) const { return SHOMATE; }
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380 virtual void reportParams(int index, int &type,
00381 doublereal * const c,
00382 doublereal &minTemp,
00383 doublereal &maxTemp,
00384 doublereal &refPressure) const {
00385 type = reportType(index);
00386 if (type == SHOMATE) {
00387 int grp = m_group_map[index];
00388 int pos = m_posInGroup_map[index];
00389 int itype = SHOMATE;
00390 const vector<ShomatePoly> &mlg = m_low[grp-1];
00391 const vector<ShomatePoly> &mhg = m_high[grp-1];
00392 const ShomatePoly *lowPoly = &(mlg[pos]);
00393 const ShomatePoly *highPoly = &(mhg[pos]);
00394 doublereal tmid = lowPoly->maxTemp();
00395 c[0] = tmid;
00396 int n;
00397 double ttemp;
00398 lowPoly->reportParameters(n, itype, minTemp, ttemp, refPressure,
00399 c + 1);
00400 if (n != index) {
00401 throw CanteraError(" ", "confused");
00402 }
00403 if (itype != SHOMATE && itype != SHOMATE1) {
00404 throw CanteraError(" ", "confused");
00405 }
00406 highPoly->reportParameters(n, itype, ttemp, maxTemp,
00407 refPressure, c + 8);
00408 if (n != index) {
00409 throw CanteraError(" ", "confused");
00410 }
00411 if (itype != SHOMATE && itype != SHOMATE1) {
00412 throw CanteraError(" ", "confused");
00413 }
00414 } else {
00415 throw CanteraError(" ", "confused");
00416 }
00417 }
00418
00419
00420
00421
00422
00423
00424
00425 virtual void modifyParams(int index, doublereal *c) {
00426 int type = reportType(index);
00427 if (type == SHOMATE) {
00428 int grp = m_group_map[index];
00429 int pos = m_posInGroup_map[index];
00430 vector<ShomatePoly> &mlg = m_low[grp-1];
00431 vector<ShomatePoly> &mhg = m_high[grp-1];
00432 ShomatePoly *lowPoly = &(mlg[pos]);
00433 ShomatePoly *highPoly = &(mhg[pos]);
00434 doublereal tmid = lowPoly->maxTemp();
00435 if (fabs(c[0] - tmid) > 0.001) {
00436 throw CanteraError("modifyParams", "can't change mid temp");
00437 }
00438
00439 lowPoly->modifyParameters(c + 1);
00440
00441 highPoly->modifyParameters(c + 8);
00442
00443 } else {
00444 throw CanteraError(" ", "confused");
00445 }
00446 }
00447
00448 #ifdef H298MODIFY_CAPABILITY
00449
00450 virtual doublereal reportOneHf298(int k) const {
00451 doublereal h;
00452 doublereal t = 298.15;
00453
00454 int grp = m_group_map[k];
00455 int pos = m_posInGroup_map[k];
00456 const vector<ShomatePoly> &mlg = m_low[grp-1];
00457 const ShomatePoly *nlow = &(mlg[pos]);
00458
00459 doublereal tmid = nlow->maxTemp();
00460 if (t <= tmid) {
00461 h = nlow->reportHf298();
00462 } else {
00463 const vector<ShomatePoly> &mhg = m_high[grp-1];
00464 const ShomatePoly *nhigh = &(mhg[pos]);
00465 h = nhigh->reportHf298();
00466 }
00467 return h;
00468 }
00469
00470 virtual void modifyOneHf298(const int k, const doublereal Hf298New) {
00471
00472 int grp = m_group_map[k];
00473 int pos = m_posInGroup_map[k];
00474 vector<ShomatePoly> &mlg = m_low[grp-1];
00475 ShomatePoly *nlow = &(mlg[pos]);
00476 vector<ShomatePoly> &mhg = m_high[grp-1];
00477 ShomatePoly *nhigh = &(mhg[pos]);
00478 doublereal tmid = nlow->maxTemp();
00479
00480 double hnow = reportOneHf298(k);
00481 double delH = Hf298New - hnow;
00482 if (298.15 <= tmid) {
00483 nlow->modifyOneHf298(k, Hf298New);
00484 double h = nhigh->reportHf298(0);
00485 double hnew = h + delH;
00486 nhigh->modifyOneHf298(k, hnew);
00487 } else {
00488 nhigh->modifyOneHf298(k, Hf298New);
00489 double h = nlow->reportHf298(0);
00490 double hnew = h + delH;
00491 nlow->modifyOneHf298(k, hnew);
00492 }
00493
00494 }
00495
00496
00497 #endif
00498 protected:
00499
00500
00501
00502
00503
00504
00505
00506
00507 vector<vector<ShomatePoly> > m_high;
00508
00509
00510
00511
00512
00513
00514
00515
00516 vector<vector<ShomatePoly> > m_low;
00517
00518
00519
00520
00521
00522 map<int, int> m_index;
00523
00524
00525
00526
00527
00528 vector_fp m_tmid;
00529
00530
00531 doublereal m_tlow_max;
00532
00533
00534 doublereal m_thigh_min;
00535
00536
00537
00538
00539
00540 vector_fp m_tlow;
00541
00542
00543
00544
00545
00546 vector_fp m_thigh;
00547
00548
00549
00550
00551
00552 doublereal m_p0;
00553
00554
00555 int m_ngroups;
00556
00557
00558 mutable vector_fp m_t;
00559
00560
00561
00562
00563
00564
00565
00566 mutable map<int, int> m_group_map;
00567
00568
00569
00570
00571
00572
00573 mutable map<int, int> m_posInGroup_map;
00574 };
00575
00576 }
00577
00578 #endif