Enable distributed materials in PyAPI

This commit is contained in:
Sterling Harper 2016-01-09 19:36:53 -05:00
parent 20d6cc471a
commit 60732fd7df
2 changed files with 16 additions and 3 deletions

View file

@ -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)

View file

@ -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)