diff --git a/openmc/material.py b/openmc/material.py index b104b374e6..f40ac805f7 100644 --- a/openmc/material.py +++ b/openmc/material.py @@ -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()]) diff --git a/tests/unit_tests/test_material.py b/tests/unit_tests/test_material.py index ec55a77563..cb71cd09be 100644 --- a/tests/unit_tests/test_material.py +++ b/tests/unit_tests/test_material.py @@ -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():