00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef CT_SPECIESTHERMO_MGR_H
00016 #define CT_SPECIESTHERMO_MGR_H
00017
00018 #include "ct_defs.h"
00019 #include "ctexceptions.h"
00020 #include "stringUtils.h"
00021 #include "SpeciesThermo.h"
00022 #include <map>
00023
00024 namespace Cantera {
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 template<class InputIter>
00046 inline void _updateAll(InputIter begin,
00047 InputIter end,
00048 doublereal T,
00049 vector_fp& cp_R,
00050 vector_fp& h_RT,
00051 vector_fp& s_R)
00052 {
00053 for (; begin != end; ++begin) {
00054 begin->updateProperties(T, cp_R, h_RT, s_R);
00055 }
00056 }
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 template<class InputIter>
00071 doublereal _minTemp(InputIter begin, InputIter end) {
00072 doublereal _minT = 0.0;
00073 for (; begin != end; ++begin)
00074 _minT = fmaxx(_minT, begin->minTemp());
00075 return _minT;
00076 }
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 template<class _InputIter>
00091 doublereal _maxTemp(_InputIter begin, _InputIter end) {
00092 doublereal _maxT = 1.e10;
00093 for (; begin != end; ++begin)
00094 _maxT = fminn(_maxT, begin->maxTemp());
00095 return _maxT;
00096 }
00097
00098
00099
00100
00101
00102
00103
00104 class RefPressureMismatch : public CanteraError {
00105 public:
00106
00107
00108
00109
00110
00111
00112 RefPressureMismatch(std::string proc, doublereal prnew,
00113 doublereal prold) : CanteraError(proc,
00114 "Species reference pressure ("
00115 + fp2str(prnew) + ") does not match previously-defined "
00116 + "reference pressure (" + fp2str(prold) + ")") {}
00117
00118 virtual ~RefPressureMismatch() throw() {}
00119 };
00120
00121
00122
00123
00124
00125 class UnknownSpeciesThermo : public CanteraError {
00126 public:
00127
00128
00129
00130
00131
00132
00133 UnknownSpeciesThermo(std::string proc, int type) :
00134 CanteraError(proc, "Specified species parameterization type (" + int2str(type)
00135 + ") does not match any known type.") {}
00136
00137
00138
00139
00140
00141
00142 UnknownSpeciesThermo(std::string proc, std::string stype) :
00143 CanteraError(proc, "Specified species parameterization type (" + stype
00144 + ") does not match any known type.") {}
00145
00146 virtual ~UnknownSpeciesThermo() throw() {}
00147 };
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158 template<class T1, class T2>
00159 class SpeciesThermoDuo : public SpeciesThermo {
00160
00161 public:
00162
00163 SpeciesThermoDuo();
00164
00165
00166 virtual ~SpeciesThermoDuo();
00167
00168
00169
00170
00171
00172 SpeciesThermoDuo(const SpeciesThermoDuo &right);
00173
00174
00175
00176
00177
00178 SpeciesThermoDuo& operator=(const SpeciesThermoDuo &right);
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189 virtual SpeciesThermo *duplMyselfAsSpeciesThermo() const;
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212 virtual void install(std::string name, int sp, int type,
00213 const doublereal* c,
00214 doublereal minTemp, doublereal maxTemp,
00215 doublereal refPressure);
00216
00217
00218
00219
00220
00221
00222
00223 virtual void install_STIT(SpeciesThermoInterpType *stit_ptr);
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240 virtual void update(doublereal t, doublereal* cp_R,
00241 doublereal* h_RT, doublereal* s_R) const;
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253 virtual doublereal minTemp(int k = -1) const;
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265 virtual doublereal maxTemp(int k = -1) const;
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280 virtual doublereal refPressure(int k = -1) const;
00281
00282
00283
00284
00285
00286
00287
00288 virtual int reportType(int k) const;
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304 virtual void reportParams(int index, int &type,
00305 doublereal * const c,
00306 doublereal &minTemp,
00307 doublereal &maxTemp,
00308 doublereal &refPressure) const;
00309
00310
00311
00312
00313
00314
00315
00316 virtual void modifyParams(int index, doublereal *c);
00317
00318
00319 #ifdef H298MODIFY_CAPABILITY
00320
00321 virtual doublereal reportOneHf298(int k) const {
00322 throw CanteraError("reportHF298", "unimplemented");
00323 }
00324
00325 virtual void modifyOneHf298(const int k, const doublereal Hf298New) {
00326 throw CanteraError("reportHF298", "unimplemented");
00327 }
00328
00329 #endif
00330
00331 private:
00332
00333
00334 T1 m_thermo1;
00335
00336 T2 m_thermo2;
00337
00338 doublereal m_p0;
00339
00340 std::map<int, int> speciesToType;
00341 };
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363 template<class SPM>
00364 class SpeciesThermo1 : public SpeciesThermo {
00365
00366 public:
00367
00368 SpeciesThermo1();
00369
00370 virtual ~SpeciesThermo1();
00371
00372
00373
00374
00375
00376 SpeciesThermo1(const SpeciesThermo1 &right);
00377
00378
00379
00380
00381
00382 SpeciesThermo1 & operator=(const SpeciesThermo1 &right);
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393 virtual SpeciesThermo *duplMyselfAsSpeciesThermo() const;
00394
00395
00396
00397
00398
00399
00400
00401
00402 virtual void install(std::string name, int sp, int type,
00403 const vector_fp& c);
00404
00405
00406
00407
00408
00409
00410
00411
00412 virtual void update(doublereal t, vector_fp& cp_R,
00413 vector_fp& h_RT, vector_fp& s_R) const;
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423 virtual void update_one(int k, doublereal t, vector_fp& cp_R,
00424 vector_fp& h_RT, vector_fp& s_R) const;
00425
00426
00427
00428
00429
00430 virtual doublereal minTemp(int k = -1) const;
00431
00432
00433
00434
00435
00436 virtual doublereal maxTemp(int k = -1) const;
00437
00438
00439
00440
00441
00442 virtual doublereal refPressure(int k = -1) const;
00443
00444
00445
00446
00447
00448
00449
00450
00451 virtual int reportType(int k) const;
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466 virtual void reportParams(int index, int &type,
00467 doublereal * const c,
00468 doublereal &minTemp,
00469 doublereal &maxTemp,
00470 doublereal &refPressure) const;
00471
00472
00473
00474
00475
00476
00477
00478 virtual void modifyParams(int index, doublereal *c);
00479
00480 #ifdef H298MODIFY_CAPABILITY
00481
00482
00483
00484
00485
00486
00487
00488
00489 virtual doublereal reportOneHf298(int k) const {
00490 throw CanteraError("reportHF298", "unimplemented");
00491 }
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501 virtual void modifyOneHf298(const int k, const doublereal Hf298New) {
00502 throw CanteraError("reportHF298", "unimplemented");
00503 }
00504 #endif
00505
00506 private:
00507
00508 std::vector<SPM> m_thermo;
00509
00510
00511 doublereal m_pref;
00512 };
00513
00514
00515
00516
00517
00518 template<class T1, class T2>
00519 SpeciesThermoDuo<T1, T2>::SpeciesThermoDuo()
00520 {
00521 }
00522
00523 template<class T1, class T2>
00524 SpeciesThermoDuo<T1, T2>::~SpeciesThermoDuo()
00525 {
00526 }
00527
00528 template<class T1, class T2>
00529 SpeciesThermoDuo<T1, T2>::SpeciesThermoDuo(const SpeciesThermoDuo &right) {
00530 *this = operator=(right);
00531 }
00532
00533 template<class T1, class T2>
00534 SpeciesThermoDuo<T1, T2> &
00535 SpeciesThermoDuo<T1, T2>::operator=(const SpeciesThermoDuo &right) {
00536 if (&right == this) return *this;
00537
00538 m_thermo1 = right.m_thermo1;
00539 m_thermo2 = right.m_thermo2;
00540 m_p0 = right.m_p0;
00541 speciesToType = right.speciesToType;
00542
00543 return *this;
00544 }
00545
00546 template<class T1, class T2>
00547 SpeciesThermo *
00548 SpeciesThermoDuo<T1, T2>::duplMyselfAsSpeciesThermo() const {
00549 SpeciesThermoDuo<T1,T2> *nt = new SpeciesThermoDuo<T1,T2>(*this);
00550 return (SpeciesThermo *) nt;
00551 }
00552
00553 template<class T1, class T2>
00554 void
00555 SpeciesThermoDuo<T1, T2>::install(std::string name, int sp, int type,
00556 const doublereal* c,
00557 doublereal minTemp,
00558 doublereal maxTemp,
00559 doublereal refPressure) {
00560 m_p0 = refPressure;
00561 if (type == m_thermo1.ID) {
00562 m_thermo1.install(name, sp, 0, c, minTemp, maxTemp,
00563 refPressure);
00564 speciesToType[sp] = m_thermo1.ID;
00565 } else if (type == m_thermo2.ID) {
00566 m_thermo2.install(name, sp, 0, c, minTemp, maxTemp,
00567 refPressure);
00568 speciesToType[sp] = m_thermo2.ID;
00569 } else {
00570 throw UnknownSpeciesThermo("SpeciesThermoDuo:install",type);
00571 }
00572 }
00573
00574 template<class T1, class T2>
00575 void
00576 SpeciesThermoDuo<T1, T2>::install_STIT(SpeciesThermoInterpType *stit_ptr) {
00577 throw CanteraError("install_STIT", "not implemented");
00578 }
00579
00580 template<class T1, class T2>
00581 void
00582 SpeciesThermoDuo<T1, T2>::update(doublereal t, doublereal* cp_R,
00583 doublereal* h_RT, doublereal* s_R) const {
00584 m_thermo1.update(t, cp_R, h_RT, s_R);
00585 m_thermo2.update(t, cp_R, h_RT, s_R);
00586 }
00587
00588 template<class T1, class T2>
00589 doublereal
00590 SpeciesThermoDuo<T1, T2>::minTemp(int k) const {
00591 doublereal tm1 = m_thermo1.minTemp();
00592 doublereal tm2 = m_thermo2.minTemp();
00593 return (tm1 < tm2 ? tm2 : tm1);
00594 }
00595
00596 template<class T1, class T2>
00597 doublereal
00598 SpeciesThermoDuo<T1, T2>::maxTemp(int k) const {
00599 doublereal tm1 = m_thermo1.maxTemp();
00600 doublereal tm2 = m_thermo2.maxTemp();
00601 return (tm1 < tm2 ? tm1 : tm2);
00602 }
00603
00604 template<class T1, class T2>
00605 doublereal
00606 SpeciesThermoDuo<T1, T2>::refPressure(int k) const {
00607 return m_p0;
00608 }
00609
00610 template<class T1, class T2>
00611 int
00612 SpeciesThermoDuo<T1, T2>::reportType(int k) const {
00613 std::map<int, int>::const_iterator p = speciesToType.find(k);
00614 if (p != speciesToType.end()) {
00615 const int type = p->second;
00616 return type;
00617 }
00618 return -1;
00619 }
00620
00621 template<class T1, class T2>
00622 void
00623 SpeciesThermoDuo<T1, T2>::reportParams(int index, int &type,
00624 doublereal * const c,
00625 doublereal &minTemp,
00626 doublereal &maxTemp,
00627 doublereal &refPressure) const {
00628 int ctype = reportType(index);
00629 if (ctype == m_thermo1.ID) {
00630 m_thermo1.reportParams(index, type, c, minTemp, maxTemp,
00631 refPressure);
00632 } else if (ctype == m_thermo2.ID) {
00633 m_thermo2.reportParams(index, type, c, minTemp, maxTemp,
00634 refPressure);
00635 } else {
00636 throw CanteraError(" ", "confused");
00637 }
00638 }
00639
00640 template<class T1, class T2>
00641 void
00642 SpeciesThermoDuo<T1, T2>::modifyParams(int index, doublereal *c) {
00643 int ctype = reportType(index);
00644 if (ctype == m_thermo1.ID) {
00645 m_thermo1.modifyParams(index, c);
00646 } else if (ctype == m_thermo2.ID) {
00647 m_thermo2.modifyParams(index, c);
00648 } else {
00649 throw CanteraError("modifyParams", "confused");
00650 }
00651 }
00652
00653
00654
00655 template<class SPM>
00656 SpeciesThermo1<SPM>::SpeciesThermo1() :
00657 m_pref(0.0)
00658 {
00659 }
00660
00661 template<class SPM>
00662 SpeciesThermo1<SPM>::~SpeciesThermo1()
00663 {
00664 }
00665
00666 template<class SPM>
00667 SpeciesThermo1<SPM>::SpeciesThermo1(const SpeciesThermo1 &right) :
00668 m_pref(0.0)
00669 {
00670 *this = operator=(right);
00671 }
00672
00673 template<class SPM>
00674 SpeciesThermo1<SPM> &
00675 SpeciesThermo1<SPM>::operator=(const SpeciesThermo1 &right)
00676 {
00677 if (&right == this) return *this;
00678 m_thermo = right.m_thermo;
00679 m_pref = right.m_pref;
00680 return *this;
00681 }
00682
00683 template<class SPM>
00684 SpeciesThermo *
00685 SpeciesThermo1<SPM>::duplMyselfAsSpeciesThermo() const {
00686 SpeciesThermo1<SPM> *nt = new SpeciesThermo1<SPM>(*this);
00687 return (SpeciesThermo *) nt;
00688 }
00689
00690 template<class SPM>
00691 void
00692 SpeciesThermo1<SPM>::install(std::string name, int sp, int type, const vector_fp& c)
00693 {
00694 m_thermo.push_back(SPM(sp, c));
00695 if (m_pref) {
00696 if (m_thermo.begin()->refPressure() != m_pref) {
00697 throw RefPressureMismatch("SpeciesThermo1:install",
00698 refPressure(), m_pref);
00699 }
00700 }
00701 else m_pref = m_thermo.begin()->refPressure();
00702 }
00703
00704 template<class SPM>
00705 inline void
00706 SpeciesThermo1<SPM>::update(doublereal t, vector_fp& cp_R,
00707 vector_fp& h_RT, vector_fp& s_R) const {
00708 _updateAll(m_thermo.begin(), m_thermo.end(), t, cp_R, h_RT, s_R);
00709 }
00710
00711 template<class SPM>
00712 void
00713 SpeciesThermo1<SPM>::update_one(int k, doublereal t, vector_fp& cp_R,
00714 vector_fp& h_RT, vector_fp& s_R) const {
00715 m_thermo[k]->update(t, cp_R, h_RT, s_R);
00716 }
00717
00718 template<class SPM>
00719 doublereal
00720 SpeciesThermo1<SPM>::minTemp(int k) const {
00721 if (k < 0)
00722 return _minTemp(m_thermo.begin(), m_thermo.end());
00723 else
00724 return m_thermo[k].minTemp();
00725 }
00726
00727 template<class SPM>
00728 doublereal
00729 SpeciesThermo1<SPM>::maxTemp(int k) const {
00730 if (k < 0)
00731 return _maxTemp(m_thermo.begin(), m_thermo.end());
00732 else
00733 return m_thermo[k].maxTemp();
00734 }
00735
00736 template<class SPM>
00737 doublereal
00738 SpeciesThermo1<SPM>::refPressure(int k) const {
00739 return m_pref;
00740 }
00741
00742 template<class SPM>
00743 int
00744 SpeciesThermo1<SPM>::reportType(int k) const {
00745 return m_thermo[k]->reportType(-1);
00746 }
00747
00748 template<class SPM>
00749 void
00750 SpeciesThermo1<SPM>::reportParams(int index, int &type,
00751 doublereal * const c,
00752 doublereal &minTemp,
00753 doublereal &maxTemp,
00754 doublereal &refPressure) const {
00755 m_thermo[index]->reportParameters(index, type, c, minTemp, maxTemp, refPressure);
00756 }
00757
00758 template<class SPM>
00759 void
00760 SpeciesThermo1<SPM>::modifyParams(int index, doublereal *c) {
00761 m_thermo[index]->modifyParameters(index, c);
00762 }
00763 }
00764
00765 #endif