CoolProp
FlashRoutines.h
1 
8 // ***************************************************************
9 // ******************* FLASH ROUTINES **************************
10 // ***************************************************************
11 
12 #ifndef FLASHROUTINES_H
13 #define FLASHROUTINES_H
14 
15 #include "HelmholtzEOSMixtureBackend.h"
16 #include "Solvers.h"
17 
18 namespace CoolProp{
19 
29 public:
30 
31  template<class T> T
32  static g_RachfordRice(const std::vector<T> &z, const std::vector<T> &lnK, T beta)
33  {
34  // g function from Rachford-Rice
35  T summer = 0;
36  for (std::size_t i = 0; i < z.size(); i++)
37  {
38  T Ki = exp(lnK[i]);
39  summer += z[i]*(Ki-1)/(1-beta+beta*Ki);
40  }
41  return summer;
42  }
43  template<class T> T
44  static dgdbeta_RachfordRice(const std::vector<T> &z, const std::vector<T> &lnK, T beta)
45  {
46  // derivative of g function from Rachford-Rice with respect to beta
47  T summer = 0;
48  for (std::size_t i = 0; i < z.size(); i++)
49  {
50  T Ki = exp(lnK[i]);
51  summer += -z[i]*pow((Ki-1)/(1-beta+beta*Ki),2);
52  }
53  return summer;
54  }
55 
58  static void PQ_flash(HelmholtzEOSMixtureBackend &HEOS);
59 
63  static void PQ_flash_with_guesses(HelmholtzEOSMixtureBackend &HEOS, const GuessesStructure &guess);
64 
68  static void QT_flash_with_guesses(HelmholtzEOSMixtureBackend &HEOS, const GuessesStructure &guess);
69 
73  static void PT_flash_with_guesses(HelmholtzEOSMixtureBackend &HEOS, const GuessesStructure &guess);
74 
77  static void QT_flash(HelmholtzEOSMixtureBackend &HEOS);
78 
81  static void QS_flash(HelmholtzEOSMixtureBackend &HEOS);
82 
85  static void DQ_flash(HelmholtzEOSMixtureBackend &HEOS);
86 
90  static void HQ_flash(HelmholtzEOSMixtureBackend &HEOS, CoolPropDbl Tguess = -1);
91 
96  static void PT_Q_flash_mixtures(HelmholtzEOSMixtureBackend &HEOS, parameters other, CoolPropDbl value);
97 
100  static void PT_flash(HelmholtzEOSMixtureBackend &HEOS);
101 
105 
107  static double T_DP_PengRobinson(HelmholtzEOSMixtureBackend &HEOS, double rhomolar, double p);
108 
111  static void DP_flash(HelmholtzEOSMixtureBackend &HEOS);
112 
118  static void solver_for_rho_given_T_oneof_HSU(HelmholtzEOSMixtureBackend &HEOS, CoolPropDbl T, CoolPropDbl value, parameters other);
119 
123  static void DHSU_T_flash(HelmholtzEOSMixtureBackend &HEOS, parameters other);
124 
128  static void HSU_P_flash(HelmholtzEOSMixtureBackend &HEOS, parameters other);
129 
135  static void HSU_P_flash_singlephase_Newton(HelmholtzEOSMixtureBackend &HEOS, parameters other, CoolPropDbl T0, CoolPropDbl rhomolar0);
136 
144  static void HSU_P_flash_singlephase_Brent(HelmholtzEOSMixtureBackend &HEOS, parameters other, CoolPropDbl value, CoolPropDbl Tmin, CoolPropDbl Tmax, phases phase);
145 
149  static void HSU_D_flash_twophase(HelmholtzEOSMixtureBackend &HEOS, CoolPropDbl rhomolar_spec, parameters other, CoolPropDbl value);
150 
154  static void HSU_D_flash(HelmholtzEOSMixtureBackend &HEOS, parameters other);
155 
158  static void HS_flash(HelmholtzEOSMixtureBackend &HEOS);
159 
164  static void HS_flash_generate_TP_singlephase_guess(HelmholtzEOSMixtureBackend &HEOS, double &T, double &p);
165 
167  {
168  double omega;
169  HS_flash_singlephaseOptions(){omega = 1.0;}
170  };
171  static void HS_flash_singlephase(HelmholtzEOSMixtureBackend &HEOS, CoolPropDbl hmolar_spec, CoolPropDbl smolar_spec, HS_flash_singlephaseOptions &options);
172 
174  {
175  double omega;
176  HS_flash_twophaseOptions(){omega = 1.0;}
177  };
178  static void HS_flash_twophase(HelmholtzEOSMixtureBackend &HEOS, CoolPropDbl hmolar_spec, CoolPropDbl smolar_spec, HS_flash_twophaseOptions &options);
179 };
180 
181 
185 {
186 public:
188  CoolPropDbl T, p, rhor, tau, R_u, delta;
189 
190  solver_TP_resid(HelmholtzEOSMixtureBackend &HEOS, CoolPropDbl T, CoolPropDbl p):
191  HEOS(&HEOS),T(T),p(p),rhor(HEOS.get_reducing_state().rhomolar),
192  tau(HEOS.get_reducing_state().T/T),R_u(HEOS.gas_constant()),delta(-_HUGE) {}
193  double call(double rhomolar){
194  delta = rhomolar/rhor; // needed for derivative
195  HEOS->update_DmolarT_direct(rhomolar, T);
196  CoolPropDbl peos = HEOS->p();
197  return (peos-p)/p;
198  };
199  double deriv(double rhomolar){
200  // dp/drho|T / pspecified
201  return R_u*T*(1+2*delta*HEOS->dalphar_dDelta()+pow(delta, 2)*HEOS->d2alphar_dDelta2())/p;
202  };
203 };
204 
208 {
209 public:
210 
212  CoolPropDbl p;
213  parameters other;
214  CoolPropDbl value;
215  PY_singlephase_flash_resid(HelmholtzEOSMixtureBackend &HEOS, CoolPropDbl p, parameters other, CoolPropDbl value) :
216  HEOS(&HEOS), p(p), other(other), value(value)
217  {
218  // Specify the state to avoid saturation calls, but only if phase is subcritical
219  if (HEOS.phase() == iphase_liquid || HEOS.phase() == iphase_gas ){
220  HEOS.specify_phase(HEOS.phase());
221  }
222  };
223  double call(double T){
224 
225  // Run the solver with T,P as inputs;
226  HEOS->update(PT_INPUTS, p, T);
227 
228  CoolPropDbl rhomolar = HEOS->rhomolar();
229  HEOS->update(DmolarT_INPUTS, rhomolar, T);
230  // Get the value of the desired variable
231  CoolPropDbl eos = HEOS->keyed_output(other);
232 
233  // Difference between the two is to be driven to zero
234  return eos - value;
235  };
236 };
237 
238 } /* namespace CoolProp */
239 #endif /* FLASHROUTINES_H */
static void HSU_D_flash(HelmholtzEOSMixtureBackend &HEOS, parameters other)
A generic flash routine for the pairs (D,P), (D,H), (D,S), and (D,U).
Definition: FlashRoutines.cpp:1038
static double T_DP_PengRobinson(HelmholtzEOSMixtureBackend &HEOS, double rhomolar, double p)
Use Peng-Robinson to get guess for temperature for given density and pressure.
Definition: FlashRoutines.cpp:175
CoolPropDbl dalphar_dDelta(void)
Return the term .
Definition: AbstractState.h:1099
double gas_constant(void)
Return the mole-fraction weighted gas constant in J/mol/K.
Definition: AbstractState.cpp:651
double rhomolar(void)
Return the molar density in mol/m^3.
Definition: AbstractState.h:702
Molar density in mol/m^3, Temperature in K.
Definition: DataStructures.h:230
Definition: Solvers.h:37
static void HSU_P_flash_singlephase_Brent(HelmholtzEOSMixtureBackend &HEOS, parameters other, CoolPropDbl value, CoolPropDbl Tmin, CoolPropDbl Tmax, phases phase)
The single-phase flash routine for the pairs (P,H), (P,S), and (P,U).
Definition: FlashRoutines.cpp:1359
Subcritical liquid.
Definition: DataStructures.h:158
static void DHSU_T_flash(HelmholtzEOSMixtureBackend &HEOS, parameters other)
A generic flash routine for the pairs (T,D), (T,H), (T,S), and (T,U).
Definition: FlashRoutines.cpp:1737
A residual function for the f(P, Y) solver.
Definition: FlashRoutines.h:207
static void PT_flash_mixtures(HelmholtzEOSMixtureBackend &HEOS)
Flash for given pressure and temperature for mixtures.
Definition: FlashRoutines.cpp:15
phases
These are constants for the phases of the fluid.
Definition: DataStructures.h:158
virtual void update(CoolProp::input_pairs input_pair, double value1, double value2)
The standard update function.
Definition: HelmholtzEOSMixtureBackend.cpp:1281
phases phase(void)
Get the phase of the state.
Definition: AbstractState.h:616
static void PT_Q_flash_mixtures(HelmholtzEOSMixtureBackend &HEOS, parameters other, CoolPropDbl value)
Flash for mixture given temperature or pressure and (molar) quality.
Definition: FlashRoutines.cpp:809
static void solver_for_rho_given_T_oneof_HSU(HelmholtzEOSMixtureBackend &HEOS, CoolPropDbl T, CoolPropDbl value, parameters other)
The flash routine for T given and one of H,S,U.
Definition: FlashRoutines.cpp:1579
static void QT_flash_with_guesses(HelmholtzEOSMixtureBackend &HEOS, const GuessesStructure &guess)
Flash for given temperature and (molar) quality with guess values provided.
Definition: FlashRoutines.cpp:746
const CoolProp::SimpleState & get_reducing_state()
Get the state that is used in the equation of state or mixture model to reduce the state...
Definition: HelmholtzEOSMixtureBackend.h:453
static void PT_flash_with_guesses(HelmholtzEOSMixtureBackend &HEOS, const GuessesStructure &guess)
Flash for given pressure and temperature with guess values provided for molar density.
Definition: FlashRoutines.cpp:779
static void HSU_P_flash(HelmholtzEOSMixtureBackend &HEOS, parameters other)
A generic flash routine for the pairs (P,H), (P,S), and (P,U).
Definition: FlashRoutines.cpp:1469
static void HS_flash_generate_TP_singlephase_guess(HelmholtzEOSMixtureBackend &HEOS, double &T, double &p)
Randomly generate a single phase set of inputs for T and p - searches entire single-phase region...
Definition: FlashRoutines.cpp:1954
Pressure in Pa, Temperature in K.
Definition: DataStructures.h:227
static void DQ_flash(HelmholtzEOSMixtureBackend &HEOS)
Flash for given molar density and (molar) quality.
Definition: FlashRoutines.cpp:271
void specify_phase(phases phase)
Specify the phase for all further calculations with this state class.
Definition: AbstractState.h:618
Subcritical gas.
Definition: DataStructures.h:163
static void DP_flash(HelmholtzEOSMixtureBackend &HEOS)
Flash for given density and pressure.
Definition: FlashRoutines.cpp:200
static void PQ_flash_with_guesses(HelmholtzEOSMixtureBackend &HEOS, const GuessesStructure &guess)
Flash for given pressure and (molar) quality with guess values provided.
Definition: FlashRoutines.cpp:716
static void PQ_flash(HelmholtzEOSMixtureBackend &HEOS)
Flash for given pressure and (molar) quality.
Definition: FlashRoutines.cpp:535
A residual function for the rho(T,P) solver.
Definition: FlashRoutines.h:184
static void HS_flash(HelmholtzEOSMixtureBackend &HEOS)
A flash routine for (H,S)
Definition: FlashRoutines.cpp:1961
static void HSU_P_flash_singlephase_Newton(HelmholtzEOSMixtureBackend &HEOS, parameters other, CoolPropDbl T0, CoolPropDbl rhomolar0)
The single-phase flash routine for the pairs (P,H), (P,S), and (P,U).
Definition: FlashRoutines.cpp:1266
static void QT_flash(HelmholtzEOSMixtureBackend &HEOS)
Flash for given temperature and (molar) quality.
Definition: FlashRoutines.cpp:365
double p(void)
Return the pressure in Pa.
Definition: AbstractState.h:706
static void HQ_flash(HelmholtzEOSMixtureBackend &HEOS, CoolPropDbl Tguess=-1)
Flash for given molar enthalpy and (molar) quality.
Definition: FlashRoutines.cpp:294
static void HSU_D_flash_twophase(HelmholtzEOSMixtureBackend &HEOS, CoolPropDbl rhomolar_spec, parameters other, CoolPropDbl value)
A generic flash routine for the pairs (D,H), (D,S), and (D,U) for twophase state. ...
Definition: FlashRoutines.cpp:1000
Definition: Solvers.h:19
This simple class holds the values for guesses for use in some solvers that have the ability to use g...
Definition: AbstractState.h:32
Definition: HelmholtzEOSMixtureBackend.h:22
CoolPropDbl d2alphar_dDelta2(void)
Return the term .
Definition: AbstractState.h:1109
static void PT_flash(HelmholtzEOSMixtureBackend &HEOS)
Flash for given pressure and temperature.
Definition: FlashRoutines.cpp:94
This class is a friend class of HelmholtzEOSMixtureBackend, therefore the static methods contained in...
Definition: FlashRoutines.h:28
This file contains flash routines in which the state is unknown, and a solver of some kind must be us...
Definition: AbstractState.h:19
static void QS_flash(HelmholtzEOSMixtureBackend &HEOS)
Flash for given molar entropy and (molar) quality.
Definition: FlashRoutines.cpp:321
parameters
Define some constants that will be used throughout These are constants for the input and output para...
Definition: DataStructures.h:49
double keyed_output(parameters key)
Retrieve a value by key.
Definition: AbstractState.cpp:392