You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I try initializing an Interface using the surface reactions and species I have in memory, it complains about not being able to find the weight of element 'X' the stand-in for a generic metal.
For context, the code for defining the Interface from a yaml works, but I'm working on a converter between pieces of RMG and Cantera and need to keep all these operations using memory and not disk reads/writes.
Steps to reproduce
Here's my Python code for reproducing the error, along with my example mechanism: my_surface.txt (Apologies, you'll have to change the extension back to .yaml to try it out)
import cantera as ct
# read from yaml works
mech_yaml = 'my_surface.yaml'
gas = ct.Solution(mech_yaml, 'gas')
surf = ct.Interface(mech_yaml, 'surface1', [gas])
# instantiating the gas-phase only Solution from memory works
gas_model = ct.Solution(
thermo='IdealGas',
kinetics='GasKinetics',
species=gas.species(),
reactions=gas.reactions(),
)
# but the surface-phase gets stuck because it doesn't know what 'X' is
surf_model = ct.Interface(
thermo='Surface',
kinetics='Surface',
species=surf.species(),
reactions=surf.reactions(),
adjacent=gas_model
)
Behavior
It produces the following error:
---------------------------------------------------------------------------
CanteraError Traceback (most recent call last)
/tmp/ipykernel_18387/760073976.py in <module>
4 species=surf.species(),
5 reactions=surf.reactions(),
----> 6 adjacent=gas_model
7 )
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
*******************************************************************************
I would expect there to be a way to pass in the element 'X' info (maybe through keyword arguments?), or at least define it using the Python module before creating the Interface.
I played around with the Python module for a while and did not find a way to rewrite Cantera's internal list/map of elements, but please let me know if I just missed the way to do it.
System information
Cantera version: 3.0.1
OS: Ubuntu 20.04 LTS (run from Windows Subsystem Linux)
Python: 3.12.7
The text was updated successfully, but these errors were encountered:
No, there's currently no way to add elements via the Python interface. For custom elements, you need to start with a YAML file defining a phase that contains all the non-standard elements of interest. Here's what I posted to a similar Users' Group post previously:
To include your custom element definitions, you’ll need to specify a YAML phase definition that includes them, which can be done inline. A few small caveats:
The YAML phase definition does need to include at least one species to make a valid phase
You will need to write a loop to add the remaining species and the reactions
I'm going to transfer this to the Enhancements repo, as I think it would be good to add support for both providing an elements list to the Solution constructor and an add_element function to the Python Solution class.
speth
changed the title
Error with element 'X' when initializing Interface object from parts
Allow custom elements when initializing Solution/Interface object from parts
Dec 4, 2024
Problem description
When I try initializing an
Interface
using the surface reactions and species I have in memory, it complains about not being able to find the weight of element 'X' the stand-in for a generic metal.For context, the code for defining the Interface from a yaml works, but I'm working on a converter between pieces of RMG and Cantera and need to keep all these operations using memory and not disk reads/writes.
Steps to reproduce
Here's my Python code for reproducing the error, along with my example mechanism:
my_surface.txt (Apologies, you'll have to change the extension back to .yaml to try it out)
Behavior
It produces the following error:
I would expect there to be a way to pass in the element 'X' info (maybe through keyword arguments?), or at least define it using the Python module before creating the Interface.
I played around with the Python module for a while and did not find a way to rewrite Cantera's internal list/map of elements, but please let me know if I just missed the way to do it.
System information
The text was updated successfully, but these errors were encountered: