Skip to content

Commit

Permalink
[ck2yaml] Add link to Chemkin syntax for inupt errors
Browse files Browse the repository at this point in the history
  • Loading branch information
12Chao authored and speth committed Sep 1, 2020
1 parent 83b323a commit 61d8b4a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
18 changes: 10 additions & 8 deletions interfaces/cython/cantera/ck2yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ class InputError(Exception):
the exceptional behavior.
"""
def __init__(self, message, *args, **kwargs):
message += ("\nPlease check https://cantera.org/tutorials/"
"ck2yaml-tutorial.html#debugging-common-errors-in-ck-files"
"\nfor the correct Chemkin syntax.")
if args or kwargs:
super().__init__(message.format(*args, **kwargs))
else:
Expand Down Expand Up @@ -688,8 +691,7 @@ def __init__(self, label, geometry, well_depth, collision_diameter,
"Bad geometry flag '{}' for species '{}', is the flag a float "
"or character? It should be an integer.", geometry, label)
if geometry not in (0, 1, 2):
raise InputError("Bad geometry flag '{}' for species '{}'",
geometry, label)
raise InputError("Bad geometry flag '{}' for species '{}'.", geometry, label)

self.geometry = self.geometry_flags[int(geometry)]
self.well_depth = float(well_depth)
Expand Down Expand Up @@ -885,7 +887,7 @@ def read_NASA7_entry(self, lines, TintDefault, comments):

if not composition:
raise InputError("Error parsing elemental composition for "
"species '{}'", species)
"species '{}'.", species)

for symbol in composition.keys():
# Some CHEMKIN input files may have quantities of elements with
Expand All @@ -894,8 +896,8 @@ def read_NASA7_entry(self, lines, TintDefault, comments):
# more useful error message.
if any(map(str.isdigit, symbol)) and symbol not in self.elements:
raise InputError("Error parsing elemental composition for "
"species thermo entry:\n{}\nElement amounts"
"can have no more than 3 digits",
"species thermo entry:\n{}\nElement amounts "
"can have no more than 3 digits.",
"".join(lines))

# Extract the NASA polynomial coefficients
Expand Down Expand Up @@ -965,7 +967,7 @@ def read_NASA9_entry(self, entry, comments):
fortFloat(C[64:80])]
polys.append((Trange, coeffs))
except (IndexError, ValueError) as err:
raise InputError('Error while reading thermo entry for species {}:\n{}',
raise InputError('Error while reading thermo entry for species {}:\n{}.',
species, err)

thermo = Nasa9(data=polys, note=note)
Expand Down Expand Up @@ -1315,7 +1317,7 @@ def parse_expression(expression, dest):
surface]
if sum(bool(t) for t in tests) > 1:
raise InputError('Reaction {} contains parameters for more than '
'one reaction type.', original_reaction)
'one reaction type.', original_reaction)

if cheb_coeffs:
if Tmin is None or Tmax is None:
Expand Down Expand Up @@ -1354,7 +1356,7 @@ def parse_expression(expression, dest):
elif reaction.third_body:
raise InputError('Reaction equation implies pressure '
'dependence but no alternate rate parameters (i.e. HIGH or '
'LOW) were given for reaction {}', reaction)
'LOW) were given for reaction {}.', reaction)
elif surface:
reaction.kinetics = SurfaceRate(rate=arrhenius,
coverages=coverages,
Expand Down
3 changes: 1 addition & 2 deletions interfaces/cython/cantera/test/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,10 +509,9 @@ def test_duplicate_reactions(self):
self.assertIn(token, message)

def test_error_for_big_element_number(self):
with self.assertRaisesRegex(self.InputError, 'Element amounts'):
with self.assertRaisesRegex(self.InputError, 'Element amounts can have no more than 3 digits.'):
self.convert('big_element_num_err.inp')


class CtmlConverterTest(utilities.CanteraTest):
def test_sofc(self):
gas_a, anode_bulk, oxide_a = ct.import_phases(
Expand Down

0 comments on commit 61d8b4a

Please sign in to comment.