merge_reservoirs Subroutine

public subroutine merge_reservoirs(res1, res2)

Merge reservoir 2 into reservoir 1

Arguments

TypeIntentOptionalAttributesName
type(NeutralParticleReservoir), intent(inout) :: res1

Reservoir 1

type(NeutralParticleReservoir), intent(inout) :: res2

Reservoir 2


Calls

proc~~merge_reservoirs~~CallsGraph proc~merge_reservoirs merge_reservoirs proc~init_reservoir init_reservoir proc~merge_reservoirs->proc~init_reservoir proc~update_reservoir update_reservoir proc~merge_reservoirs->proc~update_reservoir float float proc~merge_reservoirs->float interface~randu randu proc~merge_reservoirs->interface~randu proc~init_reservoir->interface~randu proc~update_reservoir->proc~init_reservoir proc~update_reservoir->interface~randu interface~randind randind proc~update_reservoir->interface~randind

Called by

proc~~merge_reservoirs~~CalledByGraph proc~merge_reservoirs merge_reservoirs proc~merge_neutral_populations merge_neutral_populations proc~merge_neutral_populations->proc~merge_reservoirs proc~parallel_merge_reservoirs parallel_merge_reservoirs proc~parallel_merge_reservoirs->proc~merge_reservoirs proc~dcx dcx proc~dcx->proc~parallel_merge_reservoirs proc~parallel_merge_populations parallel_merge_populations proc~dcx->proc~parallel_merge_populations proc~fida_f fida_f proc~fida_f->proc~parallel_merge_reservoirs proc~pfida_f pfida_f proc~pfida_f->proc~parallel_merge_reservoirs proc~halo halo proc~halo->proc~merge_neutral_populations proc~halo->proc~parallel_merge_reservoirs proc~halo->proc~parallel_merge_populations proc~pfida_mc pfida_mc proc~pfida_mc->proc~parallel_merge_reservoirs proc~parallel_merge_populations->proc~parallel_merge_reservoirs proc~fida_mc fida_mc proc~fida_mc->proc~parallel_merge_reservoirs program~fidasim fidasim program~fidasim->proc~dcx program~fidasim->proc~fida_f program~fidasim->proc~pfida_f program~fidasim->proc~halo program~fidasim->proc~pfida_mc program~fidasim->proc~fida_mc proc~ndmc ndmc program~fidasim->proc~ndmc proc~ndmc->proc~parallel_merge_populations

Contents

Source Code


Source Code

subroutine merge_reservoirs(res1,res2)
    !+ Merge reservoir 2 into reservoir 1
    type(NeutralParticleReservoir), intent(inout) :: res1
        !+ Reservoir 1
    type(NeutralParticleReservoir), intent(inout) :: res2
        !+ Reservoir 2

    integer :: i
    type(NeutralParticleReservoir) :: res3
    real(Float64) :: p, randomu(1)

    if(res1%n.le.0) then
        call init_reservoir(res1) !res2%k)
    endif
    if(res2%n.le.0) return

    !! If neither reservoir is full just fill res1 from res2 normally
    if ((res1%n.le.res1%k).and.(res2%n.le.res2%k)) then
        do i=1,res2%n
            call update_reservoir(res1, res2%R(i)%v, res2%R(i)%w)
        enddo
        res2 = res1
        return
    endif

    !! Switch res1 with res2 if res1 is not full but res2 is
    if (res1%n.le.res1%k) then
        res3 = res1
        res1 = res2
        res2 = res3
    endif

    !! if res2 is not full then fill res1 from res2 normally
    if (res2%n.le.res2%k) then
        do i=1,res2%n
            call update_reservoir(res1, res2%R(i)%v, res2%R(i)%w)
        enddo
    else !! if both are full select particles from res2 according to # particles seen
        p = float(res1%n)/(res1%n + res2%n)
        do i=1,res1%k
            call randu(randomu)
            if(randomu(1).gt.p) then
                res1%R(i) = res2%R(i)
            endif
        enddo
    endif
    !! set res1 to res2
    res2 = res1

end subroutine merge_reservoirs