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 <ian.h.bell@gmail.com>
This commit is contained in:
Ian Bell
2014-12-05 11:24:29 -05:00
parent 93305f0413
commit 0cb02a3e2f
5 changed files with 39 additions and 4 deletions

View File

@@ -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);

View File

@@ -37,6 +37,16 @@ class PredefinedMixturesLibrary{
};
static PredefinedMixturesLibrary predefined_mixtures_library;
std::string get_csv_predefined_mixtures()
{
std::vector<std::string> 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];

View File

@@ -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
*

View File

@@ -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<double> 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<double>());
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<num_good_inputs; ++i){
ss3c << "Test for" << good_inputs[i];

View File

@@ -1322,6 +1322,17 @@ TEST_CASE("Test that saturation solvers solve all the way to T = Tc", "[sat_T_to
}
}
TEST_CASE("Predefined mixtures", "[predefined_mixtures]")
{
SECTION("PropsSI"){
double val = PropsSI("Dmolar","P",101325,"T",300,"Air.mix");
std::string err = get_global_param_string("errstring");
CAPTURE(val);
CAPTURE(err);
CHECK(ValidNumber(val));
}
}
TEST_CASE("Test that reference states are correct", "[reference_states]")
{
std::vector<std::string> fluids = strsplit(CoolProp::get_global_param_string("fluids_list"),',');