diff --git a/openmc/filter.py b/openmc/filter.py index 676bc66e17..063961d814 100644 --- a/openmc/filter.py +++ b/openmc/filter.py @@ -15,7 +15,7 @@ import openmc.checkvalue as cv _FILTER_TYPES = ['universe', 'material', 'cell', 'cellborn', 'surface', 'mesh', 'energy', 'energyout', 'mu', 'polar', 'azimuthal', - 'distribcell', 'delayedgroup', 'energyfunction'] + 'distribcell', 'delayedgroup', 'energyfunction', 'celltocell', 'cellfrom', 'cellto'] _CURRENT_NAMES = {1: 'x-min out', 2: 'x-min in', 3: 'x-max out', 4: 'x-max in', @@ -335,6 +335,9 @@ class Filter(object): """ if filter_bin not in self.bins: + print('Failed to find') + print(filter_bin) + print(self.bins) msg = 'Unable to get the bin index for Filter since "{0}" ' \ 'is not one of the bins'.format(filter_bin) raise ValueError(msg) @@ -533,7 +536,66 @@ class CellFilter(IntegralFilter): """ +class CellToCellFilter(IntegralFilter): + """Bins tally on which couple of cells the neutrons went from and to. /CHANGE/ + Parameters + ---------- + bins : Iterable of Integral + openmc.Cell IDs. + + Attributes + ---------- + bins : Iterable of Integral + openmc.Cell IDs. + num_bins : Integral + The number of filter bins + stride : Integral + The number of filter, nuclide and score bins within each of this + filter's bins. + + """ + +class CellFromFilter(IntegralFilter): + """Bins tally on which couple of cells the neutrons came from. /CHANGE/ + + Parameters + ---------- + bins : Integral or Iterable of Integral + openmc.Cell IDs. + + Attributes + ---------- + bins : Integral or Iterable of Integral + openmc.Cell IDs. + num_bins : Integral + The number of filter bins + stride : Integral + The number of filter, nuclide and score bins within each of this + filter's bins. + + """ + +class CellToFilter(IntegralFilter): + """Bins tally on which couple of cells the neutrons went to. /CHANGE/ + + Parameters + ---------- + bins : Integral or Iterable of Integral + openmc.Cell IDs. + + Attributes + ---------- + bins : Integral or Iterable of Integral + openmc.Cell IDs. + num_bins : Integral + The number of filter bins + stride : Integral + The number of filter, nuclide and score bins within each of this + filter's bins. + + """ + class CellbornFilter(IntegralFilter): """Bins tally events based on the cell that the particle was born in. @@ -901,8 +963,12 @@ class RealFilter(Filter): return np.allclose(self.bins, other.bins) def get_bin_index(self, filter_bin): - i = np.where(self.bins == filter_bin[1])[0] + i = np.where(abs(self.bins -filter_bin[1]) < 1e-10)[0] if len(i) == 0: + print('Tally bins', self.bins) + print('Bins searched for:', filter_bin) + print('Search result', i) + print(self.bins - filter_bin[1]) msg = 'Unable to get the bin index for Filter since "{0}" ' \ 'is not one of the bins'.format(filter_bin) raise ValueError(msg) @@ -940,6 +1006,9 @@ class EnergyFilter(RealFilter): def get_bin_index(self, filter_bin): # Use lower energy bound to find index for RealFilters + + #print(self.bins, filter_bin) + deltas = np.abs(self.bins - filter_bin[1]) / filter_bin[1] min_delta = np.min(deltas) if min_delta < 1E-3: diff --git a/openmc/tallies.py b/openmc/tallies.py index 0bf87de101..f3af788a65 100644 --- a/openmc/tallies.py +++ b/openmc/tallies.py @@ -239,6 +239,9 @@ class Tally(object): num_bins = 1 for self_filter in self.filters: + + #print("Looping through filters, num_bin", self_filter.num_bins, num_bins) + num_bins *= self_filter.num_bins return num_bins @@ -1215,6 +1218,7 @@ class Tally(object): # Find the equivalent Filter in this Tally's list of Filters filter_found = self.find_filter(filter_type) + #print('searched for filter', filter_type, 'and found', filter_found) # Get the index for the requested bin from the Filter and return it filter_index = filter_found.get_bin_index(filter_bin) @@ -1376,6 +1380,12 @@ class Tally(object): else: bins = self_filter.bins + #print('in get_filter_indices') + #print('arguments', filters, filter_bins) + #print('params') + #print(bins) + #print(type(self_filter), self_filter) + # Initialize a NumPy array for the Filter bin indices filter_indices.append(np.zeros(len(bins), dtype=np.int)) @@ -1520,6 +1530,8 @@ class Tally(object): e.g., if the score(s) do not match those in the Tally. """ + #print("\n In get_values") + #print("Tally shape", self.shape) # Ensure that the tally has data if (value == 'mean' and self.mean is None) or \ @@ -1529,6 +1541,13 @@ class Tally(object): (value == 'sum_sq' and self.sum_sq is None): msg = 'The Tally ID="{0}" has no data to return'.format(self.id) raise ValueError(msg) + + #print('\n arguments') + #print(filters) + #print(filter_bins) + #print('\n Tally characteristics') + #print(self) + #print(self.name, self.filters, self.scores,self.num_filter_bins) # Get filter, nuclide and score indices filter_indices = self.get_filter_indices(filters, filter_bins) @@ -1537,7 +1556,7 @@ class Tally(object): # Construct outer product of all three index types with each other indices = np.ix_(filter_indices, nuclide_indices, score_indices) - + # Return the desired result from Tally if value == 'mean': data = self.mean[indices]