From 5c2ac7cea624ca8ace936ac703f1f0e9bcb246fd Mon Sep 17 00:00:00 2001 From: Christopher Neal Date: Sun, 21 Jan 2024 15:33:31 -0500 Subject: [PATCH] [thermo] initial exposing of Peng-Robinson eos parameters to python interface --- include/cantera/thermo/PengRobinson.h | 8 ++++++++ include/cantera/thermo/ThermoPhase.h | 10 ++++++++++ interfaces/cython/cantera/thermo.pxd | 2 ++ interfaces/cython/cantera/thermo.pyx | 4 ++++ src/thermo/PengRobinson.cpp | 14 ++++++++++++++ 5 files changed, 38 insertions(+) diff --git a/include/cantera/thermo/PengRobinson.h b/include/cantera/thermo/PengRobinson.h index 86aa08610..8eeafc24f 100644 --- a/include/cantera/thermo/PengRobinson.h +++ b/include/cantera/thermo/PengRobinson.h @@ -173,6 +173,14 @@ public: void setBinaryCoeffs(const string& species_i, const string& species_j, double a); //! @} + //! Compute additional method based on name + /*! + * @param name The name of the quantity to compute + * @return Computed value wrapped in AnyValue type for Peng-Robinson phase + * quantities + */ + AnyValue compute_extra_method(const std::string& name) override; + protected: // Special functions inherited from MixtureFugacityTP double sresid() const override; diff --git a/include/cantera/thermo/ThermoPhase.h b/include/cantera/thermo/ThermoPhase.h index b267582a0..6e8c66a26 100644 --- a/include/cantera/thermo/ThermoPhase.h +++ b/include/cantera/thermo/ThermoPhase.h @@ -1556,6 +1556,16 @@ public: const Composition& oxComp, ThermoBasis basis=ThermoBasis::molar) const; //! @} + //! Compute additional method based on name + /*! + * @param name The name of the quantity to compute + * @return Computed value wrapped in AnyValue type + */ + virtual AnyValue compute_extra_method(const std::string& name) + { + throw NotImplementedError("ThermoPhase::compute_extra_method"); + } + private: //! Carry out work in HP and UV calculations. diff --git a/interfaces/cython/cantera/thermo.pxd b/interfaces/cython/cantera/thermo.pxd index bf023dcf7..0c8c26284 100644 --- a/interfaces/cython/cantera/thermo.pxd +++ b/interfaces/cython/cantera/thermo.pxd @@ -175,6 +175,8 @@ cdef extern from "cantera/thermo/ThermoPhase.h" namespace "Cantera": double equivalenceRatio() except +translate_exception double stoichAirFuelRatio(const double* fuelComp, const double* oxComp, ThermoBasis basis) except +translate_exception + CxxAnyValue compute_extra_method(string) except +translate_exception + cdef extern from "cantera/thermo/SurfPhase.h": cdef cppclass CxxSurfPhase "Cantera::SurfPhase": diff --git a/interfaces/cython/cantera/thermo.pyx b/interfaces/cython/cantera/thermo.pyx index 32de07cf8..2001c7d34 100644 --- a/interfaces/cython/cantera/thermo.pyx +++ b/interfaces/cython/cantera/thermo.pyx @@ -1172,6 +1172,10 @@ cdef class ThermoPhase(_SolutionBase): X = self.thermo.getMoleFractionsByName(threshold) return {pystr(item.first):item.second for item in X} + def compute_extra_method(self, name): + cdef CxxAnyValue value = self.thermo.compute_extra_method(stringify(name)) + return anyvalue_to_python(name, value) + ######## Read-only thermodynamic properties ######## property P: diff --git a/src/thermo/PengRobinson.cpp b/src/thermo/PengRobinson.cpp index 5ef044f88..b55e234c9 100644 --- a/src/thermo/PengRobinson.cpp +++ b/src/thermo/PengRobinson.cpp @@ -780,4 +780,18 @@ int PengRobinson::solveCubic(double T, double pres, double a, double b, double a an, bn, cn, dn, tc, vc); } +AnyValue PengRobinson::compute_extra_method(const std::string& name) +{ + if(name == "aAlpha_mix") { + return AnyValue(m_aAlpha_mix); + } else if(name == "b_mix") { + return AnyValue(m_b); + } else if(name == "daAlpha_dT") { + return AnyValue(daAlpha_dT()); + } else if(name == "d2aAlpha_dT2") { + return AnyValue(d2aAlpha_dT2()); + } + throw CanteraError("PengRobinson::compute_extra_method", "Unknown method: {}", name); +} + }