mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 21:55:41 -04:00
fixed a bug in MeshMaterialFilter.from_volumes (#3520)
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
This commit is contained in:
parent
a64cc96ed5
commit
4fabed542d
2 changed files with 8 additions and 2 deletions
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue