From acdf287c013dcf70799695307e95e3eb8703687b Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Sun, 19 Feb 2017 21:19:30 -0600 Subject: [PATCH] Allow volume information to be added to materials and universes --- openmc/geometry.py | 8 +++++++ openmc/material.py | 28 ++++++++++++++++++++++ openmc/universe.py | 28 ++++++++++++++++++++++ tests/test_volume_calc/test_volume_calc.py | 3 +-- 4 files changed, 65 insertions(+), 2 deletions(-) diff --git a/openmc/geometry.py b/openmc/geometry.py index a272eec0a..023a7abd5 100644 --- a/openmc/geometry.py +++ b/openmc/geometry.py @@ -63,6 +63,14 @@ class Geometry(object): for cell in self.get_all_cells(): if cell.id in volume_calc.results: cell.add_volume_information(volume_calc) + elif volume_calc.domain_type == 'material': + for material in self.get_all_materials(): + if material.id in volume_calc.results: + material.add_volume_information(volume_calc) + elif volume_calc.domain_type == 'universe': + for universe in self.get_all_universes(): + if universe.id in volume_calc.results: + universe.add_volume_information(volume_calc) def export_to_xml(self, path='geometry.xml'): """Export geometry to an XML file. diff --git a/openmc/material.py b/openmc/material.py index b9705243e..179d43579 100644 --- a/openmc/material.py +++ b/openmc/material.py @@ -71,6 +71,10 @@ class Material(object): The average molar mass of nuclides in the material in units of grams per mol. For example, UO2 with 3 nuclides will have an average molar mass of 270 / 3 = 90 g / mol. + volume_information : dict + Estimate of the volume and total number of atoms of each nuclide from a + stochastic volume calculation. This information is set with the + :meth:`Material.add_volume_information` method. """ @@ -82,6 +86,7 @@ class Material(object): self._density = None self._density_units = '' self._depletable = False + self._volume_information = None # A list of tuples (nuclide, percent, percent type) self._nuclides = [] @@ -226,6 +231,10 @@ class Material(object): # Compute and return the molar mass return mass / moles + @property + def volume_information(self): + return self._volume_information + @id.setter def id(self, material_id): @@ -302,6 +311,25 @@ class Material(object): return material + def add_volume_information(self, volume_calc): + """Add volume information to a material. + + Parameters + ---------- + volume_calc : openmc.VolumeCalculation + Results from a stochastic volume calculation + + """ + if volume_calc.domain_type == 'material': + for mat_id in volume_calc.results: + if mat_id == self.id: + self._volume_information = volume_calc.results[mat_id] + break + else: + raise ValueError('No volume information found for this material.') + else: + raise ValueError('No volume information found for this material.') + def set_density(self, units, density=None): """Set the density of the material diff --git a/openmc/universe.py b/openmc/universe.py index fa850968d..65d09f707 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -42,6 +42,10 @@ class Universe(object): cells : collections.OrderedDict Dictionary whose keys are cell IDs and values are :class:`Cell` instances + volume_information : dict + Estimate of the volume and total number of atoms of each nuclide from a + stochastic volume calculation. This information is set with the + :meth:`Universe.add_volume_information` method. """ @@ -49,6 +53,7 @@ class Universe(object): # Initialize Cell class attributes self.id = universe_id self.name = name + self._volume_information = None # Keys - Cell IDs # Values - Cells @@ -99,6 +104,10 @@ class Universe(object): def cells(self): return self._cells + @property + def volume_information(self): + return self._volume_information + @id.setter def id(self, universe_id): if universe_id is None: @@ -147,6 +156,25 @@ class Universe(object): return universe + def add_volume_information(self, volume_calc): + """Add volume information to a universe. + + Parameters + ---------- + volume_calc : openmc.VolumeCalculation + Results from a stochastic volume calculation + + """ + if volume_calc.domain_type == 'cell': + for univ_id in volume_calc.results: + if univ_id == self.id: + self._volume_information = volume_calc.results[univ_id] + break + else: + raise ValueError('No volume information found for this universe.') + else: + raise ValueError('No volume information found for this universe.') + def find(self, point): """Find cells/universes/lattices which contain a given point diff --git a/tests/test_volume_calc/test_volume_calc.py b/tests/test_volume_calc/test_volume_calc.py index cb4ecc2d7..4461e231d 100644 --- a/tests/test_volume_calc/test_volume_calc.py +++ b/tests/test_volume_calc/test_volume_calc.py @@ -38,8 +38,7 @@ class VolumeTest(PyAPITestHarness): bottom_hemisphere = openmc.Cell(3, fill=water, region=-bottom_sphere & -top_plane) root = openmc.Universe(0, cells=(inside_cyl, top_hemisphere, bottom_hemisphere)) - geometry = openmc.Geometry() - geometry.root_universe = root + geometry = openmc.Geometry(root) geometry.export_to_xml() # Set up stochastic volume calculation