Skip to content

Commit

Permalink
Add get_BIP function for multiparameter models
Browse files Browse the repository at this point in the history
Closes #84
  • Loading branch information
ianhbell committed Jan 12, 2024
1 parent a129dd2 commit 2001c17
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
12 changes: 12 additions & 0 deletions include/teqp/models/multifluid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ class DepartureContribution {
const DepartureFunctionCollection funcs;
public:
DepartureContribution(FCollection&& F, DepartureFunctionCollection&& funcs) : F(F), funcs(funcs) {};

const auto& get_F() const { return F; }

template<typename TauType, typename DeltaType, typename MoleFractions>
auto alphar(const TauType& tau, const DeltaType& delta, const MoleFractions& molefracs) const {
Expand Down Expand Up @@ -134,6 +136,16 @@ class MultiFluid {
void set_meta(const std::string& m) { meta = m; }
/// Get the metadata stored in string form
auto get_meta() const { return meta; }
/// Return a binary interaction parameter
const std::variant<double, std::string> get_BIP(const std::size_t &i, const std::size_t &j, const std::string& key) const{
if (key == "F" || key == "Fij"){
auto F = dep.get_F();
if (0 <= i && i < F.rows() && 0 <= j && j < F.cols()){
return F(i,j);
}
}
return redfunc.get_BIP(i, j, key);
}

MultiFluid(ReducingFunctions&& redfunc, CorrespondingTerm&& corr, DepartureTerm&& dep, GasConstantCalculator&& Rcalc) : redfunc(redfunc), corr(corr), dep(dep), Rcalc(Rcalc) {};

Expand Down
10 changes: 10 additions & 0 deletions include/teqp/models/multifluid_mutant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ namespace teqp {
void set_meta(const std::string& m) { meta = m; }
/// Get the metadata stored in string form
auto get_meta() const { return meta; }
/// Return a binary interaction parameter
const std::variant<double, std::string> get_BIP(const std::size_t &i, const std::size_t &j, const std::string& key) const{
if (key == "F" || key == "Fij"){
auto F = dep.get_F();
if (0 <= i && i < F.rows() && 0 <= j && j < F.cols()){
return F(i,j);
}
}
return redfunc.get_BIP(i, j, key);
}

template<typename TType, typename RhoType, typename MoleFracType>
auto alphar(const TType& T,
Expand Down
39 changes: 39 additions & 0 deletions include/teqp/models/multifluid_reducing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,24 @@ namespace teqp {

template<typename MoleFractions> auto get_Tr(const MoleFractions& molefracs) const { return Y(molefracs, Tc, betaT, YT); }
template<typename MoleFractions> auto get_rhor(const MoleFractions& molefracs) const { return 1.0 / Y(molefracs, vc, betaV, Yv); }

const auto& get_mat(const std::string& key) const {
if (key == "betaT"){ return betaT; }
if (key == "gammaT"){ return gammaT; }
if (key == "betaV"){ return betaV; }
if (key == "gammaV"){ return gammaV; }
throw std::invalid_argument("variable is not understood: " + key);
}
auto get_BIP(const std::size_t& i, const std::size_t& j, const std::string& key) const {
const auto& mat = get_mat(key);
if (i < mat.rows() && j < mat.cols()){
return mat(i,j);
}
else{
throw std::invalid_argument("Indices are out of bounds");
}
}

};

class MultiFluidInvariantReducingFunction {
Expand Down Expand Up @@ -265,6 +283,23 @@ namespace teqp {
}
template<typename MoleFractions> auto get_Tr(const MoleFractions& molefracs) const { return Y(molefracs, phiT, lambdaT, YT); }
template<typename MoleFractions> auto get_rhor(const MoleFractions& molefracs) const { return 1.0 / Y(molefracs, phiV, lambdaV, Yv); }

const auto& get_mat(const std::string& key) const {
if (key == "phiT"){ return phiT; }
if (key == "lambdaT"){ return lambdaT; }
if (key == "phiV"){ return phiV; }
if (key == "lambdaV"){ return lambdaV; }
throw std::invalid_argument("variable is not understood: " + key);
}
auto get_BIP(const std::size_t& i, const std::size_t& j, const std::string& key) const {
const auto& mat = get_mat(key);
if (i < mat.rows() && j < mat.cols()){
return mat(i,j);
}
else{
throw std::invalid_argument("Indices are out of bounds");
}
}
};


Expand All @@ -289,6 +324,10 @@ namespace teqp {
auto get_rhor(const MoleFractions& molefracs) const {
return std::visit([&](auto& t) { return t.get_rhor(molefracs); }, term);
}

auto get_BIP(const std::size_t& i, const std::size_t& j, const std::string& key) const {
return std::visit([&](auto& t) { return t.get_BIP(i, j, key); }, term);
}
};

using ReducingFunctions = ReducingTermContainer<MultiFluidReducingFunction, MultiFluidInvariantReducingFunction>;
Expand Down
1 change: 1 addition & 0 deletions interface/pybind11_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ void attach_multifluid_methods(py::object&obj){
setattr("get_meta", MethodType(py::cpp_function([](py::object& o){ return get_typed<TYPE>(o).get_meta(); }), obj));
setattr("set_meta", MethodType(py::cpp_function([](py::object& o, const std::string& s){ return get_mutable_typed<TYPE>(o).set_meta(s); }, "self"_a, "s"_a), obj));
setattr("get_alpharij", MethodType(py::cpp_function([](py::object& o, const int i, const int j, const double tau, const double delta){ return get_typed<TYPE>(o).dep.get_alpharij(i,j,tau,delta); }, "self"_a, "i"_a, "j"_a, "tau"_a, "delta"_a), obj));
setattr("get_BIP", MethodType(py::cpp_function([](py::object& o, const std::size_t& i, const std::size_t& j, const std::string& key){ return get_typed<TYPE>(o).get_BIP(i,j,key); }, "self"_a, "i"_a, "j"_a, "key"_a), obj));
}
template<typename TYPE>
void attach_GERG_methods(py::object&obj){
Expand Down

0 comments on commit 2001c17

Please sign in to comment.