From d0243d19c17450d7a640dd2f893f4443b518fbba Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Mon, 14 Mar 2022 23:48:34 -0500 Subject: [PATCH 1/3] Fix filter bin selection performance bug --- openmc_plotter/docks.py | 27 +++++++++++++++++++++------ openmc_plotter/main_window.py | 8 ++------ openmc_plotter/plotmodel.py | 4 ++-- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/openmc_plotter/docks.py b/openmc_plotter/docks.py index e63930e..aac5331 100644 --- a/openmc_plotter/docks.py +++ b/openmc_plotter/docks.py @@ -381,7 +381,6 @@ def _createFilterTree(self, spatial_filters): self.filterTree.setHeaderItem(header) self.filterTree.setItemHidden(header, True) self.filterTree.setColumnCount(1) - self.filterTree.itemChanged.connect(self.updateFilters) self.filter_map = {} self.bin_map = {} @@ -489,8 +488,6 @@ def selectTally(self, tally_label=None): # scores self.score_map = {} - self.scoresListWidget.itemClicked.connect( - self.main_window.updateScores) self.score_map.clear() self.scoresListWidget.clear() @@ -525,7 +522,6 @@ def selectTally(self, tally_label=None): # nuclides self.nuclide_map = {} - self.nuclidesListWidget.itemClicked.connect(self.main_window.updateNuclides) self.nuclide_map.clear() self.nuclidesListWidget.clear() @@ -574,13 +570,27 @@ def updateSelectedTally(self): self.tallySelector.setCurrentIndex(idx) def updateFilters(self): + # if the filters header is checked, uncheck all bins and return applied_filters = defaultdict(tuple) for f, f_item in self.filter_map.items(): if type(f) == openmc.MeshFilter: continue filter_checked = f_item.checkState(0) - if filter_checked != QtCore.Qt.Unchecked: + if filter_checked == QtCore.Qt.Unchecked: + for i in range(f_item.childCount()): + bin_item = f_item.child(i) + bin_item.setCheckState(0, QtCore.Qt.Unchecked) + applied_filters[f] = tuple() + elif filter_checked == QtCore.Qt.Checked: + if isinstance(f, openmc.EnergyFunctionFilter): + bins = [0] + else: + for i in range(f_item.childCount()): + bin_item = f_item.child(i) + bin_item.setCheckState(0, QtCore.Qt.Checked) + applied_filters[f] = tuple(i for i in range(f_item.childCount())) + elif filter_checked == QtCore.Qt.PartiallyChecked: selected_bins = [] if isinstance(f, openmc.EnergyFunctionFilter): bins = [0] @@ -593,7 +603,7 @@ def updateFilters(self): selected_bins.append(idx) applied_filters[f] = tuple(selected_bins) - self.model.appliedFilters = applied_filters + self.model.appliedFilters = applied_filters def updateScores(self): applied_scores = [] @@ -649,6 +659,11 @@ def updateNuclides(self): nuclide_box.setFlags(empty_item.flags() | QtCore.Qt.ItemIsUserCheckable) nuclide_box.setFlags(empty_item.flags() & ~QtCore.Qt.ItemIsSelectable) + def updateModel(self): + self.updateFilters() + self.updateScores() + self.updateNuclides() + def update(self): # update the color form diff --git a/openmc_plotter/main_window.py b/openmc_plotter/main_window.py index 03555f9..bea0e87 100755 --- a/openmc_plotter/main_window.py +++ b/openmc_plotter/main_window.py @@ -585,6 +585,8 @@ def applyChanges(self): if self.model.activeView != self.model.currentView: self.statusBar().showMessage('Generating Plot...') QApplication.processEvents() + if self.model.activeView.selectedTally is not None: + self.tallyDock.updateModel() self.model.storeCurrent() self.model.subsequentViews = [] self.plotIm.generatePixmap() @@ -901,12 +903,6 @@ def editTallyValue(self, event): av = self.model.activeView av.tallyValue = event - def updateScores(self, state): - self.tallyDock.updateScores() - - def updateNuclides(self, state): - self.tallyDock.updateNuclides() - def toggleTallyVisibility(self, state, apply=False): av = self.model.activeView av.tallyDataVisible = bool(state) diff --git a/openmc_plotter/plotmodel.py b/openmc_plotter/plotmodel.py index 4cea483..491f893 100644 --- a/openmc_plotter/plotmodel.py +++ b/openmc_plotter/plotmodel.py @@ -541,8 +541,8 @@ def _do_op(array, tally_value, ax=0): if type(tally_filter) == openmc.MeshFilter: continue - if tally_filter in self.appliedFilters: - selected_bins = self.appliedFilters[tally_filter] + selected_bins = self.appliedFilters[tally_filter] + if selected_bins: # sum filter data for the selected bins data = data[np.array(selected_bins)].sum(axis=0) else: From 7c32ab6aa7c11398b1d82f9d553eb3fdb7124750 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 22 Mar 2022 10:52:36 -0500 Subject: [PATCH 2/3] Update openmc_plotter/docks.py Co-authored-by: Paul Romano --- openmc_plotter/docks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openmc_plotter/docks.py b/openmc_plotter/docks.py index aac5331..052eac7 100644 --- a/openmc_plotter/docks.py +++ b/openmc_plotter/docks.py @@ -589,7 +589,7 @@ def updateFilters(self): for i in range(f_item.childCount()): bin_item = f_item.child(i) bin_item.setCheckState(0, QtCore.Qt.Checked) - applied_filters[f] = tuple(i for i in range(f_item.childCount())) + applied_filters[f] = tuple(range(f_item.childCount())) elif filter_checked == QtCore.Qt.PartiallyChecked: selected_bins = [] if isinstance(f, openmc.EnergyFunctionFilter): From 4dd28aeb5d7cbc0698bf5d7badb1cdf665ddc63e Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 22 Mar 2022 15:54:42 -0500 Subject: [PATCH 3/3] Update openmc_plotter/docks.py Co-authored-by: Paul Romano