[ck2cti] Fix over-zealous detection of new input file sections

Species names starting with the short form of input file section names
(e.g. 'tran') were incorrectly identified as indicating the start of that
section if they occurred at the start of a line.
This commit is contained in:
Ray Speth 2018-02-07 21:27:21 -05:00
parent d86a7c176e
commit f47e98a594
3 changed files with 35 additions and 20 deletions

View file

@ -1549,7 +1549,8 @@ class Parser(object):
tokens = tokens[1:]
while line is not None and not contains(line, 'END'):
# Grudging support for implicit end of section
if line.strip()[:4].upper() == 'SPEC':
start = line.strip().upper().split()
if start and start[0] in ('SPEC', 'SPECIES'):
self.warn('"ELEMENTS" section implicitly ended by start of '
'next section on line {0}.'.format(self.line_number))
advance = False
@ -1572,7 +1573,9 @@ class Parser(object):
inHeader = False
while line is not None and not contains(line, 'END'):
# Grudging support for implicit end of section
if line.strip()[:4].upper() in ('REAC', 'TRAN', 'THER'):
start = line.strip().upper().split()
if start and start[0] in ('REAC', 'REACTIONS', 'TRAN',
'TRANSPORT', 'THER', 'THERMO'):
self.warn('"SPECIES" section implicitly ended by start of '
'next section on line {0}.'.format(self.line_number))
advance = False
@ -1620,7 +1623,9 @@ class Parser(object):
inHeader = False
while line is not None and not contains(line, 'END'):
# Grudging support for implicit end of section
if line.strip()[:4].upper() in ('REAC', 'THER'):
start = line.strip().upper().split()
if start and start[0] in ('REAC', 'REACTIONS', 'THER',
'THERMO'):
self.warn('"SITE" section implicitly ended by start of '
'next section on line {0}.'.format(self.line_number))
advance = False
@ -1659,7 +1664,8 @@ class Parser(object):
entry = []
while line is not None and not get_index(line, 'END') == 0:
# Grudging support for implicit end of section
if line.strip()[:4].upper() in ('REAC', 'TRAN'):
start = line.strip().upper().split()
if start and start[0] in ('REAC', 'REACTIONS', 'TRAN', 'TRANSPORT'):
self.warn('"THERMO" section implicitly ended by start of '
'next section on line {0}.'.format(self.line_number))
advance = False
@ -1728,7 +1734,8 @@ class Parser(object):
current = []
while line is not None and not contains(line, 'END'):
# Grudging support for implicit end of section
if line.strip()[:4].upper() in ('REAC', 'TRAN'):
start = line.strip().upper().split()
if start and start[0] in ('REAC', 'REACTIONS', 'TRAN', 'TRANSPORT'):
self.warn('"THERMO" section implicitly ended by start of '
'next section on line {0}.'.format(self.line_number))
advance = False
@ -1819,7 +1826,8 @@ class Parser(object):
reactions = self.reactions
while line is not None and not contains(line, 'END'):
# Grudging support for implicit end of section
if line.strip()[:4].upper() == 'TRAN':
start = line.strip().upper().split()
if start and start[0] in ('TRAN', 'TRANSPORT'):
self.warn('"REACTIONS" section implicitly ended by start of '
'next section on line {0}.'.format(self.line_number))
advance = False
@ -1878,7 +1886,8 @@ class Parser(object):
transport_start_line = self.line_number
while line is not None and not contains(line, 'END'):
# Grudging support for implicit end of section
if line.strip()[:4].upper() == 'REAC':
start = line.strip().upper().split()
if start and start[0] in ('REAC', 'REACTIONS'):
self.warn('"TRANSPORT" section implicitly ended by start of '
'next section on line {0}.'.format(self.line_number))
advance = False

View file

@ -142,7 +142,7 @@ class chemkinConverterTest(utilities.CanteraTest):
outName=pjoin(self.test_work_dir, 'species-names.cti'), quiet=True)
gas = ct.Solution('species-names.cti')
self.assertEqual(gas.n_species, 7)
self.assertEqual(gas.n_species, 8)
self.assertEqual(gas.species_name(0), '(Parens)')
self.assertEqual(gas.species_name(1), '@#$%^-2')
self.assertEqual(gas.species_index('co:lons:'), 2)
@ -151,18 +151,19 @@ class chemkinConverterTest(utilities.CanteraTest):
self.assertEqual(gas.species_name(5), 'eq=uals')
self.assertEqual(gas.species_name(6), 'plus')
self.assertEqual(gas.n_reactions, 10)
self.assertEqual(gas.n_reactions, 11)
nu = gas.product_stoich_coeffs() - gas.reactant_stoich_coeffs()
self.assertEqual(list(nu[:,0]), [-1, -1, 0, 2, 0, 0, 0])
self.assertEqual(list(nu[:,1]), [-2, 3, 0, -1, 0, 0, 0])
self.assertEqual(list(nu[:,2]), [-1, 0, 0, 0, 1, 0, 0])
self.assertEqual(list(nu[:,3]), [3, 0, 0, 0, -2, -1, 0])
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])
self.assertEqual(list(nu[:,0]), [-1, -1, 0, 2, 0, 0, 0, 0])
self.assertEqual(list(nu[:,1]), [-2, 3, 0, -1, 0, 0, 0, 0])
self.assertEqual(list(nu[:,2]), [-1, 0, 0, 0, 1, 0, 0, 0])
self.assertEqual(list(nu[:,3]), [3, 0, 0, 0, -2, -1, 0, 0])
self.assertEqual(list(nu[:,4]), [2, 0, 0, 0, -1, 0, -1, 0])
self.assertEqual(list(nu[:,5]), [1, 0, 0, 0, 1, -1, -1, 0])
self.assertEqual(list(nu[:,6]), [2, 0, -1, 0, 0, -1, 0, 0])
self.assertEqual(list(nu[:,7]), [0, 0, 0, 0, -1, 1, 0, 0])
self.assertEqual(list(nu[:,8]), [0, 0, 0, 0, -1, 1, 0, 0])
self.assertEqual(list(nu[:,9]), [0, 0, 0, 0, -1, 1, 0, 0])
self.assertEqual(list(nu[:,10]), [0, 0, -1, 0, 2, 0, 0, -1])
def test_unterminatedSections(self):
with self.assertRaises(ck2cti.InputParseError):

View file

@ -2,7 +2,7 @@ Elements
H C
End
SPEC
(Parens) @#$%^-2 co:lons: [xy2]*{.} plus+ eq=uals plus
(Parens) @#$%^-2 co:lons: [xy2]*{.} plus+ eq=uals plus trans_butene
end
thermo
@ -23,6 +23,10 @@ co:lons: C 1H 4 G 200.000 3500.000 1000.000 1
7.48514950E-02 1.33909467E-02-5.73285809E-06 1.22292535E-09-1.01815230E-13 2
-9.46834459E+03 1.84373180E+01 5.14987613E+00-1.36709788E-02 4.91800599E-05 3
-4.84743026E-08 1.66693956E-11-1.02466476E+04-4.64130376E+00 4
trans_butene C 1H 4 G 200.000 3500.000 1000.000 1
7.48514950E-02 1.33909467E-02-5.73285809E-06 1.22292535E-09-1.01815230E-13 2
-9.46834459E+03 1.84373180E+01 5.14987613E+00-1.36709788E-02 4.91800599E-05 3
-4.84743026E-08 1.66693956E-11-1.02466476E+04-4.64130376E+00 4
plus+ C 1H 4 G 200.000 3500.000 1000.000 1
7.48514950E-02 1.33909467E-02-5.73285809E-06 1.22292535E-09-1.01815230E-13 2
-9.46834459E+03 1.84373180E+01 5.14987613E+00-1.36709788E-02 4.91800599E-05 3
@ -51,5 +55,6 @@ plus+ (+(Parens)) = eq=uals (+(Parens)) 9.999e9 9.9 999.9
LOW / 8.888e8 8.8 888.8 /
plus+ (+plus+) = eq=uals (+plus+) 9.999e9 9.9 999.9
LOW / 8.888e8 8.8 888.8 /
trans_butene + co:lons: = 2 plus+ 9.999e9 9.9 999.9
end