[ck2cti] Added '--permissive' flag to ignore certain errors
This commit is contained in:
parent
1eec20baf0
commit
60d44997e0
2 changed files with 37 additions and 9 deletions
|
|
@ -62,6 +62,7 @@ UNIT_OPTIONS = {'CAL/': 'cal/mol',
|
|||
PROCESSED_UNITS = False
|
||||
ENERGY_UNITS = 'cal/mol'
|
||||
QUANTITY_UNITS = 'mol'
|
||||
WARNING_AS_ERROR = True
|
||||
|
||||
|
||||
class InputParseError(Exception):
|
||||
|
|
@ -73,6 +74,13 @@ class InputParseError(Exception):
|
|||
pass
|
||||
|
||||
|
||||
def warn(message):
|
||||
if WARNING_AS_ERROR:
|
||||
raise InputParseError(message)
|
||||
else:
|
||||
logging.warning(message)
|
||||
|
||||
|
||||
class Species(object):
|
||||
def __init__(self, label):
|
||||
self.label = label
|
||||
|
|
@ -1295,7 +1303,7 @@ def loadChemkinFile(path, speciesList=None):
|
|||
speciesDict[label].composition = comp
|
||||
speciesDict[label].note = note
|
||||
except KeyError:
|
||||
logging.warning('Skipping unexpected species "{0}" while reading thermodynamics entry.'.format(label))
|
||||
logging.info('Skipping unexpected species "{0}" while reading thermodynamics entry.'.format(label))
|
||||
|
||||
entryPosition = -1
|
||||
entry = []
|
||||
|
|
@ -1318,7 +1326,7 @@ def loadChemkinFile(path, speciesList=None):
|
|||
speciesDict[label].composition = comp
|
||||
speciesDict[label].note = note
|
||||
except KeyError:
|
||||
logging.warning('Skipping unexpected species "{0}" while reading thermodynamics entry.'.format(label))
|
||||
logging.info('Skipping unexpected species "{0}" while reading thermodynamics entry.'.format(label))
|
||||
thermo = ''
|
||||
line = f.readline()
|
||||
|
||||
|
|
@ -1460,8 +1468,8 @@ def parseTransportData(lines, speciesList):
|
|||
if speciesDict[speciesName].transport is None:
|
||||
speciesDict[speciesName].transport = TransportData(*data)
|
||||
else:
|
||||
logging.warning('Ignoring duplicate transport data'
|
||||
' for species "{0}".'.format(speciesName))
|
||||
warn('Ignoring duplicate transport data'
|
||||
' for species "{0}".'.format(speciesName))
|
||||
|
||||
|
||||
def writeCTI(elements,
|
||||
|
|
@ -1542,29 +1550,37 @@ def showHelp():
|
|||
print """
|
||||
ck2cti.py: Convert Chemkin-format mechanisms to Cantera input files (.cti)
|
||||
|
||||
If the output file name is not given, an output file with the same name as the
|
||||
input file, with the extension changed to '.cti'.
|
||||
|
||||
Usage:
|
||||
ck2cti --input=<filename>
|
||||
[--thermo=<filename>]
|
||||
[--transport=<filename>]
|
||||
[--id=<phase-id>]
|
||||
[--output=<filename>]
|
||||
[--permissive]
|
||||
[-d | --debug]
|
||||
|
||||
Example:
|
||||
ck2cti --input=chem.inp --thermo=therm.dat --transport=tran.dat
|
||||
|
||||
If the output file name is not given, an output file with the same name as the
|
||||
input file, with the extension changed to '.cti'.
|
||||
|
||||
The '--permissive' option allows certain recoverable parsing errors (e.g.
|
||||
duplicate transport data) to be ignored.
|
||||
|
||||
"""
|
||||
|
||||
|
||||
def convertMech(inputFile, thermoFile=None,
|
||||
transportFile=None, phaseName='gas',
|
||||
outName=None, quiet=False):
|
||||
outName=None, quiet=False, permissive=None):
|
||||
if quiet:
|
||||
logging.basicConfig(level=logging.ERROR)
|
||||
|
||||
if permissive is not None:
|
||||
global WARNING_AS_ERROR
|
||||
WARNING_AS_ERROR = not permissive
|
||||
|
||||
# Read input mechanism files
|
||||
elements, species, reactions = loadChemkinFile(inputFile)
|
||||
|
||||
|
|
@ -1595,7 +1611,7 @@ if __name__ == '__main__':
|
|||
import sys
|
||||
|
||||
longOptions = ['input=', 'thermo=', 'transport=', 'id=', 'output=',
|
||||
'help', 'debug']
|
||||
'permissive', 'help', 'debug']
|
||||
|
||||
try:
|
||||
optlist, args = getopt.getopt(sys.argv[1:], 'dh', longOptions)
|
||||
|
|
@ -1630,6 +1646,9 @@ if __name__ == '__main__':
|
|||
else:
|
||||
outName = None
|
||||
|
||||
if '--permissive' in options:
|
||||
WARNING_AS_ERROR = False
|
||||
|
||||
thermoFile = options.get('--thermo')
|
||||
transportFile = options.get('--transport')
|
||||
|
||||
|
|
|
|||
|
|
@ -198,8 +198,17 @@ class chemkinConverterTest(utilities.CanteraTest):
|
|||
outName='h2o2_transport_duplicate_species.cti',
|
||||
quiet=True)
|
||||
|
||||
# This should fail
|
||||
self.assertRaises(ck2cti.InputParseError, convert)
|
||||
|
||||
# This should succeed
|
||||
ck2cti.convertMech('../../data/inputs/h2o2.inp',
|
||||
transportFile='../data/h2o2-duplicate-species-tran.dat',
|
||||
outName='h2o2_transport_duplicate_species.cti',
|
||||
quiet=True,
|
||||
permissive=True)
|
||||
|
||||
|
||||
def test_transport_bad_geometry(self):
|
||||
if os.path.exists('h2o2_transport_bad_geometry.cti'):
|
||||
os.remove('h2o2_transport_bad_geometry.cti')
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue