Skip to content

Commit 845092c

Browse files
authored
Merge pull request #63 from paulromano/import-properties
Ability to import properties (temperature/density)
2 parents bf03181 + 2d56360 commit 845092c

4 files changed

Lines changed: 55 additions & 16 deletions

File tree

openmc_plotter/main_window.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,13 @@ def createMenuBar(self):
190190
self.openStatePointAction.setToolTip('Open statepoint file')
191191
self.openStatePointAction.triggered.connect(self.openStatePoint)
192192

193+
self.importPropertiesAction = QAction("&Import properties...", self)
194+
self.importPropertiesAction.setToolTip("Import properties")
195+
self.importPropertiesAction.triggered.connect(self.importProperties)
196+
193197
self.dataMenu = self.mainMenu.addMenu('D&ata')
194198
self.dataMenu.addAction(self.openStatePointAction)
199+
self.dataMenu.addAction(self.importPropertiesAction)
195200
self.updateDataMenu()
196201

197202
# Edit Menu
@@ -531,6 +536,28 @@ def openStatePoint(self):
531536
self.updateDataMenu()
532537
self.tallyDock.update()
533538

539+
def importProperties(self):
540+
filename, ext = QFileDialog.getOpenFileName(self, "Import properties",
541+
".", "*.h5")
542+
if not filename:
543+
return
544+
545+
try:
546+
openmc.lib.import_properties(filename)
547+
message = 'Imported properties: {}'
548+
except (FileNotFoundError, OSError, openmc.lib.exc.OpenMCError) as e:
549+
message = 'Error opening properties file: {}'
550+
msg_box = QMessageBox()
551+
msg_box.setText(f"Error opening properties file: \n\n {e} \n")
552+
msg_box.setIcon(QMessageBox.Warning)
553+
msg_box.setStandardButtons(QMessageBox.Ok)
554+
msg_box.exec_()
555+
finally:
556+
self.statusBar().showMessage(message.format(filename), 5000)
557+
558+
if self.model.activeView.colorby == 'temperature':
559+
self.applyChanges()
560+
534561
def closeStatePoint(self):
535562
# remove the statepoint object and update the data menu
536563
filename = self.model.statepoint.filename

openmc_plotter/plotgui.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,13 @@ def getIDinfo(self, event):
183183
# check that the position is in the axes view
184184
if 0 <= yPos < self.model.currentView.v_res \
185185
and 0 <= xPos and xPos < self.model.currentView.h_res:
186-
id = self.model.ids[yPos][xPos]
187-
temp = "{:g}".format(self.model.properties[yPos][xPos][0])
188-
density = "{:g}".format(self.model.properties[yPos][xPos][1])
186+
id = self.model.ids[yPos, xPos]
187+
instance = self.model.instances[yPos, xPos]
188+
temp = "{:g}".format(self.model.properties[yPos, xPos, 0])
189+
density = "{:g}".format(self.model.properties[yPos, xPos, 1])
189190
else:
190191
id = _NOT_FOUND
192+
instance = _NOT_FOUND
191193
density = str(_NOT_FOUND)
192194
temp = str(_NOT_FOUND)
193195

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

210-
return id, properties, domain, domain_kind
212+
return id, instance, properties, domain, domain_kind
211213

212214
def mouseDoubleClickEvent(self, event):
213215
xCenter, yCenter = self.getPlotCoords(event.pos())
@@ -219,7 +221,7 @@ def mouseMoveEvent(self, event):
219221
xPlotPos, yPlotPos = self.getPlotCoords(event.pos())
220222

221223
# Show Cell/Material ID, Name in status bar
222-
id, properties, domain, domain_kind = self.getIDinfo(event)
224+
id, instance, properties, domain, domain_kind = self.getIDinfo(event)
223225

224226
domainInfo = ""
225227
tallyInfo = ""
@@ -235,21 +237,29 @@ def mouseMoveEvent(self, event):
235237
temperature = properties['temperature']
236238
density = properties['density']
237239

240+
if instance != _NOT_FOUND and domain_kind == 'Cell':
241+
instanceInfo = f" ({instance})"
242+
else:
243+
instanceInfo = ""
238244
if id == _VOID_REGION:
239245
domainInfo = ("VOID")
240246
elif id == _OVERLAP:
241247
domainInfo = ("OVERLAP")
242248
elif id != _NOT_FOUND and domain[id].name:
243-
domainInfo = ("{} {}: \"{}\"\t Density: {} g/cc\t"
244-
"Temperature: {} K".format(domain_kind,
245-
id,
246-
domain[id].name,
247-
density,
248-
temperature))
249+
domainInfo = ("{} {}{}: \"{}\"\t Density: {} g/cc\t"
250+
"Temperature: {} K".format(
251+
domain_kind,
252+
id,
253+
instanceInfo,
254+
domain[id].name,
255+
density,
256+
temperature
257+
))
249258
elif id != _NOT_FOUND:
250-
domainInfo = ("{} {}\t Density: {} g/cc\t"
259+
domainInfo = ("{} {}{}\t Density: {} g/cc\t"
251260
"Temperature: {} K".format(domain_kind,
252261
id,
262+
instanceInfo,
253263
density,
254264
temperature))
255265
else:
@@ -328,7 +338,7 @@ def contextMenuEvent(self, event):
328338
self.main_window.undoAction.setText('&Undo ({})'.format(len(self.model.previousViews)))
329339
self.main_window.redoAction.setText('&Redo ({})'.format(len(self.model.subsequentViews)))
330340

331-
id, properties, domain, domain_kind = self.getIDinfo(event)
341+
id, instance, properties, domain, domain_kind = self.getIDinfo(event)
332342

333343
cv = self.model.currentView
334344

openmc_plotter/plotmodel.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ def __init__(self):
100100

101101
# Cell/Material ID by coordinates
102102
self.ids = None
103+
self.instances = None
103104

104105
self.version = __VERSION__
105106

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

200201
self.cell_ids = ids[:, :, 0]
201-
self.mat_ids = ids[:, :, 1]
202+
self.instances = ids[:, :, 1]
203+
self.mat_ids = ids[:, :, 2]
202204

203205
# set model ids based on domain
204206
if cv.colorby == 'cell':

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
],
3636

3737
# Dependencies
38-
'python_requires': '>=3.5',
38+
'python_requires': '>=3.6',
3939
'install_requires': [
40-
'openmc>0.12.0', 'numpy', 'matplotlib', 'PySide2'
40+
'openmc>0.12.2', 'numpy', 'matplotlib', 'PySide2'
4141
],
4242
'extras_require': {
4343
'test' : ['pytest', 'pytest-qt'],

0 commit comments

Comments
 (0)