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

Minor refactoring of the FFTs

Open abussy opened this issue 6 months ago • 6 comments

In this PR, I propose some refactoring of the FFTs, in order to try and help disentangle the massive PlaneWaveBasis type.

The rational behind the proposed changes is that FFTs can, in principle, take place independently of the basis. As a result, a new FFTBundle type is created, containing all data required to perform such operations. The creation of a FFTBundle can take place independently of a PlaneWaveBasis, and only requires fft_size, unit_cell_volume and architecture. All subsequent calls to the fft() and ifft() functions now require a FFTBundle as argument, rather than a PlaneWaveBasis. Instead of having a loose collection of FFT plans, the PlaneWaveBasus now has a single FFTBundle as a field.

The main changes are in these files:

  • fft.jl, where the FFTBundle type is defined. All functions in this file are now independent of the PlaneWaveBasis type. An extra couple of functions (fft_matrix() and ifft_matrix()) were also moved to this file from PlaneWaveBasis.jl, as they are also basis independent.
  • A Kpoint.jl file was created, containing the definition of the Kpoint type and related functions. This was also taken out of PlaneWaveBasis.jl, for the main reason that Kpoint must be defined for FFTs, which should be defined for the creation of a PlaneWaveBasis. Note that this also reduces the size and complexity of PlaneWaveBasis.jl.
  • PlaneWaveBasis.jl, which was simplified.

The changes in all other files essentially consist in replacing argument in FFT function calls, e.g. fft(basis, ...) --> fft(basis.fft_bundle, ...). Note that the original fft() calls with the basis as argument could be easily retrieved by defining functions such as fft(basis, ...) = fft(basis.fft_bundle, ...) in PlaneWaveBasis.jl. I guess this is a stylistic question, and I personally like having these explicit calls (I am happy to change if the DFTK standard is different).

In the future, I plan to open a new PR where I take some of the K-point complexity out of PlaneWaveBasis.jl, by creating a new type containing all the necessary data for a set K-points.

abussy avatar Aug 14 '24 09:08 abussy