[ck2cti] Check for duplicate thermo entries

By default, raise an exception.
With '--permissive', use the first entry found.
This commit is contained in:
Ray Speth 2013-07-08 01:35:30 +00:00
parent 5d26a264f4
commit a69d56ab28
3 changed files with 62 additions and 6 deletions

View file

@ -1421,9 +1421,14 @@ class Parser(object):
if entryPosition == entryLength-1:
label, thermo, comp, note = self.readNasa9Entry(entry)
try:
self.speciesDict[label].thermo = thermo
self.speciesDict[label].composition = comp
self.speciesDict[label].note = note
species = self.speciesDict[label]
# use the first set of thermo data found
if species.thermo is not None:
self.warn('Found additional thermo entry for species {0}'.format(label))
else:
species.thermo = thermo
species.composition = comp
species.note = note
except KeyError:
logging.info('Skipping unexpected species "{0}" while reading thermodynamics entry.'.format(label))
@ -1452,9 +1457,14 @@ class Parser(object):
if line[79] == '4':
label, thermo, comp, note = self.readThermoEntry(thermo, TintDefault)
try:
self.speciesDict[label].thermo = thermo
self.speciesDict[label].composition = comp
self.speciesDict[label].note = note
species = self.speciesDict[label]
# use the first set of thermo data found
if species.thermo is not None:
self.warn('Found additional thermo entry for species {0}'.format(label))
else:
species.thermo = thermo
species.composition = comp
species.note = note
except KeyError:
logging.info('Skipping unexpected species "{0}" while reading thermodynamics entry.'.format(label))
thermo = []

View file

@ -0,0 +1,32 @@
Elements
H C
END
SPECIES
foo bar baz
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
! extra definition has different composition, which will trigger an exception
! if this set of parameters are used.
bar C 1H 6 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

@ -100,6 +100,20 @@ class chemkinConverterTest(utilities.CanteraTest):
outName='h2o2_missingThermo.cti',
quiet=True))
def test_duplicate_thermo(self):
self.assertRaises(ck2cti.InputParseError,
lambda: convertMech('../data/duplicate-thermo.inp',
outName='duplicate-thermo.cti',
quiet=True))
convertMech('../data/duplicate-thermo.inp',
outName='duplicate-thermo.cti',
quiet=True, permissive=True)
gas = ct.IdealGasMix('duplicate-thermo.cti')
self.assertTrue(gas.nSpecies(), 3)
self.assertTrue(gas.nReactions(), 2)
def test_pathologicalSpeciesNames(self):
convertMech('../data/species-names.inp',
outName='species-names.cti', quiet=True)