From 9aa507a0988e9b12724f1c25ef23a67f4b04cd27 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Mon, 5 Feb 2018 18:52:22 -0500 Subject: [PATCH] [Kinetics] Make some member functions const --- include/cantera/kinetics/Kinetics.h | 11 ++++++----- src/kinetics/Kinetics.cpp | 12 +++++++++++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/include/cantera/kinetics/Kinetics.h b/include/cantera/kinetics/Kinetics.h index 2175449cc..b34188193 100644 --- a/include/cantera/kinetics/Kinetics.h +++ b/include/cantera/kinetics/Kinetics.h @@ -186,11 +186,11 @@ public: * If a -1 is returned, then the phase is not defined in the Kinetics * object. */ - size_t phaseIndex(const std::string& ph) { + size_t phaseIndex(const std::string& ph) const { if (m_phaseindex.find(ph) == m_phaseindex.end()) { return npos; } else { - return m_phaseindex[ph] - 1; + return m_phaseindex.at(ph) - 1; } } @@ -199,7 +199,7 @@ public: * cSurf. For heterogeneous mechanisms, this identifies the one surface * phase. For homogeneous mechanisms, this returns -1. */ - size_t surfacePhaseIndex() { + size_t surfacePhaseIndex() const { return m_surfphase; } @@ -211,7 +211,7 @@ public: * of phases. If there is more than one, the index of the first one is * returned. For homogeneous mechanisms, the value 0 is returned. */ - size_t reactionPhaseIndex() { + size_t reactionPhaseIndex() const { return m_rxnphase; } @@ -309,6 +309,7 @@ public: * @param nm String containing the name of the species. */ thermo_t& speciesPhase(const std::string& nm); + const thermo_t& speciesPhase(const std::string& nm) const; /** * This function takes as an argument the kineticsSpecies index @@ -328,7 +329,7 @@ public: * * @param k Species index */ - size_t speciesPhaseIndex(size_t k); + size_t speciesPhaseIndex(size_t k) const; //! @} //! @name Reaction Rates Of Progress diff --git a/src/kinetics/Kinetics.cpp b/src/kinetics/Kinetics.cpp index 0675277f6..52bd8a2e2 100644 --- a/src/kinetics/Kinetics.cpp +++ b/src/kinetics/Kinetics.cpp @@ -330,7 +330,17 @@ thermo_t& Kinetics::speciesPhase(const std::string& nm) throw CanteraError("speciesPhase", "unknown species "+nm); } -size_t Kinetics::speciesPhaseIndex(size_t k) +const thermo_t& Kinetics::speciesPhase(const std::string& nm) const +{ + for (const auto thermo : m_thermo) { + if (thermo->speciesIndex(nm) != npos) { + return *thermo; + } + } + throw CanteraError("speciesPhase", "unknown species "+nm); +} + +size_t Kinetics::speciesPhaseIndex(size_t k) const { for (size_t n = m_start.size()-1; n != npos; n--) { if (k >= m_start[n]) {