diff --git a/openmc/mesh.py b/openmc/mesh.py index 48263c2055c..f0c0d7414fe 100644 --- a/openmc/mesh.py +++ b/openmc/mesh.py @@ -152,6 +152,7 @@ def get_homogenized_materials( model: openmc.Model, n_samples: int = 10_000, prn_seed: Optional[int] = None, + include_void: bool = True, **kwargs ) -> List[openmc.Material]: """Generate homogenized materials over each element in a mesh. @@ -168,6 +169,8 @@ def get_homogenized_materials( prn_seed : int, optional Pseudorandom number generator (PRNG) seed; if None, one will be generated randomly. + include_void : bool, optional + Whether homogenization should include voids. **kwargs Keyword-arguments passed to :func:`openmc.lib.init`. @@ -222,6 +225,10 @@ def get_homogenized_materials( material_ids.pop(index_void) volumes.pop(index_void) + # If void should be excluded, adjust total volume + if not include_void: + total_volume = sum(volumes) + # Compute volume fractions volume_fracs = np.array(volumes) / total_volume diff --git a/tests/unit_tests/test_mesh.py b/tests/unit_tests/test_mesh.py index 5bacd5fc693..0f7f71ceae1 100644 --- a/tests/unit_tests/test_mesh.py +++ b/tests/unit_tests/test_mesh.py @@ -386,3 +386,9 @@ def test_mesh_get_homogenized_materials(): # Mesh element that overlaps void should have half density assert m4.get_mass_density('H1') == pytest.approx(0.5, rel=1e-2) + + # If not including void, density of homogenized material should be same as + # original material + m5, = mesh_void.get_homogenized_materials( + model, n_samples=1000, include_void=False) + assert m5.get_mass_density('H1') == pytest.approx(1.0)