Exemple #1
0
def mixed_lattice_model(uo2, water):
    cyl = openmc.ZCylinder(r=0.4)
    c1 = openmc.Cell(fill=uo2, region=-cyl)
    c1.temperature = 600.0
    c2 = openmc.Cell(fill=water, region=+cyl)
    pin = openmc.Universe(cells=[c1, c2])

    empty = openmc.Cell()
    empty_univ = openmc.Universe(cells=[empty])

    hex_lattice = openmc.HexLattice()
    hex_lattice.center = (0.0, 0.0)
    hex_lattice.pitch = (1.2, 10.0)
    outer_ring = [pin]*6
    inner_ring = [empty_univ]
    axial_level = [outer_ring, inner_ring]
    hex_lattice.universes = [axial_level]*3
    hex_lattice.outer = empty_univ

    cell_hex = openmc.Cell(fill=hex_lattice)
    u = openmc.Universe(cells=[cell_hex])
    rotated_cell_hex = openmc.Cell(fill=u)
    rotated_cell_hex.rotation = (0., 0., 30.)
    ur = openmc.Universe(cells=[rotated_cell_hex])

    d = 6.0
    rect_lattice = openmc.RectLattice()
    rect_lattice.lower_left = (-d, -d)
    rect_lattice.pitch = (d, d)
    rect_lattice.outer = empty_univ
    rect_lattice.universes = [
        [ur, empty_univ],
        [empty_univ, u]
    ]

    xmin = openmc.XPlane(-d, boundary_type='periodic')
    xmax = openmc.XPlane(d, boundary_type='periodic')
    xmin.periodic_surface = xmax
    ymin = openmc.YPlane(-d, boundary_type='periodic')
    ymax = openmc.YPlane(d, boundary_type='periodic')
    main_cell = openmc.Cell(fill=rect_lattice,
                            region=+xmin & -xmax & +ymin & -ymax)

    # Create geometry and use unique material in each fuel cell
    geometry = openmc.Geometry([main_cell])
    geometry.determine_paths()
    c1.fill = [water.clone() for i in range(c1.num_instances)]

    return openmc.model.Model(geometry)
def test_get_by_name():
    m1 = openmc.Material(name='zircaloy')
    m1.add_element('Zr', 1.0)
    m2 = openmc.Material(name='Zirconium')
    m2.add_element('Zr', 1.0)

    c1 = openmc.Cell(fill=m1, name='cell1')
    u1 = openmc.Universe(name='Zircaloy universe', cells=[c1])

    cyl = openmc.ZCylinder()
    c2 = openmc.Cell(fill=u1, region=-cyl, name='cell2')
    c3 = openmc.Cell(fill=m2, region=+cyl, name='Cell3')
    root = openmc.Universe(name='root Universe', cells=[c2, c3])
    geom = openmc.Geometry(root)

    mats = set(geom.get_materials_by_name('zirc'))
    assert not mats ^ {m1, m2}
    mats = set(geom.get_materials_by_name('zirc', True))
    assert not mats ^ {m1}
    mats = set(geom.get_materials_by_name('zirconium', False, True))
    assert not mats ^ {m2}
    mats = geom.get_materials_by_name('zirconium', True, True)
    assert not mats

    cells = set(geom.get_cells_by_name('cell'))
    assert not cells ^ {c1, c2, c3}
    cells = set(geom.get_cells_by_name('cell', True))
    assert not cells ^ {c1, c2}
    cells = set(geom.get_cells_by_name('cell3', False, True))
    assert not cells ^ {c3}
    cells = geom.get_cells_by_name('cell3', True, True)
    assert not cells

    cells = set(geom.get_cells_by_fill_name('Zircaloy'))
    assert not cells ^ {c1, c2}
    cells = set(geom.get_cells_by_fill_name('Zircaloy', True))
    assert not cells ^ {c2}
    cells = set(geom.get_cells_by_fill_name('Zircaloy', False, True))
    assert not cells ^ {c1}
    cells = geom.get_cells_by_fill_name('Zircaloy', True, True)
    assert not cells

    univs = set(geom.get_universes_by_name('universe'))
    assert not univs ^ {u1, root}
    univs = set(geom.get_universes_by_name('universe', True))
    assert not univs ^ {u1}
    univs = set(geom.get_universes_by_name('universe', True, True))
    assert not univs
Exemple #3
0
def _make_outer_mg_universe(outmat):
    cell = openmc.Cell(cell_id=100000)
    univ = openmc.Universe(universe_id=100000)
    cell.fill = outmat
    univ.add_cell(cell)
    outsurface = openmc.ZCylinder(R=175.25, name='Reactor preasure vessel out', boundary_type = 'vacuum')
    return univ, outsurface
Exemple #4
0
def materials(tmpdir_factory):
    """Use C API to construct realistic materials for testing tallies"""
    tmpdir = tmpdir_factory.mktemp("lib")
    orig = tmpdir.chdir()
    # Create proxy problem to please openmc
    mfuel = openmc.Material(name="test_fuel")
    mfuel.volume = 1.0
    for nuclide in ["U235", "U238", "Xe135", "Pu239"]:
        mfuel.add_nuclide(nuclide, 1.0)
    openmc.Materials([mfuel]).export_to_xml()
    # Geometry
    box = openmc.rectangular_prism(1.0, 1.0, boundary_type="reflective")
    cell = openmc.Cell(fill=mfuel, region=box)
    root = openmc.Universe(cells=[cell])
    openmc.Geometry(root).export_to_xml()
    # settings
    settings = openmc.Settings()
    settings.particles = 100
    settings.inactive = 0
    settings.batches = 10
    settings.verbosity = 1
    settings.export_to_xml()

    try:
        with lib.run_in_memory():
            yield [lib.Material(), lib.Material()]
    finally:
        # Convert to strings as os.remove in py 3.5 doesn't support Paths
        for file_path in ("settings.xml", "geometry.xml", "materials.xml",
                          "summary.h5"):
            os.remove(str(tmpdir / file_path))
        orig.chdir()
        os.rmdir(str(tmpdir))
Exemple #5
0
def test_transfer_volumes(run_in_tmpdir):
    """Unit test of volume transfer in restart calculations."""

    op = dummy_operator.DummyOperator()
    op.output_dir = "test_transfer_volumes"

    # Perform simulation using the predictor algorithm
    dt = [0.75]
    power = 1.0
    PredictorIntegrator(op, dt, power).integrate()

    # Load the files
    res = openmc.deplete.ResultsList.from_hdf5(op.output_dir /
                                               "depletion_results.h5")

    # Create a dictionary of volumes to transfer
    res[0].volume['1'] = 1.5
    res[0].volume['2'] = 2.5

    # Create dummy geometry
    mat1 = openmc.Material(material_id=1)
    mat1.depletable = True
    mat2 = openmc.Material(material_id=2)

    cell = openmc.Cell()
    cell.fill = [mat1, mat2]
    root = openmc.Universe()
    root.add_cell(cell)
    geometry = openmc.Geometry(root)

    # Transfer volumes
    res[0].transfer_volumes(openmc.Model(geometry))

    assert mat1.volume == 1.5
    assert mat2.volume is None
Exemple #6
0
    def _add_dummy_universe(self):
        """ Adds all-water universe for empty lattice positions"""

        self.u_waterPin = openmc.Universe(name='Dummy Water Universe')
        self.c_water = openmc.Cell(name='Water',
                                   fill=self.mats['Borated Water'])
        self.u_waterPin.add_cells([self.c_water])
Exemple #7
0
def buildTriangUni(modSetting,pitch,diameter,boron,modT,fuelT,DyFrac,enrich):
    uo2=getU(fuelT,DyFrac,enrich)
    mod=getMod(modSetting,boron,modT) #loads the moderator
    mats = openmc.Materials([uo2, mod])
    mats.export_to_xml()
       
    ####################build the surfaces################################
    fuel_or1 = openmc.ZCylinder(R=diameter/2)
    box = openmc.get_hexagonal_prism(edge_length=pitch/math.sqrt(3.0),boundary_type='reflective')
        
    #################Build the Cells #######################################
    fuel_region = -fuel_or1   #beautiful abuse of operator overloading
    mod_region = box & +fuel_or1
    # c
    # c Fuel 
    # c
    # c throwback to MCNP
    fuel = openmc.Cell(1, 'fuel')
    fuel.fill = uo2
    fuel.region = fuel_region
    #
    # Moderator 
    #
    moderator = openmc.Cell(4, 'moderator')
    moderator.fill = mod
    moderator.region = mod_region
       
    #I am groot!
    groot = openmc.Universe(cells=(fuel, moderator))
    geom = openmc.Geometry(groot)
    geom.export_to_xml()
    cell_filter = openmc.CellFilter([fuel, moderator])
    # tallies
    buildTallies(cell_filter)
    return (fuel,moderator)
