From cd545af5edee950617c4eafc95113331289f4d2b Mon Sep 17 00:00:00 2001 From: Kyle Niemeyer Date: Wed, 17 Jun 2015 17:44:07 -0700 Subject: [PATCH] [Python/Thermo] Added functions for getting species thermo parameters Resolves #275; Closes #276; Closes #277 --- interfaces/cython/cantera/_cantera.pxd | 4 +++ interfaces/cython/cantera/speciesthermo.pyx | 30 +++++++++++++++++++ interfaces/cython/cantera/test/test_thermo.py | 19 ++++++++---- 3 files changed, 48 insertions(+), 5 deletions(-) diff --git a/interfaces/cython/cantera/_cantera.pxd b/interfaces/cython/cantera/_cantera.pxd index eb5eb3fc9..d50389605 100644 --- a/interfaces/cython/cantera/_cantera.pxd +++ b/interfaces/cython/cantera/_cantera.pxd @@ -76,6 +76,10 @@ cdef extern from "cantera/thermo/SpeciesThermoInterpType.h": CxxSpeciesThermo() int reportType() void updatePropertiesTemp(double, double*, double*, double*) except + + double minTemp() + double maxTemp() + double refPressure() + void reportParameters(size_t&, int&, double&, double&, double&, double* const) except + cdef extern from "cantera/thermo/SpeciesThermoFactory.h": cdef CxxSpeciesThermo* CxxNewSpeciesThermo "Cantera::newSpeciesThermoInterpType"\ diff --git a/interfaces/cython/cantera/speciesthermo.pyx b/interfaces/cython/cantera/speciesthermo.pyx index 8cb02e5f7..f529d151b 100644 --- a/interfaces/cython/cantera/speciesthermo.pyx +++ b/interfaces/cython/cantera/speciesthermo.pyx @@ -39,6 +39,36 @@ cdef class SpeciesThermo: self._spthermo = other self.spthermo = self._spthermo.get() + property min_temp: + """ Minimum temperature [K] at which the parameterization is valid.""" + def __get__(self): + return self.spthermo.minTemp() + + property max_temp: + """ Maximum temperature [K] at which the parameterization is valid.""" + def __get__(self): + return self.spthermo.maxTemp() + + property reference_pressure: + """ Reference pressure [Pa] for the parameterization.""" + def __get__(self): + return self.spthermo.refPressure() + + property coeffs: + """ + Array of coefficients for the parameterization. The length of this + array and the meaning of each element depends on the specific + parameterization. + """ + def __get__(self): + cdef size_t index = 0 + cdef int thermo_type = 0 + cdef double T_low = 0, T_high = 0, P_ref = 0 + cdef np.ndarray[np.double_t, ndim=1] data = np.empty(self.n_coeffs) + self.spthermo.reportParameters(index, thermo_type, T_low, + T_high, P_ref, &data[0]) + return data + def cp(self, T): """ Molar heat capacity at constant pressure [J/kmol/K] at temperature *T*. diff --git a/interfaces/cython/cantera/test/test_thermo.py b/interfaces/cython/cantera/test/test_thermo.py index b75886f43..0bfb5ed00 100644 --- a/interfaces/cython/cantera/test/test_thermo.py +++ b/interfaces/cython/cantera/test/test_thermo.py @@ -854,16 +854,18 @@ class TestSpecies(utilities.CanteraTest): class TestSpeciesThermo(utilities.CanteraTest): + h2o_coeffs = [ + 1000.0, 3.03399249E+00, 2.17691804E-03, -1.64072518E-07, + -9.70419870E-11, 1.68200992E-14, -3.00042971E+04, 4.96677010E+00, + 4.19864056E+00, -2.03643410E-03, 6.52040211E-06, -5.48797062E-09, + 1.77197817E-12, -3.02937267E+04, -8.49032208E-01 + ] def setUp(self): self.gas = ct.Solution('h2o2.xml') self.gas.X = 'H2O:1.0' def test_create(self): - st = ct.NasaPoly2(300, 3500, 101325, - [1000.0, 3.03399249E+00, 2.17691804E-03, -1.64072518E-07, - -9.70419870E-11, 1.68200992E-14, -3.00042971E+04, 4.96677010E+00, - 4.19864056E+00, -2.03643410E-03, 6.52040211E-06, -5.48797062E-09, - 1.77197817E-12, -3.02937267E+04, -8.49032208E-01]) + st = ct.NasaPoly2(300, 3500, 101325, self.h2o_coeffs) for T in [300, 500, 900, 1200, 2000]: self.gas.TP = T, 101325 @@ -887,3 +889,10 @@ class TestSpeciesThermo(utilities.CanteraTest): self.assertAlmostEqual(st.cp(T), self.gas.cp_mole) self.assertAlmostEqual(st.h(T), self.gas.enthalpy_mole) self.assertAlmostEqual(st.s(T), self.gas.entropy_mole) + + def test_coeffs(self): + st = ct.NasaPoly2(300, 3500, 101325, self.h2o_coeffs) + self.assertEqual(st.min_temp, 300) + self.assertEqual(st.max_temp, 3500) + self.assertEqual(st.reference_pressure, 101325) + self.assertArrayNear(self.h2o_coeffs, st.coeffs)