Minor restructuring in source module, added copy_source_attributes subroutine. Moved count for total_weight into transport module.

This commit is contained in:
Paul Romano 2012-07-30 12:41:40 -04:00
parent d721072423
commit b6bee4cc7a
4 changed files with 79 additions and 21 deletions

View file

@ -65,6 +65,7 @@ fixed_source.o: constants.o
fixed_source.o: global.o
fixed_source.o: output.o
fixed_source.o: physics.o
fixed_source.o: random_lcg.o
fixed_source.o: source.o
fixed_source.o: string.o
fixed_source.o: tally.o

View file

@ -4,24 +4,29 @@ module fixed_source
use global
use output, only: write_message, header
use physics, only: transport
use source, only: get_source_particle
use random_lcg, only: set_particle_seed
use source, only: initialize_particle, sample_external_source, &
copy_source_attributes
use string, only: to_str
use tally, only: synchronize_tallies
use timing, only: timer_start, timer_stop
type(Bank), pointer :: source_site => null()
contains
subroutine run_fixedsource()
integer(8) :: i ! index over histories in single cycle
integer(8) :: i ! index over histories in single cycle
if (master) call header("BEGIN SIMULATION", level=1)
tallies_on = .true.
call timer_start(time_inactive)
! Allocate particle
! Allocate particle and dummy source site
allocate(p)
allocate(source_site)
! ==========================================================================
! LOOP OVER BATCHES
@ -36,8 +41,19 @@ contains
! LOOP OVER PARTICLES
PARTICLE_LOOP: do i = 1, work
! Set unique particle ID
p % id = (current_batch - 1)*n_particles + bank_first + i - 1
! set particle trace
trace = .false.
if (current_batch == trace_batch .and. current_gen == trace_gen .and. &
bank_first + i - 1 == trace_particle) trace = .true.
! set random number seed
call set_particle_seed(p % id)
! grab source particle from bank
call get_source_particle(i)
call sample_source_particle()
! transport particle
call transport()
@ -76,4 +92,21 @@ contains
end subroutine initialize_batch
!===============================================================================
! SAMPLE_SOURCE_PARTICLE
!===============================================================================
subroutine sample_source_particle()
! Set particle
call initialize_particle()
! Sample the external source distribution
call sample_external_source(source_site)
! Copy source attributes to the particle
call copy_source_attributes(source_site)
end subroutine sample_source_particle
end module fixed_source

View file

@ -41,13 +41,17 @@ contains
logical :: found_cell ! found cell which particle is in?
type(LocalCoord), pointer :: coord => null()
! Display message if high verbosity or trace is on
if (verbosity >= 9 .or. trace) then
message = "Simulating Particle " // trim(to_str(p % id))
call write_message()
end if
! If the cell hasn't been determined based on the particle's location,
! initiate a search for the current cell
if (p % coord % cell == NONE) then
call find_cell(found_cell)
! Particle couldn't be located
if (.not. found_cell) then
message = "Could not locate particle " // trim(to_str(p % id))
@ -61,6 +65,9 @@ contains
! Initialize number of events to zero
n_event = 0
! Add paricle's starting weight to count for normalizing tallies later
total_weight = total_weight + p % wgt
! Force calculation of cross-sections by setting last energy to zero
micro_xs % last_E = ZERO

View file

@ -28,6 +28,8 @@ contains
integer(8) :: i ! loop index over bank sites
integer(8) :: id ! particle id
type(Bank), pointer :: src => null() ! source bank site
message = "Initializing source particles..."
call write_message(6)
@ -40,17 +42,21 @@ contains
else
! Generation source sites from specified distribution in user input
do i = 1, work
! Get pointer to source bank site
src => source_bank(i)
! Set ID of source bank site
id = bank_first + i - 1
source_bank(i) % id = id
src % id = id
! Set weight to one
source_bank(i) % wgt = ONE
src % wgt = ONE
! initialize random number seed
call set_particle_seed(id)
! sample external source distribution
call sample_external_source(source_bank(i))
call sample_external_source(src)
end do
end if
@ -62,7 +68,7 @@ contains
subroutine sample_external_source(site)
type(Bank), intent(inout) :: site ! source site
type(Bank), pointer :: site ! source site
integer :: i ! dummy loop index
real(8) :: r(3) ! sampled coordinates
@ -73,6 +79,9 @@ contains
real(8) :: a ! Arbitrary parameter 'a'
real(8) :: b ! Arbitrary parameter 'b'
! Set weight to one by default
site % wgt = ONE
! Sample position
select case (external_source % type_space)
case (SRC_SPACE_BOX)
@ -155,17 +164,9 @@ contains
! set defaults
call initialize_particle()
! point to next source particle
! Copy attributes from source to particle
src => source_bank(index_source)
! copy attributes from source bank site
p % wgt = src % wgt
p % last_wgt = src % wgt
p % coord % xyz = src % xyz
p % coord % uvw = src % uvw
p % last_xyz = src % xyz
p % E = src % E
p % last_E = src % E
call copy_source_attributes(src)
! set identifier for particle
p % id = bank_first + index_source - 1
@ -180,11 +181,27 @@ contains
if (current_batch == trace_batch .and. current_gen == trace_gen .and. &
p % id == trace_particle) trace = .true.
! Add paricle's starting weight to count for normalizing tallies later
total_weight = total_weight + src % wgt
end subroutine get_source_particle
!===============================================================================
! COPY_SOURCE_ATTRIBUTES
!===============================================================================
subroutine copy_source_attributes(src)
type(Bank), pointer :: src
! copy attributes from source bank site
p % wgt = src % wgt
p % last_wgt = src % wgt
p % coord % xyz = src % xyz
p % coord % uvw = src % uvw
p % last_xyz = src % xyz
p % E = src % E
p % last_E = src % E
end subroutine copy_source_attributes
!===============================================================================
! INITIALIZE_PARTICLE sets default attributes for a particle from the source
! bank