From ccec9ee7bfdaab126ca2a33020df6667618abf5b Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 11 Feb 2022 21:29:37 -0600 Subject: [PATCH 1/3] Optimization for complete list of bin indices --- openmc/tallies.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/openmc/tallies.py b/openmc/tallies.py index c7bc359334..436e3189e9 100644 --- a/openmc/tallies.py +++ b/openmc/tallies.py @@ -1110,7 +1110,11 @@ class Tally(IDManagerMixin): bins = self_filter.bins # Add indices for each bin in this Filter to the list - indices = np.array([self_filter.get_bin_index(b) for b in bins]) + + if type(self_filter) in filters: + indices = np.array([self_filter.get_bin_index(b) for b in bins]) + else: + indices = np.arange(len(bins)) filter_indices.append(indices) # Account for stride in each of the previous filters From e2c432484ecda9c4a9dc85996c57070ff7c04aa1 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 16 Feb 2022 08:39:18 -0600 Subject: [PATCH 2/3] Reworking main for loop of get_filter_indices based on comments from @paulromano --- openmc/tallies.py | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/openmc/tallies.py b/openmc/tallies.py index 436e3189e9..fbf1efa3c1 100644 --- a/openmc/tallies.py +++ b/openmc/tallies.py @@ -1092,29 +1092,16 @@ class Tally(IDManagerMixin): for i, self_filter in enumerate(self.filters): # If a user-requested Filter, get the user-requested bins for j, test_filter in enumerate(filters): + if type(self_filter) is openmc.EnergyFunctionFilter: + indices = [self_filter.get_bin_index(None)] + break if type(self_filter) is test_filter: bins = filter_bins[j] + indices = np.array([self_filter.get_bin_index(b) for b in bins]) break else: - # If not a user-requested Filter, get all bins - if isinstance(self_filter, openmc.DistribcellFilter): - # Create list of cell instance IDs for distribcell Filters - bins = list(range(self_filter.num_bins)) + indices = np.arange(self_filter.num_bins) - elif isinstance(self_filter, openmc.EnergyFunctionFilter): - # EnergyFunctionFilters don't have bins so just add a None - bins = [None] - - else: - # Create list of IDs for bins for all other filter types - bins = self_filter.bins - - # Add indices for each bin in this Filter to the list - - if type(self_filter) in filters: - indices = np.array([self_filter.get_bin_index(b) for b in bins]) - else: - indices = np.arange(len(bins)) filter_indices.append(indices) # Account for stride in each of the previous filters From 9a28bc8da14dfca15b3fb95c20029497e10813ab Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 16 Feb 2022 15:26:51 -0600 Subject: [PATCH 3/3] Removing special case for EnergyFunctionFilter --- openmc/tallies.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/openmc/tallies.py b/openmc/tallies.py index fbf1efa3c1..db2ef6570b 100644 --- a/openmc/tallies.py +++ b/openmc/tallies.py @@ -1092,9 +1092,6 @@ class Tally(IDManagerMixin): for i, self_filter in enumerate(self.filters): # If a user-requested Filter, get the user-requested bins for j, test_filter in enumerate(filters): - if type(self_filter) is openmc.EnergyFunctionFilter: - indices = [self_filter.get_bin_index(None)] - break if type(self_filter) is test_filter: bins = filter_bins[j] indices = np.array([self_filter.get_bin_index(b) for b in bins])