from openmc.examples import slab_mg if __name__ == '__main__': model = slab_mg(as_macro=False) # Instantiate a tally mesh mesh = openmc.Mesh(mesh_id=1) mesh.type = 'regular' mesh.dimension = [1, 1, 10] mesh.lower_left = [0.0, 0.0, 0.0] mesh.upper_right = [10, 10, 5] # Instantiate some tally filters energy_filter = openmc.EnergyFilter([0.0, 20.0e6]) energyout_filter = openmc.EnergyoutFilter([0.0, 20.0e6]) energies = [1e-5, 0.0635, 10.0, 1.0e2, 1.0e3, 0.5e6, 1.0e6, 20.0e6] matching_energy_filter = openmc.EnergyFilter(energies) matching_eout_filter = openmc.EnergyoutFilter(energies) mesh_filter = openmc.MeshFilter(mesh) mat_filter = openmc.MaterialFilter(model.materials) nuclides = model.xs_data scores = {False: ['total', 'absorption', 'flux', 'fission', 'nu-fission'], True: ['total', 'absorption', 'fission', 'nu-fission']} for do_nuclides in [False, True]: t = openmc.Tally() t.filters = [mesh_filter]
def test_mg_tallies(): create_library() model = slab_mg() # Instantiate a tally mesh mesh = openmc.RegularMesh(mesh_id=1) mesh.dimension = [10, 1, 1] mesh.lower_left = [0.0, 0.0, 0.0] mesh.upper_right = [929.45, 1000, 1000] # Instantiate some tally filters energy_filter = openmc.EnergyFilter([0.0, 20.0e6]) energyout_filter = openmc.EnergyoutFilter([0.0, 20.0e6]) energies = [0.0, 0.625, 20.0e6] matching_energy_filter = openmc.EnergyFilter(energies) matching_eout_filter = openmc.EnergyoutFilter(energies) mesh_filter = openmc.MeshFilter(mesh) mat_filter = openmc.MaterialFilter(model.materials) nuclides = model.xs_data scores_with_nuclides = [ 'total', 'absorption', 'fission', 'nu-fission', 'inverse-velocity', 'prompt-nu-fission', 'delayed-nu-fission', 'kappa-fission', 'events', 'decay-rate' ] scores_without_nuclides = scores_with_nuclides + ['flux'] for do_nuclides, scores in ((False, scores_without_nuclides), (True, scores_with_nuclides)): t = openmc.Tally() t.filters = [mesh_filter] t.estimator = 'analog' t.scores = scores if do_nuclides: t.nuclides = nuclides model.tallies.append(t) t = openmc.Tally() t.filters = [mesh_filter] t.estimator = 'tracklength' t.scores = scores if do_nuclides: t.nuclides = nuclides model.tallies.append(t) # Impose energy bins that dont match the MG structure and those # that do for match_energy_bins in [False, True]: if match_energy_bins: e_filter = matching_energy_filter eout_filter = matching_eout_filter else: e_filter = energy_filter eout_filter = energyout_filter t = openmc.Tally() t.filters = [mat_filter, e_filter] t.estimator = 'analog' t.scores = scores + ['scatter', 'nu-scatter'] if do_nuclides: t.nuclides = nuclides model.tallies.append(t) t = openmc.Tally() t.filters = [mat_filter, e_filter] t.estimator = 'collision' t.scores = scores if do_nuclides: t.nuclides = nuclides model.tallies.append(t) t = openmc.Tally() t.filters = [mat_filter, e_filter] t.estimator = 'tracklength' t.scores = scores if do_nuclides: t.nuclides = nuclides model.tallies.append(t) t = openmc.Tally() t.filters = [mat_filter, e_filter, eout_filter] t.scores = ['scatter', 'nu-scatter', 'nu-fission'] if do_nuclides: t.nuclides = nuclides model.tallies.append(t) harness = MGXSTestHarness('statepoint.10.h5', model) harness.main()
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # Set settings explicitly self._model.settings.batches = 3 self._model.settings.inactive = 0 self._model.settings.particles = 100 self._model.settings.source = openmc.Source( space=openmc.stats.Box([-160, -160, -183], [160, 160, 183])) self._model.settings.temperature['multipole'] = True filt_mats = openmc.MaterialFilter((1, 3)) filt_eout = openmc.EnergyoutFilter((0.0, 0.625, 20.0e6)) # We want density derivatives for both water and fuel to get coverage # for both fissile and non-fissile materials. d1 = openmc.TallyDerivative(derivative_id=1) d1.variable = 'density' d1.material = 3 d2 = openmc.TallyDerivative(derivative_id=2) d2.variable = 'density' d2.material = 1 # O-16 is a good nuclide to test against because it is present in both # water and fuel. Some routines need to recognize that they have the # perturbed nuclide but not the perturbed material. d3 = openmc.TallyDerivative(derivative_id=3) d3.variable = 'nuclide_density' d3.material = 1 d3.nuclide = 'O16' # A fissile nuclide, just for good measure. d4 = openmc.TallyDerivative(derivative_id=4) d4.variable = 'nuclide_density' d4.material = 1 d4.nuclide = 'U235' # Temperature derivatives. d5 = openmc.TallyDerivative(derivative_id=5) d5.variable = 'temperature' d5.material = 1 derivs = [d1, d2, d3, d4, d5] # Cover the flux score. for i in range(5): t = openmc.Tally() t.scores = ['flux'] t.filters = [filt_mats] t.derivative = derivs[i] self._model.tallies.append(t) # Cover supported scores with a collision estimator. for i in range(5): t = openmc.Tally() t.scores = [ 'total', 'absorption', 'scatter', 'fission', 'nu-fission' ] t.filters = [filt_mats] t.nuclides = ['total', 'U235'] t.derivative = derivs[i] self._model.tallies.append(t) # Cover an analog estimator. for i in range(5): t = openmc.Tally() t.scores = ['absorption'] t.filters = [filt_mats] t.estimator = 'analog' t.derivative = derivs[i] self._model.tallies.append(t) # Energyout filter and total nuclide for the density derivatives. for i in range(2): t = openmc.Tally() t.scores = ['nu-fission', 'scatter'] t.filters = [filt_mats, filt_eout] t.nuclides = ['total', 'U235'] t.derivative = derivs[i] self._model.tallies.append(t) # Energyout filter without total nuclide for other derivatives. for i in range(2, 5): t = openmc.Tally() t.scores = ['nu-fission', 'scatter'] t.filters = [filt_mats, filt_eout] t.nuclides = ['U235'] t.derivative = derivs[i] self._model.tallies.append(t)
# Create an initial uniform spatial source distribution over fissionable zones bounds = [-4., -4., -4., 4., 4., 4.] uniform_dist = openmc.stats.Box(bounds[:3], bounds[3:], only_fissionable=True) settings_file.source = openmc.source.Source(space=uniform_dist) settings_file.export_to_xml() ############################################################################### # Exporting to OpenMC tallies.xml file ############################################################################### # Instantiate some tally Filters cell_filter = openmc.CellFilter(cell2) energy_filter = openmc.EnergyFilter([0., 20.e6]) energyout_filter = openmc.EnergyoutFilter([0., 20.e6]) # Instantiate the first Tally first_tally = openmc.Tally(tally_id=1, name='first tally') first_tally.filters = [cell_filter] scores = ['total', 'scatter', 'nu-scatter', 'absorption', 'fission', 'nu-fission'] first_tally.scores = scores # Instantiate the second Tally second_tally = openmc.Tally(tally_id=2, name='second tally') second_tally.filters = [cell_filter, energy_filter] second_tally.scores = scores # Instantiate the third Tally third_tally = openmc.Tally(tally_id=3, name='third tally')