From f1fc8c7f5e19dc0777706de465cd722e95143f59 Mon Sep 17 00:00:00 2001 From: Sterling Harper Date: Wed, 6 Aug 2014 10:56:52 +0200 Subject: [PATCH] Use different stream for source sampling This commit makes it easier for eigenvalue and fixed source runs to use the same seeds when sampling sources. --- src/constants.F90 | 8 ++++++++ src/fixed_source.F90 | 7 ------- src/global.F90 | 2 ++ src/particle_restart.F90 | 2 +- src/random_lcg.F90 | 7 ++----- src/source.F90 | 8 +++++++- 6 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/constants.F90 b/src/constants.F90 index 94edd9d2a2..f83f7bd2c1 100644 --- a/src/constants.F90 +++ b/src/constants.F90 @@ -348,6 +348,14 @@ module constants K_TRACKLENGTH = 3, & LEAKAGE = 4 + ! ============================================================================ + ! RANDOM NUMBER STREAM CONSTANTS + + integer, parameter :: N_STREAMS = 3 + integer, parameter :: STREAM_TRACKING = 1 + integer, parameter :: STREAM_TALLIES = 2 + integer, parameter :: STREAM_SOURCE = 3 + ! ============================================================================ ! EXTERNAL SOURCE PARAMETERS diff --git a/src/fixed_source.F90 b/src/fixed_source.F90 index bb26d671fe..11290db538 100644 --- a/src/fixed_source.F90 +++ b/src/fixed_source.F90 @@ -11,8 +11,6 @@ module fixed_source use tally, only: synchronize_tallies, setup_active_usertallies use tracking, only: transport -!$omp threadprivate(source_site) - contains subroutine run_fixedsource() @@ -68,11 +66,6 @@ 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/global.F90 b/src/global.F90 index 1f4fba2c50..41052afe4c 100644 --- a/src/global.F90 +++ b/src/global.F90 @@ -258,6 +258,8 @@ module global ! Fixed source particle bank type(Bank), pointer :: source_site => null() +!$omp threadprivate(source_site) + ! Restart run logical :: restart_run = .false. diff --git a/src/particle_restart.F90 b/src/particle_restart.F90 index e1480e141c..db2490dd2a 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, prn + use random_lcg, only: set_particle_seed use tracking, only: transport implicit none diff --git a/src/random_lcg.F90 b/src/random_lcg.F90 index e3a9885af1..a29d1aa9a0 100644 --- a/src/random_lcg.F90 +++ b/src/random_lcg.F90 @@ -1,15 +1,12 @@ module random_lcg + use constants + implicit none private save - ! Random number streams - integer, parameter :: N_STREAMS = 2 - integer, parameter :: STREAM_TRACKING = 1 - integer, parameter :: STREAM_TALLIES = 2 - integer(8) :: prn_seed0 ! original seed integer(8) :: prn_seed(N_STREAMS) ! current seed integer(8) :: prn_mult ! multiplication factor, g diff --git a/src/source.F90 b/src/source.F90 index 79bc49fd57..9dcfd01445 100644 --- a/src/source.F90 +++ b/src/source.F90 @@ -10,7 +10,7 @@ module source use output, only: write_message use output_interface, only: BinaryOutput use particle_header, only: Particle - use random_lcg, only: prn, set_particle_seed + use random_lcg, only: prn, set_particle_seed, prn_set_stream use string, only: to_str #ifdef MPI @@ -101,6 +101,9 @@ contains ! Set weight to one by default site % wgt = ONE + ! Set the random number generator to the source stream. + call prn_set_stream(STREAM_SOURCE) + ! Sample position select case (external_source % type_space) case (SRC_SPACE_BOX) @@ -189,6 +192,9 @@ contains call fatal_error() end select + ! Set the random number generator back to the tracking stream. + call prn_set_stream(STREAM_TRACKING) + end subroutine sample_external_source !===============================================================================