def from_xml_element(cls, elem, surfaces, materials, get_universe):
        """Generate cell from XML element

        Parameters
        ----------
        elem : xml.etree.ElementTree.Element
            `<cell>` element
        surfaces : dict
            Dictionary mapping surface IDs to :class:`openmc.Surface` instances
        materials : dict
            Dictionary mapping material IDs to :class:`openmc.Material`
            instances (defined in :math:`openmc.Geometry.from_xml`)
        get_universe : function
            Function returning universe (defined in
            :meth:`openmc.Geometry.from_xml`)

        Returns
        -------
        Cell
            Cell instance

        """
        cell_id = int(get_text(elem, 'id'))
        name = get_text(elem, 'name')
        c = cls(cell_id, name)

        # Assign material/distributed materials or fill
        mat_text = get_text(elem, 'material')
        if mat_text is not None:
            mat_ids = mat_text.split()
            if len(mat_ids) > 1:
                c.fill = [materials[i] for i in mat_ids]
            else:
                c.fill = materials[mat_ids[0]]
        else:
            fill_id = int(get_text(elem, 'fill'))
            c.fill = get_universe(fill_id)

        # Assign region
        region = get_text(elem, 'region')
        if region is not None:
            c.region = Region.from_expression(region, surfaces)

        # Check for other attributes
        t = get_text(elem, 'temperature')
        if t is not None:
            if ' ' in t:
                c.temperature = [float(t_i) for t_i in t.split()]
            else:
                c.temperature = float(t)
        for key in ('temperature', 'rotation', 'translation'):
            value = get_text(elem, key)
            if value is not None:
                setattr(c, key, [float(x) for x in value.split()])

        # Add this cell to appropriate universe
        univ_id = int(get_text(elem, 'universe', 0))
        get_universe(univ_id).add_cell(c)
        return c
Beispiel #2
0
    def _read_cells(self):

        # Initialize dictionary for each Cell's fill
        cell_fills = {}

        for key, group in self._f['geometry/cells'].items():
            cell_id = int(key.lstrip('cell '))
            name = group['name'].value.decode() if 'name' in group else ''
            fill_type = group['fill_type'].value.decode()

            if fill_type == 'material':
                fill = group['material'].value
            elif fill_type == 'universe':
                fill = group['fill'].value
            else:
                fill = group['lattice'].value

            region = group['region'].value.decode(
            ) if 'region' in group else ''

            # Create this Cell
            cell = openmc.Cell(cell_id=cell_id, name=name)

            if fill_type == 'universe':
                if 'translation' in group:
                    translation = group['translation'][...]
                    translation = np.asarray(translation, dtype=np.float64)
                    cell.translation = translation

                if 'rotation' in group:
                    rotation = group['rotation'][...]
                    rotation = np.asarray(rotation, dtype=np.int)
                    cell._rotation = rotation

            elif fill_type == 'material':
                cell.temperature = group['temperature'][...]

            # Store Cell fill information for after Universe/Lattice creation
            cell_fills[cell.id] = (fill_type, fill)

            # Generate Region object given infix expression
            if region:
                cell.region = Region.from_expression(region,
                                                     self._fast_surfaces)

            # Add the Cell to the global dictionary of all Cells
            self._fast_cells[cell.id] = cell

        return cell_fills
Beispiel #3
0
    def _read_cells(self):

        # Initialize dictionary for each Cell's fill
        cell_fills = {}

        for key, group in self._f['geometry/cells'].items():
            cell_id = int(key.lstrip('cell '))
            name = group['name'].value.decode() if 'name' in group else ''
            fill_type = group['fill_type'].value.decode()

            if fill_type == 'material':
                fill = group['material'].value
            elif fill_type == 'universe':
                fill = group['fill'].value
            else:
                fill = group['lattice'].value

            region = group['region'].value.decode() if 'region' in group else ''

            # Create this Cell
            cell = openmc.Cell(cell_id=cell_id, name=name)

            if fill_type == 'universe':
                if 'translation' in group:
                    translation = group['translation'][...]
                    translation = np.asarray(translation, dtype=np.float64)
                    cell.translation = translation

                if 'rotation' in group:
                    rotation = group['rotation'][...]
                    rotation = np.asarray(rotation, dtype=np.int)
                    cell._rotation = rotation

            elif fill_type == 'material':
                cell.temperature = group['temperature'][...]

            # Store Cell fill information for after Universe/Lattice creation
            cell_fills[cell.id] = (fill_type, fill)

            # Generate Region object given infix expression
            if region:
                cell.region = Region.from_expression(region, self._fast_surfaces)

            # Add the Cell to the global dictionary of all Cells
            self._fast_cells[cell.id] = cell

        return cell_fills
Beispiel #4
0
    def _read_cells(self):
        self.n_cells = self._f['geometry/n_cells'].value

        # Initialize dictionary for each Cell
        # Keys     - Cell keys
        # Values   - Cell objects
        self.cells = {}

        # Initialize dictionary for each Cell's fill
        # (e.g., Material, Universe or Lattice ID)
        # This dictionary is used later to link the fills with
        # the corresponding objects
        # Keys     - Cell keys
        # Values   - Filling Material, Universe or Lattice ID
        self._cell_fills = {}

        for key in self._f['geometry/cells'].keys():
            if key == 'n_cells':
                continue

            cell_id = int(key.lstrip('cell '))
            index = self._f['geometry/cells'][key]['index'].value
            name = self._f['geometry/cells'][key]['name'].value.decode()
            fill_type = self._f['geometry/cells'][key][
                'fill_type'].value.decode()

            if fill_type == 'normal':
                fill = self._f['geometry/cells'][key]['material'].value
            elif fill_type == 'universe':
                fill = self._f['geometry/cells'][key]['fill'].value
            else:
                fill = self._f['geometry/cells'][key]['lattice'].value

            if 'region' in self._f['geometry/cells'][key].keys():
                region = self._f['geometry/cells'][key]['region'].value.decode(
                )
            else:
                region = []

            # Create this Cell
            cell = openmc.Cell(cell_id=cell_id, name=name)

            if fill_type == 'universe':
                if 'offset' in self._f['geometry/cells'][key]:
                    offset = self._f['geometry/cells'][key]['offset'][...]
                    cell.offsets = offset

                if 'translation' in self._f['geometry/cells'][key]:
                    translation = \
                      self._f['geometry/cells'][key]['translation'][...]
                    translation = np.asarray(translation, dtype=np.float64)
                    cell.translation = translation

                if 'rotation' in self._f['geometry/cells'][key]:
                    rotation = \
                      self._f['geometry/cells'][key]['rotation'][...]
                    rotation = np.asarray(rotation, dtype=np.int)
                    cell.rotation = rotation

            # Store Cell fill information for after Universe/Lattice creation
            self._cell_fills[index] = (fill_type, fill)

            # Generate Region object given infix expression
            if region:
                cell.region = Region.from_expression(
                    region, {s.id: s
                             for s in self.surfaces.values()})

            # Add the Cell to the global dictionary of all Cells
            self.cells[index] = cell
Beispiel #5
0
    def _read_cells(self):
        self.n_cells = self._f['geometry/n_cells'].value

        # Initialize dictionary for each Cell
        # Keys     - Cell keys
        # Values   - Cell objects
        self.cells = {}

        # Initialize dictionary for each Cell's fill
        # (e.g., Material, Universe or Lattice ID)
        # This dictionary is used later to link the fills with
        # the corresponding objects
        # Keys     - Cell keys
        # Values   - Filling Material, Universe or Lattice ID
        self._cell_fills = {}

        for key in self._f['geometry/cells'].keys():
            if key == 'n_cells':
                continue

            cell_id = int(key.lstrip('cell '))
            index = self._f['geometry/cells'][key]['index'].value
            name = self._f['geometry/cells'][key]['name'].value.decode()
            fill_type = self._f['geometry/cells'][key]['fill_type'].value.decode()

            if fill_type == 'normal':
                fill = self._f['geometry/cells'][key]['material'].value
            elif fill_type == 'universe':
                fill = self._f['geometry/cells'][key]['fill'].value
            else:
                fill = self._f['geometry/cells'][key]['lattice'].value

            if 'region' in self._f['geometry/cells'][key].keys():
                region = self._f['geometry/cells'][key]['region'].value.decode()
            else:
                region = []

            # Create this Cell
            cell = openmc.Cell(cell_id=cell_id, name=name)

            if fill_type == 'universe':
                if 'offset' in self._f['geometry/cells'][key]:
                    offset = self._f['geometry/cells'][key]['offset'][...]
                    cell.offsets = offset

                if 'translation' in self._f['geometry/cells'][key]:
                    translation = \
                      self._f['geometry/cells'][key]['translation'][...]
                    translation = np.asarray(translation, dtype=np.float64)
                    cell.translation = translation

                if 'rotation' in self._f['geometry/cells'][key]:
                    rotation = \
                      self._f['geometry/cells'][key]['rotation'][...]
                    rotation = np.asarray(rotation, dtype=np.int)
                    cell.rotation = rotation

            # Store Cell fill information for after Universe/Lattice creation
            self._cell_fills[index] = (fill_type, fill)

            # Generate Region object given infix expression
            if region:
                cell.region = Region.from_expression(
                    region, {s.id: s for s in self.surfaces.values()})

            # Add the Cell to the global dictionary of all Cells
            self.cells[index] = cell