CoolProp  6.6.0
An open-source fluid property and humid air property database
PCSAFTBackend.h
Go to the documentation of this file.
1 #ifndef PCSAFTBACKEND_H
2 #define PCSAFTBACKEND_H
3 
4 #include "AbstractState.h"
5 #include "CoolPropTools.h"
6 #include "DataStructures.h"
7 #include "PCSAFTLibrary.h"
8 #include "Configuration.h"
9 #include "Exceptions.h"
10 #include <vector>
11 
12 using std::vector;
13 
14 namespace CoolProp {
15 
16 const static double kb = 1.380649e-23; // Boltzmann constant, J K^-1
17 const static double PI = 3.141592653589793;
18 const static double N_AV = 6.02214076e23; // Avagadro's number
19 const static double E_CHRG = 1.6021766208e-19; // elementary charge, units of coulomb
20 const static double perm_vac = 8.854187817e-22; //permittivity in vacuum, C V^-1 Angstrom^-1
21 
22 class PCSAFTBackend : public AbstractState {
23 
24 protected:
25  std::vector<PCSAFTFluid> components;
26  std::vector<int> assoc_num;
27  std::vector<int> assoc_matrix;
28  std::vector<double> k_ij;
29  std::vector<double> k_ijT;
31  std::vector<CoolPropDbl> mole_fractions;
32  std::vector<double> mole_fractions_double;
33  std::vector<CoolPropDbl> K,
34  lnK;
35  double dielc;
36 
37  shared_ptr<PCSAFTBackend> SatL;
38  shared_ptr<PCSAFTBackend> SatV;
39 
40  std::size_t N;
41 
43  int water_idx;
44  bool ion_term;
45  bool polar_term;
46  bool assoc_term;
47 
48  void post_update(bool optional_checks = true);
49 
51  double estimate_flash_p(PCSAFTBackend &PCSAFT);
52  double estimate_flash_t(PCSAFTBackend &PCSAFT);
53  double outerTQ(double p_guess, PCSAFTBackend &PCSAFT);
54  double outerPQ(double t_guess, PCSAFTBackend &PCSAFT);
57 
58  // these functions are used internally to solve for association parameters
59  vector<double> XA_find(vector<double> XA_guess, vector<double> delta_ij, double den,
60  vector<double> x);
61  vector<double> dXAdx_find(vector<int> assoc_num, vector<double> delta_ij,
62  double den, vector<double> XA, vector<double> ddelta_dx, vector<double> x);
63  vector<double> dXAdt_find(vector<double> delta_ij, double den,
64  vector<double> XA, vector<double> ddelta_dt, vector<double> x);
65  void set_assoc_matrix();
66  double dielc_water(double t);
67 
68  public:
69  PCSAFTBackend(const std::vector<std::string>& component_names, bool generate_SatL_and_SatV = true);
70  PCSAFTBackend(const std::vector<PCSAFTFluid>& components, bool generate_SatL_and_SatV = true);
71  virtual PCSAFTBackend* get_copy(bool generate_SatL_and_SatV = true);
72 
74  std::string backend_name(void) {
76  }
77 
78  bool using_mole_fractions(void) {
79  return true;
80  };
81  bool using_mass_fractions(void) {
82  return false;
83  };
84  bool using_volu_fractions(void) {
85  return false;
86  };
87 
88  void set_mass_fractions(const std::vector<CoolPropDbl>& mass_fractions);
89  void set_volu_fractions(const std::vector<CoolPropDbl>& volu_fractions) {
90  throw NotImplementedError("Volume composition has not been implemented.");
91  };
92  void set_mole_fractions(const std::vector<CoolPropDbl>& mole_fractions);
93  const std::vector<CoolPropDbl>& get_mole_fractions(void) {
94  return this->mole_fractions;
95  };
96 
97  void resize(std::size_t N);
98 
99  virtual void update(CoolProp::input_pairs input_pair, double value1, double value2); // %%checked
100 
101  const double get_fluid_constant(std::size_t i, parameters param) const {
102  // const PCSAFTFluid &fld = components[i];
103  // switch(param){
104  // case im: return fld.m;
105  // case isigma: return fld.sigma;
106  // case iu: return fld.u;
107  // case iuAB: return fld.uAB;
108  // case ikappa: return fld.kappa;
109  // case idipm: return fld.dipm;
110  // case idipnum: return fld.dipnum;
111  // case iacentric_factor: return fld.EOS().acentric;
112  // case imolar_mass: return fld.EOS().molar_mass;
113  // default:
114  // throw ValueError(format("I don't know what to do with this fluid constant: %s", get_parameter_information(param,"short").c_str()));
115  // }
116  throw ValueError(format("I don't know what to do with this fluid constant: %s", get_parameter_information(param, "short").c_str()));
117  }
118 
119  // ************************************************************************* //
120  // Basic Thermodynamic Functions //
121  // ************************************************************************* //
122  //
125 
128 
129  // CoolPropDbl calc_alpha0(void); // ideal gas helmholtz energy term
130  CoolPropDbl calc_alphar(void); // residual helmholtz energy
131  CoolPropDbl calc_dadt(void); // derivative of the residual helmholtz energy with respect to temperature
134  vector<CoolPropDbl> calc_fugacity_coefficients(void);
136  // CoolPropDbl calc_cpmolar(void); // TODO implement these heat capacity functions
137  // CoolPropDbl calc_cp0molar(void);
139 
140  void flash_QT(PCSAFTBackend& PCSAFT);
141  void flash_PQ(PCSAFTBackend& PCSAFT);
142 
144  return _phase;
145  };
150  void calc_specify_phase(phases phase_index) {
151  imposed_phase_index = phase_index;
152  _phase = phase_index;
153  }
158  }
159  //
160  // ************************************************************************* //
161  // Trivial Functions //
162  // ************************************************************************* //
163  //
164  double calc_molar_mass(void);
165  //
166 };
167 } /* namespace CoolProp */
168 #endif /* PCSAFTBACKEND_H_ */