Example #1
0
    def _read_lattices(self):
        self.n_lattices = self._f['geometry/n_lattices'].value

        # Initialize lattices for each Lattice
        # Keys     - Lattice keys
        # Values   - Lattice objects
        self.lattices = {}

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

            lattice_id = int(key.lstrip('lattice '))
            index = self._f['geometry/lattices'][key]['index'].value
            name = self._f['geometry/lattices'][key]['name'].value.decode()
            lattice_type = self._f['geometry/lattices'][key][
                'type'].value.decode()

            if 'offsets' in self._f['geometry/lattices'][key]:
                offsets = self._f['geometry/lattices'][key]['offsets'][...]
            else:
                offsets = None

            if lattice_type == 'rectangular':
                dimension = self._f['geometry/lattices'][key]['dimension'][...]
                lower_left = \
                     self._f['geometry/lattices'][key]['lower_left'][...]
                pitch = self._f['geometry/lattices'][key]['pitch'][...]
                outer = self._f['geometry/lattices'][key]['outer'].value

                universe_ids = \
                     self._f['geometry/lattices'][key]['universes'][...]
                universe_ids = np.swapaxes(universe_ids, 0, 1)
                universe_ids = np.swapaxes(universe_ids, 1, 2)

                # Create the Lattice
                lattice = openmc.RectLattice(lattice_id=lattice_id, name=name)
                lattice.dimension = tuple(dimension)
                lattice.lower_left = lower_left
                lattice.pitch = pitch

                # If the Universe specified outer the Lattice is not void (-22)
                if outer != -22:
                    lattice.outer = self.universes[outer]

                # Build array of Universe pointers for the Lattice
                universes = \
                    np.ndarray(tuple(universe_ids.shape), dtype=openmc.Universe)

                for x in range(universe_ids.shape[0]):
                    for y in range(universe_ids.shape[1]):
                        for z in range(universe_ids.shape[2]):
                            universes[x, y, z] = \
                                 self.get_universe_by_id(universe_ids[x, y, z])

                # Transpose, reverse y-dimension for appropriate ordering
                shape = universes.shape
                universes = np.transpose(universes, (1, 0, 2))
                universes.shape = shape
                universes = universes[:, ::-1, :]
                lattice.universes = universes

                if offsets is not None:
                    offsets = np.swapaxes(offsets, 0, 1)
                    offsets = np.swapaxes(offsets, 1, 2)
                    lattice.offsets = offsets

                # Add the Lattice to the global dictionary of all Lattices
                self.lattices[index] = lattice

            if lattice_type == 'hexagonal':
                n_rings = self._f['geometry/lattices'][key]['n_rings'][0]
                n_axial = self._f['geometry/lattices'][key]['n_axial'][0]
                center = self._f['geometry/lattices'][key]['center'][...]
                pitch = self._f['geometry/lattices'][key]['pitch'][...]
                outer = self._f['geometry/lattices'][key]['outer'][0]

                universe_ids = self._f['geometry/lattices'][key]['universes'][
                    ...]

                # Create the Lattice
                lattice = openmc.HexLattice(lattice_id=lattice_id, name=name)
                lattice.num_rings = n_rings
                lattice.num_axial = n_axial
                lattice.center = center
                lattice.pitch = pitch

                # If the Universe specified outer the Lattice is not void (-22)
                if outer != -22:
                    lattice.outer = self.universes[outer]

                # Build array of Universe pointers for the Lattice.  Note that
                # we need to convert between the HDF5's square array of
                # (x, alpha, z) to the Python API's format of a ragged nested
                # list of (z, ring, theta).
                universes = []
                for z in range(lattice.num_axial):
                    # Add a list for this axial level.
                    universes.append([])
                    x = lattice.num_rings - 1
                    a = 2 * lattice.num_rings - 2
                    for r in range(lattice.num_rings - 1, 0, -1):
                        # Add a list for this ring.
                        universes[-1].append([])

                        # Climb down the top-right.
                        for i in range(r):
                            universes[-1][-1].append(universe_ids[z, a, x])
                            x += 1
                            a -= 1

                        # Climb down the right.
                        for i in range(r):
                            universes[-1][-1].append(universe_ids[z, a, x])
                            a -= 1

                        # Climb down the bottom-right.
                        for i in range(r):
                            universes[-1][-1].append(universe_ids[z, a, x])
                            x -= 1

                        # Climb up the bottom-left.
                        for i in range(r):
                            universes[-1][-1].append(universe_ids[z, a, x])
                            x -= 1
                            a += 1

                        # Climb up the left.
                        for i in range(r):
                            universes[-1][-1].append(universe_ids[z, a, x])
                            a += 1

                        # Climb up the top-left.
                        for i in range(r):
                            universes[-1][-1].append(universe_ids[z, a, x])
                            x += 1

                        # Move down to the next ring.
                        a -= 1

                        # Convert the ids into Universe objects.
                        universes[-1][-1] = [
                            self.get_universe_by_id(u_id)
                            for u_id in universes[-1][-1]
                        ]

                    # Handle the degenerate center ring separately.
                    u_id = universe_ids[z, a, x]
                    universes[-1].append([self.get_universe_by_id(u_id)])

                # Add the universes to the lattice.
                if len(pitch) == 2:
                    # Lattice is 3D
                    lattice.universes = universes
                else:
                    # Lattice is 2D; extract the only axial level
                    lattice.universes = universes[0]

                if offsets is not None:
                    lattice.offsets = offsets

                # Add the Lattice to the global dictionary of all Lattices
                self.lattices[index] = lattice
Example #2
0
# Instantiate a Materials and export to XML
materials_file = openmc.Materials(materials.values())
materials_file.cross_sections = './mgxs.h5'
materials_file.export_to_xml()


###############################################################################
#                 Exporting to OpenMC geometry.xml File
###############################################################################

# Instantiate Core boundaries
cells['Core'].region = +surfaces['Core x-min'] & +surfaces['Core y-min'] & \
                       +surfaces['Small Core z-min'] & -surfaces['Core x-max'] & \
                       -surfaces['Core y-max'] & -surfaces['Small Core z-max']

lattices['Core'] = openmc.RectLattice(lattice_id=201, name='3x3 core lattice')
lattices['Core'].dimension = [3,3,9]
lattices['Core'].lower_left = [-32.13, -32.13, -32.13]
lattices['Core'].pitch = [21.42, 21.42, 7.14]
w = universes['Reflector Unrodded Assembly']
x = universes['Reflector Rodded Assembly']
u = universes['UO2 Unrodded Assembly']
v = universes['UO2 Rodded Assembly']
m = universes['MOX Unrodded Assembly']
n = universes['MOX Rodded Assembly']
lattices['Core'].universes = [[[u, m, w], [m, u, w], [w, w, w]]] * 6 + \
                             [[[x, x, w], [x, x, w], [w, w, w]]] * 3

# Add Core lattice to Core cell
cells['Core'].fill = lattices['Core']
Example #3
0
cell5 = openmc.Cell()
cell5.region = +zc2 & -zp11
cell5.fill = water

cell6 = openmc.Cell()
cell6.region = +zc2 & +zp11

u1 = openmc.Universe(cells=(cell1, cell2, cell5, cell6))

all_water = openmc.Cell(region=-zp11, fill=water)
void = openmc.Cell(region=+zp11)
u2 = openmc.Universe(cells=(all_water, void))

#Rectangular Lattices 20*20(x*y)
lattice = openmc.RectLattice()
lattice.lower_left = (0, 0)
lattice.pitch = (1.849, 1.849)
lattice.universes = np.tile(u1, (20, 20))
lattice.outer = u2

#创建堆芯lattice
cell8 = openmc.Cell()
cell8.region = -xp10 & +xp11 & -yp20 & +yp19 & +zp7 & -zp8
cell8.fill = lattice

cell9 = openmc.Cell()
cell9.region = -xp31 & +xp32 & +yp34 & -yp33 & +zp29 & -zp11 & ~cell8.region
cell9.fill = water

#outer
Example #4
0
def generate_geometry(n_rings, n_wedges):
    """ Generates example geometry.

    This function creates the initial geometry, a 9 pin reflective problem.
    One pin, containing gadolinium, is discretized into sectors.

    In addition to what one would do with the general OpenMC geometry code, it
    is necessary to create a dictionary, volume, that maps a cell ID to a
    volume. Further, by naming cells the same as the above materials, the code
    can automatically handle the mapping.

    Parameters
    ----------
    n_rings : int
        Number of rings to generate for the geometry
    n_wedges : int
        Number of wedges to generate for the geometry
    """

    pitch = 1.26197
    r_fuel = 0.412275
    r_gap = 0.418987
    r_clad = 0.476121

    n_pin = 3

    # This table describes the 'fuel' to actual type mapping
    # It's not necessary to do it this way.  Just adjust the initial conditions
    # below.
    mapping = [
        'fuel', 'fuel', 'fuel', 'fuel', 'fuel_gd', 'fuel', 'fuel', 'fuel',
        'fuel'
    ]

    # Form pin cell
    fuel_u, v_segment, v_gap, v_clad = segment_pin(n_rings, n_wedges, r_fuel,
                                                   r_gap, r_clad)

    # Form lattice
    all_water_c = openmc.Cell(name='cool')
    all_water_u = openmc.Universe(cells=(all_water_c, ))

    lattice = openmc.RectLattice()
    lattice.pitch = [pitch] * 2
    lattice.lower_left = [-pitch * n_pin / 2, -pitch * n_pin / 2]
    lattice_array = [[fuel_u for i in range(n_pin)] for j in range(n_pin)]
    lattice.universes = lattice_array
    lattice.outer = all_water_u

    # Bound universe
    x_low = openmc.XPlane(-pitch * n_pin / 2, boundary_type='reflective')
    x_high = openmc.XPlane(pitch * n_pin / 2, boundary_type='reflective')
    y_low = openmc.YPlane(-pitch * n_pin / 2, boundary_type='reflective')
    y_high = openmc.YPlane(pitch * n_pin / 2, boundary_type='reflective')
    z_low = openmc.ZPlane(-10, boundary_type='reflective')
    z_high = openmc.ZPlane(10, boundary_type='reflective')

    # Compute bounding box
    lower_left = [-pitch * n_pin / 2, -pitch * n_pin / 2, -10]
    upper_right = [pitch * n_pin / 2, pitch * n_pin / 2, 10]

    root_c = openmc.Cell(fill=lattice)
    root_c.region = (+x_low & -x_high & +y_low & -y_high & +z_low & -z_high)
    root_u = openmc.Universe(universe_id=0, cells=(root_c, ))
    geometry = openmc.Geometry(root_u)

    v_cool = pitch**2 - (v_gap + v_clad + n_rings * n_wedges * v_segment)

    # Store volumes for later usage
    volume = {'fuel': v_segment, 'gap': v_gap, 'clad': v_clad, 'cool': v_cool}

    return geometry, volume, mapping, lower_left, upper_right
Example #5
0
cell7.fill = moderator

# Instantiate Universe
univ1 = openmc.Universe(universe_id=1)
univ2 = openmc.Universe(universe_id=2)
univ3 = openmc.Universe(universe_id=3)
root = openmc.Universe(universe_id=0, name='root universe')

# Register Cells with Universe
univ1.add_cells([cell2, cell3])
univ2.add_cells([cell4, cell5])
univ3.add_cells([cell6, cell7])
root.add_cell(cell1)

# Instantiate a Lattice
lattice = openmc.RectLattice(lattice_id=5)
lattice.lower_left = [-2., -2.]
lattice.pitch = [1., 1.]
lattice.universes = [[univ1, univ2, univ1, univ2],
                     [univ2, univ3, univ2, univ3],
                     [univ1, univ2, univ1, univ2],
                     [univ2, univ3, univ2, univ3]]

# Fill Cell with the Lattice
cell1.fill = lattice

# Instantiate a Geometry, register the root Universe, and export to XML
geometry = openmc.Geometry(root)
geometry.export_to_xml()

Example #6
0
    def build_cells(self, bc=['reflective'] * 6):
        """Generates a lattice of universes with the same dimensionality
        as the mesh object.  The individual cells/universes produced
        will not have material definitions applied and so downstream code
        will have to apply that information.

        Parameters
        ----------
        bc : iterable of {'reflective', 'periodic', 'transmission', or 'vacuum'}
            Boundary conditions for each of the four faces of a rectangle
            (if aplying to a 2D mesh) or six faces of a parallelepiped
            (if applying to a 3D mesh) provided in the following order:
            [x min, x max, y min, y max, z min, z max].  2-D cells do not
            contain the z min and z max entries.

        Returns
        -------
        root_cell : openmc.Cell
            The cell containing the lattice representing the mesh geometry;
            this cell is a single parallelepiped with boundaries matching
            the outermost mesh boundary with the boundary conditions from bc
            applied.
        cells : iterable of openmc.Cell
            The list of cells within each lattice position mimicking the mesh
            geometry.

        """

        cv.check_length('bc', bc, length_min=4, length_max=6)
        for entry in bc:
            cv.check_value(
                'bc', entry,
                ['transmission', 'vacuum', 'reflective', 'periodic'])

        # Build the cell which will contain the lattice
        xplanes = [
            openmc.XPlane(x0=self.lower_left[0], boundary_type=bc[0]),
            openmc.XPlane(x0=self.upper_right[0], boundary_type=bc[1])
        ]
        if len(self.dimension) == 1:
            yplanes = [
                openmc.YPlane(y0=-1e10, boundary_type='reflective'),
                openmc.YPlane(y0=1e10, boundary_type='reflective')
            ]
        else:
            yplanes = [
                openmc.YPlane(y0=self.lower_left[1], boundary_type=bc[2]),
                openmc.YPlane(y0=self.upper_right[1], boundary_type=bc[3])
            ]

        if len(self.dimension) <= 2:
            # Would prefer to have the z ranges be the max supported float, but
            # these values are apparently different between python and Fortran.
            # Choosing a safe and sane default.
            # Values of +/-1e10 are used here as there seems to be an
            # inconsistency between what numpy uses as the max float and what
            # Fortran expects for a real(8), so this avoids code complication
            # and achieves the same goal.
            zplanes = [
                openmc.ZPlane(z0=-1e10, boundary_type='reflective'),
                openmc.ZPlane(z0=1e10, boundary_type='reflective')
            ]
        else:
            zplanes = [
                openmc.ZPlane(z0=self.lower_left[2], boundary_type=bc[4]),
                openmc.ZPlane(z0=self.upper_right[2], boundary_type=bc[5])
            ]
        root_cell = openmc.Cell()
        root_cell.region = ((+xplanes[0] & -xplanes[1]) &
                            (+yplanes[0] & -yplanes[1]) &
                            (+zplanes[0] & -zplanes[1]))

        # Build the universes which will be used for each of the [i,j,k]
        # locations within the mesh.
        # We will concurrently build cells to assign to these universes
        cells = []
        universes = []
        for [i, j, k] in self.cell_generator():
            cells.append(openmc.Cell())
            universes.append(openmc.Universe())
            universes[-1].add_cell(cells[-1])

        lattice = openmc.RectLattice()
        lattice.lower_left = self.lower_left

        # Assign the universe and rotate to match the indexing expected for
        # the lattice
        lattice.universes = np.rot90(np.reshape(universes, self.dimension))

        if self.width is not None:
            lattice.pitch = self.width
        else:
            dx = ((self.upper_right[0] - self.lower_left[0]) /
                  self.dimension[0])

            if len(self.dimension) == 1:
                lattice.pitch = [dx]
            elif len(self.dimension) == 2:
                dy = ((self.upper_right[1] - self.lower_left[1]) /
                      self.dimension[1])
                lattice.pitch = [dx, dy]
            else:
                dy = ((self.upper_right[1] - self.lower_left[1]) /
                      self.dimension[1])
                dz = ((self.upper_right[2] - self.lower_left[2]) /
                      self.dimension[2])
                lattice.pitch = [dx, dy, dz]

        # Fill Cell with the Lattice
        root_cell.fill = lattice

        return root_cell, cells
Example #7
0
def pwr_assembly():
    """Create a PWR assembly model.

    This model is a reflected 17x17 fuel assembly from the the `BEAVRS
    <http://crpg.mit.edu/research/beavrs>`_ benchmark. The fuel is 2.4 w/o
    enriched UO2 corresponding to a beginning-of-cycle condition. Note that the
    number of particles/batches is initially set very low for testing purposes.

    Returns
    -------
    model : openmc.model.Model
        A PWR assembly model

    """

    model = openmc.model.Model()

    # Define materials.
    fuel = openmc.Material(name='Fuel')
    fuel.set_density('g/cm3', 10.29769)
    fuel.add_nuclide('U234', 4.4843e-6)
    fuel.add_nuclide('U235', 5.5815e-4)
    fuel.add_nuclide('U238', 2.2408e-2)
    fuel.add_nuclide('O16', 4.5829e-2)

    clad = openmc.Material(name='Cladding')
    clad.set_density('g/cm3', 6.55)
    clad.add_nuclide('Zr90', 2.1827e-2)
    clad.add_nuclide('Zr91', 4.7600e-3)
    clad.add_nuclide('Zr92', 7.2758e-3)
    clad.add_nuclide('Zr94', 7.3734e-3)
    clad.add_nuclide('Zr96', 1.1879e-3)

    hot_water = openmc.Material(name='Hot borated water')
    hot_water.set_density('g/cm3', 0.740582)
    hot_water.add_nuclide('H1', 4.9457e-2)
    hot_water.add_nuclide('O16', 2.4672e-2)
    hot_water.add_nuclide('B10', 8.0042e-6)
    hot_water.add_nuclide('B11', 3.2218e-5)
    hot_water.add_s_alpha_beta('c_H_in_H2O')

    # Define the materials file.
    model.materials = (fuel, clad, hot_water)

    # Instantiate ZCylinder surfaces
    fuel_or = openmc.ZCylinder(x0=0, y0=0, r=0.39218, name='Fuel OR')
    clad_or = openmc.ZCylinder(x0=0, y0=0, r=0.45720, name='Clad OR')

    # Create boundary planes to surround the geometry
    pitch = 21.42
    min_x = openmc.XPlane(x0=-pitch/2, boundary_type='reflective')
    max_x = openmc.XPlane(x0=+pitch/2, boundary_type='reflective')
    min_y = openmc.YPlane(y0=-pitch/2, boundary_type='reflective')
    max_y = openmc.YPlane(y0=+pitch/2, boundary_type='reflective')

    # Create a fuel pin universe
    fuel_pin_universe = openmc.Universe(name='Fuel Pin')
    fuel_cell = openmc.Cell(name='fuel', fill=fuel, region=-fuel_or)
    clad_cell = openmc.Cell(name='clad', fill=clad, region=+fuel_or & -clad_or)
    hot_water_cell = openmc.Cell(name='hot water', fill=hot_water, region=+clad_or)
    fuel_pin_universe.add_cells([fuel_cell, clad_cell, hot_water_cell])


    # Create a control rod guide tube universe
    guide_tube_universe = openmc.Universe(name='Guide Tube')
    gt_inner_cell = openmc.Cell(name='guide tube inner water', fill=hot_water,
                                region=-fuel_or)
    gt_clad_cell = openmc.Cell(name='guide tube clad', fill=clad,
                               region=+fuel_or & -clad_or)
    gt_outer_cell = openmc.Cell(name='guide tube outer water', fill=hot_water,
                                region=+clad_or)
    guide_tube_universe.add_cells([gt_inner_cell, gt_clad_cell, gt_outer_cell])

    # Create fuel assembly Lattice
    assembly = openmc.RectLattice(name='Fuel Assembly')
    assembly.pitch = (pitch/17, pitch/17)
    assembly.lower_left = (-pitch/2, -pitch/2)

    # Create array indices for guide tube locations in lattice
    template_x = np.array([5, 8, 11, 3, 13, 2, 5, 8, 11, 14, 2, 5, 8,
                           11, 14, 2, 5, 8, 11, 14, 3, 13, 5, 8, 11])
    template_y = np.array([2, 2, 2, 3, 3, 5, 5, 5, 5, 5, 8, 8, 8, 8,
                           8, 11, 11, 11, 11, 11, 13, 13, 14, 14, 14])

    # Create 17x17 array of universes
    assembly.universes = np.tile(fuel_pin_universe, (17, 17))
    assembly.universes[template_x, template_y] = guide_tube_universe

    # Create root Cell
    root_cell = openmc.Cell(name='root cell', fill=assembly)
    root_cell.region = +min_x & -max_x & +min_y & -max_y

    # Create root Universe
    model.geometry.root_universe = openmc.Universe(name='root universe')
    model.geometry.root_universe.add_cell(root_cell)

    model.settings.batches = 10
    model.settings.inactive = 5
    model.settings.particles = 100
    model.settings.source = openmc.Source(space=openmc.stats.Box(
        [-pitch/2, -pitch/2, -1], [pitch/2, pitch/2, 1], only_fissionable=True))

    plot = openmc.Plot()
    plot.origin = (0.0, 0.0, 0)
    plot.width = (21.42, 21.42)
    plot.pixels = (300, 300)
    plot.color_by = 'material'
    model.plots.append(plot)

    return model
Example #8
0
# Instantiate Universe
univ1 = openmc.Universe(universe_id=1)
univ2 = openmc.Universe(universe_id=2)
univ3 = openmc.Universe(universe_id=3)
univ4 = openmc.Universe(universe_id=5)
root = openmc.Universe(universe_id=0, name='root universe')

# Register Cells with Universe
univ1.add_cells([cell3, cell4])
univ2.add_cells([cell5, cell6])
univ3.add_cells([cell7, cell8])
root.add_cell(cell1)
univ4.add_cell(cell2)

# Instantiate nested Lattices
lattice1 = openmc.RectLattice(lattice_id=4, name='4x4 assembly')
lattice1.lower_left = [-1., -1.]
lattice1.pitch = [1., 1.]
lattice1.universes = [[univ1, univ2], [univ2, univ3]]

lattice2 = openmc.RectLattice(lattice_id=6, name='4x4 core')
lattice2.lower_left = [-2., -2.]
lattice2.pitch = [2., 2.]
lattice2.universes = [[univ4, univ4], [univ4, univ4]]

# Fill Cell with the Lattice
cell1.fill = lattice2
cell2.fill = lattice1

# Instantiate a Geometry, register the root Universe, and export to XML
geometry = openmc.Geometry(root)
Example #9
0
import openmc
import openmc.mgxs
from universes import universes, cells

###############################################################################
#                     Create a dictionary of the assembly lattices
###############################################################################

# Instantiate the Lattices
lattices = {}
lattices['UO2 Unrodded Assembly'] = \
    openmc.RectLattice(lattice_id=101, name='UO2 Unrodded Assembly')
lattices['UO2 Unrodded Assembly'].dimension = [17, 17]
lattices['UO2 Unrodded Assembly'].lower_left = [-10.71, -10.71]
lattices['UO2 Unrodded Assembly'].pitch = [1.26, 1.26]
u = universes['UO2']
g = universes['Guide Tube']
f = universes['Fission Chamber']
lattices['UO2 Unrodded Assembly'].universes = \
    [[u, u, u, u, u, u, u, u, u, u, u, u, u, u, u, u, u],
     [u, u, u, u, u, u, u, u, u, u, u, u, u, u, u, u, u],
     [u, u, u, u, u, g, u, u, g, u, u, g, u, u, u, u, u],
     [u, u, u, g, u, u, u, u, u, u, u, u, u, g, u, u, u],
     [u, u, u, u, u, u, u, u, u, u, u, u, u, u, u, u, u],
     [u, u, g, u, u, g, u, u, g, u, u, g, u, u, g, u, u],
     [u, u, u, u, u, u, u, u, u, u, u, u, u, u, u, u, u],
     [u, u, u, u, u, u, u, u, u, u, u, u, u, u, u, u, u],
     [u, u, g, u, u, g, u, u, f, u, u, g, u, u, g, u, u],
     [u, u, u, u, u, u, u, u, u, u, u, u, u, u, u, u, u],
     [u, u, u, u, u, u, u, u, u, u, u, u, u, u, u, u, u],
     [u, u, g, u, u, g, u, u, g, u, u, g, u, u, g, u, u],
Example #10
0
def create_triso_lattice(trisos, lower_left, pitch, shape, background):
    """Create a lattice containing TRISO particles for optimized tracking.

    Parameters
    ----------
    trisos : list of openmc.model.TRISO
        List of TRISO particles to put in lattice
    lower_left : Iterable of float
        Lower-left Cartesian coordinates of the lattice
    pitch : Iterable of float
        Pitch of the lattice elements in the x-, y-, and z-directions
    shape : Iterable of float
        Number of lattice elements in the x-, y-, and z-directions
    background : openmc.Material
        A background material that is used anywhere within the lattice but
        outside a TRISO particle

    Returns
    -------
    lattice : openmc.RectLattice
        A lattice containing the TRISO particles

    """

    lattice = openmc.RectLattice()
    lattice.lower_left = lower_left
    lattice.pitch = pitch

    indices = list(np.broadcast(*np.ogrid[:shape[2], :shape[1], :shape[0]]))
    triso_locations = {idx: [] for idx in indices}
    for t in trisos:
        for idx in t.classify(lattice):
            if idx in sorted(triso_locations):
                # Create copy of TRISO particle with materials preserved and
                # different cell/surface IDs
                t_copy = copy.deepcopy(t)
                t_copy.id = None
                t_copy.fill = t.fill
                t_copy._surface.id = None
                triso_locations[idx].append(t_copy)
            else:
                warnings.warn('TRISO particle is partially or completely '
                              'outside of the lattice.')

    # Create universes
    universes = np.empty(shape[::-1], dtype=openmc.Universe)
    for idx, triso_list in sorted(triso_locations.items()):
        if len(triso_list) > 0:
            outside_trisos = openmc.Intersection(~t.region for t in triso_list)
            background_cell = openmc.Cell(fill=background,
                                          region=outside_trisos)
        else:
            background_cell = openmc.Cell(fill=background)

        u = openmc.Universe()
        u.add_cell(background_cell)
        for t in triso_list:
            u.add_cell(t)
            iz, iy, ix = idx
            t.center = lattice.get_local_coordinates(t.center, (ix, iy, iz))

        if len(shape) == 2:
            universes[-1 - idx[0], idx[1]] = u
        else:
            universes[idx[0], -1 - idx[1], idx[2]] = u
    lattice.universes = universes

    # Set outer universe
    background_cell = openmc.Cell(fill=background)
    lattice.outer = openmc.Universe(cells=[background_cell])

    return lattice
Example #11
0
    def _build_inputs(self):
        ####################
        # Materials
        ####################

        moderator = openmc.Material(material_id=1)
        moderator.set_density('g/cc', 1.0)
        moderator.add_nuclide('H1', 2.0)
        moderator.add_nuclide('O16', 1.0)

        dense_fuel = openmc.Material(material_id=2)
        dense_fuel.set_density('g/cc', 4.5)
        dense_fuel.add_nuclide('U235', 1.0)

        light_fuel = openmc.Material(material_id=3)
        light_fuel.set_density('g/cc', 2.0)
        light_fuel.add_nuclide('U235', 1.0)

        mats_file = openmc.Materials([moderator, dense_fuel, light_fuel])
        mats_file.export_to_xml()

        ####################
        # Geometry
        ####################

        c1 = openmc.Cell(cell_id=1, fill=moderator)
        mod_univ = openmc.Universe(universe_id=1, cells=[c1])

        r0 = openmc.ZCylinder(r=0.3)
        c11 = openmc.Cell(cell_id=11, region=-r0)
        c11.fill = [dense_fuel, None, light_fuel, dense_fuel]
        c12 = openmc.Cell(cell_id=12, region=+r0, fill=moderator)
        fuel_univ = openmc.Universe(universe_id=11, cells=[c11, c12])

        lat = openmc.RectLattice(lattice_id=101)
        lat.lower_left = [-2.0, -2.0]
        lat.pitch = [2.0, 2.0]
        lat.universes = [[fuel_univ]*2]*2
        lat.outer = mod_univ

        x0 = openmc.XPlane(x0=-3.0)
        x1 = openmc.XPlane(x0=3.0)
        y0 = openmc.YPlane(y0=-3.0)
        y1 = openmc.YPlane(y0=3.0)
        for s in [x0, x1, y0, y1]:
            s.boundary_type = 'reflective'
        c101 = openmc.Cell(cell_id=101, fill=lat)
        c101.region = +x0 & -x1 & +y0 & -y1
        root_univ = openmc.Universe(universe_id=0, cells=[c101])

        geometry = openmc.Geometry(root_univ)
        geometry.export_to_xml()

        ####################
        # Settings
        ####################

        sets_file = openmc.Settings()
        sets_file.batches = 5
        sets_file.inactive = 0
        sets_file.particles = 1000
        sets_file.source = openmc.Source(space=openmc.stats.Box(
            [-1, -1, -1], [1, 1, 1]))
        sets_file.export_to_xml()

        ####################
        # Plots
        ####################

        plot1 = openmc.Plot(plot_id=1)
        plot1.basis = 'xy'
        plot1.color_by = 'cell'
        plot1.filename = 'cellplot'
        plot1.origin = (0, 0, 0)
        plot1.width = (7, 7)
        plot1.pixels = (400, 400)

        plot2 = openmc.Plot(plot_id=2)
        plot2.basis = 'xy'
        plot2.color_by = 'material'
        plot2.filename = 'matplot'
        plot2.origin = (0, 0, 0)
        plot2.width = (7, 7)
        plot2.pixels = (400, 400)

        plots = openmc.Plots([plot1, plot2])
        plots.export_to_xml()
Example #12
0
lattice_left = openmc.XPlane(x0=-10.71)
lattice_right = openmc.XPlane(x0=10.71)
lattice_back = openmc.YPlane(y0=-10.71)
lattice_front = openmc.YPlane(y0=10.71)
lattice_bottom = openmc.ZPlane(z0=-200.0)
lattice_top = openmc.ZPlane(z0=200.0)

# fuel rod cell with 3.6 w/o
u_fuel = openmc.model.pin([fuel_or, clad_ir, clad_or],
                          [fuel_31, helium, zirc4, water_600])

# guide tube
u_gt = openmc.model.pin([gt_ir, gt_or], [water_600, zirc4, water_600])

# Instantiate a Lattice
lattice_2a = openmc.RectLattice()
lattice_2a.lower_left = [-10.71, -10.71]
lattice_2a.pitch = [1.2600, 1.2600]
# 1        2       3      4       5        6       7       8       9       10     11       12      13     14      15      16      17
lattice_2a.universes = [
    [
        u_fuel, u_fuel, u_fuel, u_fuel, u_fuel, u_fuel, u_fuel, u_fuel, u_fuel,
        u_fuel, u_fuel, u_fuel, u_fuel, u_fuel, u_fuel, u_fuel, u_fuel
    ],  # 1
    [
        u_fuel, u_fuel, u_fuel, u_fuel, u_fuel, u_fuel, u_fuel, u_fuel, u_fuel,
        u_fuel, u_fuel, u_fuel, u_fuel, u_fuel, u_fuel, u_fuel, u_fuel
    ],  # 2
    [
        u_fuel, u_fuel, u_fuel, u_fuel, u_fuel, u_gt, u_fuel, u_fuel, u_gt,
        u_fuel, u_fuel, u_gt, u_fuel, u_fuel, u_fuel, u_fuel, u_fuel
Example #13
0
                           universe_id=3, cells=(c27, c28, c29))

c30 = openmc.Cell(cell_id=30, fill=hot_water, region=-s3)
c31 = openmc.Cell(cell_id=31, fill=clad, region=+s3 & -s4)
c32 = openmc.Cell(cell_id=32, fill=hot_water, region=+s4)
tube_hot = openmc.Universe(name='Instrumentation guide tube, hot water',
                           universe_id=4, cells=(c30, c31, c32))

guide_tubes = [(2, 5), (2, 8), (2, 11), (3, 3), (3, 13),
               (5, 2), (5, 5), (5, 8), (5, 11), (5, 14),
               (8, 2), (8, 5), (8, 8), (8, 11), (8, 14),
               (11, 2), (11, 5), (11, 8), (11, 11), (11, 14),
               (13, 3), (13, 13), (14, 5), (14, 8), (14, 11)]

# Define fuel lattices.
l100 = openmc.RectLattice(name='Fuel assembly (lower half)', lattice_id=100)
l100.lower_left = (-10.71, -10.71)
l100.pitch = (1.26, 1.26)
l100.universes = np.tile(fuel_cold, (17, 17))
for position in guide_tubes:
    l100.universes[position] = tube_cold

l101 = openmc.RectLattice(name='Fuel assembly (upper half)', lattice_id=101)
l101.lower_left = (-10.71, -10.71)
l101.pitch = (1.26, 1.26)
l101.universes = np.tile(fuel_hot, (17, 17))
for position in guide_tubes:
    l101.universes[position] = tube_hot

# Define assemblies.
c50 = openmc.Cell(cell_id=50, fill=cold_water, region=+s34 & -s35)
Example #14
0
    def from_hdf5(group, universes):
        """Create lattice from HDF5 group

        Parameters
        ----------
        group : h5py.Group
            Group in HDF5 file
        universes : dict
            Dictionary mapping universe IDs to instances of
            :class:`openmc.Universe`.

        Returns
        -------
        openmc.Lattice
            Instance of lattice subclass

        """
        lattice_id = int(group.name.split('/')[-1].lstrip('lattice '))
        name = group['name'].value.decode() if 'name' in group else ''
        lattice_type = group['type'].value.decode()

        if lattice_type == 'rectangular':
            dimension = group['dimension'][...]
            lower_left = group['lower_left'][...]
            pitch = group['pitch'][...]
            outer = group['outer'].value
            universe_ids = group['universes'][...]

            # Create the Lattice
            lattice = openmc.RectLattice(lattice_id, name)
            lattice.lower_left = lower_left
            lattice.pitch = pitch

            # If the Universe specified outer the Lattice is not void
            if outer >= 0:
                lattice.outer = universes[outer]

            # Build array of Universe pointers for the Lattice
            uarray = np.empty(universe_ids.shape, dtype=openmc.Universe)

            for z in range(universe_ids.shape[0]):
                for y in range(universe_ids.shape[1]):
                    for x in range(universe_ids.shape[2]):
                        uarray[z, y, x] = universes[universe_ids[z, y, x]]

            # Use 2D NumPy array to store lattice universes for 2D lattices
            if len(dimension) == 2:
                uarray = np.squeeze(uarray)
                uarray = np.atleast_2d(uarray)

            # Set the universes for the lattice
            lattice.universes = uarray

        elif lattice_type == 'hexagonal':
            n_rings = group['n_rings'].value
            n_axial = group['n_axial'].value
            center = group['center'][...]
            pitch = group['pitch'][...]
            outer = group['outer'].value

            universe_ids = group['universes'][...]

            # Create the Lattice
            lattice = openmc.HexLattice(lattice_id, name)
            lattice.center = center
            lattice.pitch = pitch

            # If the Universe specified outer the Lattice is not void
            if outer >= 0:
                lattice.outer = universes[outer]

            # Build array of Universe pointers for the Lattice.  Note that
            # we need to convert between the HDF5's square array of
            # (x, alpha, z) to the Python API's format of a ragged nested
            # list of (z, ring, theta).
            uarray = []
            for z in range(n_axial):
                # Add a list for this axial level.
                uarray.append([])
                x = n_rings - 1
                a = 2*n_rings - 2
                for r in range(n_rings - 1, 0, -1):
                    # Add a list for this ring.
                    uarray[-1].append([])

                    # Climb down the top-right.
                    for i in range(r):
                        uarray[-1][-1].append(universe_ids[z, a, x])
                        x += 1
                        a -= 1

                    # Climb down the right.
                    for i in range(r):
                        uarray[-1][-1].append(universe_ids[z, a, x])
                        a -= 1

                    # Climb down the bottom-right.
                    for i in range(r):
                        uarray[-1][-1].append(universe_ids[z, a, x])
                        x -= 1

                    # Climb up the bottom-left.
                    for i in range(r):
                        uarray[-1][-1].append(universe_ids[z, a, x])
                        x -= 1
                        a += 1

                    # Climb up the left.
                    for i in range(r):
                        uarray[-1][-1].append(universe_ids[z, a, x])
                        a += 1

                    # Climb up the top-left.
                    for i in range(r):
                        uarray[-1][-1].append(universe_ids[z, a, x])
                        x += 1

                    # Move down to the next ring.
                    a -= 1

                    # Convert the ids into Universe objects.
                    uarray[-1][-1] = [universes[u_id]
                                      for u_id in uarray[-1][-1]]

                # Handle the degenerate center ring separately.
                u_id = universe_ids[z, a, x]
                uarray[-1].append([universes[u_id]])

            # Add the universes to the lattice.
            if len(pitch) == 2:
                # Lattice is 3D
                lattice.universes = uarray
            else:
                # Lattice is 2D; extract the only axial level
                lattice.universes = uarray[0]

        return lattice
Example #15
0
def pwr_core():
    """Create a PWR full-core model.

    This model is the OECD/NEA Monte Carlo Performance benchmark which is a
    grossly simplified pressurized water reactor (PWR) with 241 fuel
    assemblies. Note that the number of particles/batches is initially set very
    low for testing purposes.

    Returns
    -------
    model : openmc.model.Model
        Full-core PWR model

    """
    model = openmc.model.Model()

    # Define materials.
    fuel = openmc.Material(1, name='UOX fuel')
    fuel.set_density('g/cm3', 10.062)
    fuel.add_nuclide('U234', 4.9476e-6)
    fuel.add_nuclide('U235', 4.8218e-4)
    fuel.add_nuclide('U238', 2.1504e-2)
    fuel.add_nuclide('Xe135', 1.0801e-8)
    fuel.add_nuclide('O16', 4.5737e-2)

    clad = openmc.Material(2, name='Zircaloy')
    clad.set_density('g/cm3', 5.77)
    clad.add_nuclide('Zr90', 0.5145)
    clad.add_nuclide('Zr91', 0.1122)
    clad.add_nuclide('Zr92', 0.1715)
    clad.add_nuclide('Zr94', 0.1738)
    clad.add_nuclide('Zr96', 0.0280)

    cold_water = openmc.Material(3, name='Cold borated water')
    cold_water.set_density('atom/b-cm', 0.07416)
    cold_water.add_nuclide('H1', 2.0)
    cold_water.add_nuclide('O16', 1.0)
    cold_water.add_nuclide('B10', 6.490e-4)
    cold_water.add_nuclide('B11', 2.689e-3)
    cold_water.add_s_alpha_beta('c_H_in_H2O')

    hot_water = openmc.Material(4, name='Hot borated water')
    hot_water.set_density('atom/b-cm', 0.06614)
    hot_water.add_nuclide('H1', 2.0)
    hot_water.add_nuclide('O16', 1.0)
    hot_water.add_nuclide('B10', 6.490e-4)
    hot_water.add_nuclide('B11', 2.689e-3)
    hot_water.add_s_alpha_beta('c_H_in_H2O')

    rpv_steel = openmc.Material(5, name='Reactor pressure vessel steel')
    rpv_steel.set_density('g/cm3', 7.9)
    rpv_steel.add_nuclide('Fe54', 0.05437098, 'wo')
    rpv_steel.add_nuclide('Fe56', 0.88500663, 'wo')
    rpv_steel.add_nuclide('Fe57', 0.0208008, 'wo')
    rpv_steel.add_nuclide('Fe58', 0.00282159, 'wo')
    rpv_steel.add_nuclide('Ni58', 0.0067198, 'wo')
    rpv_steel.add_nuclide('Ni60', 0.0026776, 'wo')
    rpv_steel.add_nuclide('Mn55', 0.01, 'wo')
    rpv_steel.add_nuclide('Cr52', 0.002092475, 'wo')
    rpv_steel.add_nuclide('C0', 0.0025, 'wo')
    rpv_steel.add_nuclide('Cu63', 0.0013696, 'wo')

    lower_rad_ref = openmc.Material(6, name='Lower radial reflector')
    lower_rad_ref.set_density('g/cm3', 4.32)
    lower_rad_ref.add_nuclide('H1', 0.0095661, 'wo')
    lower_rad_ref.add_nuclide('O16', 0.0759107, 'wo')
    lower_rad_ref.add_nuclide('B10', 3.08409e-5, 'wo')
    lower_rad_ref.add_nuclide('B11', 1.40499e-4, 'wo')
    lower_rad_ref.add_nuclide('Fe54', 0.035620772088, 'wo')
    lower_rad_ref.add_nuclide('Fe56', 0.579805982228, 'wo')
    lower_rad_ref.add_nuclide('Fe57', 0.01362750048, 'wo')
    lower_rad_ref.add_nuclide('Fe58', 0.001848545204, 'wo')
    lower_rad_ref.add_nuclide('Ni58', 0.055298376566, 'wo')
    lower_rad_ref.add_nuclide('Mn55', 0.0182870, 'wo')
    lower_rad_ref.add_nuclide('Cr52', 0.145407678031, 'wo')
    lower_rad_ref.add_s_alpha_beta('c_H_in_H2O')

    upper_rad_ref = openmc.Material(7, name='Upper radial reflector / Top plate region')
    upper_rad_ref.set_density('g/cm3', 4.28)
    upper_rad_ref.add_nuclide('H1', 0.0086117, 'wo')
    upper_rad_ref.add_nuclide('O16', 0.0683369, 'wo')
    upper_rad_ref.add_nuclide('B10', 2.77638e-5, 'wo')
    upper_rad_ref.add_nuclide('B11', 1.26481e-4, 'wo')
    upper_rad_ref.add_nuclide('Fe54', 0.035953677186, 'wo')
    upper_rad_ref.add_nuclide('Fe56', 0.585224740891, 'wo')
    upper_rad_ref.add_nuclide('Fe57', 0.01375486056, 'wo')
    upper_rad_ref.add_nuclide('Fe58', 0.001865821363, 'wo')
    upper_rad_ref.add_nuclide('Ni58', 0.055815129186, 'wo')
    upper_rad_ref.add_nuclide('Mn55', 0.0184579, 'wo')
    upper_rad_ref.add_nuclide('Cr52', 0.146766614995, 'wo')
    upper_rad_ref.add_s_alpha_beta('c_H_in_H2O')

    bot_plate = openmc.Material(8, name='Bottom plate region')
    bot_plate.set_density('g/cm3', 7.184)
    bot_plate.add_nuclide('H1', 0.0011505, 'wo')
    bot_plate.add_nuclide('O16', 0.0091296, 'wo')
    bot_plate.add_nuclide('B10', 3.70915e-6, 'wo')
    bot_plate.add_nuclide('B11', 1.68974e-5, 'wo')
    bot_plate.add_nuclide('Fe54', 0.03855611055, 'wo')
    bot_plate.add_nuclide('Fe56', 0.627585036425, 'wo')
    bot_plate.add_nuclide('Fe57', 0.014750478, 'wo')
    bot_plate.add_nuclide('Fe58', 0.002000875025, 'wo')
    bot_plate.add_nuclide('Ni58', 0.059855207342, 'wo')
    bot_plate.add_nuclide('Mn55', 0.0197940, 'wo')
    bot_plate.add_nuclide('Cr52', 0.157390026871, 'wo')
    bot_plate.add_s_alpha_beta('c_H_in_H2O')

    bot_nozzle = openmc.Material(9, name='Bottom nozzle region')
    bot_nozzle.set_density('g/cm3', 2.53)
    bot_nozzle.add_nuclide('H1', 0.0245014, 'wo')
    bot_nozzle.add_nuclide('O16', 0.1944274, 'wo')
    bot_nozzle.add_nuclide('B10', 7.89917e-5, 'wo')
    bot_nozzle.add_nuclide('B11', 3.59854e-4, 'wo')
    bot_nozzle.add_nuclide('Fe54', 0.030411411144, 'wo')
    bot_nozzle.add_nuclide('Fe56', 0.495012237964, 'wo')
    bot_nozzle.add_nuclide('Fe57', 0.01163454624, 'wo')
    bot_nozzle.add_nuclide('Fe58', 0.001578204652, 'wo')
    bot_nozzle.add_nuclide('Ni58', 0.047211231662, 'wo')
    bot_nozzle.add_nuclide('Mn55', 0.0156126, 'wo')
    bot_nozzle.add_nuclide('Cr52', 0.124142524198, 'wo')
    bot_nozzle.add_s_alpha_beta('c_H_in_H2O')

    top_nozzle = openmc.Material(10, name='Top nozzle region')
    top_nozzle.set_density('g/cm3', 1.746)
    top_nozzle.add_nuclide('H1', 0.0358870, 'wo')
    top_nozzle.add_nuclide('O16', 0.2847761, 'wo')
    top_nozzle.add_nuclide('B10', 1.15699e-4, 'wo')
    top_nozzle.add_nuclide('B11', 5.27075e-4, 'wo')
    top_nozzle.add_nuclide('Fe54', 0.02644016154, 'wo')
    top_nozzle.add_nuclide('Fe56', 0.43037146399, 'wo')
    top_nozzle.add_nuclide('Fe57', 0.0101152584, 'wo')
    top_nozzle.add_nuclide('Fe58', 0.00137211607, 'wo')
    top_nozzle.add_nuclide('Ni58', 0.04104621835, 'wo')
    top_nozzle.add_nuclide('Mn55', 0.0135739, 'wo')
    top_nozzle.add_nuclide('Cr52', 0.107931450781, 'wo')
    top_nozzle.add_s_alpha_beta('c_H_in_H2O')

    top_fa = openmc.Material(11, name='Top of fuel assemblies')
    top_fa.set_density('g/cm3', 3.044)
    top_fa.add_nuclide('H1', 0.0162913, 'wo')
    top_fa.add_nuclide('O16', 0.1292776, 'wo')
    top_fa.add_nuclide('B10', 5.25228e-5, 'wo')
    top_fa.add_nuclide('B11', 2.39272e-4, 'wo')
    top_fa.add_nuclide('Zr90', 0.43313403903, 'wo')
    top_fa.add_nuclide('Zr91', 0.09549277374, 'wo')
    top_fa.add_nuclide('Zr92', 0.14759527104, 'wo')
    top_fa.add_nuclide('Zr94', 0.15280552077, 'wo')
    top_fa.add_nuclide('Zr96', 0.02511169542, 'wo')
    top_fa.add_s_alpha_beta('c_H_in_H2O')

    bot_fa = openmc.Material(12, name='Bottom of fuel assemblies')
    bot_fa.set_density('g/cm3', 1.762)
    bot_fa.add_nuclide('H1', 0.0292856, 'wo')
    bot_fa.add_nuclide('O16', 0.2323919, 'wo')
    bot_fa.add_nuclide('B10', 9.44159e-5, 'wo')
    bot_fa.add_nuclide('B11', 4.30120e-4, 'wo')
    bot_fa.add_nuclide('Zr90', 0.3741373658, 'wo')
    bot_fa.add_nuclide('Zr91', 0.0824858164, 'wo')
    bot_fa.add_nuclide('Zr92', 0.1274914944, 'wo')
    bot_fa.add_nuclide('Zr94', 0.1319920622, 'wo')
    bot_fa.add_nuclide('Zr96', 0.0216912612, 'wo')
    bot_fa.add_s_alpha_beta('c_H_in_H2O')

    # Define the materials file.
    model.materials = (fuel, clad, cold_water, hot_water, rpv_steel,
                       lower_rad_ref, upper_rad_ref, bot_plate,
                       bot_nozzle, top_nozzle, top_fa, bot_fa)

    # Define surfaces.
    s1 = openmc.ZCylinder(r=0.41, surface_id=1)
    s2 = openmc.ZCylinder(r=0.475, surface_id=2)
    s3 = openmc.ZCylinder(r=0.56, surface_id=3)
    s4 = openmc.ZCylinder(r=0.62, surface_id=4)
    s5 = openmc.ZCylinder(r=187.6, surface_id=5)
    s6 = openmc.ZCylinder(r=209.0, surface_id=6)
    s7 = openmc.ZCylinder(r=229.0, surface_id=7)
    s8 = openmc.ZCylinder(r=249.0, surface_id=8, boundary_type='vacuum')

    s31 = openmc.ZPlane(z0=-229.0, surface_id=31, boundary_type='vacuum')
    s32 = openmc.ZPlane(z0=-199.0, surface_id=32)
    s33 = openmc.ZPlane(z0=-193.0, surface_id=33)
    s34 = openmc.ZPlane(z0=-183.0, surface_id=34)
    s35 = openmc.ZPlane(z0=0.0, surface_id=35)
    s36 = openmc.ZPlane(z0=183.0, surface_id=36)
    s37 = openmc.ZPlane(z0=203.0, surface_id=37)
    s38 = openmc.ZPlane(z0=215.0, surface_id=38)
    s39 = openmc.ZPlane(z0=223.0, surface_id=39, boundary_type='vacuum')

    # Define pin cells.
    fuel_cold = openmc.Universe(name='Fuel pin, cladding, cold water',
                                universe_id=1)
    c21 = openmc.Cell(cell_id=21, fill=fuel, region=-s1)
    c22 = openmc.Cell(cell_id=22, fill=clad, region=+s1 & -s2)
    c23 = openmc.Cell(cell_id=23, fill=cold_water, region=+s2)
    fuel_cold.add_cells((c21, c22, c23))

    tube_cold = openmc.Universe(name='Instrumentation guide tube, '
                                'cold water', universe_id=2)
    c24 = openmc.Cell(cell_id=24, fill=cold_water, region=-s3)
    c25 = openmc.Cell(cell_id=25, fill=clad, region=+s3 & -s4)
    c26 = openmc.Cell(cell_id=26, fill=cold_water, region=+s4)
    tube_cold.add_cells((c24, c25, c26))

    fuel_hot = openmc.Universe(name='Fuel pin, cladding, hot water',
                               universe_id=3)
    c27 = openmc.Cell(cell_id=27, fill=fuel, region=-s1)
    c28 = openmc.Cell(cell_id=28, fill=clad, region=+s1 & -s2)
    c29 = openmc.Cell(cell_id=29, fill=hot_water, region=+s2)
    fuel_hot.add_cells((c27, c28, c29))

    tube_hot = openmc.Universe(name='Instrumentation guide tube, hot water',
                               universe_id=4)
    c30 = openmc.Cell(cell_id=30, fill=hot_water, region=-s3)
    c31 = openmc.Cell(cell_id=31, fill=clad, region=+s3 & -s4)
    c32 = openmc.Cell(cell_id=32, fill=hot_water, region=+s4)
    tube_hot.add_cells((c30, c31, c32))

    # Set positions occupied by guide tubes
    tube_x = np.array([5, 8, 11, 3, 13, 2, 5, 8, 11, 14, 2, 5, 8, 11, 14,
                       2, 5, 8, 11, 14, 3, 13, 5, 8, 11])
    tube_y = np.array([2, 2, 2, 3, 3, 5, 5, 5, 5, 5, 8, 8, 8, 8, 8,
                       11, 11, 11, 11, 11, 13, 13, 14, 14, 14])

    # Define fuel lattices.
    l100 = openmc.RectLattice(name='Fuel assembly (lower half)', lattice_id=100)
    l100.lower_left = (-10.71, -10.71)
    l100.pitch = (1.26, 1.26)
    l100.universes = np.tile(fuel_cold, (17, 17))
    l100.universes[tube_x, tube_y] = tube_cold

    l101 = openmc.RectLattice(name='Fuel assembly (upper half)', lattice_id=101)
    l101.lower_left = (-10.71, -10.71)
    l101.pitch = (1.26, 1.26)
    l101.universes = np.tile(fuel_hot, (17, 17))
    l101.universes[tube_x, tube_y] = tube_hot

    # Define assemblies.
    fa_cw = openmc.Universe(name='Water assembly (cold)', universe_id=5)
    c50 = openmc.Cell(cell_id=50, fill=cold_water, region=+s34 & -s35)
    fa_cw.add_cell(c50)

    fa_hw = openmc.Universe(name='Water assembly (hot)', universe_id=7)
    c70 = openmc.Cell(cell_id=70, fill=hot_water, region=+s35 & -s36)
    fa_hw.add_cell(c70)

    fa_cold = openmc.Universe(name='Fuel assembly (cold)', universe_id=6)
    c60 = openmc.Cell(cell_id=60, fill=l100, region=+s34 & -s35)
    fa_cold.add_cell(c60)

    fa_hot = openmc.Universe(name='Fuel assembly (hot)', universe_id=8)
    c80 = openmc.Cell(cell_id=80, fill=l101, region=+s35 & -s36)
    fa_hot.add_cell(c80)

    # Define core lattices
    l200 = openmc.RectLattice(name='Core lattice (lower half)', lattice_id=200)
    l200.lower_left = (-224.91, -224.91)
    l200.pitch = (21.42, 21.42)
    l200.universes = [
        [fa_cw]*21,
        [fa_cw]*21,
        [fa_cw]*7 + [fa_cold]*7 + [fa_cw]*7,
        [fa_cw]*5 + [fa_cold]*11 + [fa_cw]*5,
        [fa_cw]*4 + [fa_cold]*13 + [fa_cw]*4,
        [fa_cw]*3 + [fa_cold]*15 + [fa_cw]*3,
        [fa_cw]*3 + [fa_cold]*15 + [fa_cw]*3,
        [fa_cw]*2 + [fa_cold]*17 + [fa_cw]*2,
        [fa_cw]*2 + [fa_cold]*17 + [fa_cw]*2,
        [fa_cw]*2 + [fa_cold]*17 + [fa_cw]*2,
        [fa_cw]*2 + [fa_cold]*17 + [fa_cw]*2,
        [fa_cw]*2 + [fa_cold]*17 + [fa_cw]*2,
        [fa_cw]*2 + [fa_cold]*17 + [fa_cw]*2,
        [fa_cw]*2 + [fa_cold]*17 + [fa_cw]*2,
        [fa_cw]*3 + [fa_cold]*15 + [fa_cw]*3,
        [fa_cw]*3 + [fa_cold]*15 + [fa_cw]*3,
        [fa_cw]*4 + [fa_cold]*13 + [fa_cw]*4,
        [fa_cw]*5 + [fa_cold]*11 + [fa_cw]*5,
        [fa_cw]*7 + [fa_cold]*7 + [fa_cw]*7,
        [fa_cw]*21,
        [fa_cw]*21]

    l201 = openmc.RectLattice(name='Core lattice (lower half)', lattice_id=201)
    l201.lower_left = (-224.91, -224.91)
    l201.pitch = (21.42, 21.42)
    l201.universes = [
        [fa_hw]*21,
        [fa_hw]*21,
        [fa_hw]*7 + [fa_hot]*7 + [fa_hw]*7,
        [fa_hw]*5 + [fa_hot]*11 + [fa_hw]*5,
        [fa_hw]*4 + [fa_hot]*13 + [fa_hw]*4,
        [fa_hw]*3 + [fa_hot]*15 + [fa_hw]*3,
        [fa_hw]*3 + [fa_hot]*15 + [fa_hw]*3,
        [fa_hw]*2 + [fa_hot]*17 + [fa_hw]*2,
        [fa_hw]*2 + [fa_hot]*17 + [fa_hw]*2,
        [fa_hw]*2 + [fa_hot]*17 + [fa_hw]*2,
        [fa_hw]*2 + [fa_hot]*17 + [fa_hw]*2,
        [fa_hw]*2 + [fa_hot]*17 + [fa_hw]*2,
        [fa_hw]*2 + [fa_hot]*17 + [fa_hw]*2,
        [fa_hw]*2 + [fa_hot]*17 + [fa_hw]*2,
        [fa_hw]*3 + [fa_hot]*15 + [fa_hw]*3,
        [fa_hw]*3 + [fa_hot]*15 + [fa_hw]*3,
        [fa_hw]*4 + [fa_hot]*13 + [fa_hw]*4,
        [fa_hw]*5 + [fa_hot]*11 + [fa_hw]*5,
        [fa_hw]*7 + [fa_hot]*7 + [fa_hw]*7,
        [fa_hw]*21,
        [fa_hw]*21]

    # Define root universe.
    root = openmc.Universe(universe_id=0, name='root universe')
    c1 = openmc.Cell(cell_id=1, fill=l200, region=-s6 & +s34 & -s35)
    c2 = openmc.Cell(cell_id=2, fill=l201, region=-s6 & +s35 & -s36)
    c3 = openmc.Cell(cell_id=3, fill=bot_plate, region=-s7 & +s31 & -s32)
    c4 = openmc.Cell(cell_id=4, fill=bot_nozzle, region=-s5 & +s32 & -s33)
    c5 = openmc.Cell(cell_id=5, fill=bot_fa, region=-s5 & +s33 & -s34)
    c6 = openmc.Cell(cell_id=6, fill=top_fa, region=-s5 & +s36 & -s37)
    c7 = openmc.Cell(cell_id=7, fill=top_nozzle, region=-s5 & +s37 & -s38)
    c8 = openmc.Cell(cell_id=8, fill=upper_rad_ref, region=-s7 & +s38 & -s39)
    c9 = openmc.Cell(cell_id=9, fill=bot_nozzle, region=+s6 & -s7 & +s32 & -s38)
    c10 = openmc.Cell(cell_id=10, fill=rpv_steel, region=+s7 & -s8 & +s31 & -s39)
    c11 = openmc.Cell(cell_id=11, fill=lower_rad_ref, region=+s5 & -s6 & +s32 & -s34)
    c12 = openmc.Cell(cell_id=12, fill=upper_rad_ref, region=+s5 & -s6 & +s36 & -s38)
    root.add_cells((c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12))

    # Assign root universe to geometry
    model.geometry.root_universe = root

    model.settings.batches = 10
    model.settings.inactive = 5
    model.settings.particles = 100
    model.settings.source = openmc.Source(space=openmc.stats.Box(
        [-160, -160, -183], [160, 160, 183]))

    plot = openmc.Plot()
    plot.origin = (125, 125, 0)
    plot.width = (250, 250)
    plot.pixels = (3000, 3000)
    plot.color_by = 'material'
    model.plots.append(plot)

    return model
Example #16
0
tube_cold.add_cells((fuel_cell_24, fuel_cell_25, fuel_cell_26))

#Defining assemblies
moderator_assembly = openmc.Universe(name='Water assembly', universe_id=5)
fuel_cell_50 = openmc.Cell(cell_id=50,
                           fill=borated_water,
                           region=+core_surf_lowertank_wall_in
                           & -core_surf_uppertank_wall_in)
moderator_assembly.add_cell(fuel_cell_50)

#Set positions occupied by guide tubes
tube_x = np.array([0])
tube_y = np.array([0])

#Defining assembly lattice
fuel_lattice_101 = openmc.RectLattice(name='Fuel lattice', lattice_id=101)
fuel_lattice_101.lower_left = (-5, -5)
fuel_lattice_101.pitch = (1, 1)
fuel_lattice_101.universes = np.tile(fuel, (10, 10))
fuel_lattice_101.universes[tube_x, tube_y] = tube_cold

#Construct filling for the reactor core lattice
fuel_assembly = openmc.Universe(name='Fuel assembly', universe_id=6)
fuel_assembly_cell_60 = openmc.Cell(cell_id=60,
                                    fill=fuel_lattice_101,
                                    region=+core_surf_lowertank_wall_in
                                    & -core_surf_uppertank_wall_in)
fuel_assembly.add_cell(fuel_assembly_cell_60)

fuel_assembly_hotwater = openmc.Universe(name='Water assembly', universe_id=8)
fuel_cell_70 = openmc.Cell(cell_id=70,
Example #17
0
cell5 = openmc.Cell()
cell5.region = -zc2 & -zp7
cell5.fill = rubber

#water
cell6 = openmc.Cell()
cell6.region = +zc12
cell6.fill = water

u1 = openmc.Universe(cells=(cell1, cell2, cell3, cell4, cell5, cell6))

all_water = openmc.Cell(fill=water)
u2 = openmc.Universe(cells=(all_water, ))

#Rectangular Lattices 13*8
lattice1 = openmc.RectLattice()
lattice1.lower_left = (0, 0)
lattice1.pitch = (2.54, 2.54)
lattice1.universes = np.tile(u1, (8, 13))  # 13*8
lattice1.outer = u2

lattice2 = openmc.RectLattice()
lattice2.lower_left = (52.515, 0)
lattice2.pitch = (2.54, 2.54)
lattice2.universes = np.tile(u1, (8, 13))
lattice2.outer = u2

lattice3 = openmc.RectLattice()
lattice3.lower_left = (105.03, 0)
lattice3.pitch = (2.54, 2.54)
lattice3.universes = np.tile(u1, (8, 13))
Example #18
0
    def build_cells(self, bc=None):
        """Generates a lattice of universes with the same dimensionality
        as the mesh object.  The individual cells/universes produced
        will not have material definitions applied and so downstream code
        will have to apply that information.

        Parameters
        ----------
        bc : iterable of {'reflective', 'periodic', 'transmission', 'vacuum', or 'white'}
            Boundary conditions for each of the four faces of a rectangle
            (if applying to a 2D mesh) or six faces of a parallelepiped
            (if applying to a 3D mesh) provided in the following order:
            [x min, x max, y min, y max, z min, z max].  2-D cells do not
            contain the z min and z max entries. Defaults to 'reflective' for
            all faces.

        Returns
        -------
        root_cell : openmc.Cell
            The cell containing the lattice representing the mesh geometry;
            this cell is a single parallelepiped with boundaries matching
            the outermost mesh boundary with the boundary conditions from bc
            applied.
        cells : iterable of openmc.Cell
            The list of cells within each lattice position mimicking the mesh
            geometry.

        """
        if bc is None:
            bc = ['reflective'] * 6
        if len(bc) not in (4, 6):
            raise ValueError('Boundary condition must be of length 4 or 6')
        for entry in bc:
            cv.check_value('bc', entry, _BOUNDARY_TYPES)

        n_dim = len(self.dimension)

        # Build the cell which will contain the lattice
        xplanes = [
            openmc.XPlane(self.lower_left[0], boundary_type=bc[0]),
            openmc.XPlane(self.upper_right[0], boundary_type=bc[1])
        ]
        if n_dim == 1:
            yplanes = [
                openmc.YPlane(-1e10, boundary_type='reflective'),
                openmc.YPlane(1e10, boundary_type='reflective')
            ]
        else:
            yplanes = [
                openmc.YPlane(self.lower_left[1], boundary_type=bc[2]),
                openmc.YPlane(self.upper_right[1], boundary_type=bc[3])
            ]

        if n_dim <= 2:
            # Would prefer to have the z ranges be the max supported float, but
            # these values are apparently different between python and Fortran.
            # Choosing a safe and sane default.
            # Values of +/-1e10 are used here as there seems to be an
            # inconsistency between what numpy uses as the max float and what
            # Fortran expects for a real(8), so this avoids code complication
            # and achieves the same goal.
            zplanes = [
                openmc.ZPlane(-1e10, boundary_type='reflective'),
                openmc.ZPlane(1e10, boundary_type='reflective')
            ]
        else:
            zplanes = [
                openmc.ZPlane(self.lower_left[2], boundary_type=bc[4]),
                openmc.ZPlane(self.upper_right[2], boundary_type=bc[5])
            ]
        root_cell = openmc.Cell()
        root_cell.region = ((+xplanes[0] & -xplanes[1]) &
                            (+yplanes[0] & -yplanes[1]) &
                            (+zplanes[0] & -zplanes[1]))

        # Build the universes which will be used for each of the (i,j,k)
        # locations within the mesh.
        # We will concurrently build cells to assign to these universes
        cells = []
        universes = []
        for _ in self.indices:
            cells.append(openmc.Cell())
            universes.append(openmc.Universe())
            universes[-1].add_cell(cells[-1])

        lattice = openmc.RectLattice()
        lattice.lower_left = self.lower_left

        # Assign the universe and rotate to match the indexing expected for
        # the lattice
        if n_dim == 1:
            universe_array = np.array([universes])
        elif n_dim == 2:
            universe_array = np.empty(self.dimension[::-1],
                                      dtype=openmc.Universe)
            i = 0
            for y in range(self.dimension[1] - 1, -1, -1):
                for x in range(self.dimension[0]):
                    universe_array[y][x] = universes[i]
                    i += 1
        else:
            universe_array = np.empty(self.dimension[::-1],
                                      dtype=openmc.Universe)
            i = 0
            for z in range(self.dimension[2]):
                for y in range(self.dimension[1] - 1, -1, -1):
                    for x in range(self.dimension[0]):
                        universe_array[z][y][x] = universes[i]
                        i += 1
        lattice.universes = universe_array

        if self.width is not None:
            lattice.pitch = self.width
        else:
            dx = ((self.upper_right[0] - self.lower_left[0]) /
                  self.dimension[0])

            if n_dim == 1:
                lattice.pitch = [dx]
            elif n_dim == 2:
                dy = ((self.upper_right[1] - self.lower_left[1]) /
                      self.dimension[1])
                lattice.pitch = [dx, dy]
            else:
                dy = ((self.upper_right[1] - self.lower_left[1]) /
                      self.dimension[1])
                dz = ((self.upper_right[2] - self.lower_left[2]) /
                      self.dimension[2])
                lattice.pitch = [dx, dy, dz]

        # Fill Cell with the Lattice
        root_cell.fill = lattice

        return root_cell, cells
Example #19
0
def get_openmc_lattice(openmoc_lattice):
    """Return an OpenMC lattice corresponding to an OpenMOC lattice.

    Parameters
    ----------
    openmoc_lattice : openmoc.Lattice
        OpenMOC lattice

    Returns
    -------
    openmc_lattice : openmc.RectLattice
        Equivalent OpenMC lattice

    """

    cv.check_type('openmoc_lattice', openmoc_lattice, openmoc.Lattice)

    lattice_id = openmoc_lattice.getId()

    # If this Lattice was already created, use it
    if lattice_id in OPENMC_LATTICES:
        return OPENMC_LATTICES[lattice_id]

    name = openmoc_lattice.getName()
    dimension = [openmoc_lattice.getNumX(),
                 openmoc_lattice.getNumY(),
                 openmoc_lattice.getNumZ()]
    width = [openmoc_lattice.getWidthX(),
             openmoc_lattice.getWidthY(),
             openmoc_lattice.getWidthZ()]
    offset = openmoc_lattice.getOffset()
    offset = [offset.getX(), offset.getY(), offset.getZ()]
    lower_left = np.array(offset, dtype=np.float64) + \
                 ((np.array(width, dtype=np.float64) *
                   np.array(dimension, dtype=np.float64))) / -2.0

    # Initialize an empty array for the OpenMOC nested Universes in this Lattice
    universe_array = np.ndarray(tuple(np.array(dimension)),
                                dtype=openmoc.Universe)

    # Create OpenMOC Universes for each unique nested Universe in this Lattice
    unique_universes = openmoc_lattice.getUniqueUniverses()

    for universe_id, universe in unique_universes.items():
        unique_universes[universe_id] = get_openmc_universe(universe)

    # Build the nested Universe array
    for x in range(dimension[0]):
        for y in range(dimension[1]):
            for z in range(dimension[2]):
                universe = openmoc_lattice.getUniverse(x, y, z)
                universe_id = universe.getId()
                universe_array[x][y][z] = \
                    unique_universes[universe_id]

    universe_array = np.swapaxes(universe_array, 0, 1)
    universe_array = universe_array[::-1, :, :]

    # Convert axially infinite 3D OpenMOC lattice to a 2D OpenMC lattice
    if width[2] == np.finfo(np.float64).max:
        dimension = dimension[:2]
        width = width[:2]
        offset = offset[:2]
        lower_left = lower_left[:2]
        universe_array = np.squeeze(universe_array, 2)

    openmc_lattice = openmc.RectLattice(lattice_id=lattice_id, name=name)
    openmc_lattice.pitch = width
    openmc_lattice.lower_left = lower_left
    openmc_lattice.universes = universe_array

    # Add the OpenMC Lattice to the global collection of all OpenMC Lattices
    OPENMC_LATTICES[lattice_id] = openmc_lattice

    # Add the OpenMOC Lattice to the global collection of all OpenMOC Lattices
    OPENMOC_LATTICES[lattice_id] = openmoc_lattice

    return openmc_lattice
Example #20
0
def get_openmc_lattice(opencg_lattice):
    """Return an OpenMC lattice corresponding to an OpenCG lattice.

    Parameters
    ----------
    opencg_lattice : opencg.Lattice
        OpenCG lattice

    Returns
    -------
    openmc_lattice : openmc.universe.Lattice
        Equivalent OpenMC lattice

    """

    if not isinstance(opencg_lattice, opencg.Lattice):
        msg = 'Unable to create an OpenMC Lattice from "{0}" which ' \
              'is not an OpenCG Lattice'.format(opencg_lattice)
        raise ValueError(msg)

    global OPENMC_LATTICES
    lattice_id = opencg_lattice.id

    # If this Lattice was already created, use it
    if lattice_id in OPENMC_LATTICES:
        return OPENMC_LATTICES[lattice_id]

    dimension = opencg_lattice.dimension
    width = opencg_lattice.width
    offset = opencg_lattice.offset
    universes = opencg_lattice.universes
    outer = opencg_lattice.outside

    # Initialize an empty array for the OpenMC nested Universes in this Lattice
    universe_array = np.ndarray(tuple(np.array(dimension)),
                                dtype=openmc.Universe)

    # Create OpenMC Universes for each unique nested Universe in this Lattice
    unique_universes = opencg_lattice.get_unique_universes()

    for universe_id, universe in unique_universes.items():
        unique_universes[universe_id] = get_openmc_universe(universe)

    # Build the nested Universe array
    for z in range(dimension[2]):
        for y in range(dimension[1]):
            for x in range(dimension[0]):
                universe_id = universes[z][y][x].id
                universe_array[x][y][z] = unique_universes[universe_id]

    # Reverse y-dimension in array to match ordering in OpenCG
    universe_array = universe_array[:, ::-1, :]

    lower_left = np.array(offset, dtype=np.float64) + \
                 ((np.array(width, dtype=np.float64) *
                   np.array(dimension, dtype=np.float64))) / -2.0

    openmc_lattice = openmc.RectLattice(lattice_id=lattice_id)
    openmc_lattice.dimension = dimension
    openmc_lattice.pitch = width
    openmc_lattice.universes = universe_array
    openmc_lattice.lower_left = lower_left
    if outer is not None:
        openmc_lattice.outer = get_openmc_universe(outer)

    # Add the OpenMC Lattice to the global collection of all OpenMC Lattices
    OPENMC_LATTICES[lattice_id] = openmc_lattice

    # Add the OpenCG Lattice to the global collection of all OpenCG Lattices
    OPENCG_LATTICES[lattice_id] = opencg_lattice

    return openmc_lattice
Example #21
0
    u_box = u_prism & -openmc.ZPlane(detector.z / 2.) & +openmc.ZPlane(
        -detector.z / 2.)
    l_box = l_prism & -openmc.ZPlane(detector.z / 2.) & +openmc.ZPlane(
        -detector.z / 2.)
    d_box = d_prism & -openmc.ZPlane(detector.z / 2.) & +openmc.ZPlane(
        -detector.z / 2.)

    d_cell = openmc.Cell(name="detector", fill=cdte, region=d_box)
    u_cell = openmc.Cell(fill=water, region=u_box)
    l_cell = openmc.Cell(fill=water, region=l_box)

    univ = openmc.Universe(name='detector')
    univ.add_cells([d_cell, u_cell, l_cell])

    lattice = openmc.RectLattice(name='detector')

    lattice.pitch = (detector.x, hypp.interelement)

    ll_y = -(hypp.interelement * hypp.n_elements) / 2.
    ll_x = 5.
    lattice.lower_left = (ll_x, ll_y)

    lattice.universes = np.full((int(hypp.n_elements), 1), univ)

    h_prism = openmc.model.rectangular_prism(
        width=detector.x,
        height=hypp.interelement * hypp.n_elements,
        origin=(ll_x + detector.x / 2, 0., 0.),
        boundary_type='transmission')