From 60732fd7dfeacbc5f92e2b769a19caf10658d5d8 Mon Sep 17 00:00:00 2001 From: Sterling Harper Date: Sat, 9 Jan 2016 19:36:53 -0500 Subject: [PATCH] Enable distributed materials in PyAPI --- openmc/geometry.py | 7 +++++-- openmc/universe.py | 12 +++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/openmc/geometry.py b/openmc/geometry.py index fc8e19f071..9788671f5c 100644 --- a/openmc/geometry.py +++ b/openmc/geometry.py @@ -1,4 +1,4 @@ -from collections import OrderedDict +from collections import Iterable, OrderedDict from xml.etree import ElementTree as ET import openmc @@ -140,7 +140,10 @@ class Geometry(object): materials = set() for cell in material_cells: - materials.add(cell._fill) + if isinstance(cell.fill, Iterable): + for m in cell.fill: materials.add(m) + else: + materials.add(cell.fill) materials = list(materials) materials.sort(key=lambda x: x.id) diff --git a/openmc/universe.py b/openmc/universe.py index 8417f27c71..2fa535265c 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -50,7 +50,7 @@ class Cell(object): Unique identifier for the cell name : str Name of the cell - fill : Material or Universe or Lattice or 'void' + fill : Materials or Universe or Lattice or 'void' Indicates what the region of space is filled with region : openmc.region.Region Region of space that is assigned to the cell. @@ -112,6 +112,9 @@ class Cell(object): if isinstance(self._fill, openmc.Material): string += '{0: <16}{1}{2}\n'.format('\tMaterial', '=\t', self._fill._id) + elif isinstance(self._fill, Iterable): + string += ('{0: <16}{1}'.format('\tMaterial', '=\t') + + '[' + ', '.join([str(m.id) for m in self.fill]) + ']\n') elif isinstance(self._fill, (Universe, Lattice)): string += '{0: <16}{1}{2}\n'.format('\tFill', '=\t', self._fill._id) @@ -205,6 +208,10 @@ class Cell(object): elif isinstance(fill, openmc.Material): self._type = 'normal' + elif isinstance(fill, Iterable): + cv.check_type('cell.fill', fill, Iterable, openmc.Material) + self._type = 'normal' + elif isinstance(fill, Universe): self._type = 'fill' @@ -394,6 +401,9 @@ class Cell(object): if isinstance(self._fill, openmc.Material): element.set("material", str(self._fill._id)) + elif isinstance(self._fill, Iterable): + element.set("material", ' '.join([str(m.id) for m in self.fill])) + elif isinstance(self._fill, (Universe, Lattice)): element.set("fill", str(self._fill._id)) self._fill.create_xml_subelement(xml_element)