From 9ab2b0d8607714e0782e2a8798d021e98a1d6b03 Mon Sep 17 00:00:00 2001 From: Sterling Harper Date: Wed, 6 Aug 2014 15:20:22 +0200 Subject: [PATCH] Added test for particle restart with fixed source --- src/CMakeLists.txt | 12 ++-- .../geometry.xml | 0 .../materials.xml | 0 .../results.py | 0 .../results_true.dat | 0 .../settings.xml | 0 .../test_part_restart_eigval.py} | 0 tests/test_part_restart_fixed/geometry.xml | 9 +++ tests/test_part_restart_fixed/materials.xml | 9 +++ tests/test_part_restart_fixed/results.py | 38 +++++++++++ .../test_part_restart_fixed/results_true.dat | 16 +++++ tests/test_part_restart_fixed/settings.xml | 15 ++++ .../test_part_restart_fixed.py | 68 +++++++++++++++++++ 13 files changed, 163 insertions(+), 4 deletions(-) rename tests/{test_particle_restart => test_part_restart_eigval}/geometry.xml (100%) rename tests/{test_particle_restart => test_part_restart_eigval}/materials.xml (100%) rename tests/{test_particle_restart => test_part_restart_eigval}/results.py (100%) rename tests/{test_particle_restart => test_part_restart_eigval}/results_true.dat (100%) rename tests/{test_particle_restart => test_part_restart_eigval}/settings.xml (100%) rename tests/{test_particle_restart/test_particle_restart.py => test_part_restart_eigval/test_part_restart_eigval.py} (100%) create mode 100644 tests/test_part_restart_fixed/geometry.xml create mode 100644 tests/test_part_restart_fixed/materials.xml create mode 100644 tests/test_part_restart_fixed/results.py create mode 100644 tests/test_part_restart_fixed/results_true.dat create mode 100644 tests/test_part_restart_fixed/settings.xml create mode 100644 tests/test_part_restart_fixed/test_part_restart_fixed.py diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ee5f882b7e..9ce433731f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -345,8 +345,10 @@ foreach(test ${TESTS}) set(RESTART_FILE statepoint.7.h5) elseif(${test} MATCHES "test_sourcepoint_restart") set(RESTART_FILE statepoint.7.h5 source.7.h5) - elseif(${test} MATCHES "test_particle_restart") - set(RESTART_FILE particle_12_192.h5) + elseif(${test} MATCHES "test_part_restart_eigval") + set(RESTART_FILE particle_12_842.h5) + elseif(${test} MATCHES "test_part_restart_fixed") + set(RESTART_FILE particle_7_6144.h5) else(${test} MATCHES "test_statepoint_restart") message(FATAL_ERROR "Restart test ${test} not recognized") endif(${test} MATCHES "test_statepoint_restart") @@ -358,8 +360,10 @@ foreach(test ${TESTS}) set(RESTART_FILE statepoint.7.binary) elseif(${test} MATCHES "test_sourcepoint_restart") set(RESTART_FILE statepoint.7.binary source.7.binary) - elseif(${test} MATCHES "test_particle_restart") - set(RESTART_FILE particle_12_192.binary) + elseif(${test} MATCHES "test_part_restart_eigval") + set(RESTART_FILE particle_12_842.binary) + elseif(${test} MATCHES "test_part_restart_fixed") + set(RESTART_FILE particle_7_6144.binary) else(${test} MATCHES "test_statepoint_restart") message(FATAL_ERROR "Restart test ${test} not recognized") endif(${test} MATCHES "test_statepoint_restart") diff --git a/tests/test_particle_restart/geometry.xml b/tests/test_part_restart_eigval/geometry.xml similarity index 100% rename from tests/test_particle_restart/geometry.xml rename to tests/test_part_restart_eigval/geometry.xml diff --git a/tests/test_particle_restart/materials.xml b/tests/test_part_restart_eigval/materials.xml similarity index 100% rename from tests/test_particle_restart/materials.xml rename to tests/test_part_restart_eigval/materials.xml diff --git a/tests/test_particle_restart/results.py b/tests/test_part_restart_eigval/results.py similarity index 100% rename from tests/test_particle_restart/results.py rename to tests/test_part_restart_eigval/results.py diff --git a/tests/test_particle_restart/results_true.dat b/tests/test_part_restart_eigval/results_true.dat similarity index 100% rename from tests/test_particle_restart/results_true.dat rename to tests/test_part_restart_eigval/results_true.dat diff --git a/tests/test_particle_restart/settings.xml b/tests/test_part_restart_eigval/settings.xml similarity index 100% rename from tests/test_particle_restart/settings.xml rename to tests/test_part_restart_eigval/settings.xml diff --git a/tests/test_particle_restart/test_particle_restart.py b/tests/test_part_restart_eigval/test_part_restart_eigval.py similarity index 100% rename from tests/test_particle_restart/test_particle_restart.py rename to tests/test_part_restart_eigval/test_part_restart_eigval.py diff --git a/tests/test_part_restart_fixed/geometry.xml b/tests/test_part_restart_fixed/geometry.xml new file mode 100644 index 0000000000..52fea4df64 --- /dev/null +++ b/tests/test_part_restart_fixed/geometry.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/tests/test_part_restart_fixed/materials.xml b/tests/test_part_restart_fixed/materials.xml new file mode 100644 index 0000000000..deddaef97f --- /dev/null +++ b/tests/test_part_restart_fixed/materials.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/tests/test_part_restart_fixed/results.py b/tests/test_part_restart_fixed/results.py new file mode 100644 index 0000000000..e84cb88cff --- /dev/null +++ b/tests/test_part_restart_fixed/results.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python + +import sys + +# import particle restart +sys.path.append('../../src/utils') +import particle_restart as pr + +# read in particle restart file +if len(sys.argv) > 1: + p = pr.Particle(sys.argv[1]) +else: + p = pr.Particle('particle_7_6144.binary') + +# set up output string +outstr = '' + +# write out properties +outstr += 'current batch:\n' +outstr += "{0:12.6E}\n".format(p.current_batch) +outstr += 'current gen:\n' +outstr += "{0:12.6E}\n".format(p.current_gen) +outstr += 'particle id:\n' +outstr += "{0:12.6E}\n".format(p.id) +outstr += 'run mode:\n' +outstr += "{0:12.6E}\n".format(p.run_mode) +outstr += 'particle weight:\n' +outstr += "{0:12.6E}\n".format(p.weight) +outstr += 'particle energy:\n' +outstr += "{0:12.6E}\n".format(p.energy) +outstr += 'particle xyz:\n' +outstr += "{0:12.6E} {1:12.6E} {2:12.6E}\n".format(p.xyz[0],p.xyz[1],p.xyz[2]) +outstr += 'particle uvw:\n' +outstr += "{0:12.6E} {1:12.6E} {2:12.6E}\n".format(p.uvw[0],p.uvw[1],p.uvw[2]) + +# write results to file +with open('results_test.dat','w') as fh: + fh.write(outstr) diff --git a/tests/test_part_restart_fixed/results_true.dat b/tests/test_part_restart_fixed/results_true.dat new file mode 100644 index 0000000000..ffe7d2cae5 --- /dev/null +++ b/tests/test_part_restart_fixed/results_true.dat @@ -0,0 +1,16 @@ +current batch: +7.000000E+00 +current gen: +0.000000E+00 +particle id: +6.144000E+03 +run mode: +1.000000E+00 +particle weight: +1.000000E+00 +particle energy: +5.749729E+00 +particle xyz: +8.754675E+00 2.551620E+00 4.394350E-01 +particle uvw: +-5.971721E-01 -4.845709E-01 6.391999E-01 diff --git a/tests/test_part_restart_fixed/settings.xml b/tests/test_part_restart_fixed/settings.xml new file mode 100644 index 0000000000..1d8193f8f6 --- /dev/null +++ b/tests/test_part_restart_fixed/settings.xml @@ -0,0 +1,15 @@ + + + + + 12 + 1000 + + + + + -10 -10 -5 10 10 5 + + + + diff --git a/tests/test_part_restart_fixed/test_part_restart_fixed.py b/tests/test_part_restart_fixed/test_part_restart_fixed.py new file mode 100644 index 0000000000..11ee1fad0c --- /dev/null +++ b/tests/test_part_restart_fixed/test_part_restart_fixed.py @@ -0,0 +1,68 @@ +#!/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_restart(): + particle = glob.glob(os.path.join(cwd, 'particle_7_6144.*')) + assert len(particle) == 1, 'Either multiple or no particle restart files exist.' + assert particle[0].endswith('binary') or \ + particle[0].endswith('h5'), 'Particle restart file not a binary or hdf5 file.' + +def test_results(): + particle = glob.glob(os.path.join(cwd, 'particle_7_6144.*')) + call(['python', 'results.py', particle[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 test_run_restart(): + particle = glob.glob(os.path.join(cwd, 'particle_7_6144.*')) + proc = Popen([opts.exe, '-r', particle[0], cwd], stderr=STDOUT, stdout=PIPE) + print(proc.communicate()[0]) + returncode = proc.returncode + assert returncode == 0, 'Particle restart not successful.' + +def teardown(): + output = glob.glob(os.path.join(cwd, 'statepoint.*')) + \ + glob.glob(os.path.join(cwd, 'particle_*')) + \ + [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_restart() + test_results() + test_run_restart() + finally: + teardown()