Exemple #8
0
def uo2_trigger_model():
    """Set up a simple UO2 model with k-eff trigger"""
    model = openmc.model.Model()
    m = openmc.Material(name='UO2')
    m.add_nuclide('U235', 1.0)
    m.add_nuclide('O16', 2.0)
    m.set_density('g/cm3', 10.0)
    model.materials.append(m)

    cyl = openmc.ZCylinder(r=1.0, boundary_type='vacuum')
    c = openmc.Cell(fill=m, region=-cyl)
    model.geometry.root_universe = openmc.Universe(cells=[c])

    model.settings.batches = 10
    model.settings.inactive = 5
    model.settings.particles = 100
    model.settings.source = openmc.Source(space=openmc.stats.Box(
        [-0.5, -0.5, -1], [0.5, 0.5, 1], only_fissionable=True))
    model.settings.verbosity = 1
    model.settings.keff_trigger = {'type': 'std_dev', 'threshold': 0.001}
    model.settings.trigger_active = True
    model.settings.trigger_max_batches = 10
    model.settings.trigger_batch_interval = 1

    # Write XML files in tmpdir
    with cdtemp():
        model.export_to_xml()
        yield
Exemple #9
0
def test_volume(uo2):
    """Test adding volume information from a volume calculation."""
    # Create model with nested spheres
    model = openmc.model.Model()
    model.materials.append(uo2)
    inner = openmc.Sphere(R=1.)
    outer = openmc.Sphere(R=2., boundary_type='vacuum')
    c1 = openmc.Cell(fill=uo2, region=-inner)
    c2 = openmc.Cell(region=+inner & -outer)
    u = openmc.Universe(cells=[c1, c2])
    model.geometry.root_universe = u
    model.settings.particles = 100
    model.settings.batches = 10
    model.settings.run_mode = 'fixed source'
    model.settings.source = openmc.Source(space=openmc.stats.Point())

    ll, ur = model.geometry.bounding_box
    
    model.settings.volume_calculations

    for domain in (c1, uo2, u):
        # Run stochastic volume calculation
        volume_calc = openmc.VolumeCalculation(
            domains=[domain], samples=1000, lower_left=ll, upper_right=ur)
        model.settings.volume_calculations = [volume_calc]
        model.export_to_xml()
        openmc.calculate_volumes()

        # Load results and add volume information
        volume_calc.load_results('volume_1.h5')
        model.geometry.add_volume_information(volume_calc)

        # get_nuclide_densities relies on volume information
        nucs = set(domain.get_nuclide_densities())
Exemple #10
0
    def build_default_materials_and_geometry(self):
        # Define materials needed for 1D/1G slab problem
        uo2_data = openmc.Macroscopic('uo2_iso', '71c')
        uo2 = openmc.Material(name='UO2', material_id=1)
        uo2.set_density('macro', 1.0)
        uo2.add_macroscopic(uo2_data)

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

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

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

        # Define surfaces.

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

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

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

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

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

        # Assign root universe to geometry
        self.geometry.root_universe = root
Exemple #11
0
    def _read_universes(self):
        self.n_universes = self._f['geometry/n_universes'].value

        # Initialize dictionary for each Universe
        # Keys     - Universe keys
        # Values   - Universe objects
        self.universes = {}

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

            universe_id = int(key.lstrip('universe '))
            index = self._f['geometry/universes'][key]['index'].value
            cells = self._f['geometry/universes'][key]['cells'][...]

            # Create this Universe
            universe = openmc.Universe(universe_id=universe_id)

            # Add each Cell to the Universe
            for cell_id in cells:
                cell = self.cells[cell_id]
                universe.add_cell(cell)

            # Add the Universe to the global list of Universes
            self.universes[index] = universe
Exemple #12
0
 def build(self):
     # All cylinders
     fcyl = openmc.ZCylinder(R=self.rfuel, name="Fuel Cylinder")
     gcyl = openmc.ZCylinder(R=self.rgap, name="Gap Cylinder")
     ccyl = openmc.ZCylinder(R=self.rclad, name="Clad Cylinder")
     # Innermost ring: plain fuel
     fring = openmc.Cell()
     fring.region = -fcyl
     fring.fill = self.fuel_mat
     # Next ring: gap
     gring = openmc.Cell()
     gring.region = +fcyl & -gcyl
     gring.fill = self.gap_mat  # probably void
     # Next ring: clad
     cring = openmc.Cell()
     cring.region = +gcyl & -ccyl
     cring.fill = self.clad_mat
     # Outside: moderator
     moderator = openmc.Cell()
     moderator.region = +ccyl
     moderator.fill = self.mod_mat
     # Finalize
     pincell_universe = openmc.Universe(name="Pincell")
     pincell_universe.add_cells((fring, gring, cring, moderator))
     return pincell_universe
Exemple #13
0
def test_fixed_source():
    mat = openmc.Material()
    mat.add_nuclide('O16', 1.0)
    mat.add_nuclide('U238', 0.0001)
    mat.set_density('g/cc', 7.5)

    surf = openmc.Sphere(r=10.0, boundary_type='vacuum')
    cell = openmc.Cell(fill=mat, region=-surf)

    model = openmc.model.Model()
    model.geometry.root_universe = openmc.Universe(cells=[cell])
    model.materials.append(mat)

    model.settings.run_mode = 'fixed source'
    model.settings.batches = 10
    model.settings.particles = 100
    model.settings.temperature = {'default': 294}
    model.settings.source = openmc.Source(space=openmc.stats.Point(),
                                          strength=10.0)

    tally = openmc.Tally()
    tally.scores = ['flux']
    model.tallies.append(tally)

    harness = FixedSourceTestHarness('statepoint.10.h5', model)
    harness.main()
Exemple #14
0
    def _build_inputs(self):
        # Define materials
        water = openmc.Material(1)
        water.add_nuclide('H1', 2.0)
        water.add_nuclide('O16', 1.0)
        water.add_nuclide('B10', 0.0001)
        water.add_s_alpha_beta('c_H_in_H2O')
        water.set_density('g/cc', 1.0)

        fuel = openmc.Material(2)
        fuel.add_nuclide('U235', 1.0)
        fuel.add_nuclide('Mo99', 0.1)
        fuel.set_density('g/cc', 4.5)

        materials = openmc.Materials((water, fuel))
        materials.export_to_xml()

        cyl = openmc.ZCylinder(surface_id=1, r=1.0, boundary_type='vacuum')
        top_sphere = openmc.Sphere(surface_id=2,
                                   z0=5.,
                                   r=1.,
                                   boundary_type='vacuum')
        top_plane = openmc.ZPlane(surface_id=3, z0=5.)
        bottom_sphere = openmc.Sphere(surface_id=4,
                                      z0=-5.,
                                      r=1.,
                                      boundary_type='vacuum')
        bottom_plane = openmc.ZPlane(surface_id=5, z0=-5.)

        # Define geometry
        inside_cyl = openmc.Cell(1,
                                 fill=fuel,
                                 region=-cyl & -top_plane & +bottom_plane)
        top_hemisphere = openmc.Cell(2,
                                     fill=water,
                                     region=-top_sphere & +top_plane)
        bottom_hemisphere = openmc.Cell(3,
                                        fill=water,
                                        region=-bottom_sphere & -top_plane)
        root = openmc.Universe(0,
                               cells=(inside_cyl, top_hemisphere,
                                      bottom_hemisphere))

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

        # Set up stochastic volume calculation
        ll, ur = root.bounding_box
        vol_calcs = [
            openmc.VolumeCalculation(list(root.cells.values()), 100000),
            openmc.VolumeCalculation([water, fuel], 100000, ll, ur),
            openmc.VolumeCalculation([root], 100000, ll, ur)
        ]

        # Define settings
        settings = openmc.Settings()
        settings.run_mode = 'volume'
        settings.volume_calculations = vol_calcs
        settings.export_to_xml()
def test_get_all_cells():
    cells = [openmc.Cell() for i in range(5)]
    cells2 = [openmc.Cell() for i in range(3)]
    cells[0].fill = openmc.Universe(cells=cells2)
    geom = openmc.Geometry(cells)

    all_cells = set(geom.get_all_cells().values())
    assert not all_cells ^ set(cells + cells2)
Exemple #16
0
    def build_default_materials_and_geometry(self):
        # Define materials.
        fuel = openmc.Material(name='Fuel')
        fuel.set_density('g/cm3', 10.29769)
        fuel.add_nuclide("U234", 4.4843e-6)
        fuel.add_nuclide("U235", 5.5815e-4)
        fuel.add_nuclide("U238", 2.2408e-2)
        fuel.add_nuclide("O16", 4.5829e-2)

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

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

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

        # Instantiate ZCylinder surfaces
        fuel_or = openmc.ZCylinder(x0=0, y0=0, R=0.39218, name='Fuel OR')
        clad_or = openmc.ZCylinder(x0=0, y0=0, R=0.45720, name='Clad OR')
        left = openmc.XPlane(x0=-0.63, name='left', boundary_type='reflective')
        right = openmc.XPlane(x0=0.63,
                              name='right',
                              boundary_type='reflective')
        bottom = openmc.YPlane(y0=-0.63,
                               name='bottom',
                               boundary_type='reflective')
        top = openmc.YPlane(y0=0.63, name='top', boundary_type='reflective')

        # Instantiate Cells
        fuel_pin = openmc.Cell(name='cell 1', fill=fuel)
        cladding = openmc.Cell(name='cell 3', fill=clad)
        water = openmc.Cell(name='cell 2', fill=hot_water)

        # Use surface half-spaces to define regions
        fuel_pin.region = -fuel_or
        cladding.region = +fuel_or & -clad_or
        water.region = +clad_or & +left & -right & +bottom & -top

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

        # Register Cells with Universe
        root.add_cells([fuel_pin, cladding, water])

        # Instantiate a Geometry, register the root Universe, and export to XML
        self.geometry.root_universe = root
Exemple #17
0
def test_pins_of_universes(pin_mats, good_radii):
    """Build a pin with a Universe in one ring"""
    u1 = openmc.Universe(cells=[openmc.Cell(fill=pin_mats[1])])
    new_items = pin_mats[:1] + (u1, ) + pin_mats[2:]
    new_pin = pin([openmc.ZCylinder(r=r) for r in good_radii],
                  new_items,
                  subdivisions={0: 2},
                  divide_vols=True)
    assert len(new_pin.cells) == len(pin_mats) + 1
Exemple #18
0
def pincell1(uo2, water):
    cyl = openmc.ZCylinder(r=0.35)
    fuel = openmc.Cell(fill=uo2, region=-cyl)
    moderator = openmc.Cell(fill=water, region=+cyl)

    univ = openmc.Universe(cells=[fuel, moderator])
    univ.fuel = fuel
    univ.moderator = moderator
    return univ
Exemple #19
0
    def from_hdf5(cls, filename):
        """Load stochastic volume calculation results from HDF5 file.

        Parameters
        ----------
        filename : str
            Path to volume.h5 file

        Returns
        -------
        openmc.VolumeCalculation
            Results of the stochastic volume calculation

        """
        with h5py.File(filename, 'r') as f:
            cv.check_filetype_version(f, "volume", _VERSION_VOLUME)

            domain_type = f.attrs['domain_type'].decode()
            samples = f.attrs['samples']
            lower_left = f.attrs['lower_left']
            upper_right = f.attrs['upper_right']

            volumes = {}
            atoms = {}
            ids = []
            for obj_name in f:
                if obj_name.startswith('domain_'):
                    domain_id = int(obj_name[7:])
                    ids.append(domain_id)
                    group = f[obj_name]
                    volume = tuple(group['volume'].value)
                    nucnames = group['nuclides'].value
                    atoms_ = group['atoms'].value

                    atom_dict = OrderedDict()
                    for name_i, atoms_i in zip(nucnames, atoms_):
                        atom_dict[name_i.decode()] = tuple(atoms_i)
                    volumes[domain_id] = volume
                    atoms[domain_id] = atom_dict

        # Instantiate some throw-away domains that are used by the constructor
        # to assign IDs
        with warnings.catch_warnings():
            warnings.simplefilter('ignore', openmc.IDWarning)
            if domain_type == 'cell':
                domains = [openmc.Cell(uid) for uid in ids]
            elif domain_type == 'material':
                domains = [openmc.Material(uid) for uid in ids]
            elif domain_type == 'universe':
                domains = [openmc.Universe(uid) for uid in ids]

        # Instantiate the class and assign results
        vol = cls(domains, samples, lower_left, upper_right)
        vol.volumes = volumes
        vol.atoms = atoms
        return vol
