示例#1
0
    def _build_inputs(self):
        # Instantiate a tally mesh
        mesh = openmc.Mesh(mesh_id=1)
        mesh.type = 'regular'
        mesh.dimension = [17, 17, 1]
        mesh.lower_left = [0.0, 0.0, 0.0]
        mesh.upper_right = [21.42, 21.42, 100.0]

        # Instantiate some tally filters
        energy_filter = openmc.Filter(type='energy', bins=[0.0, 20.0])
        energyout_filter = openmc.Filter(type='energyout', bins=[0.0, 20.0])
        mesh_filter = openmc.Filter()
        mesh_filter.mesh = mesh

        mat_filter = openmc.Filter(type='material', bins=[1, 2, 3])

        tally1 = openmc.Tally(tally_id=1)
        tally1.filters = [mesh_filter]
        tally1.scores = [
            'total', 'absorption', 'flux', 'fission', 'nu-fission'
        ]

        tally2 = openmc.Tally(tally_id=2)
        tally2.filters = [mat_filter, energy_filter, energyout_filter]
        tally2.scores = ['scatter', 'nu-scatter']

        self._input_set.tallies = openmc.Tallies([tally1, tally2])

        super(MGTalliesTestHarness, self)._build_inputs()
    def _build_inputs(self):

        # The summary.h5 file needs to be created to read in the tallies
        self._input_set.settings.output = {'summary': True}

        # Initialize the nuclides
        u235 = openmc.Nuclide('U-235')
        u238 = openmc.Nuclide('U-238')
        pu239 = openmc.Nuclide('Pu-239')

        # Initialize the filters
        energy_filter = openmc.Filter(type='energy',
                                      bins=[0.0, 0.253e-6, 1.0e-3, 1.0, 20.0])
        distrib_filter = openmc.Filter(type='distribcell', bins=[60])

        # Initialized the tallies
        tally = openmc.Tally(name='distribcell tally')
        tally.filters = [energy_filter, distrib_filter]
        tally.scores = ['nu-fission', 'total']
        tally.nuclides = [u235, u238, pu239]
        tallies_file = openmc.Tallies([tally])

        # Export tallies to file
        self._input_set.tallies = tallies_file
        super(TallyAggregationTestHarness, self)._build_inputs()
示例#3
0
    def _build_inputs(self):
        filt1 = openmc.Filter(type='mu', bins=(-1.0, -0.5, 0.0, 0.5, 1.0))
        tally1 = openmc.Tally(tally_id=1)
        tally1.add_filter(filt1)
        tally1.add_score('scatter')
        tally1.add_score('nu-scatter')

        filt2 = openmc.Filter(type='mu', bins=(5, ))
        tally2 = openmc.Tally(tally_id=2)
        tally2.add_filter(filt2)
        tally2.add_score('scatter')
        tally2.add_score('nu-scatter')

        mesh = openmc.Mesh(mesh_id=1)
        mesh.lower_left = [-182.07, -182.07]
        mesh.upper_right = [182.07, 182.07]
        mesh.dimension = [2, 2]
        filt_mesh = openmc.Filter(type='mesh', bins=(1, ))
        tally3 = openmc.Tally(tally_id=3)
        tally3.add_filter(filt2)
        tally3.add_filter(filt_mesh)
        tally3.add_score('scatter')
        tally3.add_score('nu-scatter')

        self._input_set.tallies = openmc.TalliesFile()
        self._input_set.tallies.add_tally(tally1)
        self._input_set.tallies.add_tally(tally2)
        self._input_set.tallies.add_tally(tally3)
        self._input_set.tallies.add_mesh(mesh)

        super(FilterMuTestHarness, self)._build_inputs()
    def _build_inputs(self):
        filt1 = openmc.Filter(type='energy',
                              bins=(0.0, 0.253e-6, 1.0e-3, 1.0, 20.0))
        filt2 = openmc.Filter(type='energyout',
                              bins=(0.0, 0.253e-6, 1.0e-3, 1.0, 20.0))
        tally = openmc.Tally(tally_id=1)
        tally.add_filter(filt1)
        tally.add_filter(filt2)
        tally.add_score('scatter')
        tally.add_score('nu-fission')
        self._input_set.tallies = openmc.TalliesFile()
        self._input_set.tallies.add_tally(tally)

        super(FilterGroupTransferTestHarness, self)._build_inputs()
示例#5
0
    def _build_inputs(self):
        filt = openmc.Filter(type='universe', bins=(1, 2, 3, 4))
        tally = openmc.Tally(tally_id=1)
        tally.add_filter(filt)
        tally.add_score('total')
        self._input_set.tallies = openmc.TalliesFile()
        self._input_set.tallies.add_tally(tally)

        super(FilterUniverseTestHarness, self)._build_inputs()
示例#6
0
    def generate_tally_xml(self, settings):

        import copy

        """ Generates tally.xml.

        Using information from self.depletion_chain as well as the nuclides
        currently in the problem, this function automatically generates a
        tally.xml for the simulation.
        """
        chain = self.chain

        # ----------------------------------------------------------------------
        # Create tallies for depleting regions
        tally_ind = 1
        cell_filter_dep = openmc.Filter(type='cell', bins=self.burn_list)
        tallies_file = openmc.Tallies()

        nuc_superset = set()

        for cell in self.burn_list:
            for key in self.number_density[cell]:
                # Check if in participating nuclides
                if key in self.participating_nuclides:
                    nuc_superset.add(key)

        # For each reaction in the chain, for each nuclide, and for each
        # cell, make a tally
        tally_dep = openmc.Tally(tally_id=tally_ind)
        for key in nuc_superset:
            if key in chain.nuclide_dict:
                tally_dep.add_nuclide(key)

        tally_dep.add_filter(cell_filter_dep)

        if (settings.fet_order == None):
            for reaction in chain.react_to_ind:
                tally_dep.add_score(reaction)
            tallies_file.add_tally(tally_dep)
        else:
            # Add the geomtric norm to tally if we are doing FETs
            # TODO we need geometry constants in another PYTHON file for easy use
            tally_dep.add_geom_norm(0.4096)
            tally_dep.estimator = 'collision'
            # The current implementation does not allow multiple score pins for FETs
            # Therefore, we need a unique tally for each reaction
            fet_tallies = []
            for reaction in chain.react_to_ind:
                fet_tallies.append(copy.deepcopy(tally_dep))
                fet_score_name = 'micro-' + reaction + '-z' + str(settings.fet_order)
                fet_tallies[-1].id = tally_ind
                fet_tallies[-1].add_score(fet_score_name)
                tally_ind += 1

            [tallies_file.add_tally(t) for t in fet_tallies]

        tallies_file.export_to_xml()
示例#7
0
    def _build_inputs(self):
        filt = openmc.Filter(type='cellborn', bins=(10, 21, 22, 23))
        tally = openmc.Tally(tally_id=1)
        tally.add_filter(filt)
        tally.add_score('total')
        self._input_set.tallies = openmc.TalliesFile()
        self._input_set.tallies.add_tally(tally)

        super(FilterCellbornTestHarness, self)._build_inputs()
    def _build_inputs(self):
        filt = openmc.Filter(type='delayedgroup', bins=(1, 2, 3, 4, 5, 6))
        tally = openmc.Tally(tally_id=1)
        tally.add_filter(filt)
        tally.add_score('delayed-nu-fission')
        self._input_set.tallies = openmc.TalliesFile()
        self._input_set.tallies.add_tally(tally)

        super(FilterDelayedgroupTestHarness, self)._build_inputs()
    def _build_inputs(self):

        # The summary.h5 file needs to be created to read in the tallies
        self._input_set.settings.output = {'summary': True}

        # Initialize the tallies file
        tallies_file = openmc.Tallies()

        # Initialize the nuclides
        u235 = openmc.Nuclide('U-235')
        u238 = openmc.Nuclide('U-238')
        pu239 = openmc.Nuclide('Pu-239')

        # Initialize Mesh
        mesh = openmc.Mesh(mesh_id=1)
        mesh.type = 'regular'
        mesh.dimension = [2, 2, 2]
        mesh.lower_left = [-160.0, -160.0, -183.0]
        mesh.upper_right = [160.0, 160.0, 183.0]

        # Initialize the filters
        energy_filter = openmc.Filter(type='energy',
                                      bins=(0.0, 0.253e-6, 1.0e-3, 1.0, 20.0))
        material_filter = openmc.Filter(type='material', bins=(1, 3))
        distrib_filter = openmc.Filter(type='distribcell', bins=(60))
        mesh_filter = openmc.Filter(type='mesh')
        mesh_filter.mesh = mesh

        # Initialized the tallies
        tally = openmc.Tally(name='tally 1')
        tally.filters = [material_filter, energy_filter, distrib_filter]
        tally.scores = ['nu-fission', 'total']
        tally.nuclides = [u235, pu239]
        tallies_file.append(tally)

        tally = openmc.Tally(name='tally 2')
        tally.filters = [energy_filter, mesh_filter]
        tally.scores = ['total', 'fission']
        tally.nuclides = [u238, u235]
        tallies_file.append(tally)

        # Export tallies to file
        self._input_set.tallies = tallies_file
        super(TallyArithmeticTestHarness, self)._build_inputs()
示例#10
0
    def _build_inputs(self):
        filt = openmc.Filter(type='energyout',
                             bins=(0.0, 0.253e-6, 1.0e-3, 1.0, 20.0))
        tally = openmc.Tally(tally_id=1)
        tally.add_filter(filt)
        tally.add_score('scatter')
        self._input_set.tallies = openmc.TalliesFile()
        self._input_set.tallies.add_tally(tally)

        super(FilterEnergyoutTestHarness, self)._build_inputs()
示例#11
0
    def _build_inputs(self):
        filt = openmc.Filter(type='cell', bins=(21, 27))
        tallies = [openmc.Tally(tally_id=i) for i in range(1, 3)]
        [t.add_filter(filt) for t in tallies]
        [t.add_score('events') for t in tallies]
        tallies[0].estimator = 'tracklength'
        tallies[1].estimator = 'analog'
        self._input_set.tallies = openmc.TalliesFile()
        [self._input_set.tallies.add_tally(t) for t in tallies]

        super(ScoreEventsTestHarness, self)._build_inputs()
示例#12
0
    def _build_inputs(self):
        filt = openmc.Filter(type='cell', bins=(21, 22, 23, 27))
        tallies = [openmc.Tally(tally_id=i) for i in range(1, 4)]
        [t.add_filter(filt) for t in tallies]
        [t.add_score('kappa-fission') for t in tallies]
        tallies[0].estimator = 'tracklength'
        tallies[1].estimator = 'analog'
        tallies[2].estimator = 'collision'
        self._input_set.tallies = openmc.TalliesFile()
        [self._input_set.tallies.add_tally(t) for t in tallies]

        super(ScoreKappaFissionTestHarness, self)._build_inputs()
示例#13
0
    def _build_inputs(self):
        filt = openmc.Filter(type='cell', bins=(21, 22, 23))
        t = openmc.Tally(tally_id=1)
        t.add_filter(filt)
        t.add_score('scatter')
        t.add_score('scatter-1')
        t.add_score('scatter-2')
        t.add_score('scatter-3')
        t.add_score('scatter-4')
        self._input_set.tallies = openmc.TalliesFile()
        self._input_set.tallies.add_tally(t)

        super(ScoreScatterNTestHarness, self)._build_inputs()
示例#14
0
    def _build_inputs(self):
        filt = openmc.Filter(type='cell', bins=(21, 22, 23, 27, 28, 29))
        tallies = [openmc.Tally(tally_id=i) for i in range(1, 5)]
        [t.add_filter(filt) for t in tallies]
        tallies[0].add_score('flux')
        [t.add_score('flux-y5') for t in tallies[1:]]
        tallies[1].estimator = 'tracklength'
        tallies[2].estimator = 'analog'
        tallies[3].estimator = 'collision'
        self._input_set.tallies = openmc.TalliesFile()
        [self._input_set.tallies.add_tally(t) for t in tallies]

        super(ScoreFluxYnTestHarness, self)._build_inputs()
