From dd71b1ac22192e626da82cd988f9f3a516edde9d Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Mon, 18 Aug 2014 19:26:31 +0200 Subject: [PATCH] Really this time un-specify the phase More logical debug output for invalid phases Signed-off-by: Ian Bell --- src/Backends/Helmholtz/FlashRoutines.cpp | 15 +++++++++++---- .../Helmholtz/HelmholtzEOSMixtureBackend.cpp | 12 ++++++------ .../Helmholtz/HelmholtzEOSMixtureBackend.h | 5 +++++ 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/Backends/Helmholtz/FlashRoutines.cpp b/src/Backends/Helmholtz/FlashRoutines.cpp index 94f2d649..e487b610 100644 --- a/src/Backends/Helmholtz/FlashRoutines.cpp +++ b/src/Backends/Helmholtz/FlashRoutines.cpp @@ -563,10 +563,17 @@ void FlashRoutines::HSU_P_flash_singlephase_Brent(HelmholtzEOSMixtureBackend &HE solver_resid resid(&HEOS, HEOS._p, value, other); std::string errstr; - double T = Brent(resid, Tmin, Tmax, DBL_EPSILON, 1e-12, 100, errstr); - - // Un-impose the phase of the fluid - HEOS.specify_phase(iphase_not_imposed); + try{ + double T = Brent(resid, Tmin, Tmax, DBL_EPSILON, 1e-12, 100, errstr); + // Un-specify the phase of the fluid + HEOS.unspecify_phase(); + } + catch(std::exception &e){ + // Un-specify the phase of the fluid + HEOS.unspecify_phase(); + throw; + } + int rr = 4; } diff --git a/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp b/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp index 69a63001..1074b291 100644 --- a/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp +++ b/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp @@ -590,7 +590,7 @@ void HelmholtzEOSMixtureBackend::mass_to_molar_inputs(long &input_pair, double & } void HelmholtzEOSMixtureBackend::update(long input_pair, double value1, double value2 ) { - if (get_debug_level() > 0){std::cout << format("%s (%d): update called with (%d: (%s), %g, %g)",__FILE__,__LINE__, input_pair, get_input_pair_short_desc(input_pair).c_str(), value1, value2) << std::endl;} + if (get_debug_level() > 10){std::cout << format("%s (%d): update called with (%d: (%s), %g, %g)",__FILE__,__LINE__, input_pair, get_input_pair_short_desc(input_pair).c_str(), value1, value2) << std::endl;} clear(); @@ -1688,7 +1688,7 @@ long double HelmholtzEOSMixtureBackend::calc_hmolar(void) return static_cast(_hmolar); } else{ - throw ValueError(format("phase is invalid")); + throw ValueError(format("phase is invalid in calc_hmolar")); } } long double HelmholtzEOSMixtureBackend::calc_smolar_nocache(long double T, long double rhomolar) @@ -1734,7 +1734,7 @@ long double HelmholtzEOSMixtureBackend::calc_smolar(void) return static_cast(_smolar); } else{ - throw ValueError(format("phase is invalid")); + throw ValueError(format("phase is invalid in calc_smolar")); } } long double HelmholtzEOSMixtureBackend::calc_umolar_nocache(long double T, long double rhomolar) @@ -1775,7 +1775,7 @@ long double HelmholtzEOSMixtureBackend::calc_umolar(void) return static_cast(_umolar); } else{ - throw ValueError(format("phase is invalid")); + throw ValueError(format("phase is invalid in calc_umolar")); } } long double HelmholtzEOSMixtureBackend::calc_cvmolar(void) @@ -1865,13 +1865,13 @@ long double HelmholtzEOSMixtureBackend::calc_gibbsmolar(void) long double dar_dDelta = dalphar_dDelta(); long double R_u = gas_constant(); - // Get molar entropy + // Get molar gibbs function _gibbsmolar = R_u*_T*(1 + a0 + ar +_delta.pt()*dar_dDelta); return static_cast(_gibbsmolar); } else{ - throw ValueError(format("phase is invalid")); + throw ValueError(format("phase is invalid in calc_gibbsmolar")); } } long double HelmholtzEOSMixtureBackend::calc_fugacity_coefficient(int i) diff --git a/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.h b/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.h index 2ebf6d13..847177f0 100644 --- a/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.h +++ b/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.h @@ -74,6 +74,11 @@ public: @param phase_index The index from CoolProp::phases */ void specify_phase(phases phase_index){imposed_phase_index = phase_index; _phase = phase_index;}; + + /** + \brief Unspecify the phase - the phase is no longer imposed, different solvers can do as they like + */ + void unspecify_phase(){imposed_phase_index = iphase_not_imposed;}; void set_reducing_function(); void set_excess_term();