diff --git a/openmc_plotter/plotgui.py b/openmc_plotter/plotgui.py index 13dd69a..13aa91e 100644 --- a/openmc_plotter/plotgui.py +++ b/openmc_plotter/plotgui.py @@ -1,5 +1,6 @@ import io from functools import partial +import openmc from PySide6 import QtCore, QtGui from PySide6.QtWidgets import (QWidget, QPushButton, QHBoxLayout, QVBoxLayout, @@ -308,7 +309,10 @@ def getIDinfo(self, event): # check that the position is in the axes view if 0 <= yPos < self.model.currentView.v_res \ and 0 <= xPos and xPos < self.model.currentView.h_res: - id = self.model.ids[yPos, xPos] + if self.model.currentView.colorby == 'cell': + id = int(self.model.cell_ids[yPos, xPos]) + else: + id = int(self.model.mat_ids[yPos, xPos]) instance = self.model.instances[yPos, xPos] temp = "{:g}".format(self.model.property_data[yPos, xPos, 0]) density = "{:g}".format(self.model.property_data[yPos, xPos, 1]) @@ -354,7 +358,6 @@ def mouseMoveEvent(self, event): tallyInfo = "" if self.parent.underMouse(): - if domain_kind.lower() in _MODEL_PROPERTIES: line_val = float(properties[domain_kind.lower()]) line_val = max(line_val, 0.0) @@ -370,8 +373,25 @@ def mouseMoveEvent(self, event): instanceInfo = "" if id == _VOID_REGION: domainInfo = ("VOID") - elif id == _OVERLAP: - domainInfo = ("OVERLAP") + elif id < _OVERLAP: + # Unpack the index and find it in overlap map + overlap_idx = int(_OVERLAP - int(id) - 1) + if overlap_idx in self.model.overlap_map: + universe, cell1, cell2 = self.model.overlap_map[overlap_idx] + try: + name1 = self.model.activeView.cells[cell1].name or str(cell1) + except KeyError: + name1 = str(cell1) + try: + name2 = self.model.activeView.cells[cell2].name or str(cell2) + except KeyError: + name2 = str(cell2) + domainInfo = ( + f"OVERLAP: Universe {universe}, " + f"Cells {name1} and {name2}" + ) + else: + domainInfo = "OVERLAP (unknown region)" elif id != _NOT_FOUND and domain[id].name: domainInfo = ("{} {}{}: \"{}\"\t Density: {} g/cc\t" "Temperature: {} K".format( @@ -483,7 +503,7 @@ def contextMenuEvent(self, event): self.menu.addAction(self.main_window.redoAction) self.menu.addSeparator() - if int(id) not in (_NOT_FOUND, _OVERLAP) and \ + if int(id) not in (_NOT_FOUND) and int(id) >= _OVERLAP and \ cv.colorby not in _MODEL_PROPERTIES: # Domain ID diff --git a/openmc_plotter/plotmodel.py b/openmc_plotter/plotmodel.py index 95e01f2..c454731 100644 --- a/openmc_plotter/plotmodel.py +++ b/openmc_plotter/plotmodel.py @@ -324,6 +324,9 @@ def __init__(self, use_settings_pkl, model_path, default_res): self.property_data = None self.map_view_params = None + # Map to be populated by overlap functions + self.overlap_map = {} + self.version = __version__ # default statepoint value @@ -530,24 +533,34 @@ def makePlot(self, view: Optional["PlotView"] = None, filter=filter_cpp, ) self.map_view_params = self.view_params_payload(view) + else: self.geom_data = geom_data self.property_data = property_data self.map_view_params = self.view_params_payload(view) + overlap_info, n = openmc.lib.slice_data_overlap_info() + self.overlap_map = {} + for i in range(n): + self.overlap_map[i] = (overlap_info[i*3], overlap_info[i*3+1], overlap_info[i*3+2]) + # update current view cv = self.currentView = copy.deepcopy(view) # set model ids based on domain if cv.colorby == 'cell': - self.ids = self.cell_ids + self.ids = self.cell_ids.copy() domain = cv.cells source = self.modelCells else: - self.ids = self.mat_ids + self.ids = self.mat_ids.copy() domain = cv.materials source = self.modelMaterials + # Normalizes so that domain only sees -3, but + # overlap indices are still available in cell_ids + self.ids[self.ids < _OVERLAP] = _OVERLAP # new line + # generate colors if not present for cell_id, cell in cv.cells.items(): if cell.color is None: