diff --git a/include/AbstractState.h b/include/AbstractState.h index 4b09ac2b49..86680640c3 100644 --- a/include/AbstractState.h +++ b/include/AbstractState.h @@ -484,6 +484,8 @@ class AbstractState { virtual double get_binary_interaction_double(const std::size_t i, const std::size_t j, const std::string ¶meter){ throw NotImplementedError("get_binary_interaction_double is not implemented for this backend"); }; /// Get binary mixture string value (EXPERT USE ONLY!!!) virtual std::string get_binary_interaction_string(const std::string &CAS1, const std::string &CAS2, const std::string ¶meter){ throw NotImplementedError("get_binary_interaction_string is not implemented for this backend"); }; + /// Apply a simple mixing rule (EXPERT USE ONLY!!!) + virtual void apply_simple_mixing_rule(std::size_t i, std::size_t j, const std::string &model) { throw NotImplementedError("apply_simple_mixing_rule is not implemented for this backend"); }; /// Clear all the cached values virtual bool clear(); diff --git a/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp b/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp index f37a4fb177..e7558200e6 100644 --- a/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp +++ b/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp @@ -195,6 +195,27 @@ std::string HelmholtzEOSMixtureBackend::fluid_param_string(const std::string &Pa } } +void HelmholtzEOSMixtureBackend::apply_simple_mixing_rule(std::size_t i, std::size_t j, const std::string &model){ + if (model == "linear"){ + double Tc1 = get_fluid_constant(i, iT_critical), Tc2 = get_fluid_constant(j, iT_critical); + double gammaT = 0.5*(Tc1 + Tc2) / sqrt(Tc1*Tc2); + double rhoc1 = get_fluid_constant(i, irhomolar_critical), rhoc2 = get_fluid_constant(j, irhomolar_critical); + double gammaV = 4.0 * (1/rhoc1 + 1/rhoc2) / pow(pow(rhoc1, -1.0 / 3.0) + pow(rhoc2, -1.0/3.0), 3); + set_binary_interaction_double(i, j, "betaT", 1.0); + set_binary_interaction_double(i, j, "gammaT", gammaT); + set_binary_interaction_double(i, j, "betaV", 1.0); + set_binary_interaction_double(i, j, "gammaV", gammaV); + } + else if (model == "Lorentz-Berthelot"){ + set_binary_interaction_double(i, j, "betaT", 1.0); + set_binary_interaction_double(i, j, "gammaT", 1.0); + set_binary_interaction_double(i, j, "betaV", 1.0); + set_binary_interaction_double(i, j, "gammaV", 1.0); + } + else{ + throw ValueError(format("mixing rule [%s] is not understood", model.c_str())); + } +} /// Set binary mixture floating point parameter for this instance void HelmholtzEOSMixtureBackend::set_binary_interaction_double(const std::size_t i, const std::size_t j, const std::string ¶meter, const double value){ if (parameter == "Fij"){ @@ -204,6 +225,9 @@ void HelmholtzEOSMixtureBackend::set_binary_interaction_double(const std::size_t else{ Reducing->set_binary_interaction_double(i,j,parameter,value); } + /// Also set the parameters in the managed pointers for saturated liquid and vapor states + if (this->SatL){ this->SatL->set_binary_interaction_double(i, j, parameter, value); } + if (this->SatV) { this->SatV->set_binary_interaction_double(i, j, parameter, value); } }; /// Get binary mixture floating point parameter for this instance double HelmholtzEOSMixtureBackend::get_binary_interaction_double(const std::size_t i, const std::size_t j, const std::string ¶meter){ diff --git a/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.h b/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.h index e316ebdfb7..298a04076f 100644 --- a/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.h +++ b/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.h @@ -84,6 +84,8 @@ class HelmholtzEOSMixtureBackend : public AbstractState { virtual double get_binary_interaction_double(const std::size_t i, const std::size_t j, const std::string ¶meter); ///// Get binary mixture string value //virtual std::string get_binary_interaction_string(const std::size_t &i, const std::size_t &j, const std::string ¶meter); + /// Apply a simple mixing rule + void apply_simple_mixing_rule(std::size_t i, std::size_t j, const std::string &model); phases calc_phase(void){return _phase;}; void calc_specify_phase(phases phase){ specify_phase(phase); } diff --git a/wrappers/Python/CoolProp/AbstractState.pxd b/wrappers/Python/CoolProp/AbstractState.pxd index 16a2dbedb0..bd3e706328 100644 --- a/wrappers/Python/CoolProp/AbstractState.pxd +++ b/wrappers/Python/CoolProp/AbstractState.pxd @@ -52,6 +52,7 @@ cdef class AbstractState: cpdef double get_binary_interaction_double(self, string_or_size_t CAS1, string_or_size_t CAS2, string parameter) except * cpdef set_binary_interaction_string(self, string CAS1, string CAS2, string parameter, string val) cpdef string get_binary_interaction_string(self, string CAS1, string CAS2, string parameter) except * + cpdef apply_simple_mixing_rule(self, size_t, size_t, string) cpdef name(self) cpdef fluid_param_string(self, string key) diff --git a/wrappers/Python/CoolProp/AbstractState.pyx b/wrappers/Python/CoolProp/AbstractState.pyx index b6e7c501ec..9a16dffbd4 100644 --- a/wrappers/Python/CoolProp/AbstractState.pyx +++ b/wrappers/Python/CoolProp/AbstractState.pyx @@ -54,6 +54,10 @@ cdef class AbstractState: """ Change the EOS for one component - wrapper of c++ function :cpapi:`CoolProp::AbstractState::change_EOS` """ self.thisptr.change_EOS(i, EOS_name) + cpdef apply_simple_mixing_rule(self, size_t i, size_t j, string model): + """ Apply a simple mixing rule - wrapper of c++ function :cpapi:`CoolProp::AbstractState::apply_simple_mixing_rule` """ + self.thisptr.apply_simple_mixing_rule(i, j, model) + cpdef set_binary_interaction_double(self, string_or_size_t arg1, string_or_size_t arg2, string parameter, double val): """ Set a double precision interaction parameter - wrapper of c++ function :cpapi:`CoolProp::AbstractState::set_binary_interaction_double` """ if string_or_size_t in cython.integral: diff --git a/wrappers/Python/CoolProp/cAbstractState.pxd b/wrappers/Python/CoolProp/cAbstractState.pxd index b89f27346b..2c4b37cef1 100644 --- a/wrappers/Python/CoolProp/cAbstractState.pxd +++ b/wrappers/Python/CoolProp/cAbstractState.pxd @@ -52,6 +52,7 @@ cdef extern from "AbstractState.h" namespace "CoolProp": void set_binary_interaction_string(const string &, const string &, const string &, const string &) except +ValueError double get_binary_interaction_double(const string &, const string &, const string &) except +ValueError string get_binary_interaction_string(const string &, const string &, const string &) except +ValueError + void apply_simple_mixing_rule(size_t, size_t, const string &) except +ValueError double get_binary_interaction_double(const size_t, const size_t, const string &) except +ValueError void set_binary_interaction_double(const size_t, const size_t, const string &, const double s) except +ValueError