def simulate(self):
        """this runs a simple tbr simulation using openmc and returns the
        tritium breeding ratio"""

        breeder_material = openmc.Material(1, "PbLi")  # Pb84.2Li15.8
        breeder_material.add_element('Pb', 84.2, percent_type='ao')
        breeder_material.add_element('Li',
                                     15.8,
                                     percent_type='ao',
                                     enrichment=50.0,
                                     enrichment_target='Li6',
                                     enrichment_type='ao')  # 50% enriched
        breeder_material.set_density('atom/b-cm',
                                     3.2720171e-2)  # around 11 g/cm3

        mats = openmc.Materials([breeder_material])

        # GEOMETRY

        # surfaces
        vessel_inner = openmc.Sphere(r=500)
        breeder_blanket_outer_surface = openmc.Sphere(r=600,
                                                      boundary_type='vacuum')

        # cells
        inner_vessel_region = -vessel_inner
        inner_vessel_cell = openmc.Cell(region=inner_vessel_region)

        breeder_blanket_region = -breeder_blanket_outer_surface
        breeder_blanket_cell = openmc.Cell(region=breeder_blanket_region)
        breeder_blanket_cell.fill = breeder_material

        # universe
        universe = openmc.Universe(
            cells=[inner_vessel_cell, breeder_blanket_cell])
        geom = openmc.Geometry(universe)

        # SIMULATION SETTINGS

        # Instantiate a Settings object
        sett = openmc.Settings()
        sett.batches = 2
        sett.inactive = 0
        sett.particles = 100
        sett.run_mode = 'fixed source'

        # Create a DT point source
        source = openmc.Source()
        source.space = openmc.stats.Point((0, 0, 0))
        source.angle = openmc.stats.Isotropic()
        source.energy = openmc.stats.Discrete([14e6], [1])
        sett.source = source

        tallies = openmc.Tallies()

        # added a cell tally for tritium production
        cell_filter = openmc.CellFilter(breeder_blanket_cell)
        tbr_tally = openmc.Tally(name='TBR')
        tbr_tally.filters = [cell_filter]
        tbr_tally.scores = [
            '(n,Xt)'
        ]  # MT 205 is the (n,Xt) reaction where X is a wildcard, if MT 105 or (n,t) then some tritium production will be missed, for example (n,nt) which happens in Li7 would be missed
        tallies.append(tbr_tally)

        # Run OpenMC!
        model = openmc.model.Model(geom, mats, sett, tallies)
        sp_filename = model.run()

        # open the results file
        sp = openmc.StatePoint(sp_filename)

        # access the tally using pandas dataframes
        tbr_tally = sp.get_tally(name='TBR')
        df = tbr_tally.get_pandas_dataframe()

        tbr_tally_result = df['mean'].sum()

        return tbr_tally_result
Ejemplo n.º 2
0
def test_full(run_in_tmpdir, problem, multiproc):
    """Full system test suite.

    Runs an entire OpenMC simulation with depletion coupling and verifies
    that the outputs match a reference file.  Sensitive to changes in
    OpenMC.

    This test runs a complete OpenMC simulation and tests the outputs.
    It will take a while.

    """

    geometry, lower_left, upper_right = problem

    # OpenMC-specific settings
    settings = openmc.Settings()
    settings.particles = 100
    settings.batches = 10
    settings.inactive = 0
    space = openmc.stats.Box(lower_left, upper_right)
    settings.source = openmc.Source(space=space)
    settings.seed = 1
    settings.verbosity = 1

    # Create operator
    chain_file = Path(__file__).parents[2] / 'chain_simple.xml'
    op = openmc.deplete.Operator(geometry, settings, chain_file)
    op.round_number = True

    # Power and timesteps
    dt1 = 15. * 24 * 60 * 60  # 15 days
    dt2 = 1.5 * 30 * 24 * 60 * 60  # 1.5 months
    N = floor(dt2 / dt1)
    dt = np.full(N, dt1)
    power = 2.337e15 * 4 * JOULE_PER_EV * 1e6  # MeV/second cm from CASMO

    # Perform simulation using the predictor algorithm
    openmc.deplete.pool.USE_MULTIPROCESSING = multiproc
    openmc.deplete.PredictorIntegrator(op, dt, power).integrate()

    # Get path to test and reference results
    path_test = op.output_dir / 'depletion_results.h5'
    path_reference = Path(__file__).with_name('test_reference.h5')

    # If updating results, do so and return
    if config['update']:
        shutil.copyfile(str(path_test), str(path_reference))
        return

    # Load the reference/test results
    res_test = openmc.deplete.ResultsList.from_hdf5(path_test)
    res_ref = openmc.deplete.ResultsList.from_hdf5(path_reference)

    # Assert same mats
    for mat in res_ref[0].mat_to_ind:
        assert mat in res_test[0].mat_to_ind, \
            "Material {} not in new results.".format(mat)
    for nuc in res_ref[0].nuc_to_ind:
        assert nuc in res_test[0].nuc_to_ind, \
            "Nuclide {} not in new results.".format(nuc)

    for mat in res_test[0].mat_to_ind:
        assert mat in res_ref[0].mat_to_ind, \
            "Material {} not in old results.".format(mat)
    for nuc in res_test[0].nuc_to_ind:
        assert nuc in res_ref[0].nuc_to_ind, \
            "Nuclide {} not in old results.".format(nuc)

    tol = 1.0e-6
    for mat in res_test[0].mat_to_ind:
        for nuc in res_test[0].nuc_to_ind:
            _, y_test = res_test.get_atoms(mat, nuc)
            _, y_old = res_ref.get_atoms(mat, nuc)

            # Test each point
            correct = True
            for i, ref in enumerate(y_old):
                if ref != y_test[i]:
                    if ref != 0.0:
                        correct = np.abs(y_test[i] - ref) / ref <= tol
                    else:
                        correct = False

            assert correct, "Discrepancy in mat {} and nuc {}\n{}\n{}".format(
                mat, nuc, y_old, y_test)

    # Compare statepoint files with depletion results

    t_test, k_test = res_test.get_eigenvalue()
    t_ref, k_ref = res_ref.get_eigenvalue()
    k_state = np.empty_like(k_ref)

    n_tallies = np.empty(N + 1, dtype=int)

    # Get statepoint files for all BOS points and EOL
    for n in range(N + 1):
        statepoint = openmc.StatePoint("openmc_simulation_n{}.h5".format(n))
        k_n = statepoint.k_combined
        k_state[n] = [k_n.nominal_value, k_n.std_dev]
        n_tallies[n] = len(statepoint.tallies)
    # Look for exact match pulling from statepoint and depletion_results
    assert np.all(k_state == k_test)
    assert np.allclose(k_test, k_ref)

    # Check that no additional tallies are loaded from the files
    assert np.all(n_tallies == 0)
Ejemplo n.º 3
0
breeder_blanket_region = +first_wall_outer_surface & -breeder_blanket_outer_surface & +central_shield_outer_surface
breeder_blanket_cell = openmc.Cell(region=breeder_blanket_region)
breeder_blanket_cell.fill = breeder_material

universe = openmc.Universe(cells=[
    central_sol_cell, central_shield_cell, first_wall_cell,
    breeder_blanket_cell
])

geom = openmc.Geometry(universe)

geom.export_to_xml()

# A blank settings.xml is exported to allow the openmc plotter to work
sett = openmc.Settings()
sett.export_to_xml()

# makes the 3d "cube" style geometry
vox_plot = openmc.Plot()
vox_plot.type = 'voxel'
vox_plot.width = (1500., 1500., 1500.)
vox_plot.pixels = (200, 200, 200)
vox_plot.filename = 'plot_3d_tokamak'
vox_plot.color_by = 'material'
# vox_plot.colors = {copper: 'blue'}  # materials can be coloured using this command
plots = openmc.Plots([vox_plot])
plots.export_to_xml()

openmc.plot_geometry()
Ejemplo n.º 4
0
    def simulate_cylinder_cask_csg(self, material, source, height,
                                   outer_radius, thickness, batches,
                                   particles):
        """Makes a CSG cask geometry runs a simulation and returns the result"""

        mats = openmc.Materials([material])

        outer_cylinder = openmc.ZCylinder(r=outer_radius)
        inner_cylinder = openmc.ZCylinder(r=outer_radius - thickness)
        inner_top = openmc.ZPlane(z0=height * 0.5)
        inner_bottom = openmc.ZPlane(z0=-height * 0.5)
        outer_top = openmc.ZPlane(z0=(height * 0.5) + thickness)
        outer_bottom = openmc.ZPlane(z0=(-height * 0.5) - thickness)

        sphere_1 = openmc.Sphere(r=100, boundary_type='vacuum')

        cylinder_region = -outer_cylinder & +inner_cylinder & -inner_top & +inner_bottom
        cylinder_cell = openmc.Cell(region=cylinder_region)
        cylinder_cell.fill = material

        top_cap_region = -outer_top & +inner_top & -outer_cylinder
        top_cap_cell = openmc.Cell(region=top_cap_region)
        top_cap_cell.fill = material

        bottom_cap_region = +outer_bottom & -inner_bottom & -outer_cylinder
        bottom_cap_cell = openmc.Cell(region=bottom_cap_region)
        bottom_cap_cell.fill = material

        inner_void_region = -inner_cylinder & -inner_top & +inner_bottom
        inner_void_cell = openmc.Cell(region=inner_void_region)

        # sphere 1 region is below -sphere_1 and not (~) in the other regions
        sphere_1_region = -sphere_1
        sphere_1_cell = openmc.Cell(region=sphere_1_region
                                    & ~bottom_cap_region
                                    & ~top_cap_region
                                    & ~cylinder_region
                                    & ~inner_void_region)

        universe = openmc.Universe(cells=[
            inner_void_cell, cylinder_cell, top_cap_cell, bottom_cap_cell,
            sphere_1_cell
        ])

        geom = openmc.Geometry(universe)

        # Instantiate a Settings object
        sett = openmc.Settings()
        sett.batches = batches
        sett.particles = particles
        sett.inactive = 0
        sett.run_mode = 'fixed source'
        sett.photon_transport = True
        sett.source = source

        cell_filter = openmc.CellFilter(
            [cylinder_cell, top_cap_cell, bottom_cap_cell])

        tally = openmc.Tally(name='csg_heating')
        tally.filters = [cell_filter]
        tally.scores = ['heating']
        tallies = openmc.Tallies()
        tallies.append(tally)

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

        # open the results file
        results = openmc.StatePoint(sp_filename)

        # access the tally using pandas dataframes
        tally = results.get_tally(name='csg_heating')
        tally_df = tally.get_pandas_dataframe()

        return tally_df['mean'].sum()
Ejemplo n.º 5
0
    def create_neutronics_model(self, method: str = None):
        """Uses OpenMC python API to make a neutronics model, including tallies
        (cell_tallies and mesh_tally_2d), simulation settings (batches,
        particles per batch).

        Arguments:
            method: (str): The method to use when making the imprinted and
                merged geometry. Options are "ppp", "trelis", "pymoab".
                Defaults to None.
        """

        self.create_materials()

        self.create_neutronics_geometry(method=method)

        # this is the underlying geometry container that is filled with the
        # faceteted DGAMC CAD model
        self.universe = openmc.Universe()
        geom = openmc.Geometry(self.universe)

        # settings for the number of neutrons to simulate
        settings = openmc.Settings()
        settings.batches = self.simulation_batches
        settings.inactive = 0
        settings.particles = self.simulation_particles_per_batch
        settings.run_mode = "fixed source"
        settings.dagmc = True
        settings.photon_transport = True
        settings.source = self.source
        settings.max_lost_particles = self.max_lost_particles

        # details about what neutrons interactions to keep track of (tally)
        self.tallies = openmc.Tallies()

        if self.mesh_tally_3d is not None:
            mesh_xyz = openmc.RegularMesh(mesh_id=1, name='3d_mesh')
            mesh_xyz.dimension = self.mesh_3D_resolution
            mesh_xyz.lower_left = [
                -self.geometry.largest_dimension,
                -self.geometry.largest_dimension,
                -self.geometry.largest_dimension
            ]

            mesh_xyz.upper_right = [
                self.geometry.largest_dimension,
                self.geometry.largest_dimension,
                self.geometry.largest_dimension
            ]

            for standard_tally in self.mesh_tally_3d:
                if standard_tally == 'tritium_production':
                    score = '(n,Xt)'  # where X is a wild card
                    prefix = 'tritium_production'
                else:
                    score = standard_tally
                    prefix = standard_tally

                mesh_filter = openmc.MeshFilter(mesh_xyz)
                tally = openmc.Tally(name=prefix + '_on_3D_mesh')
                tally.filters = [mesh_filter]
                tally.scores = [score]
                self.tallies.append(tally)

        if self.mesh_tally_2d is not None:

            # Create mesh which will be used for tally
            mesh_xz = openmc.RegularMesh(mesh_id=2, name='2d_mesh_xz')

            mesh_xz.dimension = [
                self.mesh_2D_resolution[1],
                1,
                self.mesh_2D_resolution[0]
            ]

            mesh_xz.lower_left = [
                -self.geometry.largest_dimension,
                -1,
                -self.geometry.largest_dimension
            ]

            mesh_xz.upper_right = [
                self.geometry.largest_dimension,
                1,
                self.geometry.largest_dimension
            ]

            mesh_xy = openmc.RegularMesh(mesh_id=3, name='2d_mesh_xy')
            mesh_xy.dimension = [
                self.mesh_2D_resolution[1],
                self.mesh_2D_resolution[0],
                1
            ]

            mesh_xy.lower_left = [
                -self.geometry.largest_dimension,
                -self.geometry.largest_dimension,
                -1
            ]

            mesh_xy.upper_right = [
                self.geometry.largest_dimension,
                self.geometry.largest_dimension,
                1
            ]

            mesh_yz = openmc.RegularMesh(mesh_id=4, name='2d_mesh_yz')
            mesh_yz.dimension = [
                1,
                self.mesh_2D_resolution[1],
                self.mesh_2D_resolution[0]
            ]

            mesh_yz.lower_left = [
                -1,
                -self.geometry.largest_dimension,
                -self.geometry.largest_dimension
            ]

            mesh_yz.upper_right = [
                1,
                self.geometry.largest_dimension,
                self.geometry.largest_dimension
            ]

            for standard_tally in self.mesh_tally_2d:
                if standard_tally == 'tritium_production':
                    score = '(n,Xt)'  # where X is a wild card
                    prefix = 'tritium_production'
                else:
                    score = standard_tally
                    prefix = standard_tally

                for mesh_filter, plane in zip(
                        [mesh_xz, mesh_xy, mesh_yz], ['xz', 'xy', 'yz']):
                    mesh_filter = openmc.MeshFilter(mesh_filter)
                    tally = openmc.Tally(name=prefix + '_on_2D_mesh_' + plane)
                    tally.filters = [mesh_filter]
                    tally.scores = [score]
                    self.tallies.append(tally)

        if self.cell_tallies is not None:

            for standard_tally in self.cell_tallies:
                if standard_tally == 'TBR':
                    score = '(n,Xt)'  # where X is a wild card
                    sufix = 'TBR'
                    tally = openmc.Tally(name='TBR')
                    tally.scores = [score]
                    self.tallies.append(tally)
                    self._add_tally_for_every_material(sufix, score)

                elif standard_tally == 'spectra':
                    neutron_particle_filter = openmc.ParticleFilter([
                                                                    'neutron'])
                    photon_particle_filter = openmc.ParticleFilter(['photon'])
                    energy_bins = openmc.mgxs.GROUP_STRUCTURES['CCFE-709']
                    energy_filter = openmc.EnergyFilter(energy_bins)

                    self._add_tally_for_every_material(
                        'neutron_spectra',
                        'flux',
                        [neutron_particle_filter, energy_filter]
                    )

                    self._add_tally_for_every_material(
                        'photon_spectra',
                        'flux',
                        [photon_particle_filter, energy_filter]
                    )
                else:
                    score = standard_tally
                    sufix = standard_tally
                    self._add_tally_for_every_material(sufix, score)

        # make the model from gemonetry, materials, settings and tallies
        self.model = openmc.model.Model(
            geom, self.mats, settings, self.tallies)
Ejemplo n.º 6
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])
Ejemplo n.º 7
0
def make_geometry_tallies(batches, nps, enrichment_fraction, inner_radius,
                          thickness, breeder_material_name, temperature_in_C):
    #print('simulating ',batches,enrichment_fraction,inner_radius,thickness,breeder_material_name)

    #MATERIALS#
    breeder_material = make_breeder_materials(enrichment_fraction,
                                              breeder_material_name,
                                              temperature_in_C)
    eurofer = make_eurofer()
    copper = make_copper()
    mats = openmc.Materials([breeder_material, eurofer, copper])
    mats.export_to_xml('materials.xml')

    #GEOMETRY#

    central_sol_surface = openmc.ZCylinder(R=100)
    central_shield_outer_surface = openmc.ZCylinder(R=110)
    first_wall_inner_surface = openmc.Sphere(R=inner_radius)
    first_wall_outer_surface = openmc.Sphere(R=inner_radius + 10)
    breeder_blanket_outer_surface = openmc.Sphere(R=inner_radius + 10.0 +
                                                  thickness)
    vessel_outer_surface = openmc.Sphere(R=inner_radius + 10.0 + thickness +
                                         10.0,
                                         boundary_type='vacuum')

    central_sol_region = -central_sol_surface & -breeder_blanket_outer_surface
    central_sol_cell = openmc.Cell(region=central_sol_region)
    central_sol_cell.fill = copper

    central_shield_region = +central_sol_surface & -central_shield_outer_surface & -breeder_blanket_outer_surface
    central_shield_cell = openmc.Cell(region=central_shield_region)
    central_shield_cell.fill = eurofer

    inner_void_region = -first_wall_inner_surface & +central_shield_outer_surface
    inner_void_cell = openmc.Cell(region=inner_void_region)
    inner_void_cell.name = 'inner_void'

    first_wall_region = -first_wall_outer_surface & +first_wall_inner_surface & +central_shield_outer_surface
    first_wall_cell = openmc.Cell(region=first_wall_region)
    first_wall_cell.fill = eurofer

    breeder_blanket_region = +first_wall_outer_surface & -breeder_blanket_outer_surface & +central_shield_outer_surface
    breeder_blanket_cell = openmc.Cell(region=breeder_blanket_region)
    breeder_blanket_cell.fill = breeder_material

    vessel_region = +breeder_blanket_outer_surface & -vessel_outer_surface
    vessel_cell = openmc.Cell(region=vessel_region)
    vessel_cell.name = 'vessel'
    vessel_cell.fill = eurofer

    universe = openmc.Universe(cells=[
        central_sol_cell, central_shield_cell, inner_void_cell,
        first_wall_cell, breeder_blanket_cell, vessel_cell
    ])

    #plt.show(universe.plot(width=(1500,1500),basis='xz'))

    geom = openmc.Geometry(universe)
    # geom.export_to_xml('geometry.xml')

    #SIMULATION SETTINGS#

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

    source = openmc.Source()
    source.space = openmc.stats.Point((150, 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
    )  #neutron energy = 14.08MeV, AMU for D + T = 5, temperature is 20KeV
    sett.source = source

    sett.export_to_xml('settings.xml')

    #tally filters
    particle_filter = openmc.ParticleFilter([1])  #1 is neutron, 2 is photon
    cell_filter_breeder = openmc.CellFilter(breeder_blanket_cell)
    cell_filter_vessel = openmc.CellFilter(vessel_cell)
    surface_filter_front = openmc.SurfaceFilter(first_wall_inner_surface)
    surface_filter_rear = openmc.SurfaceFilter(breeder_blanket_outer_surface)
    energy_bins = openmc.mgxs.GROUP_STRUCTURES['VITAMIN-J-175']
    energy_filter = openmc.EnergyFilter(energy_bins)

    #TALLIES#
    tallies = openmc.Tallies()

    tally = openmc.Tally(name='TBR')
    tally.filters = [cell_filter_breeder, particle_filter]
    tally.scores = ['205']
    tallies.append(tally)

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

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

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

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

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

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

    tally = openmc.Tally(name='DPA')
    tally.filters = [cell_filter_vessel, particle_filter]
    tally.scores = ['444']
    tallies.append(tally)

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

    model.run()

    #RETRIEVING TALLY RESULTS

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

    json_output = {
        'enrichment_fraction': enrichment_fraction,
        'inner_radius': inner_radius,
        'thickness': thickness,
        'breeder_material_name': breeder_material_name,
        'temperature_in_C': temperature_in_C
    }

    tallies_to_retrieve = ['TBR', 'DPA', 'blanket_leakage', 'vessel_leakage']
    for tally_name in tallies_to_retrieve:
        tally = sp.get_tally(name=tally_name)
        tally_result = tally.sum[0][0][
            0] / batches  #for some reason the tally sum is a nested list
        tally_std_dev = tally.std_dev[0][0][
            0] / batches  #for some reason the tally std_dev is a nested list

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

    spectra_tallies_to_retrieve = [
        'front_neutron_spectra', 'breeder_blanket_spectra',
        'vacuum_vessel_spectra', 'rear_neutron_spectra'
    ]
    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
        ]

        json_output[spectra_name] = {
            'value': spectra_tally_result,
            'std_dev': spectra_tally_std_dev,
            'energy_groups': list(energy_bins)
        }

    return json_output
Ejemplo n.º 8
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
Ejemplo n.º 9
0
def simulate_model(
    enrichment,
    thickness,
    breeder_material_name="Li4SiO4",
    temperature_in_C=500,
    batches=2,
    nps=500,
    inner_radius=500,
):

    # MATERIALS from library of materials in neutronics_material_maker package
    breeder_material = Material(
        material_name=breeder_material_name,
        enrichment=enrichment,
        temperature_in_C=temperature_in_C,
    ).neutronics_material

    SS316 = Material(material_name="SS316").neutronics_material
    copper = Material(material_name="copper").neutronics_material

    mats = openmc.Materials([breeder_material, SS316, copper])
    mats.export_to_xml("materials.xml")

    # GEOMETRY#

    first_wall_inner_surface = openmc.Sphere(r=inner_radius)
    first_wall_outer_surface = openmc.Sphere(r=inner_radius + 10.)
    breeder_blanket_outer_surface = openmc.Sphere(r=inner_radius + 10. +
                                                  thickness)
    vessel_outer_surface = openmc.Sphere(r=inner_radius + 10.0 + thickness +
                                         10.,
                                         boundary_type="vacuum")

    inner_void_region = -first_wall_inner_surface
    inner_void_cell = openmc.Cell(region=inner_void_region)
    inner_void_cell.name = "inner_void"

    first_wall_region = (-first_wall_outer_surface & +first_wall_inner_surface)
    first_wall_cell = openmc.Cell(region=first_wall_region)
    first_wall_cell.fill = SS316

    breeder_blanket_region = (+first_wall_outer_surface
                              & -breeder_blanket_outer_surface)
    breeder_blanket_cell = openmc.Cell(region=breeder_blanket_region)
    breeder_blanket_cell.fill = breeder_material

    vessel_region = +breeder_blanket_outer_surface & -vessel_outer_surface
    vessel_cell = openmc.Cell(region=vessel_region)
    vessel_cell.name = "vessel"
    vessel_cell.fill = SS316

    universe = openmc.Universe(cells=[
        inner_void_cell, first_wall_cell, breeder_blanket_cell, vessel_cell
    ])

    geom = openmc.Geometry(universe)

    # SIMULATION SETTINGS#

    sett = openmc.Settings()
    sett.batches = batches  # this is the minimum number of batches which will be run
    sett.trigger_active = True
    sett.trigger_max_batches = 200  # this is the maximum number of batches which will be run
    sett.inactive = 0
    sett.particles = nps  # as we are using a trigger, we specify a small number of particles per batch
    sett.run_mode = "fixed source"

    source = openmc.Source()
    source.space = openmc.stats.Point((150, 0, 0))
    source.angle = openmc.stats.Isotropic()
    source.energy = openmc.stats.Discrete([14.08e6], [1])
    sett.source = source

    # sett.export_to_xml("settings.xml")

    # tally filters
    particle_filter = openmc.ParticleFilter("neutron")
    cell_filter_breeder = openmc.CellFilter(breeder_blanket_cell)

    # TALLIES#
    tallies = openmc.Tallies()

    tally = openmc.Tally(name="TBR")
    tally.filters = [cell_filter_breeder, particle_filter]
    tally.scores = ["(n,Xt)"]
    tally.triggers = [openmc.Trigger(trigger_type='std_dev', threshold=0.01)]
    tallies.append(tally)

    # RUN OPENMC #
    model = openmc.model.Model(geom, mats, sett, tallies)
    sp_filename = model.run(output=False)

    # RETRIEVING TALLY RESULTS

    sp = openmc.StatePoint(sp_filename)

    json_output = {
        "batches": batches,
        "nps": nps,
        "enrichment": enrichment,
        "inner_radius": inner_radius,
        "thickness": thickness,
        "breeder_material_name": breeder_material_name,
        "temperature_in_C": temperature_in_C,
    }

    tally = sp.get_tally(name="TBR")

    df = tally.get_pandas_dataframe()

    json_output["TBR"] = df["mean"].sum()
    json_output["TBR_std_dev"] = df["std. dev."].sum()

    return json_output
def make_materials_geometry_tallies(enrichment_list,
                                    batches=2,
                                    inner_radius=500,
                                    thickness=100,
                                    breeder_material_name='Li',
                                    temperature_in_C=500):
    if isinstance(enrichment_list, list):
        enrichment = enrichment_list[0]
    else:
        enrichment = enrichment_list
    print('simulating ', batches, enrichment, inner_radius, thickness,
          breeder_material_name)

    # MATERIALS from library of materials in neutronics_material_maker package
    breeder_material = Material(
        material_name=breeder_material_name,
        enrichment=enrichment,
        enrichment_target='Li6',
        enrichment_type='ao',
        temperature_in_C=temperature_in_C).neutronics_material

    eurofer = Material(material_name='eurofer').neutronics_material

    mats = openmc.Materials([breeder_material, eurofer])

    # GEOMETRY

    breeder_blanket_inner_surface = openmc.Sphere(r=inner_radius)
    breeder_blanket_outer_surface = openmc.Sphere(r=inner_radius + thickness)

    vessel_inner_surface = openmc.Sphere(r=inner_radius + thickness + 10)
    vessel_outer_surface = openmc.Sphere(r=inner_radius + thickness + 20,
                                         boundary_type='vacuum')

    breeder_blanket_region = -breeder_blanket_outer_surface & +breeder_blanket_inner_surface
    breeder_blanket_cell = openmc.Cell(region=breeder_blanket_region)
    breeder_blanket_cell.fill = breeder_material
    breeder_blanket_cell.name = 'breeder_blanket'

    inner_void_region = -breeder_blanket_inner_surface
    inner_void_cell = openmc.Cell(region=inner_void_region)
    inner_void_cell.name = 'inner_void'

    vessel_region = +vessel_inner_surface & -vessel_outer_surface
    vessel_cell = openmc.Cell(region=vessel_region)
    vessel_cell.name = 'vessel'
    vessel_cell.fill = eurofer

    blanket_vessel_gap_region = -vessel_inner_surface & +breeder_blanket_outer_surface
    blanket_vessel_gap_cell = openmc.Cell(region=blanket_vessel_gap_region)
    blanket_vessel_gap_cell.name = 'blanket_vessel_gap'

    universe = openmc.Universe(cells=[
        inner_void_cell, breeder_blanket_cell, blanket_vessel_gap_cell,
        vessel_cell
    ])

    geom = openmc.Geometry(universe)

    # SIMULATION SETTINGS

    sett = openmc.Settings()
    # batches = 3 # this is parsed as an argument
    sett.batches = batches
    sett.inactive = 20
    sett.particles = 5000
    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.Muir(
        e0=14080000.0, m_rat=5.0, kt=20000.0
    )  # neutron energy = 14.08MeV, AMU for D + T = 5, temperature is 20KeV
    sett.source = source

    # TALLIES

    tallies = openmc.Tallies()

    # define filters
    cell_filter_breeder = openmc.CellFilter(breeder_blanket_cell)
    cell_filter_vessel = openmc.CellFilter(vessel_cell)
    particle_filter = openmc.ParticleFilter(
        'neutron')  # 1 is neutron, 2 is photon
    surface_filter_rear_blanket = openmc.SurfaceFilter(
        breeder_blanket_outer_surface)
    surface_filter_rear_vessel = openmc.SurfaceFilter(vessel_outer_surface)
    energy_bins = openmc.mgxs.GROUP_STRUCTURES['VITAMIN-J-175']
    energy_filter = openmc.EnergyFilter(energy_bins)

    tally = openmc.Tally(name='TBR')
    tally.filters = [cell_filter_breeder]
    tally.scores = [
        '205'
    ]  # MT 205 is the (n,Xt) reaction where X is a wildcard, if MT 105 or (n,t) then some tritium production will be missed, for example (n,nt) which happens in Li7 would be missed
    tallies.append(tally)

    tally = openmc.Tally(name='blanket_leakage')
    tally.filters = [surface_filter_rear_blanket]
    tally.scores = ['current']
    tallies.append(tally)

    tally = openmc.Tally(name='vessel_leakage')
    tally.filters = [surface_filter_rear_vessel]
    tally.scores = ['current']
    tallies.append(tally)

    tally = openmc.Tally(name='breeder_blanket_spectra')
    tally.filters = [cell_filter_breeder, energy_filter]
    tally.scores = ['flux']
    tallies.append(tally)

    tally = openmc.Tally(name='vacuum_vessel_spectra')
    tally.filters = [cell_filter_vessel, energy_filter]
    tally.scores = ['flux']
    tallies.append(tally)

    tally = openmc.Tally(name='DPA')
    tally.filters = [cell_filter_vessel]
    tally.scores = ['444']
    tallies.append(tally)

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

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

    json_output = {
        'enrichment': enrichment,
        'inner_radius': inner_radius,
        'thickness': thickness,
        'breeder_material_name': breeder_material_name,
        'temperature_in_C': temperature_in_C
    }

    tallies_to_retrieve = ['TBR', 'DPA', 'blanket_leakage', 'vessel_leakage']
    for tally_name in tallies_to_retrieve:
        tally = sp.get_tally(name=tally_name)

        df = tally.get_pandas_dataframe()

        tally_result = df['mean'].sum()
        tally_std_dev = df['std. dev.'].sum()

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

    spectra_tallies_to_retrieve = [
        'breeder_blanket_spectra', 'vacuum_vessel_spectra'
    ]
    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
        ]

        json_output[spectra_name] = {
            'value': spectra_tally_result,
            'std_dev': spectra_tally_std_dev,
            'energy_groups': list(energy_bins)
        }

    return json_output
Ejemplo n.º 11
0
def build_inf_model(xsnames, xslibname, temperature, tempmethod='nearest'):
    """ Building an infinite medium for openmc multi-group testing
    Parameters:
    ----------
    xsnames : list of str()
        list with xs names
    xslibname:
        name of hdf5 file with cross-section library
    temperature : float
        value of a current temperature in K
    tempmethod : {'nearest', 'interpolation'}
        by default 'nearest'
    """
    inf_medium = openmc.Material(name='test material', material_id=1)
    inf_medium.set_density("sum")
    for xs in xsnames:
        inf_medium.add_nuclide(xs, 1)
    INF = 11.1
    # Instantiate a Materials collection and export to XML
    materials_file = openmc.Materials([inf_medium])
    materials_file.cross_sections = xslibname
    materials_file.export_to_xml()

    # Instantiate boundary Planes
    min_x = openmc.XPlane(boundary_type='reflective', x0=-INF)
    max_x = openmc.XPlane(boundary_type='reflective', x0=INF)
    min_y = openmc.YPlane(boundary_type='reflective', y0=-INF)
    max_y = openmc.YPlane(boundary_type='reflective', y0=INF)

    # Instantiate a Cell
    cell = openmc.Cell(cell_id=1, name='cell')
    cell.temperature = temperature
    # Register bounding Surfaces with the Cell
    cell.region = +min_x & -max_x & +min_y & -max_y

    # Fill the Cell with the Material
    cell.fill = inf_medium

    # Create root universe
    root_universe = openmc.Universe(name='root universe', cells=[cell])

    # Create Geometry and set root Universe
    openmc_geometry = openmc.Geometry(root_universe)

    # Export to "geometry.xml"
    openmc_geometry.export_to_xml()

    # OpenMC simulation parameters
    batches = 200
    inactive = 5
    particles = 5000

    # Instantiate a Settings object
    settings_file = openmc.Settings()
    settings_file.batches = batches
    settings_file.inactive = inactive
    settings_file.particles = particles
    settings_file.energy_mode = 'multi-group'
    settings_file.output = {'summary': False}
    # Create an initial uniform spatial source distribution over fissionable zones
    bounds = [-INF, -INF, -INF, INF, INF, INF]
    uniform_dist = openmc.stats.Box(bounds[:3], bounds[3:], only_fissionable=True)
    settings_file.temperature = {'method': tempmethod}
    settings_file.source = openmc.Source(space=uniform_dist)
    settings_file.export_to_xml()
Ejemplo n.º 12
0
def make_neutronics_model(
    reactor,
    firstwall_radial_thickness,
    firstwall_armour_material,
    firstwall_coolant_material,
    firstwall_structural_material,
    firstwall_armour_fraction,
    firstwall_coolant_fraction,
    firstwall_coolant_temperature_C,
    firstwall_coolant_pressure_Pa,
    firstwall_structural_fraction,
    blanket_rear_wall_coolant_material,
    blanket_rear_wall_structural_material,
    blanket_rear_wall_coolant_fraction,
    blanket_rear_wall_structural_fraction,
    blanket_rear_wall_coolant_temperature_C,
    blanket_rear_wall_coolant_pressure_Pa,
    blanket_lithium6_enrichment_percent,
    blanket_breeder_material,
    blanket_coolant_material,
    blanket_multiplier_material,
    blanket_structural_material,
    blanket_breeder_fraction,
    blanket_coolant_fraction,
    blanket_multiplier_fraction,
    blanket_structural_fraction,
    blanket_breeder_packing_fraction,
    blanket_multiplier_packing_fraction,
    blanket_coolant_temperature_C,
    blanket_coolant_pressure_Pa,
    blanket_breeder_temperature_C,
    blanket_breeder_pressure_Pa,
    divertor_coolant_fraction,
    divertor_structural_fraction,
    divertor_coolant_material,
    divertor_structural_material,
    divertor_coolant_temperature_C,
    divertor_coolant_pressure_Pa,
    center_column_shield_coolant_fraction,
    center_column_shield_structural_fraction,
    center_column_shield_coolant_material,
    center_column_shield_structural_material,
    center_column_shield_coolant_temperature_C,
    center_column_shield_coolant_pressure_Pa,
    inboard_tf_coils_conductor_fraction,
    inboard_tf_coils_coolant_fraction,
    inboard_tf_coils_structure_fraction,
    inboard_tf_coils_conductor_material,
    inboard_tf_coils_coolant_material,
    inboard_tf_coils_structure_material,
    inboard_tf_coils_coolant_temperature_C,
    inboard_tf_coils_coolant_pressure_Pa,
):
    """
    Makes and runs a simple OpenMC neutronics model with
    the materials with the same tags as the DAGMC neutronics
    geometry. The model also specifies the computational
    intensity (particles and batches) and the tally to record
    """
    input_parameters = locals()

    # this is the underlying geometry container that is filled with the
    # faceteted CAD model
    universe = openmc.Universe()
    geom = openmc.Geometry(universe)

    center_column_shield_material = MultiMaterial(
        material_tag="center_column_shield_mat",
        materials=[
            Material(
                material_name=center_column_shield_coolant_material,
                temperature_in_C=center_column_shield_coolant_temperature_C,
                pressure_in_Pa=center_column_shield_coolant_pressure_Pa,
            ),
            Material(material_name=center_column_shield_structural_material),
        ],
        fracs=[
            center_column_shield_coolant_fraction,
            center_column_shield_structural_fraction,
        ],
        percent_type="vo",
        packing_fraction=1.0,
    ).openmc_material

    firstwall_material = MultiMaterial(
        material_tag="firstwall_mat",
        materials=[
            Material(
                material_name=firstwall_coolant_material,
                temperature_in_C=firstwall_coolant_temperature_C,
                pressure_in_Pa=firstwall_coolant_pressure_Pa,
            ),
            Material(material_name=firstwall_structural_material),
            Material(material_name=firstwall_armour_material),
        ],
        fracs=[
            firstwall_coolant_fraction,
            firstwall_structural_fraction,
            firstwall_armour_fraction,
        ],
        percent_type="vo",
        packing_fraction=1.0,
    ).openmc_material

    if (
        blanket_multiplier_material is None
        and blanket_multiplier_fraction is None
        and blanket_multiplier_packing_fraction is None
    ):

        blanket_material = MultiMaterial(
            material_tag="blanket_mat",
            materials=[
                Material(
                    material_name=blanket_coolant_material,
                    temperature_in_C=blanket_coolant_temperature_C,
                    pressure_in_Pa=blanket_coolant_pressure_Pa,
                ),
                Material(material_name=blanket_structural_material),
                Material(
                    material_name=blanket_breeder_material,
                    enrichment=blanket_lithium6_enrichment_percent,
                    packing_fraction=blanket_breeder_packing_fraction,
                    temperature_in_C=blanket_breeder_temperature_C,
                    pressure_in_Pa=blanket_breeder_pressure_Pa,
                ),
            ],
            fracs=[
                blanket_coolant_fraction,
                blanket_structural_fraction,
                blanket_breeder_fraction,
            ],
            percent_type="vo",
            packing_fraction=1.0,
        ).openmc_material
    else:
        blanket_material = MultiMaterial(
            material_tag="blanket_mat",
            materials=[
                Material(
                    material_name=blanket_coolant_material,
                    temperature_in_C=blanket_coolant_temperature_C,
                    pressure_in_Pa=blanket_coolant_pressure_Pa,
                ),
                Material(material_name=blanket_structural_material),
                Material(
                    material_name=blanket_multiplier_material,
                    packing_fraction=blanket_multiplier_packing_fraction,
                ),
                Material(
                    material_name=blanket_breeder_material,
                    enrichment=blanket_lithium6_enrichment_percent,
                    packing_fraction=blanket_breeder_packing_fraction,
                    temperature_in_C=blanket_breeder_temperature_C,
                    pressure_in_Pa=blanket_breeder_pressure_Pa,
                ),
            ],
            fracs=[
                blanket_coolant_fraction,
                blanket_structural_fraction,
                blanket_multiplier_fraction,
                blanket_breeder_fraction,
            ],
            percent_type="vo",
            packing_fraction=1.0,
        ).openmc_material

    divertor_material = MultiMaterial(
        material_tag="divertor_mat",
        materials=[
            Material(
                material_name=divertor_coolant_material,
                temperature_in_C=divertor_coolant_temperature_C,
                pressure_in_Pa=divertor_coolant_pressure_Pa,
            ),
            Material(material_name=divertor_structural_material),
        ],
        fracs=[divertor_coolant_fraction, divertor_structural_fraction],
        percent_type="vo",
        packing_fraction=1.0,
    ).openmc_material

    inboard_tf_coils_material = MultiMaterial(
        material_tag="inboard_tf_coils_mat",
        materials=[
            Material(
                material_name=inboard_tf_coils_coolant_material,
                temperature_in_C=inboard_tf_coils_coolant_temperature_C,
                pressure_in_Pa=inboard_tf_coils_coolant_pressure_Pa,
            ),
            Material(material_name=inboard_tf_coils_conductor_material),
            Material(material_name=inboard_tf_coils_structure_material),
        ],
        fracs=[
            inboard_tf_coils_coolant_fraction,
            inboard_tf_coils_conductor_fraction,
            inboard_tf_coils_structure_fraction,
        ],
        percent_type="vo",
        packing_fraction=1.0,
    ).openmc_material

    blanket_rear_wall_material = MultiMaterial(
        material_tag="blanket_rear_wall_mat",
        materials=[
            Material(
                material_name=blanket_rear_wall_coolant_material,
                temperature_in_C=blanket_rear_wall_coolant_temperature_C,
                pressure_in_Pa=blanket_rear_wall_coolant_pressure_Pa,
            ),
            Material(material_name=blanket_rear_wall_structural_material),
        ],
        fracs=[
            blanket_rear_wall_coolant_fraction,
            blanket_rear_wall_structural_fraction,
        ],
        percent_type="vo",
        packing_fraction=1.0,
    ).openmc_material

    mats = openmc.Materials(
        [
            center_column_shield_material,
            firstwall_material,
            blanket_material,
            divertor_material,
            inboard_tf_coils_material,
            blanket_rear_wall_material,
        ]
    )

    # settings for the number of neutrons to simulate
    settings = openmc.Settings()
    settings.batches = 10
    settings.inactive = 0
    settings.particles = 1000
    settings.run_mode = "fixed source"
    settings.dagmc = True

    # details of the birth locations and energy of the neutronis
    source = openmc.Source()
    source.space = openmc.stats.Point((reactor["major_radius"], 0, 0))
    source.angle = openmc.stats.Isotropic()
    source.energy = openmc.stats.Discrete([14e6], [1])
    settings.source = source
    settings.photon_transport = (
        True  # This line is required to switch on photons tracking
    )

    # details about what neutrons interactions to keep track of (called a
    # tally)
    tallies = openmc.Tallies()
    material_filter = openmc.MaterialFilter(blanket_material)
    tbr_tally = openmc.Tally(name="TBR")
    tbr_tally.filters = [material_filter]
    tbr_tally.scores = ["(n,Xt)"]  # where X is a wild card
    tallies.append(tbr_tally)

    material_filter = openmc.MaterialFilter(
        [blanket_material, firstwall_material, blanket_rear_wall_material]
    )
    blanket_heating_tally = openmc.Tally(name="blanket_heating")
    blanket_heating_tally.filters = [material_filter]
    blanket_heating_tally.scores = ["heating"]
    tallies.append(blanket_heating_tally)

    # make the model from gemonetry, materials, settings and tallies
    model = openmc.model.Model(geom, mats, settings, tallies)

    # run the simulation
    output_filename = model.run()

    """
    Reads the output file from the neutronics simulation
    and prints the TBR tally result to screen
    """

    # open the results file
    sp = openmc.StatePoint(output_filename)

    # access TBR tally
    tbr_tally = sp.get_tally(name="TBR")
    df = tbr_tally.get_pandas_dataframe()
    tbr_tally_result = df["mean"].sum()
    tbr_tally_std_dev = df["std. dev."].sum()

    # access heating tally
    blanket_heating_tally = sp.get_tally(name="blanket_heating")
    df = blanket_heating_tally.get_pandas_dataframe()
    blanket_heating_tally_result = df["mean"].sum() / 1e6
    blanket_heating_tally_std_dev = df["std. dev."].sum() / 1e6

    # returns all the inputs and some extra reactor attributes, merged into a
    # single dictionary
    return {
        **input_parameters,
        **{
            "tbr": tbr_tally_result,
            "tbr_std_dev": tbr_tally_std_dev,
            "blanket_heating": blanket_heating_tally_result,
            "blanket_heating_std_dev": blanket_heating_tally_std_dev,
        },
    }
Ejemplo n.º 13
0
    def _build_inputs(self):
        mat = openmc.Material()
        mat.set_density('g/cm3', 2.6989)
        mat.add_nuclide('Al27', 1.0)
        materials = openmc.Materials([mat])
        materials.export_to_xml()

        cyl = openmc.XCylinder(r=1.0, boundary_type='vacuum')
        x_plane_left = openmc.XPlane(-1.0, 'vacuum')
        x_plane_center = openmc.XPlane(1.0)
        x_plane_right = openmc.XPlane(1.0e9, 'vacuum')

        inner_cyl_left = openmc.Cell()
        inner_cyl_right = openmc.Cell()
        outer_cyl = openmc.Cell()

        inner_cyl_left.region = -cyl & +x_plane_left & -x_plane_center
        inner_cyl_right.region = -cyl & +x_plane_center & -x_plane_right
        outer_cyl.region = ~(-cyl & +x_plane_left & -x_plane_right)
        inner_cyl_right.fill = mat
        geometry = openmc.Geometry(
            [inner_cyl_left, inner_cyl_right, outer_cyl])
        geometry.export_to_xml()

        source = openmc.Source()
        source.space = openmc.stats.Point((0, 0, 0))
        source.angle = openmc.stats.Monodirectional()
        source.energy = openmc.stats.Discrete([14.0e6], [1.0])
        source.particle = 'neutron'

        settings = openmc.Settings()
        settings.particles = 10000
        settings.run_mode = 'fixed source'
        settings.batches = 1
        settings.photon_transport = True
        settings.electron_treatment = 'ttb'
        settings.cutoff = {'energy_photon': 1000.0}
        settings.source = source
        settings.export_to_xml()

        surface_filter = openmc.SurfaceFilter(cyl)
        particle_filter = openmc.ParticleFilter('photon')
        current_tally = openmc.Tally()
        current_tally.filters = [surface_filter, particle_filter]
        current_tally.scores = ['current']
        tally_tracklength = openmc.Tally()
        tally_tracklength.filters = [particle_filter]
        tally_tracklength.scores = ['total', 'heating']
        tally_tracklength.nuclides = ['Al27', 'total']
        tally_tracklength.estimator = 'tracklength'
        tally_collision = openmc.Tally()
        tally_collision.filters = [particle_filter]
        tally_collision.scores = ['total', 'heating']
        tally_collision.nuclides = ['Al27', 'total']
        tally_collision.estimator = 'collision'
        tally_analog = openmc.Tally()
        tally_analog.filters = [particle_filter]
        tally_analog.scores = ['total', 'heating']
        tally_analog.nuclides = ['Al27', 'total']
        tally_analog.estimator = 'analog'
        tallies = openmc.Tallies(
            [current_tally, tally_tracklength, tally_collision, tally_analog])
        tallies.export_to_xml()
Ejemplo n.º 14
0
def define_Geo_Mat_Set(cells_num_dic,parameters_dic,settings_dic,temp_phy_mat,controlRod_deep,empty_reflector_height):
    # Check file
    if os.path.exists('geometry.xml'):
        os.remove('geometry.xml')
    if os.path.exists('materials.xml'):
        os.remove('materials.xml')
    if os.path.exists('settings.xml'):
        os.remove('settings.xml')
    if os.path.exists('tallies.xml'):
        os.remove('tallies.xml')

    # defualt temperature: 1073.5K
    if settings_dic['temperature_update']== True:
        temp_defualt = temp_phy_mat.min()
    else:
        temp_defualt = 1073.5

    # Structural Material HAYNES230
    structure_HAY = openmc.Material(name='HAYNES230')
    structure_HAY.set_density('g/cm3',8.97)
    structure_HAY.add_element('Ni',0.57,'wo')
    structure_HAY.add_element('Cr',0.22,'wo')
    structure_HAY.add_element('W',0.14,'wo')
    structure_HAY.add_element('Mo',0.02,'wo')
    structure_HAY.add_element('Fe',0.01875,'wo')
    structure_HAY.add_element('Co',0.03125,'wo')

    # Structural Material SS316
    structure_SS = openmc.Material(name='SS316')
    structure_SS.set_density('g/cm3',7.99)
    structure_SS.add_element('Ni',0.12,'wo')
    structure_SS.add_element('Cr',0.17,'wo')
    structure_SS.add_element('Mo',0.025,'wo')
    structure_SS.add_element('Mn',0.02,'wo')
    structure_SS.add_element('Fe',0.665,'wo')

    #Control Rod Material B4C
    ControlRod_B4C = openmc.Material(name='B4C')
    ControlRod_B4C.set_density('g/cm3',2.52)
    ControlRod_B4C.add_nuclide('B10',4,'ao')
    ControlRod_B4C.add_element('C',1,'ao')

    #Reflector Material BeO
    Reflector_BeO = openmc.Material(name='BeO')
    Reflector_BeO.set_density('g/cm3',3.025)
    Reflector_BeO.add_element('Be',1,'ao')
    Reflector_BeO.add_element('O',1,'ao')

    #Coolant Na
    Coolant_Na = openmc.Material(name='Na')
    Coolant_Na.set_density('g/cm3',0.76)
    Coolant_Na.add_element('Na',1,'ao')

    # Instantiate a Materials collection
    materials_file = openmc.Materials([structure_HAY, structure_SS, ControlRod_B4C, Reflector_BeO, Coolant_Na])


    # Number of cells
    n_r = cells_num_dic['n_r']
    n_r_outer = cells_num_dic['n_r_outer']
    n_h = cells_num_dic['n_h']
    

    # Effect of Temperature on density of fuel
    fuel_list = []
    density_mat = calUMoDensity(temp_phy_mat)

    # Fuel U-10Mo
    for j in range(n_h):
        for i in range(n_r):
            fuel_name = str((j+1)*10000+(i + 1)*100)
            fuel = openmc.Material(name='U-10Mo '+ fuel_name)
            fuel.set_density('g/cm3',density_mat[j,i])
            fuel.add_element('Mo',0.1,'wo')
            # fuel.add_nuclide('U235',0.1773,'wo') # for LEU (19.7%)
            # fuel.add_nuclide('U238',0.7227,'wo')
            fuel.add_nuclide('U235',0.837,'wo') # for HEU (93.0%)
            fuel.add_nuclide('U238',0.063,'wo')
            fuel_list.append(fuel)
            materials_file.append(fuel)

        for i in range(n_r_outer):
            fuel_name = str((j+1)*10000+(i + n_r + 1)*100)
            fuel = openmc.Material(name='U-10Mo '+ fuel_name)
            fuel.set_density('g/cm3',density_mat[j,i+n_r])
            fuel.add_element('Mo',0.1,'wo')
            # fuel.add_nuclide('U235',0.1773,'wo') # for LEU (19.7%)
            # fuel.add_nuclide('U238',0.7227,'wo')
            fuel.add_nuclide('U235',0.837,'wo') # for HEU (93.0%)
            fuel.add_nuclide('U238',0.063,'wo')
            fuel_list.append(fuel)
            materials_file.append(fuel)

    # Export to "materials.xml"
    materials_file.export_to_xml()

    num_heat_pipe = 8

    # Parameters of reactor
    # Unit:cm

    fuel_r = parameters_dic['fuel_r']
    fuel_h = parameters_dic['fuel_h']

    controlRod_r = parameters_dic['controlRod_r']
    controlRod_h_max = parameters_dic['controlRod_h_max']
    controlRod_l = parameters_dic['controlRod_l']

    reflector_r = parameters_dic['reflector_r']
    reflector_h = parameters_dic['reflector_h']

    heat_pipe_R = parameters_dic['heat_pipe_R']
    heat_pipe_r = parameters_dic['heat_pipe_r']

    top_distance = parameters_dic['top_distance']
    bottom_distance = parameters_dic['bottom_distance']

    # Create cylinders for the fuel control rod and reflector
    fuel_OD = openmc.ZCylinder(x0=0.0, y0=0.0, r=fuel_r)
    controlRod_OD = openmc.ZCylinder(x0=0.0, y0=0.0, r=controlRod_r)
    reflector_OD = openmc.ZCylinder(x0=0.0, y0=0.0, r=reflector_r, boundary_type='vacuum')

    # Create planes for fuel control rod and reflector
    reflector_TOP = openmc.ZPlane(z0 = (top_distance+fuel_h/2),boundary_type='vacuum')
    reflector_BOTTOM = openmc.ZPlane(z0 = -(bottom_distance+fuel_h/2),boundary_type='vacuum')
    reflector_empty_TOP = openmc.ZPlane(z0 = -(bottom_distance+fuel_h/2-empty_reflector_height))


    fuel_TOP = openmc.ZPlane(z0 = fuel_h/2)
    fuel_BOTTOM = openmc.ZPlane(z0 = -fuel_h/2)

    controlRodSpace_TOP = openmc.ZPlane(z0 = (controlRod_h_max-bottom_distance-fuel_h/2))

    # Create cylinders for heat pipes
    heat_pipe_OD = openmc.ZCylinder(x0=fuel_r, y0=0, r=heat_pipe_R)

    n_ang = num_heat_pipe
    ang_mesh = np.pi/n_ang


    r_mesh = np.linspace(controlRod_r,(fuel_r-heat_pipe_R),n_r+1)
    r_outer_mesh = np.linspace(fuel_r-heat_pipe_R,fuel_r,n_r_outer+1)
    h_mesh = np.linspace(-fuel_h/2,fuel_h/2,n_h+1)

    line_1 = openmc.Plane(a=np.tan(-ang_mesh),b=-1.0,c=0.0,d=0.0,boundary_type='reflective')
    line_2 = openmc.Plane(a=np.tan(ang_mesh),b=-1.0,c=0.0,d=0.0,boundary_type='reflective')

    # Create volume vector and matrix
    volume_vec = np.zeros(n_r+n_r_outer)
    d_h = fuel_h/n_h

    for i in range(n_r+n_r_outer):
        if i >= n_r:
            d = heat_pipe_R*(i-n_r)/n_r_outer
            x_i = np.sqrt(2*heat_pipe_R*d-d*d)
            d = heat_pipe_R*(i-n_r+1)/n_r_outer
            x_i1 = np.sqrt(2*heat_pipe_R*d-d*d)
            s = (x_i+x_i1)*heat_pipe_R/n_r_outer
            volume_vec[i] = d_h*np.pi*(r_outer_mesh[i+1-n_r]*r_outer_mesh[i+1-n_r]-r_outer_mesh[i-n_r]*r_outer_mesh[i-n_r])/8-s
        else:
            volume_vec[i] = d_h*np.pi*(r_mesh[i+1]*r_mesh[i+1]-r_mesh[i]*r_mesh[i])/8

    volume_mat = np.zeros((n_h,(n_r+n_r_outer)))
    for i in range(n_h):
        volume_mat[i,:] = volume_vec

    # Create heat_pipe universe
    heat_pipe_Inner = openmc.ZCylinder(r=heat_pipe_r)

    coolant_cell = openmc.Cell(fill=Coolant_Na, region=(-heat_pipe_Inner & -reflector_TOP & +reflector_BOTTOM))
    pipe_cell = openmc.Cell(fill=structure_HAY, region=(+heat_pipe_Inner & -reflector_TOP & +reflector_BOTTOM))

    heat_pipe_universe = openmc.Universe(cells=(coolant_cell, pipe_cell))

    # Create a Universe to encapsulate a fuel pin
    pin_cell_universe = openmc.Universe(name='U-10Mo Pin')

    # Create fine-fuel-cell (num of cells: n_r + n_r_outer)
    fuel_cell_list = []
    fuel_cell_ID_list = []


    k = 0
    for j in range(n_h):
        cir_top = openmc.ZPlane(z0 = h_mesh[j+1])
        cir_bottom = openmc.ZPlane(z0 = h_mesh[j])
        for i in range(n_r):
            cir_in = openmc.ZCylinder(r=r_mesh[i])
            cir_out = openmc.ZCylinder(r=r_mesh[i+1])
            fuel_cell = openmc.Cell()
            fuel_cell.fill = fuel_list[k]
            k = k+1
            fuel_cell.region = +cir_in & -cir_out & +cir_bottom &-cir_top
            fuel_cell.temperature = temp_phy_mat[j,i]
            fuel_cell.id = (j+1)*10000+(i + 1)*100
            fuel_cell_ID_list.append((j+1)*10000+(i + 1)*100)
            fuel_cell_list.append(fuel_cell)
            pin_cell_universe.add_cell(fuel_cell)

        for i in range(n_r_outer):
            cir_in = openmc.ZCylinder(r=r_outer_mesh[i])
            cir_out = openmc.ZCylinder(r=r_outer_mesh[i+1])
            fuel_cell = openmc.Cell()
            fuel_cell.fill = fuel_list[k]
            k = k+1
            fuel_cell.region = +cir_in & -cir_out & +heat_pipe_OD & +cir_bottom &-cir_top
            fuel_cell.temperature = temp_phy_mat[j,i+n_r]
            fuel_cell.id = (j+1)*10000+(n_r + i + 1)*100
            fuel_cell_ID_list.append((j+1)*10000+(n_r + i + 1)*100)
            fuel_cell_list.append(fuel_cell)
            pin_cell_universe.add_cell(fuel_cell)

    # Create control rod Cell
    controlRod_TOP = openmc.ZPlane(z0 = (controlRod_deep-fuel_h/2-bottom_distance))
    controlRod_TOP.name = 'controlRod_TOP'
    if controlRod_deep < controlRod_h_max:
        controlRod_empty_cell = openmc.Cell(name='Control Rod Empty')
        controlRod_empty_cell.region = -controlRod_OD & +controlRod_TOP & -controlRodSpace_TOP
        pin_cell_universe.add_cell(controlRod_empty_cell)


    if controlRod_deep > 0:
        controlRod_cell = openmc.Cell(name='Control Rod')
        controlRod_cell.fill = ControlRod_B4C
        controlRod_cell.region = -controlRod_OD & +reflector_BOTTOM & -controlRod_TOP
        controlRod_cell.tempearture = temp_defualt
        pin_cell_universe.add_cell(controlRod_cell)

    # Create heat pipe Cell
    heat_pipe_cell = openmc.Cell(name='Heat Pipe')
    heat_pipe_cell.fill = heat_pipe_universe
    heat_pipe_cell.region = -heat_pipe_OD & +reflector_BOTTOM & -reflector_TOP
    heat_pipe_cell.temperature = temp_defualt
    heat_pipe_cell.translation = (fuel_r,0,0)
    pin_cell_universe.add_cell(heat_pipe_cell)

    # To be edited
    # Create reflector Cell

    if empty_reflector_height >0:
        reflector_radial_empty_cell = openmc.Cell(name='Radial Reflector Empty')
        reflector_radial_empty_cell.region = +fuel_OD & +heat_pipe_OD & +reflector_BOTTOM & -reflector_empty_TOP
        pin_cell_universe.add_cell(reflector_radial_empty_cell)

        reflector_radial_cell = openmc.Cell(name='Radial Reflector')
        reflector_radial_cell.fill = Reflector_BeO
        reflector_radial_cell.region = +fuel_OD & +heat_pipe_OD & +reflector_empty_TOP & -reflector_TOP
        reflector_radial_cell.temperature = temp_defualt
        pin_cell_universe.add_cell(reflector_radial_cell)
    else:
        reflector_radial_cell = openmc.Cell(name='Radial Reflector')
        reflector_radial_cell.fill = Reflector_BeO
        reflector_radial_cell.region = +fuel_OD & +heat_pipe_OD & +reflector_BOTTOM & -reflector_TOP
        reflector_radial_cell.temperature = temp_defualt
        pin_cell_universe.add_cell(reflector_radial_cell)


    reflector_bottom_cell = openmc.Cell(name='Bottom Reflector')
    reflector_bottom_cell.fill = Reflector_BeO
    reflector_bottom_cell.region = +controlRod_OD & +heat_pipe_OD & -fuel_OD  & -fuel_BOTTOM & +reflector_BOTTOM
    reflector_bottom_cell.temperature = temp_defualt
    pin_cell_universe.add_cell(reflector_bottom_cell)

    reflector_top_cell = openmc.Cell(name='Top Reflector')
    reflector_top_cell.fill = Reflector_BeO
    reflector_top_cell.region = +heat_pipe_OD & -fuel_OD  & +controlRodSpace_TOP & -reflector_TOP
    reflector_top_cell.region = reflector_top_cell.region | (+controlRod_OD & +heat_pipe_OD & -fuel_OD & +fuel_TOP & -controlRodSpace_TOP)
    reflector_top_cell.temperature = temp_defualt
    pin_cell_universe.add_cell(reflector_top_cell)

    # Create root Cell
    root_cell = openmc.Cell(name='root cell')
    root_cell.fill = pin_cell_universe

    # Add boundary planes
    root_cell.region = -reflector_OD & +line_2 & -line_1 & +reflector_BOTTOM & -reflector_TOP

    # Create root Universe
    root_universe = openmc.Universe(universe_id=0, name='root universe')
    root_universe.add_cell(root_cell)

    # Create Geometry and set root Universe
    geometry = openmc.Geometry(root_universe)

    # Export to "geometry.xml"
    geometry.export_to_xml()

    # Instantiate a Settings object
    settings_file = openmc.Settings()
    settings_file.batches = settings_dic['batches']
    settings_file.inactive = settings_dic['inactive']
    settings_file.particles = settings_dic['particles']
    settings_file.temperature['multipole']= True
    settings_file.temperature['method']= 'interpolation'

    settings_file.source = openmc.Source(space=openmc.stats.Point((15,0,0)))
    # Export to "settings.xml"
    settings_file.export_to_xml()

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

    for i in range(len(fuel_cell_ID_list)):
        tally = openmc.Tally(name='cell tally '+str(fuel_cell_ID_list[i]))
        tally.filters = [openmc.DistribcellFilter(fuel_cell_ID_list[i])]
        tally.scores = ['heating','flux']
        tallies_file.append(tally)


    # Export to "tallies.xml"
    tallies_file.export_to_xml()
    
    return volume_mat,fuel_cell_ID_list
