From 9fcdd5e04624793016c72bd3fa90b9fde90a6fc9 Mon Sep 17 00:00:00 2001 From: tjlaboss Date: Tue, 28 Mar 2017 17:50:29 -0400 Subject: [PATCH] Wrote method Geometry.get_all_surface() A method in the vein of `Geometry.get_all_cells()` --- openmc/geometry.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/openmc/geometry.py b/openmc/geometry.py index 598aa43125..f271c9f716 100644 --- a/openmc/geometry.py +++ b/openmc/geometry.py @@ -257,7 +257,49 @@ class Geometry(object): lattices[cell.fill.id] = cell.fill return lattices + + def get_all_surfaces(self): + """ + Return all surfaces used in the geometry + Returns + ------- + collections.OrderedDict + Dictionary mapping lattice IDs to :class:`openmc.Surface` instances + + """ + surfaces = OrderedDict() + + for cell in self.get_all_cells().values(): + self.get_surfaces_from_region(surfaces, cell.region) + return surfaces + + def get_surfaces_from_region(self, surfaces, region): + """ + Recursively find all the surfaces referenced by a region and return them + + Parameters + ---------- + surfaces: collections.OrderedDict + Dictionary mapping lattice IDs to :class:`openmc.Surface` instances + + region: openmc.surface.Region + The region of space defined by Surfaces + Returns + ------- + collections.OrderedDict + Dictionary mapping lattice IDs to :class:`openmc.Surface` instances + + """ + if isinstance(region, openmc.Halfspace): + s = region.surface + if s.id not in surfaces: + surfaces[s.id] = s + else: + for reg in region: + surfaces = self.get_surfaces_from_region(surfaces, reg) + return surfaces + def get_materials_by_name(self, name, case_sensitive=False, matching=False): """Return a list of materials with matching names.