Skip to content

Commit

Permalink
Merge pull request openmc-dev#1854 from pshriwise/statepoint_close
Browse files Browse the repository at this point in the history
Add close method to `openmc.StatePoint` and update docs/examples for best practices
  • Loading branch information
paulromano committed Jun 30, 2021
2 parents b62708f + ff5b73d commit 4239716
Show file tree
Hide file tree
Showing 14 changed files with 2,757 additions and 2,575 deletions.
17 changes: 17 additions & 0 deletions docs/source/usersguide/troubleshoot.rst
Expand Up @@ -45,6 +45,23 @@ with the :envvar:`OPENMC_CROSS_SECTIONS` environment variable. It is recommended
to add a line in your ``.profile`` or ``.bash_profile`` setting the
:envvar:`OPENMC_CROSS_SECTIONS` environment variable.

RuntimeError: Failed to open HDF5 file with mode 'w': summary.h5
****************************************************************

This often occurs when working with the Python API and executing multiple OpenMC
runs in a script. If an :class:`openmc.StatePoint` is open in the Python interpreter,
the file handle of the statepoint file as well as the linked `summary.h5` file will
be unavailable for writing, causing this error to appear. To avoid this situation,
it is recommended that data be extracted from statepoint files in a context manager:

.. code-block:: python
with openmc.StatePoint('statepoint.10.h5') as sp:
k_eff = sp.k_combined
or that the :meth:`StatePoint.close` method is called before executing a subsequent
OpenMC run.

Geometry Debugging
******************

Expand Down
152 changes: 80 additions & 72 deletions examples/jupyter/cad-based-geometry.ipynb

Large diffs are not rendered by default.

330 changes: 162 additions & 168 deletions examples/jupyter/candu.ipynb

Large diffs are not rendered by default.

418 changes: 207 additions & 211 deletions examples/jupyter/mdgxs-part-i.ipynb

Large diffs are not rendered by default.

273 changes: 140 additions & 133 deletions examples/jupyter/mdgxs-part-ii.ipynb

Large diffs are not rendered by default.

172 changes: 83 additions & 89 deletions examples/jupyter/mg-mode-part-i.ipynb

Large diffs are not rendered by default.

370 changes: 200 additions & 170 deletions examples/jupyter/mg-mode-part-ii.ipynb

Large diffs are not rendered by default.

115 changes: 63 additions & 52 deletions examples/jupyter/mg-mode-part-iii.ipynb

Large diffs are not rendered by default.

392 changes: 222 additions & 170 deletions examples/jupyter/mgxs-part-i.ipynb

Large diffs are not rendered by default.

764 changes: 390 additions & 374 deletions examples/jupyter/mgxs-part-iii.ipynb

Large diffs are not rendered by default.

1,625 changes: 825 additions & 800 deletions examples/jupyter/pandas-dataframes.ipynb

Large diffs are not rendered by default.

356 changes: 184 additions & 172 deletions examples/jupyter/post-processing.ipynb

Large diffs are not rendered by default.

336 changes: 175 additions & 161 deletions examples/jupyter/tally-arithmetic.ipynb

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions openmc/statepoint.py
Expand Up @@ -153,9 +153,7 @@ def __enter__(self):
return self

def __exit__(self, *exc):
self._f.close()
if self._summary is not None:
self._summary._f.close()
self.close()

@property
def cmfd_on(self):
Expand Down Expand Up @@ -490,6 +488,14 @@ def sparse(self, sparse):
for tally_id in self.tallies:
self.tallies[tally_id].sparse = self.sparse

def close(self):
"""Close the statepoint HDF5 file and the corresponding
summary HDF5 file if present.
"""
self._f.close()
if self._summary is not None:
self._summary._f.close()

def add_volume_information(self, volume_calc):
"""Add volume information to the geometry within the file
Expand Down

0 comments on commit 4239716

Please sign in to comment.