├── test ├── _input.dat └── _properties.dat ├── .vscode └── settings.json ├── .github └── workflows │ └── c-cpp.yml ├── region_calc.h ├── .gitignore ├── if97_general.c ├── LICENSE ├── if97_general.h ├── steam_property_calc.h ├── region5.h ├── region1.h ├── region2.h ├── region_calc.c ├── region3.h ├── README.md ├── ws-if97-main.c ├── region5.c ├── region1.c ├── region2.c ├── steam_property_calc.c └── region3.c /test/_input.dat: -------------------------------------------------------------------------------- 1 | 1,25e6,873 2 | 1,23.96e6,811 3 | 1,6e6,811 4 | 1,6e6,573 5 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "steam_property_calc.h": "c", 4 | "stdio.h": "c", 5 | "region1.h": "c", 6 | "if97_general.h": "c", 7 | "region3.h": "c", 8 | "region_calc.h": "c" 9 | } 10 | } -------------------------------------------------------------------------------- /.github/workflows/c-cpp.yml: -------------------------------------------------------------------------------- 1 | name: C/C++ CI 2 | 3 | on: 4 | push: 5 | branches: [ "master" ] 6 | pull_request: 7 | branches: [ "master" ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v3 16 | - name: make 17 | run: gcc ws-if97.c -o my-if97.exe -lm 18 | -------------------------------------------------------------------------------- /region_calc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This code is distributed under the license: MIT License 3 | * Originally written by Zhenrong WANG 4 | * mailto: zhenrongwang@live.com 5 | */ 6 | 7 | #ifndef REGION_CALC_H_ 8 | #define REGION_CALC_H_ 9 | 10 | double calc_sat_pres(double temp); 11 | double calc_bound23(double temp); 12 | int region(double pressure, double temp); 13 | 14 | #endif -------------------------------------------------------------------------------- /test/_properties.dat: -------------------------------------------------------------------------------- 1 | PRES TEMP SPE_VOL DENS u h s Cv Cp Vsound Visc Lamd V_FRAC 2 | MPa K m^3/kg kg/m^3 kJ/kg kJ/kg kJ/(kg*K) kJ/(kg*K) kJ/(kg*K) m/s Pa.s W/(m*K) - 3 | 1 25.000000 873.00 0.01413568 70.742982 3139.8533 3493.2453 6.36331821 3.936474 2.968506 676.9141 0.00003454 0.1037 1.0000 4 | 2 23.960000 811.00 0.01302808 76.757281 3000.1149 3312.2677 6.16497670 4.458888 3.261395 637.2774 0.00003204 0.0982 1.0000 5 | 3 6.000000 811.00 0.05997518 16.673564 3152.7060 3512.5571 6.99551467 2.939427 2.358648 677.1181 0.00003033 0.0761 1.0000 6 | 4 6.000000 573.00 0.03617050 27.646842 2667.9215 2884.9445 6.06925828 5.049962 3.642072 525.8732 0.00001971 0.0575 1.0000 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf 53 | -------------------------------------------------------------------------------- /if97_general.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This code is distributed under the license: MIT License 3 | * Originally written by Zhenrong WANG 4 | * mailto: zhenrongwang@live.com 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | int NRP(double pres) 12 | { 13 | if(isnan(pres)!=0) 14 | { 15 | return -1; 16 | } 17 | else 18 | { 19 | if(pres<1e-10||pres>1e8) 20 | { 21 | return -1; 22 | } 23 | } 24 | return 0; 25 | } 26 | 27 | int NRT(double temp) 28 | { 29 | if(isnan(temp)!=0) 30 | { 31 | return -1; 32 | } 33 | else 34 | { 35 | if(temp<273.15||temp>2273.15) 36 | { 37 | return -1; 38 | } 39 | } 40 | return 0; 41 | } 42 | 43 | int NRR(double dens) 44 | { 45 | if(isnan(dens)!=0) 46 | { 47 | return -1; 48 | } 49 | else 50 | { 51 | if(dens<0||dens>1e10) 52 | { 53 | return -1; 54 | } 55 | } 56 | return 0; 57 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | Copyright (c) 2023 Zhenrong WANG zhenrongwang@live.com 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | -------------------------------------------------------------------------------- /if97_general.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This code is distributed under the license: MIT License 3 | * Originally written by Zhenrong WANG 4 | * mailto: zhenrongwang@live.com 5 | */ 6 | 7 | //units: pressure-Pa, temp-K, spe_vol-m3/kg, dens-kg/m3, spe_ener-J/kg, spe_entr-J/kgK, spe_enth-J/kg, spe_h-J/kgK 8 | 9 | #ifndef IF97_GENERAL_H_ 10 | #define IF97_GENERAL_H_ 11 | 12 | #define MAX_PRES 1e8 13 | #define MAX_TEMP 2273.15 14 | #define INTER_TEMP1 623.15 15 | #define INTER_TEMP2 1073.15 16 | #define MIN_TEMP 273.15 17 | #define INTER_PRES 5e7 18 | #define MAX_ITER_NUMSR2 200 19 | #define MAX_ITER_NUMS 100 20 | #define MAX_ITER_TIMES 900 21 | #define ERR_FOR_DENS 1e-12 22 | #define ZERO 1e-9 23 | #define MAX_ITER_TIMES_R5 200 24 | 25 | #define T_C 647.096 26 | #define P_C 22.064e6 27 | #define r_c 322 28 | 29 | #define GAS_CONST_STEAM 461.526 30 | 31 | typedef struct{ 32 | double pressure; 33 | double temp; 34 | double spe_vol; 35 | double dens; 36 | double spe_energy; 37 | double spe_entr; 38 | double spe_enth; 39 | double spe_h_v; 40 | double spe_h_p; 41 | double speed_sound; 42 | double vapor_fraction; 43 | double drdp; 44 | }steam_prop; 45 | 46 | int NRP(double pres); 47 | int NRT(double temp); 48 | int NRR(double dens); 49 | 50 | #endif -------------------------------------------------------------------------------- /steam_property_calc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This code is distributed under the license: MIT License 3 | * Originally written by Zhenrong WANG 4 | * mailto: zhenrongwang@live.com 5 | */ 6 | 7 | //units: pressure-Pa, temp-K, spe_vol-m3/kg, dens-kg/m3, spe_ener-J/kg, spe_entr-J/kgK, spe_enth-J/kg, spe_h-J/kgK 8 | 9 | #ifndef STEAM_PROPERTY_CALC_H_ 10 | #define STEAM_PROPERTY_CALC_H_ 11 | 12 | void print_prop(steam_prop *p_prop); 13 | int hs_find_tsat(double *t, double spe_enth, double spe_entr); 14 | //normal version 15 | int steam_prop_calc_pt(double pressure, double temp, steam_prop *p_prop, steam_prop *p_prop_bkup); 16 | int steam_prop_calc_pr(double pressure, double dens, steam_prop* p_prop); 17 | int steam_prop_calc_pu(double pressure, double spe_ener, steam_prop* p_prop); 18 | int steam_prop_calc_ph(double pressure, double spe_enth, steam_prop* p_prop); 19 | int steam_prop_calc_ps(double pressure, double spe_entr, steam_prop* p_prop); 20 | int steam_prop_calc_tr(double temp, double dens, steam_prop* p_prop); 21 | int steam_prop_calc_tu(double temp, double spe_ener, steam_prop* p_prop); 22 | int steam_prop_calc_th(double temp, double spe_enth, steam_prop* p_prop); 23 | int steam_prop_calc_ts(double temp, double spe_entr, steam_prop* p_prop); 24 | int steam_prop_calc_hs(double spe_enth, double spe_entr, steam_prop* p_prop); 25 | int steam_prop_calc_px(double pres, double vf, steam_prop *p_prop); 26 | int steam_prop_calc_tx(double temp, double vf, steam_prop *p_prop); 27 | double steam_visc_calc(double temp, double dens); 28 | int calc_index_lmd2(double dens, double ref_dens); 29 | double steam_thcond_calc(double temp, double dens, double visc, double cp, double cv, double drdp, double pressure); 30 | //special for THE PROGRAM 31 | int steam_prop_calc(double pressure, double temp, double *dens,double *cp, double* cv, double* spe_enth, double* drdp); 32 | 33 | #endif -------------------------------------------------------------------------------- /region5.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This code is distributed under the license: MIT License 3 | * Originally written by Zhenrong WANG 4 | * mailto: zhenrongwang@live.com 5 | */ 6 | 7 | #ifndef REGION5_H_ 8 | #define REGION5_H_ 9 | 10 | #include "if97_general.h" 11 | 12 | double gm05(double pi, double tau); 13 | double gmr5(double pi, double tau); 14 | double gm0pi5(double pi); 15 | double gm0pipi5(double pi); 16 | double gm0tau5(double tau); 17 | double gm0tautau5(double tau); 18 | double gmrpi5(double pi, double tau); 19 | double gmrpipi5(double pi, double tau); 20 | double gmrtau5(double pi, double tau); 21 | double gmrtautau5(double pi, double tau); 22 | double gmrpitau5(double pi, double tau); 23 | void steam_prop_calc_r5(double pressure, double temp, steam_prop* p_prop); 24 | void calcFT_dFT_prr5(double* ft, double* dft, double pressure, double dens, double tau); 25 | int temp_pr_r5(double *temp, double pressure, double dens); 26 | void calcFT_dFT_pur5(double* ft, double* dft, double pressure, double spe_ener, double tau); 27 | int temp_pu_r5(double* temp, double pressure, double spe_ener); 28 | void calcFT_dFT_phr5(double* ft, double* dft, double pressure, double spe_enth, double tau); 29 | int temp_ph_r5(double* temp, double pressure, double spe_enth); 30 | void calcFT_dFT_psr5(double* ft, double* dft, double pressure, double spe_entr, double tau); 31 | int temp_ps_r5(double* temp, double pressure, double spe_entr); 32 | void calcFP_dFP_trr5(double* fp, double* dfp, double temp, double dens, double pi); 33 | int pres_tr_r5(double* pres, double temp, double dens); 34 | void calcFP_dFP_tur5(double* fp, double* dfp, double temp, double spe_ener, double pi); 35 | int pres_tu_r5(double* pres, double temp, double spe_ener); 36 | void calcFP_dFP_thr5(double* fp, double* dfp, double temp, double spe_enth, double pi); 37 | int pres_th_r5(double* pres, double temp, double spe_enth); 38 | void calcFP_dFP_tsr5(double* fp, double* dfp, double temp, double spe_entr, double pi); 39 | int pres_ts_r5(double* pres, double temp, double spe_entr); 40 | void calcFG_dFG_hs_r5(double* f, double* g, double*dfdp, double* dfdt, double* dgdp, double* dgdt, double spec_enth, double spec_entr, double pi, double tau); 41 | int pt_hs_r5(double* pres, double* temp, double spe_enth, double spe_entr); 42 | 43 | #endif -------------------------------------------------------------------------------- /region1.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This code is distributed under the license: MIT License 3 | * Originally written by Zhenrong WANG 4 | * mailto: zhenrongwang@live.com 5 | */ 6 | 7 | #ifndef REGION1_H_ 8 | #define REGION1_H_ 9 | 10 | #include "if97_general.h" 11 | 12 | double gm(double pi, double tau); 13 | double gmpi(double pi, double tau); 14 | double gmpipi(double pi, double tau); 15 | double gmtau(double pi, double tau); 16 | double gmtautau(double pi, double tau); 17 | double gmpitau(double pi, double tau); 18 | void steam_prop_calc_r1(double pressure, double temp, steam_prop* p_prop); 19 | double tempini_ph_r1(double pressure, double spec_enth); 20 | void calcFT_dFT_ph(double* ft, double* dft, double pres, double spec_enth, double tau); 21 | int temp_ph_r1(double* temp, double pres, double spe_enth); 22 | double tempini_ps_r1(double pressure, double spec_entr); 23 | void calcFT_dFT_ps(double* ft, double* dft, double pres, double spec_entr, double tau); 24 | int temp_ps_r1(double* temp, double pres, double spe_entr); 25 | double presini_hs_r1(double spec_enth, double spec_entr); 26 | double tempini_hs_r1(double spec_enth, double spec_entr); 27 | void calcFG_dFG_hs(double* f, double* g, double*dfdp, double* dfdt, double* dgdp, double* dgdt, double spec_enth, double spec_entr, double pi, double tau); 28 | int pt_hs_r1(double* pres, double* temp, double spe_enth, double spe_entr); 29 | void calcFT_dFT_pr(double* ft, double* dft, double pressure, double dens, double T); 30 | int temp_pr_r1(double* temp, double pressure, double dens); 31 | void calcFT_dFT_pu(double* ft, double* dft, double pressure, double spe_ener, double T); 32 | int temp_pu_r1(double* temp, double pressure, double spe_ener); 33 | void calcFPi_dFPi_tr(double* fpi, double* dfpi, double Temp, double dens, double pi); 34 | int pres_tr_r1(double* pres, double temp, double dens); 35 | void calcFPi_dFPi_tu(double* fpi, double* dfpi, double temp, double spe_ener, double pi); 36 | int pres_tu_r1(double* pres, double temp, double spe_ener); 37 | void calcFPi_dFPi_th(double* fpi, double* dfpi, double temp, double spe_enth, double pi); 38 | int pres_th_r1(double* pres, double temp, double spe_enth); 39 | void calcFPi_dFPi_ts(double* fpi, double* dfpi, double temp, double spe_entr, double pi); 40 | int pres_ts_r1(double* pres, double temp, double spe_entr); 41 | 42 | #endif -------------------------------------------------------------------------------- /region2.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This code is distributed under the license: MIT License 3 | * Originally written by Zhenrong WANG 4 | * mailto: zhenrongwang@live.com 5 | */ 6 | 7 | #ifndef REGION2_H_ 8 | #define REGION2_H_ 9 | 10 | #include "if97_general.h" 11 | 12 | double gm0(double pi, double tau); 13 | double gm0pi(double pi); 14 | double gm0pipi(double pi); 15 | double gm0tau(double tau); 16 | double gm0tautau(double tau); 17 | double gmr(double pi, double tau); 18 | double gmrpi(double pi, double tau); 19 | double gmrpipi(double pi, double tau); 20 | double gmrtau(double pi, double tau); 21 | double gmrtautau(double pi, double tau); 22 | double gmrpitau(double pi, double tau); 23 | void steam_prop_calc_r2(double pressure, double temp, steam_prop* p_prop); 24 | int sub_region(double pressure, double spec_enth); 25 | int temp_ph_r2(double* temp, double pressure, double spec_enth); 26 | int sub_region_s(double pressure, double spe_entr); 27 | int temp_ps_r2(double* temp, double pressure, double spe_entr); 28 | int sub_region_hs(double spe_enth, double spe_entr); 29 | int pres_hs_r2(double* pressure, double spe_enth, double spe_entr); 30 | void calcFT_dFT_prr2(double* ft, double* dft, double pressure, double dens, double tau); 31 | int temp_pr_r2(double* temp, double pressure, double dens); 32 | void calcFT_dFT_pur2(double* ft, double* dft, double pressure, double spe_ener, double tau); 33 | int temp_pu_r2(double* temp, double pressure, double spe_ener); 34 | void calcFPi_dFPi_trr2(double* fp, double* dfp, double temp, double dens, double pi); 35 | int pres_tr_r2(double* pres, double temp, double dens); 36 | void calcFPi_dFPi_tur2(double* fp, double* dfp, double temp, double spe_ener, double pi); 37 | int pres_tu_r2(double* pres, double temp, double spe_ener); 38 | void calcFPi_dFPi_thr2(double* fp, double* dfp, double temp, double spe_enth, double pi); 39 | int pres_th_r2(double* pres, double temp, double spe_enth); 40 | void calcFPi_dFPi_tsr2(double* fp, double* dfp, double temp, double spe_entr, double pi); 41 | int pres_ts_r2(double* pres, double temp, double spe_entr); 42 | int ptini_hs_r2(double* presini, double* tempini, double spe_enth, double spe_entr); 43 | void calcFG_dFG_hs_r2(double* f, double* g, double*dfdp, double* dfdt, double* dgdp, double* dgdt, double spec_enth, double spec_entr, double pi, double tau); 44 | int pt_hs_r2(double* pres, double* temp, double spe_enth, double spe_entr); 45 | 46 | #endif -------------------------------------------------------------------------------- /region_calc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This code is distributed under the license: MIT License 3 | * Originally written by Zhenrong WANG 4 | * mailto: zhenrongwang@live.com 5 | */ 6 | 7 | #include 8 | #include 9 | #include "if97_general.h" 10 | #include "region_calc.h" 11 | 12 | static double sat_coeff[10]={ 13 | 0.11670521452767e4,-0.72421316703206e6,-0.17073846940092e2,0.12020824702470e5,-0.32325550322333e7,0.14915108613530e2,-0.48232657361591e4,0.40511340542057e6,-0.23855557567849,0.65017534844798e3 14 | }; 15 | 16 | static double bound2_3[5]={ 17 | 0.34805185628969e3,-0.11671859879975e1,0.10192970039326e-2,0.57254459862746e3,0.13918839778870e2 18 | }; 19 | 20 | double calc_sat_pres(double temp) 21 | { 22 | double phi; 23 | double A,B,C; 24 | double D; 25 | double p_ratio; 26 | phi=temp+sat_coeff[8]/(temp-sat_coeff[9]); 27 | A=phi*phi+sat_coeff[0]*phi+sat_coeff[1]; 28 | B=phi*phi*sat_coeff[2]+phi*sat_coeff[3]+sat_coeff[4]; 29 | C=sat_coeff[5]*phi*phi+sat_coeff[6]*phi+sat_coeff[7]; 30 | D=2*C/((-B)+sqrt(B*B-4*A*C)); 31 | p_ratio=pow(D,4); 32 | return p_ratio*1e6; 33 | } 34 | 35 | double calc_bound23(double temp) 36 | { 37 | double p_ratio; 38 | p_ratio=bound2_3[0]+bound2_3[1]*temp+bound2_3[2]*temp*temp; 39 | return p_ratio*1e6; 40 | } 41 | 42 | 43 | int region(double pressure, double temp) 44 | { 45 | if(pressure<0||pressure>MAX_PRES) 46 | { 47 | return -1; 48 | } 49 | else if(tempMAX_TEMP) 50 | { 51 | return -1; 52 | } 53 | else if(temp>INTER_TEMP2&&pressure>INTER_PRES) 54 | { 55 | return -1; 56 | } 57 | else if(temp>INTER_TEMP2&&pressurecalc_sat_pres(temp)) 68 | { 69 | return 1; 70 | } 71 | else if(pressureINTER_TEMP1&&tempcalc_bound23(temp)) 79 | { 80 | return 3; 81 | } 82 | else 83 | { 84 | return 2; 85 | } 86 | } 87 | } 88 | 89 | 90 | /*int main() 91 | { 92 | printf("\n%lf\n",calc_sat_pres(341)) 93 | printf("%d",region(99568,341)); 94 | } 95 | /* double temp2=373.15; 96 | double temp3=623.15; 97 | // for(i=0;i<10;i++) 98 | // { 99 | // printf("%lf\n",sat_coeff[i]); 100 | // } 101 | 102 | printf("%lf\n%lf\n",calc_sat_pres(temp2),calc_bound23(temp3)); 103 | // for(i=0;i<3;i++) 104 | // { 105 | // printf("%lf\n",calc_sat_pres(temp[i])); 106 | // } 107 | }*/ -------------------------------------------------------------------------------- /region3.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This code is distributed under the license: MIT License 3 | * Originally written by Zhenrong WANG 4 | * mailto: zhenrongwang@live.com 5 | */ 6 | 7 | #ifndef REGION3_H_ 8 | #define REGION3_H_ 9 | 10 | #include "if97_general.h" 11 | 12 | double t3abp(double pres); 13 | double t3cdp(double pres); 14 | double t3efp(double pres); 15 | double t3ghp(double pres); 16 | double t3ijp(double pres); 17 | double t3jkp(double pres); 18 | double t3mnp(double pres); 19 | double t3opp(double pres); 20 | double t3qup(double pres); 21 | double t3rxp(double pres); 22 | double tsatp(double pres); 23 | double psatt(double temp); 24 | double t3uvp(double pres); 25 | double t3wxp(double pres); 26 | int pt_subregion_calc1(double pres, double temp); 27 | int pt_subregion_calc2(double pres, double temp); 28 | double calc_vpt(int sr, double pres, double temp); 29 | double spe_vol_pt(double pres, double temp); 30 | double phi(double delta, double tau); 31 | double phid(double delta, double tau); 32 | double phidd(double delta, double tau); 33 | double phit(double delta, double tau); 34 | double phitt(double delta, double tau); 35 | double phidt(double delta, double tau); 36 | void r3prop_calc_tr(double temp, double dens, steam_prop* p_prop); 37 | void calcFD_dFD_pt(double* fd, double* dfd, double pres, double temp, double del); 38 | int hp_dens_pt(double* dens_final, double dens_ini, double pres, double temp); 39 | void calcFT_dFT_prr3(double* ft, double* dft, double pres, double dens, double tau); 40 | int temp_pr_r3(double* temp, double pres, double dens); 41 | void calcFG_DFG_ph(double* f, double* g, double* dfdd, double* dgdd, double* dfdt, double* dgdt, double pres, double spe_enth, double del, double tau); 42 | int tr_ph_r3(double* temp, double* dens, double pres, double spe_enth); 43 | void calcFG_DFG_ps(double* f, double* g, double* dfdd, double* dgdd, double* dfdt, double* dgdt, double pres, double spe_entr, double del, double tau); 44 | int tr_ps_r3(double* temp, double* dens, double pres, double spe_entr); 45 | void calcFG_DFG_pu(double* f, double* g, double* dfdd, double* dgdd, double* dfdt, double* dgdt, double pres, double spe_ener, double del, double tau); 46 | int tr_pu_r3(double* temp, double* dens, double pres, double spe_ener); 47 | void calcFG_DFG_hs(double* f, double* g, double* dfdd, double* dgdd, double* dfdt, double* dgdt, double spe_enth, double spe_entr, double del, double tau); 48 | int pres_tr_r3(double* pres, double temp, double dens); 49 | int tr_hs_r3(double* temp, double* dens, double spe_enth, double spe_entr); 50 | void calcFd_DFd_th(double* fd, double* dfd, double temp, double spe_enth, double del); 51 | int dens_th_r3(double* dens, double temp, double spe_enth); 52 | int pres_th_r3(double* pres, double temp, double spe_enth); 53 | int pt_hs_r3(double* pres, double* temp, double spe_enth, double spe_entr); 54 | void calcFd_DFd_tu(double* fd, double* dfd, double temp, double spe_ener, double del); 55 | int dens_tu_r3(double* dens, double temp, double spe_ener); 56 | int pres_tu_r3(double* pres, double temp, double spe_ener); 57 | void calcFd_DFd_ts(double* fd, double* dfd, double temp, double spe_entr, double del); 58 | int dens_ts_r3(double* dens, double temp, double spe_entr); 59 | int pres_ts_r3(double* pres, double temp, double spe_entr); 60 | int steam_prop_calc_r3(double pressure, double temp, steam_prop* p_prop); 61 | 62 | #endif -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Water and Steam Thermophysical Property Calculation 2 | 3 | # 1. Background 4 | 5 | The thermophysical properties of water and steam are very important to researchers and engineers in various domains (energy, power, chemistry, materials ...). 6 | 7 | Usually, researchers and engineers rely on the [NIST Refprop](https://www.nist.gov/srd/refprop) to calculate the properties. However, Refprop is commercial and not open-source. Therefore, I wrote this code to provide an alternative to the Refprop. 8 | 9 | # 2. Brief Intro 10 | 11 | **Program Name**: Ultra-high-resolution Water and Steam Thermophysical Property Calculation 12 | 13 | **Purpose**: Calculate the **very-high-resolution** thermophysical properties at given point(s) 14 | 15 | **License**: MIT 16 | 17 | **Technical Reference**: [IAPWS IF97](http://www.iapws.org/) 18 | 19 | # 3. How-To: Build, Run, and Use 20 | 21 | ## 3.1 Build 22 | 23 | ### 3.1.1 Prerequisites 24 | 25 | You need a C compiler to build. 26 | 27 | - For Microsoft Windows users, [mingw-w64](https://sourceforge.net/projects/mingw-w64/) is required. 28 | - For GNU/Linux Distro or other *nix users, the [GNU Compiler Collections](https://gcc.gnu.org/), known as gcc, is recommended. 29 | - For macOS users, [clang](https://clang.llvm.org/) is easy to install and use (brew is not needed to install clang on macOS). 30 | 31 | ### 3.1.2 Build Guide 32 | 33 | 1. Use `git` to clone this code: `git clone https://github.com/zhenrong-wang/water-steam-if97.git` 34 | 2. Build command example: `gcc *.c -o my-if97.exe -lm` 35 | 36 | Note: the `-lm` may not be valid for Windows or macOS. It is necessary for GNU/Linux distros. 37 | 38 | ## 3.2 Run 39 | 40 | ### Run the Test Data 41 | 42 | Suppose you have followed the steps above and built the my-if97.exe in the source code folder. 43 | 44 | - `cd test` 45 | - `../my-if97.exe` (**UNIX-like OS**) or `..\my-if97.exe` (**Microsoft Windows**) 46 | 47 | If you see the output below, congrats, you've built the binary successfully. 48 | 49 | ... 50 | 51 | 1 25000000.00000000 873.00000000 52 | 1 23960000.00000000 811.00000000 53 | 1 6000000.00000000 811.00000000 54 | 1 6000000.00000000 573.00000000 55 | 56 | # Calculation finished. Please check _properties.dat for results. 57 | # Press any key to exit. 58 | 59 | @ Any problems found, please contact the author. 60 | @ Zhenrong Wang, zhenrongwang@live.com. 61 | 62 | ### An Example for UNIX-like OS: 63 | 64 | Suppose the working directory is `/home/amber/water-steam/` 65 | 66 | Suppose the absolute path of the executable is `/home/amber/bin/my-if97.exe` 67 | 68 | - `$ cd /home/amber/water-steam/` 69 | - `$ vim _input.dat` # Create an input file named '**_input.dat**' with some input data (See Section 3.3 below) 70 | - `$ /home/amber/bin/my-if97.exe` 71 | 72 | ### An Example for Windows: 73 | 74 | Suppose the working directory is `C:\Users\amber\water-steam\` 75 | 76 | Suppose the absolute path of the executable is `C:\Users\amber\bin\my-if97.exe` 77 | 78 | - Open a Command Prompt Window 79 | - `cd C:\Users\amber\water-steam\` 80 | - `notepad _input.dat` 81 | - `C:\Users\amber\bin\my-if97.exe` 82 | 83 | ## 3.3 Use 84 | 85 | For the **_input.dat** file, you need to input the data in lines. A single line refers to a point. Strict format: 86 | 87 | `POINT_TYPE(int),PARAM1(float/double),PARAM2 (float/double)` 88 | 89 | **Please separate the params by a comma ','** 90 | 91 | POINT_TYPE: 92 | 93 | - 1 Pressure and Temperature 94 | - 2 Pressure and Density 95 | - 3 Pressure and Specific Internal Energy 96 | - 4 Pressure and Specific Enthalpy 97 | - 5 Pressure and Specific Entropy 98 | - 6 Temperature and Density 99 | - 7 Temperature and Specific Internal Energy 100 | - 8 Temperature and Specific Enthalpy 101 | - 9 Temperature and Specific Entropy 102 | - 10 Specific Enthalpy and Specific Entropy 103 | - 11 Pressure and Steam Dryness 104 | - 12 Temperature and Steam Dryness 105 | 106 | Example: `1,100000,300` 107 | 108 | Example: `1,1e5,3e2` 109 | 110 | Units: 111 | 112 | - Pressure(p): Pa 113 | - Temperature(t): K 114 | - Density(r): kg/m3 115 | - Specific Internal Energy(u): J/kg 116 | - Specific Enthalpy(h): J/kg 117 | - Specific Entropy(s): J/(kg.K) 118 | 119 | ## 3.4 Output 120 | 121 | The program writes out a file named '**_properties.dat**' in the working directory. 122 | 123 | # 4 Bugs and Communications 124 | 125 | This code was written years ago, and I didn't continuously develop it. Therefore, bugs may occur. 126 | 127 | If you are interested in this project, please submit issues to this repo. I'd be glad to communicate on any issues. 128 | 129 | Or, you can also email me: zhenrongwang@live.com 130 | 131 | -------------------------------------------------------------------------------- /ws-if97-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "if97_general.h" 5 | #include "region_calc.h" 6 | #include "region1.h" 7 | #include "region2.h" 8 | #include "region3.h" 9 | #include "region5.h" 10 | #include "steam_property_calc.h" 11 | 12 | int welcome(void) 13 | { 14 | time_t rtime; 15 | struct tm* timeinfo=NULL; 16 | time(&rtime); 17 | timeinfo=localtime(&rtime); 18 | printf("/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */\n"); 19 | printf("/* Water and Steam Properties Calculation */\n"); 20 | printf("/* VERSION 1.2(beta) LICENSE: MIT */\n"); 21 | printf("/* WANG ZHENRONG (Edison WANG), reserves all rights of this program. */\n"); 22 | printf("/* Contacts: zhenrongwang@live.com(email). K495458966(wechat). */\n"); 23 | printf("/* Main function: calculating properties by given two values: */\n"); 24 | printf("/* 1-pt, 2-pr, 3-pu, 4-ph, 5-ps, 6-tr, 7-tu, 8-th, 9-ts, 10-hs. */\n"); 25 | printf("/* 11-px, 12-tx (x - vapor fraction). */\n"); 26 | printf("/* Input File: _input.dat; Output File: _properties.dat. */\n"); 27 | printf("/* Range1: 273.15K0&&type<15) 80 | { 81 | printf("\n%d\t%.8lf\t%.8lf",type,v1,v2); 82 | } 83 | 84 | if(type==1) 85 | flag=steam_prop_calc_pt(v1,v2,&prop,&prop_bkup); 86 | else if(type==2) 87 | flag=steam_prop_calc_pr(v1,v2,&prop); 88 | else if(type==3) 89 | flag=steam_prop_calc_pu(v1,v2,&prop); 90 | else if(type==4) 91 | flag=steam_prop_calc_ph(v1,v2,&prop); 92 | else if(type==5) 93 | flag=steam_prop_calc_ps(v1,v2,&prop); 94 | else if(type==6) 95 | flag=steam_prop_calc_tr(v1,v2,&prop); 96 | else if(type==7) 97 | flag=steam_prop_calc_tu(v1,v2,&prop); 98 | else if(type==8) 99 | flag=steam_prop_calc_th(v1,v2,&prop); 100 | else if(type==9) 101 | flag=steam_prop_calc_ts(v1,v2,&prop); 102 | else if(type==10) 103 | flag=steam_prop_calc_hs(v1,v2,&prop); 104 | else if(type==11) 105 | flag=steam_prop_calc_px(v1,v2,&prop); 106 | else if(type==12) 107 | flag=steam_prop_calc_tx(v1,v2,&prop); 108 | else if(type==13) 109 | flag=steam_prop_calc_pt(v1,tsatp(v1),&prop,&prop_bkup); 110 | else if(type==14) 111 | flag=steam_prop_calc_pt(calc_sat_pres(v1),v1,&prop,&prop_bkup); 112 | else 113 | { 114 | continue; 115 | } 116 | 117 | if(flag==-1) 118 | { 119 | printf("\n! WARNING: Calculation error at line # %d of the input file.\n", i); 120 | fprintf(fout,"%d\t-1\n",i); 121 | continue; 122 | type=-1; 123 | } 124 | else if(flag==1) 125 | { 126 | viscous=steam_visc_calc(prop.temp,prop.dens); 127 | thcond=steam_thcond_calc(prop.temp,prop.dens,viscous,prop.spe_h_p,prop.spe_h_v,prop.drdp,prop.pressure); 128 | fprintf(fout,"%d\t%.6lf*\t%.2lf*\t%.8lf\t%.6lf\t%8.4lf\t%8.4lf\t%.8lf\t%.6lf\t%.6lf\t%.4lf\t%.8lf\t%.4lf\t%.4lf\n",i,prop.pressure/1e6,prop.temp,prop.spe_vol,prop.dens,prop.spe_energy/1000,prop.spe_enth/1000,prop.spe_entr/1000,prop.spe_h_v/1000,prop.spe_h_p/1000,prop.speed_sound,viscous,thcond,prop.vapor_fraction); 129 | fprintf(fout,"\t%.6lf**\t%.2lf*\t%.8lf\t%.6lf\t%8.4lf\t%8.4lf\t%.8lf\t%.6lf\t%.6lf\t%.4lf\t%.8lf\t%.4lf\t%.4lf\n",prop_bkup.pressure/1e6,prop_bkup.temp,prop_bkup.spe_vol,prop_bkup.dens,prop_bkup.spe_energy/1000,prop_bkup.spe_enth/1000,prop_bkup.spe_entr/1000,prop_bkup.spe_h_v/1000,prop_bkup.spe_h_p/1000,prop_bkup.speed_sound,viscous,thcond,prop_bkup.vapor_fraction); 130 | type=-1; 131 | } 132 | else 133 | { 134 | viscous=steam_visc_calc(prop.temp,prop.dens); 135 | thcond=steam_thcond_calc(prop.temp,prop.dens,viscous,prop.spe_h_p,prop.spe_h_v,prop.drdp,prop.pressure); 136 | fprintf(fout,"%d\t%.6lf\t%.2lf\t%.8lf\t%.6lf\t%.4lf\t%.4lf\t%.8lf\t%.6lf\t%.6lf\t%.4lf\t%.8lf\t%.4lf\t%.4lf\n",i,prop.pressure/1e6,prop.temp,prop.spe_vol,prop.dens,prop.spe_energy/1000,prop.spe_enth/1000,prop.spe_entr/1000,prop.spe_h_v/1000,prop.spe_h_p/1000,prop.speed_sound,viscous,thcond,prop.vapor_fraction); 137 | type=-1; 138 | } 139 | } 140 | 141 | printf("\n\n# Calculation finished. Please check _properties.dat for results.\n# Press any key to exit.\n\n@ Any problems found, please contact the author.\n@ Zhenrong Wang, zhenrongwang@live.com.\n"); 142 | fclose(fin); 143 | fclose(fout); 144 | fflush(stdin); 145 | getchar(); 146 | return 0; 147 | 148 | } 149 | -------------------------------------------------------------------------------- /region5.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This code is distributed under the license: MIT License 3 | * Originally written by Zhenrong WANG 4 | * mailto: zhenrongwang@live.com 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | #include "if97_general.h" 11 | #include "region_calc.h" 12 | #include "region5.h" 13 | 14 | static double region5_coeff0[6][3]={ 15 | 1,0,-0.13179983674201e2, 16 | 2,1,0.68540841634434e1, 17 | 3,-3,-0.24805148933466e-1, 18 | 4,-2,0.36901534980333, 19 | 5,-1,-0.31161318213925e1, 20 | 6,2,-0.32961626538917 21 | }; 22 | 23 | static double region5_coeffr[6][4]={ 24 | 1,1,1,0.15736404855259e-2, 25 | 2,1,2,0.90153761673944e-3, 26 | 3,1,3,-0.50270077677648e-2, 27 | 4,2,3,0.22440037409485e-5, 28 | 5,2,9,-0.41163275453471e-5, 29 | 6,3,7,0.37919454822955e-7 30 | }; 31 | 32 | double gm05(double pi, double tau) 33 | { 34 | int i; 35 | double ni,ji; 36 | double res=log(pi); 37 | for(i=0;i<6;i++) 38 | { 39 | ni=region5_coeff0[i][2]; 40 | ji=region5_coeff0[i][1]; 41 | res+=ni*pow(tau,ji); 42 | } 43 | return res; 44 | } 45 | 46 | double gmr5(double pi, double tau) 47 | { 48 | int i; 49 | double ni,ii,ji; 50 | double res=0; 51 | for(i=0;i<6;i++) 52 | { 53 | ni=region5_coeffr[i][3]; 54 | ji=region5_coeffr[i][2]; 55 | ii=region5_coeffr[i][1]; 56 | res+=ni*pow(pi,ii)*pow(tau,ji); 57 | } 58 | return res; 59 | } 60 | 61 | double gm0pi5(double pi) 62 | { 63 | return 1/pi; 64 | } 65 | 66 | double gm0pipi5(double pi) 67 | { 68 | return -1/(pi*pi); 69 | } 70 | 71 | double gm0tau5(double tau) 72 | { 73 | int i; 74 | double res=0; 75 | double ni,ji; 76 | for(i=0;i<6;i++) 77 | { 78 | ni=region5_coeff0[i][2]; 79 | ji=region5_coeff0[i][1]; 80 | res+=ni*ji*pow(tau,ji-1); 81 | } 82 | return res; 83 | } 84 | 85 | double gm0tautau5(double tau) 86 | { 87 | int i; 88 | double res=0; 89 | double ni,ji; 90 | for(i=0;i<6;i++) 91 | { 92 | ni=region5_coeff0[i][2]; 93 | ji=region5_coeff0[i][1]; 94 | res+=ni*ji*(ji-1)*pow(tau,ji-2); 95 | } 96 | return res; 97 | } 98 | 99 | double gmrpi5(double pi, double tau) 100 | { 101 | int i; 102 | double ni,ii,ji; 103 | double res=0; 104 | for(i=0;i<6;i++) 105 | { 106 | ni=region5_coeffr[i][3]; 107 | ji=region5_coeffr[i][2]; 108 | ii=region5_coeffr[i][1]; 109 | res+=ni*ii*pow(pi,ii-1)*pow(tau,ji); 110 | } 111 | return res; 112 | } 113 | 114 | double gmrpipi5(double pi, double tau) 115 | { 116 | int i; 117 | double ni,ii,ji; 118 | double res=0; 119 | for(i=0;i<6;i++) 120 | { 121 | ni=region5_coeffr[i][3]; 122 | ji=region5_coeffr[i][2]; 123 | ii=region5_coeffr[i][1]; 124 | res+=ni*ii*(ii-1)*pow(pi,ii-2)*pow(tau,ji); 125 | } 126 | return res; 127 | } 128 | 129 | double gmrtau5(double pi, double tau) 130 | { 131 | int i; 132 | double ni,ii,ji; 133 | double res=0; 134 | for(i=0;i<6;i++) 135 | { 136 | ni=region5_coeffr[i][3]; 137 | ji=region5_coeffr[i][2]; 138 | ii=region5_coeffr[i][1]; 139 | res+=ni*pow(pi,ii)*ji*pow(tau,ji-1); 140 | } 141 | return res; 142 | } 143 | 144 | double gmrtautau5(double pi, double tau) 145 | { 146 | int i; 147 | double ni,ii,ji; 148 | double res=0; 149 | for(i=0;i<6;i++) 150 | { 151 | ni=region5_coeffr[i][3]; 152 | ji=region5_coeffr[i][2]; 153 | ii=region5_coeffr[i][1]; 154 | res+=ni*pow(pi,ii)*ji*(ji-1)*pow(tau,ji-2); 155 | } 156 | return res; 157 | } 158 | 159 | double gmrpitau5(double pi, double tau) 160 | { 161 | int i; 162 | double ni,ii,ji; 163 | double res=0; 164 | for(i=0;i<6;i++) 165 | { 166 | ni=region5_coeffr[i][3]; 167 | ji=region5_coeffr[i][2]; 168 | ii=region5_coeffr[i][1]; 169 | res+=ni*ii*pow(pi,ii-1)*ji*pow(tau,ji-1); 170 | } 171 | return res; 172 | } 173 | 174 | 175 | void steam_prop_calc_r5(double pressure, double temp, steam_prop* p_prop) 176 | { 177 | double pi,tau; 178 | 179 | pi=pressure/1e6; 180 | tau=1000/temp; 181 | 182 | p_prop->pressure=pressure; 183 | p_prop->temp=temp; 184 | p_prop->spe_vol=pi*(gm0pi5(pi)+gmrpi5(pi,tau))*GAS_CONST_STEAM*temp/pressure; 185 | p_prop->dens=1/p_prop->spe_vol; 186 | p_prop->spe_energy=GAS_CONST_STEAM*temp*(tau*(gm0tau5(tau)+gmrtau5(pi,tau))-pi*(gm0pi5(pi)+gmrpi5(pi,tau))); 187 | p_prop->spe_entr=GAS_CONST_STEAM*(tau*(gm0tau5(tau)+gmrtau5(pi,tau))-gm05(pi,tau)-gmr5(pi,tau)); 188 | p_prop->spe_enth=GAS_CONST_STEAM*temp*tau*(gm0tau5(tau)+gmrtau5(pi,tau)); 189 | p_prop->spe_h_v=GAS_CONST_STEAM*(-tau*tau*(gm0tautau5(tau)+gmrtautau5(pi,tau))+pow(1+pi*gmrpi5(pi,tau)-tau*pi*gmrpitau5(pi,tau),2)/(1-pi*pi*gmrpipi5(pi,tau))); 190 | p_prop->spe_h_p=-GAS_CONST_STEAM*tau*tau*(gm0tautau5(tau)+gmrtautau5(pi,tau)); 191 | p_prop->speed_sound=sqrt(GAS_CONST_STEAM*temp*(1+2*pi*gmrpi5(pi,tau)+pi*pi*gmrpi5(pi,tau)*gmrpi5(pi,tau))/(1-pi*pi*gmrpipi5(pi,tau)+pow(1+pi*gmrpi5(pi,tau)-tau*pi*gmrpitau5(pi,tau),2)/(tau*tau*(gm0tautau5(tau)+gmrtautau5(pi,tau))))); 192 | p_prop->drdp=-p_prop->dens*p_prop->dens*GAS_CONST_STEAM*temp*(gm0pipi5(pi)+gmrpipi5(pi,tau))/(1e12); 193 | p_prop->vapor_fraction=1; 194 | } 195 | 196 | void calcFT_dFT_prr5(double* ft, double* dft, double pressure, double dens, double tau) 197 | { 198 | double pi; 199 | pi=pressure/1e6; 200 | *ft=gm0pi5(pi)+gmrpi5(pi,tau)-1e6*tau/(dens*GAS_CONST_STEAM*1000); 201 | *dft=gmrpitau5(pi,tau)-1e6/(dens*GAS_CONST_STEAM*1000); 202 | } 203 | 204 | int temp_pr_r5(double *temp, double pressure, double dens) 205 | { 206 | double tau_prev,tau_nxt,ft,dft; 207 | int iter_times; 208 | int ti=0; 209 | double tau_ini[12]={ 210 | 1,0.95,0.9,0.85,0.8,0.75,0.7,0.65,0.6,0.55,0.5,0.45 211 | }; 212 | 213 | do{ 214 | iter_times=0; 215 | calcFT_dFT_prr5(&ft,&dft,pressure,dens,tau_ini[ti]); 216 | tau_nxt=tau_ini[ti]-ft/dft; 217 | do{ 218 | tau_prev=tau_nxt; 219 | calcFT_dFT_prr5(&ft,&dft,pressure,dens,tau_prev); 220 | tau_nxt=tau_prev-ft/dft; 221 | iter_times++; 222 | }while(fabs(tau_nxt-tau_prev)>1e-6&&iter_times1e-6&&iter_times1e-6&&iter_times1e-6&&iter_times1e-6&&iter_times1e-6&&iter_times1e-6&&iter_times1e-6&&iter_timesfabs(dp)) 663 | { 664 | maxd=fabs(dt); 665 | } 666 | else 667 | { 668 | maxd=fabs(dp); 669 | } 670 | i++; 671 | }while(maxd>1e-8&&i1e-4||fabs((spe_entr-prop.spe_entr)/spe_entr)>1e-4) 684 | continue; 685 | else 686 | { 687 | *pres=pp; 688 | *temp=tt; 689 | return 0; 690 | } 691 | } 692 | } 693 | } 694 | } 695 | return -1; 696 | } -------------------------------------------------------------------------------- /region1.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This code is distributed under the license: MIT License 3 | * Originally written by Zhenrong WANG 4 | * mailto: zhenrongwang@live.com 5 | */ 6 | 7 | #include 8 | #include 9 | #include "if97_general.h" 10 | #include "region_calc.h" 11 | #include "region1.h" 12 | 13 | const double region1_coeff[34][4]={ 14 | 1,0,-2,0.14632971213167, 15 | 2,0,-1,-0.84548187169114, 16 | 3,0,0,-0.37563603672040e1, 17 | 4,0,1,0.33855169168385e1, 18 | 5,0,2,-0.95791963387872, 19 | 6,0,3,0.15772038513228, 20 | 7,0,4,-0.16616417199501e-1, 21 | 8,0,5,0.81214629983568e-3, 22 | 9,1,-9,0.28319080123804e-3, 23 | 10,1,-7,-0.60706301565874e-3, 24 | 11,1,-1,-0.18990068218419e-1, 25 | 12,1,0,-0.32529748770505e-1, 26 | 13,1,1,-0.21841717175414e-1, 27 | 14,1,3,-0.52838357969930e-4, 28 | 15,2,-3,-0.47184321073267e-3, 29 | 16,2,0,-0.30001780793026e-3, 30 | 17,2,1,0.47661393906987e-4, 31 | 18,2,3,-0.44141845330846e-5, 32 | 19,2,17,-0.72694996297594e-15, 33 | 20,3,-4,-0.31679644845054e-4, 34 | 21,3,0,-0.28270797985312e-5, 35 | 22,3,6,-0.85205128120103e-9, 36 | 23,4,-5,-0.22425281908000e-5, 37 | 24,4,-2,-0.65171222895601e-6, 38 | 25,4,10,-0.14341729937924e-12, 39 | 26,5,-8,-0.40516996860117e-6, 40 | 27,8,-11,-0.12734301741641e-8, 41 | 28,8,-6,-0.17424871230634e-9, 42 | 29,21,-29,-0.68762131295531e-18, 43 | 30,23,-31,0.14478307828521e-19, 44 | 31,29,-38,0.26335781662795e-22, 45 | 32,30,-39,-0.11947622640071e-22, 46 | 33,31,-40,0.18228094581404e-23, 47 | 34,32,-41,-0.93537087292458e-25, 48 | }; 49 | 50 | const double region1_coeff_ph[20][4]={ 51 | 1,0,0,-0.23872489924521e3, 52 | 2,0,1,0.40421188637945e3, 53 | 3,0,2,0.11349746881718e3, 54 | 4,0,6,-0.58457616048039e1, 55 | 5,0,22,-0.15285482413140e-3, 56 | 6,0,32,-0.10866707695377e-5, 57 | 7,1,0,-0.13391744872602e2, 58 | 8,1,1,0.43211039183559e2, 59 | 9,1,2,-0.54010067170506e2, 60 | 10,1,3,0.30535892203916e2, 61 | 11,1,4,-0.65964749423638e1, 62 | 12,1,10,0.93965400878363e-2, 63 | 13,1,32,0.11573647505340e-6, 64 | 14,2,10,-0.25858641282073e-4, 65 | 15,2,32,-0.40644363084799e-8, 66 | 16,3,10,0.66456186191635e-7, 67 | 17,3,32,0.80670734103027e-10, 68 | 18,4,32,-0.93477771213947e-12, 69 | 19,5,32,0.58265442020601e-14, 70 | 20,6,32,-0.15020185953503e-16, 71 | }; 72 | 73 | const double region1_coeff_ps[20][4]={ 74 | 1,0,0,0.17478268058307e3, 75 | 2,0,1,0.34806930892873e2, 76 | 3,0,2,0.65292584978455e1, 77 | 4,0,3,0.33039981775489, 78 | 5,0,11,-0.19281382923196e-6, 79 | 6,0,31,-0.24909197244573e-22, 80 | 7,1,0,-0.26107636489332, 81 | 8,1,1,0.22592965981586, 82 | 9,1,2,-0.64256463395226e-1, 83 | 10,1,3,0.78876289270526e-2, 84 | 11,1,12,0.35672110607366e-9, 85 | 12,1,31,0.17332496994895e-23, 86 | 13,2,0,0.56608900654837e-3, 87 | 14,2,1,-0.32635483139717e-3, 88 | 15,2,2,0.44778286690632e-4, 89 | 16,2,9,-0.51322156908507e-9, 90 | 17,2,31,-0.42522657042207e-25, 91 | 18,3,10,0.26400441360689e-12, 92 | 19,3,32,0.78124600459723e-28, 93 | 20,4,32,-0.30732199903668e-30, 94 | }; 95 | 96 | const double region1_coeff_hs[19][4]={ 97 | 1,0,0,-0.691997014660582, 98 | 2,0,1,-0.183612548787560e2, 99 | 3,0,2,-0.928332409297335e1, 100 | 4,0,4,0.659639569909906e2, 101 | 5,0,5,-0.162060388912024e2, 102 | 6,0,6,0.450620017338667e3, 103 | 7,0,8,0.854680678224170e3, 104 | 8,0,14,0.607523214001162e4, 105 | 9,1,0,0.326487682621856e2, 106 | 10,1,1,-0.269408844582931e2, 107 | 11,1,4,-0.319947848334300e3, 108 | 12,1,6,-0.928354307043320e3, 109 | 13,2,0,0.303634537455249e2, 110 | 14,2,1,-0.650540422444146e2, 111 | 15,2,10,-0.430991316516130e4, 112 | 16,3,4,-0.747512324096068e3, 113 | 17,4,1,0.730000345529245e3, 114 | 18,4,4,0.114284032569021e4, 115 | 19,5,0,-0.436407041874559e3, 116 | }; 117 | 118 | double gm(double pi, double tau) 119 | { 120 | int i; 121 | double res=0; 122 | double ii,ji,ni; 123 | for(i=0;i<34;i++) 124 | { 125 | ii=region1_coeff[i][1]; 126 | ji=region1_coeff[i][2]; 127 | ni=region1_coeff[i][3]; 128 | res+=ni*pow(7.1-pi,ii)*pow(tau-1.222,ji); 129 | } 130 | return res; 131 | } 132 | 133 | 134 | double gmpi(double pi, double tau) 135 | { 136 | int i; 137 | double res=0; 138 | double ii,ji,ni; 139 | for(i=0;i<34;i++) 140 | { 141 | ii=region1_coeff[i][1]; 142 | ji=region1_coeff[i][2]; 143 | ni=region1_coeff[i][3]; 144 | res+=(-ni)*ii*pow(7.1-pi,ii-1)*pow(tau-1.222,ji); 145 | } 146 | return res; 147 | } 148 | 149 | double gmpipi(double pi, double tau) 150 | { 151 | int i; 152 | double res=0; 153 | double ii,ji,ni; 154 | for(i=0;i<34;i++) 155 | { 156 | ii=region1_coeff[i][1]; 157 | ji=region1_coeff[i][2]; 158 | ni=region1_coeff[i][3]; 159 | res+=ni*ii*(ii-1)*pow(7.1-pi,ii-2)*pow(tau-1.222,ji); 160 | } 161 | return res; 162 | } 163 | 164 | double gmtau(double pi, double tau) 165 | { 166 | int i; 167 | double res=0; 168 | double ii,ji,ni; 169 | for(i=0;i<34;i++) 170 | { 171 | ii=region1_coeff[i][1]; 172 | ji=region1_coeff[i][2]; 173 | ni=region1_coeff[i][3]; 174 | res+=ni*pow(7.1-pi,ii)*ji*pow(tau-1.222,ji-1); 175 | } 176 | return res; 177 | } 178 | 179 | double gmtautau(double pi, double tau) 180 | { 181 | int i; 182 | double res=0; 183 | double ii,ji,ni; 184 | for(i=0;i<34;i++) 185 | { 186 | ii=region1_coeff[i][1]; 187 | ji=region1_coeff[i][2]; 188 | ni=region1_coeff[i][3]; 189 | res+=ni*pow(7.1-pi,ii)*ji*(ji-1)*pow(tau-1.222,ji-2); 190 | } 191 | return res; 192 | } 193 | 194 | double gmpitau(double pi, double tau) 195 | { 196 | int i; 197 | double res=0; 198 | double ii,ji,ni; 199 | for(i=0;i<34;i++) 200 | { 201 | ii=region1_coeff[i][1]; 202 | ji=region1_coeff[i][2]; 203 | ni=region1_coeff[i][3]; 204 | res+=(-ni)*ii*pow(7.1-pi,ii-1)*ji*pow(tau-1.222,ji-1); 205 | } 206 | return res; 207 | } 208 | 209 | void steam_prop_calc_r1(double pressure, double temp, steam_prop* p_prop) 210 | { 211 | double pi,tau; 212 | 213 | pi=pressure/16.53e6; 214 | tau=1386/temp; 215 | 216 | p_prop->pressure=pressure; 217 | p_prop->temp=temp; 218 | p_prop->spe_vol=pi*gmpi(pi,tau)*GAS_CONST_STEAM*temp/pressure; 219 | p_prop->dens=pressure/(GAS_CONST_STEAM*temp*pi*gmpi(pi,tau)); 220 | p_prop->spe_energy=GAS_CONST_STEAM*temp*(tau*gmtau(pi,tau)-pi*gmpi(pi,tau)); 221 | p_prop->spe_entr=GAS_CONST_STEAM*(tau*gmtau(pi,tau)-gm(pi,tau)); 222 | p_prop->spe_enth=GAS_CONST_STEAM*temp*tau*gmtau(pi,tau); 223 | p_prop->spe_h_v=GAS_CONST_STEAM*(-tau*tau*gmtautau(pi,tau)+(gmpi(pi,tau)-tau*gmpitau(pi,tau))*(gmpi(pi,tau)-tau*gmpitau(pi,tau))/gmpipi(pi,tau)); 224 | p_prop->spe_h_p=GAS_CONST_STEAM*(-tau*tau*gmtautau(pi,tau)); 225 | p_prop->speed_sound=sqrt(GAS_CONST_STEAM*temp*gmpi(pi,tau)*gmpi(pi,tau)/(pow(gmpi(pi,tau)-tau*gmpitau(pi,tau),2)/(tau*tau*gmtautau(pi,tau))-gmpipi(pi,tau))); 226 | p_prop->drdp=-p_prop->dens*p_prop->dens*GAS_CONST_STEAM*temp*gmpipi(pi,tau)/(16.53*16.53*1e12); 227 | p_prop->vapor_fraction=0; 228 | } 229 | 230 | double tempini_ph_r1(double pressure, double spec_enth) 231 | { 232 | double pi, eta, ni, ii, ji; 233 | int i; 234 | double theta=0; 235 | 236 | pi=pressure/1e6; 237 | eta=spec_enth/2.5e6; 238 | for(i=0;i<20;i++) 239 | { 240 | ni=region1_coeff_ph[i][3]; 241 | ii=region1_coeff_ph[i][1]; 242 | ji=region1_coeff_ph[i][2]; 243 | theta+=ni*pow(pi,ii)*pow(eta+1,ji); 244 | } 245 | return theta; 246 | } 247 | 248 | void calcFT_dFT_ph(double* ft, double* dft, double pres, double spec_enth, double tau) 249 | { 250 | double pi; 251 | pi=pres/16.53e6; 252 | *ft=tau*gmtau(pi,tau)-spec_enth*tau/(GAS_CONST_STEAM*1386); 253 | *dft=tau*gmtautau(pi,tau)+gmtau(pi,tau)-spec_enth/(GAS_CONST_STEAM*1386); 254 | } 255 | int temp_ph_r1(double* temp, double pres, double spe_enth) 256 | { 257 | int i=0; 258 | double temp_ini,tau_ini,tau_prev,tau_nxt,ft,dft; 259 | temp_ini=tempini_ph_r1(pres,spe_enth); 260 | tau_ini=1386/temp_ini; 261 | calcFT_dFT_ph(&ft,&dft,pres,spe_enth,tau_ini); 262 | tau_nxt=tau_ini-ft/dft; 263 | do 264 | { 265 | tau_prev=tau_nxt; 266 | calcFT_dFT_ph(&ft,&dft,pres,spe_enth,tau_prev); 267 | tau_nxt=tau_prev-ft/dft; 268 | i++; 269 | }while(fabs(tau_prev-tau_nxt)>1e-8&&i1e-8&&ifabs(dp)) 411 | { 412 | maxd=fabs(dt); 413 | } 414 | else 415 | { 416 | maxd=fabs(dp); 417 | } 418 | i++; 419 | }while(maxd>1e-8&&i1e-6&&iter_times1e-6&&iter_times1e-8&&iter_times1e-8&&iter_times1e-8&&iter_times1e-8&&iter_times 8 | #include 9 | #include "if97_general.h" 10 | #include "region_calc.h" 11 | #include "region2.h" 12 | 13 | static double region2_coeff0[9][3]={ 14 | 1,0,-0.96927686500217e1, 15 | 2,1,0.10086655968018e2, 16 | 3,-5,-0.56087911283020e-2, 17 | 4,-4,0.71452738081455e-1, 18 | 5,-3,-0.40710498223928, 19 | 6,-2,0.14240819171444e1, 20 | 7,-1,-0.43839511319450e1, 21 | 8,2,-0.28408632460772, 22 | 9,3,0.21268463753307e-1, 23 | }; 24 | 25 | static double region2_coeffr[43][4]={ 26 | 1,1,0,-0.17731742473213e-2, 27 | 2,1,1,-0.17834862292358e-1, 28 | 3,1,2,-0.45996013696365e-1, 29 | 4,1,3,-0.57581259083432e-1, 30 | 5,1,6,-0.50325278727930e-1, 31 | 6,2,1,-0.33032641670203e-4, 32 | 7,2,2,-0.18948987516315e-3, 33 | 8,2,4,-0.39392777243355e-2, 34 | 9,2,7,-0.43797295650573e-1, 35 | 10,2,36,-0.26674547914087e-4, 36 | 11,3,0,0.20481737692309e-7, 37 | 12,3,1,0.43870667284435e-6, 38 | 13,3,3,-0.32277677238570e-4, 39 | 14,3,6,-0.15033924542148e-2, 40 | 15,3,35,-0.40668253562649e-1, 41 | 16,4,1,-0.78847309559367e-9, 42 | 17,4,2,0.12790717852285e-7, 43 | 18,4,3,0.48225372718507e-6, 44 | 19,5,7,0.22922076337661e-5, 45 | 20,6,3,-0.16714766451061e-10, 46 | 21,6,16,-0.21171472321355e-2, 47 | 22,6,35,-0.23895741934104e2, 48 | 23,7,0,-0.59059564324270e-17, 49 | 24,7,11,-0.12621808899101e-5, 50 | 25,7,25,-0.38946842435739e-1, 51 | 26,8,8,0.11256211360459e-10, 52 | 27,8,36,-0.82311340897998e1, 53 | 28,9,13,0.19809712802088e-7, 54 | 29,10,4,0.10406965210174e-18, 55 | 30,10,10,-0.10234747095929e-12, 56 | 31,10,14,-0.10018179379511e-8, 57 | 32,16,29,-0.80882908646985e-10, 58 | 33,16,50,0.10693031879409, 59 | 34,18,57,-0.33662250574171, 60 | 35,20,20,0.89185845355421e-24, 61 | 36,20,35,0.30629316876232e-12, 62 | 37,20,48,-0.42002467698208e-5, 63 | 38,21,21,-0.59056029685639e-25, 64 | 39,22,53,0.37826947613457e-5, 65 | 40,23,39,-0.12768608934681e-14, 66 | 41,24,26,0.73087610595061e-28, 67 | 42,24,40,0.55414715350778e-16, 68 | 43,24,58,-0.94369707241210e-6, 69 | }; 70 | 71 | static double region2a_coeff_ph[34][4]={ 72 | 1,0,0,0.10898952318288e4, 73 | 2,0,1,0.84951654495535e3, 74 | 3,0,2,-0.10781748091826e3, 75 | 4,0,3,0.33153654801263e2, 76 | 5,0,7,-0.74232016790248e1, 77 | 6,0,20,0.11765048724356e2, 78 | 7,1,0,0.18445749355790e1, 79 | 8,1,1,-0.41792700549624e1, 80 | 9,1,2,0.62478196935812e1, 81 | 10,1,3,-0.17344563108114e2, 82 | 11,1,7,-0.20058176862096e3, 83 | 12,1,9,0.27196065473796e3, 84 | 13,1,11,-0.45511318285818e3, 85 | 14,1,18,0.30919688604755e4, 86 | 15,1,44,0.25226640357872e6, 87 | 16,2,0,-0.61707422868339e-2, 88 | 17,2,2,-0.31078046629583, 89 | 18,2,7,0.11670873077107e2, 90 | 19,2,36,0.12812798404046e9, 91 | 20,2,38,-0.98554909623276e9, 92 | 21,2,40,0.28224546973002e10, 93 | 22,2,42,-0.35948971410703e10, 94 | 23,2,44,0.17227349913197e10, 95 | 24,3,24,-0.13551334240775e5, 96 | 25,3,44,0.12848734664650e8, 97 | 26,4,12,0.13865724283226e1, 98 | 27,4,32,0.23598832556514e6, 99 | 28,4,44,-0.13105236545054e8, 100 | 29,5,32,0.73999835474766e4, 101 | 30,5,36,-0.55196697030060e6, 102 | 31,5,42,0.37154085996233e7, 103 | 32,6,34,0.19127729239660e5, 104 | 33,6,44,-0.41535164835634e6, 105 | 34,7,28,-0.62459855192507e2, 106 | }; 107 | 108 | static double region2b_coeff_ph[38][4]={ 109 | 1,0,0,0.14895041079516e4, 110 | 2,0,1,0.74307798314034e3, 111 | 3,0,2,-0.97708318797837e2, 112 | 4,0,12,0.24742464705674e1, 113 | 5,0,18,-0.63281320016026, 114 | 6,0,24,0.11385952129658e1, 115 | 7,0,28,-0.47811863648625, 116 | 8,0,40,0.85208123431544e-2, 117 | 9,1,0,0.93747147377932, 118 | 10,1,2,0.33593118604916e1, 119 | 11,1,6,0.33809355601454e1, 120 | 12,1,12,0.16844539671904, 121 | 13,1,18,0.73875745236695, 122 | 14,1,24,-0.47128737436186, 123 | 15,1,28,0.15020273139707, 124 | 16,1,40,-0.21764114219750e-2, 125 | 17,2,2,-0.21810755324761e-1, 126 | 18,2,8,-0.10829784403677, 127 | 19,2,18,-0.46333324635812e-1, 128 | 20,2,40,0.71280351959551e-4, 129 | 21,3,1,0.11032831789999e-3, 130 | 22,3,2,0.18955248387902e-3, 131 | 23,3,12,0.30891541160537e-2, 132 | 24,3,24,0.13555504554949e-2, 133 | 25,4,2,0.28640237477456e-6, 134 | 26,4,12,-0.10779857357512e-4, 135 | 27,4,18,-0.76462712454814e-4, 136 | 28,4,24,0.14052392818316e-4, 137 | 29,4,28,-0.31083814331434e-4, 138 | 30,4,40,-0.10302738212103e-5, 139 | 31,5,18,0.28217281635040e-6, 140 | 32,5,24,0.12704902271945e-5, 141 | 33,5,40,0.73803353468292e-7, 142 | 34,6,28,-0.11030139238909e-7, 143 | 35,7,2,-0.81456365207833e-13, 144 | 36,7,28,-0.25180545682962e-10, 145 | 37,9,1,-0.17565233969407e-17, 146 | 38,9,40,0.86934156344163e-14, 147 | }; 148 | 149 | static double region2c_coeff_ph[23][4]={ 150 | 1,-7,0,-0.32368398555242e13, 151 | 2,-7,4,0.73263350902181e13, 152 | 3,-6,0,0.35825089945447e12, 153 | 4,-6,2,-0.58340131851590e12, 154 | 5,-5,0,-0.10783068217470e11, 155 | 6,-5,2,0.20825544563171e11, 156 | 7,-2,0,0.61074783564516e6, 157 | 8,-2,1,0.85977722535580e6, 158 | 9,-1,0,-0.25745723604170e5, 159 | 10,-1,2,0.31081088422714e5, 160 | 11,0,0,0.12082315865936e4, 161 | 12,0,1,0.48219755109255e3, 162 | 13,1,4,0.37966001272486e1, 163 | 14,1,8,-0.10842984880077e2, 164 | 15,2,4,-0.45364172676660e-1, 165 | 16,6,0,0.14559115658698e-12, 166 | 17,6,1,0.11261597407230e-11, 167 | 18,6,4,-0.17804982240686e-10, 168 | 19,6,10,0.12324579690832e-6, 169 | 20,6,12,-0.11606921130984e-5, 170 | 21,6,16,0.27846367088554e-4, 171 | 22,6,20,-0.59270038474176e-3, 172 | 23,6,22,0.12918582991878e-2, 173 | }; 174 | 175 | static double region2a_coeff_ps[46][4]={ 176 | 1,-1.5,-24,-0.39235983861984e6, 177 | 2,-1.5,-23,0.51526573827270e6, 178 | 3,-1.5,-19,0.40482443161048e5, 179 | 4,-1.5,-13,-0.32193790923902e3, 180 | 5,-1.5,-11,0.96961424218694e2, 181 | 6,-1.5,-10,-0.22867846371773e2, 182 | 7,-1.25,-19,-0.44942914124357e6, 183 | 8,-1.25,-15,-0.50118336020166e4, 184 | 9,-1.25,-6,0.35684463560015, 185 | 10,-1.0,-26,0.44235335848190e5, 186 | 11,-1.0,-21,-0.13673388811708e5, 187 | 12,-1.0,-17,0.42163260207864e6, 188 | 13,-1.0,-16,0.22516925837475e5, 189 | 14,-1.0,-9,0.47442144865646e3, 190 | 15,-1.0,-8,-0.14931130797647e3, 191 | 16,-0.75,-15,-0.19781126320452e6, 192 | 17,-0.75,-14,-0.23554399470760e5, 193 | 18,-0.5,-26,-0.19070616302076e5, 194 | 19,-0.5,-13,0.55375669883164e5, 195 | 20,-0.5,-9,0.38293691437363e4, 196 | 21,-0.5,-7,-0.60391860580567e3, 197 | 22,-0.25,-27,0.19363102620331e4, 198 | 23,-0.25,-25,0.42660643698610e4, 199 | 24,-0.25,-11,-0.59780638872718e4, 200 | 25,-0.25,-6,-0.70401463926862e3, 201 | 26,0.25,1,0.33836784107553e3, 202 | 27,0.25,4,0.20862786635187e2, 203 | 28,0.25,8,0.33834172656196e-1, 204 | 29,0.25,11,-0.43124428414893e-4, 205 | 30,0.5,0,0.16653791356412e3, 206 | 31,0.5,1,-0.13986292055898e3, 207 | 32,0.5,5,-0.78849547999872, 208 | 33,0.5,6,0.72132411753872e-1, 209 | 34,0.5,10,-0.59754839398283e-2, 210 | 35,0.5,14,-0.12141358953904e-4, 211 | 36,0.5,16,0.23227096733871e-6, 212 | 37,0.75,0,-0.10538463566194e2, 213 | 38,0.75,4,0.20718925496502e1, 214 | 39,0.75,9,-0.72193155260427e-1, 215 | 40,0.75,17,0.20749887081120e-6, 216 | 41,1,7,-0.18340657911379e-1, 217 | 42,1,18,0.29036272348696e-6, 218 | 43,1.25,3,0.21037527893619, 219 | 44,1.25,15,0.25681239729999e-3, 220 | 45,1.5,5,-0.12799002933781e-1, 221 | 46,1.5,18,-0.82198102652018e-5, 222 | }; 223 | 224 | const double region2b_coeff_ps[44][4]={ 225 | 1,-6,0,0.31687665083497e6, 226 | 2,-6,11,0.20864175881858e2, 227 | 3,-5,0,-0.39859399803599e6, 228 | 4,-5,11,-0.21816058518877e2, 229 | 5,-4,0,0.22369785194242e6, 230 | 6,-4,1,-0.27841703445817e4, 231 | 7,-4,11,0.99207436071480e1, 232 | 8,-3,0,-0.75197512299157e5, 233 | 9,-3,1,0.29708605951158e4, 234 | 10,-3,11,-0.34406878548526e1, 235 | 11,-3,12,0.38815564249115, 236 | 12,-2,0,0.17511295085750e5, 237 | 13,-2,1,-0.14237112854449e4, 238 | 14,-2,6,0.10943803364167e1, 239 | 15,-2,10,0.89971619308495, 240 | 16,-1,0,-0.33759740098958e4, 241 | 17,-1,1,0.47162885818355e3, 242 | 18,-1,5,-0.19188241993679e1, 243 | 19,-1,8,0.41078580492196, 244 | 20,-1,9,-0.33465378172097, 245 | 21,0,0,0.13870034777505e4, 246 | 22,0,1,-0.40663326195838e3, 247 | 23,0,2,0.41727347159610e2, 248 | 24,0,4,0.21932549434532e1, 249 | 25,0,5,-0.10320050009077e1, 250 | 26,0,6,0.35882943516703, 251 | 27,0,9,0.52511453726066e-2, 252 | 28,1,0,0.12838916450705e2, 253 | 29,1,1,-0.28642437219381e1, 254 | 30,1,2,0.56912683664855, 255 | 31,1,3,-0.99962954584931e-1, 256 | 32,1,7,-0.32632037778459e-2, 257 | 33,1,8,0.23320922576723e-3, 258 | 34,2,0,-0.15334809857450, 259 | 35,2,1,0.29072288239902e-1, 260 | 36,2,5,0.37534702741167e-3, 261 | 37,3,0,0.17296691702411e-2, 262 | 38,3,1,-0.38556050844504e-3, 263 | 39,3,3,-0.35017712292608e-4, 264 | 40,4,0,-0.14566393631492e-4, 265 | 41,4,1,0.56420857267269e-5, 266 | 42,5,0,0.41286150074605e-7, 267 | 43,5,1,-0.20684671118824e-7, 268 | 44,5,2,0.16409393674725e-8, 269 | }; 270 | 271 | const double region2c_coeff_ps[30][4]={ 272 | 1,-2,0,0.90968501005365e3, 273 | 2,-2,1,0.24045667088420e4, 274 | 3,-1,0,-0.59162326387130e3, 275 | 4,0,0,0.54145404128074e3, 276 | 5,0,1,-0.27098308411192e3, 277 | 6,0,2,0.97976525097926e3, 278 | 7,0,3,-0.46966772959435e3, 279 | 8,1,0,0.14399274604723e2, 280 | 9,1,1,-0.19104204230429e2, 281 | 10,1,3,0.53299167111971e1, 282 | 11,1,4,-0.21252975375934e2, 283 | 12,2,0,-0.31147334413760, 284 | 13,2,1,0.60334840894623, 285 | 14,2,2,-0.42764839702509e-1, 286 | 15,3,0,0.58185597255259e-2, 287 | 16,3,1,-0.14597008284753e-1, 288 | 17,3,5,0.56631175631027e-2, 289 | 18,4,0,-0.76155864584577e-4, 290 | 19,4,1,0.22440342919332e-3, 291 | 20,4,4,-0.12561095013413e-4, 292 | 21,5,0,0.63323132660934e-6, 293 | 22,5,1,-0.20541989675375e-5, 294 | 23,5,2,0.36405370390082e-7, 295 | 24,6,0,-0.29759897789215e-8, 296 | 25,6,1,0.10136618529763e-7, 297 | 26,7,0,0.59925719692351e-11, 298 | 27,7,1,-0.20677870105164e-10, 299 | 28,7,3,-0.20874278181886e-10, 300 | 29,7,4,0.10162166825089e-9, 301 | 30,7,5,-0.16429828281347e-9, 302 | }; 303 | 304 | const double region2a_coeff_hs[29][4]={ 305 | 1,0,1,-0.182575361923032e-1, 306 | 2,0,3,-0.125229548799536, 307 | 3,0,6,0.592290437320145, 308 | 4,0,16,0.604769706185122e1, 309 | 5,0,20,0.238624965444474e3, 310 | 6,0,22,-0.298639090222922e3, 311 | 7,1,0,0.512250813040750e-1, 312 | 8,1,1,-0.437266515606486, 313 | 9,1,2,0.413336902999504, 314 | 10,1,3,-0.516468254574773e1, 315 | 11,1,5,-0.557014838445711e1, 316 | 12,1,6,0.128555037824478e2, 317 | 13,1,10,0.114144108953290e2, 318 | 14,1,16,-0.119504225652714e3, 319 | 15,1,20,-0.284777985961560e4, 320 | 16,1,22,0.431757846408006e4, 321 | 17,2,3,0.112894040802650e1, 322 | 18,2,16,0.197409186206319e4, 323 | 19,2,20,0.151612444706087e4, 324 | 20,3,0,0.141324451421235e-1, 325 | 21,3,2,0.585501282219601, 326 | 22,3,3,-0.297258075863012e1, 327 | 23,3,6,0.594567314847319e1, 328 | 24,3,16,-0.623656565798905e4, 329 | 25,4,16,0.965986235133332e4, 330 | 26,5,3,0.681500934948134e1, 331 | 27,5,16,-0.633207286824489e4, 332 | 28,6,3,-0.558919224465760e1, 333 | 29,7,1,0.400645798472063e-1, 334 | }; 335 | 336 | const double region2b_coeff_hs[33][4]={ 337 | 1,0,0,0.801496989929495e-1, 338 | 2,0,1,-0.543862807146111, 339 | 3,0,2,0.337455597421283, 340 | 4,0,4,0.890555451157450e1, 341 | 5,0,8,0.313840736431485e3, 342 | 6,1,0,0.797367065977789, 343 | 7,1,1,-0.121616973556240e1, 344 | 8,1,2,0.872803386937477e1, 345 | 9,1,3,-0.169769781757602e2, 346 | 10,1,5,-0.186552827328416e3, 347 | 11,1,12,0.951159274344237e5, 348 | 12,2,1,-0.189168510120494e2, 349 | 13,2,6,-0.433407037194840e4, 350 | 14,2,18,0.543212633012715e9, 351 | 15,3,0,0.144793408386013, 352 | 16,3,1,0.128024559637516e3, 353 | 17,3,7,-0.672309534071268e5, 354 | 18,3,12,0.336972380095287e8, 355 | 19,4,1,-0.586634196762720e3, 356 | 20,4,16,-0.221403224769889e11, 357 | 21,5,1,0.171606668708389e4, 358 | 22,5,12,-0.570817595806302e9, 359 | 23,6,1,-0.312109693178482e4, 360 | 24,6,8,-0.207841384633010e7, 361 | 25,6,18,0.305605946157786e13, 362 | 26,7,1,0.322157004314333e4, 363 | 27,7,16,0.326810259797295e12, 364 | 28,8,1,-0.144104158934487e4, 365 | 29,8,3,0.410694867802691e3, 366 | 30,8,14,0.109077066873024e12, 367 | 31,8,18,-0.247964654258893e14, 368 | 32,12,10,0.188801906865134e10, 369 | 33,14,16,-0.123651009018773e15, 370 | }; 371 | 372 | const double region2c_coeff_hs[31][4]={ 373 | 1,0,0,0.112225607199012, 374 | 2,0,1,-0.339005953606712e1, 375 | 3,0,2,-0.320503911730094e2, 376 | 4,0,3,-0.197597305104900e3, 377 | 5,0,4,-0.407693861553446e3, 378 | 6,0,8,0.132943775222331e5, 379 | 7,1,0,0.170846839774007e1, 380 | 8,1,2,0.373694198142245e2, 381 | 9,1,5,0.358144365815434e4, 382 | 10,1,8,0.423014446424664e6, 383 | 11,1,14,-0.751071025760063e9, 384 | 12,2,2,0.523446127607898e2, 385 | 13,2,3,-0.228351290812417e3, 386 | 14,2,7,-0.960652417056937e6, 387 | 15,2,10,-0.807059292526074e8, 388 | 16,2,18,0.162698017225669e13, 389 | 17,3,0,0.772465073604171, 390 | 18,3,5,0.463929973837746e5, 391 | 19,3,8,-0.137317885134128e8, 392 | 20,3,16,0.170470392630512e13, 393 | 21,3,18,-0.251104628187308e14, 394 | 22,4,18,0.317748830835520e14, 395 | 23,5,1,0.538685623675312e2, 396 | 24,5,4,-0.553089094625169e5, 397 | 25,5,6,-0.102861522421405e7, 398 | 26,5,14,0.204249418756234e13, 399 | 27,6,8,0.273918446626977e9, 400 | 28,6,18,-0.263963146312685e16, 401 | 29,10,7,-0.107890854108088e10, 402 | 30,12,7,-0.296492620980124e11, 403 | 31,16,10,-0.111754907323424e16, 404 | }; 405 | 406 | double gm0(double pi, double tau) 407 | { 408 | double ni,ji; 409 | double res=log(pi); 410 | int i; 411 | for(i=0;i<9;i++) 412 | { 413 | ni=region2_coeff0[i][2]; 414 | ji=region2_coeff0[i][1]; 415 | res+=(ni*pow(tau,ji)); 416 | } 417 | return res; 418 | } 419 | 420 | double gm0pi(double pi) 421 | { 422 | return 1/pi; 423 | } 424 | 425 | double gm0pipi(double pi) 426 | { 427 | return -1/(pi*pi); 428 | } 429 | 430 | double gm0tau(double tau) 431 | { 432 | double ni,ji; 433 | double res=0; 434 | int i; 435 | for(i=0;i<9;i++) 436 | { 437 | ni=region2_coeff0[i][2]; 438 | ji=region2_coeff0[i][1]; 439 | res+=(ni*ji*pow(tau,ji-1)); 440 | } 441 | return res; 442 | } 443 | 444 | double gm0tautau(double tau) 445 | { 446 | double ni,ji; 447 | double res=0; 448 | int i; 449 | for(i=0;i<9;i++) 450 | { 451 | ni=region2_coeff0[i][2]; 452 | ji=region2_coeff0[i][1]; 453 | res+=(ni*ji*(ji-1)*pow(tau,ji-2)); 454 | } 455 | return res; 456 | } 457 | 458 | double gmr(double pi, double tau) 459 | { 460 | int i; 461 | double res=0; 462 | double ni,ii,ji; 463 | for(i=0;i<43;i++) 464 | { 465 | ni=region2_coeffr[i][3]; 466 | ii=region2_coeffr[i][1]; 467 | ji=region2_coeffr[i][2]; 468 | res+=(ni*pow(pi,ii)*pow(tau-0.5,ji)); 469 | } 470 | return res; 471 | } 472 | 473 | double gmrpi(double pi, double tau) 474 | { 475 | int i; 476 | double res=0; 477 | double ni,ii,ji; 478 | for(i=0;i<43;i++) 479 | { 480 | ni=region2_coeffr[i][3]; 481 | ii=region2_coeffr[i][1]; 482 | ji=region2_coeffr[i][2]; 483 | res+=(ni*ii*pow(pi,ii-1)*pow(tau-0.5,ji)); 484 | } 485 | return res; 486 | } 487 | 488 | double gmrpipi(double pi, double tau) 489 | { 490 | int i; 491 | double res=0; 492 | double ni,ii,ji; 493 | for(i=0;i<43;i++) 494 | { 495 | ni=region2_coeffr[i][3]; 496 | ii=region2_coeffr[i][1]; 497 | ji=region2_coeffr[i][2]; 498 | res+=(ni*ii*(ii-1)*pow(pi,ii-2)*pow(tau-0.5,ji)); 499 | } 500 | return res; 501 | } 502 | 503 | double gmrtau(double pi, double tau) 504 | { 505 | int i; 506 | double res=0; 507 | double ni,ii,ji; 508 | for(i=0;i<43;i++) 509 | { 510 | ni=region2_coeffr[i][3]; 511 | ii=region2_coeffr[i][1]; 512 | ji=region2_coeffr[i][2]; 513 | res+=(ni*pow(pi,ii)*ji*pow(tau-0.5,ji-1)); 514 | } 515 | return res; 516 | } 517 | 518 | double gmrtautau(double pi, double tau) 519 | { 520 | int i; 521 | double res=0; 522 | double ni,ii,ji; 523 | for(i=0;i<43;i++) 524 | { 525 | ni=region2_coeffr[i][3]; 526 | ii=region2_coeffr[i][1]; 527 | ji=region2_coeffr[i][2]; 528 | res+=(ni*pow(pi,ii)*ji*(ji-1)*pow(tau-0.5,ji-2)); 529 | } 530 | return res; 531 | } 532 | 533 | double gmrpitau(double pi, double tau) 534 | { 535 | int i; 536 | double res=0; 537 | double ni,ii,ji; 538 | for(i=0;i<43;i++) 539 | { 540 | ni=region2_coeffr[i][3]; 541 | ii=region2_coeffr[i][1]; 542 | ji=region2_coeffr[i][2]; 543 | res+=(ni*ii*pow(pi,ii-1)*ji*pow(tau-0.5,ji-1)); 544 | } 545 | return res; 546 | } 547 | 548 | 549 | 550 | 551 | void steam_prop_calc_r2(double pressure, double temp, steam_prop* p_prop) 552 | { 553 | double pi,tau; 554 | 555 | pi=pressure/1e6; 556 | tau=540/temp; 557 | 558 | p_prop->pressure=pressure; 559 | p_prop->temp=temp; 560 | p_prop->spe_vol=pi*(gm0pi(pi)+gmrpi(pi,tau))*GAS_CONST_STEAM*temp/pressure; 561 | p_prop->dens=pressure/(GAS_CONST_STEAM*temp*(pi*(gm0pi(pi)+gmrpi(pi,tau)))); 562 | p_prop->spe_energy=GAS_CONST_STEAM*temp*(tau*(gm0tau(tau)+gmrtau(pi,tau))-pi*(gm0pi(pi)+gmrpi(pi,tau))); 563 | p_prop->spe_entr=GAS_CONST_STEAM*(tau*(gm0tau(tau)+gmrtau(pi,tau))-(gm0(pi,tau)+gmr(pi,tau))); 564 | p_prop->spe_enth=GAS_CONST_STEAM*temp*tau*(gm0tau(tau)+gmrtau(pi,tau)); 565 | p_prop->spe_h_v=GAS_CONST_STEAM*(pow(1+pi*gmrpi(pi,tau)-tau*pi*gmrpitau(pi,tau),2)/(1-pi*pi*gmrpipi(pi,tau))-tau*tau*(gm0tautau(tau)+gmrtautau(pi,tau))); 566 | p_prop->spe_h_p=-GAS_CONST_STEAM*tau*tau*(gm0tautau(tau)+gmrtautau(pi,tau)); 567 | p_prop->speed_sound=sqrt(GAS_CONST_STEAM*temp*(1+2*pi*gmrpi(pi,tau)+pi*pi*gmrpi(pi,tau)*gmrpi(pi,tau))/(1-pi*pi*gmrpipi(pi,tau)+pow(1+pi*gmrpi(pi,tau)-tau*pi*gmrpitau(pi,tau),2)/(tau*tau*(gm0tautau(tau)+gmrtautau(pi,tau))))); 568 | p_prop->drdp=-p_prop->dens*p_prop->dens*GAS_CONST_STEAM*temp*(gm0pipi(pi)+gmrpipi(pi,tau))/(1e12); 569 | p_prop->vapor_fraction=1; 570 | } 571 | 572 | int sub_region(double pressure, double spec_enth) 573 | { 574 | double eta; 575 | double pi, pi_ref; 576 | double n1,n2,n3; 577 | 578 | n1=0.90584278514723e3; 579 | n2=-0.67955786399241; 580 | n3=0.12809002730136e-3; 581 | 582 | if(pressure<4e6) 583 | { 584 | return 21; 585 | } 586 | else 587 | { 588 | eta=spec_enth/1000; 589 | pi=pressure/1e6; 590 | pi_ref=n1+n2*eta+n3*eta*eta; 591 | if(pi>pi_ref||pi==pi_ref) 592 | { 593 | return 23; 594 | } 595 | else 596 | { 597 | return 22; 598 | } 599 | } 600 | } 601 | 602 | int temp_ph_r2(double* temp, double pressure, double spec_enth) 603 | { 604 | int sub_reg; 605 | int i; 606 | double ni,ii,ji,eta,pi,tau; 607 | tau=0; 608 | 609 | pi=pressure/1e6; 610 | eta=spec_enth/2e6; 611 | 612 | sub_reg=sub_region(pressure,spec_enth); 613 | if(sub_reg==21) 614 | { 615 | for(i=0;i<34;i++) 616 | { 617 | ni=region2a_coeff_ph[i][3]; 618 | ii=region2a_coeff_ph[i][1]; 619 | ji=region2a_coeff_ph[i][2]; 620 | tau+=ni*pow(pi,ii)*pow(eta-2.1,ji); 621 | } 622 | } 623 | else if(sub_reg==22) 624 | { 625 | for(i=0;i<38;i++) 626 | { 627 | ni=region2b_coeff_ph[i][3]; 628 | ii=region2b_coeff_ph[i][1]; 629 | ji=region2b_coeff_ph[i][2]; 630 | tau+=ni*pow(pi-2,ii)*pow(eta-2.6,ji); 631 | } 632 | } 633 | else if(sub_reg==23) 634 | { 635 | for(i=0;i<23;i++) 636 | { 637 | ni=region2c_coeff_ph[i][3]; 638 | ii=region2c_coeff_ph[i][1]; 639 | ji=region2c_coeff_ph[i][2]; 640 | tau+=ni*pow(pi+25,ii)*pow(eta-1.8,ji); 641 | } 642 | } 643 | *temp=tau; 644 | return 0; 645 | } 646 | 647 | int sub_region_s(double pressure, double spe_entr) 648 | { 649 | if(pressure<4e6) 650 | { 651 | return 21; 652 | } 653 | else 654 | { 655 | if(spe_entr<5.85e3) 656 | { 657 | return 23; 658 | } 659 | else 660 | { 661 | return 22; 662 | } 663 | } 664 | } 665 | 666 | int temp_ps_r2(double* temp, double pressure, double spe_entr) 667 | { 668 | int sub_reg; 669 | double pi,sigma2a,sigma2b,sigma2c,ni,ii,ji; 670 | int i; 671 | double tau=0; 672 | 673 | pi=pressure/1e6; 674 | sigma2a=spe_entr/2e3; 675 | sigma2b=spe_entr/0.7853e3; 676 | sigma2c=spe_entr/2.9251e3; 677 | 678 | sub_reg=sub_region_s(pressure,spe_entr); 679 | if(sub_reg==21) 680 | { 681 | for(i=0;i<46;i++) 682 | { 683 | ni=region2a_coeff_ps[i][3]; 684 | ii=region2a_coeff_ps[i][1]; 685 | ji=region2a_coeff_ps[i][2]; 686 | tau+=ni*pow(pi,ii)*pow(sigma2a-2,ji); 687 | } 688 | } 689 | 690 | else if(sub_reg==22) 691 | { 692 | for(i=0;i<44;i++) 693 | { 694 | ni=region2b_coeff_ps[i][3]; 695 | ii=region2b_coeff_ps[i][1]; 696 | ji=region2b_coeff_ps[i][2]; 697 | tau+=ni*pow(pi,ii)*pow(10-sigma2b,ji); 698 | } 699 | } 700 | 701 | else if(sub_reg==23) 702 | { 703 | for(i=0;i<30;i++) 704 | { 705 | ni=region2c_coeff_ps[i][3]; 706 | ii=region2c_coeff_ps[i][1]; 707 | ji=region2c_coeff_ps[i][2]; 708 | tau+=ni*pow(pi,ii)*pow(2-sigma2c,ji); 709 | } 710 | } 711 | *temp=tau; 712 | return 0; 713 | } 714 | 715 | int sub_region_hs(double spe_enth, double spe_entr) 716 | { 717 | double n[4]={-0.349898083432139e4,0.257560716905876e4,-0.421073558227969e3,0.276349063799944e2}; 718 | double h2ab; 719 | 720 | h2ab=n[0]+n[1]*spe_entr/1e3+n[2]*spe_entr*spe_entr/1e6+n[3]*spe_entr*spe_entr*spe_entr/1e9; 721 | 722 | if(spe_entr<5.85e3) 723 | { 724 | return 23; 725 | } 726 | else 727 | { 728 | if(spe_enth/1e3>h2ab) 729 | { 730 | return 22; 731 | } 732 | else 733 | { 734 | return 21; 735 | } 736 | } 737 | } 738 | 739 | int pres_hs_r2(double* pressure, double spe_enth, double spe_entr) 740 | { 741 | double eta2a,eta2b,eta2c,sig2a,sig2b,sig2c; 742 | int i; 743 | int sub_reg; 744 | double pi; 745 | double ni,ii,ji; 746 | 747 | eta2a=spe_enth/4200e3; 748 | eta2b=spe_enth/4100e3; 749 | eta2c=spe_enth/3500e3; 750 | sig2a=spe_entr/12e3; 751 | sig2b=spe_entr/7.9e3; 752 | sig2c=spe_entr/5.9e3; 753 | 754 | sub_reg=sub_region_hs(spe_enth,spe_entr); 755 | // printf("\n\n\\\\\\\\\\\\\\\\\\\\\\\\%d\n",sub_reg); 756 | if(sub_reg==21) 757 | { 758 | pi=0; 759 | for(i=0;i<29;i++) 760 | { 761 | ni=region2a_coeff_hs[i][3]; 762 | ii=region2a_coeff_hs[i][1]; 763 | ji=region2a_coeff_hs[i][2]; 764 | pi+=ni*pow(eta2a-0.5,ii)*pow(sig2a-1.2,ji); 765 | } 766 | *pressure=pi*pi*pi*pi*4e6; 767 | return 0; 768 | } 769 | else if(sub_reg==22) 770 | { 771 | pi=0; 772 | for(i=0;i<33;i++) 773 | { 774 | ni=region2b_coeff_hs[i][3]; 775 | ii=region2b_coeff_hs[i][1]; 776 | ji=region2b_coeff_hs[i][2]; 777 | pi+=ni*pow(eta2b-0.6,ii)*pow(sig2b-1.01,ji); 778 | } 779 | *pressure=pi*pi*pi*pi*1e8; 780 | return 0; 781 | } 782 | else if(sub_reg==23) 783 | { 784 | pi=0; 785 | for(i=0;i<31;i++) 786 | { 787 | ni=region2c_coeff_hs[i][3]; 788 | ii=region2c_coeff_hs[i][1]; 789 | ji=region2c_coeff_hs[i][2]; 790 | pi+=ni*pow(eta2c-0.7,ii)*pow(sig2c-1.1,ji); 791 | } 792 | *pressure=pi*pi*pi*pi*1e8; 793 | // printf("\n[[[[[[[[[[[[[[[[[[[[[[%lf,%lf\n",pi,*pressure); 794 | return 0; 795 | } 796 | return -1; 797 | } 798 | 799 | void calcFT_dFT_prr2(double* ft, double* dft, double pressure, double dens, double tau) 800 | { 801 | double pi; 802 | pi=pressure/1e6; 803 | *ft=gm0pi(pi)+gmrpi(pi,tau)-1e6*tau/(dens*GAS_CONST_STEAM*540); 804 | *dft=gmrpitau(pi,tau)-1e6/(dens*GAS_CONST_STEAM*540); 805 | } 806 | 807 | int temp_pr_r2(double* temp, double pressure, double dens) 808 | { 809 | double tau_prev,tau_nxt,ft,dft; 810 | int iter_times; 811 | int ti=0; 812 | double tau_ini[10]={ 813 | 1.97,1.8,1.5,1.3,1.1,1,0.9,0.7,0.6,0.5, 814 | }; 815 | 816 | do{ 817 | iter_times=0; 818 | calcFT_dFT_prr2(&ft,&dft,pressure,dens,tau_ini[ti]); 819 | tau_nxt=tau_ini[ti]-ft/dft; 820 | do{ 821 | tau_prev=tau_nxt; 822 | calcFT_dFT_prr2(&ft,&dft,pressure,dens,tau_prev); 823 | tau_nxt=tau_prev-ft/dft; 824 | iter_times++; 825 | }while(fabs(tau_nxt-tau_prev)>1e-6&&iter_times1e-6&&iter_times1e-8&&iter_times1e-8&&iter_times1e-8&&iter_times1e-8&&iter_timesfabs(dp)) 1178 | { 1179 | maxd=fabs(dt); 1180 | } 1181 | else 1182 | { 1183 | maxd=fabs(dp); 1184 | } 1185 | i++; 1186 | }while(maxd>1e-8&&i 2 | #include 3 | #include "if97_general.h" 4 | #include "region_calc.h" 5 | #include "region1.h" 6 | #include "region2.h" 7 | #include "region3.h" 8 | #include "region5.h" 9 | #include "steam_property_calc.h" 10 | 11 | static double coeff_visc1[4]={ 12 | 1.67752,2.20462,0.6366564,-0.241605 13 | }; 14 | 15 | static double coeff_visc2[6][7]={ 16 | 5.20094e-1,2.22531e-1,-2.81378e-1,1.61913e-1,-3.25372e-2,0,0, 17 | 8.50895e-2,9.99115e-1,-9.06851e-1,2.57399e-1,0,0,0, 18 | -1.08374,1.88797,-7.72479e-1,0,0,0,0, 19 | -2.89555e-1,1.26613,-4.89837e-1,0,6.98452e-2,0,-4.35673e-3, 20 | 0,0,-2.57040e-1,0,0,8.72102e-3,0, 21 | 0,1.20573e-1,0,0,0,0,-5.93264e-4, 22 | }; 23 | 24 | static double coeff_thcond1[5]={ 25 | 2.443221e-3,1.323095e-2,6.770357e-3,-3.454586e-3,4.096266e-4 26 | }; 27 | 28 | static double coeff_thcond2[5][6]={ 29 | 1.60397357,-0.646013523,0.111443906,0.102997357,-0.0504123634,0.00609859258, 30 | 2.33771842,-2.78843778,1.53616167,-0.463045512,0.0832827019,-0.00719201245, 31 | 2.19650529,-4.54580785,3.55777244,-1.40944978,0.275418278,-0.0205938816, 32 | -1.21051378,1.60812989,-0.621178141,0.0716373224,0,0, 33 | -2.7203370,4.57586331,-3.18369245,1.1168348,-0.19268305,0.012913842, 34 | }; 35 | 36 | static double coeff_thcond3[6][5]={ 37 | 6.53786807199516,6.52717759281799,5.35500529896124,1.55225959906681,1.11999926419994, 38 | -5.61149954923348,-6.30816983387575,-3.96415689925446,0.464621290821181,0.595748562571649, 39 | 3.39624167361325,8.08379285492595,8.91990208918795,8.93237374861479,9.8895256507892, 40 | -2.27492629730878,-9.82240510197603,-12.033872950579,-11.0321960061126,-10.325505114704, 41 | 10.2631854662709,12.1358413791395,9.19494865194302,6.1678099993336,4.66861294457414, 42 | 1.97815050331519,-5.54349664571295,-2.16866274479712,-0.965458722086812,-0.503243546373828, 43 | }; 44 | 45 | static double coeff_thcond4[6][5]={ 46 | 6.53786807199516,6.52717759281799,5.35500529896124,1.55225959906681,1.11999926419994, 47 | -5.61149954923348,-6.30816983387575,-3.96415689925446,0.464621290821181,0.595748562571649, 48 | 3.39624167361325,8.08379285492595,8.91990208918795,8.93237374861479,9.8895256507892, 49 | -2.27492629730878,-9.82240510197603,-12.033872950579,-11.0321960061126,-10.325505114704, 50 | 10.2631854662709,12.1358413791395,9.19494865194302,6.1678099993336,4.66861294457414, 51 | 1.97815050331519,-5.54349664571295,-2.16866274479712,-0.965458722086812,-0.503243546373828, 52 | }; 53 | 54 | void print_prop(steam_prop *p_prop) 55 | { 56 | printf("%.14lf\n%.14lf\n%.14lf\n%.14lf\n%.14lf\n%.14lf\n%.14lf\n%.14lf\n%.14lf\n%.14lf\n",p_prop->pressure,p_prop->temp,p_prop->spe_vol,p_prop->dens,p_prop->spe_energy,p_prop->spe_entr,p_prop->spe_enth,p_prop->spe_h_v,p_prop->spe_h_p,p_prop->speed_sound); 57 | } 58 | 59 | int hs_find_tsat(double *t, double spe_enth, double spe_entr) 60 | { 61 | double tt1,tt2,ps1,ps2,xs1,xs2,xh1,xh2,ttm,psm,xhm,xsm; 62 | steam_prop propw,props,propmw,propms; 63 | int i=0; 64 | 65 | tt1=MIN_TEMP; 66 | tt2=INTER_TEMP1; 67 | ps1=calc_sat_pres(tt1); 68 | ps2=calc_sat_pres(tt2); 69 | steam_prop_calc_r1(ps1,tt1,&propw); 70 | steam_prop_calc_r2(ps1,tt1,&props); 71 | xs1=(spe_entr-propw.spe_entr)/(props.spe_entr-propw.spe_entr); 72 | xh1=(spe_enth-propw.spe_enth)/(props.spe_enth-propw.spe_enth); 73 | // printf("\n%lf,%lf\n",xh1,xs1); 74 | steam_prop_calc_r1(ps2,tt2,&propw); 75 | steam_prop_calc_r2(ps2,tt2,&props); 76 | xs2=(spe_entr-propw.spe_entr)/(props.spe_entr-propw.spe_entr); 77 | xh2=(spe_enth-propw.spe_enth)/(props.spe_enth-propw.spe_enth); 78 | // printf("\n%lf,%lf\n",xh2,xs2); 79 | if((xh1-xs1)*(xh2-xs2)>0) 80 | { 81 | *t=-1; 82 | return -1; 83 | } 84 | do 85 | { 86 | ttm=0.5*(tt1+tt2); 87 | // printf("\n............%lf\n",ttm); 88 | psm=calc_sat_pres(ttm); 89 | // printf("\n...........%lf,%lf\n",psm,ttm); 90 | steam_prop_calc_r1(psm,ttm,&propmw); 91 | steam_prop_calc_r2(psm,ttm,&propms); 92 | xsm=(spe_entr-propmw.spe_entr)/(propms.spe_entr-propmw.spe_entr); 93 | xhm=(spe_enth-propmw.spe_enth)/(propms.spe_enth-propmw.spe_enth); 94 | // printf("\n...........%lf,%lf\n",xhm,xsm); 95 | i++; 96 | if(fabs(xhm-xsm)<1e-6) 97 | { 98 | *t=ttm; 99 | return 0; 100 | } 101 | else if((xhm-xsm)*(xh1-xs1)>0) 102 | { 103 | tt1=ttm; 104 | } 105 | else if((xhm-xsm)*(xh2-xs2)>0) 106 | { 107 | tt2=ttm; 108 | } 109 | }while(i<200); 110 | if(i==200) 111 | { 112 | *t=-1; 113 | return -1; 114 | } 115 | } 116 | 117 | //normal version 118 | int steam_prop_calc_pt(double pressure, double temp, steam_prop *p_prop, steam_prop *p_prop_bkup) 119 | { 120 | int region_code; 121 | int calc_flag; 122 | 123 | p_prop_bkup->pressure=-1; 124 | p_prop_bkup->temp=-1; 125 | p_prop_bkup->spe_vol=-1; 126 | p_prop_bkup->dens=-1; 127 | p_prop_bkup->spe_energy=-1; 128 | p_prop_bkup->spe_entr=-1; 129 | p_prop_bkup->spe_enth=-1; 130 | p_prop_bkup->spe_h_v=-1; 131 | p_prop_bkup->spe_h_p=-1; 132 | p_prop_bkup->speed_sound=-1; 133 | p_prop_bkup->drdp=-1; 134 | 135 | region_code=region(pressure,temp); 136 | // printf("!!!!%d\n",region_code); 137 | if(region_code==-1) 138 | { 139 | printf("\nFATAL ERROR: PRESSURE/TEMP EXCEEDS BOUNDARIES.\n"); 140 | return -1; 141 | } 142 | else if(region_code==1) 143 | { 144 | steam_prop_calc_r1(pressure,temp,p_prop); 145 | return 0; 146 | } 147 | else if(region_code==2) 148 | { 149 | steam_prop_calc_r2(pressure,temp,p_prop); 150 | return 0; 151 | } 152 | 153 | else if(region_code==4) 154 | { 155 | steam_prop_calc_r1(pressure,temp,p_prop); 156 | steam_prop_calc_r2(pressure,temp,p_prop_bkup); 157 | return 1; 158 | } 159 | else if(region_code==3) 160 | { 161 | calc_flag=steam_prop_calc_r3(pressure,temp,p_prop); 162 | if(calc_flag==-1) 163 | { 164 | printf("\nFATAL ERROR: DENSITY ITERATION NOT CONVERGED.\n"); 165 | return -2; 166 | } 167 | else 168 | { 169 | // print_prop(p_prop); 170 | return 0; 171 | } 172 | } 173 | else if(region_code==5) 174 | { 175 | steam_prop_calc_r5(pressure,temp,p_prop); 176 | return 0; 177 | } 178 | } 179 | 180 | int steam_prop_calc_pr(double pressure, double dens, steam_prop* p_prop) 181 | { 182 | int rc,flag; 183 | double temp,temp_sat; 184 | double pres_h,pres_l,vapor_frac; 185 | steam_prop prop_w,prop_s; 186 | pres_l=calc_sat_pres(MIN_TEMP); 187 | pres_h=calc_sat_pres(INTER_TEMP1); 188 | 189 | // printf("\n\n%lf,%lf,%lf\n",pres_h,pres_l); 190 | if(pressure>pres_l&&pressureprop_s.dens&&denspressure=pressure; 202 | p_prop->temp=temp_sat; 203 | p_prop->spe_vol=1/dens; 204 | p_prop->dens=dens; 205 | p_prop->spe_energy=vapor_frac*prop_s.spe_energy+(1-vapor_frac)*prop_w.spe_energy; 206 | p_prop->spe_entr=vapor_frac*prop_s.spe_entr+(1-vapor_frac)*prop_w.spe_entr; 207 | p_prop->spe_enth=vapor_frac*prop_s.spe_enth+(1-vapor_frac)*prop_w.spe_enth; 208 | p_prop->spe_h_v=vapor_frac*prop_s.spe_h_v+(1-vapor_frac)*prop_w.spe_h_v; 209 | p_prop->spe_h_p=vapor_frac*prop_s.spe_h_p+(1-vapor_frac)*prop_w.spe_h_p; 210 | p_prop->speed_sound=vapor_frac*prop_s.speed_sound+(1-vapor_frac)*prop_w.speed_sound; 211 | p_prop->drdp=vapor_frac*prop_s.drdp+(1-vapor_frac)*prop_w.drdp; 212 | p_prop->vapor_fraction=vapor_frac; 213 | //solve vapor fraction and properties; 214 | 215 | return 0; 216 | } 217 | } 218 | 219 | // printf("\n\tPREEEEEEEEEEEEEEEEEEEEEEE\n"); 220 | flag=temp_pr_r1(&temp,pressure,dens); 221 | if(flag==0) 222 | { 223 | rc=region(pressure,temp); 224 | steam_prop_calc_r1(pressure,temp,p_prop); 225 | if(rc==1&&fabs((p_prop->dens-dens)/dens<1e-4)) 226 | { 227 | p_prop->dens=dens; 228 | return 0; 229 | } 230 | } 231 | 232 | flag=temp_pr_r2(&temp,pressure,dens); 233 | if(flag==0) 234 | { 235 | rc=region(pressure,temp); 236 | steam_prop_calc_r2(pressure,temp,p_prop); 237 | if(rc==2&&fabs((p_prop->dens-dens)/dens<1e-4)) 238 | { 239 | p_prop->dens=dens; 240 | return 0; 241 | } 242 | } 243 | 244 | flag=temp_pr_r3(&temp,pressure,dens); 245 | if(flag==0) 246 | { 247 | rc=region(pressure,temp); 248 | steam_prop_calc_r3(pressure,temp,p_prop); 249 | if(rc==3&&fabs((p_prop->dens-dens)/dens<1e-4)) 250 | { 251 | p_prop->dens=dens; 252 | return 0; 253 | } 254 | } 255 | flag=temp_pr_r5(&temp,pressure,dens); 256 | if(flag==0) 257 | { 258 | rc=region(pressure,temp); 259 | steam_prop_calc_r5(pressure,temp,p_prop); 260 | if(rc==5&&fabs((p_prop->dens-dens)/dens<1e-4)) 261 | { 262 | p_prop->dens=dens; 263 | return 0; 264 | } 265 | } 266 | return -1; 267 | } 268 | 269 | int steam_prop_calc_pu(double pressure, double spe_ener, steam_prop* p_prop) 270 | { 271 | int rc,flag; 272 | double temp,r3dens; 273 | double pres_h,pres_l,temp_sat,vapor_frac; 274 | steam_prop prop_s,prop_w; 275 | 276 | pres_l=calc_sat_pres(MIN_TEMP); 277 | pres_h=calc_sat_pres(INTER_TEMP1); 278 | 279 | if(pressure>pres_l&&pressureprop_w.spe_energy) 285 | { 286 | vapor_frac=(spe_ener-prop_w.spe_energy)/(prop_s.spe_energy-prop_w.spe_energy); 287 | p_prop->pressure=pressure; 288 | p_prop->temp=temp_sat; 289 | p_prop->spe_vol=vapor_frac*prop_s.spe_vol+(1-vapor_frac)*prop_w.spe_vol; 290 | p_prop->dens=1/p_prop->spe_vol; 291 | p_prop->spe_energy=spe_ener; 292 | p_prop->spe_entr=vapor_frac*prop_s.spe_entr+(1-vapor_frac)*prop_w.spe_entr; 293 | p_prop->spe_enth=vapor_frac*prop_s.spe_enth+(1-vapor_frac)*prop_w.spe_enth; 294 | p_prop->spe_h_v=vapor_frac*prop_s.spe_h_v+(1-vapor_frac)*prop_w.spe_h_v; 295 | p_prop->spe_h_p=vapor_frac*prop_s.spe_h_p+(1-vapor_frac)*prop_w.spe_h_p; 296 | p_prop->speed_sound=vapor_frac*prop_s.speed_sound+(1-vapor_frac)*prop_w.speed_sound; 297 | p_prop->drdp=vapor_frac*prop_s.drdp+(1-vapor_frac)*prop_w.drdp; 298 | p_prop->vapor_fraction=vapor_frac; 299 | //solve vapor fraction and properties; 300 | return 0; 301 | } 302 | } 303 | 304 | flag=temp_pu_r1(&temp,pressure,spe_ener); 305 | if(flag==0) 306 | { 307 | rc=region(pressure,temp); 308 | steam_prop_calc_r1(pressure,temp,p_prop); 309 | if(rc==1&&fabs((p_prop->spe_energy-spe_ener)/spe_ener)<1e-4) 310 | { 311 | p_prop->spe_energy=spe_ener; 312 | return 0; 313 | } 314 | } 315 | 316 | flag=temp_pu_r2(&temp,pressure,spe_ener); 317 | if(flag==0) 318 | { 319 | rc=region(pressure,temp); 320 | steam_prop_calc_r2(pressure,temp,p_prop); 321 | if(rc==2&&fabs((p_prop->spe_energy-spe_ener)/spe_ener)<1e-4) 322 | { 323 | p_prop->spe_energy=spe_ener; 324 | return 0; 325 | } 326 | } 327 | 328 | flag=tr_pu_r3(&temp,&r3dens,pressure,spe_ener); 329 | if(flag==0) 330 | { 331 | rc=region(pressure,temp); 332 | steam_prop_calc_r3(pressure,temp,p_prop); 333 | if(rc==3&&fabs((p_prop->spe_energy-spe_ener)/spe_ener)<1e-4) 334 | { 335 | p_prop->pressure=pressure; 336 | p_prop->spe_energy=spe_ener; 337 | return 0; 338 | } 339 | } 340 | 341 | flag=temp_pu_r5(&temp,pressure,spe_ener); 342 | if(flag==0) 343 | { 344 | rc=region(pressure,temp); 345 | steam_prop_calc_r5(pressure,temp,p_prop); 346 | if(rc==5&&fabs((p_prop->spe_energy-spe_ener)/spe_ener)<1e-4) 347 | { 348 | p_prop->spe_energy=spe_ener; 349 | return 0; 350 | } 351 | } 352 | return -1; 353 | } 354 | 355 | int steam_prop_calc_ph(double pressure, double spe_enth, steam_prop* p_prop) 356 | { 357 | int rc,flag; 358 | double temp,r3dens; 359 | double pres_h,pres_l,temp_sat,vapor_frac; 360 | steam_prop prop_s,prop_w; 361 | 362 | pres_l=calc_sat_pres(MIN_TEMP); 363 | pres_h=calc_sat_pres(INTER_TEMP1); 364 | 365 | if(pressure>pres_l&&pressureprop_w.spe_enth) 371 | { 372 | vapor_frac=(spe_enth-prop_w.spe_enth)/(prop_s.spe_enth-prop_w.spe_enth); 373 | p_prop->pressure=pressure; 374 | p_prop->temp=temp_sat; 375 | p_prop->spe_vol=vapor_frac*prop_s.spe_vol+(1-vapor_frac)*prop_w.spe_vol; 376 | p_prop->dens=1/p_prop->spe_vol; 377 | p_prop->spe_energy=vapor_frac*prop_s.spe_energy+(1-vapor_frac)*prop_w.spe_energy; 378 | p_prop->spe_entr=vapor_frac*prop_s.spe_entr+(1-vapor_frac)*prop_w.spe_entr; 379 | p_prop->spe_enth=spe_enth; 380 | p_prop->spe_h_v=vapor_frac*prop_s.spe_h_v+(1-vapor_frac)*prop_w.spe_h_v; 381 | p_prop->spe_h_p=vapor_frac*prop_s.spe_h_p+(1-vapor_frac)*prop_w.spe_h_p; 382 | p_prop->speed_sound=vapor_frac*prop_s.speed_sound+(1-vapor_frac)*prop_w.speed_sound; 383 | p_prop->drdp=vapor_frac*prop_s.drdp+(1-vapor_frac)*prop_w.drdp; 384 | p_prop->vapor_fraction=vapor_frac; 385 | //solve vapor fraction and properties; 386 | return 0; 387 | } 388 | } 389 | 390 | // printf("\nEEEEEEEEEEEEEEEEE\n\n"); 391 | flag=temp_ph_r1(&temp,pressure,spe_enth); 392 | if(flag==0) 393 | { 394 | rc=region(pressure,temp); 395 | steam_prop_calc_r1(pressure,temp,p_prop); 396 | if(rc==1&&fabs((p_prop->spe_enth-spe_enth)/spe_enth)<1e-4) 397 | { 398 | p_prop->spe_enth=spe_enth; 399 | return 0; 400 | } 401 | } 402 | 403 | flag=temp_ph_r2(&temp,pressure,spe_enth); 404 | if(flag==0) 405 | { 406 | rc=region(pressure,temp); 407 | steam_prop_calc_r2(pressure,temp,p_prop); 408 | if(rc==2&&fabs((p_prop->spe_enth-spe_enth)/spe_enth)<1e-4) 409 | { 410 | p_prop->spe_enth=spe_enth; 411 | return 0; 412 | } 413 | } 414 | 415 | flag=tr_ph_r3(&temp,&r3dens,pressure,spe_enth); 416 | if(flag==0) 417 | { 418 | // printf("\nEEEEEEEEEE%lf,%lf",temp,r3dens); 419 | rc=region(pressure,temp); 420 | steam_prop_calc_r3(pressure,temp,p_prop); 421 | if(rc==3&&fabs((p_prop->spe_enth-spe_enth)/spe_enth)<1e-4) 422 | { 423 | p_prop->pressure=pressure; 424 | p_prop->spe_enth=spe_enth; 425 | return 0; 426 | } 427 | } 428 | flag=temp_ph_r5(&temp,pressure,spe_enth); 429 | if(flag==0) 430 | { 431 | rc=region(pressure,temp); 432 | steam_prop_calc_r5(pressure,temp,p_prop); 433 | if(rc==5&&fabs((p_prop->spe_enth-spe_enth)/spe_enth)<1e-4) 434 | { 435 | p_prop->spe_enth=spe_enth; 436 | return 0; 437 | } 438 | } 439 | return -1; 440 | } 441 | 442 | int steam_prop_calc_ps(double pressure, double spe_entr, steam_prop* p_prop) 443 | { 444 | int rc,flag; 445 | double temp,r3dens; 446 | double pres_h,pres_l,temp_sat,vapor_frac; 447 | steam_prop prop_s,prop_w; 448 | 449 | pres_l=calc_sat_pres(MIN_TEMP); 450 | pres_h=calc_sat_pres(INTER_TEMP1); 451 | 452 | if(pressure>pres_l&&pressureprop_w.spe_entr) 458 | { 459 | vapor_frac=(spe_entr-prop_w.spe_entr)/(prop_s.spe_entr-prop_w.spe_entr); 460 | p_prop->pressure=pressure; 461 | p_prop->temp=temp_sat; 462 | p_prop->spe_vol=vapor_frac*prop_s.spe_vol+(1-vapor_frac)*prop_w.spe_vol; 463 | p_prop->dens=1/p_prop->spe_vol; 464 | p_prop->spe_energy=vapor_frac*prop_s.spe_energy+(1-vapor_frac)*prop_w.spe_energy; 465 | p_prop->spe_entr=spe_entr; 466 | p_prop->spe_enth=vapor_frac*prop_s.spe_enth+(1-vapor_frac)*prop_w.spe_enth; 467 | p_prop->spe_h_v=vapor_frac*prop_s.spe_h_v+(1-vapor_frac)*prop_w.spe_h_v; 468 | p_prop->spe_h_p=vapor_frac*prop_s.spe_h_p+(1-vapor_frac)*prop_w.spe_h_p; 469 | p_prop->speed_sound=vapor_frac*prop_s.speed_sound+(1-vapor_frac)*prop_w.speed_sound; 470 | p_prop->drdp=vapor_frac*prop_s.drdp+(1-vapor_frac)*prop_w.drdp; 471 | p_prop->vapor_fraction=vapor_frac; 472 | //solve vapor fraction and properties; 473 | return 0; 474 | } 475 | } 476 | 477 | flag=temp_ps_r1(&temp,pressure,spe_entr); 478 | if(flag==0) 479 | { 480 | rc=region(pressure,temp); 481 | steam_prop_calc_r1(pressure,temp,p_prop); 482 | if(rc==1&&fabs((p_prop->spe_entr-spe_entr)/spe_entr)<1e-4) 483 | { 484 | p_prop->spe_entr=spe_entr; 485 | return 0; 486 | } 487 | } 488 | 489 | flag=temp_ps_r2(&temp,pressure,spe_entr); 490 | if(flag==0) 491 | { 492 | rc=region(pressure,temp); 493 | steam_prop_calc_r2(pressure,temp,p_prop); 494 | if(rc==2&&fabs((p_prop->spe_entr-spe_entr)/spe_entr)<1e-4) 495 | { 496 | p_prop->spe_entr=spe_entr; 497 | return 0; 498 | } 499 | } 500 | 501 | flag=tr_ps_r3(&temp,&r3dens,pressure,spe_entr); 502 | // printf("\t#########%lf,%lf",temp,1/r3dens); 503 | if(flag==0) 504 | { 505 | rc=region(pressure,temp); 506 | steam_prop_calc_r3(pressure,temp,p_prop); 507 | if(rc==3&&fabs((p_prop->spe_entr-spe_entr)/spe_entr)<1e-4) 508 | { 509 | p_prop->pressure=pressure; 510 | p_prop->spe_entr=spe_entr; 511 | return 0; 512 | } 513 | } 514 | 515 | flag=temp_ps_r5(&temp,pressure,spe_entr); 516 | if(flag==0) 517 | { 518 | rc=region(pressure,temp); 519 | steam_prop_calc_r5(pressure,temp,p_prop); 520 | if(rc==5&&fabs((p_prop->spe_entr-spe_entr)/spe_entr)<1e-4) 521 | { 522 | p_prop->spe_entr=spe_entr; 523 | return 0; 524 | } 525 | } 526 | return -1; 527 | } 528 | 529 | int steam_prop_calc_tr(double temp, double dens, steam_prop* p_prop) 530 | { 531 | int rc,flag; 532 | double pres,pres_sat,vapor_frac; 533 | steam_prop prop_w,prop_s; 534 | 535 | if(temp>INTER_TEMP1) 536 | { 537 | flag=pres_tr_r2(&pres,temp,dens); 538 | if(flag==0) 539 | { 540 | rc=region(pres,temp); 541 | steam_prop_calc_r2(pres,temp,p_prop); 542 | if(rc==2&&fabs((p_prop->dens-dens)/dens)<1e-4) 543 | { 544 | p_prop->dens=dens; 545 | return 0; 546 | } 547 | } 548 | 549 | flag=pres_tr_r3(&pres,temp,dens); 550 | // printf("\n.............%d,%lf\n",flag,pres); 551 | if(flag==0) 552 | { 553 | rc=region(pres,temp); 554 | // printf("...........%d\n",rc); 555 | steam_prop_calc_r3(pres,temp,p_prop); 556 | if(rc==3&&fabs((p_prop->dens-dens)/dens)<1e-4) 557 | { 558 | p_prop->temp=temp; 559 | p_prop->dens=dens; 560 | return 0; 561 | } 562 | } 563 | 564 | flag=pres_tr_r5(&pres,temp,dens); 565 | if(flag==0) 566 | { 567 | rc=region(pres,temp); 568 | steam_prop_calc_r5(pres,temp,p_prop); 569 | if(rc==5&&fabs((p_prop->dens-dens)/dens)<1e-4) 570 | { 571 | p_prop->dens=dens; 572 | return 0; 573 | } 574 | } 575 | return -1; 576 | } 577 | 578 | else 579 | { 580 | flag=pres_tr_r1(&pres,temp,dens); 581 | if(flag==0) 582 | { 583 | rc=region(pres,temp); 584 | steam_prop_calc_r1(pres,temp,p_prop); 585 | if(rc==1&&fabs((p_prop->dens-dens)/dens)<1e-4) 586 | { 587 | p_prop->dens=dens; 588 | return 0; 589 | } 590 | } 591 | 592 | flag=pres_tr_r2(&pres,temp,dens); 593 | if(flag==0) 594 | { 595 | rc=region(pres,temp); 596 | steam_prop_calc_r2(pres,temp,p_prop); 597 | if(rc==2&&fabs((p_prop->dens-dens)/dens)<1e-4) 598 | { 599 | p_prop->dens=dens; 600 | return 0; 601 | } 602 | } 603 | pres_sat=calc_sat_pres(temp); 604 | steam_prop_calc_r1(pres_sat,temp,&prop_w); 605 | steam_prop_calc_r2(pres_sat,temp,&prop_s); 606 | 607 | if(dens>prop_s.dens&&denspressure=pres_sat; 611 | p_prop->temp=temp; 612 | p_prop->spe_vol=1/dens; 613 | p_prop->dens=dens; 614 | p_prop->spe_energy=vapor_frac*prop_s.spe_energy+(1-vapor_frac)*prop_w.spe_energy; 615 | p_prop->spe_entr=vapor_frac*prop_s.spe_entr+(1-vapor_frac)*prop_w.spe_entr; 616 | p_prop->spe_enth=vapor_frac*prop_s.spe_enth+(1-vapor_frac)*prop_w.spe_enth; 617 | p_prop->spe_h_v=vapor_frac*prop_s.spe_h_v+(1-vapor_frac)*prop_w.spe_h_v; 618 | p_prop->spe_h_p=vapor_frac*prop_s.spe_h_p+(1-vapor_frac)*prop_w.spe_h_p; 619 | p_prop->speed_sound=vapor_frac*prop_s.speed_sound+(1-vapor_frac)*prop_w.speed_sound; 620 | p_prop->drdp=vapor_frac*prop_s.drdp+(1-vapor_frac)*prop_w.drdp; 621 | p_prop->vapor_fraction=vapor_frac; 622 | //solve vapor fraction and properties; 623 | return 0; 624 | } 625 | return -1; 626 | } 627 | } 628 | 629 | int steam_prop_calc_tu(double temp, double spe_ener, steam_prop* p_prop) 630 | { 631 | int rc,flag; 632 | double pres,pres_sat,vapor_frac; 633 | steam_prop prop_w,prop_s; 634 | 635 | if(temp>INTER_TEMP1) 636 | { 637 | flag=pres_tu_r2(&pres,temp,spe_ener); 638 | if(flag==0) 639 | { 640 | rc=region(pres,temp); 641 | steam_prop_calc_r2(pres,temp,p_prop); 642 | if(rc==2&&fabs((p_prop->spe_energy-spe_ener)/spe_ener)<1e-4) 643 | { 644 | p_prop->spe_energy=spe_ener; 645 | return 0; 646 | } 647 | } 648 | 649 | flag=pres_tu_r3(&pres,temp,spe_ener); 650 | if(flag==0) 651 | { 652 | rc=region(pres,temp); 653 | steam_prop_calc_r3(pres,temp,p_prop); 654 | if(rc==3&&fabs((p_prop->spe_energy-spe_ener)/spe_ener)<1e-4) 655 | { 656 | p_prop->temp=temp; 657 | p_prop->spe_energy=spe_ener; 658 | return 0; 659 | } 660 | } 661 | 662 | flag=pres_tu_r5(&pres,temp,spe_ener); 663 | if(flag==0) 664 | { 665 | rc=region(pres,temp); 666 | steam_prop_calc_r5(pres,temp,p_prop); 667 | if(rc==5&&fabs((p_prop->spe_energy-spe_ener)/spe_ener)<1e-4) 668 | { 669 | p_prop->spe_energy=spe_ener; 670 | return 0; 671 | } 672 | } 673 | return -1; 674 | } 675 | 676 | else 677 | { 678 | flag=pres_tu_r1(&pres,temp,spe_ener); 679 | if(flag==0) 680 | { 681 | rc=region(pres,temp); 682 | steam_prop_calc_r1(pres,temp,p_prop); 683 | if(rc==1&&fabs((p_prop->spe_energy-spe_ener)/spe_ener)<1e-4) 684 | { 685 | p_prop->spe_energy=spe_ener; 686 | return 0; 687 | } 688 | } 689 | 690 | flag=pres_tu_r2(&pres,temp,spe_ener); 691 | if(flag==0) 692 | { 693 | rc=region(pres,temp); 694 | steam_prop_calc_r2(pres,temp,p_prop); 695 | if(rc==2&&fabs((p_prop->spe_energy-spe_ener)/spe_ener)<1e-4) 696 | { 697 | p_prop->spe_energy=spe_ener; 698 | return 0; 699 | } 700 | } 701 | 702 | pres_sat=calc_sat_pres(temp); 703 | steam_prop_calc_r1(pres_sat,temp,&prop_w); 704 | steam_prop_calc_r2(pres_sat,temp,&prop_s); 705 | 706 | if(spe_ener>prop_w.spe_energy&&spe_enerpressure=pres_sat; 710 | p_prop->temp=temp; 711 | p_prop->spe_vol=vapor_frac*prop_s.spe_vol+(1-vapor_frac)*prop_w.spe_vol; 712 | p_prop->dens=1/p_prop->spe_vol; 713 | p_prop->spe_energy=spe_ener; 714 | p_prop->spe_entr=vapor_frac*prop_s.spe_entr+(1-vapor_frac)*prop_w.spe_entr; 715 | p_prop->spe_enth=vapor_frac*prop_s.spe_enth+(1-vapor_frac)*prop_w.spe_enth; 716 | p_prop->spe_h_v=vapor_frac*prop_s.spe_h_v+(1-vapor_frac)*prop_w.spe_h_v; 717 | p_prop->spe_h_p=vapor_frac*prop_s.spe_h_p+(1-vapor_frac)*prop_w.spe_h_p; 718 | p_prop->speed_sound=vapor_frac*prop_s.speed_sound+(1-vapor_frac)*prop_w.speed_sound; 719 | p_prop->drdp=vapor_frac*prop_s.drdp+(1-vapor_frac)*prop_w.drdp; 720 | p_prop->vapor_fraction=vapor_frac; 721 | //solve vapor fraction and properties; 722 | return 0; 723 | } 724 | return -1; 725 | } 726 | } 727 | 728 | int steam_prop_calc_th(double temp, double spe_enth, steam_prop* p_prop) 729 | { 730 | int rc,flag; 731 | double pres,pres_sat,vapor_frac; 732 | steam_prop prop_w,prop_s; 733 | 734 | if(temp>INTER_TEMP1) 735 | { 736 | flag=pres_th_r2(&pres,temp,spe_enth); 737 | if(flag==0) 738 | { 739 | rc=region(pres,temp); 740 | steam_prop_calc_r2(pres,temp,p_prop); 741 | if(rc==2&&fabs((p_prop->spe_enth-spe_enth)/spe_enth)<1e-4) 742 | { 743 | p_prop->spe_enth=spe_enth; 744 | return 0; 745 | } 746 | } 747 | 748 | flag=pres_th_r3(&pres,temp,spe_enth); 749 | if(flag==0) 750 | { 751 | rc=region(pres,temp); 752 | steam_prop_calc_r3(pres,temp,p_prop); 753 | if(rc==3&&fabs((p_prop->spe_enth-spe_enth)/spe_enth)<1e-4) 754 | { 755 | p_prop->temp=temp; 756 | p_prop->spe_enth=spe_enth; 757 | return 0; 758 | } 759 | } 760 | 761 | flag=pres_th_r5(&pres,temp,spe_enth); 762 | if(flag==0) 763 | { 764 | rc=region(pres,temp); 765 | steam_prop_calc_r5(pres,temp,p_prop); 766 | if(rc==5&&fabs((p_prop->spe_enth-spe_enth)/spe_enth)<1e-4) 767 | { 768 | p_prop->spe_enth=spe_enth; 769 | return 0; 770 | } 771 | } 772 | return -1; 773 | } 774 | 775 | else 776 | { 777 | flag=pres_th_r1(&pres,temp,spe_enth); 778 | if(flag==0) 779 | { 780 | rc=region(pres,temp); 781 | steam_prop_calc_r1(pres,temp,p_prop); 782 | if(rc==1&&fabs((p_prop->spe_enth-spe_enth)/spe_enth)<1e-4) 783 | { 784 | p_prop->spe_enth=spe_enth; 785 | return 0; 786 | } 787 | } 788 | 789 | flag=pres_th_r2(&pres,temp,spe_enth); 790 | if(flag==0) 791 | { 792 | rc=region(pres,temp); 793 | steam_prop_calc_r2(pres,temp,p_prop); 794 | if(rc==2&&fabs((p_prop->spe_enth-spe_enth)/spe_enth)<1e-4) 795 | { 796 | p_prop->spe_enth=spe_enth; 797 | return 0; 798 | } 799 | } 800 | 801 | pres_sat=calc_sat_pres(temp); 802 | steam_prop_calc_r1(pres_sat,temp,&prop_w); 803 | steam_prop_calc_r2(pres_sat,temp,&prop_s); 804 | printf("\n\t%lf,%lf\n",prop_w.spe_enth,prop_s.spe_enth); 805 | if(spe_enth>prop_w.spe_enth&&spe_enthpressure=pres_sat; 810 | p_prop->temp=temp; 811 | p_prop->spe_vol=vapor_frac*prop_s.spe_vol+(1-vapor_frac)*prop_w.spe_vol; 812 | p_prop->dens=1/p_prop->spe_vol; 813 | p_prop->spe_energy=vapor_frac*prop_s.spe_energy+(1-vapor_frac)*prop_w.spe_energy; 814 | p_prop->spe_entr=vapor_frac*prop_s.spe_entr+(1-vapor_frac)*prop_w.spe_entr; 815 | p_prop->spe_enth=spe_enth; 816 | p_prop->spe_h_v=vapor_frac*prop_s.spe_h_v+(1-vapor_frac)*prop_w.spe_h_v; 817 | p_prop->spe_h_p=vapor_frac*prop_s.spe_h_p+(1-vapor_frac)*prop_w.spe_h_p; 818 | p_prop->speed_sound=vapor_frac*prop_s.speed_sound+(1-vapor_frac)*prop_w.speed_sound; 819 | p_prop->drdp=vapor_frac*prop_s.drdp+(1-vapor_frac)*prop_w.drdp; 820 | p_prop->vapor_fraction=vapor_frac; 821 | //solve vapor fraction and properties; 822 | return 0; 823 | } 824 | 825 | return -1; 826 | } 827 | } 828 | 829 | int steam_prop_calc_ts(double temp, double spe_entr, steam_prop* p_prop) 830 | { 831 | int rc,flag; 832 | double pres,pres_sat,vapor_frac; 833 | steam_prop prop_w,prop_s; 834 | 835 | if(temp>INTER_TEMP1) 836 | { 837 | flag=pres_ts_r2(&pres,temp,spe_entr); 838 | if(flag==0) 839 | { 840 | rc=region(pres,temp); 841 | steam_prop_calc_r2(pres,temp,p_prop); 842 | if(rc==2&&fabs((p_prop->spe_entr-spe_entr)/spe_entr)<1e-4) 843 | { 844 | p_prop->spe_entr=spe_entr; 845 | return 0; 846 | } 847 | } 848 | 849 | flag=pres_ts_r3(&pres,temp,spe_entr); 850 | if(flag==0) 851 | { 852 | rc=region(pres,temp); 853 | steam_prop_calc_r3(pres,temp,p_prop); 854 | if(rc==3&&fabs((p_prop->spe_entr-spe_entr)/spe_entr)<1e-4) 855 | { 856 | p_prop->temp=temp; 857 | p_prop->spe_entr=spe_entr; 858 | return 0; 859 | } 860 | } 861 | 862 | flag=pres_ts_r5(&pres,temp,spe_entr); 863 | if(flag==0) 864 | { 865 | rc=region(pres,temp); 866 | steam_prop_calc_r5(pres,temp,p_prop); 867 | if(rc==5&&fabs((p_prop->spe_entr-spe_entr)/spe_entr)<1e-4) 868 | { 869 | p_prop->temp=temp; 870 | p_prop->spe_entr=spe_entr; 871 | return 0; 872 | } 873 | } 874 | return -1; 875 | } 876 | 877 | else 878 | { 879 | flag=pres_ts_r1(&pres,temp,spe_entr); 880 | if(flag==0) 881 | { 882 | rc=region(pres,temp); 883 | steam_prop_calc_r1(pres,temp,p_prop); 884 | if(rc==1&&fabs((p_prop->spe_entr-spe_entr)/spe_entr)<1e-4) 885 | { 886 | p_prop->spe_entr=spe_entr; 887 | return 0; 888 | } 889 | } 890 | flag=pres_ts_r2(&pres,temp,spe_entr); 891 | if(flag==0) 892 | { 893 | rc=region(pres,temp); 894 | steam_prop_calc_r2(pres,temp,p_prop); 895 | if(rc==2&&fabs((p_prop->spe_entr-spe_entr)/spe_entr)<1e-4) 896 | { 897 | p_prop->spe_entr=spe_entr; 898 | return 0; 899 | } 900 | } 901 | pres_sat=calc_sat_pres(temp); 902 | steam_prop_calc_r1(pres_sat,temp,&prop_w); 903 | steam_prop_calc_r2(pres_sat,temp,&prop_s); 904 | if(spe_entr>prop_w.spe_entr&&spe_entrpressure=pres_sat; 908 | p_prop->temp=temp; 909 | p_prop->spe_vol=vapor_frac*prop_s.spe_vol+(1-vapor_frac)*prop_w.spe_vol; 910 | p_prop->dens=1/p_prop->spe_vol; 911 | p_prop->spe_energy=vapor_frac*prop_s.spe_energy+(1-vapor_frac)*prop_w.spe_energy; 912 | p_prop->spe_entr=spe_entr; 913 | p_prop->spe_enth=vapor_frac*prop_s.spe_enth+(1-vapor_frac)*prop_w.spe_enth; 914 | p_prop->spe_h_v=vapor_frac*prop_s.spe_h_v+(1-vapor_frac)*prop_w.spe_h_v; 915 | p_prop->spe_h_p=vapor_frac*prop_s.spe_h_p+(1-vapor_frac)*prop_w.spe_h_p; 916 | p_prop->speed_sound=vapor_frac*prop_s.speed_sound+(1-vapor_frac)*prop_w.speed_sound; 917 | p_prop->drdp=vapor_frac*prop_s.drdp+(1-vapor_frac)*prop_w.drdp; 918 | p_prop->vapor_fraction=vapor_frac; 919 | } 920 | 921 | return -1; 922 | } 923 | } 924 | 925 | int steam_prop_calc_hs(double spe_enth, double spe_entr, steam_prop* p_prop) 926 | { 927 | int rc,flag; 928 | double pres,temp,temp_sat,p_sat,vapor_frac; 929 | steam_prop prop_w,prop_s; 930 | flag=pt_hs_r1(&pres,&temp,spe_enth,spe_entr); 931 | if(flag==0) 932 | { 933 | // printf("\n....................\n"); 934 | rc=region(pres,temp); 935 | steam_prop_calc_r1(pres,temp,p_prop); 936 | if(rc==1&&fabs((p_prop->spe_entr-spe_entr)/spe_entr)<1e-4&&fabs((p_prop->spe_enth-spe_enth)/spe_enth)<1e-4) 937 | { 938 | p_prop->spe_entr=spe_entr; 939 | p_prop->spe_enth=spe_enth; 940 | return 0; 941 | } 942 | } 943 | 944 | flag=pt_hs_r2(&pres,&temp,spe_enth,spe_entr); 945 | if(flag==0) 946 | { 947 | // printf("\n....................%lf,%lf\n",pres,temp); 948 | rc=region(pres,temp); 949 | steam_prop_calc_r2(pres,temp,p_prop); 950 | // printf("\n\n%d,%lf,%lf,%lf,%lf,%lf\n",rc,pres,temp,p_prop->spe_enth,p_prop->spe_entr,p_prop->vapor_fraction); 951 | if(rc==2&&fabs((p_prop->spe_entr-spe_entr)/spe_entr)<1e-4&&fabs((p_prop->spe_enth-spe_enth)/spe_enth)<1e-4) 952 | { 953 | p_prop->spe_entr=spe_entr; 954 | p_prop->spe_enth=spe_enth; 955 | // printf("\nGREAT!\n"); 956 | return 0; 957 | } 958 | } 959 | 960 | flag=pt_hs_r3(&pres,&temp,spe_enth,spe_entr); 961 | if(flag==0) 962 | { 963 | // printf("\n....................%lf,%lf\n",pres,temp); 964 | rc=region(pres,temp); 965 | // printf("@@@@@@@@@@@@@@@%d\n",rc); 966 | steam_prop_calc_r3(pres,temp,p_prop); 967 | // printf("\n\n%d,%lf,%lf,%lf,%lf,%lf\n",rc,pres,temp,p_prop->spe_enth,p_prop->spe_entr,p_prop->vapor_fraction); 968 | if(rc==3&&fabs((p_prop->spe_entr-spe_entr)/spe_entr)<1e-4&&fabs((p_prop->spe_enth-spe_enth)/spe_enth)<1e-4) 969 | { 970 | p_prop->spe_entr=spe_entr; 971 | p_prop->spe_enth=spe_enth; 972 | return 0; 973 | } 974 | } 975 | 976 | flag=pt_hs_r5(&pres,&temp,spe_enth,spe_entr); 977 | if(flag==0) 978 | { 979 | // printf("\n....................%lf,%lf\n",pres,temp); 980 | rc=region(pres,temp); 981 | // printf("@@@@@@@@@@@@@@@%d\n",rc); 982 | steam_prop_calc_r5(pres,temp,p_prop); 983 | // printf("\n\n%d,%lf,%lf,%lf,%lf,%lf\n",rc,pres,temp,p_prop->spe_enth,p_prop->spe_entr,p_prop->vapor_fraction); 984 | if(rc==5&&fabs((p_prop->spe_entr-spe_entr)/spe_entr)<1e-4&&fabs((p_prop->spe_enth-spe_enth)/spe_enth)<1e-4) 985 | { 986 | p_prop->spe_entr=spe_entr; 987 | p_prop->spe_enth=spe_enth; 988 | return 0; 989 | } 990 | } 991 | 992 | flag=hs_find_tsat(&temp_sat,spe_enth,spe_entr); 993 | // printf("\n%d,%lf\n",flag,temp_sat); 994 | if(flag==-1) 995 | { 996 | return -1; 997 | } 998 | 999 | p_sat=calc_sat_pres(temp_sat); 1000 | steam_prop_calc_r1(p_sat,temp_sat,&prop_w); 1001 | steam_prop_calc_r2(p_sat,temp_sat,&prop_s); 1002 | vapor_frac=(spe_enth-prop_w.spe_enth)/(prop_s.spe_enth-prop_w.spe_enth); 1003 | p_prop->pressure=p_sat; 1004 | p_prop->temp=temp_sat; 1005 | p_prop->spe_vol=vapor_frac*prop_s.spe_vol+(1-vapor_frac)*prop_w.spe_vol; 1006 | p_prop->dens=1/p_prop->spe_vol; 1007 | p_prop->spe_energy=vapor_frac*prop_s.spe_energy+(1-vapor_frac)*prop_w.spe_energy; 1008 | p_prop->spe_entr=spe_entr; 1009 | p_prop->spe_enth=spe_enth; 1010 | p_prop->spe_h_v=vapor_frac*prop_s.spe_h_v+(1-vapor_frac)*prop_w.spe_h_v; 1011 | p_prop->spe_h_p=vapor_frac*prop_s.spe_h_p+(1-vapor_frac)*prop_w.spe_h_p; 1012 | p_prop->speed_sound=vapor_frac*prop_s.speed_sound+(1-vapor_frac)*prop_w.speed_sound; 1013 | p_prop->drdp=vapor_frac*prop_s.drdp+(1-vapor_frac)*prop_w.drdp; 1014 | p_prop->vapor_fraction=vapor_frac; 1015 | return 0; 1016 | } 1017 | 1018 | int steam_prop_calc_px(double pres, double vf, steam_prop *p_prop) 1019 | { 1020 | double presmn,presmx; 1021 | double temp_sat; 1022 | steam_prop prop_w,prop_s; 1023 | 1024 | if(vf<0||vf>1) 1025 | { 1026 | return -1; 1027 | } 1028 | presmn=calc_sat_pres(MIN_TEMP); 1029 | presmx=calc_sat_pres(INTER_TEMP1); 1030 | if(prespresmx) 1031 | { 1032 | return -1; 1033 | } 1034 | temp_sat=tsatp(pres); 1035 | steam_prop_calc_r1(pres,temp_sat,&prop_w); 1036 | steam_prop_calc_r2(pres,temp_sat,&prop_s); 1037 | p_prop->pressure=pres; 1038 | p_prop->temp=temp_sat; 1039 | p_prop->spe_vol=vf*prop_s.spe_vol+(1-vf)*prop_w.spe_vol; 1040 | p_prop->dens=1/p_prop->spe_vol; 1041 | p_prop->spe_energy=vf*prop_s.spe_energy+(1-vf)*prop_w.spe_energy; 1042 | p_prop->spe_entr=vf*prop_s.spe_entr+(1-vf)*prop_w.spe_entr; 1043 | p_prop->spe_enth=vf*prop_s.spe_enth+(1-vf)*prop_w.spe_enth; 1044 | p_prop->spe_h_v=vf*prop_s.spe_h_v+(1-vf)*prop_w.spe_h_v; 1045 | p_prop->spe_h_p=vf*prop_s.spe_h_p+(1-vf)*prop_w.spe_h_p; 1046 | p_prop->speed_sound=vf*prop_s.speed_sound+(1-vf)*prop_w.speed_sound; 1047 | p_prop->drdp=vf*prop_s.drdp+(1-vf)*prop_w.drdp; 1048 | p_prop->vapor_fraction=vf; 1049 | return 0; 1050 | } 1051 | 1052 | int steam_prop_calc_tx(double temp, double vf, steam_prop *p_prop) 1053 | { 1054 | double pres_sat; 1055 | steam_prop prop_w,prop_s; 1056 | 1057 | if(vf<0||vf>1) 1058 | { 1059 | return -1; 1060 | } 1061 | if(tempINTER_TEMP1) 1062 | { 1063 | return -1; 1064 | } 1065 | pres_sat=calc_sat_pres(temp); 1066 | steam_prop_calc_r1(pres_sat,temp,&prop_w); 1067 | steam_prop_calc_r2(pres_sat,temp,&prop_s); 1068 | p_prop->pressure=pres_sat; 1069 | p_prop->temp=temp; 1070 | p_prop->spe_vol=vf*prop_s.spe_vol+(1-vf)*prop_w.spe_vol; 1071 | p_prop->dens=1/p_prop->spe_vol; 1072 | p_prop->spe_energy=vf*prop_s.spe_energy+(1-vf)*prop_w.spe_energy; 1073 | p_prop->spe_entr=vf*prop_s.spe_entr+(1-vf)*prop_w.spe_entr; 1074 | p_prop->spe_enth=vf*prop_s.spe_enth+(1-vf)*prop_w.spe_enth; 1075 | p_prop->spe_h_v=vf*prop_s.spe_h_v+(1-vf)*prop_w.spe_h_v; 1076 | p_prop->spe_h_p=vf*prop_s.spe_h_p+(1-vf)*prop_w.spe_h_p; 1077 | p_prop->speed_sound=vf*prop_s.speed_sound+(1-vf)*prop_w.speed_sound; 1078 | p_prop->drdp=vf*prop_s.drdp+(1-vf)*prop_w.drdp; 1079 | p_prop->vapor_fraction=vf; 1080 | return 0; 1081 | } 1082 | 1083 | double steam_visc_calc(double temp, double dens) 1084 | { 1085 | double visc_0,visc_1; 1086 | double sum1,sum2,sum_temp; 1087 | double ref_t=647.096; 1088 | double ref_dens=322; 1089 | double ref_p=22.064e6; 1090 | double ref_visc=1e-6; 1091 | int i,j; 1092 | 1093 | sum1=0; 1094 | for(i=0;i<4;i++) 1095 | { 1096 | sum1+=coeff_visc1[i]/pow(temp/ref_t,i); 1097 | } 1098 | visc_0=100*sqrt(temp/ref_t)/sum1; 1099 | 1100 | sum1=0; 1101 | for(i=0;i<6;i++) 1102 | { 1103 | sum_temp=pow(ref_t/temp-1,i); 1104 | sum2=0; 1105 | for(j=0;j<7;j++) 1106 | { 1107 | sum2+=coeff_visc2[i][j]*pow(dens/ref_dens-1,j); 1108 | } 1109 | sum1=sum1+(sum_temp*sum2); 1110 | } 1111 | visc_1=exp(dens/ref_dens*sum1); 1112 | return visc_0*visc_1*ref_visc; 1113 | } 1114 | 1115 | int calc_index_lmd2(double dens, double ref_dens) 1116 | { 1117 | double nd_dens=dens/ref_dens; 1118 | if((nd_dens-0.310559006)<1e-8) 1119 | { 1120 | return 0; 1121 | } 1122 | else if((nd_dens-0.776397516)<1e-8) 1123 | { 1124 | return 1; 1125 | } 1126 | else if((nd_dens-1.242236025)<1e-8) 1127 | { 1128 | return 2; 1129 | } 1130 | else if((nd_dens-1.863354037)<1e-8) 1131 | { 1132 | return 3; 1133 | } 1134 | else 1135 | { 1136 | return 4; 1137 | } 1138 | } 1139 | 1140 | double steam_thcond_calc(double temp, double dens, double visc, double cp, double cv, double drdp, double pressure) 1141 | { 1142 | double lamd0,lamd1,lamd2; 1143 | double ref_t=647.096; 1144 | double ref_p=22.064e6; 1145 | double ref_dens=322; 1146 | double ref_lamd=1e-3; 1147 | double ref_visc=1e-6; 1148 | double gas_const=0.46151805e3; 1149 | double nd_visc; 1150 | double nd_cp, real_cp; 1151 | double sp_ratio; 1152 | double delta_x; 1153 | double y,zy; 1154 | 1155 | double A=177.8514; 1156 | double qd=2.5e9; 1157 | double v=0.630; 1158 | double gamma=1.239; 1159 | double ypsilon0=0.13e-9; 1160 | double gamma0=0.06; 1161 | double tr=1.5; 1162 | double ksai_t,ksai_tr,ypsilon; 1163 | 1164 | int indexj; 1165 | 1166 | int i,j; 1167 | double sum1,sum2,sum3; 1168 | sum1=0; 1169 | for(i=0;i<5;i++) 1170 | { 1171 | sum1+=coeff_thcond1[i]/pow(temp/ref_t,i); 1172 | } 1173 | lamd0=sqrt(temp/ref_t)/sum1; 1174 | // printf("\t%lf\n",lamd0); 1175 | 1176 | sum1=0; 1177 | for(i=0;i<5;i++) 1178 | { 1179 | sum2=pow(ref_t/temp-1,i); 1180 | sum3=0; 1181 | for(j=0;j<6;j++) 1182 | { 1183 | sum3+=coeff_thcond2[i][j]*pow(dens/ref_dens-1,j); 1184 | } 1185 | sum1=sum1+(sum2*sum3); 1186 | } 1187 | lamd1=exp(dens/ref_dens*sum1); 1188 | 1189 | // printf("\t%lf\n",lamd1); 1190 | // printf("%lf,%lf,%lf\n",temp/ref_t,dens/ref_dens,visc/ref_visc); 1191 | 1192 | nd_visc=visc/ref_visc; 1193 | nd_cp=cp/gas_const; 1194 | if(nd_cp<0||nd_cp>1e13) 1195 | { 1196 | nd_cp=1e13; 1197 | } 1198 | // printf("\n%lf\n",nd_cp); 1199 | real_cp=nd_cp*gas_const; 1200 | // printf("\n%lf\n",real_cp); 1201 | sp_ratio=real_cp/cv; 1202 | // printf("\t\t%lf\n",sp_ratio); 1203 | ksai_t=drdp*ref_p/ref_dens; 1204 | // printf("\t%lf\n",ksai_t); 1205 | indexj=calc_index_lmd2(dens,ref_dens); 1206 | // printf("\n%d\n",indexj); 1207 | sum1=0; 1208 | for(i=0;i<6;i++) 1209 | { 1210 | sum1+=coeff_thcond4[i][indexj]*pow(dens/ref_dens,i); 1211 | } 1212 | ksai_tr=1/sum1; 1213 | // printf("\t\t%lf\n\n",ksai_tr); 1214 | delta_x=(ksai_t-ksai_tr*tr*ref_t/temp)*dens/ref_dens; 1215 | if(delta_x<0) 1216 | { 1217 | delta_x=0; 1218 | } 1219 | ypsilon=ypsilon0*pow(delta_x/gamma0,v/gamma); 1220 | if(ypsilon<0||ypsilon>1e4) 1221 | { 1222 | ypsilon=1e4; 1223 | } 1224 | y=qd*ypsilon; 1225 | zy=(((1-1/sp_ratio)*atan(y)+y/sp_ratio)-(1-exp(-1/(1/y+y*y/(3*dens*dens/(ref_dens*ref_dens))))))*2/(3.14159265358*y); 1226 | if(y<1.2e-7) 1227 | { 1228 | zy=0; 1229 | } 1230 | lamd2=A*zy*(dens/ref_dens)*nd_cp*(temp/ref_t)/(visc/ref_visc); 1231 | // printf("\t%lf\n",lamd2); 1232 | return (lamd0*lamd1+lamd2)*ref_lamd; 1233 | } 1234 | 1235 | 1236 | //special for THE PROGRAM 1237 | int steam_prop_calc(double pressure, double temp, double *dens,double *cp, double* cv, double* spe_enth, double* drdp) 1238 | { 1239 | steam_prop p_prop; 1240 | int region_code; 1241 | int calc_flag; 1242 | 1243 | region_code=region(pressure,temp); 1244 | if(region_code==-1) 1245 | { 1246 | printf("\n%lf,%lfFATAL ERROR: PRESSURE/TEMP EXCEEDS BOUNDARIES.\n",pressure,temp); 1247 | return -1; 1248 | } 1249 | else if(region_code==1) 1250 | { 1251 | steam_prop_calc_r1(pressure,temp,&p_prop); 1252 | } 1253 | else if(region_code==2||region_code==4) 1254 | { 1255 | steam_prop_calc_r2(pressure,temp,&p_prop); 1256 | } 1257 | else if(region_code==3) 1258 | { 1259 | calc_flag=steam_prop_calc_r3(pressure,temp,&p_prop); 1260 | if(calc_flag==-1) 1261 | { 1262 | printf("\nFATAL ERROR: DENSITY ITERATION NOT CONVERGED.\n"); 1263 | return -2; 1264 | } 1265 | } 1266 | else if(region_code==5) 1267 | { 1268 | steam_prop_calc_r5(pressure,temp,&p_prop); 1269 | } 1270 | // print_prop(&p_prop); 1271 | *dens=p_prop.dens; 1272 | *cp=p_prop.spe_h_p; 1273 | *cv=p_prop.spe_h_v; 1274 | *spe_enth=p_prop.spe_enth; 1275 | *drdp=p_prop.drdp; 1276 | return 0; 1277 | } -------------------------------------------------------------------------------- /region3.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This code is distributed under the license: MIT License 3 | * Originally written by Zhenrong WANG 4 | * mailto: zhenrongwang@live.com 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | #include "if97_general.h" 11 | #include "region_calc.h" 12 | #include "region3.h" 13 | 14 | const double region3_coeff[40][4]={ 15 | 1,0,0,0.10658070028513e1, 16 | 2,0,0,-0.15732845290239e2, 17 | 3,0,1,0.20944396974307e2, 18 | 4,0,2,-0.76867707878716e1, 19 | 5,0,7,0.26185947787954e1, 20 | 6,0,10,-0.28080781148620e1, 21 | 7,0,12,0.12053369696517e1, 22 | 8,0,23,-0.84566812812502e-2, 23 | 9,1,2,-0.12654315477714e1, 24 | 10,1,6,-0.11524407806681e1, 25 | 11,1,15,0.88521043984318, 26 | 12,1,17,-0.64207765181607, 27 | 13,2,0,0.38493460186671, 28 | 14,2,2,-0.85214708824206, 29 | 15,2,6,0.48972281541877e1, 30 | 16,2,7,-0.30502617256965e1, 31 | 17,2,22,0.39420536879154e-1, 32 | 18,2,26,0.12558408424308, 33 | 19,3,0,-0.27999329698710, 34 | 20,3,2,0.13899799569460e1, 35 | 21,3,4,-0.20189915023570e1, 36 | 22,3,16,-0.82147637173963e-2, 37 | 23,3,26,-0.47596035734923, 38 | 24,4,0,0.43984074473500e-1, 39 | 25,4,2,-0.44476435428739, 40 | 26,4,4,0.90572070719733, 41 | 27,4,26,0.70522450087967, 42 | 28,5,1,0.10770512626332, 43 | 29,5,3,-0.32913623258954, 44 | 30,5,26,-0.50871062041158, 45 | 31,6,0,-0.22175400873096e-1, 46 | 32,6,2,0.94260751665092e-1, 47 | 33,6,26,0.16436278447961, 48 | 34,7,2,-0.13503372241348e-1, 49 | 35,8,26,-0.14834345352472e-1, 50 | 36,9,2,0.57922953628084e-3, 51 | 37,9,26,0.32308904703711e-2, 52 | 38,10,0,0.80964802996215e-4, 53 | 39,10,1,-0.16557679795037e-3, 54 | 40,11,26,-0.44923899061815e-4 55 | }; 56 | 57 | const double t3ab[5][2]={ 58 | 0,0.154793642129415e4, 59 | 1,-0.187661219490113e3, 60 | 2,0.213144632222113e2, 61 | -1,-0.191887498864292e4, 62 | -2,0.918419702359447e3, 63 | }; 64 | 65 | const double t3cd[4][2]={ 66 | 0,0.585276966696349e3, 67 | 1,0.278233532206915e1, 68 | 2,-0.127283549295878e-1, 69 | 3,0.159090746562729e-3, 70 | }; 71 | 72 | const double t3gh[5][2]={ 73 | 0,-0.249284240900418e5, 74 | 1,0.428143584791546e4, 75 | 2,-0.269029173140130e3, 76 | 3,0.751608051114157e1, 77 | 4,-0.787105249910383e-1, 78 | }; 79 | 80 | const double t3ij[5][2]={ 81 | 0,0.584814781649163e3, 82 | 1,-0.616179320924617, 83 | 2,0.260763050899562, 84 | 3,-0.587071076864459e-2, 85 | 4,0.515308185433082e-4 86 | }; 87 | 88 | const double t3jk[5][2]={ 89 | 0,0.617229772068439e3, 90 | 1,-0.770600270141675e1, 91 | 2,0.697072596851896, 92 | 3,-0.157391839848015e-1, 93 | 4,0.137897492684194e-3, 94 | }; 95 | 96 | const double t3mn[4][2]={ 97 | 0,0.535339483742384e3, 98 | 1,0.761978122720128e1, 99 | 2,-0.158365725441648, 100 | 3,0.192871054508108e-2, 101 | }; 102 | 103 | const double t3op[5][2]={ 104 | 0,0.969461372400213e3, 105 | 1,-0.332500170441278e3, 106 | 2,0.642859598466067e2, 107 | -1,0.773845935768222e3, 108 | -2,-0.152313732937084e4, 109 | }; 110 | 111 | const double t3qu[4][2]={ 112 | 0,0.565603648239126e3, 113 | 1,0.529062258221222e1, 114 | 2,-0.102020639611016, 115 | 3,0.122240301070145e-2, 116 | }; 117 | 118 | const double t3rx[4][2]={ 119 | 0,0.584561202520006e3, 120 | 1,-0.102961025163669e1, 121 | 2,0.243293362700452, 122 | 3,-0.294905044740799e-2, 123 | }; 124 | 125 | const double sat_coeff_r3[10]={ 126 | 0.11670521452767e4, 127 | -0.72421316703206e6, 128 | -0.17073846940092e2, 129 | 0.12020824702470e5, 130 | -0.32325550322333e7, 131 | 0.14915108613530e2, 132 | -0.48232657361591e4, 133 | 0.40511340542057e6, 134 | -0.23855557567849, 135 | 0.65017534844798e3, 136 | }; 137 | 138 | const double t3uv[4][2]={ 139 | 0,0.528199646263062e3, 140 | 1,0.890579602135307e1, 141 | 2,-0.222814134903755, 142 | 3,0.286791682263697e-2, 143 | }; 144 | 145 | const double t3wx[5][2]={ 146 | 0,0.728052609145380e1, 147 | 1,0.973505869861952e2, 148 | 2,0.147370491183191e2, 149 | -1,0.329196213998375e3, 150 | -2,0.873371668682417e3, 151 | }; 152 | 153 | const double v3a[3][30]={ 154 | -12,-12,-12,-10,-10,-10,-8,-8,-8,-6,-5,-5,-5,-4,-3,-3,-3,-3,-2,-2,-2,-1,-1,-1,0,0,1,1,2,2, 155 | 5,10,12,5,10,12,5,8,10,1,1,5,10,8,0,1,3,6,0,2,3,0,1,2,0,1,0,2,0,2, 156 | 0.110879558823853e-2,0.572616740810616e3,-0.767051948380852e5,-0.253321069529674e-1,0.628008049345689e4,0.234105654131876e6,0.216867826045856,-0.156237904341963e3,-0.269893956176613e5,-0.180407100085505e-3,0.116732227668261e-2,0.266987040856040e2,0.282776617243286e5,-0.242431520029523e4,0.435217323022733e-3,-0.122494831387441e-1,0.179357604019989e1,0.442729521058314e2,-0.593223489018342e-2,0.453186261685774,0.135825703129140e1,0.408748415856745e-1,0.474686397863312,0.118646814997915e1,0.546987265727549,0.195266770452643,-0.502268790869663e-1,-0.369645308193377,0.633828037528420e-2,0.797441793901017e-1, 157 | }; 158 | 159 | const double v3b[3][32]={ 160 | -12,-12,-10,-10,-8,-6,-6,-6,-5,-5,-5,-4,-4,-4,-3,-3,-3,-3,-3,-2,-2,-2,-1,-1,0,0,1,1,2,3,4,4, 161 | 10,12,8,14,8,5,6,8,5,8,10,2,4,5,0,1,2,3,5,0,2,5,0,2,0,1,0,2,0,2,0,1, 162 | -0.827670470003621e-1,0.416887126010565e2,0.483651982197059e-1,-0.291032084950276e5,-0.111422582236948e3,-0.202300083904014e-1,0.294002509338515e3,0.140244997609658e3,-0.344384158811459e3,0.361182452612149e3,-0.140699677420738e4,-0.202023902676481e-2,0.171346792457471e3,-0.425597804058632e1,0.691346085000334e-5,0.151140509678925e-2,-0.416375290166236e-1,-0.413754957011042e2,-0.506673295721637e2,-0.572212965569023e-3,0.608817368401785e1,0.239600660256161e2,0.122261479925384e-1,0.216356057692938e1,0.398198903368642,-0.116892827834085,-0.102845919373532,-0.492676637589284,0.655540456406790e-1,-0.240462535078530,-0.269798180310075e-1,0.128369435967012, 163 | }; 164 | 165 | const double v3c[3][35]={ 166 | -12,-12,-12,-10,-10,-10,-8,-8,-8,-6,-5,-5,-5,-4,-4,-3,-3,-2,-2,-2,-1,-1,-1,0,0,0,1,1,2,2,2,2,3,3,8, 167 | 6,8,10,6,8,10,5,6,7,8,1,4,7,2,8,0,3,0,4,5,0,1,2,0,1,2,0,2,0,1,3,7,0,7,1, 168 | 3.11967788763030,2.76713458847564E+04,3.22583103403269E+07,-3.42416065095363E+02,-8.99732529907377E+05,-7.93892049821251E+07,9.53193003217388E+01,2.29784742345072E+03,1.75336675322499E+05,7.91214365222792E+06,3.19933345844209E-05,-6.59508863555767E+01,-8.33426563212851E+05,6.45734680583292E-02,-3.82031020570813E+06,4.06398848470079E-05,3.10327498492008E+01,-8.92996718483724E-04,2.34604891591616E+02,3.77515668966951E+03,1.58646812591361E-02,7.07906336241843E-01,1.26016225146570E+01,7.36143655772152E-01,6.76544268999101E-01,-1.78100588189137E+01,-1.56531975531713E-01,1.17707430048158E+01,8.40143653860447E-02,-1.86442467471949E-01,-4.40170203949645E+01,1.23290423502494E+06,-2.40650039730845E-02,-1.07077716660869E+06,4.38319858566475E-02, 169 | }; 170 | 171 | const double v3d[3][38]={ 172 | -12,-12,-12,-12,-12,-12,-10,-10,-10,-10,-10,-10,-10,-8,-8,-8,-8,-6,-6,-5,-5,-5,-5,-4,-4,-4,-3,-3,-2,-2,-1,-1,-1,0,0,1,1,3, 173 | 4,6,7,10,12,16,0,2,4,6,8,10,14,3,7,8,10,6,8,1,2,5,7,0,1,7,2,4,0,1,0,1,5,0,2,0,6,0, 174 | -4.52484847171645e-10,3.15210389538801e-05,-2.14991352047545e-03,5.08058874808345e+02,-1.27123036845932e+07,1.15371133120497e+12,-1.97805728776273e-16,2.41554806033972e-11,-1.56481703640525e-06,2.77211346836625e-03,-2.03578994462286e+01,1.44369489909053e+06,-4.11254217946539e+10,6.23449786243773e-06,-2.21774281146038e+01,-6.89315087933158e+04,-1.95419525060713e+07,3.16373510564015e+03,2.24040754426988e+06,-4.36701347922356e-06,-4.04213852833996e-04,-3.48153203414663e+02,-3.85294213555289e+05,1.35203700099403e-07,1.34648383271089e-04,1.25031835351736e+05,9.68123678455841e-02,2.25660517512438e+02,-1.90102435341872e-04,-2.99628410819229e-02,5.00833915372121e-03,3.87842482998411e-01,-1.38535367777182e+03,8.70745245971773e-01,1.71946252068742,-3.26650121426383e-02,4.98044171727877e+03,5.51478022765087e-03, 175 | }; 176 | 177 | const double v3e[3][29]={ 178 | -12,-12,-10,-10,-10,-10,-10,-8,-8,-8,-6,-5,-4,-4,-3,-3,-3,-2,-2,-2,-2,-1,0,0,1,1,1,2,2, 179 | 14,16,3,6,10,14,16,7,8,10,6,6,2,4,2,6,7,0,1,3,4,0,0,1,0,4,6,0,2, 180 | 7.15815808404721e+08,-1.14328360753449e+11,3.76531002015720e-12,-9.03983668691157e-05,6.65695908836252e+05,5.35364174960127e+09,7.94977402335603e+10,9.22230563421437e+01,-1.42586073991215e+05,-1.11796381424162e+06,8.96121629640760e+03,-6.69989239070491e+03,4.51242538486834e-03,-3.39731325977713e+01,-1.20523111552278,4.75992667717124e+04,-2.66627750390341e+05,-1.53314954386524e-04,3.05638404828265e-01,1.23654999499486e+02,-1.04390794213011e+03,-1.57496516174308e-02,6.85331118940253e-01,1.78373462873903,-5.44674124878910e-01,2.04529931318843e+03,-2.28342359328752e+04,4.13197481515899e-01,-3.41931835910405e+01, 181 | }; 182 | 183 | const double v3f[3][42]={ 184 | 0,0,0,0,0,0,1,1,1,1,2,2,3,3,3,4,5,5,6,7,7,10,12,12,12,14,14,14,14,14,16,16,18,18,20,20,20,22,24,24,28,32, 185 | -3,-2,-1,0,1,2,-1,1,2,3,0,1,-5,-2,0,-3,-8,1,-6,-4,1,-6,-10,-8,-4,-12,-10,-8,-6,-4,-10,-8,-12,-10,-12,-10,-6,-12,-12,-4,-12,-12, 186 | -2.51756547792325E-08,6.01307193668763E-06,-1.00615977450049E-03,9.99969140252192E-01,2.14107759236486,-1.65175571959086E+01,-1.41987303638727E-03,2.69251915156554,3.49741815858722E+01,-3.00208695771783E+01,-1.31546288252539,-8.39091277286169,1.81545608337015E-10,-5.91099206478909E-04,1.52115067087106,2.52956470663225E-05,1.00726265203786E-15,-1.49774533860650,-7.93940970562969E-10,-1.50290891264717E-04,1.51205531275133,4.70942606221652E-06,1.95049710391712E-13,-9.11627886266077E-09,6.04374640201265E-04,-2.25132933900136E-16,6.10916973582981E-12,-3.03063908043404E-07,-1.37796070798409E-05,-9.19296736666106E-04,6.39288223132545E-10,7.53259479898699E-07,-4.00321478682929E-13,7.56140294351614E-09,-9.12082054034891E-12,-2.37612381140539E-08,2.69586010591874E-05,-7.32828135157839E-11,2.41995578306660E-10,-4.05735532730322E-04,1.89424143498011E-10,-4.86632965074563E-10, 187 | }; 188 | 189 | const double v3g[3][38]={ 190 | -12,-12,-12,-12,-12,-12,-10,-10,-10,-8,-8,-8,-8,-6,-6,-5,-5,-4,-3,-2,-2,-2,-2,-1,-1,-1,0,0,0,1,1,1,3,5,6,8,10,10, 191 | 7,12,14,18,22,24,14,20,24,7,8,10,12,8,22,7,20,22,7,3,5,14,24,2,8,18,0,1,2,0,1,3,24,22,12,3,0,6, 192 | 4.12209020652996E-05,-1.14987238280587E+06,9.48180885032080E+09,-1.95788865718971E+17,4.96250704871300E+24,-1.05549884548496E+28,-7.58642165988278E+11,-9.22172769596101E+22,7.25379072059348E+29,-6.17718249205859E+01,1.07555033344858E+04,-3.79545802336487E+07,2.28646846221831E+11,-4.99741093010619E+06,-2.80214310054101E+30,1.04915406769586E+06,6.13754229168619E+27,8.02056715528378E+31,-2.98617819828065E+07,-9.10782540134681E+01,1.35033227281565E+05,-7.12949383408211E+18,-1.04578785289542E+36,3.04331584444093E+01,5.93250797959445E+09,-3.64174062110798E+27,9.21791403532461E-01,-3.37693609657471E-01,-7.24644143758508E+01,-1.10480239272601E-01,5.36516031875059,-2.91441872156205E+03,6.16338176535305E+39,-1.20889175861180E+38,8.18396024524612E+22,9.40781944835829E+08,-3.67279669545448E+04,-8.37513931798655E+15, 193 | }; 194 | 195 | const double v3h[3][29]={ 196 | -12,-12,-10,-10,-10,-10,-10,-10,-8,-8,-8,-8,-8,-6,-6,-6,-5,-5,-5,-4,-4,-3,-3,-2,-1,-1,0,1,1, 197 | 8,12,4,6,8,10,14,16,0,1,6,7,8,4,6,8,2,3,4,2,4,1,2,0,0,2,0,0,2, 198 | 5.61379678887577E-02,7.74135421587083E+09,1.11482975877938E-09,-1.43987128208183E-03,1.93696558764920E+03,-6.05971823585005E+08,1.71951568124337E+13,-1.85461154985145E+16,3.87851168078010E-17,-3.95464327846105E-14,-1.70875935679023E+02,-2.12010620701220E+03,1.77683337348191E+07,1.10177443629575E+01,-2.34396091693313E+05,-6.56174421999594E+06,1.56362212977396E-05,-2.12946257021400,1.35249306374858E+01,1.77189164145813E-01,1.39499167345464E+03,-7.03670932036388E-03,-1.52011044389648E-01,9.81916922991113E-05,1.47199658618076E-03,2.02618487025578E+01,8.99345518944240E-01,-2.11346402240858E-01,2.49971752957491E+01, 199 | }; 200 | 201 | const double v3i[3][42]={ 202 | 0,0,0,1,1,1,1,2,3,3,4,4,4,5,5,5,7,7,8,8,10,12,12,12,14,14,14,14,18,18,18,18,18,20,20,22,24,24,32,32,36,36, 203 | 0,1,10,-4,-2,-1,0,0,-5,0,-3,-2,-1,-6,-1,12,-4,-3,-6,10,-8,-12,-6,-4,-10,-8,-4,5,-12,-10,-8,-6,2,-12,-10,-12,-12,-8,-10,-5,-10,-8, 204 | 1.06905684359136,-1.48620857922333,2.59862256980408E+14,-4.46352055678749E-12,-5.66620757170032E-07,-2.35302885736849E-03,-2.69226321968839E-01,9.22024992944392,3.57633505503772E-12,-1.73942565562222E+01,7.00681785556229E-06,-2.67050351075768E-04,-2.31779669675624,-7.53533046979752E-13,4.81337131452891,-2.23286270422356E+21,-1.18746004987383E-05,6.46412934136496E-03,-4.10588536330937E-10,4.22739537057241E+19,3.13698180473812E-13,1.64395334345040E-24,-3.39823323754373E-06,-1.35268639905021E-02,-7.23252514211625E-15,1.84386437538366E-09,-4.63959533752385E-02,-9.92263100376750E+13,6.88169154439335E-17,-2.22620998452197E-11,-5.40843018624083E-08,3.45570606200257E-03,4.22275800304086E+10,-1.26974478770487E-15,9.27237985153679E-10,6.12670812016489E-14,-7.22693924063497E-12,-3.83669502636822E-04,3.74684572410204E-04,-9.31976897511086E+04,-2.47690616026922E-02,6.58110546759474E+01, 205 | }; 206 | 207 | const double v3j[3][29]={ 208 | 0,0,0,1,1,1,2,2,3,4,4,5,5,5,6,10,12,12,14,14,14,16,18,20,20,24,24,28,28, 209 | -1,0,1,-2,-1,1,-1,1,-2,-2,2,-3,-2,0,3,-6,-8,-3,-10,-8,-5,-10,-12,-12,-10,-12,-6,-12,-5, 210 | -1.11371317395540E-04,1.00342892423685,5.30615581928979,1.79058760078792E-06,-7.28541958464774E-04,-1.87576133371704E+01,1.99060874071849E-03,2.43574755377290E+01,-1.77040785499444E-04,-2.59680385227130E-03,-1.98704578406823E+02,7.38627790224287E-05,-2.36264692844138E-03,-1.61023121314333,6.22322971786473E+03,-9.60754116701669E-09,-5.10572269720488E-11,7.67373781404211E-03,6.63855469485254E-15,-7.17590735526745E-10,1.46564542926508E-05,3.09029474277013E-12,-4.64216300971708E-16,-3.90499637961161E-14,-2.36716126781431E-10,4.54652854268717E-12,-4.22271787482497E-03,2.83911742354706E-11,2.70929002720228, 211 | }; 212 | 213 | const double v3k[3][34]={ 214 | -2,-2,-1,-1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,2,2,2,2,2,2,5,5,5,6,6,6,6,8,10,12, 215 | 10,12,-5,6,-12,-6,-2,-1,0,1,2,3,14,-3,-2,0,1,2,-8,-6,-3,-2,0,4,-12,-6,-3,-12,-10,-8,-5,-12,-12,-10, 216 | -4.01215699576099E+08,4.84501478318406E+10,3.94721471363678E-15,3.72629967374147E+04,-3.69794374168666E-30,-3.80436407012452E-15,4.75361629970233E-07,-8.79148916140706E-04,8.44317863844331E-01,1.22433162656600E+01,-1.04529634830279E+02,5.89702771277429E+02,-2.91026851164444E+13,1.70343072841850E-06,-2.77617606975748E-04,-3.44709605486686,2.21333862447095E+01,-1.94646110037079E+02,8.08354639772825E-16,-1.80845209145470E-11,-6.96664158132412E-06,-1.81057560300994E-03,2.55830298579027,3.28913873658481E+03,-1.73270241249904E-19,-6.61876792558034E-07,-3.95688923421250E-03,6.04203299819132E-18,-4.00879935920517E-14,1.60751107464958E-09,3.83719409025556E-05,-6.49565446702457E-15,-1.49095328506000E-12,5.41449377329581E-09, 217 | }; 218 | 219 | const double v3l[3][43]={ 220 | -12,-12,-12,-12,-12,-10,-10,-8,-8,-8,-8,-8,-8,-8,-6,-5,-5,-4,-4,-3,-3,-3,-3,-2,-2,-2,-1,-1,-1,0,0,0,0,1,1,2,4,5,5,6,10,10,14, 221 | 14,16,18,20,22,14,24,6,10,12,14,18,24,36,8,4,5,7,16,1,3,18,20,2,3,10,0,1,3,0,1,2,12,0,16,1,0,0,1,14,4,12,10, 222 | 2.60702058647537E+09,-1.88277213604704E+14,5.54923870289667E+18,-7.58966946387758E+22,4.13865186848908E+26,-8.15038000738060E+11,-3.81458260489955E+32,-1.23239564600519E-02,2.26095631437174E+07,-4.95017809506720E+11,5.29482996422863E+15,-4.44359478746295E+22,5.21635864527315E+34,-4.87095672740742E+54,-7.14430209937547E+05,1.27868634615495E-01,-1.00752127917598E+01,7.77451437960990E+06,-1.08105480796471E+24,-3.57578581169659E-06,-2.12857169423484,2.70706111085238E+29,-6.95953622348829E+32,1.10609027472280E-01,7.21559163361354E+01,-3.06367307532219E+14,2.65839618885530E-05,2.53392392889754E-02,-2.14443041836579E+02,9.37846601489667E-01,2.23184043101700,3.38401222509191E+01,4.94237237179718E+20,-1.98068404154428E-01,-1.41415349881140E+30,-9.93862421613651E+01,1.25070534142731E+02,-9.96473529004439E+02,4.73137909872765E+04,1.16662121219322E+32,-3.15874976271533E+15,-4.45703369196945E+32,6.42794932373694E+32, 223 | }; 224 | 225 | const double v3m[3][40]={ 226 | 0,3,8,20,1,3,4,5,1,6,2,4,14,2,5,3,0,1,1,1,28,2,16,0,5,0,3,4,12,16,1,8,14,0,2,3,4,8,14,24, 227 | 0,0,0,2,5,5,5,5,6,6,7,8,8,10,10,12,14,14,18,20,20,22,22,24,24,28,28,28,28,28,32,32,32,36,36,36,36,36,36,36, 228 | 8.11384363481847E-01,-5.68199310990094E+03,-1.78657198172556E+10,7.95537657613427E+31,-8.14568209346872E+04,-6.59774567602874E+07,-1.52861148659302E+10,-5.60165667510446E+11,4.58384828593949E+05,-3.85754000383848E+13,4.53735800004273E+07,9.39454935735563E+11,2.66572856432938E+27,-5.47578313899097E+09,2.00725701112386E+14,1.85007245563239E+12,1.85135446828337E+08,-1.70451090076385E+11,1.57890366037614E+14,-2.02530509748774E+15,3.68193926183570E+59,1.70215539458936E+17,6.39234909918741E+41,-8.21698160721956E+14,-7.95260241872306E+23,2.33415869478510E+17,-6.00079934586803E+22,5.94584382273384E+24,1.89461279349492E+39,-8.10093428842645E+45,1.88813911076809E+21,1.11052244098768E+35,2.91133958602503E+45,-3.29421923951460E+21,-1.37570282536696E+25,1.81508996303902E+27,-3.46865122768353E+29,-2.11961148774260E+37,-1.28617899887675E+48,4.79817895699239E+64, 229 | }; 230 | 231 | const double v3n[3][39]={ 232 | 0,3,4,6,7,10,12,14,18,0,3,5,6,8,12,0,3,7,12,2,3,4,2,4,7,4,3,5,6,0,0,3,1,0,1,0,1,0,1, 233 | -12,-12,-12,-12,-12,-12,-12,-12,-12,-10,-10,-10,-10,-10,-10,-8,-8,-8,-8,-6,-6,-6,-5,-5,-5,-4,-3,-3,-3,-2,-1,-1,0,1,1,2,4,5,6, 234 | 2.80967799943151E-39,6.14869006573609E-31,5.82238667048942E-28,3.90628369238462E-23,8.21445758255119E-21,4.02137961842776E-15,6.51718171878301E-13,-2.11773355803058E-08,2.64953354380072E-03,-1.35031446451331E-32,-6.07246643970893E-24,-4.02352115234494E-19,-7.44938506925544E-17,1.89917206526237E-13,3.64975183508473E-06,1.77274872361946E-26,-3.34952758812999E-19,-4.21537726098389E-09,-3.91048167929649E-02,5.41276911564176E-14,7.05412100773699E-12,2.58585887897486E-09,-4.93111362030162E-11,-1.58649699894543E-06,-5.25037427886100E-01,2.20019901729615E-03,-6.43064132636925E-03,6.29154149015048E+01,1.35147318617061E+02,2.40560808321713E-07,-8.90763306701305E-04,-4.40209599407714E+03,-3.02807107747776E+02,1.59158748314599E+03,2.32534272709876E+05,-7.92681207132600E+05,-8.69871364662769E+10,3.54542769185671E+11,4.00849240129329E+14, 235 | }; 236 | 237 | const double v3o[3][24]={ 238 | 0,0,0,2,3,4,4,4,4,4,5,5,6,7,8,8,8,10,10,14,14,20,20,24, 239 | -12,-4,-1,-1,-10,-12,-8,-5,-4,-1,-4,-3,-8,-12,-10,-8,-4,-12,-8,-12,-8,-12,-10,-12, 240 | 1.28746023979718E-35,-7.35234770382342E-12,2.89078692149150E-03,2.44482731907223E-01,1.41733492030985E-24,-3.54533853059476E-29,-5.94539202901431E-18,-5.85188401782779E-09,2.01377325411803E-06,1.38647388209306,-1.73959365084772E-05,1.37680878349369E-03,8.14897605805513E-15,4.25596631351839E-26,-3.87449113787755E-18,1.39814747930240E-13,-1.71849638951521E-03,6.41890529513296E-22,1.18960578072018E-11,-1.55282762571611E-18,2.33907907347507E-08,-1.74093247766213E-13,3.77682649089149E-09,-5.16720236575302E-11, 241 | }; 242 | 243 | const double v3p[3][27]={ 244 | 0,0,0,0,1,2,3,3,4,6,7,7,8,10,12,12,12,14,14,14,16,18,20,22,24,24,36, 245 | -1,0,1,2,1,-1,-3,0,-2,-2,-5,-4,-2,-3,-12,-6,-5,-10,-8,-3,-8,-8,-10,-10,-12,-8,-12, 246 | -9.82825342010366E-05,1.05145700850612,1.16033094095084E+02,3.24664750281543E+03,-1.23592348610137E+03,-5.61403450013495E-02,8.56677401640869E-08,2.36313425393924E+02,9.72503292350109E-03,-1.03001994531927,-1.49653706199162E-09,-2.15743778861592E-05,-8.34452198291445,5.86602660564988E-01,3.43480022104968E-26,8.16256095947021E-06,2.94985697916798E-03,7.11730466276584E-17,4.00954763806941E-10,1.07766027032853E+01,-4.09449599138182E-07,-7.29121307758902E-06,6.77107970938909E-09,6.02745973022975E-08,-3.82323011855257E-11,1.79946628317437E-03,-3.45042834640005E-04, 247 | }; 248 | 249 | const double v3q[3][24]={ 250 | -12,-12,-10,-10,-10,-10,-8,-6,-5,-5,-4,-4,-3,-2,-2,-2,-2,-1,-1,-1,0,1,1,1, 251 | 10,12,6,7,8,10,8,6,2,5,3,4,3,0,1,2,4,0,1,2,0,0,1,3, 252 | -8.20433843259950E+04,4.73271518461586E+10,-8.05950021005413E-02,3.28600025435980E+01,-3.56617029982490E+03,-1.72985781433335E+09,3.51769232729192E+07,-7.75489259985144E+05,7.10346691966018E-05,9.93499883820274E+04,-6.42094171904570E-01,-6.12842816820083E+03,2.32808472983776E+02,-1.42808220416837E-05,-6.43596060678456E-03,-4.28577227475614,2.25689939161918E+03,1.00355651721510E-03,3.33491455143516E-01,1.09697576888873,9.61917379376452E-01,-8.38165632204598E-02,2.47795908411492,-3.19114969006533E+03, 253 | }; 254 | 255 | const double v3r[3][27]={ 256 | -8,-8,-3,-3,-3,-3,-3,0,0,0,0,3,3,8,8,8,8,10,10,10,10,10,10,10,10,12,14, 257 | 6,14,-3,3,4,5,8,-1,0,1,5,-6,-2,-12,-10,-8,-5,-12,-10,-8,-6,-5,-4,-3,-2,-12,-12, 258 | 1.44165955660863E-03,-7.01438599628258E+12,-8.30946716459219E-17,2.61975135368109E-01,3.93097214706245E+02,-1.04334030654021E+04,4.90112654154211E+08,-1.47104222772069E-04,1.03602748043408,3.05308890065089,-3.99745276971264E+06,5.69233719593750E-12,-4.64923504407778E-02,-5.35400396512906E-18,3.99988795693162E-13,-5.36479560201811E-07,1.59536722411202E-02,2.70303248860217E-15,2.44247453858506E-08,-9.83430636716454E-06,6.63513144224454E-02,-9.93456957845006,5.46491323528491E+02,-1.43365406393758E+04,1.50764974125511E+05,-3.37209709340105E-10,3.77501980025469E-09, 259 | }; 260 | 261 | const double v3s[3][29]={ 262 | -12,-12,-10,-8,-6,-5,-5,-4,-4,-3,-3,-2,-1,-1,-1,0,0,0,0,1,1,3,3,3,4,4,4,5,14, 263 | 20,24,22,14,36,8,16,6,32,3,8,4,1,2,3,0,1,4,28,0,32,0,1,2,3,18,24,4,24, 264 | -5.32466612140254E+22,1.00415480000824E+31,-1.91540001821367E+29,1.05618377808847E+16,2.02281884477061E+58,8.84585472596134E+07,1.66540181638363E+22,-3.13563197669111E+05,-1.85662327545324E+53,-6.24942093918942E-02,-5.04160724132590E+09,1.87514491833092E+04,1.21399979993217E-03,1.88317043049455,-1.67073503962060E+03,9.65961650599775E-01,2.94885696802488,-6.53915627346115E+04,6.04012200163444E+49,-1.98339358557937E-01,-1.75984090163501E+57,3.56314881403987,-5.75991255144384E+02,4.56213415338071E+04,-1.09174044987829E+07,4.37796099975134E+33,-6.16552611135792E+45,1.93568768917797E+09,9.50898170425042E+53, 265 | }; 266 | 267 | const double v3t[3][33]={ 268 | 0,0,0,0,1,1,2,2,2,3,3,4,4,7,7,7,7,7,10,10,10,10,10,18,20,22,22,24,28,32,32,32,36, 269 | 0,1,4,12,0,10,0,6,14,3,8,0,10,3,4,7,20,36,10,12,14,16,22,18,32,22,36,24,28,22,32,36,36, 270 | 1.55287249586268,6.64235115009031,-2.89366236727210E+03,-3.85923202309848E+12,-2.91002915783761,-8.29088246858083E+11,1.76814899675218,-5.34686695713469E+08,1.60464608687834E+17,1.96435366560186E+05,1.56637427541729E+12,-1.78154560260006,-2.29746237623692E+15,3.85659001648006E+07,1.10554446790543E+09,-6.77073830687349E+13,-3.27910592086523E+30,-3.41552040860644E+50,-5.27251339709047E+20,2.45375640937055E+23,-1.68776617209269E+26,3.58958955867578E+28,-6.56475280339411E+35,3.55286045512301E+38,5.69021454413270E+57,-7.00584546433113E+47,-7.05772623326374E+64,1.66861176200148E+52,-3.00475129680486E+60,-6.68481295196808E+50,4.28432338620678E+68,-4.44227367758304E+71,-2.81396013562745E+76, 271 | }; 272 | 273 | const double v3u[3][38]={ 274 | -12,-10,-10,-10,-8,-8,-8,-6,-6,-5,-5,-5,-3,-1,-1,-1,-1,0,0,1,2,2,3,5,5,5,6,6,8,8,10,12,12,12,14,14,14,14, 275 | 14,10,12,14,10,12,14,8,12,4,8,12,2,-1,1,12,14,-3,1,-2,5,10,-5,-4,2,3,-5,2,-8,8,-4,-12,-4,4,-12,-10,-6,6, 276 | 1.22088349258355E+17,1.04216468608488E+09,-8.82666931564652E+15,2.59929510849499E+19,2.22612779142211E+14,-8.78473585050085E+17,-3.14432577551552E+21,-2.16934916996285E+12,1.59079648196849E+20,-3.39567617303423E+02,8.84387651337836E+12,-8.43405926846418E+20,1.14178193518022E+01,-1.22708229235641E-04,-1.06201671767107E+02,9.03443213959313E+24,-6.93996270370852E+27,6.48916718965575E-09,7.18957567127851E+03,1.05581745346187E-03,-6.51903203602581E+14,-1.60116813274676E+24,-5.10254294237837E-09,-1.52355388953402E-01,6.77143292290144E+11,2.76378438378930E+14,1.16862983141686E-02,-3.01426947980171E+13,1.69719813884840E-08,1.04674840020929E+26,-1.08016904560140E+04,-9.90623601934295E-13,5.36116483602738E+06,2.26145963747881E+21,-4.88731565776210E-10,1.51001548880670E-05,-2.27700464643920E+04,-7.81754507698846E+27, 277 | }; 278 | 279 | const double v3v[3][39]={ 280 | -10,-8,-6,-6,-6,-6,-6,-6,-5,-5,-5,-5,-5,-5,-4,-4,-4,-4,-3,-3,-3,-2,-2,-1,-1,0,0,0,1,1,3,4,4,4,5,8,10,12,14, 281 | -8,-12,-12,-3,5,6,8,10,1,2,6,8,10,14,-12,-10,-6,10,-3,10,12,2,4,-2,0,-2,6,10,-12,-10,3,-6,3,10,2,-12,-2,-3,1, 282 | -4.15652812061591E-55,1.77441742924043E-61,-3.57078668203377E-55,3.59252213604114E-26,-2.59123736380269E+01,5.94619766193460E+04,-6.24184007103158E+10,3.13080299915944E+16,1.05006446192036E-09,-1.92824336984852E-06,6.54144373749937E+05,5.13117462865044E+12,-6.97595750347391E+18,-1.03977184454767E+28,1.19563135540666E-48,-4.36677034051655E-42,9.26990036530639E-30,5.87793105620748E+20,2.80375725094731E-18,-1.92359972440634E+22,7.42705723302738E+26,-5.17429682450605E+01,8.20612048645469E+06,-1.88214882341448E-09,1.84587261114837E-02,-1.35830407782663E-06,-7.23681885626348E+16,-2.23449194054124E+26,-1.11526741826431E-35,2.76032601145151E-29,1.34856491567853E+14,6.52440293345860E-10,5.10655119774360E+16,-4.68138358908732E+31,-7.60667491183279E+15,-4.17247986986821E-19,3.12545677756104E+13,-1.00375333864186E+14,2.47761392329058E+26, 283 | }; 284 | 285 | const double v3w[3][35]={ 286 | -12,-12,-10,-10,-8,-8,-8,-6,-6,-6,-6,-5,-4,-4,-3,-3,-2,-2,-1,-1,-1,0,0,1,2,2,3,3,5,5,5,8,8,10,10, 287 | 8,14,-1,8,6,8,14,-4,-3,2,8,-10,-1,3,-10,3,1,2,-8,-4,1,-12,1,-1,-1,2,-12,-5,-10,-8,-6,-12,-10,-12,-8, 288 | -5.86219133817016E-08,-8.94460355005526E+10,5.31168037519774E-31,1.09892402329239E-01,-5.75368389425212E-02,2.28276853990249E+04,-1.58548609655002E+18,3.29865748576503E-28,-6.34987981190669E-25,6.15762068640611E-09,-9.61109240985747E+07,-4.06274286652625E-45,-4.71103725498077E-13,7.25937724828145E-01,1.87768525763682E-39,-1.03308436323771E+03,-6.62552816342168E-02,5.79514041765710E+02,2.37416732616644E-27,2.71700235739893E-15,-9.07886213483600E+01,-1.71242509570207E-37,1.56792067854621E+02,9.23261357901470E-01,-5.97865988422577,3.21988767636389E+06,-3.99441390042203E-30,4.93429086046981E-08,8.12036983370565E-20,-2.07610284654137E-12,-3.40821291419719E-07,5.42000573372233E-18,-8.56711586510214E-13,2.66170454405981E-14,8.58133791857099E-06, 289 | }; 290 | 291 | const double v3x[3][36]={ 292 | -8,-6,-5,-4,-4,-4,-3,-3,-1,0,0,0,1,1,2,3,3,3,4,5,5,5,6,8,8,8,8,10,12,12,12,12,14,14,14,14, 293 | 14,10,10,1,2,14,-2,12,5,0,4,10,-10,-1,6,-12,0,8,3,-6,-2,1,1,-6,-3,1,8,-8,-10,-8,-5,-4,-12,-10,-8,-6, 294 | 3.77373741298151E+18,-5.07100883722913E+12,-1.03363225598860E+15,1.84790814320773E-06,-9.24729378390945E-04,-4.25999562292738E+23,-4.62307771873973E-13,1.07319065855767E+21,6.48662492280682E+10,2.44200600688281,-8.51535733484258E+09,1.69894481433592E+21,2.15780222509020E-27,-3.20850551367334E-01,-3.82642448458610E+16,-2.75386077674421E-29,-5.63199253391666E+05,-3.26068646279314E+20,3.97949001553184E+13,1.00824008584757E-07,1.62234569738433E+04,-4.32355225319745E+10,-5.92874245598610E+11,1.33061647281106,1.57338197797544E+06,2.58189614270853E+13,2.62413209706358E+24,-9.20011937431142E-02,2.20213765905426E-03,-1.10433759109547E+01,8.47004870612087E+06,-5.92910695762536E+08,-1.83027173269660E-05,1.81339603516302E-01,-1.19228759669889E+03,4.30867658061468E+06, 295 | }; 296 | 297 | const double v3y[3][20]={ 298 | 0,0,0,0,1,2,2,2,2,3,3,3,4,4,5,5,8,8,10,12, 299 | -3,1,5,8,8,-4,-1,4,5,-8,4,8,-6,6,-2,1,-8,-2,-5,-8, 300 | -5.25597995024633E-10,5.83441305228407E+03,-1.34778968457925E+16,1.18973500934212E+25,-1.59096490904708E+26,-3.15839902302021E-07,4.96212197158239E+02,3.27777227273171E+18,-5.27114657850696E+21,2.10017506281863E-17,7.05106224399834E+20,-2.66713136106469E+30,-1.45370512554562E-08,1.49333917053130E+27,-1.49795620287641E+07,-3.81881906271100E+15,7.24660165585797E-05,-9.37808169550193E+13,5.14411468376383E+09,-8.28198594040141E+04, 301 | }; 302 | 303 | const double v3z[3][23]={ 304 | -8,-6,-5,-5,-4,-4,-4,-3,-3,-3,-2,-1,0,1,2,3,3,6,6,6,6,8,8, 305 | 3,6,6,8,5,6,8,-2,5,6,2,-6,3,1,6,-6,-2,-6,-5,-4,-1,-8,-4, 306 | 2.4400789229065E-11,-4.6305743033124E+06,7.2880327477771E+09,3.2777630285886E+15,-1.1059817011841E+09,-3.2389991572996E+12,9.2381400702325E+15,8.4225008041371E-13,6.6322143624551E+11,-1.6717018667214E+14,2.5374935870139E+03,-8.1973155961052E-21,3.2838058789066E+11,-6.2500479117154E+07,8.0319795746202E+20,-2.0439701133835E-11,-3.7839104705594E+03,9.7287654593862E-03,1.5435572168146E+01,-3.7396286292864E+03,-6.8285901137457E+10,-2.4848801561454E-04,3.9453604949707E+06, 307 | }; 308 | 309 | const double subregion_coeff[26][9]={ 310 | 0.0024,100e6,760,30,0.085,0.817,1,1,1, 311 | 0.0041,100e6,860,32,0.280,0.779,1,1,1, 312 | 0.0022,40e6,690,35,0.259,0.903,1,1,1, 313 | 0.0029,40e6,690,38,0.559,0.939,1,1,4, 314 | 0.0032,40e6,710,29,0.587,0.918,1,1,1, 315 | 0.0064,40e6,730,42,0.587,0.891,0.5,1,4, 316 | 0.0027,25e6,660,38,0.872,0.971,1,1,4, 317 | 0.0032,25e6,660,29,0.898,0.983,1,1,4, 318 | 0.0041,25e6,660,42,0.910,0.984,0.5,1,4, 319 | 0.0054,25e6,670,29,0.875,0.964,0.5,1,4, 320 | 0.0077,25e6,680,34,0.802,0.935,1,1,1, 321 | 0.0026,24e6,650,43,0.908,0.989,1,1,4, 322 | 0.0028,23e6,650,40,1.00,0.997,1,0.25,1, 323 | 0.0031,23e6,650,39,0.976,0.997,-1,-1,-1, 324 | 0.0034,23e6,650,24,0.974,0.996,0.5,1,1, 325 | 0.0041,23e6,650,27,0.972,0.997,0.5,1,1, 326 | 0.0022,23e6,650,24,0.848,0.983,1,1,4, 327 | 0.0054,23e6,650,27,0.874,0.982,1,1,1, 328 | 0.0022,21e6,640,29,0.886,0.990,1,1,4, 329 | 0.0088,20e6,650,33,0.803,1.02,1,1,1, 330 | 0.0026,23e6,650,38,0.902,0.988,1,1,1, 331 | 0.0031,23e6,650,39,0.960,0.995,1,1,1, 332 | 0.0039,23e6,650,35,0.959,0.995,1,1,4, 333 | 0.0049,23e6,650,36,0.910,0.988,1,1,1, 334 | 0.0031,22e6,650,20,0.996,0.994,1,1,4, 335 | 0.0038,22e6,650,23,0.993,0.994,1,1,4, 336 | }; 337 | 338 | //const double subregion_coeff_ 339 | 340 | double t3abp(double pres) 341 | { 342 | double ii,ni,pi,res; 343 | int i; 344 | res=0; 345 | pi=pres/1e6; 346 | for(i=0;i<5;i++) 347 | { 348 | ni=t3ab[i][1]; 349 | ii=t3ab[i][0]; 350 | res+=ni*pow(log(pi),ii); 351 | } 352 | return res; 353 | } 354 | 355 | double t3cdp(double pres) 356 | { 357 | double ii,ni,pi,res; 358 | int i; 359 | res=0; 360 | pi=pres/1e6; 361 | for(i=0;i<4;i++) 362 | { 363 | ni=t3cd[i][1]; 364 | ii=t3cd[i][0]; 365 | res+=ni*pow(pi,ii); 366 | } 367 | return res; 368 | } 369 | 370 | double t3efp(double pres) 371 | { 372 | double pi; 373 | pi=pres/1e6; 374 | return 3.727888004*(pi-22.064)+647.096; 375 | } 376 | 377 | double t3ghp(double pres) 378 | { 379 | double ii,ni,pi,res; 380 | int i; 381 | res=0; 382 | pi=pres/1e6; 383 | for(i=0;i<5;i++) 384 | { 385 | ni=t3gh[i][1]; 386 | ii=t3gh[i][0]; 387 | res+=ni*pow(pi,ii); 388 | } 389 | return res; 390 | } 391 | 392 | double t3ijp(double pres) 393 | { 394 | double ii,ni,pi,res; 395 | int i; 396 | res=0; 397 | pi=pres/1e6; 398 | for(i=0;i<5;i++) 399 | { 400 | ni=t3ij[i][1]; 401 | ii=t3ij[i][0]; 402 | res+=ni*pow(pi,ii); 403 | } 404 | return res; 405 | } 406 | 407 | double t3jkp(double pres) 408 | { 409 | double ii,ni,pi,res; 410 | int i; 411 | res=0; 412 | pi=pres/1e6; 413 | for(i=0;i<5;i++) 414 | { 415 | ni=t3jk[i][1]; 416 | ii=t3jk[i][0]; 417 | res+=ni*pow(pi,ii); 418 | } 419 | return res; 420 | } 421 | 422 | double t3mnp(double pres) 423 | { 424 | double ii,ni,pi,res; 425 | int i; 426 | res=0; 427 | pi=pres/1e6; 428 | for(i=0;i<4;i++) 429 | { 430 | ni=t3mn[i][1]; 431 | ii=t3mn[i][0]; 432 | res+=ni*pow(pi,ii); 433 | } 434 | return res; 435 | } 436 | 437 | double t3opp(double pres) 438 | { 439 | double ii,ni,pi,res; 440 | int i; 441 | res=0; 442 | pi=pres/1e6; 443 | for(i=0;i<5;i++) 444 | { 445 | ni=t3op[i][1]; 446 | ii=t3op[i][0]; 447 | res+=ni*pow(log(pi),ii); 448 | } 449 | return res; 450 | } 451 | 452 | double t3qup(double pres) 453 | { 454 | double ii,ni,pi,res; 455 | int i; 456 | res=0; 457 | pi=pres/1e6; 458 | for(i=0;i<4;i++) 459 | { 460 | ni=t3qu[i][1]; 461 | ii=t3qu[i][0]; 462 | res+=ni*pow(pi,ii); 463 | } 464 | return res; 465 | } 466 | 467 | double t3rxp(double pres) 468 | { 469 | double ii,ni,pi,res; 470 | int i; 471 | res=0; 472 | pi=pres/1e6; 473 | for(i=0;i<4;i++) 474 | { 475 | ni=t3rx[i][1]; 476 | ii=t3rx[i][0]; 477 | res+=ni*pow(pi,ii); 478 | } 479 | return res; 480 | } 481 | double tsatp(double pres) 482 | { 483 | double D,E,F,G,beta; 484 | double n10,n9; 485 | beta=pow(pres/1e6,0.25); 486 | E=beta*beta+sat_coeff_r3[2]*beta+sat_coeff_r3[5]; 487 | F=sat_coeff_r3[0]*beta*beta+sat_coeff_r3[3]*beta+sat_coeff_r3[6]; 488 | G=sat_coeff_r3[1]*beta*beta+sat_coeff_r3[4]*beta+sat_coeff_r3[7]; 489 | D=2*G/(-F-sqrt(F*F-4*E*G)); 490 | n10=sat_coeff_r3[9]; 491 | n9=sat_coeff_r3[8]; 492 | return 0.5*(n10+D-sqrt((n10+D)*(n10+D)-4*(n9+n10*D))); 493 | } 494 | 495 | double psatt(double temp) 496 | { 497 | double A,B,C,delt,n9,n10; 498 | n9=sat_coeff_r3[8]; 499 | n10=sat_coeff_r3[9]; 500 | 501 | delt=temp+n9/(temp-n10); 502 | A=delt*delt+sat_coeff_r3[0]*delt+sat_coeff_r3[1]; 503 | B=sat_coeff_r3[2]*delt*delt+sat_coeff_r3[3]*delt+sat_coeff_r3[4]; 504 | C=sat_coeff_r3[5]*delt*delt+sat_coeff_r3[6]*delt+sat_coeff_r3[7]; 505 | return 1e6*pow(2*C/(-B+sqrt(B*B-4*A*C)),4); 506 | } 507 | 508 | double t3uvp(double pres) 509 | { 510 | double ii,ni,pi,res; 511 | int i; 512 | res=0; 513 | pi=pres/1e6; 514 | for(i=0;i<4;i++) 515 | { 516 | ni=t3uv[i][1]; 517 | ii=t3uv[i][0]; 518 | res+=ni*pow(pi,ii); 519 | } 520 | return res; 521 | } 522 | 523 | double t3wxp(double pres) 524 | { 525 | double ii,ni,pi,res; 526 | int i; 527 | res=0; 528 | pi=pres/1e6; 529 | for(i=0;i<5;i++) 530 | { 531 | ni=t3wx[i][1]; 532 | ii=t3wx[i][0]; 533 | res+=ni*pow(log(pi),ii); 534 | } 535 | return res; 536 | } 537 | 538 | int pt_subregion_calc1(double pres, double temp) 539 | { 540 | double t3abb,t3cdb,t3efb,t3ghb,t3ijb,t3jkb,t3mnb,t3opb,t3qub,t3rxb; 541 | double p3cd,psat643,tsatb; 542 | 543 | p3cd=19.00881189173929e6; 544 | psat643=21.04336732e6; 545 | if(pres>40e6) 546 | { 547 | t3abb=t3abp(pres); 548 | if(temp-t3abb25e6) 554 | { 555 | t3abb=t3abp(pres); 556 | t3cdb=t3cdp(pres); 557 | t3efb=t3efp(pres); 558 | 559 | if(temp-t3cdb23.5e6) 569 | { 570 | t3cdb=t3cdp(pres); 571 | t3efb=t3efp(pres); 572 | t3ghb=t3ghp(pres); 573 | t3ijb=t3ijp(pres); 574 | t3jkb=t3jkp(pres); 575 | 576 | if(temp-t3cdb23e6) 590 | { 591 | t3cdb=t3cdp(pres); 592 | t3efb=t3efp(pres); 593 | t3ghb=t3ghp(pres); 594 | t3ijb=t3ijp(pres); 595 | t3jkb=t3jkp(pres); 596 | 597 | if(temp-t3cdb22.5e6) 611 | { 612 | t3cdb=t3cdp(pres); 613 | t3efb=t3efp(pres); 614 | t3ghb=t3ghp(pres); 615 | t3ijb=t3ijp(pres); 616 | t3jkb=t3jkp(pres); 617 | t3mnb=t3mnp(pres); 618 | t3opb=t3opp(pres); 619 | if(temp-t3cdbpsat643) 637 | { 638 | t3cdb=t3cdp(pres); 639 | t3qub=t3qup(pres); 640 | t3rxb=t3rxp(pres); 641 | t3jkb=t3jkp(pres); 642 | // printf("%lf\n",t3qub); 643 | 644 | if(temp-t3cdbt3rxb&&(temp-t3jkbt3jkb) 651 | return 11;//3k 652 | } 653 | 654 | else if(pres>20.5e6) 655 | { 656 | t3cdb=t3cdp(pres); 657 | tsatb=tsatp(pres); 658 | t3jkb=t3jkp(pres); 659 | 660 | if(temp-t3cdbp3cd) 671 | { 672 | t3cdb=t3cdp(pres); 673 | tsatb=tsatp(pres); 674 | 675 | if(temp-t3cdbpsatt(623.15)) 683 | { 684 | tsatb=tsatp(pres); 685 | if(temp-tsatb22.11e6&&(pres-22.5e6t3qub&&(temp-t3uvb22.064e6&&(pres-22.11e6t3qub&&(temp-t3uvbpsat264&&(pres-22.064e6t3qub&&(temp-t3uvbpsat643) 751 | { 752 | t3qub=t3qup(pres); 753 | if(temp>t3qub) 754 | return 21;//3u 755 | } 756 | } 757 | else if(temp>tsatp(pres)) 758 | { 759 | if(pres>psat385&&(pres-22.064e6)psat643) 769 | { 770 | t3rxb=t3rxp(pres); 771 | if(temp-t3rxbpressure=dens*GAS_CONST_STEAM*temp*del*phid(del,tau); 1106 | p_prop->temp=temp; 1107 | p_prop->dens=dens; 1108 | p_prop->spe_vol=1/dens; 1109 | p_prop->spe_energy=tau*phit(del,tau)*GAS_CONST_STEAM*temp; 1110 | p_prop->spe_entr=(tau*phit(del,tau)-phi(del,tau))*GAS_CONST_STEAM; 1111 | p_prop->spe_enth=(tau*phit(del,tau)+del*phid(del,tau))*GAS_CONST_STEAM*temp; 1112 | p_prop->spe_h_v=-tau*tau*phitt(del,tau)*GAS_CONST_STEAM; 1113 | p_prop->spe_h_p=(-tau*tau*phitt(del,tau)+pow(del*phid(del,tau)-del*tau*phidt(del,tau),2)/(2*del*phid(del,tau)+del*del*phidd(del,tau)))*GAS_CONST_STEAM; 1114 | p_prop->speed_sound=sqrt(GAS_CONST_STEAM*temp*(2*del*phid(del,tau)+del*del*phidd(del,tau)-pow(del*phid(del,tau)-del*tau*phidt(del,tau),2)/(tau*tau*phitt(del,tau)))); 1115 | p_prop->drdp=1/(GAS_CONST_STEAM*temp*(phidd(del,tau)*del*del+2*del*phid(del,tau))); 1116 | p_prop->vapor_fraction=1; 1117 | } 1118 | 1119 | 1120 | void calcFD_dFD_pt(double* fd, double* dfd, double pres, double temp, double del) 1121 | { 1122 | double tau=T_C/temp; 1123 | *fd=r_c*del*del*phid(del,tau)-pres/(GAS_CONST_STEAM*temp); 1124 | *dfd=r_c*(2*del*phid(del,tau)+del*del*phidd(del,tau)); 1125 | } 1126 | 1127 | int hp_dens_pt(double* dens_final, double dens_ini, double pres, double temp) 1128 | { 1129 | double fd,dfd,del_prev,del_next; 1130 | int i=0; 1131 | del_prev=dens_ini/r_c; 1132 | do 1133 | { 1134 | calcFD_dFD_pt(&fd,&dfd,pres,temp,del_prev); 1135 | del_next=del_prev-fd/dfd; 1136 | if(fabs(del_next-del_prev)ZERO&&iter_timesfabs(dd)) 1222 | dmax=fabs(dt); 1223 | else 1224 | dmax=fabs(dd); 1225 | }while(dmax>ZERO&&ifabs(dd)) 1279 | dmax=fabs(dt); 1280 | else 1281 | dmax=fabs(dd); 1282 | }while(dmax>ZERO&&ifabs(dd)) 1336 | dmax=fabs(dt); 1337 | else 1338 | dmax=fabs(dd); 1339 | }while(dmax>ZERO&&ifabs(dd)) 1419 | dmax=fabs(dt); 1420 | else 1421 | dmax=fabs(dd); 1422 | // printf("!!!%lf!!!!\n",dmax); 1423 | }while(dmax>ZERO&&i1e-8); 1477 | if(i==MAX_ITER_TIMES) 1478 | { 1479 | *dens=-1; 1480 | return -1; 1481 | } 1482 | else 1483 | { 1484 | *dens=del_nxt*r_c; 1485 | return 0; 1486 | } 1487 | } 1488 | 1489 | int pres_th_r3(double* pres, double temp, double spe_enth) 1490 | { 1491 | double dens,del,tau; 1492 | int flag; 1493 | flag=dens_th_r3(&dens,temp,spe_enth); 1494 | 1495 | if(flag==-1) 1496 | { 1497 | return -1; 1498 | } 1499 | else 1500 | { 1501 | del=dens/r_c; 1502 | tau=T_C/temp; 1503 | *pres=dens*GAS_CONST_STEAM*temp*del*phid(del,tau); 1504 | return 0; 1505 | } 1506 | } 1507 | 1508 | int pt_hs_r3(double* pres, double* temp, double spe_enth, double spe_entr) 1509 | { 1510 | double tempr3,dens,presr3; 1511 | int flag; 1512 | flag=tr_hs_r3(&tempr3,&dens,spe_enth,spe_entr); 1513 | // printf("\n###############################%.8lf,%.8lf\n",tempr3,dens); 1514 | if(flag==-1) 1515 | { 1516 | *pres=-1; 1517 | *temp=-1; 1518 | return -1; 1519 | } 1520 | flag=pres_th_r3(&presr3,tempr3,spe_enth); 1521 | if(flag==-1) 1522 | { 1523 | *pres=-1; 1524 | *temp=-1; 1525 | return -1; 1526 | } 1527 | *pres=presr3; 1528 | *temp=tempr3; 1529 | return 0; 1530 | } 1531 | 1532 | void calcFd_DFd_tu(double* fd, double* dfd, double temp, double spe_ener, double del) 1533 | { 1534 | double tau=T_C/temp; 1535 | *fd=phit(del,tau)-spe_ener/(GAS_CONST_STEAM*T_C); 1536 | *dfd=phidt(del,tau); 1537 | } 1538 | int dens_tu_r3(double* dens, double temp, double spe_ener) 1539 | { 1540 | double fd,dfd,del_ini,del_prev,del_nxt; 1541 | int i=0; 1542 | del_ini=1; 1543 | 1544 | calcFd_DFd_tu(&fd,&dfd,temp,spe_ener,del_ini); 1545 | del_nxt=del_ini-fd/dfd; 1546 | do 1547 | { 1548 | del_prev=del_nxt; 1549 | calcFd_DFd_tu(&fd,&dfd,temp,spe_ener,del_prev); 1550 | del_nxt=del_prev-fd/dfd; 1551 | i++; 1552 | }while(i1e-8); 1553 | if(i==MAX_ITER_TIMES) 1554 | { 1555 | *dens=-1; 1556 | return -1; 1557 | } 1558 | else 1559 | { 1560 | *dens=del_nxt*r_c; 1561 | return 0; 1562 | } 1563 | } 1564 | 1565 | int pres_tu_r3(double* pres, double temp, double spe_ener) 1566 | { 1567 | double dens,del; 1568 | int flag; 1569 | flag=dens_tu_r3(&dens,temp,spe_ener); 1570 | if(flag==-1) 1571 | { 1572 | return -1; 1573 | } 1574 | else 1575 | { 1576 | del=dens/r_c; 1577 | *pres=dens*GAS_CONST_STEAM*temp*del*phid(del,T_C/temp); 1578 | return 0; 1579 | } 1580 | } 1581 | 1582 | void calcFd_DFd_ts(double* fd, double* dfd, double temp, double spe_entr, double del) 1583 | { 1584 | double tau=T_C/temp; 1585 | *fd=tau*phit(del,tau)-phi(del,tau)-spe_entr/GAS_CONST_STEAM; 1586 | *dfd=tau*phidt(del,tau)-phid(del,tau); 1587 | } 1588 | 1589 | int dens_ts_r3(double* dens, double temp, double spe_entr) 1590 | { 1591 | double fd,dfd,del_ini,del_prev,del_nxt; 1592 | int i=0; 1593 | del_ini=1; 1594 | 1595 | calcFd_DFd_ts(&fd,&dfd,temp,spe_entr,del_ini); 1596 | del_nxt=del_ini-fd/dfd; 1597 | do 1598 | { 1599 | del_prev=del_nxt; 1600 | calcFd_DFd_ts(&fd,&dfd,temp,spe_entr,del_prev); 1601 | del_nxt=del_prev-fd/dfd; 1602 | i++; 1603 | }while(i1e-8); 1604 | if(i==MAX_ITER_TIMES) 1605 | { 1606 | *dens=-1; 1607 | return -1; 1608 | } 1609 | else 1610 | { 1611 | *dens=del_nxt*r_c; 1612 | return 0; 1613 | } 1614 | } 1615 | 1616 | int pres_ts_r3(double* pres, double temp, double spe_entr) 1617 | { 1618 | double dens,del; 1619 | int flag; 1620 | flag=dens_ts_r3(&dens,temp,spe_entr); 1621 | if(flag==-1) 1622 | { 1623 | return -1; 1624 | } 1625 | else 1626 | { 1627 | del=dens/r_c; 1628 | *pres=dens*GAS_CONST_STEAM*temp*del*phid(del,T_C/temp); 1629 | return 0; 1630 | } 1631 | } 1632 | 1633 | int steam_prop_calc_r3(double pressure, double temp, steam_prop* p_prop) 1634 | { 1635 | double tau=647.096/temp; 1636 | double spe_vol; 1637 | double del,hp_dens; 1638 | int hp_dens_flag,i; 1639 | double dens_ini[10]={ 1640 | 10,50,100,200,300,400,500,800,1000,1500 1641 | }; 1642 | 1643 | spe_vol=spe_vol_pt(pressure,temp); 1644 | if(fabs(spe_vol+1)dens=hp_dens; 1656 | } 1657 | } 1658 | 1659 | else 1660 | { 1661 | hp_dens_flag=hp_dens_pt(&hp_dens,1/spe_vol,pressure,temp); 1662 | if(hp_dens_flag==0) 1663 | p_prop->dens=hp_dens; 1664 | else 1665 | p_prop->dens=1/spe_vol; 1666 | } 1667 | 1668 | r3prop_calc_tr(temp,p_prop->dens,p_prop); 1669 | return 0; 1670 | } --------------------------------------------------------------------------------