def make_materials_geometry_tallies(batches, enrichment_fraction, inner_radius, thickness, breeder_material_name, temperature_in_C): print('simulating ', batches, enrichment_fraction, inner_radius, thickness, breeder_material_name) #MATERIALS# breeder_material = make_breeder_material(enrichment_fraction, breeder_material_name, temperature_in_C) eurofer = make_eurofer() mats = openmc.Materials([breeder_material, eurofer]) #GEOMETRY# breeder_blanket_inner_surface = openmc.Sphere(R=inner_radius) breeder_blanket_outer_surface = openmc.Sphere(R=inner_radius + thickness) vessel_inner_surface = openmc.Sphere(R=inner_radius + thickness + 10) vessel_outer_surface = openmc.Sphere(R=inner_radius + thickness + 20, boundary_type='vacuum') breeder_blanket_region = -breeder_blanket_outer_surface & +breeder_blanket_inner_surface breeder_blanket_cell = openmc.Cell(region=breeder_blanket_region) breeder_blanket_cell.fill = breeder_material breeder_blanket_cell.name = 'breeder_blanket' inner_void_region = -breeder_blanket_inner_surface inner_void_cell = openmc.Cell(region=inner_void_region) inner_void_cell.name = 'inner_void' vessel_region = +vessel_inner_surface & -vessel_outer_surface vessel_cell = openmc.Cell(region=vessel_region) vessel_cell.name = 'vessel' vessel_cell.fill = eurofer blanket_vessel_gap_region = -vessel_inner_surface & +breeder_blanket_outer_surface blanket_vessel_gap_cell = openmc.Cell(region=blanket_vessel_gap_region) blanket_vessel_gap_cell.name = 'blanket_vessel_gap' universe = openmc.Universe(cells=[ inner_void_cell, breeder_blanket_cell, blanket_vessel_gap_cell, vessel_cell ]) geom = openmc.Geometry(universe) #SIMULATION SETTINGS# sett = openmc.Settings() # batches = 3 # this is parsed as an argument sett.batches = batches sett.inactive = 10 sett.particles = 500 sett.run_mode = 'fixed source' source = openmc.Source() source.space = openmc.stats.Point((0, 0, 0)) source.angle = openmc.stats.Isotropic() source.energy = openmc.stats.Muir( e0=14080000.0, m_rat=5.0, kt=20000.0 ) #neutron energy = 14.08MeV, AMU for D + T = 5, temperature is 20KeV sett.source = source #TALLIES# tallies = openmc.Tallies() # define filters cell_filter_breeder = openmc.CellFilter(breeder_blanket_cell) cell_filter_vessel = openmc.CellFilter(vessel_cell) particle_filter = openmc.ParticleFilter([1]) #1 is neutron, 2 is photon surface_filter_rear_blanket = openmc.SurfaceFilter( breeder_blanket_outer_surface) surface_filter_rear_vessel = openmc.SurfaceFilter(vessel_outer_surface) energy_bins = openmc.mgxs.GROUP_STRUCTURES['VITAMIN-J-175'] energy_filter = openmc.EnergyFilter(energy_bins) tally = openmc.Tally(name='TBR') tally.filters = [cell_filter_breeder, particle_filter] tally.scores = ['205'] tallies.append(tally) tally = openmc.Tally(name='blanket_leakage') tally.filters = [surface_filter_rear_blanket, particle_filter] tally.scores = ['current'] tallies.append(tally) tally = openmc.Tally(name='vessel_leakage') tally.filters = [surface_filter_rear_vessel, particle_filter] tally.scores = ['current'] tallies.append(tally) tally = openmc.Tally(name='breeder_blanket_spectra') tally.filters = [cell_filter_breeder, particle_filter, energy_filter] tally.scores = ['flux'] tallies.append(tally) tally = openmc.Tally(name='vacuum_vessel_spectra') tally.filters = [cell_filter_vessel, particle_filter, energy_filter] tally.scores = ['flux'] tallies.append(tally) tally = openmc.Tally(name='DPA') tally.filters = [cell_filter_vessel, particle_filter] tally.scores = ['444'] tallies.append(tally) #RUN OPENMC # model = openmc.model.Model(geom, mats, sett, tallies) model.run() sp = openmc.StatePoint('statepoint.' + str(batches) + '.h5') json_output = { 'enrichment_fraction': enrichment_fraction, 'inner_radius': inner_radius, 'thickness': thickness, 'breeder_material_name': breeder_material_name, 'temperature_in_C': temperature_in_C } tallies_to_retrieve = ['TBR', 'DPA', 'blanket_leakage', 'vessel_leakage'] for tally_name in tallies_to_retrieve: tally = sp.get_tally(name=tally_name) # for some reason the tally sum is a nested list tally_result = tally.sum[0][0][0] / batches # for some reason the tally std_dev is a nested list tally_std_dev = tally.std_dev[0][0][0] / batches json_output[tally_name] = { 'value': tally_result, 'std_dev': tally_std_dev } spectra_tallies_to_retrieve = [ 'breeder_blanket_spectra', 'vacuum_vessel_spectra' ] for spectra_name in spectra_tallies_to_retrieve: spectra_tally = sp.get_tally(name=spectra_name) spectra_tally_result = [entry[0][0] for entry in spectra_tally.mean] spectra_tally_std_dev = [ entry[0][0] for entry in spectra_tally.std_dev ] json_output[spectra_name] = { 'value': spectra_tally_result, 'std_dev': spectra_tally_std_dev, 'energy_groups': list(energy_bins) } return json_output
def make_model(): model = openmc.model.Model() # Materials m1 = openmc.Material() m1.set_density('g/cc', 4.5) m1.add_nuclide('U235', 1.0) m1.add_nuclide('H1', 1.0) m1.add_s_alpha_beta('c_H_in_H2O', fraction=0.5) m2 = openmc.Material() m2.set_density('g/cc', 4.5) m2.add_nuclide('U235', 1.0) m2.add_nuclide('C0', 1.0) m2.add_s_alpha_beta('c_Graphite') m3 = openmc.Material() m3.set_density('g/cc', 4.5) m3.add_nuclide('U235', 1.0) m3.add_nuclide('Be9', 1.0) m3.add_nuclide('O16', 1.0) m3.add_s_alpha_beta('c_Be_in_BeO') m3.add_s_alpha_beta('c_O_in_BeO') m4 = openmc.Material() m4.set_density('g/cm3', 5.90168) m4.add_nuclide('H1', 0.3) m4.add_nuclide('Zr90', 0.15) m4.add_nuclide('Zr91', 0.1) m4.add_nuclide('Zr92', 0.1) m4.add_nuclide('Zr94', 0.05) m4.add_nuclide('Zr96', 0.05) m4.add_nuclide('U235', 0.1) m4.add_nuclide('U238', 0.15) m4.add_s_alpha_beta('c_Zr_in_ZrH') m4.add_s_alpha_beta('c_H_in_ZrH') model.materials += [m1, m2, m3, m4] # Geometry x0 = openmc.XPlane(x0=-10, boundary_type='vacuum') x1 = openmc.XPlane(x0=-5) x2 = openmc.XPlane(x0=0) x3 = openmc.XPlane(x0=5) x4 = openmc.XPlane(x0=10, boundary_type='vacuum') root_univ = openmc.Universe() surfs = (x0, x1, x2, x3, x4) mats = (m1, m2, m3, m4) cells = [] for i in range(4): cell = openmc.Cell() cell.region = +surfs[i] & -surfs[i + 1] cell.fill = mats[i] root_univ.add_cell(cell) model.geometry.root_universe = root_univ # Settings model.settings.batches = 5 model.settings.inactive = 0 model.settings.particles = 1000 model.settings.source = openmc.Source( space=openmc.stats.Box([-4, -4, -4], [4, 4, 4])) return model
def initial(self, opt, Mesh): #, nthreads): ##################################### # Create OpenMC geometry ##################################### FuelOR = opt.FuelOR * 100 #[cm] CladIR = opt.CladIR * 100 #[cm] CladOR = opt.CladOR * 100 #[cm] # ExtraCladOR = opt.ExtraCladOR*100 #[cm] Pitch = opt.PinPitch * 100 #[cm] # Construct uniform initial source distribution over fissionable zones lower_left = [-Pitch / 2, -Pitch / 2, 0] upper_right = [+Pitch / 2, +Pitch / 2, +365.76] uniform_dist = openmc.stats.Box(lower_left, upper_right, only_fissionable=True) # Settings file self.settings_file = openmc.Settings() self.settings_file.batches = 1100 self.settings_file.inactive = 100 self.settings_file.particles = 20000 self.settings_file.generations_per_batch = 5 self.settings_file.output = {'tallies': False} self.settings_file.temperature = {'multipole': True, 'tolerance': 3000} self.settings_file.source = openmc.source.Source(space=uniform_dist) self.settings_file.seed = np.random.randint(1, 100) # for correlation self.settings_file.export_to_xml() #Removed for correlation # Materials file uo2 = openmc.Material(material_id=1, name='UO2 fuel at 2.4% wt enrichment') uo2.temperature = 900. #opt.Tin uo2.set_density('g/cm3', 10.29769) uo2.add_element('U', 1., enrichment=2.4) uo2.add_element('O', 2.) # helium = openmc.Material(material_id=2, name='Helium for gap') # helium.temperature = opt.Tin # helium.set_density('g/cm3', 0.001598) # helium.add_element('He', 2.4044e-4) zircaloy = openmc.Material(material_id=3, name='Zircaloy 4') zircaloy.temperature = opt.Tin zircaloy.set_density('g/cm3', 6.55) zircaloy.add_element('Sn', 0.014, 'wo') zircaloy.add_element('Fe', 0.00165, 'wo') zircaloy.add_element('Cr', 0.001, 'wo') zircaloy.add_element('Zr', 0.98335, 'wo') # borated_water = openmc.Material() # borated_water.temperature = opt.Tin # borated_water.set_density('g/cm3', 0.7406) # 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 = openmc.model.borated_water(boron_ppm=432.473, temperature=opt.Tin, pressure=15) self.materials_file = openmc.Materials([uo2, zircaloy, borated_water]) #helium self.materials_file.export_to_xml() #Removed for correlation # Geometry file fuel_or = openmc.ZCylinder(x0=0, y0=0, R=FuelOR) # clad_ir = openmc.ZCylinder(x0=0, y0=0, R=CladIR) clad_or = openmc.ZCylinder(x0=0, y0=0, R=CladOR) # extra_clad_or = openmc.ZCylinder(x0=0, y0=0, R=ExtraCladOR) left = openmc.XPlane(x0=-Pitch / 2) right = openmc.XPlane(x0=Pitch / 2) back = openmc.YPlane(y0=-Pitch / 2) front = openmc.YPlane(y0=Pitch / 2) top = openmc.ZPlane(z0=396.24) bottom = openmc.ZPlane(z0=-30.48) z_list = [] for i in range(0, len(Mesh)): z_list.append(openmc.ZPlane(z0=Mesh[i])) left.boundary_type = 'reflective' right.boundary_type = 'reflective' front.boundary_type = 'reflective' back.boundary_type = 'reflective' top.boundary_type = 'vacuum' bottom.boundary_type = 'vacuum' # z_list[-1].boundary_type = 'vacuum' # z_list[0].boundary_type = 'vacuum' self.reflectTOP = openmc.Cell() self.reflectBOT = openmc.Cell() self.fuel_list = [] # self.gap_list = [] self.clad_list = [] # self.extra_clad_list = [] self.water_list = [] for i in range(0, len(Mesh) - 1): self.fuel_list.append(openmc.Cell()) # self.gap_list.append(openmc.Cell()) self.clad_list.append(openmc.Cell()) # self.extra_clad_list.append(openmc.Cell()) self.water_list.append(openmc.Cell()) self.reflectTOP.region = +left & -right & +back & -front & +z_list[ -1] & -top self.reflectBOT.region = +left & -right & +back & -front & +bottom & -z_list[ 0] self.reflectTOP.fill = borated_water self.reflectBOT.fill = borated_water j = 0 for fuels in self.fuel_list: fuels.region = -fuel_or & +z_list[j] & -z_list[j + 1] fuels.fill = uo2 j = j + 1 # j = 0 # for gaps in self.gap_list: # gaps.region = +fuel_or & -clad_ir & +z_list[j] & -z_list[j+1] # gaps.fill = helium # j = j+1 j = 0 for clads in self.clad_list: clads.region = +fuel_or & -clad_or & +z_list[j] & -z_list[ j + 1] #clad_ir instead of fuel_or clads.fill = zircaloy j = j + 1 # j = 0 # for extra_clads in self.extra_clad_list: # extra_clads.region = +clad_or & -extra_clad_or & +left & -right & +back & -front & +z_list[j] & -z_list[j+1] # grid_flag = 0 # for i in range(0,len(opt.GridBot_z)): # if z_list[j].z0 == opt.GridBot_z[i]: # extra_clads.fill = zircaloy # grid_flag = 1 # if grid_flag == 1: # extra_clads.fill = zircaloy # else: # extra_clads.fill = borated_water # extra_clads.fill = borated_water # j = j+1 j = 0 for waters in self.water_list: waters.region = +clad_or & +left & -right & +back & -front & +z_list[ j] & -z_list[j + 1] waters.fill = borated_water j = j + 1 self.root = openmc.Universe(universe_id=0, name='root universe') self.root.add_cells(self.fuel_list) # self.root.add_cells(self.gap_list) self.root.add_cells(self.clad_list) # self.root.add_cells(self.extra_clad_list) self.root.add_cells(self.water_list) self.root.add_cells([self.reflectTOP, self.reflectBOT]) self.geometry_file = openmc.Geometry(self.root) self.geometry_file.export_to_xml() #Removed for correlation # Tallies # power distribution: fission q recoverable (Sterling's note: starts 0, might be data pb) # openmc accounts for incoming neutron energy and isotope cell_filter = openmc.CellFilter(self.fuel_list) t = openmc.Tally(tally_id=1) t.filters.append(cell_filter) t.scores = ['fission-q-recoverable'] tallies = openmc.Tallies([t]) tallies.export_to_xml() #Removed for correlation # Plots plot = openmc.Plot() plot.width = [Pitch + 45, Pitch + 45] plot.origin = [0., 0., -20] plot.color_by = 'material' plot.filename = 'fuel-pin' plot.pixels = [1000, 1000] plot.basis = 'yz' # openmc.plot_inline(plot) # Move Files to PinGeo folder #Removed for correlation shutil.move('settings.xml', 'PinGeo/settings.xml') shutil.move('materials.xml', 'PinGeo/materials.xml') shutil.move('geometry.xml', 'PinGeo/geometry.xml') shutil.move('tallies.xml', 'PinGeo/tallies.xml') # shutil.move('plots.xml', 'PinGeo/plots.xml') openmc.run( cwd='PinGeo') #, threads=nthreads, mpi_args=['mpiexec','-n','2']) sp = openmc.StatePoint('PinGeo/statepoint.' + str(self.settings_file.batches) + '.h5') tally = sp.get_tally(scores=['fission-q-recoverable']) self.Tally = np.ndarray.flatten(tally.sum) Pfactor = 66945.4 / sum(np.ndarray.flatten(tally.sum)) # print("Pfactor: ", Pfactor) self.Tally = np.ndarray.flatten(tally.sum) * Pfactor self.Var = np.divide(np.ndarray.flatten(tally.std_dev), np.ndarray.flatten(tally.mean))
def make_geometry_tallies(batches, nps, inner_radius, thickness): first_wall_inner_surface = openmc.Sphere(r=inner_radius) first_wall_outer_surface = openmc.Sphere(r=inner_radius + thickness, boundary_type='vacuum') first_wall = +first_wall_inner_surface & -first_wall_outer_surface first_wall = openmc.Cell(region=first_wall) first_wall.fill = eurofer inner_vac_cell = -first_wall_inner_surface inner_vac_cell = openmc.Cell(region=inner_vac_cell) universe = openmc.Universe(cells=[first_wall, inner_vac_cell]) geom = openmc.Geometry(universe) geom.export_to_xml('geometry') vox_plot = openmc.Plot() vox_plot.type = 'voxel' vox_plot.width = (10, 10, 10) vox_plot.pixels = (200, 200, 200) vox_plot.filename = 'plot_3d' vox_plot.color_by = 'material' vox_plot.colors = {eurofer: 'blue'} plots = openmc.Plots([vox_plot]) plots.export_to_xml() openmc.plot_geometry() os.system('openmc-voxel-to-vtk plot_3d.h5 -o plot_3d.vti') os.system('paraview plot_3d.vti') sett = openmc.Settings() sett.batches = batches sett.inactive = 0 sett.particles = nps sett.run_mode = 'fixed source' source = openmc.Source() source.space = openmc.stats.Point((0, 0, 0)) source.angle = openmc.stats.Isotropic() source.energy = openmc.stats.Discrete([14.08e6], [1]) #source.energy = openmc.stats.Muir(e0=14080000.0, m_rat=5.0, kt=20000.0) sett.source = source sett.export_to_xml('settings.xml') #tallies particle_filter = openmc.ParticleFilter([1]) surface_filter_front = openmc.SurfaceFilter(first_wall_inner_surface) surface_filter_rear = openmc.SurfaceFilter(first_wall_outer_surface) bins = openmc.mgxs.GROUP_STRUCTURES['VITAMIN-J-175'] #think will need to change this energy_filter = openmc.EnergyFilter(bins) tallies = openmc.Tallies() tally = openmc.Tally(name='wall_leakage') tally.filters = [surface_filter_rear, particle_filter] tally.scores = ['current'] tallies.append(tally) tally = openmc.Tally(name='incident_neutron_spectrum') tally.filters = [surface_filter_rear, particle_filter, energy_filter] tally.scores = ['flux'] tallies.append(tally) tally = openmc.Tally(name='leakage_neutron_spectrum') tally.filters = [surface_filter_front, particle_filter, energy_filter] tally.scores = ['flux'] tallies.append(tally) model = openmc.model.Model(geom, mats, sett, tallies) model.run() sp = openmc.StatePoint('statepoint.' + str(batches) + '.h5') tallies_to_retrieve = ['wall_leakage'] #at the moment, we only have one tally to retrieve, but we will set it up in a list anyway so we know how to do it for tally_name in tallies_to_retrieve: tally = sp.get_tally(name=tally_name) df = tally.get_pandas_dataframe() #defining something that stands for dataframe, need to investigate this #its basically something that we use to obtain the mean value and the std deviation value of the tally tally_result = df['mean'].sum() tally_std_dev = df['std. dev.'].sum() #for now, we will just try to print these values #get spectra spectra_tallies_to_retrieve = [ 'incident_neutron_spectrum', 'leakage_neutron_spectrum' ] for spectra_name in spectra_tallies_to_retrieve: spectra_tally = sp.get_tally(name=spectra_name) spectra_tally_result = [entry[0][0] for entry in spectra_tally.mean] spectra_tally_std_dev = [ entry[0][0] for entry in spectra_tally.std_dev ]
# Instantiate Surfaces left = openmc.XPlane(surface_id=1, x0=-2, name='left') right = openmc.XPlane(surface_id=2, x0=2, name='right') bottom = openmc.YPlane(surface_id=3, y0=-2, name='bottom') top = openmc.YPlane(surface_id=4, y0=2, name='top') fuel1 = openmc.ZCylinder(surface_id=5, x0=0, y0=0, R=0.4) fuel2 = openmc.ZCylinder(surface_id=6, x0=0, y0=0, R=0.3) fuel3 = openmc.ZCylinder(surface_id=7, x0=0, y0=0, R=0.2) left.boundary_type = 'vacuum' right.boundary_type = 'vacuum' top.boundary_type = 'vacuum' bottom.boundary_type = 'vacuum' # Instantiate Cells cell1 = openmc.Cell(cell_id=1, name='Cell 1') cell2 = openmc.Cell(cell_id=101, name='cell 2') cell3 = openmc.Cell(cell_id=102, name='cell 3') cell4 = openmc.Cell(cell_id=201, name='cell 4') cell5 = openmc.Cell(cell_id=202, name='cell 5') cell6 = openmc.Cell(cell_id=301, name='cell 6') cell7 = openmc.Cell(cell_id=302, name='cell 7') # Use surface half-spaces to define regions cell1.region = +left & -right & +bottom & -top cell2.region = -fuel1 cell3.region = +fuel1 cell4.region = -fuel2 cell5.region = +fuel2 cell6.region = -fuel3 cell7.region = +fuel3
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 simulate_model( enrichment, thickness, breeder_material_name="Li4SiO4", temperature_in_C=500, batches=2, nps=500, inner_radius=500, ): # MATERIALS from library of materials in neutronics_material_maker package breeder_material = Material( material_name=breeder_material_name, enrichment=enrichment, temperature_in_C=temperature_in_C, ).neutronics_material SS316 = Material(material_name="SS316").neutronics_material copper = Material(material_name="copper").neutronics_material mats = openmc.Materials([breeder_material, SS316, copper]) mats.export_to_xml("materials.xml") # GEOMETRY# first_wall_inner_surface = openmc.Sphere(r=inner_radius) first_wall_outer_surface = openmc.Sphere(r=inner_radius + 10.) breeder_blanket_outer_surface = openmc.Sphere(r=inner_radius + 10. + thickness) vessel_outer_surface = openmc.Sphere(r=inner_radius + 10.0 + thickness + 10., boundary_type="vacuum") inner_void_region = -first_wall_inner_surface inner_void_cell = openmc.Cell(region=inner_void_region) inner_void_cell.name = "inner_void" first_wall_region = (-first_wall_outer_surface & +first_wall_inner_surface) first_wall_cell = openmc.Cell(region=first_wall_region) first_wall_cell.fill = SS316 breeder_blanket_region = (+first_wall_outer_surface & -breeder_blanket_outer_surface) breeder_blanket_cell = openmc.Cell(region=breeder_blanket_region) breeder_blanket_cell.fill = breeder_material vessel_region = +breeder_blanket_outer_surface & -vessel_outer_surface vessel_cell = openmc.Cell(region=vessel_region) vessel_cell.name = "vessel" vessel_cell.fill = SS316 universe = openmc.Universe(cells=[ inner_void_cell, first_wall_cell, breeder_blanket_cell, vessel_cell ]) geom = openmc.Geometry(universe) # SIMULATION SETTINGS# sett = openmc.Settings() sett.batches = batches # this is the minimum number of batches which will be run sett.trigger_active = True sett.trigger_max_batches = 200 # this is the maximum number of batches which will be run sett.inactive = 0 sett.particles = nps # as we are using a trigger, we specify a small number of particles per batch sett.run_mode = "fixed source" source = openmc.Source() source.space = openmc.stats.Point((150, 0, 0)) source.angle = openmc.stats.Isotropic() source.energy = openmc.stats.Discrete([14.08e6], [1]) sett.source = source # sett.export_to_xml("settings.xml") # tally filters particle_filter = openmc.ParticleFilter("neutron") cell_filter_breeder = openmc.CellFilter(breeder_blanket_cell) # TALLIES# tallies = openmc.Tallies() tally = openmc.Tally(name="TBR") tally.filters = [cell_filter_breeder, particle_filter] tally.scores = ["(n,Xt)"] tally.triggers = [openmc.Trigger(trigger_type='std_dev', threshold=0.01)] tallies.append(tally) # RUN OPENMC # model = openmc.model.Model(geom, mats, sett, tallies) sp_filename = model.run(output=False) # RETRIEVING TALLY RESULTS sp = openmc.StatePoint(sp_filename) json_output = { "batches": batches, "nps": nps, "enrichment": enrichment, "inner_radius": inner_radius, "thickness": thickness, "breeder_material_name": breeder_material_name, "temperature_in_C": temperature_in_C, } tally = sp.get_tally(name="TBR") df = tally.get_pandas_dataframe() json_output["TBR"] = df["mean"].sum() json_output["TBR_std_dev"] = df["std. dev."].sum() return json_output
s8.boundary_type = 'vacuum' s31 = openmc.ZPlane(z0=-229.0, surface_id=31) s31.boundary_type = 'vacuum' s32 = openmc.ZPlane(z0=-199.0, surface_id=32) s33 = openmc.ZPlane(z0=-193.0, surface_id=33) s34 = openmc.ZPlane(z0=-183.0, surface_id=34) s35 = openmc.ZPlane(z0=0.0, surface_id=35) s36 = openmc.ZPlane(z0=183.0, surface_id=36) s37 = openmc.ZPlane(z0=203.0, surface_id=37) s38 = openmc.ZPlane(z0=215.0, surface_id=38) s39 = openmc.ZPlane(z0=223.0, surface_id=39) s39.boundary_type = 'vacuum' # Define pin cells. c21 = openmc.Cell(cell_id=21, fill=fuel, region=-s1) c22 = openmc.Cell(cell_id=22, fill=clad, region=+s1 & -s2) c23 = openmc.Cell(cell_id=23, fill=cold_water, region=+s2) fuel_cold = openmc.Universe(name='Fuel pin, cladding, cold water', universe_id=1, cells=(c21, c22, c23)) c24 = openmc.Cell(cell_id=24, fill=cold_water, region=-s3) c25 = openmc.Cell(cell_id=25, fill=clad, region=+s3 & -s4) c26 = openmc.Cell(cell_id=26, fill=cold_water, region=+s4) tube_cold = openmc.Universe(name='Instrumentation guide tube, cold water', universe_id=2, cells=(c24, c25, c26)) c27 = openmc.Cell(cell_id=27, fill=fuel, region=-s1) c28 = openmc.Cell(cell_id=28, fill=clad, region=+s1 & -s2) c29 = openmc.Cell(cell_id=29, fill=hot_water, region=+s2) fuel_hot = openmc.Universe(name='Fuel pin, cladding, hot water',
borated_water.add_element('O', 2.4e-2) borated_water.add_s_alpha_beta('c_H_in_H2O') ############################################################################### # Create geometry ############################################################################### # Create 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') pitch = 1.25984 box = openmc.model.rectangular_prism(pitch, pitch, boundary_type='reflective') # Create cells fuel = openmc.Cell(fill=uo2, region=-fuel_or) gap = openmc.Cell(fill=helium, region=+fuel_or & -clad_ir) clad = openmc.Cell(fill=zircaloy, region=+clad_ir & -clad_or) water = openmc.Cell(fill=borated_water, region=+clad_or & box) # Create a geometry geometry = openmc.Geometry([fuel, gap, clad, water]) ############################################################################### # Set volumes of depletable materials ############################################################################### # Since this is a 2D model, use area instead of volume uo2.volume = pi * fuel_or.r**2 ###############################################################################
surf1 = openmc.XPlane(surface_id=1, x0=-1, name='surf 1') surf2 = openmc.XPlane(surface_id=2, x0=+1, name='surf 2') surf3 = openmc.YPlane(surface_id=3, y0=-1, name='surf 3') surf4 = openmc.YPlane(surface_id=4, y0=+1, name='surf 4') surf5 = openmc.ZPlane(surface_id=5, z0=-1, name='surf 5') surf6 = openmc.ZPlane(surface_id=6, z0=+1, name='surf 6') surf1.boundary_type = 'vacuum' surf2.boundary_type = 'vacuum' surf3.boundary_type = 'reflective' surf4.boundary_type = 'reflective' surf5.boundary_type = 'reflective' surf6.boundary_type = 'reflective' # Instantiate Cell cell = openmc.Cell(cell_id=1, name='cell 1') # Use surface half-spaces to define region cell.region = +surf1 & -surf2 & +surf3 & -surf4 & +surf5 & -surf6 # Register Material with Cell cell.fill = fuel # Instantiate Universes root = openmc.Universe(universe_id=0, name='root universe') # Register Cell with Universe root.add_cell(cell) # Instantiate a Geometry and register the root Universe geometry = openmc.Geometry()
# sheild_material.add_material(natural_tungsten, 0.9, 'ao') # sheild_material.add_material(natural_copper, 0.1, 'ao') # mats.append(sheild_material) mats.export_to_xml() #example surfaces surface_sph1 = openmc.Sphere(r=500) surface_sph2 = openmc.Sphere(r=600) #add more surfaces here using https://openmc.readthedocs.io/en/stable/usersguide/geometry.html#surfaces-and-regions volume_sph1 = +surface_sph1 & -surface_sph2 # above (+) surface_sph and below (-) surface_sph2 #example cell cell_1 = openmc.Cell(region=volume_sph1) cell_1.fill = natural_lead #assigning a material to a cell #add more cells here universe = openmc.Universe( cells=[cell_1]) #hint, this list will need to include the new cell plt.show(universe.plot(width=(1200, 1200), basis='xz', colors={cell_1: 'blue'})) plt.show(universe.plot(width=(1200, 1200), basis='xy', colors={cell_1: 'blue'})) plt.show(universe.plot(width=(1200, 1200), basis='yz', colors={cell_1: 'blue'})) universe.plot(width=(1200, 1200), basis='xz', colors={
def build_cells(self, bc=['reflective'] * 6): """Generates a lattice of universes with the same dimensionality as the mesh object. The individual cells/universes produced will not have material definitions applied and so downstream code will have to apply that information. Parameters ---------- bc : iterable of {'reflective', 'periodic', 'transmission', or 'vacuum'} Boundary conditions for each of the four faces of a rectangle (if aplying to a 2D mesh) or six faces of a parallelepiped (if applying to a 3D mesh) provided in the following order: [x min, x max, y min, y max, z min, z max]. 2-D cells do not contain the z min and z max entries. Returns ------- root_cell : openmc.Cell The cell containing the lattice representing the mesh geometry; this cell is a single parallelepiped with boundaries matching the outermost mesh boundary with the boundary conditions from bc applied. cells : iterable of openmc.Cell The list of cells within each lattice position mimicking the mesh geometry. """ cv.check_length('bc', bc, length_min=4, length_max=6) for entry in bc: cv.check_value( 'bc', entry, ['transmission', 'vacuum', 'reflective', 'periodic']) n_dim = len(self.dimension) # Build the cell which will contain the lattice xplanes = [ openmc.XPlane(self.lower_left[0], bc[0]), openmc.XPlane(self.upper_right[0], bc[1]) ] if n_dim == 1: yplanes = [ openmc.YPlane(-1e10, 'reflective'), openmc.YPlane(1e10, 'reflective') ] else: yplanes = [ openmc.YPlane(self.lower_left[1], bc[2]), openmc.YPlane(self.upper_right[1], bc[3]) ] if n_dim <= 2: # Would prefer to have the z ranges be the max supported float, but # these values are apparently different between python and Fortran. # Choosing a safe and sane default. # Values of +/-1e10 are used here as there seems to be an # inconsistency between what numpy uses as the max float and what # Fortran expects for a real(8), so this avoids code complication # and achieves the same goal. zplanes = [ openmc.ZPlane(-1e10, 'reflective'), openmc.ZPlane(1e10, 'reflective') ] else: zplanes = [ openmc.ZPlane(self.lower_left[2], bc[4]), openmc.ZPlane(self.upper_right[2], bc[5]) ] root_cell = openmc.Cell() root_cell.region = ((+xplanes[0] & -xplanes[1]) & (+yplanes[0] & -yplanes[1]) & (+zplanes[0] & -zplanes[1])) # Build the universes which will be used for each of the (i,j,k) # locations within the mesh. # We will concurrently build cells to assign to these universes cells = [] universes = [] for index in self.indices: cells.append(openmc.Cell()) universes.append(openmc.Universe()) universes[-1].add_cell(cells[-1]) lattice = openmc.RectLattice() lattice.lower_left = self.lower_left # Assign the universe and rotate to match the indexing expected for # the lattice if n_dim == 1: universe_array = np.array([universes]) elif n_dim == 2: universe_array = np.empty(self.dimension[::-1], dtype=openmc.Universe) i = 0 for y in range(self.dimension[1] - 1, -1, -1): for x in range(self.dimension[0]): universe_array[y][x] = universes[i] i += 1 else: universe_array = np.empty(self.dimension[::-1], dtype=openmc.Universe) i = 0 for z in range(self.dimension[2]): for y in range(self.dimension[1] - 1, -1, -1): for x in range(self.dimension[0]): universe_array[z][y][x] = universes[i] i += 1 lattice.universes = universe_array if self.width is not None: lattice.pitch = self.width else: dx = ((self.upper_right[0] - self.lower_left[0]) / self.dimension[0]) if n_dim == 1: lattice.pitch = [dx] elif n_dim == 2: dy = ((self.upper_right[1] - self.lower_left[1]) / self.dimension[1]) lattice.pitch = [dx, dy] else: dy = ((self.upper_right[1] - self.lower_left[1]) / self.dimension[1]) dz = ((self.upper_right[2] - self.lower_left[2]) / self.dimension[2]) lattice.pitch = [dx, dy, dz] # Fill Cell with the Lattice root_cell.fill = lattice return root_cell, cells
def define_Geo_Mat_Set(cells_num_dic,parameters_dic,settings_dic,temp_phy_mat,controlRod_deep,empty_reflector_height): # Check file if os.path.exists('geometry.xml'): os.remove('geometry.xml') if os.path.exists('materials.xml'): os.remove('materials.xml') if os.path.exists('settings.xml'): os.remove('settings.xml') if os.path.exists('tallies.xml'): os.remove('tallies.xml') # defualt temperature: 1073.5K if settings_dic['temperature_update']== True: temp_defualt = temp_phy_mat.min() else: temp_defualt = 1073.5 # Structural Material HAYNES230 structure_HAY = openmc.Material(name='HAYNES230') structure_HAY.set_density('g/cm3',8.97) structure_HAY.add_element('Ni',0.57,'wo') structure_HAY.add_element('Cr',0.22,'wo') structure_HAY.add_element('W',0.14,'wo') structure_HAY.add_element('Mo',0.02,'wo') structure_HAY.add_element('Fe',0.01875,'wo') structure_HAY.add_element('Co',0.03125,'wo') # Structural Material SS316 structure_SS = openmc.Material(name='SS316') structure_SS.set_density('g/cm3',7.99) structure_SS.add_element('Ni',0.12,'wo') structure_SS.add_element('Cr',0.17,'wo') structure_SS.add_element('Mo',0.025,'wo') structure_SS.add_element('Mn',0.02,'wo') structure_SS.add_element('Fe',0.665,'wo') #Control Rod Material B4C ControlRod_B4C = openmc.Material(name='B4C') ControlRod_B4C.set_density('g/cm3',2.52) ControlRod_B4C.add_nuclide('B10',4,'ao') ControlRod_B4C.add_element('C',1,'ao') #Reflector Material BeO Reflector_BeO = openmc.Material(name='BeO') Reflector_BeO.set_density('g/cm3',3.025) Reflector_BeO.add_element('Be',1,'ao') Reflector_BeO.add_element('O',1,'ao') #Coolant Na Coolant_Na = openmc.Material(name='Na') Coolant_Na.set_density('g/cm3',0.76) Coolant_Na.add_element('Na',1,'ao') # Instantiate a Materials collection materials_file = openmc.Materials([structure_HAY, structure_SS, ControlRod_B4C, Reflector_BeO, Coolant_Na]) # Number of cells n_r = cells_num_dic['n_r'] n_r_outer = cells_num_dic['n_r_outer'] n_h = cells_num_dic['n_h'] # Effect of Temperature on density of fuel fuel_list = [] density_mat = calUMoDensity(temp_phy_mat) # Fuel U-10Mo for j in range(n_h): for i in range(n_r): fuel_name = str((j+1)*10000+(i + 1)*100) fuel = openmc.Material(name='U-10Mo '+ fuel_name) fuel.set_density('g/cm3',density_mat[j,i]) fuel.add_element('Mo',0.1,'wo') # fuel.add_nuclide('U235',0.1773,'wo') # for LEU (19.7%) # fuel.add_nuclide('U238',0.7227,'wo') fuel.add_nuclide('U235',0.837,'wo') # for HEU (93.0%) fuel.add_nuclide('U238',0.063,'wo') fuel_list.append(fuel) materials_file.append(fuel) for i in range(n_r_outer): fuel_name = str((j+1)*10000+(i + n_r + 1)*100) fuel = openmc.Material(name='U-10Mo '+ fuel_name) fuel.set_density('g/cm3',density_mat[j,i+n_r]) fuel.add_element('Mo',0.1,'wo') # fuel.add_nuclide('U235',0.1773,'wo') # for LEU (19.7%) # fuel.add_nuclide('U238',0.7227,'wo') fuel.add_nuclide('U235',0.837,'wo') # for HEU (93.0%) fuel.add_nuclide('U238',0.063,'wo') fuel_list.append(fuel) materials_file.append(fuel) # Export to "materials.xml" materials_file.export_to_xml() num_heat_pipe = 8 # Parameters of reactor # Unit:cm fuel_r = parameters_dic['fuel_r'] fuel_h = parameters_dic['fuel_h'] controlRod_r = parameters_dic['controlRod_r'] controlRod_h_max = parameters_dic['controlRod_h_max'] controlRod_l = parameters_dic['controlRod_l'] reflector_r = parameters_dic['reflector_r'] reflector_h = parameters_dic['reflector_h'] heat_pipe_R = parameters_dic['heat_pipe_R'] heat_pipe_r = parameters_dic['heat_pipe_r'] top_distance = parameters_dic['top_distance'] bottom_distance = parameters_dic['bottom_distance'] # Create cylinders for the fuel control rod and reflector fuel_OD = openmc.ZCylinder(x0=0.0, y0=0.0, r=fuel_r) controlRod_OD = openmc.ZCylinder(x0=0.0, y0=0.0, r=controlRod_r) reflector_OD = openmc.ZCylinder(x0=0.0, y0=0.0, r=reflector_r, boundary_type='vacuum') # Create planes for fuel control rod and reflector reflector_TOP = openmc.ZPlane(z0 = (top_distance+fuel_h/2),boundary_type='vacuum') reflector_BOTTOM = openmc.ZPlane(z0 = -(bottom_distance+fuel_h/2),boundary_type='vacuum') reflector_empty_TOP = openmc.ZPlane(z0 = -(bottom_distance+fuel_h/2-empty_reflector_height)) fuel_TOP = openmc.ZPlane(z0 = fuel_h/2) fuel_BOTTOM = openmc.ZPlane(z0 = -fuel_h/2) controlRodSpace_TOP = openmc.ZPlane(z0 = (controlRod_h_max-bottom_distance-fuel_h/2)) # Create cylinders for heat pipes heat_pipe_OD = openmc.ZCylinder(x0=fuel_r, y0=0, r=heat_pipe_R) n_ang = num_heat_pipe ang_mesh = np.pi/n_ang r_mesh = np.linspace(controlRod_r,(fuel_r-heat_pipe_R),n_r+1) r_outer_mesh = np.linspace(fuel_r-heat_pipe_R,fuel_r,n_r_outer+1) h_mesh = np.linspace(-fuel_h/2,fuel_h/2,n_h+1) line_1 = openmc.Plane(a=np.tan(-ang_mesh),b=-1.0,c=0.0,d=0.0,boundary_type='reflective') line_2 = openmc.Plane(a=np.tan(ang_mesh),b=-1.0,c=0.0,d=0.0,boundary_type='reflective') # Create volume vector and matrix volume_vec = np.zeros(n_r+n_r_outer) d_h = fuel_h/n_h for i in range(n_r+n_r_outer): if i >= n_r: d = heat_pipe_R*(i-n_r)/n_r_outer x_i = np.sqrt(2*heat_pipe_R*d-d*d) d = heat_pipe_R*(i-n_r+1)/n_r_outer x_i1 = np.sqrt(2*heat_pipe_R*d-d*d) s = (x_i+x_i1)*heat_pipe_R/n_r_outer volume_vec[i] = d_h*np.pi*(r_outer_mesh[i+1-n_r]*r_outer_mesh[i+1-n_r]-r_outer_mesh[i-n_r]*r_outer_mesh[i-n_r])/8-s else: volume_vec[i] = d_h*np.pi*(r_mesh[i+1]*r_mesh[i+1]-r_mesh[i]*r_mesh[i])/8 volume_mat = np.zeros((n_h,(n_r+n_r_outer))) for i in range(n_h): volume_mat[i,:] = volume_vec # Create heat_pipe universe heat_pipe_Inner = openmc.ZCylinder(r=heat_pipe_r) coolant_cell = openmc.Cell(fill=Coolant_Na, region=(-heat_pipe_Inner & -reflector_TOP & +reflector_BOTTOM)) pipe_cell = openmc.Cell(fill=structure_HAY, region=(+heat_pipe_Inner & -reflector_TOP & +reflector_BOTTOM)) heat_pipe_universe = openmc.Universe(cells=(coolant_cell, pipe_cell)) # Create a Universe to encapsulate a fuel pin pin_cell_universe = openmc.Universe(name='U-10Mo Pin') # Create fine-fuel-cell (num of cells: n_r + n_r_outer) fuel_cell_list = [] fuel_cell_ID_list = [] k = 0 for j in range(n_h): cir_top = openmc.ZPlane(z0 = h_mesh[j+1]) cir_bottom = openmc.ZPlane(z0 = h_mesh[j]) for i in range(n_r): cir_in = openmc.ZCylinder(r=r_mesh[i]) cir_out = openmc.ZCylinder(r=r_mesh[i+1]) fuel_cell = openmc.Cell() fuel_cell.fill = fuel_list[k] k = k+1 fuel_cell.region = +cir_in & -cir_out & +cir_bottom &-cir_top fuel_cell.temperature = temp_phy_mat[j,i] fuel_cell.id = (j+1)*10000+(i + 1)*100 fuel_cell_ID_list.append((j+1)*10000+(i + 1)*100) fuel_cell_list.append(fuel_cell) pin_cell_universe.add_cell(fuel_cell) for i in range(n_r_outer): cir_in = openmc.ZCylinder(r=r_outer_mesh[i]) cir_out = openmc.ZCylinder(r=r_outer_mesh[i+1]) fuel_cell = openmc.Cell() fuel_cell.fill = fuel_list[k] k = k+1 fuel_cell.region = +cir_in & -cir_out & +heat_pipe_OD & +cir_bottom &-cir_top fuel_cell.temperature = temp_phy_mat[j,i+n_r] fuel_cell.id = (j+1)*10000+(n_r + i + 1)*100 fuel_cell_ID_list.append((j+1)*10000+(n_r + i + 1)*100) fuel_cell_list.append(fuel_cell) pin_cell_universe.add_cell(fuel_cell) # Create control rod Cell controlRod_TOP = openmc.ZPlane(z0 = (controlRod_deep-fuel_h/2-bottom_distance)) controlRod_TOP.name = 'controlRod_TOP' if controlRod_deep < controlRod_h_max: controlRod_empty_cell = openmc.Cell(name='Control Rod Empty') controlRod_empty_cell.region = -controlRod_OD & +controlRod_TOP & -controlRodSpace_TOP pin_cell_universe.add_cell(controlRod_empty_cell) if controlRod_deep > 0: controlRod_cell = openmc.Cell(name='Control Rod') controlRod_cell.fill = ControlRod_B4C controlRod_cell.region = -controlRod_OD & +reflector_BOTTOM & -controlRod_TOP controlRod_cell.tempearture = temp_defualt pin_cell_universe.add_cell(controlRod_cell) # Create heat pipe Cell heat_pipe_cell = openmc.Cell(name='Heat Pipe') heat_pipe_cell.fill = heat_pipe_universe heat_pipe_cell.region = -heat_pipe_OD & +reflector_BOTTOM & -reflector_TOP heat_pipe_cell.temperature = temp_defualt heat_pipe_cell.translation = (fuel_r,0,0) pin_cell_universe.add_cell(heat_pipe_cell) # To be edited # Create reflector Cell if empty_reflector_height >0: reflector_radial_empty_cell = openmc.Cell(name='Radial Reflector Empty') reflector_radial_empty_cell.region = +fuel_OD & +heat_pipe_OD & +reflector_BOTTOM & -reflector_empty_TOP pin_cell_universe.add_cell(reflector_radial_empty_cell) reflector_radial_cell = openmc.Cell(name='Radial Reflector') reflector_radial_cell.fill = Reflector_BeO reflector_radial_cell.region = +fuel_OD & +heat_pipe_OD & +reflector_empty_TOP & -reflector_TOP reflector_radial_cell.temperature = temp_defualt pin_cell_universe.add_cell(reflector_radial_cell) else: reflector_radial_cell = openmc.Cell(name='Radial Reflector') reflector_radial_cell.fill = Reflector_BeO reflector_radial_cell.region = +fuel_OD & +heat_pipe_OD & +reflector_BOTTOM & -reflector_TOP reflector_radial_cell.temperature = temp_defualt pin_cell_universe.add_cell(reflector_radial_cell) reflector_bottom_cell = openmc.Cell(name='Bottom Reflector') reflector_bottom_cell.fill = Reflector_BeO reflector_bottom_cell.region = +controlRod_OD & +heat_pipe_OD & -fuel_OD & -fuel_BOTTOM & +reflector_BOTTOM reflector_bottom_cell.temperature = temp_defualt pin_cell_universe.add_cell(reflector_bottom_cell) reflector_top_cell = openmc.Cell(name='Top Reflector') reflector_top_cell.fill = Reflector_BeO reflector_top_cell.region = +heat_pipe_OD & -fuel_OD & +controlRodSpace_TOP & -reflector_TOP reflector_top_cell.region = reflector_top_cell.region | (+controlRod_OD & +heat_pipe_OD & -fuel_OD & +fuel_TOP & -controlRodSpace_TOP) reflector_top_cell.temperature = temp_defualt pin_cell_universe.add_cell(reflector_top_cell) # Create root Cell root_cell = openmc.Cell(name='root cell') root_cell.fill = pin_cell_universe # Add boundary planes root_cell.region = -reflector_OD & +line_2 & -line_1 & +reflector_BOTTOM & -reflector_TOP # Create root Universe root_universe = openmc.Universe(universe_id=0, name='root universe') root_universe.add_cell(root_cell) # Create Geometry and set root Universe geometry = openmc.Geometry(root_universe) # Export to "geometry.xml" geometry.export_to_xml() # Instantiate a Settings object settings_file = openmc.Settings() settings_file.batches = settings_dic['batches'] settings_file.inactive = settings_dic['inactive'] settings_file.particles = settings_dic['particles'] settings_file.temperature['multipole']= True settings_file.temperature['method']= 'interpolation' settings_file.source = openmc.Source(space=openmc.stats.Point((15,0,0))) # Export to "settings.xml" settings_file.export_to_xml() # Instantiate an empty Tallies object tallies_file = openmc.Tallies() for i in range(len(fuel_cell_ID_list)): tally = openmc.Tally(name='cell tally '+str(fuel_cell_ID_list[i])) tally.filters = [openmc.DistribcellFilter(fuel_cell_ID_list[i])] tally.scores = ['heating','flux'] tallies_file.append(tally) # Export to "tallies.xml" tallies_file.export_to_xml() return volume_mat,fuel_cell_ID_list
def _build_inputs(self): #################### # Materials #################### moderator = openmc.Material(material_id=1) moderator.set_density('g/cc', 1.0) moderator.add_nuclide('H1', 2.0) moderator.add_nuclide('O16', 1.0) dense_fuel = openmc.Material(material_id=2) dense_fuel.set_density('g/cc', 4.5) dense_fuel.add_nuclide('U235', 1.0) light_fuel = openmc.Material(material_id=3) light_fuel.set_density('g/cc', 2.0) light_fuel.add_nuclide('U235', 1.0) mats_file = openmc.Materials([moderator, dense_fuel, light_fuel]) mats_file.export_to_xml() #################### # Geometry #################### c1 = openmc.Cell(cell_id=1, fill=moderator) mod_univ = openmc.Universe(universe_id=1, cells=[c1]) r0 = openmc.ZCylinder(R=0.3) c11 = openmc.Cell(cell_id=11, region=-r0) c11.fill = [dense_fuel, light_fuel, None, dense_fuel] c12 = openmc.Cell(cell_id=12, region=+r0, fill=moderator) fuel_univ = openmc.Universe(universe_id=11, cells=[c11, c12]) lat = openmc.RectLattice(lattice_id=101) lat.lower_left = [-2.0, -2.0] lat.pitch = [2.0, 2.0] lat.universes = [[fuel_univ] * 2] * 2 lat.outer = mod_univ x0 = openmc.XPlane(x0=-3.0) x1 = openmc.XPlane(x0=3.0) y0 = openmc.YPlane(y0=-3.0) y1 = openmc.YPlane(y0=3.0) for s in [x0, x1, y0, y1]: s.boundary_type = 'reflective' c101 = openmc.Cell(cell_id=101, fill=lat) c101.region = +x0 & -x1 & +y0 & -y1 root_univ = openmc.Universe(universe_id=0, cells=[c101]) geometry = openmc.Geometry(root_univ) geometry.export_to_xml() #################### # Settings #################### sets_file = openmc.Settings() sets_file.batches = 5 sets_file.inactive = 0 sets_file.particles = 1000 sets_file.source = openmc.Source( space=openmc.stats.Box([-1, -1, -1], [1, 1, 1])) sets_file.export_to_xml() #################### # Plots #################### plot1 = openmc.Plot(plot_id=1) plot1.basis = 'xy' plot1.color_by = 'cell' plot1.filename = 'cellplot' plot1.origin = (0, 0, 0) plot1.width = (7, 7) plot1.pixels = (400, 400) plot2 = openmc.Plot(plot_id=2) plot2.basis = 'xy' plot2.color_by = 'material' plot2.filename = 'matplot' plot2.origin = (0, 0, 0) plot2.width = (7, 7) plot2.pixels = (400, 400) plots = openmc.Plots([plot1, plot2]) plots.export_to_xml()
def build_inf_model(xsnames, xslibname, temperature, tempmethod='nearest'): """ Building an infinite medium for openmc multi-group testing Parameters: ---------- xsnames : list of str() list with xs names xslibname: name of hdf5 file with cross-section library temperature : float value of a current temperature in K tempmethod : {'nearest', 'interpolation'} by default 'nearest' """ inf_medium = openmc.Material(name='test material', material_id=1) inf_medium.set_density("sum") for xs in xsnames: inf_medium.add_nuclide(xs, 1) INF = 11.1 # Instantiate a Materials collection and export to XML materials_file = openmc.Materials([inf_medium]) materials_file.cross_sections = xslibname materials_file.export_to_xml() # Instantiate boundary Planes min_x = openmc.XPlane(boundary_type='reflective', x0=-INF) max_x = openmc.XPlane(boundary_type='reflective', x0=INF) min_y = openmc.YPlane(boundary_type='reflective', y0=-INF) max_y = openmc.YPlane(boundary_type='reflective', y0=INF) # Instantiate a Cell cell = openmc.Cell(cell_id=1, name='cell') cell.temperature = temperature # Register bounding Surfaces with the Cell cell.region = +min_x & -max_x & +min_y & -max_y # Fill the Cell with the Material cell.fill = inf_medium # Create root universe root_universe = openmc.Universe(name='root universe', cells=[cell]) # Create Geometry and set root Universe openmc_geometry = openmc.Geometry(root_universe) # Export to "geometry.xml" openmc_geometry.export_to_xml() # OpenMC simulation parameters batches = 200 inactive = 5 particles = 5000 # Instantiate a Settings object settings_file = openmc.Settings() settings_file.batches = batches settings_file.inactive = inactive settings_file.particles = particles settings_file.energy_mode = 'multi-group' settings_file.output = {'summary': False} # Create an initial uniform spatial source distribution over fissionable zones bounds = [-INF, -INF, -INF, INF, INF, INF] uniform_dist = openmc.stats.Box(bounds[:3], bounds[3:], only_fissionable=True) settings_file.temperature = {'method': tempmethod} settings_file.source = openmc.Source(space=uniform_dist) settings_file.export_to_xml()
mats = openmc.Materials([breeder_material, eurofer, copper]) # GEOMETRY # surfaces central_sol_surface = openmc.ZCylinder(r=100) central_shield_outer_surface = openmc.ZCylinder(r=110) vessel_inner_surface = openmc.Sphere(r=500) first_wall_outer_surface = openmc.Sphere(r=510) breeder_blanket_outer_surface = openmc.Sphere(r=610, boundary_type='vacuum') # cells central_sol_region = -central_sol_surface & -breeder_blanket_outer_surface central_sol_cell = openmc.Cell(region=central_sol_region) central_sol_cell.fill = copper central_shield_region = +central_sol_surface & -central_shield_outer_surface & -breeder_blanket_outer_surface central_shield_cell = openmc.Cell(region=central_shield_region) central_shield_cell.fill = eurofer inner_vessel_region = -vessel_inner_surface & +central_shield_outer_surface inner_vessel_cell = openmc.Cell(region=inner_vessel_region) # no material set as default is vacuum first_wall_region = -first_wall_outer_surface & +vessel_inner_surface first_wall_cell = openmc.Cell(region=first_wall_region) first_wall_cell.fill = eurofer breeder_blanket_region = +first_wall_outer_surface & -breeder_blanket_outer_surface & +central_shield_outer_surface
def hexfunction(pitch, pack_frac): settings = openmc.Settings() # Set high tolerance to allow use of lower temperature xs settings.temperature['tolerance'] = 1000 settings.temperature['method'] = 'nearest' settings.temperature['multipole'] = True settings.cutoff = {'energy': 1e-8} #energy cutoff in eV ############################# ### MATERIALS ### ############################# mat_list = [] enrichment = 20.0 uo2 = openmc.Material(1, "uo2") uo2.add_element('U', 1.0, enrichment=enrichment) uo2.add_element('O', 2.0) uo2.set_density('g/cm3', 10.97) uo2.temperature = 900 #kelvin mat_list.append(uo2) graphite = openmc.Material(2, "graphite") graphite.set_density('g/cm3', 1.1995) graphite.add_element('C', 1.0) graphite.add_s_alpha_beta('c_Graphite') graphite.temperature = 900 #kelvin mat_list.append(graphite) # sodium = openmc.Material(3, "sodium") sodium = openmc.Material() sodium.set_density('g/cm3', 0.8017) # 900 K sodium.add_element('Na', 1.0) # sodium.add_s_alpha_beta('c_Graphite') sodium.temperature = 900 #kelvin mat_list.append(sodium) # naoh = openmc.Material(6, "naoh") naoh = openmc.Material() naoh.set_density('g/cm3', 1.5) # 900 K naoh.add_element('Na', 1.0) naoh.add_element('O', 1.0) naoh.add_element('H', 1.0) # sodium.add_s_alpha_beta('c_Graphite') naoh.temperature = 900 #kelvin mat_list.append(naoh) # TRISO Materials fuel = openmc.Material(name='Fuel') fuel.set_density('g/cm3', 10.5) # fuel.add_nuclide('U235', 4.6716e-02) fuel.add_nuclide('U235', 0.0667372) # fuel.add_nuclide('U238', 2.8697e-01) fuel.add_nuclide('U238', 0.2669488) fuel.add_nuclide('O16', 5.0000e-01) fuel.add_element('C', 1.6667e-01) mat_list.append(fuel) buff = openmc.Material(name='Buffer') buff.set_density('g/cm3', 1.0) buff.add_element('C', 1.0) buff.add_s_alpha_beta('c_Graphite') mat_list.append(buff) PyC1 = openmc.Material(name='PyC1') PyC1.set_density('g/cm3', 1.9) PyC1.add_element('C', 1.0) PyC1.add_s_alpha_beta('c_Graphite') mat_list.append(PyC1) PyC2 = openmc.Material(name='PyC2') PyC2.set_density('g/cm3', 1.87) PyC2.add_element('C', 1.0) PyC2.add_s_alpha_beta('c_Graphite') mat_list.append(PyC2) SiC = openmc.Material(name='SiC') SiC.set_density('g/cm3', 3.2) SiC.add_element('C', 0.5) SiC.add_element('Si', 0.5) mat_list.append(SiC) fuel_temp = 900 homogeneous_fuel = build_fuel_material(fuel_temp, pack_frac) mat_list.append(homogeneous_fuel) mats = openmc.Materials(mat_list) mats.export_to_xml() ############################# ### GEOMETRY ### ############################# pitch = 17.4 fuel_bottom = -pitch / 2 fuel_top = pitch / 2 coolant_r = 4 # fuel_r = (pitch/2 - coolant_r)/2 fuel_r = (pitch / (3**(1 / 2)) - coolant_r) / 2 hex_universe = openmc.Universe() top = openmc.ZPlane(z0=fuel_top, boundary_type='reflective') bottom = openmc.ZPlane(z0=fuel_bottom, boundary_type='reflective') surf_fuel = openmc.ZCylinder(r=fuel_r) # Make TRISOS to be filled in fuel cylinders by chopping up # fuel cylinder into segments n_cyls = 40 fuel_segment_heights = np.linspace(fuel_bottom, fuel_top, n_cyls) segment_height = fuel_segment_heights[1] - fuel_segment_heights[0] fuel_planes = [bottom] fuel_cells = [] for i, height in enumerate(fuel_segment_heights[1:-1]): this_plane = openmc.ZPlane(z0=height) fuel_planes.append(this_plane) this_cell = openmc.Cell() this_cell.region = +fuel_planes[i] & -fuel_planes[i + 1] & -surf_fuel fuel_cells.append(copy.deepcopy(this_cell)) # last cell fuel_planes.append(top) this_cell = openmc.Cell() this_cell.region = +fuel_planes[-2] & -fuel_planes[-1] & -surf_fuel fuel_cells.append(copy.deepcopy(this_cell)) # Make fuel cylinder fuel_cyl_top = openmc.ZPlane(z0=segment_height / 2) fuel_cyl_bottom = openmc.ZPlane(z0=-segment_height / 2) fuel_triso_region = -surf_fuel & +fuel_cyl_bottom & -fuel_cyl_top outer_radius = 425. * 1e-4 # openmc.model.triso._Cylinder.from_region(fuel_region, outer_radius) spheres = [openmc.Sphere(r=r * 1e-4) for r in [215., 315., 350., 385.]] cells = [ openmc.Cell(fill=fuel, region=-spheres[0]), openmc.Cell(fill=buff, region=+spheres[0] & -spheres[1]), openmc.Cell(fill=PyC1, region=+spheres[1] & -spheres[2]), openmc.Cell(fill=SiC, region=+spheres[2] & -spheres[3]), openmc.Cell(fill=PyC2, region=+spheres[3]) ] triso_univ = openmc.Universe(cells=cells) outer_radius = 425. * 1e-4 centers = openmc.model.pack_spheres(radius=outer_radius, region=fuel_triso_region, pf=pack_frac) trisos = [openmc.model.TRISO(outer_radius, triso_univ, c) for c in centers] outside_trisos = openmc.Intersection(~t.region for t in trisos) # background_region = outside_trisos & +fuel_cyl_bottom & \ # -fuel_cyl_top & -surf_fuel background_region = outside_trisos background_cell = openmc.Cell(fill=graphite, region=background_region) fuel_triso_univ = openmc.Universe() fuel_triso_univ.add_cell(background_cell) for idx, triso in enumerate(trisos): fuel_triso_univ.add_cell(triso) # Fill in fuel cells with triso cells and translate to location for i, cell in enumerate(fuel_cells): cell_height = segment_height * (i + 1 / 2) + fuel_bottom cell.translation = [0, 0, cell_height] cell.fill = fuel_triso_univ fuel_cell_univ = openmc.Universe(cells=fuel_cells) # For testing solid fuel # test_region = +bottom & -top & -surf_fuel # fuel_cell = openmc.Cell(region=test_region, fill=fuel) # fuel_cell_univ = openmc.Universe(cells=[fuel_cell]) coolant_cyl = openmc.ZCylinder(r=coolant_r) coolant_region = -coolant_cyl coolant_cell = openmc.Cell() coolant_cell.fill = naoh coolant_cell.region = coolant_region hex_universe.add_cell(coolant_cell) hex_prism = openmc.get_hexagonal_prism(edge_length=pitch / (3**1 / 2), boundary_type='reflective') graphite_region = hex_prism & +coolant_cyl & -top & +bottom graphite_cell = openmc.Cell() graphite_cell.fill = graphite graphite_cell.region = graphite_region hex_universe.add_cell(graphite_cell) fuel_cells = [] root3 = 3**(1 / 2) half_to_vertex = pitch / root3 / 2 half_to_edge = pitch / 4 # fuel_id = 100 offset_angle = 30 n_pins = 6 for i in range(n_pins): theta = (offset_angle + i / n_pins * 360) * pi / 180 r = coolant_r + fuel_r + 0.01 x = r * np.cos(theta) y = r * np.sin(theta) fuel_cyl_bound = openmc.ZCylinder(x0=x, y0=y, r=fuel_r) graphite_cell.region &= +fuel_cyl_bound fuel_cell = openmc.Cell() fuel_cell.fill = copy.deepcopy(fuel_cell_univ) fuel_cell.translation = [x, y, 0] fuel_cell.region = -fuel_cyl_bound & -top & +bottom # fuel_cell.id = fuel_id # fuel_id += 1 fuel_cells.append(fuel_cell) hex_universe.add_cell(fuel_cell) geom = openmc.Geometry(hex_universe) # geom = openmc.Geometry(fuel_cell_univ) geom.export_to_xml() ##################################### ### SOURCE/BATCHES ### ##################################### point = openmc.stats.Point((0, 0, 0)) src = openmc.Source(space=point) settings.source = src settings.batches = 50 settings.inactive = 10 settings.particles = 200 settings.export_to_xml() ############################# ### TALLIES ### ############################# # Instantiate an empty Tallies object tallies_file = openmc.Tallies() # K-Eigenvalue (infinity) tallies fiss_rate = openmc.Tally(name='fiss. rate') fiss_rate.scores = ['nu-fission'] tallies_file.append(fiss_rate) abs_rate = openmc.Tally(name='abs. rate') abs_rate.scores = ['absorption'] tallies_file.append(abs_rate) # Resonance Escape Probability tallies therm_abs_rate = openmc.Tally(name='therm. abs. rate') therm_abs_rate.scores = ['absorption'] therm_abs_rate.filters = [openmc.EnergyFilter([0., 0.625])] tallies_file.append(therm_abs_rate) # Thermal Flux Utilization tallies # fuel_therm_abs_rate = openmc.Tally(name='fuel therm. abs. rate') # fuel_therm_abs_rate.scores = ['absorption'] # fuel_therm_abs_rate.filters = [openmc.EnergyFilter([0., 0.625]), # openmc.CellFilter([fuel_cell])] # tallies_file.append(fuel_therm_abs_rate) # Fast Fission Factor tallies therm_fiss_rate = openmc.Tally(name='therm. fiss. rate') therm_fiss_rate.scores = ['nu-fission'] therm_fiss_rate.filters = [openmc.EnergyFilter([0., 0.625])] tallies_file.append(therm_fiss_rate) tallies_file.export_to_xml() ############################# ### PLOTTING ### ############################# zs = np.linspace(0, 1, 2) plots = [] for z in zs: p = openmc.Plot() p.filename = 'pinplot' + str(z) p.width = (1.4 * pitch, 1.4 * pitch) p.pixels = (2000, 2000) p.color_by = 'material' p.origin = [0, 0, z] # p.color_by = 'cell' # p.colors = {homogeneous_fuel: 'yellow', naoh: 'grey', graphite: 'black'} p.colors = {fuel: 'yellow', naoh: 'grey', graphite: 'black'} plots.append(copy.deepcopy(p)) plots = openmc.Plots(plots) plots.export_to_xml() # openmc.plot_geometry(output = False) openmc.plot_geometry() # pngstring = 'pinplot{}.png'.format(str(pitch)) # subprocess.call(['convert','pinplot.ppm',pngstring]) # subprocess.call(['mv',pngstring,'figures/'+pngstring]) ############################# ### EXECUTION ### ############################# # openmc.run(output=False) openmc.run() sp = openmc.StatePoint('statepoint.{}.h5'.format(settings.batches)) # Collect all the tallies fiss_rate = sp.get_tally(name='fiss. rate') fiss_rate_df = fiss_rate.get_pandas_dataframe() abs_rate = sp.get_tally(name='abs. rate') abs_rate_df = abs_rate.get_pandas_dataframe() therm_abs_rate = sp.get_tally(name='therm. abs. rate') therm_abs_rate_df = therm_abs_rate.get_pandas_dataframe() fuel_therm_abs_rate = sp.get_tally(name='fuel therm. abs. rate') fuel_therm_abs_rate_df = fuel_therm_abs_rate.get_pandas_dataframe() therm_fiss_rate = sp.get_tally(name='therm. fiss. rate') therm_fiss_rate_df = therm_fiss_rate.get_pandas_dataframe() # Compute k-infinity kinf = fiss_rate / abs_rate kinf_df = kinf.get_pandas_dataframe() # Compute resonance escape probability res_esc = (therm_abs_rate) / (abs_rate) res_esc_df = res_esc.get_pandas_dataframe() # Compute fast fission factor fast_fiss = fiss_rate / therm_fiss_rate fast_fiss_df = fast_fiss.get_pandas_dataframe() # Compute thermal flux utilization therm_util = fuel_therm_abs_rate / therm_abs_rate therm_util_df = therm_util.get_pandas_dataframe() # Compute neutrons produced per absorption eta = therm_fiss_rate / fuel_therm_abs_rate eta_df = eta.get_pandas_dataframe() columns = [ 'pitch', 'enrichment', 'kinf mean', 'kinf sd', 'res_esc mean', 'res_esc sd', 'fast_fiss mean', 'fast_fiss sd', 'therm_util mean', 'therm_util sd', 'eta mean', 'eta sd' ] data = [[ pitch, enrichment, kinf_df['mean'][0], kinf_df['std. dev.'][0], res_esc_df['mean'][0], res_esc_df['std. dev.'][0], fast_fiss_df['mean'][0], fast_fiss_df['std. dev.'][0], therm_util_df['mean'][0], therm_util_df['std. dev.'][0], eta_df['mean'][0], eta_df['std. dev.'][0] ]] all_tallies = pd.DataFrame(data, columns=columns) return all_tallies
def _build_inputs(self): mat = openmc.Material() mat.set_density('g/cm3', 2.6989) mat.add_nuclide('Al27', 1.0) materials = openmc.Materials([mat]) materials.export_to_xml() cyl = openmc.XCylinder(r=1.0, boundary_type='vacuum') x_plane_left = openmc.XPlane(-1.0, 'vacuum') x_plane_center = openmc.XPlane(1.0) x_plane_right = openmc.XPlane(1.0e9, 'vacuum') inner_cyl_left = openmc.Cell() inner_cyl_right = openmc.Cell() outer_cyl = openmc.Cell() inner_cyl_left.region = -cyl & +x_plane_left & -x_plane_center inner_cyl_right.region = -cyl & +x_plane_center & -x_plane_right outer_cyl.region = ~(-cyl & +x_plane_left & -x_plane_right) inner_cyl_right.fill = mat geometry = openmc.Geometry( [inner_cyl_left, inner_cyl_right, outer_cyl]) geometry.export_to_xml() source = openmc.Source() source.space = openmc.stats.Point((0, 0, 0)) source.angle = openmc.stats.Monodirectional() source.energy = openmc.stats.Discrete([14.0e6], [1.0]) source.particle = 'neutron' settings = openmc.Settings() settings.particles = 10000 settings.run_mode = 'fixed source' settings.batches = 1 settings.photon_transport = True settings.electron_treatment = 'ttb' settings.cutoff = {'energy_photon': 1000.0} settings.source = source settings.export_to_xml() surface_filter = openmc.SurfaceFilter(cyl) particle_filter = openmc.ParticleFilter('photon') current_tally = openmc.Tally() current_tally.filters = [surface_filter, particle_filter] current_tally.scores = ['current'] tally_tracklength = openmc.Tally() tally_tracklength.filters = [particle_filter] tally_tracklength.scores = ['total', 'heating'] tally_tracklength.nuclides = ['Al27', 'total'] tally_tracklength.estimator = 'tracklength' tally_collision = openmc.Tally() tally_collision.filters = [particle_filter] tally_collision.scores = ['total', 'heating'] tally_collision.nuclides = ['Al27', 'total'] tally_collision.estimator = 'collision' tally_analog = openmc.Tally() tally_analog.filters = [particle_filter] tally_analog.scores = ['total', 'heating'] tally_analog.nuclides = ['Al27', 'total'] tally_analog.estimator = 'analog' tallies = openmc.Tallies( [current_tally, tally_tracklength, tally_collision, tally_analog]) tallies.export_to_xml()
materials_file = openmc.Materials([moderator, fuel]) materials_file.export_to_xml() ############################################################################### # Exporting to OpenMC geometry.xml file ############################################################################### # Instantiate ZCylinder surfaces surf1 = openmc.ZCylinder(surface_id=1, x0=0, y0=0, R=7, name='surf 1') surf2 = openmc.ZCylinder(surface_id=2, x0=0, y0=0, R=9, name='surf 2') surf3 = openmc.ZCylinder(surface_id=3, x0=0, y0=0, R=11, name='surf 3') surf3.boundary_type = 'vacuum' # Instantiate Cells cell1 = openmc.Cell(cell_id=1, name='cell 1') cell2 = openmc.Cell(cell_id=100, name='cell 2') cell3 = openmc.Cell(cell_id=101, name='cell 3') cell4 = openmc.Cell(cell_id=2, name='cell 4') # Use surface half-spaces to define regions cell1.region = -surf2 cell2.region = -surf1 cell3.region = +surf1 cell4.region = +surf2 & -surf3 # Register Materials with Cells cell2.fill = fuel cell3.fill = moderator cell4.fill = moderator
def make_materials_geometry_tallies(enrichment_list, batches=2, inner_radius=500, thickness=100, breeder_material_name='Li', temperature_in_C=500): if isinstance(enrichment_list, list): enrichment = enrichment_list[0] else: enrichment = enrichment_list print('simulating ', batches, enrichment, inner_radius, thickness, breeder_material_name) # MATERIALS from library of materials in neutronics_material_maker package breeder_material = Material( material_name=breeder_material_name, enrichment=enrichment, enrichment_target='Li6', enrichment_type='ao', temperature_in_C=temperature_in_C).neutronics_material eurofer = Material(material_name='eurofer').neutronics_material mats = openmc.Materials([breeder_material, eurofer]) # GEOMETRY breeder_blanket_inner_surface = openmc.Sphere(r=inner_radius) breeder_blanket_outer_surface = openmc.Sphere(r=inner_radius + thickness) vessel_inner_surface = openmc.Sphere(r=inner_radius + thickness + 10) vessel_outer_surface = openmc.Sphere(r=inner_radius + thickness + 20, boundary_type='vacuum') breeder_blanket_region = -breeder_blanket_outer_surface & +breeder_blanket_inner_surface breeder_blanket_cell = openmc.Cell(region=breeder_blanket_region) breeder_blanket_cell.fill = breeder_material breeder_blanket_cell.name = 'breeder_blanket' inner_void_region = -breeder_blanket_inner_surface inner_void_cell = openmc.Cell(region=inner_void_region) inner_void_cell.name = 'inner_void' vessel_region = +vessel_inner_surface & -vessel_outer_surface vessel_cell = openmc.Cell(region=vessel_region) vessel_cell.name = 'vessel' vessel_cell.fill = eurofer blanket_vessel_gap_region = -vessel_inner_surface & +breeder_blanket_outer_surface blanket_vessel_gap_cell = openmc.Cell(region=blanket_vessel_gap_region) blanket_vessel_gap_cell.name = 'blanket_vessel_gap' universe = openmc.Universe(cells=[ inner_void_cell, breeder_blanket_cell, blanket_vessel_gap_cell, vessel_cell ]) geom = openmc.Geometry(universe) # SIMULATION SETTINGS sett = openmc.Settings() # batches = 3 # this is parsed as an argument sett.batches = batches sett.inactive = 20 sett.particles = 5000 sett.run_mode = 'fixed source' source = openmc.Source() source.space = openmc.stats.Point((0, 0, 0)) source.angle = openmc.stats.Isotropic() source.energy = openmc.stats.Muir( e0=14080000.0, m_rat=5.0, kt=20000.0 ) # neutron energy = 14.08MeV, AMU for D + T = 5, temperature is 20KeV sett.source = source # TALLIES tallies = openmc.Tallies() # define filters cell_filter_breeder = openmc.CellFilter(breeder_blanket_cell) cell_filter_vessel = openmc.CellFilter(vessel_cell) particle_filter = openmc.ParticleFilter( 'neutron') # 1 is neutron, 2 is photon surface_filter_rear_blanket = openmc.SurfaceFilter( breeder_blanket_outer_surface) surface_filter_rear_vessel = openmc.SurfaceFilter(vessel_outer_surface) energy_bins = openmc.mgxs.GROUP_STRUCTURES['VITAMIN-J-175'] energy_filter = openmc.EnergyFilter(energy_bins) tally = openmc.Tally(name='TBR') tally.filters = [cell_filter_breeder] tally.scores = [ '205' ] # MT 205 is the (n,Xt) reaction where X is a wildcard, if MT 105 or (n,t) then some tritium production will be missed, for example (n,nt) which happens in Li7 would be missed tallies.append(tally) tally = openmc.Tally(name='blanket_leakage') tally.filters = [surface_filter_rear_blanket] tally.scores = ['current'] tallies.append(tally) tally = openmc.Tally(name='vessel_leakage') tally.filters = [surface_filter_rear_vessel] tally.scores = ['current'] tallies.append(tally) tally = openmc.Tally(name='breeder_blanket_spectra') tally.filters = [cell_filter_breeder, energy_filter] tally.scores = ['flux'] tallies.append(tally) tally = openmc.Tally(name='vacuum_vessel_spectra') tally.filters = [cell_filter_vessel, energy_filter] tally.scores = ['flux'] tallies.append(tally) tally = openmc.Tally(name='DPA') tally.filters = [cell_filter_vessel] tally.scores = ['444'] tallies.append(tally) # RUN OPENMC model = openmc.model.Model(geom, mats, sett, tallies) model.run() sp = openmc.StatePoint('statepoint.' + str(batches) + '.h5') json_output = { 'enrichment': enrichment, 'inner_radius': inner_radius, 'thickness': thickness, 'breeder_material_name': breeder_material_name, 'temperature_in_C': temperature_in_C } tallies_to_retrieve = ['TBR', 'DPA', 'blanket_leakage', 'vessel_leakage'] for tally_name in tallies_to_retrieve: tally = sp.get_tally(name=tally_name) df = tally.get_pandas_dataframe() tally_result = df['mean'].sum() tally_std_dev = df['std. dev.'].sum() json_output[tally_name] = { 'value': tally_result, 'std_dev': tally_std_dev } spectra_tallies_to_retrieve = [ 'breeder_blanket_spectra', 'vacuum_vessel_spectra' ] for spectra_name in spectra_tallies_to_retrieve: spectra_tally = sp.get_tally(name=spectra_name) spectra_tally_result = [entry[0][0] for entry in spectra_tally.mean] spectra_tally_std_dev = [ entry[0][0] for entry in spectra_tally.std_dev ] json_output[spectra_name] = { 'value': spectra_tally_result, 'std_dev': spectra_tally_std_dev, 'energy_groups': list(energy_bins) } return json_output
clad_ir = openmc.ZCylinder(surface_id=2, x0=0, y0=0, r=clad_ir, name='Clad IR') clad_or = openmc.ZCylinder(surface_id=3, x0=0, y0=0, r=clar_or, name='Clad OR') void_r= openmc.ZCylinder(surface_id=4, x0=0, y0=0, r=void_r, name='Clad OR') left = openmc.XPlane(surface_id=5, x0=-plane_value, name='left') right = openmc.XPlane(surface_id=6, x0=plane_value, name='right') bottom = openmc.YPlane(surface_id=7, y0=-plane_value, name='bottom') top = openmc.YPlane(surface_id=8, y0=plane_value, name='top') left.boundary_type = 'reflective' right.boundary_type = 'reflective' top.boundary_type = 'reflective' bottom.boundary_type = 'reflective' # Instantiate Cells fuel = openmc.Cell(cell_id=1, name='cell 1') gap = openmc.Cell(cell_id=2, name='cell 2') clad = openmc.Cell(cell_id=3, name='cell 3') void = openmc.Cell(cell_id=4, name='cell 4') water = openmc.Cell(cell_id=5, name='cell 5') # Use surface half-spaces to define regions fuel.region = -fuel_or gap.region = +fuel_or & -clad_ir clad.region = +clad_ir & -clad_or void.region = +clad_or & -void_r water.region = +void_r & +left & -right & +bottom & -top # Register Materials with Cells fuel.fill = uo2 gap.fill = helium
# ## Surfaces # In[9]: rfo = openmc.ZCylinder(R=radius_fuel) xy_box = openmc.model.get_rectangular_prism(pitch, pitch, boundary_type='reflective') z0 = openmc.ZPlane(z0=-10, boundary_type='reflective') z1 = openmc.ZPlane(z0=10, boundary_type='reflective') # ## Cells, etc. # In[10]: fuel = openmc.Cell(name='fuel', fill=uo2) fuel.region = -rfo & +z0 & -z1 mod = openmc.Cell(name='moderator', fill=homogenized) mod.region = +rfo & xy_box & +z0 & -z1 root = openmc.Universe(cells=(fuel, mod)) geometry = openmc.Geometry(root) # # Settings # In[11]: settings = openmc.Settings() # In[12]: #TODO: how many batches/particles are needed for good cross sections?
def _build_openmc(self): """Generate the OpenMC input XML """ # Directory from which openmc is run os.makedirs('openmc', exist_ok=True) # Define material mat = openmc.Material() for nuclide, fraction in self.nuclides: mat.add_nuclide(nuclide, fraction) mat.set_density('g/cm3', self.density) materials = openmc.Materials([mat]) materials.export_to_xml(os.path.join('openmc', 'materials.xml')) # Instantiate surfaces cyl = openmc.XCylinder(boundary_type='vacuum', R=1.e-6) px1 = openmc.XPlane(boundary_type='vacuum', x0=-1.) px2 = openmc.XPlane(boundary_type='transmission', x0=1.) px3 = openmc.XPlane(boundary_type='vacuum', x0=1.e9) # Instantiate cells inner_cyl_left = openmc.Cell() inner_cyl_right = openmc.Cell() outer_cyl = openmc.Cell() # Set cells regions and materials inner_cyl_left.region = -cyl & +px1 & -px2 inner_cyl_right.region = -cyl & +px2 & -px3 outer_cyl.region = ~(-cyl & +px1 & -px3) inner_cyl_right.fill = mat # Create root universe and export to XML geometry = openmc.Geometry( [inner_cyl_left, inner_cyl_right, outer_cyl]) geometry.export_to_xml(os.path.join('openmc', 'geometry.xml')) # Define source source = openmc.Source() source.space = openmc.stats.Point((0, 0, 0)) source.angle = openmc.stats.Monodirectional() source.energy = openmc.stats.Discrete([self.energy], [1.]) source.particle = 'neutron' # Settings settings = openmc.Settings() settings.source = source settings.particles = self.particles settings.run_mode = 'fixed source' settings.batches = 1 settings.photon_transport = True settings.electron_treatment = self.electron_treatment settings.cutoff = {'energy_photon': 1000.} settings.export_to_xml(os.path.join('openmc', 'settings.xml')) # Define filters surface_filter = openmc.SurfaceFilter(cyl) particle_filter = openmc.ParticleFilter('photon') energy_bins = np.logspace(3, np.log10(2 * self.energy), 500) energy_filter = openmc.EnergyFilter(energy_bins) # Create tallies and export to XML tally = openmc.Tally(name='photon current') tally.filters = [surface_filter, energy_filter, particle_filter] tally.scores = ['current'] tallies = openmc.Tallies([tally]) tallies.export_to_xml(os.path.join('openmc', 'tallies.xml'))
fuel.add_s_alpha_beta('c_H_in_H2O') mats = openmc.Materials([clad, air, fuel]) mats.cross_sections = '/home/tang/nndc_hdf5/cross_sections.xml' mats.export_to_xml() zp1 = openmc.ZPlane(z0=0.0) zp2 = openmc.ZPlane(z0=83.55) zp3 = openmc.ZPlane(z0=150.0) zp4 = openmc.ZPlane(z0=152.5, boundary_type='vacuum') zp5 = openmc.ZPlane(z0=-2.0, boundary_type='vacuum') zc10 = openmc.ZCylinder(x0=0, y0=0, R=29.5) zc20 = openmc.ZCylinder(x0=0, y0=0, R=29.8, boundary_type='vacuum') cell1 = openmc.Cell() region1 = +zp1 & -zp2 & -zc10 cell1.region = region1 cell1.fill = fuel cell2 = openmc.Cell() region2 = +zp2 & -zp3 & -zc10 cell2.region = region2 cell2.fill = air cell3 = openmc.Cell() cell3.region = -zp1 | +zp3 | +zc10 cell3.fill = clad u1 = openmc.Universe(cells=(cell1, cell2, cell3))
def create_triso_lattice(trisos, lower_left, pitch, shape, background): """Create a lattice containing TRISO particles for optimized tracking. Parameters ---------- trisos : list of openmc.model.TRISO List of TRISO particles to put in lattice lower_left : Iterable of float Lower-left Cartesian coordinates of the lattice pitch : Iterable of float Pitch of the lattice elements in the x-, y-, and z-directions shape : Iterable of float Number of lattice elements in the x-, y-, and z-directions background : openmc.Material A background material that is used anywhere within the lattice but outside a TRISO particle Returns ------- lattice : openmc.RectLattice A lattice containing the TRISO particles """ lattice = openmc.RectLattice() lattice.lower_left = lower_left lattice.pitch = pitch indices = list(np.broadcast(*np.ogrid[:shape[2], :shape[1], :shape[0]])) triso_locations = {idx: [] for idx in indices} for t in trisos: for idx in t.classify(lattice): if idx in triso_locations: # Create copy of TRISO particle with materials preserved and # different cell/surface IDs t_copy = copy.copy(t) t_copy.id = None t_copy.fill = t.fill t_copy._surface = openmc.Sphere(r=t._surface.r, x0=t._surface.x0, y0=t._surface.y0, z0=t._surface.z0) t_copy.region = -t_copy._surface triso_locations[idx].append(t_copy) else: warnings.warn('TRISO particle is partially or completely ' 'outside of the lattice.') # Create universes universes = np.empty(shape[::-1], dtype=openmc.Universe) for idx, triso_list in sorted(triso_locations.items()): if len(triso_list) > 0: outside_trisos = openmc.Intersection(~t.region for t in triso_list) background_cell = openmc.Cell(fill=background, region=outside_trisos) else: background_cell = openmc.Cell(fill=background) u = openmc.Universe() u.add_cell(background_cell) for t in triso_list: u.add_cell(t) iz, iy, ix = idx t.center = lattice.get_local_coordinates(t.center, (ix, iy, iz)) if len(shape) == 2: universes[-1 - idx[0], idx[1]] = u else: universes[idx[0], -1 - idx[1], idx[2]] = u lattice.universes = universes # Set outer universe background_cell = openmc.Cell(fill=background) lattice.outer = openmc.Universe(cells=[background_cell]) return lattice
############################################################################### # Instantiate Surfaces left = openmc.XPlane(surface_id=1, x0=-3, name='left') right = openmc.XPlane(surface_id=2, x0=3, name='right') bottom = openmc.YPlane(surface_id=3, y0=-4, name='bottom') top = openmc.YPlane(surface_id=4, y0=4, name='top') fuel_surf = openmc.ZCylinder(surface_id=5, x0=0, y0=0, R=0.4) left.boundary_type = 'vacuum' right.boundary_type = 'vacuum' top.boundary_type = 'vacuum' bottom.boundary_type = 'vacuum' # Instantiate Cells cell1 = openmc.Cell(cell_id=1, name='Cell 1') cell2 = openmc.Cell(cell_id=101, name='cell 2') cell3 = openmc.Cell(cell_id=102, name='cell 3') cell4 = openmc.Cell(cell_id=500, name='cell 4') cell5 = openmc.Cell(cell_id=600, name='cell 5') cell6 = openmc.Cell(cell_id=601, name='cell 6') # Use surface half-spaces to define regions cell1.region = +left & -right & +bottom & -top cell2.region = -fuel_surf cell3.region = +fuel_surf cell5.region = -fuel_surf cell6.region = +fuel_surf # Register Materials with Cells cell2.fill = fuel
############################################################################### # Instantiate ZCylinder surfaces fuel_or = openmc.ZCylinder(surface_id=1, x0=0, y0=0, R=0.54, name='Fuel OR') left = openmc.XPlane(surface_id=4, x0=-0.63, name='left') right = openmc.XPlane(surface_id=5, x0=0.63, name='right') bottom = openmc.YPlane(surface_id=6, y0=-0.63, name='bottom') top = openmc.YPlane(surface_id=7, y0=0.63, name='top') left.boundary_type = 'reflective' right.boundary_type = 'reflective' top.boundary_type = 'reflective' bottom.boundary_type = 'reflective' # Instantiate Cells fuel = openmc.Cell(cell_id=1, name='cell 1') moderator = openmc.Cell(cell_id=2, name='cell 2') # Use surface half-spaces to define regions fuel.region = -fuel_or moderator.region = +fuel_or & +left & -right & +bottom & -top # Register Materials with Cells fuel.fill = uo2 moderator.fill = water # Instantiate Universe root = openmc.Universe(universe_id=0, name='root universe') # Register Cells with Universe root.add_cells([fuel, moderator])
mats.export_to_xml() # example surfaces surface_sph1 = openmc.Sphere(r=500) surface_sph2 = openmc.Sphere(r=600) # add more surfaces here using https://openmc.readthedocs.io/en/stable/usersguide/geometry.html#surfaces-and-regions # for the first wall you will need another sphere # for the center column you will need a cylinder blanket_region = +surface_sph1 & -surface_sph2 # above (+) surface_sph and below (-) surface_sph2 # example cell cell_1 = openmc.Cell(region=blanket_region) cell_1.fill = natural_lead # assigning a material to a cell # add more cells here for the first wall and the center column universe = openmc.Universe(cells=[cell_1]) # HINT: this list will need to include the new cell # shows the plots plt.show(universe.plot(width=(1200, 1200), basis='xz', colors={cell_1: 'blue'})) plt.show(universe.plot(width=(1200, 1200), basis='xy', colors={cell_1: 'blue'})) plt.show(universe.plot(width=(1200, 1200), basis='yz', colors={cell_1: 'blue'})) # saves the plots universe.plot(width=(1200, 1200), basis='xz', colors={cell_1: 'blue'}).get_figure().savefig('xz_sphere.png') universe.plot(width=(1200, 1200), basis='xy', colors={cell_1: 'blue'}).get_figure().savefig('xy_sphere.png') universe.plot(width=(1200, 1200), basis='yz', colors={cell_1: 'blue'}).get_figure().savefig('yz_sphere.png')
yp27 = openmc.YPlane(y0=-30., boundary_type='vacuum') zp28 = openmc.ZPlane(z0=106.44, boundary_type='vacuum') #top of water zp29 = openmc.ZPlane(z0=-3.81) zp30 = openmc.ZPlane(z0=-19.11, boundary_type='vacuum') #bottom of water yp31 = openmc.YPlane(y0=-1.544) yp32 = openmc.YPlane(y0=34.056) xp33 = openmc.XPlane(x0=45.063) xp34 = openmc.XPlane(x0=45.548) xp35 = openmc.XPlane(x0=91.652) xp36 = openmc.XPlane(x0=92.137) zp37 = openmc.ZPlane(z0=90.23) ##堆芯部分 #uo2 fuel cell1 = openmc.Cell() core_region = -zc1 & +zp7 & -zp8 cell1.region = core_region cell1.fill = fuel cell2 = openmc.Cell() core_up = +zc1 & -zc2 & -zp9 cell2.region = core_up cell2.fill = clad6061 #clad cell3 = openmc.Cell() cell3.region = -zc1 & +zp8 & -zp9 cell3.fill = clad1100 cell4 = openmc.Cell()
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()