Exemple #20
0
    def _build_inputs(self):
        # Instantiate some Macroscopic Data
        uo2_data = openmc.Macroscopic('UO2')

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

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

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

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

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

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

        # Register Materials with Cells
        fuel.fill = mat

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

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

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

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

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

        settings_file.export_to_xml()
Exemple #21
0
def _make_outer_universe():
    mat  = openmc.Material(material_id=100000)
    mat.set_density('g/cm3',0.88)
    mat.add_nuclide("Na23", 1.0)
    cell = openmc.Cell(cell_id=100000)
    univ = openmc.Universe(universe_id=100000)
    cell.fill = mat
    univ.add_cell(cell)
    outsurface = openmc.ZCylinder(R=175.25, name='Reactor preasure vessel out', boundary_type = 'vacuum')
    return univ, outsurface
Exemple #22
0
def guide_tube_pin():
    """Returns a control rod guide tube universe."""

    gt_inner_cell = openmc.Cell(fill=hot_water, region=-fuel_or)
    gt_clad_cell = openmc.Cell(fill=clad, region=+fuel_or & -clad_or)
    gt_outer_cell = openmc.Cell(fill=hot_water, region=+clad_or)

    univ = openmc.Universe(name='Guide Tube')
    univ.add_cells([gt_inner_cell, gt_clad_cell, gt_outer_cell])
    return univ
Exemple #23
0
def fuel_pin():
    """Returns a fuel pin universe."""

    fuel_cell = openmc.Cell(fill=fuel, region=-fuel_or)
    clad_cell = openmc.Cell(fill=clad, region=+fuel_or & -clad_or)
    hot_water_cell = openmc.Cell(fill=hot_water, region=+clad_or)

    univ = openmc.Universe(name='Fuel Pin')
    univ.add_cells([fuel_cell, clad_cell, hot_water_cell])
    return univ
Exemple #24
0
def test_rotation():
    u = openmc.Universe()
    c = openmc.Cell(fill=u)
    c.rotation = (180.0, 0.0, 0.0)
    assert np.allclose(c.rotation_matrix,
                       [[1., 0., 0.], [0., -1., 0.], [0., 0., -1.]])

    c.rotation = (0.0, 90.0, 0.0)
    assert np.allclose(c.rotation_matrix,
                       [[0., 0., -1.], [0., 1., 0.], [1., 0., 0.]])
Exemple #25
0
    def _build_inputs(self):
        # Define materials
        water = openmc.Material(1)
        water.add_nuclide('H1', 2.0)
        water.add_nuclide('O16', 1.0)
        water.add_s_alpha_beta('c_H_in_H2O')
        water.set_density('g/cc', 1.0)

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

        materials = openmc.Materials((water, fuel))
        materials.default_temperature = '294K'
        materials.export_to_xml()

        # Define the geometry.  Note that this geometry is somewhat non-sensical
        # (it essentially defines a circle of half-cylinders), but it is
        # designed so that periodic and reflective BCs will give different
        # answers.
        theta1 = (-1 / 6 + 1 / 2) * np.pi
        theta2 = (1 / 6 - 1 / 2) * np.pi
        plane1 = openmc.Plane(a=np.cos(theta1),
                              b=np.sin(theta1),
                              boundary_type='periodic')
        plane2 = openmc.Plane(a=np.cos(theta2),
                              b=np.sin(theta2),
                              boundary_type='periodic')

        x_max = openmc.XPlane(x0=5., boundary_type='reflective')

        z_cyl = openmc.ZCylinder(x0=3 * np.cos(np.pi / 6),
                                 y0=3 * np.sin(np.pi / 6),
                                 r=2.0)

        outside_cyl = openmc.Cell(1,
                                  fill=water,
                                  region=(+plane1 & +plane2 & -x_max & +z_cyl))
        inside_cyl = openmc.Cell(2,
                                 fill=fuel,
                                 region=(+plane1 & +plane2 & -z_cyl))
        root_universe = openmc.Universe(0, cells=(outside_cyl, inside_cyl))

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

        # Define settings
        settings = openmc.Settings()
        settings.particles = 1000
        settings.batches = 4
        settings.inactive = 0
        settings.source = openmc.Source(
            space=openmc.stats.Box((0, 0, 0), (5, 5, 0)))
        settings.export_to_xml()
Exemple #26
0
def test_from_geometry():
    width = 25.
    s = openmc.Sphere(r=width / 2, boundary_type='vacuum')
    c = openmc.Cell(region=-s)
    univ = openmc.Universe(cells=[c])
    geom = openmc.Geometry(univ)

    for basis in ('xy', 'yz', 'xz'):
        plot = openmc.Plot.from_geometry(geom, basis)
        assert plot.origin == pytest.approx((0., 0., 0.))
        assert plot.width == pytest.approx((width, width))
Exemple #27
0
 def __init__(self, root=None):
     self._root_universe = None
     self._offsets = {}
     if root is not None:
         if isinstance(root, openmc.Universe):
             self.root_universe = root
         else:
             univ = openmc.Universe()
             for cell in root:
                 univ.add_cell(cell)
             self._root_universe = univ
Exemple #28
0
def model(request):
    openmc.reset_auto_ids()
    marker = request.node.get_closest_marker("surf_source_op")
    surf_source_op = marker.args[0]

    openmc_model = openmc.model.Model()

    # Materials
    # None

    # Geometry
    # Concentric void spheres
    # - Innermost sphere to bank surface sources
    # - Second shell to tally cell flux
    # - Outermost sphere as vacuum boundary
    sph_1 = openmc.Sphere(r=1.0)  # Surface to bank/write sources.
    sph_2 = openmc.Sphere(r=2.0)
    sph_3 = openmc.Sphere(r=2.5)
    sph_4 = openmc.Sphere(r=4.0, boundary_type='vacuum')
    cell_1 = openmc.Cell(region=-sph_1)
    cell_2 = openmc.Cell(region=+sph_1 & -sph_2)
    cell_3 = openmc.Cell(region=+sph_2 & -sph_3)  # Cell to tally flux.
    cell_4 = openmc.Cell(region=+sph_3 & -sph_4)
    root = openmc.Universe(cells=[cell_1, cell_2, cell_3, cell_4])
    openmc_model.geometry = openmc.Geometry(root)

    # Settings
    openmc_model.settings.run_mode = 'fixed source'
    openmc_model.settings.particles = 1000
    openmc_model.settings.batches = 10
    openmc_model.settings.seed = 1

    if surf_source_op == 'write':
        point = openmc.stats.Point((0, 0, 0))
        pt_src = openmc.Source(space=point)
        openmc_model.settings.source = pt_src

        openmc_model.settings.surf_source_write = {
            'surface_ids': [1],
            'max_particles': 1000
        }
    elif surf_source_op == 'read':
        openmc_model.settings.surf_source_read = {
            'path': 'surface_source_true.h5'
        }

    # Tallies
    tal = openmc.Tally()
    cell_filter = openmc.CellFilter(cell_3)
    tal.filters = [cell_filter]
    tal.scores = ['flux']
    openmc_model.tallies.append(tal)

    return openmc_model
Exemple #29
0
def test_create_xml(cell_with_lattice):
    cells = [openmc.Cell() for i in range(5)]
    u = openmc.Universe(cells=cells)

    geom = ET.Element('geom')
    u.create_xml_subelement(geom)
    cell_elems = geom.findall('cell')
    assert len(cell_elems) == len(cells)
    assert all(c.get('universe') == str(u.id) for c in cell_elems)
    assert not (set(c.get('id')
                    for c in cell_elems) ^ set(str(c.id) for c in cells))
def test_clone():
    c1 = openmc.Cell()
    c2 = openmc.Cell()
    root = openmc.Universe(cells=[c1, c2])
    geom = openmc.Geometry(root)

    clone = geom.clone()
    root_clone = clone.root_universe

    assert root.id != root_clone.id
    assert not (set(root.cells) & set(root_clone.cells))