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 trap_error (g, weights, total)
use theta_grid, only: ntgrid
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, ntrap
!How many trapped pitch angles are there?
ntrap = nlambda - ng2
!If weights not calculated yet do so now
if (.not. allocated(wtmod)) then
!Allocate array, don't need to initialise as below loops
!ensure every element is assigned a value
allocate (wtmod(-ntgrid:ntgrid,nlambda,ntrap))
if (proc0) then
do ipt=1,ntrap
wtmod(:,:ng2,ipt) = wl(:,:ng2)
end do
!Left below comments, but are we done testing this now?
! next line only to be used when testing!!!!
! wtmod(:,:ng2,:) = 0.
wtmod(:,ng2+1:,:) = wlterr(:,ng2+1:,:)
endif
!Send from proc0 to all others | We could just do the above calculations on all procs?
call broadcast (wtmod)
end if
!Initialise to zero
total = 0.
!Loop over number of trapped points
do ipt=1,ntrap
!Do local velocity integral
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)*wtmod(:,il,ipt)*(g(:,1,iglo)+g(:,2,iglo))
end do
end do
!Moved this out of ipt loop above
call sum_allreduce (total)
end subroutine trap_error