diff --git a/interface/multifluid.cpp b/interface/multifluid.cpp index 225d7ba14ef4ee9b63711eb13c24fb7480081626..33761db9e5c6027cbb0fa14d7876f04291ba1409 100644 --- a/interface/multifluid.cpp +++ b/interface/multifluid.cpp @@ -3,16 +3,16 @@ #include "teqp/models/multifluid.hpp" #include "teqp/derivs.hpp" +#include "multifluid_shared.hpp" + void add_multifluid(py::module& m) { // Multifluid model m.def("build_multifluid_model", &build_multifluid_model, py::arg("components"), py::arg("coolprop_root"), py::arg("BIPcollectionpath") = "", py::arg("flags") = nlohmann::json{}, py::arg("departurepath") = ""); using MultiFluid = decltype(build_multifluid_model(std::vector<std::string>{"",""},"","")); - auto wMF = py::class_<MultiFluid>(m, "MultiFluid") - .def("get_Tcvec", [](const MultiFluid& c) { return c.redfunc.Tc; }) - .def("get_vcvec", [](const MultiFluid& c) { return c.redfunc.vc; }) - ; + auto wMF = py::class_<MultiFluid>(m, "MultiFluid"); add_derivatives<MultiFluid>(m, wMF); + add_multifluid_methods<MultiFluid>(wMF); // Expose some additional functions for working with the JSON data structures and resolving aliases m.def("get_BIPdep", &MultiFluidReducingFunction::get_BIPdep, py::arg("BIPcollection"), py::arg("identifiers"), py::arg("flags") = nlohmann::json{}); diff --git a/interface/multifluid_mutant.cpp b/interface/multifluid_mutant.cpp index b878b1434ea225fd594bde2e6661a970ef11ae0c..d217519a13908561717e1086703bc245af54adb7 100644 --- a/interface/multifluid_mutant.cpp +++ b/interface/multifluid_mutant.cpp @@ -5,6 +5,8 @@ #include <type_traits> +#include "multifluid_shared.hpp" + void add_multifluid_mutant(py::module& m) { // A typedef for the base model @@ -22,11 +24,10 @@ void add_multifluid_mutant(py::module& m) { using BIPmod = std::decay_t<MultiFluidAdapter<RedType, DepType, MultiFluid>>; // Define python wrapper of the mutant class - auto wMFBIP = py::class_<BIPmod>(m, "MultiFluidMutant") - .def("set_meta", [](BIPmod& c, const std::string &s) { return c.set_meta(s); }) - .def("get_meta", [](const BIPmod& c) { return c.get_meta(); }) - ; + auto wMFBIP = py::class_<BIPmod>(m, "MultiFluidMutant"); + add_derivatives<BIPmod>(m, wMFBIP); + add_multifluid_methods<BIPmod>(wMFBIP); } void add_multifluid_mutant_invariant(py::module& m) { @@ -41,9 +42,8 @@ void add_multifluid_mutant_invariant(py::module& m) { using Mutant = std::invoke_result_t<decltype(build_multifluid_mutant_invariant<MultiFluid>), MultiFluid&, nlohmann::json&>; // Define python wrapper of the mutant class - auto wMutant = py::class_<Mutant>(m, "MultiFluidMutantInvariant") - .def("set_meta", [](Mutant& c, const std::string& s) { return c.set_meta(s); }) - .def("get_meta", [](const Mutant& c) { return c.get_meta(); }) - ; + auto wMutant = py::class_<Mutant>(m, "MultiFluidMutantInvariant"); + add_derivatives<Mutant>(m, wMutant); + add_multifluid_methods<Mutant>(wMutant); } \ No newline at end of file diff --git a/interface/multifluid_shared.hpp b/interface/multifluid_shared.hpp new file mode 100644 index 0000000000000000000000000000000000000000..2aa39f9be8851819ba3f72ead9a9d3bb7e1b4cb8 --- /dev/null +++ b/interface/multifluid_shared.hpp @@ -0,0 +1,11 @@ +#pragma once + +template<typename Model, typename Wrapper> +void add_multifluid_methods(Wrapper &wMF){ + wMF.def("get_Tcvec", [](const Model& c) { return c.redfunc.Tc; }) + .def("get_vcvec", [](const Model& c) { return c.redfunc.vc; }) + .def("get_Tr", [](const Model& c, const Eigen::ArrayXd &molefrac) { return c.redfunc.get_Tr(molefrac); }) + .def("get_rhor", [](const Model& c, const Eigen::ArrayXd &molefrac) { return c.redfunc.get_rhor(molefrac); }) + .def("set_meta", [](Model& c, const std::string &s) { return c.set_meta(s); }) + .def("get_meta", [](const Model& c) { return c.get_meta(); }); +} \ No newline at end of file