Skip to content

Commit

Permalink
[ck2cti] Fix over-zealous detection of new input file sections
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
speth committed Feb 8, 2018
1 parent d86a7c1 commit f47e98a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 20 deletions.
23 changes: 16 additions & 7 deletions interfaces/cython/cantera/ck2cti.py
Original file line number Diff line number Diff line change
Expand Up @@ -1549,7 +1549,8 @@ def readline():
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
Expand All @@ -1572,7 +1573,9 @@ def readline():
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
Expand Down Expand Up @@ -1620,7 +1623,9 @@ def readline():
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
Expand Down Expand Up @@ -1659,7 +1664,8 @@ def readline():
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
Expand Down Expand Up @@ -1728,7 +1734,8 @@ def readline():
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
Expand Down Expand Up @@ -1819,7 +1826,8 @@ def readline():
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
Expand Down Expand Up @@ -1878,7 +1886,8 @@ def readline():
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
Expand Down
25 changes: 13 additions & 12 deletions interfaces/cython/cantera/test/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def test_pathologicalSpeciesNames(self):
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)
Expand All @@ -151,18 +151,19 @@ def test_pathologicalSpeciesNames(self):
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):
Expand Down
7 changes: 6 additions & 1 deletion test/data/species-names.inp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

0 comments on commit f47e98a

Please sign in to comment.