Skip to content

RT-TDDFT+RT-BSE : Fourier Transform Outputs#4527

Merged
fstein93 merged 25 commits intocp2k:masterfrom
StepanMarek:rtbse_outputs_10_2025
Nov 12, 2025
Merged

RT-TDDFT+RT-BSE : Fourier Transform Outputs#4527
fstein93 merged 25 commits intocp2k:masterfrom
StepanMarek:rtbse_outputs_10_2025

Conversation

@StepanMarek
Copy link
Contributor

Following discussion at #4489 (@Anyborr ), this pull request refactors the calculation of Fourier transforms in real-time propagation calculations and allows for printing of polarizability components and Fourier transform of dipole moments in both RT-BSE and RT-TDDFT.

So far, I have only implemented the already present methods for RT-BSE - namely, the printing of the mentioned observables is only available for non-periodic systems.

On a more technical level, I also refactored the FTs, so now the FFTW3 library is used if available.

The input structure changes a little bit - the parameters setting for the Fourier transforms of the observables are now set in a subsection directly in &REAL_TIME_PROPAGATION section, instead of subsection of &RTBSE, since they apply for both RT-BSE and RT-TDDFT. Specifically, new the subsection &FT and its subsection &PADE set these parameters, with reasonable defaults.

CHARACTER(len=21) :: prefix
CHARACTER(len=5) :: prefix_format
COMPLEX(kind=dp), DIMENSION(:), POINTER :: omegas_complex, omegas_pade
COMPLEX(kind=dp), DIMENSION(:, :), POINTER :: field_results, field_results_pade, &
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hint: Most (all?) of these pointers can be downgraded to ALLOCATABLE, TARGET. This prevents accidental memory leaks although you deallocate all variables AFAICS.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rewrote the local arrays to be ALLOCATABLE, TARGET, but due to multi_fft requiring pointers, I included additional pointer that point to them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

multi_fft does not actually need a POINTER. In most cases, you can drop it (and probably also in the interface of some other routines) except from its third argument (result_series) which you can downgrade to ALLOCATABLE because it may be reallocated within multi_fft.
Another issue is the planner routine fft_create_plan_1dm which should not be called with the actual input array because it may be overwritten with some FFTW planning modes (default in CP2K is FFTW_ESTIMATE) (see here). Apparently, this behavior is assumed at several occasions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the specific suggestions - I rewrote multi_fft so that it now accepts the arrays directly and the pointers are therefore reduced. Inside multi_fft, I left a few pointers to arrays used in fft_alloc - I assume since this is coupling to C arrays, these really have to be pointers.

For the planner routine, I now call fft_create_plan_1dm with empty (allocated but not initialized) arrays and fft_1dm with additional array, which contains copy of the input data (for the results, I reuse the array used in fft_create_plan_1dm). I tested determination of POLARIZABILITY with different FFTW plans (ESTIMATE, MEASURE and PATIENT) on a simple system and the results are identical in all cases, so I hope this approach will be valid.

Štěpán Marek added 15 commits November 10, 2025 15:23
The Fourier transforms that are carried out in the RT-BSE code can now
be done by the FFTW3 library, if it is present
 + preparation for the Fourier transform in TDDFT
 + unifying the iteration levels between TDDFT and RTBSE
 + unifying the printing routines of moments trace between TDDFT and
   RTBSE
 + providing the access to reference points
 + making the field in moments_utils optional
Polarizability and moments' Fourier transform now in output
Reading of moments, which are needed for the restart calculations of FT,
is implemented
Change in FT leads to a changed grid

Verified that the results from the polarizability is essentially the
same as before the change.
GreenX is now coupled to the print_ft method, which is applicable for
both RT-BSE and RT-TDDFT.

RT-X : Output cleanup
 - Moved pol elements guess after reading of efields
 - separated printing of FTs into separate function
Done before rebase
Now contains the current Padé section
Specific flag is now set when local moments should (and can)
be calculated.
@StepanMarek StepanMarek force-pushed the rtbse_outputs_10_2025 branch from 4de3c2a to b1beaee Compare November 10, 2025 14:23
Štěpán Marek added 9 commits November 10, 2025 17:37
With the new logical flag, allocating 0 elements should no longer be
neccessary.
Instead, when the FT fails (given by a stat code), the backup FT is
carried out.
The continuation test was continuing from the wrong restart and printed
undefinable FTs
Per recomendation of @hfp, local arrays are changed to
`ALLOCATABLE, TARGET`, which should be less prone to memory leaks.

Nevertheless, multi_fft is left to still accept pointers, so local
pointer reassignment is done.
@StepanMarek StepanMarek marked this pull request as ready for review November 11, 2025 17:05
Since pointers are typically not needed, try to avoid them in the FT
routines.

Also changed the order in FT input arrays + added additional input array
- in some cases, the planner routine could overwrite the input array,
  this should now NOT be the case (thanks to @hfp)
@fstein93 fstein93 merged commit 5ef3a49 into cp2k:master Nov 12, 2025
41 checks passed
BelizSertcan pushed a commit to BelizSertcan/cp2k that referenced this pull request Nov 24, 2025
Co-authored-by: Štěpán Marek <stepan.marek@physik.uni-regensburg.de>
BelizSertcan pushed a commit to BelizSertcan/cp2k that referenced this pull request Feb 5, 2026
Co-authored-by: Štěpán Marek <stepan.marek@physik.uni-regensburg.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants