From bc0b8262499f6fe0d08ee9b3fc8f979319cfa013 Mon Sep 17 00:00:00 2001 From: "wbinventor@gmail.com" Date: Fri, 15 Jan 2016 17:33:22 -0500 Subject: [PATCH] Added new tally aggregation (summation) test --- openmc/aggregate.py | 2 +- openmc/tallies.py | 2 +- tests/test_tally_aggregation/inputs_true.dat | 1 + tests/test_tally_aggregation/results_true.dat | 1 + .../test_tally_aggregation.py | 99 +++++++++++++++++++ .../test_tally_arithmetic.py | 2 - 6 files changed, 103 insertions(+), 4 deletions(-) create mode 100644 tests/test_tally_aggregation/inputs_true.dat create mode 100644 tests/test_tally_aggregation/results_true.dat create mode 100644 tests/test_tally_aggregation/test_tally_aggregation.py diff --git a/openmc/aggregate.py b/openmc/aggregate.py index 50eb8c6278..67995a41f2 100644 --- a/openmc/aggregate.py +++ b/openmc/aggregate.py @@ -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 \ No newline at end of file diff --git a/openmc/tallies.py b/openmc/tallies.py index b0265b841a..980c5fa2b5 100644 --- a/openmc/tallies.py +++ b/openmc/tallies.py @@ -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) diff --git a/tests/test_tally_aggregation/inputs_true.dat b/tests/test_tally_aggregation/inputs_true.dat new file mode 100644 index 0000000000..7b4276f59e --- /dev/null +++ b/tests/test_tally_aggregation/inputs_true.dat @@ -0,0 +1 @@ +530a5e969901e153531f74aed46246b1e8783a0e2f347e472f7554c9970152f45d85499f17d7df9c35c74fed6f78d449aa70bf0c1f8947cd34d3a829483a0055 \ No newline at end of file diff --git a/tests/test_tally_aggregation/results_true.dat b/tests/test_tally_aggregation/results_true.dat new file mode 100644 index 0000000000..cde3e281c2 --- /dev/null +++ b/tests/test_tally_aggregation/results_true.dat @@ -0,0 +1 @@ +ba8bfe764fcc0484a4fdab8fdc4ff8ad0e4a98b1ff33e8687899c8cc6bf80cb28b3a59aeaec84bd74681b8b5f19f714292ccaa9c9d4ba852b2cc29872f612e10 \ No newline at end of file diff --git a/tests/test_tally_aggregation/test_tally_aggregation.py b/tests/test_tally_aggregation/test_tally_aggregation.py new file mode 100644 index 0000000000..a5c8d94141 --- /dev/null +++ b/tests/test_tally_aggregation/test_tally_aggregation.py @@ -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() diff --git a/tests/test_tally_arithmetic/test_tally_arithmetic.py b/tests/test_tally_arithmetic/test_tally_arithmetic.py index 6643fd5a22..1954334b7f 100644 --- a/tests/test_tally_arithmetic/test_tally_arithmetic.py +++ b/tests/test_tally_arithmetic/test_tally_arithmetic.py @@ -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()