mirror of
https://github.com/CoolProp/CoolProp.git
synced 2026-04-23 03:00:17 -04:00
Move predefined mixture parsing to HelmholtzEOS initializer function; Closes #373
Renamed functions for Helmholtz backend for getting const or non-const reference to mole fractions Signed-off-by: Ian Bell <ian.h.bell@gmail.com>
This commit is contained in:
@@ -85,7 +85,7 @@ void FlashRoutines::PT_flash_mixtures(HelmholtzEOSMixtureBackend &HEOS)
|
||||
}
|
||||
|
||||
// Use Rachford-Rice to check whether you are in a homogeneous phase
|
||||
long double g_RR_0 = g_RachfordRice(HEOS.get_const_mole_fractions(), lnK, 0.0L);
|
||||
long double g_RR_0 = g_RachfordRice(HEOS.get_mole_fractions(), lnK, 0.0L);
|
||||
if (g_RR_0 < 0){
|
||||
// Subcooled liquid - done
|
||||
long double rhomolar_guess = HEOS.solver_rho_Tp_SRK(HEOS._T, HEOS._p, iphase_liquid);
|
||||
@@ -95,7 +95,7 @@ void FlashRoutines::PT_flash_mixtures(HelmholtzEOSMixtureBackend &HEOS)
|
||||
return;
|
||||
}
|
||||
else{
|
||||
long double g_RR_1 = g_RachfordRice(HEOS.get_const_mole_fractions(), lnK, 1.0L);
|
||||
long double g_RR_1 = g_RachfordRice(HEOS.get_mole_fractions(), lnK, 1.0L);
|
||||
if (g_RR_1 > 0){
|
||||
// Superheated vapor - done
|
||||
long double rhomolar_guess = HEOS.solver_rho_Tp_SRK(HEOS._T, HEOS._p, iphase_gas);
|
||||
|
||||
@@ -137,8 +137,8 @@ public:
|
||||
*/
|
||||
void set_mole_fractions(const std::vector<long double> &mole_fractions);
|
||||
|
||||
std::vector<long double> &get_mole_fractions(){return mole_fractions;};
|
||||
const std::vector<long double> &get_const_mole_fractions(){return mole_fractions;};
|
||||
const std::vector<long double> &get_mole_fractions(){return mole_fractions;};
|
||||
std::vector<long double> &get_mole_fractions_ref(){return mole_fractions;};
|
||||
|
||||
/** \brief Set the mass fractions
|
||||
*
|
||||
|
||||
@@ -160,7 +160,7 @@ long double MixtureDerivatives::dln_fugacity_dxj__constT_p_xi(HelmholtzEOSMixtur
|
||||
{
|
||||
// This is a term to which some more might be added depending on i and j
|
||||
long double val = dln_fugacity_coefficient_dxj__constT_p_xi(HEOS, i, j, xN_flag);
|
||||
const std::vector<long double> &x = HEOS.get_const_mole_fractions();
|
||||
const std::vector<long double> &x = HEOS.get_mole_fractions();
|
||||
std::size_t N = x.size();
|
||||
if (i == N-1){
|
||||
val += -1/x[N-1];
|
||||
@@ -173,17 +173,17 @@ long double MixtureDerivatives::dln_fugacity_dxj__constT_p_xi(HelmholtzEOSMixtur
|
||||
long double MixtureDerivatives::dln_fugacity_dxj__constT_rho_xi(HelmholtzEOSMixtureBackend &HEOS, std::size_t i, std::size_t j, x_N_dependency_flag xN_flag)
|
||||
{
|
||||
if (xN_flag == XN_INDEPENDENT){throw ValueError("dln_fugacity_dxj__constT_rho_xi only valid for xN_DEPENDENT for now");}
|
||||
long double rhor = HEOS.Reducing->rhormolar(HEOS.get_const_mole_fractions());
|
||||
long double Tr = HEOS.Reducing->Tr(HEOS.get_const_mole_fractions());
|
||||
long double dTrdxj = HEOS.Reducing->dTrdxi__constxj(HEOS.get_const_mole_fractions(),j,xN_flag);
|
||||
long double drhordxj = HEOS.Reducing->drhormolardxi__constxj(HEOS.get_const_mole_fractions(),j,xN_flag);
|
||||
long double rhor = HEOS.Reducing->rhormolar(HEOS.get_mole_fractions());
|
||||
long double Tr = HEOS.Reducing->Tr(HEOS.get_mole_fractions());
|
||||
long double dTrdxj = HEOS.Reducing->dTrdxi__constxj(HEOS.get_mole_fractions(),j,xN_flag);
|
||||
long double drhordxj = HEOS.Reducing->drhormolardxi__constxj(HEOS.get_mole_fractions(),j,xN_flag);
|
||||
|
||||
// These lines are all the same
|
||||
long double line1 = dln_fugacity_i_dtau__constdelta_x(HEOS, i, xN_flag)*1/HEOS.T()*dTrdxj;
|
||||
long double line2 = -dln_fugacity_i_ddelta__consttau_x(HEOS, i, xN_flag)*1/rhor*drhordxj;
|
||||
long double line4 = dalphar_dxi(HEOS, j, xN_flag) + d_ndalphardni_dxj__constdelta_tau_xi(HEOS, i, j, xN_flag);
|
||||
|
||||
const std::vector<long double> &x = HEOS.get_const_mole_fractions();
|
||||
const std::vector<long double> &x = HEOS.get_mole_fractions();
|
||||
std::size_t N = x.size();
|
||||
|
||||
long double line3 = 1/rhor*HEOS.Reducing->drhormolardxi__constxj(x, j, xN_flag) + 1/Tr*HEOS.Reducing->dTrdxi__constxj(x, j, xN_flag);;
|
||||
@@ -675,9 +675,9 @@ TEST_CASE("Mixture derivative checks", "[mixtures],[mixture_derivs]")
|
||||
SECTION(ss7.str(), "")
|
||||
{
|
||||
if (i == z.size()-1){break;}
|
||||
double analytic = rHEOS.Reducing->dTrdxi__constxj(rHEOS.get_const_mole_fractions(), i, xN_flag);
|
||||
double v1 = rHEOS_pluszi.Reducing->Tr(rHEOS_pluszi.get_const_mole_fractions());
|
||||
double v2 = rHEOS_minuszi.Reducing->Tr(rHEOS_minuszi.get_const_mole_fractions());
|
||||
double analytic = rHEOS.Reducing->dTrdxi__constxj(rHEOS.get_mole_fractions(), i, xN_flag);
|
||||
double v1 = rHEOS_pluszi.Reducing->Tr(rHEOS_pluszi.get_mole_fractions());
|
||||
double v2 = rHEOS_minuszi.Reducing->Tr(rHEOS_minuszi.get_mole_fractions());
|
||||
double numeric = (v1 - v2)/(2*dz);
|
||||
double err = std::abs((numeric-analytic)/analytic);
|
||||
CAPTURE(numeric);
|
||||
@@ -689,9 +689,9 @@ TEST_CASE("Mixture derivative checks", "[mixtures],[mixture_derivs]")
|
||||
SECTION(ss8.str(), "")
|
||||
{
|
||||
if (i == z.size()-1){break;}
|
||||
double analytic = rHEOS.Reducing->drhormolardxi__constxj(rHEOS.get_const_mole_fractions(), i, xN_flag);
|
||||
double v1 = rHEOS_pluszi.Reducing->rhormolar(rHEOS_pluszi.get_const_mole_fractions());
|
||||
double v2 = rHEOS_minuszi.Reducing->rhormolar(rHEOS_minuszi.get_const_mole_fractions());
|
||||
double analytic = rHEOS.Reducing->drhormolardxi__constxj(rHEOS.get_mole_fractions(), i, xN_flag);
|
||||
double v1 = rHEOS_pluszi.Reducing->rhormolar(rHEOS_pluszi.get_mole_fractions());
|
||||
double v2 = rHEOS_minuszi.Reducing->rhormolar(rHEOS_minuszi.get_mole_fractions());
|
||||
double numeric = (v1 - v2)/(2*dz);
|
||||
double err = std::abs((numeric-analytic)/analytic);
|
||||
CAPTURE(numeric);
|
||||
@@ -704,8 +704,8 @@ TEST_CASE("Mixture derivative checks", "[mixtures],[mixture_derivs]")
|
||||
{
|
||||
if (i == z.size()-1){break;}
|
||||
double analytic = rHEOS.Reducing->d2Trdxi2__constxj(z, i, xN_flag);
|
||||
double v1 = rHEOS_pluszi.Reducing->dTrdxi__constxj(rHEOS_pluszi.get_const_mole_fractions(), i, xN_flag);
|
||||
double v2 = rHEOS_minuszi.Reducing->dTrdxi__constxj(rHEOS_minuszi.get_const_mole_fractions(), i, xN_flag);
|
||||
double v1 = rHEOS_pluszi.Reducing->dTrdxi__constxj(rHEOS_pluszi.get_mole_fractions(), i, xN_flag);
|
||||
double v2 = rHEOS_minuszi.Reducing->dTrdxi__constxj(rHEOS_minuszi.get_mole_fractions(), i, xN_flag);
|
||||
double numeric = (v1 - v2)/(2*dz);
|
||||
double err = std::abs((numeric-analytic)/analytic);
|
||||
CAPTURE(numeric);
|
||||
@@ -784,9 +784,9 @@ TEST_CASE("Mixture derivative checks", "[mixtures],[mixture_derivs]")
|
||||
SECTION(ss2.str(), "")
|
||||
{
|
||||
if (j == z.size()-1){break;}
|
||||
double analytic = rHEOS.Reducing->d_ndTrdni_dxj__constxi(rHEOS.get_const_mole_fractions(), i, j, xN_flag);
|
||||
double v1 = rHEOS_pluszj.Reducing->ndTrdni__constnj(rHEOS_pluszj.get_const_mole_fractions(), i, xN_flag);
|
||||
double v2 = rHEOS_minuszj.Reducing->ndTrdni__constnj(rHEOS_minuszj.get_const_mole_fractions(), i, xN_flag);
|
||||
double analytic = rHEOS.Reducing->d_ndTrdni_dxj__constxi(rHEOS.get_mole_fractions(), i, j, xN_flag);
|
||||
double v1 = rHEOS_pluszj.Reducing->ndTrdni__constnj(rHEOS_pluszj.get_mole_fractions(), i, xN_flag);
|
||||
double v2 = rHEOS_minuszj.Reducing->ndTrdni__constnj(rHEOS_minuszj.get_mole_fractions(), i, xN_flag);
|
||||
double numeric = (v1 - v2)/(2*dz);
|
||||
double err = std::abs((numeric-analytic)/analytic);
|
||||
CAPTURE(numeric);
|
||||
@@ -798,9 +798,9 @@ TEST_CASE("Mixture derivative checks", "[mixtures],[mixture_derivs]")
|
||||
SECTION(ss4.str(), "")
|
||||
{
|
||||
if (j == z.size()-1){break;}
|
||||
double analytic = rHEOS.Reducing->d_ndrhorbardni_dxj__constxi(rHEOS.get_const_mole_fractions(), i, j, xN_flag);
|
||||
double v1 = rHEOS_pluszj.Reducing->ndrhorbardni__constnj(rHEOS_pluszj.get_const_mole_fractions(), i, xN_flag);
|
||||
double v2 = rHEOS_minuszj.Reducing->ndrhorbardni__constnj(rHEOS_minuszj.get_const_mole_fractions(), i, xN_flag);
|
||||
double analytic = rHEOS.Reducing->d_ndrhorbardni_dxj__constxi(rHEOS.get_mole_fractions(), i, j, xN_flag);
|
||||
double v1 = rHEOS_pluszj.Reducing->ndrhorbardni__constnj(rHEOS_pluszj.get_mole_fractions(), i, xN_flag);
|
||||
double v2 = rHEOS_minuszj.Reducing->ndrhorbardni__constnj(rHEOS_minuszj.get_mole_fractions(), i, xN_flag);
|
||||
double numeric = (v1 - v2)/(2*dz);
|
||||
double err = std::abs((numeric-analytic)/analytic);
|
||||
CAPTURE(numeric);
|
||||
@@ -855,8 +855,8 @@ TEST_CASE("Mixture derivative checks", "[mixtures],[mixture_derivs]")
|
||||
{
|
||||
if (j == z.size()-1 || i == j){break;}
|
||||
double analytic = rHEOS.Reducing->d2Trdxidxj(z, i, j, xN_flag);
|
||||
double v1 = rHEOS.Reducing->dTrdxi__constxj(rHEOS_pluszj.get_const_mole_fractions(), i, xN_flag);
|
||||
double v2 = rHEOS.Reducing->dTrdxi__constxj(rHEOS_minuszj.get_const_mole_fractions(), i, xN_flag);
|
||||
double v1 = rHEOS.Reducing->dTrdxi__constxj(rHEOS_pluszj.get_mole_fractions(), i, xN_flag);
|
||||
double v2 = rHEOS.Reducing->dTrdxi__constxj(rHEOS_minuszj.get_mole_fractions(), i, xN_flag);
|
||||
double numeric = (v1 - v2)/(2*dz);
|
||||
double err = std::abs((numeric-analytic)/analytic);
|
||||
if (std::abs(numeric) < DBL_EPSILON && std::abs(analytic) < DBL_EPSILON){break;}
|
||||
|
||||
@@ -1106,7 +1106,7 @@ void SaturationSolvers::successive_substitution(HelmholtzEOSMixtureBackend &HEOS
|
||||
std::vector<long double> ln_phi_liq, ln_phi_vap;
|
||||
ln_phi_liq.resize(N); ln_phi_vap.resize(N);
|
||||
|
||||
std::vector<long double> &x = HEOS.SatL->get_mole_fractions(), &y = HEOS.SatV->get_mole_fractions();
|
||||
std::vector<long double> &x = HEOS.SatL->get_mole_fractions_ref(), &y = HEOS.SatV->get_mole_fractions_ref();
|
||||
x_and_y_from_K(beta, K, z, x, y);
|
||||
|
||||
HEOS.SatL->specify_phase(iphase_liquid);
|
||||
@@ -1415,8 +1415,7 @@ void SaturationSolvers::newton_raphson_saturation::build_arrays()
|
||||
rSatL.set_mole_fractions(x);
|
||||
rSatV.set_mole_fractions(y);
|
||||
}
|
||||
std::vector<long double> &x = rSatL.get_mole_fractions();
|
||||
std::vector<long double> &y = rSatV.get_mole_fractions();
|
||||
|
||||
if (imposed_variable == newton_raphson_saturation_options::RHOV_IMPOSED){
|
||||
rSatL.update(DmolarT_INPUTS, rhomolar_liq, T);
|
||||
rSatV.update(DmolarT_INPUTS, rhomolar_vap, T);
|
||||
|
||||
@@ -60,6 +60,7 @@ public:
|
||||
@param mole_fractions The vector of mole fractions of the components
|
||||
*/
|
||||
void set_mole_fractions(const std::vector<long double> &mole_fractions);
|
||||
const std::vector<long double> & get_mole_fractions(void){throw NotImplementedError("get_mole_fractions not implemented for this backend");};
|
||||
|
||||
/// Set the mass fractions
|
||||
/**
|
||||
|
||||
@@ -456,6 +456,7 @@ void REFPROPMixtureBackend::set_mole_fractions(const std::vector<long double> &m
|
||||
{
|
||||
this->mole_fractions[i] = static_cast<double>(mole_fractions[i]);
|
||||
}
|
||||
this->mole_fractions_long_double = mole_fractions;
|
||||
_mole_fractions_set = true;
|
||||
}
|
||||
void REFPROPMixtureBackend::set_mass_fractions(const std::vector<long double> &mole_fractions)
|
||||
|
||||
@@ -20,6 +20,7 @@ protected:
|
||||
std::size_t Ncomp;
|
||||
bool _mole_fractions_set;
|
||||
static bool _REFPROP_supported;
|
||||
std::vector<long double> mole_fractions_long_double; // read-only
|
||||
std::vector<double> mole_fractions, mass_fractions;
|
||||
std::vector<double> mole_fractions_liq, mole_fractions_vap;
|
||||
std::vector<std::string> fluid_names;
|
||||
@@ -85,6 +86,8 @@ public:
|
||||
@param mass_fractions The vector of mass fractions of the components
|
||||
*/
|
||||
void set_mass_fractions(const std::vector<long double> &mass_fractions);
|
||||
|
||||
const std::vector<long double> &get_mole_fractions(){return mole_fractions_long_double;};
|
||||
|
||||
void calc_phase_envelope(const std::string &type);
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ class GriddedTableBackend : public AbstractState
|
||||
void update(CoolProp::input_pairs input_pair, double Value1, double Value2){};
|
||||
void set_mole_fractions(const std::vector<long double> &mole_fractions){};
|
||||
void set_mass_fractions(const std::vector<long double> &mass_fractions){};
|
||||
|
||||
const std::vector<long double> & get_mole_fractions(){throw NotImplementedError("get_mole_fractions not implemented for TTSE");};
|
||||
void build_tables(tabular_types type);
|
||||
void load_tables(void);
|
||||
void bounding_curves(void);
|
||||
|
||||
Reference in New Issue
Block a user