diff --git a/include/cantera/thermo/PureFluidPhase.h b/include/cantera/thermo/PureFluidPhase.h index 1cfe75204..62a99b6e4 100644 --- a/include/cantera/thermo/PureFluidPhase.h +++ b/include/cantera/thermo/PureFluidPhase.h @@ -553,15 +553,6 @@ protected: //! Sets the state using a TPX::TV call void setTPXState() const; - //! Carry out a internal check on tpx, it may have thrown an error. - /*! - * @param v Defaults to zero - */ - void check(doublereal v = 0.0) const; - - //! Report errors in the TPX level - void reportTPXError() const; - private: //! Pointer to the underlying tpx object Substance that does the work diff --git a/include/cantera/tpx/Sub.h b/include/cantera/tpx/Sub.h index 630ae2d28..ef36229cc 100644 --- a/include/cantera/tpx/Sub.h +++ b/include/cantera/tpx/Sub.h @@ -19,22 +19,18 @@ #ifndef TPX_SUB_H #define TPX_SUB_H +#include "cantera/base/ctexceptions.h" + #include #include namespace tpx { -class TPX_Error +class TPX_Error : public Cantera::CanteraError { public: - TPX_Error(std::string p, std::string e) { - ErrorMessage = e; - ErrorProcedure = p; - } - virtual ~TPX_Error() {} - static std::string ErrorMessage; - static std::string ErrorProcedure; + TPX_Error(std::string p, std::string e) : CanteraError(p, e) { } }; @@ -50,14 +46,6 @@ const int VT = -12, PH = -34, PS = -54, VP = -42, PT = -14, VU = -62, TS = -51, VS = -52, PU = -64, HV = -23, HT = -13, HS = -53, XP = -47, XT = -17; -const int NoConverge = -900; -const int GenError = -901; -const int InvalidInput = -902; -const int TempError = -800; -const int PresError = -801; -const int CKError = -802; - - const int Pgiven = 0, Tgiven = 1; const int EvalH = 3; @@ -82,8 +70,6 @@ const int EvalRgas = 19; const double Undef = 999.1234; -std::string errorMsg(int flag); - class Substance { public: @@ -205,17 +191,11 @@ public: void Set(int XY, double x0, double y0); void Set_meta(double phase, double pp); - int Error() { - return Err; - } - - protected: double T, Rho; double Tslast, Rhf, Rhv; double Pst; - int Err; double m_energy_offset; double m_entropy_offset; std::string m_name; @@ -237,17 +217,6 @@ protected: int Lever(int itp, double sat, double val, int ifunc); void update_sat(); - void set_Err(int ErrFlag) { - if (!Err) { - Err = ErrFlag; - //throw TPX_Error(""errorMsg(Err)); - } - } - void clear_Err() { - Err = 0; - } - - private: void set_Rho(double r0); void set_T(double t0); @@ -265,9 +234,6 @@ private: double v_here, P_here; }; -void Error(char* message, int flag, double val=Undef); -void Mess(char* message); - } diff --git a/src/thermo/PureFluidPhase.cpp b/src/thermo/PureFluidPhase.cpp index c6e2c2d3a..3be6435b9 100644 --- a/src/thermo/PureFluidPhase.cpp +++ b/src/thermo/PureFluidPhase.cpp @@ -134,63 +134,49 @@ doublereal PureFluidPhase:: enthalpy_mole() const { setTPXState(); - doublereal h = m_sub->h() * m_mw; - check(h); - return h; + return m_sub->h() * m_mw; } doublereal PureFluidPhase:: intEnergy_mole() const { setTPXState(); - doublereal u = m_sub->u() * m_mw; - check(u); - return u; + return m_sub->u() * m_mw; } doublereal PureFluidPhase:: entropy_mole() const { setTPXState(); - doublereal s = m_sub->s() * m_mw; - check(s); - return s; + return m_sub->s() * m_mw; } doublereal PureFluidPhase:: gibbs_mole() const { setTPXState(); - doublereal g = m_sub->g() * m_mw; - check(g); - return g; + return m_sub->g() * m_mw; } doublereal PureFluidPhase:: cp_mole() const { setTPXState(); - doublereal cp = m_sub->cp() * m_mw; - check(cp); - return cp; + return m_sub->cp() * m_mw; } doublereal PureFluidPhase:: cv_mole() const { setTPXState(); - doublereal cv = m_sub->cv() * m_mw; - check(cv); - return cv; + return m_sub->cv() * m_mw; } doublereal PureFluidPhase:: pressure() const { setTPXState(); - doublereal p = m_sub->P(); - check(p); - return p; + return m_sub->P(); } //==================================================================================================================== void PureFluidPhase:: @@ -198,16 +184,11 @@ setPressure(doublereal p) { Set(tpx::TP, temperature(), p); setDensity(1.0/m_sub->v()); - check(); } //==================================================================================================================== void PureFluidPhase::Set(int n, double x, double y) const { - try { - m_sub->Set(n, x, y); - } catch (tpx::TPX_Error) { - reportTPXError(); - } + m_sub->Set(n, x, y); } //==================================================================================================================== void PureFluidPhase::setTPXState() const @@ -215,21 +196,6 @@ void PureFluidPhase::setTPXState() const Set(tpx::TV, temperature(), 1.0/density()); } //==================================================================================================================== -void PureFluidPhase::check(doublereal v) const -{ - if (m_sub->Error() || v == tpx::Undef) { - throw CanteraError("PureFluidPhase",string(tpx::errorMsg( - m_sub->Error()))); - } -} -//==================================================================================================================== -void PureFluidPhase::reportTPXError() const -{ - string msg = tpx::TPX_Error::ErrorMessage; - string proc = "tpx::"+tpx::TPX_Error::ErrorProcedure; - throw CanteraError(proc,msg); -} -//==================================================================================================================== doublereal PureFluidPhase::isothermalCompressibility() const { @@ -468,13 +434,8 @@ doublereal PureFluidPhase::critDensity() const /// saturation temperature doublereal PureFluidPhase::satTemperature(doublereal p) const { - try { - doublereal ts = m_sub->Tsat(p); - return ts; - } catch (tpx::TPX_Error) { - reportTPXError(); - return -1.0; - } + doublereal ts = m_sub->Tsat(p); + return ts; } //==================================================================================================================== void PureFluidPhase::setState_HP(doublereal h, doublereal p, @@ -482,7 +443,6 @@ void PureFluidPhase::setState_HP(doublereal h, doublereal p, { Set(tpx::HP, h, p); setState_TR(m_sub->Temp(), 1.0/m_sub->v()); - check(); } //==================================================================================================================== void PureFluidPhase::setState_UV(doublereal u, doublereal v, @@ -490,7 +450,6 @@ void PureFluidPhase::setState_UV(doublereal u, doublereal v, { Set(tpx::UV, u, v); setState_TR(m_sub->Temp(), 1.0/m_sub->v()); - check(); } //==================================================================================================================== void PureFluidPhase::setState_SV(doublereal s, doublereal v, @@ -498,7 +457,6 @@ void PureFluidPhase::setState_SV(doublereal s, doublereal v, { Set(tpx::SV, s, v); setState_TR(m_sub->Temp(), 1.0/m_sub->v()); - check(); } //==================================================================================================================== void PureFluidPhase::setState_SP(doublereal s, doublereal p, @@ -506,29 +464,21 @@ void PureFluidPhase::setState_SP(doublereal s, doublereal p, { Set(tpx::SP, s, p); setState_TR(m_sub->Temp(), 1.0/m_sub->v()); - check(); } //==================================================================================================================== // saturation pressure doublereal PureFluidPhase::satPressure(doublereal t) const { doublereal vsv = m_sub->v(); - try { - Set(tpx::TV,t,vsv); - doublereal ps = m_sub->Ps(); - return ps; - } catch (tpx::TPX_Error) { - reportTPXError(); - return -1.0; - } + Set(tpx::TV,t,vsv); + doublereal ps = m_sub->Ps(); + return ps; } //==================================================================================================================== doublereal PureFluidPhase::vaporFraction() const { setTPXState(); - doublereal x = m_sub->x(); - check(x); - return x; + return m_sub->x(); } //==================================================================================================================== void PureFluidPhase::setState_Tsat(doublereal t, doublereal x) @@ -537,7 +487,6 @@ void PureFluidPhase::setState_Tsat(doublereal t, doublereal x) setTPXState(); Set(tpx::TX, t, x); setDensity(1.0/m_sub->v()); - check(); } //==================================================================================================================== void PureFluidPhase::setState_Psat(doublereal p, doublereal x) @@ -546,7 +495,6 @@ void PureFluidPhase::setState_Psat(doublereal p, doublereal x) Set(tpx::PX, p, x); setTemperature(m_sub->Temp()); setDensity(1.0/m_sub->v()); - check(); } //==================================================================================================================== diff --git a/src/tpx/CarbonDioxide.cpp b/src/tpx/CarbonDioxide.cpp index 2ceecb6e8..2d5c3e173 100644 --- a/src/tpx/CarbonDioxide.cpp +++ b/src/tpx/CarbonDioxide.cpp @@ -10,6 +10,9 @@ #include "CarbonDioxide.h" #include #include +#include "cantera/base/stringUtils.h" + +using namespace Cantera; namespace tpx { @@ -320,8 +323,8 @@ double CarbonDioxide::Psat() double log, sum=0,P; if ((T < Tmn) || (T > Tc)) { - std::cout << " error in Psat " << TempError << std::endl; - set_Err(TempError); // Error("CarbonDioxide::Psat",TempError,T); + throw TPX_Error("CarbonDixoide::Psat", + "Temperature out of range. T = " + fp2str(T)); } for (int i=1; i<=8; i++) { sum += F[i-1] * pow((T/Tp -1),double(i-1)); @@ -343,8 +346,8 @@ double CarbonDioxide::ldens() { double xx=1-(T/Tc), sum=0; if ((T < Tmn) || (T > Tc)) { - std::cout << " error in ldens " << TempError << std::endl; - set_Err(TempError); + throw TPX_Error("CarbonDixoide::ldens", + "Temperature out of range. T = " + fp2str(T)); } for (int i=1; i<=6; i++) { sum+=D[i-1]*pow(xx,double(i-1)/3.0); diff --git a/src/tpx/HFC134a.cpp b/src/tpx/HFC134a.cpp index bf9f542e4..38db2834a 100644 --- a/src/tpx/HFC134a.cpp +++ b/src/tpx/HFC134a.cpp @@ -2,6 +2,9 @@ #include "HFC134a.h" #include +#include "cantera/base/stringUtils.h" + +using namespace Cantera; namespace tpx { @@ -153,7 +156,8 @@ double HFC134a::Pp() double HFC134a::Psat() { if ((T < Tmn) || (T > Tc)) { - set_Err(TempError); + throw TPX_Error("HFC134a::Psat", + "Temperature out of range. T = " + fp2str(T)); } double x1 = T/Tc; double x2 = 1.0 - x1; @@ -178,7 +182,8 @@ double HFC134a::Psat() double HFC134a::ldens() { if ((T < Tmn) || (T > Tc)) { - set_Err(TempError); + throw TPX_Error("HFC134a::ldens", + "Temperature out of range. T = " + fp2str(T)); } double x1 = T/Tc; double x2 = 1.0 - x1; diff --git a/src/tpx/Heptane.cpp b/src/tpx/Heptane.cpp index e977725e3..573287d70 100644 --- a/src/tpx/Heptane.cpp +++ b/src/tpx/Heptane.cpp @@ -8,9 +8,12 @@ */ #include "Heptane.h" +#include "cantera/base/stringUtils.h" #include #include +using namespace Cantera; + namespace tpx { @@ -277,8 +280,8 @@ double Heptane::Psat() { double log, sum=0,P; if ((T < Tmn) || (T > Tc)) { - - set_Err(TempError); // Error("Heptane::Psat",TempError,T); + throw TPX_Error("Heptane::Psat", + "Temperature out of range. T = " + fp2str(T)); } for (int i=1; i<=8; i++) { sum += F[i-1] * pow((T/Tp -1),double(i-1)); @@ -299,7 +302,8 @@ double Heptane::ldens() { double xx=1-(T/Tc), sum=0; if ((T < Tmn) || (T > Tc)) { - set_Err(TempError); + throw TPX_Error("Heptane::ldens", + "Temperature out of range. T = " + fp2str(T)); } for (int i=1; i<=6; i++) { sum+=D[i-1]*pow(xx,double(i-1)/3.0); diff --git a/src/tpx/Hydrogen.cpp b/src/tpx/Hydrogen.cpp index 849918cae..56f484d8f 100644 --- a/src/tpx/Hydrogen.cpp +++ b/src/tpx/Hydrogen.cpp @@ -2,6 +2,9 @@ #include "Hydrogen.h" #include +#include "cantera/base/stringUtils.h" + +using namespace Cantera; namespace tpx { @@ -221,7 +224,8 @@ double hydrogen::Pp() double hydrogen::ldens() { if ((T < Tmn) || (T > Tc)) { - set_Err(TempError); + throw TPX_Error("hydrogen::ldens", + "Temperature out of range. T = " + fp2str(T)); } double x=1-T/Tc; double sum, term; @@ -240,7 +244,8 @@ double hydrogen::Psat() double x = (1.0 - Tt/T)/(1.0 - Tt/Tc); double result; if ((T < Tmn) || (T > Tc)) { - set_Err(TempError); + throw TPX_Error("hydrogen::Psat", + "Temperature out of range. T = " + fp2str(T)); } result = Fhydro[0]*x + Fhydro[1]*x*x + Fhydro[2]*x*x*x + Fhydro[3]*x*pow(1-x, alpha); diff --git a/src/tpx/Methane.cpp b/src/tpx/Methane.cpp index 3ffd51f08..423339612 100644 --- a/src/tpx/Methane.cpp +++ b/src/tpx/Methane.cpp @@ -1,9 +1,12 @@ // Methane #include "Methane.h" +#include "cantera/base/stringUtils.h" #include #include + using namespace std; +using namespace Cantera; namespace tpx { @@ -193,7 +196,8 @@ double methane::Psat() double x = (1.0 - Tt/T)/(1.0 - Tt/Tc); double result; if ((T < Tmn) || (T > Tc)) { - set_Err(TempError); + throw TPX_Error("methane::Psat", + "Temperature out of range. T = " + fp2str(T)); } result = Fmeth[0]*x + Fmeth[1]*x*x + Fmeth[2]*x*x*x + Fmeth[3]*x*pow(1-x, alpha); @@ -208,7 +212,8 @@ double methane::ldens() double sum; double w; if ((T < Tmn) || (T > Tc)) { - set_Err(TempError); + throw TPX_Error("methane::ldens", + "Temperature out of range. T = " + fp2str(T)); } w = (Tc - T)/(Tc - Tt); sum = Dmeth[0]*(1.0 - pow(w, 2.0/3.0)) + Dmeth[1]*(1.0 - pow(w, 4.0/3.0)) diff --git a/src/tpx/Nitrogen.cpp b/src/tpx/Nitrogen.cpp index 23130d71d..931e34c90 100644 --- a/src/tpx/Nitrogen.cpp +++ b/src/tpx/Nitrogen.cpp @@ -1,9 +1,11 @@ // Nitrogen #include "Nitrogen.h" +#include "cantera/base/stringUtils.h" #include #include using namespace std; +using namespace Cantera; namespace tpx { @@ -209,7 +211,8 @@ double nitrogen::Psat() double lnp; int i; if ((T < Tmn) || (T > Tc)) { - set_Err(TempError); + throw TPX_Error("nitrogen::Psat", + "Temperature out of range. T = " + fp2str(T)); } for (i=0, lnp=0; i<=7; i++) { if (i==3) { @@ -227,7 +230,8 @@ double nitrogen::ldens() { double xx=1-T/Tc, sum=0; if ((T < Tmn) || (T > Tc)) { - set_Err(TempError); + throw TPX_Error("nitrogen::ldens", + "Temperature out of range. T = " + fp2str(T)); } for (int i=0; i<=5; i++) { sum+=Dnn[i]*pow(xx,double(i)/3.0); diff --git a/src/tpx/Oxygen.cpp b/src/tpx/Oxygen.cpp index af6970557..d9433ae8e 100644 --- a/src/tpx/Oxygen.cpp +++ b/src/tpx/Oxygen.cpp @@ -1,8 +1,11 @@ // Oxygen #include "Oxygen.h" +#include "cantera/base/stringUtils.h" #include +using namespace Cantera; + namespace tpx { @@ -198,7 +201,8 @@ double oxygen::Psat() double lnp; int i; if ((T < Tmn) || (T > Tc)) { - set_Err(TempError); + throw TPX_Error("oxygen::Psat", + "Temperature out of range. T = " + fp2str(T)); } for (i=0, lnp=0; i<=7; i++) { if (i==3) { @@ -216,7 +220,8 @@ double oxygen::ldens() { double xx=1-T/Tc, sum=0; if ((T < Tmn) || (T > Tc)) { - set_Err(TempError); + throw TPX_Error("oxygen::ldens", + "Temperature out of range. T = " + fp2str(T)); } for (int i=0; i<=5; i++) { sum+=Doxy[i]*pow(xx,double(i)/3.0); diff --git a/src/tpx/Sub.cpp b/src/tpx/Sub.cpp index 4772d7625..db1c977bd 100644 --- a/src/tpx/Sub.cpp +++ b/src/tpx/Sub.cpp @@ -3,51 +3,16 @@ * D. Goodwin, Caltech Nov. 1996 */ #include "cantera/tpx/Sub.h" +#include "cantera/base/stringUtils.h" #include #include #include using std::string; +using namespace Cantera; namespace tpx { - -static string fp2str(double x, string fmt="%g") -{ - char buf[30]; - sprintf(buf, fmt.c_str(), x); - return string(buf); -} - -/* - static string int2str(int n, string fmt="%d") { - char buf[30]; - sprintf(buf, fmt.c_str(), n); - return string(buf); - } -*/ - -string TPX_Error::ErrorMessage = ""; -string TPX_Error::ErrorProcedure = ""; - -string errorMsg(int flag) -{ - switch (flag) { - case NoConverge: - return "no convergence"; - case GenError: - return "general error"; - case InvalidInput: - return "invalid input"; - case TempError: - return "temperature error"; - case PresError: - return "pressure error"; - default: - return "(unknown error)"; - } -} - //-------------- Public Member Functions -------------- Substance::Substance() : @@ -57,7 +22,6 @@ Substance::Substance() : Rhf(Undef), Rhv(Undef), Pst(Undef), - Err(0), m_energy_offset(0.0), m_entropy_offset(0.0), kbr(0) @@ -69,8 +33,7 @@ Substance::Substance() : /// computed directly from the underlying eos. double Substance::P() { - double ppp = (TwoPhase() ? Ps() : Pp()); - return (Err ? Undef : ppp); + return TwoPhase() ? Ps() : Pp(); } const double DeltaT = 0.000001; @@ -85,7 +48,7 @@ double Substance::dPsdT() set_T(T + DeltaT); dpdt = (Ps() - ps1)/DeltaT; set_T(tsave); - return (Err ? Undef : dpdt); + return dpdt; } /// true if a liquid/vapor mixture, false otherwise @@ -103,21 +66,20 @@ int Substance::TwoPhase() /// returned if v > Vcrit. double Substance::x() { - double xx, vv, vl; + double vv, vl; if (T >= Tcrit()) { return (1.0/Rho < Vcrit() ? 0.0 : 1.0); } else { update_sat(); if (Rho <= Rhv) { - xx = 1.0; + return 1.0; } else if (Rho >= Rhf) { - xx = 0.0; + return 0.0; } else { vv = 1.0/Rhv; vl = 1.0/Rhf; - xx = (1.0/Rho - vl)/(vv - vl); + return (1.0/Rho - vl)/(vv - vl); } - return (Err ? Undef : xx); } } @@ -126,10 +88,8 @@ double Substance::Tsat(double p) { double Tsave, p_here, dp, dt, dpdt, dta, dtm, tsat; - if (Err || (p <= 0.0) || (p > Pcrit())) { - throw TPX_Error("Substance::Tsat","illegal pressure value"); - set_Err(PresError); - return Undef; + if (p <= 0.0 || p > Pcrit()) { + throw TPX_Error("Substance::Tsat", "illegal pressure value"); } int LoopCount = 0; double tol = 1.e-6*p; @@ -141,9 +101,6 @@ double Substance::Tsat(double p) T = 0.5*(Tcrit() - Tmin()); } do { - if (Err) { - break; - } if (T > Tcrit()) { T = Tcrit() - 0.001; } @@ -163,13 +120,12 @@ double Substance::Tsat(double p) LoopCount++; if (LoopCount > 100) { T = Tsave; - set_Err(NoConverge); - return Undef; + throw TPX_Error("Substance::Tsat", "No convergence"); } } while (fabs(dp) > tol); tsat = T; T = Tsave; - return (Err ? Undef : tsat); + return tsat; } @@ -187,8 +143,6 @@ void Substance::Set(int XY, double x0, double y0) { double temp; - clear_Err(); // clear error flag - /* if inverted (PT) switch order and change sign of XY (TP = -PT) */ if (XY < 0) { double tmp = x0; @@ -274,34 +228,35 @@ void Substance::Set(int XY, double x0, double y0) case PX: temp = Tsat(x0); - if ((y0 >= 0.0) && (y0 <= 1.0) && (temp < Tcrit())) { + if (y0 > 1.0 || y0 < 0.0) { + throw TPX_Error("Substance::Set", + "Invalid vapor fraction, " + fp2str(y0)); + } else if (temp >= Tcrit()) { + throw TPX_Error("Substance::Set", + "Can't set vapor fraction above the critical point"); + } else { set_T(temp); update_sat(); Rho = 1.0/((1.0 - y0)/Rhf + y0/Rhv); - } else { - set_Err(InvalidInput); } break; case TX: - if ((y0 >= 0.0) && (y0 <= 1.0) && (x0 < Tcrit())) { + if (y0 > 1.0 || y0 < 0.0) { + throw TPX_Error("Substance::Set", + "Invalid vapor fraction, " + fp2str(y0)); + } else if (x0 >= Tcrit()) { + throw TPX_Error("Substance::Set", + "Can't set vapor fraction above the critical point"); + } else { set_T(x0); update_sat(); Rho = 1.0/((1.0 - y0)/Rhf + y0/Rhv); - } else { - set_Err(InvalidInput); } break; default: - set_Err(InvalidInput); - } - if (Err) { - T = Undef; - Rho = Undef; - Tslast = Undef; - Rhf = Undef; - Rhv = Undef; + throw TPX_Error("Substance::Set", "Invalid input."); } } @@ -312,7 +267,7 @@ void Substance::set_Rho(double r0) if (r0 > 0.0) { Rho = r0; } else { - set_Err(InvalidInput); + throw TPX_Error("Substance::set_Rho", "Invalid density: " + fp2str(r0)); } } @@ -321,9 +276,7 @@ void Substance::set_T(double t0) if ((t0 >= Tmin()) && (t0 <= Tmax())) { T = t0; } else { - throw TPX_Error("Substance::set_T", - "illegal temperature value "+fp2str(t0)); - set_Err(TempError); + throw TPX_Error("Substance::set_T", "illegal temperature: " + fp2str(t0)); } } @@ -334,7 +287,6 @@ void Substance::set_v(double v0) } else { throw TPX_Error("Substance::set_v", "negative specific volume: "+fp2str(v0)); - set_Err(InvalidInput); } } @@ -343,8 +295,6 @@ double Substance::Ps() if (T < Tmin() || T > Tcrit()) { throw TPX_Error("Substance::Ps", "illegal temperature value "+fp2str(T)); - set_Err(TempError); - return Undef; } update_sat(); return Pst; @@ -427,12 +377,7 @@ void Substance::update_sat() } if (i >= 20) { - Pst = Undef; - Rhv = Undef; - Rhf = Undef; - Tslast = Undef; throw TPX_Error("substance::update_sat","no convergence"); - set_Err(NoConverge); } else { Pst = pp; Tslast = T; @@ -455,7 +400,7 @@ double Substance::vprop(int ijob) case EvalP: return Pp(); default: - return Undef; + throw TPX_Error("Substance::vprop", "invalid job index"); } } @@ -479,25 +424,22 @@ int Substance::Lever(int itp, double sat, double val, int ifunc) return 0; } psat = sat; - T = Tsat(psat); - if (T == Undef) { - Err = 0; + try { + T = Tsat(psat); + } catch (TPX_Error&) { + // Failure to converge here is not an error T = Tsave; Rho = Rhosave; return 0; } } else { throw TPX_Error("Substance::Lever","general error"); - set_Err(GenError); - return GenError; } Set(TX, T, Vapor); Valg = vprop(ifunc); Set(TX, T, Liquid); Valf = vprop(ifunc); - if (Err) { - return Err; - } else if ((val >= Valf) && (val <= Valg)) { + if (val >= Valf && val <= Valg) { xx = (val - Valf)/(Valg - Valf); vv = (1.0 - xx)/Rhf + xx/Rhv; set_v(vv); @@ -525,10 +467,6 @@ void Substance::set_xy(int ifx, int ify, double X, double Y, double v_save = 1.0/Rho; double t_save = T; - if (Err) { - return; - } - if ((T == Undef) && (Rho == Undef)) { // new object, try to pick Set(TV,Tcrit()*1.1,Vcrit()*1.1); // "reasonable" starting point t_here = T; @@ -545,12 +483,8 @@ void Substance::set_xy(int ifx, int ify, double X, double Y, Xa = fabs(X); Ya = fabs(Y); - // loop do { - if (Err) { - break; - } x_here = prop(ifx); y_here = prop(ify); err_x = fabs(X - x_here); @@ -616,8 +550,6 @@ void Substance::set_xy(int ifx, int ify, double X, double Y, LoopCount++; if (LoopCount > 200) { throw TPX_Error("Substance::set_xy","no convergence"); - set_Err(NoConverge); - break; } } while (1); } @@ -713,7 +645,6 @@ void Substance::set_TPp(double Temp, double Pressure) } if (Vmin >= Vmax) { throw TPX_Error("Substance::set_TPp","Vmin >= Vmax"); - set_Err(GenError); } else if ((Vmin > 0.0) && (Vmax < Big)) { kbr = 1; } @@ -746,8 +677,6 @@ void Substance::set_TPp(double Temp, double Pressure) v_here += dv; if (dv == 0.0) { throw TPX_Error("Substance::set_TPp","dv = 0 and no convergence"); - set_Err(NoConverge); - return; } Set(TV, Temp, v_here); LoopCount++; @@ -756,8 +685,6 @@ void Substance::set_TPp(double Temp, double Pressure) throw TPX_Error("Substance::set_TPp",string("no convergence for ") +"P* = "+fp2str(Pressure/Pcrit())+". V* = " +fp2str(v_save/Vcrit())); - set_Err(NoConverge); - return; } } Set(TV, Temp,v_here); diff --git a/src/tpx/Water.cpp b/src/tpx/Water.cpp index 7e33b1e62..8a8c34a7e 100644 --- a/src/tpx/Water.cpp +++ b/src/tpx/Water.cpp @@ -1,9 +1,12 @@ // water #include "Water.h" +#include "cantera/base/stringUtils.h" #include #include +using namespace Cantera; + namespace tpx { @@ -159,7 +162,8 @@ double water::Psat() { double log, sum=0,P; if ((T < Tmn) || (T > Tc)) { - set_Err(TempError); // Error("water::Psat",TempError,T); + throw TPX_Error("water::Psat", + "Temperature out of range. T = " + fp2str(T)); } for (int i=1; i<=8; i++) { sum += F[i-1]*pow(aww*(T-Tp),double(i-1)); // DGG mod @@ -189,7 +193,8 @@ double water::ldens() double sum=0; int i; if ((T < Tmn) || (T >= Tc)) { - set_Err(TempError); // Error("water::ldens",TempError,T); + throw TPX_Error("water::ldens", + "Temperature out of range. T = " + fp2str(T)); } for (i=0; i<8; i++) { sum+=D[i]*pow(1.0 - T/Tc, double(i+1)/3.0);