コード例 #1
0
    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()
コード例 #2
0
ファイル: test_model.py プロジェクト: yardasol/openmc
def test_calc_volumes(run_in_tmpdir, pin_model_attributes, mpi_intracomm):
    mats, geom, settings, tals, plots, _, _ = pin_model_attributes

    test_model = openmc.Model(geom, mats, settings, tals, plots)

    # With no vol calcs, it should fail
    with pytest.raises(ValueError):
        test_model.calculate_volumes(output=False)

    # Add a cell and mat volume calc
    material_vol_calc = openmc.VolumeCalculation([mats[2]],
                                                 samples=1000,
                                                 lower_left=(-.63, -.63,
                                                             -100.),
                                                 upper_right=(.63, .63, 100.))
    cell_vol_calc = openmc.VolumeCalculation([geom.root_universe.cells[3]],
                                             samples=1000,
                                             lower_left=(-.63, -.63, -100.),
                                             upper_right=(.63, .63, 100.))
    test_model.settings.volume_calculations = \
        [material_vol_calc, cell_vol_calc]

    # Now lets compute the volumes and check to see if it was applied
    # First lets do without using the C-API
    # Make sure the volumes are unassigned first
    assert mats[2].volume is None
    assert geom.root_universe.cells[3].volume is None
    test_model.calculate_volumes(output=False, apply_volumes=True)

    # Now let's test that we have volumes assigned; we arent checking the
    # value, just that the value was changed
    assert mats[2].volume > 0.
    assert geom.root_universe.cells[3].volume > 0.

    # Now reset the values
    mats[2].volume = None
    geom.root_universe.cells[3].volume = None

    # And do again with an initialized library
    for file in ['volume_1.h5', 'volume_2.h5']:
        file = Path(file)
        file.unlink()
    test_model.init_lib(output=False, intracomm=mpi_intracomm)
    test_model.calculate_volumes(output=False, apply_volumes=True)
    assert mats[2].volume > 0.
    assert geom.root_universe.cells[3].volume > 0.
    assert openmc.lib.materials[3].volume == mats[2].volume

    test_model.finalize_lib()
コード例 #3
0
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())
コード例 #4
0
ファイル: test_settings.py プロジェクト: yardasol/openmc
def test_export_to_xml(run_in_tmpdir):
    s = openmc.Settings()
    s.run_mode = 'fixed source'
    s.batches = 1000
    s.generations_per_batch = 10
    s.inactive = 100
    s.particles = 1000000
    s.max_lost_particles = 5
    s.rel_max_lost_particles = 1e-4
    s.keff_trigger = {'type': 'std_dev', 'threshold': 0.001}
    s.energy_mode = 'continuous-energy'
    s.max_order = 5
    s.source = openmc.Source(space=openmc.stats.Point())
    s.output = {'summary': True, 'tallies': False, 'path': 'here'}
    s.verbosity = 7
    s.sourcepoint = {
        'batches': [50, 150, 500, 1000],
        'separate': True,
        'write': True,
        'overwrite': True
    }
    s.statepoint = {'batches': [50, 150, 500, 1000]}
    s.surf_source_read = {'path': 'surface_source_1.h5'}
    s.surf_source_write = {'surface_ids': [2], 'max_particles': 200}
    s.confidence_intervals = True
    s.ptables = True
    s.seed = 17
    s.survival_biasing = True
    s.cutoff = {
        'weight': 0.25,
        'weight_avg': 0.5,
        'energy_neutron': 1.0e-5,
        'energy_photon': 1000.0,
        'energy_electron': 1.0e-5,
        'energy_positron': 1.0e-5
    }
    mesh = openmc.RegularMesh()
    mesh.lower_left = (-10., -10., -10.)
    mesh.upper_right = (10., 10., 10.)
    mesh.dimension = (5, 5, 5)
    s.entropy_mesh = mesh
    s.trigger_active = True
    s.trigger_max_batches = 10000
    s.trigger_batch_interval = 50
    s.no_reduce = False
    s.tabular_legendre = {'enable': True, 'num_points': 50}
    s.temperature = {
        'default': 293.6,
        'method': 'interpolation',
        'multipole': True,
        'range': (200., 1000.)
    }
    s.trace = (10, 1, 20)
    s.track = [1, 1, 1, 2, 1, 1]
    s.ufs_mesh = mesh
    s.resonance_scattering = {
        'enable': True,
        'method': 'rvs',
        'energy_min': 1.0,
        'energy_max': 1000.0,
        'nuclides': ['U235', 'U238', 'Pu239']
    }
    s.volume_calculations = openmc.VolumeCalculation(domains=[openmc.Cell()],
                                                     samples=1000,
                                                     lower_left=(-10., -10.,
                                                                 -10.),
                                                     upper_right=(10., 10.,
                                                                  10.))
    s.create_fission_neutrons = True
    s.log_grid_bins = 2000
    s.photon_transport = False
    s.electron_treatment = 'led'
    s.write_initial_source = True

    # Make sure exporting XML works
    s.export_to_xml()

    # Generate settings from XML
    s = openmc.Settings.from_xml()
    assert s.run_mode == 'fixed source'
    assert s.batches == 1000
    assert s.generations_per_batch == 10
    assert s.inactive == 100
    assert s.particles == 1000000
    assert s.max_lost_particles == 5
    assert s.rel_max_lost_particles == 1e-4
    assert s.keff_trigger == {'type': 'std_dev', 'threshold': 0.001}
    assert s.energy_mode == 'continuous-energy'
    assert s.max_order == 5
    assert isinstance(s.source[0], openmc.Source)
    assert isinstance(s.source[0].space, openmc.stats.Point)
    assert s.output == {'summary': True, 'tallies': False, 'path': 'here'}
    assert s.verbosity == 7
    assert s.sourcepoint == {
        'batches': [50, 150, 500, 1000],
        'separate': True,
        'write': True,
        'overwrite': True
    }
    assert s.statepoint == {'batches': [50, 150, 500, 1000]}
    assert s.surf_source_read == {'path': 'surface_source_1.h5'}
    assert s.surf_source_write == {'surface_ids': [2], 'max_particles': 200}
    assert s.confidence_intervals
    assert s.ptables
    assert s.seed == 17
    assert s.survival_biasing
    assert s.cutoff == {
        'weight': 0.25,
        'weight_avg': 0.5,
        'energy_neutron': 1.0e-5,
        'energy_photon': 1000.0,
        'energy_electron': 1.0e-5,
        'energy_positron': 1.0e-5
    }
    assert isinstance(s.entropy_mesh, openmc.RegularMesh)
    assert s.entropy_mesh.lower_left == [-10., -10., -10.]
    assert s.entropy_mesh.upper_right == [10., 10., 10.]
    assert s.entropy_mesh.dimension == [5, 5, 5]
    assert s.trigger_active
    assert s.trigger_max_batches == 10000
    assert s.trigger_batch_interval == 50
    assert not s.no_reduce
    assert s.tabular_legendre == {'enable': True, 'num_points': 50}
    assert s.temperature == {
        'default': 293.6,
        'method': 'interpolation',
        'multipole': True,
        'range': [200., 1000.]
    }
    assert s.trace == [10, 1, 20]
    assert s.track == [1, 1, 1, 2, 1, 1]
    assert isinstance(s.ufs_mesh, openmc.RegularMesh)
    assert s.ufs_mesh.lower_left == [-10., -10., -10.]
    assert s.ufs_mesh.upper_right == [10., 10., 10.]
    assert s.ufs_mesh.dimension == [5, 5, 5]
    assert s.resonance_scattering == {
        'enable': True,
        'method': 'rvs',
        'energy_min': 1.0,
        'energy_max': 1000.0,
        'nuclides': ['U235', 'U238', 'Pu239']
    }
    assert s.create_fission_neutrons
    assert s.log_grid_bins == 2000
    assert not s.photon_transport
    assert s.electron_treatment == 'led'
    assert s.write_initial_source == True
    assert len(s.volume_calculations) == 1
    vol = s.volume_calculations[0]
    assert vol.domain_type == 'cell'
    assert len(vol.ids) == 1
    assert vol.samples == 1000
    assert vol.lower_left == (-10., -10., -10.)
    assert vol.upper_right == (10., 10., 10.)
コード例 #5
0
ファイル: test.py プロジェクト: yardasol/openmc
    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)
        if self.is_ce:
            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))
        if not self.is_ce:
            materials.cross_sections = 'mg_lib.h5'
        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),
            openmc.VolumeCalculation(list(root.cells.values()), 100),
            openmc.VolumeCalculation([water, fuel], 100, ll, ur),
            openmc.VolumeCalculation(list(root.cells.values()), 100)
        ]

        vol_calcs[3].set_trigger(self.exp_std_dev, 'std_dev')

        vol_calcs[4].set_trigger(self.exp_rel_err, 'rel_err')

        vol_calcs[5].set_trigger(self.exp_variance, 'variance')

        # Define settings
        settings = openmc.Settings()
        settings.run_mode = 'volume'
        if not self.is_ce:
            settings.energy_mode = 'multi-group'
        settings.volume_calculations = vol_calcs
        settings.export_to_xml()

        # Create the MGXS file if necessary
        if not self.is_ce:
            groups = openmc.mgxs.EnergyGroups(group_edges=[0., 20.e6])
            mg_xs_file = openmc.MGXSLibrary(groups)

            nu = [2.]
            fiss = [1.]
            capture = [1.]
            absorption_fissile = np.add(fiss, capture)
            absorption_other = capture
            scatter = np.array([[[1.]]])
            total_fissile = np.add(absorption_fissile,
                                   np.sum(scatter[:, :, 0], axis=1))
            total_other = np.add(absorption_other,
                                 np.sum(scatter[:, :, 0], axis=1))
            chi = [1.]

            for iso in ['H1', 'O16', 'B10', 'Mo99', 'U235']:
                mat = openmc.XSdata(iso, groups)
                mat.order = 0
                mat.atomic_weight_ratio = \
                    openmc.data.atomic_mass(iso) / openmc.data.NEUTRON_MASS
                mat.set_scatter_matrix(scatter)
                if iso == 'U235':
                    mat.set_nu_fission(np.multiply(nu, fiss))
                    mat.set_absorption(absorption_fissile)
                    mat.set_total(total_fissile)
                    mat.set_chi(chi)
                else:
                    mat.set_absorption(absorption_other)
                    mat.set_total(total_other)
                mg_xs_file.add_xsdata(mat)
            mg_xs_file.export_to_hdf5('mg_lib.h5')
コード例 #6
0
breeder_blanket_region = +first_wall_outer_surface & -breeder_blanket_outer_surface & +central_shield_outer_surface
breeder_blanket_cell = openmc.Cell(region=breeder_blanket_region)
breeder_blanket_cell.fill = breeder_material

universe = openmc.Universe(cells=[
    central_sol_cell, central_shield_cell, inner_vessel_cell, first_wall_cell,
    breeder_blanket_cell
])
geom = openmc.Geometry(universe)

geom.export_to_xml()

sphere = openmc.Sphere(r=10.0)
cell = openmc.Cell(region=-sphere)
vol_calc = openmc.VolumeCalculation(domains=[cell], samples=1000000)

# cell_vol_calc = openmc.VolumeCalculation([breeder_blanket_cell], 10000)

#SIMULATION SETTINGS#

# Instantiate a Settings object
sett = openmc.Settings()
batches = 2
sett.batches = batches
sett.inactive = 1
sett.particles = 50
sett.run_mode = 'fixed source'

# Create a DT point source
source = openmc.Source()
コード例 #7
0
ファイル: couple_openmc.py プロジェクト: drewejohnson/ONIX
	def _pre_run(self, root_cell):

		MC_input_path = self.MC_input_path
		pre_run_path = os.getcwd() +'/pre_run'
		try:
			shutil.rmtree(pre_run_path)
		except OSError:
			pass
		os.mkdir(pre_run_path)

		# Prepare the volume calculation
		#bounding_box = root_cell.bounding_box
		ll = self.bounding_box[0]
		ur = self.bounding_box[1]
		cell_dict = root_cell.get_all_cells()
		cell_list = utils.cell_dict_to_cell_list(cell_dict)
		cell_list.append(root_cell) # Add root_cell so that the total volume is calculated
		vol1 = openmc.VolumeCalculation(cell_list, 100000, lower_left = ll, upper_right = ur)

		settings = openmc.Settings()
		settings.volume_calculations = [vol1]
		settings.temperature = {'method':'interpolation'}
		settings.run_mode='volume'
		settings.export_to_xml(path = pre_run_path + '/settings.xml')

		# Copy the geometry and material file to the new dummy dir
		shutil.copyfile(MC_input_path + '/geometry.xml', pre_run_path + '/geometry.xml')
		shutil.copyfile(MC_input_path + '/materials.xml', pre_run_path + '/materials.xml')

		# By default, the openm_exec is set to 'openmc'
		# For some reasons, this does not work on the cluster (della)
		# On della, we need to explicitly define the absolute path to the bin we want to use
		# Right now a temporary path that depends on my installation is used

		#openmc.calculate_volumes(cwd = pre_run_path, openmc_exec='/tigress/jdtdl/openmc/py3-mpi-190324/bin/openmc')
		openmc.calculate_volumes(cwd = pre_run_path, openmc_exec=self.openmc_bin_path)
		#openmc.run()

		# Read and set initial nuclides dict
		self.set_init_nucl_dict(root_cell)

		# # Read each material object and add 1atm nuclides chosen by the user
		# if self.mode == 'no_const_lib':
		# 	self.add_zero_dens_nuclides(self.nucl_list_dict)

		self._set_initial_summary(pre_run_path)
		self._set_cross_sections_path(pre_run_path)
		# Read cross sections xml files, create MC_XS_nucl_list
		self.set_MC_XS_nucl_list()
		self.set_root_universe()
		root_cell_name = 'root cell' # 	need to be specified by the user at some point
		self._set_root_cell(root_cell_name)

		# Extract cells from summary, add 1 atm nuclides to their material
		self._change_cell_materials()

		# Read and distribute volumes to cells
		self.set_vol_to_cell(vol1, pre_run_path)

		# pdb.set_trace()

		shutil.rmtree(pre_run_path)
コード例 #8
0
first_wall_cell = openmc.Cell(region=first_wall_region)
first_wall_cell.fill = firstwall_material

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

universe = openmc.Universe(cells=[inner_vessel_cell, first_wall_cell, breeder_blanket_cell])
geom = openmc.Geometry(universe)
geom.export_to_xml()


# volume calculates for materials require a bounding box
lower_left = (-1000, -1000, -1000.)
upper_right = (1000, 1000, 1000.)
material_vol_calc = openmc.VolumeCalculation([firstwall_material, breeder_material], 100000, lower_left, upper_right)

cell_vol_calc = openmc.VolumeCalculation([inner_vessel_cell, first_wall_cell, breeder_blanket_cell], 100000)

settings = openmc.Settings()
settings.volume_calculations = [cell_vol_calc, material_vol_calc]
settings.run_mode = 'volume'
settings.export_to_xml()
openmc.run()

cell_vol_calc_results = openmc.VolumeCalculation.from_hdf5('volume_1.h5')


print('\ninner_vessel_cell volume', cell_vol_calc_results.volumes[1], 'cm3')
print('first_wall_cell volume', cell_vol_calc_results.volumes[2], 'cm3')
print('breeder_blanket_cell volume', cell_vol_calc_results.volumes[3], 'cm3\n')