14 #ifndef CUBICBACKEND_H_ 15 #define CUBICBACKEND_H_ 17 #include "CoolPropTools.h" 18 #include "DataStructures.h" 19 #include "GeneralizedCubic.h" 20 #include "CubicsLibrary.h" 21 #include "Configuration.h" 22 #include "AbstractState.h" 23 #include "Backends/Helmholtz/HelmholtzEOSMixtureBackend.h" 24 #include "Exceptions.h" 30 class CubicResidualHelmholtz;
35 shared_ptr<AbstractCubic> cubic;
39 void setup(
bool generate_SatL_and_SatV =
true);
54 bool using_mole_fractions(
void) {
57 bool using_mass_fractions(
void) {
60 bool using_volu_fractions(
void) {
64 void set_mass_fractions(
const std::vector<CoolPropDbl>& mass_fractions) {
67 void set_volu_fractions(
const std::vector<CoolPropDbl>& volu_fractions) {
77 return cubic->get_pc()[i];
80 return cubic->get_Tc()[i];
82 return cubic->get_acentric()[i];
84 return components[i].molemass;
86 return HelmholtzEOSMixtureBackend::get_components()[i].EOS().sat_min_liquid.T;
88 return HelmholtzEOSMixtureBackend::get_components()[i].EOS().sat_min_liquid.p;
91 return components[i].rhomolarc;
103 return cubic->get_R_u();
108 reducing.T = cubic->get_Tr();
109 reducing.rhomolar = cubic->get_rhor();
118 std::vector<double> spinodal_densities();
122 return cubic->get_Tc()[0];
129 return cubic->get_pc()[0];
136 return cubic->get_acentric()[0];
138 throw ValueError(
"acentric factor cannot be calculated for mixtures");
144 double v_c_Lmol = 2.14107171795 * (cubic->get_Tc()[0] / cubic->get_pc()[0] * 1000) + 0.00773144012514;
145 return 1 / (v_c_Lmol / 1000.0);
164 CoolPropDbl calc_alphar_deriv_nocache(
const int nTau,
const int nDelta,
const std::vector<CoolPropDbl>&
mole_fractions,
const CoolPropDbl& tau,
165 const CoolPropDbl& delta);
197 void rho_Tp_cubic(CoolPropDbl T, CoolPropDbl
p,
int& Nsolns,
double& rho0,
double& rho1,
double& rho2);
208 CoolPropDbl
solver_rho_Tp(CoolPropDbl T, CoolPropDbl p, CoolPropDbl rho_guess = -1);
210 CoolPropDbl solver_rho_Tp_global(CoolPropDbl T, CoolPropDbl p, CoolPropDbl rhomax);
226 throw ValueError(
"set_binary_interaction_double not defined for AbstractCubic not defined for CAS #");
229 throw ValueError(
"get_binary_interaction_double not defined for AbstractCubic not defined for CAS #");
245 void set_cubic_alpha_C(
const size_t i,
const std::string& parameter,
const double c1,
const double c2,
const double c3);
258 SRKBackend(
const std::vector<double>& Tc,
const std::vector<double>& pc,
const std::vector<double>& acentric,
double R_u,
259 bool generate_SatL_and_SatV =
true) {
260 cubic.reset(
new SRK(Tc, pc, acentric, R_u));
261 setup(generate_SatL_and_SatV);
263 SRKBackend(
double Tc,
double pc,
double acentric,
double R_u,
bool generate_SatL_and_SatV =
true) {
264 cubic.reset(
new SRK(Tc, pc, acentric, R_u));
265 setup(generate_SatL_and_SatV);
268 bool generate_SatL_and_SatV =
true) {
269 std::vector<double> Tc, pc, acentric;
270 N = fluid_identifiers.size();
272 for (std::size_t i = 0; i < fluid_identifiers.size(); ++i) {
273 components[i] = CubicLibrary::get_cubic_values(fluid_identifiers[i]);
278 cubic.reset(
new SRK(Tc, pc, acentric, R_u));
279 setup(generate_SatL_and_SatV);
287 return get_backend_string(SRK_BACKEND);
296 PengRobinsonBackend(
const std::vector<double>& Tc,
const std::vector<double>& pc,
const std::vector<double>& acentric,
double R_u,
297 bool generate_SatL_and_SatV =
true) {
299 setup(generate_SatL_and_SatV);
301 PengRobinsonBackend(
double Tc,
double pc,
double acentric,
double R_u,
bool generate_SatL_and_SatV =
true) {
303 setup(generate_SatL_and_SatV);
306 bool generate_SatL_and_SatV =
true) {
307 std::vector<double> Tc, pc, acentric;
308 N = fluid_identifiers.size();
310 for (std::size_t i = 0; i < fluid_identifiers.size(); ++i) {
311 components[i] = CubicLibrary::get_cubic_values(fluid_identifiers[i]);
317 setup(generate_SatL_and_SatV);
321 new PengRobinsonBackend(cubic->get_Tc(), cubic->get_pc(), cubic->get_acentric(), cubic->get_R_u(), generate_SatL_and_SatV);
326 return get_backend_string(PR_BACKEND);
354 bool cache_values =
false) {
356 std::vector<double> z = std::vector<double>(mole_fractions.begin(), mole_fractions.end());
357 shared_ptr<AbstractCubic>& cubic = ACB->
get_cubic();
358 a.alphar = cubic->alphar(tau, delta, z, 0, 0);
359 a.dalphar_dtau = cubic->alphar(tau, delta, z, 1, 0);
360 a.dalphar_ddelta = cubic->alphar(tau, delta, z, 0, 1);
361 a.d2alphar_dtau2 = cubic->alphar(tau, delta, z, 2, 0);
362 a.d2alphar_ddelta_dtau = cubic->alphar(tau, delta, z, 1, 1);
363 a.d2alphar_ddelta2 = cubic->alphar(tau, delta, z, 0, 2);
364 a.d3alphar_dtau3 = cubic->alphar(tau, delta, z, 3, 0);
365 a.d3alphar_ddelta_dtau2 = cubic->alphar(tau, delta, z, 2, 1);
366 a.d3alphar_ddelta2_dtau = cubic->alphar(tau, delta, z, 1, 2);
367 a.d3alphar_ddelta3 = cubic->alphar(tau, delta, z, 0, 3);
368 a.d4alphar_dtau4 = cubic->alphar(tau, delta, z, 4, 0);
369 a.d4alphar_ddelta_dtau3 = cubic->alphar(tau, delta, z, 3, 1);
370 a.d4alphar_ddelta2_dtau2 = cubic->alphar(tau, delta, z, 2, 2);
371 a.d4alphar_ddelta3_dtau = cubic->alphar(tau, delta, z, 1, 3);
372 a.d4alphar_ddelta4 = cubic->alphar(tau, delta, z, 0, 4);
395 return ACB->
get_cubic()->d2_alphar_dxidxj(HEOS.
tau(), HEOS.
delta(), HEOS.get_mole_fractions_doubleref(), 0, 0, i, j,
399 return ACB->
get_cubic()->d2_alphar_dxidxj(HEOS.
tau(), HEOS.
delta(), HEOS.get_mole_fractions_doubleref(), 1, 0, i, j,
403 return ACB->
get_cubic()->d2_alphar_dxidxj(HEOS.
tau(), HEOS.
delta(), HEOS.get_mole_fractions_doubleref(), 0, 1, i, j,
420 return ACB->
get_cubic()->d2_alphar_dxidxj(HEOS.
tau(), HEOS.
delta(), HEOS.get_mole_fractions_doubleref(), 2, 0, i, j,
424 return ACB->
get_cubic()->d2_alphar_dxidxj(HEOS.
tau(), HEOS.
delta(), HEOS.get_mole_fractions_doubleref(), 1, 1, i, j,
428 return ACB->
get_cubic()->d2_alphar_dxidxj(HEOS.
tau(), HEOS.
delta(), HEOS.get_mole_fractions_doubleref(), 0, 2, i, j,
433 return ACB->
get_cubic()->d3_alphar_dxidxjdxk(HEOS.
tau(), HEOS.
delta(), HEOS.get_mole_fractions_doubleref(), 0, 0, i, j, k,
438 return ACB->
get_cubic()->d3_alphar_dxidxjdxk(HEOS.
tau(), HEOS.
delta(), HEOS.get_mole_fractions_doubleref(), 1, 0, i, j, k,
441 virtual CoolPropDbl d4alphar_dxi_dxj_dxk_dDelta(
HelmholtzEOSMixtureBackend& HEOS, std::size_t i, std::size_t j, std::size_t k,
443 return ACB->
get_cubic()->d3_alphar_dxidxjdxk(HEOS.
tau(), HEOS.
delta(), HEOS.get_mole_fractions_doubleref(), 0, 1, i, j, k,
double T(void)
Return the temperature in K.
Definition: AbstractState.h:1048
void set_binary_interaction_double(const std::size_t i1, const std::size_t i2, const std::string ¶meter, const double value)
Set binary mixture floating point parameter.
Definition: CubicBackend.cpp:587
void get_critical_point_starting_values(double &delta0, double &tau0)
Get the the starting values for the critical point evaluation routines.
Definition: CubicBackend.cpp:171
CoolPropDbl calc_gas_constant(void)
Calculate the gas constant in J/mol/K.
Definition: CubicBackend.h:102
double rhomolar(void)
Return the molar density in mol/m^3.
Definition: AbstractState.h:1052
std::string backend_name(void)
Get a string representation of the backend - for instance "HelmholtzEOSMixtureBackend" for the core m...
Definition: CubicBackend.h:286
const std::vector< CoolPropDbl > & get_mole_fractions(void)
Get the mole fractions of the fluid.
Definition: CubicBackend.h:70
void get_linear_reducing_parameters(double &rhomolar, double &T)
Get linear mole fraction weighting of the critical molar volumes and temperatures these are used in t...
Definition: CubicBackend.cpp:135
void set_binary_interaction_double(const std::string &CAS1, const std::string &CAS2, const std::string ¶meter, const double value)
Set binary mixture floating point parameter (EXPERT USE ONLY!!!)
Definition: CubicBackend.h:225
MoleFractions mole_fractions
The bulk mole fractions of the mixture.
Definition: HelmholtzEOSMixtureBackend.h:96
double delta(void)
Return the reduced density ( )
Definition: AbstractState.cpp:549
CoolPropDbl calc_T_critical(void)
Using this backend, get the critical point temperature in K.
Definition: CubicBackend.h:120
Definition: CubicBackend.h:291
CoolPropDbl calc_reciprocal_reduced_temperature(void)
Using this backend, calculate the reciprocal reduced temperature (Tc/T)
Definition: CubicBackend.h:115
virtual CoolPropDbl calc_T_critical(void)
Using this backend, get the critical point temperature in K.
Definition: HelmholtzEOSMixtureBackend.cpp:1033
Temperature at the critical point.
Definition: DataStructures.h:75
Molar density used for the critical point.
Definition: DataStructures.h:73
void set_fluid_parameter_double(const size_t i, const std::string ¶meter, const double value)
Set fluid parameter (currently the volume translation parameter for cubic)
Definition: CubicBackend.cpp:675
double get_config_double(configuration_keys key)
Return the value of a double configuration key.
Definition: Configuration.cpp:92
virtual void update(CoolProp::input_pairs input_pair, double value1, double value2)
The standard update function.
Definition: CubicBackend.cpp:283
phases
These are constants for the phases of the fluid.
Definition: DataStructures.h:176
phases phase(void)
Get the phase of the state.
Definition: AbstractState.h:938
Pressure at the critical point.
Definition: DataStructures.h:78
std::string backend_name(void)
Get a string representation of the backend - for instance "HelmholtzEOSMixtureBackend" for the core m...
Definition: CubicBackend.h:325
double get_fluid_parameter_double(const size_t i, const std::string ¶meter)
Double fluid parameter (currently the volume translation parameter for cubic)
Definition: CubicBackend.cpp:697
virtual CoolPropDbl calc_rhomolar_critical(void)
Using this backend, get the critical point molar density in mol/m^3.
Definition: HelmholtzEOSMixtureBackend.cpp:1059
Temperature at the reducing state.
Definition: DataStructures.h:74
std::size_t N
Number of components.
Definition: HelmholtzEOSMixtureBackend.h:101
Ideal-gas constant.
Definition: DataStructures.h:69
CoolPropDbl calc_molar_mass(void)
Using this backend, calculate the molar mass in kg/mol.
Definition: CubicBackend.cpp:579
double get_binary_interaction_double(const std::string &CAS1, const std::string &CAS2, const std::string ¶meter)
Get binary mixture double value (EXPERT USE ONLY!!!)
Definition: CubicBackend.h:228
void set_cubic_alpha_C(const size_t i, const std::string ¶meter, const double c1, const double c2, const double c3)
Set the cubic alpha function's constants:
Definition: CubicBackend.cpp:656
std::string get_parameter_information(int key, const std::string &info)
Return information about the parameter.
Definition: DataStructures.cpp:176
CoolPropDbl calc_p_critical(void)
Using this backend, get the critical point pressure in Pa.
Definition: CubicBackend.h:127
std::string fluid_param_string(const std::string &)
Return a string from the backend for the mixture/fluid.
Definition: CubicBackend.cpp:87
CoolPropDbl solver_rho_Tp(CoolPropDbl T, CoolPropDbl p, CoolPropDbl rho_guess=-1)
/brief Solve for rho = f(T,p)
Definition: CubicBackend.cpp:514
Definition: GeneralizedCubic.h:612
CoolPropDbl calc_rhomolar_critical(void)
Using this backend, get the critical point molar density in mol/m^3.
Definition: CubicBackend.h:141
const double get_fluid_constant(std::size_t i, parameters param) const
Get a constant for one of the fluids forming this mixture.
Definition: CubicBackend.h:74
bool get_critical_is_terminated(double &delta, double &tau)
Checking function to see if we should stop the tracing of the critical contour.
Definition: CubicBackend.cpp:161
virtual void update_DmolarT()
Update the state for DT inputs if phase is imposed. Otherwise delegate to base class.
Definition: CubicBackend.cpp:198
input_pairs
These are input pairs that can be used for the update function (in each pair, input keys are sorted a...
Definition: DataStructures.h:274
CoolPropDbl solver_rho_Tp_SRK(CoolPropDbl T, CoolPropDbl p, phases phase)
In this class, we are already doing cubic evaluation, just delegate to our function.
Definition: CubicBackend.h:200
Definition: Exceptions.h:45
This class implements all the derivatives of the Helmholtz energy (as well as composition derivatives...
Definition: CubicBackend.h:334
SimpleState calc_reducing_state_nocache(const std::vector< CoolPropDbl > &mole_fractions)
Get the reducing state to be used.
Definition: CubicBackend.h:106
std::vector< CubicLibrary::CubicsValues > components
The components that are in use.
Definition: CubicBackend.h:36
Definition: CubicBackend.h:32
shared_ptr< HelmholtzEOSMixtureBackend > TPD_state
A temporary state used for calculations of the tangent-plane-distance.
Definition: HelmholtzEOSMixtureBackend.h:67
Triple point temperature.
Definition: DataStructures.h:80
double tau(void)
Return the reciprocal of the reduced temperature ( )
Definition: AbstractState.cpp:545
Molar mass.
Definition: DataStructures.h:70
shared_ptr< AbstractCubic > & get_cubic()
Get a reference to the shared pointer managing the generalized cubic class.
Definition: CubicBackend.h:48
Molar density used for the reducing state.
Definition: DataStructures.h:72
Acentric factor.
Definition: DataStructures.h:71
std::vector< std::string > calc_fluid_names(void)
Using this backend, get a vector of fluid names.
Definition: CubicBackend.cpp:127
virtual HelmholtzDerivatives all(HelmholtzEOSMixtureBackend &HEOS, const std::vector< CoolPropDbl > &mole_fractions, double tau, double delta, bool cache_values=false)
All the derivatives of the residual Helmholtz energy w.r.t. tau and delta that do not involve composi...
Definition: CubicBackend.h:353
void update_TPD_state()
Update the state used to calculate the tangent-plane-distance.
Definition: CubicBackend.h:213
void copy_internals(AbstractCubicBackend &donor)
Copy the internals from another class into this one (kij, alpha functions, cp0 functions, etc.)
Definition: CubicBackend.cpp:642
Definition: Helmholtz.h:45
double p(void)
Return the pressure in Pa.
Definition: AbstractState.h:1060
void saturation(CoolProp::input_pairs inputs)
Cubic backend flashes for PQ, and QT.
Definition: CubicBackend.cpp:447
x_N is an independent variable, and not calculated by
Definition: ReducingFunctions.h:20
double _rhomolar
Bulk values.
Definition: AbstractState.h:108
Definition: GeneralizedCubic.h:632
CoolPropDbl calc_pressure_nocache(CoolPropDbl T, CoolPropDbl rhomolar)
Calculate the pressure in most computationally efficient manner.
Definition: CubicBackend.cpp:192
Definition: HelmholtzEOSMixtureBackend.h:58
Triple point pressure.
Definition: DataStructures.h:81
void set_alpha_from_components()
Set the alpha function based on the alpha function defined in the components vector;.
Definition: CubicBackend.cpp:45
void setup(bool generate_SatL_and_SatV=true)
Set the pointer to the residual helmholtz class, etc.
Definition: CubicBackend.cpp:6
void set_alpha0_from_components()
Set the non-dimensionalized Helmholtz energy based on the fluids defined in the components vector...
Definition: CubicBackend.cpp:69
virtual CoolPropDbl calc_p_critical(void)
Using this backend, get the critical point pressure in Pa.
Definition: HelmholtzEOSMixtureBackend.cpp:1046
Definition: CubicBackend.h:254
void rho_Tp_cubic(CoolPropDbl T, CoolPropDbl p, int &Nsolns, double &rho0, double &rho1, double &rho2)
Use the cubic EOS to solve for density.
Definition: CubicBackend.cpp:337
x_N_dependency_flag
Definition: ReducingFunctions.h:18
bool is_pure_or_pseudopure
A flag for whether the substance is a pure or pseudo-pure fluid (true) or a mixture (false) ...
Definition: HelmholtzEOSMixtureBackend.h:95
void get_critical_point_search_radii(double &R_delta, double &R_tau)
Get the search radius in delta and tau for the tracer, scaled appropriately for cubic.
Definition: CubicBackend.cpp:150
This file contains flash routines in which the state is unknown, and a solver of some kind must be us...
Definition: AbstractState.h:19
double get_binary_interaction_double(const std::size_t i1, const std::size_t i2, const std::string ¶meter)
Get binary mixture double value.
Definition: CubicBackend.cpp:608
CoolPropDbl calc_reduced_density(void)
Using this backend, calculate the reduced density (rho/rhoc)
Definition: CubicBackend.h:112
parameters
Define some constants that will be used throughout These are constants for the input and output para...
Definition: DataStructures.h:64
CoolPropDbl calc_acentric_factor(void)
Using this backend, calculate the acentric factor.
Definition: CubicBackend.h:134
This class contains the two primary contributions to the residual Helmholtz energy - a corresponding ...
Definition: HelmholtzEOSMixtureBackend.h:791
Definition: DataStructures.h:16