示例#15
0
    def _build_inputs(self):
        filt1 = openmc.Filter(type='polar',
                              bins=(0.0, 0.6283, 1.2566, 1.8850, 2.5132,
                                    3.1416))
        tally1 = openmc.Tally(tally_id=1)
        tally1.add_filter(filt1)
        tally1.add_score('flux')
        tally1.estimator = 'tracklength'

        tally2 = openmc.Tally(tally_id=2)
        tally2.add_filter(filt1)
        tally2.add_score('flux')
        tally2.estimator = 'analog'

        filt3 = openmc.Filter(type='polar', bins=(5, ))
        tally3 = openmc.Tally(tally_id=3)
        tally3.add_filter(filt3)
        tally3.add_score('flux')
        tally3.estimator = 'tracklength'

        mesh = openmc.Mesh(mesh_id=1)
        mesh.lower_left = [-182.07, -182.07]
        mesh.upper_right = [182.07, 182.07]
        mesh.dimension = [2, 2]
        filt_mesh = openmc.Filter(type='mesh', bins=(1, ))
        tally4 = openmc.Tally(tally_id=4)
        tally4.add_filter(filt3)
        tally4.add_filter(filt_mesh)
        tally4.add_score('flux')
        tally4.estimator = 'tracklength'

        self._input_set.tallies = openmc.TalliesFile()
        self._input_set.tallies.add_tally(tally1)
        self._input_set.tallies.add_tally(tally2)
        self._input_set.tallies.add_tally(tally3)
        self._input_set.tallies.add_tally(tally4)
        self._input_set.tallies.add_mesh(mesh)

        super(FilterPolarTestHarness, self)._build_inputs()
示例#16
0
    def _build_inputs(self):
        filt = openmc.Filter(type='cell', bins=(21, ))
        t1 = openmc.Tally(tally_id=1)
        t1.add_filter(filt)
        t1.add_score('scatter-0')
        t1.estimator = 'analog'
        t2 = openmc.Tally(tally_id=2)
        t2.add_filter(filt)
        t2.add_score('scatter-y4')
        self._input_set.tallies = openmc.TalliesFile()
        self._input_set.tallies.add_tally(t1)
        self._input_set.tallies.add_tally(t2)

        super(ScoreScatterYNTestHarness, self)._build_inputs()
示例#17
0
    def _build_inputs(self):
        filt = openmc.Filter(type='cell', bins=(10, 21, 22, 23))
        t = openmc.Tally(tally_id=1)
        t.add_filter(filt)
        t.add_score('nu-scatter')
        self._input_set.tallies = openmc.TalliesFile()
        self._input_set.tallies.add_tally(t)

        self._input_set.build_default_materials_and_geometry()
        self._input_set.build_default_settings()

        self._input_set.settings.inactive = 0

        self._input_set.export()
示例#18
0
    def _build_inputs(self):
        filt = openmc.Filter(type='cell', bins=(10, 21, 22, 23))
        tallies = [openmc.Tally(tally_id=i) for i in range(1, 5)]
        [t.add_filter(filt) for t in tallies]
        tallies[0].add_score('total')
        [t.add_score('total-y4') for t in tallies[1:]]
        [t.add_nuclide('U-235') for t in tallies[1:]]
        [t.add_nuclide('total') for t in tallies[1:]]
        tallies[1].estimator = 'tracklength'
        tallies[2].estimator = 'analog'
        tallies[3].estimator = 'collision'
        self._input_set.tallies = openmc.TalliesFile()
        [self._input_set.tallies.add_tally(t) for t in tallies]

        super(ScoreTotalYNTestHarness, self)._build_inputs()
示例#19
0
    def _build_inputs(self):
        filt = openmc.Filter(type='cell', bins=(21, ))
        t1 = openmc.Tally(tally_id=1)
        t1.add_filter(filt)
        t1.add_score('nu-scatter-0')
        t2 = openmc.Tally(tally_id=2)
        t2.add_filter(filt)
        t2.add_score('nu-scatter-y3')
        self._input_set.tallies = openmc.TalliesFile()
        self._input_set.tallies.add_tally(t1)
        self._input_set.tallies.add_tally(t2)

        self._input_set.build_default_materials_and_geometry()
        self._input_set.build_default_settings()

        self._input_set.settings.inactive = 0

        self._input_set.export()
示例#20
0
plot_xy.filename = 'plot_xy'
plot_xy.origin = [0, 0, 0]
plot_xy.width = [6, 6]
plot_xy.pixels = [400, 400]
plot_xy.color = 'mat'

plot_yz = openmc.Plot(plot_id=2)
plot_yz.filename = 'plot_yz'
plot_yz.basis = 'yz'
plot_yz.origin = [0, 0, 0]
plot_yz.width = [8, 8]
plot_yz.pixels = [400, 400]
plot_yz.color = 'mat'

# Instantiate a Plots collection, add plots, and export to XML
plot_file = openmc.Plots((plot_xy, plot_yz))
plot_file.export_to_xml()

