diff --git a/openmc/model/model.py b/openmc/model/model.py index 80859c55db4..c8329c2fbbf 100644 --- a/openmc/model/model.py +++ b/openmc/model/model.py @@ -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) @@ -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 @@ -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 @@ -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( diff --git a/tests/unit_tests/test_deplete_coupled_operator.py b/tests/unit_tests/test_deplete_coupled_operator.py index fe79d621b12..ba291e07dd5 100644 --- a/tests/unit_tests/test_deplete_coupled_operator.py +++ b/tests/unit_tests/test_deplete_coupled_operator.py @@ -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