diff --git a/openmc/filter.py b/openmc/filter.py index f29c540857..53fec898fc 100644 --- a/openmc/filter.py +++ b/openmc/filter.py @@ -1082,7 +1082,12 @@ class MeshMaterialFilter(MeshFilter): A new MeshMaterialFilter instance """ - bins = list(zip(*np.where(volumes._materials > -1))) + # Get flat arrays of material IDs and element indices + mat_ids = volumes._materials[volumes._materials > -1] + elems, _ = np.where(volumes._materials > -1) + + # Stack them into a 2D array of (element, material) pairs + bins = np.column_stack((elems, mat_ids)) return cls(mesh, bins) def __hash__(self): diff --git a/tests/unit_tests/test_filter_meshmaterial.py b/tests/unit_tests/test_filter_meshmaterial.py index 1205332097..a05ed5a120 100644 --- a/tests/unit_tests/test_filter_meshmaterial.py +++ b/tests/unit_tests/test_filter_meshmaterial.py @@ -9,6 +9,7 @@ def test_filter_mesh_material(run_in_tmpdir): materials = [] for i in range(4): mat = openmc.Material() + mat.id = 10*(i+1) mat.add_nuclide('Fe56', 1.0) materials.append(mat) @@ -35,7 +36,7 @@ def test_filter_mesh_material(run_in_tmpdir): # MeshMaterialFilter with corresponding bins vols = mesh.material_volumes(model) mmf = openmc.MeshMaterialFilter.from_volumes(mesh, vols) - expected_bins = [(0, 1), (1, 1), (1, 2), (2, 2), (2, 3), (3, 3), (3, 4), (4, 4)] + expected_bins = [(0, 10), (1, 10), (1, 20), (2, 20), (2, 30), (3, 40), (3, 30), (4, 40)] np.testing.assert_equal(mmf.bins, expected_bins) # Create two tallies, one with a mesh filter and one with mesh-material