###############################################################################
#                   Exporting to OpenMC tallies.xml File
###############################################################################

# Instantiate a distribcell Tally
tally = openmc.Tally(tally_id=1)
tally.filters = [openmc.Filter(type='distribcell', bins=[cell2.id])]
tally.scores = ['total']

# Instantiate a Tallies collection and export to XML
tallies_file = openmc.Tallies([tally])
tallies_file.export_to_xml()
示例#21
0
# Instantiate a PlotsFile, add Plot, and export to XML
plot_file = openmc.PlotsFile()
plot_file.add_plot(plot)
plot_file.export_to_xml()

###############################################################################
#                   Exporting to OpenMC tallies.xml File
###############################################################################

# Instantiate a tally mesh
mesh = openmc.Mesh(mesh_id=1)
mesh.type = 'regular'
mesh.dimension = [4, 4]
mesh.lower_left = [-2, -2]
mesh.width = [1, 1]

# Instantiate tally Filter
mesh_filter = openmc.Filter()
mesh_filter.mesh = mesh

# Instantiate the Tally
tally = openmc.Tally(tally_id=1)
tally.add_filter(mesh_filter)
tally.add_score('total')

# Instantiate a TalliesFile, register Tally/Mesh, and export to XML
tallies_file = openmc.TalliesFile()
tallies_file.add_mesh(mesh)
tallies_file.add_tally(tally)
tallies_file.export_to_xml()
plots = openmc.Plots([plot])
plots.export_to_xml()

###############################################################################
#                   Create Mesh Tallies for Verification
###############################################################################

# Instantiate a tally Mesh
mesh = openmc.Mesh(name='assembly mesh')
mesh.type = 'regular'
mesh.dimension = assembly.dimension
mesh.lower_left = assembly.lower_left
mesh.width = assembly.pitch

# Instantiate mesh Filter
mesh_filter = openmc.Filter()
mesh_filter.mesh = mesh

# Fission rate mesh Tally
mesh_fiss = openmc.Tally(name='mesh fission')
mesh_fiss.filters = [mesh_filter]
mesh_fiss.scores = ['fission']
mesh_fiss.nuclides = ['U-235', 'U-238']

# Fine energy flux Tally
flux = openmc.Tally(name='flux')
energies = np.logspace(np.log10(1E-8), np.log10(8.), 1000)
flux.filters = [openmc.Filter(type='energy', bins=energies)]
flux.scores = ['flux']

# U-238 capture and fission distribcell Tally
示例#23
0
settings_file.source = openmc.source.Source(space=uniform_dist)

settings_file.export_to_xml()

###############################################################################
#                   Exporting to OpenMC tallies.xml file
###############################################################################

# Instantiate a tally mesh
mesh = openmc.Mesh(mesh_id=1)
mesh.type = 'regular'
mesh.dimension = [100, 100, 1]
mesh.lower_left = [-0.63, -0.63, -1.e50]
mesh.upper_right = [0.63, 0.63, 1.e50]

# Instantiate some tally Filters
energy_filter = openmc.Filter(type='energy',
                              bins=[1E-11, 0.0635E-6, 10.0E-6, 1.0E-4, 1.0E-3,
                                    0.5, 1.0, 20.0])
mesh_filter = openmc.Filter()
mesh_filter.mesh = mesh

# Instantiate the Tally
tally = openmc.Tally(tally_id=1, name='tally 1')
tally.filters = [energy_filter, mesh_filter]
tally.scores = ['flux', 'fission', 'nu-fission']

# Instantiate a Tallies collection, register all Tallies, and export to XML
tallies_file = openmc.Tallies([tally])
tallies_file.export_to_xml()
示例#24
0
settings_file.entropy_dimension = [10, 10, 1]
settings_file.export_to_xml()

###############################################################################
#                   Exporting to OpenMC tallies.xml File
###############################################################################

# Instantiate a tally mesh
mesh = openmc.Mesh(mesh_id=1)
mesh.type = 'rectangular'
mesh.dimension = [100, 100, 1]
mesh.lower_left = [-0.62992, -0.62992, -1.e50]
mesh.upper_right = [0.62992, 0.62992, 1.e50]

# Instantiate some tally Filters
energy_filter = openmc.Filter(type='energy', bins=[0., 4.e-6, 20.])
mesh_filter = openmc.Filter()
mesh_filter.mesh = mesh

