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 eint_error (g, weights, total)
use theta_grid, only: ntgrid
use species, only: nspec
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 we don't have the weights then calculate them now
if (.not. allocated(wmod)) then
!Allocate array, don't initialise as we fill in all values below
allocate (wmod(negrid,wdim,nspec))
if (proc0) then
wmod(:negrid-1,:,:) = werr(:,:,:)
do is = 1,nspec
wmod(negrid,:,is) = w(negrid,is)
end do
end if
!send from proc0 to everywhere else
call broadcast(wmod)
end if
!Initialise to zero
total=0.
!Do velocity space integral for each ipt (for all energy grid points)
do ipt=1,wdim
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)*wmod(ie,ipt,is)*wl(:,il)*(g(:,1,iglo)+g(:,2,iglo))
end do
end do
!Moved this out of the above loop over ipt
call sum_allreduce (total)
end subroutine eint_error