From 891ad670b7d95e13bd6ea6672fd75b68e30a5cd7 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Thu, 15 May 2014 23:24:49 -0400 Subject: [PATCH 1/5] Fix bug when using all with a void material present. --- src/tally.F90 | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/tally.F90 b/src/tally.F90 index b731c1ae5e..31ef3afd34 100644 --- a/src/tally.F90 +++ b/src/tally.F90 @@ -498,7 +498,9 @@ contains filter_index = sum((matching_bins(1:t%n_filters) - 1) * t % stride) + 1 if (t % all_nuclides) then - call score_all_nuclides(p, i_tally, flux, filter_index) + if (p % material /= MATERIAL_VOID) then + call score_all_nuclides(p, i_tally, flux, filter_index) + end if else NUCLIDE_BIN_LOOP: do k = 1, t % n_nuclide_bins @@ -1167,9 +1169,10 @@ contains filter_index = sum((matching_bins(1:t%n_filters) - 1) * t % stride) + 1 if (t % all_nuclides) then - ! Score reaction rates for each nuclide in material - call score_all_nuclides(p, i_tally, flux, filter_index) - + if (p % material /= MATERIAL_VOID) then + ! Score reaction rates for each nuclide in material + call score_all_nuclides(p, i_tally, flux, filter_index) + end if else NUCLIDE_BIN_LOOP: do b = 1, t % n_nuclide_bins ! Get index of nuclide in nuclides array From 028a271e861affc44a31e15918a39a848d0702f2 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Thu, 15 May 2014 23:39:46 -0400 Subject: [PATCH 2/5] Added new test in test suite to check for all with void material. --- tests/test_tally_nuclides/geometry.xml | 10 ++++ tests/test_tally_nuclides/materials.xml | 13 +++++ tests/test_tally_nuclides/results.py | 37 ++++++++++++ tests/test_tally_nuclides/results_true.dat | 19 +++++++ tests/test_tally_nuclides/settings.xml | 17 ++++++ tests/test_tally_nuclides/tallies.xml | 9 +++ .../test_tally_nuclides.py | 57 +++++++++++++++++++ 7 files changed, 162 insertions(+) create mode 100644 tests/test_tally_nuclides/geometry.xml create mode 100644 tests/test_tally_nuclides/materials.xml create mode 100644 tests/test_tally_nuclides/results.py create mode 100644 tests/test_tally_nuclides/results_true.dat create mode 100644 tests/test_tally_nuclides/settings.xml create mode 100644 tests/test_tally_nuclides/tallies.xml create mode 100644 tests/test_tally_nuclides/test_tally_nuclides.py diff --git a/tests/test_tally_nuclides/geometry.xml b/tests/test_tally_nuclides/geometry.xml new file mode 100644 index 0000000000..65954a7853 --- /dev/null +++ b/tests/test_tally_nuclides/geometry.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/tests/test_tally_nuclides/materials.xml b/tests/test_tally_nuclides/materials.xml new file mode 100644 index 0000000000..2761be30cf --- /dev/null +++ b/tests/test_tally_nuclides/materials.xml @@ -0,0 +1,13 @@ + + + + 71c + + + + + + + + + diff --git a/tests/test_tally_nuclides/results.py b/tests/test_tally_nuclides/results.py new file mode 100644 index 0000000000..93371960ae --- /dev/null +++ b/tests/test_tally_nuclides/results.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python + +import sys +import numpy as np + +# import statepoint +sys.path.append('../../src/utils') +import statepoint + +# read in statepoint file +if len(sys.argv) > 1: + sp = statepoint.StatePoint(sys.argv[1]) +else: + sp = statepoint.StatePoint('statepoint.10.binary') +sp.read_results() + +# extract tally results and convert to vector +results = sp.tallies[0].results +shape = results.shape +size = (np.product(shape)) +results = np.reshape(results, size) + +# 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 += 'tallies:\n' +for item in results: + 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_tally_nuclides/results_true.dat b/tests/test_tally_nuclides/results_true.dat new file mode 100644 index 0000000000..ce7400500d --- /dev/null +++ b/tests/test_tally_nuclides/results_true.dat @@ -0,0 +1,19 @@ +k-combined: +9.914201E-01 3.310472E-02 +tallies: +7.251620E+00 +1.056750E+01 +1.649542E+00 +5.462124E-01 +1.598276E+00 +5.127366E-01 +5.602079E+00 +6.310407E+00 +7.251620E+00 +1.056750E+01 +1.649542E+00 +5.462124E-01 +1.598276E+00 +5.127366E-01 +5.602079E+00 +6.310407E+00 diff --git a/tests/test_tally_nuclides/settings.xml b/tests/test_tally_nuclides/settings.xml new file mode 100644 index 0000000000..b2ddb42483 --- /dev/null +++ b/tests/test_tally_nuclides/settings.xml @@ -0,0 +1,17 @@ + + + + + 10 + 5 + 100 + + + + + point + 0.0 0.0 0.0 + + + + diff --git a/tests/test_tally_nuclides/tallies.xml b/tests/test_tally_nuclides/tallies.xml new file mode 100644 index 0000000000..d8c294de11 --- /dev/null +++ b/tests/test_tally_nuclides/tallies.xml @@ -0,0 +1,9 @@ + + + + + all + total absorption fission scatter + + + diff --git a/tests/test_tally_nuclides/test_tally_nuclides.py b/tests/test_tally_nuclides/test_tally_nuclides.py new file mode 100644 index 0000000000..bcc3f8a819 --- /dev/null +++ b/tests/test_tally_nuclides/test_tally_nuclides.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python + +import os +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.10.*')) + 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_results(): + statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*')) + call(['python', '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.10.*')) + 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 + test_run() + test_created_statepoint() + test_results() + teardown() From 40b1dc35f1d2ecdb83479dcb44d39e9a8cb000d2 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Wed, 28 May 2014 17:14:00 -0400 Subject: [PATCH 3/5] Fixed tallying for specific in a void material. The earlier change only fixed the special case of all. --- src/tally.F90 | 66 +++++++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 29 deletions(-) diff --git a/src/tally.F90 b/src/tally.F90 index 31ef3afd34..466f94b1c0 100644 --- a/src/tally.F90 +++ b/src/tally.F90 @@ -508,23 +508,27 @@ contains i_nuclide = t % nuclide_bins(k) if (i_nuclide > 0) then - ! Get pointer to current material - mat => materials(p % material) + if (p % material /= MATERIAL_VOID) then + ! Get pointer to current material + mat => materials(p % material) - ! Determine if nuclide is actually in material - NUCLIDE_MAT_LOOP: do j = 1, mat % n_nuclides - ! If index of nuclide matches the j-th nuclide listed in the - ! material, break out of the loop - if (i_nuclide == mat % nuclide(j)) exit + ! Determine if nuclide is actually in material + NUCLIDE_MAT_LOOP: do j = 1, mat % n_nuclides + ! If index of nuclide matches the j-th nuclide listed in the + ! material, break out of the loop + if (i_nuclide == mat % nuclide(j)) exit - ! If we've reached the last nuclide in the material, it means - ! the specified nuclide to be tallied is not in this material - if (j == mat % n_nuclides) then - cycle NUCLIDE_BIN_LOOP - end if - end do NUCLIDE_MAT_LOOP + ! If we've reached the last nuclide in the material, it means + ! the specified nuclide to be tallied is not in this material + if (j == mat % n_nuclides) then + cycle NUCLIDE_BIN_LOOP + end if + end do NUCLIDE_MAT_LOOP - atom_density = mat % atom_density(j) + atom_density = mat % atom_density(j) + else + atom_density = ZERO + end if end if ! Determine score for each bin @@ -1179,24 +1183,28 @@ contains i_nuclide = t % nuclide_bins(b) if (i_nuclide > 0) then - ! Get pointer to current material - mat => materials(p % material) + if (p % material /= MATERIAL_VOID) then + ! Get pointer to current material + mat => materials(p % material) - ! Determine if nuclide is actually in material - NUCLIDE_MAT_LOOP: do j = 1, mat % n_nuclides - ! If index of nuclide matches the j-th nuclide listed in - ! the material, break out of the loop - if (i_nuclide == mat % nuclide(j)) exit + ! Determine if nuclide is actually in material + NUCLIDE_MAT_LOOP: do j = 1, mat % n_nuclides + ! If index of nuclide matches the j-th nuclide listed in + ! the material, break out of the loop + if (i_nuclide == mat % nuclide(j)) exit - ! If we've reached the last nuclide in the material, it - ! means the specified nuclide to be tallied is not in this - ! material - if (j == mat % n_nuclides) then - cycle NUCLIDE_BIN_LOOP - end if - end do NUCLIDE_MAT_LOOP + ! If we've reached the last nuclide in the material, it + ! means the specified nuclide to be tallied is not in this + ! material + if (j == mat % n_nuclides) then + cycle NUCLIDE_BIN_LOOP + end if + end do NUCLIDE_MAT_LOOP - atom_density = mat % atom_density(j) + atom_density = mat % atom_density(j) + else + atom_density = ZERO + end if end if ! Determine score for each bin From 1eabfc7cd2ea078522d11c8b9efd66d2c57bb63b Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Mon, 2 Jun 2014 21:12:12 -0400 Subject: [PATCH 4/5] Updated test_tally_nuclides to include a tally containing a filter with only one nuclide. --- tests/test_tally_nuclides/results.py | 7 +++---- tests/test_tally_nuclides/results_true.dat | 8 ++++++++ tests/test_tally_nuclides/tallies.xml | 5 +++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/tests/test_tally_nuclides/results.py b/tests/test_tally_nuclides/results.py index 93371960ae..3aa0946a5d 100644 --- a/tests/test_tally_nuclides/results.py +++ b/tests/test_tally_nuclides/results.py @@ -15,10 +15,9 @@ else: sp.read_results() # extract tally results and convert to vector -results = sp.tallies[0].results -shape = results.shape -size = (np.product(shape)) -results = np.reshape(results, size) +results0 = sp.tallies[0].results +results1 = sp.tallies[1].results +results = np.concatenate((results0.flatten(), results1.flatten())) # set up output string outstr = '' diff --git a/tests/test_tally_nuclides/results_true.dat b/tests/test_tally_nuclides/results_true.dat index ce7400500d..e429381ddb 100644 --- a/tests/test_tally_nuclides/results_true.dat +++ b/tests/test_tally_nuclides/results_true.dat @@ -17,3 +17,11 @@ tallies: 5.127366E-01 5.602079E+00 6.310407E+00 +7.251620E+00 +1.056750E+01 +1.649542E+00 +5.462124E-01 +1.598276E+00 +5.127366E-01 +5.602079E+00 +6.310407E+00 diff --git a/tests/test_tally_nuclides/tallies.xml b/tests/test_tally_nuclides/tallies.xml index d8c294de11..cf20668c83 100644 --- a/tests/test_tally_nuclides/tallies.xml +++ b/tests/test_tally_nuclides/tallies.xml @@ -6,4 +6,9 @@ total absorption fission scatter + + Pu-239 + total absorption fission scatter + + From df426181303113a8d298b9b04042a687db67f057 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Mon, 2 Jun 2014 21:14:25 -0400 Subject: [PATCH 5/5] Added try/finally in test_tally_nuclides.py. --- tests/test_tally_nuclides/test_tally_nuclides.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/test_tally_nuclides/test_tally_nuclides.py b/tests/test_tally_nuclides/test_tally_nuclides.py index bcc3f8a819..6fdbf87459 100644 --- a/tests/test_tally_nuclides/test_tally_nuclides.py +++ b/tests/test_tally_nuclides/test_tally_nuclides.py @@ -51,7 +51,9 @@ if __name__ == '__main__': raise Exception('Must specify OpenMC executable from command line with --exe.') # run tests - test_run() - test_created_statepoint() - test_results() - teardown() + try: + test_run() + test_created_statepoint() + test_results() + finally: + teardown()