CoolProp 8.0.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
17#include <optional>
18
19namespace CoolProp {
20
30{
31 public:
32 template <class T>
33 T static g_RachfordRice(const std::vector<T>& z, const std::vector<T>& lnK, T beta) {
34 // g function from Rachford-Rice
35 T summer = 0;
36 for (std::size_t i = 0; i < z.size(); i++) {
37 T Ki = exp(lnK[i]);
38 summer += z[i] * (Ki - 1) / (1 - beta + beta * Ki);
39 }
40 return summer;
41 }
42 template <class T>
43 T static dgdbeta_RachfordRice(const std::vector<T>& z, const std::vector<T>& lnK, T beta) {
44 // derivative of g function from Rachford-Rice with respect to beta
45 T summer = 0;
46 for (std::size_t i = 0; i < z.size(); i++) {
47 T Ki = exp(lnK[i]);
48 summer += -z[i] * pow((Ki - 1) / (1 - beta + beta * Ki), 2);
49 }
50 return summer;
51 }
52
55 static void PQ_flash(HelmholtzEOSMixtureBackend& HEOS);
56
61
66
71
74 static void QT_flash(HelmholtzEOSMixtureBackend& HEOS);
75
78 static void QS_flash(HelmholtzEOSMixtureBackend& HEOS);
79
82 static void DQ_flash(HelmholtzEOSMixtureBackend& HEOS);
83
92
96 static void HQ_flash(HelmholtzEOSMixtureBackend& HEOS, CoolPropDbl Tguess = -1);
97
106
113
132 static double resolve_T_via_superancillary(HelmholtzEOSMixtureBackend& HEOS, parameters key, double target_value, std::optional<double> guess_T,
133 const char* fn_name);
134
141
150 static std::pair<double, double> alpha0_offset_total(HelmholtzEOSMixtureBackend& HEOS);
151
157
160 static void PT_flash(HelmholtzEOSMixtureBackend& HEOS);
161
165
167 static double T_DP_PengRobinson(HelmholtzEOSMixtureBackend& HEOS, double rhomolar, double p);
168
171 static void DP_flash(HelmholtzEOSMixtureBackend& HEOS);
172
179
183 static void DHSU_T_flash(HelmholtzEOSMixtureBackend& HEOS, parameters other);
184
188 static void HSU_P_flash(HelmholtzEOSMixtureBackend& HEOS, parameters other);
189
196
205 CoolPropDbl Tmax, phases phase);
206
212 static void HSU_D_flash_twophase(HelmholtzEOSMixtureBackend& HEOS, CoolPropDbl rhomolar_spec, parameters other, CoolPropDbl value);
213
217 static void HSU_D_flash(HelmholtzEOSMixtureBackend& HEOS, parameters other);
218
221 static void HS_flash(HelmholtzEOSMixtureBackend& HEOS);
222
227 static void HS_flash_generate_TP_singlephase_guess(HelmholtzEOSMixtureBackend& HEOS, double& T, double& p);
228
230 {
231 double omega;
233 };
234 static void HS_flash_singlephase(HelmholtzEOSMixtureBackend& HEOS, CoolPropDbl hmolar_spec, CoolPropDbl smolar_spec,
235 HS_flash_singlephaseOptions& options);
236
238 {
239 double omega;
241 };
242 static void HS_flash_twophase(HelmholtzEOSMixtureBackend& HEOS, CoolPropDbl hmolar_spec, CoolPropDbl smolar_spec,
243 HS_flash_twophaseOptions& options);
244
246 static bool hs_corrector_probe(HelmholtzEOSMixtureBackend& H, double T0, double rho0, double h_t, double s_t, double& T_out, double& rho_out,
247 double Tlo_override);
248};
249
253{
254 public:
257
259 : HEOS(&HEOS),
260 T(T),
261 p(p),
262 rhor(HEOS.get_reducing_state().rhomolar),
263 tau(HEOS.get_reducing_state().T / T),
264 R_u(HEOS.gas_constant()),
265 delta(-_HUGE) {}
266 double call(double rhomolar) override {
267 delta = rhomolar / rhor; // needed for derivative
268 HEOS->update_DmolarT_direct(rhomolar, T);
269 CoolPropDbl peos = HEOS->p();
270 return (peos - p) / p;
271 };
272 double deriv(double rhomolar) override {
273 // dp/drho|T / pspecified
274 return R_u * T * (1 + 2 * delta * HEOS->dalphar_dDelta() + pow(delta, 2) * HEOS->d2alphar_dDelta2()) / p;
275 };
276};
277
281{
282 public:
288 : HEOS(&HEOS), p(p), other(other), value(value) {
289 // Specify the state to avoid saturation calls, but only if phase is subcritical
290 if (HEOS.phase() == iphase_liquid || HEOS.phase() == iphase_gas) {
292 }
293 };
294 double call(double T) override {
295
296 // Run the solver with T,P as inputs;
297 HEOS->update(PT_INPUTS, p, T);
298
299 CoolPropDbl rhomolar = HEOS->rhomolar();
300 HEOS->update(DmolarT_INPUTS, rhomolar, T);
301 // Get the value of the desired variable
303
304 // Difference between the two is to be driven to zero
305 return eos - value;
306 };
307};
308
309} /* namespace CoolProp */
310#endif /* FLASHROUTINES_H */