27 #include "sll_memory.h"
28 #include "sll_working_precision.h"
29 #include "sll_assert.h"
56 sll_real64,
dimension(:, :),
pointer :: kx
57 sll_real64,
dimension(:, :),
pointer :: ky
58 sll_real64,
dimension(:, :),
pointer :: k2
63 sll_comp64,
pointer :: rht(:, :)
64 sll_comp64,
pointer :: exy(:, :)
70 sll_real64,
pointer :: tmp(:, :)
90 procedure,
public, pass(poisson) :: init => &
93 procedure,
public, pass(poisson) :: compute_phi_from_rho => &
96 procedure,
public, pass(poisson) :: compute_e_from_rho => &
114 sll_real64,
intent(in) :: coefs_dofs(:, :)
117 r = sum(coefs_dofs**2)*poisson%solver%dx*poisson%solver%dy
124 sll_real64,
intent(out) :: coefs_dofs(:)
126 print *,
'compute_rhs_from_function not implemented for sll_t_poisson_2d_periodic.'
145 sll_real64 :: eta1_min
146 sll_real64 :: eta1_max
148 sll_real64 :: eta2_min
149 sll_real64 :: eta2_max
153 sll_allocate(poisson, ierr)
174 sll_real64 :: eta1_min
175 sll_real64 :: eta1_max
177 sll_real64 :: eta2_min
178 sll_real64 :: eta2_max
197 sll_real64,
dimension(:, :),
intent(in) :: rho
198 sll_real64,
dimension(:, :),
intent(out) :: phi
214 sll_real64,
dimension(:, :),
intent(in) :: rho
215 sll_real64,
dimension(:, :),
intent(out) :: e1
216 sll_real64,
dimension(:, :),
intent(out) :: e2
235 sll_int32,
intent(in) :: nc_x
236 sll_int32,
intent(in) :: nc_y
237 sll_real64,
intent(in) :: x_min
238 sll_real64,
intent(in) :: x_max
239 sll_real64,
intent(in) :: y_min
240 sll_real64,
intent(in) :: y_max
241 sll_int32,
intent(out) :: error
243 sll_allocate(self, error)
245 self, x_min, x_max, nc_x, y_min, y_max, nc_y, error)
260 sll_real64,
intent(in) :: x_min
261 sll_real64,
intent(in) :: x_max
262 sll_real64,
intent(in) :: y_min
263 sll_real64,
intent(in) :: y_max
268 sll_real64 :: kx1, kx0, ky0
273 self%dx = (x_max - x_min)/real(nc_x, f64)
274 self%dy = (y_max - y_min)/real(nc_y, f64)
277 print *,
" FFT version of poisson 2d periodic solver "
280 sll_allocate(self%rht(1:nc_x/2 + 1, 1:nc_y), error)
281 sll_allocate(self%exy(1:nc_x/2 + 1, 1:nc_y), error)
282 sll_clear_allocate(self%tmp(1:nc_x, 1:nc_y), error)
286 sll_allocate(self%kx(nc_x/2 + 1, nc_y), error)
287 sll_allocate(self%ky(nc_x/2 + 1, nc_y), error)
288 sll_allocate(self%k2(nc_x/2 + 1, nc_y), error)
290 kx0 = 2._f64*
sll_p_pi/(x_max - x_min)
291 ky0 = 2._f64*
sll_p_pi/(y_max - y_min)
293 do ik = 1, nc_x/2 + 1
296 self%kx(ik, jk) = kx1
297 self%ky(ik, jk) = (jk - 1)*ky0
299 do jk = nc_y/2 + 1, nc_y
300 self%kx(ik, jk) = kx1
301 self%ky(ik, jk) = (jk - 1 - nc_y)*ky0
305 self%kx(1, 1) = 1.0_f64
306 self%k2 = self%kx*self%kx + self%ky*self%ky
307 self%kx = self%kx/self%k2
308 self%ky = self%ky/self%k2
317 sll_real64,
dimension(:, :),
intent(in) :: rho
318 sll_real64,
dimension(:, :),
intent(out) :: phi
325 self%tmp = rho(1:nc_x, 1:nc_y)
328 self%rht = self%rht/self%k2
332 phi(1:nc_x, 1:nc_y) = self%tmp/real(nc_x*nc_y, f64)
335 if (
size(phi, 1) == nc_x + 1) phi(nc_x + 1, :) = phi(1, :)
336 if (
size(phi, 2) == nc_y + 1) phi(:, nc_y + 1) = phi(:, 1)
345 sll_real64,
dimension(:, :),
intent(in) :: rho
346 sll_real64,
dimension(:, :),
intent(out) :: e_x
347 sll_real64,
dimension(:, :),
intent(out) :: e_y
348 sll_real64,
optional :: nrj
350 sll_int32 :: nc_x, nc_y
356 self%tmp = rho(1:nc_x, 1:nc_y)
359 self%exy(1, 1) = (0.0_f64, 0.0_f64)
360 self%exy = -cmplx(0.0_f64, self%kx, kind=f64)*self%rht
362 e_x(1:nc_x, 1:nc_y) = self%tmp/real(nc_x*nc_y, f64)
364 self%exy(1, 1) = (0.0_f64, 0.0_f64)
365 self%exy = -cmplx(0.0_f64, self%ky, kind=f64)*self%rht
368 e_y(1:nc_x, 1:nc_y) = self%tmp/real(nc_x*nc_y, f64)
371 if (
size(e_x, 1) == nc_x + 1) e_x(nc_x + 1, :) = e_x(1, :)
372 if (
size(e_x, 2) == nc_y + 1) e_x(:, nc_y + 1) = e_x(:, 1)
373 if (
size(e_y, 1) == nc_x + 1) e_y(nc_x + 1, :) = e_y(1, :)
374 if (
size(e_y, 2) == nc_y + 1) e_y(:, nc_y + 1) = e_y(:, 1)
376 if (
present(nrj))
then
379 nrj = sum(e_x(1:nc_x, 1:nc_y)*e_x(1:nc_x, 1:nc_y) &
380 + e_y(1:nc_x, 1:nc_y)*e_y(1:nc_x, 1:nc_y))*dx*dy
Fortran module where set some physical and mathematical constants.
real(kind=f64), parameter, public sll_p_pi
subroutine, public sll_s_fft_free(plan)
Delete a plan.
subroutine, public sll_s_fft_exec_c2r_2d(plan, array_in, array_out)
Compute fast Fourier transform in complex to real mode.
subroutine, public sll_s_fft_init_c2r_2d(plan, nx, ny, array_in, array_out, normalized, aligned, optimization)
Create new 2d real to complex plan for backward FFT.
subroutine, public sll_s_fft_exec_r2c_2d(plan, array_in, array_out)
Compute fast Fourier transform in real to complex mode.
subroutine, public sll_s_fft_init_r2c_2d(plan, nx, ny, array_in, array_out, normalized, aligned, optimization)
Create new 2d complex to real plan for forward FFT.
Module interface to solve Poisson equation in 2D.
Regular cartesian two dimensional mesh with periodic bounday conditions.
type(sll_t_poisson_2d_periodic) function, pointer, public sll_f_new_poisson_2d_periodic(eta1_min, eta1_max, nc_eta1, eta2_min, eta2_max, nc_eta2)
subroutine initialize_poisson_2d_periodic_fft(self, x_min, x_max, nc_x, y_min, y_max, nc_y, error)
sll_o_initialize the Poisson solver
real(kind=f64) function l2norm_squarred_2d_periodic(poisson, coefs_dofs)
subroutine solve_e_fields_poisson_2d_periodic_fft(self, e_x, e_y, rho, nrj)
sll_o_solve Poisson equation on 2D mesh with periodic boundary conditions. return electric fields.
type(sll_t_poisson_2d_periodic_fft) function, pointer new_poisson_2d_periodic_fft(x_min, x_max, nc_x, y_min, y_max, nc_y, error)
Create a sll_o_new solver.
subroutine delete_poisson_2d_periodic_fft(self)
Delete the Poisson object.
subroutine compute_rhs_from_function_2d_periodic(poisson, func, coefs_dofs)
subroutine compute_phi_from_rho_2d_fft(poisson, phi, rho)
solves
subroutine initialize_poisson_2d_periodic(poisson, eta1_min, eta1_max, nc_eta1, eta2_min, eta2_max, nc_eta2)
subroutine solve_potential_poisson_2d_periodic_fft(self, phi, rho)
sll_o_solve Poisson equation on 2D mesh with periodic boundary conditions. return potential.
subroutine compute_e_from_rho_2d_fft(poisson, E1, E2, rho)
sll_o_solve Poisson equation to compute electric fields
subroutine delete_2d_periodic(poisson)
Type for FFT plan in SeLaLib.
derived type to sll_o_solve the Poisson equation on 2d regular cartesian mesh with periodic boundary ...