diff --git a/include/cantera/kinetics/Kinetics.h b/include/cantera/kinetics/Kinetics.h index 10ed03632..d430a0cb9 100644 --- a/include/cantera/kinetics/Kinetics.h +++ b/include/cantera/kinetics/Kinetics.h @@ -384,23 +384,32 @@ public: std::string kineticsSpeciesName(size_t k) const; /** - * This routine will look up a species number based on - * the input std::string nm. The lookup of species will - * occur for all phases listed in the kinetics object, - * unless the std::string ph refers to a specific phase of - * the object. + * This routine will look up a species number based on the input + * std::string nm. The lookup of species will occur for all phases + * listed in the kinetics object. * * return - * - If a match is found, the position in the species list - * is returned. - * - If a specific phase is specified and no match is found, - * the value -1 is returned. - * - If no match is found in any phase, the value -2 is returned. + * - If a match is found, the position in the species list is returned. + * - If no match is found, the value -1 is returned. * * @param nm Input string name of the species - * @param ph Input string name of the phase. Defaults to "" */ - size_t kineticsSpeciesIndex(std::string nm, std::string ph = "") const; + size_t kineticsSpeciesIndex(const std::string& nm) const; + + /** + * This routine will look up a species number based on the input + * std::string nm. The lookup of species will occur in the specified + * phase of the object, or all phases if ph is "". + * + * return + * - If a match is found, the position in the species list is returned. + * - If no match is found, the value npos (-1) is returned. + * + * @param nm Input string name of the species + * @param ph Input string name of the phase. + */ + size_t kineticsSpeciesIndex(const std::string& nm, + const std::string& ph) const; /** * This function looks up the std::string name of a species and diff --git a/src/kinetics/Kinetics.cpp b/src/kinetics/Kinetics.cpp index 0e82fb0c7..268030677 100644 --- a/src/kinetics/Kinetics.cpp +++ b/src/kinetics/Kinetics.cpp @@ -205,46 +205,62 @@ string Kinetics::kineticsSpeciesName(size_t k) const } /** - * kineticsSpeciesIndex(): - * - * This routine will look up a species number based on - * the input string nm. The lookup of species will - * occur for all phases listed in the kinetics object, - * unless the string ph refers to a specific phase of - * the object. + * This routine will look up a species number based on the input + * std::string nm. The lookup of species will occur for all phases + * listed in the kinetics object. * * return - * - If a match is found, the position in the species list - * is returned. - * - If no match is found, the value -1 (npos) is returned. + * - If a match is found, the position in the species list is returned. + * - If no match is found, the value -1 is returned. + * + * @param nm Input string name of the species */ -size_t Kinetics::kineticsSpeciesIndex(std::string nm, std::string ph) const +size_t Kinetics::kineticsSpeciesIndex(const std::string& nm) const { - size_t np = m_thermo.size(); - size_t k; - string id; - for (size_t n = 0; n < np; n++) { - id = thermo(n).id(); - if (ph == id) { - k = thermo(n).speciesIndex(nm); - if (k == npos) { - return npos; - } + for (size_t n = 0; n < m_thermo.size(); n++) { + string id = thermo(n).id(); + // Check the ThermoPhase object for a match + size_t k = thermo(n).speciesIndex(nm); + if (k != npos) { return k + m_start[n]; - } else if (ph == "") { - /* - * Call the speciesIndex() member function of the - * ThermoPhase object to find a match. - */ - k = thermo(n).speciesIndex(nm); - if (k != npos) { - return k + m_start[n]; - } } } return npos; } +/** + * This routine will look up a species number based on the input + * std::string nm. The lookup of species will occur in the specified + * phase of the object, or all phases if ph is "". + * + * return + * - If a match is found, the position in the species list is returned. + * - If no match is found, the value npos (-1) is returned. + * + * @param nm Input string name of the species + * @param ph Input string name of the phase. + */ +size_t Kinetics::kineticsSpeciesIndex(const std::string& nm, + const std::string& ph) const +{ + if (ph == "") { + return kineticsSpeciesIndex(nm); + } + + for (size_t n = 0; n < m_thermo.size(); n++) { + string id = thermo(n).id(); + if (ph == id) { + size_t k = thermo(n).speciesIndex(nm); + if (k == npos) { + return npos; + } + return k + m_start[n]; + } + } + return npos; +} + + /** * This function looks up the string name of a species and * returns a reference to the ThermoPhase object of the diff --git a/src/kinetics/importKinetics.cpp b/src/kinetics/importKinetics.cpp index 87417ff33..606cc6db0 100644 --- a/src/kinetics/importKinetics.cpp +++ b/src/kinetics/importKinetics.cpp @@ -219,7 +219,7 @@ bool getReagents(const XML_Node& rxn, kinetics_t& kin, int rp, * member function kineticsSpeciesIndex(). We will search * for the species in all phases defined in the kinetics operator. */ - size_t isp = kin.kineticsSpeciesIndex(sp,""); + size_t isp = kin.kineticsSpeciesIndex(sp); if (isp == npos) { if (rule == 1) { return false;