Skip to content
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

Adding in coverage dependent effects to surface kinetics #2090

Merged
merged 43 commits into from Jul 23, 2021
Merged

Adding in coverage dependent effects to surface kinetics #2090

merged 43 commits into from Jul 23, 2021

Conversation

mazeau
Copy link
Contributor

@mazeau mazeau commented Mar 16, 2021

Motivation or Problem

Coverage dependent effects are found in many surface mechanisms, and we have been unable to use them. These effects can become significant at high temperatures and pressures. Additionally, some models would have too much O2 adsorbing to the surface too quickly, blocking anything else from happening.

Description of Changes

A new kinetics attribute called coverage_dependence was added that is a dictionary of dictionaries that holds the Species the parameters correspond to and the coverage dependent parameters.

Testing

Unit tests to make sure RMG can read in kinetics entries with coverage dependent parameters, write chemkin and cantera output files with the coverage parameters, and use the parameters correctly. We've built a few models with it, and it seems to be working.

Note: dual PR with database.

Goes with ReactionMechanismGenerator/RMG-database#462
The commits that add this to the CI testing should be removed from both PRs before merging.

@mazeau
Copy link
Contributor Author

mazeau commented Mar 16, 2021

Is able to currently compile, and rmg test errors are as follows:

======================================================================
ERROR: This example tests if family and templates info can be correctly
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/emilymazeau/Code/RMG-Py/rmgpy/chemkinTest.py", line 157, in test_read_and_write_and_read_template_reaction_family_for_minimal_example
    save_chemkin_file(chemkin_save_path, species, reactions, verbose=True, check_for_duplicates=True)
  File "rmgpy/chemkin.pyx", line 2110, in rmgpy.chemkin.save_chemkin_file
    f.write(write_kinetics_entry(rxn, species_list=species, verbose=verbose))
  File "rmgpy/chemkin.pyx", line 1792, in rmgpy.chemkin.write_kinetics_entry
    if kinetics.cov is not None:
AttributeError: 'rmgpy.kinetics.arrhenius.Arrhenius' object has no attribute 'cov'

======================================================================
ERROR: This example is mainly to ensure comments like
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/emilymazeau/Code/RMG-Py/rmgpy/chemkinTest.py", line 206, in test_read_and_write_template_reaction_family_for_pdd_example
    save_chemkin_file(chemkin_save_path, species, reactions, verbose=False, check_for_duplicates=False)
  File "rmgpy/chemkin.pyx", line 2110, in rmgpy.chemkin.save_chemkin_file
    f.write(write_kinetics_entry(rxn, species_list=species, verbose=verbose))
  File "rmgpy/chemkin.pyx", line 1792, in rmgpy.chemkin.write_kinetics_entry
    if kinetics.cov is not None:
AttributeError: 'rmgpy.kinetics.arrhenius.Arrhenius' object has no attribute 'cov'

======================================================================
ERROR: Test the Reaction.reverse_surface_arrhenius_rate() method works for SurfaceArrhenius format.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/emilymazeau/Code/RMG-Py/rmgpy/reactionTest.py", line 780, in test_reverse_surface_arrhenius_rate
    reverse_kinetics = self.reaction2.generate_reverse_rate_coefficient()
  File "rmgpy/reaction.py", line 885, in rmgpy.reaction.Reaction.generate_reverse_rate_coefficient
    def generate_reverse_rate_coefficient(self, network_kinetics=False, Tmin=None, Tmax=None, surface_site_density=0):
  File "rmgpy/reaction.py", line 938, in rmgpy.reaction.Reaction.generate_reverse_rate_coefficient
    return self.reverse_surface_arrhenius_rate(kf, kunits, Tmin, Tmax)
  File "rmgpy/reaction.py", line 854, in rmgpy.reaction.Reaction.reverse_surface_arrhenius_rate
    klist[i] = kf.get_rate_coefficient(Tlist[i]) / self.get_equilibrium_constant(Tlist[i])
  File "rmgpy/kinetics/surface.pyx", line 478, in rmgpy.kinetics.surface.SurfaceArrhenius.get_rate_coefficient
    cov = self.cov
  File "rmgpy/kinetics/surface.pyx", line 442, in rmgpy.kinetics.surface.SurfaceArrhenius.cov.__get__
    return self._cov
AttributeError: 'rmgpy.kinetics.surface.SurfaceArrhenius' object has no attribute '_cov'

======================================================================
ERROR: test_get_rate_coefficient_units_from_reaction_order (rmgpy.reactionTest.TestSurfaceReaction)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/emilymazeau/Code/RMG-Py/rmgpy/reactionTest.py", line 263, in test_get_rate_coefficient_units_from_reaction_order
    self.assertEqual(self.rxn1s.generate_reverse_rate_coefficient().A.units, 'm^2/(mol*s)')
  File "rmgpy/reaction.py", line 885, in rmgpy.reaction.Reaction.generate_reverse_rate_coefficient
    def generate_reverse_rate_coefficient(self, network_kinetics=False, Tmin=None, Tmax=None, surface_site_density=0):
  File "rmgpy/reaction.py", line 938, in rmgpy.reaction.Reaction.generate_reverse_rate_coefficient
    return self.reverse_surface_arrhenius_rate(kf, kunits, Tmin, Tmax)
  File "rmgpy/reaction.py", line 854, in rmgpy.reaction.Reaction.reverse_surface_arrhenius_rate
    klist[i] = kf.get_rate_coefficient(Tlist[i]) / self.get_equilibrium_constant(Tlist[i])
  File "rmgpy/kinetics/surface.pyx", line 478, in rmgpy.kinetics.surface.SurfaceArrhenius.get_rate_coefficient
    cov = self.cov
  File "rmgpy/kinetics/surface.pyx", line 442, in rmgpy.kinetics.surface.SurfaceArrhenius.cov.__get__
    return self._cov
AttributeError: 'rmgpy.kinetics.surface.SurfaceArrhenius' object has no attribute '_cov'

======================================================================
ERROR: Test the CH3 adsorption rate given by SurfaceArrhenius
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/emilymazeau/Code/RMG-Py/rmgpy/reactionTest.py", line 240, in test_methyl_adsorption_surface_arrhenius
    calculated = self.rxn2sSA.get_surface_rate_coefficient(T, surface_site_density)
  File "rmgpy/reaction.py", line 691, in rmgpy.reaction.Reaction.get_surface_rate_coefficient
    def get_surface_rate_coefficient(self, T, surface_site_density):
  File "rmgpy/reaction.py", line 730, in rmgpy.reaction.Reaction.get_surface_rate_coefficient
    return self.kinetics.get_rate_coefficient(T, P=0)
  File "rmgpy/kinetics/surface.pyx", line 478, in rmgpy.kinetics.surface.SurfaceArrhenius.get_rate_coefficient
    cov = self.cov
  File "rmgpy/kinetics/surface.pyx", line 442, in rmgpy.kinetics.surface.SurfaceArrhenius.cov.__get__
    return self._cov
AttributeError: 'rmgpy.kinetics.surface.SurfaceArrhenius' object has no attribute '_cov'

======================================================================
ERROR: Test the Reaction.reverse_sticking_coeff_rate() method works for StickingCoefficient format.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/emilymazeau/Code/RMG-Py/rmgpy/reactionTest.py", line 288, in test_reverse_sticking_coeff_rate
    reverse_reverse_kinetics = rxn_copy.generate_reverse_rate_coefficient(surface_site_density=2.5e-5)
  File "rmgpy/reaction.py", line 885, in rmgpy.reaction.Reaction.generate_reverse_rate_coefficient
    def generate_reverse_rate_coefficient(self, network_kinetics=False, Tmin=None, Tmax=None, surface_site_density=0):
  File "rmgpy/reaction.py", line 938, in rmgpy.reaction.Reaction.generate_reverse_rate_coefficient
    return self.reverse_surface_arrhenius_rate(kf, kunits, Tmin, Tmax)
  File "rmgpy/reaction.py", line 854, in rmgpy.reaction.Reaction.reverse_surface_arrhenius_rate
    klist[i] = kf.get_rate_coefficient(Tlist[i]) / self.get_equilibrium_constant(Tlist[i])
  File "rmgpy/kinetics/surface.pyx", line 478, in rmgpy.kinetics.surface.SurfaceArrhenius.get_rate_coefficient
    cov = self.cov
  File "rmgpy/kinetics/surface.pyx", line 442, in rmgpy.kinetics.surface.SurfaceArrhenius.cov.__get__
    return self._cov
AttributeError: 'rmgpy.kinetics.surface.SurfaceArrhenius' object has no attribute '_cov'

======================================================================
ERROR: Test that SurfaceReactor mole fractions are set properly
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/emilymazeau/Code/RMG-Py/rmgpy/rmg/inputTest.py", line 300, in test_surface_reactor_mole_fractions
    terminationTime=(1, 's'),
  File "/Users/emilymazeau/Code/RMG-Py/rmgpy/rmg/input.py", line 512, in surface_reactor
    sens_conditions=sens_conditions)
  File "rmgpy/solver/surface.pyx", line 104, in rmgpy.solver.surface.SurfaceReactor.__init__
    self.cov_dep = {}
AttributeError: 'rmgpy.solver.surface.SurfaceReactor' object has no attribute 'cov_dep'

======================================================================
ERROR: Test that SurfaceReactor mole fractions are normalized properly
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/emilymazeau/anaconda3/envs/rmg_env/lib/python3.7/unittest/mock.py", line 1259, in patched
    return func(*args, **keywargs)
  File "/Users/emilymazeau/Code/RMG-Py/rmgpy/rmg/inputTest.py", line 322, in test_surface_reactor_mole_fractions_normalize_1
    terminationTime=(1, 's'),
  File "/Users/emilymazeau/Code/RMG-Py/rmgpy/rmg/input.py", line 512, in surface_reactor
    sens_conditions=sens_conditions)
  File "rmgpy/solver/surface.pyx", line 104, in rmgpy.solver.surface.SurfaceReactor.__init__
    self.cov_dep = {}
AttributeError: 'rmgpy.solver.surface.SurfaceReactor' object has no attribute 'cov_dep'

======================================================================
ERROR: This example is to test if an HTML file can be generated
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/emilymazeau/Code/RMG-Py/rmgpy/rmg/outputTest.py", line 61, in test_save_output_html
    save_output_html(out, cerm)
  File "/Users/emilymazeau/Code/RMG-Py/rmgpy/rmg/output.py", line 513, in save_output_html
    textwrap=textwrap))
  File "/Users/emilymazeau/anaconda3/envs/rmg_env/lib/python3.7/site-packages/jinja2/environment.py", line 1090, in render
    self.environment.handle_exception()
  File "/Users/emilymazeau/anaconda3/envs/rmg_env/lib/python3.7/site-packages/jinja2/environment.py", line 832, in handle_exception
    reraise(*rewrite_traceback_stack(source=source))
  File "/Users/emilymazeau/anaconda3/envs/rmg_env/lib/python3.7/site-packages/jinja2/_compat.py", line 28, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 359, in top-level template code
  File "rmgpy/reaction.py", line 244, in rmgpy.reaction.Reaction.to_chemkin
    return rmgpy.chemkin.write_kinetics_entry(self, species_list)
  File "rmgpy/chemkin.pyx", line 1792, in rmgpy.chemkin.write_kinetics_entry
    if kinetics.cov is not None:
AttributeError: 'rmgpy.kinetics.arrhenius.Arrhenius' object has no attribute 'cov'

======================================================================
ERROR: Test the surface batch reactor with a nondissociative adsorption of CH3
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/emilymazeau/Code/RMG-Py/rmgpy/solver/surfaceTest.py", line 225, in test_solve_ch3
    termination=[])
  File "rmgpy/solver/surface.pyx", line 104, in rmgpy.solver.surface.SurfaceReactor.__init__
    self.cov_dep = {}
AttributeError: 'rmgpy.solver.surface.SurfaceReactor' object has no attribute 'cov_dep'

======================================================================
ERROR: Test the surface batch reactor with a dissociative adsorption of H2
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/emilymazeau/Code/RMG-Py/rmgpy/solver/surfaceTest.py", line 95, in test_solve_h2
    termination=[])
  File "rmgpy/solver/surface.pyx", line 104, in rmgpy.solver.surface.SurfaceReactor.__init__
    self.cov_dep = {}
AttributeError: 'rmgpy.solver.surface.SurfaceReactor' object has no attribute 'cov_dep'

======================================================================
ERROR: test_identical_models (rmgpy.tools.diffmodelsTest.DiffModelsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/emilymazeau/Code/RMG-Py/rmgpy/tools/diffmodelsTest.py", line 52, in test_identical_models
    execute(chemkin1, species_dict1, None, chemkin2, species_dict2, None, **kwargs)
  File "/Users/emilymazeau/Code/RMG-Py/rmgpy/tools/diffmodels.py", line 430, in execute
    common_reactions, unique_reactions1, unique_reactions2)
  File "/Users/emilymazeau/Code/RMG-Py/rmgpy/rmg/output.py", line 1316, in save_diff_html
    get_species_identifier=get_species_identifier, textwrap=textwrap))
  File "/Users/emilymazeau/anaconda3/envs/rmg_env/lib/python3.7/site-packages/jinja2/environment.py", line 1090, in render
    self.environment.handle_exception()
  File "/Users/emilymazeau/anaconda3/envs/rmg_env/lib/python3.7/site-packages/jinja2/environment.py", line 832, in handle_exception
    reraise(*rewrite_traceback_stack(source=source))
  File "/Users/emilymazeau/anaconda3/envs/rmg_env/lib/python3.7/site-packages/jinja2/_compat.py", line 28, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 539, in top-level template code
  File "rmgpy/reaction.py", line 244, in rmgpy.reaction.Reaction.to_chemkin
    return rmgpy.chemkin.write_kinetics_entry(self, species_list)
  File "rmgpy/chemkin.pyx", line 1792, in rmgpy.chemkin.write_kinetics_entry
    if kinetics.cov is not None:
AttributeError: 'rmgpy.kinetics.arrhenius.Arrhenius' object has no attribute 'cov'

@mazeau
Copy link
Contributor Author

mazeau commented Mar 16, 2021

Current errors:

======================================================================
ERROR: Test the surface batch reactor with a nondissociative adsorption of CH3
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/emilymazeau/Code/RMG-Py/rmgpy/solver/surfaceTest.py", line 228, in test_solve_ch3
    rxn_system.initialize_model(core_species, core_reactions, edge_species, edge_reactions)
  File "rmgpy/solver/surface.pyx", line 123, in rmgpy.solver.surface.SurfaceReactor.initialize_model
    cpdef initialize_model(self,
  File "rmgpy/solver/surface.pyx", line 173, in rmgpy.solver.surface.SurfaceReactor.initialize_model
    self.cov_dep_index_smiles[index] = spec.smiles
AttributeError: 'rmgpy.solver.surface.SurfaceReactor' object has no attribute 'cov_dep_index_smiles'

======================================================================
ERROR: Test the surface batch reactor with a dissociative adsorption of H2
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/emilymazeau/Code/RMG-Py/rmgpy/solver/surfaceTest.py", line 97, in test_solve_h2
    rxn_system.initialize_model(core_species, core_reactions, edge_species, edge_reactions)
  File "rmgpy/solver/surface.pyx", line 123, in rmgpy.solver.surface.SurfaceReactor.initialize_model
    cpdef initialize_model(self,
  File "rmgpy/solver/surface.pyx", line 173, in rmgpy.solver.surface.SurfaceReactor.initialize_model
    self.cov_dep_index_smiles[index] = spec.smiles
AttributeError: 'rmgpy.solver.surface.SurfaceReactor' object has no attribute 'cov_dep_index_smiles'

@mazeau
Copy link
Contributor Author

mazeau commented Mar 16, 2021

latest errors.. seems like the attribute is there now but is a nonetype:

======================================================================
ERROR: Test the surface batch reactor with a nondissociative adsorption of CH3
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/emilymazeau/Code/RMG-Py/rmgpy/solver/surfaceTest.py", line 228, in test_solve_ch3
    rxn_system.initialize_model(core_species, core_reactions, edge_species, edge_reactions)
  File "rmgpy/solver/surface.pyx", line 126, in rmgpy.solver.surface.SurfaceReactor.initialize_model
    cpdef initialize_model(self,
  File "rmgpy/solver/surface.pyx", line 176, in rmgpy.solver.surface.SurfaceReactor.initialize_model
    self.cov_dep_index_smiles[index] = spec.smiles
TypeError: 'NoneType' object is not subscriptable

======================================================================
ERROR: Test the surface batch reactor with a dissociative adsorption of H2
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/emilymazeau/Code/RMG-Py/rmgpy/solver/surfaceTest.py", line 97, in test_solve_h2
    rxn_system.initialize_model(core_species, core_reactions, edge_species, edge_reactions)
  File "rmgpy/solver/surface.pyx", line 126, in rmgpy.solver.surface.SurfaceReactor.initialize_model
    cpdef initialize_model(self,
  File "rmgpy/solver/surface.pyx", line 176, in rmgpy.solver.surface.SurfaceReactor.initialize_model
    self.cov_dep_index_smiles[index] = spec.smiles
TypeError: 'NoneType' object is not subscriptable

@mazeau
Copy link
Contributor Author

mazeau commented Mar 17, 2021

Potential issues:
SMILES for H-X is the same as empty surface site [Pt]

@mazeau
Copy link
Contributor Author

mazeau commented Mar 17, 2021

All rmg tests pass now

Ran 1807 tests in 185.080s

OK (SKIP=45)

@mazeau
Copy link
Contributor Author

mazeau commented Mar 17, 2021

all rmg tests and database tests pass now!!!!!

@codecov
Copy link

codecov bot commented Mar 17, 2021

Codecov Report

Merging #2090 (7f64fc6) into master (3965d59) will increase coverage by 0.05%.
The diff coverage is 33.33%.

❗ Current head 7f64fc6 differs from pull request most recent head 5918981. Consider uploading reports for the commit 5918981 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2090      +/-   ##
==========================================
+ Coverage   47.84%   47.90%   +0.05%     
==========================================
  Files         102      102              
  Lines       27089    27116      +27     
  Branches     6948     6957       +9     
==========================================
+ Hits        12962    12989      +27     
- Misses      12734    12737       +3     
+ Partials     1393     1390       -3     
Impacted Files Coverage Δ
rmgpy/data/kinetics/family.py 47.38% <ø> (ø)
rmgpy/rmg/input.py 41.01% <0.00%> (-0.26%) ⬇️
rmgpy/rmg/model.py 40.59% <6.66%> (-0.49%) ⬇️
rmgpy/data/kinetics/library.py 42.35% <100.00%> (+0.82%) ⬆️
rmgpy/rmg/main.py 22.62% <100.00%> (+0.10%) ⬆️
arkane/kinetics.py 12.24% <0.00%> (ø)
rmgpy/molecule/draw.py 53.52% <0.00%> (+1.54%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3965d59...5918981. Read the comment docs.

@mazeau
Copy link
Contributor Author

mazeau commented Mar 19, 2021

fixing up repr current errors:


======================================================================
ERROR: This tests the the library.save method by writing a new temporary file and
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/emilymazeau/Code/RMG-Py/rmgpy/data/kinetics/libraryTest.py", line 91, in test_save_library
    libraries=None)  # this loads all of them, including the new copy
  File "/Users/emilymazeau/Code/RMG-Py/rmgpy/data/kinetics/database.py", line 258, in load_libraries
    library.load(library_file, self.local_context, self.global_context)
  File "/Users/emilymazeau/Code/RMG-Py/rmgpy/data/kinetics/library.py", line 411, in load
    exec(f.read(), global_context, local_context)
  File "<string>", line 17
SyntaxError: positional argument follows keyword argument

======================================================================
ERROR: Test that an StickingCoefficient object can be reconstructed from its repr()
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/emilymazeau/Code/RMG-Py/rmgpy/kinetics/surfaceTest.py", line 148, in test_repr
    exec('stick = {0!r}'.format(self.stick), globals(), namespace)
  File "<string>", line 1
SyntaxError: positional argument follows keyword argument

======================================================================
ERROR: Test that an SurfaceArrhenius object can be reconstructed from its repr()
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/emilymazeau/Code/RMG-Py/rmgpy/kinetics/surfaceTest.py", line 300, in test_repr
    exec('surfarr = {0!r}'.format(self.surfarr), globals(), namespace)
  File "<string>", line 1
SyntaxError: positional argument follows keyword argument

@mazeau
Copy link
Contributor Author

mazeau commented Mar 19, 2021

All new and old rmg tests pass and all new and old database tests pass. Only thing left is cantera export I think

@mazeau mazeau force-pushed the cde branch 8 times, most recently from d0df754 to 679a5e8 Compare March 20, 2021 00:01
Copy link
Member

@rwest rwest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made a few comments.
I'm worried about depending on SMILES. There are many possible SMILES for a given species, and sometimes RMG gets them wrong, etc.

rmgpy/kinetics/surface.pyx Outdated Show resolved Hide resolved
rmgpy/kinetics/surface.pyx Outdated Show resolved Hide resolved
rmgpy/reactionTest.py Outdated Show resolved Hide resolved
rmgpy/solver/surface.pyx Outdated Show resolved Hide resolved
rmgpy/solver/surface.pyx Outdated Show resolved Hide resolved
Copy link
Contributor

@davidfarinajr davidfarinajr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking good @mazeau . I think we should add more type and value checks when setting the cov dep params for kinetics. We should also figure out how to represent species in cov dep dicts, and determine the most efficient way to find those species and apply cov dep correction in the solver

rmgpy/solver/surface.pyx Outdated Show resolved Hide resolved
rmgpy/kinetics/surface.pyx Show resolved Hide resolved
@rwest
Copy link
Member

rwest commented Mar 24, 2021

I agree that SMILES has its downsides, but we need to use some kind of chemical identifier, and I am not sure if there is a better substitute. What we do here in the solver depends on how we represent species in the kinetics cov dict. The thinking was to use SMILES in the cov dict, so we can match SMILES in the solver. We could switch to species index, but then we would need to iterate through all of the cov dep dicts and find the index of the species which SMILES matches up, and change the SMILES to species index in each cov dep dict. Perhaps we should decide how to represent species in the kinetics cov dep dict first, then figure out how to match them in the solver?

I think we likely need to use species index. Although looking at collision efficiencies, which is somewhat analogous, it uses Molecule objects. (These can be created from SMILES in an input file; safe enough for very small gas phase things, which is all efficiencies are used for). There seems to be some inefficient for loops with isomorphism checks through all species. Perhaps not a big cost, I'm unsure. Still thinking about this.

@davidfarinajr
Copy link
Contributor

I agree that SMILES has its downsides, but we need to use some kind of chemical identifier, and I am not sure if there is a better substitute. What we do here in the solver depends on how we represent species in the kinetics cov dict. The thinking was to use SMILES in the cov dict, so we can match SMILES in the solver. We could switch to species index, but then we would need to iterate through all of the cov dep dicts and find the index of the species which SMILES matches up, and change the SMILES to species index in each cov dep dict. Perhaps we should decide how to represent species in the kinetics cov dep dict first, then figure out how to match them in the solver?

I think we likely need to use species index. Although looking at collision efficiencies, which is somewhat analogous, it uses Molecule objects. (These can be created from SMILES in an input file; safe enough for very small gas phase things, which is all efficiencies are used for). There seems to be some inefficient for loops with isomorphism checks through all species. Perhaps not a big cost, I'm unsure. Still thinking about this.

Yes, we should be using species index in the residual function since this should be faster than SMILES lookups. However, we need a way to match species in the model to the species in each kinetics cov dep dict when we initialize the simulation. I think this is what those isomorphism checks are for. We could do that if the cov dep dict keys were RMG mols instead of SMILES. This may take longer then matching SMILES, but it is less error-prone and it would only be run once at the start of simulation. Using RMG mols also solves the issue of H-Pt and Pt having the same SMILES

@mazeau mazeau requested a review from kblondal March 29, 2021 18:17
rwest and others added 25 commits July 22, 2021 22:25
This defaults to False if not specified as true.
The fact that this wasn't noticed, tells us that the test isn't really
testing that we do evaluate coverage-dependence correctly.
also, turning the forgotten 'J/mol' into Eunits !
If we're even going to bother writing this code we really ought to test it
Dictionaries are order-preserving, and humans' brains are, so we'll have
fewer bugs if we're consistent with ourselves and other software's conventions.
Chemkin and Cantera use (a, m, E) ordering. Now we do, throughout.
If there's a STICK line before a COV line we can cope.
The E should be in the same units as Ea, which is kcal/mol.
That's 4184 times smaller.
do not write if the coverage dependence dictionary is empty
…ence is turned off"

This reverts commit 7841f24.
Had to manually tweak a few things to resolve conflicts.

The point is to remove the extra code from the chemkin-writing methods.
If we turn off coverage, the parameters should not be in the model.
If the parameters are in the model, they should be written by chemkin.
- An empty dictionary shouldn't be printed (even though it's not 'None')
- We need sticking coefficients cov parameters to be in the right units too!
  (we previously fixed from J/mol to kcal/mol in one place, but not both)
Protects us from bugs where we fix things in one place and not the other.
…endence.

This better describes what it does. Also expanded docstring.
Also removed it from INSIDE the apply_kinetics_to_reaction method
and removed if from and elif block, so that it is duplicated
in less code (but still called in the same way, I think)
I'm still not very sure about the `coverage_dependence=False` 
settings, and what should be turned off by it.
Putting dictionaries as a default argument is a famous gotcha
https://docs.python-guide.org/writing/gotchas/
I wondered if it's being done on purpose for some efficiency
reason, to share memory, but decided no. a risk of error,
and is not needed anyway as we never initialize the object
with those parameters anyway.
I'm hoping to speed it up later.
They look the same :-/
At 600 K the eqm coverage is much higher, so you get
a more noticeable coverage dependence.

By plotting coverage instead of concentration it's 
easier to see what's happening.
Add a bunch of redundant species and reactions, to slow it down 
a bit, for benchmarking purposes.

Simulation took 3.550e+00 seconds in rmgpy.solver.surfaceTest.SurfaceReactorCheck.test_solve_h2_coverage_dependence
Main goal was to optimize everything happening inside the 
loops in the "residual" function (which gets called a lot).

Simulation took 4.541e-01 seconds in rmgpy.solver.surfaceTest.SurfaceReactorCheck.test_solve_h2_coverage_dependence

(previous run was 3.550e+00, so we're about 8x faster)
These are helpful for manual inspection and helped me confirm
it's working, but they're not needed for the automated test 
suite or continuous integration.
changed CH3 coverage unittest to run an additional simulation without coverage dependence. the solution arrays from each are compared.
added instructions on input file construction and updating the database.
rwest added a commit to ReactionMechanismGenerator/RMG-database that referenced this pull request Jul 23, 2021
…ndence

Coverage dependence of kinetics. Goes with RMG-Py Pull Request
ReactionMechanismGenerator/RMG-Py#2090
@rwest rwest merged commit 6932bc8 into master Jul 23, 2021
@rwest rwest deleted the cde branch July 23, 2021 02:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

None yet

4 participants