Skip to content

Commit e12c65d

Browse files
authored
openmc.Material.mix_materials() allows for **kwargs (#3336)
1 parent e878933 commit e12c65d

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

openmc/material.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,7 +1467,7 @@ def to_xml_element(
14671467

14681468
@classmethod
14691469
def mix_materials(cls, materials, fracs: Iterable[float],
1470-
percent_type: str = 'ao', name: str | None = None) -> Material:
1470+
percent_type: str = 'ao', **kwargs) -> Material:
14711471
"""Mix materials together based on atom, weight, or volume fractions
14721472
14731473
.. versionadded:: 0.12
@@ -1482,10 +1482,8 @@ def mix_materials(cls, materials, fracs: Iterable[float],
14821482
Type of percentage, must be one of 'ao', 'wo', or 'vo', to signify atom
14831483
percent (molar percent), weight percent, or volume percent,
14841484
optional. Defaults to 'ao'
1485-
name : str
1486-
The name for the new material, optional. Defaults to concatenated
1487-
names of input materials with percentages indicated inside
1488-
parentheses.
1485+
**kwargs
1486+
Keyword arguments passed to :class:`openmc.Material`
14891487
14901488
Returns
14911489
-------
@@ -1544,10 +1542,11 @@ def mix_materials(cls, materials, fracs: Iterable[float],
15441542
openmc.data.AVOGADRO
15451543

15461544
# Create the new material with the desired name
1547-
if name is None:
1548-
name = '-'.join([f'{m.name}({f})' for m, f in
1545+
if "name" not in kwargs:
1546+
kwargs["name"] = '-'.join([f'{m.name}({f})' for m, f in
15491547
zip(materials, fracs)])
1550-
new_mat = cls(name=name)
1548+
1549+
new_mat = cls(**kwargs)
15511550

15521551
# Compute atom fractions of nuclides and add them to the new material
15531552
tot_nuclides_per_cc = np.sum([dens for dens in nuclides_per_cc.values()])

tests/unit_tests/test_material.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,11 +533,13 @@ def test_mix_materials():
533533
dens4 = 1. / (f0 / m1dens + f1 / m2dens)
534534
dens5 = f0*m1dens + f1*m2dens
535535
m3 = openmc.Material.mix_materials([m1, m2], [f0, f1], percent_type='ao')
536-
m4 = openmc.Material.mix_materials([m1, m2], [f0, f1], percent_type='wo')
537-
m5 = openmc.Material.mix_materials([m1, m2], [f0, f1], percent_type='vo')
536+
m4 = openmc.Material.mix_materials([m1, m2], [f0, f1], percent_type='wo', material_id=999)
537+
m5 = openmc.Material.mix_materials([m1, m2], [f0, f1], percent_type='vo', name='m5')
538538
assert m3.density == pytest.approx(dens3)
539539
assert m4.density == pytest.approx(dens4)
540540
assert m5.density == pytest.approx(dens5)
541+
assert m4.id == 999
542+
assert m5.name == 'm5'
541543

542544

543545
def test_get_activity():

0 commit comments

Comments
 (0)