25 use,
intrinsic :: iso_c_binding
32 & plan_g2r, & !< FFTW plan for F(G)e^{iGr} -> f(r) (backward)
33 & plan_r2g !< FFTW plan for f(r)e^{-iGr} -> F(G) (forward)
35 integer,
allocatable,
save :: &
36 & w2r(:) !< (g_wf%npw) g_wf%npw -> g_rh%nr
38 complex(c_double_complex),
allocatable,
save :: &
39 & fft_in(:), & !< (g_rh%nr) FFT buffer
40 & fft_out(:) !< (g_rh%nr) FFT buffer
42 private plan_g2r, plan_r2g, fft_in, fft_out
50 integer :: ipw, igv(3)
51 integer(c_int) :: fftwdim(3)
55 allocate(fft_in(
g_rh%nr), fft_out(
g_rh%nr))
57 plan_g2r = fftw_plan_dft(3, fftwdim, fft_in, fft_out, &
58 & fftw_backward, fftw_estimate)
60 plan_r2g = fftw_plan_dft(3, fftwdim, fft_in, fft_out, &
61 & fftw_forward, fftw_estimate)
65 igv(1:3) =
g_wf%mill(1:3,
g_wf%map(ipw))
66 igv(1:3) = modulo(igv(1:3),
g_rh%nft(1:3))
67 w2r(ipw) = 1 + igv(1) +
g_rh%nft(1)*(igv(2) +
g_rh%nft(2)*igv(3))
74 subroutine fft_r2g(VlocR, VlocG)
78 real(8),
intent(in) :: VlocR(g_rh%nr)
79 complex(8),
intent(out) :: VlocG(g_rh%nr)
81 fft_in(1:g_rh%nr) = vlocr(1:g_rh%nr)
82 call fftw_execute_dft(plan_r2g, fft_in, fft_out)
83 vlocg(1:g_rh%nr) = fft_out(1:g_rh%nr) / dble(g_rh%nr)
89 subroutine fft_g2r(VlocG, VlocR)
93 complex(8),
intent(in) :: VlocG(g_rh%nr)
94 real(8),
intent(out) :: VlocR(g_rh%nr)
96 fft_in(1:g_rh%nr) = vlocg(1:g_rh%nr)
97 call fftw_execute_dft(plan_g2r, fft_in, fft_out)
98 vlocr(1:g_rh%nr) = dble(fft_out(1:g_rh%nr))
109 complex(8),
intent(in) :: wfR(g_rh%nr)
110 complex(8),
intent(out) :: wfG(g_wf%npw)
112 fft_in(1:g_rh%nr) = wfr(1:g_rh%nr)
113 call fftw_execute_dft(plan_r2g, fft_in, fft_out)
114 wfg(1:g_wf%npw) = fft_out(
w2r(1:g_wf%npw)) * sqrt(
vcell) / dble(g_rh%nr)
125 complex(8),
intent(in) :: wfG(g_wf%npw)
126 complex(8),
intent(out) :: wfR(g_rh%nr)
128 fft_in(1:g_rh%nr) = 0.0d0
129 fft_in(
w2r(1:g_wf%npw)) = wfg(1:g_wf%npw)
130 call fftw_execute_dft(plan_g2r, fft_in, fft_out)
131 wfr(1:g_rh%nr) = fft_out(1:g_rh%nr) / sqrt(
vcell)