mirror of
https://github.com/CoolProp/CoolProp.git
synced 2026-01-09 14:08:08 -05:00
Merge branch 'master' into cpp_review
# Conflicts: # src/DataStructures.cpp
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
|
||||
|
||||
#include "DataStructures.h"
|
||||
#include "Exceptions.h"
|
||||
#include "CoolPropTools.h"
|
||||
#include "CoolProp.h"
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
|
||||
namespace CoolProp {
|
||||
using std::string;
|
||||
|
||||
struct parameter_info
|
||||
{
|
||||
@@ -15,8 +15,7 @@ struct parameter_info
|
||||
bool trivial; ///< True if the input is trivial, and can be directly calculated (constants like critical properties, etc.)
|
||||
};
|
||||
|
||||
// TODO: C++17: static constexpr!
|
||||
const std::array<parameter_info, 78> parameter_info_list{{
|
||||
const parameter_info parameter_info_list[] = {
|
||||
/// Input/Output parameters
|
||||
{iT, "T", "IO", "K", "Temperature", false},
|
||||
{iP, "P", "IO", "Pa", "Pressure", false},
|
||||
@@ -103,7 +102,7 @@ const std::array<parameter_info, 78> parameter_info_list{{
|
||||
|
||||
{iPhase, "Phase", "O", "-", "Phase index as a float", false},
|
||||
|
||||
}};
|
||||
};
|
||||
|
||||
class ParameterInformation
|
||||
{
|
||||
@@ -112,16 +111,14 @@ class ParameterInformation
|
||||
std::map<int, std::string> short_desc_map, description_map, IO_map, units_map;
|
||||
std::map<std::string, int> index_map;
|
||||
ParameterInformation() {
|
||||
for (const auto& el : parameter_info_list) {
|
||||
// TODO: in C++17 and above, consider replacing all your maps with a **constexpr** std::array<std::pair<int, std::string_view>>
|
||||
// or std::array<std::pair<parameter_info, std::string_view>> if you make that an enum **class**
|
||||
// for better performance, or just plain std::array<std::string_view> actually since you use an int as a key...
|
||||
short_desc_map.insert(std::pair<int, std::string>(el.key, el.short_desc));
|
||||
IO_map.insert(std::pair<int, std::string>(el.key, el.IO));
|
||||
units_map.insert(std::pair<int, std::string>(el.key, el.units));
|
||||
description_map.insert(std::pair<int, std::string>(el.key, el.description));
|
||||
index_map_insert(el.short_desc, el.key);
|
||||
trivial_map.insert(std::pair<int, bool>(el.key, el.trivial));
|
||||
const parameter_info* const end = parameter_info_list + sizeof(parameter_info_list) / sizeof(parameter_info_list[0]);
|
||||
for (const parameter_info* el = parameter_info_list; el != end; ++el) {
|
||||
short_desc_map.insert(std::pair<int, std::string>(el->key, el->short_desc));
|
||||
IO_map.insert(std::pair<int, std::string>(el->key, el->IO));
|
||||
units_map.insert(std::pair<int, std::string>(el->key, el->units));
|
||||
description_map.insert(std::pair<int, std::string>(el->key, el->description));
|
||||
index_map_insert(el->short_desc, el->key);
|
||||
trivial_map.insert(std::pair<int, bool>(el->key, el->trivial));
|
||||
}
|
||||
// Backward compatibility aliases
|
||||
index_map_insert("D", iDmass);
|
||||
@@ -157,61 +154,57 @@ class ParameterInformation
|
||||
}
|
||||
};
|
||||
|
||||
static ParameterInformation parameter_information;
|
||||
std::unique_ptr<ParameterInformation> parameter_information_p;
|
||||
const ParameterInformation& get_parameter_information() {
|
||||
if (!parameter_information_p) {
|
||||
parameter_information_p = std::make_unique<ParameterInformation>();
|
||||
}
|
||||
return *parameter_information_p;
|
||||
}
|
||||
|
||||
bool is_trivial_parameter(int key) {
|
||||
// Try to find it
|
||||
std::map<int, bool>::const_iterator it = parameter_information.trivial_map.find(key);
|
||||
// If equal to end, not found
|
||||
auto& parameter_information = get_parameter_information();
|
||||
auto it = parameter_information.trivial_map.find(key);
|
||||
if (it != parameter_information.trivial_map.end()) {
|
||||
// Found it, return it
|
||||
return it->second;
|
||||
} else {
|
||||
throw ValueError(format("Unable to match the key [%d: %s] in is_trivial_parameter", key, get_parameter_information(key, "short").c_str()));
|
||||
}
|
||||
throw ValueError(format("Unable to match the key [%d: %s] in is_trivial_parameter", key, get_parameter_information(key, "short").c_str()));
|
||||
}
|
||||
|
||||
std::string get_parameter_information(int key, const std::string& info) {
|
||||
std::map<int, std::string>* M;
|
||||
|
||||
const std::map<int, std::string>* M;
|
||||
auto& parameter_information = get_parameter_information();
|
||||
// Hook up the right map (since they are all of the same type)
|
||||
if (info == "IO") {
|
||||
if (!info.compare("IO")) {
|
||||
M = &(parameter_information.IO_map);
|
||||
} else if (info == "short") {
|
||||
} else if (!info.compare("short")) {
|
||||
M = &(parameter_information.short_desc_map);
|
||||
} else if (info == "long") {
|
||||
} else if (!info.compare("long")) {
|
||||
M = &(parameter_information.description_map);
|
||||
} else if (info == "units") {
|
||||
} else if (!info.compare("units")) {
|
||||
M = &(parameter_information.units_map);
|
||||
} else {
|
||||
throw ValueError(format("Bad info string [%s] to get_parameter_information", info.c_str()));
|
||||
}
|
||||
|
||||
// Try to find it
|
||||
std::map<int, std::string>::const_iterator it = M->find(key);
|
||||
// If equal to end, not found
|
||||
auto it = M->find(key);
|
||||
if (it != M->end()) {
|
||||
// Found it, return it
|
||||
return it->second;
|
||||
} else {
|
||||
throw ValueError(format("Unable to match the key [%d] in get_parameter_information for info [%s]", key, info.c_str()));
|
||||
}
|
||||
throw ValueError(format("Unable to match the key [%d] in get_parameter_information for info [%s]", key, info.c_str()));
|
||||
}
|
||||
|
||||
/// Return a list of parameters
|
||||
std::string get_csv_parameter_list() {
|
||||
auto& parameter_information = get_parameter_information();
|
||||
std::vector<std::string> strings;
|
||||
strings.reserve(parameter_information.index_map.size());
|
||||
for (const auto& kv : parameter_information.index_map) {
|
||||
strings.push_back(kv.first);
|
||||
for (std::map<std::string, int>::const_iterator it = parameter_information.index_map.begin(); it != parameter_information.index_map.end(); ++it) {
|
||||
strings.push_back(it->first);
|
||||
}
|
||||
return strjoin(strings, ",");
|
||||
}
|
||||
|
||||
// TODO: parameters is an enum that has a INVALID_PARAMETER value, so you can just change the signature to
|
||||
// parameters is_valid_parameter(const std::string& param_name)
|
||||
// [...] if not found: return parameters::INVALID_PARAMETER
|
||||
bool is_valid_parameter(const std::string& param_name, parameters& iOutput) {
|
||||
auto& parameter_information = get_parameter_information();
|
||||
// Try to find it
|
||||
std::map<std::string, int>::const_iterator it = parameter_information.index_map.find(param_name);
|
||||
// If equal to end, not found
|
||||
@@ -242,23 +235,21 @@ bool is_valid_first_derivative(const std::string& name, parameters& iOf, paramet
|
||||
return false;
|
||||
}
|
||||
|
||||
std::size_t i0 = split_at_slash[0].find('(');
|
||||
std::size_t i1 = split_at_slash[0].find(')', i0);
|
||||
std::size_t i0 = split_at_slash[0].find("(");
|
||||
std::size_t i1 = split_at_slash[0].find(")", i0);
|
||||
if (!((i0 > 0) && (i0 != std::string::npos) && (i1 > (i0 + 1)) && (i1 != std::string::npos))) {
|
||||
return false;
|
||||
}
|
||||
std::string num = split_at_slash[0].substr(i0 + 1, i1 - i0 - 1);
|
||||
|
||||
i0 = split_at_slash[1].find('(');
|
||||
i1 = split_at_slash[1].find(')', i0);
|
||||
i0 = split_at_slash[1].find("(");
|
||||
i1 = split_at_slash[1].find(")", i0);
|
||||
if (!((i0 > 0) && (i0 != std::string::npos) && (i1 > (i0 + 1)) && (i1 != std::string::npos))) {
|
||||
return false;
|
||||
}
|
||||
std::string den = split_at_slash[1].substr(i0 + 1, i1 - i0 - 1);
|
||||
|
||||
parameters Of;
|
||||
parameters Wrt;
|
||||
parameters Constant;
|
||||
parameters Of, Wrt, Constant;
|
||||
if (is_valid_parameter(num, Of) && is_valid_parameter(den, Wrt) && is_valid_parameter(split_at_bar[1], Constant)) {
|
||||
iOf = Of;
|
||||
iWrt = Wrt;
|
||||
@@ -287,22 +278,21 @@ bool is_valid_first_saturation_derivative(const std::string& name, parameters& i
|
||||
return false;
|
||||
}
|
||||
|
||||
std::size_t i0 = split_at_slash[0].find('(');
|
||||
std::size_t i1 = split_at_slash[0].find(')', i0);
|
||||
std::size_t i0 = split_at_slash[0].find("(");
|
||||
std::size_t i1 = split_at_slash[0].find(")", i0);
|
||||
if (!((i0 > 0) && (i0 != std::string::npos) && (i1 > (i0 + 1)) && (i1 != std::string::npos))) {
|
||||
return false;
|
||||
}
|
||||
std::string num = split_at_slash[0].substr(i0 + 1, i1 - i0 - 1);
|
||||
|
||||
i0 = split_at_slash[1].find('(');
|
||||
i1 = split_at_slash[1].find(')', i0);
|
||||
i0 = split_at_slash[1].find("(");
|
||||
i1 = split_at_slash[1].find(")", i0);
|
||||
if (!((i0 > 0) && (i0 != std::string::npos) && (i1 > (i0 + 1)) && (i1 != std::string::npos))) {
|
||||
return false;
|
||||
}
|
||||
std::string den = split_at_slash[1].substr(i0 + 1, i1 - i0 - 1);
|
||||
|
||||
parameters Of;
|
||||
parameters Wrt;
|
||||
parameters Of, Wrt;
|
||||
if (is_valid_parameter(num, Of) && is_valid_parameter(den, Wrt) && upper(split_at_bar[1]) == "SIGMA") {
|
||||
iOf = Of;
|
||||
iWrt = Wrt;
|
||||
@@ -336,8 +326,8 @@ bool is_valid_second_derivative(const std::string& name, parameters& iOf1, param
|
||||
std::string left_of_slash = left_of_bar.substr(0, i); // "d(d(P)/d(Dmolar)|T)"
|
||||
std::string right_of_slash = left_of_bar.substr(i + 1); // "d(Dmolar)"
|
||||
|
||||
i = left_of_slash.find('(');
|
||||
std::size_t i1 = left_of_slash.rfind(')');
|
||||
i = left_of_slash.find("(");
|
||||
std::size_t i1 = left_of_slash.rfind(")");
|
||||
if (!((i > 0) && (i != std::string::npos) && (i1 > (i + 1)) && (i1 != std::string::npos))) {
|
||||
return false;
|
||||
}
|
||||
@@ -346,14 +336,18 @@ bool is_valid_second_derivative(const std::string& name, parameters& iOf1, param
|
||||
return false;
|
||||
}
|
||||
|
||||
i = right_of_slash.find('(');
|
||||
i1 = right_of_slash.rfind(')');
|
||||
i = right_of_slash.find("(");
|
||||
i1 = right_of_slash.rfind(")");
|
||||
if (!((i > 0) && (i != std::string::npos) && (i1 > (i + 1)) && (i1 != std::string::npos))) {
|
||||
return false;
|
||||
}
|
||||
std::string den = right_of_slash.substr(i + 1, i1 - i - 1); // "Dmolar"
|
||||
if (!is_valid_parameter(den, iWrt2)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return is_valid_parameter(den, iWrt2);
|
||||
// If we haven't quit yet, all is well
|
||||
return true;
|
||||
}
|
||||
|
||||
struct phase_info
|
||||
@@ -362,7 +356,7 @@ struct phase_info
|
||||
const char *short_desc, *long_desc;
|
||||
};
|
||||
|
||||
const std::array<phase_info, 9> phase_info_list{{
|
||||
const phase_info phase_info_list[] = {
|
||||
{iphase_liquid, "phase_liquid", ""},
|
||||
{iphase_gas, "phase_gas", ""},
|
||||
{iphase_twophase, "phase_twophase", ""},
|
||||
@@ -372,7 +366,7 @@ const std::array<phase_info, 9> phase_info_list{{
|
||||
{iphase_critical_point, "phase_critical_point", "p = pc, T = Tc"},
|
||||
{iphase_unknown, "phase_unknown", ""},
|
||||
{iphase_not_imposed, "phase_not_imposed", ""},
|
||||
}};
|
||||
};
|
||||
|
||||
class PhaseInformation
|
||||
{
|
||||
@@ -380,19 +374,33 @@ class PhaseInformation
|
||||
std::map<phases, std::string> short_desc_map, long_desc_map;
|
||||
std::map<std::string, phases> index_map;
|
||||
PhaseInformation() {
|
||||
for (const phase_info& el : phase_info_list) {
|
||||
short_desc_map.insert(std::pair<phases, std::string>(el.key, el.short_desc));
|
||||
long_desc_map.insert(std::pair<phases, std::string>(el.key, el.long_desc));
|
||||
index_map.insert(std::pair<std::string, phases>(el.short_desc, el.key));
|
||||
const phase_info* const end = phase_info_list + sizeof(phase_info_list) / sizeof(phase_info_list[0]);
|
||||
for (const phase_info* el = phase_info_list; el != end; ++el) {
|
||||
short_desc_map.insert(std::pair<phases, std::string>(el->key, el->short_desc));
|
||||
long_desc_map.insert(std::pair<phases, std::string>(el->key, el->long_desc));
|
||||
index_map.insert(std::pair<std::string, phases>(el->short_desc, el->key));
|
||||
}
|
||||
}
|
||||
};
|
||||
static PhaseInformation phase_information;
|
||||
|
||||
std::unique_ptr<PhaseInformation> phase_information_p;
|
||||
const PhaseInformation& get_phase_information() {
|
||||
if (!phase_information_p) {
|
||||
phase_information_p = std::make_unique<PhaseInformation>();
|
||||
}
|
||||
return *phase_information_p;
|
||||
}
|
||||
|
||||
const std::string& get_phase_short_desc(phases phase) {
|
||||
return phase_information.short_desc_map[phase];
|
||||
auto& coolprop_information = get_phase_information();
|
||||
auto iter = coolprop_information.short_desc_map.find(phase);
|
||||
if (iter != coolprop_information.short_desc_map.end()) {
|
||||
return iter->second;
|
||||
}
|
||||
throw ValueError("Cannot find the short phase description.");
|
||||
}
|
||||
bool is_valid_phase(const std::string& phase_name, phases& iOutput) {
|
||||
auto& phase_information = get_phase_information();
|
||||
// Try to find it
|
||||
std::map<std::string, phases>::const_iterator it = phase_information.index_map.find(phase_name);
|
||||
// If equal to end, not found
|
||||
@@ -445,15 +453,27 @@ public:
|
||||
}
|
||||
}
|
||||
};
|
||||
static SchemeInformation scheme_information;
|
||||
|
||||
std::unique_ptr<SchemeInformation> scheme_information_p;
|
||||
const SchemeInformation& get_scheme_information() {
|
||||
if (!scheme_information_p) {
|
||||
scheme_information_p = std::make_unique<SchemeInformation>();
|
||||
}
|
||||
return *scheme_information_p;
|
||||
}
|
||||
|
||||
const std::string& get_scheme_short_desc(schemes scheme) {
|
||||
return scheme_information.short_desc_map[scheme];
|
||||
auto& coolprop_information = get_scheme_information();
|
||||
auto it = coolprop_information.short_desc_map.find(scheme);
|
||||
if (it != coolprop_information.short_desc_map.end()) {
|
||||
return it->second;
|
||||
}
|
||||
throw ValueError("Cannot find the short scheme description.");
|
||||
}
|
||||
|
||||
bool is_valid_scheme(const std::string &scheme_name, schemes &iOutput) {
|
||||
// Try to find it
|
||||
std::map<std::string, schemes>::const_iterator it = scheme_information.index_map.find(scheme_name);
|
||||
auto& scheme_information = get_scheme_information();
|
||||
auto it = scheme_information.index_map.find(scheme_name);
|
||||
// If equal to end, not found
|
||||
if (it != scheme_information.index_map.end()){
|
||||
// Found, return it
|
||||
@@ -490,7 +510,7 @@ struct input_pair_info
|
||||
const char *short_desc, *long_desc;
|
||||
};
|
||||
|
||||
const std::array<input_pair_info, 35> input_pair_list{{
|
||||
const input_pair_info input_pair_list[] = {
|
||||
{QT_INPUTS, "QT_INPUTS", "Molar quality, Temperature in K"},
|
||||
{QSmolar_INPUTS, "QS_INPUTS", "Molar quality, Entropy in J/mol/K"},
|
||||
{QSmass_INPUTS, "QS_INPUTS", "Molar quality, Entropy in J/kg/K"},
|
||||
@@ -532,7 +552,7 @@ const std::array<input_pair_info, 35> input_pair_list{{
|
||||
{HmolarSmolar_INPUTS, "HmolarSmolar_INPUTS", "Enthalpy in J/mol, Entropy in J/mol/K"},
|
||||
{SmassUmass_INPUTS, "SmassUmass_INPUTS", "Entropy in J/kg/K, Internal energy in J/kg"},
|
||||
{SmolarUmolar_INPUTS, "SmolarUmolar_INPUTS", "Entropy in J/mol/K, Internal energy in J/mol"},
|
||||
}};
|
||||
};
|
||||
|
||||
class InputPairInformation
|
||||
{
|
||||
@@ -540,30 +560,47 @@ class InputPairInformation
|
||||
std::map<input_pairs, std::string> short_desc_map, long_desc_map;
|
||||
std::map<std::string, input_pairs> index_map;
|
||||
InputPairInformation() {
|
||||
for (const input_pair_info& el : input_pair_list) {
|
||||
short_desc_map.insert(std::pair<input_pairs, std::string>(el.key, el.short_desc));
|
||||
long_desc_map.insert(std::pair<input_pairs, std::string>(el.key, el.long_desc));
|
||||
index_map.insert(std::pair<std::string, input_pairs>(el.short_desc, el.key));
|
||||
const input_pair_info* const end = input_pair_list + sizeof(input_pair_list) / sizeof(input_pair_list[0]);
|
||||
for (const input_pair_info* el = input_pair_list; el != end; ++el) {
|
||||
short_desc_map.insert(std::pair<input_pairs, std::string>(el->key, el->short_desc));
|
||||
long_desc_map.insert(std::pair<input_pairs, std::string>(el->key, el->long_desc));
|
||||
index_map.insert(std::pair<std::string, input_pairs>(el->short_desc, el->key));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static InputPairInformation input_pair_information;
|
||||
std::unique_ptr<InputPairInformation> input_pair_information_p;
|
||||
const InputPairInformation& get_input_pair_information() {
|
||||
if (!input_pair_information_p) {
|
||||
input_pair_information_p = std::make_unique<InputPairInformation>();
|
||||
}
|
||||
return *input_pair_information_p;
|
||||
}
|
||||
|
||||
input_pairs get_input_pair_index(const std::string& input_pair_name) {
|
||||
auto it = input_pair_information.index_map.find(input_pair_name);
|
||||
if (it != input_pair_information.index_map.end()) {
|
||||
auto& coolprop_information = get_input_pair_information();
|
||||
auto it = coolprop_information.index_map.find(input_pair_name);
|
||||
if (it != coolprop_information.index_map.end()) {
|
||||
return it->second;
|
||||
} else {
|
||||
throw ValueError(format("Your input name [%s] is not valid in get_input_pair_index (names are case sensitive)", input_pair_name.c_str()));
|
||||
}
|
||||
throw ValueError(format("Your input name [%s] is not valid in get_input_pair_index (names are case sensitive)", input_pair_name.c_str()));
|
||||
}
|
||||
|
||||
const std::string& get_input_pair_short_desc(input_pairs pair) {
|
||||
return input_pair_information.short_desc_map[pair];
|
||||
auto& coolprop_information = get_input_pair_information();
|
||||
auto it = coolprop_information.short_desc_map.find(pair);
|
||||
if (it != coolprop_information.short_desc_map.end()) {
|
||||
return it->second;
|
||||
}
|
||||
throw ValueError("Cannot find the short input pair description.");
|
||||
}
|
||||
const std::string& get_input_pair_long_desc(input_pairs pair) {
|
||||
return input_pair_information.long_desc_map[pair];
|
||||
auto& coolprop_information = get_input_pair_information();
|
||||
auto it = coolprop_information.long_desc_map.find(pair);
|
||||
if (it != coolprop_information.long_desc_map.end()) {
|
||||
return it->second;
|
||||
}
|
||||
throw ValueError("Cannot find the long input pair description.");
|
||||
}
|
||||
void split_input_pair(input_pairs pair, parameters& p1, parameters& p2) {
|
||||
switch (pair) {
|
||||
@@ -725,35 +762,24 @@ struct backend_info
|
||||
backend_families family;
|
||||
};
|
||||
|
||||
const std::array<backend_family_info, 11> backend_family_list{{
|
||||
{HEOS_BACKEND_FAMILY, "HEOS"},
|
||||
{REFPROP_BACKEND_FAMILY, "REFPROP"},
|
||||
{INCOMP_BACKEND_FAMILY, "INCOMP"},
|
||||
{IF97_BACKEND_FAMILY, "IF97"},
|
||||
{TREND_BACKEND_FAMILY, "TREND"},
|
||||
{TTSE_BACKEND_FAMILY, "TTSE"},
|
||||
{BICUBIC_BACKEND_FAMILY, "BICUBIC"},
|
||||
{SRK_BACKEND_FAMILY, "SRK"},
|
||||
{PR_BACKEND_FAMILY, "PR"},
|
||||
{VTPR_BACKEND_FAMILY, "VTPR"},
|
||||
{PCSAFT_BACKEND_FAMILY, "PCSAFT"},
|
||||
}};
|
||||
const backend_family_info backend_family_list[] = {
|
||||
{HEOS_BACKEND_FAMILY, "HEOS"}, {REFPROP_BACKEND_FAMILY, "REFPROP"}, {INCOMP_BACKEND_FAMILY, "INCOMP"}, {IF97_BACKEND_FAMILY, "IF97"},
|
||||
{TREND_BACKEND_FAMILY, "TREND"}, {TTSE_BACKEND_FAMILY, "TTSE"}, {BICUBIC_BACKEND_FAMILY, "BICUBIC"}, {SRK_BACKEND_FAMILY, "SRK"},
|
||||
{PR_BACKEND_FAMILY, "PR"}, {VTPR_BACKEND_FAMILY, "VTPR"}, {PCSAFT_BACKEND_FAMILY, "PCSAFT"}};
|
||||
|
||||
const std::array<backend_info, 13> backend_list{{
|
||||
{HEOS_BACKEND_PURE, "HelmholtzEOSBackend", HEOS_BACKEND_FAMILY},
|
||||
{HEOS_BACKEND_MIX, "HelmholtzEOSMixtureBackend", HEOS_BACKEND_FAMILY},
|
||||
{REFPROP_BACKEND_PURE, "REFPROPBackend", REFPROP_BACKEND_FAMILY},
|
||||
{REFPROP_BACKEND_MIX, "REFPROPMixtureBackend", REFPROP_BACKEND_FAMILY},
|
||||
{INCOMP_BACKEND, "IncompressibleBackend", INCOMP_BACKEND_FAMILY},
|
||||
{IF97_BACKEND, "IF97Backend", IF97_BACKEND_FAMILY},
|
||||
{TREND_BACKEND, "TRENDBackend", TREND_BACKEND_FAMILY},
|
||||
{TTSE_BACKEND, "TTSEBackend", TTSE_BACKEND_FAMILY},
|
||||
{BICUBIC_BACKEND, "BicubicBackend", BICUBIC_BACKEND_FAMILY},
|
||||
{SRK_BACKEND, "SRKBackend", SRK_BACKEND_FAMILY},
|
||||
{PR_BACKEND, "PengRobinsonBackend", PR_BACKEND_FAMILY},
|
||||
{VTPR_BACKEND, "VTPRBackend", VTPR_BACKEND_FAMILY},
|
||||
{PCSAFT_BACKEND, "PCSAFTBackend", PCSAFT_BACKEND_FAMILY},
|
||||
}};
|
||||
const backend_info backend_list[] = {{HEOS_BACKEND_PURE, "HelmholtzEOSBackend", HEOS_BACKEND_FAMILY},
|
||||
{HEOS_BACKEND_MIX, "HelmholtzEOSMixtureBackend", HEOS_BACKEND_FAMILY},
|
||||
{REFPROP_BACKEND_PURE, "REFPROPBackend", REFPROP_BACKEND_FAMILY},
|
||||
{REFPROP_BACKEND_MIX, "REFPROPMixtureBackend", REFPROP_BACKEND_FAMILY},
|
||||
{INCOMP_BACKEND, "IncompressibleBackend", INCOMP_BACKEND_FAMILY},
|
||||
{IF97_BACKEND, "IF97Backend", IF97_BACKEND_FAMILY},
|
||||
{TREND_BACKEND, "TRENDBackend", TREND_BACKEND_FAMILY},
|
||||
{TTSE_BACKEND, "TTSEBackend", TTSE_BACKEND_FAMILY},
|
||||
{BICUBIC_BACKEND, "BicubicBackend", BICUBIC_BACKEND_FAMILY},
|
||||
{SRK_BACKEND, "SRKBackend", SRK_BACKEND_FAMILY},
|
||||
{PR_BACKEND, "PengRobinsonBackend", PR_BACKEND_FAMILY},
|
||||
{VTPR_BACKEND, "VTPRBackend", VTPR_BACKEND_FAMILY},
|
||||
{PCSAFT_BACKEND, "PCSAFTBackend", PCSAFT_BACKEND_FAMILY}};
|
||||
|
||||
class BackendInformation
|
||||
{
|
||||
@@ -766,64 +792,67 @@ class BackendInformation
|
||||
std::map<std::string, backends> backend_name_map_r; /// < from backend name to backend
|
||||
|
||||
BackendInformation() {
|
||||
for (const backend_family_info& el : backend_family_list) {
|
||||
family_name_map.insert(std::pair<backend_families, std::string>(el.family, el.name));
|
||||
family_name_map_r.insert(std::pair<std::string, backend_families>(el.name, el.family));
|
||||
const backend_family_info* const family_end = backend_family_list + sizeof(backend_family_list) / sizeof(backend_family_list[0]);
|
||||
for (const backend_family_info* el = backend_family_list; el != family_end; ++el) {
|
||||
family_name_map.insert(std::pair<backend_families, std::string>(el->family, el->name));
|
||||
family_name_map_r.insert(std::pair<std::string, backend_families>(el->name, el->family));
|
||||
}
|
||||
for (const backend_info& el : backend_list) {
|
||||
backend_family_map.insert(std::pair<backends, backend_families>(el.backend, el.family));
|
||||
backend_name_map.insert(std::pair<backends, std::string>(el.backend, el.name));
|
||||
backend_name_map_r.insert(std::pair<std::string, backends>(el.name, el.backend));
|
||||
family_name_map_r.insert(std::pair<std::string, backend_families>(el.name, el.family));
|
||||
const backend_info* const backend_end = backend_list + sizeof(backend_list) / sizeof(backend_list[0]);
|
||||
for (const backend_info* el = backend_list; el != backend_end; ++el) {
|
||||
backend_family_map.insert(std::pair<backends, backend_families>(el->backend, el->family));
|
||||
backend_name_map.insert(std::pair<backends, std::string>(el->backend, el->name));
|
||||
backend_name_map_r.insert(std::pair<std::string, backends>(el->name, el->backend));
|
||||
family_name_map_r.insert(std::pair<std::string, backend_families>(el->name, el->family));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static BackendInformation backend_information;
|
||||
std::unique_ptr<BackendInformation> backend_information_p;
|
||||
const BackendInformation& get_backend_information() {
|
||||
if (!backend_information_p) {
|
||||
backend_information_p = std::make_unique<BackendInformation>();
|
||||
}
|
||||
return *backend_information_p;
|
||||
}
|
||||
|
||||
/// Convert a string into the enum values
|
||||
void extract_backend_families(const std::string& backend_string, backend_families& f1, backend_families& f2) {
|
||||
void extract_backend_families(std::string backend_string, backend_families& f1, backend_families& f2) {
|
||||
auto& backend_information = get_backend_information();
|
||||
f1 = INVALID_BACKEND_FAMILY;
|
||||
f2 = INVALID_BACKEND_FAMILY;
|
||||
std::size_t i = backend_string.find('&');
|
||||
std::size_t i = backend_string.find("&");
|
||||
std::map<std::string, backend_families>::const_iterator it;
|
||||
if (i != std::string::npos) {
|
||||
it = backend_information.family_name_map_r.find(backend_string.substr(0, i)); // Before "&"
|
||||
if (it != backend_information.family_name_map_r.end()) {
|
||||
f1 = it->second;
|
||||
}
|
||||
if (it != backend_information.family_name_map_r.end()) f1 = it->second;
|
||||
it = backend_information.family_name_map_r.find(backend_string.substr(i + 1)); // After "&"
|
||||
if (it != backend_information.family_name_map_r.end()) {
|
||||
f2 = it->second;
|
||||
}
|
||||
if (it != backend_information.family_name_map_r.end()) f2 = it->second;
|
||||
} else {
|
||||
it = backend_information.family_name_map_r.find(backend_string);
|
||||
if (it != backend_information.family_name_map_r.end()) {
|
||||
f1 = it->second;
|
||||
}
|
||||
if (it != backend_information.family_name_map_r.end()) f1 = it->second;
|
||||
}
|
||||
}
|
||||
|
||||
void extract_backend_families_string(const std::string& backend_string, backend_families& f1, std::string& f2) {
|
||||
void extract_backend_families_string(std::string backend_string, backend_families& f1, std::string& f2) {
|
||||
auto& backend_information = get_backend_information();
|
||||
backend_families f2_enum;
|
||||
extract_backend_families(backend_string, f1, f2_enum);
|
||||
std::map<backend_families, std::string>::const_iterator it;
|
||||
it = backend_information.family_name_map.find(f2_enum);
|
||||
if (it != backend_information.family_name_map.end()) {
|
||||
if (it != backend_information.family_name_map.end())
|
||||
f2 = it->second;
|
||||
} else {
|
||||
else
|
||||
f2.clear();
|
||||
}
|
||||
}
|
||||
|
||||
std::string get_backend_string(backends backend) {
|
||||
auto& backend_information = get_backend_information();
|
||||
std::map<backends, std::string>::const_iterator it;
|
||||
it = backend_information.backend_name_map.find(backend);
|
||||
if (it != backend_information.backend_name_map.end()) {
|
||||
if (it != backend_information.backend_name_map.end())
|
||||
return it->second;
|
||||
}
|
||||
|
||||
return {};
|
||||
else
|
||||
return std::string("");
|
||||
}
|
||||
|
||||
} /* namespace CoolProp */
|
||||
|
||||
Reference in New Issue
Block a user