DFTK.jl icon indicating copy to clipboard operation
DFTK.jl copied to clipboard

Derivative in Fourier space of real function not real

Open epolack opened this issue 3 years ago • 1 comments
trafficstars

Linked to https://github.com/JuliaMolSim/DFTK.jl/pull/691

Gist of the issue if real functions are converted in Fourier with complex FFT

ifft(im .* [0 1 -1] .* fft([1 8 7])))

is real, but not

ifft(im .* [0 1] .* fft([1 8])))

To bypass the issue when getting a gradient, I have used G_to_r(…; assume_real=Val(true)).

Otherwise, with filters, G_to_r(r_to_G) may not be the identity.

epolack avatar Jul 22 '22 13:07 epolack

To bypass the issue when getting a gradient, I have used G_to_r(…; assume_real=Val(true))

I think that's fine. Other possibilities are to filter out the last component of the gradient operator (here 1 in [0, 1]), which is super annoying, or to have r_to_G filter it out, which makes r_to_G and G_to_r not inverses of each other, which is even worse. Of course, longer term we should use the real FFT routines...

antoine-levitt avatar Jul 22 '22 13:07 antoine-levitt

Real FFT routines implemented now.

mfherbst avatar Oct 04 '22 06:10 mfherbst