From f1e807d314de55a213f096685d143da9fe4d833e Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Mon, 27 Feb 2012 18:11:28 +0000 Subject: [PATCH] Moved global variables from tpx namespace into class Substance This fixes failures in the pureFluid test on OSX with certain compilier optimizations enabled. --- include/cantera/tpx/Sub.h | 19 +++++++--------- src/tpx/Sub.cpp | 48 +++++++++++++++++++++++---------------- 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/include/cantera/tpx/Sub.h b/include/cantera/tpx/Sub.h index 9d0359365..87d8a6a2d 100644 --- a/include/cantera/tpx/Sub.h +++ b/include/cantera/tpx/Sub.h @@ -87,17 +87,8 @@ std::string errorMsg(int flag); class Substance { public: - Substance() { - T = Undef; - Rho = Undef; - Tslast = Undef; - Rhf = Undef; - Rhv = Undef; - Pst = Undef; - Err = 0; - m_energy_offset = 0.0; - m_entropy_offset = 0.0; - } + Substance(); + virtual ~Substance() {} void setStdState(double h0 = 0.0, double s0 = 0.0, @@ -266,6 +257,12 @@ private: double vprop(int ijob); void set_xy(int if1, int if2, double X, double Y, double atx, double aty, double rtx, double rty); + + int kbr; + double Vmin, Vmax; + double Pmin, Pmax; + double dvbf, dv; + double v_here, P_here; }; void Error(char* message, int flag, double val=Undef); diff --git a/src/tpx/Sub.cpp b/src/tpx/Sub.cpp index 5925eb773..918c99dec 100644 --- a/src/tpx/Sub.cpp +++ b/src/tpx/Sub.cpp @@ -50,6 +50,20 @@ string errorMsg(int flag) //-------------- Public Member Functions -------------- +Substance::Substance() : + T(Undef), + Rho(Undef), + Tslast(Undef), + Rhf(Undef), + Rhv(Undef), + Pst(Undef), + Err(0), + m_energy_offset(0.0), + m_entropy_offset(0.0), + kbr(0) +{ +} + /// Pressure [Pa]. If two phases are present, return the /// saturation pressure; otherwise return the pressure /// computed directly from the underlying eos. @@ -161,13 +175,13 @@ double Substance::Tsat(double p) // absolute tolerances -double TolAbsH = 0.0001; // J/kg -double TolAbsU = 0.0001; -double TolAbsS = 1.e-7; -double TolAbsP = 0.000; // Pa -double TolAbsV = 1.e-8; -double TolAbsT = 1.e-3; -double TolRel = 3.e-8; +static const double TolAbsH = 0.0001; // J/kg +static const double TolAbsU = 0.0001; +static const double TolAbsS = 1.e-7; +static const double TolAbsP = 0.000; // Pa +static const double TolAbsV = 1.e-8; +static const double TolAbsT = 1.e-3; +static const double TolRel = 3.e-8; void Substance::Set(int XY, double x0, double y0) { @@ -620,12 +634,8 @@ double Substance::prop(int ijob) } } -int kbr; -const double ErrP = 1.e-7; -const double Big = 1.e30; - -double Vmin, Vmax, Pmin, Pmax, dvs1, dvs2, dpdv, dvbf, dv, dva, dvm, - dt, v_here, P_here, vt; +static const double ErrP = 1.e-7; +static const double Big = 1.e30; void Substance::BracketSlope(double Pressure) { @@ -654,8 +664,8 @@ void Substance::set_TPp(double Temp, double Pressure) Vmax = Big; Pmin = Big; Pmax = 0.0; - dvs1 = 2.0*Vcrit(); - dvs2 = 0.7*Vcrit(); + double dvs1 = 2.0*Vcrit(); + double dvs2 = 0.7*Vcrit(); int LoopCount = 0; double v_save = 1.0/Rho; @@ -673,7 +683,7 @@ void Substance::set_TPp(double Temp, double Pressure) dv *= -1.0; } Set(TV, Temp, v_here+dv); - dpdv = (Pp() - P_here)/dv; + double dpdv = (Pp() - P_here)/dv; if (dpdv > 0.0) { BracketSlope(Pressure); } else { @@ -703,7 +713,7 @@ void Substance::set_TPp(double Temp, double Pressure) } } } - dvm = 0.2*v_here; + double dvm = 0.2*v_here; if (v_here < dvs1) { dvm *= 0.5; } @@ -711,12 +721,12 @@ void Substance::set_TPp(double Temp, double Pressure) dvm *= 0.5; } if (kbr != 0) { - vt = v_here + dv; + double vt = v_here + dv; if ((vt < Vmin) || (vt > Vmax)) { dv = Vmin + (Pressure - Pmin)*(Vmax - Vmin)/(Pmax - Pmin) - v_here; } } - dva = fabs(dv); + double dva = fabs(dv); if (dva > dvm) { dv *= dvm/dva; }