From b1ff706f96ae9b61826489da64e6b5bfeef8dfb0 Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Tue, 20 Aug 2024 11:14:03 -0400 Subject: [PATCH] Give access to assoc calcs in python --- include/teqp/models/multifluid_association.hpp | 2 ++ interface/pybind11_wrapper.cpp | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/include/teqp/models/multifluid_association.hpp b/include/teqp/models/multifluid_association.hpp index 19dce08..35d40eb 100644 --- a/include/teqp/models/multifluid_association.hpp +++ b/include/teqp/models/multifluid_association.hpp @@ -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 auto R(const VecType& molefrac) const { return get_R_gas(); diff --git a/interface/pybind11_wrapper.cpp b/interface/pybind11_wrapper.cpp index f073e08..a0ee325 100644 --- a/interface/pybind11_wrapper.cpp +++ b/interface/pybind11_wrapper.cpp @@ -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" @@ -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 @@ -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(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