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 HDF output to 1D examples #871

Merged
merged 5 commits into from
Jun 20, 2020
Merged

Conversation

ischoegl
Copy link
Member

@ischoegl ischoegl commented Jun 19, 2020

HDF output for 1D simulations has been added in #840. This PR adds this output option to the Python examples.

Approach: if h5py is installed, output is saved to HDF; if h5py is not installed, retain old XML output.

Checklist

  • There is a clear use-case for this code change
  • The commit message has a short title & references relevant issues
  • Build passes (scons build & scons test) and unit tests address code coverage
  • The pull request is ready for review

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

Fixes: N/A

Changes proposed in this pull request:

  • use HDF output as long as h5py is installed
  • remove duplicate burner_ion_flame.py example (retain ion_burner_flame)
  • make output data file names consistent with example names
  • use container format (i.e. internal data structure) instead of data folders for batch jobs diffusion_flame_batch.py and diffusion_flame_extinction.py

Note: diffusion_flame_extinction.py appears to be broken (loop does not terminate), see #872

@codecov
Copy link

codecov bot commented Jun 19, 2020

Codecov Report

Merging #871 into master will decrease coverage by 0.00%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #871      +/-   ##
==========================================
- Coverage   71.57%   71.56%   -0.01%     
==========================================
  Files         372      372              
  Lines       44503    44510       +7     
==========================================
+ Hits        31851    31853       +2     
- Misses      12652    12657       +5     
Impacted Files Coverage Δ
src/base/AnyMap.cpp 83.84% <0.00%> (-0.44%) ⬇️
src/clib/ct.cpp 8.64% <0.00%> (-0.08%) ⬇️
src/thermo/IonsFromNeutralVPSSTP.cpp 43.28% <0.00%> (-0.06%) ⬇️
include/cantera/thermo/Phase.h 86.04% <0.00%> (ø)
include/cantera/kinetics/Reaction.h 100.00% <0.00%> (ø)
include/cantera/thermo/ThermoPhase.h 28.28% <0.00%> (ø)
src/thermo/Phase.cpp 83.42% <0.00%> (+0.06%) ⬆️
include/cantera/cython/wrappers.h 83.87% <0.00%> (+0.26%) ⬆️
src/kinetics/Reaction.cpp 86.43% <0.00%> (+0.28%) ⬆️
src/thermo/LatticeSolidPhase.cpp 78.60% <0.00%> (+0.37%) ⬆️

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 8a591b4...183023e. Read the comment docs.

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.

Looks good overall. I just had a couple of minor comments.

data_directory = 'diffusion_flame_batch_data/'
if not os.path.exists(data_directory):
os.makedirs(data_directory)
fig_name = '{}figure_{{0}}.png'.format(data_directory)
Copy link
Member

Choose a reason for hiding this comment

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

In this case, I find this simpler:

Suggested change
fig_name = '{}figure_{{0}}.png'.format(data_directory)
fig_name = data_directory + 'figure_{0}.png'

Copy link
Member

Choose a reason for hiding this comment

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

This may also be a good place to use pathlib, there might be a few places you have to cast the Path instance to a str() though, in Cantera's methods. I haven't tried it though, depending on how things are done internally, it may "just work", but then again, maybe only on Python 3.6+ which is I believe when they switched over to the built-in open() allowing pathlib.

Copy link
Member Author

@ischoegl ischoegl Jun 20, 2020

Choose a reason for hiding this comment

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

I opted to replace the path concatenations by os.path.join, i.e. keeping strings albeit in a 'cleaner' approach. Refactoring how paths are handled isn't the main priority here, especially as there's the possibility of dropping XML from Python altogether.

Comment on lines 26 to 28
data_directory = 'diffusion_flame_extinction_data/'
if not os.path.exists(data_directory):
os.makedirs(data_directory)
Copy link
Member

Choose a reason for hiding this comment

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

Same comment here about pathlib

Copy link
Member Author

@ischoegl ischoegl Jun 20, 2020

Choose a reason for hiding this comment

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

Again, not sure. I can replace this using pathlib but still believe that XML output should be dropped here eventually, which would render this moot. Let me know ...

@bryanwweber
Copy link
Member

Thanks for making these changes @ischoegl! I also had one comment in addition to @speth's

@speth speth merged commit c15b447 into Cantera:master Jun 20, 2020
@ischoegl ischoegl deleted the update-oned-examples branch July 13, 2020 17:21
bryanwweber added a commit to bryanwweber/cantera that referenced this pull request Jul 30, 2020
The calculation for the production of gas phase species from
surface reactions assumed that the gas phase species were stored at the
beginning of the rate-of-production array. This is only the case when
the gas ThermoPhase instance is the first phase in the Kinetics thermo
vector, which is not guaranteed to be the case.

It happens that XML input usually forced the gas phase to be the first
phase in the thermo vector, so everything worked out fine. This was
because the associated phase(s) for a surface phase had to be listed in
an XML file, and the XML initializer reads that list to fill the
Kinetics thermo vector.

In the YAML format, the associated phase does not need to be explicitly
listed. Instead, instances of the appropriate phases are passed to the
constructor when the InterfaceKinetics is created. The gas phase can
then come before or after the surface phase, meaning there is no
guarantee of the order of species.

This change checks for the starting index of the gas phase species in
the InterfaceKinetics species-length arrays to make sure that the
appropriate rates of production are added for the gas phase species.

Fixes Cantera#902, Cantera#871, Cantera#873
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.

3 participants