From 6d591b82efc9b8909ffaa6fe7e70812bdd8c9135 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Tue, 11 Jul 2017 23:49:23 -0400 Subject: [PATCH] [ck2cti] Fix reactions with pathologically named third bodies 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. --- interfaces/cython/cantera/ck2cti.py | 12 +++--------- interfaces/cython/cantera/test/test_convert.py | 3 +++ 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/interfaces/cython/cantera/ck2cti.py b/interfaces/cython/cantera/ck2cti.py index 4c40635a7..504fffe7c 100644 --- a/interfaces/cython/cantera/ck2cti.py +++ b/interfaces/cython/cantera/ck2cti.py @@ -1179,7 +1179,7 @@ class Parser(object): 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): @@ -1188,14 +1188,8 @@ class Parser(object): 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 '+' diff --git a/interfaces/cython/cantera/test/test_convert.py b/interfaces/cython/cantera/test/test_convert.py index c8b342ebd..6da1d2878 100644 --- a/interfaces/cython/cantera/test/test_convert.py +++ b/interfaces/cython/cantera/test/test_convert.py @@ -160,6 +160,9 @@ class chemkinConverterTest(utilities.CanteraTest): 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):