示例#1
0
    def build_default_materials_and_geometry(self):
        # Define materials needed for 1D/1G slab problem
        uo2_data = openmc.Macroscopic('uo2_iso', '71c')
        uo2 = openmc.Material(name='UO2', material_id=1)
        uo2.set_density('macro', 1.0)
        uo2.add_macroscopic(uo2_data)

        clad_data = openmc.Macroscopic('clad_ang_mu', '71c')
        clad = openmc.Material(name='Clad', material_id=2)
        clad.set_density('macro', 1.0)
        clad.add_macroscopic(clad_data)

        water_data = openmc.Macroscopic('lwtr_iso_mu', '71c')
        water = openmc.Material(name='LWTR', material_id=3)
        water.set_density('macro', 1.0)
        water.add_macroscopic(water_data)

        # Define the materials file.
        self.materials.default_xs = '71c'
        self.materials += (uo2, clad, water)

        # Define surfaces.

        # Assembly/Problem Boundary
        left = openmc.XPlane(x0=0.0,
                             surface_id=200,
                             boundary_type='reflective')
        right = openmc.XPlane(x0=10.0,
                              surface_id=201,
                              boundary_type='reflective')
        bottom = openmc.YPlane(y0=0.0,
                               surface_id=300,
                               boundary_type='reflective')
        top = openmc.YPlane(y0=10.0,
                            surface_id=301,
                            boundary_type='reflective')

        down = openmc.ZPlane(z0=0.0, surface_id=0, boundary_type='reflective')
        fuel_clad_intfc = openmc.ZPlane(z0=2.0, surface_id=1)
        clad_lwtr_intfc = openmc.ZPlane(z0=2.4, surface_id=2)
        up = openmc.ZPlane(z0=5.0, surface_id=3, boundary_type='reflective')

        # Define cells
        c1 = openmc.Cell(cell_id=1)
        c1.region = +left & -right & +bottom & -top & +down & -fuel_clad_intfc
        c1.fill = uo2
        c2 = openmc.Cell(cell_id=2)
        c2.region = +left & -right & +bottom & -top & +fuel_clad_intfc & -clad_lwtr_intfc
        c2.fill = clad
        c3 = openmc.Cell(cell_id=3)
        c3.region = +left & -right & +bottom & -top & +clad_lwtr_intfc & -up
        c3.fill = water

        # Define root universe.
        root = openmc.Universe(universe_id=0, name='root universe')

        root.add_cells((c1, c2, c3))

        # Assign root universe to geometry
        self.geometry.root_universe = root
示例#2
0
    def _build_inputs(self):
        # Instantiate some Macroscopic Data
        uo2_data = openmc.Macroscopic('UO2')

        # Instantiate some Materials and register the appropriate objects
        mat = openmc.Material(material_id=1, name='UO2 fuel')
        mat.set_density('macro', 1.0)
        mat.add_macroscopic(uo2_data)

        # Instantiate a Materials collection and export to XML
        materials_file = openmc.Materials([mat])
        materials_file.cross_sections = "./mgxs.h5"
        materials_file.export_to_xml()

        # Instantiate ZCylinder surfaces
        left = openmc.XPlane(surface_id=4, x0=-5., name='left')
        right = openmc.XPlane(surface_id=5, x0=5., name='right')
        bottom = openmc.YPlane(surface_id=6, y0=-5., name='bottom')
        top = openmc.YPlane(surface_id=7, y0=5., name='top')

        left.boundary_type = 'reflective'
        right.boundary_type = 'vacuum'
        top.boundary_type = 'reflective'
        bottom.boundary_type = 'reflective'

        # Instantiate Cells
        fuel = openmc.Cell(cell_id=1, name='cell 1')

        # Use surface half-spaces to define regions
        fuel.region = +left & -right & +bottom & -top

        # Register Materials with Cells
        fuel.fill = mat

        # Instantiate Universe
        root = openmc.Universe(universe_id=0, name='root universe')

        # Register Cells with Universe
        root.add_cells([fuel])

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

        settings_file = openmc.Settings()
        settings_file.energy_mode = "multi-group"
        settings_file.batches = batches
        settings_file.inactive = inactive
        settings_file.particles = particles

        # Create an initial uniform spatial source distribution
        bounds = [-5, -5, -5, 5, 5, 5]
        uniform_dist = openmc.stats.Box(bounds[:3], bounds[3:])
        settings_file.source = openmc.source.Source(space=uniform_dist)

        settings_file.export_to_xml()
示例#3
0
    def make_materials(self):
        materials_file = openmc.Materials()

        mats = []
        macros = []
        for i in range(len(self.mat_names)):
            macros.append(openmc.Macroscopic(self.mat_names[i]))
            mats.append(openmc.Material(name=self.mat_names[i]))
            mats[-1].set_density('macro', 1.0)
            mats[-1].add_macroscopic(macros[-1])
            materials_file.add_material(mats[-1])

        materials_file.cross_sections = GROUP_FILES[self.groups]

        return mats, materials_file
示例#4
0
    def add_macroscopic(self, macroscopic):
        """Add a macroscopic to the material.  This will also set the
        density of the material to 1.0, unless it has been otherwise set,
        as a default for Macroscopic cross sections.

        Parameters
        ----------
        macroscopic : str or openmc.Macroscopic
            Macroscopic to add

        """

        # Ensure no nuclides, elements, or sab are added since these would be
        # incompatible with macroscopics
        if self._nuclides or self._elements or self._sab:
            msg = 'Unable to add a Macroscopic data set to Material ID="{0}" ' \
                  'with a macroscopic value "{1}" as an incompatible data ' \
                  'member (i.e., nuclide, element, or S(a,b) table) ' \
                  'has already been added'.format(self._id, macroscopic)
            raise ValueError(msg)

        if not isinstance(macroscopic, (openmc.Macroscopic, basestring)):
            msg = 'Unable to add a Macroscopic to Material ID="{0}" with a ' \
                  'non-Macroscopic value "{1}"'.format(self._id, macroscopic)
            raise ValueError(msg)

        if isinstance(macroscopic, openmc.Macroscopic):
            # Copy this Macroscopic to separate it from the Macroscopic in
            # other Materials
            macroscopic = deepcopy(macroscopic)
        else:
            macroscopic = openmc.Macroscopic(macroscopic)

        if self._macroscopic is None:
            self._macroscopic = macroscopic
        else:
            msg = 'Unable to add a Macroscopic to Material ID="{0}". ' \
                  'Only one Macroscopic allowed per ' \
                  'Material.'.format(self._id)
            raise ValueError(msg)

        # Generally speaking, the density for a macroscopic object will
        # be 1.0.  Therefore, lets set density to 1.0 so that the user
        # doesnt need to set it unless its needed.
        # Of course, if the user has already set a value of density,
        # then we will not override it.
        if self._density is None:
            self.set_density('macro', 1.0)
示例#5
0
    0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0022157, 0.6999130, 0.5373200
], [
    0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.1324400, 2.4807000
]]])
scatter_matrix = np.rollaxis(scatter_matrix, 0, 3)
h2o_xsdata.set_scatter_matrix(scatter_matrix)

mg_cross_sections_file = openmc.MGXSLibrary(groups)
mg_cross_sections_file.add_xsdatas([uo2_xsdata, h2o_xsdata])
mg_cross_sections_file.export_to_hdf5()

###############################################################################
# Create materials for the problem

# Instantiate some Macroscopic Data
uo2_data = openmc.Macroscopic('UO2')
h2o_data = openmc.Macroscopic('LWTR')

# Instantiate some Materials and register the appropriate Macroscopic objects
uo2 = openmc.Material(name='UO2 fuel')
uo2.set_density('macro', 1.0)
uo2.add_macroscopic(uo2_data)

water = openmc.Material(name='Water')
water.set_density('macro', 1.0)
water.add_macroscopic(h2o_data)

# Instantiate a Materials collection and export to XML
materials_file = openmc.Materials([uo2, water])
materials_file.cross_sections = "mgxs.h5"
materials_file.export_to_xml()
示例#6
0
control_rod_xsdata.nu_fission = np.zeros(7)
control_rod_xsdata.chi = np.zeros(7)

mg_cross_sections_file = openmc.MGXSLibrary(groups)
mg_cross_sections_file.add_xsdatas([uo2_xsdata, mox43_xsdata, mox7_xsdata, mox87_xsdata,
                                    fiss_chamber_xsdata, guide_tube_xsdata, water_xsdata,
                                    control_rod_xsdata])
mg_cross_sections_file.export_to_xml()


###############################################################################
#                 Exporting to OpenMC materials.xml File
###############################################################################

# Instantiate some Macroscopic Data
uo2_data = openmc.Macroscopic('uo2', '300k')
mox43_data = openmc.Macroscopic('mox43', '300k')
mox7_data = openmc.Macroscopic('mox7', '300k')
mox87_data = openmc.Macroscopic('mox87', '300k')
fiss_chamber_data = openmc.Macroscopic('fiss_chamber', '300k')
guide_tube_data = openmc.Macroscopic('guide_tube', '300k')
water_data = openmc.Macroscopic('water', '300k')
control_rod_data = openmc.Macroscopic('control_rod', '300k')

# Instantiate Materials dictionary
materials = {}

# Instantiate some Materials and register the appropriate Nuclides
materials['UO2'] = openmc.Material(material_id=1, name='UO2')
materials['UO2'].set_density('macro', 1.0)
materials['UO2'].add_macroscopic(uo2_data)
示例#7
0
def slab_mg(num_regions=1, mat_names=None, mgxslib_name='2g.h5'):
    """Create a 1D slab model.

    Parameters
    ----------
    num_regions : int, optional
        Number of regions in the problem, each with a unique MGXS dataset.
        Defaults to 1.

    mat_names : Iterable of str, optional
        List of the material names to use; defaults to ['mat_1', 'mat_2',...].

    mgxslib_name : str, optional
        MGXS Library file to use; defaults to '2g.h5'.

    Returns
    -------
    model : openmc.model.Model
        One-group, 1D slab model

    """

    openmc.check_type('num_regions', num_regions, Integral)
    openmc.check_greater_than('num_regions', num_regions, 0)
    if mat_names is not None:
        openmc.check_length('mat_names', mat_names, num_regions)
        openmc.check_iterable_type('mat_names', mat_names, str)
    else:
        mat_names = []
        for i in range(num_regions):
            mat_names.append('mat_' + str(i + 1))

    # # Make Materials
    materials_file = openmc.Materials()
    macros = []
    mats = []
    for i in range(len(mat_names)):
        macros.append(openmc.Macroscopic('mat_' + str(i + 1)))
        mats.append(openmc.Material(name=mat_names[i]))
        mats[-1].set_density('macro', 1.0)
        mats[-1].add_macroscopic(macros[-1])

    materials_file += mats

    materials_file.cross_sections = mgxslib_name

    # # Make Geometry
    rad_outer = 929.45
    # Set a cell boundary to exist for every material above (exclude the 0)
    rads = np.linspace(0., rad_outer, len(mats) + 1, endpoint=True)[1:]

    # Instantiate Universe
    root = openmc.Universe(universe_id=0, name='root universe')
    cells = []

    surfs = []
    surfs.append(openmc.XPlane(x0=0., boundary_type='reflective'))
    for r, rad in enumerate(rads):
        if r == len(rads) - 1:
            surfs.append(openmc.XPlane(x0=rad, boundary_type='vacuum'))
        else:
            surfs.append(openmc.XPlane(x0=rad))

    # Instantiate Cells
    cells = []
    for c in range(len(surfs) - 1):
        cells.append(openmc.Cell())
        cells[-1].region = (+surfs[c] & -surfs[c + 1])
        cells[-1].fill = mats[c]

    # Register Cells with Universe
    root.add_cells(cells)

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

    # # Make Settings
    # Instantiate a Settings object, set all runtime parameters
    settings_file = openmc.Settings()
    settings_file.energy_mode = 'multi-group'
    settings_file.tabular_legendre = {'enable': False}
    settings_file.batches = 10
    settings_file.inactive = 5
    settings_file.particles = 1000

    # Build source distribution
    INF = 1000.
    bounds = [0., -INF, -INF, rads[0], INF, INF]
    uniform_dist = openmc.stats.Box(bounds[:3], bounds[3:])
    settings_file.source = openmc.source.Source(space=uniform_dist)

    settings_file.output = {'summary': False}

    model = openmc.model.Model()
    model.geometry = geometry_file
    model.materials = materials_file
    model.settings = settings_file
    model.xs_data = macros

    return model
示例#8
0
                       [0.0000000, 0.0000000, 0.0000000, 0.0910284, 0.4155100, 0.0637320, 0.0121390],
                       [0.0000000, 0.0000000, 0.0000000, 0.0000714, 0.1391380, 0.5118200, 0.0612290],
                       [0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0022157, 0.6999130, 0.5373200],
                       [0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.1324400, 2.4807000]]]

mg_cross_sections_file = openmc.MGXSLibrary(groups)
mg_cross_sections_file.add_xsdatas([uo2_xsdata, h2o_xsdata])
mg_cross_sections_file.export_to_xml()


###############################################################################
#                 Exporting to OpenMC materials.xml file
###############################################################################

# Instantiate some Macroscopic Data
uo2_data = openmc.Macroscopic('UO2', '300K')
h2o_data = openmc.Macroscopic('LWTR', '300K')

# Instantiate some Materials and register the appropriate Macroscopic objects
uo2 = openmc.Material(material_id=1, name='UO2 fuel')
uo2.set_density('macro', 1.0)
uo2.add_macroscopic(uo2_data)

water = openmc.Material(material_id=2, name='Water')
water.set_density('macro', 1.0)
water.add_macroscopic(h2o_data)

# Instantiate a Materials collection and export to XML
materials_file = openmc.Materials([uo2, water])
materials_file.default_xs = '300K'
materials_file.export_to_xml()
示例#9
0
    def create_mg_mode(self, xsdata_names=None, xs_ids=None,
                       tabular_legendre=None, tabular_points=33):
        """Creates an openmc.MGXSLibrary object to contain the MGXS data for the
        Multi-Group mode of OpenMC as well as the associated openmc.Materials
        and openmc.Geometry objects. The created Geometry is the same as that
        used to generate the MGXS data, with the only differences being
        modifications to point to newly-created Materials which point to the
        multi-group data. This method only creates a macroscopic
        MGXS Library even if nuclidic tallies are specified in the Library.

        Parameters
        ----------
        xsdata_names : Iterable of str
            List of names to apply to the "xsdata" entries in the
            resultant mgxs data file. Defaults to 'set1', 'set2', ...
        xs_ids : str or Iterable of str
            Cross section set identifier (i.e., '71c') for all
            data sets (if only str) or for each individual one
            (if iterable of str). Defaults to '1m'.
        tabular_legendre : None or bool
            Flag to denote whether or not the Legendre expansion of the
            scattering angular distribution is to be converted to a tabular
            representation by OpenMC.  A value of `True` means that it is to be
            converted while a value of `False` means that it will not be.
            Defaults to `None` which leaves the default behavior of OpenMC in
            place (the distribution is converted to a tabular representation).
        tabular_points : int
            This parameter is not used unless the ``tabular_legendre``
            parameter is set to `True`.  In this case, this parameter sets the
            number of equally-spaced points in the domain of [-1,1] to be used
            in building the tabular distribution. Default is `33`.

        Returns
        -------
        mgxs_file : openmc.MGXSLibrary
            Multi-Group Cross Section File that is ready to be printed to the
            file of choice by the user.
        materials : openmc.Materials
            Materials file ready to be printed with all the macroscopic data
            present within this Library.
        geometry : openmc.Geometry
            Materials file ready to be printed with all the macroscopic data
            present within this Library.

        Raises
        ------
        ValueError
            When the Library object is initialized with insufficient types of
            cross sections for the Library.

        See also
        --------
        Library.create_mg_library()
        Library.dump_to_file()

        """

        # Check to ensure the Library contains the correct
        # multi-group cross section types
        self.check_library_for_openmc_mgxs()

        if xsdata_names is not None:
            cv.check_iterable_type('xsdata_names', xsdata_names, basestring)
        if xs_ids is not None:
            if isinstance(xs_ids, basestring):
                # If we only have a string lets convert it now to a list
                # of strings.
                xs_ids = [xs_ids for i in range(len(self.domains))]
            else:
                cv.check_iterable_type('xs_ids', xs_ids, basestring)
        else:
            xs_ids = ['1m' for i in range(len(self.domains))]
        xs_type = 'macro'

        # Initialize MGXS File
        mgxs_file = openmc.MGXSLibrary(self.energy_groups)

        # Create a copy of the Geometry to differentiate for these Macroscopics
        geometry = copy.deepcopy(self.openmc_geometry)
        materials = openmc.Materials()

        # Get all Cells from the Geometry for differentiation
        all_cells = geometry.get_all_material_cells()

        # Create the xsdata object and add it to the mgxs_file
        for i, domain in enumerate(self.domains):

            # Build & add metadata to XSdata object
            if xsdata_names is None:
                xsdata_name = 'set' + str(i + 1)
            else:
                xsdata_name = xsdata_names[i]

            # Create XSdata and Macroscopic for this domain
            xsdata = self.get_xsdata(domain, xsdata_name, nuclide='total',
                                     xs_type=xs_type, xs_id=xs_ids[i],
                                     tabular_legendre=tabular_legendre,
                                     tabular_points=tabular_points)
            mgxs_file.add_xsdata(xsdata)
            macroscopic = openmc.Macroscopic(name=xsdata_name, xs=xs_ids[i])

            # Create Material and add to collection
            material = openmc.Material(name=xsdata_name + '.' + xs_ids[i])
            material.add_macroscopic(macroscopic)
            materials.append(material)

            # Differentiate Geometry with new Material
            if self.domain_type == 'material':
                # Fill all appropriate Cells with new Material
                for cell in all_cells:
                    if cell.fill.id == domain.id:
                        cell.fill = material

            elif self.domain_type == 'cell':
                for cell in all_cells:
                    if cell.id == domain.id:
                        cell.fill = material

        return mgxs_file, materials, geometry
示例#10
0
def slab_mg(reps=None, as_macro=True):
    """Create a one-group, 1D slab model.

    Parameters
    ----------
    reps : list, optional
        List of angular representations. Each item corresponds to materials and
        dictates the angular representation of the multi-group cross
        sections---isotropic ('iso') or angle-dependent ('ang'), and if Legendre
        scattering or tabular scattering ('mu') is used. Thus, items can be
        'ang', 'ang_mu', 'iso', or 'iso_mu'.

    as_macro : bool, optional
        Whether :class:`openmc.Macroscopic` is used

    Returns
    -------
    model : openmc.model.Model
        One-group, 1D slab model

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

    # Define materials needed for 1D/1G slab problem
    mat_names = ['uo2', 'clad', 'lwtr']
    mgxs_reps = ['ang', 'ang_mu', 'iso', 'iso_mu']

    if reps is None:
        reps = mgxs_reps

    xs = []
    i = 0
    for mat in mat_names:
        for rep in reps:
            i += 1
            if as_macro:
                xs.append(openmc.Macroscopic(mat + '_' + rep))
                m = openmc.Material(name=str(i))
                m.set_density('macro', 1.)
                m.add_macroscopic(xs[-1])
            else:
                xs.append(openmc.Nuclide(mat + '_' + rep))
                m = openmc.Material(name=str(i))
                m.set_density('atom/b-cm', 1.)
                m.add_nuclide(xs[-1].name, 1.0, 'ao')
            model.materials.append(m)

    # Define the materials file
    model.xs_data = xs
    model.materials.cross_sections = "../1d_mgxs.h5"

    # Define surfaces.
    # Assembly/Problem Boundary
    left = openmc.XPlane(x0=0.0, boundary_type='reflective')
    right = openmc.XPlane(x0=10.0, boundary_type='reflective')
    bottom = openmc.YPlane(y0=0.0, boundary_type='reflective')
    top = openmc.YPlane(y0=10.0, boundary_type='reflective')

    # for each material add a plane
    planes = [openmc.ZPlane(z0=0.0, boundary_type='reflective')]
    dz = round(5. / float(len(model.materials)), 4)
    for i in range(len(model.materials) - 1):
        planes.append(openmc.ZPlane(z0=dz * float(i + 1)))
    planes.append(openmc.ZPlane(z0=5.0, boundary_type='reflective'))

    # Define cells for each material
    model.geometry.root_universe = openmc.Universe(name='root universe')
    xy = +left & -right & +bottom & -top
    for i, mat in enumerate(model.materials):
        c = openmc.Cell(fill=mat, region=xy & +planes[i] & -planes[i + 1])
        model.geometry.root_universe.add_cell(c)

    model.settings.batches = 10
    model.settings.inactive = 5
    model.settings.particles = 100
    model.settings.source = openmc.Source(space=openmc.stats.Box(
        [0.0, 0.0, 0.0], [10.0, 10.0, 5.]))
    model.settings.energy_mode = "multi-group"

    plot = openmc.Plot()
    plot.filename = 'mat'
    plot.origin = (5.0, 5.0, 2.5)
    plot.width = (2.5, 2.5)
    plot.basis = 'xz'
    plot.pixels = (3000, 3000)
    plot.color_by = 'material'
    model.plots.append(plot)

    return model