Fixed the fixed_source seed and updated the tests

This commit is contained in:
Sterling Harper 2014-07-01 17:33:02 +02:00
parent d3f4efde46
commit 0bd1394f87
8 changed files with 35 additions and 15 deletions

View file

@ -68,6 +68,11 @@ contains
! grab source particle from bank
call sample_source_particle(p)
! Reset random number seed (it was changed during source sampling and
! it should be set before transport is called to make it consistent
! with eigenvalue and particle_restart).
call set_particle_seed(p % id)
! transport particle
call transport(p)

View file

@ -9,7 +9,7 @@ module particle_restart
use output, only: write_message, print_particle
use output_interface, only: BinaryOutput
use particle_header, only: Particle
use random_lcg, only: set_particle_seed
use random_lcg, only: set_particle_seed, prn
use tracking, only: transport
implicit none
@ -28,6 +28,7 @@ contains
subroutine run_particle_restart()
integer(8) :: particle_seed
integer :: previous_run_mode
type(Particle) :: p
! Set verbosity high
@ -37,14 +38,20 @@ contains
call p % initialize()
! Read in the restart information
call read_particle_restart(p)
call read_particle_restart(p, previous_run_mode)
! Set all tallies to 0 for now (just tracking errors)
n_tallies = 0
! Compute random number seed
particle_seed = ((current_batch - 1)*gen_per_batch + &
current_gen - 1)*n_particles + p % id
select case (previous_run_mode)
case (MODE_EIGENVALUE)
particle_seed = ((current_batch - 1)*gen_per_batch + &
current_gen - 1)*n_particles + p % id
case (MODE_FIXEDSOURCE)
particle_seed = p % id
end select
call set_particle_seed(particle_seed)
! Transport neutron
@ -59,9 +66,10 @@ contains
! READ_PARTICLE_RESTART reads the particle restart file
!===============================================================================
subroutine read_particle_restart(p)
subroutine read_particle_restart(p, previous_run_mode)
integer :: int_scalar
integer, intent(inout) :: previous_run_mode
type(Particle), intent(inout) :: p
! Write meessage
@ -79,6 +87,7 @@ contains
call pr % read_data(gen_per_batch, 'gen_per_batch')
call pr % read_data(current_gen, 'current_gen')
call pr % read_data(n_particles, 'n_particles')
call pr % read_data(previous_run_mode, 'run_mode')
call pr % read_data(p % id, 'id')
call pr % read_data(p % wgt, 'weight')
call pr % read_data(p % E, 'energy')

View file

@ -56,6 +56,7 @@ contains
call pr % write_data(gen_per_batch, 'gen_per_batch')
call pr % write_data(current_gen, 'current_gen')
call pr % write_data(n_particles, 'n_particles')
call pr % write_data(run_mode, 'run_mode')
call pr % write_data(p % id, 'id')
call pr % write_data(src % wgt, 'weight')
call pr % write_data(src % E, 'energy')

View file

@ -30,6 +30,7 @@ class Particle(object):
self.gen_per_batch = self._get_int(path='gen_per_batch')[0]
self.current_gen = self._get_int(path='current_gen')[0]
self.n_particles = self._get_long(path='n_particles')[0]
self.run_mode = self._get_int(path='run_mode')[0]
# Read particle properties
self.id = self._get_long(path='id')[0]

View file

@ -1,3 +1,3 @@
tallies:
4.538492E+02
2.066738E+04
4.339791E+02
1.898784E+04

View file

@ -10,7 +10,7 @@ import particle_restart as pr
if len(sys.argv) > 1:
p = pr.Particle(sys.argv[1])
else:
p = pr.Particle('particle_12_192.binary')
p = pr.Particle('particle_12_556.binary')
# set up output string
outstr = ''
@ -22,6 +22,8 @@ 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'

View file

@ -3,12 +3,14 @@ current batch:
current gen:
1.000000E+00
particle id:
1.920000E+02
5.560000E+02
run mode:
2.000000E+00
particle weight:
1.000000E+00
particle energy:
3.643953E+00
1.691175E+00
particle xyz:
-4.855597E+01 5.269521E+01 3.202196E+01
-3.806864E+01 6.026401E+01 1.932278E+01
particle uvw:
-8.742346E-01 4.493061E-01 -1.839506E-01
4.129564E-01 -8.535159E-01 3.177696E-01

View file

@ -24,13 +24,13 @@ def test_run():
assert returncode == 0, 'OpenMC did not exit successfully.'
def test_created_restart():
particle = glob.glob(os.path.join(cwd, 'particle_12_192.*'))
particle = glob.glob(os.path.join(cwd, 'particle_12_556.*'))
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_12_192.*'))
particle = glob.glob(os.path.join(cwd, 'particle_12_556.*'))
call(['python', 'results.py', particle[0]])
compare = filecmp.cmp('results_test.dat', 'results_true.dat')
if not compare:
@ -38,7 +38,7 @@ def test_results():
assert compare, 'Results do not agree.'
def test_run_restart():
particle = glob.glob(os.path.join(cwd, 'particle_12_192.*'))
particle = glob.glob(os.path.join(cwd, 'particle_12_556.*'))
proc = Popen([opts.exe, '-r', particle[0], cwd], stderr=STDOUT, stdout=PIPE)
print(proc.communicate()[0])
returncode = proc.returncode