VPStandardStateTP.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 #ifdef WIN32
00021 #pragma warning(disable:4786)
00022 #pragma warning(disable:4503)
00023 #endif
00024
00025 #include "VPStandardStateTP.h"
00026 #include "VPSSMgr.h"
00027 #include "PDSS.h"
00028
00029 using namespace std;
00030
00031 namespace Cantera {
00032
00033
00034
00035
00036 VPStandardStateTP::VPStandardStateTP() :
00037 ThermoPhase(),
00038 m_Pcurrent(OneAtm),
00039 m_Tlast_ss(-1.0),
00040 m_Plast_ss(-1.0),
00041 m_P0(OneAtm),
00042 m_VPSS_ptr(0)
00043 {
00044 }
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 VPStandardStateTP::VPStandardStateTP(const VPStandardStateTP &b) :
00056 ThermoPhase(),
00057 m_Pcurrent(OneAtm),
00058 m_Tlast_ss(-1.0),
00059 m_Plast_ss(-1.0),
00060 m_P0(OneAtm),
00061 m_VPSS_ptr(0)
00062 {
00063 VPStandardStateTP::operator=(b);
00064 }
00065
00066
00067
00068
00069
00070
00071
00072 VPStandardStateTP&
00073 VPStandardStateTP::operator=(const VPStandardStateTP &b) {
00074 if (&b != this) {
00075
00076
00077
00078
00079 ThermoPhase::operator=(b);
00080
00081
00082
00083 m_Pcurrent = b.m_Pcurrent;
00084 m_Tlast_ss = b.m_Tlast_ss;
00085 m_Plast_ss = b.m_Plast_ss;
00086 m_P0 = b.m_P0;
00087
00088
00089
00090
00091 if (m_PDSS_storage.size() > 0) {
00092 for (int k = 0; k < (int) m_PDSS_storage.size(); k++) {
00093 delete(m_PDSS_storage[k]);
00094 }
00095 }
00096 m_PDSS_storage.resize(m_kk);
00097 for (int k = 0; k < m_kk; k++) {
00098 PDSS *ptmp = b.m_PDSS_storage[k];
00099 m_PDSS_storage[k] = ptmp->duplMyselfAsPDSS();
00100 }
00101
00102
00103
00104
00105 if (m_VPSS_ptr) {
00106 delete m_VPSS_ptr;
00107 m_VPSS_ptr = 0;
00108 }
00109 m_VPSS_ptr = (b.m_VPSS_ptr)->duplMyselfAsVPSSMgr();
00110
00111
00112
00113
00114
00115
00116 m_VPSS_ptr->initAllPtrs(this, m_spthermo);
00117
00118
00119
00120
00121
00122
00123 for (int k = 0; k < m_kk; k++) {
00124 PDSS *ptmp = m_PDSS_storage[k];
00125 ptmp->initAllPtrs(this, m_VPSS_ptr, m_spthermo);
00126 }
00127
00128
00129
00130
00131
00132 m_VPSS_ptr->setState_TP(m_Tlast_ss, m_Plast_ss);
00133 }
00134 return *this;
00135 }
00136
00137
00138
00139
00140
00141 VPStandardStateTP::~VPStandardStateTP() {
00142 for (int k = 0; k < (int) m_PDSS_storage.size(); k++) {
00143 delete(m_PDSS_storage[k]);
00144 }
00145 delete m_VPSS_ptr;
00146 }
00147
00148
00149
00150
00151
00152 ThermoPhase* VPStandardStateTP::duplMyselfAsThermoPhase() const {
00153 VPStandardStateTP* vptp = new VPStandardStateTP(*this);
00154 return (ThermoPhase *) vptp;
00155 }
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169 int VPStandardStateTP::standardStateConvention() const {
00170 return cSS_CONVENTION_VPSS;
00171 }
00172
00173
00174
00175
00176
00177
00178
00179 doublereal VPStandardStateTP::err(std::string msg) const {
00180 throw CanteraError("VPStandardStateTP","Base class method "
00181 +msg+" called. Equation of state type: "+int2str(eosType()));
00182 return 0;
00183 }
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198 void VPStandardStateTP::getChemPotentials_RT(doublereal* muRT) const{
00199 getChemPotentials(muRT);
00200 doublereal invRT = 1.0 / _RT();
00201 for (int k = 0; k < m_kk; k++) {
00202 muRT[k] *= invRT;
00203 }
00204 }
00205
00206
00207
00208
00209 void VPStandardStateTP::getStandardChemPotentials(doublereal* g) const {
00210 getGibbs_RT(g);
00211 doublereal RT = _RT();
00212 for (int k = 0; k < m_kk; k++) {
00213 g[k] *= RT;
00214 }
00215 }
00216
00217 inline
00218 void VPStandardStateTP::getEnthalpy_RT(doublereal* hrt) const {
00219 updateStandardStateThermo();
00220 m_VPSS_ptr->getEnthalpy_RT(hrt);
00221 }
00222
00223
00224 #ifdef H298MODIFY_CAPABILITY
00225
00226
00227
00228
00229
00230
00231
00232
00233 void VPStandardStateTP::modifyOneHf298SS(const int k, const doublereal Hf298New) {
00234 m_spthermo->modifyOneHf298(k, Hf298New);
00235 m_Tlast_ss += 0.0001234;
00236 }
00237 #endif
00238
00239 void VPStandardStateTP::getEntropy_R(doublereal* srt) const {
00240 updateStandardStateThermo();
00241 m_VPSS_ptr->getEntropy_R(srt);
00242 }
00243
00244 inline
00245 void VPStandardStateTP::getGibbs_RT(doublereal* grt) const {
00246 updateStandardStateThermo();
00247 m_VPSS_ptr->getGibbs_RT(grt);
00248 }
00249
00250 inline
00251 void VPStandardStateTP::getPureGibbs(doublereal* g) const {
00252 updateStandardStateThermo();
00253 m_VPSS_ptr->getStandardChemPotentials(g);
00254 }
00255
00256 void VPStandardStateTP::getIntEnergy_RT(doublereal* urt) const {
00257 updateStandardStateThermo();
00258 m_VPSS_ptr->getIntEnergy_RT(urt);
00259 }
00260
00261 void VPStandardStateTP::getCp_R(doublereal* cpr) const {
00262 updateStandardStateThermo();
00263 m_VPSS_ptr->getCp_R(cpr);
00264 }
00265
00266 void VPStandardStateTP::getStandardVolumes(doublereal *vol) const {
00267 updateStandardStateThermo();
00268 m_VPSS_ptr->getStandardVolumes(vol);
00269 }
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280 void VPStandardStateTP::getEnthalpy_RT_ref(doublereal *hrt) const {
00281 updateStandardStateThermo();
00282 m_VPSS_ptr->getEnthalpy_RT_ref(hrt);
00283 }
00284
00285
00286
00287
00288
00289
00290 void VPStandardStateTP::getGibbs_RT_ref(doublereal *grt) const {
00291 updateStandardStateThermo();
00292 m_VPSS_ptr->getGibbs_RT_ref(grt);
00293 }
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304 void VPStandardStateTP::getGibbs_ref(doublereal *g) const {
00305 updateStandardStateThermo();
00306 m_VPSS_ptr->getGibbs_ref(g);
00307 }
00308
00309 const vector_fp & VPStandardStateTP::Gibbs_RT_ref() const {
00310 updateStandardStateThermo();
00311 return m_VPSS_ptr->Gibbs_RT_ref();
00312 }
00313
00314
00315
00316
00317
00318
00319 void VPStandardStateTP::getEntropy_R_ref(doublereal *er) const {
00320 updateStandardStateThermo();
00321 m_VPSS_ptr->getEntropy_R_ref(er);
00322 }
00323
00324
00325
00326
00327
00328
00329
00330 void VPStandardStateTP::getCp_R_ref(doublereal *cpr) const {
00331 updateStandardStateThermo();
00332 m_VPSS_ptr->getCp_R_ref(cpr);
00333 }
00334
00335
00336
00337
00338
00339
00340
00341 void VPStandardStateTP::getStandardVolumes_ref(doublereal *vol) const {
00342 updateStandardStateThermo();
00343 m_VPSS_ptr->getStandardVolumes_ref(vol);
00344 }
00345
00346
00347
00348
00349
00350 void VPStandardStateTP::initThermo() {
00351 initLengths();
00352 ThermoPhase::initThermo();
00353 m_VPSS_ptr->initThermo();
00354 for (int k = 0; k < m_kk; k++) {
00355 PDSS *kPDSS = m_PDSS_storage[k];
00356 if (kPDSS) {
00357 kPDSS->initThermo();
00358 }
00359 }
00360 }
00361
00362 void VPStandardStateTP::setVPSSMgr(VPSSMgr *vp_ptr) {
00363 m_VPSS_ptr = vp_ptr;
00364 }
00365
00366
00367
00368
00369
00370 void VPStandardStateTP::initLengths() {
00371 m_kk = nSpecies();
00372
00373 }
00374
00375
00376 void VPStandardStateTP::setTemperature(const doublereal temp) {
00377 setState_TP(temp, m_Pcurrent);
00378 updateStandardStateThermo();
00379 }
00380
00381 void VPStandardStateTP::setPressure(doublereal p) {
00382 setState_TP(temperature(), p);
00383 updateStandardStateThermo();
00384 }
00385
00386 void VPStandardStateTP::calcDensity() {
00387 err("VPStandardStateTP::calcDensity() called, but EOS for phase is not known");
00388 }
00389
00390
00391 void VPStandardStateTP::setState_TP(doublereal t, doublereal pres) {
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401 State::setTemperature(t);
00402 m_Pcurrent = pres;
00403 updateStandardStateThermo();
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414 calcDensity();
00415 }
00416
00417
00418
00419 void
00420 VPStandardStateTP::createInstallPDSS(int k, const XML_Node& s,
00421 const XML_Node * phaseNode_ptr) {
00422 if ((int) m_PDSS_storage.size() < k+1) {
00423 m_PDSS_storage.resize(k+1,0);
00424 }
00425 if (m_PDSS_storage[k] != 0) {
00426 delete m_PDSS_storage[k] ;
00427 }
00428 m_PDSS_storage[k] = m_VPSS_ptr->createInstallPDSS(k, s, phaseNode_ptr);
00429 }
00430
00431 PDSS *
00432 VPStandardStateTP::providePDSS(int k) {
00433 return m_PDSS_storage[k];
00434 }
00435
00436 const PDSS *
00437 VPStandardStateTP::providePDSS(int k) const {
00438 return m_PDSS_storage[k];
00439 }
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458 void VPStandardStateTP::initThermoXML(XML_Node& phaseNode, std::string id) {
00459 VPStandardStateTP::initLengths();
00460
00461
00462 for (int k = 0; k < m_kk; k++) {
00463 PDSS *kPDSS = m_PDSS_storage[k];
00464 AssertTrace(kPDSS != 0);
00465 if (kPDSS) {
00466 kPDSS->initThermoXML(phaseNode, id);
00467 }
00468 }
00469 m_VPSS_ptr->initThermoXML(phaseNode, id);
00470 ThermoPhase::initThermoXML(phaseNode, id);
00471 }
00472
00473
00474 VPSSMgr *VPStandardStateTP::provideVPSSMgr() {
00475 return m_VPSS_ptr;
00476 }
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492 void VPStandardStateTP::_updateStandardStateThermo() const {
00493 double Tnow = temperature();
00494 m_Plast_ss = m_Pcurrent;
00495 m_Tlast_ss = Tnow;
00496 AssertThrowMsg(m_VPSS_ptr != 0, "VPStandardStateTP::_updateStandardStateThermo()",
00497 "Probably indicates that ThermoPhase object wasn't initialized correctly");
00498 m_VPSS_ptr->setState_TP(Tnow, m_Pcurrent);
00499 }
00500
00501 void VPStandardStateTP::updateStandardStateThermo() const {
00502 double Tnow = temperature();
00503 if (Tnow != m_Tlast_ss || m_Pcurrent != m_Plast_ss) {
00504 _updateStandardStateThermo();
00505 }
00506 }
00507 }
00508
00509