Skip to content

Commit

Permalink
[ck2cti] Fix reactions with pathologically named third bodies
Browse files Browse the repository at this point in the history
This changes the order in which tokens are identified to be strictly
descending in length, so that third bodies are identified correctly
even when the third body expression could potentially be interpreted
as containing a standalone species name.
  • Loading branch information
speth committed Jul 12, 2017
1 parent 55a8910 commit 6d591b8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
12 changes: 3 additions & 9 deletions interfaces/cython/cantera/ck2cti.py
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@ def readKineticsEntry(self, entry, surface):
Ea = float(tokens[-1])
reaction = ''.join(tokens[:-3]) + '\n'

# Identify species tokens in the reaction expression in order of
# Identify tokens in the reaction expression in order of
# decreasing length
locs = {}
for i in range(self.Slen, 0, -1):
Expand All @@ -1188,14 +1188,8 @@ def readKineticsEntry(self, entry, surface):
if test in self.species_tokens:
reaction = reaction[:j] + ' '*(i-1) + reaction[j+i-1:]
locs[j] = test[:-1], 'species'

# Identify other tokens in the reaction expression in order of
# descending length
for i in range(self.Slen, 0, -1):
for j in range(len(reaction)-i+1):
test = reaction[j:j+i]
if test in self.other_tokens:
reaction = reaction[:j] + ' '*i + reaction[j+i:]
elif test in self.other_tokens:
reaction = reaction[:j] + '\n'*i + reaction[j+i:]
locs[j] = test, self.other_tokens[test]

# Anything that's left should be a stoichiometric coefficient or a '+'
Expand Down
3 changes: 3 additions & 0 deletions interfaces/cython/cantera/test/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ def test_pathologicalSpeciesNames(self):
self.assertEqual(list(nu[:,4]), [2, 0, 0, 0, -1, 0, -1])
self.assertEqual(list(nu[:,5]), [1, 0, 0, 0, 1, -1, -1])
self.assertEqual(list(nu[:,6]), [2, 0, -1, 0, 0, -1, 0])
self.assertEqual(list(nu[:,7]), [0, 0, 0, 0, -1, 1, 0])
self.assertEqual(list(nu[:,8]), [0, 0, 0, 0, -1, 1, 0])
self.assertEqual(list(nu[:,9]), [0, 0, 0, 0, -1, 1, 0])

def test_unterminatedSections(self):
with self.assertRaises(ck2cti.InputParseError):
Expand Down

0 comments on commit 6d591b8

Please sign in to comment.