From 46e012de9b50249daf444e267111c0274c65f2ab Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Mon, 12 Oct 2015 17:00:26 -0400 Subject: [PATCH] Added get_all_materials to Cell, Universe and Lattice classes --- openmc/universe.py | 59 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/openmc/universe.py b/openmc/universe.py index f8ecb535c7..61e48f79d7 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -300,6 +300,27 @@ class Cell(object): return cells + def get_all_materials(self): + """Return all materials that are contained within the cell + + Returns + ------- + materials : dict + Dictionary whose keys are material IDs and values are Material instances + + """ + + materials = OrderedDict() + if self.fill_type == 'material': + materials[self.fill.id] = self.fill + + # Append all Cells in each Cell in the Universe to the dictionary + cells = self.get_all_cells() + for cell_id, cell in cells.items(): + materials.update(cell.get_all_materials()) + + return materials + def get_all_universes(self): """Return all universes that are contained within this one if any of its cells are filled with a universe or lattice. @@ -570,6 +591,25 @@ class Universe(object): return cells + def get_all_materials(self): + """Return all materials that are contained within the universe + + Returns + ------- + materials : dict + Dictionary whose keys are material IDs and values are Material instances + + """ + + materials = OrderedDict() + + # Append all Cells in each Cell in the Universe to the dictionary + cells = self.get_all_cells() + for cell_id, cell in cells.items(): + materials.update(cell.get_all_materials()) + + return materials + def get_all_universes(self): """Return all universes that are contained within this one. @@ -775,6 +815,25 @@ class Lattice(object): return cells + def get_all_materials(self): + """Return all materials that are contained within the lattice + + Returns + ------- + materials : dict + Dictionary whose keys are material IDs and values are Material instances + + """ + + materials = OrderedDict() + + # Append all Cells in each Cell in the Universe to the dictionary + cells = self.get_all_cells() + for cell_id, cell in cells.items(): + materials.update(cell.get_all_materials()) + + return materials + def get_all_universes(self): """Return all universes that are contained within the lattice