Ejemplo n.º 15
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()
Ejemplo n.º 16
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 = (10, 10, 10)
    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='wall_leakage')
    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')

    tallies_to_retrieve = ['wall_leakage']
    #at the moment, we only have one tally to retrieve, but we will set it up in a list anyway so we know how to do it
    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()

        #for now, we will just try to print these values

    #get spectra

    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
        ]
Ejemplo n.º 17
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
Ejemplo n.º 18
0
    def _build_openmc(self):
        """Generate the OpenMC input XML

        """
        # Directory from which openmc is run
        os.makedirs('openmc', exist_ok=True)

        # Define material
        mat = openmc.Material()
        for nuclide, fraction in self.nuclides:
            mat.add_nuclide(nuclide, fraction)
        mat.set_density('g/cm3', self.density)
        materials = openmc.Materials([mat])
        materials.export_to_xml(os.path.join('openmc', 'materials.xml'))

        # Instantiate surfaces
        cyl = openmc.XCylinder(boundary_type='vacuum', R=1.e-6)
        px1 = openmc.XPlane(boundary_type='vacuum', x0=-1.)
        px2 = openmc.XPlane(boundary_type='transmission', x0=1.)
        px3 = openmc.XPlane(boundary_type='vacuum', x0=1.e9)

        # Instantiate cells
        inner_cyl_left = openmc.Cell()
        inner_cyl_right = openmc.Cell()
        outer_cyl = openmc.Cell()

        # Set cells regions and materials
        inner_cyl_left.region = -cyl & +px1 & -px2
        inner_cyl_right.region = -cyl & +px2 & -px3
        outer_cyl.region = ~(-cyl & +px1 & -px3)
        inner_cyl_right.fill = mat

        # Create root universe and export to XML
        geometry = openmc.Geometry(
            [inner_cyl_left, inner_cyl_right, outer_cyl])
        geometry.export_to_xml(os.path.join('openmc', 'geometry.xml'))

        # Define source
        source = openmc.Source()
        source.space = openmc.stats.Point((0, 0, 0))
        source.angle = openmc.stats.Monodirectional()
        source.energy = openmc.stats.Discrete([self.energy], [1.])
        source.particle = 'neutron'

        # Settings
        settings = openmc.Settings()
        settings.source = source
        settings.particles = self.particles
        settings.run_mode = 'fixed source'
        settings.batches = 1
        settings.photon_transport = True
        settings.electron_treatment = self.electron_treatment
        settings.cutoff = {'energy_photon': 1000.}
        settings.export_to_xml(os.path.join('openmc', 'settings.xml'))

        # Define filters
        surface_filter = openmc.SurfaceFilter(cyl)
        particle_filter = openmc.ParticleFilter('photon')
        energy_bins = np.logspace(3, np.log10(2 * self.energy), 500)
        energy_filter = openmc.EnergyFilter(energy_bins)

        # Create tallies and export to XML
        tally = openmc.Tally(name='photon current')
        tally.filters = [surface_filter, energy_filter, particle_filter]
        tally.scores = ['current']
        tallies = openmc.Tallies([tally])
        tallies.export_to_xml(os.path.join('openmc', 'tallies.xml'))
Ejemplo n.º 19
0
def make_model_mg_by_nuclide(nameoflib):

    nuclist, conc, temp, rodnuclist, concrod, temprod, dzz, hss, rods, type_fuel, type_assembly = make_datas()
    nkas = len(rods)
    diction_mg = translate_mg(nkas, rods, dzz, [sum(dzz)], nameoflib,
                                 nuclist, conc, rodnuclist, concrod)
    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, temprod)
            load_dict[i+1]  = [i+1]
        else:
            assemblies[i+1] = make_abl_mg_cells(diction_mg, hexsurf, zfaces, i+1, temp)
            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.survival_biasing = True
    #settings_file.cutoff = {'energy_neutron' : 1.0,'weight':1.e-10}
    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()
    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'
Ejemplo n.º 20
0
    def initial(self, opt, Mesh):  #, nthreads):

        #####################################
        # Create OpenMC geometry
        #####################################

        FuelOR = opt.FuelOR * 100  #[cm]
        CladIR = opt.CladIR * 100  #[cm]
        CladOR = opt.CladOR * 100  #[cm]
        # ExtraCladOR = opt.ExtraCladOR*100 #[cm]
        Pitch = opt.PinPitch * 100  #[cm]

        # Construct uniform initial source distribution over fissionable zones
        lower_left = [-Pitch / 2, -Pitch / 2, 0]
        upper_right = [+Pitch / 2, +Pitch / 2, +365.76]
        uniform_dist = openmc.stats.Box(lower_left,
                                        upper_right,
                                        only_fissionable=True)

        # Settings file
        self.settings_file = openmc.Settings()
        self.settings_file.batches = 1100
        self.settings_file.inactive = 100
        self.settings_file.particles = 20000
        self.settings_file.generations_per_batch = 5
        self.settings_file.output = {'tallies': False}
        self.settings_file.temperature = {'multipole': True, 'tolerance': 3000}
        self.settings_file.source = openmc.source.Source(space=uniform_dist)
        self.settings_file.seed = np.random.randint(1, 100)  # for correlation

        self.settings_file.export_to_xml()  #Removed for correlation

        # Materials file
        uo2 = openmc.Material(material_id=1,
                              name='UO2 fuel at 2.4% wt enrichment')
        uo2.temperature = 900.  #opt.Tin
        uo2.set_density('g/cm3', 10.29769)
        uo2.add_element('U', 1., enrichment=2.4)
        uo2.add_element('O', 2.)

        # helium = openmc.Material(material_id=2, name='Helium for gap')
        # helium.temperature = opt.Tin
        # helium.set_density('g/cm3', 0.001598)
        # helium.add_element('He', 2.4044e-4)

        zircaloy = openmc.Material(material_id=3, name='Zircaloy 4')
        zircaloy.temperature = opt.Tin
        zircaloy.set_density('g/cm3', 6.55)
        zircaloy.add_element('Sn', 0.014, 'wo')
        zircaloy.add_element('Fe', 0.00165, 'wo')
        zircaloy.add_element('Cr', 0.001, 'wo')
        zircaloy.add_element('Zr', 0.98335, 'wo')

        # borated_water = openmc.Material()
        # borated_water.temperature = opt.Tin
        # borated_water.set_density('g/cm3', 0.7406)
        # 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 = openmc.model.borated_water(boron_ppm=432.473,
                                                   temperature=opt.Tin,
                                                   pressure=15)

        self.materials_file = openmc.Materials([uo2, zircaloy,
                                                borated_water])  #helium
        self.materials_file.export_to_xml()  #Removed for correlation

        # Geometry file
        fuel_or = openmc.ZCylinder(x0=0, y0=0, R=FuelOR)
        # clad_ir = openmc.ZCylinder(x0=0, y0=0, R=CladIR)
        clad_or = openmc.ZCylinder(x0=0, y0=0, R=CladOR)
        # extra_clad_or = openmc.ZCylinder(x0=0, y0=0, R=ExtraCladOR)
        left = openmc.XPlane(x0=-Pitch / 2)
        right = openmc.XPlane(x0=Pitch / 2)
        back = openmc.YPlane(y0=-Pitch / 2)
        front = openmc.YPlane(y0=Pitch / 2)
        top = openmc.ZPlane(z0=396.24)
        bottom = openmc.ZPlane(z0=-30.48)
        z_list = []
        for i in range(0, len(Mesh)):
            z_list.append(openmc.ZPlane(z0=Mesh[i]))

        left.boundary_type = 'reflective'
        right.boundary_type = 'reflective'
        front.boundary_type = 'reflective'
        back.boundary_type = 'reflective'
        top.boundary_type = 'vacuum'
        bottom.boundary_type = 'vacuum'
        # z_list[-1].boundary_type = 'vacuum'
        # z_list[0].boundary_type = 'vacuum'

        self.reflectTOP = openmc.Cell()
        self.reflectBOT = openmc.Cell()
        self.fuel_list = []
        # self.gap_list = []
        self.clad_list = []
        # self.extra_clad_list = []
        self.water_list = []
        for i in range(0, len(Mesh) - 1):
            self.fuel_list.append(openmc.Cell())
            # self.gap_list.append(openmc.Cell())
            self.clad_list.append(openmc.Cell())
            # self.extra_clad_list.append(openmc.Cell())
            self.water_list.append(openmc.Cell())

        self.reflectTOP.region = +left & -right & +back & -front & +z_list[
            -1] & -top
        self.reflectBOT.region = +left & -right & +back & -front & +bottom & -z_list[
            0]

        self.reflectTOP.fill = borated_water
        self.reflectBOT.fill = borated_water

        j = 0
        for fuels in self.fuel_list:
            fuels.region = -fuel_or & +z_list[j] & -z_list[j + 1]
            fuels.fill = uo2
            j = j + 1
        # j = 0
        # for gaps in self.gap_list:
        # 	gaps.region = +fuel_or & -clad_ir & +z_list[j] & -z_list[j+1]
        # 	gaps.fill = helium
        # 	j = j+1
        j = 0
        for clads in self.clad_list:
            clads.region = +fuel_or & -clad_or & +z_list[j] & -z_list[
                j + 1]  #clad_ir instead of fuel_or
            clads.fill = zircaloy
            j = j + 1
        # j = 0
        # for extra_clads in self.extra_clad_list:
        # 	extra_clads.region = +clad_or & -extra_clad_or & +left & -right & +back & -front & +z_list[j] & -z_list[j+1]
        # 	grid_flag = 0
        # 	for i in range(0,len(opt.GridBot_z)):
        # 		if z_list[j].z0 == opt.GridBot_z[i]:
        # 			extra_clads.fill = zircaloy
        # 			grid_flag = 1
        # 	if grid_flag == 1:
        # 		extra_clads.fill = zircaloy
        # 	else:
        # 		extra_clads.fill = borated_water
        # 	extra_clads.fill = borated_water
        # 	j = j+1
        j = 0
        for waters in self.water_list:
            waters.region = +clad_or & +left & -right & +back & -front & +z_list[
                j] & -z_list[j + 1]
            waters.fill = borated_water
            j = j + 1

        self.root = openmc.Universe(universe_id=0, name='root universe')
        self.root.add_cells(self.fuel_list)
        # self.root.add_cells(self.gap_list)
        self.root.add_cells(self.clad_list)
        # self.root.add_cells(self.extra_clad_list)
        self.root.add_cells(self.water_list)
        self.root.add_cells([self.reflectTOP, self.reflectBOT])
        self.geometry_file = openmc.Geometry(self.root)
        self.geometry_file.export_to_xml()  #Removed for correlation

        # Tallies
        # power distribution: fission q recoverable (Sterling's note: starts 0, might be data pb)
        # openmc accounts for incoming neutron energy and isotope
        cell_filter = openmc.CellFilter(self.fuel_list)
        t = openmc.Tally(tally_id=1)
        t.filters.append(cell_filter)
        t.scores = ['fission-q-recoverable']
        tallies = openmc.Tallies([t])
        tallies.export_to_xml()  #Removed for correlation

        # Plots
        plot = openmc.Plot()
        plot.width = [Pitch + 45, Pitch + 45]
        plot.origin = [0., 0., -20]
        plot.color_by = 'material'
        plot.filename = 'fuel-pin'
        plot.pixels = [1000, 1000]
        plot.basis = 'yz'
        # openmc.plot_inline(plot)

        # Move Files to PinGeo folder #Removed for correlation
        shutil.move('settings.xml', 'PinGeo/settings.xml')
        shutil.move('materials.xml', 'PinGeo/materials.xml')
        shutil.move('geometry.xml', 'PinGeo/geometry.xml')
        shutil.move('tallies.xml', 'PinGeo/tallies.xml')
        # shutil.move('plots.xml', 'PinGeo/plots.xml')

        openmc.run(
            cwd='PinGeo')  #, threads=nthreads, mpi_args=['mpiexec','-n','2'])
        sp = openmc.StatePoint('PinGeo/statepoint.' +
                               str(self.settings_file.batches) + '.h5')
        tally = sp.get_tally(scores=['fission-q-recoverable'])

        self.Tally = np.ndarray.flatten(tally.sum)
        Pfactor = 66945.4 / sum(np.ndarray.flatten(tally.sum))
        # print("Pfactor: ", Pfactor)
        self.Tally = np.ndarray.flatten(tally.sum) * Pfactor
        self.Var = np.divide(np.ndarray.flatten(tally.std_dev),
                             np.ndarray.flatten(tally.mean))
Ejemplo n.º 21
0
    def _build_inputs(self):
        # Define TRISO matrials
        fuel = openmc.Material()
        fuel.set_density('g/cm3', 10.5)
        fuel.add_nuclide('U235', 0.14154)
        fuel.add_nuclide('U238', 0.85846)
        fuel.add_nuclide('C0', 0.5)
        fuel.add_nuclide('O16', 1.5)

        porous_carbon = openmc.Material()
        porous_carbon.set_density('g/cm3', 1.0)
        porous_carbon.add_nuclide('C0', 1.0)
        porous_carbon.add_s_alpha_beta('c_Graphite')

        ipyc = openmc.Material()
        ipyc.set_density('g/cm3', 1.90)
        ipyc.add_nuclide('C0', 1.0)
        ipyc.add_s_alpha_beta('c_Graphite')

        sic = openmc.Material()
        sic.set_density('g/cm3', 3.20)
        sic.add_element('Si', 1.0)
        sic.add_nuclide('C0', 1.0)

        opyc = openmc.Material()
        opyc.set_density('g/cm3', 1.87)
        opyc.add_nuclide('C0', 1.0)
        opyc.add_s_alpha_beta('c_Graphite')

        graphite = openmc.Material()
        graphite.set_density('g/cm3', 1.1995)
        graphite.add_nuclide('C0', 1.0)
        graphite.add_s_alpha_beta('c_Graphite')

        # Create TRISO particles
        spheres = [
            openmc.Sphere(R=r * 1e-4) for r in [212.5, 312.5, 347.5, 382.5]
        ]
        c1 = openmc.Cell(fill=fuel, region=-spheres[0])
        c2 = openmc.Cell(fill=porous_carbon, region=+spheres[0] & -spheres[1])
        c3 = openmc.Cell(fill=ipyc, region=+spheres[1] & -spheres[2])
        c4 = openmc.Cell(fill=sic, region=+spheres[2] & -spheres[3])
        c5 = openmc.Cell(fill=opyc, region=+spheres[3])
        inner_univ = openmc.Universe(cells=[c1, c2, c3, c4, c5])

        outer_radius = 422.5 * 1e-4
        trisos = openmc.model.pack_trisos(radius=outer_radius,
                                          fill=inner_univ,
                                          domain_shape='cube',
                                          domain_length=1.,
                                          domain_center=(0., 0., 0.),
                                          n_particles=100)

        # Define box to contain lattice
        min_x = openmc.XPlane(x0=-0.5, boundary_type='reflective')
        max_x = openmc.XPlane(x0=0.5, boundary_type='reflective')
        min_y = openmc.YPlane(y0=-0.5, boundary_type='reflective')
        max_y = openmc.YPlane(y0=0.5, boundary_type='reflective')
        min_z = openmc.ZPlane(z0=-0.5, boundary_type='reflective')
        max_z = openmc.ZPlane(z0=0.5, boundary_type='reflective')
        box = openmc.Cell(region=+min_x & -max_x & +min_y & -max_y & +min_z
                          & -max_z)

        # Create lattice
        ll, ur = box.region.bounding_box
        shape = (3, 3, 3)
        pitch = (ur - ll) / shape
        lattice = openmc.model.create_triso_lattice(trisos, ll, pitch, shape,
                                                    graphite)
        box.fill = lattice

        root = openmc.Universe(0, cells=[box])
        geom = openmc.Geometry(root)
        geom.export_to_xml()

        settings = openmc.Settings()
        settings.batches = 5
        settings.inactive = 0
        settings.particles = 100
        settings.source = openmc.Source(space=openmc.stats.Point())
        settings.export_to_xml()

        mats = openmc.Materials(
            [fuel, porous_carbon, ipyc, sic, opyc, graphite])
        mats.export_to_xml()
Ejemplo n.º 22
0
    def _make_openmc_input(self):
        """Generate the OpenMC input XML

        """
        # Define material
        mat = openmc.Material()
        for nuclide, fraction in self.nuclides:
            mat.add_nuclide(nuclide, fraction)
        mat.set_density('g/cm3', self.density)
        materials = openmc.Materials([mat])
        if self.xsdir is not None:
            xs_path = (self.openmc_dir / 'cross_sections.xml').resolve()
            materials.cross_sections = str(xs_path)
        materials.export_to_xml(self.openmc_dir / 'materials.xml')

        # Instantiate surfaces
        cyl = openmc.XCylinder(boundary_type='vacuum', r=1.e-6)
        px1 = openmc.XPlane(boundary_type='vacuum', x0=-1.)
        px2 = openmc.XPlane(boundary_type='transmission', x0=1.)
        px3 = openmc.XPlane(boundary_type='vacuum', x0=1.e9)

        # Instantiate cells
        inner_cyl_left = openmc.Cell()
        inner_cyl_right = openmc.Cell()
        outer_cyl = openmc.Cell()

        # Set cells regions and materials
        inner_cyl_left.region = -cyl & +px1 & -px2
        inner_cyl_right.region = -cyl & +px2 & -px3
        outer_cyl.region = ~(-cyl & +px1 & -px3)
        inner_cyl_right.fill = mat

        # Create root universe and export to XML
        geometry = openmc.Geometry(
            [inner_cyl_left, inner_cyl_right, outer_cyl])
        geometry.export_to_xml(self.openmc_dir / 'geometry.xml')

        # Define source
        source = openmc.Source()
        source.space = openmc.stats.Point((0, 0, 0))
        source.angle = openmc.stats.Monodirectional()
        source.energy = openmc.stats.Discrete([self.energy], [1.])
        source.particle = 'neutron'

        # Settings
        settings = openmc.Settings()
        if self._temperature is not None:
            settings.temperature = {'default': self._temperature}
        settings.source = source
        settings.particles = self.particles // self._batches
        settings.run_mode = 'fixed source'
        settings.batches = self._batches
        settings.photon_transport = True
        settings.electron_treatment = self.electron_treatment
        settings.cutoff = {'energy_photon': self._cutoff_energy}
        settings.export_to_xml(self.openmc_dir / 'settings.xml')

        # Define filters
        surface_filter = openmc.SurfaceFilter(cyl)
        particle_filter = openmc.ParticleFilter('photon')
        energy_bins = np.logspace(np.log10(self._cutoff_energy),
                                  np.log10(self.max_energy), self._bins + 1)
        energy_filter = openmc.EnergyFilter(energy_bins)

        # Create tallies and export to XML
        tally = openmc.Tally(name='tally')
        tally.filters = [surface_filter, energy_filter, particle_filter]
        tally.scores = ['current']
        tallies = openmc.Tallies([tally])
        tallies.export_to_xml(self.openmc_dir / 'tallies.xml')
Ejemplo n.º 23
0
def simulate_model(
    enrichment,
    thickness,
    breeder_material_name="Li4SiO4",
    temperature_in_C=500,
    batches=10,
    nps=1000,
    inner_radius=500,
):

    # MATERIALS from library of materials in neutronics_material_maker package
    breeder_material = Material(
        material_name=breeder_material_name,
        enrichment=enrichment,
        temperature_in_C=temperature_in_C,
    ).neutronics_material

    eurofer = Material(material_name="eurofer").neutronics_material
    copper = Material(material_name="copper").neutronics_material

    mats = openmc.Materials([breeder_material, eurofer, copper])
    mats.export_to_xml("materials.xml")

    # GEOMETRY#

    central_sol_surface = openmc.ZCylinder(r=100)
    central_shield_outer_surface = openmc.ZCylinder(r=110)
    first_wall_inner_surface = openmc.Sphere(r=inner_radius)
    first_wall_outer_surface = openmc.Sphere(r=inner_radius + 10)
    breeder_blanket_outer_surface = openmc.Sphere(r=inner_radius + 10.0 +
                                                  thickness)
    vessel_outer_surface = openmc.Sphere(r=inner_radius + 10.0 + thickness +
                                         10.0,
                                         boundary_type="vacuum")

    central_sol_region = -central_sol_surface & -breeder_blanket_outer_surface
    central_sol_cell = openmc.Cell(region=central_sol_region)
    central_sol_cell.fill = copper

    central_shield_region = (+central_sol_surface
                             & -central_shield_outer_surface
                             & -breeder_blanket_outer_surface)
    central_shield_cell = openmc.Cell(region=central_shield_region)
    central_shield_cell.fill = eurofer

    inner_void_region = -first_wall_inner_surface & +central_shield_outer_surface
    inner_void_cell = openmc.Cell(region=inner_void_region)
    inner_void_cell.name = "inner_void"

    first_wall_region = (-first_wall_outer_surface
                         & +first_wall_inner_surface
                         & +central_shield_outer_surface)
    first_wall_cell = openmc.Cell(region=first_wall_region)
    first_wall_cell.fill = eurofer

    breeder_blanket_region = (+first_wall_outer_surface
                              & -breeder_blanket_outer_surface
                              & +central_shield_outer_surface)
    breeder_blanket_cell = openmc.Cell(region=breeder_blanket_region)
    breeder_blanket_cell.fill = breeder_material

    vessel_region = +breeder_blanket_outer_surface & -vessel_outer_surface
    vessel_cell = openmc.Cell(region=vessel_region)
    vessel_cell.name = "vessel"
    vessel_cell.fill = eurofer

    universe = openmc.Universe(cells=[
        central_sol_cell,
        central_shield_cell,
        inner_void_cell,
        first_wall_cell,
        breeder_blanket_cell,
        vessel_cell,
    ])

    geom = openmc.Geometry(universe)

    # SIMULATION SETTINGS#

    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((150, 0, 0))
    source.angle = openmc.stats.Isotropic()
    source.energy = openmc.stats.Discrete([14.08e6], [1])
    sett.source = source

    # sett.export_to_xml("settings.xml")

    # tally filters
    particle_filter = openmc.ParticleFilter("neutron")
    cell_filter_breeder = openmc.CellFilter(breeder_blanket_cell)

    # TALLIES#
    tallies = openmc.Tallies()

    tally = openmc.Tally(name="TBR")
    tally.filters = [cell_filter_breeder, particle_filter]
    tally.scores = ["(n,Xt)"]
    tallies.append(tally)

    # RUN OPENMC #
    model = openmc.model.Model(geom, mats, sett, tallies)
    model.run(output=False)

    # RETRIEVING TALLY RESULTS

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

    json_output = {
        "batches": batches,
        "nps": nps,
        "enrichment": enrichment,
        "inner_radius": inner_radius,
        "thickness": thickness,
        "breeder_material_name": breeder_material_name,
        "temperature_in_C": temperature_in_C,
    }

    tally = sp.get_tally(name="TBR")

    df = tally.get_pandas_dataframe()

    json_output["TBR"] = df["mean"].sum()
    json_output["TBR_std_dev"] = df["std. dev."].sum()

    return json_output
Ejemplo n.º 24
0
	def _pre_run(self, root_cell):

		MC_input_path = self.MC_input_path
		pre_run_path = os.getcwd() +'/pre_run'
		try:
			shutil.rmtree(pre_run_path)
		except OSError:
			pass
		os.mkdir(pre_run_path)

		# Prepare the volume calculation
		#bounding_box = root_cell.bounding_box
		ll = self.bounding_box[0]
		ur = self.bounding_box[1]
		cell_dict = root_cell.get_all_cells()
		cell_list = utils.cell_dict_to_cell_list(cell_dict)
		cell_list.append(root_cell) # Add root_cell so that the total volume is calculated
		vol1 = openmc.VolumeCalculation(cell_list, 100000, lower_left = ll, upper_right = ur)

		settings = openmc.Settings()
		settings.volume_calculations = [vol1]
		settings.temperature = {'method':'interpolation'}
		settings.run_mode='volume'
		settings.export_to_xml(path = pre_run_path + '/settings.xml')

		# Copy the geometry and material file to the new dummy dir
		shutil.copyfile(MC_input_path + '/geometry.xml', pre_run_path + '/geometry.xml')
		shutil.copyfile(MC_input_path + '/materials.xml', pre_run_path + '/materials.xml')

		# By default, the openm_exec is set to 'openmc'
		# For some reasons, this does not work on the cluster (della)
		# On della, we need to explicitly define the absolute path to the bin we want to use
		# Right now a temporary path that depends on my installation is used

		#openmc.calculate_volumes(cwd = pre_run_path, openmc_exec='/tigress/jdtdl/openmc/py3-mpi-190324/bin/openmc')
		openmc.calculate_volumes(cwd = pre_run_path, openmc_exec=self.openmc_bin_path)
		#openmc.run()

		# Read and set initial nuclides dict
		self.set_init_nucl_dict(root_cell)

		# # Read each material object and add 1atm nuclides chosen by the user
		# if self.mode == 'no_const_lib':
		# 	self.add_zero_dens_nuclides(self.nucl_list_dict)

		self._set_initial_summary(pre_run_path)
		self._set_cross_sections_path(pre_run_path)
		# Read cross sections xml files, create MC_XS_nucl_list
		self.set_MC_XS_nucl_list()
		self.set_root_universe()
		root_cell_name = 'root cell' # 	need to be specified by the user at some point
		self._set_root_cell(root_cell_name)

		# Extract cells from summary, add 1 atm nuclides to their material
		self._change_cell_materials()

		# Read and distribute volumes to cells
		self.set_vol_to_cell(vol1, pre_run_path)

		# pdb.set_trace()

		shutil.rmtree(pre_run_path)
Ejemplo n.º 25
0
def sphere_with_firstwall_model(
        material_for_structure,
        blanket_breeder_material,
        blanket_coolant_material,
        firstwall_coolant_material,
        blanket_breeder_li6_enrichment,  # this is a percentage
        coolant_pressure,  # this is in Pa
        blanket_coolant_temperature_in_C,
        firstwall_coolant_temperature_in_C,
        blanket_breeder_fraction,
        blanket_coolant_fraction,
        blanket_structural_fraction,
        blanket_breeder_temperature_in_C = None, #needed for liquid breeders like lithium lead
        firstwall_thickness = 2.7,  # this is in cm
        blanket_thickness = 200,  # this is in cm
        inner_radius = 1000,
        firstwall_armour_fraction = 0.106305, # equivilent to 3mm and based on https://doi.org/10.1016/j.fusengdes.2017.02.008
        firstwall_coolant_fraction= 0.333507, # based on https://doi.org/10.1016/j.fusengdes.2017.02.008
        firstwall_structural_fraction = 0.560188, # based on https://doi.org/10.1016/j.fusengdes.2017.02.008
        blanket_multipler_material = None, #used for combined breeder multiplier options
        blanket_multiplier_fraction = None, #used for combined breeder multiplier options
        blanket_breeder_material_packing_fraction = None, #used for combined breeder multiplier options
        blanket_multiplier_packing_fraction = None, #used for combined breeder multiplier options
        blanket_multiplier_material = None #used for combined breeder multiplier options
        ):

    breeder_percent_in_breeder_plus_multiplier_ratio = 100 * (blanket_breeder_fraction / (blanket_breeder_fraction + blanket_multiplier_fraction))

    inputs = locals()

    """ 
    This function builds materials for the homogenised blanket material, homogenised firstwall material
    The creates a simple sphere geometry with a simple point source and TBR tally on the blanket
    The function also carries out the simulation and writes the results to a JSON file
    """

    # creates homogensied blanket material using a single breeder / multiplier material (e.g lithium lead)
    if blanket_breeder_material == 'Pb842Li158':
        blanket_material =  MultiMaterial(material_tag = 'blanket_material',
                            materials = [
                                        Material(material_name = material_for_structure),
                                        Material(material_name = blanket_coolant_material,
                                                 temperature_in_C = blanket_coolant_temperature_in_C,
                                                 pressure_in_Pa = coolant_pressure),
                                        Material(material_name = blanket_breeder_material, 
                                                 enrichment = blanket_breeder_li6_enrichment,
                                                 temperature_in_C = blanket_breeder_temperature_in_C),
                                        ],
                            fracs = [blanket_structural_fraction,
                                    blanket_coolant_fraction,
                                    blanket_breeder_fraction],
                            percent_type='vo'
                            ).openmc_material

    # creates homogensied blanket material using a combined breeder multiplier material (e.g lithium ceramic with be multiplier)
    else:

        blanket_material =  MultiMaterial(
                                material_tag = 'blanket_material',
                                materials = [
                                            Material(material_name = material_for_structure),
                                            Material(material_name = blanket_coolant_material,
                                                    temperature_in_C = blanket_coolant_temperature_in_C,
                                                    pressure_in_Pa = coolant_pressure),
                                            Material(material_name = blanket_breeder_material, 
                                                    enrichment = blanket_breeder_li6_enrichment,
                                                    packing_fraction = blanket_breeder_material_packing_fraction),
                                            Material(material_name = blanket_multipler_material,
                                                    packing_fraction = blanket_multiplier_packing_fraction),
                                            ],
                                fracs = [blanket_structural_fraction,
                                        blanket_coolant_fraction,
                                        blanket_breeder_fraction,
                                        blanket_multiplier_fraction],
                                percent_type='vo'
                                ).openmc_material


    # creates homogensied firstwall material with eurofer, tungsten and a coolant
    firstwall_material = MultiMaterial(material_tag = 'firstwall_material',
                                        materials = [
                                            Material(material_name = 'tungsten'),
                                            Material(material_name = firstwall_coolant_material,
                                                        temperature_in_C = firstwall_coolant_temperature_in_C,
                                                        pressure_in_Pa = coolant_pressure),
                                            Material(material_name = 'eurofer')],
                                        fracs = [firstwall_armour_fraction,
                                                 firstwall_coolant_fraction,
                                                 firstwall_structural_fraction]
                                        ).openmc_material

    mats = openmc.Materials([blanket_material, firstwall_material]) 

    # creates surfaces
    breeder_blanket_inner_surface = openmc.Sphere(r=inner_radius+firstwall_thickness)
    firstwall_outer_surface = openmc.Sphere(r=inner_radius)  

    inner_void_region = -firstwall_outer_surface 
    inner_void_cell = openmc.Cell(region=inner_void_region) 
    inner_void_cell.name = 'inner_void'

    firstwall_region = +firstwall_outer_surface & -breeder_blanket_inner_surface 
    firstwall_cell = openmc.Cell(name='firstwall', region=firstwall_region)
    firstwall_cell.fill = firstwall_material

    breeder_blanket_outer_surface = openmc.Sphere(r=inner_radius+firstwall_thickness+blanket_thickness, boundary_type='vacuum')
    breeder_blanket_region = -breeder_blanket_outer_surface & +breeder_blanket_inner_surface
    breeder_blanket_cell = openmc.Cell(name = 'breeder_blanket', region=breeder_blanket_region) 
    breeder_blanket_cell.fill = blanket_material

    universe = openmc.Universe(cells=[inner_void_cell, 
                                      firstwall_cell,
                                      breeder_blanket_cell])

    geom = openmc.Geometry(universe)

    # assigns simulation settings
    sett = openmc.Settings()
    sett.batches = 200  # this is minimum number of batches that will be run
    sett.trigger_active = True
    sett.trigger_max_batches =  1500  # this is maximum number of batches that will be run
    sett.particles = 300
    sett.verbosity = 1
    sett.run_mode = 'fixed source'

    # sets a 14MeV (distributuion) point source
    source = openmc.Source()
    source.space = openmc.stats.Point((0,0,0))
    source.angle = openmc.stats.Isotropic()
    source.energy = openmc.stats.Muir(e0=14080000.0, m_rat=5.0, kt=20000.0) #neutron energy = 14.08MeV, AMU for D + T = 5, temperature is 20KeV
    sett.source = source

    # this is the tally set up
    tallies = openmc.Tallies()

    # define filters
    cell_filter_breeder = openmc.CellFilter(breeder_blanket_cell)
    particle_filter = openmc.ParticleFilter(['neutron'])

    # creates the TBR tally using the filters and sets a completion trigger
    tally = openmc.Tally(name='TBR')
    tally.filters = [cell_filter_breeder, particle_filter]
    tally.scores = ['(n,Xt)'] # where X is a wildcard, if MT 105 or (n,t) then some tritium production will be missed, for example (n,nt) which happens in Li7 would be missed
    tally.triggers = [openmc.Trigger(trigger_type='rel_err', threshold=0.0001)]  # This stops the simulation if the threshold is meet
    tallies.append(tally)

    # collects all the model parts and runs the model
    model = openmc.model.Model(geom, mats, sett, tallies)
    sp_filename = model.run(output=False)

    # opens the output file and retrieves the tally results
    sp = openmc.StatePoint(sp_filename)

    tally = sp.get_tally(name='TBR')

    df = tally.get_pandas_dataframe()

    tally_result = df['mean'].sum()
    tally_std_dev = df['std. dev.'].sum()

    # combines the tally results with the input data
    inputs.update({'tbr': tally_result})
    inputs.update({'tbr_error': tally_std_dev})

    return inputs
Ejemplo n.º 26
0
    def _build_inputs(self):
        # Instantiate some Materials and register the appropriate Nuclides
        uo2 = openmc.Material(name='UO2 fuel at 2.4% wt enrichment')
        uo2.set_density('g/cc', 10.0)
        uo2.add_nuclide('U238', 1.0)
        uo2.add_nuclide('U235', 0.02)
        uo2.add_nuclide('O16', 2.0)

        borated_water = openmc.Material(name='Borated water')
        borated_water.set_density('g/cm3', 1)
        borated_water.add_nuclide('B10', 10e-5)
        borated_water.add_nuclide('H1', 2.0)
        borated_water.add_nuclide('O16', 1.0)

        # Instantiate a Materials collection and export to XML
        materials_file = openmc.Materials([uo2, borated_water])
        materials_file.export_to_xml()

        # Instantiate ZCylinder surfaces
        fuel_or = openmc.ZCylinder(surface_id=1, x0=0, y0=0, R=1, \
             name='Fuel OR')
        left = openmc.XPlane(surface_id=2, x0=-2, name='left')
        right = openmc.XPlane(surface_id=3, x0=2, name='right')
        bottom = openmc.YPlane(y0=-2, name='bottom')
        top = openmc.YPlane(y0=2, name='top')

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

        # Instantiate Cells
        fuel = openmc.Cell(name='fuel')
        water = openmc.Cell(name='water')

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

        # Register Materials with Cells
        fuel.fill = uo2
        water.fill = borated_water

        # Instantiate pin cell Universe
        pin_cell = openmc.Universe(name='pin cell')
        pin_cell.add_cells([fuel, water])

        # Instantiate root Cell and Universe
        root_cell = openmc.Cell(name='root cell')
        root_cell.region = +left & -right & +bottom & -top
        root_cell.fill = pin_cell
        root_univ = openmc.Universe(universe_id=0, name='root universe')
        root_univ.add_cell(root_cell)

        # Instantiate a Geometry, register the root Universe
        geometry = openmc.Geometry(root_univ)
        geometry.export_to_xml()

        # Instantiate a Settings object, set all runtime parameters
        settings_file = openmc.Settings()
        settings_file.batches = 10
        settings_file.inactive = 0
        settings_file.particles = 1000
        #settings_file.output = {'tallies': True}

        # Create an initial uniform spatial source distribution
        bounds = [-0.62992, -0.62992, -1, 0.62992, 0.62992, 1]
        uniform_dist = openmc.stats.Box(bounds[:3], bounds[3:],\
             only_fissionable=True)
        settings_file.source = openmc.source.Source(space=uniform_dist)
        settings_file.export_to_xml()

        # Tallies file
        tallies_file = openmc.Tallies()

        # Create partial current tallies from fuel to water
        # Filters
        two_groups = [0., 4e6, 20e6]
        energy_filter = openmc.EnergyFilter(two_groups)
        polar_filter = openmc.PolarFilter([0, np.pi / 4, np.pi])
        azimuthal_filter = openmc.AzimuthalFilter([0, np.pi / 4, np.pi])
        surface_filter = openmc.SurfaceFilter([1])
        cell_from_filter = openmc.CellFromFilter(fuel)
        cell_filter = openmc.CellFilter(water)

        # Use Cell to cell filters for partial current
        cell_to_cell_tally = openmc.Tally(name=str('fuel_to_water_1'))
        cell_to_cell_tally.filters = [cell_from_filter, cell_filter, \
             energy_filter, polar_filter, azimuthal_filter]
        cell_to_cell_tally.scores = ['current']
        tallies_file.append(cell_to_cell_tally)

        # Use a Cell from + surface filters for partial current
        cell_to_cell_tally = openmc.Tally(name=str('fuel_to_water_2'))
        cell_to_cell_tally.filters = [cell_from_filter, surface_filter, \
             energy_filter, polar_filter, azimuthal_filter]
        cell_to_cell_tally.scores = ['current']
        tallies_file.append(cell_to_cell_tally)

        # Create partial current tallies from water to fuel
        # Filters
        cell_from_filter = openmc.CellFromFilter(water)
        cell_filter = openmc.CellFilter(fuel)

        # Cell to cell filters for partial current
        cell_to_cell_tally = openmc.Tally(name=str('water_to_fuel_1'))
        cell_to_cell_tally.filters = [cell_from_filter, cell_filter, \
             energy_filter, polar_filter, azimuthal_filter]
        cell_to_cell_tally.scores = ['current']
        tallies_file.append(cell_to_cell_tally)

        # Cell from + surface filters for partial current
        cell_to_cell_tally = openmc.Tally(name=str('water_to_fuel_2'))
        cell_to_cell_tally.filters = [cell_from_filter, surface_filter, \
             energy_filter, polar_filter, azimuthal_filter]
        cell_to_cell_tally.scores = ['current']
        tallies_file.append(cell_to_cell_tally)

        # Create a net current tally on inner surface using a surface filter
        surface_filter = openmc.SurfaceFilter([1])
        surf_tally1 = openmc.Tally(name='net_cylinder')
        surf_tally1.filters = [surface_filter, energy_filter, polar_filter, \
             azimuthal_filter]
        surf_tally1.scores = ['current']
        tallies_file.append(surf_tally1)

        # Create a net current tally on left surface using a surface filter
        # This surface has a vacuum boundary condition, so leakage is tallied
        surface_filter = openmc.SurfaceFilter([2])
        surf_tally2 = openmc.Tally(name='leakage_left')
        surf_tally2.filters = [surface_filter, energy_filter, polar_filter, \
            azimuthal_filter]
        surf_tally2.scores = ['current']
        tallies_file.append(surf_tally2)

        # Create a net current tally on right surface using a surface filter
        # This surface has a reflective boundary condition, but the zero
        # net current is not picked up because particles are only tallied once
        surface_filter = openmc.SurfaceFilter([3])
        surf_tally3 = openmc.Tally(name='net_right')
        surf_tally3.filters = [surface_filter, energy_filter]
        surf_tally3.scores = ['current']
        tallies_file.append(surf_tally3)

        surface_filter = openmc.SurfaceFilter([3])
        surf_tally3 = openmc.Tally(name='net_right')
        surf_tally3.filters = [surface_filter, energy_filter]
        surf_tally3.scores = ['current']
        tallies_file.append(surf_tally3)

        tallies_file.export_to_xml()
