Skip to content

Commit 628993a

Browse files
committed
Address comments from PR review
1 parent 392d4aa commit 628993a

4 files changed

Lines changed: 27 additions & 22 deletions

File tree

include/openmc/tallies/filter_meshmaterial.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class MeshMaterialFilter : public Filter {
7676

7777
void set_mesh(int32_t mesh);
7878

79-
void set_bins(span<ElementMat> bins);
79+
void set_bins(vector<ElementMat>&& bins);
8080

8181
virtual void set_translation(const Position& translation);
8282

@@ -94,7 +94,8 @@ class MeshMaterialFilter : public Filter {
9494
bool translated_ {false}; //!< Whether or not the filter is translated
9595
Position translation_ {0.0, 0.0, 0.0}; //!< Filter translation
9696

97-
//! The indices of the mesh element-material combinations binned by this filter.
97+
//! The indices of the mesh element-material combinations binned by this
98+
//! filter.
9899
vector<ElementMat> bins_;
99100

100101
//! The set of materials used in this filter

openmc/filter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,7 @@ def __repr__(self):
10931093
string = type(self).__name__ + '\n'
10941094
string += '{: <16}=\t{}\n'.format('\tID', self.id)
10951095
string += '{: <16}=\t{}\n'.format('\tMesh ID', self.mesh.id)
1096-
string += '{: <16}=\t{}\n'.format('\tBins', self.bins)
1096+
string += '{: <16}=\n{}\n'.format('\tBins', self.bins)
10971097
string += '{: <16}=\t{}\n'.format('\tTranslation', self.translation)
10981098
return string
10991099

openmc/lib/filter.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
'CellInstanceFilter', 'CollisionFilter', 'DistribcellFilter', 'DelayedGroupFilter',
2222
'EnergyFilter', 'EnergyoutFilter', 'EnergyFunctionFilter', 'LegendreFilter',
2323
'MaterialFilter', 'MaterialFromFilter', 'MeshFilter', 'MeshBornFilter',
24-
'MeshSurfaceFilter', 'MuFilter', 'MuSurfaceFilter', 'ParentNuclideFilter',
25-
'ParticleFilter', 'PolarFilter', 'SphericalHarmonicsFilter',
26-
'SpatialLegendreFilter', 'SurfaceFilter', 'UniverseFilter', 'ZernikeFilter',
27-
'ZernikeRadialFilter', 'filters'
24+
'MeshMaterialFilter', 'MeshSurfaceFilter', 'MuFilter', 'MuSurfaceFilter',
25+
'ParentNuclideFilter', 'ParticleFilter', 'PolarFilter', 'SphericalHarmonicsFilter',
26+
'SpatialLegendreFilter', 'SurfaceFilter', 'TimeFilter', 'UniverseFilter',
27+
'WeightFilter', 'ZernikeFilter', 'ZernikeRadialFilter', 'filters'
2828
]
2929

3030
# Tally functions
@@ -651,6 +651,7 @@ class ZernikeRadialFilter(ZernikeFilter):
651651
'cellborn': CellbornFilter,
652652
'cellfrom': CellfromFilter,
653653
'cellinstance': CellInstanceFilter,
654+
'collision': CollisionFilter,
654655
'delayedgroup': DelayedGroupFilter,
655656
'distribcell': DistribcellFilter,
656657
'energy': EnergyFilter,

src/tallies/filter_meshmaterial.cpp

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#include "openmc/tallies/filter_meshmaterial.h"
22

3+
#include <utility> // for move
4+
35
#include <fmt/core.h>
46

57
#include "openmc/capi.h"
68
#include "openmc/constants.h"
9+
#include "openmc/container_util.h"
710
#include "openmc/error.h"
811
#include "openmc/material.h"
912
#include "openmc/mesh.h"
@@ -30,8 +33,9 @@ void MeshMaterialFilter::from_xml(pugi::xml_node node)
3033

3134
// Get pairs of (element index, material)
3235
auto bins = get_node_array<int32_t>(node, "bins");
33-
if (bins.size() % 2 == 0) {
34-
fatal_error(fmt::format("Size of mesh material bins is not even: {}", bins.size()));
36+
if (bins.size() % 2 != 0) {
37+
fatal_error(
38+
fmt::format("Size of mesh material bins is not even: {}", bins.size()));
3539
}
3640

3741
// Convert into vector of ElementMat
@@ -41,35 +45,34 @@ void MeshMaterialFilter::from_xml(pugi::xml_node node)
4145
int32_t mat_id = bins[2 * i + 1];
4246
auto search = model::material_map.find(mat_id);
4347
if (search == model::material_map.end()) {
44-
throw std::runtime_error {fmt::format(
45-
"Could not find material {} specified on tally filter.", mat_id)};
48+
fatal_error(fmt::format(
49+
"Could not find material {} specified on tally filter.", mat_id));
4650
}
4751
int32_t mat_index = search->second;
4852
element_mats.push_back({element, mat_index});
4953
}
5054

51-
this->set_bins(element_mats);
55+
this->set_bins(std::move(element_mats));
5256

5357
if (check_for_node(node, "translation")) {
5458
set_translation(get_node_array<double>(node, "translation"));
5559
}
5660
}
5761

58-
void MeshMaterialFilter::set_bins(span<ElementMat> bins)
62+
void MeshMaterialFilter::set_bins(vector<ElementMat>&& bins)
5963
{
60-
// Clear existing cells
61-
bins_.clear();
62-
bins_.reserve(bins.size());
64+
// Swap internal bins_ with the provided vector to avoid copying
65+
bins_.swap(bins);
66+
67+
// Clear and update the mapping and vector of materials
6368
materials_.clear();
6469
map_.clear();
65-
66-
// Update cells and mapping
67-
for (auto& x : bins) {
70+
for (std::size_t i = 0; i < bins_.size(); ++i) {
71+
const auto& x = bins_[i];
6872
assert(x.index_mat >= 0);
6973
assert(x.index_mat < model::materials.size());
70-
bins_.push_back(x);
7174
materials_.insert(x.index_mat);
72-
map_[x] = bins_.size() - 1;
75+
map_[x] = i;
7376
}
7477

7578
n_bins_ = bins_.size();
@@ -118,7 +121,7 @@ void MeshMaterialFilter::get_all_bins(
118121
}
119122
} else {
120123
// If current material is not in any bins, don't bother checking
121-
if (contains(materials_, p.material()) {
124+
if (!contains(materials_, p.material())) {
122125
return;
123126
}
124127

0 commit comments

Comments
 (0)