Fix Phase.species_index when species name contains a colon

This commit is contained in:
Ray Speth 2016-11-19 16:30:00 -05:00
parent 3300611379
commit 1db103cd87
2 changed files with 4 additions and 2 deletions

View file

@ -145,6 +145,7 @@ class chemkinConverterTest(utilities.CanteraTest):
self.assertEqual(gas.n_species, 7)
self.assertEqual(gas.species_name(0), '(Parens)')
self.assertEqual(gas.species_name(1), '@#$%^-2')
self.assertEqual(gas.species_index('co:lons'), 2)
self.assertEqual(gas.species_name(3), '[xy2]*{.}')
self.assertEqual(gas.species_name(4), 'plus+')
self.assertEqual(gas.species_name(5), 'eq=uals')

View file

@ -250,7 +250,8 @@ void Phase::getAtoms(size_t k, double* atomArray) const
size_t Phase::speciesIndex(const std::string& nameStr) const
{
if (nameStr.find(':') != npos) {
size_t loc = getValue(m_speciesIndices, ba::to_lower_copy(nameStr), npos);
if (loc == npos && nameStr.find(':') != npos) {
std::string pn;
std::string sn = ba::to_lower_copy(parseSpeciesName(nameStr, pn));
if (pn == "" || pn == m_name || pn == m_id) {
@ -259,7 +260,7 @@ size_t Phase::speciesIndex(const std::string& nameStr) const
return npos;
}
} else {
return getValue(m_speciesIndices, ba::to_lower_copy(nameStr), npos);
return loc;
}
}