Skip to content

Commit 54c4b73

Browse files
committed
Implement support for CellInstanceFilter tally plotting
1 parent 60cc46a commit 54c4b73

2 files changed

Lines changed: 44 additions & 19 deletions

File tree

openmc_plotter/docks.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,11 @@ def _createFilterTree(self, spatial_filters):
406406
continue
407407

408408
def _bin_sort_val(bin):
409-
if isinstance(bin, Iterable) and all([isinstance(val, float) for val in bin]):
410-
return np.sum(bin)
409+
if isinstance(bin, Iterable):
410+
if all([isinstance(val, float) for val in bin]):
411+
return np.sum(bin)
412+
else:
413+
return tuple(bin)
411414
else:
412415
return bin
413416

openmc_plotter/plotmodel.py

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
openmc.MaterialFilter,
3535
openmc.CellFilter,
3636
openmc.DistribcellFilter,
37+
openmc.CellInstanceFilter,
3738
openmc.MeshFilter)
3839

3940
_PRODUCTIONS = ('delayed-nu-fission', 'prompt-nu-fission', 'nu-fission',
@@ -330,6 +331,9 @@ def create_tally_image(self, view=None):
330331

331332
units_out = list(units)[0]
332333

334+
contains_distribcell = tally.contains_filter(openmc.DistribcellFilter)
335+
contains_cellinstance = tally.contains_filter(openmc.CellInstanceFilter)
336+
333337
if tally.contains_filter(openmc.MeshFilter):
334338
if tally_value == 'rel_err':
335339
# get both the std. dev. data and mean data
@@ -360,28 +364,26 @@ def create_tally_image(self, view=None):
360364
nuclides,
361365
view)
362366
return image + (units_out,)
363-
elif tally.contains_filter(openmc.DistribcellFilter):
367+
elif contains_distribcell or contains_cellinstance:
368+
# Select appropriate function
369+
if contains_distribcell:
370+
create_image = self._create_distribcell_image
371+
else:
372+
create_image = self._create_cellinstance_image
373+
364374
if tally_value == 'rel_err':
365-
mean_data = self._create_distribcell_image(tally,
366-
'mean',
367-
scores,
368-
nuclides)
369-
std_dev_data = self._create_distribcell_image(tally,
370-
'std_dev',
371-
scores,
372-
nuclides)
373-
image_data = 100 * np.divide(std_dev_data[0],
374-
mean_data[0],
375-
out=np.zeros_like(mean_data[0]),
376-
where=mean_data != 0)
375+
mean_data = create_image(tally, 'mean', scores, nuclides)
376+
std_dev_data = create_image(tally, 'std_dev', scores, nuclides)
377+
image_data = 100 * np.divide(
378+
std_dev_data[0], mean_data[0],
379+
out=np.zeros_like(mean_data[0]),
380+
where=mean_data != 0
381+
)
377382
data_min = np.min(image_data)
378383
data_max = np.max(image_data)
379384
return image_data, None, data_min, data_max, '% error'
380385
else:
381-
image = self._create_distribcell_image(tally,
382-
tally_value,
383-
scores,
384-
nuclides)
386+
image = create_image(tally, tally_value, scores, nuclides)
385387
return image + (units_out,)
386388
else:
387389
# same as above, get the std. dev. data
@@ -522,6 +524,26 @@ def _create_distribcell_image(self, tally, tally_value, scores, nuclides):
522524

523525
return image_data, None, data_min, data_max
524526

527+
def _create_cellinstance_image(self, tally, tally_value, scores, nuclides):
528+
cellinst_filter = tally.find_filter(openmc.CellInstanceFilter)
529+
530+
data = tally.get_values(scores=scores, nuclides=nuclides, value=tally_value)
531+
data = data.flatten()
532+
533+
# create a mask for ids that match the cell
534+
image_data = np.full_like(self.ids, np.nan, dtype=float)
535+
536+
for v, (cell_id, instance) in zip(data, cellinst_filter.bins):
537+
cell_id_mask = self.cell_ids == cell_id
538+
instance_mask = self.instances == instance
539+
image_data[cell_id_mask & instance_mask] = v
540+
541+
data_min = np.min(data)
542+
data_max = np.max(data)
543+
image_data = np.ma.masked_where(image_data < 0.0, image_data)
544+
545+
return image_data, None, data_min, data_max
546+
525547
def _create_tally_mesh_image(self, tally, tally_value, scores, nuclides, view=None):
526548
# some variables used throughout
527549
if view is None:

0 commit comments

Comments
 (0)