Ejemplo n.º 27
0
def test_export_to_xml(run_in_tmpdir):
    s = openmc.Settings()
    s.run_mode = 'fixed source'
    s.batches = 1000
    s.generations_per_batch = 10
    s.inactive = 100
    s.particles = 1000000
    s.max_lost_particles = 5
    s.rel_max_lost_particles = 1e-4
    s.keff_trigger = {'type': 'std_dev', 'threshold': 0.001}
    s.energy_mode = 'continuous-energy'
    s.max_order = 5
    s.source = openmc.Source(space=openmc.stats.Point())
    s.output = {'summary': True, 'tallies': False, 'path': 'here'}
    s.verbosity = 7
    s.sourcepoint = {
        'batches': [50, 150, 500, 1000],
        'separate': True,
        'write': True,
        'overwrite': True
    }
    s.statepoint = {'batches': [50, 150, 500, 1000]}
    s.surf_source_read = {'path': 'surface_source_1.h5'}
    s.surf_source_write = {'surface_ids': [2], 'max_particles': 200}
    s.confidence_intervals = True
    s.ptables = True
    s.seed = 17
    s.survival_biasing = True
    s.cutoff = {
        'weight': 0.25,
        'weight_avg': 0.5,
        'energy_neutron': 1.0e-5,
        'energy_photon': 1000.0,
        'energy_electron': 1.0e-5,
        'energy_positron': 1.0e-5
    }
    mesh = openmc.RegularMesh()
    mesh.lower_left = (-10., -10., -10.)
    mesh.upper_right = (10., 10., 10.)
    mesh.dimension = (5, 5, 5)
    s.entropy_mesh = mesh
    s.trigger_active = True
    s.trigger_max_batches = 10000
    s.trigger_batch_interval = 50
    s.no_reduce = False
    s.tabular_legendre = {'enable': True, 'num_points': 50}
    s.temperature = {
        'default': 293.6,
        'method': 'interpolation',
        'multipole': True,
        'range': (200., 1000.)
    }
    s.trace = (10, 1, 20)
    s.track = [1, 1, 1, 2, 1, 1]
    s.ufs_mesh = mesh
    s.resonance_scattering = {
        'enable': True,
        'method': 'rvs',
        'energy_min': 1.0,
        'energy_max': 1000.0,
        'nuclides': ['U235', 'U238', 'Pu239']
    }
    s.volume_calculations = openmc.VolumeCalculation(domains=[openmc.Cell()],
                                                     samples=1000,
                                                     lower_left=(-10., -10.,
                                                                 -10.),
                                                     upper_right=(10., 10.,
                                                                  10.))
    s.create_fission_neutrons = True
    s.log_grid_bins = 2000
    s.photon_transport = False
    s.electron_treatment = 'led'
    s.dagmc = False

    # Make sure exporting XML works
    s.export_to_xml()

    # Generate settings from XML
    s = openmc.Settings.from_xml()
    assert s.run_mode == 'fixed source'
    assert s.batches == 1000
    assert s.generations_per_batch == 10
    assert s.inactive == 100
    assert s.particles == 1000000
    assert s.max_lost_particles == 5
    assert s.rel_max_lost_particles == 1e-4
    assert s.keff_trigger == {'type': 'std_dev', 'threshold': 0.001}
    assert s.energy_mode == 'continuous-energy'
    assert s.max_order == 5
    assert isinstance(s.source[0], openmc.Source)
    assert isinstance(s.source[0].space, openmc.stats.Point)
    assert s.output == {'summary': True, 'tallies': False, 'path': 'here'}
    assert s.verbosity == 7
    assert s.sourcepoint == {
        'batches': [50, 150, 500, 1000],
        'separate': True,
        'write': True,
        'overwrite': True
    }
    assert s.statepoint == {'batches': [50, 150, 500, 1000]}
    assert s.surf_source_read == {'path': 'surface_source_1.h5'}
    assert s.surf_source_write == {'surface_ids': [2], 'max_particles': 200}
    assert s.confidence_intervals
    assert s.ptables
    assert s.seed == 17
    assert s.survival_biasing
    assert s.cutoff == {
        'weight': 0.25,
        'weight_avg': 0.5,
        'energy_neutron': 1.0e-5,
        'energy_photon': 1000.0,
        'energy_electron': 1.0e-5,
        'energy_positron': 1.0e-5
    }
    assert isinstance(s.entropy_mesh, openmc.RegularMesh)
    assert s.entropy_mesh.lower_left == [-10., -10., -10.]
    assert s.entropy_mesh.upper_right == [10., 10., 10.]
    assert s.entropy_mesh.dimension == [5, 5, 5]
    assert s.trigger_active
    assert s.trigger_max_batches == 10000
    assert s.trigger_batch_interval == 50
    assert not s.no_reduce
    assert s.tabular_legendre == {'enable': True, 'num_points': 50}
    assert s.temperature == {
        'default': 293.6,
        'method': 'interpolation',
        'multipole': True,
        'range': [200., 1000.]
    }
    assert s.trace == [10, 1, 20]
    assert s.track == [1, 1, 1, 2, 1, 1]
    assert isinstance(s.ufs_mesh, openmc.RegularMesh)
    assert s.ufs_mesh.lower_left == [-10., -10., -10.]
    assert s.ufs_mesh.upper_right == [10., 10., 10.]
    assert s.ufs_mesh.dimension == [5, 5, 5]
    assert s.resonance_scattering == {
        'enable': True,
        'method': 'rvs',
        'energy_min': 1.0,
        'energy_max': 1000.0,
        'nuclides': ['U235', 'U238', 'Pu239']
    }
    assert s.create_fission_neutrons
    assert s.log_grid_bins == 2000
    assert not s.photon_transport
    assert s.electron_treatment == 'led'
    assert not s.dagmc
def make_materials_geometry_tallies(enrichment_fraction_list,
                                    batches=2,
                                    inner_radius=500,
                                    thickness=100,
                                    breeder_material_name='Li',
                                    temperature_in_C=500):
    if isinstance(enrichment_fraction_list, list):
        enrichment_fraction = enrichment_fraction_list[0]
    else:
        enrichment_fraction = enrichment_fraction_list
    print('simulating ', batches, enrichment_fraction, inner_radius, thickness,
          breeder_material_name)

    #MATERIALS#

    breeder_material = make_breeder_material(enrichment_fraction,
                                             breeder_material_name,
                                             temperature_in_C)
    eurofer = make_eurofer()
    mats = openmc.Materials([breeder_material, eurofer])

    #GEOMETRY#

    breeder_blanket_inner_surface = openmc.Sphere(R=inner_radius)
    breeder_blanket_outer_surface = openmc.Sphere(R=inner_radius + thickness)

    vessel_inner_surface = openmc.Sphere(R=inner_radius + thickness + 10)
    vessel_outer_surface = openmc.Sphere(R=inner_radius + thickness + 20,
                                         boundary_type='vacuum')

    breeder_blanket_region = -breeder_blanket_outer_surface & +breeder_blanket_inner_surface
    breeder_blanket_cell = openmc.Cell(region=breeder_blanket_region)
    breeder_blanket_cell.fill = breeder_material
    breeder_blanket_cell.name = 'breeder_blanket'

    inner_void_region = -breeder_blanket_inner_surface
    inner_void_cell = openmc.Cell(region=inner_void_region)
    inner_void_cell.name = 'inner_void'

    vessel_region = +vessel_inner_surface & -vessel_outer_surface
    vessel_cell = openmc.Cell(region=vessel_region)
    vessel_cell.name = 'vessel'
    vessel_cell.fill = eurofer

    blanket_vessel_gap_region = -vessel_inner_surface & +breeder_blanket_outer_surface
    blanket_vessel_gap_cell = openmc.Cell(region=blanket_vessel_gap_region)
    blanket_vessel_gap_cell.name = 'blanket_vessel_gap'

    universe = openmc.Universe(cells=[
        inner_void_cell, breeder_blanket_cell, blanket_vessel_gap_cell,
        vessel_cell
    ])

    geom = openmc.Geometry(universe)

    #SIMULATION SETTINGS#

    sett = openmc.Settings()
    # batches = 3 # this is parsed as an argument
    sett.batches = batches
    sett.inactive = 10
    sett.particles = 500
    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.Muir(
        e0=14080000.0, m_rat=5.0, kt=20000.0
    )  #neutron energy = 14.08MeV, AMU for D + T = 5, temperature is 20KeV
    sett.source = source

    #TALLIES#

    tallies = openmc.Tallies()

    # define filters
    cell_filter_breeder = openmc.CellFilter(breeder_blanket_cell)
    cell_filter_vessel = openmc.CellFilter(vessel_cell)
    particle_filter = openmc.ParticleFilter([1])  #1 is neutron, 2 is photon
    surface_filter_rear_blanket = openmc.SurfaceFilter(
        breeder_blanket_outer_surface)
    surface_filter_rear_vessel = openmc.SurfaceFilter(vessel_outer_surface)
    energy_bins = openmc.mgxs.GROUP_STRUCTURES['VITAMIN-J-175']
    energy_filter = openmc.EnergyFilter(energy_bins)

    tally = openmc.Tally(name='TBR')
    tally.filters = [cell_filter_breeder, particle_filter]
    tally.scores = ['205']
    tallies.append(tally)

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

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

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

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

    tally = openmc.Tally(name='DPA')
    tally.filters = [cell_filter_vessel, particle_filter]
    tally.scores = ['444']
    tallies.append(tally)

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

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

    json_output = {
        'enrichment_fraction': enrichment_fraction,
        'inner_radius': inner_radius,
        'thickness': thickness,
        'breeder_material_name': breeder_material_name,
        'temperature_in_C': temperature_in_C
    }

    tallies_to_retrieve = ['TBR', 'DPA', 'blanket_leakage', 'vessel_leakage']
    for tally_name in tallies_to_retrieve:
        tally = sp.get_tally(name=tally_name)
        # for some reason the tally sum is a nested list
        tally_result = tally.sum[0][0][0] / batches
        # for some reason the tally std_dev is a nested list
        tally_std_dev = tally.std_dev[0][0][0] / batches

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

    spectra_tallies_to_retrieve = [
        'breeder_blanket_spectra', 'vacuum_vessel_spectra'
    ]
    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
        ]

        json_output[spectra_name] = {
            'value': spectra_tally_result,
            'std_dev': spectra_tally_std_dev,
            'energy_groups': list(energy_bins)
        }

    return json_output
Ejemplo n.º 29
0
u = universes['UO2 Unrodded Assembly']
m = universes['MOX Unrodded Assembly']
lattices['Core'].universes = [[u, m, w], [m, u, w], [w, w, w]]
cells['Core'].fill = lattices['Core']

# Instantiate a Geometry, register the root Universe, and export to XML
geometry = openmc.Geometry()
geometry.root_universe = universes['Root']
geometry.export_to_xml()

###############################################################################
#                   Exporting to OpenMC settings.xml File
###############################################################################

# Instantiate a Settings, set all runtime parameters, and export to XML
settings_file = openmc.Settings()
settings_file.energy_mode = "multi-group"
settings_file.cross_sections = "./mgxs.xml"
settings_file.batches = batches
settings_file.inactive = inactive
settings_file.particles = particles
settings_file.output = {'tallies': True, 'summary': True}
settings_file.source = openmc.Source(space=openmc.stats.Box(
    [-32.13, -10.71, -1.0], [10.71, 32.13, 1.0], only_fissionable=True))
settings_file.entropy_lower_left = [-32.13, -32.13, -1.E50]
settings_file.entropy_upper_right = [32.13, 32.13, 1.E50]
settings_file.entropy_dimension = [51, 51, 1]
settings_file.export_to_xml()

###############################################################################
#                   Exporting to OpenMC plots.xml File
Ejemplo n.º 30
0
    h_cell = openmc.Cell(fill=lattice, region=h_box)

    domain = openmc.model.rectangular_prism(width=1000,
                                            height=1000,
                                            origin=(0., 0., 0.),
                                            boundary_type='vacuum')

    domain_box = domain & -ceil & +floor & ~h_box

    domain_cell = openmc.Cell(region=domain_box, fill=water)

    model = openmc.model.Model()
    model.geometry = openmc.Geometry([h_cell, domain_cell])

    point = openmc.stats.Point((0, 0, 0))
    settings = openmc.Settings()
    src = openmc.Source(space=point, particle="photon")
    src.angle = openmc.stats.Isotropic()
    src.energy = openmc.stats.Discrete([1e6], [1.])

    settings = openmc.Settings()
    settings.run_mode = "fixed source"
    settings.batches = 10
    settings.inactive = 2
    settings.particles = 100000
    settings.photon_transport = True

    settings.source = [src]

    model.settings = settings