Added test for particle restart with fixed source

This commit is contained in:
Sterling Harper 2014-08-06 15:20:22 +02:00
parent 93a0e06c57
commit 9ab2b0d860
13 changed files with 163 additions and 4 deletions

View file

@ -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")

View file

@ -0,0 +1,9 @@
<?xml version="1.0"?>
<geometry>
<!-- Sphere with no boundary condition -->
<surface id="1" type="sphere" coeffs="0.0 0.0 0.0 80.0" />
<surface id="2" type="sphere" coeffs="0.0 0.0 0.0 10000.0" boundary="vacuum" />
<cell id="1" material="1" surfaces="-1" />
</geometry>

View file

@ -0,0 +1,9 @@
<?xml version="1.0"?>
<materials>
<material id="1">
<density value="1.4" units="g/cc" />
<nuclide name="B-10" xs="71c" ao="1.0" />
</material>
</materials>

View file

@ -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)

View file

@ -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

View file

@ -0,0 +1,15 @@
<?xml version="1.0"?>
<settings>
<fixed_source>
<batches>12</batches>
<particles>1000</particles>
</fixed_source>
<source>
<space type="box">
<parameters>-10 -10 -5 10 10 5</parameters>
</space>
</source>
</settings>

View file

@ -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()