Some bug fixes for volume calculations

This commit is contained in:
Paul Romano 2017-03-11 14:31:02 -06:00
parent f08c627dab
commit b8f6575cc4
4 changed files with 22 additions and 9 deletions

View file

@ -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)

View file

@ -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.')

View file

@ -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

View file

@ -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),