From b99d868f3607378e27c0eaf7430f2764bdf7489e Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Tue, 30 Dec 2014 21:42:57 -0500 Subject: [PATCH] Repaired failing incompressible tests - string parsing had to be repaired Signed-off-by: Ian Bell --- .../Incompressible/IncompressibleBackend.cpp | 112 ++++++++---------- src/CoolProp.cpp | 48 +++++--- 2 files changed, 82 insertions(+), 78 deletions(-) diff --git a/src/Backends/Incompressible/IncompressibleBackend.cpp b/src/Backends/Incompressible/IncompressibleBackend.cpp index c0129e64..338526c0 100644 --- a/src/Backends/Incompressible/IncompressibleBackend.cpp +++ b/src/Backends/Incompressible/IncompressibleBackend.cpp @@ -470,8 +470,6 @@ TEST_CASE("Internal consistency checks and example use cases for the incompressi CAPTURE(res); CHECK( check_abs(val,res,acc) ); } - - } SECTION("Tests for the full implementation using PropsSI") { @@ -490,6 +488,7 @@ TEST_CASE("Internal consistency checks and example use cases for the incompressi expected = 9.6212e+02; std::vector fluid_Melinder(1,fluid); std::vector > IO = CoolProp::PropsSImulti(std::vector(1,"D"),"T",std::vector(1,T),"P",std::vector(1,p),"INCOMP",fluid_Melinder,std::vector(1,x)); + REQUIRE(!IO.empty()); actual = IO[0][0]; { CAPTURE(T); @@ -500,7 +499,7 @@ TEST_CASE("Internal consistency checks and example use cases for the incompressi CHECK( check_abs(expected,actual,acc) ); } // ... as % - actual = CoolProp::PropsSI("D","T",T,"P",p,"INCOMP::"+fluid+format("-%f%s",x*100.0,"%")); + actual = CoolProp::PropsSI("D","T",T,"P",p,"INCOMP::"+fluid+format("-%f%%", x*100.0)); { CAPTURE(T); CAPTURE(p); @@ -525,89 +524,82 @@ TEST_CASE("Internal consistency checks and example use cases for the incompressi CAPTURE(errmsg); CHECK( check_abs(expected,actual,acc) ); } - + } + SECTION("SecCool example") + { + double acc = 0.0001; std::string backend = "INCOMP"; std::vector fluids(1,"ExampleSecCool"); - T = -5 + 273.15; - p = 10e5; - x = 0.4; + double T = -5 + 273.15; + double p = 10e5; + double x = 0.4; std::vector x_vec = std::vector(1,x); std::vector T_vec = std::vector(1,T); std::vector p_vec = std::vector(1,p); // Compare d - expected = 9.4844e+02; - - IO = CoolProp::PropsSImulti(std::vector(1,"D"),"T",T_vec,"P",p_vec,backend,fluids,x_vec); - actual = IO[0][0]; + double dexpected = 9.4844e+02; + std::vector > IO = CoolProp::PropsSImulti(std::vector(1,"D"),"T",T_vec,"P",p_vec,backend,fluids,x_vec); + REQUIRE(!IO.empty()); + double dactual = IO[0][0]; { CAPTURE(T); CAPTURE(p); CAPTURE(x); - CAPTURE(expected); - CAPTURE(actual); + CAPTURE(dexpected); + CAPTURE(dactual); std::string errmsg = CoolProp::get_global_param_string("errstring"); CAPTURE(errmsg); - CHECK( check_abs(expected,actual,acc) ); + CHECK( check_abs(dexpected,dactual,acc) ); } // Compare cp - expected = 3.6304e+03; - actual = CoolProp::PropsSImulti(std::vector(1,"C"),"T",T_vec,"P",p_vec,backend,fluids,x_vec)[0][0]; + double cpexpected = 3.6304e+03; + double cpactual = CoolProp::PropsSImulti(std::vector(1,"C"),"T",T_vec,"P",p_vec,backend,fluids,x_vec)[0][0]; { CAPTURE(T); CAPTURE(p); CAPTURE(x); - CAPTURE(expected); - CAPTURE(actual); + CAPTURE(cpexpected); + CAPTURE(cpactual); std::string errmsg = CoolProp::get_global_param_string("errstring"); CAPTURE(errmsg); - CHECK( check_abs(expected,actual,acc) ); - } - - fluid = std::string("INCOMP::ExamplePure"); - T = +55 + 273.15; - p = 10e5; - - // Compare d - expected = 7.3646e+02; - actual = CoolProp::PropsSI("D","T",T,"P",p,fluid); - { - CAPTURE(T); - CAPTURE(p); - CAPTURE(x); - CAPTURE(expected); - CAPTURE(actual); - std::string errmsg = CoolProp::get_global_param_string("errstring"); - CAPTURE(errmsg); - CHECK( check_abs(expected,actual,acc) ); - } - - // Compare cp - expected = 2.2580e+03; - actual = CoolProp::PropsSI("C","T",T,"P",p,fluid); - { - CAPTURE(T); - CAPTURE(p); - CAPTURE(x); - CAPTURE(expected); - CAPTURE(actual); - std::string errmsg = CoolProp::get_global_param_string("errstring"); - CAPTURE(errmsg); - CHECK( check_abs(expected,actual,acc) ); + CHECK( check_abs(cpexpected,cpactual,acc) ); } } + SECTION("INCOMP::ExamplePure") + { + double acc = 0.0001; + std::string fluid = std::string("INCOMP::ExamplePure"); + double T = +55 + 273.15; + double p = 10e5; - //std::string name("INCOMP::TCO"); - double T = 50 + 273.15; - double p = 10e5; - double x = 0.3; - -// std::cout << CoolProp::PropsSI("D","T",T,"P",p,"INCOMP::TCO",std::vector(1,x)) << std::endl; -// std::cout << CoolProp::PropsSI("D","T",T,"P",p,"INCOMP::LiBr",std::vector(1,x)) << std::endl; -// std::cout << CoolProp::PropsSI("D","T",T,"P",p,"INCOMP::NaK",std::vector(1,x)) << std::endl; - + // Compare d + double dexpected = 7.3646e+02; + double dactual = CoolProp::PropsSI("D","T",T,"P",p,fluid); + { + CAPTURE(T); + CAPTURE(p); + CAPTURE(dexpected); + CAPTURE(dactual); + std::string errmsg = CoolProp::get_global_param_string("errstring"); + CAPTURE(errmsg); + CHECK( check_abs(dexpected,dactual,acc) ); + } + // Compare cp + double cpexpected = 2.2580e+03; + double cpactual = CoolProp::PropsSI("C","T",T,"P",p,fluid); + { + CAPTURE(T); + CAPTURE(p); + CAPTURE(cpexpected); + CAPTURE(cpactual); + std::string errmsg = CoolProp::get_global_param_string("errstring"); + CAPTURE(errmsg); + CHECK( check_abs(cpexpected,cpactual,acc) ); + } + } // SECTION("Tests for the hardcoded fluids") { // diff --git a/src/CoolProp.cpp b/src/CoolProp.cpp index 009f3da0..47860c10 100644 --- a/src/CoolProp.cpp +++ b/src/CoolProp.cpp @@ -213,24 +213,37 @@ void _PropsSI_initialize(const std::string &backend, } } else{ - std::vector fractions(1, 1.0); // Default to one component, unity mole fraction - const std::vector *fractions_ptr; // Pointer to the array to be used; - std::string fluid_string; + std::vector fractions(1, 1.0); // Default to one component, unity fraction + const std::vector *fractions_ptr = NULL; // Pointer to the array to be used; - if (fluid_names.size() == 1){ - // Extract fractions from the string if you can (or need to) - fluid_string = extract_fractions(fluid_names[0], fractions); - // Reset the state - State.reset(AbstractState::factory(backend, fluid_string)); - // Set the pointer - we are going to use the extracted fractions - fractions_ptr = &fractions; - } - else{ - // Set the pointer - we are going to use the supplied fractions + if (fluid_names.size() > 1){ + // Set the pointer - we are going to use the supplied fractions; they must be provided fractions_ptr = &z; // Reset the state State.reset(AbstractState::factory(backend, fluid_names)); } + else if (fluid_names.size() == 1){ + if (has_fractions_in_string(fluid_names[0]) || has_solution_concentration(fluid_names[0])){ + // Extract fractions from the string + std::string fluid_string = extract_fractions(fluid_names[0], fractions); + // Set the pointer - we are going to use the extracted fractions + fractions_ptr = &fractions; + // Reset the state + State.reset(AbstractState::factory(backend, fluid_string)); + } + else{ + if (z.empty()){ + // Set the pointer - we are going to use the default fractions + fractions_ptr = &fractions; + } + else{ + // Set the pointer - we are going to use the provided fractions + fractions_ptr = &z; + } + // Reset the state + State.reset(AbstractState::factory(backend, fluid_names)); + } + } // Set the fraction for the state if (State->using_mole_fractions()){ @@ -243,7 +256,6 @@ void _PropsSI_initialize(const std::string &backend, if (get_debug_level()>50) std::cout << format("%s:%d: _PropsSI, could not set composition to %s, defaulting to mole fraction.\n",__FILE__,__LINE__, vec_to_string(z).c_str()).c_str(); } } - } struct output_parameter{ @@ -365,7 +377,7 @@ std::vector > PropsSImulti(const std::vector &O } catch (std::exception &e){ // Input parameter parsing failed. Stop - throw ValueError(format("Input pair parsing failed for Name1: \"%s\", Name2: \"%s\"; error: %s", Name1.c_str(), Name2.c_str(),e.what())); + throw ValueError(format("Input pair parsing failed for Name1: \"%s\", Name2: \"%s\"; err: %s", Name1.c_str(), Name2.c_str(), e.what())); } try{ @@ -515,10 +527,10 @@ TEST_CASE("Check inputs to PropsSI","[PropsSI]") REQUIRE(IO.empty()); }; SECTION("bad mole fraction length"){ - std::vector p(1, 101325), Q(1, 1.0), z(100, 1.0); + std::vector p(1, 101325), Q(1, 1.0), z(1, 1.0); std::vector > IO; std::vector outputs(1,"T"); - std::vector fluids(1, "Water"); + std::vector fluids(1, "Water&Ethanol"); CHECK_NOTHROW(IO = CoolProp::PropsSImulti(outputs,"P",p,"Q",Q,"HEOS",fluids,z);); std::string errstring = get_global_param_string("errstring"); CAPTURE(errstring); @@ -535,7 +547,7 @@ TEST_CASE("Check inputs to PropsSI","[PropsSI]") REQUIRE(IO.empty()); }; SECTION("bad input pair"){ - std::vector Q(2, 1.0), z(100, 1.0); + std::vector Q(2, 1.0), z(1, 1.0); std::vector > IO; std::vector outputs(1,"Cpmolar"); outputs.push_back("d(Hmolar)/d(T)|P"); std::vector fluids(1, "Water");