Skip to content

Commit

Permalink
Give access to assoc calcs in python
Browse files Browse the repository at this point in the history
  • Loading branch information
ianhbell committed Aug 26, 2024
1 parent 007f919 commit b1ff706
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/teqp/models/multifluid_association.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class MultifluidPlusAssociation{
m_multifluid(multifluidfactory(spec.at("multifluid"))),
m_association(association::Association::factory(spec.at("association").at("model"))){}

const auto& get_association() const { return m_association; }

template<class VecType>
auto R(const VecType& molefrac) const {
return get_R_gas<decltype(molefrac[0])>();
Expand Down
7 changes: 7 additions & 0 deletions interface/pybind11_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "teqp/models/fwd.hpp"
#include "teqp/algorithms/ancillary_builder.hpp"
#include "teqp/models/multifluid_ecs_mutant.hpp"
#include "teqp/models/multifluid_association.hpp"
#include "teqp/models/saft/genericsaft.hpp"

#include "teqp/algorithms/pure_param_optimization.hpp"
Expand Down Expand Up @@ -149,6 +150,7 @@ const std::type_index GERG2008ResidualModel_i{std::type_index(typeid(GERG2008::G
using CPA_t = decltype(teqp::CPA::CPAfactory(""));
const std::type_index CPA_i{std::type_index(typeid(CPA_t))};
const std::type_index genericSAFT_i{std::type_index(typeid(teqp::saft::genericsaft::GenericSAFT))};
const std::type_index MultiFluidAssociation_i{std::type_index(typeid(MultifluidPlusAssociation))};

/**
At runtime we can add additional model-specific methods that only apply for a particular model. We take in a Python-wrapped
Expand Down Expand Up @@ -311,6 +313,11 @@ void attach_model_specific_methods(py::object& obj){
return std::visit([&](const auto& a){ return a.get_assoc_calcs(T, rhomolar, molefrac); }, assocoptvariant.value());
}, "self"_a, "T"_a, "rhomolar"_a, "molefrac"_a), obj));
}
else if (index == MultiFluidAssociation_i){
setattr("get_assoc_calcs", MethodType(py::cpp_function([](py::object& o, double T, double rhomolar, REArrayd& molefrac){
return get_typed<MultifluidPlusAssociation>(o).get_association().get_assoc_calcs(T, rhomolar, molefrac);
}, "self"_a, "T"_a, "rhomolar"_a, "molefrac"_a), obj));
}
};

/// Instantiate "instances" of models (really wrapped Python versions of the models), and then attach all derivative methods
Expand Down

0 comments on commit b1ff706

Please sign in to comment.