is_lower_bounce_point Function

public elemental function is_lower_bounce_point(ig, il) result(is_lower)

Uses

Returns true if the passed theta grid index, ig, is a lower bounce point for the passed pitch angle index, il.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: ig
integer, intent(in) :: il

Return Value logical


Contents

Source Code


Source Code

  elemental logical function is_lower_bounce_point(ig, il) result(is_lower)
    use theta_grid, only: ntgrid
    implicit none
    integer, intent(in) :: ig, il
    is_lower = .false.

    ! A lower bounce point firstly has to be a bounce point
    if (.not. is_bounce_point(ig, il)) return

    ! Special handling for wfb, only bounce for trapped_wfb Currently
    ! this doesn't activate as wfb don't have bounce points flagged in
    ! is_bounce_point.
    if (il_is_wfb(il) .and. .not. trapped_wfb) return

    ! If we're at the lower end of the grid then it is a lower bounce
    ! point (if it's a bounce point). If not at the lower end of the
    ! theta grid, the magnetic field at the previous theta grid point
    ! must be higher than this one. Note we can't chain checks
    ! together as there's no short-circuiting so if ig==-ntgrid we don't
    ! want to access bmag(ig-1)
    if (ig == -ntgrid) then
       is_lower = .true.
    elseif (ig == ntgrid) then
       is_lower = .false.
    else
       ! The commented out below code is fine for non-wfb like particles (those
       ! which have bounce points which are both upper and lower bounce points, i.e.
       ! those without a fobidden region separating allowed regions).
       ! is_lower = bmag(ig-1) > bmag(ig)

       ! Instead we simply check if the _next_ theta grid point is part of an allowed
       ! region. This works for all pitch angles _except_ totally trapped particles.
       !is_lower = .not. forbid(ig + 1, il) .or. &
       !     (forbid(ig - 1, il) .and. forbid(ig + 1, il)) ! For totally trapped particles

       ! For now we choose to invert this logic and check if the _previous_ theta grid point
       ! is forbidden. This means that internal wfb-like bounce points are not detected
       ! as having an upper bounce point. This is a temporary work around to maintain
       ! old behaviour whilst we improve our trapped particle handling. See issues 148
       ! and 239
       is_lower = forbid(ig - 1, il) .or. &
            (forbid(ig - 1, il) .and. forbid(ig + 1, il)) ! For totally trapped particles
    end if

  end function is_lower_bounce_point