Determine which lambda grid point bounces at this theta/bmag value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(out), | dimension(-ntgrid:) | :: | jend |
subroutine calculate_jend(jend)
use theta_grid, only: ntgrid, bmag
use mp, only: mp_abort
implicit none
integer, dimension(-ntgrid:), intent(out) :: jend
integer :: ig, il
jend = 0
! jend(ig) is total # of valid al grid points at each theta value
!CMR, 1/11/2013:
! Above, with no trapped particles, we set: jend(ig)= 0
! Here, with trapped particles, we set: jend(ig)= il
! where il is the lambda index of the trapped particle bouncing at theta(ig)
! Note it might be better to set jend(ig) > nlambda if we have no
! trapped particles so il <= jend(ig) is always true for a particle
! which isn't forbidden. This would require a change in logic elsewhere
! Exit now if there are no trapped particles
if (.not. grid_has_trapped_particles()) return
do ig = -ntgrid, ntgrid
! We could initialise jend to ng2 and start this loop at ng2 + 1
! as we assume that all lambda up to and including with ng2 satisfy
! 1-lambda*bmag > -bouncefuzz for all theta. This is enforced/checked
! in [[calculate_forbidden_region]].
do il = 1, nlambda
if (1.0 - al(il)*bmag(ig) > -bouncefuzz) jend(ig) = jend(ig) + 1
end do
end do
end subroutine calculate_jend