@@ -53,7 +53,7 @@ namespace IF97
5353 }
5454
5555 // CoolProp-IF97 Version Number
56- static const char IF97VERSION [] = " v2.2.0 " ;
56+ static const char IF97VERSION [] = " v2.2.1 " ;
5757 // Setup Water Constants for Trivial Functions and use in Region Classes
5858 // Constant values from:
5959 // Revised Release on the IAPWS Industrial Formulation 1997
@@ -75,7 +75,7 @@ namespace IF97
7575 // IF97 Constants
7676 const double Tcrit = 647.096 ; // K
7777 const double Pcrit = 22.064 *p_fact; // MPa*
78- const double Rhocrit = 322.0 ; // kg/m³
78+ const double Rhocrit = 322.0 ; // kg/m³
7979 const double Scrit = 4.41202148223476 *R_fact; // kJ*/kg-K (needed for backward eqn. in Region 3(a)(b)
8080 const double Ttrip = 273.16 ; // K
8181 const double Ptrip = 0.000611657 *p_fact; // MPa* [Change per IAPWS R7-97(2012), p. 7, Eq. 9]
@@ -2418,7 +2418,7 @@ namespace IF97
24182418 // The equation is rearranged to solve for rho and turned
24192419 // into functions f(T,P,rho0) and f'(T,P,rho0) for the
24202420 // Newton-Raphson technique. Functions for
2421- // dphi/ddelta and d²phi/ddelta² were also required. These
2421+ // dphi/ddelta and d²phi/ddelta² were also required. These
24222422 // additional Taylor functions are defined above.
24232423 //
24242424 double f (double T, double p, double rho0) const {
@@ -2624,10 +2624,26 @@ namespace IF97
26242624 if ( ( T < Tmin ) || ( T > Tcrit ) ){
26252625 throw std::out_of_range (" Temperature out of range" );
26262626 }
2627+ // Initial formulas
26272628 const double theta = T/T_star+n[9 ]/(T/T_star-n[10 ]);
2628- const double AA = theta*theta + n[1 ]*theta + n[2 ];
2629- const double BB = n[3 ]*theta*theta + n[4 ]*theta + n[5 ];
2630- const double CC = n[6 ]*theta*theta + n[7 ]*theta + n[8 ];
2629+ // const double AA = theta*theta + n[1]*theta + n[2];
2630+ // const double BB = n[3]*theta*theta + n[4]*theta + n[5];
2631+ // const double CC = n[6]*theta*theta + n[7]*theta + n[8];
2632+
2633+ // First optimization
2634+ double ABC[3 ];
2635+ double & AA = ABC[0 ];
2636+ double & BB = ABC[1 ];
2637+ double & CC = ABC[2 ];
2638+ ABC[0 ] = 1.0 ; ABC[1 ] = n[3 ]; ABC[2 ] = n[6 ];
2639+ for (int j = 1 ; j < 3 ; ++j) {
2640+ for (int i = 0 ; i < 3 ; ++i) {
2641+ ABC[i] *= theta;
2642+ }
2643+ for (int i = 0 ; i < 3 ; ++i) {
2644+ ABC[i] += n[i * 3 + j];
2645+ }
2646+ }
26312647 return p_star*powi (2 *CC/(-BB+sqrt (BB*BB-4 *AA*CC)), 4 );
26322648 };
26332649 double T_p (double p) const {
@@ -4039,7 +4055,7 @@ namespace IF97
40394055 static const Backwards::Region3aS B3aS;
40404056 static const Backwards::Region3bS B3bS;
40414057
4042- // NOTE: Uncertainty in these reverse functions are ±25 mK, as documented in
4058+ // NOTE: Uncertainty in these reverse functions are ±25 mK, as documented in
40434059 // IAPWS R7-97(2012) and IAPWS SR3-03(2014). This can result in temperatures
40444060 // that are very slightly (within 25 mK) on the opposite side of the
40454061 // saturation curve from S/H values that are very near saturation. Use of these
@@ -4062,7 +4078,7 @@ namespace IF97
40624078 // When limiting to Tsat, this will keep
40634079 // temperature in Region 1 or Region 2.
40644080 if ((p < Pcrit) && Clip) { // If below Pcrit (where Tsat is available),
4065- double Tsat = Tsat97 (p); // Only calculate Tsat ± eps once and
4081+ double Tsat = Tsat97 (p); // Only calculate Tsat ± eps once and
40664082 tmin = Tsat + eps; // set tmin just above and
40674083 tmax = Tsat - eps; // tmax just below saturation.
40684084 }
@@ -4385,7 +4401,7 @@ namespace IF97
43854401 return RegionOutput ( IF97_HMASS,RegionOutputBackward (Pmax,s,IF97_SMASS,false ,NONE),Pmax, NONE);
43864402 else {
43874403 // Determining H(s) along Tmax is difficult because there is no direct p(T,s) formulation.
4388- // This linear combination fit h(s)=a*ln(s)+b/s+c/s²+d is not perfect, but it's close
4404+ // This linear combination fit h(s)=a*ln(s)+b/s+c/s²+d is not perfect, but it's close
43894405 // and can serve as a limit along that Tmax boundary. Coefficients in HTmaxdata above.
43904406 // There is a better way to do this using Newton-Raphson on Tmax = T(p,s), but it is iterative and slow.
43914407 double ETA = Hmax_n[0 ]*log (sigma) + Hmax_n[1 ]/sigma + Hmax_n[2 ]/powi (sigma,2 ) +Hmax_n[3 ];
@@ -4540,14 +4556,14 @@ namespace IF97
45404556 inline double cvmass_Tp (double T, double p){ return RegionOutput ( IF97_CVMASS, T, p, NONE); };
45414557 // / Get the speed of sound [m/s] as a function of T [K] and p [Pa]
45424558 inline double speed_sound_Tp (double T, double p){ return RegionOutput ( IF97_W, T, p, NONE); };
4543- // / Get the [d(rho)/d(p)]T [kg/m³/Pa] as a function of T [K] and p [Pa]
4559+ // / Get the [d(rho)/d(p)]T [kg/m³/Pa] as a function of T [K] and p [Pa]
45444560 inline double drhodp_Tp (double T, double p){ return RegionOutput ( IF97_DRHODP, T, p, NONE); };
45454561
45464562 // ******************************************************************************** //
45474563 // Transport Properties //
45484564 // ******************************************************************************** //
45494565
4550- // / Get the viscosity [Pa-s] as a function of T [K] and Rho [kg/m³]
4566+ // / Get the viscosity [Pa-s] as a function of T [K] and Rho [kg/m³]
45514567 // / Used for function verification only
45524568 inline double visc_TRho (double T, double rho) {
45534569 // Since we have density, we don't need to determine the region for viscosity.
@@ -4557,7 +4573,7 @@ namespace IF97
45574573 // / Get the viscosity [Pa-s] as a function of T [K] and p [Pa]
45584574 inline double visc_Tp (double T, double p) { return RegionOutput (IF97_MU, T, p, NONE); };
45594575
4560- // / Get the thermal conductivity [W/m-K] as a function of T [K], p [Pa], and Rho [kg/m³]
4576+ // / Get the thermal conductivity [W/m-K] as a function of T [K], p [Pa], and Rho [kg/m³]
45614577 // / Used for function verification only
45624578 inline double tcond_TpRho (double T, double p, double rho) {
45634579 // Since we have density, we don't need to determine the region for viscosity.
0 commit comments