Skip to content

Commit 8be3859

Browse files
committed
Add support for plotting 2D mesh data
1 parent 845092c commit 8be3859

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

openmc_plotter/plotmodel.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
from ast import literal_eval
12
from collections import defaultdict
23
import copy
34
import itertools
45
import threading
5-
from ast import literal_eval
66

77
from PySide2.QtWidgets import QItemDelegate, QColorDialog, QLineEdit, QMessageBox
88
from PySide2.QtCore import QAbstractTableModel, QModelIndex, Qt, QSize, QEvent
@@ -503,28 +503,37 @@ def _do_op(array, tally_value, ax=0):
503503
# applied to the mesh filter
504504
lower_left = mesh.lower_left
505505
upper_right = mesh.upper_right
506+
width = mesh.width
507+
dimension = mesh.dimension
506508
if hasattr(mesh_filter, 'translation') and mesh_filter.translation is not None:
507509
lower_left += mesh_filter.translation
508510
upper_right += mesh_filter.translation
509511

512+
# For 2D meshes, add an extra z dimension
513+
if len(mesh.dimension) == 2:
514+
lower_left = np.hstack((lower_left, -1e50))
515+
upper_right = np.hstack((upper_right, 1e50))
516+
width = np.hstack((width, 2e50))
517+
dimension = np.hstack((dimension, 1))
518+
510519
# reduce data to the visible slice of the mesh values
511-
k = int((view.origin[ax] - lower_left[ax]) // mesh.width[ax])
520+
k = int((view.origin[ax] - lower_left[ax]) // width[ax])
512521

513522
# setup slice
514523
data_slice = [None, None, None]
515-
data_slice[h_ind] = slice(mesh.dimension[h_ind])
516-
data_slice[v_ind] = slice(mesh.dimension[v_ind])
524+
data_slice[h_ind] = slice(dimension[h_ind])
525+
data_slice[v_ind] = slice(dimension[v_ind])
517526
data_slice[ax] = k
518527

519-
if k < 0 or k > mesh.dimension[ax]:
528+
if k < 0 or k > dimension[ax]:
520529
return (None, None, None, None)
521530

522531
# move mesh axes to the end of the filters
523532
filter_idx = [type(filter) for filter in tally.filters].index(openmc.MeshFilter)
524533
data = np.moveaxis(data, filter_idx, -1)
525534

526535
# reshape data (with zyx ordering for mesh data)
527-
data = data.reshape(data.shape[:-1] + tuple(mesh.dimension[::-1]))
536+
data = data.reshape(data.shape[:-1] + tuple(dimension[::-1]))
528537
data = data[..., data_slice[2], data_slice[1], data_slice[0]]
529538

530539
# sum over the rest of the tally filters

0 commit comments

Comments
 (0)