Esempio n. 1
0
 def export_to_xml(self):
     folder_name = "{clad_type}/radius{radius:.2f}_pitch{pitch:.2f}/".format(
         **vars(self))
     if not os.path.isdir(folder_name):
         os.makedirs(folder_name)
     self._geometry.export_to_xml(folder_name + "geometry.xml")
     mfile = openmc.Materials()
     for mat in all_materials.values():
         mfile.append(mat)
     mfile.export_to_xml(folder_name + "materials.xml")
     pfile = openmc.Plots()
     pfile += self.make_plots()
     # noinspection PyTypeChecker
     for p in pfile:
         if p.color_by == "material":
             p.colors = colormap
     pfile.export_to_xml(folder_name + "plots.xml")
     tfile = self.make_tallies(folder_name)
     tfile.export_to_xml(folder_name + "tallies.xml")
     sfile = openmc.Settings()
     sfile.particles = 10000
     sfile.batches = 50
     sfile.inactive = 20
     sfile.source = openmc.Source(
         space=Box([-RAD_MIN / 2, -RAD_MAJ, -10], [RAD_MIN / 2, 0, 10]))
     sfile.export_to_xml(folder_name + "settings.xml")
     print("Exported to:", folder_name)
Esempio n. 2
0
def test_highlight_domains():
    plot = openmc.Plot()
    plot.color_by = 'material'
    plots = openmc.Plots([plot])

    model = openmc.examples.pwr_pin_cell()
    mats = {m for m in model.materials if 'UO2' in m.name}
    plots.highlight_domains(model.geometry, mats)
Esempio n. 3
0
    def makePlot(self):
        """ Generate new plot image from active view settings

        Creates corresponding .xml files from user-chosen settings.
        Runs OpenMC in plot mode to generate new plot image.
        """

        cv = self.currentView = copy.deepcopy(self.activeView)

        plot = openmc.Plot()
        plot.filename = 'plot'
        plot.color_by = cv.colorby
        plot.basis = cv.basis
        plot.origin = cv.origin
        plot.width = (cv.width, cv.height)
        plot.pixels = (cv.hRes, cv.vRes)
        plot.background = cv.plotBackground

        # Determine domain type and source
        if cv.colorby == 'cell':
            domain = self.currentView.cells
            source = self.modelCells
        else:
            domain = self.currentView.materials
            source = self.modelMaterials

        # Custom Colors
        plot.colors = {}
        for id, dom in domain.items():
            if dom.color:
                plot.colors[source[int(id)]] = dom.color

        # Masking options
        if cv.masking:
            plot.mask_components = []
            for id, dom in domain.items():
                if not dom.masked:
                    plot.mask_components.append(source[int(id)])
            plot.mask_background = cv.maskBackground

        # Highlighting options
        if cv.highlighting:
            domains = []
            for id, dom in domain.items():
                if dom.highlighted:
                    domains.append(source[int(id)])
            background = cv.highlightBackground
            alpha = cv.highlightAlpha
            seed = cv.highlightSeed

            plot.highlight_domains(self.geom, domains, seed, alpha, background)

        # Generate plot.xml
        plots = openmc.Plots([plot])
        plots.export_to_xml()
        openmc.plot_geometry()

        self.updateIDs()
Esempio n. 4
0
def test_plots(run_in_tmpdir):
    p1 = openmc.Plot(name='plot1')
    p2 = openmc.Plot(name='plot2')
    plots = openmc.Plots([p1, p2])
    assert len(plots) == 2

    p3 = openmc.Plot(name='plot3')
    plots.append(p3)
    assert len(plots) == 3

    plots.export_to_xml()
Esempio n. 5
0
def plot_inline(plots, openmc_exec='openmc', cwd='.', convert_exec='convert'):
    """Display plots inline in a Jupyter notebook.

    This function requires that you have a program installed to convert PPM
    files to PNG files. Typically, that would be `ImageMagick
    <https://www.imagemagick.org>`_ which includes a `convert` command.

    Parameters
    ----------
    plots : Iterable of openmc.Plot
        Plots to display
    openmc_exec : str
        Path to OpenMC executable
    cwd : str, optional
        Path to working directory to run in
    convert_exec : str, optional
        Command that can convert PPM files into PNG files

    Raises
    ------
    subprocess.CalledProcessError
        If the `openmc` executable returns a non-zero status

    """
    from IPython.display import Image, display

    if not isinstance(plots, Iterable):
        plots = [plots]

    # Create plots.xml
    openmc.Plots(plots).export_to_xml()

    # Run OpenMC in geometry plotting mode
    plot_geometry(False, openmc_exec, cwd)

    images = []
    if plots is not None:
        for p in plots:
            if p.filename is not None:
                ppm_file = '{}.ppm'.format(p.filename)
            else:
                ppm_file = 'plot_{}.ppm'.format(p.id)
            png_file = ppm_file.replace('.ppm', '.png')
            subprocess.check_call([convert_exec, ppm_file, png_file])
            images.append(Image(png_file))
        display(*images)
Esempio n. 6
0
def createMaterials(createplots=True):

    air = openmc.Material(1, name='air')
    air.set_density('g/cc', 0.001205)
    air.add_element('N', 0.784431)
    air.add_element('O', 0.210748)
    air.add_element('Ar', 0.0046)

    copper = Material(2, "copper")
    copper.add_element('Cu', 1.0)
    copper.set_density('g/cm3', 8.96)
    copper.temperature = 300

    mats = openmc.Materials([copper, air])
    mats.export_to_xml()
    print("Created materials.xml")

    if createplots:
        p_xy = openmc.Plot()
        p_xy.width = (2500.0, 2500.0)
        p_xy.pixels = (400, 400)
        p_xy.origin = (0., 0., 0.)
        p_xy.color_by = 'material'
        p_xy.colors = {copper: 'orange', air: 'blue'}
        p_xy.basis = 'xy'

        p_xz = openmc.Plot()
        p_xz.width = (2500.0, 2500.0)
        p_xz.pixels = (400, 400)
        p_xz.origin = (0., 0., 0.)
        p_xz.color_by = 'material'
        p_xz.colors = {copper: 'orange', air: 'blue'}
        p_xz.basis = 'xz'

        p_yz = openmc.Plot()
        p_yz.width = (2500.0, 2500.0)
        p_yz.pixels = (400, 400)
        p_yz.origin = (500., 0., 0.)
        p_yz.color_by = 'material'
        p_yz.colors = {copper: 'orange', air: 'blue'}
        p_yz.basis = 'yz'

        plots = openmc.Plots([p_xy, p_xz, p_yz])
        plots.export_to_xml()
        print("Created plots.xml")
Esempio n. 7
0
def test_plots(run_in_tmpdir):
    p1 = openmc.Plot(name='plot1')
    p1.origin = (5., 5., 5.)
    p2 = openmc.Plot(name='plot2')
    p2.origin = (-3., -3., -3.)
    plots = openmc.Plots([p1, p2])
    assert len(plots) == 2

    p3 = openmc.Plot(name='plot3')
    plots.append(p3)
    assert len(plots) == 3

    plots.export_to_xml()

    # from_xml
    new_plots = openmc.Plots.from_xml()
    assert len(plots)
    assert plots[0].origin == p1.origin
    assert plots[1].origin == p2.origin
Esempio n. 8
0
    def __init__(self,
                 geometry=None,
                 materials=None,
                 settings=None,
                 tallies=None,
                 plots=None):
        self.geometry = openmc.Geometry()
        self.materials = openmc.Materials()
        self.settings = openmc.Settings()
        self.tallies = openmc.Tallies()
        self.plots = openmc.Plots()

        if geometry is not None:
            self.geometry = geometry
        if materials is not None:
            self.materials = materials
        if settings is not None:
            self.settings = settings
        if tallies is not None:
            self.tallies = tallies
        if plots is not None:
            self.plots = plots
Esempio n. 9
0
def plot_inline(plots, openmc_exec='openmc', cwd='.'):
    """Display plots inline in a Jupyter notebook.

    .. versionchanged:: 0.13.0
        The *convert_exec* argument was removed since OpenMC now produces
        .png images directly.


    Parameters
    ----------
    plots : Iterable of openmc.Plot
        Plots to display
    openmc_exec : str
        Path to OpenMC executable
    cwd : str, optional
        Path to working directory to run in

    Raises
    ------
    RuntimeError
        If the `openmc` executable returns a non-zero status

    """
    from IPython.display import display

    if not isinstance(plots, Iterable):
        plots = [plots]

    # Create plots.xml
    openmc.Plots(plots).export_to_xml()

    # Run OpenMC in geometry plotting mode
    plot_geometry(False, openmc_exec, cwd)

    if plots is not None:
        images = [_get_plot_image(p) for p in plots]
        display(*images)
