Implement fugacity through low-level interface; closes #699

This commit is contained in:
Ian Bell
2015-06-30 22:04:08 -06:00
parent 39b1c90004
commit 111371df98
10 changed files with 54 additions and 10 deletions

View File

@@ -431,10 +431,14 @@ double AbstractState::gas_constant(void){
if (!_gas_constant) _gas_constant = calc_gas_constant();
return _gas_constant;
}
double AbstractState::fugacity_coefficient(int i){
double AbstractState::fugacity_coefficient(std::size_t i){
// TODO: Cache the fug. coeff for each component
return calc_fugacity_coefficient(i);
}
double AbstractState::fugacity(std::size_t i){
// TODO: Cache the fug. coeff for each component
return calc_fugacity(i);
}
void AbstractState::build_phase_envelope(const std::string &type)
{
calc_phase_envelope(type);

View File

@@ -2341,11 +2341,16 @@ CoolPropDbl HelmholtzEOSMixtureBackend::calc_gibbsmolar(void)
throw ValueError(format("phase is invalid in calc_gibbsmolar"));
}
}
CoolPropDbl HelmholtzEOSMixtureBackend::calc_fugacity_coefficient(int i)
CoolPropDbl HelmholtzEOSMixtureBackend::calc_fugacity_coefficient(std::size_t i)
{
x_N_dependency_flag xN_flag = XN_DEPENDENT;
return exp(MixtureDerivatives::ln_fugacity_coefficient(*this, i, xN_flag));
}
CoolPropDbl HelmholtzEOSMixtureBackend::calc_fugacity(std::size_t i)
{
x_N_dependency_flag xN_flag = XN_DEPENDENT;
return MixtureDerivatives::fugacity_i(*this, i, xN_flag);
}
CoolPropDbl HelmholtzEOSMixtureBackend::calc_phase_identification_parameter(void)
{
return 2 - rhomolar()*(second_partial_deriv(iP, iDmolar, iT, iT, iDmolar)/first_partial_deriv(iP, iT, iDmolar) - second_partial_deriv(iP, iDmolar, iT, iDmolar, iT)/first_partial_deriv(iP, iDmolar, iT));

View File

@@ -192,8 +192,11 @@ public:
*
*
*/
CoolPropDbl calc_fugacity_coefficient(int i);
CoolPropDbl calc_phase_identification_parameter(void);
CoolPropDbl calc_fugacity(std::size_t i);
CoolPropDbl calc_fugacity_coefficient(std::size_t i);
/// Using this backend, calculate the flame hazard
CoolPropDbl calc_flame_hazard(void){ return components[0].environment.FH;};

View File

@@ -22,8 +22,10 @@ surface tension N/m
#define _CRT_SECURE_NO_WARNINGS
#define REFPROP_IMPLEMENTATION
#define REFPROP_CSTYLE_REFERENCES
#include "REFPROP_lib.h"
#undef REFPROP_IMPLEMENTATION
#undef REFPROP_CSTYLE_REFERENCES
#include "CoolPropTools.h"
#include "REFPROPMixtureBackend.h"
@@ -584,7 +586,7 @@ CoolPropDbl REFPROPMixtureBackend::calc_surface_tension(void)
_surface_tension = sigma;
return static_cast<double>(_surface_tension);
}
CoolPropDbl REFPROPMixtureBackend::calc_fugacity_coefficient(int i)
CoolPropDbl REFPROPMixtureBackend::calc_fugacity_coefficient(std::size_t i)
{
this->check_loaded_fluid();
double rho_mol_L = 0.001*_rhomolar;
@@ -593,12 +595,26 @@ CoolPropDbl REFPROPMixtureBackend::calc_fugacity_coefficient(int i)
fug_cof.resize(mole_fractions.size());
char herr[255];
FUGCOFdll(&_T, &rho_mol_L, &(mole_fractions[0]), // Inputs
&(fug_cof[0]), // Outputs
&ierr, herr, errormessagelength); // Error message
&(fug_cof[0]), // Outputs
&ierr, herr, errormessagelength); // Error message
if (static_cast<int>(ierr) > 0) { throw ValueError(format("%s",herr).c_str()); }
//else if (ierr < 0) {set_warning(format("%s",herr).c_str());}
return static_cast<CoolPropDbl>(fug_cof[i]);
}
CoolPropDbl REFPROPMixtureBackend::calc_fugacity(std::size_t i)
{
this->check_loaded_fluid();
double rho_mol_L = 0.001*_rhomolar;
long ierr = 0;
std::vector<double> f(mole_fractions.size());
char herr[255];
FGCTY2dll(&_T, &rho_mol_L, &(mole_fractions[0]), // Inputs
&(f[0]), // Outputs
&ierr, herr, errormessagelength); // Error message
if (static_cast<int>(ierr) > 0) { throw ValueError(format("%s", herr).c_str()); }
//else if (ierr < 0) {set_warning(format("%s",herr).c_str());}
return static_cast<CoolPropDbl>(f[i]*1000);
}
void REFPROPMixtureBackend::calc_phase_envelope(const std::string &type)
{

View File

@@ -130,7 +130,8 @@ public:
/// Calc the C virial coefficient
CoolPropDbl calc_Cvirial(void);
CoolPropDbl calc_fugacity_coefficient(int i);
CoolPropDbl calc_fugacity_coefficient(std::size_t i);
CoolPropDbl calc_fugacity(std::size_t i);
CoolPropDbl calc_melting_line(int param, int given, CoolPropDbl value);
bool has_melting_line(){return true;};
double calc_melt_Tmax();