From 0cb02a3e2fba0dc237f17db3fd05ab683633b497 Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Fri, 5 Dec 2014 11:24:29 -0500 Subject: [PATCH] Predefined mixtures working in PropsSI now Added Catch test ``` python In [1]: import CoolProp In [2]: CoolProp.CoolProp.PropsSI('D','P',101325,'T',300,'Air.mix') Out[2]: 1.1766975266680577 ``` Closes https://github.com/CoolProp/CoolProp/issues/287 Signed-off-by: Ian Bell --- include/CoolProp.h | 2 +- src/Backends/Helmholtz/MixtureParameters.cpp | 10 ++++++++++ src/Backends/Helmholtz/MixtureParameters.h | 5 +++++ src/CoolProp.cpp | 15 ++++++++++++--- src/Tests/CoolProp-Tests.cpp | 11 +++++++++++ 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/include/CoolProp.h b/include/CoolProp.h index 8e0e14ed..9bc4509f 100644 --- a/include/CoolProp.h +++ b/include/CoolProp.h @@ -91,7 +91,7 @@ You might want to start by looking at CoolProp.h double saturation_ancillary(const std::string &fluid_name, const std::string &output, int Q, const std::string &input, double value); /// Get a globally-defined string - /// @param ParamName A string, one of "version", "errstring", "warnstring", "gitrevision", "FluidsList", "fluids_list", "parameter_list" + /// @param ParamName A string, one of "version", "errstring", "warnstring", "gitrevision", "FluidsList", "fluids_list", "parameter_list","predefined_mixtures" /// @returns str The string, or an error message if not valid input std::string get_global_param_string(std::string ParamName); diff --git a/src/Backends/Helmholtz/MixtureParameters.cpp b/src/Backends/Helmholtz/MixtureParameters.cpp index 2813be2a..1aa735ad 100644 --- a/src/Backends/Helmholtz/MixtureParameters.cpp +++ b/src/Backends/Helmholtz/MixtureParameters.cpp @@ -37,6 +37,16 @@ class PredefinedMixturesLibrary{ }; static PredefinedMixturesLibrary predefined_mixtures_library; +std::string get_csv_predefined_mixtures() +{ + std::vector out; + for (std::map< std::string, Dictionary >::iterator it = predefined_mixtures_library.predefined_mixture_map.begin(); it != predefined_mixtures_library.predefined_mixture_map.end(); ++it) + { + out.push_back(it->first); + } + return strjoin(out, ","); +} + bool is_predefined_mixture(const std::string name, Dictionary &dict){ if (predefined_mixtures_library.predefined_mixture_map.find(name) != predefined_mixtures_library.predefined_mixture_map.end()){ dict = predefined_mixtures_library.predefined_mixture_map[name]; diff --git a/src/Backends/Helmholtz/MixtureParameters.h b/src/Backends/Helmholtz/MixtureParameters.h index 563f56bd..751defff 100644 --- a/src/Backends/Helmholtz/MixtureParameters.h +++ b/src/Backends/Helmholtz/MixtureParameters.h @@ -15,6 +15,11 @@ std::string get_csv_mixture_binary_pairs(); * */ bool is_predefined_mixture(const std::string name, Dictionary &dict); + +/** \brief Get a comma-separated list of predefined mixtures in + * + */ +std::string get_csv_predefined_mixtures(); /** \brief Get a string for the given binary pair * diff --git a/src/CoolProp.cpp b/src/CoolProp.cpp index 68b2da1a..539dc8a2 100644 --- a/src/CoolProp.cpp +++ b/src/CoolProp.cpp @@ -307,6 +307,7 @@ double Props1SI(const std::string &FluidName, const std::string &Output) double PropsSI(const std::string &Output, const std::string &Name1, double Prop1, const std::string &Name2, double Prop2, const std::string &Ref) { std::string backend, fluid; + std::vector fractions; #if !defined(NO_ERROR_CATCHING) // In this function the error catching happens; try{ @@ -314,7 +315,12 @@ double PropsSI(const std::string &Output, const std::string &Name1, double Prop1 // BEGIN OF TRY // Here is the real code that is inside the try block extract_backend(Ref, backend, fluid); - double val = _PropsSI(Output, Name1, Prop1, Name2, Prop2, backend, fluid, std::vector()); + Dictionary dict; + if (is_predefined_mixture(fluid, dict)){ + fractions = dict.get_double_vector("mole_fractions"); + fluid = strjoin(dict.get_string_vector("fluids"),"&"); + } + double val = _PropsSI(Output, Name1, Prop1, Name2, Prop2, backend, fluid, fractions); if (get_debug_level() > 1){ std::cout << format("_PropsSI will return %g",val) << std::endl; } return val; // END OF TRY @@ -498,6 +504,9 @@ std::string get_global_param_string(std::string ParamName) } else if (!ParamName.compare("parameter_list") ){ return get_csv_parameter_list(); + } + else if (!ParamName.compare("predefined_mixtures") ){ + return get_csv_predefined_mixtures(); } else{ throw ValueError(format("Input value [%s] is invalid",ParamName.c_str())); @@ -506,8 +515,8 @@ std::string get_global_param_string(std::string ParamName) #if defined(ENABLE_CATCH) TEST_CASE("Check inputs to get_global_param_string","[get_global_param_string]") { - const int num_good_inputs = 7; - std::string good_inputs[num_good_inputs] = {"version", "gitrevision", "fluids_list", "incompressible_list_pure", "incompressible_list_solution", "mixture_binary_pairs_list","parameter_list"}; + const int num_good_inputs = 8; + std::string good_inputs[num_good_inputs] = {"version", "gitrevision", "fluids_list", "incompressible_list_pure", "incompressible_list_solution", "mixture_binary_pairs_list","parameter_list","predefined_mixtures"}; std::ostringstream ss3c; for (int i = 0; i fluids = strsplit(CoolProp::get_global_param_string("fluids_list"),',');