fix the bug in function differentiate_mats() (#3277)

Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
This commit is contained in:
Skywalker 2025-01-29 03:44:04 +08:00 committed by GitHub
parent 860d739f4c
commit d9c8e594c7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 8 deletions

View file

@ -1199,7 +1199,7 @@ class Model:
diff_volume_method : str
Specifies how the volumes of the new materials should be found.
- None: Do not assign volumes to the new materials (Default)
- 'divide_equally': Divide the original material volume equally between the new materials
- 'divide equally': Divide the original material volume equally between the new materials
- 'match cell': Set the volume of the material to the volume of the cell they fill
"""
self.differentiate_mats(diff_volume_method, depletable_only=True)
@ -1214,7 +1214,7 @@ class Model:
diff_volume_method : str
Specifies how the volumes of the new materials should be found.
- None: Do not assign volumes to the new materials (Default)
- 'divide_equally': Divide the original material volume equally between the new materials
- 'divide equally': Divide the original material volume equally between the new materials
- 'match cell': Set the volume of the material to the volume of the cell they fill
depletable_only : bool
Default is True, only depletable materials will be differentiated. If False, all materials will be
@ -1225,9 +1225,15 @@ class Model:
# Count the number of instances for each cell and material
self.geometry.determine_paths(instances_only=True)
# Get list of materials
if self.materials:
materials = self.materials
else:
materials = list(self.geometry.get_all_materials().values())
# Find all or depletable_only materials which have multiple instance
distribmats = set()
for mat in self.materials:
for mat in materials:
# Differentiate all materials with multiple instances
diff_mat = mat.num_instances > 1
# If depletable_only is True, differentiate only depletable materials
@ -1259,11 +1265,20 @@ class Model:
for cell in self.geometry.get_all_material_cells().values():
if cell.fill in distribmats:
mat = cell.fill
if diff_volume_method != 'match cell':
# Clone materials
if cell.num_instances > 1:
cell.fill = [mat.clone() for _ in range(cell.num_instances)]
elif diff_volume_method == 'match cell':
else:
cell.fill = mat.clone()
cell.fill.volume = cell.volume
# For 'match cell', assign volumes based on the cells
if diff_volume_method == 'match cell':
if cell.fill_type == 'distribmat':
for clone_mat in cell.fill:
clone_mat.volume = cell.volume
else:
cell.fill.volume = cell.volume
if self.materials is not None:
self.materials = openmc.Materials(

View file

@ -114,7 +114,7 @@ def test_diff_volume_method_divide_equally(model_with_volumes):
)
all_cells = list(operator.model.geometry.get_all_cells().values())
assert all_cells[0].fill[0].volume == 51
assert all_cells[1].fill[0].volume == 51
assert all_cells[0].fill.volume == 51
assert all_cells[1].fill.volume == 51
# mat2 is not depletable
assert all_cells[2].fill.volume is None