Skip to content

Commit 7c488a0

Browse files
authored
Merge pull request #64 from paulromano/mesh2d-fix
Support 2D meshes, energy function filter
2 parents 845092c + 0843eb1 commit 7c488a0

File tree

5 files changed

+29
-13
lines changed

5 files changed

+29
-13
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
shell: bash
2828
run: |
2929
apt update
30-
apt install -y libglu1-mesa
30+
apt install -y libglu1-mesa libglib2.0-0 libfontconfig1
3131
-
3232
uses: actions/checkout@v2
3333
-

openmc_plotter/docks.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,12 @@ def _bin_sort_val(bin):
412412
else:
413413
return bin
414414

415-
for bin in sorted(tally_filter.bins, key=_bin_sort_val):
415+
if isinstance(tally_filter, openmc.EnergyFunctionFilter):
416+
bins = [0]
417+
else:
418+
bins = tally_filter.bins
419+
420+
for bin in sorted(bins, key=_bin_sort_val):
416421
item = QTreeWidgetItem(filter_item, [str(bin),])
417422
if not spatial_filters:
418423
item.setFlags(QtCore.Qt.ItemIsUserCheckable)
@@ -577,7 +582,11 @@ def updateFilters(self):
577582
filter_checked = f_item.checkState(0)
578583
if filter_checked != QtCore.Qt.Unchecked:
579584
selected_bins = []
580-
for idx, b in enumerate(f.bins):
585+
if isinstance(f, openmc.EnergyFunctionFilter):
586+
bins = [0]
587+
else:
588+
bins = f.bins
589+
for idx, b in enumerate(bins):
581590
b = b if not isinstance(b, Iterable) else tuple(b)
582591
bin_checked = self.bin_map[(f, b)].checkState(0)
583592
if bin_checked == QtCore.Qt.Checked:

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

pytest.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
qt_api=pyside2
33
python_files = test*.py
44
python_classes = NoThanks
5-
filter_warnings = ignore::UserWarning
6-
addopts = -rs
5+
filterwarnings = ignore::UserWarning
6+
addopts = -rs

tests/setup_test/test.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import openmc.lib
2-
31
from openmc_plotter.main_window import MainWindow, _openmcReload
42

53
def test_window(qtbot):

0 commit comments

Comments
 (0)