mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 14:15:42 -04:00
Allow mesh material homogenization to include or exclude voids (#3000)
This commit is contained in:
parent
e6c5f56ee2
commit
88f3e4d21f
2 changed files with 13 additions and 0 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue