Skip to content

Commit

Permalink
Add apply_simple_mixing_rule to AbstractState; fix bug with SatL and …
Browse files Browse the repository at this point in the history
…SatV and setting interaction parameters

closes #1048
closes #1049
  • Loading branch information
ibell committed May 8, 2016
1 parent 4562e6e commit 5fcb5dd
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/AbstractState.h
Expand Up @@ -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 &parameter){ 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 &parameter){ 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();
Expand Down
24 changes: 24 additions & 0 deletions src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp
Expand Up @@ -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 &parameter, const double value){
if (parameter == "Fij"){
Expand All @@ -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 &parameter){
Expand Down
2 changes: 2 additions & 0 deletions src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.h
Expand Up @@ -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 &parameter);
///// 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 &parameter);
/// 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); }
Expand Down
1 change: 1 addition & 0 deletions wrappers/Python/CoolProp/AbstractState.pxd
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions wrappers/Python/CoolProp/AbstractState.pyx
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions wrappers/Python/CoolProp/cAbstractState.pxd
Expand Up @@ -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
Expand Down

0 comments on commit 5fcb5dd

Please sign in to comment.