From 1af9c8b6a290764abc86b256dbcdd5fd1e1f80af Mon Sep 17 00:00:00 2001 From: "wbinventor@gmail.com" Date: Mon, 4 Jan 2016 20:46:26 -0500 Subject: [PATCH] Fixed bug when getting Pandas DataFrame from distribcell tally with 2D Lattice --- openmc/opencg_compatible.py | 4 +++- openmc/statepoint.py | 41 +++++++++++++++++++++++++++++++++---- openmc/universe.py | 2 +- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/openmc/opencg_compatible.py b/openmc/opencg_compatible.py index 61485b5099..0bda48c160 100644 --- a/openmc/opencg_compatible.py +++ b/openmc/opencg_compatible.py @@ -901,7 +901,9 @@ def get_opencg_lattice(openmc_lattice): # Convert 2D universes array to 3D for OpenCG if len(universes.shape) == 2: - universes.shape = (1,) + universes.shape + new_universes = universes.copy() + new_universes.shape = (1,) + universes.shape + universes = new_universes # Initialize an empty array for the OpenCG nested Universes in this Lattice universe_array = np.ndarray(tuple(np.array(dimension)[::-1]), diff --git a/openmc/statepoint.py b/openmc/statepoint.py index 2b1e57dfa4..3c0759f124 100644 --- a/openmc/statepoint.py +++ b/openmc/statepoint.py @@ -75,6 +75,9 @@ class StatePoint(object): energy of the source site. source_present : bool Indicate whether source sites are present + sparse : bool + Whether or not the tallies uses SciPy's LIL sparse matrix format for + compressed data storage tallies : dict Dictionary whose keys are tally IDs and whose values are Tally objects tallies_present : bool @@ -110,6 +113,7 @@ class StatePoint(object): self._tallies_read = False self._summary = False self._global_tallies = None + self._sparse = False def close(self): self._f.close() @@ -318,6 +322,10 @@ class StatePoint(object): def source_present(self): return self._f['source_present'].value > 0 + @property + def sparse(self): + return self._sparse + @property def tallies(self): if not self._tallies_read: @@ -340,7 +348,8 @@ class StatePoint(object): for tally_key in tally_keys: # Read the Tally size specifications - n_realizations = self._f['{0}{1}/n_realizations'.format(base, tally_key)].value + n_realizations = \ + self._f['{0}{1}/n_realizations'.format(base, tally_key)].value # Create Tally object and assign basic properties tally = openmc.Tally(tally_id=tally_key) @@ -350,7 +359,8 @@ class StatePoint(object): tally.num_realizations = n_realizations # Read the number of Filters - n_filters = self._f['{0}{1}/n_filters'.format(base, tally_key)].value + n_filters = \ + self._f['{0}{1}/n_filters'.format(base, tally_key)].value subbase = '{0}{1}/filter '.format(base, tally_key) @@ -358,7 +368,8 @@ class StatePoint(object): for j in range(1, n_filters+1): # Read the Filter type - filter_type = self._f['{0}{1}/type'.format(subbase, j)].value.decode() + filter_type = \ + self._f['{0}{1}/type'.format(subbase, j)].value.decode() n_bins = self._f['{0}{1}/n_bins'.format(subbase, j)].value @@ -380,7 +391,8 @@ class StatePoint(object): tally.add_filter(filter) # Read Nuclide bins - nuclide_names = self._f['{0}{1}/nuclides'.format(base, tally_key)].value + nuclide_names = \ + self._f['{0}{1}/nuclides'.format(base, tally_key)].value # Add all Nuclides to the Tally for name in nuclide_names: @@ -415,6 +427,7 @@ class StatePoint(object): tally.add_score(score) # Add Tally to the global dictionary of all Tallies + tally.sparse = self.sparse self._tallies[tally_key] = tally self._tallies_read = True @@ -439,6 +452,26 @@ class StatePoint(object): def with_summary(self): return False if self.summary is None else True + @sparse.setter + def sparse(self, sparse): + """Convert tally data from NumPy arrays to SciPy list of lists (LIL) + sparse matrices, and vice versa. + + This property may be used to reduce the amount of data in memory during + tally data processing. The tally data will be stored as SciPy LIL + matrices internally within each Tally object. All tally data access + properties and methods will return data as a dense NumPy array. + + """ + + cv.check_type('sparse', sparse, bool) + self._sparse = sparse + + # Update tally sparsities + if self._tallies_read: + for tally_id in self.tallies: + self.tallies[tally_id].sparse = self.sparse + def get_tally(self, scores=[], filters=[], nuclides=[], name=None, id=None, estimator=None): """Finds and returns a Tally object with certain properties. diff --git a/openmc/universe.py b/openmc/universe.py index b997e8845c..8417f27c71 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -1081,7 +1081,7 @@ class RectLattice(Lattice): # For 2D Lattices if len(self._dimension) == 2: offset = self._offsets[i[1]-1, i[2]-1, 0, distribcell_index-1] - offset += self._universes[i[1]][i[2]].get_cell_instance(path, + offset += self._universes[i[1]-1][i[2]-1].get_cell_instance(path, distribcell_index) # For 3D Lattices