CoolProp
REFPROPMixtureBackend.h
1 /*
2  * AbstractBackend.h
3  *
4  * Created on: 20 Dec 2013
5  * Author: jowr
6  */
7 
8 #ifndef REFPROPMIXTUREBACKEND_H_
9 #define REFPROPMIXTUREBACKEND_H_
10 
11 #include "AbstractState.h"
12 #include "DataStructures.h"
13 
14 #include <vector>
15 
16 namespace CoolProp {
17 
18 
20  private:
21  std::string cached_component_string;
22 protected:
23  std::size_t Ncomp;
24  bool _mole_fractions_set;
25 
26  static std::size_t instance_counter;
27  static bool _REFPROP_supported;
28  std::vector<CoolPropDbl> mole_fractions_long_double; // read-only
29  std::vector<double> mole_fractions, mass_fractions;
30  std::vector<double> mole_fractions_liq, mole_fractions_vap;
31  std::vector<std::string> fluid_names;
32 
33 
35  CoolPropDbl call_phixdll(int itau, int idelta);
37  CoolPropDbl call_phi0dll(int itau, int idelta);
38 
39 public:
40  REFPROPMixtureBackend():Ncomp(0),_mole_fractions_set(false) {instance_counter++;}
41 
44  REFPROPMixtureBackend(const std::vector<std::string>& fluid_names) {construct(fluid_names);};
45 
47  void construct(const std::vector<std::string>& fluid_names);
48 
49  std::string backend_name(void) { return get_backend_string(REFPROP_BACKEND_MIX); }
50  virtual ~REFPROPMixtureBackend();
51 
52  static std::string version();
53 
54  std::vector<std::string> calc_fluid_names(){return fluid_names;};
55  PhaseEnvelopeData PhaseEnvelope;
56 
58  void set_binary_interaction_double(const std::string &CAS1, const std::string &CAS2, const std::string &parameter, const double value);
60  double get_binary_interaction_double(const std::string &CAS1, const std::string &CAS2, const std::string &parameter);
61 
63  std::string get_binary_interaction_string(const std::string &CAS1, const std::string &CAS2, const std::string &parameter);
65  void set_binary_interaction_string(const std::size_t i, const std::size_t j, const std::string &parameter, const std::string &value);
66 
68  void set_binary_interaction_double(const std::size_t i, const std::size_t j, const std::string &parameter, const double value);
70  double get_binary_interaction_double(const std::size_t i, const std::size_t j, const std::string &parameter);
71 
73  int match_CAS(const std::string &CAS);
74 
75  // REFPROP backend uses mole fractions
76  bool using_mole_fractions(){return true;}
77  bool using_mass_fractions(){return false;}
78  bool using_volu_fractions(){return false;}
79 
81  std::string calc_name(){ return fluid_param_string("name"); }
82 
83  // Get _phase for pure fluids only
84  phases calc_phase(void) {
85  if (this->Ncomp > 1) {
86  throw NotImplementedError("The REFPROP backend does not implement calc_phase function for mixtures.");
87  }
88  else {
89  return _phase;
90  }
91  };
92 
93  // Utility function to determine the phase from quality value return from REFPROP
94  phases GetRPphase();
95 
100  void calc_specify_phase(phases phase_index){ imposed_phase_index = phase_index; _phase = phase_index; }
103  void calc_unspecify_phase(){ imposed_phase_index = iphase_not_imposed;}
104 
106 
117  double value1,
118  double value2
119  );
120 
125  double value1,
126  double value2,
127  const GuessesStructure &guesses);
128 
129  CoolPropDbl calc_molar_mass(void);
130 
131  void check_loaded_fluid(void);
132 
133  void calc_excess_properties();
134 
136  static bool REFPROP_supported(void);
137 
138  std::string fluid_param_string(const std::string &ParamName);
139 
140  CoolPropDbl calc_PIP(void);
141 
142  CoolPropDbl calc_cpmolar_idealgas(void);
143 
145 
148  void set_REFPROP_fluids(const std::vector<std::string> &fluid_names);
149 
151 
154  void set_mole_fractions(const std::vector<CoolPropDbl> &mole_fractions);
155 
157 
160  void set_mass_fractions(const std::vector<CoolPropDbl> &mass_fractions);
161 
162  const std::vector<CoolPropDbl> &get_mole_fractions(){return mole_fractions_long_double;};
163 
164  const std::vector<CoolPropDbl> calc_mass_fractions();
165 
166  void calc_phase_envelope(const std::string &type);
167 
168  CoolPropDbl calc_compressibility_factor(void){ return _p/(_rhomolar*gas_constant()*_T); };
169 
170  const CoolProp::PhaseEnvelopeData &calc_phase_envelope_data(){return PhaseEnvelope;};
171 
172  std::vector<CoolPropDbl> calc_mole_fractions_liquid(void){return std::vector<CoolPropDbl>(mole_fractions_liq.begin(), mole_fractions_liq.begin()+this->Ncomp);}
173  std::vector<CoolPropDbl> calc_mole_fractions_vapor(void){return std::vector<CoolPropDbl>(mole_fractions_vap.begin(), mole_fractions_vap.begin()+this->Ncomp);}
174 
176  void check_status();
177 
179  CoolPropDbl calc_viscosity(void);
181  CoolPropDbl calc_conductivity(void);
183  CoolPropDbl calc_surface_tension(void);
185  CoolPropDbl calc_Bvirial(void);
187  CoolPropDbl calc_dBvirial_dT(void);
189  CoolPropDbl calc_Cvirial(void);
190 
191  CoolPropDbl calc_fugacity_coefficient(std::size_t i);
192  CoolPropDbl calc_fugacity(std::size_t i);
193  CoolPropDbl calc_chemical_potential(std::size_t i);
194  CoolPropDbl calc_melting_line(int param, int given, CoolPropDbl value);
195  bool has_melting_line();
196  double calc_melt_Tmax();
197  CoolPropDbl calc_T_critical(void);
198  CoolPropDbl calc_T_reducing(void);
199  void calc_reducing_state(void);
200  CoolPropDbl calc_p_critical(void);
201  CoolPropDbl calc_p_triple(void);
202  CoolPropDbl calc_p_min(void){return calc_p_triple();};
203  CoolPropDbl calc_rhomolar_critical(void);
204  CoolPropDbl calc_rhomolar_reducing(void);
205  CoolPropDbl calc_Ttriple(void);
206  CoolPropDbl calc_acentric_factor(void);
207  CoolPropDbl calc_gas_constant(void);
208  CoolPropDbl calc_dipole_moment(void);
209 
211  void calc_true_critical_point(double &T, double &rho);
212 
215  CoolPropDbl calc_saturated_vapor_keyed_output(parameters key);
216 
218  void calc_ideal_curve(const std::string &type, std::vector<double> &T, std::vector<double> &p);
219 
221  void limits(double &Tmin, double &Tmax, double &rhomolarmax, double &pmax);
223  CoolPropDbl calc_pmax(void);
225  CoolPropDbl calc_Tmax(void);
227  CoolPropDbl calc_Tmin(void);
228 
230  CoolPropDbl calc_smolar_residual(void){ return (tau()*calc_dalphar_dTau()-calc_alphar())*gas_constant(); }
231 
233  CoolPropDbl calc_alphar(void){return call_phixdll(0,0);};
235  CoolPropDbl calc_dalphar_dDelta(void){ return call_phixdll(0,1); };
237  CoolPropDbl calc_dalphar_dTau(void){ return call_phixdll(1,0); };
239  CoolPropDbl calc_d2alphar_dDelta2(void){ return call_phixdll(0,2); };
241  CoolPropDbl calc_d2alphar_dDelta_dTau(void){ return call_phixdll(1,1); };
243  CoolPropDbl calc_d2alphar_dTau2(void){ return call_phixdll(2,0); };
245  CoolPropDbl calc_d3alphar_dDelta3(void){ return call_phixdll(0,3); };
247  CoolPropDbl calc_d3alphar_dDelta2_dTau(void){ return call_phixdll(1,2); };
249  CoolPropDbl calc_d3alphar_dDelta_dTau2(void){ return call_phixdll(2,1); };
251  CoolPropDbl calc_d3alphar_dTau3(void){ return call_phixdll(3,0); };
252 
253  CoolPropDbl calc_alpha0(void){ return call_phi0dll(0,0); };
254  CoolPropDbl calc_dalpha0_dDelta(void){ return call_phi0dll(0,1); };
255  CoolPropDbl calc_dalpha0_dTau(void){ return call_phi0dll(1,0); };
256  CoolPropDbl calc_d2alpha0_dDelta2(void){ return call_phi0dll(0,2); };
257  CoolPropDbl calc_d2alpha0_dDelta_dTau(void){ return call_phi0dll(1,1); };
258  CoolPropDbl calc_d2alpha0_dTau2(void){ return call_phi0dll(2,0); };
259  CoolPropDbl calc_d3alpha0_dDelta3(void){ return call_phi0dll(0,3); };
260  CoolPropDbl calc_d3alpha0_dDelta2_dTau(void){ return call_phi0dll(1,2); };
261  CoolPropDbl calc_d3alpha0_dDelta_dTau2(void){ return call_phi0dll(2,1); };
262  CoolPropDbl calc_d3alpha0_dTau3(void){ return call_phi0dll(3,0); };
263 };
264 
265 bool force_load_REFPROP();
266 bool force_unload_REFPROP();
267 void REFPROP_SETREF(char hrf[3], int ixflag, double x0[1], double &h0, double &s0, double &T0, double &p0, int &ierr, char herr[255], int l1, int l2);
268 
269 } /* namespace CoolProp */
270 #endif /* REFPROPMIXTUREBACKEND_H_ */
double T(void)
Return the temperature in K.
Definition: AbstractState.h:700
phases imposed_phase_index
If the phase is imposed, the imposed phase index.
Definition: AbstractState.h:76
CoolPropDbl calc_dBvirial_dT(void)
Calc the temperature derivative of the second virial coefficient.
Definition: REFPROPMixtureBackend.cpp:899
static bool REFPROP_supported(void)
Returns true if REFPROP is supported on this platform.
Definition: REFPROPMixtureBackend.cpp:207
double gas_constant(void)
Return the mole-fraction weighted gas constant in J/mol/K.
Definition: AbstractState.cpp:651
CoolPropDbl calc_Ttriple(void)
Using this backend, get the triple point temperature in K.
Definition: REFPROPMixtureBackend.cpp:798
void calc_ideal_curve(const std::string &type, std::vector< double > &T, std::vector< double > &p)
Calculate an ideal curve.
Definition: REFPROPMixtureBackend.cpp:2106
CoolPropDbl calc_molar_mass(void)
Using this backend, calculate the molar mass in kg/mol.
Definition: REFPROPMixtureBackend.cpp:885
double get_binary_interaction_double(const std::string &CAS1, const std::string &CAS2, const std::string &parameter)
Get binary mixture double value.
Definition: REFPROPMixtureBackend.cpp:536
CoolPropDbl calc_d2alphar_dDelta2(void)
Using this backend, calculate the residual Helmholtz energy term (dimensionless) ...
Definition: REFPROPMixtureBackend.h:239
CoolPropDbl calc_viscosity(void)
Get the viscosity [Pa-s] (based on the temperature and density in the state class) ...
Definition: REFPROPMixtureBackend.cpp:1003
CoolPropDbl calc_rhomolar_reducing(void)
Using this backend, get the reducing point molar density in mol/m^3.
Definition: REFPROPMixtureBackend.cpp:777
CoolPropDbl calc_p_triple(void)
Using this backend, get the triple point pressure in Pa.
Definition: REFPROPMixtureBackend.cpp:831
CoolPropDbl calc_dalphar_dDelta(void)
Using this backend, calculate the residual Helmholtz energy term (dimensionless) ...
Definition: REFPROPMixtureBackend.h:235
CoolPropDbl calc_p_critical(void)
Using this backend, get the critical point pressure in Pa.
Definition: REFPROPMixtureBackend.cpp:749
CoolPropDbl calc_pmax(void)
Calculate the maximum pressure.
Definition: REFPROPMixtureBackend.cpp:725
CoolPropDbl calc_fugacity(std::size_t i)
Using this backend, calculate the fugacity in Pa.
Definition: REFPROPMixtureBackend.cpp:1053
void update(CoolProp::input_pairs, double value1, double value2)
Updating function for REFPROP.
Definition: REFPROPMixtureBackend.cpp:1221
CoolPropDbl calc_dalpha0_dTau(void)
Using this backend, calculate the ideal-gas Helmholtz energy term (dimensionless) ...
Definition: REFPROPMixtureBackend.h:255
phases
These are constants for the phases of the fluid.
Definition: DataStructures.h:158
CoolPropDbl calc_d3alpha0_dDelta_dTau2(void)
Using this backend, calculate the ideal-gas Helmholtz energy term (dimensionless) ...
Definition: REFPROPMixtureBackend.h:261
CoolPropDbl calc_T_critical(void)
Using this backend, get the critical point temperature in K.
Definition: REFPROPMixtureBackend.cpp:740
std::vector< std::string > calc_fluid_names()
Using this backend, get a vector of fluid names.
Definition: REFPROPMixtureBackend.h:54
void calc_specify_phase(phases phase_index)
Specify the phase - this phase will always be used in calculations.
Definition: REFPROPMixtureBackend.h:100
void set_binary_interaction_string(const std::size_t i, const std::size_t j, const std::string &parameter, const std::string &value)
Set binary mixture string value.
Definition: REFPROPMixtureBackend.cpp:570
CoolPropDbl call_phixdll(int itau, int idelta)
Call the PHIXdll function in the dll.
Definition: REFPROPMixtureBackend.cpp:1977
void calc_unspecify_phase()
Unspecify the phase - the phase is no longer imposed, different solvers can do as they like...
Definition: REFPROPMixtureBackend.h:103
double Tmax(void)
Get the maximum temperature in K.
Definition: AbstractState.cpp:516
void construct(const std::vector< std::string > &fluid_names)
A function to actually do the initialization to allow it to be called in derived classes.
Definition: REFPROPMixtureBackend.cpp:174
CoolPropDbl calc_cpmolar_idealgas(void)
Using this backend, calculate the ideal gas molar constant-pressure specific heat in J/mol/K...
Definition: REFPROPMixtureBackend.cpp:1174
CoolPropDbl calc_Tmin(void)
Calculate the minimum temperature.
Definition: REFPROPMixtureBackend.cpp:735
CoolPropDbl calc_d2alpha0_dTau2(void)
Using this backend, calculate the ideal-gas Helmholtz energy term (dimensionless) ...
Definition: REFPROPMixtureBackend.h:258
CoolPropDbl calc_conductivity(void)
Get the thermal conductivity [W/m/K] (based on the temperature and density in the state class) ...
Definition: REFPROPMixtureBackend.cpp:1018
CoolPropDbl calc_dalpha0_dDelta(void)
Using this backend, calculate the ideal-gas Helmholtz energy term (dimensionless) ...
Definition: REFPROPMixtureBackend.h:254
The mother of all state classes.
Definition: AbstractState.h:70
CoolPropDbl calc_Cvirial(void)
Calc the C virial coefficient.
Definition: REFPROPMixtureBackend.cpp:905
CoolPropDbl calc_surface_tension(void)
Get the surface tension [N/m] (based on the temperature in the state class). Invalid for temperatures...
Definition: REFPROPMixtureBackend.cpp:1024
CoolPropDbl calc_d2alphar_dTau2(void)
Using this backend, calculate the residual Helmholtz energy term (dimensionless) ...
Definition: REFPROPMixtureBackend.h:243
CoolPropDbl calc_gas_constant(void)
Using this backend, calculate the universal gas constant in J/mol/K.
Definition: REFPROPMixtureBackend.cpp:879
bool has_melting_line()
Return true if the fluid has a melting line - default is false, but can be re-implemented by derived ...
Definition: REFPROPMixtureBackend.cpp:958
void set_mass_fractions(const std::vector< CoolPropDbl > &mass_fractions)
Set the mass fractions.
Definition: REFPROPMixtureBackend.cpp:669
CoolPropDbl calc_d3alpha0_dTau3(void)
Using this backend, calculate the ideal-gas Helmholtz energy term (dimensionless) ...
Definition: REFPROPMixtureBackend.h:262
A data structure to hold the data for a phase envelope.
Definition: PhaseEnvelope.h:14
void limits(double &Tmin, double &Tmax, double &rhomolarmax, double &pmax)
A wrapper function to calculate the limits for the EOS.
Definition: REFPROPMixtureBackend.cpp:693
CoolPropDbl calc_d3alpha0_dDelta2_dTau(void)
Using this backend, calculate the ideal-gas Helmholtz energy term (dimensionless) ...
Definition: REFPROPMixtureBackend.h:260
CoolPropDbl calc_d3alphar_dDelta_dTau2(void)
Using this backend, calculate the residual Helmholtz energy term (dimensionless) ...
Definition: REFPROPMixtureBackend.h:249
std::string calc_name()
Calculate the name of the fluid.
Definition: REFPROPMixtureBackend.h:81
CoolPropDbl calc_fugacity_coefficient(std::size_t i)
Using this backend, calculate the fugacity coefficient (dimensionless)
Definition: REFPROPMixtureBackend.cpp:1038
CoolPropDbl calc_d3alphar_dTau3(void)
Using this backend, calculate the residual Helmholtz energy term (dimensionless) ...
Definition: REFPROPMixtureBackend.h:251
CoolPropDbl calc_compressibility_factor(void)
Using this backend, calculate the compressibility factor Z .
Definition: REFPROPMixtureBackend.h:168
void set_binary_interaction_double(const std::string &CAS1, const std::string &CAS2, const std::string &parameter, const double value)
Set binary mixture floating point parameter.
Definition: REFPROPMixtureBackend.cpp:531
std::string fluid_param_string(const std::string &ParamName)
Return a string from the backend for the mixture/fluid - backend dependent - could be CAS #...
Definition: REFPROPMixtureBackend.cpp:472
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:216
void set_mole_fractions(const std::vector< CoolPropDbl > &mole_fractions)
Set the mole fractions.
Definition: REFPROPMixtureBackend.cpp:655
CoolPropDbl calc_Bvirial(void)
Calc the B virial coefficient.
Definition: REFPROPMixtureBackend.cpp:893
Definition: Exceptions.h:26
CoolPropDbl calc_acentric_factor(void)
Using this backend, calculate the acentric factor.
Definition: REFPROPMixtureBackend.cpp:783
CoolPropDbl calc_d2alpha0_dDelta2(void)
Using this backend, calculate the ideal-gas Helmholtz energy term (dimensionless) ...
Definition: REFPROPMixtureBackend.h:256
CoolPropDbl calc_rhomolar_critical(void)
Using this backend, get the critical point molar density in mol/m^3.
Definition: REFPROPMixtureBackend.cpp:757
Definition: REFPROPMixtureBackend.h:19
std::vector< std::string > fluid_names(void)
Return a vector of strings of the fluid names that are in use.
Definition: AbstractState.cpp:173
double tau(void)
Return the reciprocal of the reduced temperature ( )
Definition: AbstractState.cpp:505
void calc_excess_properties()
Calculate excess properties.
Definition: REFPROPMixtureBackend.cpp:1994
CoolPropDbl calc_chemical_potential(std::size_t i)
Using this backend, calculate the chemical potential in J/mol.
Definition: REFPROPMixtureBackend.cpp:1067
CoolPropDbl calc_d3alphar_dDelta2_dTau(void)
Using this backend, calculate the residual Helmholtz energy term (dimensionless) ...
Definition: REFPROPMixtureBackend.h:247
CoolPropDbl calc_d2alpha0_dDelta_dTau(void)
Using this backend, calculate the ideal-gas Helmholtz energy term (dimensionless) ...
Definition: REFPROPMixtureBackend.h:257
const std::vector< CoolPropDbl > & get_mole_fractions()
Get the mole fractions of the fluid.
Definition: REFPROPMixtureBackend.h:162
CoolPropDbl calc_d3alphar_dDelta3(void)
Using this backend, calculate the residual Helmholtz energy term (dimensionless) ...
Definition: REFPROPMixtureBackend.h:245
void calc_phase_envelope(const std::string &type)
Using this backend, construct the phase envelope, the variable type describes the type of phase envel...
Definition: REFPROPMixtureBackend.cpp:1082
double p(void)
Return the pressure in Pa.
Definition: AbstractState.h:706
void update_with_guesses(CoolProp::input_pairs, double value1, double value2, const GuessesStructure &guesses)
Update the state, while providing guess values.
Definition: REFPROPMixtureBackend.cpp:1867
double Tmin(void)
Get the minimum temperature in K.
Definition: AbstractState.cpp:513
CoolPropDbl call_phi0dll(int itau, int idelta)
Call the PHI0dll function in the dll.
Definition: REFPROPMixtureBackend.cpp:1985
CoolPropDbl calc_alphar(void)
Using this backend, calculate the residual Helmholtz energy term (dimensionless) ...
Definition: REFPROPMixtureBackend.h:233
phases _phase
The key for the phase from CoolProp::phases enum.
Definition: AbstractState.h:75
double _rhomolar
Bulk values.
Definition: AbstractState.h:100
CoolPropDbl calc_d2alphar_dDelta_dTau(void)
Using this backend, calculate the residual Helmholtz energy term (dimensionless) ...
Definition: REFPROPMixtureBackend.h:241
This simple class holds the values for guesses for use in some solvers that have the ability to use g...
Definition: AbstractState.h:32
REFPROPMixtureBackend(const std::vector< std::string > &fluid_names)
The instantiator.
Definition: REFPROPMixtureBackend.h:44
std::string backend_name(void)
Get a string representation of the backend - for instance "HelmholtzEOSMixtureBackend" for the core m...
Definition: REFPROPMixtureBackend.h:49
CoolPropDbl calc_dipole_moment(void)
Using this backend, calculate the dipole moment in C-m (1 D = 3.33564e-30 C-m)
Definition: REFPROPMixtureBackend.cpp:848
std::string get_binary_interaction_string(const std::string &CAS1, const std::string &CAS2, const std::string &parameter)
Get binary mixture string value.
Definition: REFPROPMixtureBackend.cpp:541
CoolPropDbl calc_d3alpha0_dDelta3(void)
Using this backend, calculate the ideal-gas Helmholtz energy term (dimensionless) ...
Definition: REFPROPMixtureBackend.h:259
CoolPropDbl calc_saturated_liquid_keyed_output(parameters key)
Calculate the saturation properties.
Definition: REFPROPMixtureBackend.cpp:2063
CoolPropDbl calc_dalphar_dTau(void)
Using this backend, calculate the residual Helmholtz energy term (dimensionless) ...
Definition: REFPROPMixtureBackend.h:237
CoolPropDbl calc_alpha0(void)
Using this backend, calculate the ideal-gas Helmholtz energy term (dimensionless) ...
Definition: REFPROPMixtureBackend.h:253
CoolPropDbl calc_Tmax(void)
Calculate the maximum temperature.
Definition: REFPROPMixtureBackend.cpp:730
phases calc_phase(void)
Using this backend, calculate the phase.
Definition: REFPROPMixtureBackend.h:84
void check_status()
Check if the mole fractions have been set, etc.
Definition: REFPROPMixtureBackend.cpp:688
This file contains flash routines in which the state is unknown, and a solver of some kind must be us...
Definition: AbstractState.h:19
CoolPropDbl calc_PIP(void)
Using this backend, calculate the phase identification parameter (PIP)
Definition: REFPROPMixtureBackend.cpp:987
parameters
Define some constants that will be used throughout These are constants for the input and output para...
Definition: DataStructures.h:49
double pmax(void)
Get the maximum pressure in Pa.
Definition: AbstractState.cpp:522
void calc_true_critical_point(double &T, double &rho)
Calculate the "true" critical point where dp/drho|T and d2p/drho2|T are zero.
Definition: REFPROPMixtureBackend.cpp:2036
void set_REFPROP_fluids(const std::vector< std::string > &fluid_names)
Set the fluids in REFPROP DLL by calling the SETUPdll function.
Definition: REFPROPMixtureBackend.cpp:295
CoolPropDbl calc_smolar_residual(void)
Calculate the residual entropy in J/mol/K (should be a uniquely negative quantity) ...
Definition: REFPROPMixtureBackend.h:230
CoolPropDbl calc_T_reducing(void)
Using this backend, get the reducing point temperature in K.
Definition: REFPROPMixtureBackend.cpp:771
int match_CAS(const std::string &CAS)
Find the index (1-based for FORTRAN) of the fluid with the given CAS number.
Definition: REFPROPMixtureBackend.cpp:517