def test_union(reset): s1 = openmc.XPlane(x0=5, surface_id=1) s2 = openmc.XPlane(x0=-5, surface_id=2) region = +s1 | -s2 assert isinstance(region, openmc.Union) # Check bounding box assert_unbounded(region) # __contains__ assert (6, 0, 0) in region assert (-6, 0, 0) in region assert (0, 0, 0) not in region # string representation assert str(region) == '(1 | -2)' # Combining region with intersection s3 = openmc.YPlane(surface_id=3) reg2 = region & +s3 assert (6, 1, 0) in reg2 assert (6, -1, 0) not in reg2 assert str(reg2) == '((1 | -2) 3)' # translate method regt = region.translate((2.0, 0.0, 0.0)) assert (-4, 0, 0) in regt assert (6, 0, 0) not in regt assert (8, 0, 0) in regt
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
def test_intersection(reset): s1 = openmc.XPlane(x0=5, surface_id=1) s2 = openmc.XPlane(x0=-5, surface_id=2) region = -s1 & +s2 assert isinstance(region, openmc.Intersection) # Check bounding box ll, ur = region.bounding_box assert ll == pytest.approx((-5, -np.inf, -np.inf)) assert ur == pytest.approx((5, np.inf, np.inf)) # __contains__ assert (6, 0, 0) not in region assert (-6, 0, 0) not in region assert (0, 0, 0) in region # string representation assert str(region) == '(-1 2)' # Combining region with union s3 = openmc.YPlane(surface_id=3) reg2 = region | +s3 assert (-6, 2, 0) in reg2 assert (-6, -2, 0) not in reg2 assert str(reg2) == '((-1 2) | 3)' # translate method regt = region.translate((2.0, 0.0, 0.0)) assert (-4, 0, 0) not in regt assert (6, 0, 0) in regt assert (8, 0, 0) not in regt
def make_model(): model = openmc.model.Model() # 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) moderator.add_s_alpha_beta('c_H_in_H2O') dense_fuel = openmc.Material(material_id=2) dense_fuel.set_density('g/cc', 4.5) dense_fuel.add_nuclide('U235', 1.0) model.materials += [moderator, dense_fuel] # 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, fill=dense_fuel, region=-r0) c11.temperature = [500, 0, 700, 800] c12 = openmc.Cell(cell_id=12, fill=moderator, region=+r0) fuel_univ = openmc.Universe(universe_id=11, cells=(c11, c12)) lat = openmc.RectLattice(lattice_id=101) lat.dimension = [2, 2] lat.lower_left = [-2.0, -2.0] lat.pitch = [2.0, 2.0] lat.universes = [[fuel_univ] * 2] * 2 lat.outer = mod_univ x0 = openmc.XPlane(x0=-3.0) x1 = openmc.XPlane(x0=3.0) y0 = openmc.YPlane(y0=-3.0) y1 = openmc.YPlane(y0=3.0) for s in [x0, x1, y0, y1]: s.boundary_type = 'reflective' c101 = openmc.Cell(cell_id=101, fill=lat, region=+x0 & -x1 & +y0 & -y1) model.geometry.root_universe = openmc.Universe(universe_id=0, cells=(c101, )) # Settings model.settings.batches = 5 model.settings.inactive = 0 model.settings.particles = 1000 model.settings.source = openmc.Source( space=openmc.stats.Box([-1, -1, -1], [1, 1, 1])) model.settings.temperature = {'tolerance': 1000, 'multipole': True} # Tallies tally = openmc.Tally() tally.nuclides = ['U235', 'O16', 'total'] tally.scores = ['total', 'fission', '(n,gamma)', 'elastic', '(n,p)'] model.tallies.append(tally) return model
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
def _make_openmc_input(self): """Generate the OpenMC input XML """ # Define material mat = openmc.Material() mat.add_nuclide(self.nuclide, 1.0) if self.thermal is not None: name, suffix = self.thermal.split('.') thermal_name = openmc.data.thermal.get_thermal_name(name) mat.add_s_alpha_beta(thermal_name) 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') # Set up geometry x1 = openmc.XPlane(x0=-1.e9, boundary_type='reflective') x2 = openmc.XPlane(x0=+1.e9, boundary_type='reflective') y1 = openmc.YPlane(y0=-1.e9, boundary_type='reflective') y2 = openmc.YPlane(y0=+1.e9, boundary_type='reflective') z1 = openmc.ZPlane(z0=-1.e9, boundary_type='reflective') z2 = openmc.ZPlane(z0=+1.e9, boundary_type='reflective') cell = openmc.Cell(fill=materials) cell.region = +x1 & -x2 & +y1 & -y2 & +z1 & -z2 geometry = openmc.Geometry([cell]) 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.Isotropic() source.energy = openmc.stats.Discrete([self.energy], [1.]) # 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.create_fission_neutrons = False settings.export_to_xml(self.openmc_dir / 'settings.xml') # Define tallies energy_bins = np.logspace(np.log10(self._min_energy), np.log10(1.0001 * self.energy), self._bins + 1) energy_filter = openmc.EnergyFilter(energy_bins) tally = openmc.Tally(name='tally') tally.filters = [energy_filter] tally.scores = ['flux'] tallies = openmc.Tallies([tally]) tallies.export_to_xml(self.openmc_dir / 'tallies.xml')
def centers_x_cylinder(): cylinder = openmc.XCylinder(r=1, y0=1, z0=2) min_x = openmc.XPlane(0) max_x = openmc.XPlane(1) region = +min_x & -max_x & -cylinder return openmc.model.pack_spheres(radius=_RADIUS, region=region, pf=_PACKING_FRACTION, initial_pf=0.2)
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()
def _make_openmc_input(self): """Generate the OpenMC input XML """ # Define material mat = openmc.Material() for element, fraction in self.elements: mat.add_element(element, 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') # Set up geometry x1 = openmc.XPlane(x0=-1.e9, boundary_type='reflective') x2 = openmc.XPlane(x0=+1.e9, boundary_type='reflective') y1 = openmc.YPlane(y0=-1.e9, boundary_type='reflective') y2 = openmc.YPlane(y0=+1.e9, boundary_type='reflective') z1 = openmc.ZPlane(z0=-1.e9, boundary_type='reflective') z2 = openmc.ZPlane(z0=+1.e9, boundary_type='reflective') cell = openmc.Cell(fill=materials) cell.region = +x1 & -x2 & +y1 & -y2 & +z1 & -z2 geometry = openmc.Geometry([cell]) 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.Isotropic() source.energy = openmc.stats.Discrete([self.energy], [1.]) source.particle = 'photon' # Settings settings = openmc.Settings() 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 tallies energy_bins = np.logspace(np.log10(self._cutoff_energy), np.log10(1.0001*self.energy), self._bins+1) energy_filter = openmc.EnergyFilter(energy_bins) particle_filter = openmc.ParticleFilter('photon') tally = openmc.Tally(name='tally') tally.filters = [energy_filter, particle_filter] tally.scores = ['flux'] tallies = openmc.Tallies([tally]) tallies.export_to_xml(self.openmc_dir / 'tallies.xml')
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 geometry x_min = openmc.XPlane(surface_id=1, x0=0., boundary_type='periodic') x_max = openmc.XPlane(surface_id=2, x0=5., boundary_type='reflective') y_min = openmc.YPlane(surface_id=3, y0=0., boundary_type='periodic') y_max = openmc.YPlane(surface_id=4, y0=5., boundary_type='reflective') y_min.periodic_surface = x_min z_min = openmc.ZPlane(surface_id=5, z0=-5., boundary_type='periodic') z_max = openmc.Plane(surface_id=6, a=0, b=0, c=1, d=5., boundary_type='periodic') z_cyl = openmc.ZCylinder(surface_id=7, x0=2.5, y0=0., r=2.0) outside_cyl = openmc.Cell(1, fill=water, region=(+x_min & -x_max & +y_min & -y_max & +z_min & -z_max & +z_cyl)) inside_cyl = openmc.Cell(2, fill=fuel, region=(+y_min & +z_min & -z_max & -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()
def centers_rectangular_prism(): min_x = openmc.XPlane(0) max_x = openmc.XPlane(1) min_y = openmc.YPlane(0) max_y = openmc.YPlane(1) min_z = openmc.ZPlane(0) max_z = openmc.ZPlane(1) region = +min_x & -max_x & +min_y & -max_y & +min_z & -max_z return openmc.model.pack_spheres(radius=_RADIUS, region=region, pf=_PACKING_FRACTION, initial_pf=0.2)
def __init__(self, xmin, xmax, ymin, ymax, zmin, zmax, **kwargs): if xmin >= xmax: raise ValueError('xmin must be less than xmax') if ymin >= ymax: raise ValueError('ymin must be less than ymax') if zmin >= zmax: raise ValueError('zmin must be less than zmax') self.xmin = openmc.XPlane(x0=xmin, **kwargs) self.xmax = openmc.XPlane(x0=xmax, **kwargs) self.ymin = openmc.YPlane(y0=ymin, **kwargs) self.ymax = openmc.YPlane(y0=ymax, **kwargs) self.zmin = openmc.ZPlane(z0=zmin, **kwargs) self.zmax = openmc.ZPlane(z0=zmax, **kwargs)
def _create_main_universe(self): """ Creates the main BEAVRS universe """ # For 3D problem, add full core to main universe if not self.is_2d: self.add_cell(self.c_RPV) self.add_cell(self.c_liner) self.add_cell(self.c_downcomer) for cell in self.c_shieldPanels: self.add_cell(cell) self.add_cell(self.c_coreBarrel) self.add_cell(self.c_core) # For 2D problem, create core universe separately and set bounding box as main universe else: # Define core universe that will be fill of main universe self.core_univ = openmc.Universe(name='BEAVRS core universe') self.core_univ.add_cell(self.c_RPV) self.core_univ.add_cell(self.c_liner) self.core_univ.add_cell(self.c_downcomer) for cell in self.c_shieldPanels: self.core_univ.add_cell(cell) self.core_univ.add_cell(self.c_coreBarrel) self.core_univ.add_cell(self.c_core) # Define boundaries of bounding box outer_bound = 8.5 * c.latticePitch self.s_leftBound = openmc.XPlane(name='Left Box', x0=-outer_bound, boundary_type='vacuum') self.s_rightBound = openmc.XPlane(name='Right Box', x0=outer_bound, boundary_type='vacuum') self.s_backBound = openmc.YPlane(name='Back Box', y0=-outer_bound, boundary_type='vacuum') self.s_frontBound = openmc.YPlane(name='Front Box', y0=outer_bound, boundary_type='vacuum') # Bounding box self.c_boundbox = openmc.Cell(name="Bounding box", fill=self.core_univ) self.c_boundbox.region = \ (+self.s_leftBound & -self.s_rightBound & +self.s_backBound & -self.s_frontBound & -self.s_upperBound & +self.s_lowerBound) self.add_cell(self.c_boundbox)
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 _build_inputs(self): # Set energy cutoff energy_cutoff = 4.0 # Material is composed of H-1 mat = openmc.Material(material_id=1, name='mat') mat.set_density('atom/b-cm', 0.069335) mat.add_nuclide('H1', 40.0) materials_file = openmc.Materials([mat]) materials_file.export_to_xml() # Cell is box with reflective boundary x1 = openmc.XPlane(surface_id=1, x0=-1) x2 = openmc.XPlane(surface_id=2, x0=1) y1 = openmc.YPlane(surface_id=3, y0=-1) y2 = openmc.YPlane(surface_id=4, y0=1) z1 = openmc.ZPlane(surface_id=5, z0=-1) z2 = openmc.ZPlane(surface_id=6, z0=1) for surface in [x1, x2, y1, y2, z1, z2]: surface.boundary_type = 'reflective' box = openmc.Cell(cell_id=1, name='box') box.region = +x1 & -x2 & +y1 & -y2 & +z1 & -z2 box.fill = mat root = openmc.Universe(universe_id=0, name='root universe') root.add_cell(box) geometry = openmc.Geometry(root) geometry.export_to_xml() # Set the running parameters settings_file = openmc.Settings() settings_file.run_mode = 'fixed source' settings_file.batches = 10 settings_file.particles = 100 settings_file.cutoff = {'energy_neutron': energy_cutoff} bounds = [-1, -1, -1, 1, 1, 1] uniform_dist = openmc.stats.Box(bounds[:3], bounds[3:]) watt_dist = openmc.stats.Watt() settings_file.source = openmc.source.Source(space=uniform_dist, energy=watt_dist) settings_file.export_to_xml() # Tally flux under energy cutoff tallies = openmc.Tallies() tally = openmc.Tally(1) tally.scores = ['flux'] energy_filter = openmc.filter.EnergyFilter((0.0, energy_cutoff)) tally.filters = [energy_filter] tallies.append(tally) tallies.export_to_xml()
def test_xplane(): s = openmc.XPlane(3., 'reflective') assert s.x0 == 3. assert s.boundary_type == 'reflective' # Check bounding box ll, ur = (+s).bounding_box assert ll == pytest.approx((3., -np.inf, -np.inf)) assert np.all(np.isinf(ur)) ll, ur = (-s).bounding_box assert ur == pytest.approx((3., np.inf, np.inf)) assert np.all(np.isinf(ll)) # __contains__ on associated half-spaces assert (5, 0, 0) in +s assert (5, 0, 0) not in -s assert (-2, 1, 10) in -s assert (-2, 1, 10) not in +s # evaluate method assert s.evaluate((5., 0., 0.)) == pytest.approx(2.) # translate method st = s.translate((1.0, 0.0, 0.0)) assert st.x0 == s.x0 + 1 # Make sure repr works repr(s)
def test_periodic(): x = openmc.XPlane(boundary_type='periodic') y = openmc.YPlane(boundary_type='periodic') x.periodic_surface = y assert y.periodic_surface == x with pytest.raises(TypeError): x.periodic_surface = openmc.Sphere()
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # Extract universes encapsulating fuel and water assemblies geometry = self._model.geometry water = geometry.get_universes_by_name('water assembly (hot)')[0] fuel = geometry.get_universes_by_name('fuel assembly (hot)')[0] # Construct a 3x3 lattice of fuel assemblies core_lat = openmc.RectLattice(name='3x3 Core Lattice', lattice_id=202) core_lat.lower_left = (-32.13, -32.13) core_lat.pitch = (21.42, 21.42) core_lat.universes = [[fuel, water, water], [fuel, fuel, fuel], [water, water, water]] # Create bounding surfaces min_x = openmc.XPlane(-32.13, boundary_type='reflective') max_x = openmc.XPlane(+32.13, boundary_type='reflective') min_y = openmc.YPlane(-32.13, boundary_type='reflective') max_y = openmc.YPlane(+32.13, boundary_type='reflective') min_z = openmc.ZPlane(0, boundary_type='reflective') max_z = openmc.ZPlane(+32.13, boundary_type='reflective') # Define root universe root_univ = openmc.Universe(universe_id=0, name='root universe') root_cell = openmc.Cell(cell_id=1) root_cell.region = +min_x & -max_x & +min_y & -max_y & +min_z & -max_z root_cell.fill = core_lat root_univ.add_cell(root_cell) # Over-ride geometry in the input set with this 3x3 lattice self._model.geometry.root_universe = root_univ # Initialize a "distribcell" filter for the fuel pin cell distrib_filter = openmc.DistribcellFilter(27) # Initialize the tallies tally = openmc.Tally(name='distribcell tally', tally_id=27) tally.filters.append(distrib_filter) tally.scores.append('nu-fission') # Assign the tallies file to the input set self._model.tallies.append(tally) # Specify summary output and correct source sampling box self._model.settings.source = openmc.Source(space=openmc.stats.Box( [-32, -32, 0], [32, 32, 32], only_fissionable=True))
def box_model(): model = openmc.model.Model() # Define materials water = openmc.Material() 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() fuel.add_nuclide('U235', 1.0) fuel.set_density('g/cc', 4.5) # Define geometry x_min = openmc.XPlane(surface_id=1, x0=0., boundary_type='periodic') x_max = openmc.XPlane(surface_id=2, x0=5., boundary_type='reflective') y_min = openmc.YPlane(surface_id=3, y0=0., boundary_type='periodic') y_max = openmc.YPlane(surface_id=4, y0=5., boundary_type='reflective') y_min.periodic_surface = x_min z_min = openmc.ZPlane(surface_id=5, z0=-5., boundary_type='periodic') z_max = openmc.Plane(surface_id=6, a=0, b=0, c=1, d=5., boundary_type='periodic') z_cyl = openmc.ZCylinder(surface_id=7, x0=2.5, y0=0., r=2.0) outside_cyl = openmc.Cell(1, fill=water, region=(+x_min & -x_max & +y_min & -y_max & +z_min & -z_max & +z_cyl)) inside_cyl = openmc.Cell(2, fill=fuel, region=(+y_min & +z_min & -z_max & -z_cyl)) root_universe = openmc.Universe(0, cells=(outside_cyl, inside_cyl)) model.geometry = openmc.Geometry(root_universe) # Define settings model.settings.particles = 1000 model.settings.batches = 4 model.settings.inactive = 0 model.settings.source = openmc.Source( space=openmc.stats.Box((0, 0, 0), (5, 5, 0))) return model
def __init__(self, center_base, height, radius, axis='z', **kwargs): cx, cy, cz = center_base check_greater_than('cylinder height', height, 0.0) check_greater_than('cylinder radius', radius, 0.0) check_value('cylinder axis', axis, ('x', 'y', 'z')) if axis == 'x': self.cyl = openmc.XCylinder(y0=cy, z0=cz, r=radius, **kwargs) self.bottom = openmc.XPlane(x0=cx, **kwargs) self.top = openmc.XPlane(x0=cx + height, **kwargs) elif axis == 'y': self.cyl = openmc.YCylinder(x0=cx, z0=cz, r=radius, **kwargs) self.bottom = openmc.YPlane(y0=cy, **kwargs) self.top = openmc.YPlane(y0=cy + height, **kwargs) elif axis == 'z': self.cyl = openmc.ZCylinder(x0=cx, y0=cy, r=radius, **kwargs) self.bottom = openmc.ZPlane(z0=cz, **kwargs) self.top = openmc.ZPlane(z0=cz + height, **kwargs)
def _build_inputs(self): # Define materials water = openmc.Material(1) water.add_nuclide('H-1', 2.0) water.add_nuclide('O-16', 1.0) water.add_s_alpha_beta('HH2O', '71t') water.set_density('g/cc', 1.0) fuel = openmc.Material(2) fuel.add_nuclide('U-235', 1.0) fuel.set_density('g/cc', 4.5) materials = openmc.Materials((water, fuel)) materials.default_xs = '71c' materials.export_to_xml() # Define geometry x_min = openmc.XPlane(1, x0=-5., boundary_type='periodic') x_max = openmc.XPlane(2, x0=5., boundary_type='periodic') x_max.periodic_surface = x_min y_min = openmc.YPlane(3, y0=-5., boundary_type='periodic') y_max = openmc.YPlane(4, y0=5., boundary_type='periodic') z_min = openmc.ZPlane(5, z0=-5., boundary_type='reflective') z_max = openmc.ZPlane(6, z0=5., boundary_type='reflective') z_cyl = openmc.ZCylinder(7, x0=-2.5, y0=2.5, R=2.0) outside_cyl = openmc.Cell(1, fill=water, region=( +x_min & -x_max & +y_min & -y_max & +z_min & -z_max & +z_cyl)) inside_cyl = openmc.Cell(2, fill=fuel, region=+z_min & -z_max & -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( *outside_cyl.region.bounding_box)) settings.export_to_xml()
def test_contains(): # Cell with specified region s = openmc.XPlane() c = openmc.Cell(region=+s) assert (1.0, 0.0, 0.0) in c assert (-1.0, 0.0, 0.0) not in c # Cell with no region c = openmc.Cell() assert (10.0, -4., 2.0) in c
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()
def model_surf(request): # Select random distance and source energy x = uniform(50., 100.) E = uniform(0., 20.0e6) # Create model model = openmc.Model() mat = openmc.Material() mat.add_nuclide('Zr90', 1.0) mat.set_density('g/cm3', 1.0) model.materials.append(mat) left = openmc.XPlane(-1., boundary_type='vacuum') black_surface = openmc.XPlane(x, boundary_type='vacuum') right = openmc.XPlane(x + 1) void_cell = openmc.Cell(region=+left & -black_surface) black_cell = openmc.Cell(region=+black_surface & -right) model.geometry = openmc.Geometry([void_cell, black_cell]) model.settings = openmc.Settings() model.settings.run_mode = 'fixed source' model.settings.particles = 1000 model.settings.batches = 20 particle = request.param model.settings.source = openmc.Source( space=openmc.stats.Point((0., 0., 0.)), angle=openmc.stats.Monodirectional([1., 0., 0.]), energy=openmc.stats.Discrete([E], [1.0]), particle=particle) # Calculate time it will take neutrons to reach purely-absorbing surface t0 = time(particle, x, E) # Create tally with surface and time filters tally = openmc.Tally() tally.filters = [ openmc.SurfaceFilter([black_surface]), openmc.TimeFilter([0.0, t0 * 0.999, t0 * 1.001, 100.0]) ] tally.scores = ['current'] model.tallies.append(tally) return model
def test_get_surfaces(): s1 = openmc.XPlane() s2 = openmc.YPlane() s3 = openmc.ZPlane() region = (+s1 & -s2) | +s3 # Make sure get_surfaces() returns all surfaces surfs = set(region.get_surfaces().values()) assert not (surfs ^ {s1, s2, s3}) inverse = ~region surfs = set(inverse.get_surfaces().values()) assert not (surfs ^ {s1, s2, s3})
def region_maker(area,area_type): """ Creates 2D openmc.region.Intersection on x-y plane Parameters ---------- area: str This refers to the 3 diamond sections in the FHR geometry. Options are: 'A1', 'A2', 'A3' area_type: str This refers to the various areas within each quadrant. Diamond Plank Area: 'D', Plank Area: 'P', Fuel Area: 'F' Spacers: 'S', Control Rod Slot: 'CS', Control Rod Arm: 'CA' Returns ------- openmc.region.Intersection """ if area in ['A1','A3']: if V[area][area_type]['L']['m'] == 0.0 and V[area][area_type]['R']['m'] == 0.0: region = -plane(V[area][area_type]['T']['m'],V[area][area_type]['T']['x'],V[area][area_type]['T']['y']) &\ +plane(V[area][area_type]['B']['m'],V[area][area_type]['B']['x'],V[area][area_type]['B']['y']) &\ +openmc.XPlane(x0=V[area][area_type]['L']['x']) &\ -openmc.XPlane(x0=V[area][area_type]['R']['x']) else: region = -plane(V[area][area_type]['T']['m'],V[area][area_type]['T']['x'],V[area][area_type]['T']['y']) &\ +plane(V[area][area_type]['B']['m'],V[area][area_type]['B']['x'],V[area][area_type]['B']['y']) &\ +plane(V[area][area_type]['L']['m'],V[area][area_type]['L']['x'],V[area][area_type]['L']['y']) &\ -plane(V[area][area_type]['R']['m'],V[area][area_type]['R']['x'],V[area][area_type]['R']['y']) elif area in ['A2']: region = -plane(V[area][area_type]['T']['m'],V[area][area_type]['T']['x'],V[area][area_type]['T']['y']) &\ +plane(V[area][area_type]['B']['m'],V[area][area_type]['B']['x'],V[area][area_type]['B']['y']) &\ -plane(V[area][area_type]['L']['m'],V[area][area_type]['L']['x'],V[area][area_type]['L']['y']) &\ +plane(V[area][area_type]['R']['m'],V[area][area_type]['R']['x'],V[area][area_type]['R']['y']) else: raise Exception('Your region type has yet to be defined.') return region
def build(self): x0 = openmc.XPlane(x0=0, boundary_type="reflective") right_inner_wall = openmc.Plane(A=cos(pi / 3), B=-cos(pi / 6), D=(RAD_MAJ - STEEL_THICK) * cos(pi / 6)) right_outer_wall = openmc.Plane(A=cos(pi / 3), B=-cos(pi / 6), D=RAD_MAJ * cos(pi / 6)) right_refl_edge = openmc.Plane(boundary_type="reflective", A=cos(pi / 6), B=cos(pi / 3), D=-GAP / 2 * cos(pi / 6) * 0) ymin = openmc.YPlane(y0=-RAD_MAJ, boundary_type="vacuum", name="YMIN") zmin = openmc.ZPlane(z0=-10, boundary_type="periodic", name="ZMIN") zmax = openmc.ZPlane(z0=+10, boundary_type="periodic", name="ZMAX") ru = openmc.Universe(name="root universe") radialu = openmc.Universe(name="radial universe") lattice = self.get_lattice() dist = RAD_MAJ - STEEL_THICK - sqrt(3) / 2 * self.pitch right_inner_water = openmc.Plane(A=cos(pi / 3), B=-cos(pi / 6), D=dist * cos(pi / 6)) # Fueled area inner = openmc.Cell() inner.region = -right_inner_water inner.fill = lattice radialu.add_cell(inner) # Water buffer buffer = openmc.Cell() buffer.region = +right_inner_water & -right_inner_wall buffer.fill = all_materials["Mod"] radialu.add_cell(buffer) # Reactor pressure vessel rpv = openmc.Cell() rpv.region = +right_inner_wall & -right_outer_wall rpv.fill = all_materials["SS316"] radialu.add_cell(rpv) outside = openmc.Cell() outside.region = +right_outer_wall outside.fill = all_materials["Air"] radialu.add_cell(outside) # Root Universe root_cell = openmc.Cell(name="root cell") root_cell.fill = radialu root_cell.region = +x0 & +ymin & +zmin & -zmax & -right_refl_edge ru.add_cell(root_cell) self._geometry = openmc.Geometry() self._geometry.root_universe = ru
def create_geom(radius, fuel, air): """Create geometry for some radius sphere """ # Create geometry sphere = openmc.Sphere(R=radius) min_x = openmc.XPlane(x0=-radius, boundary_type='vacuum') max_x = openmc.XPlane(x0=+radius, boundary_type='vacuum') min_y = openmc.YPlane(y0=-radius, boundary_type='vacuum') max_y = openmc.YPlane(y0=+radius, boundary_type='vacuum') min_z = openmc.ZPlane(z0=-radius, boundary_type='vacuum') max_z = openmc.ZPlane(z0=+radius, boundary_type='vacuum') # Create Universe universe = openmc.Universe(name='Universe') fuel_cell = openmc.Cell(name='fuel') fuel_cell.fill = fuel fuel_cell.region = -sphere universe.add_cell(fuel_cell) air_cell = openmc.Cell(name='air') air_cell.fill = None air_cell.region = +sphere universe.add_cell(air_cell) # Create root cell root_cell = openmc.Cell(name='root_cell') root_cell.fill = universe root_cell.region = +min_x & -max_x & +min_y & -max_y & +min_z & -max_z root_universe = openmc.Universe(universe_id=0, name='root universe') root_universe.add_cell(root_cell) geometry = openmc.Geometry() geometry.root_universe = root_universe geometry.export_to_xml()
def create_cube(x_length, y_length, z_length, start_point, boundary_type_set='reflective'): x_pos = openmc.XPlane(x0=max(x_length + start_point.x, start_point.x), boundary_type=boundary_type_set) x_neg = openmc.XPlane(x0=min(x_length + start_point.x, start_point.x), boundary_type=boundary_type_set) y_pos = openmc.YPlane(y0=max(y_length + start_point.y, start_point.y), boundary_type=boundary_type_set) y_neg = openmc.YPlane(y0=min(y_length + start_point.y, start_point.y), boundary_type=boundary_type_set) z_pos = openmc.ZPlane(z0=max(z_length + start_point.z, start_point.z), boundary_type=boundary_type_set) z_neg = openmc.ZPlane(z0=min(z_length + start_point.z, start_point.z), boundary_type=boundary_type_set) plane_list = [] plane_list.append([x_pos, x_neg]) plane_list.append([y_pos, y_neg]) plane_list.append([z_pos, z_neg]) return truncation_create(plane_list)
def test_find(uo2): xp = openmc.XPlane() c1 = openmc.Cell(fill=uo2, region=+xp) c2 = openmc.Cell(region=-xp) u1 = openmc.Universe(cells=(c1, c2)) cyl = openmc.ZCylinder() c3 = openmc.Cell(fill=u1, region=-cyl) c4 = openmc.Cell(region=+cyl) geom = openmc.Geometry((c3, c4)) seq = geom.find((0.5, 0., 0.)) assert seq[-1] == c1 seq = geom.find((-0.5, 0., 0.)) assert seq[-1] == c2 seq = geom.find((-1.5, 0., 0.)) assert seq[-1] == c4