mirror of
https://github.com/CoolProp/CoolProp.git
synced 2026-04-23 03:00:17 -04:00
Move fluid_param_string into backends, allowing access to CAS for REFPROP; closes #678
This commit is contained in:
@@ -132,6 +132,52 @@ void HelmholtzEOSMixtureBackend::recalculate_singlephase_phase()
|
||||
}
|
||||
}
|
||||
}
|
||||
std::string HelmholtzEOSMixtureBackend::fluid_param_string(const std::string &ParamName)
|
||||
{
|
||||
CoolProp::CoolPropFluid cpfluid = get_components()[0];
|
||||
if (!ParamName.compare("aliases")){
|
||||
return strjoin(cpfluid.aliases, ", ");
|
||||
}
|
||||
else if (!ParamName.compare("CAS") || !ParamName.compare("CAS_number")){
|
||||
return cpfluid.CAS;
|
||||
}
|
||||
else if (!ParamName.compare("formula")){
|
||||
return cpfluid.formula;
|
||||
}
|
||||
else if (!ParamName.compare("ASHRAE34")){
|
||||
return cpfluid.environment.ASHRAE34;
|
||||
}
|
||||
else if (!ParamName.compare("REFPROPName") || !ParamName.compare("REFPROP_name") || !ParamName.compare("REFPROPname")){
|
||||
return cpfluid.REFPROPname;
|
||||
}
|
||||
else if (ParamName.find("BibTeX") == 0) // Starts with "BibTeX"
|
||||
{
|
||||
std::vector<std::string> parts = strsplit(ParamName,'-');
|
||||
if (parts.size() != 2){ throw ValueError(format("Unable to parse BibTeX string %s",ParamName.c_str()));}
|
||||
std::string key = parts[1];
|
||||
if (!key.compare("EOS")){ return cpfluid.EOS().BibTeX_EOS; }
|
||||
else if (!key.compare("CP0")){ return cpfluid.EOS().BibTeX_CP0; }
|
||||
else if (!key.compare("VISCOSITY")){ return cpfluid.transport.BibTeX_viscosity; }
|
||||
else if (!key.compare("CONDUCTIVITY")){ return cpfluid.transport.BibTeX_conductivity; }
|
||||
else if (!key.compare("ECS_LENNARD_JONES")){ throw NotImplementedError(); }
|
||||
else if (!key.compare("ECS_VISCOSITY_FITS")){ throw NotImplementedError(); }
|
||||
else if (!key.compare("ECS_CONDUCTIVITY_FITS")){ throw NotImplementedError(); }
|
||||
else if (!key.compare("SURFACE_TENSION")){ return cpfluid.ancillaries.surface_tension.BibTeX;}
|
||||
else if (!key.compare("MELTING_LINE")){ return cpfluid.ancillaries.melting_line.BibTeX;}
|
||||
else{ throw CoolProp::KeyError(format("Bad key to get_BibTeXKey [%s]", key.c_str()));}
|
||||
}
|
||||
else if (ParamName.find("pure") == 0){
|
||||
if (is_pure()){
|
||||
return "true";
|
||||
}
|
||||
else{
|
||||
return "false";
|
||||
}
|
||||
}
|
||||
else{
|
||||
throw ValueError(format("Input value [%s] is invalid for Fluid [%s]",ParamName.c_str()));
|
||||
}
|
||||
}
|
||||
void HelmholtzEOSMixtureBackend::calc_phase_envelope(const std::string &type)
|
||||
{
|
||||
// Clear the phase envelope data
|
||||
|
||||
@@ -61,6 +61,9 @@ public:
|
||||
bool is_pure(){ return components.size() == 1 && !components[0].EOS().pseudo_pure; }
|
||||
bool has_melting_line(){ return is_pure_or_pseudopure && components[0].ancillaries.melting_line.enabled();};
|
||||
CoolPropDbl calc_melting_line(int param, int given, CoolPropDbl value);
|
||||
/// Return a string from the backend for the mixture/fluid
|
||||
std::string fluid_param_string(const std::string &);
|
||||
|
||||
phases calc_phase(void){return _phase;};
|
||||
void calc_specify_phase(phases phase){ specify_phase(phase); }
|
||||
void calc_unspecify_phase(){ unspecify_phase(); }
|
||||
|
||||
@@ -65,6 +65,15 @@ public:
|
||||
@param value2 Second input value
|
||||
*/
|
||||
void update(CoolProp::input_pairs input_pair, double value1, double value2);
|
||||
|
||||
std::string fluid_param_string(const std::string &ParamName){
|
||||
if (!ParamName.compare("long_name")){
|
||||
return calc_name();
|
||||
}
|
||||
else{
|
||||
throw ValueError(format("Input value [%s] is invalid.",ParamName.c_str()));
|
||||
}
|
||||
}
|
||||
|
||||
/// Clear all the cached values
|
||||
bool clear();
|
||||
|
||||
@@ -319,6 +319,45 @@ void REFPROPMixtureBackend::set_REFPROP_fluids(const std::vector<std::string> &f
|
||||
}
|
||||
}
|
||||
}
|
||||
std::string REFPROPMixtureBackend::fluid_param_string(const std::string &ParamName){
|
||||
if (ParamName == "CAS"){
|
||||
// subroutine NAME (icomp,hnam,hn80,hcasn)
|
||||
// c
|
||||
// c provides name information for specified component
|
||||
// c
|
||||
// c input:
|
||||
// c icomp--component number in mixture; 1 for pure fluid
|
||||
// c outputs:
|
||||
// c hnam--component name [character*12]
|
||||
// c hn80--component name--long form [character*80]
|
||||
// c hcasn--CAS (Chemical Abstracts Service) number [character*12]
|
||||
long icomp = 1L;
|
||||
char hnam[13], hn80[81], hcasn[13];
|
||||
NAMEdll(&icomp, hnam, hn80, hcasn, 12, 80, 12);
|
||||
std::string casn = hcasn;
|
||||
strstrip(casn);
|
||||
return casn;
|
||||
}
|
||||
else if (ParamName == "name"){
|
||||
long icomp = 1L;
|
||||
char hnam[13], hn80[81], hcasn[13];
|
||||
NAMEdll(&icomp, hnam, hn80, hcasn, 12, 80, 12);
|
||||
std::string name = hnam;
|
||||
strstrip(name);
|
||||
return name;
|
||||
}
|
||||
else if (ParamName == "long_name"){
|
||||
long icomp = 1L;
|
||||
char hnam[13], hn80[81], hcasn[13];
|
||||
NAMEdll(&icomp, hnam, hn80, hcasn, 12, 80, 12);
|
||||
std::string n80 = hn80;
|
||||
strstrip(n80);
|
||||
return n80;
|
||||
}
|
||||
else{
|
||||
throw ValueError(format("parameter to fluid_param_string is invalid: %s", ParamName.c_str()));
|
||||
}
|
||||
};
|
||||
void REFPROPMixtureBackend::set_mole_fractions(const std::vector<CoolPropDbl> &mole_fractions)
|
||||
{
|
||||
if (mole_fractions.size() != this->Ncomp)
|
||||
|
||||
@@ -82,6 +82,8 @@ public:
|
||||
|
||||
/// Returns true if REFPROP is supported on this platform
|
||||
bool REFPROP_supported(void);
|
||||
|
||||
std::string fluid_param_string(const std::string &ParamName);
|
||||
|
||||
CoolPropDbl calc_PIP(void);
|
||||
|
||||
|
||||
@@ -824,22 +824,7 @@ void set_reference_stateD(const std::string &Ref, double T, double rhomolar, dou
|
||||
HEOS.update_states();
|
||||
}
|
||||
|
||||
std::string get_BibTeXKey(const std::string &Ref, const std::string &key)
|
||||
{
|
||||
std::vector<std::string> names(1, Ref);
|
||||
HelmholtzEOSMixtureBackend HEOS(names);
|
||||
|
||||
if (!key.compare("EOS")){ return HEOS.get_components()[0].EOS().BibTeX_EOS; }
|
||||
else if (!key.compare("CP0")){ return HEOS.get_components()[0].EOS().BibTeX_CP0; }
|
||||
else if (!key.compare("VISCOSITY")){ return HEOS.get_components()[0].transport.BibTeX_viscosity; }
|
||||
else if (!key.compare("CONDUCTIVITY")){ return HEOS.get_components()[0].transport.BibTeX_conductivity; }
|
||||
else if (!key.compare("ECS_LENNARD_JONES")){ throw NotImplementedError(); }
|
||||
else if (!key.compare("ECS_VISCOSITY_FITS")){ throw NotImplementedError(); }
|
||||
else if (!key.compare("ECS_CONDUCTIVITY_FITS")){ throw NotImplementedError(); }
|
||||
else if (!key.compare("SURFACE_TENSION")){ return HEOS.get_components()[0].ancillaries.surface_tension.BibTeX;}
|
||||
else if (!key.compare("MELTING_LINE")){ return HEOS.get_components()[0].ancillaries.melting_line.BibTeX;}
|
||||
else{ throw CoolProp::KeyError(format("Bad key to get_BibTeXKey [%s]", key.c_str()));}
|
||||
}
|
||||
std::string get_global_param_string(const std::string &ParamName)
|
||||
{
|
||||
if (!ParamName.compare("version")){ return version; }
|
||||
@@ -892,62 +877,12 @@ TEST_CASE("Check inputs to get_global_param_string","[get_global_param_string]")
|
||||
CHECK_THROWS(CoolProp::get_global_param_string(""));
|
||||
};
|
||||
#endif
|
||||
|
||||
std::string get_fluid_param_string(const std::string &FluidName, const std::string &ParamName)
|
||||
{
|
||||
try {
|
||||
std::string backend, fluid;
|
||||
extract_backend(FluidName, backend, fluid);
|
||||
if (backend == "INCOMP"){
|
||||
CoolProp::IncompressibleBackend INCOMP(fluid);
|
||||
|
||||
if (!ParamName.compare("long_name")){
|
||||
return INCOMP.calc_name();
|
||||
}
|
||||
else{
|
||||
throw ValueError(format("Input value [%s] is invalid for Fluid [%s]",ParamName.c_str(),FluidName.c_str()));
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> comps(1, FluidName);
|
||||
CoolProp::HelmholtzEOSMixtureBackend HEOS(comps);
|
||||
CoolProp::CoolPropFluid cpfluid = HEOS.get_components()[0];
|
||||
|
||||
if (!ParamName.compare("aliases")){
|
||||
return strjoin(cpfluid.aliases, ", ");
|
||||
}
|
||||
else if (!ParamName.compare("CAS") || !ParamName.compare("CAS_number")){
|
||||
return cpfluid.CAS;
|
||||
}
|
||||
else if (!ParamName.compare("formula")){
|
||||
return cpfluid.formula;
|
||||
}
|
||||
else if (!ParamName.compare("ASHRAE34")){
|
||||
return cpfluid.environment.ASHRAE34;
|
||||
}
|
||||
else if (!ParamName.compare("REFPROPName") || !ParamName.compare("REFPROP_name") || !ParamName.compare("REFPROPname")){
|
||||
return cpfluid.REFPROPname;
|
||||
}
|
||||
else if (ParamName.find("BibTeX") == 0) // Starts with "BibTeX"
|
||||
{
|
||||
std::vector<std::string> parts = strsplit(ParamName,'-');
|
||||
if (parts.size() != 2){ throw ValueError(format("Unable to parse BibTeX string %s",ParamName.c_str()));}
|
||||
return get_BibTeXKey( FluidName, parts[1]);
|
||||
}
|
||||
else if (ParamName.find("pure") == 0){
|
||||
if (HEOS.is_pure()){
|
||||
return "true";
|
||||
}
|
||||
else{
|
||||
return "false";
|
||||
}
|
||||
}
|
||||
else{
|
||||
throw ValueError(format("Input value [%s] is invalid for Fluid [%s]",ParamName.c_str(),FluidName.c_str()));
|
||||
}
|
||||
}
|
||||
catch(std::exception &e){ throw ValueError(format("CoolProp error: %s", e.what())); }
|
||||
catch(...){ throw ValueError("CoolProp error: Indeterminate error"); }
|
||||
std::string backend, fluid;
|
||||
extract_backend(FluidName, backend, fluid);
|
||||
shared_ptr<CoolProp::AbstractState> AS(CoolProp::AbstractState::factory(backend, fluid));
|
||||
return AS->fluid_param_string(ParamName);
|
||||
}
|
||||
#if defined(ENABLE_CATCH)
|
||||
TEST_CASE("Check inputs to get_fluid_param_string", "[get_fluid_param_string]")
|
||||
|
||||
Reference in New Issue
Block a user