From 199ced3f86a0d5794ff9da845500ddcd5ef33923 Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Tue, 14 Oct 2014 11:21:07 +0200 Subject: [PATCH] Implemented Phase output again Added PhaseSI function which will return phase for given input - exposed to DLL PropsSI can also return phase as double if "Phase" is the input Signed-off-by: Ian Bell --- include/CoolProp.h | 46 +++++++++++++++++++--------------------- include/CoolPropLib.h | 9 ++++++++ include/DataStructures.h | 13 ++++++++---- src/AbstractState.cpp | 2 ++ src/CoolProp.cpp | 39 +++++++++++++++++++++++++++++++++- src/CoolPropLib.cpp | 8 +++++++ src/DataStructures.cpp | 2 ++ 7 files changed, 90 insertions(+), 29 deletions(-) diff --git a/include/CoolProp.h b/include/CoolProp.h index d6a199aa..dafc6d0f 100644 --- a/include/CoolProp.h +++ b/include/CoolProp.h @@ -40,15 +40,15 @@ You might want to start by looking at CoolProp.h /// @param Name2 The second state variable name, one of "T","D","H",etc. /// @param Prop2 The second state variable value /// @param FluidName The fluid name - /// @param x The mole or mass fractions depending on the requirements of the backend - double PropsSI(const std::string &Output, const std::string &Name1, double Prop1, const std::string &Name2, double Prop2, const std::string &FluidName, const std::vector &x); + /// @param z The mole or mass fractions depending on the requirements of the backend + double PropsSI(const std::string &Output, const std::string &Name1, double Prop1, const std::string &Name2, double Prop2, const std::string &FluidName, const std::vector &z); /// Return a value that depends on the thermodynamic state /// @param Output The output parameter, one of "T","D","H",etc. /// @param Name1 The first state variable name, one of "T","D","H",etc. /// @param Prop1 The first state variable value /// @param Name2 The second state variable name, one of "T","D","H",etc. /// @param Prop2 The second state variable value - /// @param FluidName The fluid name + /// @param FluidName The fluid name, or names seperated by '&' if a mixture /// @param z The mole or mass fractions depending on the requirements of the backend std::vector PropsSI(const std::string &Output, const std::string &Name1, const std::vector &Prop1, const std::string &Name2, const std::vector Prop2, const std::string &FluidName, const std::vector &z); /// Return a value that depends on the thermodynamic state @@ -142,27 +142,25 @@ You might want to start by looking at CoolProp.h /// @param h0 Enthalpy at reference state [J/kg] /// @param s0 Entropy at references state [J/kg/K] //void set_reference_stateD(std::string FluidName, double T, double rho, double h0, double s0); - - /* - /// Return the phase of the given state point with temperature, pressure as inputs - /// @param FluidName The name of the fluid - /// @param T Temperature [K] - /// @param p Pressure [kPa] - /// @returns Phase as string, one of ""Two-Phase","Supercritical","Gas","Liquid" - std::string Phase(std::string FluidName, double T, double p); - /// Return the phase of the given state point with temperature, density as inputs - /// @param FluidName The name of the fluid - /// @param T Temperature [K] - /// @param rho Density [kg/m^3] - /// @returns Phase as string, one of ""Two-Phase","Supercritical","Gas","Liquid" - std::string Phase_Trho(std::string FluidName, double T, double rho); - /// Return the phase of the given state point with temperature, pressure as inputs - /// @param FluidName The name of the fluid - /// @param T Temperature [K] - /// @param p Pressure [kPa] - /// @returns Phase as string, one of ""Two-Phase","Supercritical","Gas","Liquid" - std::string Phase_Tp(std::string FluidName, double T, double p);*/ - + + /// Return a string representation of the phase + /// @param Name1 The first state variable name, one of "T","D","H",etc. + /// @param Prop1 The first state variable value + /// @param Name2 The second state variable name, one of "T","D","H",etc. + /// @param Prop2 The second state variable value + /// @param FluidName The fluid name + /// \note Returns empty string if there was an error; use get_global_param_string("errstring") to retrieve the error + std::string PhaseSI(const std::string &Name1, double Prop1, const std::string &Name2, double Prop2, const std::string &FluidName); + /// Return a string representation of the phase + /// @param Name1 The first state variable name, one of "T","D","H",etc. + /// @param Prop1 The first state variable value + /// @param Name2 The second state variable name, one of "T","D","H",etc. + /// @param Prop2 The second state variable value + /// @param FluidName The fluid name + /// @param z The mole or mass fractions depending on the requirements of the backend + /// \note Returns empty string if there was an error; use get_global_param_string("errstring") to retrieve the error + std::string PhaseSI(const std::string &Name1, double Prop1, const std::string &Name2, double Prop2, const std::string &FluidName, const std::vector &z); + } /* namespace CoolProp */ #endif diff --git a/include/CoolPropLib.h b/include/CoolPropLib.h index e4978549..6702ebd1 100644 --- a/include/CoolPropLib.h +++ b/include/CoolPropLib.h @@ -63,6 +63,15 @@ */ EXPORT_CODE double CONVENTION PropsSI(const char *Output, const char *Name1, double Prop1, const char *Name2, double Prop2, const char *Ref); + /** + *\overload + *\sa \ref CoolProp::PhaseSI(const std::string &, double, const std::string &, double, const std::string&) + * + * \note this function returns the phase string in pre-allocated phase variable + */ + EXPORT_CODE long CONVENTION PhaseSI(const char *Output, const char *Name1, double Prop1, const char *Name2, double Prop2, const char *Ref, const char *phase); + + EXPORT_CODE long CONVENTION get_global_param_string(const char *param, char *Output); /** * \overload diff --git a/include/DataStructures.h b/include/DataStructures.h index e7a4b972..f59dcb31 100644 --- a/include/DataStructures.h +++ b/include/DataStructures.h @@ -66,10 +66,15 @@ enum parameters{ iBvirial, iCvirial, idBvirial_dT, idCvirial_dT, iZ, // Environmental parameters - iGWP20, iGWP100, iGWP500, iFH, iHH, iPH, iODP, - - // The last parameter, so we can check that all parameters are described in DataStructures.cpp - iundefined_parameter + iGWP20, ///< The 20-year global warming potential + iGWP100, ///< The 100-year global warming potential + iGWP500, ///< The 500-year global warming potential + iFH, ///< Fire hazard index + iHH, ///< Health hazard index + iPH, ///< + iODP, ///< Ozone depletion potential (R-11 = 1.0) + iPhase, ///< The phase index of the given state + iundefined_parameter ///< The last parameter, so we can check that all parameters are described in DataStructures.cpp }; // !! If you add a parameter, update the map in the corresponding CPP file !! diff --git a/src/AbstractState.cpp b/src/AbstractState.cpp index ec18cced..253624c1 100644 --- a/src/AbstractState.cpp +++ b/src/AbstractState.cpp @@ -262,6 +262,8 @@ double AbstractState::keyed_output(int key) return viscosity(); case iconductivity: return conductivity(); + case iPhase: + return phase(); default: throw ValueError(format("This input [%d: \"%s\"] is not valid for keyed_output",key,get_parameter_information(key,"short").c_str())); } diff --git a/src/CoolProp.cpp b/src/CoolProp.cpp index 56053088..71245511 100644 --- a/src/CoolProp.cpp +++ b/src/CoolProp.cpp @@ -31,7 +31,7 @@ #include "Backends/Incompressible/IncompressibleLibrary.h" #include "Backends/Helmholtz/HelmholtzEOSBackend.h" #include "Backends/Helmholtz/MixtureParameters.h" - +#include "DataStructures.h" namespace CoolProp { @@ -946,5 +946,42 @@ std::string get_fluid_param_string(std::string FluidName, std::string ParamName) return(std::string("CoolProp error: Indeterminate error")); } } +std::string phase_lookup_string(phases Phase) +{ + switch (Phase) + { + case iphase_liquid: ///< Liquid + return "liquid"; + case iphase_supercritical: ///< Supercritical (p > pc, T > Tc) + return "supercritical"; + case iphase_supercritical_gas: ///< Supercritical gas (p < pc, T > Tc) + return "supercritical_gas"; + case iphase_supercritical_liquid: ///< Supercritical liquid (p > pc, T < Tc) + return "supercritical_liquid"; + case iphase_gas: ///< Subcritical gas + return "gas"; + case iphase_twophase: ///< Twophase + return "twophase"; + case iphase_unknown: ///< Unknown phase + return "unknown"; + case iphase_not_imposed: + return "not_imposed"; + } +} +std::string PhaseSI(const std::string &Name1, double Prop1, const std::string &Name2, double Prop2, const std::string &FluidName) +{ + double Phase_double = PropsSI("Phase",Name1,Prop1,Name2,Prop2,FluidName); + if (!ValidNumber(Phase_double)){ return "";} + std::size_t Phase_int = static_cast(round(Phase_double)); + return phase_lookup_string(static_cast(Phase_int)); +} + +std::string PhaseSI(const std::string &Name1, double Prop1, const std::string &Name2, double Prop2, const std::string &FluidName, const std::vector &z) +{ + double Phase_double = PropsSI("Phase",Name1,Prop1,Name2,Prop2,FluidName,z); + if (!ValidNumber(Phase_double)){ return "";} + std::size_t Phase_int = static_cast(round(Phase_double)); + return phase_lookup_string(static_cast(Phase_int)); +} } /* namespace CoolProp */ diff --git a/src/CoolPropLib.cpp b/src/CoolPropLib.cpp index 5842db37..94f0bc47 100644 --- a/src/CoolPropLib.cpp +++ b/src/CoolPropLib.cpp @@ -130,6 +130,14 @@ EXPORT_CODE double CONVENTION PropsSI(const char *Output, const char *Name1, dou std::string _Output = Output, _Name1 = Name1, _Name2 = Name2, _FluidName = FluidName; return CoolProp::PropsSI(_Output, _Name1, Prop1, _Name2, Prop2, _FluidName); } +EXPORT_CODE long CONVENTION PhaseSI(const char *Output, const char *Name1, double Prop1, const char *Name2, double Prop2, const char * FluidName, char *phase) +{ + std::string _Name1 = Name1, _Name2 = Name2, _FluidName = FluidName; + std::string ph = CoolProp::PhaseSI(_Name1, Prop1, _Name2, Prop2, _FluidName); + if (ph.size() > strlen(phase)){ + strcpy(phase, ph.c_str()); + } +} EXPORT_CODE double CONVENTION PropsSIZ(const char *Output, const char *Name1, double Prop1, const char *Name2, double Prop2, const char * FluidName, const double *z, int n) { std::string _Output = Output, _Name1 = Name1, _Name2 = Name2, _FluidName = FluidName; diff --git a/src/DataStructures.cpp b/src/DataStructures.cpp index c549e351..850fd60c 100644 --- a/src/DataStructures.cpp +++ b/src/DataStructures.cpp @@ -85,6 +85,8 @@ parameter_info parameter_info_list[] = { parameter_info(idalpha0_dtau_constdelta, "dalpha0_dtau_constdelta","O","-","Derivative of ideal Helmholtz energy with tau",false), parameter_info(idalpha0_ddelta_consttau, "dalpha0_ddelta_consttau","O","-","Derivative of ideal Helmholtz energy with delta",false), + parameter_info(iPhase, "Phase","O","-","Phase index from \ref phases",false), + }; class ParameterInformation