Report Typos and Errors    
Semi-Lagrangian Library
Modular library for kinetic and gyrokinetic simulations of plasmas in fusion energy devices.
sll_m_charge_to_density.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_memory.h"
21 #include "sll_working_precision.h"
22 #include "sll_accumulators.h"
23 
24  use sll_m_accumulators, only: &
29 
30  implicit none
31 
32  public :: &
37 
38  private
39 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
40 
41 contains
42 
44  type(sll_t_charge_accumulator_2d) :: charge
45  sll_real64, dimension(:, :), intent(out) :: rho
46  sll_int32 :: i
47  sll_int32 :: j
48  sll_int32 :: ncx
49  sll_int32 :: ncy
50  sll_real64 :: deltax
51  sll_real64 :: deltay
52  sll_real64 :: factor
53 
54  ncx = charge%mesh%num_cells1
55  ncy = charge%mesh%num_cells2
56  deltax = charge%mesh%delta_eta1
57  deltay = charge%mesh%delta_eta2
58  factor = 1.0_f64/(deltax*deltay)
59 ! REMEMBER : charge is the charge MASS and not the charge DENSITY
60 ! this explains the *factor.
61  ! loop over the node indices of rho. Edges might need special treatment,
62  ! thus do the non-edge nodes first.
63  do j = 2, ncy
64  do i = 2, ncx
65  rho(i, j) = sll_get_charge_acc_value(charge, i, j, q_sw) + &
66  sll_get_charge_acc_value(charge, i - 1, j, q_se) + &
67  sll_get_charge_acc_value(charge, i - 1, j - 1, q_ne) + &
68  sll_get_charge_acc_value(charge, i, j - 1, q_nw)
69  rho(i, j) = rho(i, j)*factor
70  end do
71  end do
72 
73  do j = 2, ncy
74  rho(1, j) = sll_get_charge_acc_value(charge, 1, j, q_sw) + &
75  sll_get_charge_acc_value(charge, 1, j - 1, q_nw) + &
76  sll_get_charge_acc_value(charge, ncx, j, q_se) + &
77  sll_get_charge_acc_value(charge, ncx, j - 1, q_ne)
78  rho(1, j) = rho(1, j)*factor
79  rho(ncx + 1, j) = rho(1, j)
80  end do
81 
82  do i = 2, ncx
83  rho(i, 1) = sll_get_charge_acc_value(charge, i - 1, 1, q_se) + &
84  sll_get_charge_acc_value(charge, i, 1, q_sw) + &
85  sll_get_charge_acc_value(charge, i - 1, ncy, q_ne) + &
86  sll_get_charge_acc_value(charge, i, ncy, q_nw)
87  rho(i, 1) = rho(i, 1)*factor
88  rho(i, ncy + 1) = rho(i, 1)
89  end do
90 
91  rho(1, 1) = sll_get_charge_acc_value(charge, 1, 1, q_sw) + &
92  sll_get_charge_acc_value(charge, 1, ncy, q_nw) + &
93  sll_get_charge_acc_value(charge, ncx, 1, q_se) + &
94  sll_get_charge_acc_value(charge, ncx, ncy, q_ne)
95  rho(1, 1) = rho(1, 1)*factor
96  rho(1, ncy + 1) = rho(1, 1)
97  rho(ncx + 1, 1) = rho(1, 1)
98  rho(ncx + 1, ncy + 1) = rho(1, 1)
99 !!$ density = 0.0_f64
100 !!$ do k = 1, ncx * ncy
101 !!$ i = mod( k-1, ncx ) + 1
102 !!$ j = int((k-1)/ncx ) + 1
103 !!$ density(i ,j ) = density(i, j) + all_charge(k)%q_sw
104 !!$ density(i+1,j ) = density(i+1,j) + all_charge(k)%q_se
105 !!$ density(i ,j+1) = density(i, j+1) + all_charge(k)%q_nw
106 !!$ density(i+1,j+1) = density(i+1,j+1) + all_charge(k)%q_ne
107 !!$ enddo
109 
111  type(sll_t_charge_accumulator_2d_cs) :: charge
112  sll_real64, dimension(:, :), intent(out) :: rho
113  sll_int32 :: i, im1, im2, ip1
114  sll_int32 :: j, jm1, jm2, jp1! k
115  sll_int32 :: ncx
116  sll_int32 :: ncy
117  sll_real64 :: deltax
118  sll_real64 :: deltay
119  sll_real64 :: factor
120 
121  ncx = charge%mesh%num_cells1
122  ncy = charge%mesh%num_cells2
123  deltax = charge%mesh%delta_eta1
124  deltay = charge%mesh%delta_eta2
125  factor = 1.0_f64/(deltax*deltay)
126 ! REMEMBER : charge is just the charge MASS and not the charge DENSITY
127 ! this explains the *factor.
128  do j = 1, ncy
129  jp1 = j + 1
130  jm1 = j - 1
131  jm2 = j - 2
132  if (j == 1) then
133  jm1 = ncy
134  jm2 = ncy - 1
135  end if
136  if (j == 2) then
137  jm2 = ncy
138  end if
139  if (j == ncy) then
140  jp1 = 1
141  end if
142  do i = 1, ncx! k = i+(j-1)*ncx
143  ip1 = i + 1
144  im1 = i - 1
145  im2 = i - 2
146  if (i == 1) then
147  im1 = ncx
148  im2 = ncx - 1
149  end if
150  if (i == 2) then
151  im2 = ncx
152  end if
153  if (i == ncx) then
154  ip1 = 1
155  end if
156  rho(i, j) = charge%q_acc(im1 + (jm1 - 1)*ncx)%q_ip1jp1 + &
157  charge%q_acc(i + (jm1 - 1)*ncx)%q_ijp1 + &
158  charge%q_acc(i + (j - 1)*ncx)%q_ij + &
159  charge%q_acc(im1 + (j - 1)*ncx)%q_ip1j + &
160  charge%q_acc(im2 + (jm2 - 1)*ncx)%q_ip2jp2 + &
161  charge%q_acc(im1 + (jm2 - 1)*ncx)%q_ip1jp2 + &
162  charge%q_acc(i + (jm2 - 1)*ncx)%q_ijp2 + &
163  charge%q_acc(ip1 + (jm2 - 1)*ncx)%q_im1jp2 + &
164  charge%q_acc(ip1 + (jm1 - 1)*ncx)%q_im1jp1 + &
165  charge%q_acc(ip1 + (j - 1)*ncx)%q_im1j + &
166  charge%q_acc(ip1 + (jp1 - 1)*ncx)%q_im1jm1 + &
167  charge%q_acc(i + (jp1 - 1)*ncx)%q_ijm1 + &
168  charge%q_acc(im1 + (jp1 - 1)*ncx)%q_ip1jm1 + &
169  charge%q_acc(im2 + (jp1 - 1)*ncx)%q_ip2jm1 + &
170  charge%q_acc(im2 + (j - 1)*ncx)%q_ip2j + &
171  charge%q_acc(im2 + (jm1 - 1)*ncx)%q_ip2jp1
172  rho(i, j) = rho(i, j)*factor
173  rho(i, ncy + 1) = rho(i, 1)
174  end do
175  rho(ncx + 1, j) = rho(1, j)
176  end do
177  rho(ncx + 1, ncy + 1) = rho(1, 1)
178 
180 
181 ! ------------ COMMENTS -------------
182 ! The mesh elec field, e.g. E1(i,j), is defined for i=1,ncx+1 (the periodic BC
183 ! is automatically considered : E1(1) = E1(ncx+1) and for j=1,ncy+1
184 !
185 ! Node (i,j) is the left_bottom corner of the cell i+(j-1)*ncx
186 ! --------------------------------------
187 !
188 
189  subroutine sll_s_accumulate_field(E1, E2, E_accumulator)
190  sll_real64, dimension(:, :), intent(in) :: e1, e2
191  type(sll_t_electric_field_accumulator), intent(out) :: e_accumulator
192  sll_int32 :: i, j
193  sll_int32 :: ncx, ncy
194 
195  ncx = e_accumulator%mesh%num_cells1
196  ncy = e_accumulator%mesh%num_cells2
197  do j = 1, ncy
198  do i = 1, ncx
199  e_accumulator%e_acc(i + (j - 1)*ncx)%Ex_sw = e1(i, j)
200  e_accumulator%e_acc(i + (j - 1)*ncx)%Ex_se = e1(i + 1, j)
201  e_accumulator%e_acc(i + (j - 1)*ncx)%Ex_nw = e1(i, j + 1)
202  e_accumulator%e_acc(i + (j - 1)*ncx)%Ex_ne = e1(i + 1, j + 1)
203  !
204  e_accumulator%e_acc(i + (j - 1)*ncx)%Ey_sw = e2(i, j)
205  e_accumulator%e_acc(i + (j - 1)*ncx)%Ey_se = e2(i + 1, j)
206  e_accumulator%e_acc(i + (j - 1)*ncx)%Ey_nw = e2(i, j + 1)
207  e_accumulator%e_acc(i + (j - 1)*ncx)%Ey_ne = e2(i + 1, j + 1)
208  end do
209  end do
210 
211  end subroutine sll_s_accumulate_field
212 
213  subroutine sll_s_accumulate_field_cs(E1, E2, E_accumulator)
214 ! ------ Recall : CS is for Cubic Splines ------
215  sll_real64, dimension(:, :), intent(in) :: e1, e2
216  type(sll_t_electric_field_accumulator_cs), intent(out) :: e_accumulator
217  sll_int32 :: i, j, im1, ip2, jm1, jp2
218  sll_int32 :: ncx, ncy
219 
220  ncx = e_accumulator%mesh%num_cells1
221  ncy = e_accumulator%mesh%num_cells2
222  do j = 1, ncy
223  jm1 = j - 1
224  jp2 = j + 2
225  if (j == 1) then
226  jm1 = ncy
227  end if
228  if (j == ncy) then
229  jp2 = 2
230  end if
231  do i = 1, ncx
232  im1 = i - 1
233  ip2 = i + 2
234  if (i == 1) then
235  im1 = ncx
236  end if
237  if (i == ncx) then
238  ip2 = 2
239  end if
240  e_accumulator%e_acc(i + (j - 1)*ncx)%Ex_im1j = e1(im1, j)
241  e_accumulator%e_acc(i + (j - 1)*ncx)%Ex_ij = e1(i, j)
242  e_accumulator%e_acc(i + (j - 1)*ncx)%Ex_ip1j = e1(i + 1, j)
243  e_accumulator%e_acc(i + (j - 1)*ncx)%Ex_ip2j = e1(ip2, j)
244 
245  e_accumulator%e_acc(i + (j - 1)*ncx)%Ex_im1jm1 = e1(im1, jm1)
246  e_accumulator%e_acc(i + (j - 1)*ncx)%Ex_ijm1 = e1(i, jm1)
247  e_accumulator%e_acc(i + (j - 1)*ncx)%Ex_ip1jm1 = e1(i + 1, jm1)
248  e_accumulator%e_acc(i + (j - 1)*ncx)%Ex_ip2jm1 = e1(ip2, jm1)
249 
250  e_accumulator%e_acc(i + (j - 1)*ncx)%Ex_im1jp1 = e1(im1, j + 1)
251  e_accumulator%e_acc(i + (j - 1)*ncx)%Ex_ijp1 = e1(i, j + 1)
252  e_accumulator%e_acc(i + (j - 1)*ncx)%Ex_ip1jp1 = e1(i + 1, j + 1)
253  e_accumulator%e_acc(i + (j - 1)*ncx)%Ex_ip2jp1 = e1(ip2, j + 1)
254 
255  e_accumulator%e_acc(i + (j - 1)*ncx)%Ex_im1jp2 = e1(im1, jp2)
256  e_accumulator%e_acc(i + (j - 1)*ncx)%Ex_ijp2 = e1(i, jp2)
257  e_accumulator%e_acc(i + (j - 1)*ncx)%Ex_ip1jp2 = e1(i + 1, jp2)
258  e_accumulator%e_acc(i + (j - 1)*ncx)%Ex_ip2jp2 = e1(ip2, jp2)
259  ! ----- !
260  ! ----- !
261  e_accumulator%e_acc(i + (j - 1)*ncx)%Ey_im1j = e2(im1, j)
262  e_accumulator%e_acc(i + (j - 1)*ncx)%Ey_ij = e2(i, j)
263  e_accumulator%e_acc(i + (j - 1)*ncx)%Ey_ip1j = e2(i + 1, j)
264  e_accumulator%e_acc(i + (j - 1)*ncx)%Ey_ip2j = e2(ip2, j)
265 
266  e_accumulator%e_acc(i + (j - 1)*ncx)%Ey_im1jm1 = e2(im1, jm1)
267  e_accumulator%e_acc(i + (j - 1)*ncx)%Ey_ijm1 = e2(i, jm1)
268  e_accumulator%e_acc(i + (j - 1)*ncx)%Ey_ip1jm1 = e2(i + 1, jm1)
269  e_accumulator%e_acc(i + (j - 1)*ncx)%Ey_ip2jm1 = e2(ip2, jm1)
270 
271  e_accumulator%e_acc(i + (j - 1)*ncx)%Ey_im1jp1 = e2(im1, j + 1)
272  e_accumulator%e_acc(i + (j - 1)*ncx)%Ey_ijp1 = e2(i, j + 1)
273  e_accumulator%e_acc(i + (j - 1)*ncx)%Ey_ip1jp1 = e2(i + 1, j + 1)
274  e_accumulator%e_acc(i + (j - 1)*ncx)%Ey_ip2jp1 = e2(ip2, j + 1)
275 
276  e_accumulator%e_acc(i + (j - 1)*ncx)%Ey_im1jp2 = e2(im1, jp2)
277  e_accumulator%e_acc(i + (j - 1)*ncx)%Ey_ijp2 = e2(i, jp2)
278  e_accumulator%e_acc(i + (j - 1)*ncx)%Ey_ip1jp2 = e2(i + 1, jp2)
279  e_accumulator%e_acc(i + (j - 1)*ncx)%Ey_ip2jp2 = e2(ip2, jp2)
280  end do
281  end do
282 
283  end subroutine sll_s_accumulate_field_cs
284 
285 end module sll_m_charge_to_density
Particle deposition routines.
subroutine, public sll_s_accumulate_field_cs(E1, E2, E_accumulator)
subroutine, public sll_s_accumulate_field(E1, E2, E_accumulator)
subroutine, public sll_s_convert_charge_to_rho_2d_per_per(charge, rho)
subroutine, public sll_s_convert_charge_to_rho_2d_per_per_cs(charge, rho)
    Report Typos and Errors