Esempio n. 10
0
##################################################################
# PLOT
##################################################################
import sys
if (len(sys.argv) > 1):
    if (sys.argv[1] == 'plot'):

        p = openmc.Plot()
        p.filename = 'pinplot'
        p.width = (3 * pitch, 3 * pitch)
        p.pixels = (200, 200)
        p.color_by = 'material'
        p.colors = {uo2_hi: 'red', uo2_lo: 'yellow', water: 'blue'}
        p.origin = (3 * pitch / 2, 3 * pitch / 2, 0.0)
        plots = openmc.Plots([p])
        plots.export_to_xml()
        openmc.plot_geometry()

nufission = xs_library[fCells[0].id]['nu-fission']
u235_nu_fission = nufission.get_xs(xs_type='macro', nuclides=['U235'])
u235_nu_fission_to_write = [float('%.8E' % x) for x in u235_nu_fission]
u238_nu_fission = nufission.get_xs(xs_type='macro', nuclides=['U238'])
u238_nu_fission_to_write = [float('%.8E' % x) for x in u238_nu_fission]
o16_nu_fission = nufission.get_xs(xs_type='macro', nuclides=['O16'])
o16_nu_fission_to_write = [float('%.8E' % x) for x in o16_nu_fission]

total = xs_library[fCells[0].id]['total']
u235_total = total.get_xs(xs_type='macro', nuclides=['U235'])
u235_total_to_write = [float('%.8E' % x) for x in u235_total]
u238_total = total.get_xs(xs_type='macro', nuclides=['U238'])
Esempio n. 11
0
def hexfunction(pitch, pack_frac):

    settings = openmc.Settings()
    # Set high tolerance to allow use of lower temperature xs
    settings.temperature['tolerance'] = 1000
    settings.temperature['method'] = 'nearest'
    settings.temperature['multipole'] = True
    settings.cutoff = {'energy': 1e-8}  #energy cutoff in eV

    #############################
    ###       MATERIALS       ###
    #############################
    mat_list = []
    enrichment = 20.0

    uo2 = openmc.Material(1, "uo2")
    uo2.add_element('U', 1.0, enrichment=enrichment)
    uo2.add_element('O', 2.0)
    uo2.set_density('g/cm3', 10.97)
    uo2.temperature = 900  #kelvin
    mat_list.append(uo2)

    graphite = openmc.Material(2, "graphite")
    graphite.set_density('g/cm3', 1.1995)
    graphite.add_element('C', 1.0)
    graphite.add_s_alpha_beta('c_Graphite')
    graphite.temperature = 900  #kelvin
    mat_list.append(graphite)

    # sodium = openmc.Material(3, "sodium")
    sodium = openmc.Material()
    sodium.set_density('g/cm3', 0.8017)  # 900 K
    sodium.add_element('Na', 1.0)
    # sodium.add_s_alpha_beta('c_Graphite')
    sodium.temperature = 900  #kelvin
    mat_list.append(sodium)

    # naoh = openmc.Material(6, "naoh")
    naoh = openmc.Material()
    naoh.set_density('g/cm3', 1.5)  # 900 K
    naoh.add_element('Na', 1.0)
    naoh.add_element('O', 1.0)
    naoh.add_element('H', 1.0)
    # sodium.add_s_alpha_beta('c_Graphite')
    naoh.temperature = 900  #kelvin
    mat_list.append(naoh)

    # TRISO Materials
    fuel = openmc.Material(name='Fuel')
    fuel.set_density('g/cm3', 10.5)
    # fuel.add_nuclide('U235', 4.6716e-02)
    fuel.add_nuclide('U235', 0.0667372)
    # fuel.add_nuclide('U238', 2.8697e-01)
    fuel.add_nuclide('U238', 0.2669488)
    fuel.add_nuclide('O16', 5.0000e-01)
    fuel.add_element('C', 1.6667e-01)
    mat_list.append(fuel)

    buff = openmc.Material(name='Buffer')
    buff.set_density('g/cm3', 1.0)
    buff.add_element('C', 1.0)
    buff.add_s_alpha_beta('c_Graphite')
    mat_list.append(buff)

    PyC1 = openmc.Material(name='PyC1')
    PyC1.set_density('g/cm3', 1.9)
    PyC1.add_element('C', 1.0)
    PyC1.add_s_alpha_beta('c_Graphite')
    mat_list.append(PyC1)

    PyC2 = openmc.Material(name='PyC2')
    PyC2.set_density('g/cm3', 1.87)
    PyC2.add_element('C', 1.0)
    PyC2.add_s_alpha_beta('c_Graphite')
    mat_list.append(PyC2)

    SiC = openmc.Material(name='SiC')
    SiC.set_density('g/cm3', 3.2)
    SiC.add_element('C', 0.5)
    SiC.add_element('Si', 0.5)
    mat_list.append(SiC)

    fuel_temp = 900
    homogeneous_fuel = build_fuel_material(fuel_temp, pack_frac)
    mat_list.append(homogeneous_fuel)

    mats = openmc.Materials(mat_list)
    mats.export_to_xml()

    #############################
    ###       GEOMETRY        ###
    #############################
    pitch = 17.4
    fuel_bottom = -pitch / 2
    fuel_top = pitch / 2
    coolant_r = 4
    # fuel_r = (pitch/2 - coolant_r)/2
    fuel_r = (pitch / (3**(1 / 2)) - coolant_r) / 2

    hex_universe = openmc.Universe()

    top = openmc.ZPlane(z0=fuel_top, boundary_type='reflective')
    bottom = openmc.ZPlane(z0=fuel_bottom, boundary_type='reflective')
    surf_fuel = openmc.ZCylinder(r=fuel_r)

    # Make TRISOS to be filled in fuel cylinders by chopping up
    # fuel cylinder into segments
    n_cyls = 40
    fuel_segment_heights = np.linspace(fuel_bottom, fuel_top, n_cyls)
    segment_height = fuel_segment_heights[1] - fuel_segment_heights[0]
    fuel_planes = [bottom]
    fuel_cells = []
    for i, height in enumerate(fuel_segment_heights[1:-1]):
        this_plane = openmc.ZPlane(z0=height)
        fuel_planes.append(this_plane)
        this_cell = openmc.Cell()
        this_cell.region = +fuel_planes[i] & -fuel_planes[i + 1] & -surf_fuel
        fuel_cells.append(copy.deepcopy(this_cell))
    # last cell
    fuel_planes.append(top)
    this_cell = openmc.Cell()
    this_cell.region = +fuel_planes[-2] & -fuel_planes[-1] & -surf_fuel
    fuel_cells.append(copy.deepcopy(this_cell))

    # Make fuel cylinder
    fuel_cyl_top = openmc.ZPlane(z0=segment_height / 2)
    fuel_cyl_bottom = openmc.ZPlane(z0=-segment_height / 2)
    fuel_triso_region = -surf_fuel & +fuel_cyl_bottom & -fuel_cyl_top
    outer_radius = 425. * 1e-4
    # openmc.model.triso._Cylinder.from_region(fuel_region, outer_radius)

    spheres = [openmc.Sphere(r=r * 1e-4) for r in [215., 315., 350., 385.]]
    cells = [
        openmc.Cell(fill=fuel, region=-spheres[0]),
        openmc.Cell(fill=buff, region=+spheres[0] & -spheres[1]),
        openmc.Cell(fill=PyC1, region=+spheres[1] & -spheres[2]),
        openmc.Cell(fill=SiC, region=+spheres[2] & -spheres[3]),
        openmc.Cell(fill=PyC2, region=+spheres[3])
    ]
    triso_univ = openmc.Universe(cells=cells)
    outer_radius = 425. * 1e-4
    centers = openmc.model.pack_spheres(radius=outer_radius,
                                        region=fuel_triso_region,
                                        pf=pack_frac)
    trisos = [openmc.model.TRISO(outer_radius, triso_univ, c) for c in centers]
    outside_trisos = openmc.Intersection(~t.region for t in trisos)
    # background_region = outside_trisos & +fuel_cyl_bottom & \
    # -fuel_cyl_top & -surf_fuel
    background_region = outside_trisos
    background_cell = openmc.Cell(fill=graphite, region=background_region)

    fuel_triso_univ = openmc.Universe()
    fuel_triso_univ.add_cell(background_cell)
    for idx, triso in enumerate(trisos):
        fuel_triso_univ.add_cell(triso)

    # Fill in fuel cells with triso cells and translate to location
    for i, cell in enumerate(fuel_cells):
        cell_height = segment_height * (i + 1 / 2) + fuel_bottom
        cell.translation = [0, 0, cell_height]
        cell.fill = fuel_triso_univ
    fuel_cell_univ = openmc.Universe(cells=fuel_cells)

    # For testing solid fuel
    # test_region = +bottom & -top & -surf_fuel
    # fuel_cell = openmc.Cell(region=test_region, fill=fuel)
    # fuel_cell_univ = openmc.Universe(cells=[fuel_cell])

    coolant_cyl = openmc.ZCylinder(r=coolant_r)
    coolant_region = -coolant_cyl
    coolant_cell = openmc.Cell()
    coolant_cell.fill = naoh
    coolant_cell.region = coolant_region
    hex_universe.add_cell(coolant_cell)

    hex_prism = openmc.get_hexagonal_prism(edge_length=pitch / (3**1 / 2),
                                           boundary_type='reflective')

    graphite_region = hex_prism & +coolant_cyl & -top & +bottom
    graphite_cell = openmc.Cell()
    graphite_cell.fill = graphite
    graphite_cell.region = graphite_region
    hex_universe.add_cell(graphite_cell)

    fuel_cells = []
    root3 = 3**(1 / 2)
    half_to_vertex = pitch / root3 / 2
    half_to_edge = pitch / 4

    # fuel_id = 100
    offset_angle = 30
    n_pins = 6
    for i in range(n_pins):
        theta = (offset_angle + i / n_pins * 360) * pi / 180
        r = coolant_r + fuel_r + 0.01
        x = r * np.cos(theta)
        y = r * np.sin(theta)

        fuel_cyl_bound = openmc.ZCylinder(x0=x, y0=y, r=fuel_r)
        graphite_cell.region &= +fuel_cyl_bound

        fuel_cell = openmc.Cell()
        fuel_cell.fill = copy.deepcopy(fuel_cell_univ)
        fuel_cell.translation = [x, y, 0]
        fuel_cell.region = -fuel_cyl_bound & -top & +bottom
        # fuel_cell.id = fuel_id
        # fuel_id += 1

        fuel_cells.append(fuel_cell)
        hex_universe.add_cell(fuel_cell)

    geom = openmc.Geometry(hex_universe)
    # geom = openmc.Geometry(fuel_cell_univ)
    geom.export_to_xml()

    #####################################
    ###        SOURCE/BATCHES         ###
    #####################################
    point = openmc.stats.Point((0, 0, 0))
    src = openmc.Source(space=point)

    settings.source = src
    settings.batches = 50
    settings.inactive = 10
    settings.particles = 200

    settings.export_to_xml()

    #############################
    ###       TALLIES         ###
    #############################
    # Instantiate an empty Tallies object
    tallies_file = openmc.Tallies()

    # K-Eigenvalue (infinity) tallies
    fiss_rate = openmc.Tally(name='fiss. rate')
    fiss_rate.scores = ['nu-fission']
    tallies_file.append(fiss_rate)

    abs_rate = openmc.Tally(name='abs. rate')
    abs_rate.scores = ['absorption']
    tallies_file.append(abs_rate)

    # Resonance Escape Probability tallies
    therm_abs_rate = openmc.Tally(name='therm. abs. rate')
    therm_abs_rate.scores = ['absorption']
    therm_abs_rate.filters = [openmc.EnergyFilter([0., 0.625])]
    tallies_file.append(therm_abs_rate)

    # Thermal Flux Utilization tallies
    # fuel_therm_abs_rate = openmc.Tally(name='fuel therm. abs. rate')
    # fuel_therm_abs_rate.scores = ['absorption']
    # fuel_therm_abs_rate.filters = [openmc.EnergyFilter([0., 0.625]),
    #                                        openmc.CellFilter([fuel_cell])]
    # tallies_file.append(fuel_therm_abs_rate)

    # Fast Fission Factor tallies
    therm_fiss_rate = openmc.Tally(name='therm. fiss. rate')
    therm_fiss_rate.scores = ['nu-fission']
    therm_fiss_rate.filters = [openmc.EnergyFilter([0., 0.625])]
    tallies_file.append(therm_fiss_rate)

    tallies_file.export_to_xml()

    #############################
    ###       PLOTTING        ###
    #############################
    zs = np.linspace(0, 1, 2)
    plots = []
    for z in zs:
        p = openmc.Plot()
        p.filename = 'pinplot' + str(z)
        p.width = (1.4 * pitch, 1.4 * pitch)
        p.pixels = (2000, 2000)
        p.color_by = 'material'
        p.origin = [0, 0, z]
        # p.color_by = 'cell'
        # p.colors = {homogeneous_fuel: 'yellow', naoh: 'grey', graphite: 'black'}
        p.colors = {fuel: 'yellow', naoh: 'grey', graphite: 'black'}
        plots.append(copy.deepcopy(p))

    plots = openmc.Plots(plots)
    plots.export_to_xml()

    # openmc.plot_geometry(output = False)
    openmc.plot_geometry()
    # pngstring = 'pinplot{}.png'.format(str(pitch))
    # subprocess.call(['convert','pinplot.ppm',pngstring])
    # subprocess.call(['mv',pngstring,'figures/'+pngstring])

    #############################
    ###       EXECUTION       ###
    #############################
    # openmc.run(output=False)
    openmc.run()
    sp = openmc.StatePoint('statepoint.{}.h5'.format(settings.batches))
    # Collect all the tallies
    fiss_rate = sp.get_tally(name='fiss. rate')
    fiss_rate_df = fiss_rate.get_pandas_dataframe()
    abs_rate = sp.get_tally(name='abs. rate')
    abs_rate_df = abs_rate.get_pandas_dataframe()
    therm_abs_rate = sp.get_tally(name='therm. abs. rate')
    therm_abs_rate_df = therm_abs_rate.get_pandas_dataframe()
    fuel_therm_abs_rate = sp.get_tally(name='fuel therm. abs. rate')
    fuel_therm_abs_rate_df = fuel_therm_abs_rate.get_pandas_dataframe()
    therm_fiss_rate = sp.get_tally(name='therm. fiss. rate')
    therm_fiss_rate_df = therm_fiss_rate.get_pandas_dataframe()

    # Compute k-infinity
    kinf = fiss_rate / abs_rate
    kinf_df = kinf.get_pandas_dataframe()

    # Compute resonance escape probability
    res_esc = (therm_abs_rate) / (abs_rate)
    res_esc_df = res_esc.get_pandas_dataframe()

    # Compute fast fission factor
    fast_fiss = fiss_rate / therm_fiss_rate
    fast_fiss_df = fast_fiss.get_pandas_dataframe()

    # Compute thermal flux utilization
    therm_util = fuel_therm_abs_rate / therm_abs_rate
    therm_util_df = therm_util.get_pandas_dataframe()

    # Compute neutrons produced per absorption
    eta = therm_fiss_rate / fuel_therm_abs_rate
    eta_df = eta.get_pandas_dataframe()

    columns = [
        'pitch', 'enrichment', 'kinf mean', 'kinf sd', 'res_esc mean',
        'res_esc sd', 'fast_fiss mean', 'fast_fiss sd', 'therm_util mean',
        'therm_util sd', 'eta mean', 'eta sd'
    ]
    data = [[
        pitch, enrichment, kinf_df['mean'][0], kinf_df['std. dev.'][0],
        res_esc_df['mean'][0], res_esc_df['std. dev.'][0],
        fast_fiss_df['mean'][0], fast_fiss_df['std. dev.'][0],
        therm_util_df['mean'][0], therm_util_df['std. dev.'][0],
        eta_df['mean'][0], eta_df['std. dev.'][0]
    ]]
    all_tallies = pd.DataFrame(data, columns=columns)

    return all_tallies
Esempio n. 12
0
 def write_openmc_plots(self):
     self.plots = Plots(self.mats)
     plot_file = openmc.Plots(self.plots.plots)
     plot_file.export_to_xml()
Esempio n. 13
0
def make_geometry_tallies(batches, nps, inner_radius, thickness):

    first_wall_inner_surface = openmc.Sphere(r=inner_radius)
    first_wall_outer_surface = openmc.Sphere(r=inner_radius + thickness,
                                             boundary_type='vacuum')

    first_wall = +first_wall_inner_surface & -first_wall_outer_surface
    first_wall = openmc.Cell(region=first_wall)
    first_wall.fill = eurofer

    inner_vac_cell = -first_wall_inner_surface
    inner_vac_cell = openmc.Cell(region=inner_vac_cell)

    universe = openmc.Universe(cells=[first_wall, inner_vac_cell])
    geom = openmc.Geometry(universe)

    geom.export_to_xml('geometry')

    vox_plot = openmc.Plot()
    vox_plot.type = 'voxel'
    vox_plot.width = (15, 15, 15)
    vox_plot.pixels = (200, 200, 200)
    vox_plot.filename = 'plot_3d'
    vox_plot.color_by = 'material'
    vox_plot.colors = {eurofer: 'blue'}
    plots = openmc.Plots([vox_plot])
    plots.export_to_xml()

    openmc.plot_geometry()

    os.system('openmc-voxel-to-vtk plot_3d.h5 -o plot_3d.vti')
    os.system('paraview plot_3d.vti')

    sett = openmc.Settings()
    sett.batches = batches
    sett.inactive = 0
    sett.particles = nps
    sett.run_mode = 'fixed source'

    source = openmc.Source()
    source.space = openmc.stats.Point((0, 0, 0))
    source.angle = openmc.stats.Isotropic()
    source.energy = openmc.stats.Discrete([14.08e6], [1])
    #source.energy = openmc.stats.Muir(e0=14080000.0, m_rat=5.0, kt=20000.0)
    sett.source = source

    sett.export_to_xml('settings.xml')

    #tallies
    particle_filter = openmc.ParticleFilter([1])
    surface_filter_front = openmc.SurfaceFilter(first_wall_inner_surface)
    surface_filter_rear = openmc.SurfaceFilter(first_wall_outer_surface)
    bins = openmc.mgxs.GROUP_STRUCTURES['VITAMIN-J-175']
    #think will need to change this
    energy_filter = openmc.EnergyFilter(bins)

    tallies = openmc.Tallies()

    tally = openmc.Tally(name='incident_neutron_current')
    tally.filters = [surface_filter_front, particle_filter]
    tally.scores = ['current']
    tallies.append(tally)

    tally = openmc.Tally(name='leakage_neutron_current')
    tally.filters = [surface_filter_rear, particle_filter]
    tally.scores = ['current']
    tallies.append(tally)

    tally = openmc.Tally(name='incident_neutron_spectrum')
    tally.filters = [surface_filter_rear, particle_filter, energy_filter]
    tally.scores = ['flux']
    tallies.append(tally)

    tally = openmc.Tally(name='leakage_neutron_spectrum')
    tally.filters = [surface_filter_front, particle_filter, energy_filter]
    tally.scores = ['flux']
    tallies.append(tally)

    model = openmc.model.Model(geom, mats, sett, tallies)
    model.run()

    sp = openmc.StatePoint('statepoint.' + str(batches) + '.h5')

    #we want to retrieve our tallies, but we now want to save them in a .json file
    #therefore, we setup the json file to recieve the tally data
    #for now, we will simply get the json file to get the neutron current
    #first, we specify the 'general' parameters about the setup that we want the .json file to recieve

    json_output = {'inner_radius': inner_radius, 'thickness': thickness}

    #i.e. these are the general parameters about the setup that we want the json file to recieve

    #however, we also want the json file to retrieve the data from the tallies

    #first, we want to retrieve the neutron current at the inner and outer surfaces
    tallies_to_retrieve = [
        'incident_neutron_current', 'leakage_neutron_current'
    ]
    for tally_name in tallies_to_retrieve:
        tally = sp.get_tally(name=tally_name)

        df = tally.get_pandas_dataframe()
        #defining something that stands for dataframe, need to investigate this
        #its basically something that we use to obtain the mean value and the std deviation value of the tally
        tally_result = df['mean'].sum()
        tally_std_dev = df['std. dev.'].sum()

        json_output[tally_name] = {
            'value': tally_result,
            'std_dev': tally_std_dev
        }

    #next we wnat to retrieve the neutron spectra data at the inner and outer surfaces of the shell

    spectra_tallies_to_retrieve = [
        'incident_neutron_spectrum', 'leakage_neutron_spectrum'
    ]
    for spectra_name in spectra_tallies_to_retrieve:
        spectra_tally = sp.get_tally(name=spectra_name)
        spectra_tally_result = [entry[0][0] for entry in spectra_tally.mean]
        spectra_tally_std_dev = [
            entry[0][0] for entry in spectra_tally.std_dev
        ]
        #print(spectra_tally_result)

    return json_output
Esempio n. 14
0
plot2.basis = 'xz'
plot2.width = [200.0, 200.0]
plot2.pixels = [1000, 1000]
plot2.color = "material"

plot3 = openmc.Plot()
plot3.filename = 'materials-yz'
plot3.origin = [0, 0, 0]
plot3.basis = 'yz'
plot3.width = [200.0, 200.0]
plot3.pixels = [3000, 3000]
plot3.color = "material"


# Instantiate a Plots collection and export to "plots.xml"
plot_file = openmc.Plots([plot1, plot2, plot3])
plot_file.export_to_xml()

#openmc.plot_geometry()

#plot1.plot_inline()

# Plot inline in jupyter or QtConsole
openmc.plot_inline(plot1)


# In[11]:


openmc.plot_inline(plot2)
Esempio n. 15
0
def hexfunction(pitch, pack_frac):

    settings = openmc.Settings()
    # Set high tolerance to allow use of lower temperature xs
    settings.temperature['tolerance'] = 1000
    settings.temperature['method'] = 'nearest'
    settings.temperature['multipole'] = True
    settings.cutoff = {'energy': 1e-8}  #energy cutoff in eV

    #############################
    ###       MATERIALS       ###
    #############################
    enrichment = 20.0

    uo2 = openmc.Material(1, "uo2")
    uo2.add_element('U', 1.0, enrichment=enrichment)
    uo2.add_element('O', 2.0)
    uo2.set_density('g/cm3', 10.97)
    uo2.temperature = 900  #kelvin

    graphite = openmc.Material(2, "graphite")
    graphite.set_density('g/cm3', 1.1995)
    graphite.add_element('C', 1.0)
    graphite.add_s_alpha_beta('c_Graphite')
    graphite.temperature = 900  #kelvin

    sodium = openmc.Material(3, "sodium")
    sodium.set_density('g/cm3', 0.8017)  # 900 K
    sodium.add_element('Na', 1.0)
    # sodium.add_s_alpha_beta('c_Graphite')
    sodium.temperature = 900  #kelvin

    naoh = openmc.Material(6, "naoh")
    naoh.set_density('g/cm3', 1.5)  # 900 K
    naoh.add_element('Na', 1.0)
    naoh.add_element('O', 1.0)
    naoh.add_element('H', 1.0)
    # sodium.add_s_alpha_beta('c_Graphite')
    naoh.temperature = 900  #kelvin

    uo2 = openmc.Material(1, "uo2")
    uo2.add_element('U', 1.0, enrichment=enrichment)
    uo2.add_element('O', 2.0)
    uo2.set_density('g/cm3', 10.97)
    uo2.temperature = 900  #kelvin

    fuel_temp = 900
    homogeneous_fuel = build_fuel_material(4, fuel_temp, pack_frac)

    mats = openmc.Materials([uo2, graphite, sodium, naoh, homogeneous_fuel])
    mats.export_to_xml()

    #############################
    ###       GEOMETRY        ###
    #############################
    universe = openmc.Universe()

    coolant_cyl = openmc.ZCylinder(R=0.5)
    coolant_region = -coolant_cyl
    coolant_cell = openmc.Cell(1, 'coolant')
    coolant_cell.fill = naoh
    coolant_cell.region = coolant_region

    hex_prism = openmc.get_hexagonal_prism(edge_length=pitch / (3**1 / 2),
                                           boundary_type='reflective')
    top = openmc.YPlane(y0=pitch)
    bottom = openmc.YPlane(y0=-pitch)
    fuel_region = hex_prism & -top & +bottom
    fuel_cell = openmc.Cell(2, 'moderator')
    fuel_cell.fill = homogeneous_fuel
    fuel_cell.region = fuel_region

    root = openmc.Universe(cells=(fuel_cell, coolant_cell))
    geom = openmc.Geometry(root)
    geom.export_to_xml()

    #####################################
    ###        SOURCE/BATCHES         ###
    #####################################
    point = openmc.stats.Point((0, 0, 0))
    src = openmc.Source(space=point)

    settings.source = src
    settings.batches = 50
    settings.inactive = 10
    settings.particles = 200

    settings.export_to_xml()

    #############################
    ###       TALLIES         ###
    #############################
    # Instantiate an empty Tallies object
    tallies_file = openmc.Tallies()

    # K-Eigenvalue (infinity) tallies
    fiss_rate = openmc.Tally(name='fiss. rate')
    fiss_rate.scores = ['nu-fission']
    tallies_file.append(fiss_rate)

    abs_rate = openmc.Tally(name='abs. rate')
    abs_rate.scores = ['absorption']
    tallies_file.append(abs_rate)

    # Resonance Escape Probability tallies
    therm_abs_rate = openmc.Tally(name='therm. abs. rate')
    therm_abs_rate.scores = ['absorption']
    therm_abs_rate.filters = [openmc.EnergyFilter([0., 0.625])]
    tallies_file.append(therm_abs_rate)

    # Thermal Flux Utilization tallies
    fuel_therm_abs_rate = openmc.Tally(name='fuel therm. abs. rate')
    fuel_therm_abs_rate.scores = ['absorption']
    fuel_therm_abs_rate.filters = [
        openmc.EnergyFilter([0., 0.625]),
        openmc.CellFilter([fuel_cell])
    ]
    tallies_file.append(fuel_therm_abs_rate)

    # Fast Fission Factor tallies
    therm_fiss_rate = openmc.Tally(name='therm. fiss. rate')
    therm_fiss_rate.scores = ['nu-fission']
    therm_fiss_rate.filters = [openmc.EnergyFilter([0., 0.625])]
    tallies_file.append(therm_fiss_rate)

    tallies_file.export_to_xml()

    #############################
    ###       PLOTTING        ###
    #############################
    p = openmc.Plot()
    p.filename = 'pinplot'
    p.width = (2 * pitch, 2 * pitch)
    p.pixels = (200, 200)
    p.color_by = 'material'
    p.colors = {homogeneous_fuel: 'yellow', sodium: 'grey'}

    plots = openmc.Plots([p])
    plots.export_to_xml()

    # openmc.plot_geometry(output = False)
    openmc.plot_geometry()
    pngstring = 'pinplot{}.png'.format(str(pitch))
    subprocess.call(['convert', 'pinplot.ppm', pngstring])
    subprocess.call(['mv', pngstring, 'figures/' + pngstring])

    #############################
    ###       EXECUTION       ###
    #############################
    # openmc.run(output=False)
    openmc.run()
    sp = openmc.StatePoint('statepoint.{}.h5'.format(settings.batches))
    # Collect all the tallies
    fiss_rate = sp.get_tally(name='fiss. rate')
    fiss_rate_df = fiss_rate.get_pandas_dataframe()
    abs_rate = sp.get_tally(name='abs. rate')
    abs_rate_df = abs_rate.get_pandas_dataframe()
    therm_abs_rate = sp.get_tally(name='therm. abs. rate')
    therm_abs_rate_df = therm_abs_rate.get_pandas_dataframe()
    fuel_therm_abs_rate = sp.get_tally(name='fuel therm. abs. rate')
    fuel_therm_abs_rate_df = fuel_therm_abs_rate.get_pandas_dataframe()
    therm_fiss_rate = sp.get_tally(name='therm. fiss. rate')
    therm_fiss_rate_df = therm_fiss_rate.get_pandas_dataframe()

    # Compute k-infinity
    kinf = fiss_rate / abs_rate
    kinf_df = kinf.get_pandas_dataframe()

    # Compute resonance escape probability
    res_esc = (therm_abs_rate) / (abs_rate)
    res_esc_df = res_esc.get_pandas_dataframe()

    # Compute fast fission factor
    fast_fiss = fiss_rate / therm_fiss_rate
    fast_fiss_df = fast_fiss.get_pandas_dataframe()

    # Compute thermal flux utilization
    therm_util = fuel_therm_abs_rate / therm_abs_rate
    therm_util_df = therm_util.get_pandas_dataframe()

    # Compute neutrons produced per absorption
    eta = therm_fiss_rate / fuel_therm_abs_rate
    eta_df = eta.get_pandas_dataframe()

    columns = [
        'pitch', 'enrichment', 'kinf mean', 'kinf sd', 'res_esc mean',
        'res_esc sd', 'fast_fiss mean', 'fast_fiss sd', 'therm_util mean',
        'therm_util sd', 'eta mean', 'eta sd'
    ]
    data = [[
        pitch, enrichment, kinf_df['mean'][0], kinf_df['std. dev.'][0],
        res_esc_df['mean'][0], res_esc_df['std. dev.'][0],
        fast_fiss_df['mean'][0], fast_fiss_df['std. dev.'][0],
        therm_util_df['mean'][0], therm_util_df['std. dev.'][0],
        eta_df['mean'][0], eta_df['std. dev.'][0]
    ]]
    all_tallies = pd.DataFrame(data, columns=columns)

    return all_tallies
Esempio n. 16
0
    def _build_inputs(self):
        ####################
        # Materials
        ####################

        moderator = openmc.Material(material_id=1)
        moderator.set_density('g/cc', 1.0)
        moderator.add_nuclide('H-1', 2.0)
        moderator.add_nuclide('O-16', 1.0)

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

        mats_file = openmc.Materials([moderator, dense_fuel])
        mats_file.default_xs = '71c'
        mats_file.export_to_xml()

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

        c1 = openmc.Cell(cell_id=1)
        c1.fill = moderator
        mod_univ = openmc.Universe(universe_id=1)
        mod_univ.add_cell(c1)

        r0 = openmc.ZCylinder(R=0.3)
        c11 = openmc.Cell(cell_id=11)
        c11.region = -r0
        c11.fill = dense_fuel
        c11.temperature = [500, 0, 700, 800]
        c12 = openmc.Cell(cell_id=12)
        c12.region = +r0
        c12.fill = moderator
        fuel_univ = openmc.Universe(universe_id=11)
        fuel_univ.add_cells((c11, c12))

        lat = openmc.RectLattice(lattice_id=101)
        lat.dimension = [2, 2]
        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)
        c101.region = +x0 & -x1 & +y0 & -y1
        c101.fill = lat
        root_univ = openmc.Universe(universe_id=0)
        root_univ.add_cell(c101)

        geometry = openmc.Geometry()
        geometry.root_universe = 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 = Source(space=Box([-1, -1, -1], [1, 1, 1]))
        sets_file.output = {'summary': True}
        sets_file.use_windowed_multipole = True
        sets_file.export_to_xml()

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

        plots_file = openmc.Plots()

        plot = openmc.Plot(plot_id=1)
        plot.basis = 'xy'
        plot.color = 'cell'
        plot.filename = 'cellplot'
        plot.origin = (0, 0, 0)
        plot.width = (7, 7)
        plot.pixels = (400, 400)
        plots_file.append(plot)

        plot = openmc.Plot(plot_id=2)
        plot.basis = 'xy'
        plot.color = 'mat'
        plot.filename = 'matplot'
        plot.origin = (0, 0, 0)
        plot.width = (7, 7)
        plot.pixels = (400, 400)
        plots_file.append(plot)

        plots_file.export_to_xml()
Esempio n. 17
0
def make_model_mg(nameoflib):
    element = name_el(PATH_INOUT_DATA)
    nuclide = xml_f(PATH_REACTION_XML)
    print("Start")
    print(nuclide, element)
    diction_1, diction_2, diction_3, dzz, hss, rods, densna, type_fuel, type_assembly = run(PATH_INOUT_DATA)
    print('First point', dzz, hss,rods)
    nkas = len(rods)
    diction_mg   = translate_mg(nkas, rods, dzz, [sum(dzz)])
    outuniv, outsurface = _make_outer_mg_universe(diction_mg[(1,1)])
    #
    assemblies = {}
    load_dict  = {}
    hexsurf, rodfaces = make_surfaces([sum(dzz)], HPITCH)
    hexsurf, zfaces   = make_surfaces(dzz, HPITCH)
    for i in range(NASS):
        if (rods[i]):
            assemblies[i+1] = make_abl_mg_cells(diction_mg, hexsurf, rodfaces, i+1)
            load_dict[i+1]  = [i+1]
        else:
            assemblies[i+1] = make_abl_mg_cells(diction_mg, hexsurf, zfaces, i+1)
            load_dict[i+1]  = [i+1]
    print("Making load ..")
    ##################################################################################
    load = make_load("BN-800", outuniv, assemblies, NRING, HPITCH, sum(dzz), load_dict)
    root_cell = openmc.Cell(cell_id=0, region=-outsurface, fill=load)
    root_univ = openmc.Universe(universe_id=0, cells = [root_cell])
    # Instantiate a Geometry, register the root Universe, and export to XML
    openmc_geometry = openmc.Geometry()
    openmc_geometry.root_universe = root_univ
    openmc_geometry.export_to_xml()
    materials_list = openmc_geometry.get_all_materials()
    materials_file = openmc.Materials([v for v in materials_list.values()])
    materials_file.cross_sections = nameoflib
    materials_file.export_to_xml()
    # Instantiate a Settings object, set all runtime parameters, and export to XML
    settings_file = openmc.Settings()
    ##########################SETTINGS
    settings_file.batches = 120
    settings_file.inactive = 20
    settings_file.particles = 1000
    ###########################
    settings_file.temperature = {'range':(250,2500)}
    # Tell OpenMC this is a multi-group problem
    settings_file.energy_mode = 'multi-group'
    settings_file.source = openmc.Source(space=openmc.stats.Box(
        [-160.04, -160.04, 0.0], [160.04, 160.04, 170], only_fissionable=True))
    settings_file.export_to_xml()
    return openmc
    plot_1 = openmc.Plot(plot_id=1)
    plot_1.filename = 'plot_1'
    plot_1.origin = [0.0, 0.0, 8.]
    plot_1.width = [520.26, 520.26]
    plot_1.pixels = [2400, 2400]
    plot_1.color = 'mat'
    plot_1.basis = 'xy'

    plot_2 = openmc.Plot(plot_id=2)
    plot_2.filename = 'plot_2'
    plot_2.origin = [0.0, 0.0, 0.0]
    plot_2.width = [520.26, 350.2]
    plot_2.pixels = [1200, 1200]
    plot_2.color = 'mat'
    plot_2.basis = 'xz'

    # Instantiate a Plots collection and export to XML
    plot_file = openmc.Plots([plot_1, plot_2])
