[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.

Based on patch provided by Bryan Weber.

Resolves Issue 199.

Cherry-pick of trunk r2660.
This commit is contained in:
Ray Speth 2014-01-23 03:06:16 +00:00
parent f988382b36
commit a23eac62d8
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

@ -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

View file

@ -114,6 +114,19 @@ class chemkinConverterTest(utilities.CanteraTest):
self.assertTrue(gas.nSpecies(), 3)
self.assertTrue(gas.nReactions(), 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.IdealGasMix('duplicate-species.cti')
self.assertEqual(gas.speciesNames(), ['foo','bar','baz'])
def test_pathologicalSpeciesNames(self):
convertMech('../data/species-names.inp',
outName='species-names.cti', quiet=True)