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
def make_materials_geometry_tallies(batches, 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_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
sett = openmc.Settings()
batches = 2
sett.batches = batches
sett.inactive = 0
sett.particles = 7000
sett.run_mode = 'fixed source'

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

# setup the tallies
tallies = openmc.Tallies()

neutron_particle_filter = openmc.ParticleFilter(['neutron'])
cell_filter = openmc.CellFilter(breeder_blanket_cell)
cell_filter_fw = openmc.CellFilter(first_wall_cell)
energy_bins = openmc.mgxs.GROUP_STRUCTURES['VITAMIN-J-175']
energy_filter = openmc.EnergyFilter(energy_bins)

spectra_tally = openmc.Tally(3, name='breeder_blanket_spectra')
spectra_tally.filters = [cell_filter, neutron_particle_filter, energy_filter]
spectra_tally.scores = ['flux']
tallies.append(spectra_tally)

spectra_tally = openmc.Tally(4, name='first_wall_spectra')
spectra_tally.filters = [
    cell_filter_fw, neutron_particle_filter, energy_filter
Example #4
0
#                   Exporting to OpenMC plots.xml File
###############################################################################

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

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

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

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

# Instantiate a Tallies collection and export to XML
tallies_file = openmc.Tallies(tallies.values())
tallies_file.export_to_xml()
Example #5
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')
Example #6
0
mats = openmc.Materials([iron])
mats.export_to_xml()

# Create a 5 cm x 5 cm box filled with iron
box = openmc.model.rectangular_prism(10.0, 10.0, boundary_type='vacuum')
cell = openmc.Cell(fill=iron, region=box)
geometry = openmc.Geometry([cell])
geometry.export_to_xml()

# Tell OpenMC we're going to use our custom source
settings = openmc.Settings()
settings.run_mode = 'fixed source'
settings.batches = 10
settings.particles = 1000
source = openmc.Source()
source.library = 'build/libsource.so'
settings.source = source
settings.export_to_xml()

# Finally, define a mesh tally so that we can see the resulting flux
mesh = openmc.RegularMesh()
mesh.lower_left = (-5.0, -5.0)
mesh.upper_right = (5.0, 5.0)
mesh.dimension = (50, 50)

tally = openmc.Tally()
tally.filters = [openmc.MeshFilter(mesh)]
tally.scores = ['flux']
tallies = openmc.Tallies([tally])
tallies.export_to_xml()
###############################################################################
#                   Exporting to OpenMC tallies.xml file
###############################################################################

# Instantiate some tally Filters
cell_filter = openmc.CellFilter(cell2)
energy_filter = openmc.EnergyFilter([0., 20.e6])
energyout_filter = openmc.EnergyoutFilter([0., 20.e6])

# Instantiate the first Tally
first_tally = openmc.Tally(tally_id=1, name='first tally')
first_tally.filters = [cell_filter]
scores = ['total', 'scatter', 'nu-scatter',
          'absorption', 'fission', 'nu-fission']
first_tally.scores = scores

# Instantiate the second Tally
second_tally = openmc.Tally(tally_id=2, name='second tally')
second_tally.filters = [cell_filter, energy_filter]
second_tally.scores = scores

# Instantiate the third Tally
third_tally = openmc.Tally(tally_id=3, name='third tally')
third_tally.filters = [cell_filter, energy_filter, energyout_filter]
third_tally.scores = ['scatter', 'nu-scatter', 'nu-fission']

# Instantiate a Tallies collection and export to XML
tallies_file = openmc.Tallies((first_tally, second_tally, third_tally))
tallies_file.export_to_xml()
Example #8
0
g.root_universe = root
g.export_to_xml()

# data/control section
settings = openmc.Settings()
settings.run_mode = 'fixed source'

settings.batches = 50
# even for fixed source problems you need batches
settings.particles = 10000

source = openmc.Source()
source.particle = 'neutron'
source.space = openmc.stats.Point(xyz=(0., 0., 0.))
# default is the origin
source.angle = openmc.stats.Isotropic()
source.energy = openmc.stats.Discrete([1.0e6], [1.0])
settings.source = source

settings.export_to_xml()

t = openmc.Tally(name='sphere')
s_filter = openmc.SurfaceFilter(sphere.id)
t.filters = [s_filter]
t.scores = ['flux']

tallies = openmc.Tallies([t])
tallies.export_to_xml()

openmc.run()
Example #9
0
    settings.source = [src]

    model.settings = settings

    detector_cells = detectors_tallies(h_cell)

    print(detector_cells)

    tallies_list = []

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

    tally.scores = ['flux']

    tallies_list.append(tally)

    model.tallies = openmc.Tallies(tallies_list)

    model.export_to_xml()

    ph = horizontal_section()

    pv = vertical_section()

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

    openmc.plot_geometry()
    openmc.run()
Example #10
0
def tallies_generation(root):
    """ Creates tallies.xml file

    Parameters
    ----------
    root: openmc.Universe with all the relevant cells for the geometry.

    Returns
    -------
    This function generates the tallies.xml file.
    """
    tallies_file = openmc.Tallies()
    # phase1a-b
    energy_filter_b = openmc.EnergyFilter([1e-6, 20.0e6])
    mesh_b = openmc.RegularMesh(mesh_id=16)
    mesh_b.dimension = [1, 1]
    L = 27.02
    mesh_b.lower_left = [-L, -L]
    mesh_b.upper_right = [L, L]
    mesh_filter_b = openmc.MeshFilter(mesh_b)
    tally_b = openmc.Tally(name='mesh tally b')
    tally_b.filters = [mesh_filter_b, energy_filter_b]
    tally_b.scores = ['delayed-nu-fission', 'nu-fission']
    tallies_file.append(tally_b)
    # phase1a-c
    mesh_no = 0
    for t in range(6):
        mesh_no += 1
        for x in range(2):
            x_trans = t * T['A1']['P']['x']
            y_trans = t * T['A1']['P']['y']
            if x == 1:
                mesh_no += 1
                x_trans += T['A1']['F']['x']
                y_trans += T['A1']['F']['y']
            mesh_c = openmc.RegularMesh(mesh_id=mesh_no)
            mesh_c.dimension = [1, 5]
            mesh_c.lower_left = [
                V['A1']['F']['L']['x'] + x_trans,
                V['A1']['F']['B']['y'] + y_trans
            ]
            mesh_c.upper_right = [
                V['A1']['F']['R']['x'] + x_trans,
                V['A1']['F']['T']['y'] + y_trans
            ]
            mesh_filter_c = openmc.MeshFilter(mesh_c)
            tally_c = openmc.Tally(name='mesh tally c' + str(mesh_no))
            tally_c.filters = [mesh_filter_c]
            tally_c.scores = ['fission']
            tallies_file.append(tally_c)
    # phase 1a-d
    energy_filter_d = openmc.EnergyFilter([1e-5, 3, 1.0e5, 20.0e6])
    mesh_d = openmc.RegularMesh(mesh_id=13)
    mesh_d.dimension = [1, 1]
    L = 27.02
    mesh_d.lower_left = [-L, -L]
    mesh_d.upper_right = [L, L]
    mesh_filter_d = openmc.MeshFilter(mesh_d)
    tally_d = openmc.Tally(name='mesh tally d')
    tally_d.filters = [mesh_filter_d, energy_filter_d]
    tally_d.scores = ['flux', 'nu-fission', 'fission']
    tallies_file.append(tally_d)
    # phase 1a-e
    energy_filter_e = openmc.EnergyFilter([1e-5, 3, 0.1e6, 20.0e6])
    mesh_e = openmc.RegularMesh(mesh_id=14)
    mesh_e.dimension = [100, 100]
    L = 27.02
    mesh_e.lower_left = [-L, -L]
    mesh_e.upper_right = [L, L]
    mesh_filter_e = openmc.MeshFilter(mesh_e)
    tally_e = openmc.Tally(name='mesh tally e')
    tally_e.filters = [mesh_filter_e, energy_filter_e]
    tally_e.scores = ['flux', 'nu-fission', 'fission']
    tallies_file.append(tally_e)
    # phase 1a-f
    energy_filter_f = openmc.EnergyFilter(engs)
    mesh_f = openmc.RegularMesh(mesh_id=15)
    mesh_f.dimension = [1, 1]
    L = 27.02
    mesh_f.lower_left = [-L, -L]
    mesh_f.upper_right = [L, L]
    mesh_filter_f = openmc.MeshFilter(mesh_f)
    tally_f = openmc.Tally(name='mesh tally f')
    tally_f.filters = [mesh_filter_f, energy_filter_f]
    tally_f.scores = ['flux', 'nu-fission', 'fission']
    tallies_file.append(tally_f)

    tallies_file.export_to_xml()
    return
Example #11
0
plot_file.export_to_xml()

###############################################################################
#                        Create OpenMC MGXS Library
###############################################################################

# Instantiate a 1-group EnergyGroups object
groups = openmc.mgxs.EnergyGroups()
groups.group_edges = [0., 20e6]

# Initialize an MGXS Library for OpenMOC
mgxs_lib = openmc.mgxs.Library(openmc_geometry, by_nuclide=False)
mgxs_lib.energy_groups = groups
mgxs_lib.mgxs_types = ['total', 'nu-fission', 'nu-scatter matrix', 'chi']
mgxs_lib.domain_type = 'cell'
mgxs_lib.correction = None
mgxs_lib.domains = openmc_geometry.get_all_material_cells().values()
mgxs_lib.build_library()

# Create a "tallies.xml" file for the MGXS Library
tallies_file = openmc.Tallies()
mgxs_lib.add_to_tallies_file(tallies_file, merge=True)
tallies_file.export_to_xml()

###############################################################################
#                         Run OpenMC Simulation
###############################################################################

# Run OpenMC
openmc.run()