plot.width = [10.71 * 2] * 2
plot.basis = 'xy'
plot.color = 'mat'
plot.filename = 'materials'
plot.pixels = [2000, 2000]
plot.mask_background = [255, 255, 255]
plot.col_spec = {
    water.id: [102, 178, 255],  # water:  blue
    zirconium.id: [96, 96, 96],  # zirc:   gray
    uo2.id: [255, 75, 75],  # fuel:   red
    pyrex.id: [0, 153, 0],  # pyrex:  green
    void.id: [0, 0, 0]  # void:   white
}

# Instantiate a Materials collection and export to "materials.xml"
plots = openmc.Plots([plot])
plots.export_to_xml()

###############################################################################
#                   Create Mesh Tallies for Verification
###############################################################################

# Instantiate a tally Mesh
mesh = openmc.Mesh(name='assembly mesh')
mesh.type = 'regular'
mesh.dimension = assembly.dimension
mesh.lower_left = assembly.lower_left
mesh.width = assembly.pitch

# Instantiate mesh Filter
mesh_filter = openmc.Filter()
Esempio n. 19
0
p3 = openmc.Plot()
p3.filename = 'materials-yz'
p3.origin = [0, 0, 0]
p3.basis = 'yz'
p3.width = [200.0, 200.0]
p3.pixels = [3000, 3000]
p3.color = "material"
#p3.colors = {steel: 'lightsteelblue', fuel_material: 'magenta', shielding: 'black',
            #clad: 'burlywood', helium: 'limegreen', uo2_2: 'yellow', heavy_water: 'teal',
            #cold_water: 'lightskyblue', hot_water: 'blue', borated_water: 'cyan'}



#Make a collection of plots
plot_files = openmc.Plots([p1,p2,p3])
plot_files.export_to_xml()


plt.show()
#Uncomment this!!!!1 line
#openmc.plot_geometry()
#openmc.run()

#Uncomment this!!!!!
"""
print("Running depletion...")
op = openmc.deplete.Operator(geometry, settings, chain_file)
# Perform simulation using the cecm algorithm
openmc.deplete.CECMIntegrator(op, timesteps, power).integrate()
"""
Esempio n. 20
0
def shield(rad, major, coil, bool, outer, m_batches, m_error, neutrons):

    #MATERIALS#

    min = coil
    max = outer+coil
    major_rad = major + outer

    R1 = rad[0]
    R2 = rad[1]

    mats = openmc.Materials()

    tungsten = openmc.Material(name='Tungsten carbide')
    tungsten.set_density('g/cm3', 15.63)
    tungsten.add_element('W', 1.0)
    tungsten.add_element('C', 1.0)
    mats.append(tungsten)

    water = openmc.Material(name='Water')
    water.set_density('g/cm3', 1.0)
    water.add_element('H', 2.0)
    water.add_element('O', 1.0)
    mats.append(water)

    copper = openmc.Material(name='Copper')
    copper.set_density('g/cm3', 8.5)
    copper.add_element('Cu', 1.0)
    mats.append(copper)

    eurofer = openmc.Material(name='EUROFER97')
    eurofer.set_density('g/cm3', 7.75)
    eurofer.add_element('Fe', 89.067, percent_type='wo')
    eurofer.add_element('C', 0.11, percent_type='wo')
    eurofer.add_element('Mn', 0.4, percent_type='wo')
    eurofer.add_element('Cr', 9.0, percent_type='wo')
    eurofer.add_element('Ta', 0.12, percent_type='wo')
    eurofer.add_element('W', 1.1, percent_type='wo')
    eurofer.add_element('N', 0.003, percent_type='wo')
    eurofer.add_element('V', 0.2, percent_type='wo')
    mats.append(eurofer)

    #GEOMETRY#

    cylinder = openmc.ZCylinder(R=min)

    shield1 = openmc.ZCylinder(R=R1)
    shield2 = openmc.ZCylinder(R=R2)
    shield3 = openmc.ZCylinder(R=max)
    top = major_rad-(max-min)
    shield_sph1 = openmc.Sphere(R=top)
    shield_sph2 = openmc.Sphere(R=major_rad-(max-min)+(max-R2))
    shield_sph3 = openmc.Sphere(R=major_rad-(max-min)+(max-R2)+(R2-R1))

    pit = sqrt(top**2+top**2)
    max_shield = sqrt(top**2+pit**2)+1

    vessel_in = openmc.Sphere(R=major_rad)
    vessel_out = openmc.Sphere(R=max_shield, boundary_type='vacuum')

    magnet = -cylinder & -vessel_in

    mat1 = -shield1 & +cylinder & -shield_sph3  #work on this
    mat2 = -shield2 & +shield1 & -shield_sph2 #work on this
    mat3 = -shield3 & +shield2 & -shield_sph1 #work on this

    plasma = +shield3 & -shield_sph1

    a = +shield_sph1 & -shield_sph2 & +shield2 #work on this
    b = +shield_sph2 & -shield_sph3 & +shield1 #work on this
    c = +shield_sph3 & -vessel_in & +cylinder #work on this

    vessel = +vessel_in & -vessel_out

    plasma_cell = openmc.Cell(region=plasma) #1

    cop_mag = openmc.Cell(region=magnet) #2
    cop_mag.fill = copper

    tung1 = openmc.Cell(region=mat1) #3
    tung1.fill = tungsten
    wat = openmc.Cell(region=mat2) #4
    wat.fill = water
    tung2 = openmc.Cell(region=mat3) #5
    tung2.fill = tungsten

    ste_ves = openmc.Cell(region=vessel) #6
    ste_ves.fill = eurofer

    tung_sph1 = openmc.Cell(region=a) #7
    tung_sph1.fill = tungsten
    wat_sph = openmc.Cell(region=b) #8
    wat_sph.fill = water
    tung_sph2 = openmc.Cell(region=c) #9
    tung_sph2.fill = tungsten

    root = openmc.Universe(cells=(plasma_cell, cop_mag, tung1, wat, tung2, ste_ves, tung_sph1, wat_sph, tung_sph2))
    geom = openmc.Geometry(root)
    root.plot(width=(600.0, 600.0), basis='xz')

    #SETTINGS#

    batch = 2
    max_batches = m_batches
    inactive = 0
    particles = neutrons

    source = openmc.Source()
    source.space = openmc.stats.Box((-top,-top,-top),(top,top,top))
    source.angle = openmc.stats.Isotropic()
    source.energy = openmc.stats.Discrete([14e6], [1])

    sett = openmc.Settings()
    sett.batches = batch
    sett.trigger_active = True
    sett.trigger_max_batches = m_batches
    sett.inactive = inactive
    sett.particles = particles
    sett.output = {'tallies': True}
    sett.run_mode = 'fixed source'
    sett.source = source

    #PLOT#

    plots = openmc.Plots()

    plot = openmc.Plot()
    #plot.type = 'voxel'
    plot.basis = 'xz'
    plot.origin = (0, 0, 0)
    plot.width = (600, 600)
    plot.pixels = (1000, 1000)
    plot.color_by = 'material'
    plot.colors = {tungsten: 'black', water: 'blue', eurofer: 'grey', copper: 'brown'}
    plots.append(plot)

    plots.export_to_xml()

    #TALLIES#

    tallies = openmc.Tallies()

    filter = openmc.CellFilter(cop_mag)

    tally = openmc.Tally(name='total')
    tally.scores = ['total']
    tally.filters = [filter]
    trigger = openmc.Trigger('rel_err', m_error/100)
    tally.triggers = [trigger]
    tallies.append(tally)

    model = openmc.model.Model(geom, mats, sett, tallies)

    #RUN#

    model.run(output=bool)

    for i in reversed(range(batch,max_batches+1)):
        filename = 'statepoint.' +str(i).zfill(len(str(max_batches)))+ '.h5'
        if os.path.isfile(filename):
            sp = openmc.StatePoint(filename)
            break

    #print('file:',filename)
    leakage = sp.get_tally(name='total')
    leakage_mean = leakage.mean[0][0][0]
    leakage_error = leakage.std_dev[0][0][0]
    #print(leakage_mean)
    #print(leakage_error)

    dir = '/home/emiralle/shield_git'
    for zippath in glob.iglob(os.path.join(dir, '*.h5')):
        os.remove(zippath)

    return leakage_mean, leakage_error
Esempio n. 21
0
# Instantiate a Tallies collection and export to XML
tallies_file = openmc.Tallies([tally])
tallies_file.export_to_xml()

plot1 = openmc.Plot()
plot1.filename = 'materials-xy'
plot1.origin = [0, 0, 0]
plot1.basis = 'xy'
plot1.width = [1.0, 1.0]
plot1.pixels = [3000, 3000]
plot1.color = "material"

# Plot inline in jupyter or QtConsole
#openmc.plot_inline(plot1)
plots = openmc.Plots([plot1])
plots.export_to_xml()

#openmc.plot_geometry()

#openmc.run()


################################ Neutron fluxes

sp = openmc.StatePoint('statepoint.10.h5')

tally = sp.get_tally(scores=['flux'])

print(tally)
Esempio n. 22
0
plot_xy.filename = 'plot_xy'
plot_xy.origin = [0, 0, 0]
plot_xy.width = [6, 6]
plot_xy.pixels = [400, 400]
plot_xy.color_by = 'material'

plot_yz = openmc.Plot(plot_id=2)
plot_yz.filename = 'plot_yz'
plot_yz.basis = 'yz'
plot_yz.origin = [0, 0, 0]
plot_yz.width = [8, 8]
plot_yz.pixels = [400, 400]
plot_yz.color_by = 'material'

# Instantiate a Plots collection, add plots, and export to XML
plot_file = openmc.Plots((plot_xy, plot_yz))
plot_file.export_to_xml()

###############################################################################
#                   Exporting to OpenMC tallies.xml File
###############################################################################

# Instantiate a distribcell Tally
tally = openmc.Tally(tally_id=1)
tally.filters = [openmc.DistribcellFilter(cell2)]
tally.scores = ['total']

# Instantiate a Tallies collection and export to XML
tallies_file = openmc.Tallies([tally])
tallies_file.export_to_xml()
Esempio n. 23
0
def pin_model_attributes():
    uo2 = openmc.Material(material_id=1, name='UO2')
    uo2.set_density('g/cm3', 10.29769)
    uo2.add_element('U', 1., enrichment=2.4)
    uo2.add_element('O', 2.)
    uo2.depletable = True

    zirc = openmc.Material(material_id=2, name='Zirc')
    zirc.set_density('g/cm3', 6.55)
    zirc.add_element('Zr', 1.)
    zirc.depletable = False

    borated_water = openmc.Material(material_id=3, name='Borated water')
    borated_water.set_density('g/cm3', 0.740582)
    borated_water.add_element('B', 4.0e-5)
    borated_water.add_element('H', 5.0e-2)
    borated_water.add_element('O', 2.4e-2)
    borated_water.add_s_alpha_beta('c_H_in_H2O')
    borated_water.depletable = False

    mats = openmc.Materials([uo2, zirc, borated_water])

    pitch = 1.25984
    fuel_or = openmc.ZCylinder(r=0.39218, name='Fuel OR')
    clad_or = openmc.ZCylinder(r=0.45720, name='Clad OR')
    box = openmc.model.rectangular_prism(pitch,
                                         pitch,
                                         boundary_type='reflective')

    # Define cells
    fuel_inf_cell = openmc.Cell(cell_id=1, name='inf fuel', fill=uo2)
    fuel_inf_univ = openmc.Universe(universe_id=1, cells=[fuel_inf_cell])
    fuel = openmc.Cell(cell_id=2,
                       name='fuel',
                       fill=fuel_inf_univ,
                       region=-fuel_or)
    clad = openmc.Cell(cell_id=3, fill=zirc, region=+fuel_or & -clad_or)
    water = openmc.Cell(cell_id=4, fill=borated_water, region=+clad_or & box)

    # Define overall geometry
    geom = openmc.Geometry([fuel, clad, water])
    uo2.volume = pi * fuel_or.r**2

    settings = openmc.Settings()
    settings.batches = 100
    settings.inactive = 10
    settings.particles = 1000

    # Create a uniform spatial source distribution over fissionable zones
    bounds = [-0.62992, -0.62992, -1, 0.62992, 0.62992, 1]
    uniform_dist = openmc.stats.Box(bounds[:3],
                                    bounds[3:],
                                    only_fissionable=True)
    settings.source = openmc.source.Source(space=uniform_dist)

    entropy_mesh = openmc.RegularMesh()
    entropy_mesh.lower_left = [-0.39218, -0.39218, -1.e50]
    entropy_mesh.upper_right = [0.39218, 0.39218, 1.e50]
    entropy_mesh.dimension = [10, 10, 1]
    settings.entropy_mesh = entropy_mesh

    tals = openmc.Tallies()
    tal = openmc.Tally(tally_id=1, name='test')
    tal.filters = [openmc.MaterialFilter(bins=[uo2])]
    tal.scores = ['flux', 'fission']
    tals.append(tal)

    plot1 = openmc.Plot(plot_id=1)
    plot1.origin = (0., 0., 0.)
    plot1.width = (pitch, pitch)
    plot1.pixels = (300, 300)
    plot1.color_by = 'material'
    plot1.filename = 'test'
    plot2 = openmc.Plot(plot_id=2)
    plot2.origin = (0., 0., 0.)
    plot2.width = (pitch, pitch)
    plot2.pixels = (300, 300)
    plot2.color_by = 'cell'
    plots = openmc.Plots((plot1, plot2))

    chain = './test_chain.xml'

    chain_file_xml = """<?xml version="1.0"?>
<depletion_chain>
  <nuclide name="Xe136" decay_modes="0" reactions="0" />
  <nuclide name="U235" decay_modes="0" reactions="1">
    <reaction type="fission" Q="200000000."/>
    <neutron_fission_yields>
      <energies>2.53000e-02</energies>
      <fission_yields energy="2.53000e-02">
        <products>Xe136</products>
        <data>1.0</data>
      </fission_yields>
    </neutron_fission_yields>
  </nuclide>
</depletion_chain>
"""
    operator_kwargs = {'chain_file': chain}

    return (mats, geom, settings, tals, plots, operator_kwargs, chain_file_xml)
Esempio n. 24
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()
Esempio n. 25
0
def pincellfunction(pitch, enrichment):

    settings = openmc.Settings()
    # Set high tolerance to allow use of lower temperature xs
    settings.temperature['tolerance'] = 10000
    settings.temperature['method'] = 'nearest'
    settings.temperature['multipole'] = True
    settings.cutoff = {'energy': 1e-8}  #energy cutoff in eV

    #############################
    ###       MATERIALS       ###
    #############################
    uo2 = openmc.Material(1, "uo2")
    uo2.add_element('U', 1.0, enrichment=enrichment)
    uo2.add_element('O', 2.0)
    uo2.set_density('g/cm3', 10.97)
    uo2.temperature = 900  #kelvin

    graphite = openmc.Material(2, "graphite")
    graphite.set_density('g/cm3', 1.1995)
    graphite.add_element('C', 1.0)
    graphite.add_s_alpha_beta('c_Graphite')
    graphite.temperature = 600  #kelvin

    mats = openmc.Materials([uo2, graphite])
    mats.export_to_xml()

    #############################
    ###       GEOMETRY        ###
    #############################
    universe = openmc.Universe()

    fuel_or = openmc.ZCylinder(R=0.5)
    fuel_region = -fuel_or
    fuel_cell = openmc.Cell(1, 'fuel')
    fuel_cell.fill = uo2
    fuel_cell.region = fuel_region

    box = openmc.get_rectangular_prism(width=pitch,
                                       height=pitch,
                                       boundary_type='reflective')
    water_region = box & +fuel_or
    moderator = openmc.Cell(2, 'moderator')
    moderator.fill = graphite
    moderator.region = water_region

    root = openmc.Universe(cells=(fuel_cell, moderator))
    geom = openmc.Geometry(root)
    geom.export_to_xml()

    #####################################
    ###        SOURCE/BATCHES         ###
    #####################################
    point = openmc.stats.Point((0, 0, 0))
    src = openmc.Source(space=point)

    settings.source = src
    settings.batches = 100
    settings.inactive = 10
    settings.particles = 1000

    settings.export_to_xml()

    #############################
    ###       TALLIES         ###
    #############################
    # Instantiate an empty Tallies object
    tallies_file = openmc.Tallies()

    # K-Eigenvalue (infinity) tallies
    fiss_rate = openmc.Tally(name='fiss. rate')
    fiss_rate.scores = ['nu-fission']
    tallies_file.append(fiss_rate)

    abs_rate = openmc.Tally(name='abs. rate')
    abs_rate.scores = ['absorption']
    tallies_file.append(abs_rate)

    # Resonance Escape Probability tallies
    therm_abs_rate = openmc.Tally(name='therm. abs. rate')
    therm_abs_rate.scores = ['absorption']
    therm_abs_rate.filters = [openmc.EnergyFilter([0., 0.625])]
    tallies_file.append(therm_abs_rate)

    # Thermal Flux Utilization tallies
    fuel_therm_abs_rate = openmc.Tally(name='fuel therm. abs. rate')
    fuel_therm_abs_rate.scores = ['absorption']
    fuel_therm_abs_rate.filters = [
        openmc.EnergyFilter([0., 0.625]),
        openmc.CellFilter([fuel_cell])
    ]
    tallies_file.append(fuel_therm_abs_rate)

    # Fast Fission Factor tallies
    therm_fiss_rate = openmc.Tally(name='therm. fiss. rate')
    therm_fiss_rate.scores = ['nu-fission']
    therm_fiss_rate.filters = [openmc.EnergyFilter([0., 0.625])]
    tallies_file.append(therm_fiss_rate)

    tallies_file.export_to_xml()

    #############################
    ###       PLOTTING        ###
    #############################
    p = openmc.Plot()
    p.filename = 'pinplot'
    p.width = (pitch, pitch)
    p.pixels = (200, 200)
    p.color_by = 'material'
    p.colors = {uo2: 'yellow', graphite: 'grey'}

    plots = openmc.Plots([p])
    plots.export_to_xml()

    openmc.plot_geometry(output=False)
    pngstring = 'pinplot{}.png'.format(str(pitch))
    subprocess.call(['convert', 'pinplot.ppm', pngstring])
    subprocess.call(['mv', pngstring, 'figures/' + pngstring])

    #############################
    ###       EXECUTION       ###
    #############################
    openmc.run(output=False)
    sp = openmc.StatePoint('statepoint.{}.h5'.format(settings.batches))
    # Collect all the tallies
    fiss_rate = sp.get_tally(name='fiss. rate')
    fiss_rate_df = fiss_rate.get_pandas_dataframe()
    abs_rate = sp.get_tally(name='abs. rate')
    abs_rate_df = abs_rate.get_pandas_dataframe()
    therm_abs_rate = sp.get_tally(name='therm. abs. rate')
    therm_abs_rate_df = therm_abs_rate.get_pandas_dataframe()
    fuel_therm_abs_rate = sp.get_tally(name='fuel therm. abs. rate')
    fuel_therm_abs_rate_df = fuel_therm_abs_rate.get_pandas_dataframe()
    therm_fiss_rate = sp.get_tally(name='therm. fiss. rate')
    therm_fiss_rate_df = therm_fiss_rate.get_pandas_dataframe()

    # Compute k-infinity
    kinf = fiss_rate / abs_rate
    kinf_df = kinf.get_pandas_dataframe()

    # Compute resonance escape probability
    res_esc = (therm_abs_rate) / (abs_rate)
    res_esc_df = res_esc.get_pandas_dataframe()

    # Compute fast fission factor
    fast_fiss = fiss_rate / therm_fiss_rate
    fast_fiss_df = fast_fiss.get_pandas_dataframe()

    # Compute thermal flux utilization
    therm_util = fuel_therm_abs_rate / therm_abs_rate
    therm_util_df = therm_util.get_pandas_dataframe()

    # Compute neutrons produced per absorption
    eta = therm_fiss_rate / fuel_therm_abs_rate
    eta_df = eta.get_pandas_dataframe()

    columns = [
        'pitch', 'enrichment', 'kinf mean', 'kinf sd', 'res_esc mean',
        'res_esc sd', 'fast_fiss mean', 'fast_fiss sd', 'therm_util mean',
        'therm_util sd', 'eta mean', 'eta sd'
    ]
    data = [[
        pitch, enrichment, kinf_df['mean'][0], kinf_df['std. dev.'][0],
        res_esc_df['mean'][0], res_esc_df['std. dev.'][0],
        fast_fiss_df['mean'][0], fast_fiss_df['std. dev.'][0],
        therm_util_df['mean'][0], therm_util_df['std. dev.'][0],
        eta_df['mean'][0], eta_df['std. dev.'][0]
    ]]
    all_tallies = pd.DataFrame(data, columns=columns)

    return all_tallies
Esempio n. 26
0
geom.export_to_xml()

src = openmc.Source()
bounds = [-58, 0, 0, 0, 75.6, 91]
src.space = openmc.stats.Box(bounds[:3], bounds[3:], only_fissionable=True)
settings = openmc.Settings()
settings.source = src
settings.batches = 500
settings.inactive = 100
settings.particles = 2500
settings.output = {'tallies': False}
settings.export_to_xml()

plot = openmc.Plot()
plot.origin = [-18.9, 40, 67.5]
plot.width = [150, 150]
plot.pixels = [800, 800]
plot.color_by = 'material'

plot1 = openmc.Plot()
plot1.origin = [-17.955, 36.855, 67.5]
plot1.width = [150, 180]
plot1.pixels = [800, 800]
plot1.color_by = 'material'
plot1.basis = 'yz'

plot_file = openmc.Plots([plot, plot1])
plot_file.export_to_xml()

openmc.run()
Esempio n. 27
0
entropy_mesh = openmc.RegularMesh()
entropy_mesh.lower_left = [-0.4096, -0.4096, -1.e50]
entropy_mesh.upper_right = [0.4096, 0.4096, 1.e50]
entropy_mesh.dimension = [10, 10, 1]
settings_file.entropy_mesh = entropy_mesh

settings_file.export_to_xml()

# plot setting
plot = openmc.Plot(plot_id=1)
plot.origin = [0, 0, 0]
plot.width = [1.26, 1.26]
plot.pixels = [500, 500]
plot.color_by = 'material'
# Instantiate a Plots object and export to XML
plot_file = openmc.Plots([plot])
plot_file.export_to_xml()

###############################################################################
#                     Set volumes of depletable materials
###############################################################################

# Compute cell areas
area = {}
area[fuel] = np.pi * fuel_or.coefficients['r']**2

# Set materials volume for depletion. Set to an area for 2D simulations
fuel_31.volume = area[fuel]

###############################################################################
#                   Initialize and run depletion calculation
Esempio n. 28
0
#                   Exporting to OpenMC plots.xml File
###############################################################################

plot_1 = openmc.Plot(plot_id=1)
plot_1.filename = 'plot_1'
plot_1.origin = [0.0, 0.0, 0.0]
plot_1.width = [64.26, 64.26]
plot_1.pixels = [500, 500]
plot_1.color = 'mat'
plot_1.basis = 'xy'

plot_2 = openmc.Plot(plot_id=2)
plot_2.filename = 'plot_2'
plot_2.origin = [0.0, 21.42, 0.0]
plot_2.width = [64.26, 64.26]
plot_2.pixels = [500, 500]
plot_2.color = 'mat'
plot_2.basis = 'xz'

# Instantiate a Plots collection and export to XML
plot_file = openmc.Plots([plot_1, plot_2])
plot_file.export_to_xml()

###############################################################################
#                   Exporting to OpenMC tallies.xml File
###############################################################################

# Instantiate a Tallies and export to XML
tallies_file = openmc.Tallies(tallies.values())
tallies_file.export_to_xml()
Esempio n. 29
0
source.energy = openmc.stats.Discrete([14e6], [1])

# source.file = 'source_1000_particles.h5'
sett.source = source

# Run OpenMC!
model = openmc.model.Model(geom, mats, sett)
model.run(tracks=True)  # this creates h5 files with openmc-track-to-vtk

for i in range(1, 11):
    print('converting h5 track file to vtpi')
    os.system('openmc-track-to-vtk track_1_1_' + str(i) + '.h5 -o track_1_1_' +
              str(i))

#os.system('paraview track_1_1_'+str(i)+'.pvtp')

vox_plot = openmc.Plot()
vox_plot.type = 'voxel'
vox_plot.width = (200., 200., 200.)
vox_plot.pixels = (100, 100, 100)
vox_plot.filename = 'plot_3d'
vox_plot.color_by = 'material'
vox_plot.colors = {moderating_material: 'blue', transparent_material: 'red'}
plots = openmc.Plots([vox_plot])
plots.export_to_xml()

openmc.plot_geometry()

os.system('openmc-voxel-to-vtk plot_3d.h5 -o plot_3d.vti')
os.system('paraview plot_3d.vti')  # visit might be preffered
Esempio n. 30
0
    settings.source = [src]

    model.settings = settings

    detector_cells = detectors_tallies(h_cell)

    print(detector_cells)

    tallies_list = []

    tally = openmc.Tally(name='flux')
    tally.filters = [openmc.CellFilter(detector_cells)]

    tally.scores = ['flux']

    tallies_list.append(tally)

    model.tallies = openmc.Tallies(tallies_list)

    model.export_to_xml()

    ph = horizontal_section()

    pv = vertical_section()

    plots = openmc.Plots([ph, pv])
    plots.export_to_xml()

    openmc.plot_geometry()
    openmc.run()