Skip to content

Commit cfc56d6

Browse files
authored
Merge pull request #89 from paulromano/distribcell-performance
Improve performance of distribcell/cell instance tally plotting
2 parents 01e2387 + 6751b2a commit cfc56d6

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

openmc_plotter/plotmodel.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -508,20 +508,25 @@ def _create_distribcell_image(self, tally, tally_value, scores, nuclides, cellin
508508
# Create an empty array of appropriate shape for image
509509
image_data = np.full_like(self.ids, np.nan, dtype=float)
510510

511-
# Determine appropriate set of bins depending on filter type
511+
# Determine mapping of cell IDs to list of (instance, tally value).
512512
if cellinstance:
513513
f = tally.find_filter(openmc.CellInstanceFilter)
514-
bins = f.bins
514+
cell_id_to_inst_value = defaultdict(list)
515+
for value, (cell_id, instance) in zip(data, f.bins):
516+
cell_id_to_inst_value[cell_id].append((instance, value))
515517
else:
516518
f = tally.find_filter(openmc.DistribcellFilter)
517-
bins = [(f.bins[0], i) for i in range(data.size)]
519+
cell_id_to_inst_value = {f.bins[0]: list(enumerate(data))}
518520

519-
# Iterate over tally bins, setting any pixels that have matching (cell
520-
# ID, instance) each time
521-
for v, (cell_id, instance) in zip(data, bins):
521+
for cell_id, value_list in cell_id_to_inst_value.items():
522+
# Get mask for each relevant cell
522523
cell_id_mask = (self.cell_ids == cell_id)
523-
instance_mask = (self.instances == instance)
524-
image_data[cell_id_mask & instance_mask] = v
524+
525+
# For each cell, iterate over instances and corresponding tally
526+
# values and set any matching pixels
527+
for instance, value in value_list:
528+
instance_mask = (self.instances == instance)
529+
image_data[cell_id_mask & instance_mask] = value
525530

526531
data_min = np.min(data)
527532
data_max = np.max(data)

0 commit comments

Comments
 (0)