10 typedef std::vector<std::vector<double> >
STLMatrix;
25 virtual double Tr(
const std::vector<double> &
x) = 0;
29 virtual double rhorbar(
const std::vector<double> &
x) = 0;
37 virtual double d2rhorbardxidxj(
const std::vector<double> &
x,
int i,
int j) = 0;
39 virtual double d2Trdxidxj(
const std::vector<double> &
x,
int i,
int j) = 0;
80 this->
N = pFluids.size();
85 this->
N = pFluids.size();
87 beta_v.resize(
N,std::vector<double>(
N,0));
88 gamma_v.resize(
N,std::vector<double>(
N,0));
89 beta_T.resize(
N,std::vector<double>(
N,0));
90 gamma_T.resize(
N,std::vector<double>(
N,0));
91 T_c.resize(
N,std::vector<double>(
N,0));
92 v_c.resize(
N,std::vector<double>(
N,0));
93 for (
unsigned int i = 0; i <
N; i++)
95 for (
unsigned int j = 0; j <
N; j++)
97 T_c[i][j] = sqrt(pFluids[i]->reduce.T*pFluids[j]->reduce.T);
98 v_c[i][j] = 1.0/8.0*pow(pow(pFluids[i]->reduce.rhobar, -1.0/3.0)+pow(pFluids[j]->reduce.rhobar, -1.0/3.0),(
int)3);
105 double Tr(
const std::vector<double> &
x);
109 double rhorbar(
const std::vector<double> &
x);
119 double d2Trdxidxj(
const std::vector<double> &
x,
int i,
int j);
124 double c_Y_ij(
int i,
int j, std::vector< std::vector< double> > * beta, std::vector< std::vector< double> > *gamma, std::vector< std::vector< double> > *Y_c);
125 double c_Y_ji(
int j,
int i, std::vector< std::vector< double> > * beta, std::vector< std::vector< double> > *gamma, std::vector< std::vector< double> > *Y_c);
126 double f_Y_ij(
const std::vector<double> &
x,
int i,
int j, std::vector< std::vector< double> > * beta);
128 double dfYkidxi__constxk(
const std::vector<double> &
x,
int k,
int i,std::vector< std::vector< double> > * beta);
129 double dfYikdxi__constxk(
const std::vector<double> &
x,
int i,
int k, std::vector< std::vector< double> > * beta);
130 double d2fYkidxi2__constxk(
const std::vector<double> &
x,
int k,
int i, std::vector< std::vector< double> > * beta);
131 double d2fYikdxi2__constxk(
const std::vector<double> &
x,
int i,
int k, std::vector< std::vector< double> > * beta);
132 double d2fYijdxidxj(
const std::vector<double> &
x,
int i,
int k, std::vector< std::vector< double> > * beta);
164 this->
N = pFluids.size();
190 virtual double phir(
double tau,
double delta) = 0;
191 virtual double dphir_dDelta(
double tau,
double delta) = 0;
194 virtual double dphir_dTau(
double tau,
double delta) = 0;
195 virtual double d2phir_dTau2(
double tau,
double delta) = 0;
219 double phir(
double tau,
double delta);
237 double phir(
double tau,
double delta);
251 std::vector<std::vector<double> >
F;
254 double phir(
double tau,
double delta,
const std::vector<double> &
x);
255 double dphir_dDelta(
double tau,
double delta,
const std::vector<double> &
x);
256 double d2phir_dDelta2(
double tau,
double delta,
const std::vector<double> &
x);
258 double dphir_dTau(
double tau,
double delta,
const std::vector<double> &
x);
259 double d2phir_dTau2(
double tau,
double delta,
const std::vector<double> &
x);
260 double dphir_dxi(
double tau,
double delta,
const std::vector<double> &
x,
unsigned int i);
261 double d2phirdxidxj(
double tau,
double delta,
const std::vector<double> &
x,
unsigned int i,
unsigned int j);
262 double d2phir_dxi_dTau(
double tau,
double delta,
const std::vector<double> &
x,
unsigned int i);
263 double d2phir_dxi_dDelta(
double tau,
double delta,
const std::vector<double> &
x,
unsigned int i);
275 double phir(
double tau,
double delta,
const std::vector<double> &
x);
276 double dphir_dDelta(
double tau,
double delta,
const std::vector<double> &
x);
277 double d2phir_dDelta2(
double tau,
double delta,
const std::vector<double> &
x);
279 double d2phir_dTau2(
double tau,
double delta,
const std::vector<double> &
x);
280 double dphir_dTau(
double tau,
double delta,
const std::vector<double> &
x);
293 std::vector<double>
K,
314 std::vector<double>
K,
323 double call(
double beta,
double T,
double p,
const std::vector<double> &z, std::vector<double> &
K);
378 double call(
double beta,
double T,
double p,
double rhobar_liq,
double rhobar_vap,
const std::vector<double> &z, std::vector<double> &
K,
int spec_index,
double spec_value);
390 void build_arrays(
double beta,
double T,
double p,
const std::vector<double> &z, std::vector<double> &
K,
int spec_index,
double spec_value);
395 std::vector< std::vector<double> >
K,
lnK,
x,
y;
403 const std::vector<double> &
K,
405 const std::vector<double> &
x,
406 const std::vector<double> &
y,
407 const unsigned int N)
409 this->p.push_back(p);
410 this->T.push_back(T);
411 this->
lnT.push_back(log(T));
412 this->
lnp.push_back(log(p));
413 this->rhobar_liq.push_back(rhobar_liq);
414 this->rhobar_vap.push_back(rhobar_vap);
417 this->iS.push_back(iS);
418 for (
unsigned int i = 0; i < N; i++)
420 this->K[i].push_back(K[i]);
421 this->x[i].push_back(x[i]);
422 this->y[i].push_back(y[i]);
423 this->
lnK[i].push_back(log(K[i]));
432 std::vector<double>
K;
434 void build(
double p0,
const std::vector<double> &z,
double beta_envelope);
448 Mixture(std::string FluidsString);
452 double Rbar(
const std::vector<double> &
x);
474 double phir(
double tau,
double delta,
const std::vector<double> &
x);
476 double d2phir_dTau2(
double tau,
double delta,
const std::vector<double> &
x);
477 double dphir_dDelta(
double tau,
double delta,
const std::vector<double> &
x);
478 double d2phir_dDelta2(
double tau,
double delta,
const std::vector<double> &
x);
479 double dphir_dTau(
double tau,
double delta,
const std::vector<double> &
x);
480 double dphir_dxi(
double tau,
double delta,
const std::vector<double> &
x,
int i);
481 double d2phir_dxi_dTau(
double tau,
double delta,
const std::vector<double> &
x,
int i);
482 double d2phir_dxi_dDelta(
double tau,
double delta,
const std::vector<double> &
x,
int i);
483 double d2phirdxidxj(
double tau,
double delta,
const std::vector<double> &
x,
int i,
int j);
486 double fugacity(
double tau,
double delta,
const std::vector<double> &
x,
int i);
494 double rhobar_Tpz(
double T,
double p,
const std::vector<double> &z,
double rhobar0);
504 void TpzFlash(
double T,
double p,
const std::vector<double> &z,
double &rhobar, std::vector<double> &
x, std::vector<double> &y);
514 double g_RachfordRice(
const std::vector<double> &z,
const std::vector<double> &lnK,
double beta);
524 double dgdbeta_RachfordRice(
const std::vector<double> &z,
const std::vector<double> &lnK,
double beta);
554 double dpdT__constV_n(
double tau,
double delta,
const std::vector<double> &
x,
int i);
562 double ndpdV__constT_n(
double tau,
double delta,
const std::vector<double> &
x,
int i);
654 double d2nphir_dni_dT(
double tau,
double delta,
const std::vector<double> &
x,
int i);
664 double d_ndphirdni_dTau(
double tau,
double delta,
const std::vector<double> &
x,
int i);
722 double saturation_p_Wilson(
double beta,
double p,
const std::vector<double> &z,
double T_guess, std::vector<double> &K);
724 double saturation_p(
double beta,
double p,
const std::vector<double> &z, std::vector<double> &
x, std::vector<double> &y);
730 void x_and_y_from_K(
double beta,
const std::vector<double> &K,
const std::vector<double> &z, std::vector<double> &
x, std::vector<double> &y);
double d_ndphirdni_dxj__constdelta_tau_xi(double tau, double delta, const std::vector< double > &x, int i, int j)
double ndtaudni__constT_V_nj(double tau, double delta, const std::vector< double > &x, int i)
std::vector< double > K
K-factor [-].
double rhobar_pengrobinson(double T, double p, const std::vector< double > &x, int solution)
double f_Y_ij(const std::vector< double > &x, int i, int j, std::vector< std::vector< double > > *beta)
double nd2nphirdnidnj__constT_V(double tau, double delta, const std::vector< double > &x, int i, int j)
LemmonAirHFCReducingFunction(std::vector< Fluid * > pFluids)
std::vector< double > phi_ij_vap
double d2phir_dxi_dDelta(double tau, double delta, const std::vector< double > &x, unsigned int i)
virtual ~DepartureFunction()
void build_arrays(double beta, double T, double p, const std::vector< double > &z, std::vector< double > &K, int spec_index, double spec_value)
void set_coeffs_from_map(int i, int j, std::map< std::string, double >)
Set the coefficients based on reducing parameters loaded from JSON.
double dphir_dxi(double tau, double delta, const std::vector< double > &x, int i)
double dphir_dDelta(double tau, double delta, const std::vector< double > &x)
double dln_fugacity_coefficient_dxj__constT_p_xi(double tau, double delta, const std::vector< double > &x, int i, int j)
Gernert Equation 3.115.
double ddelta_dxj__constT_V_xi(double tau, double delta, const std::vector< double > &x, int j)
DepartureFunctionCacheElement dphir_dDelta
double saturation_p_preconditioner(double p, const std::vector< double > &z)
std::vector< Fluid * > pFluids
std::vector< std::vector< double > > K
double rhobar_vap
The molar density of the vapor phase [mol/m^3].
double ndTrdni__constnj(const std::vector< double > &x, int i)
std::vector< double > dXdS
GERG2008ReducingFunction(std::vector< Fluid * > pFluids)
double d2phir_dDelta_dTau(double tau, double delta)
double dphir_dTau(double tau, double delta, const std::vector< double > &x)
double g_RachfordRice(const std::vector< double > &z, const std::vector< double > &lnK, double beta)
double dphir_dTau(double tau, double delta, const std::vector< double > &x)
std::vector< double > lnp
void x_and_y_from_K(double beta, const std::vector< double > &K, const std::vector< double > &z, std::vector< double > &x, std::vector< double > &y)
double d2rhorbardxi2__constxj(const std::vector< double > &x, int i)
GERG2008ReducingFunction(std::vector< Fluid * > pFluids, STLMatrix beta_v, STLMatrix gamma_v, STLMatrix beta_T, STLMatrix gamma_T)
virtual double d2phir_dDelta2(double tau, double delta)=0
double d_ndphirdni_dDelta(double tau, double delta, const std::vector< double > &x, int i)
double d2fYijdxidxj(const std::vector< double > &x, int i, int k, std::vector< std::vector< double > > *beta)
double ndln_fugacity_coefficient_dnj__constT_p(double tau, double delta, const std::vector< double > &x, int i, int j)
Set the coefficients based on reducing parameters loaded from JSON void set_coeffs_from_map(int i, int j, std::map< std::string, double >)
Set the coefficients based on reducing parameters loaded from JSON.
ReducingFunction * pReducing
double saturation_p(double beta, double p, const std::vector< double > &z, std::vector< double > &x, std::vector< double > &y)
std::vector< double > rhobar_vap
double d_ndphirdni_dxj__constT_V_xi(double tau, double delta, const std::vector< double > &x, int i, int j)
double dvrbardxi__constxj(const std::vector< double > &x, int i)
virtual double d2rhorbardxidxj(const std::vector< double > &x, int i, int j)=0
double d2phir_dDelta2(double tau, double delta, const std::vector< double > &x)
phir_GERG2008_gaussian phi2
SuccessiveSubstitutionVLE()
double dtau_dxj__constT_V_xi(double tau, double delta, const std::vector< double > &x, int j)
double d2phir_dDelta2(double tau, double delta)
virtual double d2phir_dTau2(double tau, double delta)=0
double c_Y_ij(int i, int j, std::vector< std::vector< double > > *beta, std::vector< std::vector< double > > *gamma, std::vector< std::vector< double > > *Y_c)
double d_ndTrdni_dxj__constxi(const std::vector< double > &x, int i, int j)
double dnphir_dni__constT_V_nj(double tau, double delta, const std::vector< double > &x, int i)
bool logging
If true (default is false), intermediate steps will be stored for each call in the step_logger struct...
std::vector< double > ln_phi_vap
Natural logarithm of fugacity coeff. in vapor phase [-].
double ndrhorbardni__constnj(const std::vector< double > &x, int i)
double d2phir_dTau2(double tau, double delta, const std::vector< double > &x)
SuccessiveSubstitutionVLE SS
virtual double rhorbar(const std::vector< double > &x)=0
The molar reducing density.
~GERG2008DepartureFunction()
DepartureFunctionCacheElement dphir_dTau
double nddeltadni__constT_V_nj(double tau, double delta, const std::vector< double > &x, int i)
double fugacity(double tau, double delta, const std::vector< double > &x, int i)
Returns the fugacity for the given component for the given total reduced density and reciprocal reduc...
double d2vrbardxi2__constxj(const std::vector< double > &x, int i)
double d2nphir_dni_dT(double tau, double delta, const std::vector< double > &x, int i)
std::vector< double > lnrhobar_liq
std::vector< std::vector< double > > lnK
double d2nphir_dni_dxj__constT_V(double tau, double delta, const std::vector< double > &x, int i, int j)
Gernert Equation 3.117.
double dgdbeta_RachfordRice(const std::vector< double > &z, const std::vector< double > &lnK, double beta)
Mixture * Mix
Pointer to the Mixture class instance.
int Nstep_max
The maximum number of steps to take, can be changed as needed.
double d2phir_dDelta2(double tau, double delta, const std::vector< double > &x)
std::vector< std::vector< double > > F
std::vector< std::vector< DepartureFunction * > > DepartureFunctionMatrix
virtual double d2phir_dDelta_dTau(double tau, double delta)=0
double phir(double tau, double delta, const std::vector< double > &x)
ResidualIdealMixture(std::vector< Fluid * > pFluids)
std::vector< std::vector< double > > y
double dphir_dTau(double tau, double delta)
double d2phir_dTau2(double tau, double delta)
void check_WaterEthanol()
The derivative of reduced temperature with respect to component i mole fraction double dTrdxi__constxj(const std::vector< double > &x, int i)
The derivative of reduced temperature with respect to component i mole fraction.
double d2Trdxidxj(const std::vector< double > &x, int i, int j)
void build(double p0, const std::vector< double > &z, double beta_envelope)
double dln_fugacity_coefficient_dp__constT_n(double tau, double delta, const std::vector< double > &x, int i)
std::vector< double > lnK
Natural logarithm of K-factor [-].
double d2phir_dTau2(double tau, double delta)
void resize(unsigned int N)
virtual double phir(double tau, double delta)=0
double dphir_dDelta(double tau, double delta)
double dpdT__constV_n(double tau, double delta, const std::vector< double > &x, int i)
double d2phir_dDelta_dTau(double tau, double delta)
virtual void set_coeffs_from_map(int i, int j, std::map< std::string, double >)=0
Set the coefficients based on reducing parameters loaded from JSON.
DepartureFunctionCache cache
virtual ~ReducingFunction()
double rhobar_liq
The molar density of the liquid phase [mol/m^3].
double dfYikdxi__constxk(const std::vector< double > &x, int i, int k, std::vector< std::vector< double > > *beta)
std::vector< std::vector< double > > STLMatrix
STLMatrix gamma_T
from GERG-2008
double Wilson_lnK_factor(double T, double p, int i)
std::vector< SuccessiveSubstitutionStep > step_logger
void TpzFlash(double T, double p, const std::vector< double > &z, double &rhobar, std::vector< double > &x, std::vector< double > &y)
std::vector< double > ln_phi_liq
void store_variables(const double T, const double p, const double rhobar_liq, const double rhobar_vap, const std::vector< double > &K, const int iS, const std::vector< double > &x, const std::vector< double > &y, const unsigned int N)
std::map< std::string, double > load_reducing_values(int i, int j)
virtual double Tr(const std::vector< double > &x)=0
The reduced temperature.
~LemmonHFCDepartureFunction()
double d2fYkidxi2__constxk(const std::vector< double > &x, int k, int i, std::vector< std::vector< double > > *beta)
std::vector< double > x(ncmax, 0)
double dphir_dDelta(double tau, double delta, const std::vector< double > &x)
double dphir_dTau(double tau, double delta)
std::vector< double > ln_phi_liq
Natural logarithm of fugacity coeff. in liq. phase [-].
double ndpdV__constT_n(double tau, double delta, const std::vector< double > &x, int i)
ResidualIdealMixture * pResidualIdealMix
DepartureFunctionCache cache
double d2phir_dDelta2(double tau, double delta)
std::vector< Fluid * > pFluids
double d2phir_dDelta_dTau(double tau, double delta, const std::vector< double > &x)
std::vector< double > lnT
double d2phir_dTau2(double tau, double delta, const std::vector< double > &x)
double phir(double tau, double delta)
double d_dphirddelta_dxj__constT_V_xi(double tau, double delta, const std::vector< double > &x, int j)
DepartureFunctionCacheElement d2phir_dTau2
double rhobar_Tpz(double T, double p, const std::vector< double > &z, double rhobar0)
double dphir_dxi(double tau, double delta, const std::vector< double > &x, unsigned int i)
double Rbar(const std::vector< double > &x)
GERG2008DepartureFunction()
double ndpdni__constT_V_nj(double tau, double delta, const std::vector< double > &x, int i)
std::vector< double > rhobar_liq
virtual double drhorbardxi__constxj(const std::vector< double > &x, int i)=0
Derivative of the molar reducing density with respect to component i mole fraction.
double dln_fugacity_coefficient_dT__constp_n(double tau, double delta, const std::vector< double > &x, int i)
std::vector< double > lnrhobar_vap
double d2phir_dDelta_dTau(double tau, double delta, const std::vector< double > &x)
virtual double d2Trdxidxj(const std::vector< double > &x, int i, int j)=0
void set_coeffs_from_map(std::map< std::string, std::vector< double > >)
double d2vrbardxidxj(const std::vector< double > &x, int i, int j)
double d2Trdxi2__constxj(const std::vector< double > &x, int i)
void to_python_files(std::string fname)
virtual double dTrdxi__constxj(const std::vector< double > &x, int i)=0
The derivative of reduced temperature with respect to component i mole fraction.
virtual double dphir_dTau(double tau, double delta)=0
double d2phir_dDelta2(double tau, double delta, const std::vector< double > &x)
std::vector< Fluid * > pFluids
List of pointers to fluids.
double dfYkidxi__constxk(const std::vector< double > &x, int k, int i, std::vector< std::vector< double > > *beta)
DepartureFunctionCacheElement d2phir_dDelta2
double d_ndphirdni_dTau(double tau, double delta, const std::vector< double > &x, int i)
double dpdxj__constT_V_xi(double tau, double delta, const std::vector< double > &x, int j)
double dphir_dDelta(double tau, double delta, const std::vector< double > &x)
void load_excess_values(int i, int j)
std::vector< SuccessiveSubstitutionStep > step_logger
double d2phirdxidxj(double tau, double delta, const std::vector< double > &x, int i, int j)
std::vector< double > neg_dFdS
double d2phir_dxi_dTau(double tau, double delta, const std::vector< double > &x, int i)
double dphir_dTau(double tau, double delta, const std::vector< double > &x)
double partial_molar_volume(double tau, double delta, const std::vector< double > &x, int i)
STLMatrix beta_T
from GERG-2008
std::vector< double > phi_ij_liq
The reduced temperature double Tr(const std::vector< double > &x)
The reduced temperature.
double dln_fugacity_coefficient_dT__constrho(double tau, double delta, const std::vector< double > &x, int i)
LemmonHFCDepartureFunction()
double d2rhorbardxidxj(const std::vector< double > &x, int i, int j)
DepartureFunctionCacheElement phir
double d2phir_dDelta_dTau(double tau, double delta, const std::vector< double > &x)
void set_coeffs_from_map(std::map< std::string, std::vector< double > >)
double saturation_p_Wilson(double beta, double p, const std::vector< double > &z, double T_guess, std::vector< double > &K)
double phir(double tau, double delta, const std::vector< double > &x)
int Nsteps
How many steps were taken to yield tolerance.
Mixture(std::vector< Fluid * > pFluids)
double d2fYikdxi2__constxk(const std::vector< double > &x, int i, int k, std::vector< std::vector< double > > *beta)
STLMatrix beta_v
from GERG-2008
void check_MethaneEthane()
void set_coeffs_from_map(int i, int j, std::map< std::string, std::vector< double > >)
std::vector< Fluid * > pFluids
List of pointers to fluids.
double call(double beta, double T, double p, double rhobar_liq, double rhobar_vap, const std::vector< double > &z, std::vector< double > &K, int spec_index, double spec_value)
STLMatrix gamma_v
from GERG-2008
double d_ndrhorbardni_dxj__constxi(const std::vector< double > &x, int i, int j)
virtual double dphir_dDelta(double tau, double delta)=0
double call(double beta, double T, double p, const std::vector< double > &z, std::vector< double > &K)
double c_Y_ji(int j, int i, std::vector< std::vector< double > > *beta, std::vector< std::vector< double > > *gamma, std::vector< std::vector< double > > *Y_c)
double d2phir_dTau2(double tau, double delta, const std::vector< double > &x)
double phir(double tau, double delta)
double phir(double tau, double delta, const std::vector< double > &x)
virtual double d2rhorbardxi2__constxj(const std::vector< double > &x, int i)=0
std::vector< std::vector< double > > x
The molar reducing density double rhorbar(const std::vector< double > &x)
The molar reducing density.
Derivative of the molar reducing density with respect to component i mole fraction double drhorbardxi__constxj(const std::vector< double > &x, int i)
Derivative of the molar reducing density with respect to component i mole fraction.
double d2phirdxidxj(double tau, double delta, const std::vector< double > &x, unsigned int i, unsigned int j)
virtual void set_coeffs_from_map(std::map< std::string, std::vector< double > >)=0
double dphir_dxj__constT_V_xi(double tau, double delta, const std::vector< double > &x, int j)
double d2phir_dxi_dDelta(double tau, double delta, const std::vector< double > &x, int i)
virtual double d2Trdxi2__constxj(const std::vector< double > &x, int i)=0
double dphir_dDelta(double tau, double delta)
double ln_fugacity_coefficient(double tau, double delta, const std::vector< double > &x, int i)
bool useNR
If true (default is false), will call Newton-Raphson after either solving to tolerance, or taking Nmax steps.
double ndphir_dni__constT_V_nj(double tau, double delta, const std::vector< double > &x, int i)
double d2phir_dxi_dTau(double tau, double delta, const std::vector< double > &x, unsigned int i)
DepartureFunctionCacheElement d2phir_dDelta_dTau
Default destructor ~GERG2008ReducingFunction()
std::vector< double > ln_phi_vap