def _build_inputs(self): mat1 = openmc.Material(material_id=1, temperature=294) mat1.set_density('g/cm3', 4.5) mat1.add_nuclide(openmc.Nuclide('U235'), 1.0) materials = openmc.Materials([mat1]) materials.export_to_xml() sphere = openmc.Sphere(surface_id=1, r=10.0, boundary_type='vacuum') inside_sphere = openmc.Cell(cell_id=1) inside_sphere.region = -sphere inside_sphere.fill = mat1 root = openmc.Universe(universe_id=0) root.add_cell(inside_sphere) geometry = openmc.Geometry() geometry.root_universe = root geometry.export_to_xml() # Create an array of different sources x_dist = openmc.stats.Uniform(-3., 3.) y_dist = openmc.stats.Discrete([-4., -1., 3.], [0.2, 0.3, 0.5]) z_dist = openmc.stats.Tabular([-2., 0., 2.], [0.2, 0.3, 0.2]) spatial1 = openmc.stats.CartesianIndependent(x_dist, y_dist, z_dist) spatial2 = openmc.stats.Box([-4., -4., -4.], [4., 4., 4.]) spatial3 = openmc.stats.Point([1.2, -2.3, 0.781]) mu_dist = openmc.stats.Discrete([-1., 0., 1.], [0.5, 0.25, 0.25]) phi_dist = openmc.stats.Uniform(0., 6.28318530718) angle1 = openmc.stats.PolarAzimuthal(mu_dist, phi_dist) angle2 = openmc.stats.Monodirectional(reference_uvw=[0., 1., 0.]) angle3 = openmc.stats.Isotropic() E = np.logspace(0, 7) p = np.sin(np.linspace(0., pi)) p /= sum(np.diff(E) * p[:-1]) energy1 = openmc.stats.Maxwell(1.2895e6) energy2 = openmc.stats.Watt(0.988e6, 2.249e-6) energy3 = openmc.stats.Tabular(E, p, interpolation='histogram') source1 = openmc.Source(spatial1, angle1, energy1, strength=0.5) source2 = openmc.Source(spatial2, angle2, energy2, strength=0.3) source3 = openmc.Source(spatial3, angle3, energy3, strength=0.2) settings = openmc.Settings() settings.batches = 10 settings.inactive = 5 settings.particles = 1000 settings.source = [source1, source2, source3] settings.export_to_xml()
def main(): my_shape = paramak.CenterColumnShieldHyperbola( height=500, inner_radius=50, mid_radius=60, outer_radius=100, material_tag='center_column_shield_mat') # makes the openmc neutron source at x,y,z 0, 0, 0 with isotropic # directions source = openmc.Source() source.space = openmc.stats.Point((0, 0, 0)) source.energy = openmc.stats.Discrete([14e6], [1]) source.angle = openmc.stats.Isotropic() # converts the geometry into a neutronics geometry my_model = paramak.NeutronicsModel( geometry=my_shape, source=source, materials={'center_column_shield_mat': 'Be'}, cell_tallies=['(n,Xa)', '(n,Xt)', '(n,Xp)'], mesh_tally_3d=['(n,Xa)', '(n,Xt)', '(n,Xp)'], mesh_tally_2d=['(n,Xa)', '(n,Xt)', '(n,Xp)'], simulation_batches=10, simulation_particles_per_batch=200) # performs an openmc simulation on the model my_model.simulate(method='pymoab') # this extracts the values from the results dictionary print(my_model.results)
def inf_medium_model(cutoff_energy, source_energy): """Infinite medium problem with a monoenergetic photon source""" model = openmc.Model() m = openmc.Material() m.add_nuclide('Zr90', 1.0) m.set_density('g/cm3', 1.0) sph = openmc.Sphere(r=100.0, boundary_type='reflective') cell = openmc.Cell(fill=m, region=-sph) model.geometry = openmc.Geometry([cell]) model.settings.run_mode = 'fixed source' model.settings.source = openmc.Source( particle='photon', energy=openmc.stats.Discrete([source_energy], [1.0]), ) model.settings.particles = 100 model.settings.batches = 10 model.settings.cutoff = {'energy_photon': cutoff_energy} tally_flux = openmc.Tally(name='flux') tally_flux.filters = [ openmc.EnergyFilter([0.0, cutoff_energy, source_energy]), openmc.ParticleFilter(['photon']) ] tally_flux.scores = ['flux'] tally_heating = openmc.Tally(name='heating') tally_heating.scores = ['heating'] model.tallies = openmc.Tallies([tally_flux, tally_heating]) return model
def uo2_trigger_model(): """Set up a simple UO2 model with k-eff trigger""" model = openmc.model.Model() m = openmc.Material(name='UO2') m.add_nuclide('U235', 1.0) m.add_nuclide('O16', 2.0) m.set_density('g/cm3', 10.0) model.materials.append(m) cyl = openmc.ZCylinder(r=1.0, boundary_type='vacuum') c = openmc.Cell(fill=m, region=-cyl) model.geometry.root_universe = openmc.Universe(cells=[c]) model.settings.batches = 10 model.settings.inactive = 5 model.settings.particles = 100 model.settings.source = openmc.Source(space=openmc.stats.Box( [-0.5, -0.5, -1], [0.5, 0.5, 1], only_fissionable=True)) model.settings.verbosity = 1 model.settings.keff_trigger = {'type': 'std_dev', 'threshold': 0.001} model.settings.trigger_active = True model.settings.trigger_max_batches = 10 model.settings.trigger_batch_interval = 1 # Write XML files in tmpdir with cdtemp(): model.export_to_xml() yield
def model(): """Sphere of single nuclide""" model = openmc.model.Model() w = openmc.Material(name='tungsten') w.add_nuclide('W186', 1.0) w.set_density('g/cm3', 19.3) w.depletable = True r = uniform(1.0, 10.0) w.volume = 4 / 3 * pi * r**3 surf = openmc.Sphere(r=r, boundary_type='vacuum') cell = openmc.Cell(fill=w, region=-surf) model.geometry = openmc.Geometry([cell]) model.settings.batches = 10 model.settings.particles = 1000 model.settings.source = openmc.Source(space=openmc.stats.Point(), energy=openmc.stats.Discrete([1.0e6], [1.0])) model.settings.run_mode = 'fixed source' rx_tally = openmc.Tally() rx_tally.scores = ['(n,gamma)'] model.tallies.append(rx_tally) return model
def test_fixed_source(): mat = openmc.Material() mat.add_nuclide('O16', 1.0) mat.add_nuclide('U238', 0.0001) mat.set_density('g/cc', 7.5) surf = openmc.Sphere(r=10.0, boundary_type='vacuum') cell = openmc.Cell(fill=mat, region=-surf) model = openmc.model.Model() model.geometry.root_universe = openmc.Universe(cells=[cell]) model.materials.append(mat) model.settings.run_mode = 'fixed source' model.settings.batches = 10 model.settings.particles = 100 model.settings.temperature = {'default': 294} model.settings.source = openmc.Source(space=openmc.stats.Point(), strength=10.0) tally = openmc.Tally() tally.scores = ['flux'] model.tallies.append(tally) harness = FixedSourceTestHarness('statepoint.10.h5', model) harness.main()
def test_wrong_source_attributes(run_in_tmpdir): # Create a source file with animal attributes source_dtype = np.dtype([ ('platypus', '<f8'), ('axolotl', '<f8'), ('narwhal', '<i4'), ]) arr = np.array([(1.0, 2.0, 3), (4.0, 5.0, 6), (7.0, 8.0, 9)], dtype=source_dtype) with h5py.File('animal_source.h5', 'w') as fh: fh.attrs['filetype'] = np.string_("source") fh.create_dataset('source_bank', data=arr) # Create a simple model that uses this lovely animal source m = openmc.Material() m.add_nuclide('U235', 0.02) openmc.Materials([m]).export_to_xml() s = openmc.Sphere(r=10.0, boundary_type='vacuum') c = openmc.Cell(fill=m, region=-s) openmc.Geometry([c]).export_to_xml() settings = openmc.Settings() settings.particles = 100 settings.batches = 10 settings.source = openmc.Source(filename='animal_source.h5') settings.export_to_xml() # When we run the model, it should error out with a message that includes # the names of the wrong attributes with pytest.raises(RuntimeError) as excinfo: openmc.run() assert 'platypus, axolotl, narwhal' in str(excinfo.value)
def export_to_xml(self): folder_name = "{clad_type}/radius{radius:.2f}_pitch{pitch:.2f}/".format( **vars(self)) if not os.path.isdir(folder_name): os.makedirs(folder_name) self._geometry.export_to_xml(folder_name + "geometry.xml") mfile = openmc.Materials() for mat in all_materials.values(): mfile.append(mat) mfile.export_to_xml(folder_name + "materials.xml") pfile = openmc.Plots() pfile += self.make_plots() # noinspection PyTypeChecker for p in pfile: if p.color_by == "material": p.colors = colormap pfile.export_to_xml(folder_name + "plots.xml") tfile = self.make_tallies(folder_name) tfile.export_to_xml(folder_name + "tallies.xml") sfile = openmc.Settings() sfile.particles = 10000 sfile.batches = 50 sfile.inactive = 20 sfile.source = openmc.Source( space=Box([-RAD_MIN / 2, -RAD_MAJ, -10], [RAD_MIN / 2, 0, 10])) sfile.export_to_xml(folder_name + "settings.xml") print("Exported to:", folder_name)
def model(): model = openmc.model.Model() natural_lead = openmc.Material(name="natural_lead") natural_lead.add_element('Pb', 1.0) natural_lead.set_density('g/cm3', 11.34) model.materials.append(natural_lead) # geometry surface_sph1 = openmc.Sphere(r=100, boundary_type='vacuum') cell_1 = openmc.Cell(fill=natural_lead, region=-surface_sph1) model.geometry = openmc.Geometry([cell_1]) # settings model.settings.batches = 10 model.settings.inactive = 0 model.settings.particles = 1000 model.settings.run_mode = 'fixed source' # custom source from shared library source = openmc.Source() source.library = 'build/libsource.so' source.parameters = '1e3' model.settings.source = source return model
def test_source_dlopen(): library = './libsource.so' src = openmc.Source(library=library) assert src.library == library elem = src.to_xml_element() assert 'library' in elem.attrib
def _build_inputs(self): model = openmc.model.Model() # settings model.settings.batches = 5 model.settings.inactive = 0 model.settings.particles = 100 source = openmc.Source(space=Box([-4, -4, -4], [4, 4, 4])) model.settings.source = source model.settings.dagmc = True model.settings.export_to_xml() # geometry dag_univ = openmc.DAGMCUniverse("dagmc.h5m", auto_geom_ids=True) model.geometry = openmc.Geometry(dag_univ) # tally tally = openmc.Tally() tally.scores = ['total'] tally.filters = [openmc.CellFilter(2)] model.tallies = [tally] model.tallies.export_to_xml() model.export_to_xml()
def test_cylinder_cask(self): """Runs the same source and material with CAD and CSG geoemtry""" height = 100 outer_radius = 50 thickness = 10 batches = 10 particles = 500 test_material = openmc.Material(name='test_material') test_material.set_density('g/cm3', 7.75) test_material.add_element('Fe', 0.95, percent_type='wo') test_material.add_element('C', 0.05, percent_type='wo') source = openmc.Source() source.space = openmc.stats.Point((0, 0, 0)) source.angle = openmc.stats.Isotropic() source.energy = openmc.stats.Discrete([14e6], [1.0]) csg_result = self.simulate_cylinder_cask_csg(test_material, source, height, outer_radius, thickness, batches, particles) cad_result = self.simulate_cylinder_cask_cad(test_material, source, height, outer_radius, thickness, batches, particles) assert pytest.approx(csg_result, rel=0.02) == cad_result
def test_volume(uo2): """Test adding volume information from a volume calculation.""" # Create model with nested spheres model = openmc.model.Model() model.materials.append(uo2) inner = openmc.Sphere(R=1.) outer = openmc.Sphere(R=2., boundary_type='vacuum') c1 = openmc.Cell(fill=uo2, region=-inner) c2 = openmc.Cell(region=+inner & -outer) u = openmc.Universe(cells=[c1, c2]) model.geometry.root_universe = u model.settings.particles = 100 model.settings.batches = 10 model.settings.run_mode = 'fixed source' model.settings.source = openmc.Source(space=openmc.stats.Point()) ll, ur = model.geometry.bounding_box model.settings.volume_calculations for domain in (c1, uo2, u): # Run stochastic volume calculation volume_calc = openmc.VolumeCalculation( domains=[domain], samples=1000, lower_left=ll, upper_right=ur) model.settings.volume_calculations = [volume_calc] model.export_to_xml() openmc.calculate_volumes() # Load results and add volume information volume_calc.load_results('volume_1.h5') model.geometry.add_volume_information(volume_calc) # get_nuclide_densities relies on volume information nucs = set(domain.get_nuclide_densities())
def model(): model = openmc.model.Model() zn = openmc.Material() zn.set_density('g/cm3', 7.14) zn.add_nuclide('Zn64', 1.0) model.materials.append(zn) radii = np.linspace(1.0, 100.0) surfs = [openmc.Sphere(r=r) for r in radii] surfs[-1].boundary_type = 'vacuum' cells = [ openmc.Cell(fill=(zn if i % 2 == 0 else None), region=region) for i, region in enumerate(openmc.model.subdivide(surfs)) ] model.geometry = openmc.Geometry(cells) model.settings.run_mode = 'fixed source' model.settings.batches = 3 model.settings.particles = 1000 model.settings.source = openmc.Source(space=openmc.stats.Point()) cell_filter = openmc.CellFilter(cells) tally = openmc.Tally() tally.filters = [cell_filter] tally.scores = ['total'] model.tallies.append(tally) return model
def setUp(self): # makes the 3d geometry self.my_reactor = paramak.BallReactor( inner_bore_radial_thickness=1, inboard_tf_leg_radial_thickness=30, center_column_shield_radial_thickness=60, divertor_radial_thickness=50, inner_plasma_gap_radial_thickness=30, plasma_radial_thickness=300, outer_plasma_gap_radial_thickness=30, firstwall_radial_thickness=3, blanket_radial_thickness=100, blanket_rear_wall_radial_thickness=3, elongation=2.75, triangularity=0.5, rotation_angle=360, ) # makes a homogenised material for the blanket from lithium lead and # eurofer self.blanket_material = nmm.MultiMaterial( fracs=[0.8, 0.2], materials=[ nmm.Material('SiC'), nmm.Material('eurofer') ]) self.source = openmc.Source() # sets the location of the source to x=0 y=0 z=0 self.source.space = openmc.stats.Point((0, 0, 0)) # sets the direction to isotropic self.source.angle = openmc.stats.Isotropic() # sets the energy distribution to 100% 14MeV neutrons self.source.energy = openmc.stats.Discrete([14e6], [1])
def test_source_file(): filename = 'source.h5' src = openmc.Source(filename=filename) assert src.file == filename elem = src.to_xml_element() assert 'strength' in elem.attrib assert 'file' in elem.attrib
def make_model(): model = openmc.model.Model() # 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) moderator.add_s_alpha_beta('c_H_in_H2O') dense_fuel = openmc.Material(material_id=2) dense_fuel.set_density('g/cc', 4.5) dense_fuel.add_nuclide('U235', 1.0) model.materials += [moderator, dense_fuel] # 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, fill=dense_fuel, region=-r0) c11.temperature = [500, 0, 700, 800] c12 = openmc.Cell(cell_id=12, fill=moderator, region=+r0) fuel_univ = openmc.Universe(universe_id=11, cells=(c11, c12)) lat = openmc.RectLattice(lattice_id=101) lat.dimension = [2, 2] 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, region=+x0 & -x1 & +y0 & -y1) model.geometry.root_universe = openmc.Universe(universe_id=0, cells=(c101, )) # Settings model.settings.batches = 5 model.settings.inactive = 0 model.settings.particles = 1000 model.settings.source = openmc.Source( space=openmc.stats.Box([-1, -1, -1], [1, 1, 1])) model.settings.temperature = {'tolerance': 1000, 'multipole': True} # Tallies tally = openmc.Tally() tally.nuclides = ['U235', 'O16', 'total'] tally.scores = ['total', 'fission', '(n,gamma)', 'elastic', '(n,p)'] model.tallies.append(tally) return model
def _make_openmc_input(self): """Generate the OpenMC input XML """ # Define material mat = openmc.Material() mat.add_nuclide(self.nuclide, 1.0) if self.thermal is not None: name, suffix = self.thermal.split('.') thermal_name = openmc.data.thermal.get_thermal_name(name) mat.add_s_alpha_beta(thermal_name) mat.set_density('g/cm3', self.density) materials = openmc.Materials([mat]) if self.xsdir is not None: xs_path = (self.openmc_dir / 'cross_sections.xml').resolve() materials.cross_sections = str(xs_path) materials.export_to_xml(self.openmc_dir / 'materials.xml') # Set up geometry x1 = openmc.XPlane(x0=-1.e9, boundary_type='reflective') x2 = openmc.XPlane(x0=+1.e9, boundary_type='reflective') y1 = openmc.YPlane(y0=-1.e9, boundary_type='reflective') y2 = openmc.YPlane(y0=+1.e9, boundary_type='reflective') z1 = openmc.ZPlane(z0=-1.e9, boundary_type='reflective') z2 = openmc.ZPlane(z0=+1.e9, boundary_type='reflective') cell = openmc.Cell(fill=materials) cell.region = +x1 & -x2 & +y1 & -y2 & +z1 & -z2 geometry = openmc.Geometry([cell]) geometry.export_to_xml(self.openmc_dir / 'geometry.xml') # Define source source = openmc.Source() source.space = openmc.stats.Point((0, 0, 0)) source.angle = openmc.stats.Isotropic() source.energy = openmc.stats.Discrete([self.energy], [1.]) # Settings settings = openmc.Settings() if self._temperature is not None: settings.temperature = {'default': self._temperature} settings.source = source settings.particles = self.particles // self._batches settings.run_mode = 'fixed source' settings.batches = self._batches settings.create_fission_neutrons = False settings.export_to_xml(self.openmc_dir / 'settings.xml') # Define tallies energy_bins = np.logspace(np.log10(self._min_energy), np.log10(1.0001 * self.energy), self._bins + 1) energy_filter = openmc.EnergyFilter(energy_bins) tally = openmc.Tally(name='tally') tally.filters = [energy_filter] tally.scores = ['flux'] tallies = openmc.Tallies([tally]) tallies.export_to_xml(self.openmc_dir / 'tallies.xml')
def make_model_and_simulate(temperature): """Makes a neutronics Reactor model and simulates the flux""" # makes the 3d geometry from input parameters my_reactor = paramak.SubmersionTokamak( inner_bore_radial_thickness=30, inboard_tf_leg_radial_thickness=30, center_column_shield_radial_thickness=30, divertor_radial_thickness=80, inner_plasma_gap_radial_thickness=50, plasma_radial_thickness=200, outer_plasma_gap_radial_thickness=50, firstwall_radial_thickness=30, blanket_rear_wall_radial_thickness=30, rotation_angle=180, support_radial_thickness=50, inboard_blanket_radial_thickness=30, outboard_blanket_radial_thickness=30, elongation=2.75, triangularity=0.5, ) # this can just be set as a string as temperature is needed for this # material flibe = nmm.Material('FLiBe', temperature_in_C=temperature) source = openmc.Source() # sets the location of the source to x=0 y=0 z=0 source.space = openmc.stats.Point((my_reactor.major_radius, 0, 0)) # sets the direction to isotropic source.angle = openmc.stats.Isotropic() # sets the energy distribution to 100% 14MeV neutrons source.energy = openmc.stats.Discrete([14e6], [1]) # makes the neutronics model from the geometry and material allocations neutronics_model = paramak.NeutronicsModel( geometry=my_reactor, source=source, materials={ 'inboard_tf_coils_mat': 'eurofer', 'center_column_shield_mat': 'eurofer', 'divertor_mat': 'eurofer', 'firstwall_mat': 'eurofer', 'blanket_rear_wall_mat': 'eurofer', 'blanket_mat': flibe, 'supports_mat': 'eurofer' }, cell_tallies=['TBR'], simulation_batches=5, simulation_particles_per_batch=1e4, faceting_tolerance=1e-4, merge_tolerance=1e-4) # simulate the neutronics model neutronics_model.simulate(method='trelis') return neutronics_model.results['TBR']
def model(): model = openmc.model.Model() # Materials m1 = openmc.Material() m1.set_density('g/cc', 4.5) m1.add_nuclide('U235', 1.0) m2 = openmc.Material() m2.set_density('g/cc', 1.0) m2.add_nuclide('H1', 1.0) model.materials += [m1, m2] # Geometry cyl1 = openmc.ZCylinder(r=0.7) c1 = openmc.Cell(fill=m1, region=-cyl1) c2 = openmc.Cell(fill=m2, region=+cyl1) # intermediate universe containing only cell 2 u1 = openmc.Universe(cells=[c2]) c3 = openmc.Cell(fill=u1) u2 = openmc.Universe(cells=[c1, c3]) cyl2 = openmc.ZCylinder(r=0.5) c4 = openmc.Cell(fill=m1, region=-cyl2) c5 = openmc.Cell(fill=m2, region=+cyl2) u3 = openmc.Universe(cells=[c4, c5]) lat = openmc.RectLattice() lat.lower_left = (-4, -4) lat.pitch = (2, 2) lat.universes = [[u2, u3, u3, u3], [u3, u2, u3, u3], [u3, u3, u2, u3], [u3, u3, u3, u2]] box = openmc.model.rectangular_prism(8.0, 8.0, boundary_type='reflective') main_cell = openmc.Cell(fill=lat, region=box) model.geometry.root_universe = openmc.Universe(cells=[main_cell]) model.geometry.determine_paths() # Settings model.settings.batches = 5 model.settings.inactive = 0 model.settings.particles = 1000 model.settings.source = openmc.Source(space=openmc.stats.Point()) instances = ([(c4, i) for i in range(c4.num_instances)] + [(c2, i) for i in range(c2.num_instances)] + [(c3, i) for i in range(c3.num_instances)]) f1 = openmc.CellInstanceFilter(instances) f2 = openmc.CellInstanceFilter(instances[::-1]) t1 = openmc.Tally() t1.filters = [f1] t1.scores = ['total'] t2 = openmc.Tally() t2.filters = [f2] t2.scores = ['total'] model.tallies += [t1, t2] return model
def make_model_and_simulate(): simulation_values = [] for mid_radius in [60, 70, 80]: # makes the component with a few different size mid radius values my_shape = paramak.CenterColumnShieldHyperbola( height=500, inner_radius=50, mid_radius=mid_radius, outer_radius=100, material_tag='center_column_shield_mat' ) my_shape.export_stp('my_shape' + str(mid_radius) + '.stp') # makes the openmc neutron source at x,y,z 0, 0, 0 with isotropic # diections source = openmc.Source() source.space = openmc.stats.Point((0, 0, 0)) source.angle = openmc.stats.Isotropic() # converts the geometry into a neutronics geometry my_model = paramak.NeutronicsModel( geometry=my_shape, source=source, materials={'center_column_shield_mat': 'eurofer'}, cell_tallies=['heating', 'TBR'], mesh_tally_2d=['heating'], mesh_tally_3d=['heating'], simulation_batches=10, # should be increased for more accurate result simulation_particles_per_batch=10 # settings are low to reduce time required ) # performs an openmc simulation on the model my_model.simulate(method='pymoab') # extracts the heat from the results dictionary heat = my_model.results['center_column_shield_mat_heating']['Watts']['result'] # adds the heat and the mid radius value to a list simulation_values.append((mid_radius, heat)) # plots the simualtion results vs the mid_radius used for the simulation plt.plot( [i[0] for i in simulation_values], [i[1] for i in simulation_values], '-p' ) # adds labels to the graph plt.title("heating vs thickness") plt.xlabel("thickness (cm)") plt.ylabel("heating (watts)") plt.savefig('heating_vs_thickness.svg') plt.show()
def _make_openmc_input(self): """Generate the OpenMC input XML """ # Define material mat = openmc.Material() for element, fraction in self.elements: mat.add_element(element, fraction) mat.set_density('g/cm3', self.density) materials = openmc.Materials([mat]) if self.xsdir is not None: xs_path = (self.openmc_dir / 'cross_sections.xml').resolve() materials.cross_sections = str(xs_path) materials.export_to_xml(self.openmc_dir / 'materials.xml') # Set up geometry x1 = openmc.XPlane(x0=-1.e9, boundary_type='reflective') x2 = openmc.XPlane(x0=+1.e9, boundary_type='reflective') y1 = openmc.YPlane(y0=-1.e9, boundary_type='reflective') y2 = openmc.YPlane(y0=+1.e9, boundary_type='reflective') z1 = openmc.ZPlane(z0=-1.e9, boundary_type='reflective') z2 = openmc.ZPlane(z0=+1.e9, boundary_type='reflective') cell = openmc.Cell(fill=materials) cell.region = +x1 & -x2 & +y1 & -y2 & +z1 & -z2 geometry = openmc.Geometry([cell]) geometry.export_to_xml(self.openmc_dir / 'geometry.xml') # Define source source = openmc.Source() source.space = openmc.stats.Point((0,0,0)) source.angle = openmc.stats.Isotropic() source.energy = openmc.stats.Discrete([self.energy], [1.]) source.particle = 'photon' # Settings settings = openmc.Settings() settings.source = source settings.particles = self.particles // self._batches settings.run_mode = 'fixed source' settings.batches = self._batches settings.photon_transport = True settings.electron_treatment = self.electron_treatment settings.cutoff = {'energy_photon' : self._cutoff_energy} settings.export_to_xml(self.openmc_dir / 'settings.xml') # Define tallies energy_bins = np.logspace(np.log10(self._cutoff_energy), np.log10(1.0001*self.energy), self._bins+1) energy_filter = openmc.EnergyFilter(energy_bins) particle_filter = openmc.ParticleFilter('photon') tally = openmc.Tally(name='tally') tally.filters = [energy_filter, particle_filter] tally.scores = ['flux'] tallies = openmc.Tallies([tally]) tallies.export_to_xml(self.openmc_dir / 'tallies.xml')
def _build_inputs(self): # Define materials water = openmc.Material(1) water.add_nuclide('H1', 2.0) water.add_nuclide('O16', 1.0) water.add_s_alpha_beta('c_H_in_H2O') water.set_density('g/cc', 1.0) fuel = openmc.Material(2) fuel.add_nuclide('U235', 1.0) fuel.set_density('g/cc', 4.5) materials = openmc.Materials((water, fuel)) materials.default_temperature = '294K' materials.export_to_xml() # Define the geometry. Note that this geometry is somewhat non-sensical # (it essentially defines a circle of half-cylinders), but it is # designed so that periodic and reflective BCs will give different # answers. theta1 = (-1 / 6 + 1 / 2) * np.pi theta2 = (1 / 6 - 1 / 2) * np.pi plane1 = openmc.Plane(a=np.cos(theta1), b=np.sin(theta1), boundary_type='periodic') plane2 = openmc.Plane(a=np.cos(theta2), b=np.sin(theta2), boundary_type='periodic') x_max = openmc.XPlane(x0=5., boundary_type='reflective') z_cyl = openmc.ZCylinder(x0=3 * np.cos(np.pi / 6), y0=3 * np.sin(np.pi / 6), r=2.0) outside_cyl = openmc.Cell(1, fill=water, region=(+plane1 & +plane2 & -x_max & +z_cyl)) inside_cyl = openmc.Cell(2, fill=fuel, region=(+plane1 & +plane2 & -z_cyl)) root_universe = openmc.Universe(0, cells=(outside_cyl, inside_cyl)) geometry = openmc.Geometry() geometry.root_universe = root_universe geometry.export_to_xml() # Define settings settings = openmc.Settings() settings.particles = 1000 settings.batches = 4 settings.inactive = 0 settings.source = openmc.Source( space=openmc.stats.Box((0, 0, 0), (5, 5, 0))) settings.export_to_xml()
def model(request): openmc.reset_auto_ids() marker = request.node.get_closest_marker("surf_source_op") surf_source_op = marker.args[0] openmc_model = openmc.model.Model() # Materials # None # Geometry # Concentric void spheres # - Innermost sphere to bank surface sources # - Second shell to tally cell flux # - Outermost sphere as vacuum boundary sph_1 = openmc.Sphere(r=1.0) # Surface to bank/write sources. sph_2 = openmc.Sphere(r=2.0) sph_3 = openmc.Sphere(r=2.5) sph_4 = openmc.Sphere(r=4.0, boundary_type='vacuum') cell_1 = openmc.Cell(region=-sph_1) cell_2 = openmc.Cell(region=+sph_1 & -sph_2) cell_3 = openmc.Cell(region=+sph_2 & -sph_3) # Cell to tally flux. cell_4 = openmc.Cell(region=+sph_3 & -sph_4) root = openmc.Universe(cells=[cell_1, cell_2, cell_3, cell_4]) openmc_model.geometry = openmc.Geometry(root) # Settings openmc_model.settings.run_mode = 'fixed source' openmc_model.settings.particles = 1000 openmc_model.settings.batches = 10 openmc_model.settings.seed = 1 if surf_source_op == 'write': point = openmc.stats.Point((0, 0, 0)) pt_src = openmc.Source(space=point) openmc_model.settings.source = pt_src openmc_model.settings.surf_source_write = { 'surface_ids': [1], 'max_particles': 1000 } elif surf_source_op == 'read': openmc_model.settings.surf_source_read = { 'path': 'surface_source_true.h5' } # Tallies tal = openmc.Tally() cell_filter = openmc.CellFilter(cell_3) tal.filters = [cell_filter] tal.scores = ['flux'] openmc_model.tallies.append(tal) return openmc_model
def _build_inputs(self): # Define materials water = openmc.Material(1) water.add_nuclide('H1', 2.0) water.add_nuclide('O16', 1.0) water.add_s_alpha_beta('c_H_in_H2O') water.set_density('g/cc', 1.0) fuel = openmc.Material(2) fuel.add_nuclide('U235', 1.0) fuel.set_density('g/cc', 4.5) materials = openmc.Materials((water, fuel)) materials.default_temperature = '294K' materials.export_to_xml() # Define geometry x_min = openmc.XPlane(surface_id=1, x0=0., boundary_type='periodic') x_max = openmc.XPlane(surface_id=2, x0=5., boundary_type='reflective') y_min = openmc.YPlane(surface_id=3, y0=0., boundary_type='periodic') y_max = openmc.YPlane(surface_id=4, y0=5., boundary_type='reflective') y_min.periodic_surface = x_min z_min = openmc.ZPlane(surface_id=5, z0=-5., boundary_type='periodic') z_max = openmc.Plane(surface_id=6, a=0, b=0, c=1, d=5., boundary_type='periodic') z_cyl = openmc.ZCylinder(surface_id=7, x0=2.5, y0=0., r=2.0) outside_cyl = openmc.Cell(1, fill=water, region=(+x_min & -x_max & +y_min & -y_max & +z_min & -z_max & +z_cyl)) inside_cyl = openmc.Cell(2, fill=fuel, region=(+y_min & +z_min & -z_max & -z_cyl)) root_universe = openmc.Universe(0, cells=(outside_cyl, inside_cyl)) geometry = openmc.Geometry() geometry.root_universe = root_universe geometry.export_to_xml() # Define settings settings = openmc.Settings() settings.particles = 1000 settings.batches = 4 settings.inactive = 0 settings.source = openmc.Source( space=openmc.stats.Box((0, 0, 0), (5, 5, 0))) settings.export_to_xml()
def setUp(self): self.my_shape = paramak.CenterColumnShieldHyperbola( height=500, inner_radius=50, mid_radius=60, outer_radius=100, material_tag='center_column_shield_mat') # makes the openmc neutron source at x,y,z 0, 0, 0 with isotropic # directions self.source = openmc.Source() self.source.space = openmc.stats.Point((0, 0, 0)) self.source.angle = openmc.stats.Isotropic()
def assembly_model(): """Returns a single PWR fuel assembly.""" model = openmc.model.Model() # Create fuel assembly Lattice pitch = 21.42 assembly = openmc.RectLattice(name='Fuel Assembly') assembly.pitch = (pitch / 17, pitch / 17) assembly.lower_left = (-pitch / 2, -pitch / 2) # Create array indices for guide tube locations in lattice gt_pos = np.array([[2, 5], [2, 8], [2, 11], [3, 3], [3, 13], [5, 2], [5, 5], [5, 8], [5, 11], [5, 14], [8, 2], [8, 5], [8, 8], [8, 11], [8, 14], [11, 2], [11, 5], [11, 8], [11, 11], [11, 14], [13, 3], [13, 13], [14, 5], [14, 8], [14, 11]]) # Create 17x17 array of universes. First we create a 17x17 array all filled # with the fuel pin universe. Then, we replace the guide tube positions with # the guide tube pin universe (note the use of numpy fancy indexing to # achieve this). assembly.universes = np.full((17, 17), fuel_pin()) assembly.universes[gt_pos[:, 0], gt_pos[:, 1]] = guide_tube_pin() # Create outer boundary of the geometry to surround the lattice outer_boundary = openmc.model.rectangular_prism(pitch, pitch, boundary_type='reflective') # Create a cell filled with the lattice main_cell = openmc.Cell(fill=assembly, region=outer_boundary) # Finally, create geometry by providing a list of cells that fill the root # universe model.geometry = openmc.Geometry([main_cell]) model.settings.batches = 150 model.settings.inactive = 50 model.settings.particles = 1000 model.settings.source = openmc.Source( space=openmc.stats.Box((-pitch / 2, -pitch / 2, -1), (pitch / 2, pitch / 2, 1), only_fissionable=True)) # NOTE: We never actually created a Materials object. When you export/run # using the Model object, if no materials were assigned it will look through # the Geometry object and automatically export any materials that are # necessary to build the model. return model
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 element, fraction in self.elements: mat.add_element(element, fraction) mat.set_density('g/cm3', self.density) materials = openmc.Materials([mat]) materials.export_to_xml(os.path.join('openmc', 'materials.xml')) # Set up geometry sphere = openmc.Sphere(boundary_type='reflective', R=1.e9) cell = openmc.Cell() cell.fill = mat cell.region = -sphere geometry = openmc.Geometry([cell]) 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.Isotropic() source.energy = openmc.stats.Discrete([self.energy], [1.]) source.particle = 'photon' # 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 tallies cell_filter = openmc.CellFilter(cell) energy_bins = np.logspace(3, np.log10(self.energy), 500) energy_filter = openmc.EnergyFilter(energy_bins) particle_filter = openmc.ParticleFilter('photon') tally = openmc.Tally(name='photon flux') tally.filters = [cell_filter, energy_filter, particle_filter] tally.scores = ['flux'] tallies = openmc.Tallies([tally]) tallies.export_to_xml(os.path.join('openmc', 'tallies.xml'))
def dagmc_model(request): model = openmc.model.Model() # settings model.settings.batches = 5 model.settings.inactive = 0 model.settings.particles = 100 model.settings.temperature = {'tolerance': 50.0} model.settings.verbosity = 1 source_box = openmc.stats.Box([-4, -4, -4], [4, 4, 4]) source = openmc.Source(space=source_box) model.settings.source = source # geometry dagmc_universe = openmc.DAGMCUniverse('dagmc.h5m') model.geometry = openmc.Geometry(dagmc_universe) # tally tally = openmc.Tally() tally.scores = ['total'] tally.filters = [openmc.CellFilter(1)] model.tallies = [tally] # materials u235 = openmc.Material(name="no-void fuel") u235.add_nuclide('U235', 1.0, 'ao') u235.set_density('g/cc', 11) u235.id = 40 u235.temperature = 320 water = openmc.Material(name="water") water.add_nuclide('H1', 2.0, 'ao') water.add_nuclide('O16', 1.0, 'ao') water.set_density('g/cc', 1.0) water.add_s_alpha_beta('c_H_in_H2O') water.id = 41 mats = openmc.Materials([u235, water]) model.materials = mats # location of dagmc file in test directory dagmc_file = request.fspath.dirpath() + "/dagmc.h5m" # move to a temporary directory with cdtemp(): shutil.copyfile(dagmc_file, "./dagmc.h5m") model.export_to_xml() openmc.lib.init() yield openmc.lib.finalize()
def make_model_and_simulate(): """Makes a neutronics Reactor model and simulates the heat deposition""" # makes the 3d geometry my_reactor = paramak.CenterColumnStudyReactor( inner_bore_radial_thickness=20, inboard_tf_leg_radial_thickness=50, center_column_shield_radial_thickness_mid=50, center_column_shield_radial_thickness_upper=100, inboard_firstwall_radial_thickness=20, divertor_radial_thickness=100, inner_plasma_gap_radial_thickness=80, plasma_radial_thickness=200, outer_plasma_gap_radial_thickness=90, elongation=2.75, triangularity=0.5, plasma_gap_vertical_thickness=40, center_column_arc_vertical_thickness=520, rotation_angle=360) source = openmc.Source() # sets the location of the source to x=0 y=0 z=0 source.space = openmc.stats.Point((my_reactor.major_radius, 0, 0)) # sets the direction to isotropic source.angle = openmc.stats.Isotropic() # sets the energy distribution to 100% 14MeV neutrons source.energy = openmc.stats.Discrete([14e6], [1]) # creates a neutronics model from the geometry and assigned materials neutronics_model = paramak.NeutronicsModel( geometry=my_reactor, source=source, materials={ 'inboard_tf_coils_mat': 'eurofer', 'center_column_shield_mat': 'eurofer', 'divertor_mat': 'eurofer', 'firstwall_mat': 'eurofer', 'blanket_mat': 'Li4SiO4' }, cell_tallies=['heating'], simulation_batches=5, simulation_particles_per_batch=1e4, ) # starts the neutronics simulation neutronics_model.simulate(method='trelis') # prints the results print(neutronics_model.results)