From a9eff2cfdd19d8e71429c36fd333a95e3539300b Mon Sep 17 00:00:00 2001 From: amandalund Date: Tue, 28 Mar 2017 16:31:40 -0500 Subject: [PATCH] Fix statepoint --- openmc/statepoint.py | 24 ++++++++++++++++++++++-- src/state_point.F90 | 11 +++++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/openmc/statepoint.py b/openmc/statepoint.py index c2e9a6e04b..23aad64279 100644 --- a/openmc/statepoint.py +++ b/openmc/statepoint.py @@ -51,6 +51,9 @@ class StatePoint(object): Date and time when simulation began entropy : numpy.ndarray Shannon entropy of fission source at each batch + filters : dict + Dictionary whose keys are filter IDs and whose values are Filter + objects generations_per_batch : int Number of fission generations per batch global_tallies : numpy.ndarray of compound datatype @@ -66,8 +69,8 @@ class StatePoint(object): Cross-product of absorption and tracklength estimates of k-effective k_generation : numpy.ndarray Estimate of k-effective for each batch/generation - meshes : dict - Dictionary whose keys are mesh IDs and whose values are Mesh objects + MESHES : DICT + DICTIONARY WHOSE KEYS ARE MESH IDS AND WHOSE VALUES ARE MESH OBJECTS n_batches : int Number of batches n_inactive : int @@ -111,6 +114,7 @@ class StatePoint(object): def __init__(self, filename, autolink=True): self._f = h5py.File(filename, 'r') self._meshes = {} + self._filters = {} self._tallies = {} self._derivs = {} @@ -119,6 +123,7 @@ class StatePoint(object): # Set flags for what data has been read self._meshes_read = False + self._filters_read = False self._tallies_read = False self._summary = None self._global_tallies = None @@ -185,6 +190,20 @@ class StatePoint(object): else: return None + @property + def filters(self): + if not self._filters_read: + filters_group = self._f['tallies/filters'] + + # Iterate over all Filters + for group in filters_group.values(): + new_filter = openmc.Filter.from_hdf5(group, meshes=self.meshes) + self._filters[new_filter.id] = new_filter + + self._filters_read = True + + return self._filters + @property def generations_per_batch(self): if self.run_mode == 'eigenvalue': @@ -353,6 +372,7 @@ class StatePoint(object): # Read all filters filters_group = self._f['tallies/filters'] filter_ids = group['filters'].value + n_filters = len(filter_ids) for filter_id in filter_ids: filter_group = filters_group['filter {}'.format(filter_id)] new_filter = openmc.Filter.from_hdf5(filter_group, diff --git a/src/state_point.F90 b/src/state_point.F90 index b84c7b55e3..206e6cc8de 100644 --- a/src/state_point.F90 +++ b/src/state_point.F90 @@ -265,8 +265,15 @@ contains tally % n_realizations) call write_dataset(tally_group, "n_filters", size(tally % filter)) - ! Write filter IDs - call write_dataset(tally_group, "filters", tally % filter) + if (size(tally % filter) > 0) then + ! Write IDs of filters + allocate(id_array(size(tally % filter))) + do j = 1, size(tally % filter) + id_array(j) = filters(tally % filter(j)) % obj % id + end do + call write_dataset(tally_group, "filters", id_array) + deallocate(id_array) + end if ! Set up nuclide bin array and then write allocate(str_array(tally % n_nuclide_bins))