From ee41824b1edaafdb1b1b2231bc699a36ab89e88f Mon Sep 17 00:00:00 2001 From: Ingmar Schoegl Date: Tue, 22 Oct 2019 21:49:18 -0500 Subject: [PATCH] [SpeciesThermo] address review comments --- .../cantera/thermo/Nasa9PolyMultiTempRegion.h | 13 ++++++++++--- .../cantera/thermo/SpeciesThermoInterpType.h | 4 ++-- interfaces/cython/cantera/speciesthermo.pyx | 19 ++++++++++--------- interfaces/cython/cantera/test/test_thermo.py | 6 ++++-- src/thermo/Nasa9PolyMultiTempRegion.cpp | 17 ++++------------- src/thermo/SpeciesThermoInterpType.cpp | 15 +++++---------- 6 files changed, 35 insertions(+), 39 deletions(-) diff --git a/include/cantera/thermo/Nasa9PolyMultiTempRegion.h b/include/cantera/thermo/Nasa9PolyMultiTempRegion.h index f6dd79a76..2bd3f36c4 100644 --- a/include/cantera/thermo/Nasa9PolyMultiTempRegion.h +++ b/include/cantera/thermo/Nasa9PolyMultiTempRegion.h @@ -57,11 +57,18 @@ public: * @param thigh Maximum temperature * @param pref reference pressure (Pa). * @param coeffs Vector of coefficients used to set the parameters for the - * standard state. + * standard state. The vector has 1 + 11*`nzones` elements + * in the following order: + * - `coeffs[0]`: Number of zones (`nzones`) + * - `coeffs[1 + 11*zone]`: minimum temperature within zone + * - `coeffs[2 + 11*zone]`: maximum temperature within zone + * - `coeffs[3:11 + 11*zone]`: 9 coefficient parameterization + * where `zone` runs from zero to `nzones`-1. */ - Nasa9PolyMultiTempRegion(double tlow, double thigh, double pref, const double* coeffs); + Nasa9PolyMultiTempRegion(double tlow, double thigh, double pref, + const double* coeffs); - //! Set the array of polynomial coefficients for each temperature region + //! Set the array of polynomial coefficients for each temperature region /*! * @param regions Map where each key is the minimum temperature for a * region and each value is the array of 9 polynomial diff --git a/include/cantera/thermo/SpeciesThermoInterpType.h b/include/cantera/thermo/SpeciesThermoInterpType.h index b49dc486d..396389009 100644 --- a/include/cantera/thermo/SpeciesThermoInterpType.h +++ b/include/cantera/thermo/SpeciesThermoInterpType.h @@ -206,11 +206,11 @@ public: doublereal* h_RT, doublereal* s_R) const; - //! This utility function reports back the number of coefficients + //! This utility function returns the number of coefficients //! for a given type of species parameterization virtual size_t nCoeffs() const; - //! This utility function reports back the type of parameterization and all + //! This utility function returns the type of parameterization and all //! of the parameters for the species. /*! * All parameters are output variables diff --git a/interfaces/cython/cantera/speciesthermo.pyx b/interfaces/cython/cantera/speciesthermo.pyx index f67577343..dee15c72f 100644 --- a/interfaces/cython/cantera/speciesthermo.pyx +++ b/interfaces/cython/cantera/speciesthermo.pyx @@ -80,6 +80,10 @@ cdef class SpeciesThermo: return data def _check_n_coeffs(self, n): + """ + Check whether number of coefficients is compatible with a given + parameterization prior to instantiation of the underlying C++ object. + """ raise NotImplementedError('Needs to be overloaded') def cp(self, T): @@ -177,17 +181,14 @@ cdef class Nasa9PolyMultiTempRegion(SpeciesThermo): This is a wrapper for the C++ class :ct:`Nasa9PolyMultiTempRegion`. :param coeffs: - An array of 1 + 11*nzones elements, in the following order: + An array of 1 + 11*`nzones` elements, in the following order: - - `coeffs[0]`: Number of zones (nzones) - - within each zone - - `coeffs[zone][0]`: minimum temperature - - `coeffs[zone][1]`: maximum temperature - - `coeffs[zone][2:10]`: The 9 coefficients of the parameterization + - `coeffs[0]`: Number of zones (`nzones`) + - `coeffs[1 + 11*zone]`: minimum temperature within zone + - `coeffs[2 + 11*zone]`: maximum temperature within zone + - `coeffs[3:11 + 11*zone]`: 9 coefficients of the parameterization - These coefficients should be provided in their customary units (i.e. - such that :math:`c_p^o` is in J/gmol-K and :math:`H^o` is in kJ/gmol, - as in the NIST Chemistry WebBook). + where `zone` runs from zero to `nzones`-1. """ derived_type = SPECIES_THERMO_NASA9MULTITEMP diff --git a/interfaces/cython/cantera/test/test_thermo.py b/interfaces/cython/cantera/test/test_thermo.py index 89121b544..75eabf8d8 100644 --- a/interfaces/cython/cantera/test/test_thermo.py +++ b/interfaces/cython/cantera/test/test_thermo.py @@ -1236,7 +1236,8 @@ class TestSpeciesThermo(utilities.CanteraTest): self.assertNear(st.s(T), st2.s(T)) def test_piecewise_gibbs_load(self): - sol = ct.Solution('thermo-models.yaml', 'HMW-NaCl-electrolyte') + # @todo: replace by ct.Solution once issue #595 is resolved + sol = ct.ThermoPhase('thermo-models.yaml', 'HMW-NaCl-electrolyte') st = sol.species(1).thermo self.assertIsInstance(st, ct.Mu0Poly) self.assertEqual(st.n_coeffs, len(st.coeffs)) @@ -1257,7 +1258,8 @@ class TestSpeciesThermo(utilities.CanteraTest): self.assertEqual(st2.n_coeffs, len(st2.coeffs)) def test_piecewise_gibbs_create2(self): - sol = ct.Solution('thermo-models.yaml', 'HMW-NaCl-electrolyte') + # @todo: replace by ct.Solution once issue #595 is resolved + sol = ct.ThermoPhase('thermo-models.yaml', 'HMW-NaCl-electrolyte') st = sol.species(1).thermo t_min = st.min_temp t_max = st.max_temp diff --git a/src/thermo/Nasa9PolyMultiTempRegion.cpp b/src/thermo/Nasa9PolyMultiTempRegion.cpp index 3c04c17d6..bf60fa84c 100644 --- a/src/thermo/Nasa9PolyMultiTempRegion.cpp +++ b/src/thermo/Nasa9PolyMultiTempRegion.cpp @@ -59,26 +59,17 @@ Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion(vector& regionPt Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion(double tlow, double thigh, double pref, const double* coeffs) + : SpeciesThermoInterpType(tlow, thigh, pref) { - size_t regions = (size_t)coeffs[0]; + size_t regions = static_cast(coeffs[0]); for (size_t i=0; isetRefPressure(pref); - poly->setMinTemp(coeffs[11*i+1]); - poly->setMaxTemp(coeffs[11*i+2]); - for (size_t j=11*i+3; j<=11*(i+1); j++) { - cs.push_back(coeffs[j]); - } - poly->setParameters(cs); + Nasa9Poly1* poly = new Nasa9Poly1(coeffs[11*i+1], coeffs[11*i+2], + pref, coeffs + 11*i + 3); m_regionPts.emplace_back(poly); } m_lowerTempBounds.resize(regions); - m_lowT = tlow; - m_highT = thigh; - m_Pref = pref; for (size_t i = 0; i < m_regionPts.size(); i++) { m_lowerTempBounds[i] = m_regionPts[i]->minTemp(); if (i > 0) { diff --git a/src/thermo/SpeciesThermoInterpType.cpp b/src/thermo/SpeciesThermoInterpType.cpp index 3edaf9e53..7ef37423d 100644 --- a/src/thermo/SpeciesThermoInterpType.cpp +++ b/src/thermo/SpeciesThermoInterpType.cpp @@ -37,35 +37,30 @@ void SpeciesThermoInterpType::updateProperties(const doublereal* tempPoly, void SpeciesThermoInterpType::updatePropertiesTemp(const double temp, double* cp_R, double* h_RT, double* s_R) const { - throw CanteraError("SpeciesThermoInterpType::updatePropertiesTemp", - "Not implemented"); + throw NotImplementedError("SpeciesThermoInterpType::updatePropertiesTemp"); } size_t SpeciesThermoInterpType::nCoeffs() const { - throw CanteraError("SpeciesThermoInterpType::nCoeffs", - "Not implemented"); + throw NotImplementedError("SpeciesThermoInterpType::nCoeffs"); } void SpeciesThermoInterpType::reportParameters(size_t& index, int& type, double& minTemp, double& maxTemp, double& refPressure, double* const coeffs) const { - throw CanteraError("SpeciesThermoInterpType::reportParameters", - "Not implemented"); + throw NotImplementedError("SpeciesThermoInterpType::reportParameters"); } doublereal SpeciesThermoInterpType::reportHf298(doublereal* const h298) const { - throw CanteraError("SpeciesThermoInterpType::reportHf298", - "Not implemented"); + throw NotImplementedError("SpeciesThermoInterpType::reportHf298"); } void SpeciesThermoInterpType::modifyOneHf298(const size_t k, const doublereal Hf298New) { - throw CanteraError("SpeciesThermoInterpType::modifyOneHf298", - "Not implemented"); + throw NotImplementedError("SpeciesThermoInterpType::modifyOneHf298"); } }