mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 22:26:08 -04:00
Rewrite Geometry.get_cell_instance -> Geometry.get_instance
This commit is contained in:
parent
3754a2c173
commit
4cd527cb16
4 changed files with 24 additions and 100 deletions
|
|
@ -422,23 +422,6 @@ class Cell(object):
|
|||
else:
|
||||
raise ValueError('No volume information found for this cell.')
|
||||
|
||||
def get_cell_instance(self, path, distribcell_index):
|
||||
|
||||
# If the Cell is filled by a Material
|
||||
if self.fill_type in ('material', 'distribmat', 'void'):
|
||||
offset = 0
|
||||
|
||||
# If the Cell is filled by a Universe
|
||||
elif self.fill_type == 'universe':
|
||||
offset = self.offsets[distribcell_index-1]
|
||||
offset += self.fill.get_cell_instance(path, distribcell_index)
|
||||
|
||||
# If the Cell is filled by a Lattice
|
||||
else:
|
||||
offset = self.fill.get_cell_instance(path, distribcell_index)
|
||||
|
||||
return offset
|
||||
|
||||
def get_nuclides(self):
|
||||
"""Returns all nuclides in the cell
|
||||
|
||||
|
|
|
|||
|
|
@ -105,53 +105,43 @@ class Geometry(object):
|
|||
"""
|
||||
return self.root_universe.find(point)
|
||||
|
||||
def get_cell_instance(self, path):
|
||||
"""Return the instance number for the final cell in a geometry path.
|
||||
def get_instance(self, path):
|
||||
"""Return the instance number for a cell/material in a geometry path.
|
||||
|
||||
The instance is an index into tally distribcell filter arrays.
|
||||
The instance number is used as an index into distributed
|
||||
material/temperature arrays and tally distribcell filter arrays.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
path : list
|
||||
A list of IDs that form the path to the target. It should begin with
|
||||
0 for the base universe, and should cover every universe, cell, and
|
||||
lattice passed through. For the case of the lattice, a tuple should
|
||||
be provided to indicate which coordinates in the lattice should be
|
||||
entered. This should be in the form: (lat_id, i_x, i_y, i_z)
|
||||
path : str
|
||||
|
||||
The path traversed through the CSG tree to reach a cell or material
|
||||
instance. For example, 'u0->c10->l20(2,2,1)->u5->c5' would indicate
|
||||
the cell instance whose first level is universe 0 and cell 10,
|
||||
second level is lattice 20 position (2,2,1), and third level is
|
||||
universe 5 and cell 5.
|
||||
|
||||
Returns
|
||||
-------
|
||||
instance : int
|
||||
Index in tally results array for distribcell filters
|
||||
int
|
||||
Instance number for the given path
|
||||
|
||||
"""
|
||||
|
||||
# Extract the cell id from the path
|
||||
last_index = path.rfind('>')
|
||||
cell_id = int(path[last_index+1:])
|
||||
last_path = path[last_index+1:]
|
||||
uid = int(last_path[1:])
|
||||
|
||||
# Find the distribcell index of the cell.
|
||||
cells = self.get_all_cells()
|
||||
for cell in cells:
|
||||
if cell.id == cell_id:
|
||||
distribcell_index = cell.distribcell_index
|
||||
break
|
||||
else:
|
||||
raise RuntimeError('Could not find cell {} specified in a \
|
||||
distribcell filter'.format(cell_id))
|
||||
if last_path[0] == 'c':
|
||||
obj = self.get_all_cells()[uid]
|
||||
elif last_path[0] == 'm':
|
||||
obj = self.get_all_materials()[uid]
|
||||
|
||||
# Return memoize'd offset if possible
|
||||
if (path, distribcell_index) in self._offsets:
|
||||
offset = self._offsets[(path, distribcell_index)]
|
||||
|
||||
# Begin recursive call to compute offset starting with the base Universe
|
||||
else:
|
||||
offset = self._root_universe.get_cell_instance(path,
|
||||
distribcell_index)
|
||||
self._offsets[(path, distribcell_index)] = offset
|
||||
|
||||
# Return the final offset
|
||||
return offset
|
||||
try:
|
||||
return obj.paths.index(path)
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
def get_all_cells(self):
|
||||
"""Return all cells in the geometry.
|
||||
|
|
|
|||
|
|
@ -611,34 +611,6 @@ class RectLattice(Lattice):
|
|||
min_depth=2, max_depth=3)
|
||||
self._universes = np.asarray(universes)
|
||||
|
||||
def get_cell_instance(self, path, distribcell_index):
|
||||
# Extract the lattice element from the path
|
||||
next_index = path.index('-')
|
||||
lat_id_indices = path[:next_index]
|
||||
path = path[next_index+2:]
|
||||
|
||||
# Extract the lattice cell indices from the path
|
||||
i1 = lat_id_indices.index('(')
|
||||
i2 = lat_id_indices.index(')')
|
||||
i = lat_id_indices[i1+1:i2]
|
||||
lat_x = int(i.split(',')[0]) - 1
|
||||
lat_y = int(i.split(',')[1]) - 1
|
||||
lat_z = int(i.split(',')[2]) - 1
|
||||
|
||||
# For 2D Lattices
|
||||
if self.ndim == 2:
|
||||
offset = self._offsets[lat_z, lat_y, lat_x, distribcell_index-1]
|
||||
offset += self._universes[lat_x][lat_y].get_cell_instance(
|
||||
path, distribcell_index)
|
||||
|
||||
# For 3D Lattices
|
||||
else:
|
||||
offset = self._offsets[lat_z, lat_y, lat_x, distribcell_index-1]
|
||||
offset += self._universes[lat_z][lat_y][lat_x].get_cell_instance(
|
||||
path, distribcell_index)
|
||||
|
||||
return offset
|
||||
|
||||
def find_element(self, point):
|
||||
"""Determine index of lattice element and local coordinates for a point
|
||||
|
||||
|
|
|
|||
|
|
@ -392,27 +392,6 @@ class Universe(object):
|
|||
|
||||
self._cells.clear()
|
||||
|
||||
def get_cell_instance(self, path, distribcell_index):
|
||||
|
||||
# Pop off the root Universe ID from the path
|
||||
next_index = path.index('-')
|
||||
path = path[next_index+2:]
|
||||
|
||||
# Extract the Cell ID from the path
|
||||
if '-' in path:
|
||||
next_index = path.index('-')
|
||||
cell_id = int(path[:next_index])
|
||||
path = path[next_index+2:]
|
||||
else:
|
||||
cell_id = int(path)
|
||||
path = ''
|
||||
|
||||
# Make a recursive call to the Cell within this Universe
|
||||
offset = self.cells[cell_id].get_cell_instance(path, distribcell_index)
|
||||
|
||||
# Return the offset computed at all nested Universe levels
|
||||
return offset
|
||||
|
||||
def get_nuclides(self):
|
||||
"""Returns all nuclides in the universe
|
||||
|
||||
|
|
@ -553,7 +532,7 @@ class Universe(object):
|
|||
mat = None
|
||||
|
||||
if mat is not None:
|
||||
mat._paths.append(cell_path)
|
||||
mat._paths.append('{}->m{}'.format(cell_path, mat.id))
|
||||
|
||||
# Append current path
|
||||
cell._paths.append(cell_path)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue