def test_transfer_volumes(run_in_tmpdir): """Unit test of volume transfer in restart calculations.""" op = dummy_operator.DummyOperator() op.output_dir = "test_transfer_volumes" # Perform simulation using the predictor algorithm dt = [0.75] power = 1.0 PredictorIntegrator(op, dt, power).integrate() # Load the files res = openmc.deplete.ResultsList.from_hdf5(op.output_dir / "depletion_results.h5") # Create a dictionary of volumes to transfer res[0].volume['1'] = 1.5 res[0].volume['2'] = 2.5 # Create dummy geometry mat1 = openmc.Material(material_id=1) mat1.depletable = True mat2 = openmc.Material(material_id=2) cell = openmc.Cell() cell.fill = [mat1, mat2] root = openmc.Universe() root.add_cell(cell) geometry = openmc.Geometry(root) # Transfer volumes res[0].transfer_volumes(openmc.Model(geometry)) assert mat1.volume == 1.5 assert mat2.volume is None
def materials(tmpdir_factory): """Use C API to construct realistic materials for testing tallies""" tmpdir = tmpdir_factory.mktemp("lib") orig = tmpdir.chdir() # Create proxy problem to please openmc mfuel = openmc.Material(name="test_fuel") mfuel.volume = 1.0 for nuclide in ["U235", "U238", "Xe135", "Pu239"]: mfuel.add_nuclide(nuclide, 1.0) openmc.Materials([mfuel]).export_to_xml() # Geometry box = openmc.rectangular_prism(1.0, 1.0, boundary_type="reflective") cell = openmc.Cell(fill=mfuel, region=box) root = openmc.Universe(cells=[cell]) openmc.Geometry(root).export_to_xml() # settings settings = openmc.Settings() settings.particles = 100 settings.inactive = 0 settings.batches = 10 settings.verbosity = 1 settings.export_to_xml() try: with lib.run_in_memory(): yield [lib.Material(), lib.Material()] finally: # Convert to strings as os.remove in py 3.5 doesn't support Paths for file_path in ("settings.xml", "geometry.xml", "materials.xml", "summary.h5"): os.remove(str(tmpdir / file_path)) orig.chdir() os.rmdir(str(tmpdir))
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 get_openmc_geometry(openmoc_geometry): """Return an OpenMC geometry corresponding to an OpenMOC geometry. Parameters ---------- openmoc_geometry : openmoc.Geometry OpenMOC geometry Returns ------- openmc_geometry : openmc.Geometry Equivalent OpenMC geometry """ cv.check_type('openmoc_geometry', openmoc_geometry, openmoc.Geometry) # Clear dictionaries and auto-generated ID OPENMC_SURFACES.clear() OPENMOC_SURFACES.clear() OPENMC_CELLS.clear() OPENMOC_CELLS.clear() OPENMC_UNIVERSES.clear() OPENMOC_UNIVERSES.clear() OPENMC_LATTICES.clear() OPENMOC_LATTICES.clear() openmoc_root_universe = openmoc_geometry.getRootUniverse() openmc_root_universe = get_openmc_universe(openmoc_root_universe) openmc_geometry = openmc.Geometry() openmc_geometry.root_universe = openmc_root_universe return openmc_geometry
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 __init__(self, filename): if not filename.endswith(('.h5', '.hdf5')): msg = 'Unable to open "{0}" which is not an HDF5 summary file' raise ValueError(msg) self._f = h5py.File(filename, 'r') cv.check_filetype_version(self._f, 'summary', _VERSION_SUMMARY) self._geometry = openmc.Geometry() self._fast_materials = {} self._fast_surfaces = {} self._fast_cells = {} self._fast_universes = {} self._fast_lattices = {} self._materials = openmc.Materials() self._nuclides = {} self._macroscopics = [] self._read_nuclides() self._read_macroscopics() with warnings.catch_warnings(): warnings.simplefilter("ignore", openmc.IDWarning) self._read_geometry()
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_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 _finalize_geometry(self): # Initialize Geometry object self._openmc_geometry = openmc.Geometry() # Iterate over all Cells and add fill Materials, Universes and Lattices for cell_key in self._cell_fills.keys(): # Determine fill type ('normal', 'universe', or 'lattice') and ID fill_type = self._cell_fills[cell_key][0] fill_id = self._cell_fills[cell_key][1] # Retrieve the object corresponding to the fill type and ID if fill_type == 'normal': if fill_id > 0: fill = self.get_material_by_id(fill_id) else: fill = 'void' elif fill_type == 'universe': fill = self.get_universe_by_id(fill_id) else: fill = self.get_lattice_by_id(fill_id) # Set the fill for the Cell self.cells[cell_key].fill = fill # Set the root universe for the Geometry root_universe = self.get_universe_by_id(0) self.openmc_geometry.root_universe = root_universe
def buildTriangUni(modSetting,pitch,diameter,boron,modT,fuelT,DyFrac,enrich): uo2=getU(fuelT,DyFrac,enrich) mod=getMod(modSetting,boron,modT) #loads the moderator mats = openmc.Materials([uo2, mod]) mats.export_to_xml() ####################build the surfaces################################ fuel_or1 = openmc.ZCylinder(R=diameter/2) box = openmc.get_hexagonal_prism(edge_length=pitch/math.sqrt(3.0),boundary_type='reflective') #################Build the Cells ####################################### fuel_region = -fuel_or1 #beautiful abuse of operator overloading mod_region = box & +fuel_or1 # c # c Fuel # c # c throwback to MCNP fuel = openmc.Cell(1, 'fuel') fuel.fill = uo2 fuel.region = fuel_region # # Moderator # moderator = openmc.Cell(4, 'moderator') moderator.fill = mod moderator.region = mod_region #I am groot! groot = openmc.Universe(cells=(fuel, moderator)) geom = openmc.Geometry(groot) geom.export_to_xml() cell_filter = openmc.CellFilter([fuel, moderator]) # tallies buildTallies(cell_filter) return (fuel,moderator)
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 __init__(self): self.settings = openmc.Settings() self.materials = openmc.Materials() self.geometry = openmc.Geometry() self.tallies = openmc.Tallies() self.build_default_materials_and_geometry() self.build_default_settings()
def model(): model = openmc.Model() fuel = openmc.Material() fuel.set_density('g/cm3', 12.0) fuel.add_nuclide('U235', 1.0) al = openmc.Material() al.set_density('g/cm3', 1.0) al.add_nuclide('H1', 1.0) model.materials.extend([fuel, al]) # 🍩🍩🍩 zt = openmc.ZTorus(a=3, b=1.5, c=1) xt = openmc.XTorus(x0=6, a=3, b=1.5, c=1) yt = openmc.YTorus(x0=6, a=6, b=1, c=0.75) box = openmc.model.RectangularParallelepiped(-5, 14, -5, 5, -8, 8, boundary_type='vacuum') xt_cell = openmc.Cell(fill=fuel, region=-xt) yt_cell = openmc.Cell(fill=fuel, region=-yt) zt_cell = openmc.Cell(fill=fuel, region=-zt) outer_cell = openmc.Cell(fill=al, region=-box & +xt & +yt & +zt) model.geometry = openmc.Geometry([xt_cell, yt_cell, zt_cell, outer_cell]) model.settings.particles = 1000 model.settings.batches = 10 model.settings.inactive = 5 return model
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 _build_inputs(self): # Define materials water = openmc.Material(1) water.add_nuclide('H1', 2.0) water.add_nuclide('O16', 1.0) water.add_nuclide('B10', 0.0001) 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.add_nuclide('Mo99', 0.1) fuel.set_density('g/cc', 4.5) materials = openmc.Materials((water, fuel)) materials.export_to_xml() cyl = openmc.ZCylinder(surface_id=1, r=1.0, boundary_type='vacuum') top_sphere = openmc.Sphere(surface_id=2, z0=5., r=1., boundary_type='vacuum') top_plane = openmc.ZPlane(surface_id=3, z0=5.) bottom_sphere = openmc.Sphere(surface_id=4, z0=-5., r=1., boundary_type='vacuum') bottom_plane = openmc.ZPlane(surface_id=5, z0=-5.) # Define geometry inside_cyl = openmc.Cell(1, fill=fuel, region=-cyl & -top_plane & +bottom_plane) top_hemisphere = openmc.Cell(2, fill=water, region=-top_sphere & +top_plane) bottom_hemisphere = openmc.Cell(3, fill=water, region=-bottom_sphere & -top_plane) root = openmc.Universe(0, cells=(inside_cyl, top_hemisphere, bottom_hemisphere)) geometry = openmc.Geometry(root) geometry.export_to_xml() # Set up stochastic volume calculation ll, ur = root.bounding_box vol_calcs = [ openmc.VolumeCalculation(list(root.cells.values()), 100000), openmc.VolumeCalculation([water, fuel], 100000, ll, ur), openmc.VolumeCalculation([root], 100000, ll, ur) ] # Define settings settings = openmc.Settings() settings.run_mode = 'volume' settings.volume_calculations = vol_calcs settings.export_to_xml()
def test_get_all_cells(): cells = [openmc.Cell() for i in range(5)] cells2 = [openmc.Cell() for i in range(3)] cells[0].fill = openmc.Universe(cells=cells2) geom = openmc.Geometry(cells) all_cells = set(geom.get_all_cells().values()) assert not all_cells ^ set(cells + cells2)
def test_get_all_surfaces(uo2): planes = [openmc.ZPlane(z0=z) for z in np.linspace(-100., 100.)] slabs = [] for region in openmc.model.subdivide(planes): slabs.append(openmc.Cell(fill=uo2, region=region)) geom = openmc.Geometry(slabs) surfs = set(geom.get_all_surfaces().values()) assert not surfs ^ set(planes)
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 _build_inputs(self): # Instantiate some Macroscopic Data uo2_data = openmc.Macroscopic('UO2') # Instantiate some Materials and register the appropriate objects mat = openmc.Material(material_id=1, name='UO2 fuel') mat.set_density('macro', 1.0) mat.add_macroscopic(uo2_data) # Instantiate a Materials collection and export to XML materials_file = openmc.Materials([mat]) materials_file.cross_sections = "./mgxs.h5" materials_file.export_to_xml() # Instantiate ZCylinder surfaces left = openmc.XPlane(surface_id=4, x0=-5., name='left') right = openmc.XPlane(surface_id=5, x0=5., name='right') bottom = openmc.YPlane(surface_id=6, y0=-5., name='bottom') top = openmc.YPlane(surface_id=7, y0=5., name='top') left.boundary_type = 'reflective' right.boundary_type = 'vacuum' top.boundary_type = 'reflective' bottom.boundary_type = 'reflective' # Instantiate Cells fuel = openmc.Cell(cell_id=1, name='cell 1') # Use surface half-spaces to define regions fuel.region = +left & -right & +bottom & -top # Register Materials with Cells fuel.fill = mat # Instantiate Universe root = openmc.Universe(universe_id=0, name='root universe') # Register Cells with Universe root.add_cells([fuel]) # Instantiate a Geometry, register the root Universe, and export to XML geometry = openmc.Geometry(root) geometry.export_to_xml() settings_file = openmc.Settings() settings_file.energy_mode = "multi-group" settings_file.batches = batches settings_file.inactive = inactive settings_file.particles = particles # Create an initial uniform spatial source distribution bounds = [-5, -5, -5, 5, 5, 5] uniform_dist = openmc.stats.Box(bounds[:3], bounds[3:]) settings_file.source = openmc.source.Source(space=uniform_dist) settings_file.export_to_xml()
def test_get_lattice_by_name(cell_with_lattice): cells, _, _, lattice = cell_with_lattice geom = openmc.Geometry([cells[-1]]) f = geom.get_lattices_by_name assert f('lattice') == [lattice] assert f('lattice', True) == [] assert f('Lattice', True) == [lattice] assert f('my lattice', False, True) == [lattice] assert f('my lattice', True, True) == []
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 update(self, Tf, Tclad, Tbulk, Mesh, RhoBulk): #T.gap # Update temperatures in OpenMC 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.seed = np.random.randint(1,100) #for correlation calculation self.settings_file.export_to_xml() shutil.move('settings.xml', 'PinGeo/settings.xml') #START removed for uncoupled correlation self.materials_file.export_to_xml() shutil.move('materials.xml', 'PinGeo/materials.xml') self.reflectTOP.temperature = Tbulk[-1] self.reflectBOT.temperature = Tbulk[0] j = 0 for fuels in self.fuel_list: fuels.temperature = (Tf[j] + Tf[j + 1]) / 2 j = j + 1 # j = 0 # for gaps in self.gap_list: # gaps.temperature = (Tgap[j]+Tgap[j])/2. # j = j+1 j = 0 for clads in self.clad_list: clads.temperature = (Tclad[j] + Tclad[j + 1]) / 2. j = j + 1 #Update temperature of extraclad_list? j = 0 for waters in self.water_list: waters.temperature = (Tbulk[j] + Tbulk[j + 1]) / 2 j = j + 1 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.water_list) self.geometry_file = openmc.Geometry(self.root) self.geometry_file.export_to_xml() shutil.move('geometry.xml', 'PinGeo/geometry.xml') #END removed for uncoupled correlation # Tallies # power distribution: fission q recoverable (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=2) t.filters.append(cell_filter) t.scores = ['fission-q-recoverable'] self.tallies = openmc.Tallies([t]) self.tallies.export_to_xml() shutil.move('tallies.xml', 'PinGeo/tallies.xml')
def test_clone(): c1 = openmc.Cell() c2 = openmc.Cell() root = openmc.Universe(cells=[c1, c2]) geom = openmc.Geometry(root) clone = geom.clone() root_clone = clone.root_universe assert root.id != root_clone.id assert not (set(root.cells) & set(root_clone.cells))
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 test_from_geometry(): width = 25. s = openmc.Sphere(r=width / 2, boundary_type='vacuum') c = openmc.Cell(region=-s) univ = openmc.Universe(cells=[c]) geom = openmc.Geometry(univ) for basis in ('xy', 'yz', 'xz'): plot = openmc.Plot.from_geometry(geom, basis) assert plot.origin == pytest.approx((0., 0., 0.)) assert plot.width == pytest.approx((width, width))
def model(): model = openmc.model.Model() fuel = openmc.Material() fuel.set_density('g/cm3', 10.0) fuel.add_nuclide('U235', 1.0) zr = openmc.Material() zr.set_density('g/cm3', 1.0) zr.add_nuclide('Zr90', 1.0) model.materials.extend([fuel, zr]) box1 = openmc.model.rectangular_prism(10.0, 10.0) box2 = openmc.model.rectangular_prism(20.0, 20.0, boundary_type='reflective') top = openmc.ZPlane(z0=10.0, boundary_type='vacuum') bottom = openmc.ZPlane(z0=-10.0, boundary_type='vacuum') cell1 = openmc.Cell(fill=fuel, region=box1 & +bottom & -top) cell2 = openmc.Cell(fill=zr, region=~box1 & box2 & +bottom & -top) model.geometry = openmc.Geometry([cell1, cell2]) model.settings.batches = 5 model.settings.inactive = 0 model.settings.particles = 1000 # Initialize a one-group structure energy_groups = openmc.mgxs.EnergyGroups([0, 20.e6]) # Initialize MGXS Library for a few cross section types # for one material-filled cell in the geometry model.mgxs_lib = openmc.mgxs.Library(model.geometry) model.mgxs_lib.by_nuclide = False # Test all MGXS types model.mgxs_lib.mgxs_types = openmc.mgxs.MGXS_TYPES + openmc.mgxs.MDGXS_TYPES model.mgxs_lib.energy_groups = energy_groups model.mgxs_lib.num_delayed_groups = 6 model.mgxs_lib.correction = None # Avoid warning about P0 correction model.mgxs_lib.legendre_order = 3 model.mgxs_lib.domain_type = 'mesh' # Instantiate a tally mesh mesh = openmc.RegularMesh(mesh_id=1) mesh.dimension = [2, 2] mesh.lower_left = [-100., -100.] mesh.width = [100., 100.] model.mgxs_lib.domains = [mesh] model.mgxs_lib.build_library() # Add tallies model.mgxs_lib.add_to_tallies_file(model.tallies, merge=False) return model
def _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 get_openmc_geometry(opencg_geometry): """Return an OpenMC geometry corresponding to an OpenCG geometry. Parameters ---------- opencg_geometry : opencg.Geometry OpenCG geometry Returns ------- openmc_geometry : openmc.universe.Geometry Equivalent OpenMC geometry """ if not isinstance(opencg_geometry, opencg.Geometry): msg = 'Unable to get OpenMC geometry from "{0}" which is ' \ 'not an OpenCG Geometry object'.format(opencg_geometry) raise ValueError(msg) # Deep copy the goemetry since it may be modified to make all Surfaces # compatible with OpenMC's specifications opencg_geometry.assignAutoIds() opencg_geometry = copy.deepcopy(opencg_geometry) # Update Cell bounding boxes in Geometry opencg_geometry.updateBoundingBoxes() # Clear dictionaries and auto-generated ID OPENMC_SURFACES.clear() OPENCG_SURFACES.clear() OPENMC_CELLS.clear() OPENCG_CELLS.clear() OPENMC_UNIVERSES.clear() OPENCG_UNIVERSES.clear() OPENMC_LATTICES.clear() OPENCG_LATTICES.clear() # Make the entire geometry "compatible" before assigning auto IDs universes = opencg_geometry.getAllUniverses() for universe_id, universe in universes.items(): if not isinstance(universe, opencg.Lattice): make_opencg_cells_compatible(universe) opencg_geometry.assignAutoIds() opencg_root_universe = opencg_geometry._root_universe openmc_root_universe = get_openmc_universe(opencg_root_universe) openmc_geometry = openmc.Geometry() openmc_geometry.root_universe = openmc_root_universe return openmc_geometry
def test_get_all_materials(): m1 = openmc.Material() m2 = openmc.Material() c1 = openmc.Cell(fill=m1) u1 = openmc.Universe(cells=[c1]) s = openmc.Sphere() c2 = openmc.Cell(fill=u1, region=-s) c3 = openmc.Cell(fill=m2, region=+s) geom = openmc.Geometry([c2, c3]) all_mats = set(geom.get_all_materials().values()) assert not all_mats ^ {m1, m2}