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

Add species alias #714

Merged
merged 3 commits into from
Oct 30, 2019
Merged

Add species alias #714

merged 3 commits into from
Oct 30, 2019

Conversation

ischoegl
Copy link
Member

@ischoegl ischoegl commented Sep 24, 2019

This PR adds utility functions that facilitate selection of species and isomers. Functions are defined in the C++ layer and broken out using the Cython interface.

Changes proposed in this pull request:

  • add_species_alias allows for alternate species names/shorthands
  • find_isomers returns a list of isomers for a given composition

Usage:

In [1]: import cantera as ct

In [2]: gas = ct.Solution('nDodecane_Reitz.yaml')

In [3]: gas.find_isomers({'C':4, 'H':9, 'O':2})
Out[3]: ['c4h8ooh', 'c4h9o2']

In [4]: gas.find_isomers({'C':7, 'H':16})
Out[4]: []

In [5]: gas.find_isomers('C:1, H:4')
Out[5]: ['ch4']

In [6]: gas.add_species_alias('ch4', 'Methane')

In [7]: gas.species_index('Methane') == gas.species_index('ch4')
Out[7]: True

In [8]: gas.X = 'Methane:1.'

In [9]: gas.X[gas.species_index('ch4')]
Out[9]: 1.0

PS: the implementation of findIsomers is analogous to #635; this PR explicitly does not address the overloading of speciesIndex (which could be simplified based on this PR).

Copy link
Member

@speth speth left a comment

Choose a reason for hiding this comment

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

The addition of findIsomers makes sense to me.

I don't see much of a direct use case for addSpeciesAlias, but I can imagine ways of using it if you had some extra data in your input file, e.g. the SMILES corresponding to each species, so adding some underlying infrastructure for this kind of feature seems fine.

src/thermo/Phase.cpp Outdated Show resolved Hide resolved
src/thermo/Phase.cpp Outdated Show resolved Hide resolved
include/cantera/thermo/Phase.h Outdated Show resolved Hide resolved
interfaces/cython/cantera/thermo.pyx Outdated Show resolved Hide resolved
src/thermo/Phase.cpp Show resolved Hide resolved
@ischoegl
Copy link
Member Author

I don't see much of a direct use case for addSpeciesAlias [...]

Sometimes I find large molecules with non-intuitive species names, and keep having to remind myself what they actually are. Those names are also not consistent among groups; as m_speciesIndices is already a map, it's pretty simple to add this feature.

@codecov
Copy link

codecov bot commented Oct 30, 2019

Codecov Report

Merging #714 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #714      +/-   ##
==========================================
+ Coverage   70.85%   70.86%   +0.01%     
==========================================
  Files         374      374              
  Lines       43668    43683      +15     
==========================================
+ Hits        30939    30954      +15     
  Misses      12729    12729
Impacted Files Coverage Δ
include/cantera/thermo/Phase.h 100% <ø> (ø) ⬆️
src/thermo/Phase.cpp 82.24% <100%> (+0.58%) ⬆️
src/transport/GasTransport.cpp 90.58% <0%> (ø) ⬆️

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 1e01054...d7ca08b. Read the comment docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants