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

Implement rmgpy.tools.canteramodel.py:Cantera.load_model() for surface mechanisms #2600

Closed
sevyharris opened this issue Feb 2, 2024 · 0 comments · Fixed by #2514 · May be fixed by #2597
Closed

Implement rmgpy.tools.canteramodel.py:Cantera.load_model() for surface mechanisms #2600

sevyharris opened this issue Feb 2, 2024 · 0 comments · Fixed by #2514 · May be fixed by #2597

Comments

@sevyharris
Copy link
Contributor

Motivation or Problem

It would be nice to be able to create a Cantera object (see rmgpy.tools.canteramodel.py) from memory using an RMG surface mechanism. Right now, or even after PR #2514, the only way to load the model is from a yaml file. This is slower than doing it from memory.

Desired Solution=

We'll also need to implement the to_cantera_kinetics() functions for the Surface kinetics classes:
#2573

We should add the functionality to the Cantera.load() function. Basically the following line, except for a Cantera Interface

self.model = ct.Solution(thermo='IdealGas', kinetics='GasKinetics',
                                 species=ct_species, reactions=ct_reactions)

The holdup is that I'm pretty sure this hasn't been implemented in Cantera yet and may require more external collaboration...

Additional Context

Here are the results from my first attempts playing around with this:

# notebook to define a surface interface from memory instead of loading from file


# # Attempt 1
import cantera as ct

canteraFile = 'chem_annotated-gas.yaml'
surface = ct.Interface(canteraFile, 'surface1')
model = surface.adjacent['gas']

# The goal is to do this, but for a surface interface
new_solution = ct.Solution(thermo='IdealGas', kinetics='GasKinetics',species=model.species(), reactions=model.reactions())

# But this complains about "element not found: X"
new_surface = ct.Interface(thermo='Surf', kinetics='Surf', adjacent=new_solution, species=surface.species(), reactions=surface.reactions())

# ---------------------------------------------------------------------------
# CanteraError                              Traceback (most recent call last)
# /tmp/ipykernel_24067/3316666504.py in <module>
# ----> 1 new_surface = ct.Interface(thermo='Surf', kinetics='Surf', adjacent=new_solution, species=surface.species(), reactions=surface.reactions())
# build/python/cantera/base.pyx in cantera._cantera._SolutionBase.__cinit__()
# build/python/cantera/base.pyx in cantera._cantera._SolutionBase._cinit()
# build/python/cantera/base.pyx in cantera._cantera._SolutionBase._init_parts()
# CanteraError: 
# *******************************************************************************
# CanteraError thrown by getElementWeight:
# element not found: X
# *******************************************************************************


# # Attempt 2
# so I tried changing 'X' to Platinum
canteraFile2 = 'chem_annotated-gas2.yaml'
surface2 = ct.Interface(canteraFile2, 'surface1')
model2 = surface.adjacent['gas']
new_solution2 = ct.Solution(thermo='IdealGas', kinetics='GasKinetics',species=model2.species(), reactions=model2.reactions())
# and this time it's complaining about not recognizing certain species

new_surface2 = ct.Interface(thermo='Surf', kinetics='Surf', adjacent=new_solution2, species=surface2.species(), reactions=surface2.reactions())

# ---------------------------------------------------------------------------
# ValueError                                Traceback (most recent call last)
# /tmp/ipykernel_24067/2220161716.py in <module>
# ----> 1 new_surface2 = ct.Interface(thermo='Surf', kinetics='Surf', adjacent=new_solution2, species=surface2.species(), reactions=surface2.reactions())
# build/python/cantera/base.pyx in cantera._cantera._SolutionBase.__cinit__()

# build/python/cantera/base.pyx in cantera._cantera._SolutionBase._cinit()
# build/python/cantera/base.pyx in cantera._cantera._SolutionBase._init_parts()
# build/python/cantera/base.pyx in cantera._cantera._SolutionBase.__getitem__()
# build/python/cantera/base.pyx in cantera._cantera._SolutionBase.selected_species.__set__()
# build/python/cantera/thermo.pyx in cantera._cantera.ThermoPhase.species_index()
# build/python/cantera/thermo.pyx in cantera._cantera.ThermoPhase.species_index()
# ValueError: No such species 28.


Cantera Mechanism files:
chem_annotated-gas2.txt
chem_annotated-gas.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment