00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifdef WIN32
00014 #pragma warning(disable:4786)
00015 #pragma warning(disable:4503)
00016 #endif
00017
00018 #include "ct_defs.h"
00019 #include "mix_defs.h"
00020 #include "IdealGasPhase.h"
00021 #include "SpeciesThermo.h"
00022
00023 using namespace std;
00024
00025 namespace Cantera {
00026
00027 IdealGasPhase::IdealGasPhase():
00028 m_mm(0),
00029 m_tmin(0.0),
00030 m_tmax(0.0),
00031 m_p0(-1.0),
00032 m_tlast(0.0),
00033 m_logc0(0.0)
00034 {
00035 }
00036
00037
00038 IdealGasPhase::IdealGasPhase(const IdealGasPhase& right):
00039 m_mm(right.m_mm),
00040 m_tmin(right.m_tmin),
00041 m_tmax(right.m_tmax),
00042 m_p0(right.m_p0),
00043 m_tlast(right.m_tlast),
00044 m_logc0(right.m_logc0)
00045 {
00046
00047
00048
00049
00050 *this = right;
00051 }
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 IdealGasPhase& IdealGasPhase::
00062 operator=(const IdealGasPhase &right) {
00063 if (&right != this) {
00064 ThermoPhase::operator=(right);
00065 m_mm = right.m_mm;
00066 m_tmin = right.m_tmin;
00067 m_tmax = right.m_tmax;
00068 m_p0 = right.m_p0;
00069 m_tlast = right.m_tlast;
00070 m_logc0 = right.m_logc0;
00071 m_h0_RT = right.m_h0_RT;
00072 m_cp0_R = right.m_cp0_R;
00073 m_g0_RT = right.m_g0_RT;
00074 m_s0_R = right.m_s0_R;
00075 m_expg0_RT= right.m_expg0_RT;
00076 m_pe = right.m_pe;
00077 m_pp = right.m_pp;
00078 }
00079 return *this;
00080 }
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 ThermoPhase *IdealGasPhase::duplMyselfAsThermoPhase() const {
00091 ThermoPhase *igp = new IdealGasPhase(*this);
00092 return (ThermoPhase *) igp;
00093 }
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108 doublereal IdealGasPhase::intEnergy_mole() const {
00109 return GasConstant * temperature()
00110 * ( mean_X(&enthalpy_RT_ref()[0]) - 1.0);
00111 }
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 doublereal IdealGasPhase::entropy_mole() const {
00125 return GasConstant * (mean_X(&entropy_R_ref()[0]) -
00126 sum_xlogx() - std::log(pressure()/m_spthermo->refPressure()));
00127 }
00128
00129
00130
00131
00132
00133 doublereal IdealGasPhase::gibbs_mole() const {
00134 return enthalpy_mole() - temperature() * entropy_mole();
00135 }
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148 doublereal IdealGasPhase::cp_mole() const {
00149 return GasConstant * mean_X(&cp_R_ref()[0]);
00150 }
00151
00152
00153
00154
00155
00156
00157 doublereal IdealGasPhase::cv_mole() const {
00158 return cp_mole() - GasConstant;
00159 }
00160
00161
00162
00163
00164
00165
00166
00167
00168 doublereal IdealGasPhase::standardConcentration(int k) const {
00169 double p = pressure();
00170 return p/(GasConstant * temperature());
00171 }
00172
00173
00174
00175
00176
00177 doublereal IdealGasPhase::logStandardConc(int k) const {
00178 _updateThermo();
00179 double p = pressure();
00180 double lc = std::log (p / (GasConstant * temperature()));
00181 return lc;
00182 }
00183
00184
00185
00186
00187 void IdealGasPhase::getActivityCoefficients(doublereal *ac) const {
00188 for (int k = 0; k < m_kk; k++) {
00189 ac[k] = 1.0;
00190 }
00191 }
00192
00193
00194
00195
00196
00197 void IdealGasPhase::getStandardChemPotentials(doublereal* muStar) const {
00198 const array_fp& gibbsrt = gibbs_RT_ref();
00199 scale(gibbsrt.begin(), gibbsrt.end(), muStar, _RT());
00200 double tmp = log (pressure() /m_spthermo->refPressure());
00201 tmp *= GasConstant * temperature();
00202 for (int k = 0; k < m_kk; k++) {
00203 muStar[k] += tmp;
00204 }
00205 }
00206
00207
00208
00209 void IdealGasPhase::getChemPotentials(doublereal* mu) const {
00210 getStandardChemPotentials(mu);
00211
00212 doublereal xx;
00213 doublereal rt = temperature() * GasConstant;
00214
00215 for (int k = 0; k < m_kk; k++) {
00216 xx = fmaxx(SmallNumber, moleFraction(k));
00217 mu[k] += rt*(log(xx));
00218 }
00219 }
00220
00221
00222
00223
00224
00225 void IdealGasPhase::getPartialMolarEnthalpies(doublereal* hbar) const {
00226 const array_fp& _h = enthalpy_RT_ref();
00227 doublereal rt = GasConstant * temperature();
00228 scale(_h.begin(), _h.end(), hbar, rt);
00229 }
00230
00231
00232
00233
00234
00235 void IdealGasPhase::getPartialMolarEntropies(doublereal* sbar) const {
00236 const array_fp& _s = entropy_R_ref();
00237 doublereal r = GasConstant;
00238 scale(_s.begin(), _s.end(), sbar, r);
00239 doublereal logp = log(pressure()/m_spthermo->refPressure());
00240 for (int k = 0; k < m_kk; k++) {
00241 doublereal xx = fmaxx(SmallNumber, moleFraction(k));
00242 sbar[k] += r * (- logp - log(xx));
00243 }
00244 }
00245
00246
00247
00248
00249
00250 void IdealGasPhase::getPartialMolarIntEnergies(doublereal* ubar) const {
00251 const array_fp& _h = enthalpy_RT_ref();
00252 doublereal rt = GasConstant * temperature();
00253 for (int k = 0; k < m_kk; k++) {
00254 ubar[k] = rt * (_h[k] - 1.0);
00255 }
00256 }
00257
00258
00259
00260
00261 void IdealGasPhase::getPartialMolarCp(doublereal* cpbar) const {
00262 const array_fp& _cp = cp_R_ref();
00263 scale(_cp.begin(), _cp.end(), cpbar, GasConstant);
00264 }
00265
00266
00267
00268
00269
00270 void IdealGasPhase::getPartialMolarVolumes(doublereal* vbar) const {
00271 double vol = 1.0 / molarDensity();
00272 for (int k = 0; k < m_kk; k++) {
00273 vbar[k] = vol;
00274 }
00275 }
00276
00277
00278
00279
00280
00281
00282
00283
00284 void IdealGasPhase::getEnthalpy_RT(doublereal* hrt) const {
00285 const array_fp& _h = enthalpy_RT_ref();
00286 copy(_h.begin(), _h.end(), hrt);
00287 }
00288
00289
00290
00291
00292
00293
00294 void IdealGasPhase::getEntropy_R(doublereal* sr) const {
00295 const array_fp& _s = entropy_R_ref();
00296 copy(_s.begin(), _s.end(), sr);
00297 double tmp = log (pressure() /m_spthermo->refPressure());
00298 for (int k = 0; k < m_kk; k++) {
00299 sr[k] -= tmp;
00300 }
00301 }
00302
00303
00304
00305
00306
00307 void IdealGasPhase::getGibbs_RT(doublereal* grt) const {
00308 const array_fp& gibbsrt = gibbs_RT_ref();
00309 copy(gibbsrt.begin(), gibbsrt.end(), grt);
00310 double tmp = log (pressure() /m_spthermo->refPressure());
00311 for (int k = 0; k < m_kk; k++) {
00312 grt[k] += tmp;
00313 }
00314 }
00315
00316
00317
00318
00319
00320
00321 void IdealGasPhase::getPureGibbs(doublereal* gpure) const {
00322 const array_fp& gibbsrt = gibbs_RT_ref();
00323 scale(gibbsrt.begin(), gibbsrt.end(), gpure, _RT());
00324 double tmp = log (pressure() /m_spthermo->refPressure());
00325 tmp *= _RT();
00326 for (int k = 0; k < m_kk; k++) {
00327 gpure[k] += tmp;
00328 }
00329 }
00330
00331
00332
00333
00334
00335
00336 void IdealGasPhase::getIntEnergy_RT(doublereal *urt) const {
00337 const array_fp& _h = enthalpy_RT_ref();
00338 for (int k = 0; k < m_kk; k++) {
00339 urt[k] = _h[k] - 1.0;
00340 }
00341 }
00342
00343
00344
00345
00346
00347
00348 void IdealGasPhase::getCp_R(doublereal* cpr) const {
00349 const array_fp& _cpr = cp_R_ref();
00350 copy(_cpr.begin(), _cpr.end(), cpr);
00351 }
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361 void IdealGasPhase::getStandardVolumes(doublereal *vol) const {
00362 double tmp = 1.0 / molarDensity();
00363 for (int k = 0; k < m_kk; k++) {
00364 vol[k] = tmp;
00365 }
00366 }
00367
00368
00369
00370
00371
00372
00373
00374
00375 void IdealGasPhase::getEnthalpy_RT_ref(doublereal *hrt) const {
00376 const array_fp& _h = enthalpy_RT_ref();
00377 copy(_h.begin(), _h.end(), hrt);
00378 }
00379
00380
00381
00382
00383
00384
00385 void IdealGasPhase::getGibbs_RT_ref(doublereal *grt) const {
00386 const array_fp& gibbsrt = gibbs_RT_ref();
00387 copy(gibbsrt.begin(), gibbsrt.end(), grt);
00388 }
00389
00390
00391
00392
00393
00394
00395
00396 void IdealGasPhase::getGibbs_ref(doublereal *g) const {
00397 const array_fp& gibbsrt = gibbs_RT_ref();
00398 scale(gibbsrt.begin(), gibbsrt.end(), g, _RT());
00399 }
00400
00401
00402
00403
00404
00405
00406 void IdealGasPhase::getEntropy_R_ref(doublereal *er) const {
00407 const array_fp& _s = entropy_R_ref();
00408 copy(_s.begin(), _s.end(), er);
00409 }
00410
00411
00412
00413
00414
00415
00416 void IdealGasPhase::getIntEnergy_RT_ref(doublereal *urt) const {
00417 const array_fp& _h = enthalpy_RT_ref();
00418 for (int k = 0; k < m_kk; k++) {
00419 urt[k] = _h[k] - 1.0;
00420 }
00421 }
00422
00423
00424
00425
00426
00427
00428 void IdealGasPhase::getCp_R_ref(doublereal *cprt) const {
00429 const array_fp& _cpr = cp_R_ref();
00430 copy(_cpr.begin(), _cpr.end(), cprt);
00431 }
00432
00433 void IdealGasPhase::getStandardVolumes_ref(doublereal *vol) const {
00434 doublereal tmp = _RT() / m_p0;
00435 for (int k = 0; k < m_kk; k++) {
00436 vol[k] = tmp;
00437 }
00438 }
00439
00440
00441
00442
00443
00444 void IdealGasPhase::initThermo() {
00445
00446 m_mm = nElements();
00447 doublereal tmin = m_spthermo->minTemp();
00448 doublereal tmax = m_spthermo->maxTemp();
00449 if (tmin > 0.0) m_tmin = tmin;
00450 if (tmax > 0.0) m_tmax = tmax;
00451 m_p0 = refPressure();
00452
00453 int leng = m_kk;
00454 m_h0_RT.resize(leng);
00455 m_g0_RT.resize(leng);
00456 m_expg0_RT.resize(leng);
00457 m_cp0_R.resize(leng);
00458 m_s0_R.resize(leng);
00459 m_pe.resize(leng, 0.0);
00460 m_pp.resize(leng);
00461 }
00462
00463
00464
00465
00466
00467
00468 void IdealGasPhase::setToEquilState(const doublereal* mu_RT)
00469 {
00470 double tmp, tmp2;
00471 const array_fp& grt = gibbs_RT_ref();
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481 doublereal pres = 0.0;
00482 for (int k = 0; k < m_kk; k++) {
00483 tmp = -grt[k] + mu_RT[k];
00484 if (tmp < -600.) {
00485 m_pp[k] = 0.0;
00486 } else if (tmp > 500.0) {
00487 tmp2 = tmp / 500.;
00488 tmp2 *= tmp2;
00489 m_pp[k] = m_p0 * exp(500.) * tmp2;
00490 } else {
00491 m_pp[k] = m_p0 * exp(tmp);
00492 }
00493 pres += m_pp[k];
00494 }
00495
00496 setState_PX(pres, &m_pp[0]);
00497 }
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511 void IdealGasPhase::_updateThermo() const {
00512 doublereal tnow = temperature();
00513
00514
00515
00516 if (m_tlast != tnow) {
00517 m_spthermo->update(tnow, &m_cp0_R[0], &m_h0_RT[0],
00518 &m_s0_R[0]);
00519 m_tlast = tnow;
00520
00521
00522 int k;
00523 for (k = 0; k < m_kk; k++) {
00524 m_g0_RT[k] = m_h0_RT[k] - m_s0_R[k];
00525 }
00526 m_logc0 = log(m_p0/(GasConstant * tnow));
00527 m_tlast = tnow;
00528 }
00529 }
00530 }
00531