(git:97501a3)
Loading...
Searching...
No Matches
rt_bse_types.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2025 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief Data storage and other types for propagation via RT-BSE method.
10!> \author Stepan Marek (01.24)
11! **************************************************************************************************
12
14
15 USE kinds, ONLY: dp
16 USE cp_fm_types, ONLY: cp_fm_type, &
23 USE cp_cfm_types, ONLY: cp_cfm_p_type, &
37 USE cp_dbcsr_api, ONLY: dbcsr_type, &
42 dbcsr_copy, &
43 dbcsr_set, &
46 USE dbt_api, ONLY: dbt_type, &
47 dbt_pgrid_type, &
48 dbt_pgrid_create, &
49 dbt_pgrid_destroy, &
50 dbt_mp_environ_pgrid, &
51 dbt_default_distvec, &
52 dbt_distribution_type, &
53 dbt_distribution_new, &
54 dbt_distribution_destroy, &
55 dbt_create, &
56 dbt_copy_matrix_to_tensor, &
57 dbt_get_num_blocks, &
58 dbt_destroy
61 USE qs_mo_types, ONLY: mo_set_type
89 do_taylor, &
90 do_bch, &
92 USE physcon, ONLY: angstrom
93 USE mathconstants, ONLY: z_zero
98
99#include "../base/base_uses.f90"
100
101 IMPLICIT NONE
102
103 PRIVATE
104
105 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = "rt_bse"
106
107
108
109
110 PUBLIC :: rtbse_env_type, &
117
118 ! Created so that we can have an array of pointers to arrays
119 TYPE series_real_type
120 REAL(kind=dp), DIMENSION(:), POINTER :: series => null()
121 END TYPE series_real_type
122 TYPE series_complex_type
123 COMPLEX(kind=dp), DIMENSION(:), POINTER :: series => null()
124 END TYPE series_complex_type
125
126! **************************************************************************************************
127!> \param n_spin Number of spin channels that are present
128!> \param n_ao Number of atomic orbitals
129!> \param n_RI Number of RI orbitals
130!> \param n_occ Number of occupied orbitals, spin dependent
131!> \param spin_degeneracy Number of electrons per orbital
132!> \param field Electric field calculated at the given timestep
133!> \param moments Moment operators along cartesian directions - centered at zero charge - used for plotting
134!> \param moments_field Moment operators along cartesian directions - used to coupling to the field -
135!> origin bound to unit cell
136!> \param sim_step Current step of the simulation
137!> \param sim_start Starting step of the simulation
138!> \param sim_nsteps Number of steps of the simulation
139!> \param sim_time Current time of the simulation
140!> \param sim_dt Timestep of the simulation
141!> \param etrs_threshold Self-consistency threshold for enforced time reversal symmetry propagation
142!> \param exp_accuracy Threshold for matrix exponential calculation
143!> \param dft_control DFT control parameters
144!> \param ham_effective Real and imaginary part of the effective Hamiltonian used to propagate
145!> the density matrix
146!> \param ham_reference Reference Hamiltonian, which does not change in the propagation = DFT+G0W0 - initial Hartree - initial COHSEX
147!> \param ham_workspace Workspace matrices for use with the Hamiltonian propagation - storage of
148!> exponential propagators etc.
149!> \param rho Density matrix at the current time step
150!> \param rho_new Density matrix - workspace in ETRS
151!> \param rho_last Density matrix - workspace in ETRS
152!> \param rho_new_last Density matrix - workspace in ETRS
153!> \param rho_M Density matrix - workspace in ETRS
154!> \param S_inv_fm Inverse overlap matrix, full matrix
155!> \param S_fm Overlap matrix, full matrix
156!> \param S_inv Inverse overlap matrix, sparse matrix
157!> \param rho_dbcsr Density matrix, sparse matrix
158!> \param rho_workspace Matrices for storage of density matrix at different timesteps for
159!> interpolation and self-consistency checks etc.
160!> \param complex_workspace Workspace for complex density (exact diagonalisation)
161!> \param complex_s Complex overlap matrix (exact diagonalisation)
162!> \param real_eigvals Eigenvalues of hermitian matrix (exact diagonalisation)
163!> \param exp_eigvals Exponentiated eigenvalues (exact diagonalisation)
164!> \param v_dbcsr Sparse matrix with bare Coulomb in RI basis
165!> \param w_dbcsr Sparse matrix with correlation part of dressed Coulomb in RI basis (without bare Coulomb)
166!> \param screened_dbt Tensor for screened Coulomb interaction
167!> \param greens_dbt Tensor for greens function/density matrix
168!> \param t_3c_w Tensor containing 3c integrals
169!> \param t_3c_work_RI_AO__AO Tensor sigma contraction
170!> \param t_3c_work2_RI_AO__AO Tensor sigma contraction
171!> \param sigma_SEX Screened exchange self-energy
172!> \param sigma_COH Coulomb hole self-energy
173!> \param hartree_curr Current Hartree matrix
174!> \param etrs_max_iter Maximum number of ETRS iterations
175!> \param ham_reference_type Which Hamiltonian to use as single particle basis
176!> \param mat_exp_method Which method to use for matrix exponentiation
177!> \param unit_nr Number of output unit
178!> \param int_3c_array Array containing the local 3c integrals
179!> \author Stepan Marek (01.24)
180! **************************************************************************************************
182 INTEGER :: n_spin = 1, &
183 n_ao = -1, &
184 n_ri = -1
185 INTEGER, DIMENSION(2) :: n_occ = -1
186 REAL(kind=dp) :: spin_degeneracy = 2
187 REAL(kind=dp), DIMENSION(3) :: field = 0.0_dp
188 TYPE(cp_fm_type), DIMENSION(:), POINTER :: moments => null(), &
189 moments_field => null()
190 INTEGER :: sim_step = 0, &
191 sim_start = 0, &
192 ! Needed for continuation runs for loading of previous moments trace
193 sim_start_orig = 0, &
194 sim_nsteps = -1
195 REAL(kind=dp) :: sim_time = 0.0_dp, &
196 sim_dt = 0.1_dp, &
197 etrs_threshold = 1.0e-7_dp, &
198 exp_accuracy = 1.0e-10_dp, &
199 ft_damping = 0.0_dp, &
200 ft_start = 0.0_dp
201 ! Which element of polarizability to print out
202 INTEGER, DIMENSION(:, :), POINTER :: pol_elements => null()
203 TYPE(dft_control_type), POINTER :: dft_control => null()
204 ! DEBUG : Trying keeping the reference to previous environments inside this one
205 TYPE(qs_environment_type), POINTER :: qs_env => null()
206 TYPE(post_scf_bandstructure_type), POINTER :: bs_env => null()
207 ! Stores data needed for reading/writing to the restart files
208 TYPE(section_vals_type), POINTER :: restart_section => null(), &
209 field_section => null(), &
210 rho_section => null(), &
211 ft_section => null(), &
212 pol_section => null(), &
213 moments_section => null()
214 LOGICAL :: restart_extracted = .false.
215
216 ! Different indices signify different spins
217 TYPE(cp_cfm_type), DIMENSION(:), POINTER :: ham_effective => null()
218 TYPE(cp_cfm_type), DIMENSION(:), POINTER :: ham_reference => null()
219 TYPE(cp_cfm_type), DIMENSION(:), POINTER :: ham_workspace => null()
220 TYPE(cp_cfm_type), DIMENSION(:), POINTER :: sigma_sex => null()
221 TYPE(cp_fm_type), DIMENSION(:), POINTER :: sigma_coh => null(), &
222 hartree_curr => null()
223
224 TYPE(cp_cfm_type), DIMENSION(:), POINTER :: rho => null(), &
225 rho_new => null(), &
226 rho_new_last => null(), &
227 rho_m => null(), &
228 rho_orig => null()
229 TYPE(cp_fm_type) :: s_inv_fm = cp_fm_type(), &
230 s_fm = cp_fm_type()
231 ! Many routines require overlap in the complex format
232 TYPE(cp_cfm_type) :: s_cfm = cp_cfm_type()
233 TYPE(dbcsr_type) :: rho_dbcsr = dbcsr_type(), &
234 v_ao_dbcsr = dbcsr_type()
235 ! Indices only correspond to different workspaces
236 TYPE(cp_cfm_type), DIMENSION(:), POINTER :: rho_workspace => null()
237 ! Many methods use real and imaginary parts separately - prevent unnecessary reallocation
238 TYPE(cp_fm_type), DIMENSION(:), POINTER :: real_workspace => null()
239 ! Workspace required for exact matrix exponentiation
240 REAL(kind=dp), DIMENSION(:), POINTER :: real_eigvals => null()
241 COMPLEX(kind=dp), DIMENSION(:), POINTER :: exp_eigvals => null()
242 ! Workspace for saving the values for FT
243 TYPE(series_complex_type), DIMENSION(3) :: moments_trace = series_complex_type()
244 TYPE(series_real_type) :: time_trace = series_real_type()
245 TYPE(series_real_type), DIMENSION(3) :: field_trace = series_real_type()
246 ! Workspace required for hartree_pw
247 TYPE(dbcsr_type) :: v_dbcsr = dbcsr_type(), &
248 w_dbcsr = dbcsr_type()
249#if defined(FTN_NO_DEFAULT_INIT)
250 TYPE(dbt_type) :: screened_dbt, &
251 greens_dbt, &
252 t_3c_w, &
253 t_3c_work_ri_ao__ao, &
254 t_3c_work2_ri_ao__ao
255#else
256 TYPE(dbt_type) :: screened_dbt = dbt_type(), &
257 greens_dbt = dbt_type(), &
258 t_3c_w = dbt_type(), &
259 t_3c_work_ri_ao__ao = dbt_type(), &
260 t_3c_work2_ri_ao__ao = dbt_type()
261#endif
262 ! These matrices are always real
263 INTEGER :: etrs_max_iter = 10
264 INTEGER :: ham_reference_type = 2
265 INTEGER :: mat_exp_method = 4
266 INTEGER :: unit_nr = -1
267 REAL(kind=dp), DIMENSION(:, :, :), POINTER :: int_3c_array => null()
268 ! Parameters for Padé refinement
269 REAL(kind=dp) :: pade_e_min = 0.0_dp, &
270 pade_e_max = 100.0_dp, &
271 pade_e_step = 0.05_dp, &
272 pade_fit_e_min = 0.0_dp, &
273 pade_fit_e_max = -1.0_dp
274 INTEGER :: pade_npoints = 0
275 LOGICAL :: pade_requested = .false.
276 COMPLEX(kind=dp), DIMENSION(:), POINTER :: pade_x_eval => null()
277
278 END TYPE rtbse_env_type
279
280CONTAINS
281
282! **************************************************************************************************
283!> \brief Allocates structures and prepares rtbse_env for run
284!> \param rtbse_env rtbse_env_type that is initialised
285!> \param qs_env Entry point of the calculation
286!> \author Stepan Marek
287!> \date 02.2024
288! **************************************************************************************************
289 SUBROUTINE create_rtbse_env(rtbse_env, qs_env, force_env)
290 TYPE(rtbse_env_type), POINTER :: rtbse_env
291 TYPE(qs_environment_type), POINTER :: qs_env
292 TYPE(force_env_type), POINTER :: force_env
293 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
294 TYPE(rt_prop_type), POINTER :: rtp
295 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s
296 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
297 INTEGER :: i, j, k, single_pol_index
298 TYPE(section_vals_type), POINTER :: input, bs_sec, md_sec
299 INTEGER, DIMENSION(:), POINTER :: pol_tmp
300 LOGICAL :: pol_elements_explicit, &
301 pade_fit_lim_explicit, &
302 pol_vector_known
303 REAL(kind=dp), DIMENSION(3) :: pol_vector
304
305 ! Allocate the storage for the gwbse environment
306 NULLIFY (rtbse_env)
307 ALLOCATE (rtbse_env)
308 ! Extract the other types first
309 CALL get_qs_env(qs_env, &
310 bs_env=bs_env, &
311 rtp=rtp, &
312 matrix_s=matrix_s, &
313 mos=mos, &
314 dft_control=rtbse_env%dft_control, &
315 input=input)
316 bs_sec => section_vals_get_subs_vals(input, "PROPERTIES%BANDSTRUCTURE")
317 IF (.NOT. ASSOCIATED(bs_env)) THEN
318 cpabort("Cannot run RT-BSE without running GW calculation (PROPERTIES) before")
319 END IF
320 ! Number of spins
321 rtbse_env%n_spin = bs_env%n_spin
322 ! Number of atomic orbitals
323 rtbse_env%n_ao = bs_env%n_ao
324 ! Number of auxiliary basis orbitals
325 rtbse_env%n_RI = bs_env%n_RI
326 ! Number of occupied orbitals - for closed shell equals to half the number of electrons
327 rtbse_env%n_occ(:) = bs_env%n_occ(:)
328 ! Spin degeneracy - number of spins per orbital
329 rtbse_env%spin_degeneracy = bs_env%spin_degeneracy
330 ! Default field is zero
331 rtbse_env%field(:) = 0.0_dp
332 ! Default time is zero
333 rtbse_env%sim_step = 0
334 rtbse_env%sim_time = 0
335 ! Time step is taken from rtp
336 md_sec => section_vals_get_subs_vals(force_env%root_section, "MOTION%MD")
337 CALL section_vals_val_get(md_sec, "TIMESTEP", r_val=rtbse_env%sim_dt)
338 ! rtbse_env%sim_dt = rtp%dt
339 ! Threshold for etrs is taken from the eps_energy from RT propagation
340 rtbse_env%etrs_threshold = rtbse_env%dft_control%rtp_control%eps_ener
341 rtbse_env%exp_accuracy = rtbse_env%dft_control%rtp_control%eps_exp
342 ! Recover custom options
343 CALL section_vals_val_get(input, "DFT%REAL_TIME_PROPAGATION%RTBSE%RTBSE_HAMILTONIAN", &
344 i_val=rtbse_env%ham_reference_type)
345 CALL section_vals_val_get(input, "DFT%REAL_TIME_PROPAGATION%MAX_ITER", &
346 i_val=rtbse_env%etrs_max_iter)
347 CALL section_vals_val_get(input, "DFT%REAL_TIME_PROPAGATION%MAT_EXP", &
348 i_val=rtbse_env%mat_exp_method)
349 ! Output unit number, recovered from the post_scf_bandstructure_type
350 rtbse_env%unit_nr = bs_env%unit_nr
351 ! Sim start index and total number of steps as well
352 CALL section_vals_val_get(md_sec, "STEP_START_VAL", i_val=rtbse_env%sim_start)
353 ! Copy this value to sim_start_orig for continuation runs
354 rtbse_env%sim_start_orig = rtbse_env%sim_start
355 CALL section_vals_val_get(md_sec, "STEPS", i_val=rtbse_env%sim_nsteps)
356 ! Get the values for the FT
357 CALL section_vals_val_get(input, "DFT%REAL_TIME_PROPAGATION%RTBSE%FT_DAMPING", &
358 r_val=rtbse_env%ft_damping)
359 CALL section_vals_val_get(input, "DFT%REAL_TIME_PROPAGATION%RTBSE%FT_START_TIME", &
360 r_val=rtbse_env%ft_start)
361 ! Handle ELEMENT keywords
362 ! By default, if the keywords are not present, check whether just one element in polarization/delta_pulse direction
363 ! is non-zero. If that is the case, print 3 finite elements of polarizability. Otherwise, warn and print
364 ! just diagonal elements for each non-zero e-field element
365 ! Iterate over all ELEMENT keywords
366 CALL section_vals_val_get(input, "DFT%REAL_TIME_PROPAGATION%PRINT%POLARIZABILITY%ELEMENT", &
367 n_rep_val=k, explicit=pol_elements_explicit)
368 IF (pol_elements_explicit) THEN
369 ! By default, fill with 1 1 elements
370 ALLOCATE (rtbse_env%pol_elements(k, 2), source=1)
371 DO i = 1, k
372 CALL section_vals_val_get(input, "DFT%REAL_TIME_PROPAGATION%PRINT%POLARIZABILITY%ELEMENT", &
373 i_vals=pol_tmp, i_rep_val=i)
374 IF (SIZE(pol_tmp) < 2) cpabort("Less than two elements provided for polarizability")
375 rtbse_env%pol_elements(i, :) = pol_tmp(:)
376 END DO
377 ! Do basic sanity checks for pol_element
378 DO j = 1, k
379 DO i = 1, 2
380 IF (rtbse_env%pol_elements(j, i) > 3 .OR. rtbse_env%pol_elements(j, i) < 1) &
381 cpabort("Polarisation tensor element not 1,2 or 3 in at least one index")
382 END DO
383 END DO
384 ELSE
385 ! Figure out whether delta direction or polarization is applicable
386 pol_vector_known = .false.
387 IF (rtbse_env%dft_control%rtp_control%apply_delta_pulse) THEN
388 ! Delta pulse polarization
389 pol_vector(:) = rtbse_env%dft_control%rtp_control%delta_pulse_direction(:)
390 pol_vector_known = .true.
391 ELSE IF (SIZE(rtbse_env%dft_control%efield_fields) > 0) THEN
392 ! real time field polarization
393 ! Maybe generalize for all fields?
394 pol_vector(:) = rtbse_env%dft_control%efield_fields(1)%efield%polarisation(:)
395 pol_vector_known = .true.
396 END IF
397 ! Check whether the vector is not explicitly zero
398 IF (dot_product(pol_vector, pol_vector) == 0.0_dp) pol_vector_known = .false.
399 IF (pol_vector_known) THEN
400 ! Iterate over the pol vector, check whether just one is non-zero
401 single_pol_index = -1
402 DO i = 1, 3
403 IF (pol_vector(i) /= 0.0_dp .AND. &
404 pol_vector(modulo(i, 3) + 1) == 0.0_dp .AND. &
405 pol_vector(modulo(i + 1, 3) + 1) == 0.0_dp) THEN
406 single_pol_index = i
407 EXIT
408 END IF
409 END DO
410 IF (single_pol_index > 0) THEN
411 ! Print 3 elements
412 ALLOCATE (rtbse_env%pol_elements(3, 2), source=1)
413 DO i = 1, 3
414 rtbse_env%pol_elements(i, 1) = i
415 rtbse_env%pol_elements(i, 2) = single_pol_index
416 END DO
417 ELSE
418 ! More than one non-zero efield component - abort
419 cpabort("RTBSE : Guess for polarizability elements failed - please specify")
420 END IF
421 ELSE
422 ! Pol vector is unknown, but polarizability is requested - abort and request an element
423 cpabort("RTBSE : Guess for polarizability elements failed - please specify")
424 END IF
425 END IF
426
427 ! Get the restart section
428 rtbse_env%restart_section => section_vals_get_subs_vals(input, "DFT%REAL_TIME_PROPAGATION%PRINT%RESTART")
429 rtbse_env%restart_extracted = .false.
430 rtbse_env%field_section => section_vals_get_subs_vals(input, "DFT%REAL_TIME_PROPAGATION%PRINT%FIELD")
431 rtbse_env%moments_section => section_vals_get_subs_vals(input, "DFT%REAL_TIME_PROPAGATION%PRINT%MOMENTS")
432 rtbse_env%rho_section => section_vals_get_subs_vals(input, "DFT%REAL_TIME_PROPAGATION%PRINT%DENSITY_MATRIX")
433 rtbse_env%ft_section => section_vals_get_subs_vals(input, "DFT%REAL_TIME_PROPAGATION%PRINT%MOMENTS_FT")
434 rtbse_env%pol_section => section_vals_get_subs_vals(input, "DFT%REAL_TIME_PROPAGATION%PRINT%POLARIZABILITY")
435 ! Warn the user about print sections which are not yet implemented in the RTBSE run
436 CALL warn_section_unused(input, "DFT%REAL_TIME_PROPAGATION%PRINT%CURRENT", &
437 "CURRENT print section not yet implemented for RTBSE.")
438 CALL warn_section_unused(input, "DFT%REAL_TIME_PROPAGATION%PRINT%E_CONSTITUENTS", &
439 "E_CONSTITUENTS print section not yet implemented for RTBSE.")
440 CALL warn_section_unused(input, "DFT%REAL_TIME_PROPAGATION%PRINT%PROGRAM_RUN_INFO", &
441 "PROGRAM_RUN_INFO print section not yet implemented for RTBSE.")
442 CALL warn_section_unused(input, "DFT%REAL_TIME_PROPAGATION%PRINT%PROJECTION_MO", &
443 "PROJECTION_MO print section not yet implemented for RTBSE.")
444 CALL warn_section_unused(input, "DFT%REAL_TIME_PROPAGATION%PRINT%RESTART_HISTORY", &
445 "RESTART_HISTORY print section not yet implemented for RTBSE.")
446 ! DEBUG : References to previous environments
447 rtbse_env%qs_env => qs_env
448 rtbse_env%bs_env => bs_env
449 ! Padé refinement
450 CALL section_vals_get(section_vals_get_subs_vals(input, "DFT%REAL_TIME_PROPAGATION%RTBSE%PADE_FT"), &
451 explicit=rtbse_env%pade_requested)
452 CALL section_vals_val_get(input, "DFT%REAL_TIME_PROPAGATION%RTBSE%PADE_FT%E_MIN", &
453 r_val=rtbse_env%pade_e_min)
454 CALL section_vals_val_get(input, "DFT%REAL_TIME_PROPAGATION%RTBSE%PADE_FT%E_MAX", &
455 r_val=rtbse_env%pade_e_max)
456 CALL section_vals_val_get(input, "DFT%REAL_TIME_PROPAGATION%RTBSE%PADE_FT%E_STEP", &
457 r_val=rtbse_env%pade_e_step)
458 CALL section_vals_val_get(input, "DFT%REAL_TIME_PROPAGATION%RTBSE%PADE_FT%FIT_E_MIN", &
459 r_val=rtbse_env%pade_fit_e_min, explicit=pade_fit_lim_explicit)
460 ! By default, use the pade_e_min keyword to set the fit limit as well
461 IF (.NOT. pade_fit_lim_explicit) THEN
462 rtbse_env%pade_fit_e_min = rtbse_env%pade_e_min
463 END IF
464 CALL section_vals_val_get(input, "DFT%REAL_TIME_PROPAGATION%RTBSE%PADE_FT%FIT_E_MAX", &
465 r_val=rtbse_env%pade_fit_e_max, explicit=pade_fit_lim_explicit)
466 IF (.NOT. pade_fit_lim_explicit) THEN
467 rtbse_env%pade_fit_e_max = rtbse_env%pade_e_max
468 END IF
469 rtbse_env%pade_npoints = int((rtbse_env%pade_e_max - rtbse_env%pade_e_min)/rtbse_env%pade_e_step)
470 ! Evaluate the evaluation grid
471 IF (rtbse_env%pade_requested) THEN
472 NULLIFY (rtbse_env%pade_x_eval)
473 ALLOCATE (rtbse_env%pade_x_eval(rtbse_env%pade_npoints))
474 DO i = 1, rtbse_env%pade_npoints
475 rtbse_env%pade_x_eval(i) = cmplx(rtbse_env%pade_e_step*real(i - 1, kind=dp), 0.0, kind=dp)
476 END DO
477 END IF
478
479 ! Allocate moments matrices
480 NULLIFY (rtbse_env%moments)
481 ALLOCATE (rtbse_env%moments(3))
482 NULLIFY (rtbse_env%moments_field)
483 ALLOCATE (rtbse_env%moments_field(3))
484 DO k = 1, 3
485 ! Matrices are created from overlap template
486 ! Values are initialized in initialize_rtbse_env
487 CALL cp_fm_create(rtbse_env%moments(k), bs_env%fm_s_Gamma%matrix_struct)
488 CALL cp_fm_create(rtbse_env%moments_field(k), bs_env%fm_s_Gamma%matrix_struct)
489 END DO
490
491 ! Allocate space for density propagation and other operations
492 NULLIFY (rtbse_env%rho_workspace)
493 ALLOCATE (rtbse_env%rho_workspace(4))
494 DO i = 1, SIZE(rtbse_env%rho_workspace)
495 CALL cp_cfm_create(rtbse_env%rho_workspace(i), bs_env%fm_ks_Gamma(1)%matrix_struct)
496 CALL cp_cfm_set_all(rtbse_env%rho_workspace(i), cmplx(0.0, 0.0, kind=dp))
497 END DO
498 ! Allocate real workspace
499 NULLIFY (rtbse_env%real_workspace)
500 SELECT CASE (rtbse_env%mat_exp_method)
501 CASE (do_exact)
502 ALLOCATE (rtbse_env%real_workspace(4))
503 CASE (do_bch)
504 ALLOCATE (rtbse_env%real_workspace(2))
505 CASE DEFAULT
506 cpabort("Only exact and BCH matrix propagation implemented in RT-BSE")
507 END SELECT
508 DO i = 1, SIZE(rtbse_env%real_workspace)
509 CALL cp_fm_create(rtbse_env%real_workspace(i), bs_env%fm_ks_Gamma(1)%matrix_struct)
510 CALL cp_fm_set_all(rtbse_env%real_workspace(i), 0.0_dp)
511 END DO
512 ! Allocate density matrix
513 NULLIFY (rtbse_env%rho)
514 ALLOCATE (rtbse_env%rho(rtbse_env%n_spin))
515 DO i = 1, rtbse_env%n_spin
516 CALL cp_cfm_create(rtbse_env%rho(i), matrix_struct=bs_env%fm_s_Gamma%matrix_struct)
517 END DO
518 ! Create the inverse overlap matrix, for use in density propagation
519 ! Start by creating the actual overlap matrix
520 CALL cp_fm_create(rtbse_env%S_fm, bs_env%fm_s_Gamma%matrix_struct)
521 CALL cp_fm_create(rtbse_env%S_inv_fm, bs_env%fm_s_Gamma%matrix_struct)
522 CALL cp_cfm_create(rtbse_env%S_cfm, bs_env%fm_s_Gamma%matrix_struct)
523
524 ! Create the single particle hamiltonian
525 ! Allocate workspace
526 NULLIFY (rtbse_env%ham_workspace)
527 ALLOCATE (rtbse_env%ham_workspace(rtbse_env%n_spin))
528 DO i = 1, rtbse_env%n_spin
529 CALL cp_cfm_create(rtbse_env%ham_workspace(i), bs_env%fm_ks_Gamma(1)%matrix_struct)
530 CALL cp_cfm_set_all(rtbse_env%ham_workspace(i), cmplx(0.0, 0.0, kind=dp))
531 END DO
532 ! Now onto the Hamiltonian itself
533 NULLIFY (rtbse_env%ham_reference)
534 ALLOCATE (rtbse_env%ham_reference(rtbse_env%n_spin))
535 DO i = 1, rtbse_env%n_spin
536 CALL cp_cfm_create(rtbse_env%ham_reference(i), bs_env%fm_ks_Gamma(i)%matrix_struct)
537 END DO
538
539 ! Create the matrices and workspaces for ETRS propagation
540 NULLIFY (rtbse_env%ham_effective)
541 NULLIFY (rtbse_env%rho_new)
542 NULLIFY (rtbse_env%rho_new_last)
543 NULLIFY (rtbse_env%rho_M)
544 NULLIFY (rtbse_env%rho_orig)
545 ALLOCATE (rtbse_env%ham_effective(rtbse_env%n_spin))
546 ALLOCATE (rtbse_env%rho_new(rtbse_env%n_spin))
547 ALLOCATE (rtbse_env%rho_new_last(rtbse_env%n_spin))
548 ALLOCATE (rtbse_env%rho_M(rtbse_env%n_spin))
549 ALLOCATE (rtbse_env%rho_orig(rtbse_env%n_spin))
550 DO i = 1, rtbse_env%n_spin
551 CALL cp_cfm_create(rtbse_env%ham_effective(i), bs_env%fm_ks_Gamma(1)%matrix_struct)
552 CALL cp_cfm_set_all(rtbse_env%ham_effective(i), cmplx(0.0, 0.0, kind=dp))
553 CALL cp_cfm_create(rtbse_env%rho_new(i), bs_env%fm_ks_Gamma(1)%matrix_struct)
554 CALL cp_cfm_set_all(rtbse_env%rho_new(i), cmplx(0.0, 0.0, kind=dp))
555 CALL cp_cfm_create(rtbse_env%rho_new_last(i), bs_env%fm_ks_Gamma(1)%matrix_struct)
556 CALL cp_cfm_set_all(rtbse_env%rho_new_last(i), cmplx(0.0, 0.0, kind=dp))
557 CALL cp_cfm_create(rtbse_env%rho_M(i), bs_env%fm_ks_Gamma(1)%matrix_struct)
558 CALL cp_cfm_set_all(rtbse_env%rho_M(i), cmplx(0.0, 0.0, kind=dp))
559 CALL cp_cfm_create(rtbse_env%rho_orig(i), bs_env%fm_ks_Gamma(1)%matrix_struct)
560 END DO
561
562 ! Fields for exact diagonalisation
563 NULLIFY (rtbse_env%real_eigvals)
564 ALLOCATE (rtbse_env%real_eigvals(rtbse_env%n_ao))
565 rtbse_env%real_eigvals(:) = 0.0_dp
566 NULLIFY (rtbse_env%exp_eigvals)
567 ALLOCATE (rtbse_env%exp_eigvals(rtbse_env%n_ao))
568 rtbse_env%exp_eigvals(:) = cmplx(0.0, 0.0, kind=dp)
569
570 ! Workspace for FT - includes (in principle) the zeroth step and the extra last step
571 DO i = 1, 3
572 NULLIFY (rtbse_env%moments_trace(i)%series)
573 ALLOCATE (rtbse_env%moments_trace(i)%series(rtbse_env%sim_nsteps + 2), source=z_zero)
574 NULLIFY (rtbse_env%field_trace(i)%series)
575 ALLOCATE (rtbse_env%field_trace(i)%series(rtbse_env%sim_nsteps + 2), source=0.0_dp)
576 END DO
577 NULLIFY (rtbse_env%time_trace%series)
578 ALLOCATE (rtbse_env%time_trace%series(rtbse_env%sim_nsteps + 2), source=0.0_dp)
579
580 ! Allocate self-energy parts and dynamic Hartree potential
581 NULLIFY (rtbse_env%hartree_curr)
582 NULLIFY (rtbse_env%sigma_SEX)
583 NULLIFY (rtbse_env%sigma_COH)
584 ALLOCATE (rtbse_env%hartree_curr(rtbse_env%n_spin))
585 ALLOCATE (rtbse_env%sigma_SEX(rtbse_env%n_spin))
586 ALLOCATE (rtbse_env%sigma_COH(rtbse_env%n_spin))
587 DO i = 1, rtbse_env%n_spin
588 CALL cp_fm_create(rtbse_env%sigma_COH(i), bs_env%fm_ks_Gamma(1)%matrix_struct)
589 CALL cp_cfm_create(rtbse_env%sigma_SEX(i), bs_env%fm_ks_Gamma(1)%matrix_struct)
590 CALL cp_fm_create(rtbse_env%hartree_curr(i), bs_env%fm_ks_Gamma(1)%matrix_struct)
591 CALL cp_fm_set_all(rtbse_env%sigma_COH(i), 0.0_dp)
592 CALL cp_cfm_set_all(rtbse_env%sigma_SEX(i), cmplx(0.0, 0.0, kind=dp))
593 CALL cp_fm_set_all(rtbse_env%hartree_curr(i), 0.0_dp)
594 END DO
595
596 ! Allocate workspaces for get_sigma
597 CALL create_sigma_workspace(rtbse_env, qs_env)
598
599 ! Depending on the chosen methods, allocate extra workspace
600 CALL create_hartree_ri_workspace(rtbse_env, qs_env)
601
602 END SUBROUTINE
603
604! **************************************************************************************************
605!> \brief Simple reimplementation of cp_fm_release_pp1 for complex matrices
606!> \param matrices cp_cfm_p_type(:)
607!> \author Stepan Marek
608!> \date 02.2024
609! **************************************************************************************************
610 SUBROUTINE cp_cfm_release_pa1(matrices)
611 TYPE(cp_cfm_type), DIMENSION(:), POINTER :: matrices
612 INTEGER :: i
613
614 DO i = 1, SIZE(matrices)
615 CALL cp_cfm_release(matrices(i))
616 END DO
617 DEALLOCATE (matrices)
618 NULLIFY (matrices)
619 END SUBROUTINE cp_cfm_release_pa1
620
621! **************************************************************************************************
622!> \brief Releases the environment allocated structures
623!> \param rtbse_env
624!> \author Stepan Marek
625!> \date 02.2024
626! **************************************************************************************************
627 SUBROUTINE release_rtbse_env(rtbse_env)
628 TYPE(rtbse_env_type), POINTER :: rtbse_env
629 INTEGER :: i
630
631 CALL cp_cfm_release_pa1(rtbse_env%ham_effective)
632 CALL cp_cfm_release_pa1(rtbse_env%ham_workspace)
633 CALL cp_fm_release(rtbse_env%sigma_COH)
634 CALL cp_cfm_release_pa1(rtbse_env%sigma_SEX)
635 CALL cp_fm_release(rtbse_env%hartree_curr)
636 CALL cp_cfm_release_pa1(rtbse_env%ham_reference)
637 CALL cp_cfm_release_pa1(rtbse_env%rho)
638 CALL cp_cfm_release_pa1(rtbse_env%rho_workspace)
639 CALL cp_cfm_release_pa1(rtbse_env%rho_new)
640 CALL cp_cfm_release_pa1(rtbse_env%rho_new_last)
641 CALL cp_cfm_release_pa1(rtbse_env%rho_M)
642 CALL cp_cfm_release_pa1(rtbse_env%rho_orig)
643 CALL cp_fm_release(rtbse_env%real_workspace)
644 CALL cp_fm_release(rtbse_env%S_inv_fm)
645 CALL cp_fm_release(rtbse_env%S_fm)
646 CALL cp_cfm_release(rtbse_env%S_cfm)
647
648 ! DO i = 1, 3
649 ! CALL cp_fm_release(rtbse_env%moments(i)%matrix)
650 ! CALL cp_fm_release(rtbse_env%moments_field(i)%matrix)
651 ! END DO
652 CALL cp_fm_release(rtbse_env%moments)
653 CALL cp_fm_release(rtbse_env%moments_field)
654
655 CALL release_sigma_workspace(rtbse_env)
656
657 CALL release_hartree_ri_workspace(rtbse_env)
658
659 DEALLOCATE (rtbse_env%real_eigvals)
660 DEALLOCATE (rtbse_env%exp_eigvals)
661 DO i = 1, 3
662 DEALLOCATE (rtbse_env%moments_trace(i)%series)
663 DEALLOCATE (rtbse_env%field_trace(i)%series)
664 END DO
665 DEALLOCATE (rtbse_env%time_trace%series)
666
667 DEALLOCATE (rtbse_env%pol_elements)
668 IF (ASSOCIATED(rtbse_env%pade_x_eval)) DEALLOCATE (rtbse_env%pade_x_eval)
669
670 ! Deallocate the neighbour list that is not deallocated in gw anymore
671 IF (ASSOCIATED(rtbse_env%bs_env%nl_3c%ij_list)) CALL neighbor_list_3c_destroy(rtbse_env%bs_env%nl_3c)
672 ! Deallocate the storage for the environment itself
673 DEALLOCATE (rtbse_env)
674 ! Nullify to make sure it is not used again
675 NULLIFY (rtbse_env)
676
677 END SUBROUTINE
678! **************************************************************************************************
679!> \brief Allocates the workspaces for Hartree RI method
680!> \note RI method calculates the Hartree contraction without the use of DBT, as it cannot emulate vectors
681!> \param rtbse_env
682!> \param qs_env Quickstep environment - entry point of calculation
683!> \author Stepan Marek
684!> \date 05.2024
685! **************************************************************************************************
686 SUBROUTINE create_hartree_ri_workspace(rtbse_env, qs_env)
687 TYPE(rtbse_env_type) :: rtbse_env
688 TYPE(qs_environment_type), POINTER :: qs_env
689 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
690
691 CALL get_qs_env(qs_env, bs_env=bs_env)
692
693 CALL dbcsr_create(rtbse_env%rho_dbcsr, name="Sparse density", template=bs_env%mat_ao_ao%matrix)
694 CALL dbcsr_create(rtbse_env%v_ao_dbcsr, name="Sparse Hartree", template=bs_env%mat_ao_ao%matrix)
695
696 CALL create_hartree_ri_3c(rtbse_env%rho_dbcsr, rtbse_env%int_3c_array, rtbse_env%n_ao, rtbse_env%n_RI, &
697 bs_env%basis_set_AO, bs_env%basis_set_RI, bs_env%i_RI_start_from_atom, &
698 bs_env%ri_metric, qs_env, rtbse_env%unit_nr)
699 END SUBROUTINE create_hartree_ri_workspace
700! **************************************************************************************************
701!> \brief Separated method for allocating the 3c integrals for RI Hartree
702!> \note RI method calculates the Hartree contraction without the use of DBT, as it cannot emulate vectors
703!> \param rho_dbcsr matrix used for the description of shape of 3c array
704!> \param int_3c 3-center integral array to be allocated and filled
705!> \param n_ao Number of atomic orbitals
706!> \param n_RI Number of auxiliary RI orbitals
707!> \param basis_set_AO AO basis set
708!> \param basis_set_RI RI auxiliary basis set
709!> \param i_RI_start_from_atom Array of indices where functions of a given atom in RI basis start
710!> \param unit_nr Unit number used for printing information about the size of int_3c
711!> \author Stepan Marek
712!> \date 01.2025
713! **************************************************************************************************
714 SUBROUTINE create_hartree_ri_3c(rho_dbcsr, int_3c, n_ao, n_RI, basis_set_AO, basis_set_RI, &
715 i_RI_start_from_atom, ri_metric, qs_env, unit_nr)
716 TYPE(dbcsr_type) :: rho_dbcsr
717 REAL(kind=dp), DIMENSION(:, :, :), POINTER :: int_3c
718 INTEGER :: n_ao, n_ri
719 TYPE(gto_basis_set_p_type), DIMENSION(:) :: basis_set_ao, &
720 basis_set_ri
721 INTEGER, DIMENSION(:) :: i_ri_start_from_atom
722 TYPE(libint_potential_type) :: ri_metric
723 TYPE(qs_environment_type), POINTER :: qs_env
724 INTEGER :: unit_nr
725 REAL(kind=dp) :: size_mb
726 INTEGER :: nblkrows_local, &
727 nblkcols_local, &
728 i_blk_local, &
729 j_blk_local, &
730 nrows_local, &
731 ncols_local, &
732 col_local_offset, &
733 row_local_offset, &
734 start_col_index, &
735 end_col_index, &
736 start_row_index, &
737 end_row_index
738 INTEGER, DIMENSION(:), POINTER :: local_blk_rows, &
739 local_blk_cols, &
740 row_blk_size, &
741 col_blk_size
742 ! TODO : Implement option/decision to not precompute all the 3c integrals
743 size_mb = real(n_ao, kind=dp)*real(n_ao, kind=dp)*real(n_ri, kind=dp)* &
744 REAL(storage_size(size_mb), kind=dp)/8.0_dp/1024.0_dp/1024.0_dp
745 IF (unit_nr > 0) WRITE (unit_nr, '(A44,E32.2E3,A4)') &
746 " RTBSE| Approximate size of the 3c integrals", size_mb, " MiB"
747
748 ! Get the number of block rows and columns
749 CALL dbcsr_get_info(rho_dbcsr, nblkrows_local=nblkrows_local, nblkcols_local=nblkcols_local)
750 ! Get the global indices of local rows and columns
751 CALL dbcsr_get_info(rho_dbcsr, local_rows=local_blk_rows, local_cols=local_blk_cols)
752 ! Get the sizes of all blocks
753 CALL dbcsr_get_info(rho_dbcsr, row_blk_size=row_blk_size, col_blk_size=col_blk_size)
754
755 ! Get the total required local rows and cols
756 nrows_local = 0
757 DO i_blk_local = 1, nblkrows_local
758 nrows_local = nrows_local + row_blk_size(local_blk_rows(i_blk_local))
759 END DO
760 ncols_local = 0
761 DO j_blk_local = 1, nblkcols_local
762 ncols_local = ncols_local + col_blk_size(local_blk_cols(j_blk_local))
763 END DO
764
765 ! Allocate the appropriate storage
766 ALLOCATE (int_3c(nrows_local, ncols_local, n_ri))
767
768 ! Fill the storage with appropriate values, block by block
769 row_local_offset = 1
770 DO i_blk_local = 1, nblkrows_local
771 col_local_offset = 1
772 DO j_blk_local = 1, nblkcols_local
773 start_row_index = row_local_offset
774 end_row_index = start_row_index + row_blk_size(local_blk_rows(i_blk_local)) - 1
775 start_col_index = col_local_offset
776 end_col_index = start_col_index + col_blk_size(local_blk_cols(j_blk_local)) - 1
777 CALL build_3c_integral_block(int_3c(start_row_index:end_row_index, &
778 start_col_index:end_col_index, &
779 1:n_ri), &
780 qs_env, potential_parameter=ri_metric, &
781 basis_j=basis_set_ao, basis_k=basis_set_ao, &
782 basis_i=basis_set_ri, &
783 atom_j=local_blk_rows(i_blk_local), &
784 atom_k=local_blk_cols(j_blk_local), &
785 i_bf_start_from_atom=i_ri_start_from_atom)
786 col_local_offset = col_local_offset + col_blk_size(local_blk_cols(j_blk_local))
787 END DO
788 row_local_offset = row_local_offset + row_blk_size(local_blk_rows(i_blk_local))
789 END DO
790 END SUBROUTINE create_hartree_ri_3c
791! **************************************************************************************************
792!> \brief Releases the workspace for the Hartree RI method
793!> \param rtbse_env RT-BSE Environment, containing specific RI Hartree storage
794!> \author Stepan Marek
795!> \date 09.2024
796! **************************************************************************************************
797 SUBROUTINE release_hartree_ri_workspace(rtbse_env)
798 TYPE(rtbse_env_type) :: rtbse_env
799
800 DEALLOCATE (rtbse_env%int_3c_array)
801
802 CALL dbcsr_release(rtbse_env%rho_dbcsr)
803
804 CALL dbcsr_release(rtbse_env%v_dbcsr)
805
806 CALL dbcsr_release(rtbse_env%v_ao_dbcsr)
807
808 END SUBROUTINE release_hartree_ri_workspace
809! **************************************************************************************************
810!> \brief Allocates the workspaces for self-energy determination routine
811!> \param rtbse_env Structure for holding information and workspace structures
812!> \param qs_env Quickstep environment - entry point of calculation
813!> \author Stepan Marek
814!> \date 02.2024
815! **************************************************************************************************
816 SUBROUTINE create_sigma_workspace(rtbse_env, qs_env)
817 TYPE(rtbse_env_type) :: rtbse_env
818 TYPE(qs_environment_type), POINTER :: qs_env
819
820 CALL create_sigma_workspace_qs_only(qs_env, rtbse_env%screened_dbt, rtbse_env%w_dbcsr, &
821 rtbse_env%t_3c_w, rtbse_env%t_3c_work_RI_AO__AO, &
822 rtbse_env%t_3c_work2_RI_AO__AO, rtbse_env%greens_dbt)
823 END SUBROUTINE create_sigma_workspace
824! **************************************************************************************************
825!> \brief Allocates the workspaces for self-energy determination routine
826!> \note Does so without referencing the rtbse_env
827!> \note References bs_env
828!> \param rtbse_env Structure for holding information and workspace structures
829!> \param qs_env Quickstep environment - entry point of calculation
830!> \author Stepan Marek
831!> \date 02.2024
832! **************************************************************************************************
833 SUBROUTINE create_sigma_workspace_qs_only(qs_env, screened_dbt, screened_dbcsr, int_3c_dbt, &
834 work_dbt_3c_1, work_dbt_3c_2, work_dbt_2c)
835 TYPE(qs_environment_type), POINTER :: qs_env
836 TYPE(dbcsr_type) :: screened_dbcsr
837 TYPE(dbt_type) :: screened_dbt, &
838 int_3c_dbt, &
839 work_dbt_3c_1, &
840 work_dbt_3c_2, &
841 work_dbt_2c
842 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
843
844 CALL get_qs_env(qs_env, bs_env=bs_env)
845
846 ! t_3c_w
847 CALL dbt_create(bs_env%t_RI__AO_AO, int_3c_dbt)
848 ! TODO : Provide option/decision whether to store the 3c integrals precomputed
849 CALL compute_3c_integrals(qs_env, bs_env, int_3c_dbt)
850 ! t_3c_work_RI_AO__AO
851 CALL dbt_create(bs_env%t_RI_AO__AO, work_dbt_3c_1)
852 ! t_3c_work2_RI_AO__AO
853 CALL dbt_create(bs_env%t_RI_AO__AO, work_dbt_3c_2)
854 ! t_W
855 ! Populate screened_dbt from gw run
856 CALL dbcsr_create(screened_dbcsr, name="W", template=bs_env%mat_RI_RI%matrix)
857 CALL dbt_create(screened_dbcsr, screened_dbt)
858 ! greens_dbt
859 CALL dbt_create(bs_env%mat_ao_ao%matrix, work_dbt_2c)
860 END SUBROUTINE
861! **************************************************************************************************
862!> \brief Releases the workspaces for self-energy determination
863!> \param rtbse_env
864!> \author Stepan Marek
865!> \date 02.2024
866! **************************************************************************************************
867 SUBROUTINE release_sigma_workspace(rtbse_env)
868 TYPE(rtbse_env_type) :: rtbse_env
869
870 CALL dbt_destroy(rtbse_env%t_3c_w)
871 CALL dbt_destroy(rtbse_env%t_3c_work_RI_AO__AO)
872 CALL dbt_destroy(rtbse_env%t_3c_work2_RI_AO__AO)
873 CALL dbt_destroy(rtbse_env%screened_dbt)
874 CALL dbt_destroy(rtbse_env%greens_dbt)
875 CALL dbcsr_release(rtbse_env%w_dbcsr)
876 END SUBROUTINE
877! **************************************************************************************************
878!> \brief Multiplies real matrix by a complex matrix from the right
879!> \note So far only converts the real matrix to complex one, potentially doubling the work
880!> \param rtbse_env
881!> \author Stepan Marek
882!> \date 09.2024
883! **************************************************************************************************
884 SUBROUTINE multiply_fm_cfm(trans_r, trans_c, na, nb, nc, &
885 alpha, matrix_r, matrix_c, beta, res)
886 ! Transposition
887 CHARACTER(len=1) :: trans_r, trans_c
888 INTEGER :: na, nb, nc
889 ! accept real numbers
890 ! TODO : Just use complex numbers and import z_one, z_zero etc.
891 REAL(kind=dp) :: alpha, beta
892 TYPE(cp_fm_type) :: matrix_r
893 TYPE(cp_cfm_type) :: matrix_c, res
894 TYPE(cp_fm_type) :: work_re, work_im, res_re, res_im
895 REAL(kind=dp) :: i_unit
896 CHARACTER(len=1) :: trans_cr
897
898 CALL cp_fm_create(work_re, matrix_c%matrix_struct)
899 CALL cp_fm_create(work_im, matrix_c%matrix_struct)
900 CALL cp_fm_create(res_re, res%matrix_struct)
901 CALL cp_fm_create(res_im, res%matrix_struct)
902 CALL cp_cfm_to_fm(matrix_c, work_re, work_im)
903 SELECT CASE (trans_c)
904 CASE ("C")
905 i_unit = -1.0_dp
906 trans_cr = "T"
907 CASE ("T")
908 i_unit = 1.0_dp
909 trans_cr = "T"
910 CASE default
911 i_unit = 1.0_dp
912 trans_cr = "N"
913 END SELECT
914 ! Actual multiplication
915 CALL parallel_gemm(trans_r, trans_cr, na, nb, nc, &
916 alpha, matrix_r, work_re, beta, res_re)
917 CALL parallel_gemm(trans_r, trans_cr, na, nb, nc, &
918 i_unit*alpha, matrix_r, work_im, beta, res_im)
919 CALL cp_fm_to_cfm(res_re, res_im, res)
920 CALL cp_fm_release(work_re)
921 CALL cp_fm_release(work_im)
922 CALL cp_fm_release(res_re)
923 CALL cp_fm_release(res_im)
924
925 END SUBROUTINE multiply_fm_cfm
926! **************************************************************************************************
927!> \brief Multiplies complex matrix by a real matrix from the right
928!> \note So far only converts the real matrix to complex one, potentially doubling the work
929!> \param rtbse_env
930!> \author Stepan Marek
931!> \date 09.2024
932! **************************************************************************************************
933 SUBROUTINE multiply_cfm_fm(trans_c, trans_r, na, nb, nc, &
934 alpha, matrix_c, matrix_r, beta, res)
935 ! Transposition
936 CHARACTER(len=1) :: trans_c, trans_r
937 INTEGER :: na, nb, nc
938 ! accept real numbers
939 ! TODO : complex number support via interface?
940 REAL(kind=dp) :: alpha, beta
941 TYPE(cp_cfm_type) :: matrix_c, res
942 TYPE(cp_fm_type) :: matrix_r
943 TYPE(cp_fm_type) :: work_re, work_im, res_re, res_im
944 REAL(kind=dp) :: i_unit
945 CHARACTER(len=1) :: trans_cr
946
947 CALL cp_fm_create(work_re, matrix_c%matrix_struct)
948 CALL cp_fm_create(work_im, matrix_c%matrix_struct)
949 CALL cp_fm_create(res_re, res%matrix_struct)
950 CALL cp_fm_create(res_im, res%matrix_struct)
951 CALL cp_cfm_to_fm(matrix_c, work_re, work_im)
952 SELECT CASE (trans_c)
953 CASE ("C")
954 i_unit = -1.0_dp
955 trans_cr = "T"
956 CASE ("T")
957 i_unit = 1.0_dp
958 trans_cr = "T"
959 CASE default
960 i_unit = 1.0_dp
961 trans_cr = "N"
962 END SELECT
963 ! Actual multiplication
964 CALL parallel_gemm(trans_cr, trans_r, na, nb, nc, &
965 alpha, work_re, matrix_r, beta, res_re)
966 CALL parallel_gemm(trans_cr, trans_r, na, nb, nc, &
967 i_unit*alpha, work_im, matrix_r, beta, res_im)
968 CALL cp_fm_to_cfm(res_re, res_im, res)
969 CALL cp_fm_release(work_re)
970 CALL cp_fm_release(work_im)
971 CALL cp_fm_release(res_re)
972 CALL cp_fm_release(res_im)
973
974 END SUBROUTINE multiply_cfm_fm
975END MODULE
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
Basic linear algebra operations for complex full matrices.
subroutine, public cp_cfm_column_scale(matrix_a, scaling)
Scales columns of the full matrix by corresponding factors.
Represents a complex full matrix distributed on many processors.
subroutine, public cp_cfm_create(matrix, matrix_struct, name)
Creates a new full matrix with the given structure.
subroutine, public cp_cfm_release(matrix)
Releases a full matrix.
subroutine, public cp_fm_to_cfm(msourcer, msourcei, mtarget)
Construct a complex full matrix by taking its real and imaginary parts from two separate real-value f...
subroutine, public cp_cfm_set_all(matrix, alpha, beta)
Set all elements of the full matrix to alpha. Besides, set all diagonal matrix elements to beta (if g...
subroutine, public cp_cfm_to_fm(msource, mtargetr, mtargeti)
Copy real and imaginary parts of a complex full matrix into separate real-value full matrices.
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_scale(matrix, alpha_scalar)
...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_get_info(matrix, nblkrows_total, nblkcols_total, nfullrows_total, nfullcols_total, nblkrows_local, nblkcols_local, nfullrows_local, nfullcols_local, my_prow, my_pcol, local_rows, local_cols, proc_row_dist, proc_col_dist, row_blk_size, col_blk_size, row_blk_offset, col_blk_offset, distribution, name, matrix_type, group)
...
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_release(matrix)
...
subroutine, public dbcsr_print(matrix, variable_name, unit_nr)
Prints given matrix in matlab format (only present blocks).
DBCSR operations in CP2K.
subroutine, public copy_dbcsr_to_fm(matrix, fm)
Copy a DBCSR matrix to a BLACS matrix.
subroutine, public copy_fm_to_dbcsr(fm, matrix, keep_sparsity)
Copy a BLACS matrix to a dbcsr matrix.
Basic linear algebra operations for full matrices.
subroutine, public cp_fm_column_scale(matrixa, scaling)
scales column i of matrix a with scaling(i)
subroutine, public cp_fm_transpose(matrix, matrixt)
transposes a matrix matrixt = matrix ^ T
subroutine, public cp_fm_scale_and_add(alpha, matrix_a, beta, matrix_b)
calc A <- alpha*A + beta*B optimized for alpha == 1.0 (just add beta*B) and beta == 0....
subroutine, public cp_fm_invert(matrix_a, matrix_inverse, det_a, eps_svd, eigval)
Inverts a cp_fm_type matrix, optionally returning the determinant of the input matrix.
represent a full matrix distributed on many processors
Definition cp_fm_types.F:15
subroutine, public cp_fm_set_all(matrix, alpha, beta)
set all elements of a matrix to the same value, and optionally the diagonal to a different one
subroutine, public cp_fm_create(matrix, matrix_struct, name, use_sp)
creates a new full matrix with the given structure
subroutine, public cp_fm_write_formatted(fm, unit, header, value_format)
Write out a full matrix in plain text.
This is the start of a dbt_api, all publically needed functions are exported here....
Definition dbt_api.F:17
Interface for the force calculations.
Utility method to build 3-center integrals for small cell GW.
subroutine, public build_3c_integral_block(int_3c, qs_env, potential_parameter, basis_j, basis_k, basis_i, cell_j, cell_k, cell_i, atom_j, atom_k, atom_i, j_bf_start_from_atom, k_bf_start_from_atom, i_bf_start_from_atom)
...
Routines from paper [Graml2024].
subroutine, public compute_3c_integrals(qs_env, bs_env, t_3c, atoms_ao_1, atoms_ao_2, atoms_ri)
...
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public use_mom_ref_coac
integer, parameter, public do_bch
integer, parameter, public use_mom_ref_user
integer, parameter, public use_mom_ref_com
integer, parameter, public do_exact
integer, parameter, public use_mom_ref_zero
integer, parameter, public rtp_bse_ham_g0w0
integer, parameter, public do_taylor
integer, parameter, public rtp_bse_ham_ks
objects that represent the structure of input sections and the data contained in an input section
recursive type(section_vals_type) function, pointer, public section_vals_get_subs_vals(section_vals, subsection_name, i_rep_section, can_return_null)
returns the values of the requested subsection
subroutine, public section_vals_get(section_vals, ref_count, n_repetition, n_subs_vals_rep, section, explicit)
returns various attributes about the section_vals
subroutine, public section_vals_val_get(section_vals, keyword_name, i_rep_section, i_rep_val, n_rep_val, val, l_val, i_val, r_val, c_val, l_vals, i_vals, r_vals, c_vals, explicit)
returns the requested value
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
2- and 3-center electron repulsion integral routines based on libint2 Currently available operators: ...
Interface to the Libint-Library or a c++ wrapper.
subroutine, public cp_libint_static_init()
Definition of mathematical constants and functions.
complex(kind=dp), parameter, public z_zero
Routines for calculating a complex matrix exponential.
Definition matrix_exp.F:13
subroutine, public get_nsquare_norder(norm, nsquare, norder, eps_exp, method, do_emd)
optimization function for pade/taylor order and number of squaring steps
Definition matrix_exp.F:244
Calculates the moment integrals <a|r^m|b>
subroutine, public get_reference_point(rpoint, drpoint, qs_env, fist_env, reference, ref_point, ifirst, ilast)
...
basic linear algebra operations for full matrixes
Definition of physical constants:
Definition physcon.F:68
real(kind=dp), parameter, public angstrom
Definition physcon.F:144
subroutine, public create_and_init_bs_env(qs_env, bs_env, post_scf_bandstructure_section)
...
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, ecoul_1c, rho0_s_rs, rho0_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, do_rixs, tb_tblite)
Get the QUICKSTEP environment.
Definition and initialisation of the mo data type.
Definition qs_mo_types.F:22
Calculates the moment integrals <a|r^m|b> and <a|r x d/dr|b>
Definition qs_moments.F:14
subroutine, public build_local_moment_matrix(qs_env, moments, nmoments, ref_point, ref_points, basis_type)
...
Definition qs_moments.F:560
Utility methods to build 3-center integral tensors of various types.
Definition qs_tensors.F:11
subroutine, public neighbor_list_3c_destroy(ijk_list)
Destroy 3c neighborlist.
Definition qs_tensors.F:385
Data storage and other types for propagation via RT-BSE method.
subroutine, public release_rtbse_env(rtbse_env)
Releases the environment allocated structures.
subroutine, public create_hartree_ri_3c(rho_dbcsr, int_3c, n_ao, n_ri, basis_set_ao, basis_set_ri, i_ri_start_from_atom, ri_metric, qs_env, unit_nr)
Separated method for allocating the 3c integrals for RI Hartree.
subroutine, public multiply_cfm_fm(trans_c, trans_r, na, nb, nc, alpha, matrix_c, matrix_r, beta, res)
Multiplies complex matrix by a real matrix from the right.
subroutine, public create_sigma_workspace_qs_only(qs_env, screened_dbt, screened_dbcsr, int_3c_dbt, work_dbt_3c_1, work_dbt_3c_2, work_dbt_2c)
Allocates the workspaces for self-energy determination routine.
subroutine, public create_rtbse_env(rtbse_env, qs_env, force_env)
Allocates structures and prepares rtbse_env for run.
subroutine, public multiply_fm_cfm(trans_r, trans_c, na, nb, nc, alpha, matrix_r, matrix_c, beta, res)
Multiplies real matrix by a complex matrix from the right.
Routines for propagating the orbitals.
subroutine, public s_matrices_create(s_mat, rtp)
calculates the needed overlap-like matrices depending on the way the exponential is calculated,...
Types and set_get for real time propagation depending on runtype and diagonalization method different...
subroutine, public get_rtp(rtp, exp_h_old, exp_h_new, h_last_iter, rho_old, rho_next, rho_new, mos, mos_new, mos_old, mos_next, s_inv, s_half, s_minus_half, b_mat, c_mat, propagator_matrix, mixing, mixing_factor, s_der, dt, nsteps, sinvh, sinvh_imag, sinvb, admm_mos)
...
Routines needed for EMD.
subroutine, public warn_section_unused(section, subsection_name, error_message)
Warn about unused sections of the print section - only implemented for some of the methods.
Routines for that prepare rtp and EMD.
subroutine, public rt_initialize_rho_from_mos(rtp, mos, mos_old)
Computes the density matrix from the mos Update: Initialized the density matrix from complex mos (for...
Just to build arrays of pointers to matrices.
Represent a complex full matrix.
just to build arrays of pointers to matrices
represent a full matrix
wrapper to abstract the force evaluation of the various methods