OpenMC/tests/regression_tests/tally_aggregation/test.py
2018-02-06 13:14:17 -05:00

66 lines
2.2 KiB
Python

import hashlib
import openmc
from tests.testing_harness import PyAPITestHarness
class TallyAggregationTestHarness(PyAPITestHarness):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Initialize the filters
energy_filter = openmc.EnergyFilter([0.0, 0.253, 1.0e3, 1.0e6, 20.0e6])
distrib_filter = openmc.DistribcellFilter(60)
# Initialized the tallies
tally = openmc.Tally(name='distribcell tally')
tally.filters = [energy_filter, distrib_filter]
tally.scores = ['nu-fission', 'total']
tally.nuclides = ['U234', 'U235', 'U238']
self._model.tallies.append(tally)
def _get_results(self, hash_output=True):
"""Digest info in the statepoint and return as a string."""
# Read the statepoint file.
sp = openmc.StatePoint(self._sp_name)
# Extract the tally of interest
tally = sp.get_tally(name='distribcell tally')
# Perform tally aggregations across filter bins, nuclides and scores
outstr = ''
# Sum across all energy filter bins
tally_sum = tally.summation(filter_type=openmc.EnergyFilter)
outstr += ', '.join(map(str, tally_sum.mean))
outstr += ', '.join(map(str, tally_sum.std_dev))
# Sum across all distribcell filter bins
tally_sum = tally.summation(filter_type=openmc.DistribcellFilter)
outstr += ', '.join(map(str, tally_sum.mean))
outstr += ', '.join(map(str, tally_sum.std_dev))
# Sum across all nuclides
tally_sum = tally.summation(nuclides=['U234', 'U235', 'U238'])
outstr += ', '.join(map(str, tally_sum.mean))
outstr += ', '.join(map(str, tally_sum.std_dev))
# Sum across all scores
tally_sum = tally.summation(scores=['nu-fission', 'total'])
outstr += ', '.join(map(str, tally_sum.mean))
outstr += ', '.join(map(str, tally_sum.std_dev))
# Hash the results if necessary
if hash_output:
sha512 = hashlib.sha512()
sha512.update(outstr.encode('utf-8'))
outstr = sha512.hexdigest()
return outstr
def test_tally_aggregation():
harness = TallyAggregationTestHarness('statepoint.10.h5')
harness.main()