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())
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 centers_spherical_shell(): sphere = openmc.Sphere(r=1, x0=1, y0=2, z0=3) inner_sphere = openmc.Sphere(r=0.5, x0=1, y0=2, z0=3) region = -sphere & +inner_sphere return openmc.model.pack_spheres(radius=_RADIUS, region=region, pf=_PACKING_FRACTION, initial_pf=0.2)
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
def test_export_xml(run_in_tmpdir, uo2): s1 = openmc.Sphere(r=1.) s2 = openmc.Sphere(r=2., boundary_type='reflective') c1 = openmc.Cell(fill=uo2, region=-s1) c2 = openmc.Cell(fill=uo2, region=+s1 & -s2) geom = openmc.Geometry([c1, c2]) geom.export_to_xml() doc = ET.parse('geometry.xml') root = doc.getroot() assert root.tag == 'geometry' cells = root.findall('cell') assert [int(c.get('id')) for c in cells] == [c1.id, c2.id] surfs = root.findall('surface') assert [int(s.get('id')) for s in surfs] == [s1.id, s2.id]
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()
def model(): model = openmc.model.Model() natural_lead = openmc.Material(name="natural_lead") natural_lead.add_element('Pb', 1.0) natural_lead.set_density('g/cm3', 11.34) model.materials.append(natural_lead) # geometry surface_sph1 = openmc.Sphere(r=100, boundary_type='vacuum') cell_1 = openmc.Cell(fill=natural_lead, region=-surface_sph1) model.geometry = openmc.Geometry([cell_1]) # settings model.settings.batches = 10 model.settings.inactive = 0 model.settings.particles = 1000 model.settings.run_mode = 'fixed source' # custom source from shared library source = openmc.Source() source.library = 'build/libsource.so' source.parameters = '1e3' model.settings.source = source return model
def test_wrong_source_attributes(run_in_tmpdir): # Create a source file with animal attributes source_dtype = np.dtype([ ('platypus', '<f8'), ('axolotl', '<f8'), ('narwhal', '<i4'), ]) arr = np.array([(1.0, 2.0, 3), (4.0, 5.0, 6), (7.0, 8.0, 9)], dtype=source_dtype) with h5py.File('animal_source.h5', 'w') as fh: fh.attrs['filetype'] = np.string_("source") fh.create_dataset('source_bank', data=arr) # Create a simple model that uses this lovely animal source m = openmc.Material() m.add_nuclide('U235', 0.02) openmc.Materials([m]).export_to_xml() s = openmc.Sphere(r=10.0, boundary_type='vacuum') c = openmc.Cell(fill=m, region=-s) openmc.Geometry([c]).export_to_xml() settings = openmc.Settings() settings.particles = 100 settings.batches = 10 settings.source = openmc.Source(filename='animal_source.h5') settings.export_to_xml() # When we run the model, it should error out with a message that includes # the names of the wrong attributes with pytest.raises(RuntimeError) as excinfo: openmc.run() assert 'platypus, axolotl, narwhal' in str(excinfo.value)
def model(): """Sphere of single nuclide""" model = openmc.model.Model() w = openmc.Material(name='tungsten') w.add_nuclide('W186', 1.0) w.set_density('g/cm3', 19.3) w.depletable = True r = uniform(1.0, 10.0) w.volume = 4 / 3 * pi * r**3 surf = openmc.Sphere(r=r, boundary_type='vacuum') cell = openmc.Cell(fill=w, region=-surf) model.geometry = openmc.Geometry([cell]) model.settings.batches = 10 model.settings.particles = 1000 model.settings.source = openmc.Source(space=openmc.stats.Point(), energy=openmc.stats.Discrete([1.0e6], [1.0])) model.settings.run_mode = 'fixed source' rx_tally = openmc.Tally() rx_tally.scores = ['(n,gamma)'] model.tallies.append(rx_tally) return model
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 model(): model = openmc.model.Model() zn = openmc.Material() zn.set_density('g/cm3', 7.14) zn.add_nuclide('Zn64', 1.0) model.materials.append(zn) radii = np.linspace(1.0, 100.0) surfs = [openmc.Sphere(r=r) for r in radii] surfs[-1].boundary_type = 'vacuum' cells = [ openmc.Cell(fill=(zn if i % 2 == 0 else None), region=region) for i, region in enumerate(openmc.model.subdivide(surfs)) ] model.geometry = openmc.Geometry(cells) model.settings.run_mode = 'fixed source' model.settings.batches = 3 model.settings.particles = 1000 model.settings.source = openmc.Source(space=openmc.stats.Point()) cell_filter = openmc.CellFilter(cells) tally = openmc.Tally() tally.filters = [cell_filter] tally.scores = ['total'] model.tallies.append(tally) return model
def test_sphere(): x, y, z, r = -3, 5, 6, 2 s = openmc.Sphere(x0=x, y0=y, z0=z, r=r) assert s.x0 == x assert s.y0 == y assert s.z0 == z assert s.r == r # Check bounding box ll, ur = (+s).bounding_box assert np.all(np.isinf(ll)) assert np.all(np.isinf(ur)) ll, ur = (-s).bounding_box assert ll == pytest.approx((x-r, y-r, z-r)) assert ur == pytest.approx((x+r, y+r, z+r)) # evaluate method assert s.evaluate((x, y, z)) == pytest.approx(-r**2) # translate method st = s.translate((1.0, 1.0, 1.0)) assert st.x0 == s.x0 + 1 assert st.y0 == s.y0 + 1 assert st.z0 == s.z0 + 1 assert st.r == s.r # Make sure repr works repr(s)
def inf_medium_model(cutoff_energy, source_energy): """Infinite medium problem with a monoenergetic photon source""" model = openmc.Model() m = openmc.Material() m.add_nuclide('Zr90', 1.0) m.set_density('g/cm3', 1.0) sph = openmc.Sphere(r=100.0, boundary_type='reflective') cell = openmc.Cell(fill=m, region=-sph) model.geometry = openmc.Geometry([cell]) model.settings.run_mode = 'fixed source' model.settings.source = openmc.Source( particle='photon', energy=openmc.stats.Discrete([source_energy], [1.0]), ) model.settings.particles = 100 model.settings.batches = 10 model.settings.cutoff = {'energy_photon': cutoff_energy} tally_flux = openmc.Tally(name='flux') tally_flux.filters = [ openmc.EnergyFilter([0.0, cutoff_energy, source_energy]), openmc.ParticleFilter(['photon']) ] tally_flux.scores = ['flux'] tally_heating = openmc.Tally(name='heating') tally_heating.scores = ['heating'] model.tallies = openmc.Tallies([tally_flux, tally_heating]) return model
def test_packing_fraction_input(): # Provide neither packing fraction nor number of spheres with pytest.raises(ValueError): centers = openmc.model.pack_spheres(radius=_RADIUS, region=-openmc.Sphere(r=1)) # Specify a packing fraction that is too high for CRP with pytest.raises(ValueError): centers = openmc.model.pack_spheres(radius=_RADIUS, region=-openmc.Sphere(r=1), pf=1) # Specify a packing fraction that is too high for RSP with pytest.raises(ValueError): centers = openmc.model.pack_spheres(radius=_RADIUS, region=-openmc.Sphere(r=1), pf=0.5, initial_pf=0.4)
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))
def test_get_all_materials(): m1 = openmc.Material() m2 = openmc.Material() c1 = openmc.Cell(fill=m1) u1 = openmc.Universe(cells=[c1]) s = openmc.Sphere() c2 = openmc.Cell(fill=u1, region=-s) c3 = openmc.Cell(fill=m2, region=+s) geom = openmc.Geometry([c2, c3]) all_mats = set(geom.get_all_materials().values()) assert not all_mats ^ {m1, m2}
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 element, fraction in self.elements: mat.add_element(element, fraction) mat.set_density('g/cm3', self.density) materials = openmc.Materials([mat]) materials.export_to_xml(os.path.join('openmc', 'materials.xml')) # Set up geometry sphere = openmc.Sphere(boundary_type='reflective', R=1.e9) cell = openmc.Cell() cell.fill = mat cell.region = -sphere geometry = openmc.Geometry([cell]) 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.Isotropic() source.energy = openmc.stats.Discrete([self.energy], [1.]) source.particle = 'photon' # 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 tallies cell_filter = openmc.CellFilter(cell) energy_bins = np.logspace(3, np.log10(self.energy), 500) energy_filter = openmc.EnergyFilter(energy_bins) particle_filter = openmc.ParticleFilter('photon') tally = openmc.Tally(name='photon flux') tally.filters = [cell_filter, energy_filter, particle_filter] tally.scores = ['flux'] tallies = openmc.Tallies([tally]) tallies.export_to_xml(os.path.join('openmc', 'tallies.xml'))
def model(request): # Select random sphere radius, source position, and source energy r = uniform(0., 2.) x = uniform(2., 10.) 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) inner_sphere = openmc.Sphere(r=r) outer_sphere = openmc.Sphere(r=10.0, boundary_type='vacuum') center_cell = openmc.Cell(fill=mat, region=-inner_sphere) outer_void = openmc.Cell(region=+inner_sphere & -outer_sphere) model.geometry = openmc.Geometry([center_cell, outer_void]) 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((x, 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 sphere t0 = time(particle, x - r, E) # Create tally with time filter tally = openmc.Tally() tally.filters = [openmc.TimeFilter([0.0, t0, 2 * t0])] tally.scores = ['total'] model.tallies.append(tally) return model
def _build_inputs(self): mat1 = openmc.Material(material_id=1, temperature=294) mat1.set_density('g/cm3', 4.5) mat1.add_nuclide(openmc.Nuclide('U235'), 1.0) materials = openmc.Materials([mat1]) materials.export_to_xml() sphere = openmc.Sphere(surface_id=1, r=10.0, boundary_type='vacuum') inside_sphere = openmc.Cell(cell_id=1) inside_sphere.region = -sphere inside_sphere.fill = mat1 root = openmc.Universe(universe_id=0) root.add_cell(inside_sphere) geometry = openmc.Geometry() geometry.root_universe = root geometry.export_to_xml() # Create an array of different sources x_dist = openmc.stats.Uniform(-3., 3.) y_dist = openmc.stats.Discrete([-4., -1., 3.], [0.2, 0.3, 0.5]) z_dist = openmc.stats.Tabular([-2., 0., 2.], [0.2, 0.3, 0.2]) spatial1 = openmc.stats.CartesianIndependent(x_dist, y_dist, z_dist) spatial2 = openmc.stats.Box([-4., -4., -4.], [4., 4., 4.]) spatial3 = openmc.stats.Point([1.2, -2.3, 0.781]) mu_dist = openmc.stats.Discrete([-1., 0., 1.], [0.5, 0.25, 0.25]) phi_dist = openmc.stats.Uniform(0., 6.28318530718) angle1 = openmc.stats.PolarAzimuthal(mu_dist, phi_dist) angle2 = openmc.stats.Monodirectional(reference_uvw=[0., 1., 0.]) angle3 = openmc.stats.Isotropic() E = np.logspace(0, 7) p = np.sin(np.linspace(0., pi)) p /= sum(np.diff(E) * p[:-1]) energy1 = openmc.stats.Maxwell(1.2895e6) energy2 = openmc.stats.Watt(0.988e6, 2.249e-6) energy3 = openmc.stats.Tabular(E, p, interpolation='histogram') source1 = openmc.Source(spatial1, angle1, energy1, strength=0.5) source2 = openmc.Source(spatial2, angle2, energy2, strength=0.3) source3 = openmc.Source(spatial3, angle3, energy3, strength=0.2) settings = openmc.Settings() settings.batches = 10 settings.inactive = 5 settings.particles = 1000 settings.source = [source1, source2, source3] settings.export_to_xml()
def sphere_model(): model = openmc.model.Model() m = openmc.Material() m.add_nuclide('U235', 1.0) m.set_density('g/cm3', 1.0) model.materials.append(m) sph = openmc.Sphere(boundary_type='vacuum') c = openmc.Cell(fill=m, region=-sph) model.geometry.root_universe = openmc.Universe(cells=[c]) model.settings.particles = 100 model.settings.batches = 10 model.settings.run_mode = 'fixed source' model.settings.source = openmc.Source(space=openmc.stats.Point()) return model
def test_decay(run_in_tmpdir): """Test decay-only timesteps where no transport solve is performed""" # Create a model with a single nuclide, Sr89 mat = openmc.Material() mat.add_nuclide('Sr89', 1.0) mat.set_density('g/cm3', 1.0) mat.depletable = True r = 5.0 mat.volume = 4 / 3 * pi * r**3 surf = openmc.Sphere(r=r, boundary_type='vacuum') cell = openmc.Cell(fill=mat, region=-surf) geometry = openmc.Geometry([cell]) settings = openmc.Settings() settings.batches = 10 settings.particles = 1000 settings.run_mode = 'fixed source' # Create depletion chain with only Sr89 and sample its half-life. Note that # currently at least one reaction has to exist in the depletion chain chain = openmc.deplete.Chain() sr89 = openmc.deplete.Nuclide('Sr89') sr89.half_life = normalvariate(4365792.0, 6048.0) sr89.add_decay_mode('beta-', None, 1.0) sr89.add_reaction('(n,gamma)', None, 0.0, 1.0) chain.add_nuclide(sr89) chain.export_to_xml('test_chain.xml') model = openmc.Model(geometry=geometry, settings=settings) # Create transport operator op = openmc.deplete.Operator(model, 'test_chain.xml', normalization_mode="source-rate") # Deplete with two decay steps integrator = openmc.deplete.PredictorIntegrator( op, [sr89.half_life, 2 * sr89.half_life], source_rates=[0.0, 0.0]) integrator.integrate() # Get resulting number of atoms results = openmc.deplete.ResultsList.from_hdf5('depletion_results.h5') _, atoms = results.get_atoms(str(mat.id), "Sr89") # Ensure density goes down by a factor of 2 after each half-life assert atoms[1] / atoms[0] == pytest.approx(0.5) assert atoms[2] / atoms[1] == pytest.approx(0.25)
def model(): model = openmc.model.Model() m = openmc.Material() m.set_density('g/cm3', 20.0) m.add_nuclide('U233', 1.0) m.add_nuclide('Am244', 1.0) m.add_nuclide('H2', 1.0) m.add_nuclide('Na23', 1.0) m.add_nuclide('Ta181', 1.0) s = openmc.Sphere(r=100.0, boundary_type='reflective') c = openmc.Cell(fill=m, region=-s) model.geometry = openmc.Geometry([c]) model.settings.batches = 10 model.settings.inactive = 5 model.settings.particles = 1000 return model
def model(): model = openmc.model.Model() fuel = openmc.Material() fuel.set_density('g/cc', 10.0) fuel.add_nuclide('U235', 1.0) h1 = openmc.Material() h1.set_density('g/cc', 0.1) h1.add_nuclide('H1', 0.1) inner_sphere = openmc.Sphere(x0=1.0, r=5.0) fuel_cell = openmc.Cell(fill=fuel, region=-inner_sphere) hydrogen_cell = openmc.Cell(fill=h1, region=+inner_sphere) univ = openmc.Universe(cells=[fuel_cell, hydrogen_cell]) # Create one cell on top of the other. Only one # has a rotation box = openmc.rectangular_prism(15., 15., 'z', boundary_type='vacuum') lower_z = openmc.ZPlane(-7.5, boundary_type='vacuum') upper_z = openmc.ZPlane(22.5, boundary_type='vacuum') middle_z = openmc.ZPlane(7.5) lower_cell = openmc.Cell(fill=univ, region=box & +lower_z & -middle_z) lower_cell.rotation = (10, 20, 30) upper_cell = openmc.Cell(fill=univ, region=box & +middle_z & -upper_z) upper_cell.translation = (0, 0, 15) model.geometry = openmc.Geometry(root=[lower_cell, upper_cell]) model.settings.particles = 10000 model.settings.inactive = 5 model.settings.batches = 10 source_box = openmc.stats.Box((-4., -4., -4.), (4., 4., 4.)) model.settings.source = openmc.Source(space=source_box) return model
def model(): # Materials mat = openmc.Material() mat.set_density('g/cm3', 4.5) mat.add_nuclide('U235', 1.0) materials = openmc.Materials([mat]) # Geometry sph = openmc.Sphere(r=10.0, boundary_type='vacuum') cell = openmc.Cell(fill=mat, region=-sph) geometry = openmc.Geometry([cell]) # Settings settings = openmc.Settings() settings.run_mode = 'eigenvalue' settings.batches = 10 settings.inactive = 5 settings.particles = 200 # Choose a sufficiently low threshold to trigger after more than 10 batches. # 0.004 seems to take 13 batches. settings.keff_trigger = {'type': 'std_dev', 'threshold': 0.004} settings.trigger_max_batches = 1000 settings.trigger_batch_interval = 1 settings.trigger_active = True settings.verbosity = 1 # to test that this works even with no output # Tallies t = openmc.Tally() t.scores = ['flux'] tallies = openmc.Tallies([t]) # Put it all together model = openmc.model.Model(materials=materials, geometry=geometry, settings=settings, tallies=tallies) return model
def model(): model = openmc.model.Model() m = openmc.Material() m.set_density('g/cm3', 10.0) m.add_nuclide('Am241', 1.0) model.materials.append(m) s = openmc.Sphere(r=100.0, boundary_type='vacuum') c = openmc.Cell(fill=m, region=-s) model.geometry = openmc.Geometry([c]) model.settings.batches = 5 model.settings.inactive = 0 model.settings.particles = 1000 # Define Am242m / Am242 branching ratio from ENDF/B-VII.1 data. x = [1e-5, 3.69e-1, 1e3, 1e5, 6e5, 1e6, 2e6, 4e6, 3e7] y = [0.1, 0.1, 0.1333, 0.158, 0.18467, 0.25618, 0.4297, 0.48, 0.48] # Make an EnergyFunctionFilter directly from the x and y lists. filt1 = openmc.EnergyFunctionFilter(x, y) # Also make a filter with the .from_tabulated1d constructor. Make sure # the filters are identical. tab1d = openmc.data.Tabulated1D(x, y) filt2 = openmc.EnergyFunctionFilter.from_tabulated1d(tab1d) assert filt1 == filt2, 'Error with the .from_tabulated1d constructor' # Make tallies tallies = [openmc.Tally(), openmc.Tally()] for t in tallies: t.scores = ['(n,gamma)'] t.nuclides = ['Am241'] tallies[1].filters = [filt1] model.tallies.extend(tallies) return model
def th232_model(): # URR boundaries for Th232 e_min, e_max = 4000.0, 100000.0 model = openmc.model.Model() th232 = openmc.Material() th232.add_nuclide('Th232', 1.0) surf = openmc.Sphere(r=100.0, boundary_type='reflective') cell = openmc.Cell(fill=th232, region=-surf) model.geometry = openmc.Geometry([cell]) model.settings.particles = 100 model.settings.batches = 10 model.settings.run_mode = 'fixed source' energies = openmc.stats.Uniform(e_min, e_max) model.settings.source = openmc.Source(energy=energies) tally = openmc.Tally(name='rates') tally.filters = [openmc.EnergyFilter([e_min, e_max])] tally.scores = ['(n,gamma)', 'absorption', 'fission'] model.tallies.append(tally) return model
def test_quadric(): # Make a sphere from a quadric r = 10.0 coeffs = {'a': 1, 'b': 1, 'c': 1, 'k': -r**2} s = openmc.Quadric(**coeffs) assert s.a == coeffs['a'] assert s.b == coeffs['b'] assert s.c == coeffs['c'] assert s.k == coeffs['k'] assert openmc.Sphere(r=10).is_equal(s) # All other coeffs should be zero for coeff in ('d', 'e', 'f', 'g', 'h', 'j'): assert getattr(s, coeff) == 0.0 # Check bounding box assert_infinite_bb(s) # evaluate method assert s.evaluate((0., 0., 0.)) == pytest.approx(coeffs['k']) assert s.evaluate((1., 1., 1.)) == pytest.approx(3 + coeffs['k']) # translate method st = s.translate((1.0, 1.0, 1.0)) for coeff in 'abcdef': assert getattr(s, coeff) == getattr(st, coeff) assert (st.g, st.h, st.j) == (-2, -2, -2) assert st.k == s.k + 3 # rotate method x0, y0, z0, r2 = 2, 3, 4, 4 dx, dy, dz = 1, -1, 1 s = openmc.Cone(x0=x0, y0=y0, z0=z0, dx=dx, dy=dy, dz=dz, r2=r2) q = openmc.Quadric(*s._get_base_coeffs()) qr = q.rotate((45, 60, 30)) sr = s.rotate((45, 60, 30)) assert qr.is_equal(sr)
def test_sphere(): x, y, z, r = -3, 5, 6, 2 s = openmc.Sphere(x0=x, y0=y, z0=z, r=r) assert s.x0 == x assert s.y0 == y assert s.z0 == z assert s.r == r # Check bounding box ll, ur = (+s).bounding_box assert np.all(np.isinf(ll)) assert np.all(np.isinf(ur)) ll, ur = (-s).bounding_box assert ll == pytest.approx((x - r, y - r, z - r)) assert ur == pytest.approx((x + r, y + r, z + r)) # evaluate method assert s.evaluate((x, y, z)) == pytest.approx(-r**2) # translate method st = s.translate((1.0, 1.0, 1.0)) assert st.x0 == s.x0 + 1 assert st.y0 == s.y0 + 1 assert st.z0 == s.z0 + 1 assert st.r == s.r # rotate method pivot = np.array([1, -2, 3]) sr = s.rotate((90, 90, 90), pivot=pivot) R = np.array([[0, 0, 1], [0, 1, 0], [-1, 0, 0]]) assert sr._origin == pytest.approx((R @ (s._origin - pivot)) + pivot) # test passing in rotation matrix sr2 = s.rotate(R, pivot=pivot) assert sr2._get_base_coeffs() == pytest.approx(sr._get_base_coeffs()) # Make sure repr works repr(s)
def _build_inputs(self): mat = openmc.Material() mat.set_density('g/cm3', 0.998207) mat.add_element('H', 0.111894) mat.add_element('O', 0.888106) materials = openmc.Materials([mat]) materials.export_to_xml() sphere = openmc.Sphere(r=1.0e9, boundary_type='reflective') inside_sphere = openmc.Cell() inside_sphere.region = -sphere inside_sphere.fill = mat geometry = openmc.Geometry([inside_sphere]) geometry.export_to_xml() source = openmc.Source() source.space = openmc.stats.Point((0, 0, 0)) source.angle = openmc.stats.Isotropic() source.energy = openmc.stats.Discrete([10.0e6], [1.0]) source.particle = 'photon' settings = openmc.Settings() settings.particles = 10000 settings.batches = 1 settings.photon_transport = True settings.electron_treatment = 'ttb' settings.cutoff = {'energy_photon': 1000.0} settings.run_mode = 'fixed source' settings.source = source settings.export_to_xml() particle_filter = openmc.ParticleFilter('photon') tally = openmc.Tally() tally.filters = [particle_filter] tally.scores = ['flux', '(n,gamma)'] tallies = openmc.Tallies([tally]) tallies.export_to_xml()
def model(): model = openmc.model.Model() m = openmc.Material() m.set_density('g/cm3', 4.5) m.add_nuclide('U235', 1.0) model.materials.append(m) sph = openmc.Sphere(r=10.0, boundary_type='vacuum') c = openmc.Cell(fill=m, region=-sph) model.geometry = openmc.Geometry([c]) model.settings.particles = 1000 model.settings.inactive = 3 model.settings.batches = 7 model.settings.generations_per_batch = 3 space = openmc.stats.Box((-4.0, -4.0, -4.0), (4.0, 4.0, 4.)) model.settings.source = openmc.Source(space=space) t = openmc.Tally() t.scores = ['flux'] model.tallies.append(t) return model