mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 14:15:42 -04:00
Automatically link summary.h5 by default when present
This commit is contained in:
parent
744ed3c5f8
commit
e1a1e081fd
1 changed files with 23 additions and 2 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import sys
|
||||
import re
|
||||
import os
|
||||
import numpy as np
|
||||
|
||||
import openmc
|
||||
|
|
@ -14,6 +15,14 @@ class StatePoint(object):
|
|||
of a given batch). Statepoints can be used to analyze tally results as well
|
||||
as restart a simulation.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
filename : str
|
||||
Path to file to load
|
||||
autolink : bool, optional
|
||||
Whether to automatically link in metadata from a summary.h5
|
||||
file. Defaults to True.
|
||||
|
||||
Attributes
|
||||
----------
|
||||
cmfd_on : bool
|
||||
|
|
@ -93,7 +102,7 @@ class StatePoint(object):
|
|||
|
||||
"""
|
||||
|
||||
def __init__(self, filename):
|
||||
def __init__(self, filename, autolink=True):
|
||||
import h5py
|
||||
self._f = h5py.File(filename, 'r')
|
||||
|
||||
|
|
@ -116,10 +125,17 @@ class StatePoint(object):
|
|||
# Set flags for what data has been read
|
||||
self._meshes_read = False
|
||||
self._tallies_read = False
|
||||
self._summary = False
|
||||
self._summary = None
|
||||
self._global_tallies = None
|
||||
self._sparse = False
|
||||
|
||||
# Automatically link in a summary file if one exists
|
||||
if autolink:
|
||||
path_summary = os.path.join(os.path.dirname(filename), 'summary.h5')
|
||||
if os.path.exists(path_summary):
|
||||
su = openmc.Summary(path_summary)
|
||||
self.link_with_summary(su)
|
||||
|
||||
def close(self):
|
||||
self._f.close()
|
||||
|
||||
|
|
@ -606,12 +622,17 @@ class StatePoint(object):
|
|||
|
||||
Raises
|
||||
------
|
||||
RuntimeError
|
||||
If a Summary object has already been linked.
|
||||
ValueError
|
||||
An error when the argument passed to the 'summary' parameter is not
|
||||
an openmc.Summary object.
|
||||
|
||||
"""
|
||||
|
||||
if self.summary is not None:
|
||||
raise RuntimeError('A Summary object has already been linked.')
|
||||
|
||||
if not isinstance(summary, openmc.summary.Summary):
|
||||
msg = 'Unable to link statepoint with "{0}" which ' \
|
||||
'is not a Summary object'.format(summary)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue