From 71631ada048c9ca870765dfbd32c6bbc0c4e623e Mon Sep 17 00:00:00 2001 From: josh Date: Tue, 29 Nov 2022 03:39:39 +0000 Subject: [PATCH 1/2] fix universe's get_nuclide_density without volumes present --- openmc/universe.py | 2 +- tests/unit_tests/test_universe.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/openmc/universe.py b/openmc/universe.py index 94ea5624a..db0d55f21 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -469,7 +469,7 @@ class Universe(UniverseBase): """ nuclides = OrderedDict() - if self._atoms is not None: + if len(self._atoms) > 0: volume = self.volume for name, atoms in self._atoms.items(): nuclide = openmc.Nuclide(name) diff --git a/tests/unit_tests/test_universe.py b/tests/unit_tests/test_universe.py index ab3fd6e33..6f4177f54 100644 --- a/tests/unit_tests/test_universe.py +++ b/tests/unit_tests/test_universe.py @@ -132,3 +132,14 @@ def test_create_xml(cell_with_lattice): assert all(c.get('universe') == str(u.id) for c in cell_elems) assert not (set(c.get('id') for c in cell_elems) ^ set(str(c.id) for c in cells)) + + +def test_get_nuclide_densities(): + surf = openmc.Sphere() + material = openmc.Material() + material.add_elements_from_formula("H2O") + material.set_density("g/cm3", 1) + cell = openmc.Cell(region=-surf,fill=material) + universe = openmc.Universe(cells=[cell]) + with pytest.raises(RuntimeError): + universe.get_nuclide_densities() From 3f83699c225629688d8111e4b1fea9882c744af1 Mon Sep 17 00:00:00 2001 From: josh Date: Wed, 30 Nov 2022 00:59:26 +0000 Subject: [PATCH 2/2] update styling --- openmc/universe.py | 2 +- tests/unit_tests/test_universe.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/openmc/universe.py b/openmc/universe.py index db0d55f21..bdd6e6ec9 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -469,7 +469,7 @@ class Universe(UniverseBase): """ nuclides = OrderedDict() - if len(self._atoms) > 0: + if self._atoms: volume = self.volume for name, atoms in self._atoms.items(): nuclide = openmc.Nuclide(name) diff --git a/tests/unit_tests/test_universe.py b/tests/unit_tests/test_universe.py index 6f4177f54..33c86b150 100644 --- a/tests/unit_tests/test_universe.py +++ b/tests/unit_tests/test_universe.py @@ -139,7 +139,7 @@ def test_get_nuclide_densities(): material = openmc.Material() material.add_elements_from_formula("H2O") material.set_density("g/cm3", 1) - cell = openmc.Cell(region=-surf,fill=material) + cell = openmc.Cell(region=-surf, fill=material) universe = openmc.Universe(cells=[cell]) with pytest.raises(RuntimeError): universe.get_nuclide_densities()