CoolProp  4.2.5
An open-source fluid property and humid air property database
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Mixtures.h
Go to the documentation of this file.
1 #ifndef MIXTURES_H
2 #define MIXTURES_H
3 
4 #include "Helmholtz.h"
5 #include "FluidClass.h"
6 
7 #include <vector>
8 #include <string>
9 
10 typedef std::vector<std::vector<double> > STLMatrix;
11 
18 {
19 protected:
20  unsigned int N;
21 public:
23  virtual ~ReducingFunction(){};
25  virtual double Tr(const std::vector<double> &x) = 0;
27  virtual double dTrdxi__constxj(const std::vector<double> &x, int i) = 0;
29  virtual double rhorbar(const std::vector<double> &x) = 0;
31  virtual double drhorbardxi__constxj(const std::vector<double> &x, int i) = 0;
32 
34  virtual void set_coeffs_from_map(int i, int j, std::map<std::string,double >) = 0;
35 
36  virtual double d2rhorbardxi2__constxj(const std::vector<double> &x, int i) = 0;
37  virtual double d2rhorbardxidxj(const std::vector<double> &x, int i, int j) = 0;
38  virtual double d2Trdxi2__constxj(const std::vector<double> &x, int i) = 0;
39  virtual double d2Trdxidxj(const std::vector<double> &x, int i, int j) = 0;
40 
46  double d_ndTrdni_dxj__constxi(const std::vector<double> &x, int i, int j);
52  double d_ndrhorbardni_dxj__constxi(const std::vector<double> &x, int i, int j);
53 
54  double ndrhorbardni__constnj(const std::vector<double> &x, int i);
55  double ndTrdni__constnj(const std::vector<double> &x, int i);
56 };
57 
63 {
64 protected:
71  std::vector<Fluid *> pFluids;
72 public:
74  {
75  this->pFluids = pFluids;
76  this->beta_v = beta_v;
77  this->gamma_v = gamma_v;
78  this->beta_T = beta_T;
79  this->gamma_T = gamma_T;
80  this->N = pFluids.size();
81  };
82  GERG2008ReducingFunction(std::vector<Fluid *> pFluids)
83  {
84  this->pFluids = pFluids;
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++)
94  {
95  for (unsigned int j = 0; j < N; j++)
96  {
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);
99  }
100  }
101  };
105  double Tr(const std::vector<double> &x);
107  double dTrdxi__constxj(const std::vector<double> &x, int i);
109  double rhorbar(const std::vector<double> &x);
111  double drhorbardxi__constxj(const std::vector<double> &x, int i);
112  double dvrbardxi__constxj(const std::vector<double> &x, int i);
113 
114  double d2vrbardxi2__constxj(const std::vector<double> &x, int i);
115  double d2rhorbardxi2__constxj(const std::vector<double> &x, int i);
116  double d2vrbardxidxj(const std::vector<double> &x, int i, int j);
117  double d2rhorbardxidxj(const std::vector<double> &x, int i, int j);
118  double d2Trdxi2__constxj(const std::vector<double> &x, int i);
119  double d2Trdxidxj(const std::vector<double> &x, int i, int j);
120 
122  void set_coeffs_from_map(int i, int j, std::map<std::string,double >);
123 
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);
127 
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);
133 };
134 
157 {
158 protected:
159  std::vector<Fluid *> pFluids;
160 public:
162  {
163  this->pFluids = pFluids;
164  this->N = pFluids.size();
165  };
166 
168  void set_coeffs_from_map(int i, int j, std::map<std::string,double >);
169 
170 };
171 
172 
173 
174 
175 
176 
177 
178 
183 {
184 public:
186  virtual ~DepartureFunction(){};
187 
190  virtual double phir(double tau, double delta) = 0;
191  virtual double dphir_dDelta(double tau, double delta) = 0;
192  virtual double d2phir_dDelta2(double tau, double delta) = 0;
193  virtual double d2phir_dDelta_dTau(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;
196  virtual void set_coeffs_from_map(std::map<std::string,std::vector<double> >) = 0;
197 };
198 
200 {
201  double tau, delta, cached_val;
202 };
203 
205 {
207 };
208 
210 {
211 protected:
216 public:
219  double phir(double tau, double delta);
220  double dphir_dDelta(double tau, double delta);
221  double d2phir_dDelta_dTau(double tau, double delta);
222  double dphir_dTau(double tau, double delta);
223  double d2phir_dDelta2(double tau, double delta);
224  double d2phir_dTau2(double tau, double delta);
225  void set_coeffs_from_map(std::map<std::string,std::vector<double> >);
226 };
227 
229 {
230 protected:
234 public:
237  double phir(double tau, double delta);
238  double dphir_dDelta(double tau, double delta);
239  double d2phir_dDelta_dTau(double tau, double delta);
240  double dphir_dTau(double tau, double delta);
241  double d2phir_dDelta2(double tau, double delta);
242  double d2phir_dTau2(double tau, double delta);
243  void set_coeffs_from_map(std::map<std::string,std::vector<double> >);
244 };
245 
247 {
248 public:
249  unsigned int N;
250  std::vector<std::vector<DepartureFunction*> > DepartureFunctionMatrix;
251  std::vector<std::vector<double> > F;
252  ExcessTerm(int N);
253  ~ExcessTerm();
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);
257  double d2phir_dDelta_dTau(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);
264  void set_coeffs_from_map(int i, int j, std::map<std::string,std::vector<double> >);
265 };
266 
267 
269 {
270 protected:
271  unsigned int N;
272  std::vector<Fluid*> pFluids;
273 public:
274  ResidualIdealMixture(std::vector<Fluid*> pFluids);
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);
278  double d2phir_dDelta_dTau(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);
281 };
282 
283 class Mixture; // Forward declaration since some classes that are members of Mixture take pointers to Mixture
284 
290 {
291  double T,
292  p;
293  std::vector<double> K,
294  lnK,
295  ln_phi_liq,
296  ln_phi_vap;
297 };
298 
305 {
306 public:
307  bool useNR;
308  bool logging;
309  int Nsteps;
310  int Nstep_max;
312  double rhobar_liq,
313  rhobar_vap;
314  std::vector<double> K,
315  ln_phi_liq,
316  ln_phi_vap,
317  x,
318  y;
319  std::vector<SuccessiveSubstitutionStep> step_logger;
320 
321  SuccessiveSubstitutionVLE(){useNR = false; logging = false; Nstep_max = 10;};
322 
323  double call(double beta, double T, double p, const std::vector<double> &z, std::vector<double> &K);
324 };
325 
332 {
333 public:
335  unsigned int N;
336  bool logging;
337  int Nsteps;
341  std::vector<double> K, x, y, phi_ij_liq, phi_ij_vap, r, dXdS, neg_dFdS;
342  std::vector<SuccessiveSubstitutionStep> step_logger;
343 
345 
346  void resize(unsigned int N);
347 
348  // Reset the state of all the internal variables
349  void pre_call()
350  {
351  K.clear();
352  x.clear();
353  y.clear();
354  phi_ij_liq.clear();
355  phi_ij_vap.clear();
356  Nsteps = 0;
357  step_logger.clear();
358  error_rms = 1e99;
359  rhobar_liq = _HUGE;
360  rhobar_vap = _HUGE;
361  T = _HUGE;
362  p = _HUGE;
363  };
364 
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);
379 
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);
391 };
392 
394 {
395  std::vector< std::vector<double> > K, lnK, x, y;
396  std::vector<double> T, p, lnT, lnp, rhobar_liq, rhobar_vap, lnrhobar_liq, lnrhobar_vap;
397  std::vector<int> iS;
398 
399  void store_variables(const double T,
400  const double p,
401  const double rhobar_liq,
402  const double rhobar_vap,
403  const std::vector<double> & K,
404  const int iS,
405  const std::vector<double> & x,
406  const std::vector<double> & y,
407  const unsigned int N)
408  {
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);
415  this->lnrhobar_liq.push_back(log(rhobar_liq));
416  this->lnrhobar_vap.push_back(log(rhobar_vap));
417  this->iS.push_back(iS);
418  for (unsigned int i = 0; i < N; i++)
419  {
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]));
424  }
425  };
426 };
428 {
429 public:
432  std::vector<double> K;
434  void build(double p0, const std::vector<double> &z, double beta_envelope);
435  void to_python_files(std::string fname);
436 };
437 
441 class Mixture
442 {
443 
444 public:
445 
446  unsigned int N;
447  Mixture(std::vector<Fluid *> pFluids);
448  Mixture(std::string FluidsString);
449  ~Mixture();
450  void initialize();
451 
452  double Rbar(const std::vector<double> &x);
453 
454  std::vector<Fluid *> pFluids;
458 
460 
463 
472  double Wilson_lnK_factor(double T, double p, int i);
473 
474  double phir(double tau, double delta, const std::vector<double> &x);
475  double d2phir_dDelta_dTau(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);
484 
486  double fugacity(double tau, double delta, const std::vector<double> &x, int i);
487 
494  double rhobar_Tpz(double T, double p, const std::vector<double> &z, double rhobar0);
495 
504  void TpzFlash(double T, double p, const std::vector<double> &z, double &rhobar, std::vector<double> &x, std::vector<double> &y);
505 
514  double g_RachfordRice(const std::vector<double> &z, const std::vector<double> &lnK, double beta);
515 
524  double dgdbeta_RachfordRice(const std::vector<double> &z, const std::vector<double> &lnK, double beta);
525 
538  double ndphir_dni__constT_V_nj(double tau, double delta, const std::vector<double> &x, int i);
539 
546  double partial_molar_volume(double tau, double delta, const std::vector<double> &x, int i);
547 
554  double dpdT__constV_n(double tau, double delta, const std::vector<double> &x, int i);
555 
562  double ndpdV__constT_n(double tau, double delta, const std::vector<double> &x, int i);
563 
570  double ndpdni__constT_V_nj(double tau, double delta, const std::vector<double> &x, int i);
571 
575  double ln_fugacity_coefficient(double tau, double delta, const std::vector<double> &x, int i);
576 
580  double dln_fugacity_coefficient_dT__constrho(double tau, double delta, const std::vector<double> &x, int i);
581 
588  double dln_fugacity_coefficient_dT__constp_n(double tau, double delta, const std::vector<double> &x, int i);
589 
590  // GERG Equation 7.42
591  double dnphir_dni__constT_V_nj(double tau, double delta, const std::vector<double> &x, int i);
592 
599  double dln_fugacity_coefficient_dp__constT_n(double tau, double delta, const std::vector<double> &x, int i);
600 
611  double ndln_fugacity_coefficient_dnj__constT_p(double tau, double delta, const std::vector<double> &x, int i, int j);
612 
613 
615  // Catch test provided
616  double dln_fugacity_coefficient_dxj__constT_p_xi(double tau, double delta, const std::vector<double> &x, int i, int j);
617 
620  double dpdxj__constT_V_xi(double tau, double delta, const std::vector<double> &x, int j);
621 
623  double d2nphir_dni_dxj__constT_V(double tau, double delta, const std::vector<double> &x, int i, int j);
624 
627  double dphir_dxj__constT_V_xi(double tau, double delta, const std::vector<double> &x, int j);
628 
631  double d_ndphirdni_dxj__constT_V_xi(double tau, double delta, const std::vector<double> &x, int i, int j);
632 
635  double d_dphirddelta_dxj__constT_V_xi(double tau, double delta, const std::vector<double> &x, int j);
636 
639  double ddelta_dxj__constT_V_xi(double tau, double delta, const std::vector<double> &x, int j);
640 
643  double dtau_dxj__constT_V_xi(double tau, double delta, const std::vector<double> &x, int j);
644 
654  double d2nphir_dni_dT(double tau, double delta, const std::vector<double> &x, int i);
655 
664  double d_ndphirdni_dTau(double tau, double delta, const std::vector<double> &x, int i);
665 
674  double d_ndphirdni_dDelta(double tau, double delta, const std::vector<double> &x, int i);
675 
692  double nd2nphirdnidnj__constT_V(double tau, double delta, const std::vector<double> &x, int i, int j);
693 
700  double nddeltadni__constT_V_nj(double tau, double delta, const std::vector<double> &x, int i);
707  double ndtaudni__constT_V_nj(double tau, double delta, const std::vector<double> &x, int i);
708 
718  double d_ndphirdni_dxj__constdelta_tau_xi(double tau, double delta, const std::vector<double> &x, int i, int j);
719 
720  double saturation_p_preconditioner(double p, const std::vector<double> &z);
721 
722  double saturation_p_Wilson(double beta, double p, const std::vector<double> &z, double T_guess, std::vector<double> &K);
723 
724  double saturation_p(double beta, double p, const std::vector<double> &z, std::vector<double> &x, std::vector<double> &y);
725 
728  double rhobar_pengrobinson(double T, double p, const std::vector<double> &x, int solution);
729 
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);
731 
732 
737  void load_excess_values(int i, int j);
738 
743  std::map<std::string, double> load_reducing_values(int i, int j);
744 
745  void check_MethaneEthane();
746  void check_WaterEthanol();
747 
748  void test();
749 };
750 
751 
752 
753 #endif
754 
755 
double d_ndphirdni_dxj__constdelta_tau_xi(double tau, double delta, const std::vector< double > &x, int i, int j)
Definition: Mixtures.cpp:1124
double ndtaudni__constT_V_nj(double tau, double delta, const std::vector< double > &x, int i)
Definition: Mixtures.cpp:1119
std::vector< double > K
K-factor [-].
Definition: Mixtures.h:293
double rhobar_pengrobinson(double T, double p, const std::vector< double > &x, int solution)
Definition: Mixtures.cpp:1493
double f_Y_ij(const std::vector< double > &x, int i, int j, std::vector< std::vector< double > > *beta)
Definition: Mixtures.cpp:1724
double nd2nphirdnidnj__constT_V(double tau, double delta, const std::vector< double > &x, int i, int j)
Definition: Mixtures.cpp:1141
LemmonAirHFCReducingFunction(std::vector< Fluid * > pFluids)
Definition: Mixtures.h:161
std::vector< double > phi_ij_vap
Definition: Mixtures.h:341
Mixture * Mix
Definition: Mixtures.h:339
double d2phir_dxi_dDelta(double tau, double delta, const std::vector< double > &x, unsigned int i)
Definition: Mixtures.cpp:2202
virtual ~DepartureFunction()
Definition: Mixtures.h:186
void build_arrays(double beta, double T, double p, const std::vector< double > &z, std::vector< double > &K, int spec_index, double spec_value)
Definition: Mixtures.cpp:2485
void set_coeffs_from_map(int i, int j, std::map< std::string, double >)
Set the coefficients based on reducing parameters loaded from JSON.
Definition: Mixtures.cpp:2062
double dphir_dxi(double tau, double delta, const std::vector< double > &x, int i)
Definition: Mixtures.cpp:1198
double dphir_dDelta(double tau, double delta, const std::vector< double > &x)
Definition: Mixtures.cpp:2119
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.
Definition: Mixtures.cpp:999
double ddelta_dxj__constT_V_xi(double tau, double delta, const std::vector< double > &x, int j)
Definition: Mixtures.cpp:1044
DepartureFunctionCacheElement dphir_dDelta
Definition: Mixtures.h:206
double saturation_p_preconditioner(double p, const std::vector< double > &z)
Definition: Mixtures.cpp:1329
std::vector< Fluid * > pFluids
Definition: Mixtures.h:454
std::vector< std::vector< double > > K
Definition: Mixtures.h:395
double rhobar_vap
The molar density of the vapor phase [mol/m^3].
Definition: Mixtures.h:312
double ndTrdni__constnj(const std::vector< double > &x, int i)
Definition: Mixtures.cpp:2305
std::vector< double > dXdS
Definition: Mixtures.h:341
GERG2008ReducingFunction(std::vector< Fluid * > pFluids)
Definition: Mixtures.h:82
double d2phir_dDelta_dTau(double tau, double delta)
Definition: Mixtures.cpp:2003
double dphir_dTau(double tau, double delta, const std::vector< double > &x)
Definition: Mixtures.cpp:2107
double g_RachfordRice(const std::vector< double > &z, const std::vector< double > &lnK, double beta)
Definition: Mixtures.cpp:1547
double dphir_dTau(double tau, double delta, const std::vector< double > &x)
Definition: Mixtures.cpp:2260
std::vector< double > lnp
Definition: Mixtures.h:396
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)
Definition: Mixtures.cpp:1482
double d2rhorbardxi2__constxj(const std::vector< double > &x, int i)
Definition: Mixtures.cpp:1675
GERG2008ReducingFunction(std::vector< Fluid * > pFluids, STLMatrix beta_v, STLMatrix gamma_v, STLMatrix beta_T, STLMatrix gamma_T)
Definition: Mixtures.h:73
virtual double d2phir_dDelta2(double tau, double delta)=0
double d_ndphirdni_dDelta(double tau, double delta, const std::vector< double > &x, int i)
Definition: Mixtures.cpp:1154
double d2fYijdxidxj(const std::vector< double > &x, int i, int k, std::vector< std::vector< double > > *beta)
Definition: Mixtures.cpp:1739
double ndln_fugacity_coefficient_dnj__constT_p(double tau, double delta, const std::vector< double > &x, int i, int j)
Definition: Mixtures.cpp:1108
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.
Definition: Mixtures.cpp:1746
ReducingFunction * pReducing
Definition: Mixtures.h:455
double saturation_p(double beta, double p, const std::vector< double > &z, std::vector< double > &x, std::vector< double > &y)
Definition: Mixtures.cpp:1363
unsigned int N
Definition: Mixtures.h:446
std::vector< double > rhobar_vap
Definition: Mixtures.h:396
double d_ndphirdni_dxj__constT_V_xi(double tau, double delta, const std::vector< double > &x, int i, int j)
Definition: Mixtures.cpp:1037
double dvrbardxi__constxj(const std::vector< double > &x, int i)
Definition: Mixtures.cpp:1629
virtual double d2rhorbardxidxj(const std::vector< double > &x, int i, int j)=0
NewtonRaphsonVLE NRVLE
Definition: Mixtures.h:462
double d2phir_dDelta2(double tau, double delta, const std::vector< double > &x)
Definition: Mixtures.cpp:1218
phir_GERG2008_gaussian phi2
Definition: Mixtures.h:215
double dtau_dxj__constT_V_xi(double tau, double delta, const std::vector< double > &x, int j)
Definition: Mixtures.cpp:1050
double d2phir_dDelta2(double tau, double delta)
Definition: Mixtures.cpp:1822
std::vector< int > iS
Definition: Mixtures.h:397
virtual double d2phir_dTau2(double tau, double delta)=0
~Mixture()
Definition: Mixtures.cpp:919
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)
Definition: Mixtures.cpp:1716
double d_ndTrdni_dxj__constxi(const std::vector< double > &x, int i, int j)
Definition: Mixtures.cpp:2278
double dnphir_dni__constT_V_nj(double tau, double delta, const std::vector< double > &x, int i)
Definition: Mixtures.cpp:960
bool logging
If true (default is false), intermediate steps will be stored for each call in the step_logger struct...
Definition: Mixtures.h:308
std::vector< double > ln_phi_vap
Natural logarithm of fugacity coeff. in vapor phase [-].
Definition: Mixtures.h:293
double ndrhorbardni__constnj(const std::vector< double > &x, int i)
Definition: Mixtures.cpp:2296
double d2phir_dTau2(double tau, double delta, const std::vector< double > &x)
Definition: Mixtures.cpp:2143
SuccessiveSubstitutionVLE SS
Definition: Mixtures.h:461
std::vector< double > T
Definition: Mixtures.h:396
virtual double rhorbar(const std::vector< double > &x)=0
The molar reducing density.
DepartureFunctionCacheElement dphir_dTau
Definition: Mixtures.h:206
double nddeltadni__constT_V_nj(double tau, double delta, const std::vector< double > &x, int i)
Definition: Mixtures.cpp:1114
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...
Definition: Mixtures.cpp:938
double d2vrbardxi2__constxj(const std::vector< double > &x, int i)
Definition: Mixtures.cpp:1660
double d2nphir_dni_dT(double tau, double delta, const std::vector< double > &x, int i)
Definition: Mixtures.cpp:965
std::vector< double > lnrhobar_liq
Definition: Mixtures.h:396
std::vector< std::vector< double > > lnK
Definition: Mixtures.h:395
double d2nphir_dni_dxj__constT_V(double tau, double delta, const std::vector< double > &x, int i, int j)
Gernert Equation 3.117.
Definition: Mixtures.cpp:1027
double dgdbeta_RachfordRice(const std::vector< double > &z, const std::vector< double > &lnK, double beta)
Definition: Mixtures.cpp:1558
Mixture * Mix
Pointer to the Mixture class instance.
Definition: Mixtures.h:311
int Nstep_max
The maximum number of steps to take, can be changed as needed.
Definition: Mixtures.h:310
double d2phir_dDelta2(double tau, double delta, const std::vector< double > &x)
Definition: Mixtures.cpp:2131
std::vector< std::vector< double > > F
Definition: Mixtures.h:251
std::vector< std::vector< DepartureFunction * > > DepartureFunctionMatrix
Definition: Mixtures.h:250
std::vector< double > y
Definition: Mixtures.h:314
double rhobar_vap
Definition: Mixtures.h:334
virtual double d2phir_dDelta_dTau(double tau, double delta)=0
ExcessTerm(int N)
Definition: Mixtures.cpp:2075
double phir(double tau, double delta, const std::vector< double > &x)
Definition: Mixtures.cpp:2095
ResidualIdealMixture(std::vector< Fluid * > pFluids)
Definition: Mixtures.cpp:2219
std::vector< double > K
Definition: Mixtures.h:314
std::vector< std::vector< double > > y
Definition: Mixtures.h:395
double dphir_dTau(double tau, double delta)
Definition: Mixtures.cpp:2019
double d2phir_dTau2(double tau, double delta)
Definition: Mixtures.cpp:2034
void check_WaterEthanol()
Definition: Mixtures.cpp:462
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.
Definition: Mixtures.cpp:1588
double d2Trdxidxj(const std::vector< double > &x, int i, int j)
Definition: Mixtures.cpp:1617
void build(double p0, const std::vector< double > &z, double beta_envelope)
Definition: Mixtures.cpp:2613
double rhobar_liq
Definition: Mixtures.h:431
double dln_fugacity_coefficient_dp__constT_n(double tau, double delta, const std::vector< double > &x, int i)
Definition: Mixtures.cpp:982
std::vector< double > lnK
Natural logarithm of K-factor [-].
Definition: Mixtures.h:293
double d2phir_dTau2(double tau, double delta)
Definition: Mixtures.cpp:1887
void resize(unsigned int N)
Definition: Mixtures.cpp:2405
unsigned int N
Definition: Mixtures.h:249
virtual double phir(double tau, double delta)=0
double dphir_dDelta(double tau, double delta)
Definition: Mixtures.cpp:1973
std::vector< double > x
Definition: Mixtures.h:314
double dpdT__constV_n(double tau, double delta, const std::vector< double > &x, int i)
Definition: Mixtures.cpp:1060
double d2phir_dDelta_dTau(double tau, double delta)
Definition: Mixtures.cpp:1843
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
Definition: Mixtures.h:213
virtual ~ReducingFunction()
Definition: Mixtures.h:23
double rhobar_liq
The molar density of the liquid phase [mol/m^3].
Definition: Mixtures.h:312
std::vector< double > y
Definition: Mixtures.h:341
double dfYikdxi__constxk(const std::vector< double > &x, int i, int k, std::vector< std::vector< double > > *beta)
Definition: Mixtures.cpp:1711
void pre_call()
Definition: Mixtures.h:349
std::vector< std::vector< double > > STLMatrix
Definition: Mixtures.h:10
STLMatrix gamma_T
from GERG-2008
Definition: Mixtures.h:70
double Wilson_lnK_factor(double T, double p, int i)
Definition: Mixtures.cpp:931
std::vector< SuccessiveSubstitutionStep > step_logger
Definition: Mixtures.h:342
void TpzFlash(double T, double p, const std::vector< double > &z, double &rhobar, std::vector< double > &x, std::vector< double > &y)
Definition: Mixtures.cpp:1400
std::vector< double > ln_phi_liq
Definition: Mixtures.h:314
STLMatrix J
Definition: Mixtures.h:340
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)
Definition: Mixtures.h:399
std::map< std::string, double > load_reducing_values(int i, int j)
Definition: Mixtures.cpp:78
virtual double Tr(const std::vector< double > &x)=0
The reduced temperature.
double d2fYkidxi2__constxk(const std::vector< double > &x, int k, int i, std::vector< std::vector< double > > *beta)
Definition: Mixtures.cpp:1734
std::vector< double > x(ncmax, 0)
double dphir_dDelta(double tau, double delta, const std::vector< double > &x)
Definition: Mixtures.cpp:1214
double dphir_dTau(double tau, double delta)
Definition: Mixtures.cpp:1865
std::vector< double > ln_phi_liq
Natural logarithm of fugacity coeff. in liq. phase [-].
Definition: Mixtures.h:293
double ndpdV__constT_n(double tau, double delta, const std::vector< double > &x, int i)
Definition: Mixtures.cpp:1066
ResidualIdealMixture * pResidualIdealMix
Definition: Mixtures.h:457
DepartureFunctionCache cache
Definition: Mixtures.h:232
double d2phir_dDelta2(double tau, double delta)
Definition: Mixtures.cpp:1988
std::vector< Fluid * > pFluids
Definition: Mixtures.h:272
double d2phir_dDelta_dTau(double tau, double delta, const std::vector< double > &x)
Definition: Mixtures.cpp:2155
Mixture * Mix
Definition: Mixtures.h:433
std::vector< double > lnT
Definition: Mixtures.h:396
double d2phir_dTau2(double tau, double delta, const std::vector< double > &x)
Definition: Mixtures.cpp:1226
double phir(double tau, double delta)
Definition: Mixtures.cpp:1780
double d_dphirddelta_dxj__constT_V_xi(double tau, double delta, const std::vector< double > &x, int j)
Definition: Mixtures.cpp:1020
DepartureFunctionCacheElement d2phir_dTau2
Definition: Mixtures.h:206
double rhobar_Tpz(double T, double p, const std::vector< double > &z, double rhobar0)
Definition: Mixtures.cpp:1277
double dphir_dxi(double tau, double delta, const std::vector< double > &x, unsigned int i)
Definition: Mixtures.cpp:2167
double Rbar(const std::vector< double > &x)
Definition: Mixtures.cpp:310
void initialize()
Definition: Mixtures.cpp:350
double ndpdni__constT_V_nj(double tau, double delta, const std::vector< double > &x, int i)
Definition: Mixtures.cpp:1074
std::vector< double > rhobar_liq
Definition: Mixtures.h:396
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)
Definition: Mixtures.cpp:971
std::vector< double > lnrhobar_vap
Definition: Mixtures.h:396
double d2phir_dDelta_dTau(double tau, double delta, const std::vector< double > &x)
Definition: Mixtures.cpp:2251
unsigned int N
Definition: Mixtures.h:271
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 > >)
Definition: Mixtures.cpp:1910
double d2vrbardxidxj(const std::vector< double > &x, int i, int j)
Definition: Mixtures.cpp:1645
double d2Trdxi2__constxj(const std::vector< double > &x, int i)
Definition: Mixtures.cpp:1603
unsigned int N
Definition: Mixtures.h:335
void to_python_files(std::string fname)
Definition: Mixtures.cpp:2893
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 T
Temperature [K].
Definition: Mixtures.h:291
double d2phir_dDelta2(double tau, double delta, const std::vector< double > &x)
Definition: Mixtures.cpp:2242
double p
Pressure [kPa].
Definition: Mixtures.h:291
std::vector< Fluid * > pFluids
List of pointers to fluids.
Definition: Mixtures.h:159
double dfYkidxi__constxk(const std::vector< double > &x, int k, int i, std::vector< std::vector< double > > *beta)
Definition: Mixtures.cpp:1706
DepartureFunctionCacheElement d2phir_dDelta2
Definition: Mixtures.h:206
double d_ndphirdni_dTau(double tau, double delta, const std::vector< double > &x, int i)
Definition: Mixtures.cpp:1174
double dpdxj__constT_V_xi(double tau, double delta, const std::vector< double > &x, int j)
Definition: Mixtures.cpp:1009
double dphir_dDelta(double tau, double delta, const std::vector< double > &x)
Definition: Mixtures.cpp:2233
void load_excess_values(int i, int j)
Definition: Mixtures.cpp:184
std::vector< SuccessiveSubstitutionStep > step_logger
Definition: Mixtures.h:319
double d2phirdxidxj(double tau, double delta, const std::vector< double > &x, int i, int j)
Definition: Mixtures.cpp:1202
std::vector< double > neg_dFdS
Definition: Mixtures.h:341
double d2phir_dxi_dTau(double tau, double delta, const std::vector< double > &x, int i)
Definition: Mixtures.cpp:1206
void test()
Definition: Mixtures.cpp:391
double dphir_dTau(double tau, double delta, const std::vector< double > &x)
Definition: Mixtures.cpp:1230
double error_rms
Definition: Mixtures.h:334
double partial_molar_volume(double tau, double delta, const std::vector< double > &x, int i)
Definition: Mixtures.cpp:977
STLMatrix beta_T
from GERG-2008
Definition: Mixtures.h:69
PhaseEnvelopeLog bubble
Definition: Mixtures.h:430
std::vector< double > x
Definition: Mixtures.h:341
double rhobar_liq
Definition: Mixtures.h:334
std::vector< double > phi_ij_liq
Definition: Mixtures.h:341
The reduced temperature double Tr(const std::vector< double > &x)
The reduced temperature.
Definition: Mixtures.cpp:1570
double dln_fugacity_coefficient_dT__constrho(double tau, double delta, const std::vector< double > &x, int i)
Definition: Mixtures.cpp:953
std::vector< double > p
Definition: Mixtures.h:396
double d2rhorbardxidxj(const std::vector< double > &x, int i, int j)
Definition: Mixtures.cpp:1681
DepartureFunctionCacheElement phir
Definition: Mixtures.h:206
double d2phir_dDelta_dTau(double tau, double delta, const std::vector< double > &x)
Definition: Mixtures.cpp:1222
void set_coeffs_from_map(std::map< std::string, std::vector< double > >)
Definition: Mixtures.cpp:2051
double saturation_p_Wilson(double beta, double p, const std::vector< double > &z, double T_guess, std::vector< double > &K)
Definition: Mixtures.cpp:1348
double phir(double tau, double delta, const std::vector< double > &x)
Definition: Mixtures.cpp:1194
int Nsteps
How many steps were taken to yield tolerance.
Definition: Mixtures.h:309
Mixture(std::vector< Fluid * > pFluids)
Definition: Mixtures.cpp:319
double d2fYikdxi2__constxk(const std::vector< double > &x, int i, int k, std::vector< std::vector< double > > *beta)
Definition: Mixtures.cpp:1729
PhaseEnvelopeLog dew
Definition: Mixtures.h:430
STLMatrix beta_v
from GERG-2008
Definition: Mixtures.h:67
void check_MethaneEthane()
Definition: Mixtures.cpp:691
void set_coeffs_from_map(int i, int j, std::map< std::string, std::vector< double > >)
Definition: Mixtures.cpp:2214
std::vector< Fluid * > pFluids
List of pointers to fluids.
Definition: Mixtures.h:71
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)
Definition: Mixtures.cpp:2424
STLMatrix gamma_v
from GERG-2008
Definition: Mixtures.h:68
double d_ndrhorbardni_dxj__constxi(const std::vector< double > &x, int i, int j)
Definition: Mixtures.cpp:2287
virtual double dphir_dDelta(double tau, double delta)=0
PhaseEnvelope Envelope
Definition: Mixtures.h:459
double call(double beta, double T, double p, const std::vector< double > &z, std::vector< double > &K)
Definition: Mixtures.cpp:2316
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)
Definition: Mixtures.cpp:1720
double d2phir_dTau2(double tau, double delta, const std::vector< double > &x)
Definition: Mixtures.cpp:2269
double phir(double tau, double delta)
Definition: Mixtures.cpp:1958
double phir(double tau, double delta, const std::vector< double > &x)
Definition: Mixtures.cpp:2224
virtual double d2rhorbardxi2__constxj(const std::vector< double > &x, int i)=0
std::vector< std::vector< double > > x
Definition: Mixtures.h:395
The molar reducing density double rhorbar(const std::vector< double > &x)
The molar reducing density.
Definition: Mixtures.cpp:1689
std::vector< double > r
Definition: Mixtures.h:341
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.
Definition: Mixtures.cpp:1656
unsigned int N
Definition: Mixtures.h:20
double d2phirdxidxj(double tau, double delta, const std::vector< double > &x, unsigned int i, unsigned int j)
Definition: Mixtures.cpp:2179
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)
Definition: Mixtures.cpp:1032
double d2phir_dxi_dDelta(double tau, double delta, const std::vector< double > &x, int i)
Definition: Mixtures.cpp:1210
virtual double d2Trdxi2__constxj(const std::vector< double > &x, int i)=0
double dphir_dDelta(double tau, double delta)
Definition: Mixtures.cpp:1801
double ln_fugacity_coefficient(double tau, double delta, const std::vector< double > &x, int i)
Definition: Mixtures.cpp:949
bool useNR
If true (default is false), will call Newton-Raphson after either solving to tolerance, or taking Nmax steps.
Definition: Mixtures.h:307
double ndphir_dni__constT_V_nj(double tau, double delta, const std::vector< double > &x, int i)
Definition: Mixtures.cpp:1092
double d2phir_dxi_dTau(double tau, double delta, const std::vector< double > &x, unsigned int i)
Definition: Mixtures.cpp:2190
std::vector< double > K
Definition: Mixtures.h:432
DepartureFunctionCacheElement d2phir_dDelta_dTau
Definition: Mixtures.h:206
Default destructor ~GERG2008ReducingFunction()
Definition: Mixtures.h:103
std::vector< double > K
Definition: Mixtures.h:341
double rhobar_vap
Definition: Mixtures.h:431
std::vector< double > ln_phi_vap
Definition: Mixtures.h:314
ExcessTerm * pExcess
Definition: Mixtures.h:456