From 7fcc20472690c49cf2b0508b099dc440b6249dc4 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Mon, 23 May 2022 14:43:34 -0500 Subject: [PATCH] Implement Material.get_nuclide_atoms method --- openmc/material.py | 19 +++++++++++++++++++ tests/unit_tests/test_material.py | 10 ++++++++++ 2 files changed, 29 insertions(+) diff --git a/openmc/material.py b/openmc/material.py index 073dab7121..ea42d64b16 100644 --- a/openmc/material.py +++ b/openmc/material.py @@ -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 diff --git a/tests/unit_tests/test_material.py b/tests/unit_tests/test_material.py index 374b5a3d8a..fd0e4f6247 100644 --- a/tests/unit_tests/test_material.py +++ b/tests/unit_tests/test_material.py @@ -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')