openmc.Material.mix_materials() allows for **kwargs (#3336)

This commit is contained in:
Stefano Segantin 2025-03-06 08:44:10 -05:00 committed by GitHub
parent e878933b90
commit e12c65dff9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 10 deletions

View file

@ -1467,7 +1467,7 @@ class Material(IDManagerMixin):
@classmethod
def mix_materials(cls, materials, fracs: Iterable[float],
percent_type: str = 'ao', name: str | None = None) -> Material:
percent_type: str = 'ao', **kwargs) -> Material:
"""Mix materials together based on atom, weight, or volume fractions
.. versionadded:: 0.12
@ -1482,10 +1482,8 @@ class Material(IDManagerMixin):
Type of percentage, must be one of 'ao', 'wo', or 'vo', to signify atom
percent (molar percent), weight percent, or volume percent,
optional. Defaults to 'ao'
name : str
The name for the new material, optional. Defaults to concatenated
names of input materials with percentages indicated inside
parentheses.
**kwargs
Keyword arguments passed to :class:`openmc.Material`
Returns
-------
@ -1544,10 +1542,11 @@ class Material(IDManagerMixin):
openmc.data.AVOGADRO
# Create the new material with the desired name
if name is None:
name = '-'.join([f'{m.name}({f})' for m, f in
if "name" not in kwargs:
kwargs["name"] = '-'.join([f'{m.name}({f})' for m, f in
zip(materials, fracs)])
new_mat = cls(name=name)
new_mat = cls(**kwargs)
# Compute atom fractions of nuclides and add them to the new material
tot_nuclides_per_cc = np.sum([dens for dens in nuclides_per_cc.values()])

View file

@ -533,11 +533,13 @@ def test_mix_materials():
dens4 = 1. / (f0 / m1dens + f1 / m2dens)
dens5 = f0*m1dens + f1*m2dens
m3 = openmc.Material.mix_materials([m1, m2], [f0, f1], percent_type='ao')
m4 = openmc.Material.mix_materials([m1, m2], [f0, f1], percent_type='wo')
m5 = openmc.Material.mix_materials([m1, m2], [f0, f1], percent_type='vo')
m4 = openmc.Material.mix_materials([m1, m2], [f0, f1], percent_type='wo', material_id=999)
m5 = openmc.Material.mix_materials([m1, m2], [f0, f1], percent_type='vo', name='m5')
assert m3.density == pytest.approx(dens3)
assert m4.density == pytest.approx(dens4)
assert m5.density == pytest.approx(dens5)
assert m4.id == 999
assert m5.name == 'm5'
def test_get_activity():