Skip to content

Commit

Permalink
Float transport data requested changes Cantera#1396
Browse files Browse the repository at this point in the history
- Add warning message when float is automatically converted to integer
- Change test case for float transport data to test for floating point rounding errors
  • Loading branch information
corykinney committed Oct 3, 2022
1 parent 2ebcccc commit 4f99d88
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
28 changes: 18 additions & 10 deletions interfaces/cython/cantera/ck2yaml.py
Expand Up @@ -687,18 +687,26 @@ 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:
if float(geometry) == int(float(geometry)):
geometry = int(float(geometry))
else:
raise ValueError("Flag should be an integer.")
if geometry not in (0, 1, 2):
raise ValueError("Flag value should be 0, 1, or 2.")
except ValueError as e:
raise InputError("Bad geometry flag '{}' for species '{}'.", geometry, label) from e
geometry = int(geometry)
except ValueError:
try:
geometry = float(geometry)
except ValueError:
raise InputError(
"Bad geometry flag '{}' for species '{}'. "
"Flag should be an integer.", geometry, label) from None
if geometry == int(geometry):
geometry = int(geometry)
parser.warn("Incorrect syntax for geometry flag for species {0}. "
"If --permissive was given, the flag was automatically "
"converted to an integer.".format(label))
if geometry not in (0, 1, 2):
raise InputError("Bad geometry flag '{}' for species '{}'. "
"Flag value should 0, 1, or 2.", geometry, label)

self.geometry = self.geometry_flags[int(geometry)]
self.well_depth = float(well_depth)
Expand Down Expand Up @@ -1891,7 +1899,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(
Expand Down
6 changes: 3 additions & 3 deletions test/data/h2o2-float-geometry-tran.dat
@@ -1,7 +1,7 @@
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 145.000 2.050 0.000 0.000 0.000
H2 0.999999999999999999 38.000 2.920 0.000 0.790 280.000
H2O 1.999999999999999999 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
Expand Down

0 comments on commit 4f99d88

Please sign in to comment.