From a2743d2f7be50f38b428168dfb084eb7ebb6853d Mon Sep 17 00:00:00 2001
From: Ian Bell <ian.bell@nist.gov>
Date: Fri, 18 Mar 2022 08:21:28 -0400
Subject: [PATCH] Expose Tr and rhor for multifluid.

Refactor to avoid duplication
---
 interface/multifluid.cpp        |  8 ++++----
 interface/multifluid_mutant.cpp | 16 ++++++++--------
 interface/multifluid_shared.hpp | 11 +++++++++++
 3 files changed, 23 insertions(+), 12 deletions(-)
 create mode 100644 interface/multifluid_shared.hpp

diff --git a/interface/multifluid.cpp b/interface/multifluid.cpp
index 225d7ba..33761db 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 b878b14..d217519 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 0000000..2aa39f9
--- /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
-- 
GitLab