Add function to check if fluid name is valid

Closes https://github.com/CoolProp/CoolProp/issues/204

Signed-off-by: Ian Bell <ian.h.bell@gmail.com>
This commit is contained in:
Ian Bell
2014-11-20 13:31:47 -05:00
parent 6507268ade
commit 5c3d31d011
2 changed files with 28 additions and 3 deletions

View File

@@ -106,6 +106,15 @@ You might want to start by looking at CoolProp.h
@returns The string, or an error message if not valid input
*/
std::string get_fluid_param_string(std::string FluidName, std::string ParamName);
/** \brief Check if the fluid name is valid
*
* @returns output Returns true if the fluid string is valid
*
* \note "gfreilgregre" -> false; "HEOS::Water" -> true; "Water" -> true
*
*/
bool is_valid_fluid_string(std::string &fluidstring);
/// Returns the BibTeX key from the bibtex library of CoolProp corresponding to the item requested
/// @param FluidName The name of the fluid that is part of CoolProp, for instance "n-Propane"
@@ -131,7 +140,7 @@ You might want to start by looking at CoolProp.h
\f[
\displaystyle\frac{\Delta s}{R_u/M}+\frac{\Delta h}{(R_u/M)T}\tau
\f]
where \f$ \Delta s = s-_{spec} \f$ and \f$ \Delta h = h-_{spec} \f$
where \f$ \Delta s = s-s_{spec} \f$ and \f$ \Delta h = h-h_{spec} \f$
*/
void set_reference_stateS(std::string FluidName, std::string reference_state);
@@ -139,8 +148,8 @@ You might want to start by looking at CoolProp.h
/// @param FluidName The name of the fluid
/// @param T Temperature at reference state [K]
/// @param rhomolar Density at reference state [mol/m^3]
/// @param h0 Enthalpy at reference state [J/kg]
/// @param s0 Entropy at references state [J/kg/K]
/// @param h0 Enthalpy at reference state [J/mol]
/// @param s0 Entropy at references state [J/mol/K]
void set_reference_stateD(std::string FluidName, double T, double rhomolar, double h0, double s0);
/// Return a string representation of the phase

View File

@@ -510,6 +510,22 @@ double Props1SI(std::string FluidName,std::string Output)
return PropsSI(Output,"",0,"",0,FluidName);
}
bool is_valid_fluid_string(std::string &input_fluid_string)
{
try{
std::string backend, fluid;
std::vector<double> fractions;
// First try to extract backend and fractions
extract_backend(input_fluid_string, backend, fluid);
std::string fluid_string = extract_fractions(fluid, fractions);
// We are going to let the factory function load the state
shared_ptr<AbstractState> State(AbstractState::factory(backend, fluid_string));
return true;
}
catch (std::exception &e){
return false;
}
}
//EXPORT_CODE double CONVENTION IProps(long iOutput, long iName1, double Prop1, long iName2, double Prop2, long iFluid)
//{