mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 05:35:49 -04:00
Implement distributed paths
This commit is contained in:
parent
c6348700ce
commit
fd7fa59192
4 changed files with 39 additions and 53 deletions
|
|
@ -110,9 +110,9 @@ class Cell(object):
|
|||
self._offsets = None
|
||||
self._distribcell_index = None
|
||||
self._distribcell_paths = None
|
||||
self._paths = []
|
||||
self._volume = None
|
||||
self._atoms = None
|
||||
self._num_instances = None
|
||||
|
||||
def __contains__(self, point):
|
||||
if self.region is None:
|
||||
|
|
@ -233,13 +233,16 @@ class Cell(object):
|
|||
def volume(self):
|
||||
return self._volume
|
||||
|
||||
@property
|
||||
def paths(self):
|
||||
if not self._paths:
|
||||
raise ValueError('Cell instance paths have not been determined. '
|
||||
'Call the Geometry.determine_paths() method.')
|
||||
return self._paths
|
||||
|
||||
@property
|
||||
def num_instances(self):
|
||||
if self._num_instances is None:
|
||||
raise ValueError('The number of cell instances is unknown. Call '
|
||||
'the Geometry.count_cell_instances() method.')
|
||||
else:
|
||||
return self._num_instances
|
||||
return len(self.paths)
|
||||
|
||||
@id.setter
|
||||
def id(self, cell_id):
|
||||
|
|
|
|||
|
|
@ -450,24 +450,15 @@ class Geometry(object):
|
|||
lattices.sort(key=lambda x: x.id)
|
||||
return lattices
|
||||
|
||||
def count_cell_instances(self):
|
||||
def determine_paths(self):
|
||||
"""Count the number of instances for each cell in the Geometry, and
|
||||
record the count in the :attr:`Cell.num_instances` properties."""
|
||||
|
||||
# (Re-)initialize all cell instances to 0
|
||||
for cell in self.get_all_cells().values():
|
||||
cell._num_instances = 0
|
||||
|
||||
# Recursively traverse the CSG tree to count all cell instances
|
||||
self.root_universe._count_cell_instances()
|
||||
|
||||
def count_material_instances(self):
|
||||
"""Count the number of instances for each material in the Geometry, and
|
||||
record the count in the :attr:`Material.num_instances` properties."""
|
||||
|
||||
# (Re-)initialize all material instances to 0
|
||||
cell._paths = []
|
||||
for material in self.get_all_materials().values():
|
||||
material._num_instances = 0
|
||||
material._paths = []
|
||||
|
||||
# Recursively traverse the CSG tree to count all cell instances
|
||||
self.root_universe._count_material_instances()
|
||||
self.root_universe._determine_paths()
|
||||
|
|
|
|||
|
|
@ -90,9 +90,9 @@ class Material(object):
|
|||
self._density = None
|
||||
self._density_units = ''
|
||||
self._depletable = False
|
||||
self._paths = []
|
||||
self._volume = None
|
||||
self._atoms = {}
|
||||
self._num_instances = None
|
||||
|
||||
# A list of tuples (nuclide, percent, percent type)
|
||||
self._nuclides = []
|
||||
|
|
@ -200,13 +200,16 @@ class Material(object):
|
|||
def depletable(self):
|
||||
return self._depletable
|
||||
|
||||
@property
|
||||
def paths(self):
|
||||
if not self._paths:
|
||||
raise ValueError('Material instance paths have not been determined. '
|
||||
'Call the Geometry.determine_paths() method.')
|
||||
return self._paths
|
||||
|
||||
@property
|
||||
def num_instances(self):
|
||||
if self._num_instances is None:
|
||||
raise ValueError('The number of cell instances is unknown. Call '
|
||||
'the Geometry.count_cell_instances() method.')
|
||||
else:
|
||||
return self._num_instances
|
||||
return len(self.paths)
|
||||
|
||||
@property
|
||||
def elements(self):
|
||||
|
|
|
|||
|
|
@ -520,17 +520,18 @@ class Universe(object):
|
|||
cell_element.set("universe", str(self._id))
|
||||
xml_element.append(cell_element)
|
||||
|
||||
def _count_cell_instances(self):
|
||||
def _determine_paths(self, path=''):
|
||||
"""Count the number of instances for each cell in the universe, and
|
||||
record the count in the :attr:`Cell.num_instances` properties."""
|
||||
|
||||
univ_path = path + 'u{}'.format(self.id)
|
||||
|
||||
for cell in self.cells.values():
|
||||
# Increment the number of cell instances
|
||||
cell._num_instances += 1
|
||||
cell_path = '{}->c{}'.format(univ_path, cell.id)
|
||||
|
||||
# If universe-filled, recursively count cells in filling universe
|
||||
if cell.fill_type == 'universe':
|
||||
cell.fill._count_cell_instances()
|
||||
cell.fill._determine_paths(cell_path + '->')
|
||||
|
||||
# If lattice-filled, recursively call for all universes in lattice
|
||||
elif cell.fill_type == 'lattice':
|
||||
|
|
@ -538,34 +539,22 @@ class Universe(object):
|
|||
|
||||
# Count instances in each universe in the lattice
|
||||
for index in latt.indices:
|
||||
latt_path = '{}->l{}{}->'.format(cell_path, latt.id, index)
|
||||
if latt.ndim == 3:
|
||||
univ = latt.universes[index[0]][index[1]][index[2]]
|
||||
else:
|
||||
univ = latt.universes[index[0]][index[1]]
|
||||
univ._count_cell_instances()
|
||||
univ._determine_paths(latt_path)
|
||||
|
||||
def _count_material_instances(self):
|
||||
"""Count the number of instances for each material in the Universe, and
|
||||
record the count in the :attr:`Material.num_instances` properties."""
|
||||
else:
|
||||
if cell.fill_type == 'material':
|
||||
mat = cell.fill
|
||||
elif cell.fill_type == 'distribmat':
|
||||
mat = cell.fill[len(cell._paths)]
|
||||
else:
|
||||
mat = None
|
||||
|
||||
for cell in self.cells.values():
|
||||
if mat is not None:
|
||||
mat._paths.append(cell_path)
|
||||
|
||||
# If material-filled, we are finished with all levels
|
||||
if cell.fill_type == 'material':
|
||||
cell.fill._num_instances += 1
|
||||
|
||||
# If universe-filled, recursively count materials in filling universe
|
||||
elif cell.fill_type == 'universe':
|
||||
cell.fill._count_material_instances()
|
||||
|
||||
# If lattice-filled, recursively call for all universes in lattice
|
||||
elif cell.fill_type == 'lattice':
|
||||
latt = cell.fill
|
||||
|
||||
# Count instances in each universe in the lattice
|
||||
for index in latt.indices:
|
||||
if latt.ndim == 3:
|
||||
univ = latt.universes[index[0]][index[1]][index[2]]
|
||||
else:
|
||||
univ = latt.universes[index[0]][index[1]]
|
||||
univ._count_material_instances()
|
||||
cell._paths.append(univ_path)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue