Skip to content

Commit 0754ca6

Browse files
Overlapping Visualization for Plotter (#179)
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
1 parent 0125691 commit 0754ca6

2 files changed

Lines changed: 45 additions & 9 deletions

File tree

openmc_plotter/plotgui.py

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,12 @@ def getIDinfo(self, event):
308308
# check that the position is in the axes view
309309
if 0 <= yPos < self.model.currentView.v_res \
310310
and 0 <= xPos and xPos < self.model.currentView.h_res:
311-
id = self.model.ids[yPos, xPos]
311+
cell_id = int(self.model.cell_ids[yPos, xPos])
312+
mat_id = int(self.model.mat_ids[yPos, xPos])
313+
if cell_id < _OVERLAP:
314+
id = cell_id
315+
else:
316+
id = cell_id if self.model.currentView.colorby == 'cell' else mat_id
312317
instance = self.model.instances[yPos, xPos]
313318
temp = "{:g}".format(self.model.property_data[yPos, xPos, 0])
314319
density = "{:g}".format(self.model.property_data[yPos, xPos, 1])
@@ -336,6 +341,26 @@ def getIDinfo(self, event):
336341

337342
return id, instance, properties, domain, domain_kind
338343

344+
def _cellLabel(self, cell_id):
345+
try:
346+
name = self.model.activeView.cells[cell_id].name
347+
except KeyError:
348+
name = None
349+
return f"{cell_id} ({name})" if name else str(cell_id)
350+
351+
def _overlapInfo(self, id):
352+
if id == _OVERLAP:
353+
return "OVERLAP"
354+
355+
overlap_idx = int(_OVERLAP - int(id) - 1)
356+
if not 0 <= overlap_idx < len(self.model.overlap_info):
357+
return "OVERLAP (unknown region)"
358+
359+
universe, cell1, cell2 = self.model.overlap_info[overlap_idx]
360+
label1 = self._cellLabel(cell1)
361+
label2 = self._cellLabel(cell2)
362+
return f"OVERLAP: Universe {universe}, Cells {label1} and {label2}"
363+
339364
def mouseDoubleClickEvent(self, event):
340365
xCenter, yCenter = self.getPlotCoords(event.pos())
341366
self.main_window.editPlotOrigin(xCenter, yCenter, apply=True)
@@ -354,7 +379,6 @@ def mouseMoveEvent(self, event):
354379
tallyInfo = ""
355380

356381
if self.parent.underMouse():
357-
358382
if domain_kind.lower() in _MODEL_PROPERTIES:
359383
line_val = float(properties[domain_kind.lower()])
360384
line_val = max(line_val, 0.0)
@@ -370,8 +394,8 @@ def mouseMoveEvent(self, event):
370394
instanceInfo = ""
371395
if id == _VOID_REGION:
372396
domainInfo = ("VOID")
373-
elif id == _OVERLAP:
374-
domainInfo = ("OVERLAP")
397+
elif id <= _OVERLAP:
398+
domainInfo = self._overlapInfo(id)
375399
elif id != _NOT_FOUND and domain[id].name:
376400
domainInfo = ("{} {}{}: \"{}\"\t Density: {} g/cc\t"
377401
"Temperature: {} K".format(
@@ -483,8 +507,9 @@ def contextMenuEvent(self, event):
483507
self.menu.addAction(self.main_window.redoAction)
484508
self.menu.addSeparator()
485509

486-
if int(id) not in (_NOT_FOUND, _OVERLAP) and \
487-
cv.colorby not in _MODEL_PROPERTIES:
510+
if (int(id) not in (_NOT_FOUND, _VOID_REGION) and
511+
int(id) > _OVERLAP and
512+
cv.colorby not in _MODEL_PROPERTIES):
488513

489514
# Domain ID
490515
if domain[id].name:
@@ -551,7 +576,7 @@ def contextMenuEvent(self, event):
551576
connector = partial(self.main_window.editBackgroundColor,
552577
apply=True)
553578
bgColorAction.triggered.connect(connector)
554-
elif int(id) == _OVERLAP:
579+
elif int(id) <= _OVERLAP:
555580
olapColorAction = self.menu.addAction(
556581
'Edit Overlap Color...')
557582
olapColorAction.setToolTip('Edit overlap color')

openmc_plotter/plotmodel.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,9 @@ def __init__(self, use_settings_pkl, model_path, default_res):
324324
self.property_data = None
325325
self.map_view_params = None
326326

327+
# Map to be populated by overlap functions
328+
self.overlap_info = None
329+
327330
self.version = __version__
328331

329332
# default statepoint value
@@ -530,24 +533,32 @@ def makePlot(self, view: Optional["PlotView"] = None,
530533
filter=filter_cpp,
531534
)
532535
self.map_view_params = self.view_params_payload(view)
536+
533537
else:
534538
self.geom_data = geom_data
535539
self.property_data = property_data
536540
self.map_view_params = self.view_params_payload(view)
537541

542+
# Get cell overlap information
543+
self.overlap_info = openmc.lib.slice_data_overlap_info()
544+
538545
# update current view
539546
cv = self.currentView = copy.deepcopy(view)
540547

541548
# set model ids based on domain
542549
if cv.colorby == 'cell':
543-
self.ids = self.cell_ids
550+
self.ids = self.cell_ids.copy()
544551
domain = cv.cells
545552
source = self.modelCells
546553
else:
547-
self.ids = self.mat_ids
554+
self.ids = self.mat_ids.copy()
548555
domain = cv.materials
549556
source = self.modelMaterials
550557

558+
# Normalizes so that domain only sees -3, but
559+
# overlap indices are still available in cell_ids
560+
self.ids[self.ids < _OVERLAP] = _OVERLAP # new line
561+
551562
# generate colors if not present
552563
for cell_id, cell in cv.cells.items():
553564
if cell.color is None:

0 commit comments

Comments
 (0)