/** This function will never return region 4, because it's not possible to 'sit on the knife' of saturation. If you need to set saturated states, you should use another function such as freesteam_region1_set_Tx. */ SteamState freesteam_set_pT(double p, double T){ SteamState S; if(T < REGION1_TMAX){ if(p > freesteam_region4_psat_T(T)){ S.region = 1; S.R1.T = T; S.R1.p = p; }else{ S.region = 2; S.R2.T = T; S.R2.p = p; } }else{ //fprintf(stderr,"%s: T = %g >= REGION1_TMAX = %g\n",__func__,T,REGION1_TMAX); /* FIXME some optimisation possiblxe here with test for lower pressures */ double T23 = freesteam_b23_T_p(p); double p23min = freesteam_b23_p_T(REGION1_TMAX); if(p < p23min || T > T23){ //fprintf(stderr,"%s: T = %g > T23 = %g\n",__func__,T,T23); S.region = 2; S.R2.T = T; S.R2.p = p; }else{ /* FIXME the limit values are all wrong here! */ //fprintf(stderr,"%s: region 3\n",__func__); SteamPTData D = {p,T}; double ub = 1./freesteam_region1_v_pT(IAPWS97_PMAX,REGION1_TMAX); double lb = 1./freesteam_region2_v_pT(freesteam_b23_p_T(T),T); /* if we're in the little wee area around the critical pt... */ if(T < IAPWS97_TCRIT){ double psat = freesteam_region4_psat_T(T); if(p < psat){ ub = freesteam_region4_rhog_T(T); assert(lb<ub); }else{ lb = freesteam_region4_rhof_T(T); //fprintf(stderr,"lb = %g, ub = %g\n",lb,ub); assert(lb<ub); } } double tol = 1e-7; double sol, err = 0; if(zeroin_solve(&pT_region3_fn, &D, lb, ub, tol, &sol, &err)){ fprintf(stderr,"%s (%s:%d): failed to solve for rho\n",__func__,__FILE__,__LINE__); exit(1); } S.region = 3; S.R3.T = T; S.R3.rho = sol; //assert(fabs((freesteam_p(S) - p)/p) < tol); } } //fprintf(stderr,"%s: region %d\n",__func__,S.region); return S; }
/** This function will always return saturated mixtures; no negative or >1 values of x are being 'understood' here (although one can give them meaning based on extrapolated values of u or h of v, for example...) */ SteamState freesteam_set_Tx(double T, double x) { SteamState S; if(T >= IAPWS97_TCRIT) { /* region 3 supercritical. just return a state with the specified temperature and the critical point entropy. arbitrary. */ SolveTSData D = {T, freesteam_region3_s_rhoT(IAPWS97_RHOCRIT, IAPWS97_TCRIT)}; double ub = 1./freesteam_region1_v_pT(IAPWS97_PMAX,REGION1_TMAX); double lb = 1./freesteam_region2_v_pT(freesteam_b23_p_T(T),T); double tol = 1e-7; double sol, err = 0; if(zeroin_solve(&Ts_region3_fn, &D, lb, ub, tol, &sol, &err)) { fprintf(stderr,"%s (%s:%d): failed to solve for rho\n",__func__,__FILE__,__LINE__); exit(1); } S.region = 3; S.R3.T = T; S.R3.rho = sol; } else if(x <= 0) { if(T > REGION1_TMAX) { S.region = 3; S.R3.T = T; S.R3.rho = freesteam_region4_rhof_T(T); /* FIXME iteratively refine the value */ } else { S.region = 1; S.R1.p = freesteam_region4_psat_T(T); S.R1.T = T; } } else if(x >= 1) { if(T > REGION1_TMAX) { S.region = 3; S.R3.T = T; S.R3.rho = freesteam_region4_rhog_T(T); /* FIXME iteratively refine the value */ } else { S.region = 2; S.R1.p = freesteam_region4_psat_T(T); S.R1.T = T; } } else { /* finally! */ S.region = 4; S.R4.T = T; S.R4.x = x; } return S; }
int freesteam_region_pu(double p, double u){ double p13 = freesteam_region4_psat_T(REGION1_TMAX); if(p < p13){ double Tsat = freesteam_region4_Tsat_p(p); double uf = freesteam_region1_u_pT(p,Tsat); if(u < uf)return 1; double ug = freesteam_region2_u_pT(p,Tsat); if(u > ug)return 2; return 4; } double u13 = freesteam_region1_u_pT(p,REGION1_TMAX); if(u < u13){ return 1; } double T23 = freesteam_b23_T_p(p); double u23 = freesteam_region2_u_pT(p,T23); if(u > u23){ return 2; } if(p > IAPWS97_PCRIT)return 3; /* FIXME what we really need here is a psat(u) function! The current method is singular. */ double Tsat = freesteam_region4_Tsat_p(p); double rhof = freesteam_region4_rhof_T(Tsat); double uf = freesteam_region3_u_rhoT(rhof,Tsat); if(u<uf) return 3; double rhog = freesteam_region4_rhog_T(Tsat); double ug = freesteam_region3_u_rhoT(rhog,Tsat); if(u>ug)return 3; return 4; }
int freesteam_region_pv(double p, double v){ double p13 = freesteam_region4_psat_T(REGION1_TMAX); if(p > p13){ double v13 = freesteam_region1_v_pT(p, REGION1_TMAX); if(v < v13) return 1; /* region 2-3 */ double T23 = freesteam_b23_T_p(p); double v23 = freesteam_region2_v_pT(p,T23); if(v > v23) return 2; /* region 3? or high-pressure part of region 4? */ if(p >= IAPWS97_PCRIT) return 3; double Tsat = freesteam_region4_Tsat_p(p); double vf = 1./ freesteam_region4_rhof_T(Tsat); if(v < vf) return 3; double vg = 1./ freesteam_region4_rhog_T(Tsat); if(v > vg) return 3; return 4; }else{ double Tsat = freesteam_region4_Tsat_p(p); double vf = freesteam_region1_v_pT(p,Tsat); if(v < vf) return 1; double vg = freesteam_region2_v_pT(p,Tsat); if(v > vg) return 2; return 4; } }
double freesteam_region4_v_Tx(double T, double x){ double vf, vg; if(T < REGION1_TMAX){ double psat = freesteam_region4_psat_T(T); vf = freesteam_region1_v_pT(psat,T); vg = freesteam_region2_v_pT(psat,T); }else{ vf = 1./ freesteam_region4_rhof_T(T); vg = 1./ freesteam_region4_rhog_T(T); } return vf + x*(vg - vf); }
double freesteam_region4_u_Tx(double T, double x){ double uf, ug; if(T < REGION1_TMAX){ double psat = freesteam_region4_psat_T(T); uf = freesteam_region1_u_pT(psat,T); ug = freesteam_region2_u_pT(psat,T); }else{ double rhof, rhog; rhof = freesteam_region4_rhof_T(T); rhog = freesteam_region4_rhog_T(T); uf = freesteam_region3_u_rhoT(rhof,T); ug = freesteam_region3_u_rhoT(rhog,T); } return uf + x*(ug - uf); }
double freesteam_drhogdT_T(double T){ double dpsatdT = freesteam_region4_dpsatdT_T(T); double rhog = freesteam_region4_rhog_T(T); if(T < REGION1_TMAX){ double psat = freesteam_region4_psat_T(T); SteamState Sg = freesteam_region2_set_pT(psat,T); double vf = freesteam_v(Sg); return -1./SQ(vf) * (PT2('v',Sg) * dpsatdT + TP2('v',Sg)); }else{ SteamState Sg = freesteam_region3_set_rhoT(rhog,T); double dpdT = TV3('p',Sg); double dpdrho = -1./SQ(rhog) * VT3('p',Sg); return (dpsatdT - dpdT)/dpdrho; } }
double freesteam_region4_cv_Tx(double T, double x){ double cvf, cvg; if(T < REGION1_TMAX){ double psat = freesteam_region4_psat_T(T); cvf = freesteam_region1_cv_pT(psat,T); cvg = freesteam_region2_cv_pT(psat,T); }else{ double rhof, rhog; rhof = freesteam_region4_rhof_T(T); rhog = freesteam_region4_rhog_T(T); cvf = freesteam_region3_cv_rhoT(rhof,T); cvg = freesteam_region3_cv_rhoT(rhog,T); } return cvf + x*(cvg - cvf); }
double freesteam_region4_cp_Tx(double T, double x){ double cpf, cpg; if(T < REGION1_TMAX){ double psat = freesteam_region4_psat_T(T); cpf = freesteam_region1_cp_pT(psat,T); cpg = freesteam_region2_cp_pT(psat,T); }else{ double rhof, rhog; rhof = freesteam_region4_rhof_T(T); rhog = freesteam_region4_rhog_T(T); cpf = freesteam_region3_cp_rhoT(rhof,T); cpg = freesteam_region3_cp_rhoT(rhog,T); } return cpf + x*(cpg - cpf); }
double freesteam_region4_s_Tx(double T, double x){ double sf, sg; if(T < REGION1_TMAX){ double psat = freesteam_region4_psat_T(T); sf = freesteam_region1_s_pT(psat,T); sg = freesteam_region2_s_pT(psat,T); }else{ double rhof, rhog; rhof = freesteam_region4_rhof_T(T); rhog = freesteam_region4_rhog_T(T); sf = freesteam_region3_s_rhoT(rhof,T); sg = freesteam_region3_s_rhoT(rhog,T); } return sf + x*(sg - sf); }
double freesteam_drhofdT_T(double T){ double dpsatdT = freesteam_region4_dpsatdT_T(T); if(T < REGION1_TMAX){ double psat = freesteam_region4_psat_T(T); SteamState Sf = freesteam_region1_set_pT(psat,T); double vf = freesteam_v(Sf); return -1./SQ(vf) * (PT1('v',Sf) * dpsatdT + TP1('v',Sf)); }else{ /* FIXME: add iterative refinement of value of rhof */ double rhof = freesteam_region4_rhof_T(T); SteamState Sf = freesteam_region3_set_rhoT(rhof,T); double dpdT = TV3('p',Sf); double dpdrho = -1./SQ(rhof) * VT3('p',Sf); return (dpsatdT - dpdT)/dpdrho; } }
double freesteam_region4_h_Tx(double T, double x){ double hf, hg; if(T < REGION1_TMAX){ double psat = freesteam_region4_psat_T(T); hf = freesteam_region1_h_pT(psat,T); hg = freesteam_region2_h_pT(psat,T); //fprintf(stderr,"%s: T = %f K, psat = %f MPa, hf = %f kJ/kg, hg = %f kJ/kg\n",__func__,T,psat/1e6,hf/1e3,hg); }else{ double rhof, rhog; rhof = freesteam_region4_rhof_T(T); rhog = freesteam_region4_rhog_T(T); hf = freesteam_region3_h_rhoT(rhof,T); hg = freesteam_region3_h_rhoT(rhog,T); } return hf + x*(hg - hf); }
double freesteam_region4_dpsatdT_T(double T){ /* calculated this derivative using implicit differentiation of the quadratic expression, then derivatives of beta and script-theta */ double beta = pow(freesteam_region4_psat_T(T)/REGION4_PSTAR, 0.25); #define N REGION4_N double theta = T/REGION4_TSTAR + N[9] / (T/REGION4_TSTAR - N[10]); double XBETA = (2.*beta + N[3])*SQ(theta) + (2.*beta*N[1] + N[4])*theta + 2.*N[2]*beta + N[5]; double XTHETA = (2.*theta + N[1])*SQ(beta) + (2.*N[3]*theta + N[4])*beta + 2.*N[6]*theta + N[7]; double dthetadT = (1 - N[9] / (T/REGION4_TSTAR - N[10]))/REGION4_TSTAR; double dbetadtheta = -XTHETA/XBETA; double dpdbeta = 4*SQ(beta)*beta*REGION4_PSTAR; #undef N return dpdbeta * dbetadtheta * dthetadT; }
/* ⎰ ∂z ⎱ = ⎰∂z_f⎱ (1 - x) + ⎰∂z_f⎱ x ⎱ ∂T ⎰x ⎱ ∂T ⎰ ⎱ ∂T ⎰ */ double freesteam_region4_dAdTx(FREESTEAM_CHAR z, SteamState S){ double res; #define T S.R4.T switch(z){ case 'p': res = freesteam_region4_dpsatdT_T(T); return res; case 'T': res = 1; return res; case 'x': res = 0; return res; } //fprintf(stderr,"%s: T = %g\n",__func__,T); assert(!isnan(T)); double dzfdT, dzgdT; if(T < REGION1_TMAX){ //fprintf(stderr,"%s: below REGION1_TMAX\n",__func__); double psat = freesteam_region4_psat_T(T); SteamState Sf = freesteam_region1_set_pT(psat,T); SteamState Sg = freesteam_region2_set_pT(psat,T); double dpsatdT = freesteam_region4_dpsatdT_T(T); dzfdT = PT1(z,Sf)*dpsatdT + TP1(z,Sf); dzgdT = PT2(z,Sg)*dpsatdT + TP2(z,Sg); }else{ double rhof = freesteam_region4_rhof_T(T); double rhog = freesteam_region4_rhog_T(T); assert(rhof!=0); assert(rhog!=0); SteamState Sf = freesteam_region3_set_rhoT(rhof,T); SteamState Sg = freesteam_region3_set_rhoT(rhog,T); double dvfdT = -1./SQ(rhof) * freesteam_drhofdT_T(T); assert(!isnan(dvfdT)); double dvgdT = -1./SQ(rhog) * freesteam_drhogdT_T(T); assert(!isnan(dvgdT)); dzfdT = VT3(z,Sf)*dvfdT + TV3(z,Sf); dzgdT = VT3(z,Sg)*dvgdT + TV3(z,Sg); } assert(!isnan(dzfdT)); assert(!isnan(dzgdT)); #define x S.R4.x res = dzfdT*(1-x) + dzgdT*x; //fprintf(stderr,"(∂%c/∂T)x = %g\n",z,res); return res; #undef T #undef x }
/* These derivatives are simply the gradient within the two-phase region, and is very simply calculated as ⎰ ∂z ⎱ = z_g - z_f where z in {v,u,h,z,s,g,a}. ⎱ ∂x ⎰T or, otherwise, ⎰ ∂T ⎱ , ⎰ ∂p ⎱ = 0 ⎱ ∂x ⎰T ⎱ ∂x ⎰T */ double freesteam_region4_dAdxT(FREESTEAM_CHAR z, SteamState S){ switch(z){ case 'p': return 0; case 'T': return 0; case 'x': return 1; } #define T S.R4.T #define x S.R4.x double p = freesteam_region4_psat_T(T); double zf, zg; switch(z){ case 'v': ZFG(v,p,T); break; case 'u': ZFG(u,p,T); break; case 'h': ZFG(h,p,T); break; case 's': ZFG(s,p,T); break; case 'g': ZFG(g,p,T); break; case 'a': case 'f': ZFG(a,p,T); break; default: fprintf(stderr,"%s (%s:%d): Invalid character x = '%c'\n", __func__,__FILE__,__LINE__,z); exit(1); } //fprintf(stderr,"(∂%c/∂x)T = %g\n",z,zg-zf); return zg - zf; }
//CL: drhodh=(drho/dh)_p=const Foam::scalar Foam::drhodh(SteamState S) { label region; scalar cp,beta,drhodh,rho; region=freesteam_region(S); if (region==1) { rho=1/freesteam_region1_v_pT(S.R1.p,S.R1.T); //Cl: note: in FreeStream, beta=1/V*(dV/dP)_P=const is called alphaV (in this region) beta=freesteam_region1_alphav_pT(S.R1.p,S.R1.T); cp=freesteam_region1_cp_pT(S.R1.p,S.R1.T); //CL: getting derivatives using Bridgmans table //CL: drhodh=(drho/dh)_p=const drhodh=-rho*beta/cp; } else if (region==2) { rho=1/freesteam_region2_v_pT(S.R2.p,S.R2.T); //Cl: note: in FreeStream, beta=1/V*(dV/dP)_P=const is called alphaV (in this region) //Cl: note: in FreeStream, kappa=1/V*(dV/dP)_T=const is called kappaT (in this region) beta=freesteam_region2_alphav_pT(S.R2.p,S.R2.T); cp=freesteam_region2_cp_pT(S.R2.p,S.R2.T); //CL: getting derivatives using Bridgmans table //CL: drhodh=(drho/dh)_p=const drhodh=-rho*beta/cp; } else if (region==3) { scalar gamma,cv,p; p=freesteam_region3_p_rhoT(S.R3.rho,S.R3.T); //Cl: note: beta=1/V*(dV/dP)_P=const //Cl: note: in FreeStream, gamma=1/p*(dp/dT)_v=const is called alphap (in this region gamma=freesteam_region3_alphap_rhoT(S.R3.rho,S.R3.T); cp=freesteam_region3_cp_rhoT(S.R3.rho,S.R3.T); cv=freesteam_region3_cv_rhoT(S.R3.rho,S.R3.T); beta=(cp-cv)/(S.R3.T/S.R3.rho*p*gamma); //CL: getting derivatives using Bridgmans table //CL: drhodh=(drho/dh)_p=const drhodh=-S.R3.rho*beta/cp; } else if (region==4) { scalar vv,vl,hl,hv,p; SteamState Sl,Sv; rho=1/freesteam_region4_v_Tx(S.R4.T,S.R4.x); p=freesteam_region4_psat_T(S.R4.T); //CL: Getting density on the vapour and liquid lines vv=1/freesteam_region4_rhog_T(S.R4.T); vl=1/freesteam_region4_rhof_T(S.R4.T); // getting the states outside the vapour dome Sl=freesteam_set_pv(p,vl-0.0000001); //inside region 1 Sv=freesteam_set_pv(p,vv+0.0000001); //inside region 2 hl=freesteam_region1_h_pT(Sl.R1.p,Sl.R1.T); hv=freesteam_region2_h_pT(Sv.R2.p,Sv.R2.T); //CL: drhodh=(drho/dh)_p=const drhodh=-rho*rho*(vv-vl)/(hv-hl); } else { Info<<"IAPWS-IF97.C error, outside the regions 1-4"<<endl; } return drhodh; }
//CL: psiH=(drho/dp)_h=const Foam::scalar Foam::psiH(SteamState S) { label region; scalar kappa,cp,beta,psiH,rho; region=freesteam_region(S); if (region==1) { //Cl: note: in FreeStream, beta=1/V*(dV/dP)_P=const is called alphaV (in this region) //Cl: note: in FreeStream, kappa=1/V*(dV/dP)_T=const is called kappaT (in this region) kappa=freesteam_region1_kappaT_pT(S.R1.p,S.R1.T); beta=freesteam_region1_alphav_pT(S.R1.p,S.R1.T); cp=freesteam_region1_cp_pT(S.R1.p,S.R1.T); rho=1/freesteam_region1_v_pT(S.R1.p,S.R1.T); //CL: getting derivatives using Bridgmans table //CL: psiH=(drho/dp)_h=const psiH=-((S.R1.T*beta*beta-beta)/cp-kappa*rho); } else if (region==2) { //Cl: note: in FreeStream, beta=1/V*(dV/dP)_P=const is called alphaV (in this region) //Cl: note: in FreeStream, kappa=1/V*(dV/dP)_T=const is called kappaT (in this region) kappa=freesteam_region2_kappaT_pT(S.R2.p,S.R2.T); beta=freesteam_region2_alphav_pT(S.R2.p,S.R2.T); cp=freesteam_region2_cp_pT(S.R2.p,S.R2.T); rho=1/freesteam_region2_v_pT(S.R2.p,S.R2.T); //CL: getting derivatives using Bridgmans table //CL: psiH=(drho/dp)_h=const psiH=-((S.R2.T*beta*beta-beta)/cp-kappa*rho); } else if (region==3) { scalar gamma,cv,p; rho=S.R3.rho; p=freesteam_region3_p_rhoT(S.R3.rho,S.R3.T); //Cl: note: beta=1/V*(dV/dP)_P=const //Cl: note: kappa=1/V*(dV/dP)_T=const //Cl: note: in FreeStream, gamma=1/p*(dp/dT)_v=const is called alphap (in this region gamma=freesteam_region3_alphap_rhoT(S.R3.rho,S.R3.T); cp=freesteam_region3_cp_rhoT(S.R3.rho,S.R3.T); cv=freesteam_region3_cv_rhoT(S.R3.rho,S.R3.T); beta=(cp-cv)/(S.R3.T/S.R3.rho*p*gamma); kappa=(cp-cv)/(S.R3.T/S.R3.rho*p*p*gamma*gamma); //CL: getting derivatives using Bridgmans table //CL: psiH=(drho/dp)_h=const psiH=-((S.R3.T*beta*beta-beta)/cp-kappa*rho); } else if (region==4) { scalar rhov,rhol,betav,betal,kappav,kappal,vv,vl,cpl,cpv,hl,hv,h,p; scalar dvldp,dvvdp,dhldp,dhvdp; scalar dpdT,dvdp,dxdp; SteamState Sl,Sv; rho=1/freesteam_region4_v_Tx(S.R4.T,S.R4.x); h=freesteam_region4_h_Tx(S.R4.T,S.R4.x); p=freesteam_region4_psat_T(S.R4.T); //CL: Getting density on the vapour and liquid lines rhov=freesteam_region4_rhog_T(S.R4.T); rhol=freesteam_region4_rhof_T(S.R4.T); vv=1/rhov; vl=1/rhol; //CL: getting derivatives --> this is a bit tricky in the vapor dome dpdT=freesteam_region4_dpsatdT_T(S.R4.T); // getting the states outside the vapour dome Sl=freesteam_set_pv(p,vl-0.0000001); //inside region 1 Sv=freesteam_set_pv(p,vv+0.0000001); //inside region 2 kappal=freesteam_region1_kappaT_pT(Sl.R1.p,Sl.R1.T); kappav=freesteam_region2_kappaT_pT(Sv.R2.p,Sv.R2.T); betal=freesteam_region1_alphav_pT(Sl.R1.p,Sl.R1.T); betav=freesteam_region2_alphav_pT(Sv.R2.p,Sv.R2.T); cpl=freesteam_region1_cp_pT(Sl.R1.p,Sl.R1.T); cpv=freesteam_region2_cp_pT(Sv.R2.p,Sv.R2.T); hl=freesteam_region1_h_pT(Sl.R1.p,Sl.R1.T); hv=freesteam_region2_h_pT(Sv.R2.p,Sv.R2.T); //calculation derviatives on liquid and vapour line dvldp=betal*vl/dpdT-kappal*vl; dvvdp=betav*vv/dpdT-kappav*vv; dhldp=vl*(1-betal*Sl.R1.T)+cpl/dpdT; dhvdp=vv*(1-betav*Sv.R2.T)+cpl/dpdT; dxdp=-dhldp/(hv-hl) +(h-hl)/((hv-hl)*(hv-hl)) *(dhvdp-dhldp); //CL: psiH=(drho/dp)_h=const dvdp=dvldp+(dvvdp-dvldp)*S.R4.x+(vv-vl)*dxdp; psiH=-rho*rho*dvdp; } else { Info<<"IAPWS-IF97.C error, outside the regions 1-4"<<endl; } return psiH; }
//CL: calculated the properties --> this function is called by the functions above //CL: does not calulated the internal energy, if this is needed e.g. for sonicFoam //CL: the function has to be changed a little bit void Foam::calculateProperties_h ( SteamState S, scalar &p, scalar &h, scalar &T, scalar &rho, scalar &psi, scalar &drhodh, scalar &mu, scalar &alpha, scalar &x ) { label region; scalar kappa,lambda,cp,beta; region=freesteam_region(S); if (region==1) { p=S.R1.p; T=S.R1.T; rho=1/freesteam_region1_v_pT(S.R1.p,S.R1.T); h=freesteam_region1_h_pT(S.R1.p,S.R1.T); x=0; //Cl: note: in FreeStream, beta=1/V*(dV/dP)_P=const is called alphaV (in this region) //Cl: note: in FreeStream, kappa=1/V*(dV/dP)_T=const is called kappaT (in this region) kappa=freesteam_region1_kappaT_pT(S.R1.p,S.R1.T); beta=freesteam_region1_alphav_pT(S.R1.p,S.R1.T); cp=freesteam_region1_cp_pT(S.R1.p,S.R1.T); //CL: getting derivatives using Bridgmans table //CL: psi=(drho/dp)_h=const //CL: drhodh=(drho/dh)_p=const psi=-((T*beta*beta-beta)/cp-kappa*rho); drhodh=-rho*beta/cp; //CL: getting transport properties mu=freesteam_mu_rhoT(rho, T); lambda=freesteam_k_rhoT(rho,T); alpha=lambda/cp; //Cl: Important info -->alpha= thermal diffusivity time density } else if (region==2) { p=S.R2.p; T=S.R2.T; rho=1/freesteam_region2_v_pT(S.R2.p,S.R2.T); h=freesteam_region2_h_pT(S.R2.p,S.R2.T); x=1; //Cl: note: in FreeStream, beta=1/V*(dV/dP)_P=const is called alphaV (in this region) //Cl: note: in FreeStream, kappa=1/V*(dV/dP)_T=const is called kappaT (in this region) kappa=freesteam_region2_kappaT_pT(S.R2.p,S.R2.T); beta=freesteam_region2_alphav_pT(S.R2.p,S.R2.T); cp=freesteam_region2_cp_pT(S.R2.p,S.R2.T); //CL: getting derivatives using Bridgmans table //CL: psi=(drho/dp)_h=const //CL: drhodh=(drho/dh)_p=const psi=-((T*beta*beta-beta)/cp-kappa*rho); drhodh=-rho*beta/cp; //CL: getting transport properties mu=freesteam_mu_rhoT(rho, T); lambda=freesteam_k_rhoT(rho,T); alpha=lambda/cp; //Cl: Important info -->alpha= thermal diffusivity time density } else if (region==3) { scalar gamma,cv; rho=S.R3.rho; T=S.R3.T; p=freesteam_region3_p_rhoT(S.R3.rho,S.R3.T); h=freesteam_region3_h_rhoT(S.R3.rho,S.R3.T); //CL= when h<h @ critical point -->x=0 else x=1 if (h<2084256.263) { x=0; } else { x=1; } //Cl: note: beta=1/V*(dV/dP)_P=const //Cl: note: kappa=1/V*(dV/dP)_T=const //Cl: note: in FreeStream, gamma=1/p*(dp/dT)_v=const is called alphap (in this region) gamma=freesteam_region3_alphap_rhoT(S.R3.rho,S.R3.T); cp=freesteam_region3_cp_rhoT(S.R3.rho,S.R3.T); cv=freesteam_region3_cv_rhoT(S.R3.rho,S.R3.T); beta=(cp-cv)/(S.R3.T/S.R3.rho*p*gamma); kappa=(cp-cv)/(S.R3.T/S.R3.rho*p*p*gamma*gamma); //CL: getting derivatives using Bridgmans table //CL: psi=(drho/dp)_h=const //CL: drhodh=(drho/dh)_p=const psi=-((T*beta*beta-beta)/cp-kappa*rho); drhodh=-rho*beta/cp; //CL: getting transport properties mu=freesteam_mu_rhoT(rho, T); lambda=freesteam_k_rhoT(rho,T); alpha=lambda/cp; //Cl: Important info -->alpha= thermal diffusivity time density } else if (region==4) { scalar rhov,rhol,betav,betal,kappav,kappal,vv,vl,cpl,cpv,hl,hv,cp; scalar dvldp,dvvdp,dhldp,dhvdp; scalar dpdT,dvdh,dvdp,dxdp; SteamState Sl,Sv; x=S.R4.x; T=S.R4.T; rho=1/freesteam_region4_v_Tx(S.R4.T,S.R4.x); h=freesteam_region4_h_Tx(S.R4.T,S.R4.x); p=freesteam_region4_psat_T(S.R4.T); cp=freesteam_region4_cp_Tx(S.R4.T,S.R4.x); //CL: Getting density on the vapour and liquid lines rhov=freesteam_region4_rhog_T(S.R4.T); rhol=freesteam_region4_rhof_T(S.R4.T); vv=1/rhov; vl=1/rhol; //CL: getting derivatives --> this is a bit tricky inside the vapor dome dpdT=freesteam_region4_dpsatdT_T(S.R4.T); // getting the states outside the vapour dome Sl=freesteam_set_pv(p,vl-0.0000001); //inside region 1 Sv=freesteam_set_pv(p,vv+0.0000001); //inside region 2 kappal=freesteam_region1_kappaT_pT(Sl.R1.p,Sl.R1.T); kappav=freesteam_region2_kappaT_pT(Sv.R2.p,Sv.R2.T); betal=freesteam_region1_alphav_pT(Sl.R1.p,Sl.R1.T); betav=freesteam_region2_alphav_pT(Sv.R2.p,Sv.R2.T); cpl=freesteam_region1_cp_pT(Sl.R1.p,Sl.R1.T); cpv=freesteam_region2_cp_pT(Sv.R2.p,Sv.R2.T); hl=freesteam_region1_h_pT(Sl.R1.p,Sl.R1.T); hv=freesteam_region2_h_pT(Sv.R2.p,Sv.R2.T); //calculation derviatives on liquid and vapour line dvldp=betal*vl/dpdT-kappal*vl; dvvdp=betav*vv/dpdT-kappav*vv; dhldp=vl*(1-betal*Sl.R1.T)+cpl/dpdT; dhvdp=vv*(1-betav*Sv.R2.T)+cpl/dpdT; dxdp=-dhldp/(hv-hl) +(h-hl)/((hv-hl)*(hv-hl)) *(dhvdp-dhldp); //CL: psi=(drho/dp)_h=const dvdp=dvldp+(dvvdp-dvldp)*x+(vv-vl)*dxdp; psi=-rho*rho*dvdp; //CL: drhodh=(drho/dh)_p=const dvdh=(vv-vl)/(hv-hl); drhodh=-rho*rho*dvdh; //CL: getting transport properties mu=freesteam_mu_rhoT(rho, T); lambda=freesteam_k_rhoT(rho,T); alpha=lambda/cp; //Cl: Important info -->alpha= thermal diffusivity time density } else { std::cout<<"IAPWS-IF97 error, outside the regions 1-4"<<std::endl; } }
/* this function is a needed bit of a redundancy with solver2 in region 4 */ static double solver2_region4_p_Tx(double T, double x){ (void)x; return freesteam_region4_psat_T(T); }