mirror of
https://github.com/CoolProp/CoolProp.git
synced 2026-04-23 03:00:17 -04:00
Predefined mixtures are added, can be accessed with a fluid name like R410A.mix
Closes https://github.com/CoolProp/CoolProp/issues/153 Signed-off-by: Ian Bell <ian.h.bell@gmail.com>
This commit is contained in:
@@ -22,7 +22,7 @@ AbstractState * AbstractState::factory(const std::string &backend, const std::st
|
||||
if (!backend.compare("HEOS"))
|
||||
{
|
||||
if (fluid_string.find('&') == std::string::npos){
|
||||
return new HelmholtzEOSBackend(&get_fluid(fluid_string));
|
||||
return new HelmholtzEOSBackend(fluid_string);
|
||||
}
|
||||
else{
|
||||
// Split at the '&'
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <vector>
|
||||
#include "HelmholtzEOSMixtureBackend.h"
|
||||
#include "Fluids/FluidLibrary.h"
|
||||
#include "MixtureParameters.h"
|
||||
|
||||
namespace CoolProp {
|
||||
|
||||
@@ -18,7 +19,28 @@ class HelmholtzEOSBackend : public HelmholtzEOSMixtureBackend {
|
||||
public:
|
||||
HelmholtzEOSBackend();
|
||||
HelmholtzEOSBackend(CoolPropFluid *pFluid){set_components(std::vector<CoolPropFluid*>(1,pFluid));};
|
||||
HelmholtzEOSBackend(const std::string &name){set_components(std::vector<CoolPropFluid*>(1,&(get_library().get(name))));};
|
||||
HelmholtzEOSBackend(const std::string &name){
|
||||
Dictionary dict;
|
||||
std::vector<double> mole_fractions;
|
||||
std::vector<CoolPropFluid*> components;
|
||||
if (is_predefined_mixture(name, dict)){
|
||||
std::vector<std::string> fluids = dict.get_string_vector("fluids");
|
||||
mole_fractions = dict.get_double_vector("mole_fractions");
|
||||
|
||||
components.resize(fluids.size());
|
||||
for (unsigned int i = 0; i < components.size(); ++i){
|
||||
components[i] = &(get_library().get(fluids[i]));
|
||||
}
|
||||
}
|
||||
else{
|
||||
components = std::vector<CoolPropFluid*>(1,&(get_library().get(name)));
|
||||
mole_fractions = std::vector<double>(1,1);
|
||||
}
|
||||
// Set the components
|
||||
set_components(components);
|
||||
// Set the mole fractions
|
||||
set_mole_fractions(std::vector<long double>(mole_fractions.begin(), mole_fractions.end()));
|
||||
};
|
||||
virtual ~HelmholtzEOSBackend(){};
|
||||
};
|
||||
|
||||
|
||||
@@ -1,9 +1,51 @@
|
||||
#include "MixtureParameters.h"
|
||||
#include "mixture_departure_functions_JSON.h" // Creates the variable mixture_departure_functions_JSON
|
||||
#include "mixture_binary_pairs_JSON.h" // Creates the variable mixture_binary_pairs_JSON
|
||||
#include "predefined_mixtures_JSON.h" // Makes a std::string variable called predefined_mixtures_JSON
|
||||
|
||||
namespace CoolProp{
|
||||
|
||||
/** \brief A library of predefined mixtures
|
||||
*
|
||||
* Each entry in the predefined mixture library contains the names and mole fractions for the binary pairs
|
||||
*/
|
||||
class PredefinedMixturesLibrary{
|
||||
public:
|
||||
std::map<std::string, Dictionary> predefined_mixture_map;
|
||||
|
||||
PredefinedMixturesLibrary(){
|
||||
rapidjson::Document doc;
|
||||
|
||||
doc.Parse<0>(predefined_mixtures_JSON.c_str());
|
||||
if (doc.HasParseError()){throw ValueError();}
|
||||
|
||||
// Iterate over the papers in the listing
|
||||
for (rapidjson::Value::ValueIterator itr = doc.Begin(); itr != doc.End(); ++itr)
|
||||
{
|
||||
// Instantiate the empty dictionary to be filled
|
||||
Dictionary dict;
|
||||
// Get the name
|
||||
std::string name = cpjson::get_string(*itr, "name")+".mix";
|
||||
// Get the fluid names
|
||||
dict.add_string_vector("fluids", cpjson::get_string_array(*itr, "fluids"));
|
||||
// Get the mole fractions
|
||||
dict.add_double_vector("mole_fractions", cpjson::get_double_array(*itr,"mole_fractions"));
|
||||
|
||||
predefined_mixture_map.insert(std::pair<std::string, Dictionary >(name, dict));
|
||||
}
|
||||
}
|
||||
};
|
||||
static PredefinedMixturesLibrary predefined_mixtures_library;
|
||||
|
||||
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];
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/** \brief A library of binary pair parameters for the mixture
|
||||
*
|
||||
|
||||
@@ -11,6 +11,11 @@ namespace CoolProp{
|
||||
*/
|
||||
std::string get_csv_mixture_binary_pairs();
|
||||
|
||||
/** \brief Get the parameters for a predefined mixture - R410A, R404A, etc.
|
||||
*
|
||||
*/
|
||||
bool is_predefined_mixture(const std::string name, Dictionary &dict);
|
||||
|
||||
/** \brief Get a string for the given binary pair
|
||||
*
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user