Skip to content

Commit

Permalink
Don't use the 74-78 columns for 5th element CHEMKIN syntax.
Browse files Browse the repository at this point in the history
Although the CHEMKIN manual specifies that one may put
the 5th element atom count in columns 74-78 of row 1,
in practice nobody does this, and Cantera cannot read it
if we do, so this commit stops us from doing this.
Instead if there are 5 or more elements present, we use
the extended syntax (that we were using for 6+ elements).

For more details see discussion at 
Cantera/cantera#656
  • Loading branch information
rwest committed Nov 14, 2019
1 parent 12397e1 commit a99fcdc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
14 changes: 8 additions & 6 deletions rmgpy/chemkin.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1535,8 +1535,11 @@ def write_thermo_entry(species, element_counts=None, verbose=True):

# Line 1
string += '{0:<16} '.format(get_species_identifier(species))
if len(element_counts) <= 5:
if len(element_counts) <= 4:
# Use the original Chemkin syntax for the element counts
# Up to the first 4 elements only
# (don't use the space in columns 74-78 for the 5th element
# because nobody else does and Cantera can't read it)
elements = []
for key, count in element_counts.items():
if isinstance(key, tuple):
Expand All @@ -1545,23 +1548,22 @@ def write_thermo_entry(species, element_counts=None, verbose=True):
else:
chemkin_name = key
elements.append('{0!s:<2}{1:>3d}'.format(chemkin_name, count))
elements.extend([' '] * (5 - len(element_counts)))
elements.extend([' '] * (4 - len(element_counts)))
string += ''.join(elements[0:4])
string += 'G{0:>10.3f}{1:>10.3f}{2:>8.2f}{3} 1'.format(
string += 'G{0:>10.3f}{1:>10.3f}{2:>8.2f} 1'.format(
thermo.polynomials[0].Tmin.value_si,
thermo.polynomials[1].Tmax.value_si,
thermo.polynomials[0].Tmax.value_si,
elements[4]
)
else:
# Use the new-style Chemkin syntax for the element counts
# This will only be recognized by Chemkin 4 or later
string += ' G{0:>10.3f}{1:>10.3f}{2:>8.2f} 1'.format(
thermo.polynomials[0].Tmin.value_si,
thermo.polynomials[1].Tmax.value_si,
thermo.polynomials[0].Tmax.value_si,
)
string += '&\n'
# Use the new-style Chemkin syntax for the element counts
# This will only be recognized by Chemkin 4 or later
elements = []
for key, count in element_counts.items():
if isinstance(key, tuple):
Expand Down
3 changes: 2 additions & 1 deletion rmgpy/chemkinTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,8 @@ def setUp(self):
-5.99027000E-08 2.38945000E-11-1.12576000E+04 3.56130000E+00 4
"""

self.entry2 = """CH3NO2X C 1H 3N 1O 2G 300.000 3000.000 650.73X 1 1
self.entry2 = """CH3NO2X G 300.000 3000.000 650.73 1&
C 1 H 3 N 1 O 2 X 1
-3.07954000E-01 2.45269000E-02-1.24130000E-05 3.07724000E-09-3.01467000E-13 2
-1.06930000E+04 2.26280000E+01 4.03055000E+00-2.14171000E-03 4.90611000E-05 3
-5.99027000E-08 2.38945000E-11-1.12576000E+04 3.56130000E+00 4
Expand Down

0 comments on commit a99fcdc

Please sign in to comment.