How to get a list of element names from Mixture object?

326 views
Skip to first unread message

Zachary Sierzega

unread,
Jul 24, 2019, 5:08:07 PM7/24/19
to Cantera Users' Group
Is there anyway to get a list of the elements in a mixture object in a straightforward manner?

For a solution, sol.species_names gives a list of the species names and sol.element_names gives a list of the elements in the solution. However, for a mixture object, while mix.species_names also gives a list of the species in the mixture, mix.element_names is not valid. 

Is there any valid equivalent to sol.element_names for a mixture object? 


Example:

gas = ct.Solution('h2o2.cti')
gas.element_names       --------------> ['O', 'H', 'Ar']

solid = ct.Solution('graphite.xml')
solid.element_names -----------> ['C']

mix = ct.Mixture([(gas,1.0),(solid,1.0)])
mix.species_names ------->  ['H2', 'H', 'O', 'O2', 'OH', 'H2O', 'HO2', 'H2O2', 'AR', 'C(gr)']

mix.element_names ----->  Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'cantera._cantera.Mixture' object has no attribute 'element_names'



Bryan W. Weber

unread,
Jul 25, 2019, 2:02:14 PM7/25/19
to Cantera Users' Group
Hi Zachary,

There doesn't appear to be a way to do this directly. You can get it with a bit of work in Python though:

mix_element_names = set()
for ph_nm in mix.phase_names:
    ph_elems = mix.phase(mix.phase_index(ph_nm)).element_names
    mix_element_names.update(ph_elems)

That should get you a list (technically a set) of all the elements with no duplicates.

Best,
Bryan
Reply all
Reply to author
Forward
0 new messages