mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 21:55:41 -04:00
Added new tally aggregation (summation) test
This commit is contained in:
parent
c0220b24e7
commit
bc0b826249
6 changed files with 103 additions and 4 deletions
|
|
@ -405,5 +405,5 @@ class AggregateFilter(object):
|
|||
aggregate_bin_array = np.repeat(aggregate_bin_array, datasize)
|
||||
|
||||
# Construct Pandas DataFrame for the AggregateFilter
|
||||
df = pd.DataFrame({self.aggregate_filter.type : aggregate_bin_array})
|
||||
df = pd.DataFrame({self.aggregate_filter.type: aggregate_bin_array})
|
||||
return df
|
||||
|
|
@ -2873,7 +2873,7 @@ class Tally(object):
|
|||
# Sum across any scores specified by the user
|
||||
if len(scores) != 0:
|
||||
score_bins = [self.get_score_index(score) for score in scores]
|
||||
axis_index = self.num_filters + self.num_nuclides
|
||||
axis_index = self.num_filters + 1
|
||||
mean = np.take(mean, indices=score_bins, axis=axis_index)
|
||||
std_dev = np.take(std_dev, indices=score_bins, axis=axis_index)
|
||||
mean = np.sum(mean, axis=axis_index, keepdims=True)
|
||||
|
|
|
|||
1
tests/test_tally_aggregation/inputs_true.dat
Normal file
1
tests/test_tally_aggregation/inputs_true.dat
Normal file
|
|
@ -0,0 +1 @@
|
|||
530a5e969901e153531f74aed46246b1e8783a0e2f347e472f7554c9970152f45d85499f17d7df9c35c74fed6f78d449aa70bf0c1f8947cd34d3a829483a0055
|
||||
1
tests/test_tally_aggregation/results_true.dat
Normal file
1
tests/test_tally_aggregation/results_true.dat
Normal file
|
|
@ -0,0 +1 @@
|
|||
ba8bfe764fcc0484a4fdab8fdc4ff8ad0e4a98b1ff33e8687899c8cc6bf80cb28b3a59aeaec84bd74681b8b5f19f714292ccaa9c9d4ba852b2cc29872f612e10
|
||||
99
tests/test_tally_aggregation/test_tally_aggregation.py
Normal file
99
tests/test_tally_aggregation/test_tally_aggregation.py
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import sys
|
||||
import glob
|
||||
import hashlib
|
||||
sys.path.insert(0, os.pardir)
|
||||
from testing_harness import PyAPITestHarness
|
||||
import openmc
|
||||
|
||||
|
||||
class TallyAggregationTestHarness(PyAPITestHarness):
|
||||
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.TalliesFile()
|
||||
|
||||
# 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.add_filter(energy_filter)
|
||||
tally.add_filter(distrib_filter)
|
||||
tally.add_score('nu-fission')
|
||||
tally.add_score('total')
|
||||
tally.add_nuclide(u235)
|
||||
tally.add_nuclide(u238)
|
||||
tally.add_nuclide(pu239)
|
||||
tallies_file.add_tally(tally)
|
||||
|
||||
# Export tallies to file
|
||||
self._input_set.tallies = tallies_file
|
||||
super(TallyAggregationTestHarness, self)._build_inputs()
|
||||
|
||||
def _get_results(self, hash_output=True):
|
||||
"""Digest info in the statepoint and return as a string."""
|
||||
|
||||
# Read the statepoint file.
|
||||
statepoint = glob.glob(os.path.join(os.getcwd(), self._sp_name))[0]
|
||||
sp = openmc.StatePoint(statepoint)
|
||||
|
||||
# Read the summary file.
|
||||
summary = glob.glob(os.path.join(os.getcwd(), 'summary.h5'))[0]
|
||||
su = openmc.Summary(summary)
|
||||
sp.link_with_summary(su)
|
||||
|
||||
# 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='energy')
|
||||
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='distribcell')
|
||||
outstr += ', '.join(map(str, tally_sum.mean))
|
||||
outstr += ', '.join(map(str, tally_sum.std_dev))
|
||||
|
||||
# Sum across all nuclides
|
||||
tally_sum = tally.summation(nuclides=['U-235', 'U-238', 'Pu-239'])
|
||||
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 _cleanup(self):
|
||||
super(TallyAggregationTestHarness, self)._cleanup()
|
||||
f = os.path.join(os.getcwd(), 'tallies.xml')
|
||||
if os.path.exists(f): os.remove(f)
|
||||
|
||||
if __name__ == '__main__':
|
||||
harness = TallyAggregationTestHarness('statepoint.10.h5', True)
|
||||
harness.main()
|
||||
|
|
@ -100,8 +100,6 @@ class TallyArithmeticTestHarness(PyAPITestHarness):
|
|||
'entrywise')
|
||||
outstr += str(tally_3.mean)
|
||||
|
||||
print(outstr)
|
||||
|
||||
# Hash the results if necessary
|
||||
if hash_output:
|
||||
sha512 = hashlib.sha512()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue