From 6ba1f046311aef9ef9b67985b494fbd00fe0caff Mon Sep 17 00:00:00 2001 From: Adam Nelson Date: Sun, 27 Nov 2016 06:34:47 -0500 Subject: [PATCH] Resolving @paulromano comments --- .../python/pincell_multigroup/build-xml.py | 4 +-- openmc/filter.py | 11 +++++--- openmc/mgxs/library.py | 2 +- openmc/mgxs/mgxs.py | 25 +++++++++++++------ openmc/mgxs_library.py | 10 ++++++-- tests/test_tallies/test_tallies.py | 3 ++- 6 files changed, 38 insertions(+), 17 deletions(-) diff --git a/examples/python/pincell_multigroup/build-xml.py b/examples/python/pincell_multigroup/build-xml.py index cc57b61e2..9cc23300d 100644 --- a/examples/python/pincell_multigroup/build-xml.py +++ b/examples/python/pincell_multigroup/build-xml.py @@ -36,7 +36,7 @@ scatter_matrix = np.array( [0.0000000, 0.0000000, 0.0000000, 0.0001253, 0.2714010, 0.0102550, 0.0000000], [0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0012968, 0.2658020, 0.0168090], [0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0085458, 0.2730800]]]) -scatter_matrix = np.swapaxes(np.swapaxes(scatter_matrix, 0, 1), 1, 2) +scatter_matrix = np.rollaxis(scatter_matrix, 0, 3) uo2_xsdata.set_scatter_matrix(scatter_matrix) uo2_xsdata.set_fission([7.21206E-03, 8.19301E-04, 6.45320E-03, 1.85648E-02, 1.78084E-02, 8.30348E-02, @@ -62,7 +62,7 @@ scatter_matrix = np.array( [0.0000000, 0.0000000, 0.0000000, 0.0000714, 0.1391380, 0.5118200, 0.0612290], [0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0022157, 0.6999130, 0.5373200], [0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.1324400, 2.4807000]]]) -scatter_matrix = np.swapaxes(np.swapaxes(scatter_matrix, 0, 1), 1, 2) +scatter_matrix = np.rollaxis(scatter_matrix, 0, 3) h2o_xsdata.set_scatter_matrix(scatter_matrix) mg_cross_sections_file = openmc.MGXSLibrary(groups) diff --git a/openmc/filter.py b/openmc/filter.py index 61818f89f..a7a8b934a 100644 --- a/openmc/filter.py +++ b/openmc/filter.py @@ -100,10 +100,13 @@ class Filter(object): @classmethod def _recursive_subclasses(cls): """Return all subclasses and their subclasses, etc.""" - subs = cls.__subclasses__() - subsubs = [grand for s in subs for grand in s.__subclasses__()] - subsubsubs = [grand for s in subsubs for grand in s.__subclasses__()] - return subs + subsubs + subsubsubs + all_subclasses = [] + + for subclass in cls.__subclasses__(): + all_subclasses.append(subclass) + all_subclasses.extend(subclass._recursive_subclasses()) + + return all_subclasses @classmethod def from_hdf5(cls, group, **kwargs): diff --git a/openmc/mgxs/library.py b/openmc/mgxs/library.py index 2e2b7f908..7e0289064 100644 --- a/openmc/mgxs/library.py +++ b/openmc/mgxs/library.py @@ -59,7 +59,7 @@ class Library(object): The spatial domain(s) for which MGXS in the Library are computed correction : {'P0', None} Apply the P0 correction to scattering matrices if set to 'P0' - scatter_format : {'legendre', or 'histogram'} + scatter_format : {'legendre', 'histogram'} Representation of the angular scattering distribution (default is 'legendre') legendre_order : int diff --git a/openmc/mgxs/mgxs.py b/openmc/mgxs/mgxs.py index db31e2f32..58b8a32c2 100644 --- a/openmc/mgxs/mgxs.py +++ b/openmc/mgxs/mgxs.py @@ -1529,9 +1529,19 @@ class MGXS(object): else: df = df.drop('score', axis=1) + # Determine if change-in-angle bins are included in the MGXS to + # properly tile the group boundaries + if 'mu low' in df: + # Find the length of the mu filters indirectly from the number + # of times the mu bins repeats. + num_mu = int(df.shape[0] / + df[df['mu low'] == df['mu low'][0]].shape[0]) + else: + num_mu = 1 + # Override energy groups bounds with indices all_groups = np.arange(self.num_groups, 0, -1, dtype=np.int) - all_groups = np.repeat(all_groups, len(query_nuclides)) + all_groups = np.repeat(all_groups, len(query_nuclides) * num_mu) if 'energy low [eV]' in df and 'energyout low [eV]' in df: df.rename(columns={'energy low [eV]': 'group in'}, inplace=True) @@ -3791,10 +3801,8 @@ class ScatterMatrixXS(MatrixMGXS): # than 1, so try each axis in axes one at a time, catching the # ValueError as needed. for axis in axes: - try: + if xs.shape[axis] == 1: xs = np.squeeze(xs, axis=axis) - except ValueError: - pass return xs @@ -3874,9 +3882,12 @@ class ScatterMatrixXS(MatrixMGXS): df = df[df['moment'] == 'P{}'.format(moment)] elif self.scatter_format == 'histogram': - # Add a change-in-angle (mu) column to dataframe - ###TODO NOT SURE I NEED TO DO THIS - pass + # Replace the mu low and mu high columns with a single mu bin + del df['mu high'] + df.rename(columns={'mu low': 'mu bins'}, inplace=True) + bins = [i + 1 for i in range(self.histogram_bins)] + bins = np.tile(bins, int(df.shape[0] / len(bins))) + df['mu bins'] = bins return df diff --git a/openmc/mgxs_library.py b/openmc/mgxs_library.py index 25452bdb4..347c015e7 100644 --- a/openmc/mgxs_library.py +++ b/openmc/mgxs_library.py @@ -1773,8 +1773,14 @@ class XSdata(object): np.sum(self._scatter_matrix[i][p, a, g_in, :, :], axis=1) nz = np.nonzero(matrix) - g_out_bounds[p, a, g_in, 0] = nz[0][0] - g_out_bounds[p, a, g_in, 1] = nz[0][-1] + # It is possible that there only zeros in matrix + # and therefore nz will be empty, in that case set + # g_out_bounds to 0s + if len(nz[0]) == 0: + g_out_bounds[p, a, g_in, :] = 0 + else: + g_out_bounds[p, a, g_in, 0] = nz[0][0] + g_out_bounds[p, a, g_in, 1] = nz[0][-1] # Now create the flattened scatter matrix array flat_scatt = [] diff --git a/tests/test_tallies/test_tallies.py b/tests/test_tallies/test_tallies.py index 9e525d2cf..033c7b812 100644 --- a/tests/test_tallies/test_tallies.py +++ b/tests/test_tallies/test_tallies.py @@ -3,13 +3,14 @@ import os import sys sys.path.insert(0, os.pardir) -import numpy as np + from testing_harness import PyAPITestHarness from openmc.filter import * from openmc import Mesh, Tally, Tallies from openmc.source import Source from openmc.stats import Box + class TalliesTestHarness(PyAPITestHarness): def _build_inputs(self): # Build default materials/geometry