diff --git a/src/tally.F90 b/src/tally.F90 index a4fbe01cfd..f860149f6e 100644 --- a/src/tally.F90 +++ b/src/tally.F90 @@ -140,7 +140,7 @@ contains end if - case (SCORE_SCATTER_PN, SCORE_SCATTER_YN) + case (SCORE_SCATTER_PN) ! Only analog estimators are available. ! Skip any event where the particle didn't scatter if (p % event /= EVENT_SCATTER) then @@ -153,6 +153,19 @@ contains score = p % last_wgt + case (SCORE_SCATTER_YN) + ! Only analog estimators are available. + ! Skip any event where the particle didn't scatter + if (p % event /= EVENT_SCATTER) then + i = i + (t % moment_order(i) + 1)**2 - 1 + cycle SCORE_LOOP + end if + ! Since only scattering events make it here, again we can use + ! the weight entering the collision as the estimator for the + ! reaction rate + score = p % last_wgt + + case (SCORE_NU_SCATTER, SCORE_NU_SCATTER_N) ! Only analog estimators are available. ! Skip any event where the particle didn't scatter @@ -163,7 +176,7 @@ contains score = p % wgt - case (SCORE_NU_SCATTER_PN, SCORE_NU_SCATTER_YN) + case (SCORE_NU_SCATTER_PN) ! Only analog estimators are available. ! Skip any event where the particle didn't scatter if (p % event /= EVENT_SCATTER) then @@ -176,6 +189,19 @@ contains score = p % wgt + case (SCORE_NU_SCATTER_YN) + ! Only analog estimators are available. + ! Skip any event where the particle didn't scatter + if (p % event /= EVENT_SCATTER) then + i = i + (t % moment_order(i) + 1)**2 - 1 + cycle SCORE_LOOP + end if + ! For scattering production, we need to use the post-collision + ! weight as the estimate for the number of neutrons exiting a + ! reaction with neutrons in the exit channel + score = p % wgt + + case (SCORE_TRANSPORT) ! Only analog estimators are available. ! Skip any event where the particle didn't scatter diff --git a/tests/test_many_scores/geometry.xml b/tests/test_many_scores/geometry.xml new file mode 100644 index 0000000000..b85dd04df9 --- /dev/null +++ b/tests/test_many_scores/geometry.xml @@ -0,0 +1,181 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 17 17 + -10.71 -10.71 + 1.26 1.26 +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 7 7 7 7 7 + 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 + 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 + + + + diff --git a/tests/test_many_scores/materials.xml b/tests/test_many_scores/materials.xml new file mode 100644 index 0000000000..9c0b74f3f1 --- /dev/null +++ b/tests/test_many_scores/materials.xml @@ -0,0 +1,272 @@ + + + + 71c + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/test_many_scores/results.py b/tests/test_many_scores/results.py new file mode 100644 index 0000000000..8214d394c6 --- /dev/null +++ b/tests/test_many_scores/results.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python + +import sys +import numpy as np + +sys.path.insert(0, '../..') +from openmc.statepoint import StatePoint + +# read in statepoint file +if len(sys.argv) > 1: + sp = StatePoint(sys.argv[1]) +else: + sp = StatePoint('statepoint.5.binary') + +sp.read_results() + +# extract tally results and convert to vector +tally1 = sp._tallies[1] +results1 = np.zeros((tally1._sum.size + tally1._sum.size, )) +results1[0::2] = tally1._sum.ravel() +results1[1::2] = tally1._sum_sq.ravel() + +# set up output string +outstr = '' + +# write out k-combined +outstr += 'k-combined:\n' +outstr += "{0:12.6E} {1:12.6E}\n".format(sp._k_combined[0], sp._k_combined[1]) + +# write out tally results +outstr += 'tally 1:\n' +for item in results1: + outstr += "{0:12.6E}\n".format(item) + +# write results to file +with open('results_test.dat','w') as fh: + fh.write(outstr) diff --git a/tests/test_many_scores/results_true.dat b/tests/test_many_scores/results_true.dat new file mode 100644 index 0000000000..191122f13e --- /dev/null +++ b/tests/test_many_scores/results_true.dat @@ -0,0 +1,111 @@ +k-combined: +0.000000E+00 0.000000E+00 +tally 1: +2.254760E+01 +1.695439E+02 +1.017400E+01 +3.450623E+01 +8.690000E+00 +2.517771E+01 +8.696000E+00 +2.521248E+01 +5.224881E-01 +9.127522E-02 +8.690000E+00 +2.517771E+01 +9.665236E-01 +3.121401E-01 +5.224881E-01 +9.127522E-02 +5.199964E-01 +9.041516E-02 +8.696000E+00 +2.521248E+01 +9.666447E-01 +3.122176E-01 +5.199964E-01 +9.041516E-02 +9.262308E+00 +2.859762E+01 +8.684000E+00 +2.514296E+01 +1.484000E+00 +7.346160E-01 +1.804688E+00 +1.089100E+00 +1.334833E+02 +5.960573E+03 +2.254760E+01 +1.695439E+02 +-6.230152E-02 +1.023784E-02 +-2.696818E-01 +8.525477E-02 +-1.670294E-01 +4.366614E-02 +1.331953E-02 +8.064039E-05 +-2.490295E-01 +2.511425E-02 +8.289978E-02 +2.753446E-03 +-1.390686E-01 +1.592673E-02 +1.600203E-01 +1.344513E-02 +1.017400E+01 +3.450623E+01 +-6.564301E-02 +2.564587E-03 +-1.245391E-01 +1.143479E-02 +-5.550309E-02 +9.334547E-03 +4.671277E-02 +1.795787E-03 +-9.901000E-02 +4.609654E-03 +2.619012E-02 +3.011793E-04 +-7.090362E-02 +2.450750E-03 +4.059073E-02 +8.841300E-04 +8.690000E+00 +2.517771E+01 +-2.685052E-02 +2.769798E-04 +4.047919E-03 +3.384947E-03 +-1.325869E-01 +8.610169E-03 +-1.594962E-02 +5.528670E-04 +-1.320550E-02 +1.856248E-04 +1.185337E-02 +3.428536E-04 +2.622196E-02 +3.774884E-04 +2.938463E-02 +6.660370E-04 +8.696000E+00 +2.521248E+01 +-2.634867E-02 +2.718345E-04 +4.042613E-03 +3.367272E-03 +-1.328903E-01 +8.576852E-03 +-1.632965E-02 +5.577169E-04 +-1.408565E-02 +1.815109E-04 +1.202519E-02 +3.685250E-04 +2.634054E-02 +3.730853E-04 +2.941341E-02 +6.479457E-04 +1.014000E+01 +3.427460E+01 diff --git a/tests/test_many_scores/settings.xml b/tests/test_many_scores/settings.xml new file mode 100644 index 0000000000..08dc0d2e12 --- /dev/null +++ b/tests/test_many_scores/settings.xml @@ -0,0 +1,19 @@ + + + + + 5 + 2 + 500 + + + + + + -160 -160 -183 + 160 160 183 + + + + + diff --git a/tests/test_many_scores/tallies.xml b/tests/test_many_scores/tallies.xml new file mode 100644 index 0000000000..1832acf67a --- /dev/null +++ b/tests/test_many_scores/tallies.xml @@ -0,0 +1,13 @@ + + + + + + + flux total scatter nu-scatter scatter-2 scatter-p2 nu-scatter-2 + nu-scatter-p2 transport n1n absorption nu-fission kappa-fission + flux-y2 total-y2 scatter-y2 nu-scatter-y2 events + + + + diff --git a/tests/test_many_scores/test_many_scores.py b/tests/test_many_scores/test_many_scores.py new file mode 100644 index 0000000000..6b3ddeccae --- /dev/null +++ b/tests/test_many_scores/test_many_scores.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python + +import os +import sys +from subprocess import Popen, STDOUT, PIPE, call +import filecmp +import glob +from optparse import OptionParser + +parser = OptionParser() +parser.add_option('--mpi_exec', dest='mpi_exec', default='') +parser.add_option('--mpi_np', dest='mpi_np', default='3') +parser.add_option('--exe', dest='exe') +(opts, args) = parser.parse_args() +cwd = os.getcwd() + +def test_run(): + if opts.mpi_exec != '': + proc = Popen([opts.mpi_exec, '-np', opts.mpi_np, opts.exe, cwd], + stderr=STDOUT, stdout=PIPE) + else: + proc = Popen([opts.exe, cwd], stderr=STDOUT, stdout=PIPE) + print(proc.communicate()[0]) + returncode = proc.returncode + assert returncode == 0, 'OpenMC did not exit successfully.' + +def test_created_statepoint(): + statepoint = glob.glob(os.path.join(cwd, 'statepoint.5.*')) + assert len(statepoint) == 1, 'Either multiple or no statepoint files exist.' + assert statepoint[0].endswith('binary') or statepoint[0].endswith('h5'),\ + 'Statepoint file is not a binary or hdf5 file.' + +def test_output_exists(): + assert os.path.exists(os.path.join(cwd, 'tallies.out')), 'Tally output file does not exist.' + +def test_results(): + statepoint = glob.glob(os.path.join(cwd, 'statepoint.5.*')) + call([sys.executable, 'results.py', statepoint[0]]) + compare = filecmp.cmp('results_test.dat', 'results_true.dat') + if not compare: + os.rename('results_test.dat', 'results_error.dat') + assert compare, 'Results do not agree.' + +def teardown(): + output = glob.glob(os.path.join(cwd, 'statepoint.5.*')) + output.append(os.path.join(cwd, 'tallies.out')) + output.append(os.path.join(cwd, 'results_test.dat')) + for f in output: + if os.path.exists(f): + os.remove(f) + +if __name__ == '__main__': + + # test for openmc executable + if opts.exe is None: + raise Exception('Must specify OpenMC executable from command line with --exe.') + + # run tests + try: + test_run() + test_created_statepoint() + test_output_exists() + test_results() + finally: + teardown()