-
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
Merge model improvements #1649
Merged
Merged
Merge model improvements #1649
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
ELEMENTS H C O N Ne Ar He Si S Cl END | ||
|
||
SPECIES | ||
ethane | ||
C | ||
CH3 | ||
C2H5 | ||
CH2O(150) | ||
H(6) | ||
END | ||
|
||
|
||
|
||
THERM ALL | ||
300.000 1000.000 5000.000 | ||
! GRI-Mech3.0 | ||
ethane H 6C 2 G 100.000 5000.000 1002.57 1 | ||
2.56122991E+00 1.83185519E-02-7.41959133E-06 1.38553537E-09-9.75184837E-14 2 | ||
-1.19064416E+04 7.14373636E+00 3.71890614E+00 7.87935091E-04 3.81270648E-05 3 | ||
-4.17468853E-08 1.38611864E-11-1.14896639E+04 4.79187839E+00 4 | ||
|
||
C C 1 H 4 G100.000 5000.000 1084.14 1 | ||
9.08338537E-01 1.14539658E-02-4.57167062E-06 8.29175956E-10-5.66302025E-14 2 | ||
-9.72000634E+03 1.39926820E+01 4.20540260E+00-5.35542811E-03 2.51118367E-05 3 | ||
-2.13756810E-08 5.97499754E-12-1.01619428E+04-9.21233746E-01 4 | ||
|
||
CH3 C 1 H 3 G100.000 5000.000 1019.18 1 | ||
3.63559133E+00 4.67201977E-03-1.75880625E-06 3.19690509E-10-2.22178045E-14 2 | ||
1.61705114E+04 1.15112614E+00 3.91979381E+00 7.47713594E-04 8.15094523E-06 3 | ||
-8.86667966E-09 2.89448590E-12 1.62584634E+04 4.90302919E-01 4 | ||
|
||
C2H5 C 2 H 5 G100.000 5000.000 900.30 1 | ||
5.15604319E+00 9.43151705E-03-1.81963219E-06 2.21237186E-10-1.43516109E-14 2 | ||
1.20641491E+04-2.91006043E+00 3.82189848E+00-3.43439154E-03 5.09287254E-05 3 | ||
-6.20254195E-08 2.37093270E-11 1.30660102E+04 7.61621264E+00 4 | ||
|
||
CH2O(150) H 2C 1O 1 G 100.000 5000.000 1041.96 1 | ||
2.36095410E+00 7.66804276E-03-3.19770442E-06 6.04724833E-10-4.27517878E-14 2 | ||
-1.42794809E+04 1.04457152E+01 4.13878818E+00-4.69514383E-03 2.25730249E-05 3 | ||
-2.09849937E-08 6.36123283E-12-1.43493283E+04 3.23827482E+00 4 | ||
|
||
H(6) H 2 G100.000 5000.000 4448.37 1 | ||
2.50002506E+00-2.19247328E-08 7.18877672E-12-1.04676904E-15 5.71113259E-19 2 | ||
2.54741949E+04-4.45131850E-01 2.50000000E+00-9.83249483E-14 1.27659594E-16 3 | ||
-5.39769234E-19 7.02032739E-22 2.54742178E+04-4.44972896E-01 4 | ||
|
||
END | ||
|
||
|
||
|
||
REACTIONS KCAL/MOLE MOLES | ||
|
||
CH3+CH3=ethane 8.260e+15 -1.400 1.000 | ||
|
||
ethane+CH3=C+C2H5 3.936e-02 4.340 8.000 | ||
|
||
END | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
ethane | ||
1 C 0 0 {2,S} {3,S} {4,S} {5,S} | ||
2 C 0 0 {1,S} {6,S} {7,S} {8,S} | ||
3 H 0 0 {1,S} | ||
4 H 0 0 {1,S} | ||
5 H 0 0 {1,S} | ||
6 H 0 0 {2,S} | ||
7 H 0 0 {2,S} | ||
8 H 0 0 {2,S} | ||
|
||
CH3 | ||
1 C 1 0 {2,S} {3,S} {4,S} | ||
2 H 0 0 {1,S} | ||
3 H 0 0 {1,S} | ||
4 H 0 0 {1,S} | ||
|
||
C2H5 | ||
1 C 0 0 {2,S} {3,S} {4,S} {5,S} | ||
2 C 1 0 {1,S} {6,S} {7,S} | ||
3 H 0 0 {1,S} | ||
4 H 0 0 {1,S} | ||
5 H 0 0 {1,S} | ||
6 H 0 0 {2,S} | ||
7 H 0 0 {2,S} | ||
|
||
C | ||
1 C 0 0 {2,S} {3,S} {4,S} {5,S} | ||
2 H 0 0 {1,S} | ||
3 H 0 0 {1,S} | ||
4 H 0 0 {1,S} | ||
5 H 0 0 {1,S} | ||
|
||
CH2O(150) | ||
1 C u0 p0 c0 {2,D} {3,S} {4,S} | ||
2 O u0 p2 c0 {1,D} | ||
3 H u0 p0 c0 {1,S} | ||
4 H u0 p0 c0 {1,S} | ||
|
||
H(6) | ||
1 O 0 2 {2,S} {3,S} | ||
2 H 0 0 {1,S} | ||
3 H 0 0 {1,S} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
############################################################################### | ||
# # | ||
# RMG - Reaction Mechanism Generator # | ||
# # | ||
# Copyright (c) 2002-2019 Prof. William H. Green (whgreen@mit.edu), # | ||
# Prof. Richard H. West (r.west@neu.edu) and the RMG Team (rmg_dev@mit.edu) # | ||
# # | ||
# Permission is hereby granted, free of charge, to any person obtaining a # | ||
# copy of this software and associated documentation files (the 'Software'), # | ||
# to deal in the Software without restriction, including without limitation # | ||
# the rights to use, copy, modify, merge, publish, distribute, sublicense, # | ||
# and/or sell copies of the Software, and to permit persons to whom the # | ||
# Software is furnished to do so, subject to the following conditions: # | ||
# # | ||
# The above copyright notice and this permission notice shall be included in # | ||
# all copies or substantial portions of the Software. # | ||
# # | ||
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # | ||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # | ||
# DEALINGS IN THE SOFTWARE. # | ||
# # | ||
############################################################################### | ||
|
||
import unittest | ||
import os | ||
import os.path | ||
|
||
from rmgpy.tools.merge_models import get_models_to_merge, combine_models | ||
|
||
|
||
class MergeModelsTest(unittest.TestCase): | ||
|
||
def test_merge_different_models(self): | ||
folder = os.path.join(os.getcwd(), 'rmgpy/tools/data/diffmodels') | ||
|
||
chemkin3 = os.path.join(folder, 'chem3.inp') | ||
speciesDict3 = os.path.join(folder, 'species_dictionary3.txt') | ||
|
||
chemkin2 = os.path.join(folder, 'chem2.inp') | ||
speciesDict2 = os.path.join(folder, 'species_dictionary2.txt') | ||
|
||
models = get_models_to_merge(((chemkin3, speciesDict3, None), (chemkin2, speciesDict2, None))) | ||
final_model = combine_models(models) | ||
species = final_model.species | ||
reactions = final_model.reactions | ||
|
||
# make sure all species are included | ||
self.assertEqual(len(species), 15) | ||
|
||
# make sure indexes are not unnecessarily redone | ||
for s in species: | ||
if s.label == 'CH2O': | ||
self.assertEqual(s.index, 150) | ||
elif s.label == 'CH3': | ||
self.assertEqual(s.index, -1) | ||
elif s.label == 'C3H7': | ||
self.assertEqual(s.index, 14) | ||
|
||
# make sure indexes are redone when there is a conflict | ||
H_index = False | ||
for s in species: | ||
if s.label == 'H': | ||
if isinstance(H_index, bool): | ||
H_index = s.index | ||
else: | ||
# found second matching label, make sure index different | ||
self.assertNotEqual(s.index, H_index) | ||
break | ||
else: | ||
raise Exception("Could not find two species identical labels") | ||
|
||
# make sure reaction rates come from first model | ||
for r in reactions: | ||
if len(r.reactants) == 2 and r.reactants[0].label == 'CH3' and\ | ||
r.reactants[1].label == 'CH3': | ||
self.assertAlmostEqual(r.kinetics.A.value_si, 8.260e+9, places=0, | ||
msg="Kinetics did not match from first input model") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do we want to have unique indices? In other words, do we want to reindex starting from the largest index in the entire model + 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.
This code isn't guaranteeing unique indexes at all. To do that, we would pretty much have to renumber everything except the first model, which would make this PR much less useful.
From my point of view, if the user starts with an un-indexed mechanism, like aramcomech, the output should also not have indexes.
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.
Is there a benefit to unique indices that I've overlooked? My main goal for this PR was to not have any CHEMKIN or cantera strings conflict, while keeping those names as similar as possible to the input names.
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.
To give an example of the functioning in this PR: if model 1 has
CH3(15)
and model 2 hasH2O(15)
, then neither of their names would be changed, since both the name and index don't match.I would think for many users, avoiding chemkin or cantera names changing would be preferable to ensuring every species has a unique number.
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.
Let me know your thoughts on this
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, I forgot that we would also need to check for species which already have the same indices.
I think it would only matter if you were merging RMG models and wanted to load the merged model back into RMG, which would parse the indices from the labels. I'm not sure exactly what effect duplicate indices would have in that scenario though. It might not actually matter.
I'm ok with the behavior you implemented. I think the key desired outcome is that the resulting merged mechanism file is directly simulate-able in Chemkin or Cantera.