00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "WaterPropsIAPWSphi.h"
00016
00017 #include <cstdio>
00018 #include <cmath>
00019
00020 using std::printf;
00021 using std::sqrt;
00022 using std::log;
00023 using std::exp;
00024 using std::pow;
00025 using std::fabs;
00026
00027
00028
00029
00030
00031
00032 static const doublereal T_c = 647.096;
00033 static const doublereal P_c = 22.064E6;
00034 static const doublereal Rho_c = 322.;
00035 static const doublereal M_water = 18.015268;
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 static const doublereal ni0[9] = {
00046 0.0,
00047 -8.32044648201 - 0.000000001739715,
00048 6.6832105268 + 0.000000000793232,
00049 3.00632,
00050 0.012436,
00051 0.97315,
00052 1.27950,
00053 0.96956,
00054 0.24873
00055 };
00056
00057 static const doublereal gammi0[9] = {
00058 0.0,
00059 0.0,
00060 0.0,
00061 0.0,
00062 1.28728967,
00063 3.53734222,
00064 7.74073708,
00065 9.24437796,
00066 27.5075105
00067 };
00068
00069 static const int ciR[56] = {
00070 0,
00071 0,
00072 0,
00073 0,
00074 0,
00075 0,
00076 0,
00077 0,
00078 1,
00079 1,
00080 1,
00081 1,
00082 1,
00083 1,
00084 1,
00085 1,
00086 1,
00087 1,
00088 1,
00089 1,
00090 1,
00091 1,
00092 1,
00093 2,
00094 2,
00095 2,
00096 2,
00097 2,
00098 2,
00099 2,
00100 2,
00101 2,
00102 2,
00103 2,
00104 2,
00105 2,
00106 2,
00107 2,
00108 2,
00109 2,
00110 2,
00111 2,
00112 2,
00113 3,
00114 3,
00115 3,
00116 3,
00117 4,
00118 6,
00119 6,
00120 6,
00121 6,
00122 0,
00123 0,
00124 0,
00125 0
00126 };
00127
00128 static const int diR[55] = {
00129 0,
00130 1,
00131 1,
00132 1,
00133 2,
00134 2,
00135 3,
00136 4,
00137 1,
00138 1,
00139 1,
00140 2,
00141 2,
00142 3,
00143 4,
00144 4,
00145 5,
00146 7,
00147 9,
00148 10,
00149 11,
00150 13,
00151 15,
00152 1,
00153 2,
00154 2,
00155 2,
00156 3,
00157 4,
00158 4,
00159 4,
00160 5,
00161 6,
00162 6,
00163 7,
00164 9,
00165 9,
00166 9,
00167 9,
00168 9,
00169 10,
00170 10,
00171 12,
00172 3,
00173 4,
00174 4,
00175 5,
00176 14,
00177 3,
00178 6,
00179 6,
00180 6,
00181 3,
00182 3,
00183 3
00184 };
00185
00186 static const int tiR[55] = {
00187 0,
00188 0,
00189 0,
00190 0,
00191 0,
00192 0,
00193 0,
00194 0,
00195 4,
00196 6,
00197 12,
00198 1,
00199 5,
00200 4,
00201 2,
00202 13,
00203 9,
00204 3,
00205 4,
00206 11,
00207 4,
00208 13,
00209 1,
00210 7,
00211 1,
00212 9,
00213 10,
00214 10,
00215 3,
00216 7,
00217 10,
00218 10,
00219 6,
00220 10,
00221 10,
00222 1,
00223 2,
00224 3,
00225 4,
00226 8,
00227 6,
00228 9,
00229 8,
00230 16,
00231 22,
00232 23,
00233 23,
00234 10,
00235 50,
00236 44,
00237 46,
00238 50,
00239 0,
00240 1,
00241 4
00242 };
00243
00244 static const doublereal ni[57] = {
00245 +0.0,
00246 +0.12533547935523E-1,
00247 +0.78957634722828E1,
00248 -0.87803203303561E1,
00249 +0.31802509345418E0,
00250 -0.26145533859358E0,
00251 -0.78199751687981E-2,
00252 +0.88089493102134E-2,
00253 -0.66856572307965E0,
00254 +0.20433810950965,
00255 -0.66212605039687E-4,
00256 -0.19232721156002E0,
00257 -0.25709043003438E0,
00258 +0.16074868486251E0,
00259 -0.40092828925807E-1,
00260 +0.39343422603254E-6,
00261 -0.75941377088144E-5,
00262 +0.56250979351888E-3,
00263 -0.15608652257135E-4,
00264 +0.11537996422951E-8,
00265 +0.36582165144204E-6,
00266 -0.13251180074668E-11,
00267 -0.62639586912454E-9,
00268 -0.10793600908932E0,
00269 +0.17611491008752E-1,
00270 +0.22132295167546E0,
00271 -0.40247669763528E0,
00272 +0.58083399985759E0,
00273 +0.49969146990806E-2,
00274 -0.31358700712549E-1,
00275 -0.74315929710341E0,
00276 +0.47807329915480E0,
00277 +0.20527940895948E-1,
00278 -0.13636435110343E0,
00279 +0.14180634400617E-1,
00280 +0.83326504880713E-2,
00281 -0.29052336009585E-1,
00282 +0.38615085574206E-1,
00283 -0.20393486513704E-1,
00284 -0.16554050063734E-2,
00285 +0.19955571979541E-2,
00286 +0.15870308324157E-3,
00287 -0.16388568342530E-4,
00288 +0.43613615723811E-1,
00289 +0.34994005463765E-1,
00290 -0.76788197844621E-1,
00291 +0.22446277332006E-1,
00292 -0.62689710414685E-4,
00293 -0.55711118565645E-9,
00294 -0.19905718354408E0,
00295 +0.31777497330738E0,
00296 -0.11841182425981E0,
00297 -0.31306260323435E2,
00298 +0.31546140237781E2,
00299 -0.25213154341695E4,
00300 -0.14874640856724E0,
00301 +0.31806110878444E0
00302 };
00303
00304
00305 static const doublereal alphai[3] = {
00306 +20.,
00307 +20.,
00308 +20.
00309 };
00310
00311 static const doublereal betai[3] = {
00312 +150.,
00313 +150.,
00314 +250.
00315 };
00316
00317 static const doublereal gammai[3] = {
00318 +1.21,
00319 +1.21,
00320 +1.25
00321 };
00322
00323 static const doublereal epsi[3] = {
00324 +1.0,
00325 +1.0,
00326 +1.0
00327 };
00328
00329 static const doublereal ai[2] = {
00330 +3.5,
00331 +3.5
00332 };
00333
00334 static const doublereal bi[2] = {
00335 +0.85,
00336 +0.95
00337 };
00338
00339 static const doublereal Bi[2] = {
00340 +0.2,
00341 +0.2
00342 };
00343
00344 static const doublereal Ci[2] = {
00345 +28.0,
00346 +32.0
00347 };
00348
00349 static const doublereal Di[2] = {
00350 +700.,
00351 +800.
00352 };
00353
00354 static const doublereal Ai[2] = {
00355 +0.32,
00356 +0.32
00357 };
00358
00359 static const doublereal Bbetai[2] = {
00360 +0.3,
00361 +0.3
00362 };
00363
00364
00365
00366
00367 WaterPropsIAPWSphi::WaterPropsIAPWSphi() :
00368 TAUsave(-1.0),
00369 TAUsqrt(-1.0),
00370 DELTAsave(-1.0)
00371 {
00372 for (int i = 0; i < 52; i++) {
00373 TAUp[i] = 1.0;
00374 }
00375 for (int i = 0; i < 16; i++) {
00376 DELTAp[i] = 1.0;
00377 }
00378 }
00379
00380
00381
00382
00383
00384
00385 void WaterPropsIAPWSphi::intCheck(doublereal tau, doublereal delta) {
00386 tdpolycalc(tau, delta);
00387 doublereal nau = phi0();
00388 doublereal res = phiR();
00389 doublereal res_d = phiR_d();
00390 doublereal nau_d = phi0_d();
00391 doublereal res_dd = phiR_dd();
00392 doublereal nau_dd = phi0_dd();
00393 doublereal res_t = phiR_t();
00394 doublereal nau_t = phi0_t();
00395 doublereal res_tt = phiR_tt();
00396 doublereal nau_tt = phi0_tt();
00397 doublereal res_dt = phiR_dt();
00398 doublereal nau_dt = phi0_dt();
00399
00400 std::printf("nau = %20.12e\t\tres = %20.12e\n", nau, res);
00401 std::printf("nau_d = %20.12e\t\tres_d = %20.12e\n", nau_d, res_d);
00402 printf("nau_dd = %20.12e\t\tres_dd = %20.12e\n", nau_dd, res_dd);
00403 printf("nau_t = %20.12e\t\tres_t = %20.12e\n", nau_t, res_t);
00404 printf("nau_tt = %20.12e\t\tres_tt = %20.12e\n", nau_tt, res_tt);
00405 printf("nau_dt = %20.12e\t\tres_dt = %20.12e\n", nau_dt, res_dt);
00406 }
00407
00408 void WaterPropsIAPWSphi::check1() {
00409 doublereal T = 500.;
00410 doublereal rho = 838.025;
00411 doublereal tau = T_c/T;
00412 doublereal delta = rho / Rho_c;
00413 printf(" T = 500 K, rho = 838.025 kg m-3\n");
00414 intCheck(tau, delta);
00415 }
00416
00417 void WaterPropsIAPWSphi::check2() {
00418 doublereal T = 647;
00419 doublereal rho = 358.0;
00420 doublereal tau = T_c/T;
00421 doublereal delta = rho / Rho_c;
00422 printf(" T = 647 K, rho = 358.0 kg m-3\n");
00423 intCheck(tau, delta);
00424 }
00425
00426
00427
00428
00429
00430 void WaterPropsIAPWSphi::tdpolycalc(doublereal tau, doublereal delta) {
00431 if ((tau != TAUsave) || 1) {
00432 TAUsave = tau;
00433 TAUsqrt = sqrt(tau);
00434 TAUp[0] = 1.0;
00435 for (int i = 1; i < 51; i++) {
00436 TAUp[i] = TAUp[i-1] * tau;
00437 }
00438 }
00439 if ((delta != DELTAsave) || 1) {
00440 DELTAsave = delta;
00441 DELTAp[0] = 1.0;
00442 for (int i = 1; i <= 15; i++) {
00443 DELTAp[i] = DELTAp[i-1] * delta;
00444 }
00445 }
00446 }
00447
00448
00449
00450
00451
00452 doublereal WaterPropsIAPWSphi::phi0() const {
00453 doublereal tau = TAUsave;
00454 doublereal delta = DELTAsave;
00455 doublereal retn = log(delta) + ni0[1] + ni0[2]*tau + ni0[3]*log(tau);
00456
00457 retn += ni0[4] * log(1.0 - exp(-gammi0[4]*tau));
00458 retn += ni0[5] * log(1.0 - exp(-gammi0[5]*tau));
00459 retn += ni0[6] * log(1.0 - exp(-gammi0[6]*tau));
00460 retn += ni0[7] * log(1.0 - exp(-gammi0[7]*tau));
00461 retn += ni0[8] * log(1.0 - exp(-gammi0[8]*tau));
00462 return retn;
00463 }
00464
00465
00466
00467
00468
00469
00470
00471
00472 doublereal WaterPropsIAPWSphi::phiR() const {
00473 doublereal tau = TAUsave;
00474 doublereal delta = DELTAsave;
00475 int i, j;
00476
00477
00478
00479
00480 doublereal T375 = pow(tau, 0.375);
00481 doublereal val = (ni[1] * delta / TAUsqrt +
00482 ni[2] * delta * TAUsqrt * T375 +
00483 ni[3] * delta * tau +
00484 ni[4] * DELTAp[2] * TAUsqrt +
00485 ni[5] * DELTAp[2] * T375 * T375 +
00486 ni[6] * DELTAp[3] * T375 +
00487 ni[7] * DELTAp[4] * tau);
00488
00489
00490
00491 for (i = 8; i <= 51; i++) {
00492 val += (ni[i] * DELTAp[diR[i]] * TAUp[tiR[i]] * exp(-DELTAp[ciR[i]]));
00493 }
00494
00495
00496
00497
00498 for (j = 0; j < 3; j++) {
00499 i = 52 + j;
00500 doublereal dtmp = delta - epsi[j];
00501 doublereal ttmp = tau - gammai[j];
00502 val += (ni[i] * DELTAp[diR[i]] * TAUp[tiR[i]] *
00503 exp(-alphai[j]*dtmp*dtmp - betai[j]*ttmp*ttmp));
00504 }
00505
00506
00507
00508
00509 for (j = 0; j < 2; j++) {
00510 i = 55 + j;
00511 doublereal deltam1 = delta - 1.0;
00512 doublereal dtmp2 = deltam1 * deltam1;
00513 doublereal atmp = 0.5 / Bbetai[j];
00514 doublereal theta = (1.0 - tau) + Ai[j] * pow(dtmp2, atmp);
00515 doublereal triag = theta * theta + Bi[j] * pow(dtmp2, ai[j]);
00516 doublereal ttmp = tau - 1.0;
00517
00518 doublereal triagtmp = pow(triag, bi[j]);
00519
00520 doublereal phi = exp(-Ci[j]*dtmp2 - Di[j]*ttmp*ttmp);
00521 val += (ni[i] * triagtmp * delta * phi);
00522 }
00523
00524 return val;
00525 }
00526
00527
00528
00529
00530
00531 doublereal WaterPropsIAPWSphi::phi(doublereal tau, doublereal delta) {
00532 tdpolycalc(tau, delta);
00533 doublereal nau = phi0();
00534 doublereal res = phiR();
00535 doublereal retn = nau + res;
00536 return retn;
00537 }
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547 doublereal WaterPropsIAPWSphi::phiR_d() const {
00548 doublereal tau = TAUsave;
00549 doublereal delta = DELTAsave;
00550 int i, j;
00551
00552
00553
00554
00555 doublereal T375 = pow(tau, 0.375);
00556 doublereal val = (ni[1] / TAUsqrt +
00557 ni[2] * TAUsqrt * T375 +
00558 ni[3] * tau +
00559 ni[4] * 2.0 * delta * TAUsqrt +
00560 ni[5] * 2.0 * delta * T375 * T375 +
00561 ni[6] * 3.0 * DELTAp[2] * T375 +
00562 ni[7] * 4.0 * DELTAp[3] * tau);
00563
00564
00565
00566 for (i = 8; i <= 51; i++) {
00567 val += ( (ni[i] * exp(-DELTAp[ciR[i]]) * DELTAp[diR[i] - 1] *
00568 TAUp[tiR[i]]) * (diR[i] - ciR[i]* DELTAp[ciR[i]]));
00569 }
00570
00571
00572
00573
00574 for (j = 0; j < 3; j++) {
00575 i = 52 + j;
00576 doublereal dtmp = delta - epsi[j];
00577 doublereal ttmp = tau - gammai[j];
00578 doublereal tmp = (ni[i] * DELTAp[diR[i]] * TAUp[tiR[i]] *
00579 exp(-alphai[j]*dtmp*dtmp - betai[j]*ttmp*ttmp));
00580 val += tmp * (diR[i]/delta - 2.0 * alphai[j] * dtmp);
00581 }
00582
00583
00584
00585
00586 for (j = 0; j < 2; j++) {
00587 i = 55 + j;
00588 doublereal deltam1 = delta - 1.0;
00589 doublereal dtmp2 = deltam1 * deltam1;
00590 doublereal atmp = 0.5 / Bbetai[j];
00591 doublereal theta = (1.0 - tau) + Ai[j] * pow(dtmp2, atmp);
00592 doublereal triag = theta * theta + Bi[j] * pow(dtmp2, ai[j]);
00593 doublereal ttmp = tau - 1.0;
00594
00595 doublereal triagtmp = pow(triag, bi[j]);
00596 doublereal triagtmpm1 = pow(triag, bi[j]-1.0);
00597 doublereal atmpM1 = atmp - 1.0;
00598 doublereal ptmp = pow(dtmp2,atmpM1);
00599 doublereal p2tmp = pow(dtmp2, ai[j]-1.0);
00600 doublereal dtriagddelta =
00601 deltam1 *(Ai[j] * theta * 2.0 / Bbetai[j] * ptmp +
00602 2.0*Bi[j]*ai[j]*p2tmp);
00603
00604 doublereal phi = exp(-Ci[j]*dtmp2 - Di[j]*ttmp*ttmp);
00605 doublereal dphiddelta = -2.0*Ci[j]*deltam1*phi;
00606 doublereal dtriagtmpddelta = bi[j] * triagtmpm1 * dtriagddelta;
00607
00608 doublereal tmp = ni[i] * (triagtmp * (phi + delta*dphiddelta) +
00609 dtriagtmpddelta * delta * phi);
00610 val += tmp;
00611 }
00612
00613 return val;
00614 }
00615
00616
00617
00618
00619
00620
00621
00622
00623 doublereal WaterPropsIAPWSphi::phi0_d() const {
00624 doublereal delta = DELTAsave;
00625 return (1.0/delta);
00626 }
00627
00628
00629
00630
00631
00632
00633 doublereal WaterPropsIAPWSphi::phi_d(doublereal tau, doublereal delta) {
00634 tdpolycalc(tau, delta);
00635 doublereal nau = phi0_d();
00636 doublereal res = phiR_d();
00637 doublereal retn = nau + res;
00638 return retn;
00639 }
00640
00641
00642
00643
00644
00645
00646
00647
00648 doublereal WaterPropsIAPWSphi::pressureM_rhoRT(doublereal tau, doublereal delta) {
00649 tdpolycalc(tau, delta);
00650 doublereal res = phiR_d();
00651 doublereal retn = 1.0 + delta * res;
00652 return retn;
00653 }
00654
00655
00656
00657
00658
00659
00660
00661
00662 doublereal WaterPropsIAPWSphi::phiR_dd() const {
00663 doublereal tau = TAUsave;
00664 doublereal delta = DELTAsave;
00665 int i, j;
00666 doublereal atmp;
00667
00668
00669
00670
00671 doublereal T375 = pow(tau, 0.375);
00672 doublereal val = (ni[4] * 2.0 * TAUsqrt +
00673 ni[5] * 2.0 * T375 * T375 +
00674 ni[6] * 6.0 * delta * T375 +
00675 ni[7] * 12.0 * DELTAp[2] * tau);
00676
00677
00678
00679 for (i = 8; i <= 51; i++) {
00680 doublereal dtmp = DELTAp[ciR[i]];
00681 doublereal tmp = ni[i] * exp(-dtmp) * TAUp[tiR[i]];
00682 if (diR[i] == 1) {
00683 atmp = 1.0/delta;
00684 } else {
00685 atmp = DELTAp[diR[i] - 2];
00686 }
00687 tmp *= atmp *((diR[i] - ciR[i]*dtmp)*(diR[i]-1.0-ciR[i]*dtmp) -
00688 ciR[i]*ciR[i]*dtmp);
00689 val += tmp;
00690 }
00691
00692
00693
00694
00695 for (j = 0; j < 3; j++) {
00696 i = 52 + j;
00697 doublereal dtmp = delta - epsi[j];
00698 doublereal ttmp = tau - gammai[j];
00699 doublereal tmp = (ni[i] * TAUp[tiR[i]] *
00700 exp(-alphai[j]*dtmp*dtmp - betai[j]*ttmp*ttmp));
00701 doublereal deltmp = DELTAp[diR[i]];
00702 doublereal deltmpM1 = deltmp/delta;
00703 doublereal deltmpM2 = deltmpM1 / delta;
00704 doublereal d2tmp = dtmp * dtmp;
00705
00706 val += tmp * (-2.0*alphai[j]*deltmp +
00707 4.0 * alphai[j] * alphai[j] * deltmp * d2tmp -
00708 4.0 * diR[i] * alphai[j] * deltmpM1 * dtmp +
00709 diR[i] * (diR[i] - 1.0) * deltmpM2);
00710 }
00711
00712
00713
00714
00715 for (j = 0; j < 2; j++) {
00716 i = 55 + j;
00717 doublereal deltam1 = delta - 1.0;
00718 doublereal dtmp2 = deltam1 * deltam1;
00719 atmp = 0.5 / Bbetai[j];
00720 doublereal theta = (1.0 - tau) + Ai[j] * pow(dtmp2, atmp);
00721 doublereal triag = theta * theta + Bi[j] * pow(dtmp2, ai[j]);
00722 doublereal ttmp = tau - 1.0;
00723
00724 doublereal triagtmp = pow(triag, bi[j]);
00725 doublereal triagtmpm1 = pow(triag, bi[j]-1.0);
00726 doublereal atmpM1 = atmp - 1.0;
00727 doublereal ptmp = pow(dtmp2,atmpM1);
00728 doublereal p2tmp = pow(dtmp2, ai[j]-1.0);
00729 doublereal dtriagddelta =
00730 deltam1 *(Ai[j] * theta * 2.0 / Bbetai[j] * ptmp +
00731 2.0*Bi[j]*ai[j]*p2tmp);
00732
00733 doublereal phi = exp(-Ci[j]*dtmp2 - Di[j]*ttmp*ttmp);
00734 doublereal dphiddelta = -2.0*Ci[j]*deltam1*phi;
00735 doublereal dtriagtmpddelta = bi[j] * triagtmpm1 * dtriagddelta;
00736
00737
00738 doublereal d2phiddelta2 = 2.0 * Ci[j] * phi * (2.0*Ci[j]*dtmp2 - 1.0);
00739
00740 doublereal pptmp = ptmp / dtmp2;
00741 doublereal d2triagddelta2 = dtriagddelta / deltam1;
00742 d2triagddelta2 +=
00743 dtmp2 *(4.0*Bi[j]*ai[j]*(ai[j]-1.0)*pow(dtmp2,ai[j]-2.0) +
00744 2.0*Ai[j]*Ai[j]/(Bbetai[j]*Bbetai[j])*ptmp*ptmp +
00745 Ai[j]*theta*4.0/Bbetai[j]*(atmp-1.0)*pptmp);
00746
00747 doublereal d2triagtmpd2delta =
00748 bi[j] * (triagtmpm1 * d2triagddelta2 +
00749 (bi[j]-1.0)*triagtmpm1/triag*dtriagddelta*dtriagddelta);
00750
00751 doublereal ctmp = (triagtmp * (2.0*dphiddelta + delta*d2phiddelta2) +
00752 2.0*dtriagtmpddelta*(phi + delta * dphiddelta) +
00753 d2triagtmpd2delta * delta * phi);
00754
00755 val += ni[i] * ctmp;
00756 }
00757
00758 return val;
00759 }
00760
00761
00762
00763
00764
00765
00766
00767
00768 doublereal WaterPropsIAPWSphi::phi0_dd() const {
00769 doublereal delta = DELTAsave;
00770 return (-1.0/(delta*delta));
00771 }
00772
00773
00774
00775
00776
00777
00778 doublereal WaterPropsIAPWSphi::phi_dd(doublereal tau, doublereal delta) {
00779 tdpolycalc(tau, delta);
00780 doublereal nau = phi0_dd();
00781 doublereal res = phiR_dd();
00782 doublereal retn = nau + res;
00783 return retn;
00784 }
00785
00786 doublereal WaterPropsIAPWSphi::dimdpdrho(doublereal tau, doublereal delta) {
00787 tdpolycalc(tau, delta);
00788 doublereal res1 = phiR_d();
00789 doublereal res2 = phiR_dd();
00790 doublereal retn = 1.0 + delta * (2.0*res1 + delta*res2);
00791 return retn;
00792 }
00793
00794 doublereal WaterPropsIAPWSphi::dimdpdT(doublereal tau, doublereal delta) {
00795 tdpolycalc(tau, delta);
00796 doublereal res1 = phiR_d();
00797 doublereal res2 = phiR_dt();
00798 doublereal retn = (1.0 + delta * res1) - tau * delta * (res2);
00799 return retn;
00800 }
00801
00802
00803
00804
00805 doublereal WaterPropsIAPWSphi::phi0_t() const {
00806 doublereal tau = TAUsave;
00807 doublereal retn = ni0[2] + ni0[3]/tau;;
00808 retn += (ni0[4] * gammi0[4] * (1.0/(1.0 - exp(-gammi0[4]*tau)) - 1.0));
00809 retn += (ni0[5] * gammi0[5] * (1.0/(1.0 - exp(-gammi0[5]*tau)) - 1.0));
00810 retn += (ni0[6] * gammi0[6] * (1.0/(1.0 - exp(-gammi0[6]*tau)) - 1.0));
00811 retn += (ni0[7] * gammi0[7] * (1.0/(1.0 - exp(-gammi0[7]*tau)) - 1.0));
00812 retn += (ni0[8] * gammi0[8] * (1.0/(1.0 - exp(-gammi0[8]*tau)) - 1.0));
00813 return retn;
00814 }
00815
00816
00817
00818
00819
00820
00821
00822
00823 doublereal WaterPropsIAPWSphi::phiR_t() const {
00824 doublereal tau = TAUsave;
00825 doublereal delta = DELTAsave;
00826 int i, j;
00827 doublereal atmp, tmp;
00828
00829
00830
00831
00832 doublereal T375 = pow(tau, 0.375);
00833 doublereal val = ((-0.5) *ni[1] * delta / TAUsqrt / tau +
00834 ni[2] * delta * 0.875 / TAUsqrt * T375 +
00835 ni[3] * delta +
00836 ni[4] * DELTAp[2] * 0.5 / TAUsqrt +
00837 ni[5] * DELTAp[2] * 0.75 * T375 * T375 / tau +
00838 ni[6] * DELTAp[3] * 0.375 * T375 / tau +
00839 ni[7] * DELTAp[4]);
00840
00841
00842
00843 for (i = 8; i <= 51; i++) {
00844 tmp = (ni[i] * DELTAp[diR[i]] * TAUp[tiR[i]-1] * exp(-DELTAp[ciR[i]]));
00845 val += tiR[i] * tmp;
00846 }
00847
00848
00849
00850
00851 for (j = 0; j < 3; j++) {
00852 i = 52 + j;
00853 doublereal dtmp = delta - epsi[j];
00854 doublereal ttmp = tau - gammai[j];
00855 tmp = (ni[i] * DELTAp[diR[i]] * TAUp[tiR[i]] *
00856 exp(-alphai[j]*dtmp*dtmp - betai[j]*ttmp*ttmp));
00857 val += tmp *(tiR[i]/tau - 2.0 * betai[j]*ttmp);
00858 }
00859
00860
00861
00862
00863 for (j = 0; j < 2; j++) {
00864 i = 55 + j;
00865 doublereal deltam1 = delta - 1.0;
00866 doublereal dtmp2 = deltam1 * deltam1;
00867 atmp = 0.5 / Bbetai[j];
00868 doublereal theta = (1.0 - tau) + Ai[j] * pow(dtmp2, atmp);
00869 doublereal triag = theta * theta + Bi[j] * pow(dtmp2, ai[j]);
00870 doublereal ttmp = tau - 1.0;
00871
00872 doublereal triagtmp = pow(triag, bi[j]);
00873
00874 doublereal phi = exp(-Ci[j]*dtmp2 - Di[j]*ttmp*ttmp);
00875
00876
00877 doublereal dtriagtmpdtau = -2.0*theta * bi[j] * triagtmp / triag;
00878
00879 doublereal dphidtau = - 2.0 * Di[j] * ttmp * phi;
00880
00881 val += ni[i] * delta * (dtriagtmpdtau * phi + triagtmp * dphidtau);
00882 }
00883
00884 return val;
00885 }
00886
00887
00888
00889
00890
00891
00892 doublereal WaterPropsIAPWSphi::phi_t(doublereal tau, doublereal delta) {
00893 tdpolycalc(tau, delta);
00894 doublereal nau = phi0_t();
00895 doublereal res = phiR_t();
00896 doublereal retn = nau + res;
00897 return retn;
00898 }
00899
00900
00901
00902
00903 doublereal WaterPropsIAPWSphi::phi0_tt() const {
00904 doublereal tau = TAUsave;
00905 doublereal tmp, itmp;
00906 doublereal retn = - ni0[3]/(tau * tau);
00907 for (int i = 4; i <= 8; i++) {
00908 tmp = exp(-gammi0[i]*tau);
00909 itmp = 1.0 - tmp;
00910 retn -= (ni0[i] * gammi0[i] * gammi0[i] * tmp / (itmp * itmp));
00911 }
00912 return retn;
00913 }
00914
00915
00916
00917
00918
00919
00920
00921
00922 doublereal WaterPropsIAPWSphi::phiR_tt() const {
00923 doublereal tau = TAUsave;
00924 doublereal delta = DELTAsave;
00925 int i, j;
00926 doublereal atmp, tmp;
00927
00928
00929
00930
00931 doublereal T375 = pow(tau, 0.375);
00932 doublereal val = ((-0.5) * (-1.5) * ni[1] * delta / (TAUsqrt * tau * tau) +
00933 ni[2] * delta * 0.875 * (-0.125) * T375 / (TAUsqrt * tau) +
00934 ni[4] * DELTAp[2] * 0.5 * (-0.5)/ (TAUsqrt * tau) +
00935 ni[5] * DELTAp[2] * 0.75 *(-0.25) * T375 * T375 / (tau * tau) +
00936 ni[6] * DELTAp[3] * 0.375 *(-0.625) * T375 / (tau * tau));
00937
00938
00939
00940 for (i = 8; i <= 51; i++) {
00941 if (tiR[i] > 1) {
00942 tmp = (ni[i] * DELTAp[diR[i]] * TAUp[tiR[i]-2] * exp(-DELTAp[ciR[i]]));
00943 val += tiR[i] * (tiR[i] - 1.0) * tmp;
00944 }
00945 }
00946
00947
00948
00949
00950 for (j = 0; j < 3; j++) {
00951 i = 52 + j;
00952 doublereal dtmp = delta - epsi[j];
00953 doublereal ttmp = tau - gammai[j];
00954 tmp = (ni[i] * DELTAp[diR[i]] * TAUp[tiR[i]] *
00955 exp(-alphai[j]*dtmp*dtmp - betai[j]*ttmp*ttmp));
00956 atmp = tiR[i]/tau - 2.0 * betai[j]*ttmp;
00957 val += tmp *(atmp * atmp - tiR[i]/(tau*tau) - 2.0*betai[j]);
00958 }
00959
00960
00961
00962
00963 for (j = 0; j < 2; j++) {
00964 i = 55 + j;
00965 doublereal deltam1 = delta - 1.0;
00966 doublereal dtmp2 = deltam1 * deltam1;
00967 atmp = 0.5 / Bbetai[j];
00968 doublereal theta = (1.0 - tau) + Ai[j] * pow(dtmp2, atmp);
00969 doublereal triag = theta * theta + Bi[j] * pow(dtmp2, ai[j]);
00970 doublereal ttmp = tau - 1.0;
00971
00972 doublereal triagtmp = pow(triag, bi[j]);
00973 doublereal triagtmpM1 = triagtmp / triag;
00974
00975 doublereal phi = exp(-Ci[j]*dtmp2 - Di[j]*ttmp*ttmp);
00976
00977
00978 doublereal dtriagtmpdtau = -2.0*theta * bi[j] * triagtmp / triag;
00979
00980 doublereal dphidtau = - 2.0 * Di[j] * ttmp * phi;
00981
00982 doublereal d2triagtmpdtau2 =
00983 (2 * bi[j] * triagtmpM1 +
00984 4 * theta * theta * bi[j] * (bi[j]-1.0) * triagtmpM1 / triag);
00985
00986 doublereal d2phidtau2 = 2.0*Di[j]*phi *(2.0*Di[j]*ttmp*ttmp - 1.0);
00987
00988 tmp = (d2triagtmpdtau2 * phi +
00989 2 * dtriagtmpdtau * dphidtau +
00990 triagtmp * d2phidtau2);
00991 val += ni[i] * delta * tmp;
00992 }
00993
00994 return val;
00995 }
00996
00997
00998
00999
01000
01001
01002 doublereal WaterPropsIAPWSphi::phi_tt(doublereal tau, doublereal delta) {
01003 tdpolycalc(tau, delta);
01004 doublereal nau = phi0_tt();
01005 doublereal res = phiR_tt();
01006 doublereal retn = nau + res;
01007 return retn;
01008 }
01009
01010
01011
01012
01013 doublereal WaterPropsIAPWSphi::phi0_dt() const {
01014 return 0.0;
01015 }
01016
01017
01018
01019
01020
01021
01022
01023
01024 doublereal WaterPropsIAPWSphi::phiR_dt() const {
01025 doublereal tau = TAUsave;
01026 doublereal delta = DELTAsave;
01027 int i, j;
01028 doublereal tmp;
01029
01030
01031
01032 doublereal T375 = pow(tau, 0.375);
01033 doublereal val = (ni[1] * (-0.5) / (TAUsqrt * tau) +
01034 ni[2] * (0.875) * T375 / TAUsqrt +
01035 ni[3] +
01036 ni[4] * 2.0 * delta * (0.5) / TAUsqrt +
01037 ni[5] * 2.0 * delta * (0.75) * T375 * T375 / tau +
01038 ni[6] * 3.0 * DELTAp[2] * 0.375 * T375 / tau +
01039 ni[7] * 4.0 * DELTAp[3]);
01040
01041
01042
01043 for (i = 8; i <= 51; i++) {
01044 tmp = (ni[i] * tiR[i] * exp(-DELTAp[ciR[i]]) * DELTAp[diR[i] - 1] *
01045 TAUp[tiR[i] - 1]);
01046 val += tmp * (diR[i] - ciR[i] * DELTAp[ciR[i]]);
01047 }
01048
01049
01050
01051
01052 for (j = 0; j < 3; j++) {
01053 i = 52 + j;
01054 doublereal dtmp = delta - epsi[j];
01055 doublereal ttmp = tau - gammai[j];
01056 tmp = (ni[i] * DELTAp[diR[i]] * TAUp[tiR[i]] *
01057 exp(-alphai[j]*dtmp*dtmp - betai[j]*ttmp*ttmp));
01058 val += tmp * ((diR[i]/delta - 2.0 * alphai[j] * dtmp) *
01059 (tiR[i]/tau - 2.0 * betai[j] * ttmp));
01060 }
01061
01062
01063
01064
01065 for (j = 0; j < 2; j++) {
01066 i = 55 + j;
01067 doublereal deltam1 = delta - 1.0;
01068 doublereal dtmp2 = deltam1 * deltam1;
01069 doublereal atmp = 0.5 / Bbetai[j];
01070 doublereal theta = (1.0 - tau) + Ai[j] * pow(dtmp2, atmp);
01071 doublereal triag = theta * theta + Bi[j] * pow(dtmp2, ai[j]);
01072 doublereal ttmp = tau - 1.0;
01073
01074 doublereal triagtmp = pow(triag, bi[j]);
01075 doublereal triagtmpm1 = pow(triag, bi[j]-1.0);
01076 doublereal atmpM1 = atmp - 1.0;
01077 doublereal ptmp = pow(dtmp2,atmpM1);
01078 doublereal p2tmp = pow(dtmp2, ai[j]-1.0);
01079 doublereal dtriagddelta =
01080 deltam1 *(Ai[j] * theta * 2.0 / Bbetai[j] * ptmp +
01081 2.0*Bi[j]*ai[j]*p2tmp);
01082
01083 doublereal phi = exp(-Ci[j]*dtmp2 - Di[j]*ttmp*ttmp);
01084 doublereal dphiddelta = -2.0*Ci[j]*deltam1*phi;
01085 doublereal dtriagtmpddelta = bi[j] * triagtmpm1 * dtriagddelta;
01086
01087
01088 doublereal dtriagtmpdtau = -2.0*theta * bi[j] * triagtmp / triag;
01089
01090 doublereal dphidtau = - 2.0 * Di[j] * ttmp * phi;
01091
01092 doublereal d2phiddeltadtau = 4.0 * Ci[j] * Di[j] * deltam1 * ttmp * phi;
01093
01094 doublereal d2triagtmpddeltadtau =
01095 ( -Ai[j] * bi[j] * 2.0 / Bbetai[j] * triagtmpm1 * deltam1 * ptmp
01096 -2.0 * theta * bi[j] * (bi[j] - 1.0) * triagtmpm1 / triag * dtriagddelta);
01097
01098
01099 doublereal tmp = ni[i] * (triagtmp * (dphidtau + delta*d2phiddeltadtau) +
01100 delta * dtriagtmpddelta * dphidtau +
01101 dtriagtmpdtau * (phi + delta * dphiddelta) +
01102 d2triagtmpddeltadtau * delta * phi);
01103 val += tmp;
01104 }
01105
01106 return val;
01107 }
01108
01109
01110
01111
01112
01113
01114
01115
01116 doublereal WaterPropsIAPWSphi::dfind(doublereal p_red, doublereal tau, doublereal deltaGuess) {
01117 doublereal dd = deltaGuess;
01118 bool conv = false;
01119 doublereal deldd = dd;
01120 doublereal pcheck = 1.0E-30 + 1.0E-8 * p_red;
01121 for (int n = 0; n < 200; n++) {
01122
01123
01124
01125
01126 tdpolycalc(tau, dd);
01127 doublereal q1 = phiR_d();
01128 doublereal q2 = phiR_dd();
01129
01130
01131
01132
01133
01134 doublereal pred0 = dd + dd * dd * q1;
01135
01136
01137
01138
01139 doublereal dpddelta = 1.0 + 2.0 * dd * q1 + dd * dd * q2;
01140
01141
01142
01143
01144
01145 if (dpddelta <= 0.0) {
01146 if (deltaGuess > 1.0) dd = dd * 1.05;
01147 if (deltaGuess < 1.0) dd = dd * 0.95;
01148 continue;
01149 }
01150
01151
01152
01153 if (fabs(pred0-p_red) < pcheck) {
01154 conv = true;
01155 break;
01156 }
01157
01158
01159
01160
01161 doublereal dpdx = dpddelta;
01162 if (n < 10) {
01163 dpdx = dpddelta * 1.1;
01164 }
01165 if (dpdx < 0.001) dpdx = 0.001;
01166
01167
01168
01169
01170
01171
01172 deldd = - (pred0 - p_red) / dpdx;
01173 if (fabs(deldd) > 0.05) {
01174 deldd = deldd * 0.05 / fabs(deldd);
01175 }
01176
01177
01178
01179 dd = dd + deldd;
01180 if (fabs(deldd/dd) < 1.0E-14) {
01181 conv = true;
01182 break;
01183 }
01184
01185
01186
01187 if (dd <= 0.0) {
01188 dd = 1.0E-24;
01189 }
01190 }
01191
01192
01193
01194 if (! conv) {
01195 dd = 0.0;
01196 }
01197 return dd;
01198 }
01199
01200
01201
01202
01203 doublereal WaterPropsIAPWSphi::gibbs_RT() const {
01204 doublereal delta = DELTAsave;
01205 doublereal rd = phiR_d();
01206 doublereal g = 1.0 + phi0() + phiR() + delta * rd;
01207 return g;
01208 }
01209
01210
01211
01212
01213 doublereal WaterPropsIAPWSphi::enthalpy_RT() const {
01214 doublereal delta = DELTAsave;
01215 doublereal tau = TAUsave;
01216 doublereal rd = phiR_d();
01217 doublereal nt = phi0_t();
01218 doublereal rt = phiR_t();
01219 doublereal hRT = 1.0 + tau * (nt + rt) + delta * rd;
01220 return hRT;
01221 }
01222
01223
01224
01225
01226 doublereal WaterPropsIAPWSphi::entropy_R() const {
01227 doublereal tau = TAUsave;
01228 doublereal nt = phi0_t();
01229 doublereal rt = phiR_t();
01230 doublereal p0 = phi0();
01231 doublereal pR = phiR();
01232 doublereal sR = tau * (nt + rt) - p0 - pR;
01233 return sR;
01234 }
01235
01236
01237
01238
01239 doublereal WaterPropsIAPWSphi::intEnergy_RT() const {
01240 doublereal tau = TAUsave;
01241 doublereal nt = phi0_t();
01242 doublereal rt = phiR_t();
01243 doublereal uR = tau * (nt + rt);
01244 return uR;
01245 }
01246
01247
01248
01249
01250 doublereal WaterPropsIAPWSphi::cv_R() const {
01251 doublereal tau = TAUsave;
01252 doublereal ntt = phi0_tt();
01253 doublereal rtt = phiR_tt();
01254 doublereal cvR = - tau * tau * (ntt + rtt);
01255 return cvR;
01256 }
01257
01258
01259
01260
01261 doublereal WaterPropsIAPWSphi::cp_R() const {
01262 doublereal tau = TAUsave;
01263 doublereal delta = DELTAsave;
01264 doublereal cvR = cv_R();
01265
01266 doublereal rd = phiR_d();
01267 doublereal rdd = phiR_dd();
01268 doublereal rdt = phiR_dt();
01269 doublereal num = (1.0 + delta * rd - delta * tau * rdt);
01270 doublereal cpR = cvR + (num * num /
01271 (1.0 + 2.0 * delta * rd + delta * delta * rdd));
01272 return cpR;
01273 }
01274