Skip to content

Commit 506c0bb

Browse files
committed
Utilize new get_plot_bins method from OpenMC for mesh plotting
1 parent 7b79df4 commit 506c0bb

2 files changed

Lines changed: 15 additions & 55 deletions

File tree

openmc_plotter/plotgui.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import numpy as np
1515

1616
from .plot_colors import rgb_normalize, invert_rgb
17-
from .plotmodel import DomainDelegate
17+
from .plotmodel import DomainDelegate, PlotModel
1818
from .plotmodel import _NOT_FOUND, _VOID_REGION, _OVERLAP, _MODEL_PROPERTIES
1919
from .scientific_spin_box import ScientificDoubleSpinBox
2020
from .custom_widgets import HorizontalLine
@@ -23,7 +23,7 @@
2323

2424
class PlotImage(FigureCanvas):
2525

26-
def __init__(self, model, parent, main_window):
26+
def __init__(self, model: PlotModel, parent, main_window):
2727

2828
self.figure = Figure(dpi=main_window.logicalDpiX())
2929
super().__init__(self.figure)

openmc_plotter/plotmodel.py

Lines changed: 13 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -657,57 +657,10 @@ def _do_op(array, tally_value, ax=0):
657657
# start with reshaped data
658658
data = tally.get_reshaped_data(tally_value)
659659

660-
# determine basis indices
661-
if view.basis == 'xy':
662-
h_ind = 0
663-
v_ind = 1
664-
ax = 2
665-
elif view.basis == 'yz':
666-
h_ind = 1
667-
v_ind = 2
668-
ax = 0
669-
else:
670-
h_ind = 0
671-
v_ind = 2
672-
ax = 1
673-
674-
# adjust corners of the mesh for a translation
675-
# applied to the mesh filter
676-
lower_left = mesh.lower_left
677-
upper_right = mesh.upper_right
678-
width = mesh.width
679-
dimension = mesh.dimension
680-
if hasattr(mesh_filter, 'translation') and mesh_filter.translation is not None:
681-
lower_left += mesh_filter.translation
682-
upper_right += mesh_filter.translation
683-
684-
# For 2D meshes, add an extra z dimension
685-
if len(mesh.dimension) == 2:
686-
lower_left = np.hstack((lower_left, -1e50))
687-
upper_right = np.hstack((upper_right, 1e50))
688-
width = np.hstack((width, 2e50))
689-
dimension = np.hstack((dimension, 1))
690-
691-
# reduce data to the visible slice of the mesh values
692-
k = int((view.origin[ax] - lower_left[ax]) // width[ax])
693-
694-
# setup slice
695-
data_slice = [None, None, None]
696-
data_slice[h_ind] = slice(dimension[h_ind])
697-
data_slice[v_ind] = slice(dimension[v_ind])
698-
data_slice[ax] = k
699-
700-
if k < 0 or k > dimension[ax]:
701-
return (None, None, None, None)
702-
703660
# move mesh axes to the end of the filters
704661
filter_idx = [type(filter) for filter in tally.filters].index(openmc.MeshFilter)
705662
data = np.moveaxis(data, filter_idx, -1)
706663

707-
# reshape data (with zyx ordering for mesh data)
708-
data = data.reshape(data.shape[:-1] + tuple(dimension[::-1]))
709-
data = data[..., data_slice[2], data_slice[1], data_slice[0]]
710-
711664
# sum over the rest of the tally filters
712665
for tally_filter in tally.filters:
713666
if type(tally_filter) == openmc.MeshFilter:
@@ -747,14 +700,21 @@ def _do_op(array, tally_value, ax=0):
747700
data_min = np.min(data)
748701
data_max = np.max(data)
749702

750-
# set image data, reverse y-axis
751-
image_data = data[::-1, ...]
703+
# Get mesh bins from openmc.lib
704+
mesh_cpp = openmc.lib.meshes[mesh.id]
705+
mesh_bins = mesh_cpp.get_plot_bins(
706+
origin=view.origin,
707+
width=(view.width, view.height),
708+
basis=view.basis,
709+
pixels=(view.h_res, view.v_res),
710+
)
752711

753-
# return data extents (in cm) for the tally
754-
extents = [lower_left[h_ind], upper_right[h_ind],
755-
lower_left[v_ind], upper_right[v_ind]]
712+
# set image data
713+
image_data = np.full_like(self.ids, np.nan, dtype=float)
714+
mask = (mesh_bins >= 0)
715+
image_data[mask] = data[mesh_bins[mask]]
756716

757-
return image_data, extents, data_min, data_max
717+
return image_data, None, data_min, data_max
758718

759719
@property
760720
def cell_ids(self):

0 commit comments

Comments
 (0)