From a5b0bdf69547b638b7e03c5aa0273a34068eebe9 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Sun, 18 Jun 2017 17:08:17 -0400 Subject: [PATCH] [Python] Make activity coefficients and activities accessible --- include/cantera/cython/wrappers.h | 2 ++ interfaces/cython/cantera/_cantera.pxd | 2 ++ interfaces/cython/cantera/test/test_thermo.py | 7 +++++++ interfaces/cython/cantera/thermo.pyx | 15 +++++++++++++++ 4 files changed, 26 insertions(+) diff --git a/include/cantera/cython/wrappers.h b/include/cantera/cython/wrappers.h index b4eb6508a..09aec98ef 100644 --- a/include/cantera/cython/wrappers.h +++ b/include/cantera/cython/wrappers.h @@ -85,6 +85,8 @@ THERMO_1D(getEntropy_R) THERMO_1D(getIntEnergy_RT) THERMO_1D(getGibbs_RT) THERMO_1D(getCp_R) +THERMO_1D(getActivities) +THERMO_1D(getActivityCoefficients) KIN_1D(getFwdRatesOfProgress) KIN_1D(getRevRatesOfProgress) diff --git a/interfaces/cython/cantera/_cantera.pxd b/interfaces/cython/cantera/_cantera.pxd index e6fd026e5..08e6165e8 100644 --- a/interfaces/cython/cantera/_cantera.pxd +++ b/interfaces/cython/cantera/_cantera.pxd @@ -823,6 +823,8 @@ cdef extern from "cantera/cython/wrappers.h": void thermo_getIntEnergy_RT(CxxThermoPhase*, double*) except +translate_exception void thermo_getGibbs_RT(CxxThermoPhase*, double*) except +translate_exception void thermo_getCp_R(CxxThermoPhase*, double*) except +translate_exception + void thermo_getActivities(CxxThermoPhase*, double*) except +translate_exception + void thermo_getActivityCoefficients(CxxThermoPhase*, double*) except +translate_exception # other ThermoPhase methods cdef void thermo_getMolecularWeights(CxxThermoPhase*, double*) except +translate_exception diff --git a/interfaces/cython/cantera/test/test_thermo.py b/interfaces/cython/cantera/test/test_thermo.py index 513cb663e..c27d04811 100644 --- a/interfaces/cython/cantera/test/test_thermo.py +++ b/interfaces/cython/cantera/test/test_thermo.py @@ -566,6 +566,13 @@ class TestThermoPhase(utilities.CanteraTest): cp = sum(self.phase.standard_cp_R * self.phase.X) * ct.gas_constant self.assertNear(cp, self.phase.cp_mole) + def test_activities(self): + self.phase.TDY = 850.0, 0.2, 'H2:0.1, H2O:0.6, AR:0.3' + self.assertArrayNear(self.phase.X, self.phase.activities) + + self.assertArrayNear(self.phase.activity_coefficients, + np.ones(self.phase.n_species)) + def test_isothermal_compressibility(self): self.assertNear(self.phase.isothermal_compressibility, 1.0/self.phase.P) diff --git a/interfaces/cython/cantera/thermo.pyx b/interfaces/cython/cantera/thermo.pyx index 4bbe40945..c95e43552 100644 --- a/interfaces/cython/cantera/thermo.pyx +++ b/interfaces/cython/cantera/thermo.pyx @@ -1216,6 +1216,21 @@ cdef class ThermoPhase(_SolutionBase): def __get__(self): return self._getArray1(thermo_getCp_R) + property activities: + """ + Array of nondimensional activities. Returns either molar or molal + activities depending on the convention of the thermodynamic model. + """ + def __get__(self): + return self._getArray1(thermo_getActivities) + + property activity_coefficients: + """ + Array of nondimensional, molar activity coefficients. + """ + def __get__(self): + return self._getArray1(thermo_getActivityCoefficients) + ######## Miscellaneous properties ######## property isothermal_compressibility: """Isothermal compressibility [1/Pa]."""