Skip to content

Commit

Permalink
Predefined mixtures working in PropsSI now
Browse files Browse the repository at this point in the history
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 #287

Signed-off-by: Ian Bell <ian.h.bell@gmail.com>
  • Loading branch information
ibell committed Dec 5, 2014
1 parent 93305f0 commit 0cb02a3
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
2 changes: 1 addition & 1 deletion include/CoolProp.h
Expand Up @@ -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);

Expand Down
10 changes: 10 additions & 0 deletions src/Backends/Helmholtz/MixtureParameters.cpp
Expand Up @@ -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];
Expand Down
5 changes: 5 additions & 0 deletions src/Backends/Helmholtz/MixtureParameters.h
Expand Up @@ -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
*
Expand Down
15 changes: 12 additions & 3 deletions src/CoolProp.cpp
Expand Up @@ -307,14 +307,20 @@ 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{
#endif
// 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
Expand Down Expand Up @@ -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()));
Expand All @@ -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];
Expand Down
11 changes: 11 additions & 0 deletions src/Tests/CoolProp-Tests.cpp
Expand Up @@ -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"),',');
Expand Down

0 comments on commit 0cb02a3

Please sign in to comment.