Skip to content

Commit

Permalink
[ck2yaml] Add link to website for CK errors
Browse files Browse the repository at this point in the history
  • Loading branch information
12Chao authored and bryanwweber committed Jul 2, 2020
1 parent 6224c8f commit 8f65ef7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
27 changes: 18 additions & 9 deletions interfaces/cython/cantera/ck2yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@

BlockMap = yaml.comments.CommentedMap

# url to cantera tutorial about Chemkin syntax instruction
url = "https://cantera.org/tutorials/ck2yaml-tutorial.html#debugging-common-errors-in-ck-files"

logger = logging.getLogger(__name__)
loghandler = logging.StreamHandler(sys.stdout)
logformatter = logging.Formatter('%(message)s')
Expand Down Expand Up @@ -673,10 +676,12 @@ def __init__(self, label, geometry, well_depth, collision_diameter,
except ValueError:
raise InputError(
"Bad geometry flag '{}' for species '{}', is the flag a float "
"or character? It should be an integer.", geometry, label)
"or character? It should be an integer. "
"Please check {} for correct Chemkin syntax", geometry, label, url)
if geometry not in (0, 1, 2):
raise InputError("Bad geometry flag '{}' for species '{}'",
geometry, label)
raise InputError("Bad geometry flag '{}' for species '{}' "
"Please check {} for correct Chemkin syntax"
"", geometry, label, url)

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

if not composition:
raise InputError("Error parsing elemental composition for "
"species '{}'", species)
"species '{}', Please check {} for correct Chemkin syntax"
"", species, url)

for symbol in composition.keys():
# Some CHEMKIN input files may have quantities of elements with
Expand Down Expand Up @@ -952,8 +958,9 @@ 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{}',
species, err)
raise InputError('Error while reading thermo entry for species {}:\n{}'
'Please check {} about the correct Chemkin syntax.'
'',species, err, url)

thermo = Nasa9(data=polys, note=note)

Expand Down Expand Up @@ -1042,8 +1049,9 @@ def read_kinetics_entry(self, entry, surface):
try:
locs[j] = float(token), 'coeff'
except ValueError:
raise InputError('Unexpected token "{}" in reaction expression "{}".',
token, original_reaction)
raise InputError('Unexpected token "{}" in reaction expression "{}"'
'Please check {} about the correct Chemkin syntax'
'', token, original_reaction, url)

reactants = []
products = []
Expand Down Expand Up @@ -1302,7 +1310,8 @@ 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. Please check {} about the correct Chemkin syntax'
'', original_reaction, url)

if cheb_coeffs:
if Tmin is None or Tmax is None:
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 8f65ef7

Please sign in to comment.