Report Typos and Errors    
Semi-Lagrangian Library
Modular library for kinetic and gyrokinetic simulations of plasmas in fusion energy devices.
sll_m_gyroaverage_utilities.F90
Go to the documentation of this file.
2 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 #include "sll_memory.h"
4 #include "sll_working_precision.h"
5 
6  use sll_m_constants, only: &
8 
12 
16 
17  implicit none
18 
19  public :: &
24 
25  private
26 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
27 
28 contains
29 
30  subroutine sll_s_compute_shape_circle(points, N_points)
31  sll_int32, intent(in) :: n_points
32  sll_real64, dimension(:, :) ::points
33  sll_int32 :: i
34  sll_real64 :: x
35  do i = 1, n_points
36  x = 2._f64*sll_p_pi*real(i, f64)/(real(n_points, f64))
37  points(1, i) = cos(x)
38  points(2, i) = sin(x)
39  points(3, i) = 1._f64/real(n_points, f64)
40  end do
41 
42  end subroutine sll_s_compute_shape_circle
43 
44  subroutine sll_s_compute_init_f_polar(f, mode, N, eta_min, eta_max)
45  sll_real64, dimension(:, :), intent(out)::f
46  sll_int32, intent(in)::n(2), mode(2)
47  sll_real64, intent(in)::eta_min(2), eta_max(2)
48  sll_int32::i, j
49  sll_real64::eta(2), delta_eta(2), kmode, val
50 
51  call sll_s_zero_bessel_dir_dir(mode, eta_min(1), eta_max(1), val)
52  delta_eta(1) = (eta_max(1) - eta_min(1))/real(n(1), f64)
53  delta_eta(2) = (eta_max(2) - eta_min(2))/real(n(2), f64)
54 
55  kmode = real(mode(2), f64)*(2._f64*sll_p_pi)/(eta_max(2) - eta_min(2))
56 
57  do j = 1, n(2) + 1
58  eta(2) = eta_min(2) + real(j - 1, f64)*delta_eta(2)
59  do i = 1, n(1) + 1
60  eta(1) = eta_min(1) + real(i - 1, f64)*delta_eta(1)
61  eta(1) = val*eta(1)/eta_max(1)
62  f(i, j) = 0._f64 !temporary, because DBESJ not recognized on helios & curie
63  !f(i,j)=cos(kmode*eta(2))
64  !f(i,j) = (DBESJN(mode(2),val)*DBESYN(mode(2),eta(1))-DBESYN(mode(2),val)*DBESJN(mode(2),eta(1)))*cos(kmode*eta(2))
65  end do
66  end do
67 
68  end subroutine sll_s_compute_init_f_polar
69 
70  subroutine sll_s_zero_bessel_dir_dir(mode, eta_min, eta_max, val)
71  sll_real64, intent(in)::eta_min, eta_max
72  sll_int32, intent(in)::mode(2)
73  sll_real64, intent(out)::val
74  sll_real64::alpha, tmp
75  sll_int32::mode_max(2), i, j
76  logical::is_file
77  val = 0._f64
78  INQUIRE (file="zeros_bessel.txt", exist=is_file)
79  if ((is_file) .eqv. (.false.)) then
80  print *, '#file zeros_bessel.txt does not exist'
81  return
82  end if
83  open (27, file='zeros_bessel.txt', action="read")
84  read (27, *) mode_max(1), mode_max(2), alpha
85  close (27)
86  if ((mode(1) < 1) .or. (mode(1) > mode_max(1))) then
87  print *, '#bad value of mode(1) vs mode_max(1)', mode(1), mode_max(1)
88  return
89  end if
90  if ((mode(2) < 0) .or. (mode(2) > mode_max(2))) then
91  print *, '#bad value of mode(2) vs mode_max(2)', mode(2), mode_max(2)
92  return
93  end if
94  if (abs(alpha - eta_min/eta_max) > 1.e-12) then
95  print *, '#bad value of rmin/rmax w.r.t zeros_bessel.txt', eta_min/eta_max, alpha
96  return
97  end if
98  open (27, file='zeros_bessel.txt', action="read")
99  read (27, *) mode_max(1), mode_max(2), alpha
100  read (27, *) i, j, tmp
101  do while ((i .ne. mode(1)) .or. (j .ne. mode(2)))
102  read (27, *) i, j, tmp
103  end do
104  close (27)
105  val = tmp
106 
107  end subroutine sll_s_zero_bessel_dir_dir
108 
109  subroutine sll_s_compute_mu( &
110  quadrature_case, &
111  mu_points, &
112  mu_weights, &
113  N_mu, &
114  mu_min, &
115  mu_max, &
116  quadrature_points_per_cell)
117  character(len=256), intent(in) :: quadrature_case
118  sll_real64, dimension(:), intent(out) :: mu_points
119  sll_real64, dimension(:), intent(out) :: mu_weights
120  sll_int32, intent(in) :: n_mu
121  sll_real64, intent(in) :: mu_min
122  sll_real64, intent(in) :: mu_max
123  sll_int32, intent(in) :: quadrature_points_per_cell
124  sll_int32 :: i
125  sll_int32 :: s
126  sll_int32 :: num_cells
127 
128  select case (quadrature_case)
129  case ("SLL_RECTANGLE")
130  do i = 1, n_mu
131  mu_points(i) = mu_min + real(i - 1, f64)*(mu_max - mu_min)/real(n_mu, f64)
132  mu_weights(i) = (mu_max - mu_min)/real(n_mu, f64)*exp(-mu_points(i))
133  end do
134  if (n_mu == 1) then
135  mu_weights(1) = 1._f64
136  end if
137  case ("SLL_GAUSS_LOBATTO")
138  num_cells = n_mu/quadrature_points_per_cell
139  mu_points(1:n_mu) = mu_max
140  mu_weights(1:n_mu) = 0._f64
141  s = 1
142  do i = 1, num_cells
143  mu_points(s:s + quadrature_points_per_cell - 1) = &
145  quadrature_points_per_cell, &
146  mu_min + real(i - 1, f64)/real(num_cells, f64)*(mu_max - mu_min), &
147  mu_min + real(i, f64)/real(num_cells, f64)*(mu_max - mu_min))
148  mu_weights(s:s + quadrature_points_per_cell - 1) = &
150  quadrature_points_per_cell, &
151  mu_min + real(i - 1, f64)/real(num_cells, f64)*(mu_max - mu_min), &
152  mu_min + real(i, f64)/real(num_cells, f64)*(mu_max - mu_min))
153  s = s + quadrature_points_per_cell
154  end do
155  !mu_points(1:N_mu) = sll_f_gauss_lobatto_points( N_mu, 0._f64, mu_max )
156  !mu_weights(1:N_mu) = sll_f_gauss_lobatto_weights( N_mu, 0._f64, mu_max )
157  do i = 1, n_mu
158  mu_weights(i) = mu_weights(i)*exp(-mu_points(i))
159  end do
160  case ("SLL_GAUSS_LEGENDRE")
161  num_cells = n_mu/quadrature_points_per_cell
162  mu_points(1:n_mu) = mu_max
163  mu_weights(1:n_mu) = 0._f64
164  s = 1
165  do i = 1, num_cells
166  mu_points(s:s + quadrature_points_per_cell - 1) = &
168  quadrature_points_per_cell, &
169  mu_min + real(i - 1, f64)/real(num_cells, f64)*(mu_max - mu_min), &
170  mu_min + real(i, f64)/real(num_cells, f64)*(mu_max - mu_min))
171  mu_weights(s:s + quadrature_points_per_cell - 1) = &
173  quadrature_points_per_cell, &
174  mu_min + real(i - 1, f64)/real(num_cells, f64)*(mu_max - mu_min), &
175  mu_min + real(i, f64)/real(num_cells, f64)*(mu_max - mu_min))
176  s = s + quadrature_points_per_cell
177  end do
178  !mu_points(1:N_mu) = sll_f_gauss_lobatto_points( N_mu, 0._f64, mu_max )
179  !mu_weights(1:N_mu) = sll_f_gauss_lobatto_weights( N_mu, 0._f64, mu_max )
180  do i = 1, n_mu
181  mu_weights(i) = mu_weights(i)*exp(-mu_points(i))
182  end do
183  case default
184  print *, '#bad quadrature_case', trim(quadrature_case)
185  print *, '#not implemented'
186  print *, '#in sll_s_compute_mu'
187  print *, '#at line and file:', __line__, __file__
188  stop
189  end select
190 
191  end subroutine sll_s_compute_mu
192 
Fortran module where set some physical and mathematical constants.
real(kind=f64), parameter, public sll_p_pi
real(kind=f64) function, dimension(1:npoints), public sll_f_gauss_legendre_points(npoints, a, b)
real(kind=f64) function, dimension(1:npoints), public sll_f_gauss_legendre_weights(npoints, a, b)
real(kind=f64) function, dimension(n), public sll_f_gauss_lobatto_points(n, a, b)
Returns a 1d array of size (n) containing gauss-lobatto points in the interval [a,...
real(kind=f64) function, dimension(n), public sll_f_gauss_lobatto_weights(n, a, b)
Returns a 1d array of size (n) containing gauss-lobatto weights in the interval [a,...
subroutine, public sll_s_compute_init_f_polar(f, mode, N, eta_min, eta_max)
subroutine, public sll_s_compute_shape_circle(points, N_points)
subroutine, public sll_s_zero_bessel_dir_dir(mode, eta_min, eta_max, val)
subroutine, public sll_s_compute_mu(quadrature_case, mu_points, mu_weights, N_mu, mu_min, mu_max, quadrature_points_per_cell)
    Report Typos and Errors