FIXME : Add documentation
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
complex, | intent(in), | dimension (-ntgrid:,:,g_lo%llim_proc:) | :: | g | ||
real, | intent(in), | dimension (:) | :: | weights | ||
complex, | intent(out), | dimension (-ntgrid:,:,:,:) | :: | total |
subroutine lint_error (g, weights, total)
use theta_grid, only: ntgrid, bmag, bmax
use gs2_layouts, only: g_lo
use gs2_layouts, only: is_idx, ik_idx, it_idx, ie_idx, il_idx
use mp, only: sum_allreduce, proc0, broadcast
implicit none
complex, dimension (-ntgrid:,:,g_lo%llim_proc:), intent (in) :: g
real, dimension (:), intent (in) :: weights
complex, dimension (-ntgrid:,:,:,:), intent (out) :: total
integer :: is, il, ie, ik, it, iglo, ipt
!If the weights array hasn't been filled in then do so now
if (.not. allocated (wlmod)) then
!Allocate array, don't need to initialise as below loop ensures
!all elements are assigned a value
allocate (wlmod(-ntgrid:ntgrid,nlambda,ng2))
if (proc0) then
do ipt = 1, ng2
do il = 1, ng2
wlmod(:,il,ipt) = wlerr(il,ipt)*2.0*sqrt((bmag(:)/bmax) &
*((1.0/bmax-al(il))/(1.0/bmag(:)-al(il))))
end do
!If we have trapped particles use the precalculated weights
!in wlmod as above is only for passing particles
if (grid_has_trapped_particles()) wlmod(:,ng2+1:,ipt) = wl(:,ng2+1:)
end do
end if
!Now send the calculated value from proc0 to all other procs
!We could just do the above calculations on all procs?
call broadcast (wlmod)
end if
!Initialise to zero
total = 0.
!For each (passing) lambda point do velocity space integral
do ipt=1,ng2
do iglo = g_lo%llim_proc, g_lo%ulim_proc
ik = ik_idx(g_lo,iglo)
it = it_idx(g_lo,iglo)
ie = ie_idx(g_lo,iglo)
is = is_idx(g_lo,iglo)
il = il_idx(g_lo,iglo)
total(:, it, ik, ipt) = total(:, it, ik, ipt) + weights(is)*w(ie,is)*wlmod(:,il,ipt)*(g(:,1,iglo)+g(:,2,iglo))
end do
end do
!Moved this outside of the ipt loop above
call sum_allreduce (total)
end subroutine lint_error