Skip to content

Commit f8e4ba2

Browse files
committed
Support hashes of model.xml
1 parent 0ac2580 commit f8e4ba2

5 files changed

Lines changed: 67 additions & 59 deletions

File tree

openmc_plotter/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
21
__version__ = '0.3.1'

openmc_plotter/docks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,9 +678,9 @@ def update(self):
678678
self.tallySelector.addItem("None")
679679
for idx, tally in enumerate(self.model.statepoint.tallies.values()):
680680
if tally.name == "":
681-
self.tallySelector.addItem('Tally {}'.format(tally.id), userData=tally.id)
681+
self.tallySelector.addItem(f'Tally {tally.id}', userData=tally.id)
682682
else:
683-
self.tallySelector.addItem('Tally {} "{}"'.format(tally.id, tally.name), userData=tally.id)
683+
self.tallySelector.addItem(f'Tally {tally.id} "{tally.name}"', userData=tally.id)
684684
self.tally_map[idx] = tally
685685
self.updateSelectedTally()
686686
self.updateMinMax()

openmc_plotter/main_window.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import copy
22
from functools import partial
3-
import os
43
import pickle
54
from threading import Thread
65

@@ -20,13 +19,12 @@
2019
except ImportError:
2120
_HAVE_VTK = False
2221

23-
from .plotmodel import PlotModel, DomainTableModel, hash_file
22+
from .plotmodel import PlotModel, DomainTableModel, hash_model
2423
from .plotgui import PlotImage, ColorDialog
2524
from .docks import DomainDock, TallyDock
2625
from .overlays import ShortcutsOverlay
2726
from .tools import ExportDataDialog
2827

29-
_COORD_LEVELS = 0
3028

3129
def _openmcReload(threads=None):
3230
# reset OpenMC memory, instances
@@ -1151,11 +1149,10 @@ def closeEvent(self, event):
11511149

11521150
def saveSettings(self):
11531151
if self.model.statepoint:
1154-
self.model.statepoint.close()
1152+
self.model.statepoint.close()
11551153

1156-
# get hashes for geometry.xml and material.xml at close
1157-
mat_xml_hash = hash_file('materials.xml')
1158-
geom_xml_hash = hash_file('geometry.xml')
1154+
# get hashes for material.xml and geometry.xml at close
1155+
mat_xml_hash, geom_xml_hash = hash_model()
11591156

11601157
pickle_data = {
11611158
'version': self.model.version,

openmc_plotter/plotmodel.py

Lines changed: 59 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from ast import literal_eval
22
from collections import defaultdict
33
import copy
4+
import hashlib
45
import itertools
5-
import threading
66
import os
7+
from pathlib import Path
78
import pickle
8-
import hashlib
9+
import threading
910

1011
from PySide2.QtWidgets import QItemDelegate, QColorDialog, QLineEdit, QMessageBox
1112
from PySide2.QtCore import QAbstractTableModel, QModelIndex, Qt, QSize, QEvent
@@ -18,7 +19,7 @@
1819
from .statepointmodel import StatePointModel
1920
from .plot_colors import random_rgb, reset_seed
2021

21-
ID, NAME, COLOR, COLORLABEL, MASK, HIGHLIGHT = tuple(range(0, 6))
22+
ID, NAME, COLOR, COLORLABEL, MASK, HIGHLIGHT = range(6)
2223

2324
_VOID_REGION = -1
2425
_NOT_FOUND = -2
@@ -28,7 +29,6 @@
2829
_PROPERTY_INDICES = {'temperature': 0, 'density': 1}
2930

3031
_REACTION_UNITS = 'Reactions per Source Particle'
31-
_FLUX_UNITS = 'Particle-cm per Source Particle'
3232
_PRODUCTION_UNITS = 'Particles Produced per Source Particle'
3333
_ENERGY_UNITS = 'eV per Source Particle'
3434

@@ -60,6 +60,7 @@
6060
'Std. Dev.': 'std_dev',
6161
'Rel. Error': 'rel_err'}
6262

63+
6364
def hash_file(filename):
6465
# return the md5 hash of a file
6566
h = hashlib.md5()
@@ -72,47 +73,59 @@ def hash_file(filename):
7273
return h.hexdigest()
7374

7475

75-
class PlotModel():
76-
""" Geometry and plot settings for OpenMC Plot Explorer model
76+
def hash_model():
77+
"""Get hash values for materials.xml and geometry.xml (or model.xml)"""
78+
# TODO: Add support for model in file other than model.xml
79+
if Path('model.xml').is_file():
80+
mat_xml_hash = hash_file('model.xml')
81+
geom_xml_hash = ""
82+
else:
83+
mat_xml_hash = hash_file('materials.xml')
84+
geom_xml_hash = hash_file('geometry.xml')
85+
return mat_xml_hash, geom_xml_hash
7786

78-
Parameters
79-
----------
80-
use_settings_pkl : bool
81-
If True, use plot_settings.pkl file to reload settings
8287

83-
Attributes
84-
----------
85-
geom : openmc.Geometry instance
86-
OpenMC Geometry of the model
87-
modelCells : collections.OrderedDict
88-
Dictionary mapping cell IDs to openmc.Cell instances
89-
modelMaterials : collections.OrderedDict
90-
Dictionary mapping material IDs to openmc.Material instances
91-
ids : NumPy int array (v_res, h_res, 1)
92-
Mapping of plot coordinates to cell/material ID by pixel
93-
ids_map : NumPy int32 array (v_res, h_res, 3)
94-
Mapping of cell and material ids
95-
properties : Numpy float array (v_res, h_res, 3)
96-
Mapping of cell temperatures and material densities
97-
image : NumPy int array (v_res, h_res, 3)
98-
The current RGB image data
99-
statepoint : StatePointModel
100-
Simulation data model used to display tally results
101-
applied_filters : tuple of ints
102-
IDs of the applied filters for the displayed tally
103-
previousViews : list of PlotView instances
104-
List of previously created plot view settings used to undo
105-
changes made in plot explorer
106-
subsequentViews : list of PlotView instances
107-
List of undone plot view settings used to redo changes made
108-
in plot explorer
109-
defaultView : PlotView instance
110-
Default settings for given geometry
111-
currentView : PlotView instance
112-
Currently displayed plot settings in plot explorer
113-
activeView : PlotView instance
114-
Active state of settings in plot explorer, which may or may not
115-
have unapplied changes
88+
class PlotModel:
89+
"""Geometry and plot settings for OpenMC Plot Explorer model
90+
91+
Parameters
92+
----------
93+
use_settings_pkl : bool
94+
If True, use plot_settings.pkl file to reload settings
95+
96+
Attributes
97+
----------
98+
geom : openmc.Geometry
99+
OpenMC Geometry of the model
100+
modelCells : collections.OrderedDict
101+
Dictionary mapping cell IDs to openmc.Cell instances
102+
modelMaterials : collections.OrderedDict
103+
Dictionary mapping material IDs to openmc.Material instances
104+
ids : NumPy int array (v_res, h_res, 1)
105+
Mapping of plot coordinates to cell/material ID by pixel
106+
ids_map : NumPy int32 array (v_res, h_res, 3)
107+
Mapping of cell and material ids
108+
properties : Numpy float array (v_res, h_res, 3)
109+
Mapping of cell temperatures and material densities
110+
image : NumPy int array (v_res, h_res, 3)
111+
The current RGB image data
112+
statepoint : StatePointModel
113+
Simulation data model used to display tally results
114+
applied_filters : tuple of ints
115+
IDs of the applied filters for the displayed tally
116+
previousViews : list of PlotView instances
117+
List of previously created plot view settings used to undo
118+
changes made in plot explorer
119+
subsequentViews : list of PlotView instances
120+
List of undone plot view settings used to redo changes made
121+
in plot explorer
122+
defaultView : PlotView
123+
Default settings for given geometry
124+
currentView : PlotView
125+
Currently displayed plot settings in plot explorer
126+
activeView : PlotView
127+
Active state of settings in plot explorer, which may or may not
128+
have unapplied changes
116129
"""
117130

118131
def __init__(self, use_settings_pkl):
@@ -176,8 +189,7 @@ def __init__(self, use_settings_pkl):
176189

177190
# get materials.xml and geometry.xml hashes to
178191
# restore additional settings if possible
179-
mat_xml_hash = hash_file('materials.xml')
180-
geom_xml_hash = hash_file('geometry.xml')
192+
mat_xml_hash, geom_xml_hash = hash_model()
181193
if mat_xml_hash == data['mat_xml_hash'] and \
182194
geom_xml_hash == data['geom_xml_hash']:
183195
restore_domains = True
@@ -1071,8 +1083,8 @@ def adopt_plotbase(self, view):
10711083
self.basis = view.basis
10721084

10731085

1074-
class DomainView():
1075-
""" Represents view settings for OpenMC cell or material.
1086+
class DomainView:
1087+
"""Represents view settings for OpenMC cell or material.
10761088
10771089
Parameters
10781090
----------

openmc_plotter/tools.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import copy
2-
from time import sleep
32

43
import numpy as np
54
import openmc
6-
from PySide2 import QtCore, QtGui, QtWidgets
5+
from PySide2 import QtCore, QtWidgets
76

87
from .custom_widgets import HorizontalLine
98
from .scientific_spin_box import ScientificDoubleSpinBox
109

10+
1111
class ExportDataDialog(QtWidgets.QDialog):
1212
"""
1313
A dialog to facilitate generation of VTK files for

0 commit comments

Comments
 (0)