diff --git a/src/fixed_source.F90 b/src/fixed_source.F90 index 0aee9bddb6..bb26d671fe 100644 --- a/src/fixed_source.F90 +++ b/src/fixed_source.F90 @@ -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) diff --git a/src/particle_restart.F90 b/src/particle_restart.F90 index c524170a69..723d162495 100644 --- a/src/particle_restart.F90 +++ b/src/particle_restart.F90 @@ -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') diff --git a/src/particle_restart_write.F90 b/src/particle_restart_write.F90 index 90675d6343..9fcabe9229 100644 --- a/src/particle_restart_write.F90 +++ b/src/particle_restart_write.F90 @@ -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') diff --git a/src/utils/particle_restart.py b/src/utils/particle_restart.py index 92d28910c6..87b039e4a6 100644 --- a/src/utils/particle_restart.py +++ b/src/utils/particle_restart.py @@ -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] diff --git a/tests/test_fixed_source/results_true.dat b/tests/test_fixed_source/results_true.dat index 64dff1821c..e25333acf3 100644 --- a/tests/test_fixed_source/results_true.dat +++ b/tests/test_fixed_source/results_true.dat @@ -1,3 +1,3 @@ tallies: -4.538492E+02 -2.066738E+04 +4.339791E+02 +1.898784E+04 diff --git a/tests/test_particle_restart/results.py b/tests/test_particle_restart/results.py index 515274f1ee..7c10762449 100644 --- a/tests/test_particle_restart/results.py +++ b/tests/test_particle_restart/results.py @@ -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' diff --git a/tests/test_particle_restart/results_true.dat b/tests/test_particle_restart/results_true.dat index a59e626ce8..7139ec8450 100644 --- a/tests/test_particle_restart/results_true.dat +++ b/tests/test_particle_restart/results_true.dat @@ -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 diff --git a/tests/test_particle_restart/test_particle_restart.py b/tests/test_particle_restart/test_particle_restart.py index 3342c0af10..fdb2b6ba55 100644 --- a/tests/test_particle_restart/test_particle_restart.py +++ b/tests/test_particle_restart/test_particle_restart.py @@ -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