Skip to content

Commit 90a4358

Browse files
committed
Adding support for plotting distribcel tallies.
1 parent 4e57636 commit 90a4358

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

openmc_plotter/plotmodel.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
_SPATIAL_FILTERS = (openmc.UniverseFilter,
3434
openmc.MaterialFilter,
3535
openmc.CellFilter,
36+
openmc.DistribcellFilter,
3637
openmc.MeshFilter)
3738

3839
_PRODUCTIONS = ('delayed-nu-fission', 'prompt-nu-fission', 'nu-fission',
@@ -280,6 +281,13 @@ def storeCurrent(self):
280281
self.previousViews.append(copy.deepcopy(self.currentView))
281282

282283
def create_tally_image(self, view=None):
284+
"""
285+
Returns
286+
-------
287+
tuple : image data (numpy.ndarray), data extents (optional),
288+
data_min_value (float), data_max_value (float),
289+
data label (str)
290+
"""
283291
if view is None:
284292
view = self.currentView
285293

@@ -346,6 +354,32 @@ def create_tally_image(self, view=None):
346354
nuclides,
347355
view)
348356
return image + (units_out,)
357+
elif tally.contains_filter(openmc.DistribcellFilter):
358+
if tally_value == 'rel_err':
359+
mean_data = self._create_distribcell_image(tally,
360+
'mean',
361+
scores,
362+
nuclides,
363+
view)
364+
std_dev_data = self._create_distribcell_image(tally,
365+
'std_dev',
366+
scores,
367+
nuclides,
368+
view)
369+
image_data = 100 * np.divide(std_dev_data[0],
370+
mean_data[0],
371+
out=np.zeros_like(mean_data[0]),
372+
where=mean_data != 0)
373+
data_min = np.min(image_data)
374+
data_max = np.max(image_data)
375+
return image_data, None, data_min, data_max, '% error'
376+
else:
377+
image = self._create_distribcell_image(tally,
378+
tally_value,
379+
scores,
380+
nuclides,
381+
view)
382+
return image + (units_out,)
349383
else:
350384
# same as above, get the std. dev. data
351385
# and mean date to produce the relative error data
@@ -467,6 +501,31 @@ def _do_op(array, tally_value, ax=0):
467501

468502
return image_data, None, data_min, data_max
469503

504+
def _create_distribcell_image(self, tally, tally_value, scores, nuclides, view=None):
505+
if view is None:
506+
cv = self.currentView
507+
508+
sp = self.statepoint
509+
dfilter = tally.find_filter(openmc.DistribcellFilter)
510+
511+
data = tally.get_values(scores=scores, nuclides=nuclides, value=tally_value)
512+
data = data.flatten()
513+
514+
cell_id = dfilter.bins[0]
515+
# create a mask for ids that match the cell
516+
image_data = np.zeros_like(self.ids)
517+
518+
cell_id_mask = self.cell_ids == cell_id
519+
for i, v in enumerate(data):
520+
instance_mask = self.instances == i
521+
image_data[np.logical_and(cell_id_mask, instance_mask)] = v
522+
523+
data_min = np.min(data)
524+
data_max = np.max(data)
525+
image_data = np.ma.masked_where(image_data < 0.0, image_data)
526+
527+
return image_data, None, data_min, data_max
528+
470529
def _create_tally_mesh_image(self, tally, tally_value, scores, nuclides, view=None):
471530
# some variables used throughout
472531
if view is None:

0 commit comments

Comments
 (0)