From ff198abf3a704767f8195e002b8b5a4e6c2b4f04 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Mon, 2 May 2016 10:41:45 -0600 Subject: [PATCH] Improve constructors for Universe and Cell --- openmc/cell.py | 11 ++++++++++- openmc/universe.py | 10 ++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/openmc/cell.py b/openmc/cell.py index ed1f3178bf..37828d8fce 100644 --- a/openmc/cell.py +++ b/openmc/cell.py @@ -33,6 +33,10 @@ class Cell(object): automatically be assigned. name : str, optional Name of the cell. If not specified, the name is the empty string. + fill : openmc.Material or openmc.Universe or openmc.Lattice or 'void' or iterable of openmc.Material, optional + Indicates what the region of space is filled with + region : openmc.Region, optional + Region of space that is assigned to the cell. Attributes ---------- @@ -58,7 +62,7 @@ class Cell(object): """ - def __init__(self, cell_id=None, name=''): + def __init__(self, cell_id=None, name='', fill=None, region=None): # Initialize Cell class attributes self.id = cell_id self.name = name @@ -70,6 +74,11 @@ class Cell(object): self._offsets = None self._distribcell_index = None + if fill is not None: + self.fill = fill + if region is not None: + self.region = region + def __eq__(self, other): if not isinstance(other, Cell): return False diff --git a/openmc/universe.py b/openmc/universe.py index eb6d13233a..8834eaa526 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -36,6 +36,8 @@ class Universe(object): automatically be assigned name : str, optional Name of the universe. If not specified, the name is the empty string. + cells : Iterable of openmc.Cell + Cells to add to the universe Attributes ---------- @@ -49,7 +51,7 @@ class Universe(object): """ - def __init__(self, universe_id=None, name=''): + def __init__(self, universe_id=None, name='', cells=None): # Initialize Cell class attributes self.id = universe_id self.name = name @@ -61,7 +63,9 @@ class Universe(object): # Keys - Cell IDs # Values - Offsets self._cell_offsets = OrderedDict() - self._num_regions = 0 + + if cells is not None: + self.add_cells(cells) def __eq__(self, other): if not isinstance(other, Universe): @@ -87,8 +91,6 @@ class Universe(object): string += '{0: <16}{1}{2}\n'.format('\tName', '=\t', self._name) string += '{0: <16}{1}{2}\n'.format('\tCells', '=\t', list(self._cells.keys())) - string += '{0: <16}{1}{2}\n'.format('\t# Regions', '=\t', - self._num_regions) return string @property