11from ast import literal_eval
22from collections import defaultdict
33import copy
4+ import hashlib
45import itertools
5- import threading
66import os
7+ from pathlib import Path
78import pickle
8- import hashlib
9+ import threading
910
1011from PySide2 .QtWidgets import QItemDelegate , QColorDialog , QLineEdit , QMessageBox
1112from PySide2 .QtCore import QAbstractTableModel , QModelIndex , Qt , QSize , QEvent
1819from .statepointmodel import StatePointModel
1920from .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
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
6060 'Std. Dev.' : 'std_dev' ,
6161 'Rel. Error' : 'rel_err' }
6262
63+
6364def 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 ----------
0 commit comments