def test_spatial_legendre(): n = 5 axis = 'x' f = openmc.SpatialLegendreFilter(n, axis, -10., 10.) assert f.order == n assert f.axis == axis assert f.minimum == -10. assert f.maximum == 10. assert f.bins[0] == 'P0' assert f.bins[-1] == 'P5' assert len(f.bins) == n + 1 # Make sure __repr__ works repr(f) # to_xml_element() elem = f.to_xml_element() assert elem.tag == 'filter' assert elem.attrib['type'] == 'spatiallegendre' assert elem.find('order').text == str(n) assert elem.find('axis').text == str(axis) # from_xml_element() new_f = openmc.Filter.from_xml_element(elem) assert new_f.id == f.id assert new_f.order == f.order assert new_f.axis == f.axis
def test_first_moment(run_in_tmpdir, box_model): plain_tally = openmc.Tally() plain_tally.scores = ['flux', 'scatter'] # Create tallies with expansion filters leg_tally = openmc.Tally() leg_tally.filters = [openmc.LegendreFilter(3)] leg_tally.scores = ['scatter'] leg_sptl_tally = openmc.Tally() leg_sptl_tally.filters = [openmc.SpatialLegendreFilter(3, 'x', -5., 5.)] leg_sptl_tally.scores = ['scatter'] sph_scat_filter = openmc.SphericalHarmonicsFilter(5) sph_scat_filter.cosine = 'scatter' sph_scat_tally = openmc.Tally() sph_scat_tally.filters = [sph_scat_filter] sph_scat_tally.scores = ['scatter'] sph_flux_filter = openmc.SphericalHarmonicsFilter(5) sph_flux_filter.cosine = 'particle' sph_flux_tally = openmc.Tally() sph_flux_tally.filters = [sph_flux_filter] sph_flux_tally.scores = ['flux'] zernike_tally = openmc.Tally() zernike_tally.filters = [openmc.ZernikeFilter(3, r=10.)] zernike_tally.scores = ['scatter'] # Add tallies to model and ensure they all use the same estimator box_model.tallies = [ plain_tally, leg_tally, leg_sptl_tally, sph_scat_tally, sph_flux_tally, zernike_tally ] for t in box_model.tallies: t.estimator = 'analog' sp_name = box_model.run() # Check that first moment matches the score from the plain tally with openmc.StatePoint(sp_name) as sp: # Get scores from tally without expansion filters flux, scatter = sp.tallies[plain_tally.id].mean.ravel() # Check that first moment matches first_score = lambda t: sp.tallies[t.id].mean.ravel()[0] assert first_score(leg_tally) == scatter assert first_score(leg_sptl_tally) == scatter assert first_score(sph_scat_tally) == scatter assert first_score(sph_flux_tally) == approx(flux) assert first_score(zernike_tally) == approx(scatter)
def generate_tallies(fuelcelllist, total_fuel_cell, porder, flag): tallies_file = openmc.Tallies() cell_filter = openmc.CellFilter(fuelcelllist) total_fuel_cell_filter = openmc.CellFilter([total_fuel_cell]) zmin = -100 zmax = 100 if flag == 1: # choose flag 1, we use tradiational estimators tally3 = openmc.Tally(name='tracklength') tally3.filters.append(cell_filter) tally3.scores = ['nu-fission', 'absorption'] tally3.nuclides = ['U238'] tally3.estimator = 'tracklength' tallies_file.append(tally3) tally3 = openmc.Tally(name='collision') tally3.filters.append(cell_filter) tally3.scores = ['nu-fission', 'absorption'] tally3.nuclides = ['U238'] tally3.estimator = 'collision' tallies_file.append(tally3) # tally3 = openmc.Tally(name='analog') # tally3.filters.append(cell_filter) # tally3.scores = ['flux'] # tally3.nuclides = ['U238'] # tally3.estimator = 'analog' # tallies_file.append(tally3) elif flag == 2: # we tally FET str1 = 'fet' strorder = str(porder) name = str1 + strorder fet_tally = openmc.Tally(name=name) fet_tally.filters.append(total_fuel_cell_filter) fet_tally.scores = ['nu-fission', 'absorption'] fet_tally.nuclides = ['U238'] expand_filter = openmc.SpatialLegendreFilter(porder, 'z', zmin, zmax) fet_tally.filters.append(expand_filter) tallies_file.append(fet_tally) tallies_file.export_to_xml()
def build_homog_input_files(order, source_loc, bc, prob_size, num_neutrons, num_batches, SE_dim, seed, dir): os.system("mkdir -p {dir}".format(dir=dir)) os.chdir(dir) xmin = -1. * prob_size[0] / 2. xmax = prob_size[0] / 2. ymin = -1. * prob_size[1] / 2. ymax = prob_size[1] / 2. zmin = -1. * prob_size[2] / 2. zmax = prob_size[2] / 2. # Instantiate some Materials and register the appropriate Nuclides uranyl_sulf = openmc.Material(name='Uranyl Sulfate') uranyl_sulf.set_density("atom/b-cm", 9.9035E-02) uranyl_sulf.add_nuclide("U235", 9.6795E-05) uranyl_sulf.add_nuclide("U234", 7.4257E-07) uranyl_sulf.add_nuclide("U238", 5.5518E-04) uranyl_sulf.add_nuclide("S32", 6.5272E-04) uranyl_sulf.add_nuclide("O16", 3.5185E-02) uranyl_sulf.add_nuclide("H1", 6.2538E-02) uranyl_sulf.add_s_alpha_beta('c_H_in_H2O') uranyl_sulf.depletable = False # Instantiate a Materials collection and export to XML materials_file = openmc.Materials([uranyl_sulf]) materials_file.export_to_xml() # Instantiate planar surfaces x1 = openmc.XPlane(x0=xmin) x2 = openmc.XPlane(x0=xmax) y1 = openmc.YPlane(y0=ymin) y2 = openmc.YPlane(y0=ymax) z1 = openmc.ZPlane(z0=zmin) z2 = openmc.ZPlane(z0=zmax) # Set boundary conditions surface_list = [x1, x2, y1, y2, z1, z2] for i in range(len(surface_list)): surface = surface_list[i] surface.boundary_type = bc[i] # Define Cell, Region, and Fill uran_sulf_sol = openmc.Cell(name='uranyl sulfate solution') uran_sulf_sol.region = +x1 & -x2 & +y1 & -y2 & +z1 & -z2 uran_sulf_sol.fill = uranyl_sulf # Instantiate root universe root = openmc.Universe(name='root universe') root.add_cells([uran_sulf_sol]) # Instantiate a Geometry, register the root Universe, and export to XML geometry = openmc.Geometry(root) geometry.export_to_xml() # Define runtime settings settings = openmc.Settings() point_source = openmc.stats.Point(xyz=source_loc) settings.source = openmc.Source(space=point_source) settings.batches = num_batches settings.inactive = num_batches - 1 settings.particles = num_neutrons # Define entropy mesh entropy_mesh = openmc.RegularMesh() entropy_mesh.lower_left = [xmin, ymin, zmin] entropy_mesh.upper_right = [xmax, ymax, zmax] entropy_mesh.dimension = SE_dim settings.entropy_mesh = entropy_mesh settings.seed = seed settings.export_to_xml() # Create a nu-fission tally nu_fiss_tally = openmc.Tally() nu_fiss_tally.scores = ['nu-fission'] # Create a Legendre polynomial expansion filter and add to tally expand_filter = openmc.SpatialLegendreFilter(order, 'z', zmin, zmax) nu_fiss_tally.filters.append(expand_filter) tallies = openmc.Tallies([nu_fiss_tally]) tallies.export_to_xml() os.chdir("./..")