00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef CT_SHOMATEPOLY1_H
00020 #define CT_SHOMATEPOLY1_H
00021
00022 #include "SpeciesThermoInterpType.h"
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
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 class ShomatePoly : public SpeciesThermoInterpType {
00066
00067 public:
00068
00069
00070 ShomatePoly()
00071 : m_lowT(0.0), m_highT (0.0),
00072 m_Pref(0.0), m_index (0) {}
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094 ShomatePoly(int n, doublereal tlow, doublereal thigh, doublereal pref,
00095 const doublereal* coeffs) :
00096 m_lowT (tlow),
00097 m_highT (thigh),
00098 m_Pref (pref),
00099 m_index (n) {
00100 m_coeff.resize(7);
00101 std::copy(coeffs, coeffs + 7, m_coeff.begin());
00102 }
00103
00104
00105
00106
00107
00108 ShomatePoly(const ShomatePoly& b) :
00109 m_lowT (b.m_lowT),
00110 m_highT (b.m_highT),
00111 m_Pref (b.m_Pref),
00112 m_coeff (array_fp(7)),
00113 m_index (b.m_index) {
00114 std::copy(b.m_coeff.begin(),
00115 b.m_coeff.begin() + 7,
00116 m_coeff.begin());
00117 }
00118
00119
00120
00121
00122
00123 ShomatePoly& operator=(const ShomatePoly& b) {
00124 if (&b != this) {
00125 m_lowT = b.m_lowT;
00126 m_highT = b.m_highT;
00127 m_Pref = b.m_Pref;
00128 m_index = b.m_index;
00129 m_coeff.resize(7);
00130 std::copy(b.m_coeff.begin(),
00131 b.m_coeff.begin() + 7,
00132 m_coeff.begin());
00133 }
00134 return *this;
00135 }
00136
00137
00138 virtual ~ShomatePoly(){}
00139
00140
00141 virtual SpeciesThermoInterpType *
00142 duplMyselfAsSpeciesThermoInterpType() const {
00143 ShomatePoly* sp = new ShomatePoly(*this);
00144 return (SpeciesThermoInterpType *) sp;
00145 }
00146
00147
00148
00149 virtual doublereal minTemp() const { return m_lowT;}
00150
00151
00152
00153 virtual doublereal maxTemp() const { return m_highT;}
00154
00155
00156 virtual doublereal refPressure() const { return m_Pref; }
00157
00158
00159 virtual int reportType() const { return SHOMATE; }
00160
00161
00162 virtual int speciesIndex() const { return m_index; }
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189 virtual void updateProperties(const doublereal* tt,
00190 doublereal* cp_R, doublereal* h_RT,
00191 doublereal* s_R) const {
00192
00193 doublereal A = m_coeff[0];
00194 doublereal Bt = m_coeff[1]*tt[0];
00195 doublereal Ct2 = m_coeff[2]*tt[1];
00196 doublereal Dt3 = m_coeff[3]*tt[2];
00197 doublereal Etm2 = m_coeff[4]*tt[3];
00198 doublereal F = m_coeff[5];
00199 doublereal G = m_coeff[6];
00200
00201 doublereal cp, h, s;
00202 cp = A + Bt + Ct2 + Dt3 + Etm2;
00203 h = tt[0]*(A + 0.5*Bt + OneThird*Ct2 + 0.25*Dt3 - Etm2) + F;
00204 s = A*tt[4] + Bt + 0.5*Ct2 + OneThird*Dt3 - 0.5*Etm2 + G;
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215 cp_R[m_index] = 1.e3 * cp * tt[5];
00216 h_RT[m_index] = 1.e6 * h * tt[6];
00217 s_R[m_index] = 1.e3 * s * tt[5];
00218 }
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236 virtual void updatePropertiesTemp(const doublereal temp,
00237 doublereal* cp_R, doublereal* h_RT,
00238 doublereal* s_R) const {
00239 double tPoly[7];
00240 doublereal tt = 1.e-3*temp;
00241 tPoly[0] = tt;
00242 tPoly[1] = tt * tt;
00243 tPoly[2] = tPoly[1] * tt;
00244 tPoly[3] = 1.0/tPoly[1];
00245 tPoly[4] = std::log(tt);
00246 tPoly[5] = 1.0/GasConstant;
00247 tPoly[6] = 1.0/(GasConstant * temp);
00248 updateProperties(tPoly, cp_R, h_RT, s_R);
00249 }
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265 virtual void reportParameters(int &n, int &type,
00266 doublereal &tlow, doublereal &thigh,
00267 doublereal &pref,
00268 doublereal* const coeffs) const {
00269 n = m_index;
00270 type = SHOMATE;
00271 tlow = m_lowT;
00272 thigh = m_highT;
00273 pref = m_Pref;
00274 for (int i = 0; i < 7; i++) {
00275 coeffs[i] = m_coeff[i];
00276 }
00277 }
00278
00279
00280
00281
00282
00283
00284 virtual void modifyParameters(doublereal* coeffs) {
00285 if (m_coeff.size() != 7) {
00286 throw CanteraError("modifyParameters",
00287 "modifying something that hasn't been initialized");
00288 }
00289 std::copy(coeffs, coeffs + 7, m_coeff.begin());
00290 }
00291
00292 #ifdef H298MODIFY_CAPABILITY
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304 virtual doublereal reportHf298(doublereal* const h298 = 0) const {
00305
00306 double tPoly[4];
00307 doublereal tt = 1.e-3*298.15;
00308 tPoly[0] = tt;
00309 tPoly[1] = tt * tt;
00310 tPoly[2] = tPoly[1] * tt;
00311 tPoly[3] = 1.0/tPoly[1];
00312
00313 doublereal A = m_coeff[0];
00314 doublereal Bt = m_coeff[1]*tPoly[0];
00315 doublereal Ct2 = m_coeff[2]*tPoly[1];
00316 doublereal Dt3 = m_coeff[3]*tPoly[2];
00317 doublereal Etm2 = m_coeff[4]*tPoly[3];
00318 doublereal F = m_coeff[5];
00319
00320 doublereal h = tPoly[0]*(A + 0.5*Bt + OneThird*Ct2 + 0.25*Dt3 - Etm2) + F;
00321
00322 double hh = 1.e6 * h;
00323 if (h298) {
00324 h298[m_index] = 1.e6 * h;
00325 }
00326 return hh;
00327 }
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337 virtual void modifyOneHf298(const int k, const doublereal Hf298New) {
00338 doublereal hnow = reportHf298();
00339 doublereal delH = Hf298New - hnow;
00340 m_coeff[5] += delH / 1.0E6;
00341 }
00342
00343 #endif
00344
00345 protected:
00346
00347 doublereal m_lowT;
00348
00349 doublereal m_highT;
00350
00351 doublereal m_Pref;
00352
00353 array_fp m_coeff;
00354
00355 int m_index;
00356
00357 private:
00358
00359 };
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404 class ShomatePoly2 : public SpeciesThermoInterpType {
00405 public:
00406
00407
00408 ShomatePoly2()
00409 : m_lowT(0.0),
00410 m_midT(0.0),
00411 m_highT (0.0),
00412 m_Pref(0.0),
00413 msp_low(0),
00414 msp_high(0),
00415 m_index(0) {
00416 m_coeff.resize(15);
00417 }
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432 ShomatePoly2(int n, doublereal tlow, doublereal thigh, doublereal pref,
00433 const doublereal* coeffs) :
00434 m_lowT (tlow),
00435 m_midT(0.0),
00436 m_highT (thigh),
00437 m_Pref (pref),
00438 msp_low(0),
00439 msp_high(0),
00440 m_index (n) {
00441 m_coeff.resize(15);
00442 std::copy(coeffs, coeffs + 15, m_coeff.begin());
00443 m_midT = coeffs[0];
00444 msp_low = new ShomatePoly(n, tlow, m_midT, pref, coeffs+1);
00445 msp_high = new ShomatePoly(n, m_midT, thigh, pref, coeffs+8);
00446 }
00447
00448
00449
00450
00451
00452 ShomatePoly2(const ShomatePoly2& b) :
00453 m_lowT (b.m_lowT),
00454 m_midT (b.m_midT),
00455 m_highT (b.m_highT),
00456 m_Pref (b.m_Pref),
00457 msp_low(0),
00458 msp_high(0),
00459 m_coeff (array_fp(15)),
00460 m_index (b.m_index) {
00461 std::copy(b.m_coeff.begin(),
00462 b.m_coeff.begin() + 15,
00463 m_coeff.begin());
00464 msp_low = new ShomatePoly(m_index, m_lowT, m_midT,
00465 m_Pref, &m_coeff[1]);
00466 msp_high = new ShomatePoly(m_index, m_midT, m_highT,
00467 m_Pref, &m_coeff[8]);
00468 }
00469
00470
00471
00472
00473
00474 ShomatePoly2& operator=(const ShomatePoly2& b) {
00475 if (&b != this) {
00476 m_lowT = b.m_lowT;
00477 m_midT = b.m_midT;
00478 m_highT = b.m_highT;
00479 m_Pref = b.m_Pref;
00480 m_index = b.m_index;
00481 std::copy(b.m_coeff.begin(),
00482 b.m_coeff.begin() + 15,
00483 m_coeff.begin());
00484 if (msp_low) delete msp_low;
00485 if (msp_high) delete msp_high;
00486 msp_low = new ShomatePoly(m_index, m_lowT, m_midT,
00487 m_Pref, &m_coeff[1]);
00488 msp_high = new ShomatePoly(m_index, m_midT, m_highT,
00489 m_Pref, &m_coeff[8]);
00490 }
00491 return *this;
00492 }
00493
00494
00495 virtual ~ShomatePoly2(){
00496 delete msp_low;
00497 delete msp_high;
00498 }
00499
00500
00501
00502 virtual SpeciesThermoInterpType *
00503 duplMyselfAsSpeciesThermoInterpType() const {
00504 ShomatePoly2* sp = new ShomatePoly2(*this);
00505 return (SpeciesThermoInterpType *) sp;
00506 }
00507
00508
00509
00510 virtual doublereal minTemp() const { return m_lowT;}
00511
00512
00513
00514 virtual doublereal maxTemp() const { return m_highT;}
00515
00516
00517 virtual doublereal refPressure() const { return m_Pref; }
00518
00519
00520 virtual int reportType() const { return SHOMATE2; }
00521
00522
00523 virtual int speciesIndex() const { return m_index; }
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548 virtual void updateProperties(const doublereal* tt,
00549 doublereal* cp_R, doublereal* h_RT,
00550 doublereal* s_R) const {
00551 double T = 1000 * tt[0];
00552 if (T <= m_midT) {
00553 msp_low->updateProperties(tt, cp_R, h_RT, s_R);
00554 } else {
00555 msp_high->updateProperties(tt, cp_R, h_RT, s_R);
00556 }
00557
00558 }
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576 virtual void updatePropertiesTemp(const doublereal temp,
00577 doublereal* cp_R,
00578 doublereal* h_RT,
00579 doublereal* s_R) const {
00580 if (temp <= m_midT) {
00581 msp_low->updatePropertiesTemp(temp, cp_R, h_RT, s_R);
00582 } else {
00583 msp_high->updatePropertiesTemp(temp, cp_R, h_RT, s_R);
00584 }
00585 }
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601 virtual void reportParameters(int &n, int &type,
00602 doublereal &tlow, doublereal &thigh,
00603 doublereal &pref,
00604 doublereal* const coeffs) const {
00605 n = m_index;
00606 type = SHOMATE2;
00607 tlow = m_lowT;
00608 thigh = m_highT;
00609 pref = m_Pref;
00610 for (int i = 0; i < 15; i++) {
00611 coeffs[i] = m_coeff[i];
00612 }
00613 }
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623 virtual void modifyParameters(doublereal* coeffs) {
00624 delete msp_low;
00625 delete msp_high;
00626 std::copy(coeffs, coeffs + 15, m_coeff.begin());
00627 m_midT = coeffs[0];
00628 msp_low = new ShomatePoly(m_index, m_lowT, m_midT, m_Pref, coeffs+1);
00629 msp_high = new ShomatePoly(m_index, m_midT, m_highT, m_Pref, coeffs+8);
00630 }
00631
00632 #ifdef H298MODIFY_CAPABILITY
00633
00634 virtual doublereal reportHf298(doublereal* const h298 = 0) const {
00635 doublereal h;
00636 if (298.15 <= m_midT) {
00637 h = msp_low->reportHf298(h298);
00638 } else {
00639 h = msp_high->reportHf298(h298);
00640 }
00641 if (h298) {
00642 h298[m_index] = h;
00643 }
00644 return h;
00645 }
00646
00647 virtual void modifyOneHf298(const int k, const doublereal Hf298New) {
00648 if (k != m_index) return;
00649
00650 doublereal h298now = reportHf298(0);
00651 doublereal delH = Hf298New - h298now;
00652 double h = msp_low->reportHf298(0);
00653 double hnew = h + delH;
00654 msp_low->modifyOneHf298(k, hnew);
00655 h = msp_high->reportHf298(0);
00656 hnew = h + delH;
00657 msp_high->modifyOneHf298(k, hnew);
00658 }
00659
00660 #endif
00661
00662 protected:
00663
00664 doublereal m_lowT;
00665
00666 doublereal m_midT;
00667
00668 doublereal m_highT;
00669
00670 doublereal m_Pref;
00671
00672 ShomatePoly *msp_low;
00673
00674 ShomatePoly *msp_high;
00675
00676 array_fp m_coeff;
00677
00678 int m_index;
00679 };
00680 }
00681
00682 #endif