sphere Function

private function sphere(self, radius) result(xyz)

Sample point on a sphere with given radius

Type Bound

rng_t

Arguments

Type IntentOptional Attributes Name
class(rng_t), intent(inout) :: self
real(kind=dp), intent(in) :: radius

Return Value real(kind=dp), (3)


Calls

proc~~sphere~~CallsGraph proc~sphere rng_t%sphere proc~unif_01 rng_t%unif_01 proc~sphere->proc~unif_01 proc~next rng_t%next proc~unif_01->proc~next proc~rotl rotl proc~next->proc~rotl

Called by

proc~~sphere~~CalledByGraph proc~sphere rng_t%sphere proc~get_maxwellian_velocity get_maxwellian_velocity proc~get_maxwellian_velocity->proc~sphere

Source Code

  function sphere(self, radius) result(xyz)
    class(rng_t), intent(inout) :: self
    real(dp), intent(in)        :: radius
    real(dp)                    :: rands(2), xyz(3)
    real(dp)                    :: sum_sq, tmp_sqrt

    ! Marsaglia method for uniform sampling on sphere
    do
       rands(1) = 2 * self%unif_01() - 1
       rands(2) = 2 * self%unif_01() - 1
       sum_sq   = sum(rands**2)
       if (sum_sq <= 1) exit
    end do

    tmp_sqrt = sqrt(1 - sum_sq)
    xyz(1:2) = 2 * rands(1:2) * tmp_sqrt
    xyz(3)   = 1 - 2 * sum_sq
    xyz      = xyz * radius
  end function sphere