Report Typos and Errors    
Semi-Lagrangian Library
Modular library for kinetic and gyrokinetic simulations of plasmas in fusion energy devices.
sll_m_poisson_3d_periodic.F90
Go to the documentation of this file.
1 
4 
6 
7 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8 #include "sll_assert.h"
9 #include "sll_memory.h"
10 #include "sll_working_precision.h"
11 
12  use sll_m_constants, only: &
13  sll_p_pi
14 
15  use sll_m_fft, only: &
21  sll_t_fft
22 
23  implicit none
24 
25  public :: &
30 
31  private
32 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33 
37  sll_int32 :: nx
38  sll_int32 :: ny
39  sll_int32 :: nz
40  sll_real64 :: lx
41  sll_real64 :: ly
42  sll_real64 :: lz
43  type(sll_t_fft) :: fw
44  type(sll_t_fft) :: bw
45  sll_comp64, dimension(:, :, :), pointer :: hat_rho
46  sll_comp64, dimension(:, :, :), pointer :: hat_phi
48 
49 contains
50 
54  subroutine sll_s_poisson_3d_periodic_init(self, nx, ny, nz, Lx, Ly, Lz)
55 
56  sll_int32 :: nx
57  sll_int32 :: ny
58  sll_int32 :: nz
59  sll_int32 :: ierr
60  sll_real64 :: lx
61  sll_real64 :: ly
62  sll_real64 :: lz
63  type(sll_t_poisson_3d_periodic) :: self
64 
65  sll_allocate(self%hat_rho(1:nx, 1:ny, 1:nz), ierr)
66  sll_allocate(self%hat_phi(1:nx, 1:ny, 1:nz), ierr)
67 
68  ! Geometry informations
69  self%nx = nx
70  self%ny = ny
71  self%nz = nz
72  self%Lx = lx
73  self%Ly = ly
74  self%Lz = lz
75 
76  call sll_s_fft_init_c2c_3d(self%fw, nx, ny, nz, self%hat_rho, self%hat_phi, sll_p_fft_forward)
77  call sll_s_fft_init_c2c_3d(self%bw, nx, ny, nz, self%hat_phi, self%hat_rho, sll_p_fft_backward)
78 
79  end subroutine sll_s_poisson_3d_periodic_init
80 
82  subroutine sll_s_poisson_3d_periodic_solve(self, rho, phi)
83 
84  type(sll_t_poisson_3d_periodic) :: self
85  sll_real64, dimension(:, :, :) :: rho
86  sll_real64, dimension(:, :, :) :: phi
87  sll_int32 :: nx, ny, nz
88  sll_int32 :: i, j, k
89  sll_real64 :: lx, ly, lz
90  sll_real64 :: ind_x, ind_y, ind_z
91 
92  nx = self%nx
93  ny = self%ny
94  nz = self%nz
95  lx = self%Lx
96  ly = self%Ly
97  lz = self%Lz
98 
99  sll_assert(nx == size(rho, 1))
100  sll_assert(ny == size(rho, 2))
101  sll_assert(nz == size(rho, 3))
102  sll_assert(nx == size(phi, 1))
103  sll_assert(ny == size(phi, 2))
104  sll_assert(nz == size(phi, 3))
105 
106  self%hat_phi = cmplx(rho, 0_f64, kind=f64)
107  call sll_s_fft_exec_c2c_3d(self%fw, self%hat_phi, self%hat_rho)
108  self%hat_rho = self%hat_rho/cmplx(nx*ny*nz, 0.0, f64)
109 
110  ! Compute hat_phi, phi = inv_fft(hat_phi)
111  do k = 1, nz
112  do j = 1, ny
113  do i = 1, nx
114  if (i <= nx/2) then
115  ind_x = real(i - 1, f64)
116  else
117  ind_x = real(nx - (i - 1), f64)
118  end if
119  if (j <= ny/2) then
120  ind_y = real(j - 1, f64)
121  else
122  ind_y = real(ny - (j - 1), f64)
123  end if
124  if (k <= nz/2) then
125  ind_z = real(k - 1, f64)
126  else
127  ind_z = real(nz - (k - 1), f64)
128  end if
129  if ((ind_x == 0) .and. (ind_y == 0) .and. (ind_z == 0)) then
130  self%hat_rho(i, j, k) = (0._f64, 0._f64)
131  else
132  self%hat_rho(i, j, k) = self%hat_rho(i, j, k)/ &
133  (4.0_f64*sll_p_pi**2* &
134  ((real(ind_x, f64)/lx)**2 &
135  + (real(ind_y, f64)/ly)**2 &
136  + (real(ind_z, f64)/lz)**2))
137  end if
138  end do
139  end do
140  end do
141 
142  call sll_s_fft_exec_c2c_3d(self%bw, self%hat_rho, self%hat_phi)
143 
144  phi = real(self%hat_phi, f64)
145 
146  end subroutine sll_s_poisson_3d_periodic_solve
147 
150 
151  type(sll_t_poisson_3d_periodic) :: self
152  sll_int32 :: ierr
153 
154  call sll_s_fft_free(self%fw)
155  call sll_s_fft_free(self%bw)
156 
157  sll_deallocate_array(self%hat_rho, ierr)
158  sll_deallocate_array(self%hat_phi, ierr)
159 
160  end subroutine sll_s_poisson_3d_periodic_free
161 
162 end module sll_m_poisson_3d_periodic
Fortran module where set some physical and mathematical constants.
real(kind=f64), parameter, public sll_p_pi
FFT interface for FFTW.
subroutine, public sll_s_fft_free(plan)
Delete a plan.
integer, parameter, public sll_p_fft_forward
Flag to specify forward FFT (negative sign) [value -1].
subroutine, public sll_s_fft_init_c2c_3d(plan, nx, ny, nz, array_in, array_out, direction, normalized, aligned, optimization)
Create new 3d complex to complex plan.
subroutine, public sll_s_fft_exec_c2c_3d(plan, array_in, array_out)
Compute fast Fourier transform in complex to complex mode.
integer, parameter, public sll_p_fft_backward
Flag to specify backward FFT (positive sign) [value 1].
3D poisson solver with periodic boundary conditions
subroutine, public sll_s_poisson_3d_periodic_init(self, nx, ny, nz, Lx, Ly, Lz)
Allocate a structure to solve Poisson equation on 3d cartesian mesh with periodic boundary conditions...
subroutine, public sll_s_poisson_3d_periodic_solve(self, rho, phi)
Compute the potential from 3d Poisson solver.
subroutine, public sll_s_poisson_3d_periodic_free(self)
Delete the 3d poisson solver object.
Type for FFT plan in SeLaLib.
Structure to solve Poisson equation on 3d domain. Mesh is cartesian and all boundary conditions are p...
    Report Typos and Errors