-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix bugs in Chemkin thermo entry element reading/writing #1636
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1636 +/- ##
=========================================
Coverage ? 41.85%
=========================================
Files ? 82
Lines ? 21574
Branches ? 5653
=========================================
Hits ? 9030
Misses ? 11553
Partials ? 991 Continue to review full report at Codecov.
|
Ugh. This then led me to dig further and ask is the columns 74-78 extension official and/or in Chemkin or Cantera? It seems that it is official, and in Chemkin, but it is not (yet) read by Cantera, although Cantera DOES read the extended line syntax (now that we have it correctly white-space separated) This is part of Cantera's ck2cti def readThermoEntry(self, lines, TintDefault):
"""
Read a thermodynamics entry for one species in a Chemkin-format file
(consisting of two 7-coefficient NASA polynomials). Returns the label of
the species, the thermodynamics model as a :class:`MultiNASA` object, the
elemental composition of the species, and the comment/note associated with
the thermo entry.
"""
identifier = lines[0][0:24].split()
species = identifier[0].strip()
if len(identifier) > 1:
note = ''.join(identifier[1:]).strip()
else:
note = ''
# Normal method for specifying the elemental composition
composition = self.parseComposition(lines[0][24:44], 4, 5)
# Chemkin-style extended elemental composition: additional lines
# indicated by '&' continuation character on preceding lines. Element
# names and abundances are separated by whitespace (not fixed width)
if lines[0].rstrip().endswith('&'):
complines = []
for i in range(len(lines)-1):
if lines[i].rstrip().endswith('&'):
complines.append(lines[i+1])
else:
break
lines = [lines[0]] + lines[i+1:]
comp = ' '.join(line.rstrip('&\n') for line in complines).split()
composition = {}
for i in range(0, len(comp), 2):
composition[comp[i].capitalize()] = int(comp[i+1])
# Non-standard extended elemental composition data may be located beyond
# column 80 on the first line of the thermo entry
if len(lines[0]) > 80:
elements = lines[0][80:]
composition2 = self.parseComposition(elements, len(elements)//10, 10)
composition.update(composition2)
if not composition:
raise InputParseError("Error parsing elemental composition for "
"species '{0}'".format(species)) The columns 74-78 syntax is in the ckinterp.f source code comments
and the source code
and it's also documented in the 1980 Sandia report of the original CHEMKIN ...so we should open an issue (or pull request) to support it in Cantera. But until that's merged and released, doing this will make Chemkin files that Cantera can't read. I think I'd rather inconvenience Chemkin-II users than Cantera 2.4.0 users. I know several of the latter ;-) Of course, we could also include our own slightly modified ck2cti in RMG. It's a stand-alone Python script that doesn't need all of Cantera. |
For reference: Cantera/cantera#656 |
I rebased @mliu49's PR onto the new master, converting them to Python 3 and RMG 3 in the process, and added another couple of commits. Hope you don't mind that I force pushed. |
60d9467
to
a99fcdc
Compare
I did some additional refactoring of the thermo writing method and squashed the commits together. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't actually run it or the tests, but looking at the code on github I like the way you have refactored it.
""" | ||
|
||
self.entry2 = """CH3NO2X G 300.000 3000.000 650.73 1& | ||
C 1 H 3 N 1 O 2 X 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably these have to be 5-column wide blocks like C 1 H 3 N 1 O 2 X 1
now?
Haven't actually run the code or the unit tests to check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 5-column wide blocks refers to the original method of placing them in the first line. The extended line is still space delimited. The tests currently pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, I misread something. Looks good. Can I "approve"
""" | ||
|
||
self.entry3 = """CH3NO2SX G 300.000 3000.000 650.73 1& | ||
C 1 H 3 N 1 O 2 S 1 X 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for these, I imagine
Using the same algorithm as Molecule.get_formula() method which says iff there is any Carbon then C and H come first, and everything else is alphabetic. Before this, it seemed to be unstable, at least with respect to small changes in RMG, even if it were stable from one run to another.
For species with 4 elements or less, put them in the first line For species with 5 elements or more, put them on the next line using the space delimited syntax. 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
Add unit tests for various element count syntaxes Fix incorrect index for element count in columns 74-78 (should start at column 73 using zero-indexing)
Motivation or Problem
RMG Chemkin files break Cantera ck2cti for species with 5 or more elements. #1634
Description of Changes
{0!s:<2}{1:>3d}
approach.Testing
Should test with ck2cti and perhaps Chemkin as well. I have not done so yet.