Skip to content

Commit

Permalink
fix the bug in function differentiate_mats() (#3277)
Browse files Browse the repository at this point in the history
Co-authored-by: Paul Romano <[email protected]>
  • Loading branch information
cn-skywalker and paulromano authored Jan 28, 2025
1 parent 860d739 commit d9c8e59
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
27 changes: 21 additions & 6 deletions openmc/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ def differentiate_depletable_mats(self, diff_volume_method: str = None):
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)
Expand All @@ -1214,7 +1214,7 @@ def differentiate_mats(self, diff_volume_method: str = None, depletable_only: bo
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
Expand All @@ -1225,9 +1225,15 @@ def differentiate_mats(self, diff_volume_method: str = None, depletable_only: bo
# 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
Expand Down Expand Up @@ -1259,11 +1265,20 @@ def differentiate_mats(self, diff_volume_method: str = None, depletable_only: bo
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(
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/test_deplete_coupled_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d9c8e59

Please sign in to comment.