Skip to content

Commit

Permalink
[Kinetics] Make some member functions const
Browse files Browse the repository at this point in the history
  • Loading branch information
speth committed Dec 3, 2018
1 parent 8453548 commit 9aa507a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
11 changes: 6 additions & 5 deletions include/cantera/kinetics/Kinetics.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,11 @@ class Kinetics
* 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;
}
}

Expand All @@ -199,7 +199,7 @@ class Kinetics
* 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;
}

Expand All @@ -211,7 +211,7 @@ class Kinetics
* 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;
}

Expand Down Expand Up @@ -309,6 +309,7 @@ class Kinetics
* @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
Expand All @@ -328,7 +329,7 @@ class Kinetics
*
* @param k Species index
*/
size_t speciesPhaseIndex(size_t k);
size_t speciesPhaseIndex(size_t k) const;

//! @}
//! @name Reaction Rates Of Progress
Expand Down
12 changes: 11 additions & 1 deletion src/kinetics/Kinetics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down

0 comments on commit 9aa507a

Please sign in to comment.