00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "GeneralSpeciesThermo.h"
00013 #include "NasaPoly1.h"
00014 #include "NasaPoly2.h"
00015 #include "ShomatePoly.h"
00016 #include "ConstCpPoly.h"
00017 #include "Mu0Poly.h"
00018 #ifdef WITH_ADSORBATE
00019 #include "AdsorbateThermo.h"
00020 #endif
00021
00022 #include "SpeciesThermoFactory.h"
00023 #include <iostream>
00024
00025 using namespace std;
00026
00027 namespace Cantera {
00028
00029
00030
00031
00032
00033 GeneralSpeciesThermo::GeneralSpeciesThermo() :
00034 SpeciesThermo(),
00035 m_tlow_max(0.0),
00036 m_thigh_min(1.0E30),
00037 m_p0(OneAtm),
00038 m_kk(0)
00039 {
00040 m_tlow_max = 0.0;
00041 m_thigh_min = 1.0E30;
00042 }
00043
00044 GeneralSpeciesThermo::
00045 GeneralSpeciesThermo(const GeneralSpeciesThermo &b) :
00046 m_tlow_max(b.m_tlow_max),
00047 m_thigh_min(b.m_thigh_min),
00048 m_kk(b.m_kk)
00049 {
00050 m_sp.resize(m_kk, 0);
00051 for (int k = 0; k < m_kk; k++) {
00052 SpeciesThermoInterpType *bk = b.m_sp[k];
00053 if (bk) {
00054 m_sp[k] = bk->duplMyselfAsSpeciesThermoInterpType();
00055 }
00056 }
00057 }
00058
00059 GeneralSpeciesThermo&
00060 GeneralSpeciesThermo::operator=(const GeneralSpeciesThermo &b) {
00061 if (&b != this) {
00062 m_tlow_max = b.m_tlow_max;
00063 m_thigh_min = b.m_thigh_min;
00064
00065 for (int k = 0; k < m_kk; k++) {
00066 SpeciesThermoInterpType *sp = m_sp[k];
00067 if (sp) {
00068 delete sp;
00069 m_sp[k] = 0;
00070 }
00071 }
00072 m_kk = b.m_kk;
00073 m_sp.resize(m_kk, 0);
00074 for (int k = 0; k < m_kk; k++) {
00075 SpeciesThermoInterpType *bk = b.m_sp[k];
00076 if (bk) {
00077 m_sp[k] = bk->duplMyselfAsSpeciesThermoInterpType();
00078 }
00079 }
00080 }
00081 return *this;
00082 }
00083
00084 GeneralSpeciesThermo::~GeneralSpeciesThermo() {
00085 for (int k = 0; k < m_kk; k++) {
00086 SpeciesThermoInterpType *sp = m_sp[k];
00087 if (sp) {
00088 delete sp;
00089 m_sp[k] = 0;
00090 }
00091 }
00092 }
00093
00094
00095 SpeciesThermo *
00096 GeneralSpeciesThermo::duplMyselfAsSpeciesThermo() const {
00097 GeneralSpeciesThermo *gsth = new GeneralSpeciesThermo(*this);
00098 return (SpeciesThermo *) gsth;
00099 }
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109 void GeneralSpeciesThermo::install(std::string name,
00110 int index,
00111 int type,
00112 const doublereal* c,
00113 doublereal minTemp,
00114 doublereal maxTemp,
00115 doublereal refPressure) {
00116
00117
00118
00119
00120 if (index > m_kk - 1) {
00121 m_sp.resize(index+1, 0);
00122 m_kk = index+1;
00123 }
00124
00125
00126
00127
00128
00129
00130
00131
00132 switch (type) {
00133 case NASA1:
00134 m_sp[index] = new NasaPoly1(index, minTemp, maxTemp,
00135 refPressure, c);
00136 break;
00137 case SHOMATE1:
00138 m_sp[index] = new ShomatePoly(index, minTemp, maxTemp,
00139 refPressure, c);
00140 break;
00141 case CONSTANT_CP:
00142 case SIMPLE:
00143 m_sp[index] = new ConstCpPoly(index, minTemp, maxTemp,
00144 refPressure, c);
00145 break;
00146 case MU0_INTERP:
00147 m_sp[index] = new Mu0Poly(index, minTemp, maxTemp,
00148 refPressure, c);
00149 break;
00150 case SHOMATE2:
00151 m_sp[index] = new ShomatePoly2(index, minTemp, maxTemp,
00152 refPressure, c);
00153 break;
00154 case NASA2:
00155 m_sp[index] = new NasaPoly2(index, minTemp, maxTemp,
00156 refPressure, c);
00157 break;
00158 #ifdef WITH_ADSORBATE
00159 case ADSORBATE:
00160 m_sp[index] = new Adsorbate(index, minTemp, maxTemp,
00161 refPressure, c);
00162 break;
00163 #endif
00164 default:
00165 throw UnknownSpeciesThermoModel(
00166 "GeneralSpeciesThermo::install",
00167 "unknown species type", int2str(type));
00168 break;
00169 }
00170 if (!m_sp[index]) {
00171 cout << "Null m_sp... index = " << index << endl;
00172 cout << "type = " << type << endl;
00173 }
00174 m_tlow_max = max(minTemp, m_tlow_max);
00175 m_thigh_min = min(maxTemp, m_thigh_min);
00176 }
00177
00178
00179
00180
00181
00182
00183
00184 void GeneralSpeciesThermo::install_STIT(SpeciesThermoInterpType *stit_ptr) {
00185
00186
00187
00188
00189 if (!stit_ptr) {
00190 throw CanteraError("GeneralSpeciesThermo::install_STIT",
00191 "zero pointer");
00192 }
00193 int index = stit_ptr->speciesIndex();
00194 if (index > m_kk - 1) {
00195 m_sp.resize(index+1, 0);
00196 m_kk = index+1;
00197 }
00198 AssertThrow(m_sp[index] == 0,
00199 "Index position isn't null, duplication of assignment: " + int2str(index));
00200
00201
00202
00203 m_sp[index] = stit_ptr;
00204
00205
00206
00207
00208 double minTemp = stit_ptr->minTemp();
00209 double maxTemp = stit_ptr->maxTemp();
00210
00211 m_tlow_max = max(minTemp, m_tlow_max);
00212 m_thigh_min = min(maxTemp, m_thigh_min);
00213 }
00214
00215
00216
00217 void GeneralSpeciesThermo::installPDSShandler(int k, PDSS *PDSS_ptr,
00218 VPSSMgr *vpssmgr_ptr) {
00219 STITbyPDSS *stit_ptr = new STITbyPDSS(k, vpssmgr_ptr, PDSS_ptr);
00220 install_STIT(stit_ptr);
00221 }
00222
00223
00224
00225
00226 void GeneralSpeciesThermo::
00227 update_one(int k, doublereal t, doublereal* cp_R,
00228 doublereal* h_RT, doublereal* s_R) const {
00229 SpeciesThermoInterpType * sp_ptr = m_sp[k];
00230 if (sp_ptr) {
00231 sp_ptr->updatePropertiesTemp(t, cp_R, h_RT, s_R);
00232 }
00233 }
00234
00235
00236
00237
00238
00239 void GeneralSpeciesThermo::
00240 update(doublereal t, doublereal* cp_R,
00241 doublereal* h_RT, doublereal* s_R) const {
00242 vector<SpeciesThermoInterpType *>::const_iterator _begin, _end;
00243 _begin = m_sp.begin();
00244 _end = m_sp.end();
00245 SpeciesThermoInterpType * sp_ptr = 0;
00246 for (; _begin != _end; ++_begin) {
00247 sp_ptr = *(_begin);
00248 if (sp_ptr) {
00249 sp_ptr->updatePropertiesTemp(t, cp_R, h_RT, s_R);
00250 }
00251
00252
00253
00254 }
00255 }
00256
00257
00258
00259
00260
00261 int GeneralSpeciesThermo::reportType(int index) const {
00262 SpeciesThermoInterpType *sp = m_sp[index];
00263 if (sp) {
00264 return sp->reportType();
00265 }
00266 return -1;
00267 }
00268
00269
00270
00271
00272
00273
00274
00275 void GeneralSpeciesThermo::
00276 reportParams(int index, int &type, doublereal * const c,
00277 doublereal &minTemp, doublereal &maxTemp, doublereal &refPressure) const {
00278 SpeciesThermoInterpType *sp = m_sp[index];
00279 int n;
00280 if (sp) {
00281 sp->reportParameters(n, type, minTemp, maxTemp,
00282 refPressure, c);
00283 if (n != index) {
00284 throw CanteraError("GeneralSpeciesThermo::reportParams",
00285 "Internal error encountered");
00286 }
00287 } else {
00288 type = -1;
00289 }
00290 }
00291
00292
00293
00294
00295
00296
00297
00298 void GeneralSpeciesThermo::
00299 modifyParams(int index, doublereal *c) {
00300 SpeciesThermoInterpType *sp = m_sp[index];
00301 if (sp) {
00302 sp->modifyParameters(c);
00303 }
00304 }
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314 doublereal GeneralSpeciesThermo::minTemp(int k) const {
00315 if (k < 0)
00316 return m_tlow_max;
00317 else {
00318 SpeciesThermoInterpType *sp = m_sp[k];
00319 if (sp) {
00320 return sp->minTemp();
00321 }
00322 }
00323 return m_tlow_max;
00324 }
00325
00326 doublereal GeneralSpeciesThermo::maxTemp(int k) const {
00327 if (k < 0) {
00328 return m_thigh_min;
00329 } else {
00330 SpeciesThermoInterpType *sp = m_sp[k];
00331 if (sp) {
00332 return sp->maxTemp();
00333 }
00334 }
00335 return m_thigh_min;
00336 }
00337
00338 doublereal GeneralSpeciesThermo::refPressure(int k) const {
00339 if (k < 0) {
00340 return m_p0;
00341 } else {
00342 SpeciesThermoInterpType *sp = m_sp[k];
00343 if (sp) {
00344 return sp->refPressure();
00345 }
00346 }
00347 return m_p0;
00348 }
00349
00350
00351 SpeciesThermoInterpType * GeneralSpeciesThermo::provideSTIT(int k) {
00352 return (m_sp[k]);
00353 }
00354
00355 #ifdef H298MODIFY_CAPABILITY
00356
00357 doublereal GeneralSpeciesThermo::reportOneHf298(int k) const {
00358 SpeciesThermoInterpType * sp_ptr = m_sp[k];
00359 doublereal h = -1.0;
00360 if (sp_ptr) {
00361 h = sp_ptr->reportHf298(0);
00362 }
00363 return h;
00364 }
00365
00366 void GeneralSpeciesThermo::modifyOneHf298(const int k, const doublereal Hf298New) {
00367 SpeciesThermoInterpType * sp_ptr = m_sp[k];
00368 if (sp_ptr) {
00369 sp_ptr->modifyOneHf298(k, Hf298New);
00370 }
00371 }
00372
00373
00374 #endif
00375
00376
00377 }