00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifdef WIN32
00022 #pragma warning(disable:4786)
00023 #pragma warning(disable:4503)
00024 #endif
00025
00026 #include "VPSSMgr.h"
00027 #include "VPStandardStateTP.h"
00028 #include "SpeciesThermoFactory.h"
00029 #include "PDSS.h"
00030 #include "GeneralSpeciesThermo.h"
00031
00032 using namespace std;
00033
00034 namespace Cantera {
00035
00036 class SpeciesThermo;
00037
00038 VPSSMgr::VPSSMgr(VPStandardStateTP *vptp_ptr, SpeciesThermo *spthermo) :
00039 m_kk(0),
00040 m_vptp_ptr(vptp_ptr),
00041 m_spthermo(spthermo),
00042 m_tlast(-1.0),
00043 m_plast(-1.0),
00044 m_p0(-1.0),
00045 m_minTemp(-1.0),
00046 m_maxTemp(1.0E8),
00047 m_useTmpRefStateStorage(false),
00048 m_useTmpStandardStateStorage(false)
00049 {
00050 if (!m_vptp_ptr) {
00051 throw CanteraError("VPSSMgr",
00052 "null pointer for VPStandardStateTP is not permissible");
00053 }
00054 }
00055
00056 VPSSMgr::~VPSSMgr()
00057 {
00058 }
00059
00060 VPSSMgr::VPSSMgr(const VPSSMgr &right) :
00061 m_kk(0),
00062 m_vptp_ptr(0),
00063 m_spthermo(0),
00064
00065
00066 m_tlast(-1.0),
00067 m_plast(-1.0),
00068 m_p0(-1.0),
00069 m_minTemp(-1.0),
00070 m_maxTemp(1.0E8),
00071 m_useTmpRefStateStorage(false),
00072 m_useTmpStandardStateStorage(false)
00073 {
00074 *this = right;
00075 }
00076
00077
00078
00079
00080
00081
00082 VPSSMgr&
00083 VPSSMgr::operator=(const VPSSMgr &right) {
00084 if (&right == this) {
00085 return *this;
00086 }
00087 m_kk = right.m_kk;
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 m_vptp_ptr = right.m_vptp_ptr;
00102 m_spthermo = right.m_spthermo;
00103 m_tlast = -1.0;
00104 m_plast = -1.0;
00105 m_p0 = right.m_p0;
00106 m_minTemp = right.m_minTemp;
00107 m_maxTemp = right.m_maxTemp;
00108 m_useTmpRefStateStorage = right.m_useTmpRefStateStorage;
00109 m_h0_RT = right.m_h0_RT;
00110 m_cp0_R = right.m_cp0_R;
00111 m_g0_RT = right.m_g0_RT;
00112 m_s0_R = right.m_s0_R;
00113 m_V0 = right.m_V0;
00114 m_useTmpStandardStateStorage = right.m_useTmpStandardStateStorage;
00115 m_hss_RT = right.m_hss_RT;
00116 m_cpss_R = right.m_cpss_R;
00117 m_gss_RT = right.m_gss_RT;
00118 m_sss_R = right.m_sss_R;
00119 m_Vss = right.m_Vss;
00120
00121 mPDSS_h0_RT = right.mPDSS_h0_RT;
00122 mPDSS_cp0_R = right.mPDSS_cp0_R;
00123 mPDSS_g0_RT = right.mPDSS_g0_RT;
00124 mPDSS_s0_R = right.mPDSS_s0_R;
00125 mPDSS_V0 = right.mPDSS_V0;
00126 mPDSS_hss_RT = right.mPDSS_hss_RT;
00127 mPDSS_cpss_R = right.mPDSS_cpss_R;
00128 mPDSS_gss_RT = right.mPDSS_gss_RT;
00129 mPDSS_sss_R = right.mPDSS_sss_R;
00130 mPDSS_Vss = right.mPDSS_Vss;
00131
00132 return *this;
00133 }
00134
00135 VPSSMgr *VPSSMgr::duplMyselfAsVPSSMgr() const {
00136 VPSSMgr *vp = new VPSSMgr(*this);
00137 return vp;
00138 }
00139
00140 void VPSSMgr::initAllPtrs(VPStandardStateTP *vp_ptr,
00141 SpeciesThermo *sp_ptr) {
00142 m_vptp_ptr = vp_ptr;
00143 m_spthermo = sp_ptr;
00144
00145
00146
00147
00148 GeneralSpeciesThermo * gst = dynamic_cast<GeneralSpeciesThermo *>(sp_ptr);
00149 if (gst) {
00150 for (int k = 0; k < m_kk; k++) {
00151 SpeciesThermoInterpType *st = gst->provideSTIT(k);
00152 STITbyPDSS * stpd = dynamic_cast<STITbyPDSS *>(st);
00153 if (stpd) {
00154 PDSS * PDSS_ptr = vp_ptr->providePDSS(k);
00155 stpd->initAllPtrs(k, this, PDSS_ptr);
00156 }
00157 }
00158 }
00159
00160 }
00161
00162
00163
00164 void
00165 VPSSMgr::getStandardChemPotentials(doublereal *mu) const{
00166 if (m_useTmpStandardStateStorage) {
00167 std::copy(m_gss_RT.begin(), m_gss_RT.end(), mu);
00168 doublereal _rt = GasConstant * m_tlast;
00169 scale(mu, mu+m_kk, mu, _rt);
00170 } else {
00171 err("getStandardChemPotentials");
00172 }
00173 }
00174
00175 void
00176 VPSSMgr::getGibbs_RT(doublereal *grt) const{
00177 if (m_useTmpStandardStateStorage) {
00178 std::copy(m_gss_RT.begin(), m_gss_RT.end(), grt);
00179 } else {
00180 err("getGibbs_RT");
00181 }
00182 }
00183
00184 void
00185 VPSSMgr::getEnthalpy_RT(doublereal *hrt) const{
00186 if (m_useTmpStandardStateStorage) {
00187 std::copy(m_hss_RT.begin(), m_hss_RT.end(), hrt);
00188 } else {
00189 err("getEnthalpy_RT");
00190 }
00191 }
00192
00193 void
00194 VPSSMgr::getEntropy_R(doublereal *sr) const{
00195 if (m_useTmpStandardStateStorage) {
00196 std::copy(m_sss_R.begin(), m_sss_R.end(), sr);
00197 } else {
00198 err("getEntropy_RT");
00199 }
00200 }
00201
00202 void
00203 VPSSMgr::getIntEnergy_RT(doublereal *urt) const{
00204 if (m_useTmpStandardStateStorage) {
00205 std::copy(m_hss_RT.begin(), m_hss_RT.end(), urt);
00206 doublereal pRT = m_plast / (GasConstant * m_tlast);
00207 for (int k = 0; k < m_kk; k++) {
00208 urt[k] -= pRT * m_Vss[k];
00209 }
00210 } else {
00211 err("getEntropy_RT");
00212 }
00213 }
00214
00215 void
00216 VPSSMgr::getCp_R(doublereal *cpr) const{
00217 if (m_useTmpStandardStateStorage) {
00218 std::copy(m_cpss_R.begin(), m_cpss_R.end(), cpr);
00219 } else {
00220 err("getCp_R");
00221 }
00222 }
00223
00224 void
00225 VPSSMgr::getStandardVolumes(doublereal *vol) const{
00226 if (m_useTmpStandardStateStorage) {
00227 std::copy(m_Vss.begin(), m_Vss.end(), vol);
00228 } else {
00229 err("getStandardVolumes");
00230 }
00231 }
00232
00233
00234 void
00235 VPSSMgr::getEnthalpy_RT_ref(doublereal *hrt) const{
00236 if (m_useTmpRefStateStorage) {
00237 std::copy(m_h0_RT.begin(), m_h0_RT.end(), hrt);
00238 } else {
00239 err("getEnthalpy_RT_ref");
00240 }
00241 }
00242
00243 void
00244 VPSSMgr::getGibbs_RT_ref(doublereal *grt) const{
00245 if (m_useTmpRefStateStorage) {
00246 std::copy(m_g0_RT.begin(), m_g0_RT.end(), grt);
00247 } else {
00248 err("getGibbs_RT_ref");
00249 }
00250 }
00251
00252 void
00253 VPSSMgr::getGibbs_ref(doublereal *g) const{
00254 if (m_useTmpRefStateStorage) {
00255 std::copy(m_g0_RT.begin(), m_g0_RT.end(), g);
00256 doublereal _rt = GasConstant * m_tlast;
00257 scale(g, g+m_kk, g, _rt);
00258 } else {
00259 err("getGibbs_ref");
00260 }
00261 }
00262
00263 void
00264 VPSSMgr::getEntropy_R_ref(doublereal *sr) const{
00265 if (m_useTmpRefStateStorage) {
00266 std::copy(m_s0_R.begin(), m_s0_R.end(), sr);
00267 } else {
00268 err("getEntropy_R_ref");
00269 }
00270 }
00271
00272 void
00273 VPSSMgr::getCp_R_ref(doublereal *cpr) const{
00274 if (m_useTmpRefStateStorage) {
00275 std::copy(m_cp0_R.begin(), m_cp0_R.end(), cpr);
00276 } else {
00277 err("getCp_R_ref");
00278 }
00279 }
00280
00281 void
00282 VPSSMgr::getStandardVolumes_ref(doublereal *vol) const{
00283 err("getStandardVolumes_ref");
00284 }
00285
00286
00287
00288 void VPSSMgr::setState_P(doublereal pres) {
00289 if (m_plast != pres) {
00290 m_plast = pres;
00291 updateStandardStateThermo();
00292 }
00293 }
00294
00295 void VPSSMgr::setState_T(doublereal temp) {
00296 if (m_tlast != temp) {
00297 m_tlast = temp;
00298 updateRefStateThermo();
00299 updateStandardStateThermo();
00300 }
00301 }
00302
00303 void VPSSMgr::setState_TP(doublereal temp, doublereal pres) {
00304 if (m_tlast != temp) {
00305 m_tlast = temp;
00306 m_plast = pres;
00307 updateRefStateThermo();
00308 updateStandardStateThermo();
00309 } else if (m_plast != pres) {
00310 m_plast = pres;
00311 updateStandardStateThermo();
00312 }
00313 }
00314
00315 void VPSSMgr::updateStandardStateThermo() {
00316 _updateStandardStateThermo();
00317 }
00318
00319 void VPSSMgr::updateRefStateThermo() const {
00320 _updateRefStateThermo();
00321 }
00322
00323 void VPSSMgr::_updateStandardStateThermo() {
00324 for (int k = 0; k < m_kk; k++) {
00325 PDSS *kPDSS = m_vptp_ptr->providePDSS(k);
00326 kPDSS->setState_TP(m_tlast, m_plast);
00327 }
00328 err("_updateStandardStateThermo()");
00329 }
00330
00331 void VPSSMgr::_updateRefStateThermo() const {
00332 if (m_spthermo) {
00333 m_spthermo->update(m_tlast, &m_cp0_R[0], &m_h0_RT[0], &m_s0_R[0]);
00334 for (int k = 0; k < m_kk; k++) {
00335 m_g0_RT[k] = m_h0_RT[k] - m_s0_R[k];
00336 }
00337 }
00338 }
00339
00340
00341
00342
00343 void
00344 VPSSMgr::initThermo() {
00345 initLengths();
00346 }
00347
00348 void
00349 VPSSMgr::initLengths() {
00350 m_kk = m_vptp_ptr->nSpecies();
00351 m_h0_RT.resize(m_kk, 0.0);
00352 m_cp0_R.resize(m_kk, 0.0);
00353 m_g0_RT.resize(m_kk, 0.0);
00354 m_s0_R.resize(m_kk, 0.0);
00355 m_V0.resize(m_kk, 0.0);
00356 m_hss_RT.resize(m_kk, 0.0);
00357 m_cpss_R.resize(m_kk, 0.0);
00358 m_gss_RT.resize(m_kk, 0.0);
00359 m_sss_R.resize(m_kk, 0.0);
00360 m_Vss.resize(m_kk, 0.0);
00361
00362
00363
00364 mPDSS_h0_RT.resize(m_kk, 0.0);
00365 mPDSS_cp0_R.resize(m_kk, 0.0);
00366 mPDSS_g0_RT.resize(m_kk, 0.0);
00367 mPDSS_s0_R.resize(m_kk, 0.0);
00368 mPDSS_V0.resize(m_kk, 0.0);
00369 mPDSS_hss_RT.resize(m_kk, 0.0);
00370 mPDSS_cpss_R.resize(m_kk, 0.0);
00371 mPDSS_gss_RT.resize(m_kk, 0.0);
00372 mPDSS_sss_R.resize(m_kk, 0.0);
00373 mPDSS_Vss.resize(m_kk, 0.0);
00374 }
00375
00376 void VPSSMgr::initThermoXML(XML_Node& phaseNode, std::string id) {
00377 const PDSS *kPDSS = m_vptp_ptr->providePDSS(0);
00378 m_p0 = kPDSS->refPressure();
00379 for (int i = 0; i < m_kk; i++) {
00380 const PDSS *kPDSS = m_vptp_ptr->providePDSS(i);
00381 doublereal mint = kPDSS->minTemp();
00382 if (mint > m_minTemp) {
00383 m_minTemp = mint;
00384 }
00385 mint = kPDSS->maxTemp();
00386 if (mint < m_maxTemp) {
00387 m_maxTemp = mint;
00388 }
00389 }
00390 #ifdef DEBUG_MODE
00391
00392 double m_p0_k;
00393 if (m_spthermo) {
00394 for (int k = 0; k < m_kk; k++) {
00395 m_p0_k = m_spthermo->refPressure(k);
00396 if (m_p0 != m_p0_k) {
00397
00398
00399
00400
00401
00402
00403 }
00404 }
00405 }
00406
00407 for (int k = 0; k < m_kk; k++) {
00408 const PDSS *kPDSS = m_vptp_ptr->providePDSS(k);
00409 m_p0_k = kPDSS->refPressure();
00410 if (m_p0 != m_p0_k) {
00411
00412
00413
00414
00415
00416
00417 }
00418 }
00419 #endif
00420 }
00421
00422 void VPSSMgr::installSTSpecies(int k, const XML_Node& s,
00423 const XML_Node *phaseNode_ptr) {
00424
00425 SpeciesThermoFactory* f = SpeciesThermoFactory::factory();
00426 f->installThermoForSpecies(k, s, m_vptp_ptr, *m_spthermo, phaseNode_ptr);
00427 if (m_p0 < 0.0) {
00428 m_p0 = m_spthermo->refPressure(k);
00429 }
00430 }
00431
00432 PDSS * VPSSMgr::createInstallPDSS(int k, const XML_Node& s,
00433 const XML_Node *phaseNode_ptr) {
00434 err("VPSSMgr::createInstallPDSS");
00435 return (PDSS *) 0;
00436 }
00437
00438
00439
00440 doublereal VPSSMgr::minTemp(int k) const {
00441 if (k >= 0) {
00442 const PDSS *kPDSS = m_vptp_ptr->providePDSS(k);
00443 return kPDSS->minTemp();
00444 }
00445 return m_minTemp;
00446 }
00447
00448 doublereal VPSSMgr::maxTemp(int k) const {
00449 if (k >= 0) {
00450 const PDSS *kPDSS = m_vptp_ptr->providePDSS(k);
00451 return kPDSS->maxTemp();
00452 }
00453 return m_maxTemp;
00454 }
00455
00456 doublereal VPSSMgr::refPressure(int k) const {
00457 if (k >= 0) {
00458 const PDSS *kPDSS = m_vptp_ptr->providePDSS(k);
00459 return kPDSS->refPressure();
00460 }
00461 return m_p0;
00462 }
00463
00464 PDSS_enumType VPSSMgr::reportPDSSType(int index) const {
00465 err("reportPDSSType()");
00466 return cPDSS_UNDEF;
00467 }
00468
00469
00470 VPSSMgr_enumType VPSSMgr::reportVPSSMgrType() const {
00471 err("reportVPSSType()");
00472 return cVPSSMGR_UNDEF;
00473 }
00474
00475
00476
00477 void VPSSMgr::err(std::string msg) const {
00478 throw CanteraError("VPSSMgr::" + msg, "unimplemented");
00479 }
00480 }
00481
00482