Report Typos and Errors    
Semi-Lagrangian Library
Modular library for kinetic and gyrokinetic simulations of plasmas in fusion energy devices.
sll_m_particle_initializers_2d.F90
Go to the documentation of this file.
1 !**************************************************************
2 ! Copyright INRIA
3 ! Authors :
4 ! CALVI project team
5 !
6 ! This code SeLaLib (for Semi-Lagrangian-Library)
7 ! is a parallel library for simulating the plasma turbulence
8 ! in a tokamak.
9 !
10 ! This software is governed by the CeCILL-B license
11 ! under French law and abiding by the rules of distribution
12 ! of free software. You can use, modify and redistribute
13 ! the software under the terms of the CeCILL-B license as
14 ! circulated by CEA, CNRS and INRIA at the following URL
15 ! "http://www.cecill.info".
16 !**************************************************************
17 
19 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
20 #include "sll_assert.h"
21 #include "sll_memory.h"
22 #include "sll_working_precision.h"
23 #include "sll_particle_representation.h"
24 
25  use sll_m_cartesian_meshes, only: &
27 
28  use sll_m_constants, only: &
29  sll_p_pi
30 
31  use sll_m_hammersley, only: &
33 
34  use sll_m_particle_group_2d, only: &
36 
37  implicit none
38 
39  public :: &
42 
43  private
44 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
45 
46 contains
47 
49  alpha, kx, &
50  m2d, &
51  num_particles, &
52  p_group, &
53  rand_seed, rank, worldsize)
54  sll_real64, intent(in) :: alpha, kx
55  type(sll_t_cartesian_mesh_2d), intent(in) :: m2d
56  sll_int32, intent(in) :: num_particles
57  type(sll_t_particle_group_2d), pointer, intent(inout) :: p_group
58  sll_int32 :: j
59  sll_int32 :: ncx, ic_x, ic_y
60  sll_real64 :: x, y, z
61  sll_real64 :: xmin, ymin, rdx, rdy
62  sll_real32 :: weight
63  sll_real32 :: off_x, off_y
64  sll_real64 :: tmp1, tmp2
65  sll_int32, dimension(:), intent(in), optional :: rand_seed
66  sll_int32, optional :: rank, worldsize
67 !!$ character(len=8) :: rank_name
68 !!$ character(len=40) :: nomfile
69 
70  if (present(rand_seed)) then
71  call random_seed(put=rand_seed)
72  end if
73  if (present(worldsize)) then
74  weight = real((1.0 + alpha)*(m2d%eta1_max - m2d%eta1_min)* &
75  (m2d%eta2_max - m2d%eta2_min), f32)/real(worldsize*num_particles, f32)
76  else
77  weight = real((1.0 + alpha)*(m2d%eta1_max - m2d%eta1_min)* &
78  (m2d%eta2_max - m2d%eta2_min), f32)/real(num_particles, f32)
79  end if
80 
81  rdx = 1._f64/m2d%delta_eta1
82  rdy = 1._f64/m2d%delta_eta2
83  xmin = m2d%eta1_min
84  ymin = m2d%eta2_min
85  ncx = m2d%num_cells1
86 
87 !!$ if(present(rank)) then
88 !!$ write(rank_name,'(i8)') rank
89 !!$ else
90 !!$ rank_name = '00000000'
91 !!$ end if
92 !!$ nomfile='initialparts_'//trim(adjustl(rank_name))//'.dat'
93 !!$ open(90, file=nomfile)
94 !!$
95 !!$ write(90,*) '# POSITIONS in 2d'
96 
97  j = 1
98  !Rejection sampling for the function 1 + alp + alp*cos(k*x) + sin(y)
99  do while (j <= num_particles)
100  call random_number(x)
101  x = (m2d%eta1_max - xmin)*x + xmin
102  call random_number(y)
103  y = (m2d%eta2_max - ymin)*y + ymin
104  call random_number(z)
105  z = (2.0_f64 + 2.0_f64*alpha)*z
106  if (sll_f_eval_kh(alpha, kx, x, y) >= z) then
107 ! write(90,*) x, y
108  set_2dparticle_values(p_group%p_list(j), x, y, weight, xmin, ymin, ncx, ic_x, ic_y, off_x, off_y, rdx, rdy, tmp1, tmp2)
109  j = j + 1
110  end if
111  end do
112 ! close(90)
113  return
114  sll_assert(present(rank))
115 
117 
119  alpha, k, &
120  m2d, &
121  num_particles, &
122  p_group, &
123  rand_seed, rank, worldsize)
124  sll_real64, intent(in) :: alpha, k
125  type(sll_t_cartesian_mesh_2d), intent(in) :: m2d
126  sll_int32, intent(in) :: num_particles
127  type(sll_t_particle_group_2d), pointer, intent(inout) :: p_group
128  sll_int32 :: j
129  sll_int32 :: ncx, ic_x, ic_y
130  sll_real64 :: x, y, xmin, ymin, rdx, rdy
131  sll_real32 :: weight
132  sll_real32 :: off_x, off_y
133  sll_real64 :: tmp1, tmp2
134  sll_int32, dimension(:), intent(in), optional :: rand_seed
135  sll_int32, optional :: rank, worldsize
136 
137  if (present(rand_seed)) then
138  call random_seed(put=rand_seed)
139  end if
140 
141  if (present(worldsize)) then
142  weight = real(m2d%eta1_max - m2d%eta1_min, f32)* &
143  real(m2d%eta2_max - m2d%eta2_min, f32)/ &
144  real(worldsize*num_particles, f32)
145  else
146  weight = real(m2d%eta1_max - m2d%eta1_min, f32)* &
147  real(m2d%eta2_max - m2d%eta2_min, f32)/ &
148  real(num_particles, f32)
149  end if
150  rdx = 1._f64/m2d%delta_eta1
151  rdy = 1._f64/m2d%delta_eta2
152  xmin = m2d%eta1_min
153  ymin = m2d%eta2_min
154  ncx = m2d%num_cells1
155 
156  j = 1
157  do while (j <= num_particles)
158  call random_number(x)
159  x = (m2d%eta1_max - xmin)*x + xmin
160  call random_number(y)
161  y = (1._f64 + alpha)*y
162  if (sll_f_eval_landau(alpha, k, x) >= y) then
163  call random_number(y)
164  y = (m2d%eta2_max - ymin)*y + ymin
165  set_2dparticle_values(p_group%p_list(j), x, y, weight, xmin, ymin, ncx, ic_x, ic_y, off_x, off_y, rdx, rdy, tmp1, tmp2)
166  j = j + 1
167  end if
168  end do
169 
170  return
171  sll_assert(present(rank))
172  end subroutine sll_s_initial_random_particles_2d
173 
174  function sll_f_eval_landau(alp, kx, x)
175  sll_real64 :: alp, kx, x
176  sll_real64 :: sll_f_eval_landau
177 
178  sll_f_eval_landau = 1._f64 + alp*cos(kx*x)
179  end function sll_f_eval_landau
180 
181  function sll_f_eval_kh(alp, kx, x, y)
182  sll_real64 :: x, y, alp, kx
183  sll_real64 :: sll_f_eval_kh
184 
185  sll_f_eval_kh = 1.0_f64 + alp + sin(y) + alp*cos(kx*x)
186  end function sll_f_eval_kh
187 
Cartesian mesh basic types.
Fortran module where set some physical and mathematical constants.
real(kind=f64), parameter, public sll_p_pi
hamm pseudo-random generator
real(kind=f64) function, public sll_f_suite_hamm(n, b)
subroutine, public sll_s_initial_random_particles_2d(alpha, k, m2d, num_particles, p_group, rand_seed, rank, worldsize)
real(kind=f64) function sll_f_eval_landau(alp, kx, x)
subroutine, public sll_s_initial_random_particles_2d_kh(alpha, kx, m2d, num_particles, p_group, rand_seed, rank, worldsize)
real(kind=f64) function sll_f_eval_kh(alp, kx, x, y)
    Report Typos and Errors