mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 21:55:41 -04:00
openmc.Material.mix_materials() allows for **kwargs (#3336)
This commit is contained in:
parent
e878933b90
commit
e12c65dff9
2 changed files with 11 additions and 10 deletions
|
|
@ -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()])
|
||||
|
|
|
|||
|
|
@ -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():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue