Skip to content

Commit 4fabed5

Browse files
GuyStenpaulromano
andauthored
fixed a bug in MeshMaterialFilter.from_volumes (#3520)
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
1 parent a64cc96 commit 4fabed5

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

openmc/filter.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,12 @@ def from_volumes(cls, mesh: openmc.MeshBase, volumes: openmc.MeshMaterialVolumes
10821082
A new MeshMaterialFilter instance
10831083
10841084
"""
1085-
bins = list(zip(*np.where(volumes._materials > -1)))
1085+
# Get flat arrays of material IDs and element indices
1086+
mat_ids = volumes._materials[volumes._materials > -1]
1087+
elems, _ = np.where(volumes._materials > -1)
1088+
1089+
# Stack them into a 2D array of (element, material) pairs
1090+
bins = np.column_stack((elems, mat_ids))
10861091
return cls(mesh, bins)
10871092

10881093
def __hash__(self):

tests/unit_tests/test_filter_meshmaterial.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ def test_filter_mesh_material(run_in_tmpdir):
99
materials = []
1010
for i in range(4):
1111
mat = openmc.Material()
12+
mat.id = 10*(i+1)
1213
mat.add_nuclide('Fe56', 1.0)
1314
materials.append(mat)
1415

@@ -35,7 +36,7 @@ def test_filter_mesh_material(run_in_tmpdir):
3536
# MeshMaterialFilter with corresponding bins
3637
vols = mesh.material_volumes(model)
3738
mmf = openmc.MeshMaterialFilter.from_volumes(mesh, vols)
38-
expected_bins = [(0, 1), (1, 1), (1, 2), (2, 2), (2, 3), (3, 3), (3, 4), (4, 4)]
39+
expected_bins = [(0, 10), (1, 10), (1, 20), (2, 20), (2, 30), (3, 40), (3, 30), (4, 40)]
3940
np.testing.assert_equal(mmf.bins, expected_bins)
4041

4142
# Create two tallies, one with a mesh filter and one with mesh-material

0 commit comments

Comments
 (0)