Implement Material.get_nuclide_atoms method

This commit is contained in:
Paul Romano 2022-05-23 14:43:34 -05:00
parent a4f98b489c
commit 7fcc204726
2 changed files with 29 additions and 0 deletions

View file

@ -858,6 +858,25 @@ class Material(IDManagerMixin):
return nuclides
def get_nuclide_atoms(self):
"""Return number of atoms of each nuclide in the material
.. versionadded:: 0.13.1
Returns
-------
dict
Dictionary whose keys are nuclide names and values are number of
atoms present in the material.
"""
if self.volume is None:
raise ValueError("Volume must be set in order to determine atoms.")
atoms = {}
for nuclide, atom_per_bcm in self.get_nuclide_atom_densities().items():
atoms[nuclide] = 1.0e24 * atom_per_bcm * self.volume
return atoms
def get_mass_density(self, nuclide=None):
"""Return mass density of one or all nuclides

View file

@ -294,6 +294,16 @@ def test_get_nuclide_atom_densities(uo2):
assert density > 0
def test_get_nuclide_atoms():
mat = openmc.Material()
mat.add_nuclide('Li6', 1.0)
mat.set_density('atom/cm3', 3.26e20)
mat.volume = 100.0
atoms = mat.get_nuclide_atoms()
assert atoms['Li6'] == pytest.approx(mat.density * mat.volume)
def test_mass():
m = openmc.Material()
m.add_nuclide('Zr90', 1.0, 'wo')