Added hs_anchor test (passing) and function get_state to allow to get access to states stored in the backends

Signed-off-by: Ian Bell <ian.h.bell@gmail.com>
This commit is contained in:
Ian Bell
2014-08-12 21:17:34 +02:00
parent 21f18bf104
commit 8f9c6ca438
10 changed files with 111 additions and 27 deletions

View File

@@ -377,4 +377,30 @@ TEST_CASE("Tests for values from melting lines", "[melting]")
}
}
}
TEST_CASE("Test that hs_anchor enthalpy/entropy agrees with EOS", "[ancillaries]")
{
std::vector<std::string> fluids = strsplit(CoolProp::get_global_param_string("fluids_list"),',');
for (std::size_t i = 0; i < fluids.size(); ++i)
{
shared_ptr<CoolProp::AbstractState> AS(CoolProp::AbstractState::factory("HEOS",fluids[i]));
CoolProp::SimpleState hs_anchor = AS->get_state("hs_anchor");
// See https://groups.google.com/forum/?fromgroups#!topic/catch-forum/mRBKqtTrITU
std::ostringstream ss1;
ss1 << "Check hs_anchor for " << fluids[i];
SECTION(ss1.str(),"")
{
std::string note = "The enthalpy and entropy are hardcoded in the fluid JSON files. They MUST agree with the values calculated by the EOS";
AS->update(CoolProp::DmolarT_INPUTS, hs_anchor.rhomolar, hs_anchor.T);
CAPTURE(hs_anchor.hmolar);
CAPTURE(hs_anchor.smolar);
double EOS_hmolar = AS->hmolar();
double EOS_smolar = AS->smolar();
CHECK( std::abs(EOS_hmolar - hs_anchor.hmolar) < 1e-3);
CHECK( std::abs(EOS_smolar - hs_anchor.smolar) < 1e-3);
}
}
}
#endif

View File

@@ -320,6 +320,7 @@ protected:
/// \todo: define limits of EOS better
EOS.limits.Tmin = cpjson::get_double(satminL_state, "T");
EOS.ptriple = cpjson::get_double(satminL_state, "p");
EOS.Ttriple = EOS.limits.Tmin;
// BibTex keys

View File

