diff --git a/openmc/geometry.py b/openmc/geometry.py index 4bb6e23e46..02bcbe180d 100644 --- a/openmc/geometry.py +++ b/openmc/geometry.py @@ -63,15 +63,15 @@ class Geometry(object): """ if volume_calc.domain_type == 'cell': - for cell in self.get_all_cells(): + for cell in self.get_all_cells().values(): if cell.id in volume_calc.volumes: cell.add_volume_information(volume_calc) elif volume_calc.domain_type == 'material': - for material in self.get_all_materials(): + for material in self.get_all_materials().values(): if material.id in volume_calc.volumes: material.add_volume_information(volume_calc) elif volume_calc.domain_type == 'universe': - for universe in self.get_all_universes(): + for universe in self.get_all_universes().values(): if universe.id in volume_calc.volumes: universe.add_volume_information(volume_calc) diff --git a/openmc/material.py b/openmc/material.py index cd19225364..92d992a6f6 100644 --- a/openmc/material.py +++ b/openmc/material.py @@ -352,7 +352,7 @@ class Material(object): """ if volume_calc.domain_type == 'material': if self.id in volume_calc.volumes: - self._volume = volume_calc.volumes[self.id] + self._volume = volume_calc.volumes[self.id][0] self._atoms = volume_calc.atoms[self.id] else: raise ValueError('No volume information found for this material.') diff --git a/openmc/universe.py b/openmc/universe.py index 12bef012b9..1c631e7e07 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -184,9 +184,9 @@ class Universe(object): Results from a stochastic volume calculation """ - if volume_calc.domain_type == 'cell': + if volume_calc.domain_type == 'universe': if self.id in volume_calc.volumes: - self._volume = volume_calc.volumes[self.id] + self._volume = volume_calc.volumes[self.id][0] self._atoms = volume_calc.atoms[self.id] else: raise ValueError('No volume information found for this universe.') @@ -441,9 +441,22 @@ class Universe(object): (nuclide, density) """ + nuclides = OrderedDict() - raise NotImplementedError('Determining average nuclide densities over ' - 'an entire universe not yet supported.') + if self._atoms is not None: + volume = self.volume + for name, atoms in self._atoms.items(): + nuclide = openmc.Nuclide(name) + density = 1.0e-24 * atoms[0]/volume # density in atoms/b-cm + nuclides[name] = (nuclide, density) + else: + raise RuntimeError( + 'Volume information is needed to calculate microscopic cross ' + 'sections for universe {}. This can be done by running a ' + 'stochastic volume calculation via the ' + 'openmc.VolumeCalculation object'.format(self.id)) + + return nuclides def get_all_cells(self): """Return all cells that are contained within the universe diff --git a/tests/test_volume_calc/test_volume_calc.py b/tests/test_volume_calc/test_volume_calc.py index 52b474cb7d..003528b0df 100644 --- a/tests/test_volume_calc/test_volume_calc.py +++ b/tests/test_volume_calc/test_volume_calc.py @@ -42,7 +42,7 @@ class VolumeTest(PyAPITestHarness): geometry.export_to_xml() # Set up stochastic volume calculation - ll, ur = openmc.Union(*[c.region for c in root.cells.values()]).bounding_box + ll, ur = root.bounding_box vol_calcs = [ openmc.VolumeCalculation(list(root.cells.values()), 100000), openmc.VolumeCalculation([water, fuel], 100000, ll, ur),