# Instantiate the Tally
tally = openmc.Tally(tally_id=1, name='tally 1')
tally.add_filter(energy_filter)
tally.add_filter(mesh_filter)
tally.add_score('flux')
tally.add_score('fission')
tally.add_score('nu-fission')

# Instantiate a TalliesFile, register all Tallies, and export to XML
tallies_file = openmc.TalliesFile()
tallies_file.add_mesh(mesh)
tallies_file.add_tally(tally)
示例#25
0
settings_file.inactive = inactive
settings_file.particles = particles

# Create an initial uniform spatial source distribution over fissionable zones
bounds = [-4., -4., -4., 4., 4., 4.]
uniform_dist = openmc.stats.Box(bounds[:3], bounds[3:], only_fissionable=True)
settings_file.source = openmc.source.Source(space=uniform_dist)

settings_file.export_to_xml()

###############################################################################
#                   Exporting to OpenMC tallies.xml file
###############################################################################

# Instantiate some tally Filters
cell_filter = openmc.Filter(type='cell', bins=100)
energy_filter = openmc.Filter(type='energy', bins=[0., 20.])
energyout_filter = openmc.Filter(type='energyout', bins=[0., 20.])

# Instantiate the first Tally
first_tally = openmc.Tally(tally_id=1, name='first tally')
first_tally.filters = [cell_filter]
scores = [
    'total', 'scatter', 'nu-scatter', 'absorption', 'fission', 'nu-fission'
]
first_tally.scores = scores

# Instantiate the second Tally
second_tally = openmc.Tally(tally_id=2, name='second tally')
second_tally.filters = [cell_filter, energy_filter]
second_tally.scores = scores
示例#26
0
    def _read_tallies(self):
        # Initialize dictionaries for the Tallies
        # Keys     - Tally IDs
        # Values   - Tally objects
        self.tallies = {}

        # Read the number of tallies
        if 'tallies' not in self._f:
            self.n_tallies = 0
            return

        self.n_tallies = self._f['tallies/n_tallies'].value

        # OpenMC Tally keys
        all_keys = self._f['tallies/'].keys()
        tally_keys = [key for key in all_keys if 'tally' in key]

        base = 'tallies/tally '

        # Iterate over all Tallies
        for tally_key in tally_keys:
            tally_id = int(tally_key.strip('tally '))
            subbase = '{0}{1}'.format(base, tally_id)

            # Read Tally name metadata
            tally_name = self._f['{0}/name'.format(subbase)].value.decode()

            # Create Tally object and assign basic properties
            tally = openmc.Tally(tally_id, tally_name)

            # Read scattering moment order strings (e.g., P3, Y1,2, etc.)
            moments = self._f['{0}/moment_orders'.format(subbase)].value

            # Read score metadata
            scores = self._f['{0}/score_bins'.format(subbase)].value
            for j, score in enumerate(scores):
                score = score.decode()

                # If this is a moment, use generic moment order
                pattern = r'-n$|-pn$|-yn$'
                score = re.sub(pattern, '-' + moments[j].decode(), score)
                tally.scores.append(score)

            # Read filter metadata
            num_filters = self._f['{0}/n_filters'.format(subbase)].value

            # Initialize all Filters
            for j in range(1, num_filters + 1):
                subsubbase = '{0}/filter {1}'.format(subbase, j)

                # Read filter type (e.g., "cell", "energy", etc.)
                filter_type = self._f['{0}/type'.format(
                    subsubbase)].value.decode()

                # Read the filter bins
                num_bins = self._f['{0}/n_bins'.format(subsubbase)].value
                bins = self._f['{0}/bins'.format(subsubbase)][...]

                # Create Filter object
                new_filter = openmc.Filter(filter_type, bins)
                new_filter.num_bins = num_bins

                # Read in distribcell paths
                if filter_type == 'distribcell':
                    paths = self._f['{0}/paths'.format(subsubbase)][...]
                    paths = [str(path.decode()) for path in paths]
                    new_filter.distribcell_paths = paths

                # Add Filter to the Tally
                tally.filters.append(new_filter)

            # Add Tally to the global dictionary of all Tallies
            self.tallies[tally_id] = tally
    def _build_inputs(self):
        """Build an axis-asymmetric lattice of fuel assemblies"""

        # Build full core geometry from underlying input set
        self._input_set.build_default_materials_and_geometry()

        # Extract universes encapsulating fuel and water assemblies
        geometry = self._input_set.geometry
        water = geometry.get_universes_by_name('water assembly (hot)')[0]
        fuel = geometry.get_universes_by_name('fuel assembly (hot)')[0]

        # Construct a 3x3 lattice of fuel assemblies
        core_lat = openmc.RectLattice(name='3x3 Core Lattice', lattice_id=202)
        core_lat.lower_left = (-32.13, -32.13)
        core_lat.pitch = (21.42, 21.42)
        core_lat.universes = [[fuel, water, water], [fuel, fuel, fuel],
                              [water, water, water]]

        # Create bounding surfaces
        min_x = openmc.XPlane(x0=-32.13, boundary_type='reflective')
        max_x = openmc.XPlane(x0=+32.13, boundary_type='reflective')
        min_y = openmc.YPlane(y0=-32.13, boundary_type='reflective')
        max_y = openmc.YPlane(y0=+32.13, boundary_type='reflective')
        min_z = openmc.ZPlane(z0=0, boundary_type='reflective')
        max_z = openmc.ZPlane(z0=+32.13, boundary_type='reflective')

        # Define root universe
        root_univ = openmc.Universe(universe_id=0, name='root universe')
        root_cell = openmc.Cell(cell_id=1)
        root_cell.region = +min_x & -max_x & +min_y & -max_y & +min_z & -max_z
        root_cell.fill = core_lat
        root_univ.add_cell(root_cell)

        # Over-ride geometry in the input set with this 3x3 lattice
        self._input_set.geometry.root_universe = root_univ

        # Initialize a "distribcell" filter for the fuel pin cell
        distrib_filter = openmc.Filter(type='distribcell', bins=[27])

        # Initialize the tallies
        tally = openmc.Tally(name='distribcell tally', tally_id=27)
        tally.filters.append(distrib_filter)
        tally.scores.append('nu-fission')

        # Initialize the tallies file
        tallies_file = openmc.Tallies([tally])

        # Assign the tallies file to the input set
        self._input_set.tallies = tallies_file

        # Build default settings
        self._input_set.build_default_settings()

        # Specify summary output and correct source sampling box
        source = openmc.Source(
            space=openmc.stats.Box([-32, -32, 0], [32, 32, 32]))
        source.space.only_fissionable = True
        self._input_set.settings.source = source
        self._input_set.settings.output = {'summary': True}

        # Write input XML files
        self._input_set.export()
    def _build_inputs(self):

        # The summary.h5 file needs to be created to read in the tallies
        self._input_set.settings.output = {'summary': True}

        # Initialize the tallies file
        tallies_file = openmc.Tallies()

        # Define nuclides and scores to add to both tallies
        self.nuclides = ['U-235', 'U-238']
        self.scores = ['fission', 'nu-fission']

        # Define filters for energy and spatial domain

        low_energy = openmc.Filter(type='energy', bins=[0., 0.625e-6])
        high_energy = openmc.Filter(type='energy', bins=[0.625e-6, 20.])
        merged_energies = low_energy.merge(high_energy)

        cell_21 = openmc.Filter(type='cell', bins=[21])
        cell_27 = openmc.Filter(type='cell', bins=[27])
        distribcell_filter = openmc.Filter(type='distribcell', bins=[21])

        mesh = openmc.Mesh(name='mesh')
        mesh.type = 'regular'
        mesh.dimension = [2, 2]
        mesh.lower_left = [-50., -50.]
        mesh.upper_right = [+50., +50.]
        mesh_filter = openmc.Filter(type='mesh', bins=[mesh.id])
        mesh_filter.mesh = mesh

        self.cell_filters = [cell_21, cell_27]
        self.energy_filters = [low_energy, high_energy]

        # Initialize cell tallies with filters, nuclides and scores
        tallies = []
        for energy_filter in self.energy_filters:
            for cell_filter in self.cell_filters:
                for nuclide in self.nuclides:
                    for score in self.scores:
                        tally = openmc.Tally()
                        tally.estimator = 'tracklength'
                        tally.add_score(score)
                        tally.add_nuclide(nuclide)
                        tally.add_filter(cell_filter)
                        tally.add_filter(energy_filter)
                        tallies.append(tally)

        # Merge all cell tallies together
        while len(tallies) != 1:
            halfway = int(len(tallies) / 2)
            zip_split = zip(tallies[:halfway], tallies[halfway:])
            tallies = list(map(lambda xy: xy[0].merge(xy[1]), zip_split))

        # Specify a name for the tally
        tallies[0].name = 'cell tally'

        # Initialize a distribcell tally
        distribcell_tally = openmc.Tally(name='distribcell tally')
        distribcell_tally.estimator = 'tracklength'
        distribcell_tally.add_filter(distribcell_filter)
        distribcell_tally.add_filter(merged_energies)
        for score in self.scores:
            distribcell_tally.add_score(score)
        for nuclide in self.nuclides:
            distribcell_tally.add_nuclide(nuclide)

        mesh_tally = openmc.Tally(name='mesh tally')
        mesh_tally.estimator = 'tracklength'
        mesh_tally.filters = [mesh_filter, merged_energies]
        mesh_tally.scores = self.scores
        mesh_tally.nuclides = self.nuclides

        # Add tallies to a Tallies object
        tallies_file = openmc.Tallies(
            (tallies[0], distribcell_tally, mesh_tally))

        # Export tallies to file
        self._input_set.tallies = tallies_file
        super(TallySliceMergeTestHarness, self)._build_inputs()
