Skip to content

Commit

Permalink
Allow mesh material homogenization to include or exclude voids (openm…
Browse files Browse the repository at this point in the history
  • Loading branch information
paulromano authored and church89 committed Jul 18, 2024
1 parent 33f7af5 commit aca99ec
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions openmc/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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`.
Expand Down Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions tests/unit_tests/test_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit aca99ec

Please sign in to comment.