def __init__(self, *args, **kwargs): super(FilterMeshTestHarness, self).__init__(*args, **kwargs) # Initialize Meshes mesh_1d = openmc.Mesh(mesh_id=1) mesh_1d.type = 'regular' mesh_1d.dimension = [17] mesh_1d.lower_left = [-182.07] mesh_1d.upper_right = [182.07] mesh_2d = openmc.Mesh(mesh_id=2) mesh_2d.type = 'regular' mesh_2d.dimension = [17, 17] mesh_2d.lower_left = [-182.07, -182.07] mesh_2d.upper_right = [182.07, 182.07] mesh_3d = openmc.Mesh(mesh_id=3) mesh_3d.type = 'regular' mesh_3d.dimension = [17, 17, 17] mesh_3d.lower_left = [-182.07, -182.07, -183.00] mesh_3d.upper_right = [182.07, 182.07, 183.00] # Initialize the filters mesh_1d_filter = openmc.MeshFilter(mesh_1d) mesh_2d_filter = openmc.MeshFilter(mesh_2d) mesh_3d_filter = openmc.MeshFilter(mesh_3d) # Initialized the tallies tally = openmc.Tally(name='tally 1') tally.filters = [mesh_1d_filter] tally.scores = ['total'] self._model.tallies.append(tally) tally = openmc.Tally(name='tally 2') tally.filters = [mesh_1d_filter] tally.scores = ['current'] self._model.tallies.append(tally) tally = openmc.Tally(name='tally 3') tally.filters = [mesh_2d_filter] tally.scores = ['total'] self._model.tallies.append(tally) tally = openmc.Tally(name='tally 4') tally.filters = [mesh_2d_filter] tally.scores = ['current'] self._model.tallies.append(tally) tally = openmc.Tally(name='tally 5') tally.filters = [mesh_3d_filter] tally.scores = ['total'] self._model.tallies.append(tally) tally = openmc.Tally(name='tally 6') tally.filters = [mesh_3d_filter] tally.scores = ['current'] self._model.tallies.append(tally)
def __init__(self, *args, **kwargs): super(TallyArithmeticTestHarness, self).__init__(*args, **kwargs) # Initialize Mesh mesh = openmc.Mesh(mesh_id=1) mesh.type = 'regular' mesh.dimension = [2, 2, 2] mesh.lower_left = [-160.0, -160.0, -183.0] mesh.upper_right = [160.0, 160.0, 183.0] # Initialize the filters energy_filter = openmc.EnergyFilter((0.0, 0.253e-6, 1.0e-3, 1.0, 20.0)) material_filter = openmc.MaterialFilter((1, 3)) distrib_filter = openmc.DistribcellFilter(60) mesh_filter = openmc.MeshFilter(mesh) # Initialized the tallies tally = openmc.Tally(name='tally 1') tally.filters = [material_filter, energy_filter, distrib_filter] tally.scores = ['nu-fission', 'total'] tally.nuclides = ['U234', 'U235'] self._model.tallies.append(tally) tally = openmc.Tally(name='tally 2') tally.filters = [energy_filter, mesh_filter] tally.scores = ['total', 'fission'] tally.nuclides = ['U238', 'U235'] self._model.tallies.append(tally)
def make_tallies(self, r=None): if not self.tally: return None if self.geom == 'IN': return None # Instantiate a tally mesh mesh = openmc.Mesh(mesh_id=1) mesh.type = 'regular' mesh.dimension = self.mesh_dim if self.geom == 'SL' or self.geom == 'ISLC': mesh.lower_left = [-r, -INF, -INF] mesh.upper_right = [r, INF, INF] # Instantiate some tally Filters energy_filter = openmc.EnergyFilter( GROUP_STRUCT[self.groups].group_edges) mesh_filter = openmc.MeshFilter(mesh) # Instantiate the Tally tally = openmc.Tally(tally_id=1, name='tally 1') tally.filters = [energy_filter, mesh_filter] tally.scores = ['flux', 'fission', 'nu-fission'] # Instantiate a Tallies collection, register all Tallies tallies_file = openmc.Tallies([tally]) return tallies_file
def _build_inputs(self): filt1 = openmc.Filter(type='mu', bins=(-1.0, -0.5, 0.0, 0.5, 1.0)) tally1 = openmc.Tally(tally_id=1) tally1.add_filter(filt1) tally1.add_score('scatter') tally1.add_score('nu-scatter') filt2 = openmc.Filter(type='mu', bins=(5, )) tally2 = openmc.Tally(tally_id=2) tally2.add_filter(filt2) tally2.add_score('scatter') tally2.add_score('nu-scatter') mesh = openmc.Mesh(mesh_id=1) mesh.lower_left = [-182.07, -182.07] mesh.upper_right = [182.07, 182.07] mesh.dimension = [2, 2] filt_mesh = openmc.Filter(type='mesh', bins=(1, )) tally3 = openmc.Tally(tally_id=3) tally3.add_filter(filt2) tally3.add_filter(filt_mesh) tally3.add_score('scatter') tally3.add_score('nu-scatter') self._input_set.tallies = openmc.TalliesFile() self._input_set.tallies.add_tally(tally1) self._input_set.tallies.add_tally(tally2) self._input_set.tallies.add_tally(tally3) self._input_set.tallies.add_mesh(mesh) super(FilterMuTestHarness, self)._build_inputs()
def __init__(self, *args, **kwargs): super(MGXSTestHarness, self).__init__(*args, **kwargs) # Initialize a one-group structure energy_groups = openmc.mgxs.EnergyGroups(group_edges=[0, 20.e6]) # Initialize MGXS Library for a few cross section types # for one material-filled cell in the geometry self.mgxs_lib = openmc.mgxs.Library(self._model.geometry) self.mgxs_lib.by_nuclide = False # Test all MGXS types self.mgxs_lib.mgxs_types = openmc.mgxs.MGXS_TYPES + \ openmc.mgxs.MDGXS_TYPES self.mgxs_lib.energy_groups = energy_groups self.mgxs_lib.num_delayed_groups = 6 self.mgxs_lib.legendre_order = 3 self.mgxs_lib.domain_type = 'mesh' # Instantiate a tally mesh mesh = openmc.Mesh(mesh_id=1) mesh.type = 'regular' mesh.dimension = [2, 2] mesh.lower_left = [-100., -100.] mesh.width = [100., 100.] self.mgxs_lib.domains = [mesh] self.mgxs_lib.build_library() # Add tallies self.mgxs_lib.add_to_tallies_file(self._model.tallies, merge=False)
def _build_inputs(self): # Instantiate a tally mesh mesh = openmc.Mesh(mesh_id=1) mesh.type = 'regular' mesh.dimension = [17, 17, 1] mesh.lower_left = [0.0, 0.0, 0.0] mesh.upper_right = [21.42, 21.42, 100.0] # Instantiate some tally filters energy_filter = openmc.Filter(type='energy', bins=[0.0, 20.0]) energyout_filter = openmc.Filter(type='energyout', bins=[0.0, 20.0]) mesh_filter = openmc.Filter() mesh_filter.mesh = mesh mat_filter = openmc.Filter(type='material', bins=[1, 2, 3]) tally1 = openmc.Tally(tally_id=1) tally1.filters = [mesh_filter] tally1.scores = [ 'total', 'absorption', 'flux', 'fission', 'nu-fission' ] tally2 = openmc.Tally(tally_id=2) tally2.filters = [mat_filter, energy_filter, energyout_filter] tally2.scores = ['scatter', 'nu-scatter'] self._input_set.tallies = openmc.Tallies([tally1, tally2]) super(MGTalliesTestHarness, self)._build_inputs()
def meshes(self): if not self._meshes_read: # Initialize dictionaries for the Meshes # Keys - Mesh IDs # Values - Mesh objects self._meshes = {} # Read the number of Meshes n_meshes = self._f['tallies/meshes/n_meshes'].value # Read a list of the IDs for each Mesh if n_meshes > 0: # User-defined Mesh IDs mesh_keys = self._f['tallies/meshes/keys'].value else: mesh_keys = [] # Build dictionary of Meshes base = 'tallies/meshes/mesh ' # Iterate over all Meshes for mesh_key in mesh_keys: # Read the mesh type mesh_type = self._f['{0}{1}/type'.format( base, mesh_key)].value.decode() # Read the mesh dimensions, lower-left coordinates, # upper-right coordinates, and width of each mesh cell dimension = self._f['{0}{1}/dimension'.format(base, mesh_key)].value lower_left = self._f['{0}{1}/lower_left'.format( base, mesh_key)].value upper_right = self._f['{0}{1}/upper_right'.format( base, mesh_key)].value width = self._f['{0}{1}/width'.format(base, mesh_key)].value # Create the Mesh and assign properties to it mesh = openmc.Mesh(mesh_key) mesh.dimension = dimension mesh.width = width mesh.lower_left = lower_left mesh.upper_right = upper_right mesh.type = mesh_type # Add mesh to the global dictionary of all Meshes self._meshes[mesh_key] = mesh self._meshes_read = True return self._meshes
def _build_inputs(self): # The summary.h5 file needs to be created to read in the tallies self._input_set.settings.output = {'summary': True} # Initialize the tallies file tallies_file = openmc.Tallies() # Initialize the nuclides u235 = openmc.Nuclide('U-235') u238 = openmc.Nuclide('U-238') pu239 = openmc.Nuclide('Pu-239') # Initialize Mesh mesh = openmc.Mesh(mesh_id=1) mesh.type = 'regular' mesh.dimension = [2, 2, 2] mesh.lower_left = [-160.0, -160.0, -183.0] mesh.upper_right = [160.0, 160.0, 183.0] # Initialize the filters energy_filter = openmc.Filter(type='energy', bins=(0.0, 0.253e-6, 1.0e-3, 1.0, 20.0)) material_filter = openmc.Filter(type='material', bins=(1, 3)) distrib_filter = openmc.Filter(type='distribcell', bins=(60)) mesh_filter = openmc.Filter(type='mesh') mesh_filter.mesh = mesh # Initialized the tallies tally = openmc.Tally(name='tally 1') tally.filters = [material_filter, energy_filter, distrib_filter] tally.scores = ['nu-fission', 'total'] tally.nuclides = [u235, pu239] tallies_file.append(tally) tally = openmc.Tally(name='tally 2') tally.filters = [energy_filter, mesh_filter] tally.scores = ['total', 'fission'] tally.nuclides = [u238, u235] tallies_file.append(tally) # Export tallies to file self._input_set.tallies = tallies_file super(TallyArithmeticTestHarness, self)._build_inputs()
def create_tally(radius): """Create tally mesh??? """ tallies_file = openmc.Tallies() mesh = openmc.Mesh() mesh.dimension = [100, 100] mesh.lower_left = [-radius, -radius] mesh.upper_right = [radius, radius] mesh_filter = openmc.MeshFilter(mesh) mesh_filter.mesh = mesh tally = openmc.Tally(name='flux') tally.filters = [mesh_filter] tally.scores = ['flux', 'fission'] tallies_file.append(tally) tallies_file.export_to_xml()
def model(): model = openmc.model.Model() fuel = openmc.Material() fuel.set_density('g/cm3', 10.0) fuel.add_nuclide('U235', 1.0) zr = openmc.Material() zr.set_density('g/cm3', 1.0) zr.add_nuclide('Zr90', 1.0) model.materials.extend([fuel, zr]) box1 = openmc.model.rectangular_prism(10.0, 10.0) box2 = openmc.model.rectangular_prism(20.0, 20.0, boundary_type='reflective') top = openmc.ZPlane(z0=10.0, boundary_type='vacuum') bottom = openmc.ZPlane(z0=-10.0, boundary_type='vacuum') cell1 = openmc.Cell(fill=fuel, region=box1 & +bottom & -top) cell2 = openmc.Cell(fill=zr, region=~box1 & box2 & +bottom & -top) model.geometry = openmc.Geometry([cell1, cell2]) model.settings.batches = 5 model.settings.inactive = 0 model.settings.particles = 1000 mesh = openmc.Mesh() mesh.lower_left = (-10.0, -10.0, -10.0) mesh.upper_right = (10.0, 10.0, 10.0) mesh.dimension = (3, 3, 3) mesh_surface_filter = openmc.MeshSurfaceFilter(mesh) energy_filter = openmc.EnergyFilter([0.0, 0.253, 20.0e6]) tally1 = openmc.Tally() tally1.filters = [mesh_surface_filter] tally1.scores = ['current'] tally2 = openmc.Tally() tally2.filters = [mesh_surface_filter, energy_filter] tally2.scores = ['current'] model.tallies.extend([tally1, tally2]) return model
def generate_settings_xml(self): """ Generates settings.xml. This function creates settings.xml using the value of the settings variable. Todo ---- Rewrite to generalize source box. """ if self.rank == 0: batches = self.settings.batches inactive = self.settings.inactive particles = self.settings.particles # Just a generic settings file to get it running. settings_file = openmc.Settings() settings_file.batches = batches settings_file.inactive = inactive settings_file.particles = particles settings_file.source = openmc.Source( space=Box(self.settings.lower_left, self.settings.upper_right)) if self.settings.entropy_dimension is not None: entropy_mesh = openmc.Mesh() entropy_mesh.lower_left = self.settings.lower_left entropy_mesh.upper_right = self.settings.upper_right entropy_mesh.dimension = self.settings.entropy_dimension settings_file.entropy_mesh = entropy_mesh # Set seed if self.settings.constant_seed is not None: seed = self.settings.constant_seed else: seed = random.randint(1, sys.maxsize - 1) settings_file.seed = self.seed = seed settings_file.export_to_xml()
def _build_inputs(self): filt1 = openmc.Filter(type='polar', bins=(0.0, 0.6283, 1.2566, 1.8850, 2.5132, 3.1416)) tally1 = openmc.Tally(tally_id=1) tally1.add_filter(filt1) tally1.add_score('flux') tally1.estimator = 'tracklength' tally2 = openmc.Tally(tally_id=2) tally2.add_filter(filt1) tally2.add_score('flux') tally2.estimator = 'analog' filt3 = openmc.Filter(type='polar', bins=(5, )) tally3 = openmc.Tally(tally_id=3) tally3.add_filter(filt3) tally3.add_score('flux') tally3.estimator = 'tracklength' mesh = openmc.Mesh(mesh_id=1) mesh.lower_left = [-182.07, -182.07] mesh.upper_right = [182.07, 182.07] mesh.dimension = [2, 2] filt_mesh = openmc.Filter(type='mesh', bins=(1, )) tally4 = openmc.Tally(tally_id=4) tally4.add_filter(filt3) tally4.add_filter(filt_mesh) tally4.add_score('flux') tally4.estimator = 'tracklength' self._input_set.tallies = openmc.TalliesFile() self._input_set.tallies.add_tally(tally1) self._input_set.tallies.add_tally(tally2) self._input_set.tallies.add_tally(tally3) self._input_set.tallies.add_tally(tally4) self._input_set.tallies.add_mesh(mesh) super(FilterPolarTestHarness, self)._build_inputs()
p.width = (220, 220) p.pixels = (3000, 3000) p.origin = (0, 0, 105) p.color_by = 'material' p.colors = {uo2: 'yellow', na: 'blue', stainless: 'black', He: 'grey'} plots = openmc.Plots([p]) plots.export_to_xml() openmc.plot_geometry() get_ipython().system('convert coreplot.ppm core1.png') tallies = openmc.Tallies() # Create mesh which will be used for tally mesh_core = openmc.Mesh() mesh_core.dimension = [21, 1, 1] mesh_core.lower_left = (-100, -100, 0) mesh_core.upper_right = (100, 100, 160) # Create filter for tally mesh_filtercore = openmc.MeshFilter(mesh_core) core_filter = openmc.UniverseFilter([a1, a2, a3, a4, ba]) energy_filter = openmc.EnergyFilter([0.0, 1.0, 1.0e5, 2.0e7]) # Create mesh tally to score flux and fission rate tally_core = openmc.Tally(name='flux') tally_core.filters = [mesh_filtercore] tally_core.scores = ['fission-q-prompt'] tallies.append(tally_core) tallies.export_to_xml()
############################################################################### # Transport calculation settings ############################################################################### # Instantiate a Settings object, set all runtime parameters settings_file = openmc.Settings() settings_file.batches = batches settings_file.inactive = inactive settings_file.particles = particles # Create an initial uniform spatial source distribution over fissionable zones bounds = [-0.62992, -0.62992, -1, 0.62992, 0.62992, 1] uniform_dist = openmc.stats.Box(bounds[:3], bounds[3:], only_fissionable=True) settings_file.source = openmc.source.Source(space=uniform_dist) entropy_mesh = openmc.Mesh() entropy_mesh.lower_left = [-0.39218, -0.39218, -1.e50] entropy_mesh.upper_right = [0.39218, 0.39218, 1.e50] entropy_mesh.dimension = [10, 10, 1] settings_file.entropy_mesh = entropy_mesh ############################################################################### # Initialize and run depletion calculation ############################################################################### op = openmc.deplete.Operator(geometry, settings_file, chain_file, previous_results) # Perform simulation using the predictor algorithm openmc.deplete.integrator.predictor(op, time_steps, power)
def _build_inputs(self): # The summary.h5 file needs to be created to read in the tallies self._input_set.settings.output = {'summary': True} # Initialize the tallies file tallies_file = openmc.Tallies() # Define nuclides and scores to add to both tallies self.nuclides = ['U-235', 'U-238'] self.scores = ['fission', 'nu-fission'] # Define filters for energy and spatial domain low_energy = openmc.Filter(type='energy', bins=[0., 0.625e-6]) high_energy = openmc.Filter(type='energy', bins=[0.625e-6, 20.]) merged_energies = low_energy.merge(high_energy) cell_21 = openmc.Filter(type='cell', bins=[21]) cell_27 = openmc.Filter(type='cell', bins=[27]) distribcell_filter = openmc.Filter(type='distribcell', bins=[21]) mesh = openmc.Mesh(name='mesh') mesh.type = 'regular' mesh.dimension = [2, 2] mesh.lower_left = [-50., -50.] mesh.upper_right = [+50., +50.] mesh_filter = openmc.Filter(type='mesh', bins=[mesh.id]) mesh_filter.mesh = mesh self.cell_filters = [cell_21, cell_27] self.energy_filters = [low_energy, high_energy] # Initialize cell tallies with filters, nuclides and scores tallies = [] for energy_filter in self.energy_filters: for cell_filter in self.cell_filters: for nuclide in self.nuclides: for score in self.scores: tally = openmc.Tally() tally.estimator = 'tracklength' tally.add_score(score) tally.add_nuclide(nuclide) tally.add_filter(cell_filter) tally.add_filter(energy_filter) tallies.append(tally) # Merge all cell tallies together while len(tallies) != 1: halfway = int(len(tallies) / 2) zip_split = zip(tallies[:halfway], tallies[halfway:]) tallies = list(map(lambda xy: xy[0].merge(xy[1]), zip_split)) # Specify a name for the tally tallies[0].name = 'cell tally' # Initialize a distribcell tally distribcell_tally = openmc.Tally(name='distribcell tally') distribcell_tally.estimator = 'tracklength' distribcell_tally.add_filter(distribcell_filter) distribcell_tally.add_filter(merged_energies) for score in self.scores: distribcell_tally.add_score(score) for nuclide in self.nuclides: distribcell_tally.add_nuclide(nuclide) mesh_tally = openmc.Tally(name='mesh tally') mesh_tally.estimator = 'tracklength' mesh_tally.filters = [mesh_filter, merged_energies] mesh_tally.scores = self.scores mesh_tally.nuclides = self.nuclides # Add tallies to a Tallies object tallies_file = openmc.Tallies( (tallies[0], distribcell_tally, mesh_tally)) # Export tallies to file self._input_set.tallies = tallies_file super(TallySliceMergeTestHarness, self)._build_inputs()
1.22456E+000, 1.28735E+000, 1.35335E+000, 1.42274E+000, 1.49569E+000, 1.57237E+000, 1.65299E+000, 1.73774E+000, 1.82684E+000, 1.92050E+000, 2.01897E+000, 2.12248E+000, 2.23130E+000, 2.30693E+000, 2.34570E+000, 2.36533E+000, 2.38513E+000, 2.46597E+000, 2.59240E+000, 2.72532E+000, 2.86505E+000, 3.01194E+000, 3.16637E+000, 3.32871E+000, 3.67879E+000, 4.06570E+000, 4.49329E+000, 4.72367E+000, 4.96585E+000, 5.22046E+000, 5.48812E+000, 5.76950E+000, 6.06531E+000, 6.37628E+000, 6.59241E+000, 6.70320E+000, 7.04688E+000, 7.40818E+000, 7.78801E+000, 8.18731E+000, 8.60708E+000, 9.04837E+000, 9.51229E+000, 1.00000E+001, 1.05127E+001, 1.10517E+001, 1.16183E+001, 1.22140E+001, 1.25232E+001, 1.28403E+001, 1.34986E+001, 1.38403E+001, 1.41907E+001, 1.45499E+001, 1.49182E+001, 1.56831E+001, 1.64872E+001, 1.69046E+001, 1.73325E+001, 1.96403E+001 ]) energy_filter = openmc.EnergyFilter(energy_bins * 1e6) tally.filters.append(energy_filter) # mesh filter mesh = openmc.Mesh(mesh_id=14, name="n_flux") mesh.dimension = [16, 5, 1] mesh.lower_left = (-40.0, -12.5, -2.5) mesh.upper_right = (40.0, 12.5, 2.5) mesh_filter = openmc.MeshFilter(mesh) tally.filters.append(mesh_filter) # add the tally to tallies list tallies = openmc.Tallies() tallies.append(tally) tallies.export_to_xml() # run the problem #openmc.run(mpi_args=['mpiexec', '-n', '4']) openmc.run()
def _read_meshes(self): # Initialize dictionaries for the Meshes # Keys - Mesh IDs # Values - Mesh objects self._meshes = {} # Read the number of Meshes self._n_meshes = self._get_int(path='tallies/meshes/n_meshes')[0] # Read a list of the IDs for each Mesh if self._n_meshes > 0: # OpenMC Mesh IDs (redefined internally from user definitions) self._mesh_ids = self._get_int(self._n_meshes, path='tallies/meshes/ids') # User-defined Mesh IDs self._mesh_keys = self._get_int(self._n_meshes, path='tallies/meshes/keys') else: self._mesh_keys = [] self._mesh_ids = [] # Build dictionary of Meshes base = 'tallies/meshes/mesh ' # Iterate over all Meshes for mesh_key in self._mesh_keys: # Read the user-specified Mesh ID and type mesh_id = self._get_int(path='{0}{1}/id'.format(base, mesh_key))[0] mesh_type = self._get_int( path='{0}{1}/type'.format(base, mesh_key))[0] # Get the Mesh dimension n_dimension = self._get_int( path='{0}{1}/n_dimension'.format(base, mesh_key))[0] # Read the mesh dimensions, lower-left coordinates, # upper-right coordinates, and width of each mesh cell dimension = self._get_int(n_dimension, path='{0}{1}/dimension'.format( base, mesh_key)) lower_left = self._get_double(n_dimension, path='{0}{1}/lower_left'.format( base, mesh_key)) upper_right = self._get_double(n_dimension, path='{0}{1}/upper_right'.format( base, mesh_key)) width = self._get_double(n_dimension, path='{0}{1}/width'.format( base, mesh_key)) # Create the Mesh and assign properties to it mesh = openmc.Mesh(mesh_id) mesh.dimension = dimension mesh.width = width mesh.lower_left = lower_left mesh.upper_right = upper_right #FIXME: Set the mesh type to 'rectangular' by default mesh.type = 'rectangular' # Add mesh to the global dictionary of all Meshes self._meshes[mesh_id] = mesh
def __init__(self, *args, **kwargs): super(TallySliceMergeTestHarness, self).__init__(*args, **kwargs) # Define nuclides and scores to add to both tallies self.nuclides = ['U235', 'U238'] self.scores = ['fission', 'nu-fission'] # Define filters for energy and spatial domain low_energy = openmc.EnergyFilter([0., 0.625]) high_energy = openmc.EnergyFilter([0.625, 20.e6]) merged_energies = low_energy.merge(high_energy) cell_21 = openmc.CellFilter(21) cell_27 = openmc.CellFilter(27) distribcell_filter = openmc.DistribcellFilter(21) mesh = openmc.Mesh(name='mesh') mesh.type = 'regular' mesh.dimension = [2, 2] mesh.lower_left = [-50., -50.] mesh.upper_right = [+50., +50.] mesh_filter = openmc.MeshFilter(mesh) self.cell_filters = [cell_21, cell_27] self.energy_filters = [low_energy, high_energy] # Initialize cell tallies with filters, nuclides and scores tallies = [] for energy_filter in self.energy_filters: for cell_filter in self.cell_filters: for nuclide in self.nuclides: for score in self.scores: tally = openmc.Tally() tally.estimator = 'tracklength' tally.scores.append(score) tally.nuclides.append(nuclide) tally.filters.append(cell_filter) tally.filters.append(energy_filter) tallies.append(tally) # Merge all cell tallies together while len(tallies) != 1: halfway = len(tallies) // 2 zip_split = zip(tallies[:halfway], tallies[halfway:]) tallies = list(map(lambda xy: xy[0].merge(xy[1]), zip_split)) # Specify a name for the tally tallies[0].name = 'cell tally' # Initialize a distribcell tally distribcell_tally = openmc.Tally(name='distribcell tally') distribcell_tally.estimator = 'tracklength' distribcell_tally.filters = [distribcell_filter, merged_energies] for score in self.scores: distribcell_tally.scores.append(score) for nuclide in self.nuclides: distribcell_tally.nuclides.append(nuclide) mesh_tally = openmc.Tally(name='mesh tally') mesh_tally.estimator = 'tracklength' mesh_tally.filters = [mesh_filter, merged_energies] mesh_tally.scores = self.scores mesh_tally.nuclides = self.nuclides # Add tallies to a Tallies object self._model.tallies = [tallies[0], distribcell_tally, mesh_tally]
def build_inputs(n_mesh_bins, energy_bins, n_azim_bins, **kwargs): """Build OpenMC input XML files for a pincell with detailed flux tallying""" if n_azim_bins % 8 != 0: raise ValueError("The number of azimuthal bins " "must be divisible by eight") pitch = 0.62992 * 2 #################### # Define materials #################### uo2 = openmc.Material(material_id=9201, name='UO2 fuel at 2.4% wt enrichment') uo2.set_density('g/cm3', 10.29769) uo2.add_nuclide('U-234', 4.4842e-06) uo2.add_nuclide('U-235', 5.5814e-04) uo2.add_nuclide('U-238', 2.2407e-02) uo2.add_nuclide('O-16', 4.5828e-02) uo2.add_nuclide('O-17', 1.7457e-05 + 9.4176e-05) borated_water = openmc.Material(material_id=101, name='Borated water at 975 ppm') borated_water.set_density('g/cm3', 0.740582) borated_water.add_nuclide('B-10', 8.0042e-6) borated_water.add_nuclide('B-11', 3.2218e-5) borated_water.add_nuclide('H-1', 4.9457e-2) borated_water.add_nuclide('H-2', 7.4196e-6) borated_water.add_nuclide('O-16', 2.4672e-2) borated_water.add_nuclide('O-17', 9.3982e-06 + 5.0701e-05) borated_water.add_s_alpha_beta('HH2O', '71t') helium = openmc.Material(material_id=201, name='Helium for gap') helium.set_density('g/cm3', 0.001598) helium.add_nuclide('He-4', 2.4044e-4) zircaloy = openmc.Material(material_id=4001, name='Zircaloy 4') zircaloy.set_density('g/cm3', 6.55) zircaloy.add_nuclide('O-16', 3.0743e-04) zircaloy.add_nuclide('O-17', 1.1711e-07 + 6.3176e-07) zircaloy.add_nuclide('Cr-50', 3.2962e-06) zircaloy.add_nuclide('Cr-52', 6.3564e-05) zircaloy.add_nuclide('Cr-53', 7.2076e-06) zircaloy.add_nuclide('Cr-54', 1.7941e-06) zircaloy.add_nuclide('Fe-54', 8.6699e-06) zircaloy.add_nuclide('Fe-56', 1.3610e-04) zircaloy.add_nuclide('Fe-57', 3.1431e-06) zircaloy.add_nuclide('Fe-58', 4.1829e-07) zircaloy.add_nuclide('Zr-90', 2.1827e-02) zircaloy.add_nuclide('Zr-91', 4.7600e-03) zircaloy.add_nuclide('Zr-92', 7.2758e-03) zircaloy.add_nuclide('Zr-94', 7.3734e-03) zircaloy.add_nuclide('Zr-96', 1.1879e-03) zircaloy.add_nuclide('Sn-112', 4.6735e-06) zircaloy.add_nuclide('Sn-114', 3.1799e-06) zircaloy.add_nuclide('Sn-115', 1.6381e-06) zircaloy.add_nuclide('Sn-116', 7.0055e-05) zircaloy.add_nuclide('Sn-117', 3.7003e-05) zircaloy.add_nuclide('Sn-118', 1.1669e-04) zircaloy.add_nuclide('Sn-119', 4.1387e-05) zircaloy.add_nuclide('Sn-120', 1.5697e-04) zircaloy.add_nuclide('Sn-122', 2.2308e-05) zircaloy.add_nuclide('Sn-124', 2.7897e-05) materials_file = openmc.MaterialsFile() materials_file.default_xs = '71c' materials_file.add_materials([uo2, helium, zircaloy, borated_water]) materials_file.export_to_xml() #################### # Define geometry #################### # Surfaces. fuel_or = openmc.ZCylinder(R=0.39218, name='Fuel OR') clad_ir = openmc.ZCylinder(R=0.40005, name='Clad IR') clad_or = openmc.ZCylinder(R=0.45720, name='Clad OR') bottom = openmc.YPlane(y0=0.0, name='bottom') right = openmc.XPlane(x0=pitch / 2.0, name='right') top = openmc.Plane(A=1, B=-1, name='top') # 45 degree angle lower = openmc.ZPlane(z0=-10, name='lower') upper = openmc.ZPlane(z0=10, name='upper') for s in (bottom, right, top, lower, upper): s.boundary_type = 'reflective' # Cells. fuel_cell = openmc.Cell() gap_cell = openmc.Cell() clad_cell = openmc.Cell() water_cell = openmc.Cell() # Cell regions. fuel_cell.region = -fuel_or gap_cell.region = +fuel_or & -clad_ir clad_cell.region = +clad_ir & -clad_or water_cell.region = +clad_or & -right for c in (fuel_cell, gap_cell, clad_cell, water_cell): c.region = c.region & +bottom & +top & +lower & -upper # Cell fills. fuel_cell.fill = uo2 gap_cell.fill = helium clad_cell.fill = zircaloy water_cell.fill = borated_water # Universe, geometry, and XML. root = openmc.Universe(universe_id=0, name='Root universe') root.add_cells([fuel_cell, gap_cell, clad_cell, water_cell]) geometry = openmc.Geometry() geometry.root_universe = root geometry_file = openmc.GeometryFile() geometry_file.geometry = geometry geometry_file.export_to_xml() #################### # Define settings #################### settings_file = openmc.SettingsFile() settings_file.batches = kwargs.setdefault('batches', 25) settings_file.inactive = kwargs.setdefault('inactive', 5) settings_file.particles = kwargs.setdefault('particles', 1000) settings_file.source = openmc.source.Source( openmc.stats.Point((0.2, 0.1, 0.0))) settings_file.export_to_xml() #################### # Define tallies #################### mesh = openmc.Mesh(mesh_id=1) delta = pitch / 2.0 / (n_mesh_bins + 1) mesh.dimension = [n_mesh_bins, n_mesh_bins, 1] mesh.lower_left = [-delta / 2.0, -delta / 2.0, -1.e50] mesh.upper_right = [ pitch / 2.0 + delta / 2.0, pitch / 2.0 + delta / 2.0, 1.e50 ] energy_filter = openmc.Filter(type='energy', bins=energy_bins) mesh_filter = openmc.Filter() mesh_filter.mesh = mesh azim_filter = openmc.Filter(type='azimuthal', bins=n_azim_bins) tally = openmc.Tally(tally_id=1) tally.add_filter(energy_filter) tally.add_filter(mesh_filter) tally.add_filter(azim_filter) tally.add_score('flux') tallies_file = openmc.TalliesFile() tallies_file.add_mesh(mesh) tallies_file.add_tally(tally) tallies_file.export_to_xml() #################### # Define plots #################### plotfile = openmc.PlotsFile() plot = openmc.Plot() plot.filename = 'matplot' plot.origin = (pitch / 4.0, pitch / 4.0, 0) plot.width = (0.5 * pitch, 0.5 * pitch) plot.pixels = (400, 400) plot.color = 'mat' plot.col_spec = { 101: (100, 200, 200), 201: (220, 220, 220), 4001: (150, 150, 150), 9201: (255, 50, 50) } plotfile.add_plot(plot) plot = openmc.Plot() plot.filename = 'cellplot' plot.origin = (pitch / 4.0, pitch / 4.0, 0) plot.width = (0.5 * pitch, 0.5 * pitch) plot.pixels = (400, 400) plot.color = 'cell' plotfile.add_plot(plot) plotfile.export_to_xml()
zirconium.id: [96, 96, 96], # zirc: gray uo2.id: [255, 75, 75], # fuel: red pyrex.id: [0, 153, 0], # pyrex: green void.id: [0, 0, 0] # void: white } # Instantiate a Materials collection and export to "materials.xml" plots = openmc.Plots([plot]) plots.export_to_xml() ############################################################################### # Create Mesh Tallies for Verification ############################################################################### # Instantiate a tally Mesh mesh = openmc.Mesh(name='assembly mesh') mesh.type = 'regular' mesh.dimension = assembly.dimension mesh.lower_left = assembly.lower_left mesh.width = assembly.pitch # Instantiate mesh Filter mesh_filter = openmc.Filter() mesh_filter.mesh = mesh # Fission rate mesh Tally mesh_fiss = openmc.Tally(name='mesh fission') mesh_fiss.filters = [mesh_filter] mesh_fiss.scores = ['fission'] mesh_fiss.nuclides = ['U-235', 'U-238']
plot.origin = [0, 0, 0] plot.width = [4, 4] plot.pixels = [400, 400] plot.color = 'mat' # Instantiate a PlotsFile, add Plot, and export to XML plot_file = openmc.PlotsFile() plot_file.add_plot(plot) plot_file.export_to_xml() ############################################################################### # Exporting to OpenMC tallies.xml File ############################################################################### # Instantiate a tally mesh mesh = openmc.Mesh(mesh_id=1) mesh.type = 'regular' mesh.dimension = [4, 4] mesh.lower_left = [-2, -2] mesh.width = [1, 1] # Instantiate tally Filter mesh_filter = openmc.Filter() mesh_filter.mesh = mesh # Instantiate the Tally tally = openmc.Tally(tally_id=1) tally.add_filter(mesh_filter) tally.add_score('total') # Instantiate a TalliesFile, register Tally/Mesh, and export to XML
############################################################################### # Exporting to OpenMC settings.xml File ############################################################################### # Construct an initial source. This is not how a source should really be # constructed. For this problem, it would be much better to use an initial # source that encompases all the fuel and to use the only_fissionable=True # option. This source is different in order to demonstrate typical k_eff and # entropy convergence behavior. lower_left = [-8, -8, -10] upper_right = [8, 8, 10.] source = openmc.source.Source(space=openmc.stats.Box(lower_left, upper_right)) # Create an entropy mesh. entropy_mesh = openmc.Mesh() entropy_mesh.lower_left = [-10.71, -10.71, -1.e50] entropy_mesh.upper_right = [10.71, 10.71, 1.e50] entropy_mesh.dimension = [17, 17, 1] # Instantiate Settings collection and export to "settings.xml" settings = openmc.Settings() settings.batches = 50 settings.inactive = 10 settings.particles = 50000 settings.source = source settings.sourcepoint_write = True settings.entropy_mesh = entropy_mesh settings.export_to_xml() ###############################################################################
############################################################################### # Exporting to OpenMC settings.xml file ############################################################################### # Instantiate a Settings object, set all runtime parameters, and export to XML settings_file = openmc.Settings() settings_file.batches = batches settings_file.inactive = inactive settings_file.particles = particles # Create an initial uniform spatial source distribution over fissionable zones bounds = [-0.62992, -0.62992, -1, 0.62992, 0.62992, 1] uniform_dist = openmc.stats.Box(bounds[:3], bounds[3:], only_fissionable=True) settings_file.source = openmc.source.Source(space=uniform_dist) entropy_mesh = openmc.Mesh() entropy_mesh.lower_left = [-0.39218, -0.39218, -1.e50] entropy_mesh.upper_right = [0.39218, 0.39218, 1.e50] entropy_mesh.dimension = [10, 10, 1] settings_file.entropy_mesh = entropy_mesh settings_file.export_to_xml() ############################################################################### # Exporting to OpenMC tallies.xml file ############################################################################### # Instantiate a tally mesh mesh = openmc.Mesh(mesh_id=1) mesh.type = 'regular' mesh.dimension = [100, 100, 1]
# Create a DT point source source = openmc.Source() mcnpsource = openmc.Source() # source.angle = openmc.stats.Isotropic() # source.energy = openmc.stats.Discrete([14e6], [1]) # source.space = openmc.stats.Point((150,0,0)) source.file = 'source_7000_particles.h5' # not working with (n,t) for some reason source.module = 'source_7000_particles.cpp' # not working with (n,t) for some reason sett.source = source # Create mesh which will be used for tally mesh = openmc.Mesh() mesh_height=400 mesh_width = mesh_height mesh.dimension = [mesh_width, mesh_height] mesh.lower_left = [-750, -750] mesh.upper_right = [750, 750] tallies = openmc.Tallies() # Create mesh filter for tally mesh_filter = openmc.MeshFilter(mesh) # Create mesh tally to score flux mesh_tally = openmc.Tally(1,name='tallies_on_mesh') mesh_tally.filters = [mesh_filter] # works with 'flux', does not work with absorption or '(n,t)'