Move fluid_param_string into backends, allowing access to CAS for REFPROP; closes #678

This commit is contained in:
Ian Bell
2015-07-26 13:35:39 -06:00
parent 3ebeadbc54
commit 58e7edd1dc
7 changed files with 106 additions and 69 deletions

View File

@@ -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]")