Report Typos and Errors    
Semi-Lagrangian Library
Modular library for kinetic and gyrokinetic simulations of plasmas in fusion energy devices.
sll_m_gaussian.F90
Go to the documentation of this file.
1 
6 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7 #include "sll_memory.h"
8 #include "sll_working_precision.h"
9 
10  implicit none
11 
12  public :: &
15 
16  private
17 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
18 
19 contains
22 
28  sll_real64 :: sll_f_gaussian_deviate
29 
30  sll_real64 :: rsq, v(2)
31  sll_real64, save :: g
32  logical, save :: g_stored = .false.
33 
34  if (g_stored) then
36  g_stored = .false.
37  else
38  do
39  call random_number(v)
40  v(1) = 2._f64*v(1) - 1._f64
41  v(2) = 2._f64*v(2) - 1._f64
42  rsq = v(1)*v(1) + v(2)*v(2)
43  if (rsq < 1._f64) exit
44  end do
45  rsq = sqrt(-2._f64*log(rsq)/rsq)
46  sll_f_gaussian_deviate = v(1)*rsq
47  g = v(2)*rsq
48  g_stored = .true.
49  end if
50  end function sll_f_gaussian_deviate
51 
56  subroutine sll_s_gaussian_deviate_2d(res)
57  implicit none
58  sll_real64, intent(out) :: res(1:2)
59  sll_real64 :: rsq, v1, v2
60 
61  do
62  call random_number(v1)
63  call random_number(v2)
64  v1 = 2._f64*v1 - 1._f64
65  v2 = 2._f64*v2 - 1._f64
66  rsq = v1**2 + v2**2
67  if (rsq > 0._f64 .and. rsq < 1._f64) exit
68  end do
69  rsq = sqrt(-2._f64*log(rsq)/rsq)
70  res(1) = v1*rsq
71  res(2) = v2*rsq
72  end subroutine sll_s_gaussian_deviate_2d
73 
74 end module sll_m_gaussian
sll_m_gaussian random generator
real(kind=f64) function, public sll_f_gaussian_deviate()
Returns a value of a random variable in ONE dimension following the Gaussian probability density with...
subroutine, public sll_s_gaussian_deviate_2d(res)
Returns a value of a random variable in TWO dimensions following the Gaussian probability density wit...
    Report Typos and Errors