示例#29
0
plot_xy.pixels = [400, 400]
plot_xy.color = 'mat'

plot_yz = openmc.Plot(plot_id=2)
plot_yz.filename = 'plot_yz'
plot_yz.basis = 'yz'
plot_yz.origin = [0, 0, 0]
plot_yz.width = [8, 8]
plot_yz.pixels = [400, 400]
plot_yz.color = 'mat'

# Instantiate a PlotsFile, add Plot, and export to XML
plot_file = openmc.PlotsFile()
plot_file.add_plot(plot_xy)
plot_file.add_plot(plot_yz)
plot_file.export_to_xml()

###############################################################################
#                   Exporting to OpenMC tallies.xml File
###############################################################################

# Instantiate a distribcell Tally
tally = openmc.Tally(tally_id=1)
tally.add_filter(openmc.Filter(type='distribcell', bins=[cell2.id]))
tally.add_score('total')

# Instantiate a TalliesFile, register Tally/Mesh, and export to XML
tallies_file = openmc.TalliesFile()
tallies_file.add_tally(tally)
tallies_file.export_to_xml()
示例#30
0
    def _read_tallies(self):
        # Initialize dictionaries for the Tallies
        # Keys     - Tally IDs
        # Values   - Tally objects
        self.tallies = {}

        # Read the number of tallies
        if 'tallies' not in self._f:
            self.n_tallies = 0
            return

        self.n_tallies = self._f['tallies/n_tallies'].value

        # OpenMC Tally keys
        all_keys = self._f['tallies/'].keys()
        tally_keys = [key for key in all_keys if 'tally' in key]

        base = 'tallies/tally '

        # Iterate over all Tallies
        for tally_key in tally_keys:
            tally_id = int(tally_key.strip('tally '))
            subbase = '{0}{1}'.format(base, tally_id)

            # Read Tally name metadata
            tally_name = self._f['{0}/name'.format(subbase)].value.decode()

            # Create Tally object and assign basic properties
            tally = openmc.Tally(tally_id, tally_name)

            # Read score metadata
            scores = self._f['{0}/score_bins'.format(subbase)].value
            for score in scores:
                tally.add_score(score.decode())
            num_score_bins = self._f['{0}/n_score_bins'.format(subbase)][...]
            tally.num_score_bins = num_score_bins

            # Read filter metadata
            num_filters = self._f['{0}/n_filters'.format(subbase)].value

            # Initialize all Filters
            for j in range(1, num_filters + 1):
                subsubbase = '{0}/filter {1}'.format(subbase, j)

                # Read filter type (e.g., "cell", "energy", etc.)
                filter_type = self._f['{0}/type'.format(
                    subsubbase)].value.decode()

                # Read the filter bins
                num_bins = self._f['{0}/n_bins'.format(subsubbase)].value
                bins = self._f['{0}/bins'.format(subsubbase)][...]

                # Create Filter object
                filter = openmc.Filter(filter_type, bins)
                filter.num_bins = num_bins

                # Add Filter to the Tally
                tally.add_filter(filter)

            # Add Tally to the global dictionary of all Tallies
            self.tallies[tally_id] = tally