[ck2cti] Improve handling of duplicate species

Warn when a species is given multiple times in the input list. Do not add the
duplicate species to speciesList.

Resolves Issue 199.
This commit is contained in:
Bryan W. Weber
2014-01-06 18:46:49 +00:00
parent 7deb45a840
commit e3ab2dbf8a
3 changed files with 43 additions and 1 deletions

View File

@@ -1395,10 +1395,11 @@ class Parser(object):
break
if token in self.speciesDict:
species = self.speciesDict[token]
self.warn('Found additional declaration of species {0}'.format(species))
else:
species = Species(label=token)
self.speciesDict[token] = species
self.speciesList.append(species)
self.speciesList.append(species)
elif tokens[0].upper().startswith('THER') and contains(line, 'NASA9'):
entryPosition = 0

View File

@@ -113,6 +113,19 @@ class chemkinConverterTest(utilities.CanteraTest):
self.assertTrue(gas.n_species, 3)
self.assertTrue(gas.n_reactions, 2)
def test_duplicate_species(self):
self.assertRaises(ck2cti.InputParseError,
lambda: convertMech('../data/duplicate-species.inp',
outName='duplicate-species.cti',
quiet=True))
convertMech('../data/duplicate-species.inp',
outName='duplicate-species.cti',
quiet=True, permissive=True)
gas = ct.Solution('duplicate-species.cti')
self.assertEqual(gas.species_names, ['foo','bar','baz'])
def test_pathologicalSpeciesNames(self):
convertMech('../data/species-names.inp',
outName='species-names.cti', quiet=True)

View File

@@ -0,0 +1,28 @@
Elements
H C
END
SPECIES
foo bar baz bar
bar bar
bar
END
thermo
300.000 1000.000 5000.000
foo 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
bar 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
baz 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
end
reactions
foo + bar = 2 baz 1.2345e12 1.0 200.0
2foo + baz = 3bar 5.4321e10 1.0 500.0
end