Allow mesh material homogenization to include or exclude voids (#3000)

This commit is contained in:
Paul Romano 2024-06-10 12:19:46 -05:00 committed by GitHub
parent e6c5f56ee2
commit 88f3e4d21f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 0 deletions

View file

@ -152,6 +152,7 @@ class MeshBase(IDManagerMixin, ABC):
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 @@ class MeshBase(IDManagerMixin, ABC):
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 @@ class MeshBase(IDManagerMixin, ABC):
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

View file

@ -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)