def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # Initialize a two-group structure energy_groups = openmc.mgxs.EnergyGroups(group_edges=[0, 0.625, 20.e6]) # Initialize MGXS Library for a few cross section types 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.RegularMesh(mesh_id=1) 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 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 # Initialize a one-group structure energy_groups = openmc.mgxs.EnergyGroups([0, 20.e6]) # Initialize MGXS Library for a few cross section types # for one material-filled cell in the geometry model.mgxs_lib = openmc.mgxs.Library(model.geometry) model.mgxs_lib.by_nuclide = False # Test all MGXS types model.mgxs_lib.mgxs_types = openmc.mgxs.MGXS_TYPES + openmc.mgxs.MDGXS_TYPES model.mgxs_lib.energy_groups = energy_groups model.mgxs_lib.num_delayed_groups = 6 model.mgxs_lib.correction = None # Avoid warning about P0 correction model.mgxs_lib.legendre_order = 3 model.mgxs_lib.domain_type = 'mesh' # Instantiate a tally mesh mesh = openmc.RegularMesh(mesh_id=1) mesh.dimension = [2, 2] mesh.lower_left = [-100., -100.] mesh.width = [100., 100.] model.mgxs_lib.domains = [mesh] model.mgxs_lib.build_library() # Add tallies model.mgxs_lib.add_to_tallies_file(model.tallies, merge=False) return model
def model(): model = openmc.model.Model() fuel = openmc.Material() fuel.set_density('g/cm3', 10.0) fuel.add_nuclide('U234', 1.0) fuel.add_nuclide('U235', 4.0) fuel.add_nuclide('U238', 95.0) water = openmc.Material(name='light water') water.add_nuclide('H1', 2.0) water.add_nuclide('O16', 1.0) water.set_density('g/cm3', 1.0) water.add_s_alpha_beta('c_H_in_H2O') model.materials.extend([fuel, water]) cyl1 = openmc.ZCylinder(r=5.0) cyl2 = openmc.ZCylinder(r=10.0, boundary_type='vacuum') cell1 = openmc.Cell(fill=fuel, region=-cyl1) cell2 = openmc.Cell(fill=water, region=+cyl1 & -cyl2) model.geometry = openmc.Geometry([cell1, cell2]) model.settings.batches = 5 model.settings.inactive = 0 model.settings.particles = 1000 mesh = openmc.RegularMesh() mesh.dimension = (2, 2) mesh.lower_left = (-10.0, -10.0) mesh.upper_right = (10.0, 10.0) energy_filter = openmc.EnergyFilter((0.0, 10.0, 20.0e6)) material_filter = openmc.MaterialFilter((fuel, water)) mesh_filter = openmc.MeshFilter(mesh) tally = openmc.Tally(name='tally 1') tally.filters = [material_filter, energy_filter] tally.scores = ['nu-fission', 'total'] tally.nuclides = ['U234', 'U235'] model.tallies.append(tally) tally = openmc.Tally(name='tally 2') tally.filters = [energy_filter, mesh_filter] tally.scores = ['total', 'fission'] tally.nuclides = ['U238', 'U235'] model.tallies.append(tally) return model
def test_xml_roundtrip(run_in_tmpdir): # Create a tally with all possible gizmos mesh = openmc.RegularMesh() mesh.lower_left = (-10., -10., -10.) mesh.upper_right = ( 10., 10., 10., ) mesh.dimension = (5, 5, 5) mesh_filter = openmc.MeshFilter(mesh) tally = openmc.Tally() tally.filters = [mesh_filter] tally.nuclides = ['U235', 'I135', 'Li6'] tally.scores = ['total', 'fission', 'heating'] tally.derivative = openmc.TallyDerivative(variable='nuclide_density', material=1, nuclide='Li6') tally.triggers = [openmc.Trigger('rel_err', 0.025)] tally.triggers[0].scores = ['total', 'fission'] tallies = openmc.Tallies([tally]) # Roundtrip through XML and make sure we get what we started with tallies.export_to_xml() new_tallies = openmc.Tallies.from_xml() assert len(new_tallies) == 1 new_tally = new_tallies[0] assert new_tally.id == tally.id assert len(new_tally.filters) == 1 assert isinstance(new_tally.filters[0], openmc.MeshFilter) assert np.allclose(new_tally.filters[0].mesh.lower_left, mesh.lower_left) assert new_tally.nuclides == tally.nuclides assert new_tally.scores == tally.scores assert new_tally.derivative.variable == tally.derivative.variable assert new_tally.derivative.material == tally.derivative.material assert new_tally.derivative.nuclide == tally.derivative.nuclide assert len(new_tally.triggers) == 1 assert new_tally.triggers[0].trigger_type == tally.triggers[0].trigger_type assert new_tally.triggers[0].threshold == tally.triggers[0].threshold assert new_tally.triggers[0].scores == tally.triggers[0].scores
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 model(): model = openmc.Model() # materials (M4 steel alloy) m4 = openmc.Material() m4.set_density('g/cc', 2.3) m4.add_nuclide('H1', 0.168018676) m4.add_nuclide("H2", 1.93244e-05) m4.add_nuclide("O16", 0.561814465) m4.add_nuclide("O17", 0.00021401) m4.add_nuclide("Na23", 0.021365) m4.add_nuclide("Al27", 0.021343) m4.add_nuclide("Si28", 0.187439342) m4.add_nuclide("Si29", 0.009517714) m4.add_nuclide("Si30", 0.006273944) m4.add_nuclide("Ca40", 0.018026179) m4.add_nuclide("Ca42", 0.00012031) m4.add_nuclide("Ca43", 2.51033e-05) m4.add_nuclide("Ca44", 0.000387892) m4.add_nuclide("Ca46", 7.438e-07) m4.add_nuclide("Ca48", 3.47727e-05) m4.add_nuclide("Fe54", 0.000248179) m4.add_nuclide("Fe56", 0.003895875) m4.add_nuclide("Fe57", 8.99727e-05) m4.add_nuclide("Fe58", 1.19737e-05) s0 = openmc.Sphere(r=240) s1 = openmc.Sphere(r=250, boundary_type='vacuum') c0 = openmc.Cell(fill=m4, region=-s0) c1 = openmc.Cell(region=+s0 & -s1) model.geometry = openmc.Geometry([c0, c1]) # settings settings = model.settings settings.run_mode = 'fixed source' settings.particles = 200 settings.batches = 2 settings.max_splits = 200 settings.photon_transport = True space = Point((0.001, 0.001, 0.001)) energy = Discrete([14E6], [1.0]) settings.source = openmc.Source(space=space, energy=energy) # tally mesh = openmc.RegularMesh() mesh.lower_left = (-240, -240, -240) mesh.upper_right = (240, 240, 240) mesh.dimension = (5, 10, 15) mesh_filter = openmc.MeshFilter(mesh) e_bnds = [0.0, 0.5, 2E7] energy_filter = openmc.EnergyFilter(e_bnds) particle_filter = openmc.ParticleFilter(['neutron', 'photon']) tally = openmc.Tally() tally.filters = [mesh_filter, energy_filter, particle_filter] tally.scores = ['flux'] model.tallies.append(tally) # 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) ww_n = openmc.WeightWindows(ww_mesh, ww_n_lower_bnds, None, 10.0, e_bnds, max_lower_bound_ratio=1.5) ww_p = openmc.WeightWindows(ww_mesh, ww_p_lower_bnds, None, 10.0, e_bnds, max_lower_bound_ratio=1.5) model.settings.weight_windows = [ww_n, ww_p] return model
settings.batches = 100 settings.inactive = 10 settings.particles = 1000 # Create an initial uniform spatial source distribution over fissionable zones lower_left = (-pitch / 2, -pitch / 2, -1) upper_right = (pitch / 2, pitch / 2, 1) uniform_dist = openmc.stats.Box(lower_left, upper_right, only_fissionable=True) settings.source = openmc.source.Source(space=uniform_dist) settings.export_to_xml() ############################################################################### # Define tallies # Create a mesh that will be used for tallying mesh = openmc.RegularMesh() mesh.dimension = (100, 100) mesh.lower_left = (-pitch / 2, -pitch / 2) mesh.upper_right = (pitch / 2, pitch / 2) # Create a mesh filter that can be used in a tally mesh_filter = openmc.MeshFilter(mesh) # Now use the mesh filter in a tally and indicate what scores are desired mesh_tally = openmc.Tally(name="Mesh tally") mesh_tally.filters = [mesh_filter] mesh_tally.scores = ['flux', 'fission', 'nu-fission'] # Let's also create a tally to get the flux energy spectrum. We start by # creating an energy filter e_min, e_max = 1e-5, 20.0e6
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("./..")
import openmc ############################################################################### # Exporting to OpenMC tallies.xml File ############################################################################### tallies = {} # Instantiate a tally mesh mesh = openmc.RegularMesh(mesh_id=1) mesh.dimension = [51, 51, 1] mesh.lower_left = [-32.13, -32.13, -1.e50] mesh.upper_right = [32.13, 32.13, 1.e50] # Instantiate some tally Filters mesh_filter = openmc.MeshFilter(mesh) # Instantiate the Tally tallies['Mesh Rates'] = openmc.Tally(tally_id=1, name='tally 1') tallies['Mesh Rates'].filters = [mesh_filter] tallies['Mesh Rates'].scores = ['flux', 'fission', 'nu-fission'] tallies['Global Rates'] = openmc.Tally(tally_id=2, name='tally 2') tallies['Global Rates'].scores = ['flux', 'fission', 'nu-fission']
def test_unstructured_mesh(test_opts): ### Materials ### materials = openmc.Materials() fuel_mat = openmc.Material(name="fuel") fuel_mat.add_nuclide("U235", 1.0) fuel_mat.set_density('g/cc', 4.5) materials.append(fuel_mat) zirc_mat = openmc.Material(name="zircaloy") zirc_mat.add_element("Zr", 1.0) zirc_mat.set_density("g/cc", 5.77) materials.append(zirc_mat) water_mat = openmc.Material(name="water") water_mat.add_nuclide("H1", 2.0) water_mat.add_nuclide("O16", 1.0) water_mat.set_density("atom/b-cm", 0.07416) materials.append(water_mat) materials.export_to_xml() ### Geometry ### fuel_min_x = openmc.XPlane(-5.0, name="minimum x") fuel_max_x = openmc.XPlane(5.0, name="maximum x") fuel_min_y = openmc.YPlane(-5.0, name="minimum y") fuel_max_y = openmc.YPlane(5.0, name="maximum y") fuel_min_z = openmc.ZPlane(-5.0, name="minimum z") fuel_max_z = openmc.ZPlane(5.0, name="maximum z") fuel_cell = openmc.Cell(name="fuel") fuel_cell.region = +fuel_min_x & -fuel_max_x & \ +fuel_min_y & -fuel_max_y & \ +fuel_min_z & -fuel_max_z fuel_cell.fill = fuel_mat clad_min_x = openmc.XPlane(-6.0, name="minimum x") clad_max_x = openmc.XPlane(6.0, name="maximum x") clad_min_y = openmc.YPlane(-6.0, name="minimum y") clad_max_y = openmc.YPlane(6.0, name="maximum y") clad_min_z = openmc.ZPlane(-6.0, name="minimum z") clad_max_z = openmc.ZPlane(6.0, name="maximum z") clad_cell = openmc.Cell(name="clad") clad_cell.region = (-fuel_min_x | +fuel_max_x | -fuel_min_y | +fuel_max_y | -fuel_min_z | +fuel_max_z) & \ (+clad_min_x & -clad_max_x & +clad_min_y & -clad_max_y & +clad_min_z & -clad_max_z) clad_cell.fill = zirc_mat if test_opts['external_geom']: bounds = (15, 15, 15) else: bounds = (10, 10, 10) water_min_x = openmc.XPlane(x0=-bounds[0], name="minimum x", boundary_type='vacuum') water_max_x = openmc.XPlane(x0=bounds[0], name="maximum x", boundary_type='vacuum') water_min_y = openmc.YPlane(y0=-bounds[1], name="minimum y", boundary_type='vacuum') water_max_y = openmc.YPlane(y0=bounds[1], name="maximum y", boundary_type='vacuum') water_min_z = openmc.ZPlane(z0=-bounds[2], name="minimum z", boundary_type='vacuum') water_max_z = openmc.ZPlane(z0=bounds[2], name="maximum z", boundary_type='vacuum') water_cell = openmc.Cell(name="water") water_cell.region = (-clad_min_x | +clad_max_x | -clad_min_y | +clad_max_y | -clad_min_z | +clad_max_z) & \ (+water_min_x & -water_max_x & +water_min_y & -water_max_y & +water_min_z & -water_max_z) water_cell.fill = water_mat # create a containing universe geometry = openmc.Geometry([fuel_cell, clad_cell, water_cell]) ### Tallies ### # create meshes regular_mesh = openmc.RegularMesh() regular_mesh.dimension = (10, 10, 10) regular_mesh.lower_left = (-10.0, -10.0, -10.0) regular_mesh.upper_right = (10.0, 10.0, 10.0) regular_mesh_filter = openmc.MeshFilter(mesh=regular_mesh) if test_opts['holes']: mesh_filename = "test_mesh_tets_w_holes.h5m" else: mesh_filename = "test_mesh_tets.h5m" uscd_mesh = openmc.UnstructuredMesh(mesh_filename) uscd_mesh.mesh_lib = 'moab' uscd_filter = openmc.MeshFilter(mesh=uscd_mesh) # create tallies tallies = openmc.Tallies() regular_mesh_tally = openmc.Tally(name="regular mesh tally") regular_mesh_tally.filters = [regular_mesh_filter] regular_mesh_tally.scores = ['flux'] regular_mesh_tally.estimator = test_opts['estimator'] tallies.append(regular_mesh_tally) uscd_tally = openmc.Tally(name="unstructured mesh tally") uscd_tally.filters = [uscd_filter] uscd_tally.scores = ['flux'] uscd_tally.estimator = test_opts['estimator'] tallies.append(uscd_tally) ### Settings ### settings = openmc.Settings() settings.run_mode = 'fixed source' settings.particles = 100 settings.batches = 10 # source setup r = openmc.stats.Uniform(a=0.0, b=0.0) theta = openmc.stats.Discrete(x=[0.0], p=[1.0]) phi = openmc.stats.Discrete(x=[0.0], p=[1.0]) space = openmc.stats.SphericalIndependent(r, theta, phi) angle = openmc.stats.Monodirectional((-1.0, 0.0, 0.0)) energy = openmc.stats.Discrete(x=[15.e+06], p=[1.0]) source = openmc.Source(space=space, energy=energy, angle=angle) settings.source = source model = openmc.model.Model(geometry=geometry, materials=materials, tallies=tallies, settings=settings) harness = UnstructuredMeshTest('statepoint.10.h5', model, test_opts['inputs_true'], test_opts['holes']) harness.main()
def tallies_generation(root): """ Creates tallies.xml file Parameters ---------- root: openmc.Universe with all the relevant cells for the geometry. Returns ------- This function generates the tallies.xml file. """ tallies_file = openmc.Tallies() # phase1a-b energy_filter_b = openmc.EnergyFilter([1e-6, 20.0e6]) mesh_b = openmc.RegularMesh(mesh_id=16) mesh_b.dimension = [1, 1] L = 27.02 mesh_b.lower_left = [-L, -L] mesh_b.upper_right = [L, L] mesh_filter_b = openmc.MeshFilter(mesh_b) tally_b = openmc.Tally(name='mesh tally b') tally_b.filters = [mesh_filter_b, energy_filter_b] tally_b.scores = ['delayed-nu-fission', 'nu-fission'] tallies_file.append(tally_b) # phase1a-c mesh_no = 0 for t in range(6): mesh_no += 1 for x in range(2): x_trans = t * T['A1']['P']['x'] y_trans = t * T['A1']['P']['y'] if x == 1: mesh_no += 1 x_trans += T['A1']['F']['x'] y_trans += T['A1']['F']['y'] mesh_c = openmc.RegularMesh(mesh_id=mesh_no) mesh_c.dimension = [1, 5] mesh_c.lower_left = [ V['A1']['F']['L']['x'] + x_trans, V['A1']['F']['B']['y'] + y_trans ] mesh_c.upper_right = [ V['A1']['F']['R']['x'] + x_trans, V['A1']['F']['T']['y'] + y_trans ] mesh_filter_c = openmc.MeshFilter(mesh_c) tally_c = openmc.Tally(name='mesh tally c' + str(mesh_no)) tally_c.filters = [mesh_filter_c] tally_c.scores = ['fission'] tallies_file.append(tally_c) # phase 1a-d energy_filter_d = openmc.EnergyFilter([1e-5, 3, 1.0e5, 20.0e6]) mesh_d = openmc.RegularMesh(mesh_id=13) mesh_d.dimension = [1, 1] L = 27.02 mesh_d.lower_left = [-L, -L] mesh_d.upper_right = [L, L] mesh_filter_d = openmc.MeshFilter(mesh_d) tally_d = openmc.Tally(name='mesh tally d') tally_d.filters = [mesh_filter_d, energy_filter_d] tally_d.scores = ['flux', 'nu-fission', 'fission'] tallies_file.append(tally_d) # phase 1a-e energy_filter_e = openmc.EnergyFilter([1e-5, 3, 0.1e6, 20.0e6]) mesh_e = openmc.RegularMesh(mesh_id=14) mesh_e.dimension = [100, 100] L = 27.02 mesh_e.lower_left = [-L, -L] mesh_e.upper_right = [L, L] mesh_filter_e = openmc.MeshFilter(mesh_e) tally_e = openmc.Tally(name='mesh tally e') tally_e.filters = [mesh_filter_e, energy_filter_e] tally_e.scores = ['flux', 'nu-fission', 'fission'] tallies_file.append(tally_e) # phase 1a-f energy_filter_f = openmc.EnergyFilter(engs) mesh_f = openmc.RegularMesh(mesh_id=15) mesh_f.dimension = [1, 1] L = 27.02 mesh_f.lower_left = [-L, -L] mesh_f.upper_right = [L, L] mesh_filter_f = openmc.MeshFilter(mesh_f) tally_f = openmc.Tally(name='mesh tally f') tally_f.filters = [mesh_filter_f, energy_filter_f] tally_f.scores = ['flux', 'nu-fission', 'fission'] tallies_file.append(tally_f) tallies_file.export_to_xml() return
def test_export_to_xml(run_in_tmpdir): s = openmc.Settings() s.run_mode = 'fixed source' s.batches = 1000 s.generations_per_batch = 10 s.inactive = 100 s.particles = 1000000 s.max_lost_particles = 5 s.rel_max_lost_particles = 1e-4 s.keff_trigger = {'type': 'std_dev', 'threshold': 0.001} s.energy_mode = 'continuous-energy' s.max_order = 5 s.source = openmc.Source(space=openmc.stats.Point()) s.output = {'summary': True, 'tallies': False, 'path': 'here'} s.verbosity = 7 s.sourcepoint = { 'batches': [50, 150, 500, 1000], 'separate': True, 'write': True, 'overwrite': True } s.statepoint = {'batches': [50, 150, 500, 1000]} s.surf_source_read = {'path': 'surface_source_1.h5'} s.surf_source_write = {'surface_ids': [2], 'max_particles': 200} s.confidence_intervals = True s.ptables = True s.seed = 17 s.survival_biasing = True s.cutoff = { 'weight': 0.25, 'weight_avg': 0.5, 'energy_neutron': 1.0e-5, 'energy_photon': 1000.0, 'energy_electron': 1.0e-5, 'energy_positron': 1.0e-5 } mesh = openmc.RegularMesh() mesh.lower_left = (-10., -10., -10.) mesh.upper_right = (10., 10., 10.) mesh.dimension = (5, 5, 5) s.entropy_mesh = mesh s.trigger_active = True s.trigger_max_batches = 10000 s.trigger_batch_interval = 50 s.no_reduce = False s.tabular_legendre = {'enable': True, 'num_points': 50} s.temperature = { 'default': 293.6, 'method': 'interpolation', 'multipole': True, 'range': (200., 1000.) } s.trace = (10, 1, 20) s.track = [1, 1, 1, 2, 1, 1] s.ufs_mesh = mesh s.resonance_scattering = { 'enable': True, 'method': 'rvs', 'energy_min': 1.0, 'energy_max': 1000.0, 'nuclides': ['U235', 'U238', 'Pu239'] } s.volume_calculations = openmc.VolumeCalculation(domains=[openmc.Cell()], samples=1000, lower_left=(-10., -10., -10.), upper_right=(10., 10., 10.)) s.create_fission_neutrons = True s.log_grid_bins = 2000 s.photon_transport = False s.electron_treatment = 'led' s.write_initial_source = True # Make sure exporting XML works s.export_to_xml() # Generate settings from XML s = openmc.Settings.from_xml() assert s.run_mode == 'fixed source' assert s.batches == 1000 assert s.generations_per_batch == 10 assert s.inactive == 100 assert s.particles == 1000000 assert s.max_lost_particles == 5 assert s.rel_max_lost_particles == 1e-4 assert s.keff_trigger == {'type': 'std_dev', 'threshold': 0.001} assert s.energy_mode == 'continuous-energy' assert s.max_order == 5 assert isinstance(s.source[0], openmc.Source) assert isinstance(s.source[0].space, openmc.stats.Point) assert s.output == {'summary': True, 'tallies': False, 'path': 'here'} assert s.verbosity == 7 assert s.sourcepoint == { 'batches': [50, 150, 500, 1000], 'separate': True, 'write': True, 'overwrite': True } assert s.statepoint == {'batches': [50, 150, 500, 1000]} assert s.surf_source_read == {'path': 'surface_source_1.h5'} assert s.surf_source_write == {'surface_ids': [2], 'max_particles': 200} assert s.confidence_intervals assert s.ptables assert s.seed == 17 assert s.survival_biasing assert s.cutoff == { 'weight': 0.25, 'weight_avg': 0.5, 'energy_neutron': 1.0e-5, 'energy_photon': 1000.0, 'energy_electron': 1.0e-5, 'energy_positron': 1.0e-5 } assert isinstance(s.entropy_mesh, openmc.RegularMesh) assert s.entropy_mesh.lower_left == [-10., -10., -10.] assert s.entropy_mesh.upper_right == [10., 10., 10.] assert s.entropy_mesh.dimension == [5, 5, 5] assert s.trigger_active assert s.trigger_max_batches == 10000 assert s.trigger_batch_interval == 50 assert not s.no_reduce assert s.tabular_legendre == {'enable': True, 'num_points': 50} assert s.temperature == { 'default': 293.6, 'method': 'interpolation', 'multipole': True, 'range': [200., 1000.] } assert s.trace == [10, 1, 20] assert s.track == [1, 1, 1, 2, 1, 1] assert isinstance(s.ufs_mesh, openmc.RegularMesh) assert s.ufs_mesh.lower_left == [-10., -10., -10.] assert s.ufs_mesh.upper_right == [10., 10., 10.] assert s.ufs_mesh.dimension == [5, 5, 5] assert s.resonance_scattering == { 'enable': True, 'method': 'rvs', 'energy_min': 1.0, 'energy_max': 1000.0, 'nuclides': ['U235', 'U238', 'Pu239'] } assert s.create_fission_neutrons assert s.log_grid_bins == 2000 assert not s.photon_transport assert s.electron_treatment == 'led' assert s.write_initial_source == True assert len(s.volume_calculations) == 1 vol = s.volume_calculations[0] assert vol.domain_type == 'cell' assert len(vol.ids) == 1 assert vol.samples == 1000 assert vol.lower_left == (-10., -10., -10.) assert vol.upper_right == (10., 10., 10.)
def create_neutronics_model(self, method: str = None): """Uses OpenMC python API to make a neutronics model, including tallies (cell_tallies and mesh_tally_2d), simulation settings (batches, particles per batch). Arguments: method: (str): The method to use when making the imprinted and merged geometry. Options are "ppp", "trelis", "pymoab". Defaults to None. """ self.create_materials() self.create_neutronics_geometry(method=method) # this is the underlying geometry container that is filled with the # faceteted DGAMC CAD model self.universe = openmc.Universe() geom = openmc.Geometry(self.universe) # settings for the number of neutrons to simulate settings = openmc.Settings() settings.batches = self.simulation_batches settings.inactive = 0 settings.particles = self.simulation_particles_per_batch settings.run_mode = "fixed source" settings.dagmc = True settings.photon_transport = True settings.source = self.source settings.max_lost_particles = self.max_lost_particles # details about what neutrons interactions to keep track of (tally) self.tallies = openmc.Tallies() if self.mesh_tally_3d is not None: mesh_xyz = openmc.RegularMesh(mesh_id=1, name='3d_mesh') mesh_xyz.dimension = self.mesh_3D_resolution mesh_xyz.lower_left = [ -self.geometry.largest_dimension, -self.geometry.largest_dimension, -self.geometry.largest_dimension ] mesh_xyz.upper_right = [ self.geometry.largest_dimension, self.geometry.largest_dimension, self.geometry.largest_dimension ] for standard_tally in self.mesh_tally_3d: if standard_tally == 'tritium_production': score = '(n,Xt)' # where X is a wild card prefix = 'tritium_production' else: score = standard_tally prefix = standard_tally mesh_filter = openmc.MeshFilter(mesh_xyz) tally = openmc.Tally(name=prefix + '_on_3D_mesh') tally.filters = [mesh_filter] tally.scores = [score] self.tallies.append(tally) if self.mesh_tally_2d is not None: # Create mesh which will be used for tally mesh_xz = openmc.RegularMesh(mesh_id=2, name='2d_mesh_xz') mesh_xz.dimension = [ self.mesh_2D_resolution[1], 1, self.mesh_2D_resolution[0] ] mesh_xz.lower_left = [ -self.geometry.largest_dimension, -1, -self.geometry.largest_dimension ] mesh_xz.upper_right = [ self.geometry.largest_dimension, 1, self.geometry.largest_dimension ] mesh_xy = openmc.RegularMesh(mesh_id=3, name='2d_mesh_xy') mesh_xy.dimension = [ self.mesh_2D_resolution[1], self.mesh_2D_resolution[0], 1 ] mesh_xy.lower_left = [ -self.geometry.largest_dimension, -self.geometry.largest_dimension, -1 ] mesh_xy.upper_right = [ self.geometry.largest_dimension, self.geometry.largest_dimension, 1 ] mesh_yz = openmc.RegularMesh(mesh_id=4, name='2d_mesh_yz') mesh_yz.dimension = [ 1, self.mesh_2D_resolution[1], self.mesh_2D_resolution[0] ] mesh_yz.lower_left = [ -1, -self.geometry.largest_dimension, -self.geometry.largest_dimension ] mesh_yz.upper_right = [ 1, self.geometry.largest_dimension, self.geometry.largest_dimension ] for standard_tally in self.mesh_tally_2d: if standard_tally == 'tritium_production': score = '(n,Xt)' # where X is a wild card prefix = 'tritium_production' else: score = standard_tally prefix = standard_tally for mesh_filter, plane in zip( [mesh_xz, mesh_xy, mesh_yz], ['xz', 'xy', 'yz']): mesh_filter = openmc.MeshFilter(mesh_filter) tally = openmc.Tally(name=prefix + '_on_2D_mesh_' + plane) tally.filters = [mesh_filter] tally.scores = [score] self.tallies.append(tally) if self.cell_tallies is not None: for standard_tally in self.cell_tallies: if standard_tally == 'TBR': score = '(n,Xt)' # where X is a wild card sufix = 'TBR' tally = openmc.Tally(name='TBR') tally.scores = [score] self.tallies.append(tally) self._add_tally_for_every_material(sufix, score) elif standard_tally == 'spectra': neutron_particle_filter = openmc.ParticleFilter([ 'neutron']) photon_particle_filter = openmc.ParticleFilter(['photon']) energy_bins = openmc.mgxs.GROUP_STRUCTURES['CCFE-709'] energy_filter = openmc.EnergyFilter(energy_bins) self._add_tally_for_every_material( 'neutron_spectra', 'flux', [neutron_particle_filter, energy_filter] ) self._add_tally_for_every_material( 'photon_spectra', 'flux', [photon_particle_filter, energy_filter] ) else: score = standard_tally sufix = standard_tally self._add_tally_for_every_material(sufix, score) # make the model from gemonetry, materials, settings and tallies self.model = openmc.model.Model( geom, self.mats, settings, self.tallies)
############################################################################### # 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 = [-plane_value, -plane_value, -1, plane_value, plane_value, 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.RegularMesh() entropy_mesh.lower_left = [-entropy_mesh_value, -entropy_mesh_value, -1.e50] entropy_mesh.upper_right = [entropy_mesh_value, entropy_mesh_value, 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 ############################################################################### tallies_file = openmc.Tallies() energy_filter = openmc.EnergyFilter([0., 0.625, 20.0e6]) # Instantiate flux Tally in moderator and fuel
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)
def model(): openmc.reset_auto_ids() model = openmc.Model() # materials (M4 steel alloy) m4 = openmc.Material() m4.set_density('g/cc', 2.3) m4.add_nuclide('H1', 0.168018676) m4.add_nuclide("H2", 1.93244e-05) m4.add_nuclide("O16", 0.561814465) m4.add_nuclide("O17", 0.00021401) m4.add_nuclide("Na23", 0.021365) m4.add_nuclide("Al27", 0.021343) m4.add_nuclide("Si28", 0.187439342) m4.add_nuclide("Si29", 0.009517714) m4.add_nuclide("Si30", 0.006273944) m4.add_nuclide("Ca40", 0.018026179) m4.add_nuclide("Ca42", 0.00012031) m4.add_nuclide("Ca43", 2.51033e-05) m4.add_nuclide("Ca44", 0.000387892) m4.add_nuclide("Ca46", 7.438e-07) m4.add_nuclide("Ca48", 3.47727e-05) m4.add_nuclide("Fe54", 0.000248179) m4.add_nuclide("Fe56", 0.003895875) m4.add_nuclide("Fe57", 8.99727e-05) m4.add_nuclide("Fe58", 1.19737e-05) s0 = openmc.Sphere(r=240) s1 = openmc.Sphere(r=250, boundary_type='vacuum') c0 = openmc.Cell(fill=m4, region=-s0) c1 = openmc.Cell(region=+s0 & -s1) model.geometry = openmc.Geometry([c0, c1]) # settings settings = model.settings settings.run_mode = 'fixed source' settings.particles = 500 settings.batches = 2 settings.max_splits = 100 settings.photon_transport = True space = Point((0.001, 0.001, 0.001)) energy = Discrete([14E6], [1.0]) settings.source = openmc.Source(space=space, energy=energy) # tally mesh = openmc.RegularMesh() mesh.lower_left = (-240, -240, -240) mesh.upper_right = (240, 240, 240) mesh.dimension = (3, 5, 7) mesh_filter = openmc.MeshFilter(mesh) e_bnds = [0.0, 0.5, 2E7] energy_filter = openmc.EnergyFilter(e_bnds) particle_filter = openmc.ParticleFilter(['neutron', 'photon']) tally = openmc.Tally() tally.filters = [mesh_filter, energy_filter, particle_filter] tally.scores = ['flux'] model.tallies.append(tally) return model
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 # Create meshes mesh_1d = openmc.RegularMesh() mesh_1d.dimension = [5] mesh_1d.lower_left = [-7.5] mesh_1d.upper_right = [7.5] mesh_2d = openmc.RegularMesh() mesh_2d.dimension = [5, 5] mesh_2d.lower_left = [-7.5, -7.5] mesh_2d.upper_right = [7.5, 7.5] mesh_3d = openmc.RegularMesh() mesh_3d.dimension = [5, 5, 5] mesh_3d.lower_left = [-7.5, -7.5, -7.5] mesh_3d.upper_right = [7.5, 7.5, 7.5] recti_mesh = openmc.RectilinearMesh() recti_mesh.x_grid = np.linspace(-7.5, 7.5, 18) recti_mesh.y_grid = np.linspace(-7.5, 7.5, 18) recti_mesh.z_grid = np.logspace(0, np.log10(7.5), 11) # Create filters reg_filters = [ openmc.MeshFilter(mesh_1d), openmc.MeshFilter(mesh_2d), openmc.MeshFilter(mesh_3d), openmc.MeshFilter(recti_mesh) ] surf_filters = [ openmc.MeshSurfaceFilter(mesh_1d), openmc.MeshSurfaceFilter(mesh_2d), openmc.MeshSurfaceFilter(mesh_3d), openmc.MeshSurfaceFilter(recti_mesh) ] # Create tallies for f1, f2 in zip(reg_filters, surf_filters): tally = openmc.Tally() tally.filters = [f1] tally.scores = ['total'] model.tallies.append(tally) tally = openmc.Tally() tally.filters = [f2] tally.scores = ['current'] model.tallies.append(tally) return model
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 translation = np.array((10, -5, 0)) llc = np.array([-9, -9, -9]) urc = np.array([9, 9, 9]) mesh_dims = (3, 4, 5) filters = [] # un-translated meshes reg_mesh = openmc.RegularMesh() reg_mesh.dimension = mesh_dims reg_mesh.lower_left = llc reg_mesh.upper_right = urc filters.append(openmc.MeshFilter(reg_mesh)) recti_mesh = openmc.RectilinearMesh() recti_mesh.x_grid = np.linspace(llc[0], urc[0], mesh_dims[0]) recti_mesh.y_grid = np.linspace(llc[1], urc[1], mesh_dims[1]) recti_mesh.z_grid = np.linspace(llc[2], urc[2], mesh_dims[2]) filters.append(openmc.MeshFilter(recti_mesh)) llc = np.array(llc - translation) urc = np.array(urc - translation) # translated meshes translated_reg_mesh = openmc.RegularMesh() translated_reg_mesh.dimension = mesh_dims translated_reg_mesh.lower_left = llc translated_reg_mesh.upper_right = urc filters.append(openmc.MeshFilter(translated_reg_mesh)) filters[-1].translation = translation translated_recti_mesh = openmc.RectilinearMesh() translated_recti_mesh.x_grid = np.linspace(llc[0], urc[0], mesh_dims[0]) translated_recti_mesh.y_grid = np.linspace(llc[1], urc[1], mesh_dims[1]) translated_recti_mesh.z_grid = np.linspace(llc[2], urc[2], mesh_dims[2]) filters.append(openmc.MeshFilter(translated_recti_mesh)) filters[-1].translation = translation # Create tallies for f in filters: tally = openmc.Tally() tally.filters = [f] tally.scores = ['total'] model.tallies.append(tally) return model
def pin_model_attributes(): uo2 = openmc.Material(material_id=1, name='UO2') uo2.set_density('g/cm3', 10.29769) uo2.add_element('U', 1., enrichment=2.4) uo2.add_element('O', 2.) uo2.depletable = True zirc = openmc.Material(material_id=2, name='Zirc') zirc.set_density('g/cm3', 6.55) zirc.add_element('Zr', 1.) zirc.depletable = False borated_water = openmc.Material(material_id=3, name='Borated water') borated_water.set_density('g/cm3', 0.740582) borated_water.add_element('B', 4.0e-5) borated_water.add_element('H', 5.0e-2) borated_water.add_element('O', 2.4e-2) borated_water.add_s_alpha_beta('c_H_in_H2O') borated_water.depletable = False mats = openmc.Materials([uo2, zirc, borated_water]) pitch = 1.25984 fuel_or = openmc.ZCylinder(r=0.39218, name='Fuel OR') clad_or = openmc.ZCylinder(r=0.45720, name='Clad OR') box = openmc.model.rectangular_prism(pitch, pitch, boundary_type='reflective') # Define cells fuel_inf_cell = openmc.Cell(cell_id=1, name='inf fuel', fill=uo2) fuel_inf_univ = openmc.Universe(universe_id=1, cells=[fuel_inf_cell]) fuel = openmc.Cell(cell_id=2, name='fuel', fill=fuel_inf_univ, region=-fuel_or) clad = openmc.Cell(cell_id=3, fill=zirc, region=+fuel_or & -clad_or) water = openmc.Cell(cell_id=4, fill=borated_water, region=+clad_or & box) # Define overall geometry geom = openmc.Geometry([fuel, clad, water]) uo2.volume = pi * fuel_or.r**2 settings = openmc.Settings() settings.batches = 100 settings.inactive = 10 settings.particles = 1000 # Create a 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.source = openmc.source.Source(space=uniform_dist) entropy_mesh = openmc.RegularMesh() 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.entropy_mesh = entropy_mesh tals = openmc.Tallies() tal = openmc.Tally(tally_id=1, name='test') tal.filters = [openmc.MaterialFilter(bins=[uo2])] tal.scores = ['flux', 'fission'] tals.append(tal) plot1 = openmc.Plot(plot_id=1) plot1.origin = (0., 0., 0.) plot1.width = (pitch, pitch) plot1.pixels = (300, 300) plot1.color_by = 'material' plot1.filename = 'test' plot2 = openmc.Plot(plot_id=2) plot2.origin = (0., 0., 0.) plot2.width = (pitch, pitch) plot2.pixels = (300, 300) plot2.color_by = 'cell' plots = openmc.Plots((plot1, plot2)) chain = './test_chain.xml' chain_file_xml = """<?xml version="1.0"?> <depletion_chain> <nuclide name="Xe136" decay_modes="0" reactions="0" /> <nuclide name="U235" decay_modes="0" reactions="1"> <reaction type="fission" Q="200000000."/> <neutron_fission_yields> <energies>2.53000e-02</energies> <fission_yields energy="2.53000e-02"> <products>Xe136</products> <data>1.0</data> </fission_yields> </neutron_fission_yields> </nuclide> </depletion_chain> """ operator_kwargs = {'chain_file': chain} return (mats, geom, settings, tals, plots, operator_kwargs, chain_file_xml)
def __init__(self, *args, **kwargs): super().__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.RegularMesh(name='mesh') 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]
settings_file.batches = batches settings_file.inactive = inactive settings_file.particles = particles settings_file.temperature = { 'method': 'nearest', 'tolerance': 300.0, 'multipole': False } settings_file.resonance_scattering = {'enable': False, 'method': 'dbrc'} # Create an initial uniform spatial source distribution over fissionable zones bounds = [-0.6300, -0.6300, -1, 0.6300, 0.6300, 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.RegularMesh() entropy_mesh.lower_left = [-0.4096, -0.4096, -1.e50] entropy_mesh.upper_right = [0.4096, 0.4096, 1.e50] entropy_mesh.dimension = [10, 10, 1] settings_file.entropy_mesh = entropy_mesh settings_file.export_to_xml() # plot setting plot = openmc.Plot(plot_id=1) plot.origin = [0, 0, 0] plot.width = [1.26, 1.26] plot.pixels = [500, 500] plot.color_by = 'material' # Instantiate a Plots object and export to XML plot_file = openmc.Plots([plot])
# Compute cell areas volume = {} volume[fuel_material] = np.pi * (fuel_surf.coefficients['r'] ** 2) * 2*np.abs(core_surf_lowertank_wall_in.coefficients['z0']) * 10 * 10 * 15*15 #volume[fuel_cold] = np.pi * s1.coefficients['r'] ** 2 # Set materials volume for depletion. Set to an area for 2D simulations fuel_material.volume = volume[fuel_material] #+ volume[fuel_hot]; print("Volume:", volume[fuel_material]) ############################################################################### tallies_file = openmc.Tallies() # XY-MESH #Creating mesh and mesh filter mesh_xy = openmc.RegularMesh(mesh_id=1) mesh_xy.dimension = [200,200,1] mesh_xy.lower_left = [-100,-100,-1.e50] mesh_xy.upper_right = [100,100,1.e50] mesh_filter_xy = openmc.MeshFilter(mesh_xy) particle_filter = openmc.ParticleFilter(['neutron','photon'], filter_id=2) #Creating mesh tally tally_xy = openmc.Tally(name='flux_xy',tally_id=1) tally_xy.filters = [mesh_filter_xy,particle_filter] tally_xy.scores = ['flux','fission','nu-fission'] tallies_file.append(tally_xy) # XZ-MESH