Skip to content

Commit

Permalink
Merge pull request #63 from paulromano/import-properties
Browse files Browse the repository at this point in the history
Ability to import properties (temperature/density)
  • Loading branch information
pshriwise authored Jul 16, 2021
2 parents bf03181 + 2d56360 commit 845092c
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 16 deletions.
27 changes: 27 additions & 0 deletions openmc_plotter/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,13 @@ def createMenuBar(self):
self.openStatePointAction.setToolTip('Open statepoint file')
self.openStatePointAction.triggered.connect(self.openStatePoint)

self.importPropertiesAction = QAction("&Import properties...", self)
self.importPropertiesAction.setToolTip("Import properties")
self.importPropertiesAction.triggered.connect(self.importProperties)

self.dataMenu = self.mainMenu.addMenu('D&ata')
self.dataMenu.addAction(self.openStatePointAction)
self.dataMenu.addAction(self.importPropertiesAction)
self.updateDataMenu()

# Edit Menu
Expand Down Expand Up @@ -531,6 +536,28 @@ def openStatePoint(self):
self.updateDataMenu()
self.tallyDock.update()

def importProperties(self):
filename, ext = QFileDialog.getOpenFileName(self, "Import properties",
".", "*.h5")
if not filename:
return

try:
openmc.lib.import_properties(filename)
message = 'Imported properties: {}'
except (FileNotFoundError, OSError, openmc.lib.exc.OpenMCError) as e:
message = 'Error opening properties file: {}'
msg_box = QMessageBox()
msg_box.setText(f"Error opening properties file: \n\n {e} \n")
msg_box.setIcon(QMessageBox.Warning)
msg_box.setStandardButtons(QMessageBox.Ok)
msg_box.exec_()
finally:
self.statusBar().showMessage(message.format(filename), 5000)

if self.model.activeView.colorby == 'temperature':
self.applyChanges()

def closeStatePoint(self):
# remove the statepoint object and update the data menu
filename = self.model.statepoint.filename
Expand Down
36 changes: 23 additions & 13 deletions openmc_plotter/plotgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,13 @@ 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]
temp = "{:g}".format(self.model.properties[yPos][xPos][0])
density = "{:g}".format(self.model.properties[yPos][xPos][1])
id = self.model.ids[yPos, xPos]
instance = self.model.instances[yPos, xPos]
temp = "{:g}".format(self.model.properties[yPos, xPos, 0])
density = "{:g}".format(self.model.properties[yPos, xPos, 1])
else:
id = _NOT_FOUND
instance = _NOT_FOUND
density = str(_NOT_FOUND)
temp = str(_NOT_FOUND)

Expand All @@ -207,7 +209,7 @@ def getIDinfo(self, event):
properties = {'density': density,
'temperature': temp}

return id, properties, domain, domain_kind
return id, instance, properties, domain, domain_kind

def mouseDoubleClickEvent(self, event):
xCenter, yCenter = self.getPlotCoords(event.pos())
Expand All @@ -219,7 +221,7 @@ def mouseMoveEvent(self, event):
xPlotPos, yPlotPos = self.getPlotCoords(event.pos())

# Show Cell/Material ID, Name in status bar
id, properties, domain, domain_kind = self.getIDinfo(event)
id, instance, properties, domain, domain_kind = self.getIDinfo(event)

domainInfo = ""
tallyInfo = ""
Expand All @@ -235,21 +237,29 @@ def mouseMoveEvent(self, event):
temperature = properties['temperature']
density = properties['density']

if instance != _NOT_FOUND and domain_kind == 'Cell':
instanceInfo = f" ({instance})"
else:
instanceInfo = ""
if id == _VOID_REGION:
domainInfo = ("VOID")
elif id == _OVERLAP:
domainInfo = ("OVERLAP")
elif id != _NOT_FOUND and domain[id].name:
domainInfo = ("{} {}: \"{}\"\t Density: {} g/cc\t"
"Temperature: {} K".format(domain_kind,
id,
domain[id].name,
density,
temperature))
domainInfo = ("{} {}{}: \"{}\"\t Density: {} g/cc\t"
"Temperature: {} K".format(
domain_kind,
id,
instanceInfo,
domain[id].name,
density,
temperature
))
elif id != _NOT_FOUND:
domainInfo = ("{} {}\t Density: {} g/cc\t"
domainInfo = ("{} {}{}\t Density: {} g/cc\t"
"Temperature: {} K".format(domain_kind,
id,
instanceInfo,
density,
temperature))
else:
Expand Down Expand Up @@ -328,7 +338,7 @@ def contextMenuEvent(self, event):
self.main_window.undoAction.setText('&Undo ({})'.format(len(self.model.previousViews)))
self.main_window.redoAction.setText('&Redo ({})'.format(len(self.model.subsequentViews)))

id, properties, domain, domain_kind = self.getIDinfo(event)
id, instance, properties, domain, domain_kind = self.getIDinfo(event)

cv = self.model.currentView

Expand Down
4 changes: 3 additions & 1 deletion openmc_plotter/plotmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def __init__(self):

# Cell/Material ID by coordinates
self.ids = None
self.instances = None

self.version = __VERSION__

Expand Down Expand Up @@ -198,7 +199,8 @@ def makePlot(self):
props = openmc.lib.property_map(cv)

self.cell_ids = ids[:, :, 0]
self.mat_ids = ids[:, :, 1]
self.instances = ids[:, :, 1]
self.mat_ids = ids[:, :, 2]

# set model ids based on domain
if cv.colorby == 'cell':
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
],

# Dependencies
'python_requires': '>=3.5',
'python_requires': '>=3.6',
'install_requires': [
'openmc>0.12.0', 'numpy', 'matplotlib', 'PySide2'
'openmc>0.12.2', 'numpy', 'matplotlib', 'PySide2'
],
'extras_require': {
'test' : ['pytest', 'pytest-qt'],
Expand Down

0 comments on commit 845092c

Please sign in to comment.