FIXME : Add documentation
returns results to PE 0 [or to all processors if 'all' is present in input arg list] NOTE: Takes f = f(y, lambda, E, species) and returns int sum_{ky} f, where the integral is over energy and lambda (not sigma)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
complex, | intent(in), | dimension (p_lo%llim_proc:) | :: | g | ||
integer, | intent(in) | :: | ig | |||
complex, | intent(out), | dimension (:) | :: | total | ||
integer, | intent(in), | optional | :: | all |
subroutine integrate_kysum (g, ig, total, all)
use species, only: nspec
use kt_grids, only: aky
use constants, only: zi
use gs2_layouts, only: is_idx, ik_idx, ie_idx, il_idx, p_lo
use mp, only: sum_reduce, sum_allreduce, nproc
use array_utils, only: zero_array
implicit none
complex, dimension (p_lo%llim_proc:), intent (in) :: g
integer, intent (in) :: ig
complex, dimension (:), intent (out) :: total
integer, optional, intent(in) :: all
complex, dimension (negrid,nlambda,nspec) :: gksum
integer :: is, il, ie, ik, iplo
!Initialise both arrays to zero
call zero_array(total) ; call zero_array(gksum)
do iplo = p_lo%llim_proc, p_lo%ulim_proc
ik = ik_idx(p_lo,iplo)
ie = ie_idx(p_lo,iplo)
is = is_idx(p_lo,iplo)
il = il_idx(p_lo,iplo)
gksum(ie,il,is) = gksum(ie,il,is) + real(aky(ik)*g(iplo)) + zi*aimag(aky(ik)*g(iplo))
end do
! real part of gksum is | sum_{ky} ky * J0 * real[ ky*(conjg(phi+)*h- + conjg(phi-)*h+ ] |**2
! imag part of gksum is | sum_{ky} ky * J0 * aimag[ ky*(conjg(phi+)*h- + conjg(phi-)*h+ ] |**2
gksum = real(gksum)**2 + zi*aimag(gksum)**2
do iplo = p_lo%llim_proc, p_lo%ulim_proc
ie = ie_idx(p_lo,iplo)
is = is_idx(p_lo,iplo)
il = il_idx(p_lo,iplo)
total(is) = total(is) + w(ie,is)*wl(ig,il)*gksum(ie,il,is)
end do
!Do we really need this if?
if (nproc > 1) then
if (present(all)) then
call sum_allreduce (total)
else
call sum_reduce (total, 0)
end if
end if
end subroutine integrate_kysum