|
| 1 | +from ast import literal_eval |
1 | 2 | from collections import defaultdict |
2 | 3 | import copy |
3 | 4 | import itertools |
4 | 5 | import threading |
5 | | -from ast import literal_eval |
6 | 6 |
|
7 | 7 | from PySide2.QtWidgets import QItemDelegate, QColorDialog, QLineEdit, QMessageBox |
8 | 8 | from PySide2.QtCore import QAbstractTableModel, QModelIndex, Qt, QSize, QEvent |
@@ -503,28 +503,37 @@ def _do_op(array, tally_value, ax=0): |
503 | 503 | # applied to the mesh filter |
504 | 504 | lower_left = mesh.lower_left |
505 | 505 | upper_right = mesh.upper_right |
| 506 | + width = mesh.width |
| 507 | + dimension = mesh.dimension |
506 | 508 | if hasattr(mesh_filter, 'translation') and mesh_filter.translation is not None: |
507 | 509 | lower_left += mesh_filter.translation |
508 | 510 | upper_right += mesh_filter.translation |
509 | 511 |
|
| 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 | + |
510 | 519 | # 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]) |
512 | 521 |
|
513 | 522 | # setup slice |
514 | 523 | 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]) |
517 | 526 | data_slice[ax] = k |
518 | 527 |
|
519 | | - if k < 0 or k > mesh.dimension[ax]: |
| 528 | + if k < 0 or k > dimension[ax]: |
520 | 529 | return (None, None, None, None) |
521 | 530 |
|
522 | 531 | # move mesh axes to the end of the filters |
523 | 532 | filter_idx = [type(filter) for filter in tally.filters].index(openmc.MeshFilter) |
524 | 533 | data = np.moveaxis(data, filter_idx, -1) |
525 | 534 |
|
526 | 535 | # 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])) |
528 | 537 | data = data[..., data_slice[2], data_slice[1], data_slice[0]] |
529 | 538 |
|
530 | 539 | # sum over the rest of the tally filters |
|
0 commit comments