@@ -131,6 +131,27 @@ void HelmholtzEOSMixtureBackend::update_states(void)
// Clear again just to be sure
clear();
}
const CoolProp::SimpleState HelmholtzEOSMixtureBackend::calc_state(const std::string &state)
{
if (is_pure_or_pseudopure)
{
if (!state.compare("hs_anchor")){
return components[0]->pEOS->hs_anchor;
}
else if (!state.compare("max_sat_T")){
return components[0]->pEOS->max_sat_T;
}
else if (!state.compare("max_sat_p")){
return components[0]->pEOS->max_sat_p;
}
else{
throw ValueError(format("This state [%s] is invalid to calc_state",state.c_str()));
}
}
else{
throw ValueError(format("calc_state not supported for mixtures"));
}
};
long double HelmholtzEOSMixtureBackend::calc_gas_constant(void)
{
double summer = 0;
@@ -376,6 +397,14 @@ long double HelmholtzEOSMixtureBackend::calc_Ttriple(void)
}
return summer;
}
long double HelmholtzEOSMixtureBackend::calc_p_triple(void)
{
double summer = 0;
for (unsigned int i = 0; i < components.size(); ++i){
summer += mole_fractions[i]*components[i]->pEOS->ptriple;
}
return summer;
}
std::string HelmholtzEOSMixtureBackend::calc_name(void)
{
if (components.size() != 1){
@@ -625,21 +654,21 @@ void HelmholtzEOSMixtureBackend::update(long input_pair, double value1, double v
long double HelmholtzEOSMixtureBackend::calc_Bvirial()
{
return 1/get_reducing().rhomolar*calc_alphar_deriv_nocache(0,1,mole_fractions,_tau,1e-12);
return 1/get_reducing_state().rhomolar*calc_alphar_deriv_nocache(0,1,mole_fractions,_tau,1e-12);
}
long double HelmholtzEOSMixtureBackend::calc_dBvirial_dT()
{
long double dtau_dT =-get_reducing().T/pow(_T,2);
return 1/get_reducing().rhomolar*calc_alphar_deriv_nocache(1,1,mole_fractions,_tau,1e-12)*dtau_dT;
long double dtau_dT =-get_reducing_state().T/pow(_T,2);
return 1/get_reducing_state().rhomolar*calc_alphar_deriv_nocache(1,1,mole_fractions,_tau,1e-12)*dtau_dT;
}
long double HelmholtzEOSMixtureBackend::calc_Cvirial()
{
return 1/pow(get_reducing().rhomolar,2)*calc_alphar_deriv_nocache(0,2,mole_fractions,_tau,1e-12);
return 1/pow(get_reducing_state().rhomolar,2)*calc_alphar_deriv_nocache(0,2,mole_fractions,_tau,1e-12);
}
long double HelmholtzEOSMixtureBackend::calc_dCvirial_dT()
{
long double dtau_dT =-get_reducing().T/pow(_T,2);
return 1/pow(get_reducing().rhomolar,2)*calc_alphar_deriv_nocache(1,2,mole_fractions,_tau,1e-12)*dtau_dT;
long double dtau_dT =-get_reducing_state().T/pow(_T,2);
return 1/pow(get_reducing_state().rhomolar,2)*calc_alphar_deriv_nocache(1,2,mole_fractions,_tau,1e-12)*dtau_dT;
}
void HelmholtzEOSMixtureBackend::p_phase_determination_pure_or_pseudopure(int other, long double value, bool &saturation_called)
{
@@ -738,7 +767,7 @@ void HelmholtzEOSMixtureBackend::p_phase_determination_pure_or_pseudopure(int ot
case iHmolar:
{
// Ancillaries are h-h_anchor, so add back h_anchor
long double h_liq = component.ancillaries.hL.evaluate(_TLanc) + component.EOSVector[0].hs_anchor.hmolar;
long double h_liq = component.ancillaries.hL.evaluate(_TLanc) + component.pEOS->hs_anchor.hmolar;
long double h_liq_error_band = component.ancillaries.hL.get_max_abs_error();
long double h_vap = h_liq + component.ancillaries.hLV.evaluate(_TLanc);
long double h_vap_error_band = h_liq_error_band + component.ancillaries.hLV.get_max_abs_error();
@@ -1211,8 +1240,8 @@ void HelmholtzEOSMixtureBackend::T_phase_determination_pure_or_pseudopure(int ot
void get_dtau_ddelta(HelmholtzEOSMixtureBackend *HEOS, long double T, long double rho, int index, long double &dtau, long double &ddelta)
{
long double rhor = HEOS->get_reducing().rhomolar,
Tr = HEOS->get_reducing().T,
long double rhor = HEOS->get_reducing_state().rhomolar,
Tr = HEOS->get_reducing_state().T,
dT_dtau = -pow(T, 2)/Tr,
R = HEOS->gas_constant(),
delta = rho/rhor,
@@ -1441,8 +1470,8 @@ long double HelmholtzEOSMixtureBackend::solver_rho_Tp(long double T, long double
HelmholtzEOSMixtureBackend *HEOS;
solver_TP_resid(HelmholtzEOSMixtureBackend *HEOS, long double T, long double p){
this->HEOS = HEOS; this->T = T; this->p = p; this->rhor = HEOS->get_reducing().rhomolar;
this->tau = HEOS->get_reducing().T/T; this->R_u = HEOS->gas_constant();
this->HEOS = HEOS; this->T = T; this->p = p; this->rhor = HEOS->get_reducing_state().rhomolar;
this->tau = HEOS->get_reducing_state().T/T; this->R_u = HEOS->gas_constant();
};
double call(double rhomolar){
this->rhomolar = rhomolar;

View File

@@ -48,6 +48,8 @@ public:
bool has_melting_line(){ return is_pure_or_pseudopure && components[0]->ancillaries.melting_line.enabled();};
long double calc_melting_line(int param, int given, long double value);
int calc_phase(void){return _phase;};
const CoolProp::SimpleState calc_state(const std::string &state);
const std::vector<CoolPropFluid*> &get_components(){return components;};
std::vector<long double> &get_K(){return K;};
@@ -141,6 +143,7 @@ public:
long double calc_Tmax(void);
long double calc_pmax(void);
long double calc_Ttriple(void);
long double calc_p_triple(void);
long double calc_pmax_sat(void);
long double calc_Tmax_sat(void);
void calc_Tmin_sat(long double &Tmin_satL, long double &Tmin_satV);

View File

@@ -527,9 +527,9 @@ long double TransportRoutines::conductivity_critical_simplified_Olchowy_Sengers(
GAMMA = data.GAMMA,
zeta0 = data.zeta0,
qD = data.qD,
Tc = HEOS.get_reducing().T, // [K]
rhoc = HEOS.get_reducing().rhomolar, // [mol/m^3]
Pcrit = HEOS.get_reducing().p, // [Pa]
Tc = HEOS.get_reducing_state().T, // [K]
rhoc = HEOS.get_reducing_state().rhomolar, // [mol/m^3]
Pcrit = HEOS.get_reducing_state().p, // [Pa]
Tref, // [K]
cp,cv,delta,num,zeta,mu,pi=M_PI,tau,
OMEGA_tilde,OMEGA_tilde0;

View File

@@ -20,7 +20,7 @@ void SaturationSolvers::saturation_PHSU_pure(HelmholtzEOSMixtureBackend *HEOS, l
std::vector<std::vector<long double> > J(3, std::vector<long double>(3,_HUGE));
HEOS->calc_reducing_state();
const SimpleState & reduce = HEOS->get_reducing();
const SimpleState & reduce = HEOS->get_reducing_state();
shared_ptr<HelmholtzEOSMixtureBackend> SatL = HEOS->SatL,
SatV = HEOS->SatV;
@@ -223,7 +223,7 @@ void SaturationSolvers::saturation_D_pure(HelmholtzEOSMixtureBackend *HEOS, long
std::vector<std::vector<long double> > J(2, std::vector<long double>(2,_HUGE));
HEOS->calc_reducing_state();
const SimpleState & reduce = HEOS->get_reducing();
const SimpleState & reduce = HEOS->get_reducing_state();
shared_ptr<HelmholtzEOSMixtureBackend> SatL = HEOS->SatL,
SatV = HEOS->SatV;
@@ -392,7 +392,7 @@ void SaturationSolvers::saturation_T_pure_Akasaka(HelmholtzEOSMixtureBackend *HE
*/
HEOS->calc_reducing_state();
const SimpleState & reduce = HEOS->get_reducing();
const SimpleState & reduce = HEOS->get_reducing_state();
long double R_u = HEOS->calc_gas_constant();
shared_ptr<HelmholtzEOSMixtureBackend> SatL = HEOS->SatL,
SatV = HEOS->SatV;
@@ -414,7 +414,7 @@ void SaturationSolvers::saturation_T_pure_Akasaka(HelmholtzEOSMixtureBackend *HE
// Use the density ancillary function as the starting point for the solver
// If very close to the critical temp, evaluate the ancillaries for a slightly lower temperature
if (T > 0.99*HEOS->get_reducing().T){
if (T > 0.99*HEOS->get_reducing_state().T){
rhoL = HEOS->get_components()[0]->ancillaries.rhoL.evaluate(T-0.1);
rhoV = HEOS->get_components()[0]->ancillaries.rhoV.evaluate(T-0.1);
}