From e94f78254689c6f436b8f5f452d7e695a49d074b Mon Sep 17 00:00:00 2001 From: 12Chao Date: Tue, 2 Jun 2020 21:22:25 -0400 Subject: [PATCH] [ck2yaml] Raise the error when ck2yaml accidentally writes element symbol string which includes number in it, issue #853 --- interfaces/cython/cantera/ck2yaml.py | 10 +++- .../cython/cantera/test/test_convert.py | 5 +- test/data/big_element_num_err.inp | 54 +++++++++++++++++++ 3 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 test/data/big_element_num_err.inp diff --git a/interfaces/cython/cantera/ck2yaml.py b/interfaces/cython/cantera/ck2yaml.py index 292264f320e..db5692a8406 100644 --- a/interfaces/cython/cantera/ck2yaml.py +++ b/interfaces/cython/cantera/ck2yaml.py @@ -865,7 +865,15 @@ def read_NASA7_entry(self, lines, TintDefault, comments): if not composition: raise InputError("Error parsing elemental composition for " "species '{}'", species) - + else: + for symbol in composition.keys(): + + # check if self.parse_composition parses composition correctly + if any(map(str.isdigit, symbol)) and symbol not in self.elements: + raise InputError("Error parsing elemental composition for " + "species thermo entry\n{}" + "\n the first line has an incorrect format", "".join(lines)) + # Extract the NASA polynomial coefficients # Remember that the high-T polynomial comes first! Tmin = fortFloat(lines[0][45:55]) diff --git a/interfaces/cython/cantera/test/test_convert.py b/interfaces/cython/cantera/test/test_convert.py index 6f0119d3463..1227df433f5 100644 --- a/interfaces/cython/cantera/test/test_convert.py +++ b/interfaces/cython/cantera/test/test_convert.py @@ -468,7 +468,10 @@ def test_extra(self): self.assertEqual(desc, 'This is an alternative description.') for key in ['foo', 'bar']: self.assertIn(key, yml.keys()) - + + def test_error_for_big_element_number(self): + with self.assertRaisesRegex(self.InputError, 'the first line has an incorrect format'): + self.convert('big_element_num_err.inp') class CtmlConverterTest(utilities.CanteraTest): def test_sofc(self): diff --git a/test/data/big_element_num_err.inp b/test/data/big_element_num_err.inp new file mode 100644 index 00000000000..7517792a611 --- /dev/null +++ b/test/data/big_element_num_err.inp @@ -0,0 +1,54 @@ +ELEMENTS +C +H +O +END + +SPECIES +BIN7AJ +O +H2 +CO +BIN6AJ +BIN6BJ + +END + +THERMO ALL + 270.000 1000.000 3500.000 +BIN7AJ C 1250H 812 G 300.00 3500.00 1260.00 1 + 2.35938249e+03 3.50442304e+00-1.25852280e-03 2.00397985e-07-1.15957197e-11 2 + 2.45225502e+05-1.29759728e+04-1.05686227e+03 1.43496445e+01-1.41695007e-02 3 + 7.03160324e-06-1.36699359e-09 1.10611918e+06 4.29496756e+03 4 + +O O 1 G 200.00 3500.00 720.00 1 + 2.62549143e+00-2.08959644e-04 1.33918546e-07-3.85875896e-11 4.38918689e-15 2 + 2.92061519e+04 4.48358519e+00 3.14799201e+00-3.11174065e-03 6.18137897e-06 3 +-5.63808798e-09 1.94866016e-12 2.91309118e+04 2.13446549e+00 4 + +H2 H 2 G 200.00 3500.00 700.00 1 + 3.78199881e+00-1.01873259e-03 1.24226233e-06-4.19011898e-10 4.75543793e-14 2 +-1.10283023e+03-5.60525910e+00 2.64204438e+00 5.49529274e-03-1.27163634e-05 3 + 1.28749173e-08-4.70027749e-12-9.43236614e+02-5.12231102e-01 4 + +CO C 1O 1 G 200.00 3500.00 960.00 1 + 2.79255381e+00 1.87486886e-03-8.59711926e-07 1.91200070e-10-1.67855286e-14 2 +-1.41723335e+04 7.41443560e+00 3.75723891e+00-2.14465241e-03 5.42079005e-06 3 +-4.17025963e-09 1.11901127e-12-1.43575530e+04 2.79976799e+00 4 + +BIN6AJ C 640H 43 G 300.00 3500.00 1290.00 1 + 1.23762821e+03 1.77026241e+00-6.22545371e-04 9.54207658e-08-5.13173999e-12 2 + 1.25536835e+05-6.67884001e+03-5.26755261e+02 7.24121890e+00-6.98412269e-03 3 + 3.38305762e-06-6.42270665e-10 5.80747770e+05 2.28257683e+03 4 + +BIN6BJ C 640H 127 G 300.00 3500.00 1390.00 1 + 1.08992363e+03 1.08035536e+00-3.02579890e-04 2.55048499e-08 8.09218683e-13 2 +-2.94595285e+05-5.83854863e+03-5.54531539e+02 5.81260044e+00-5.40931919e-03 3 + 2.47478029e-06-4.39707947e-10 1.62563251e+05 2.63652221e+03 4 + +END + +REACTIONS +O+BIN7AJ=>0.324527000009200H2+CO+0.001558870333385BIN6AJ+0.000080473103595BIN6BJ+0.998360656160266BIN7AJ 5.0000e+13 0.000 0.00 + +END