Cantera / cantera

Chemical kinetics, thermodynamics, and transport tool suite
https://cantera.org
Other
581 stars 342 forks source link

Provide better error message when converting surface mechanism without providing gas phase input #1656

Closed speth closed 4 months ago

speth commented 5 months ago

Problem description

Generally, converting a surface mechanism from Chemkin format, separate input files are needed for both the surface and gas phase. If only the surface input file is provided, it should be relatively easy to suggest that the missing gas phase file is the problem. However, the current error message is somewhat difficult for a human to parse.

Steps to reproduce

From the Cantera source directory, run:

python -m cantera.ck2yaml --thermo=test/data/surface2-thermo.dat --surface=test/data/surface2.inp

Behavior

Resulting output:

Error reading reaction starting on line 6:
"""
 H2 + 2_Pt_  => 2H_Pt                        4.4579E+10  0.5   0.0
                      FORD/_Pt_  1/
"""

ERROR: Unable to parse 'test/data/surface2.inp' near line 6:
Unexpected token "H2+2" in reaction expression "H2+2_Pt_=>2H_Pt
".
Please check https://cantera.org/stable/userguide/ck2yaml-tutorial.html#debugging-common-errors-in-ck-files
for the correct Chemkin syntax.

Traceback (most recent call last):
  File "/Users/speth/src/cantera/build/python/cantera/ck2yaml.py", line 1059, in read_kinetics_entry
    locs[j] = int(token), 'coeff'
              ^^^^^^^^^^
ValueError: invalid literal for int() with base 10: 'H2+2'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/speth/src/cantera/build/python/cantera/ck2yaml.py", line 1062, in read_kinetics_entry
    locs[j] = float(token), 'coeff'
              ^^^^^^^^^^^^
ValueError: could not convert string to float: 'H2+2'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/Users/speth/src/cantera/build/python/cantera/ck2yaml.py", line 2312, in <module>
    main()
  File "/Users/speth/src/cantera/build/python/cantera/ck2yaml.py", line 2195, in main
    parser, surfaces = Parser.convert_mech(input_file, thermo_file,
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/speth/src/cantera/build/python/cantera/ck2yaml.py", line 2054, in convert_mech
    parser.load_chemkin_file(surface_file, surface=True)
  File "/Users/speth/src/cantera/build/python/cantera/ck2yaml.py", line 1788, in load_chemkin_file
    reaction, revReaction = self.read_kinetics_entry(kinetics, surface)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/speth/src/cantera/build/python/cantera/ck2yaml.py", line 1064, in read_kinetics_entry
    raise InputError('Unexpected token "{}" in reaction expression "{}".',
InputError: Unexpected token "H2+2" in reaction expression "H2+2_Pt_=>2H_Pt
".
Please check https://cantera.org/stable/userguide/ck2yaml-tutorial.html#debugging-common-errors-in-ck-files
for the correct Chemkin syntax.

From which the user is supposed to infer that the problem is the lack of a definition of the species "H2".

System information