EXPORT_CODE double CONVENTION Props(const char *Output, const char Name1, double Prop1, const char Name2, double Prop2, const char * Ref) { fpu_reset_guard guard; try { // Get parameter indices std::string sName1 = std::string(1, Name1), sName2 = std::string(1, Name2); CoolProp::parameters iOutput = CoolProp::get_parameter_index(Output); if (!CoolProp::is_trivial_parameter(iOutput)) { CoolProp::parameters iName1 = CoolProp::get_parameter_index(sName1); CoolProp::parameters iName2 = CoolProp::get_parameter_index(sName2); // Convert inputs to SI Prop1 = convert_from_kSI_to_SI(iName1, Prop1); Prop2 = convert_from_kSI_to_SI(iName2, Prop2); } // Call the SI function double val = PropsSI(Output, sName1.c_str(), Prop1, sName2.c_str(), Prop2, Ref); // Convert back to unit system return convert_from_SI_to_kSI(iOutput, val); } catch(std::exception &e){CoolProp::set_error_string(e.what());} catch(...){CoolProp::set_error_string("Undefined error");} return _HUGE; }
std::string PhaseSI(const std::string &Name1, double Prop1, const std::string &Name2, double Prop2, const std::string &FluidName, const std::vector<double> &z) { double Phase_double = PropsSI("Phase",Name1,Prop1,Name2,Prop2,FluidName,z); if (!ValidNumber(Phase_double)){ return "";} std::size_t Phase_int = static_cast<std::size_t>(Phase_double); return phase_lookup_string(static_cast<phases>(Phase_int)); }
double Props1SI(const std::string &FluidName, const std::string &Output) { std::string _FluidName = FluidName, empty_string = "", _Output = Output; double val1 = PropsSI(_FluidName, empty_string, 0, empty_string, 0, _Output); if (!ValidNumber(val1)){ // flush the error set_error_string(""); // Try with them flipped val1 = PropsSI(_Output, empty_string, 0, empty_string, 0, _FluidName); } if (!ValidNumber(val1)){ set_error_string(format("Unable to use inputs %s,%s in Props1SI (order doesn't matter)")); return _HUGE; } return val1; }
void CoolPropSolver::setFluidConstants(){ if ((fluidType==FLUID_TYPE_PURE)||(fluidType==FLUID_TYPE_PSEUDOPURE)||(fluidType==FLUID_TYPE_REFPROP)){ if (debug_level > 5) std::cout << format("Setting constants for fluid %s \n",substanceName.c_str()); _fluidConstants.pc = PropsSI((char *)"pcrit" ,(char *)"T",0,(char *)"P",0,(char *)substanceName.c_str()); _fluidConstants.Tc = PropsSI((char *)"Tcrit" ,(char *)"T",0,(char *)"P",0,(char *)substanceName.c_str()); _fluidConstants.MM = PropsSI((char *)"molemass",(char *)"T",0,(char *)"P",0,(char *)substanceName.c_str()); _fluidConstants.dc = PropsSI((char *)"rhocrit" ,(char *)"T",0,(char *)"P",0,(char *)substanceName.c_str()); return; } if ((fluidType==FLUID_TYPE_INCOMPRESSIBLE_LIQUID)||(fluidType==FLUID_TYPE_INCOMPRESSIBLE_SOLUTION)){ if (debug_level > 5) std::cout << format("Setting constants for incompressible fluid %s \n",substanceName.c_str()); _fluidConstants.pc = -1; _fluidConstants.Tc = -1; _fluidConstants.MM = -1; _fluidConstants.dc = -1; return; } }
std::vector<double> PropsSI(const std::string &Output, const std::string &Name1, const std::vector<double> &Prop1, const std::string &Name2, const std::vector<double> Prop2, const std::string &Ref, const std::vector<double> &z) { std::vector<double> out(Prop1.size(), _HUGE); if (Prop1.size() != Prop2.size()) { std::cout << format("Sizes of Prop1 [%d] and Prop2 [%d] to PropsSI are not the same", Prop1.size(), Prop2.size()) << std::endl; return out; } for (std::size_t i = 0; i < Prop1.size(); ++i) { out[i] = PropsSI(Output,Name1,Prop1[i],Name2,Prop2[i],Ref,z); } return out; }
void CoolPropSolver::setFluidConstants(){ if ((fluidType==FLUID_TYPE_PURE)||(fluidType==FLUID_TYPE_PSEUDOPURE)||(fluidType==FLUID_TYPE_REFPROP)){ if (debug_level > 5) std::cout << format("Setting constants for fluid %s \n",substanceName.c_str()); _fluidConstants.pc = PropsSI((char *)"pcrit" ,(char *)"T",0,(char *)"P",0,(char *)substanceName.c_str()); _fluidConstants.Tc = PropsSI((char *)"Tcrit" ,(char *)"T",0,(char *)"P",0,(char *)substanceName.c_str()); _fluidConstants.MM = PropsSI((char *)"molemass",(char *)"T",0,(char *)"P",0,(char *)substanceName.c_str()); /* TODO: Fix this dirty, dirty workaround */ if (_fluidConstants.MM > 1.0) _fluidConstants.MM *= 1e-3; _fluidConstants.dc = PropsSI((char *)"rhocrit" ,(char *)"T",0,(char *)"P",0,(char *)substanceName.c_str()); // Now we fill the close to crit record if (debug_level > 5) std::cout << format("Setting near-critical saturation conditions for fluid %s \n",substanceName.c_str()); _satPropsClose2Crit.psat = _fluidConstants.pc*(1.0-_p_eps); // Needs update, setSat_p relies on it setSat_p(_satPropsClose2Crit.psat, &_satPropsClose2Crit); } else if ((fluidType==FLUID_TYPE_INCOMPRESSIBLE_LIQUID)||(fluidType==FLUID_TYPE_INCOMPRESSIBLE_SOLUTION)){ if (debug_level > 5) std::cout << format("Setting constants for incompressible fluid %s \n",substanceName.c_str()); _fluidConstants.pc = NAN; _fluidConstants.Tc = NAN; _fluidConstants.MM = NAN; _fluidConstants.dc = NAN; } }
/* * 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; double val = CoolProp::PropsSI(_Output, _Name1, Prop1, _Name2, Prop2, _FluidName, std::vector<double>(z, z+n)); reset_fpu(); return val; } * */ EXPORT_CODE void CONVENTION propssi_(const char *Output, const char *Name1, const double *Prop1, const char *Name2, const double *Prop2, const char * FluidName, double *output) { *output = PropsSI(Output, Name1, *Prop1, Name2, *Prop2, FluidName); }
#include "CoolPropDLL.h" #include "CoolProp.h" #ifndef DISABLE_CATCH #include "Tests.h" #define CATCH_CONFIG_RUNNER #include "Catch/catch.hpp" TEST_CASE( "Check reference state", "[reference_state]" ) { SECTION("IIR") { set_reference_stateS("Propane","IIR"); double h_EOS = PropsSI("H","T",273.15,"Q",0,"Propane"); double s_EOS = PropsSI("S","T",273.15,"Q",0,"Propane"); double h_target = 200000; double s_target = 1000; REQUIRE(abs(h_target-h_EOS) < 1e-6); REQUIRE(abs(s_target-s_EOS) < 1e-6); } SECTION("NBP") { set_reference_stateS("Propane","NBP"); double h_EOS = PropsSI("H","P",101325,"Q",0,"Propane"); double s_EOS = PropsSI("S","P",101325,"Q",0,"Propane"); double h_target = 0; double s_target = 0;
double Props1SI(std::string FluidName,std::string Output) { return PropsSI(Output,"",0,"",0,FluidName); }
std::vector<double> PropsSI(const std::string &Output, const std::string &Name1, const std::vector<double> &Prop1, const std::string &Name2, const std::vector<double> Prop2, const std::string &FluidName) { return PropsSI(Output, Name1, Prop1, Name2, Prop2, FluidName, std::vector<double>(1,1)); }
double PropsSI(const char *Output, const char *Name1, double Prop1, const char *Name2, double Prop2, const char *FluidName, const std::vector<double> &x) { std::string _Output = Output, _Name1 = Name1, _Name2 = Name2, _FluidName = FluidName; return PropsSI(_Output,_Name1,Prop1,_Name2,Prop2,_FluidName, x); }
EXPORT_CODE void CONVENTION PropsSIScilab(char *Output, char *Name1, double *Prop1, char *Name2, double *Prop2, char * Ref, double *output) { *output = PropsSI(Output,Name1,*Prop1,Name2,*Prop2,Ref); }
{290,1060.,9.5458,0.22429,-218.59529,-0.66978,1.66179,1.99658,1221.38239}, {290,1070.,22.580,0.52557,-209.68922,-0.68127,1.65651,1.98783,1278.95824}, {450,1e-16,1e-16,1.00000,868.66312,0,1.31313,1.45159,262.43829}, {450,1.0,0.55569e-1,0.89189,760.34138,1.94165,3.74492,4.41190,244.91797}, {450,6.0,0.26514,0.70925,599.36342,1.40868,4.43708,5.53182,212.41678}, {450,870.,2.7252,0.05028,152.00058,0.35592,2.48256,2.74525,536.47030}, {450,880.,5.6865,0.10372,153.23341,0.35114,2.46536,2.73491,607.71381}}; int N = 10; SECTION("P") { for (int i = 0; i < N; i++) { double T = data[i][0], rho = data[i][1], p = data[i][2]*1e6; double PCP = PropsSI("P","T",T,"D",rho,"AceticAcid"); if (rho < 1e-14){p = 1; PCP = 1;} CAPTURE(rho); CAPTURE(p); CAPTURE(PCP); CHECK(fabs(PCP/p-1) < 1e-4); } } SECTION("H") { for (int i = 0; i < N; i++) { double T = data[i][0], rho = data[i][1], h = data[i][4]*1e3; double HCP = PropsSI("H","T",T,"D",rho,"AceticAcid"); CAPTURE(h); CAPTURE(HCP);