Implemented setting of reference state for REFPROP pure fluids; closes #568

Also fixed LIMITS function call for Ttriple
This commit is contained in:
Ian Bell
2015-04-03 21:08:36 -06:00
parent a3bbe15c7d
commit 7b054a2a0e
4 changed files with 91 additions and 61 deletions

View File

@@ -125,7 +125,7 @@ You might want to start by looking at CoolProp.h
/**
\brief Set the reference state based on a string representation
@param FluidName The name of the fluid
@param FluidName The name of the fluid (Backend can be provided like "REFPROP::Water", or if no backend is provided, "HEOS" is the assumed backend)
@param reference_state The reference state to use, one of
Reference State | Description

View File

@@ -334,7 +334,7 @@ bool REFPROPMixtureBackend::REFPROP_supported () {
if (rpv.compare("NOTAVAILABLE")!=0) {
// Function names were defined in "REFPROP_lib.h",
// This platform theoretically supports Refprop.
if (load_REFPROP()) {
if (::load_REFPROP()) {
return true;
}
else {
@@ -589,12 +589,10 @@ CoolPropDbl REFPROPMixtureBackend::calc_rhomolar_reducing(){
};
CoolPropDbl REFPROPMixtureBackend::calc_Ttriple(){
this->check_loaded_fluid();
double wmm, ttrp, tnbpt, tc, pc, Dc, Zc, acf, dip, Rgas, summer = 0;
for (long i = 0; i < mole_fractions.size(); ++i){
INFOdll(&i, &wmm, &ttrp, &tnbpt, &tc, &pc, &Dc, &Zc, &acf, &dip, &Rgas);
summer += ttrp*mole_fractions[i];
}
return static_cast<CoolPropDbl>(summer);
double tmin, tmax, Dmax, pmax;
char htyp[3] = {'E','O','S'};
LIMITSdll(htyp, &(mole_fractions[0]), &tmin, &tmax, &Dmax, &pmax, 3);
return static_cast<CoolPropDbl>(tmin);
};
CoolPropDbl REFPROPMixtureBackend::calc_gas_constant(){
this->check_loaded_fluid();
@@ -1389,6 +1387,11 @@ CoolPropDbl REFPROPMixtureBackend::call_phi0dll(long itau, long idel)
return static_cast<CoolPropDbl>(val)/pow(delta,idel)/pow(tau,itau);
}
void REFPROP_SETREF(char hrf[3], long ixflag, double x0[1], double &h0, double &s0, double &T0, double &p0, long &ierr, char herr[255], long l1, long l2){
::load_REFPROP();
SETREFdll(hrf, &ixflag, x0, &h0, &s0, &T0, &p0, &ierr, herr, l1, l2);
}
} /* namespace CoolProp */

View File

@@ -166,5 +166,8 @@ public:
CoolPropDbl calc_d3alpha0_dTau3(void){ return call_phi0dll(3,0); };
};
bool load_REFPROP();
void REFPROP_SETREF(char hrf[3], long ixflag, double x0[1], double &h0, double &s0, double &T0, double &p0, long &ierr, char herr[255], long l1, long l2);
} /* namespace CoolProp */
#endif /* REFPROPMIXTUREBACKEND_H_ */

View File

