Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for viewing distribcell tallies #87

Merged
merged 5 commits into from
Apr 27, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions openmc_plotter/plotmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
_SPATIAL_FILTERS = (openmc.UniverseFilter,
openmc.MaterialFilter,
openmc.CellFilter,
openmc.DistribcellFilter,
openmc.MeshFilter)

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

def create_tally_image(self, view=None):
"""
Returns
-------
tuple : image data (numpy.ndarray), data extents (optional),
data_min_value (float), data_max_value (float),
data label (str)
"""
if view is None:
view = self.currentView

Expand Down Expand Up @@ -346,6 +354,32 @@ def create_tally_image(self, view=None):
nuclides,
view)
return image + (units_out,)
elif tally.contains_filter(openmc.DistribcellFilter):
if tally_value == 'rel_err':
mean_data = self._create_distribcell_image(tally,
'mean',
scores,
nuclides,
view)
std_dev_data = self._create_distribcell_image(tally,
'std_dev',
scores,
nuclides,
view)
image_data = 100 * np.divide(std_dev_data[0],
mean_data[0],
out=np.zeros_like(mean_data[0]),
where=mean_data != 0)
data_min = np.min(image_data)
data_max = np.max(image_data)
return image_data, None, data_min, data_max, '% error'
else:
image = self._create_distribcell_image(tally,
tally_value,
scores,
nuclides,
view)
return image + (units_out,)
else:
# same as above, get the std. dev. data
# and mean date to produce the relative error data
Expand Down Expand Up @@ -467,6 +501,31 @@ def _do_op(array, tally_value, ax=0):

return image_data, None, data_min, data_max

def _create_distribcell_image(self, tally, tally_value, scores, nuclides, view=None):
if view is None:
cv = self.currentView

sp = self.statepoint
pshriwise marked this conversation as resolved.
Show resolved Hide resolved
dfilter = tally.find_filter(openmc.DistribcellFilter)

data = tally.get_values(scores=scores, nuclides=nuclides, value=tally_value)
data = data.flatten()

cell_id = dfilter.bins[0]
# create a mask for ids that match the cell
image_data = np.zeros_like(self.ids)
paulromano marked this conversation as resolved.
Show resolved Hide resolved

cell_id_mask = self.cell_ids == cell_id
for i, v in enumerate(data):
instance_mask = self.instances == i
image_data[np.logical_and(cell_id_mask, instance_mask)] = v
pshriwise marked this conversation as resolved.
Show resolved Hide resolved

data_min = np.min(data)
data_max = np.max(data)
image_data = np.ma.masked_where(image_data < 0.0, image_data)

return image_data, None, data_min, data_max

def _create_tally_mesh_image(self, tally, tally_value, scores, nuclides, view=None):
# some variables used throughout
if view is None:
Expand Down