From 99da465b06d7f7f2850a203a977f93d2e25fbd71 Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Mon, 18 Aug 2014 18:52:06 +0200 Subject: [PATCH] Unspecify the phase after the HP solver with Brent - test added Signed-off-by: Ian Bell --- src/Backends/Helmholtz/FlashRoutines.cpp | 14 ++++++++--- src/Tests/CoolProp-Tests.cpp | 31 ++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/src/Backends/Helmholtz/FlashRoutines.cpp b/src/Backends/Helmholtz/FlashRoutines.cpp index dfd9f07d..94f2d649 100644 --- a/src/Backends/Helmholtz/FlashRoutines.cpp +++ b/src/Backends/Helmholtz/FlashRoutines.cpp @@ -520,13 +520,16 @@ void FlashRoutines::HSU_P_flash_singlephase_Brent(HelmholtzEOSMixtureBackend &HE int other; int iter; long double r0, r1, T1, T0, pp; - solver_resid(HelmholtzEOSMixtureBackend *HEOS, long double p, long double value, int other) : HEOS(HEOS), p(p), value(value), other(other){iter = 0;}; + solver_resid(HelmholtzEOSMixtureBackend *HEOS, long double p, long double value, int other) : + HEOS(HEOS), p(p), value(value), other(other) + { + iter = 0; + // Specify the state to avoid saturation calls + HEOS->specify_phase(HEOS->phase()); + }; double call(double T){ this->T = T; - - // Specify the state to avoid saturation calls - HEOS->specify_phase(HEOS->phase()); // Run the solver with T,P as inputs; HEOS->update(PT_INPUTS, p, T); @@ -561,6 +564,9 @@ void FlashRoutines::HSU_P_flash_singlephase_Brent(HelmholtzEOSMixtureBackend &HE 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); int rr = 4; } diff --git a/src/Tests/CoolProp-Tests.cpp b/src/Tests/CoolProp-Tests.cpp index a56558b3..59b614b9 100644 --- a/src/Tests/CoolProp-Tests.cpp +++ b/src/Tests/CoolProp-Tests.cpp @@ -793,6 +793,37 @@ TEST_CASE("Tests for solvers in P,Y flash using Water", "[flash],[PH],[PS],[PU]" } } +TEST_CASE("Tests for solvers in P,H flash using Propane", "[flashdups],[flash],[PH],[consistency]") +{ + double hmolar, hmass; + SECTION("5 times PH with HEOS AbstractState yields same results every time","") + { + shared_ptr AS(CoolProp::AbstractState::factory("HEOS", "n-Propane")); + + CHECK_NOTHROW(AS->update(CoolProp::PT_INPUTS, 101325, 300)); + hmolar = AS->hmolar(); + hmass = AS->hmass(); + CHECK_NOTHROW(AS->update(CoolProp::HmassP_INPUTS, hmass, 101325)); + CHECK_NOTHROW(AS->update(CoolProp::HmolarP_INPUTS, hmolar, 101325)); + hmolar = AS->hmolar(); + hmass = AS->hmass(); + CHECK_NOTHROW(AS->update(CoolProp::HmassP_INPUTS, hmass, 101325)); + CHECK_NOTHROW(AS->update(CoolProp::HmolarP_INPUTS, hmolar, 101325)); + hmolar = AS->hmolar(); + hmass = AS->hmass(); + CHECK_NOTHROW(AS->update(CoolProp::HmassP_INPUTS, hmass, 101325)); + CHECK_NOTHROW(AS->update(CoolProp::HmolarP_INPUTS, hmolar, 101325)); + hmolar = AS->hmolar(); + hmass = AS->hmass(); + CHECK_NOTHROW(AS->update(CoolProp::HmassP_INPUTS, hmass, 101325)); + CHECK_NOTHROW(AS->update(CoolProp::HmolarP_INPUTS, hmolar, 101325)); + hmolar = AS->hmolar(); + hmass = AS->hmass(); + CHECK_NOTHROW(AS->update(CoolProp::HmassP_INPUTS, hmass, 101325)); + CHECK_NOTHROW(AS->update(CoolProp::HmolarP_INPUTS, hmolar, 101325)); + } +} + //TEST_CASE("Test that states agree with CoolProp", "[states]") //{ // std::vector fluids = strsplit(CoolProp::get_global_param_string("fluids_list"),',');