@@ -39,6 +39,7 @@
#include "Backends/Helmholtz/HelmholtzEOSBackend.h"
#include "Backends/Helmholtz/MixtureParameters.h"
#include "DataStructures.h"
#include "Backends/REFPROP/REFPROPMixtureBackend.h"
#if defined(ENABLE_CATCH)
#include "catch.hpp"
@@ -702,65 +703,88 @@ double saturation_ancillary(const std::string &fluid_name, const std::string &ou
return HEOS.saturation_ancillary(iOutput, Q, iInput, value);
}
void set_reference_stateS(const std::string &Ref, const std::string &reference_state)
void set_reference_stateS(const std::string &fluid_string, const std::string &reference_state)
{
CoolProp::HelmholtzEOSMixtureBackend HEOS(std::vector<std::string>(1,Ref));
if (!reference_state.compare("IIR"))
{
HEOS.update(QT_INPUTS, 0, 273.15);
// Get current values for the enthalpy and entropy
double deltah = HEOS.hmass() - 200000; // offset from 200000 J/kg enthalpy
double deltas = HEOS.smass() - 1000; // offset from 1000 J/kg/K entropy
double delta_a1 = deltas/(HEOS.gas_constant()/HEOS.molar_mass());
double delta_a2 = -deltah/(HEOS.gas_constant()/HEOS.molar_mass()*HEOS.get_reducing_state().T);
// Change the value in the library for the given fluid
set_fluid_enthalpy_entropy_offset(Ref, delta_a1, delta_a2, "IIR");
if (get_debug_level() > 0){
std::cout << format("set offsets to %g and %g\n", delta_a1, delta_a2);
std::string backend, fluid;
extract_backend(fluid_string, backend, fluid);
if (backend == "REFPROP"){
long ierr = 0, ixflag = 1;
double h0 = 0, s0 = 0, t0 = 0, p0 = 0;
char herr[255], hrf[4];
double x0[1] = {1};
if (reference_state.size() > 3){
if (reference_state == "ASHRAE"){
strcpy(hrf, "ASH");
}
else{
throw ValueError(format("Reference state string [%s] is more than 3 characters long", reference_state.c_str()));
}
}
}
else if (!reference_state.compare("ASHRAE"))
{
HEOS.update(QT_INPUTS, 0, 233.15);
// Get current values for the enthalpy and entropy
double deltah = HEOS.hmass() - 0; // offset from 0 J/kg enthalpy
double deltas = HEOS.smass() - 0; // offset from 0 J/kg/K entropy
double delta_a1 = deltas/(HEOS.gas_constant()/HEOS.molar_mass());
double delta_a2 = -deltah/(HEOS.gas_constant()/HEOS.molar_mass()*HEOS.get_reducing_state().T);
// Change the value in the library for the given fluid
set_fluid_enthalpy_entropy_offset(Ref, delta_a1, delta_a2, "ASHRAE");
if (get_debug_level() > 0){
std::cout << format("set offsets to %g and %g\n", delta_a1, delta_a2);
else{
strcpy(hrf, reference_state.c_str());
}
REFPROP_SETREF(hrf, ixflag, x0, h0, s0, t0, p0, ierr, herr, 3, 255);
}
else if (!reference_state.compare("NBP"))
{
// Saturated liquid boiling point at 1 atmosphere
HEOS.update(PQ_INPUTS, 101325, 0);
else if (backend == "HEOS" || backend == "?"){
CoolProp::HelmholtzEOSMixtureBackend HEOS(std::vector<std::string>(1, fluid));
if (!reference_state.compare("IIR"))
{
HEOS.update(QT_INPUTS, 0, 273.15);
double deltah = HEOS.hmass() - 0; // offset from 0 kJ/kg enthalpy
double deltas = HEOS.smass() - 0; // offset from 0 kJ/kg/K entropy
double delta_a1 = deltas/(HEOS.gas_constant()/HEOS.molar_mass());
double delta_a2 = -deltah/(HEOS.gas_constant()/HEOS.molar_mass()*HEOS.get_reducing_state().T);
// Change the value in the library for the given fluid
set_fluid_enthalpy_entropy_offset(Ref, delta_a1, delta_a2, "NBP");
if (get_debug_level() > 0){
std::cout << format("set offsets to %g and %g\n", delta_a1, delta_a2);
// Get current values for the enthalpy and entropy
double deltah = HEOS.hmass() - 200000; // offset from 200000 J/kg enthalpy
double deltas = HEOS.smass() - 1000; // offset from 1000 J/kg/K entropy
double delta_a1 = deltas/(HEOS.gas_constant()/HEOS.molar_mass());
double delta_a2 = -deltah/(HEOS.gas_constant()/HEOS.molar_mass()*HEOS.get_reducing_state().T);
// Change the value in the library for the given fluid
set_fluid_enthalpy_entropy_offset(fluid, delta_a1, delta_a2, "IIR");
if (get_debug_level() > 0){
std::cout << format("set offsets to %g and %g\n", delta_a1, delta_a2);
}
}
else if (!reference_state.compare("ASHRAE"))
{
HEOS.update(QT_INPUTS, 0, 233.15);
// Get current values for the enthalpy and entropy
double deltah = HEOS.hmass() - 0; // offset from 0 J/kg enthalpy
double deltas = HEOS.smass() - 0; // offset from 0 J/kg/K entropy
double delta_a1 = deltas/(HEOS.gas_constant()/HEOS.molar_mass());
double delta_a2 = -deltah/(HEOS.gas_constant()/HEOS.molar_mass()*HEOS.get_reducing_state().T);
// Change the value in the library for the given fluid
set_fluid_enthalpy_entropy_offset(fluid, delta_a1, delta_a2, "ASHRAE");
if (get_debug_level() > 0){
std::cout << format("set offsets to %g and %g\n", delta_a1, delta_a2);
}
}
else if (!reference_state.compare("NBP"))
{
// Saturated liquid boiling point at 1 atmosphere
HEOS.update(PQ_INPUTS, 101325, 0);
double deltah = HEOS.hmass() - 0; // offset from 0 kJ/kg enthalpy
double deltas = HEOS.smass() - 0; // offset from 0 kJ/kg/K entropy
double delta_a1 = deltas/(HEOS.gas_constant()/HEOS.molar_mass());
double delta_a2 = -deltah/(HEOS.gas_constant()/HEOS.molar_mass()*HEOS.get_reducing_state().T);
// Change the value in the library for the given fluid
set_fluid_enthalpy_entropy_offset(fluid, delta_a1, delta_a2, "NBP");
if (get_debug_level() > 0){
std::cout << format("set offsets to %g and %g\n", delta_a1, delta_a2);
}
}
else if (!reference_state.compare("DEF"))
{
set_fluid_enthalpy_entropy_offset(fluid, 0, 0, "DEF");
}
else if (!reference_state.compare("RESET"))
{
set_fluid_enthalpy_entropy_offset(fluid, 0, 0, "RESET");
}
else
{
throw ValueError(format("reference state string is invalid: [%s]",reference_state.c_str()));
}
}
else if (!reference_state.compare("DEF"))
{
set_fluid_enthalpy_entropy_offset(Ref, 0, 0, "DEF");
}
else if (!reference_state.compare("RESET"))
{
set_fluid_enthalpy_entropy_offset(Ref, 0, 0, "RESET");
}
else
{
throw ValueError(format("reference state string is invalid: [%s]",reference_state.c_str()));
}
}
void set_reference_stateD(const std::string &Ref, double T, double rhomolar, double h0, double s0)