prefer_periodic_candidate Function

public pure function prefer_periodic_candidate(t, elem_idx, image_shift, best_hit)

候補 hit が現在の best より優先されるかを deterministic に判定する。

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(in) :: t
integer(kind=i32), intent(in) :: elem_idx
integer(kind=i32), intent(in) :: image_shift(2)
type(hit_info), intent(in) :: best_hit

Return Value logical


Called by

proc~~prefer_periodic_candidate~~CalledByGraph proc~prefer_periodic_candidate prefer_periodic_candidate proc~find_first_hit_periodic2 find_first_hit_periodic2 proc~find_first_hit_periodic2->proc~prefer_periodic_candidate proc~find_first_hit find_first_hit proc~find_first_hit->proc~find_first_hit_periodic2 proc~sample_photo_raycast_particles sample_photo_raycast_particles proc~sample_photo_raycast_particles->proc~find_first_hit proc~sample_photo_species_state sample_photo_species_state proc~sample_photo_species_state->proc~sample_photo_raycast_particles proc~init_particle_batch_from_config init_particle_batch_from_config proc~init_particle_batch_from_config->proc~sample_photo_species_state

Source Code

  pure logical function prefer_periodic_candidate(t, elem_idx, image_shift, best_hit)
    real(dp), intent(in) :: t
    integer(i32), intent(in) :: elem_idx, image_shift(2)
    type(hit_info), intent(in) :: best_hit
    real(dp) :: tol

    if (.not. best_hit%has_hit) then
      prefer_periodic_candidate = .true.
      return
    end if

    tol = 1.0d-12*max(1.0d0, abs(t), abs(best_hit%t))
    if (t < best_hit%t - tol) then
      prefer_periodic_candidate = .true.
      return
    end if
    if (t > best_hit%t + tol) then
      prefer_periodic_candidate = .false.
      return
    end if

    if (elem_idx < best_hit%elem_idx) then
      prefer_periodic_candidate = .true.
      return
    end if
    if (elem_idx > best_hit%elem_idx) then
      prefer_periodic_candidate = .false.
      return
    end if

    if (image_shift(1) < best_hit%image_shift(1)) then
      prefer_periodic_candidate = .true.
    else if (image_shift(1) > best_hit%image_shift(1)) then
      prefer_periodic_candidate = .false.
    else
      prefer_periodic_candidate = image_shift(2) < best_hit%image_shift(2)
    end if
  end function prefer_periodic_candidate