CoolProp  6.6.0
An open-source fluid property and humid air property database
FlashRoutines.h
Go to the documentation of this file.
1 
8 // ***************************************************************
9 // ******************* FLASH ROUTINES **************************
10 // ***************************************************************
11 
12 #ifndef FLASHROUTINES_H
13 #define FLASHROUTINES_H
14 
16 #include "Solvers.h"
17 
18 namespace CoolProp {
19 
29 {
30  public:
31  template <class T>
32  T static g_RachfordRice(const std::vector<T>& z, const std::vector<T>& lnK, T beta) {
33  // g function from Rachford-Rice
34  T summer = 0;
35  for (std::size_t i = 0; i < z.size(); i++) {
36  T Ki = exp(lnK[i]);
37  summer += z[i] * (Ki - 1) / (1 - beta + beta * Ki);
38  }
39  return summer;
40  }
41  template <class T>
42  T static dgdbeta_RachfordRice(const std::vector<T>& z, const std::vector<T>& lnK, T beta) {
43  // derivative of g function from Rachford-Rice with respect to beta
44  T summer = 0;
45  for (std::size_t i = 0; i < z.size(); i++) {
46  T Ki = exp(lnK[i]);
47  summer += -z[i] * pow((Ki - 1) / (1 - beta + beta * Ki), 2);
48  }
49  return summer;
50  }
51 
54  static void PQ_flash(HelmholtzEOSMixtureBackend& HEOS);
55 
59  static void PQ_flash_with_guesses(HelmholtzEOSMixtureBackend& HEOS, const GuessesStructure& guess);
60 
64  static void QT_flash_with_guesses(HelmholtzEOSMixtureBackend& HEOS, const GuessesStructure& guess);
65 
69  static void PT_flash_with_guesses(HelmholtzEOSMixtureBackend& HEOS, const GuessesStructure& guess);
70 
73  static void QT_flash(HelmholtzEOSMixtureBackend& HEOS);
74 
77  static void QS_flash(HelmholtzEOSMixtureBackend& HEOS);
78 
81  static void DQ_flash(HelmholtzEOSMixtureBackend& HEOS);
82 
86  static void HQ_flash(HelmholtzEOSMixtureBackend& HEOS, CoolPropDbl Tguess = -1);
87 
93 
96  static void PT_flash(HelmholtzEOSMixtureBackend& HEOS);
97 
101 
103  static double T_DP_PengRobinson(HelmholtzEOSMixtureBackend& HEOS, double rhomolar, double p);
104 
107  static void DP_flash(HelmholtzEOSMixtureBackend& HEOS);
108 
115 
119  static void DHSU_T_flash(HelmholtzEOSMixtureBackend& HEOS, parameters other);
120 
124  static void HSU_P_flash(HelmholtzEOSMixtureBackend& HEOS, parameters other);
125 
132 
141  CoolPropDbl Tmax, phases phase);
142 
146  static void HSU_D_flash_twophase(HelmholtzEOSMixtureBackend& HEOS, CoolPropDbl rhomolar_spec, parameters other, CoolPropDbl value);
147 
151  static void HSU_D_flash(HelmholtzEOSMixtureBackend& HEOS, parameters other);
152 
155  static void HS_flash(HelmholtzEOSMixtureBackend& HEOS);
156 
161  static void HS_flash_generate_TP_singlephase_guess(HelmholtzEOSMixtureBackend& HEOS, double& T, double& p);
162 
164  {
165  double omega;
167  omega = 1.0;
168  }
169  };
170  static void HS_flash_singlephase(HelmholtzEOSMixtureBackend& HEOS, CoolPropDbl hmolar_spec, CoolPropDbl smolar_spec,
171  HS_flash_singlephaseOptions& options);
172 
174  {
175  double omega;
177  omega = 1.0;
178  }
179  };
180  static void HS_flash_twophase(HelmholtzEOSMixtureBackend& HEOS, CoolPropDbl hmolar_spec, CoolPropDbl smolar_spec,
181  HS_flash_twophaseOptions& options);
182 };
183 
187 {
188  public:
191 
193  : HEOS(&HEOS),
194  T(T),
195  p(p),
196  rhor(HEOS.get_reducing_state().rhomolar),
197  tau(HEOS.get_reducing_state().T / T),
198  R_u(HEOS.gas_constant()),
199  delta(-_HUGE) {}
200  double call(double rhomolar) {
201  delta = rhomolar / rhor; // needed for derivative
202  HEOS->update_DmolarT_direct(rhomolar, T);
203  CoolPropDbl peos = HEOS->p();
204  return (peos - p) / p;
205  };
206  double deriv(double rhomolar) {
207  // dp/drho|T / pspecified
208  return R_u * T * (1 + 2 * delta * HEOS->dalphar_dDelta() + pow(delta, 2) * HEOS->d2alphar_dDelta2()) / p;
209  };
210 };
211 
215 {
216  public:
222  : HEOS(&HEOS), p(p), other(other), value(value) {
223  // Specify the state to avoid saturation calls, but only if phase is subcritical
224  if (HEOS.phase() == iphase_liquid || HEOS.phase() == iphase_gas) {
226  }
227  };
228  double call(double T) {
229 
230  // Run the solver with T,P as inputs;
231  HEOS->update(PT_INPUTS, p, T);
232 
233  CoolPropDbl rhomolar = HEOS->rhomolar();
234  HEOS->update(DmolarT_INPUTS, rhomolar, T);
235  // Get the value of the desired variable
237 
238  // Difference between the two is to be driven to zero
239  return eos - value;
240  };
241 };
242 
243 } /* namespace CoolProp */
244 #endif /* FLASHROUTINES_H */