diff --git a/tests/test_tally_arithmetic/geometry.xml b/tests/test_tally_arithmetic/geometry.xml new file mode 100644 index 0000000000..bc56030e18 --- /dev/null +++ b/tests/test_tally_arithmetic/geometry.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/tests/test_tally_arithmetic/materials.xml b/tests/test_tally_arithmetic/materials.xml new file mode 100644 index 0000000000..e7947a92da --- /dev/null +++ b/tests/test_tally_arithmetic/materials.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/tests/test_tally_arithmetic/results_true.dat b/tests/test_tally_arithmetic/results_true.dat new file mode 100644 index 0000000000..85183e3e8f --- /dev/null +++ b/tests/test_tally_arithmetic/results_true.dat @@ -0,0 +1,49 @@ +Tally + ID = 10000 + Name = (tally 1 + tally 2) + Filters = + energy [ 0. 20.] + (cell + material) (array([1]), array([1])) + Nuclides = (U-235 + U-235) (U-235 + Pu-239) (U-238 + U-235) (U-238 + Pu-239) + Scores = [(fission + fission), (fission + absorption), (nu-fission + fission), (nu-fission + absorption)] + Estimator = tracklength +[[[ 0.07510122 0.07839105 0.13713377 0.1404236 ] + [ 0.0916553 0.09321683 0.15368785 0.15524938] + [ 0.04596277 0.0492526 0.06126275 0.06455259] + [ 0.06251685 0.06407838 0.07781683 0.07937836]]]Tally + ID = 10001 + Name = (tally 1 - tally 2) + Filters = + energy [ 0. 20.] + (cell - material) (array([1]), array([1])) + Nuclides = (U-235 - U-235) (U-235 - Pu-239) (U-238 - U-235) (U-238 - Pu-239) + Scores = [(fission - fission), (fission - absorption), (nu-fission - fission), (nu-fission - absorption)] + Estimator = tracklength +[[[ 0. -0.00328983 0.06203255 0.05874271] + [-0.01655408 -0.01811561 0.04547847 0.04391694] + [-0.02913845 -0.03242829 -0.01383847 -0.0171283 ] + [-0.04569253 -0.04725406 -0.03039255 -0.03195408]]]Tally + ID = 10002 + Name = (tally 1 * tally 2) + Filters = + energy [ 0. 20.] + (cell * material) (array([1]), array([1])) + Nuclides = (U-235 * U-235) (U-235 * Pu-239) (U-238 * U-235) (U-238 * Pu-239) + Scores = [(fission * fission), (fission * absorption), (nu-fission * fission), (nu-fission * absorption)] + Estimator = tracklength +[[[ 0.00141005 0.00153358 0.00373941 0.00406702] + [ 0.00203166 0.0020903 0.00538792 0.00554342] + [ 0.00031588 0.00034356 0.00089041 0.00096841] + [ 0.00045514 0.00046827 0.00128294 0.00131997]]]Tally + ID = 10003 + Name = (tally 1 / tally 2) + Filters = + energy [ 0. 20.] + (cell / material) (array([1]), array([1])) + Nuclides = (U-235 / U-235) (U-235 / Pu-239) (U-238 / U-235) (U-238 / Pu-239) + Scores = [(fission / fission), (fission / absorption), (nu-fission / fission), (nu-fission / absorption)] + Estimator = tracklength +[[[ 1. 0.91944666 2.65197177 2.4383466 ] + [ 0.69403611 0.67456727 1.84056418 1.78893335] + [ 0.22402189 0.20597618 0.63147153 0.58060439] + [ 0.15547928 0.15111784 0.43826405 0.42597002]]] \ No newline at end of file diff --git a/tests/test_tally_arithmetic/settings.xml b/tests/test_tally_arithmetic/settings.xml new file mode 100644 index 0000000000..a69dde686a --- /dev/null +++ b/tests/test_tally_arithmetic/settings.xml @@ -0,0 +1,18 @@ + + + + + 10 + 5 + 1000 + + + + + -4 -4 -4 4 4 4 + + + + + + diff --git a/tests/test_tally_arithmetic/test_tally_arithmetic.py b/tests/test_tally_arithmetic/test_tally_arithmetic.py new file mode 100644 index 0000000000..ee1a7a6481 --- /dev/null +++ b/tests/test_tally_arithmetic/test_tally_arithmetic.py @@ -0,0 +1,91 @@ +#!/usr/bin/env python + +import os +import sys +import glob +import hashlib +sys.path.insert(0, os.pardir) +from testing_harness import TestHarness +import openmc + + +class TallyArithmeticTestHarness(TestHarness): + def _build_inputs(self): + + u235 = openmc.Nuclide('U-235') + u238 = openmc.Nuclide('U-238') + pu239 = openmc.Nuclide('Pu-239') + + # Instantiate energy filter + energy_filter = openmc.Filter(type='energy', bins=[0., 20.]) + + # Create tallies + tally_1 = openmc.Tally(name='tally 1') + tally_1.add_filter(openmc.Filter(type='cell', bins=[1])) + tally_1.add_filter(energy_filter) + tally_1.add_score('fission') + tally_1.add_score('nu-fission') + tally_1.add_nuclide(u235) + tally_1.add_nuclide(u238) + + tally_2 = openmc.Tally(name='tally 2') + tally_2.add_filter(openmc.Filter(type='material', bins=[1])) + tally_2.add_filter(energy_filter) + tally_2.add_score('fission') + tally_2.add_score('absorption') + tally_2.add_nuclide(u235) + tally_2.add_nuclide(pu239) + + # Export tallies to file + tallies_file = openmc.TalliesFile() + tallies_file.add_tally(tally_1) + tallies_file.add_tally(tally_2) + tallies_file.export_to_xml() + + def _get_results(self, hash_output=False): + """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) + + # Load the tallies + tally_1 = sp.get_tally(name='tally 1') + tally_2 = sp.get_tally(name='tally 2') + + # Perform all the tally arithmetic operations and output results + outstr = '' + tally_3 = tally_1 + tally_2 + outstr += tally_3.__repr__() + outstr += str(tally_3.mean) + + tally_3 = tally_1 - tally_2 + outstr += tally_3.__repr__() + outstr += str(tally_3.mean) + + tally_3 = tally_1 * tally_2 + outstr += tally_3.__repr__() + outstr += str(tally_3.mean) + + tally_3 = tally_1 / tally_2 + outstr += tally_3.__repr__() + outstr += str(tally_3.mean) + + print(outstr) + + # Hash the results if necessary + if hash_output: + sha512 = hashlib.sha512() + sha512.update(outstr.encode('utf-8')) + outstr = sha512.hexdigest() + + return outstr + +if __name__ == '__main__': + harness = TallyArithmeticTestHarness('statepoint.10.*', True) + harness.main()