def pincell_model(): """Set up a model to test with and delete files when done""" openmc.reset_auto_ids() pincell = openmc.examples.pwr_pin_cell() pincell.settings.verbosity = 1 # Add a tally filter1 = openmc.MaterialFilter(pincell.materials) filter2 = openmc.EnergyFilter([0.0, 1.0, 1.0e3, 20.0e6]) mat_tally = openmc.Tally() mat_tally.filters = [filter1, filter2] mat_tally.nuclides = ['U235', 'U238'] mat_tally.scores = ['total', 'elastic', '(n,gamma)'] pincell.tallies.append(mat_tally) # Add an expansion tally zernike_tally = openmc.Tally() filter3 = openmc.ZernikeFilter(5, r=.63) cells = pincell.geometry.root_universe.cells filter4 = openmc.CellFilter(list(cells.values())) zernike_tally.filters = [filter3, filter4] zernike_tally.scores = ['fission'] pincell.tallies.append(zernike_tally) # Add an energy function tally energyfunc_tally = openmc.Tally() energyfunc_filter = openmc.EnergyFunctionFilter([0.0, 20e6], [0.0, 20e6]) energyfunc_tally.scores = ['fission'] energyfunc_tally.filters = [energyfunc_filter] pincell.tallies.append(energyfunc_tally) # Write XML files in tmpdir with cdtemp(): pincell.export_to_xml() yield
def pincell_model_w_univ(): """Set up a model to test with and delete files when done""" openmc.reset_auto_ids() pincell = openmc.examples.pwr_pin_cell() clad_univ = openmc.Universe(cells=[openmc.Cell(fill=pincell.materials[1])]) pincell.geometry.root_universe.cells[2].fill = clad_univ pincell.settings.verbosity = 1 # Write XML files in tmpdir with cdtemp(): pincell.export_to_xml() yield
def dagmc_model(request): model = openmc.model.Model() # settings model.settings.batches = 5 model.settings.inactive = 0 model.settings.particles = 100 model.settings.temperature = {'tolerance': 50.0} model.settings.verbosity = 1 source_box = openmc.stats.Box([-4, -4, -4], [4, 4, 4]) source = openmc.Source(space=source_box) model.settings.source = source # geometry dagmc_universe = openmc.DAGMCUniverse('dagmc.h5m') model.geometry = openmc.Geometry(dagmc_universe) # tally tally = openmc.Tally() tally.scores = ['total'] tally.filters = [openmc.CellFilter(1)] model.tallies = [tally] # materials u235 = openmc.Material(name="no-void fuel") u235.add_nuclide('U235', 1.0, 'ao') u235.set_density('g/cc', 11) u235.id = 40 u235.temperature = 320 water = openmc.Material(name="water") water.add_nuclide('H1', 2.0, 'ao') water.add_nuclide('O16', 1.0, 'ao') water.set_density('g/cc', 1.0) water.add_s_alpha_beta('c_H_in_H2O') water.id = 41 mats = openmc.Materials([u235, water]) model.materials = mats # location of dagmc file in test directory dagmc_file = request.fspath.dirpath() + "/dagmc.h5m" # move to a temporary directory with cdtemp(): shutil.copyfile(dagmc_file, "./dagmc.h5m") model.export_to_xml() openmc.lib.init() yield openmc.lib.finalize()
def test_weightwindows(model): ww_files = ('ww_n.txt', 'ww_p.txt') cwd = Path(__file__).parent.absolute() filepaths = [cwd / Path(f) for f in ww_files] with cdtemp(filepaths): # run once with variance reduction off model.settings.weight_windows_on = False analog_sp = model.run() os.rename(analog_sp, 'statepoint.analog.h5') # weight windows # load pre-generated weight windows # (created using the same tally as above) ww_n_lower_bnds = np.loadtxt('ww_n.txt') ww_p_lower_bnds = np.loadtxt('ww_p.txt') # create a mesh matching the one used # to generate the weight windows ww_mesh = openmc.RegularMesh() ww_mesh.lower_left = (-240, -240, -240) ww_mesh.upper_right = (240, 240, 240) ww_mesh.dimension = (5, 6, 7) # energy bounds matching those of the # generated weight windows e_bnds = [0.0, 0.5, 2E7] ww_n = openmc.WeightWindows(ww_mesh, ww_n_lower_bnds, None, 10.0, e_bnds, survival_ratio=1.01) ww_p = openmc.WeightWindows(ww_mesh, ww_p_lower_bnds, None, 10.0, e_bnds, survival_ratio=1.01) model.settings.weight_windows = [ww_n, ww_p] # run again with variance reduction on model.settings.weight_windows_on = True ww_sp = model.run() os.rename(ww_sp, 'statepoint.ww.h5') # load both statepoints and examine results asp = openmc.StatePoint('statepoint.analog.h5') wsp = openmc.StatePoint('statepoint.ww.h5') analog_tally = asp.tallies[1] ww_tally = wsp.tallies[1] def compare_results(particle, analog_tally, ww_tally): # get values from each of the tallies an_mean = analog_tally.get_values(filters=[openmc.ParticleFilter], filter_bins=[(particle, )]) ww_mean = ww_tally.get_values(filters=[openmc.ParticleFilter], filter_bins=[(particle, )]) # expect that more bins were scored with weight windows than # the analog run assert np.count_nonzero(an_mean) < np.count_nonzero(ww_mean) an_rel_err = analog_tally.get_values( filters=[openmc.ParticleFilter], filter_bins=[(particle, )], value='rel_err') ww_rel_err = ww_tally.get_values(filters=[openmc.ParticleFilter], filter_bins=[(particle, )], value='rel_err') an_rel_err[an_mean == 0.0] = 1.0 ww_rel_err[ww_mean == 0.0] = 1.0 an_avg_rel_err = np.mean(an_rel_err) ww_avg_rel_err = np.mean(ww_rel_err) # expect that the average relative error in the tally # decreases assert an_avg_rel_err > ww_avg_rel_err # ensure that the value of the mesh bin containing the # source is statistically similar in both runs an_std_dev = analog_tally.get_values( filters=[openmc.ParticleFilter], filter_bins=[(particle, )], value='std_dev') ww_std_dev = ww_tally.get_values(filters=[openmc.ParticleFilter], filter_bins=[(particle, )], value='std_dev') # index of the mesh bin containing the source for the higher # energy group source_bin_idx = (an_mean.shape[0] // 2, 0, 0) an_source_bin = ufloat(an_mean[source_bin_idx], an_std_dev[source_bin_idx]) ww_source_bin = ufloat(ww_mean[source_bin_idx], ww_std_dev[source_bin_idx]) diff = an_source_bin - ww_source_bin # check that values are within two combined standard deviations assert abs(diff.nominal_value) / diff.std_dev < 2.0 compare_results('neutron', analog_tally, ww_tally) compare_results('photon', analog_tally, ww_tally)