diff --git a/.gitignore b/.gitignore index 8501cdf6237..b2b47c0746e 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ stage/ .sconf_temp .vs .vscode +.idea/ .ipynb_checkpoints/ cantera.conf* config.log diff --git a/interfaces/cython/cantera/ck2yaml.py b/interfaces/cython/cantera/ck2yaml.py index 83519bc37a8..bc42527b844 100644 --- a/interfaces/cython/cantera/ck2yaml.py +++ b/interfaces/cython/cantera/ck2yaml.py @@ -687,17 +687,30 @@ def reduce(self, output): class TransportData: geometry_flags = ['atom', 'linear', 'nonlinear'] - def __init__(self, label, geometry, well_depth, collision_diameter, + def __init__(self, parser, label, geometry, well_depth, collision_diameter, dipole_moment, polarizability, z_rot, note=''): try: geometry = int(geometry) except ValueError: - raise InputError( - "Bad geometry flag '{}' for species '{}', is the flag a float " - "or character? It should be an integer.", geometry, label) + try: + geometry = float(geometry) + except ValueError: + raise InputError( + "Invalid geometry flag '{}' for species '{}'. " + "Flag should be an integer.", geometry, label) from None + if geometry == int(geometry): + geometry = int(geometry) + parser.warn("Incorrect geometry flag syntax for species {0}. " + "If --permissive was given, the flag was automatically " + "converted to an integer.".format(label)) + else: + raise InputError( + "Invalid float geometry flag '{}' for species '{}'. " + "Flag should be an integer.", geometry, label) from None if geometry not in (0, 1, 2): - raise InputError("Bad geometry flag '{}' for species '{}'.", geometry, label) + raise InputError("Invalid geometry flag value '{}' for species '{}'. " + "Flag value should be 0, 1, or 2.", geometry, label) self.geometry = self.geometry_flags[int(geometry)] self.well_depth = float(well_depth) @@ -1890,7 +1903,7 @@ def parse_transport_data(self, lines, filename, line_offset): line_offset + i, filename, original_line, len(data)-1) if self.species_dict[speciesName].transport is None: - self.species_dict[speciesName].transport = TransportData(*data, note=comment) + self.species_dict[speciesName].transport = TransportData(self, *data, note=comment) else: self.warn('Ignoring duplicate transport data' ' for species "{}" on line {} of "{}".'.format( diff --git a/test/data/h2o2-character-geometry-tran.dat b/test/data/h2o2-character-geometry-tran.dat new file mode 100644 index 00000000000..e50a0d56b5e --- /dev/null +++ b/test/data/h2o2-character-geometry-tran.dat @@ -0,0 +1,9 @@ +AR 0 136.500 3.330 0.000 0.000 0.000 +H 0 145.000 2.050 0.000 0.000 0.000 +H2 1 38.000 2.920 0.000 0.790 280.000 +H2O 2 572.400 2.605 1.844 0.000 4.000 +H2O2 2 107.400 3.458 0.000 0.000 3.800 +HO2 a 107.400 3.458 0.000 0.000 1.000 ! * +O 0 80.000 2.750 0.000 0.000 0.000 +O2 1 107.400 3.458 0.000 1.600 3.800 +OH 1 80.000 2.750 0.000 0.000 0.000 diff --git a/test/data/h2o2-float-arithmetic-error-geometry-tran.dat b/test/data/h2o2-float-arithmetic-error-geometry-tran.dat new file mode 100644 index 00000000000..ec4efa75083 --- /dev/null +++ b/test/data/h2o2-float-arithmetic-error-geometry-tran.dat @@ -0,0 +1,9 @@ +AR 0 136.500 3.330 0.000 0.000 0.000 +H 0 145.000 2.050 0.000 0.000 0.000 +H2 0.9999999999999999 38.000 2.920 0.000 0.790 280.000 ! * +H2O 1.9999999999999999 572.400 2.605 1.844 0.000 4.000 ! * +H2O2 2 107.400 3.458 0.000 0.000 3.800 +HO2 2 107.400 3.458 0.000 0.000 1.000 +O 0 80.000 2.750 0.000 0.000 0.000 +O2 1 107.400 3.458 0.000 1.600 3.800 +OH 1 80.000 2.750 0.000 0.000 0.000 diff --git a/test/data/h2o2-float-geometry-tran.dat b/test/data/h2o2-float-geometry-tran.dat index dbfefc4cc6c..45955e52d2c 100644 --- a/test/data/h2o2-float-geometry-tran.dat +++ b/test/data/h2o2-float-geometry-tran.dat @@ -1,9 +1,9 @@ AR 0 136.500 3.330 0.000 0.000 0.000 -H 0.00 145.000 2.050 0.000 0.000 0.000 -H2 1.00 38.000 2.920 0.000 0.790 280.000 -H2O 2.00 572.400 2.605 1.844 0.000 4.000 +H 0.00 145.000 2.050 0.000 0.000 0.000 ! * +H2 1.00 38.000 2.920 0.000 0.790 280.000 ! * +H2O 2.00 572.400 2.605 1.844 0.000 4.000 ! * H2O2 2 107.400 3.458 0.000 0.000 3.800 -HO2 2 107.400 3.458 0.000 0.000 1.000 ! * +HO2 2 107.400 3.458 0.000 0.000 1.000 O 0 80.000 2.750 0.000 0.000 0.000 O2 1 107.400 3.458 0.000 1.600 3.800 OH 1 80.000 2.750 0.000 0.000 0.000 diff --git a/test/python/test_convert.py b/test/python/test_convert.py index 06cdfb22179..108780f45d5 100644 --- a/test/python/test_convert.py +++ b/test/python/test_convert.py @@ -332,17 +332,36 @@ def test_transport_duplicate_species(self): output='h2o2_transport_duplicate_species', permissive=True) def test_transport_bad_geometry(self): - with self.assertRaisesRegex(ck2yaml.InputError, 'geometry flag'): + with self.assertRaisesRegex(ck2yaml.InputError, 'Invalid geometry flag value'): self.convert('h2o2.inp', transport='h2o2-bad-geometry-tran.dat', output='h2o2_transport_bad_geometry') + with self.assertRaisesRegex(ck2yaml.InputError, 'Invalid geometry flag \''): + self.convert('h2o2.inp', + transport='h2o2-character-geometry-tran.dat', + output='h2o2_transport_character_geometry') + def test_transport_float_geometry(self): - with self.assertRaisesRegex(ck2yaml.InputError, 'geometry flag'): + with self.assertRaisesRegex(ck2yaml.InputError, 'Incorrect geometry flag syntax'): self.convert('h2o2.inp', transport='h2o2-float-geometry-tran.dat', output='h2o2_transport_float_geometry') + output = self.convert('h2o2.inp', + transport='h2o2-float-geometry-tran.dat', + output='h2o2_transport_float_geometry', permissive=True) + + gas = ct.Solution(output) + self.assertTrue(gas.species("H").transport.geometry == 'atom') + self.assertTrue(gas.species("H2").transport.geometry == 'linear') + self.assertTrue(gas.species("H2O").transport.geometry == 'nonlinear') + + with self.assertRaisesRegex(ck2yaml.InputError, 'Invalid float geometry flag'): + self.convert('h2o2.inp', + transport='h2o2-float-arithmetic-error-geometry-tran.dat', + output='h2o2_transport_float_geometry', permissive=True) + def test_empty_reaction_section(self): output = self.convert('h2o2_emptyReactions.inp') gas = ct.Solution(output)