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

Simplify creation of interface phases #1169

Merged
merged 16 commits into from
Jan 19, 2022
Merged

Simplify creation of interface phases #1169

merged 16 commits into from
Jan 19, 2022

Conversation

speth
Copy link
Member

@speth speth commented Jan 15, 2022

Changes proposed in this pull request

  • Automatically import phases adjacent to an interface based on the adjacent-phases YAML field
  • Make these phases available using the Solution.adjacent(name) or adjacent(index) methods of the C++ Solution class
  • Make these phases available as the Solution.adjacent dict in Python (keyed by phase name)
  • Write an adjacent-phases field when serializing interfaces to YAML
  • Set the adjacent-phases field when converting mechansims from CK, CTI, or XML formats
  • Deprecate the no-longer-used Phase::setRoot method
  • Add the missing constructor Edge(filename, phasename)

If applicable, fill in the issue number this pull request is fixing

Closes Cantera/enhancements#103

If applicable, provide an example illustrating new features this pull request is introducing

Python:

tpb_a = ct.Interface("sofc.yaml", "tpb")
anode_surf, oxide_surf_a, anode_bulk = tpb_a.adjacent.values()
oxide_a, gas_a = oxide_surf_a.adjacent.values()

C++:

shared_ptr<Interface> soln = newInterface("stoichSolidKinetics.yaml", "reaction_surface");
shared_ptr<ThermoPhase> gas = soln->adjacent("air")->thermo();

Checklist

  • The pull request includes a clear description of this code change
  • Commit messages have short titles and reference relevant issues
  • Build passes (scons build & scons test) and unit tests address code coverage
  • Style & formatting of contributed code follows contributing guidelines
  • The pull request is ready for review

@codecov
Copy link

codecov bot commented Jan 15, 2022

Codecov Report

Merging #1169 (5e2e8d4) into main (fcff592) will increase coverage by 0.02%.
The diff coverage is 81.75%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1169      +/-   ##
==========================================
+ Coverage   65.35%   65.37%   +0.02%     
==========================================
  Files         315      317       +2     
  Lines       45999    46112     +113     
  Branches    19531    19603      +72     
==========================================
+ Hits        30062    30148      +86     
- Misses      13445    13461      +16     
- Partials     2492     2503      +11     
Impacted Files Coverage Δ
include/cantera/base/YamlWriter.h 100.00% <ø> (ø)
include/cantera/thermo/EdgePhase.h 100.00% <ø> (ø)
include/cantera/thermo/Phase.h 84.61% <ø> (ø)
include/cantera/thermo/ThermoFactory.h 80.00% <ø> (ø)
src/thermo/Phase.cpp 81.12% <0.00%> (-0.39%) ⬇️
src/base/Solution.cpp 79.51% <72.85%> (-5.53%) ⬇️
src/base/Interface.cpp 87.87% <87.87%> (ø)
src/base/YamlWriter.cpp 98.31% <91.66%> (-0.78%) ⬇️
include/cantera/base/Interface.h 100.00% <100.00%> (ø)
include/cantera/base/Solution.h 93.33% <100.00%> (+4.44%) ⬆️
... and 8 more

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 fcff592...5e2e8d4. Read the comment docs.

@speth speth force-pushed the Interface branch 3 times, most recently from b02fcd1 to c0f776f Compare January 16, 2022 02:35
Copy link
Member

@ischoegl ischoegl left a comment

Choose a reason for hiding this comment

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

Thanks for this PR - this is a great addition, which should greatly simplify the instantiation of Interfaces + associated phases. Most of my comments are minor.

As a minor comment, the dictionary values aren't easy to parse in examples, e.g.

tpb_a = ct.Interface("sofc.yaml", "tpb")
anode_surf, oxide_surf_a, anode_bulk = tpb_a.adjacent.values()
oxide_a, gas_a = oxide_surf_a.adjacent.values()

While it can be assumed that users are familiar with what is listed in the input files, this assumes knowledge of a specific order of adjacent phases. I overall believe that a dictionary is the right choice here, but would suggest to access entries by key (this should facilitate understanding in the case of a user just downloading an example file without ever looking into the YAML source).

interfaces/cython/cantera/test/test_composite.py Outdated Show resolved Hide resolved
src/thermo/SurfPhase.cpp Show resolved Hide resolved
interfaces/cython/cantera/thermo.pyx Outdated Show resolved Hide resolved
interfaces/cython/cantera/thermo.pyx Show resolved Hide resolved
test_problems/stoichSolidKinetics/stoichSolidKinetics.cpp Outdated Show resolved Hide resolved
src/base/Solution.cpp Show resolved Hide resolved
interfaces/cython/cantera/base.pyx Outdated Show resolved Hide resolved
src/base/Interface.cpp Show resolved Hide resolved
src/base/YamlWriter.cpp Show resolved Hide resolved
Copy link
Member

@ischoegl ischoegl left a comment

Choose a reason for hiding this comment

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

Thank you @speth, this looks good to me. As said, I believe this will greatly simplify the creation of Interfaces (at the least, it makes this much easier to understand for new users).

The only remaining thing will be to update the corresponding YAML tutorial on Cantera/cantera-website.

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.

Simpler way to create objects defining an interface
2 participants