(git:27c966b)
Loading...
Searching...
No Matches
rpa_util.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief Utility functions for RPA calculations
10!> \par History
11!> 06.2019 Moved from rpa_ri_gpw.F [Frederick Stein]
12! **************************************************************************************************
14
15 USE cell_types, ONLY: cell_type,&
26 USE cp_dbcsr_api, ONLY: &
39 USE cp_fm_types, ONLY: &
42 USE dbt_api, ONLY: dbt_destroy,&
43 dbt_type
47 USE hfx_types, ONLY: block_ind_type,&
52 USE kinds, ONLY: dp
53 USE kpoint_types, ONLY: get_kpoint_info,&
56 USE mathconstants, ONLY: z_zero
64#include "./base/base_uses.f90"
65
66 IMPLICIT NONE
67
68 PRIVATE
69
70 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'rpa_util'
71
74
75CONTAINS
76
77! **************************************************************************************************
78!> \brief ...
79!> \param qs_env ...
80!> \param para_env ...
81!> \param dimen_RI ...
82!> \param dimen_RI_red ...
83!> \param num_integ_points ...
84!> \param nspins ...
85!> \param create_cfm_mo_coeff whether to promote the real Gamma-point coefficients to CFM
86!> \param fm_mat_Q ...
87!> \param cfm_mo_coeff ...
88!> \param cfm_matrix_Minv_L_kpoints ...
89!> \param cfm_matrix_L_kpoints ...
90!> \param fm_matrix_Minv_L_gamma ...
91!> \param mat_P_global ...
92!> \param t_3c_O ...
93!> \param matrix_s ...
94!> \param kpoints ...
95!> \param eps_filter_im_time ...
96!> \param cut_memory ...
97!> \param nkp ...
98!> \param num_cells_dm ...
99!> \param num_3c_repl ...
100!> \param size_P ...
101!> \param ikp_local ...
102!> \param index_to_cell_3c ...
103!> \param cell_to_index_3c ...
104!> \param col_blk_size ...
105!> \param do_ic_model ...
106!> \param do_kpoints_cubic_RPA ...
107!> \param do_kpoints_from_Gamma ...
108!> \param do_ri_Sigma_x ...
109!> \param my_open_shell ...
110!> \param has_mat_P_blocks ...
111!> \param wkp_W ...
112!> \param cfm_mat_Q ...
113!> \param cfm_mat_Minv_L_kpoints ...
114!> \param cfm_mat_L_kpoints ...
115!> \param fm_mat_Minv_L_gamma ...
116!> \param cfm_mat_RI_global_work ...
117!> \param fm_mat_work ...
118!> \param mat_dm ...
119!> \param mat_L ...
120!> \param mat_M_P_munu_occ ...
121!> \param mat_M_P_munu_virt ...
122!> \param mat_MinvVMinv ...
123!> \param mat_P_omega ...
124!> \param mat_P_omega_kp ...
125!> \param mat_work ...
126!> \param mo_coeff ...
127! **************************************************************************************************
128 SUBROUTINE alloc_im_time(qs_env, para_env, dimen_RI, dimen_RI_red, num_integ_points, nspins, &
129 create_cfm_mo_coeff, &
130 fm_mat_Q, cfm_mo_coeff, &
131 cfm_matrix_Minv_L_kpoints, cfm_matrix_L_kpoints, fm_matrix_Minv_L_gamma, mat_P_global, &
132 t_3c_O, matrix_s, kpoints, eps_filter_im_time, &
133 cut_memory, nkp, num_cells_dm, num_3c_repl, &
134 size_P, ikp_local, &
135 index_to_cell_3c, &
136 cell_to_index_3c, &
137 col_blk_size, &
138 do_ic_model, do_kpoints_cubic_RPA, &
139 do_kpoints_from_Gamma, do_ri_Sigma_x, my_open_shell, &
140 has_mat_P_blocks, wkp_W, &
141 cfm_mat_Q, cfm_mat_Minv_L_kpoints, cfm_mat_L_kpoints, fm_mat_Minv_L_gamma, &
142 cfm_mat_RI_global_work, fm_mat_work, mat_dm, mat_L, mat_M_P_munu_occ, mat_M_P_munu_virt, &
143 mat_MinvVMinv, mat_P_omega, mat_P_omega_kp, &
144 mat_work, mo_coeff)
145
146 TYPE(qs_environment_type), POINTER :: qs_env
147 TYPE(mp_para_env_type), POINTER :: para_env
148 INTEGER, INTENT(IN) :: dimen_ri, dimen_ri_red, &
149 num_integ_points, nspins
150 LOGICAL, INTENT(IN) :: create_cfm_mo_coeff
151 TYPE(cp_fm_type), INTENT(IN) :: fm_mat_q
152 TYPE(cp_cfm_type), ALLOCATABLE, DIMENSION(:) :: cfm_mo_coeff, cfm_matrix_minv_l_kpoints, &
153 cfm_matrix_l_kpoints
154 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:, :) :: fm_matrix_minv_l_gamma
155 TYPE(dbcsr_p_type), INTENT(IN) :: mat_p_global
156 TYPE(dbt_type), ALLOCATABLE, DIMENSION(:, :), &
157 INTENT(INOUT) :: t_3c_o
158 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s
159 TYPE(kpoint_type), POINTER :: kpoints
160 REAL(kind=dp), INTENT(IN) :: eps_filter_im_time
161 INTEGER, INTENT(IN) :: cut_memory
162 INTEGER, INTENT(OUT) :: nkp, num_cells_dm, num_3c_repl, size_p, &
163 ikp_local
164 INTEGER, ALLOCATABLE, DIMENSION(:, :), INTENT(OUT) :: index_to_cell_3c
165 INTEGER, ALLOCATABLE, DIMENSION(:, :, :), &
166 INTENT(OUT) :: cell_to_index_3c
167 INTEGER, DIMENSION(:), POINTER :: col_blk_size
168 LOGICAL, INTENT(IN) :: do_ic_model, do_kpoints_cubic_rpa, &
169 do_kpoints_from_gamma, do_ri_sigma_x, &
170 my_open_shell
171 LOGICAL, ALLOCATABLE, DIMENSION(:, :, :, :, :), &
172 INTENT(OUT) :: has_mat_p_blocks
173 REAL(kind=dp), ALLOCATABLE, DIMENSION(:), &
174 INTENT(OUT) :: wkp_w
175 TYPE(cp_cfm_type), INTENT(OUT) :: cfm_mat_q
176 TYPE(cp_cfm_type), ALLOCATABLE, DIMENSION(:) :: cfm_mat_minv_l_kpoints, cfm_mat_l_kpoints
177 TYPE(cp_fm_type), INTENT(OUT) :: fm_mat_minv_l_gamma
178 TYPE(cp_cfm_type), INTENT(OUT) :: cfm_mat_ri_global_work
179 TYPE(cp_fm_type), INTENT(OUT) :: fm_mat_work
180 TYPE(dbcsr_p_type), INTENT(OUT) :: mat_dm, mat_l, mat_m_p_munu_occ, &
181 mat_m_p_munu_virt, mat_minvvminv
182 TYPE(dbcsr_p_type), ALLOCATABLE, &
183 DIMENSION(:, :, :) :: mat_p_omega
184 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: mat_p_omega_kp
185 TYPE(dbcsr_type), POINTER :: mat_work
186 TYPE(cp_fm_type), DIMENSION(:), INTENT(IN) :: mo_coeff
187
188 CHARACTER(LEN=*), PARAMETER :: routinen = 'alloc_im_time'
189
190 INTEGER :: cell_grid_dm(3), first_ikp_local, &
191 handle, i_dim, i_kp, ispin, jquad, &
192 nspins_p_omega, periodic(3)
193 INTEGER, DIMENSION(:), POINTER :: row_blk_size
194 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: wkp_v
195 TYPE(cell_type), POINTER :: cell
196 TYPE(cp_fm_struct_type), POINTER :: fm_struct_sub_kp
197
198 CALL timeset(routinen, handle)
199
200 NULLIFY (mat_l%matrix)
201
202 IF (create_cfm_mo_coeff) THEN
203 ALLOCATE (cfm_mo_coeff(nspins))
204 DO ispin = 1, SIZE(mo_coeff)
205 CALL create_mo_coeff(cfm_mo_coeff(ispin), mo_coeff(ispin))
206 END DO
207 END IF
208
209 num_3c_repl = SIZE(t_3c_o, 2)
210
211 IF (do_kpoints_cubic_rpa) THEN
212 ! we always use an odd number of image cells
213 ! CAUTION: also at another point, cell_grid_dm is defined, these definitions have to be identical
214 DO i_dim = 1, 3
215 cell_grid_dm(i_dim) = (kpoints%nkp_grid(i_dim)/2)*2 - 1
216 END DO
217 num_cells_dm = cell_grid_dm(1)*cell_grid_dm(2)*cell_grid_dm(3)
218 ALLOCATE (index_to_cell_3c(3, SIZE(kpoints%index_to_cell, 2)))
219 cpassert(SIZE(kpoints%index_to_cell, 1) == 3)
220 index_to_cell_3c(:, :) = kpoints%index_to_cell(:, :)
221 ALLOCATE (cell_to_index_3c(lbound(kpoints%cell_to_index, 1):ubound(kpoints%cell_to_index, 1), &
222 lbound(kpoints%cell_to_index, 2):ubound(kpoints%cell_to_index, 2), &
223 lbound(kpoints%cell_to_index, 3):ubound(kpoints%cell_to_index, 3)))
224 cell_to_index_3c(:, :, :) = kpoints%cell_to_index(:, :, :)
225
226 ELSE
227 ALLOCATE (index_to_cell_3c(3, 1))
228 index_to_cell_3c(:, 1) = 0
229 ALLOCATE (cell_to_index_3c(0:0, 0:0, 0:0))
230 cell_to_index_3c(0, 0, 0) = 1
231 num_cells_dm = 1
232 END IF
233
234 IF (do_kpoints_cubic_rpa .OR. do_kpoints_from_gamma) THEN
235
236 CALL get_sub_para_kp(fm_struct_sub_kp, para_env, dimen_ri, ikp_local, first_ikp_local)
237
238 CALL cp_cfm_create(cfm_mat_q, fm_struct_sub_kp)
239 CALL cp_cfm_set_all(cfm_mat_q, z_zero)
240 ELSE
241 first_ikp_local = 1
242 END IF
243
244 ! if we do kpoints, mat_P has a kpoint and mat_P_omega has the inted
245 ! mat_P(tau, kpoint)
246 IF (do_kpoints_cubic_rpa .OR. do_kpoints_from_gamma) THEN
247
248 NULLIFY (cell)
249 CALL get_qs_env(qs_env, cell=cell)
250 CALL get_cell(cell=cell, periodic=periodic)
251
252 CALL get_kpoint_info(kpoints, nkp=nkp)
253 ! compute k-point weights such that functions 1/k^2, 1/k and const function are
254 ! integrated correctly
255 CALL compute_wkp_w(qs_env, wkp_w, wkp_v, kpoints, cell%h_inv, periodic)
256 DEALLOCATE (wkp_v)
257
258 ELSE
259 nkp = 1
260 END IF
261
262 IF (do_kpoints_cubic_rpa) THEN
263 size_p = max(num_cells_dm/2 + 1, nkp)
264 ELSE IF (do_kpoints_from_gamma) THEN
265 size_p = max(3**(periodic(1) + periodic(2) + periodic(3)), nkp)
266 ELSE
267 size_p = 1
268 END IF
269
270 nspins_p_omega = 1
271 IF (my_open_shell) nspins_p_omega = 2
272
273 ALLOCATE (mat_p_omega(num_integ_points, size_p, nspins_p_omega))
274 DO ispin = 1, nspins_p_omega
275 DO i_kp = 1, size_p
276 DO jquad = 1, num_integ_points
277 NULLIFY (mat_p_omega(jquad, i_kp, ispin)%matrix)
278 ALLOCATE (mat_p_omega(jquad, i_kp, ispin)%matrix)
279 CALL dbcsr_create(matrix=mat_p_omega(jquad, i_kp, ispin)%matrix, &
280 template=mat_p_global%matrix)
281 CALL dbcsr_set(mat_p_omega(jquad, i_kp, ispin)%matrix, 0.0_dp)
282 END DO
283 END DO
284 END DO
285
286 IF (do_kpoints_cubic_rpa .OR. do_kpoints_from_gamma) THEN
287 CALL alloc_mat_p_omega(mat_p_omega_kp, 2, size_p, mat_p_global%matrix)
288 END IF
289
290 IF (do_kpoints_cubic_rpa .OR. do_kpoints_from_gamma) THEN
291 CALL cp_cfm_create(cfm_mat_ri_global_work, cfm_matrix_minv_l_kpoints(1)%matrix_struct, set_zero=.true.)
292 END IF
293
294 ALLOCATE (has_mat_p_blocks(num_cells_dm/2 + 1, cut_memory, cut_memory, num_3c_repl, num_3c_repl))
295 has_mat_p_blocks = .true.
296
297 IF (do_kpoints_cubic_rpa .OR. do_kpoints_from_gamma) THEN
298 CALL reorder_cfm_mat_l(cfm_mat_minv_l_kpoints, cfm_matrix_minv_l_kpoints, fm_struct_sub_kp, para_env, &
299 first_ikp_local, ikp_local)
300
301 CALL reorder_cfm_mat_l(cfm_mat_l_kpoints, cfm_matrix_l_kpoints, fm_struct_sub_kp, para_env, &
302 first_ikp_local, ikp_local)
303
304 CALL cp_fm_struct_release(fm_struct_sub_kp)
305
306 ELSE
307 CALL reorder_mat_l(fm_mat_minv_l_gamma, fm_matrix_minv_l_gamma, fm_mat_q%matrix_struct, mat_l, &
308 mat_p_global%matrix, dimen_ri, dimen_ri_red)
309 END IF
310
311 ! Create Scalapack working matrix for the contraction with the metric
312 IF (dimen_ri == dimen_ri_red) THEN
313 CALL cp_fm_create(fm_mat_work, fm_mat_q%matrix_struct, set_zero=.true.)
314
315 ELSE
316 CALL cp_fm_create(fm_mat_work, fm_mat_q%matrix_struct, nrow=dimen_ri, ncol=dimen_ri_red, &
317 set_zero=.true.)
318
319 END IF
320
321 ! Then its DBCSR counter part
322 IF (.NOT. (do_kpoints_cubic_rpa .OR. do_kpoints_from_gamma)) THEN
323 CALL dbcsr_get_info(mat_l%matrix, col_blk_size=col_blk_size, row_blk_size=row_blk_size)
324
325 ! Create mat_work having the shape of the transposed of mat_L (compare with contract_P_omega_with_mat_L)
326 NULLIFY (mat_work)
327 ALLOCATE (mat_work)
328 CALL dbcsr_create(mat_work, template=mat_l%matrix, row_blk_size=col_blk_size, col_blk_size=row_blk_size)
329 END IF
330
331 IF (do_ri_sigma_x .OR. do_ic_model) THEN
332
333 NULLIFY (mat_minvvminv%matrix)
334 ALLOCATE (mat_minvvminv%matrix)
335 CALL dbcsr_create(mat_minvvminv%matrix, template=mat_p_global%matrix)
336 CALL dbcsr_set(mat_minvvminv%matrix, 0.0_dp)
337
338 ! for kpoints we compute SinvVSinv later with kpoints
339 IF (.NOT. (do_kpoints_cubic_rpa .OR. do_kpoints_from_gamma)) THEN
340
341 ! get the Coulomb matrix for Sigma_x = G*V
342 CALL dbcsr_multiply("T", "N", 1.0_dp, mat_l%matrix, mat_l%matrix, &
343 0.0_dp, mat_minvvminv%matrix, filter_eps=eps_filter_im_time)
344
345 END IF
346
347 END IF
348
349 IF (do_ri_sigma_x) THEN
350
351 NULLIFY (mat_dm%matrix)
352 ALLOCATE (mat_dm%matrix)
353 CALL dbcsr_create(mat_dm%matrix, template=matrix_s(1)%matrix)
354
355 END IF
356
357 CALL timestop(handle)
358
359 END SUBROUTINE alloc_im_time
360
361! **************************************************************************************************
362!> \brief ...
363!> \param cfm_mo_coeff ...
364!> \param mo_coeff ...
365! **************************************************************************************************
366 SUBROUTINE create_mo_coeff(cfm_mo_coeff, mo_coeff)
367
368 TYPE(cp_cfm_type), INTENT(OUT) :: cfm_mo_coeff
369 TYPE(cp_fm_type), INTENT(IN) :: mo_coeff
370
371 CHARACTER(LEN=*), PARAMETER :: routinen = 'create_mo_coeff'
372
373 INTEGER :: handle
374
375 CALL timeset(routinen, handle)
376
377 CALL cp_cfm_create(cfm_mo_coeff, mo_coeff%matrix_struct)
378 CALL cp_fm_to_cfm(msourcer=mo_coeff, mtarget=cfm_mo_coeff)
379
380 CALL timestop(handle)
381
382 END SUBROUTINE create_mo_coeff
383
384! **************************************************************************************************
385!> \brief Reorders complex k-point matrices to the subgroup distribution.
386!> \param cfm_mat_L ...
387!> \param cfm_matrix_L_kpoints ...
388!> \param fm_struct_sub_kp ...
389!> \param para_env ...
390!> \param first_ikp_local ...
391!> \param ikp_local ...
392! **************************************************************************************************
393 SUBROUTINE reorder_cfm_mat_l(cfm_mat_L, cfm_matrix_L_kpoints, fm_struct_sub_kp, para_env, first_ikp_local, ikp_local)
394
395 TYPE(cp_cfm_type), ALLOCATABLE, DIMENSION(:) :: cfm_mat_l, cfm_matrix_l_kpoints
396 TYPE(cp_fm_struct_type), POINTER :: fm_struct_sub_kp
397 TYPE(mp_para_env_type), POINTER :: para_env
398 INTEGER, INTENT(IN) :: first_ikp_local, ikp_local
399
400 CHARACTER(LEN=*), PARAMETER :: routinen = 'reorder_cfm_mat_L'
401
402 INTEGER :: handle, ikp
403
404 CALL timeset(routinen, handle)
405
406 ALLOCATE (cfm_mat_l(SIZE(cfm_matrix_l_kpoints)))
407 DO ikp = 1, SIZE(cfm_matrix_l_kpoints)
408 IF (ikp == first_ikp_local .OR. ikp_local == -1) THEN
409 CALL cp_cfm_create(cfm_mat_l(ikp), fm_struct_sub_kp, set_zero=.true.)
410 END IF
411 CALL cp_cfm_copy_general(cfm_matrix_l_kpoints(ikp), cfm_mat_l(ikp), para_env)
412 IF (ASSOCIATED(cfm_matrix_l_kpoints(ikp)%matrix_struct)) CALL cp_cfm_release(cfm_matrix_l_kpoints(ikp))
413 END DO
414 DEALLOCATE (cfm_matrix_l_kpoints)
415
416 CALL timestop(handle)
417
418 END SUBROUTINE reorder_cfm_mat_l
419
420! **************************************************************************************************
421!> \brief ...
422!> \param mat_P_omega ...
423!> \param num_integ_points ...
424!> \param size_P ...
425!> \param template ...
426! **************************************************************************************************
427 SUBROUTINE alloc_mat_p_omega(mat_P_omega, num_integ_points, size_P, template)
428 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: mat_p_omega
429 INTEGER, INTENT(IN) :: num_integ_points, size_p
430 TYPE(dbcsr_type), POINTER :: template
431
432 CHARACTER(LEN=*), PARAMETER :: routinen = 'alloc_mat_P_omega'
433
434 INTEGER :: handle, i_kp, jquad
435
436 CALL timeset(routinen, handle)
437
438 NULLIFY (mat_p_omega)
439 CALL dbcsr_allocate_matrix_set(mat_p_omega, num_integ_points, size_p)
440 DO i_kp = 1, size_p
441 DO jquad = 1, num_integ_points
442 ALLOCATE (mat_p_omega(jquad, i_kp)%matrix)
443 CALL dbcsr_create(matrix=mat_p_omega(jquad, i_kp)%matrix, &
444 template=template)
445 CALL dbcsr_set(mat_p_omega(jquad, i_kp)%matrix, 0.0_dp)
446 END DO
447 END DO
448
449 CALL timestop(handle)
450
451 END SUBROUTINE alloc_mat_p_omega
452
453! **************************************************************************************************
454!> \brief ...
455!> \param fm_mat_L ...
456!> \param fm_matrix_Minv_L_gamma ...
457!> \param fm_struct_template ...
458!> \param mat_L ...
459!> \param mat_template ...
460!> \param dimen_RI ...
461!> \param dimen_RI_red ...
462! **************************************************************************************************
463 SUBROUTINE reorder_mat_l(fm_mat_L, fm_matrix_Minv_L_gamma, fm_struct_template, mat_L, mat_template, &
464 dimen_RI, dimen_RI_red)
465 TYPE(cp_fm_type), INTENT(OUT) :: fm_mat_l
466 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:, :) :: fm_matrix_minv_l_gamma
467 TYPE(cp_fm_struct_type), POINTER :: fm_struct_template
468 TYPE(dbcsr_p_type), INTENT(OUT) :: mat_l
469 TYPE(dbcsr_type), INTENT(IN) :: mat_template
470 INTEGER, INTENT(IN) :: dimen_ri, dimen_ri_red
471
472 CHARACTER(LEN=*), PARAMETER :: routinen = 'reorder_mat_L'
473
474 INTEGER :: handle, nblk
475 INTEGER, DIMENSION(:), POINTER :: col_blk_size, row_blk_size
476 TYPE(cp_blacs_env_type), POINTER :: blacs_env
477 TYPE(cp_fm_struct_type), POINTER :: fm_struct
478 TYPE(cp_fm_type) :: fm_mat_l_transposed
479
480 CALL timeset(routinen, handle)
481
482 ! Get the fm_struct for fm_mat_L
483 NULLIFY (fm_struct)
484 IF (dimen_ri == dimen_ri_red) THEN
485 fm_struct => fm_struct_template
486 ELSE
487 ! The template is assumed to be square such that we need a new fm_struct if dimensions are not equal
488 CALL cp_fm_struct_create(fm_struct, nrow_global=dimen_ri_red, ncol_global=dimen_ri, template_fmstruct=fm_struct_template)
489 END IF
490
491 CALL cp_fm_create(fm_mat_l, fm_struct)
492 CALL cp_fm_set_all(fm_mat_l, 0.0_dp)
493
494 ! For the transposed matric we need a different fm_struct
495 IF (dimen_ri == dimen_ri_red) THEN
496 fm_struct => fm_mat_l%matrix_struct
497 ELSE
498 CALL cp_fm_struct_release(fm_struct)
499
500 ! Create a fm_struct with transposed sizes
501 NULLIFY (fm_struct)
502 CALL cp_fm_struct_create(fm_struct, nrow_global=dimen_ri, ncol_global=dimen_ri_red, &
503 template_fmstruct=fm_mat_l%matrix_struct)
504 END IF
505
506 CALL cp_fm_create(fm_mat_l_transposed, fm_struct)
507 CALL cp_fm_set_all(matrix=fm_mat_l_transposed, alpha=0.0_dp)
508
509 IF (dimen_ri /= dimen_ri_red) CALL cp_fm_struct_release(fm_struct)
510
511 CALL cp_fm_get_info(fm_mat_l_transposed, context=blacs_env)
512
513 CALL cp_fm_copy_general(fm_matrix_minv_l_gamma(1, 1), fm_mat_l_transposed, blacs_env%para_env)
514 CALL cp_fm_transpose(fm_mat_l_transposed, fm_mat_l)
515
516 ! Release old matrix
517 CALL cp_fm_release(fm_matrix_minv_l_gamma)
518 ! Release buffer
519 CALL cp_fm_release(fm_mat_l_transposed)
520
521 NULLIFY (mat_l%matrix)
522 ALLOCATE (mat_l%matrix)
523 IF (dimen_ri == dimen_ri_red) THEN
524 CALL dbcsr_create(mat_l%matrix, template=mat_template)
525 ELSE
526 CALL dbcsr_get_info(mat_template, nblkrows_total=nblk, col_blk_size=col_blk_size)
527
528 CALL calculate_equal_blk_size(row_blk_size, dimen_ri_red, nblk)
529
530 CALL dbcsr_create(mat_l%matrix, template=mat_template, row_blk_size=row_blk_size, col_blk_size=col_blk_size)
531
532 DEALLOCATE (row_blk_size)
533 END IF
534
535 CALL copy_fm_to_dbcsr(fm_mat_l, mat_l%matrix)
536
537 CALL timestop(handle)
538
539 END SUBROUTINE reorder_mat_l
540
541! **************************************************************************************************
542!> \brief ...
543!> \param blk_size_new ...
544!> \param dimen_RI_red ...
545!> \param nblk ...
546! **************************************************************************************************
547 SUBROUTINE calculate_equal_blk_size(blk_size_new, dimen_RI_red, nblk)
548 INTEGER, DIMENSION(:), POINTER :: blk_size_new
549 INTEGER, INTENT(IN) :: dimen_ri_red, nblk
550
551 INTEGER :: col_per_blk, remainder
552
553 NULLIFY (blk_size_new)
554 ALLOCATE (blk_size_new(nblk))
555
556 remainder = mod(dimen_ri_red, nblk)
557 col_per_blk = dimen_ri_red/nblk
558
559 ! Determine a new distribution for the columns (corresponding to the number of columns)
560 IF (remainder > 0) blk_size_new(1:remainder) = col_per_blk + 1
561 blk_size_new(remainder + 1:nblk) = col_per_blk
562
563 END SUBROUTINE calculate_equal_blk_size
564
565! **************************************************************************************************
566!> \brief ...
567!> \param fm_mat_S ...
568!> \param do_ri_sos_laplace_mp2 ...
569!> \param first_cycle ...
570!> \param virtual ...
571!> \param Eigenval ...
572!> \param homo ...
573!> \param omega ...
574!> \param omega_old ...
575!> \param jquad ...
576!> \param mm_style ...
577!> \param dimen_RI ...
578!> \param dimen_ia ...
579!> \param alpha ...
580!> \param fm_mat_Q ...
581!> \param fm_mat_Q_gemm ...
582!> \param do_bse ...
583!> \param fm_mat_Q_static_bse_gemm ...
584!> \param dgemm_counter ...
585!> \param num_integ_points ...
586!> \param count_ev_sc_GW ...
587! **************************************************************************************************
588 SUBROUTINE calc_mat_q(fm_mat_S, do_ri_sos_laplace_mp2, first_cycle, virtual, &
589 Eigenval, homo, omega, omega_old, jquad, mm_style, dimen_RI, dimen_ia, alpha, fm_mat_Q, fm_mat_Q_gemm, &
590 do_bse, fm_mat_Q_static_bse_gemm, dgemm_counter, &
591 num_integ_points, count_ev_sc_GW)
592 TYPE(cp_fm_type), INTENT(IN) :: fm_mat_s
593 LOGICAL, INTENT(IN) :: do_ri_sos_laplace_mp2, first_cycle
594 INTEGER, INTENT(IN) :: virtual
595 REAL(kind=dp), DIMENSION(:), INTENT(IN) :: eigenval
596 INTEGER, INTENT(IN) :: homo
597 REAL(kind=dp), INTENT(IN) :: omega, omega_old
598 INTEGER, INTENT(IN) :: jquad, mm_style, dimen_ri, dimen_ia
599 REAL(kind=dp), INTENT(IN) :: alpha
600 TYPE(cp_fm_type), INTENT(IN) :: fm_mat_q, fm_mat_q_gemm
601 LOGICAL, INTENT(IN) :: do_bse
602 TYPE(cp_fm_type), INTENT(IN) :: fm_mat_q_static_bse_gemm
603 TYPE(dgemm_counter_type), INTENT(INOUT) :: dgemm_counter
604 INTEGER, INTENT(IN) :: num_integ_points, count_ev_sc_gw
605
606 CHARACTER(LEN=*), PARAMETER :: routinen = 'calc_mat_Q'
607
608 INTEGER :: handle
609
610 CALL timeset(routinen, handle)
611
612 IF (do_ri_sos_laplace_mp2) THEN
613 ! the first index of tau_tj starts with 0 (see mp2_weights)
614 CALL calc_fm_mat_s_laplace(fm_mat_s, homo, virtual, eigenval, omega - omega_old)
615 ELSE
616 CALL calc_fm_mat_s_rpa(fm_mat_s, first_cycle, virtual, eigenval, &
617 homo, omega, omega_old)
618 END IF
619
620 CALL contract_s_to_q(mm_style, dimen_ri, dimen_ia, alpha, fm_mat_s, fm_mat_q_gemm, &
621 fm_mat_q, dgemm_counter)
622 ! fm_mat_Q_static_bse_gemm does not enter W_ijab (A matrix in TDA), but only full ABBA
623 ! (since only B_ij_bar enters W_ijab)
624 ! Changing jquad, since omega=0 is at last idx
625 ! We enforce W0 for BSE in case of evGW
626 IF (do_bse .AND. jquad == num_integ_points .AND. count_ev_sc_gw == 1) THEN
627 CALL cp_fm_to_fm(fm_mat_q_gemm, fm_mat_q_static_bse_gemm)
628 END IF
629 CALL timestop(handle)
630
631 END SUBROUTINE calc_mat_q
632
633! **************************************************************************************************
634!> \brief ...
635!> \param fm_mat_S ...
636!> \param virtual ...
637!> \param Eigenval_last ...
638!> \param homo ...
639!> \param omega_old ...
640! **************************************************************************************************
641 SUBROUTINE remove_scaling_factor_rpa(fm_mat_S, virtual, Eigenval_last, homo, omega_old)
642 TYPE(cp_fm_type), INTENT(IN) :: fm_mat_s
643 INTEGER, INTENT(IN) :: virtual
644 REAL(kind=dp), DIMENSION(:), INTENT(IN) :: eigenval_last
645 INTEGER, INTENT(IN) :: homo
646 REAL(kind=dp), INTENT(IN) :: omega_old
647
648 CHARACTER(LEN=*), PARAMETER :: routinen = 'remove_scaling_factor_rpa'
649
650 INTEGER :: avirt, handle, i_global, iib, iocc, &
651 ncol_local
652 INTEGER, DIMENSION(:), POINTER :: col_indices
653 REAL(kind=dp) :: eigen_diff
654
655 CALL timeset(routinen, handle)
656
657 ! get info of fm_mat_S
658 CALL cp_fm_get_info(matrix=fm_mat_s, &
659 ncol_local=ncol_local, &
660 col_indices=col_indices)
661
662!$OMP PARALLEL DO DEFAULT(NONE) PRIVATE(iiB,iocc,avirt,eigen_diff,i_global) &
663!$OMP SHARED(ncol_local,col_indices,Eigenval_last,fm_mat_S,virtual,homo,omega_old)
664 DO iib = 1, ncol_local
665 i_global = col_indices(iib)
666
667 iocc = max(1, i_global - 1)/virtual + 1
668 avirt = i_global - (iocc - 1)*virtual
669 eigen_diff = eigenval_last(avirt + homo) - eigenval_last(iocc)
670
671 fm_mat_s%local_data(:, iib) = fm_mat_s%local_data(:, iib)/ &
672 sqrt(eigen_diff/(eigen_diff**2 + omega_old**2))
673
674 END DO
675
676 CALL timestop(handle)
677
678 END SUBROUTINE remove_scaling_factor_rpa
679
680! **************************************************************************************************
681!> \brief ...
682!> \param fm_mat_S ...
683!> \param first_cycle ...
684!> \param virtual ...
685!> \param Eigenval ...
686!> \param homo ...
687!> \param omega ...
688!> \param omega_old ...
689! **************************************************************************************************
690 SUBROUTINE calc_fm_mat_s_rpa(fm_mat_S, first_cycle, virtual, Eigenval, homo, &
691 omega, omega_old)
692 TYPE(cp_fm_type), INTENT(IN) :: fm_mat_s
693 LOGICAL, INTENT(IN) :: first_cycle
694 INTEGER, INTENT(IN) :: virtual
695 REAL(kind=dp), DIMENSION(:), INTENT(IN) :: eigenval
696 INTEGER, INTENT(IN) :: homo
697 REAL(kind=dp), INTENT(IN) :: omega, omega_old
698
699 CHARACTER(LEN=*), PARAMETER :: routinen = 'calc_fm_mat_S_rpa'
700
701 INTEGER :: avirt, handle, i_global, iib, iocc, &
702 ncol_local
703 INTEGER, DIMENSION(:), POINTER :: col_indices
704 REAL(kind=dp) :: eigen_diff
705
706 CALL timeset(routinen, handle)
707
708 ! get info of fm_mat_S
709 CALL cp_fm_get_info(matrix=fm_mat_s, &
710 ncol_local=ncol_local, &
711 col_indices=col_indices)
712
713 ! update G matrix with the new value of omega
714 IF (first_cycle) THEN
715 ! In this case just update the matrix (symmetric form) with
716 ! SQRT((epsi_a-epsi_i)/((epsi_a-epsi_i)**2+omega**2))
717 !$OMP PARALLEL DO DEFAULT(NONE) PRIVATE(iiB,iocc,avirt,eigen_diff,i_global) &
718 !$OMP SHARED(ncol_local,col_indices,Eigenval,fm_mat_S,virtual,homo,omega)
719 DO iib = 1, ncol_local
720 i_global = col_indices(iib)
721
722 iocc = max(1, i_global - 1)/virtual + 1
723 avirt = i_global - (iocc - 1)*virtual
724 eigen_diff = eigenval(avirt + homo) - eigenval(iocc)
725
726 fm_mat_s%local_data(:, iib) = fm_mat_s%local_data(:, iib)* &
727 sqrt(eigen_diff/(eigen_diff**2 + omega**2))
728
729 END DO
730 ELSE
731 ! In this case the update has to remove the old omega component thus
732 ! SQRT(((epsi_a-epsi_i)**2+omega_old**2)/((epsi_a-epsi_i)**2+omega**2))
733 !$OMP PARALLEL DO DEFAULT(NONE) PRIVATE(iiB,iocc,avirt,eigen_diff,i_global) &
734 !$OMP SHARED(ncol_local,col_indices,Eigenval,fm_mat_S,virtual,homo,omega,omega_old)
735 DO iib = 1, ncol_local
736 i_global = col_indices(iib)
737
738 iocc = max(1, i_global - 1)/virtual + 1
739 avirt = i_global - (iocc - 1)*virtual
740 eigen_diff = eigenval(avirt + homo) - eigenval(iocc)
741
742 fm_mat_s%local_data(:, iib) = fm_mat_s%local_data(:, iib)* &
743 sqrt((eigen_diff**2 + omega_old**2)/(eigen_diff**2 + omega**2))
744
745 END DO
746 END IF
747
748 CALL timestop(handle)
749
750 END SUBROUTINE calc_fm_mat_s_rpa
751
752! **************************************************************************************************
753!> \brief ...
754!> \param mm_style ...
755!> \param dimen_RI ...
756!> \param dimen_ia ...
757!> \param alpha ...
758!> \param fm_mat_S ...
759!> \param fm_mat_Q_gemm ...
760!> \param fm_mat_Q ...
761!> \param dgemm_counter ...
762! **************************************************************************************************
763 SUBROUTINE contract_s_to_q(mm_style, dimen_RI, dimen_ia, alpha, fm_mat_S, fm_mat_Q_gemm, &
764 fm_mat_Q, dgemm_counter)
765
766 INTEGER, INTENT(IN) :: mm_style, dimen_ri, dimen_ia
767 REAL(kind=dp), INTENT(IN) :: alpha
768 TYPE(cp_fm_type), INTENT(IN) :: fm_mat_s, fm_mat_q_gemm, fm_mat_q
769 TYPE(dgemm_counter_type), INTENT(INOUT) :: dgemm_counter
770
771 CHARACTER(LEN=*), PARAMETER :: routinen = 'contract_S_to_Q'
772
773 INTEGER :: handle
774
775 CALL timeset(routinen, handle)
776
777 CALL dgemm_counter_start(dgemm_counter)
778 SELECT CASE (mm_style)
779 CASE (wfc_mm_style_gemm)
780 ! waste-fully computes the full symmetrix matrix, but maybe faster than cp_fm_syrk for optimized cp_fm_gemm !!!
781 CALL parallel_gemm(transa="N", transb="T", m=dimen_ri, n=dimen_ri, k=dimen_ia, alpha=alpha, &
782 matrix_a=fm_mat_s, matrix_b=fm_mat_s, beta=0.0_dp, &
783 matrix_c=fm_mat_q_gemm)
784 CASE (wfc_mm_style_syrk)
785 ! will only compute the upper half of the matrix, which is fine, since we only use it for cholesky later
786 CALL cp_fm_syrk(uplo='U', trans='N', k=dimen_ia, alpha=alpha, matrix_a=fm_mat_s, &
787 ia=1, ja=1, beta=0.0_dp, matrix_c=fm_mat_q_gemm)
788 CASE DEFAULT
789 cpabort("Unknown mm_style for contract_S_to_Q")
790 END SELECT
791 CALL dgemm_counter_stop(dgemm_counter, dimen_ri, dimen_ri, dimen_ia)
792
793 ! copy/redistribute fm_mat_Q_gemm to fm_mat_Q
794 CALL cp_fm_set_all(matrix=fm_mat_q, alpha=0.0_dp)
795 CALL cp_fm_to_fm_submat_general(fm_mat_q_gemm, fm_mat_q, dimen_ri, dimen_ri, 1, 1, 1, 1, &
796 fm_mat_q_gemm%matrix_struct%context)
797
798 CALL timestop(handle)
799
800 END SUBROUTINE contract_s_to_q
801
802! **************************************************************************************************
803!> \brief Factorize epsilon in place and accumulate the frequency-weighted RPA energy.
804!> \param dimen_RI dimension of the active RI block
805!> \param diag_Qomega global diagonal elements of Q
806!> \param fm_mat_Q epsilon on entry, its upper Cholesky factor on exit
807!> \param para_env_RPA ...
808!> \param Erpa ...
809!> \param wjquad ...
810! **************************************************************************************************
811 SUBROUTINE compute_erpa_by_freq_int(dimen_RI, diag_Qomega, fm_mat_Q, para_env_RPA, Erpa, wjquad)
812
813 INTEGER, INTENT(IN) :: dimen_ri
814 REAL(kind=dp), DIMENSION(dimen_RI), INTENT(IN) :: diag_qomega
815 TYPE(cp_fm_type), INTENT(IN) :: fm_mat_q
816 TYPE(mp_para_env_type), INTENT(IN) :: para_env_rpa
817 REAL(kind=dp), INTENT(INOUT) :: erpa
818 REAL(kind=dp), INTENT(IN) :: wjquad
819
820 CHARACTER(LEN=*), PARAMETER :: routinen = 'compute_Erpa_by_freq_int'
821
822 INTEGER :: handle, iib, info_chol
823 REAL(kind=dp) :: fcomega
824 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: q_log
825
826 CALL timeset(routinen, handle)
827
828 ! epsilon = U^T U; log(det(epsilon)) = 2*sum(log(U_ii)).
829 CALL cp_fm_cholesky_decompose(matrix=fm_mat_q, n=dimen_ri, info_out=info_chol)
830 IF (info_chol /= 0) THEN
831 CALL cp_warn(__location__, &
832 "The Cholesky decomposition before inverting the RPA matrix / dielectric "// &
833 "function failed. "// &
834 "In case of low-scaling RPA/GW, decreasing EPS_FILTER in the &LOW_SCALING "// &
835 "section might "// &
836 "increase the overall accuracy making the matrix positive definite. "// &
837 "Code will abort.")
838 END IF
839
840 cpassert(info_chol == 0)
841
842 ALLOCATE (q_log(dimen_ri))
843 CALL cp_fm_get_diag(fm_mat_q, q_log, n_active=dimen_ri)
844 q_log = 2.0_dp*log(q_log)
845
846 ! the following frequency integration is Eq. (27) in M. Del Ben et al., JCTC 9, 2654 (2013)
847 ! (https://doi.org/10.1021/ct4002202)
848 fcomega = 0.0_dp
849 DO iib = 1, dimen_ri
850 IF (modulo(iib, para_env_rpa%num_pe) /= para_env_rpa%mepos) cycle
851 fcomega = fcomega + (q_log(iib) - diag_qomega(iib))/2.0_dp
852 END DO
853 erpa = erpa + fcomega*wjquad
854
855 DEALLOCATE (q_log)
856
857 CALL timestop(handle)
858
859 END SUBROUTINE compute_erpa_by_freq_int
860
861! **************************************************************************************************
862!> \brief ...
863!> \param fm_struct_sub_kp ...
864!> \param para_env ...
865!> \param dimen_RI ...
866!> \param ikp_local ...
867!> \param first_ikp_local ...
868! **************************************************************************************************
869 SUBROUTINE get_sub_para_kp(fm_struct_sub_kp, para_env, dimen_RI, &
870 ikp_local, first_ikp_local)
871 TYPE(cp_fm_struct_type), POINTER :: fm_struct_sub_kp
872 TYPE(mp_para_env_type), POINTER :: para_env
873 INTEGER, INTENT(IN) :: dimen_ri
874 INTEGER, INTENT(OUT) :: ikp_local, first_ikp_local
875
876 CHARACTER(len=*), PARAMETER :: routinen = 'get_sub_para_kp'
877
878 INTEGER :: color_sub_kp, handle, num_proc_per_kp
879 TYPE(cp_blacs_env_type), POINTER :: blacs_env_sub_kp
880 TYPE(mp_para_env_type), POINTER :: para_env_sub_kp
881
882 CALL timeset(routinen, handle)
883
884 ! we use all processors for every k-point, subgroups for cp_cfm_heevd only seems to work for
885 ! very small subgroups with 1, 2, or 3 MPI ranks. For more MPI-ranks, eigenvalues and
886 ! eigenvectors coming out of cp_cfm_heevd are totally wrong unfortunately.
887 num_proc_per_kp = para_env%num_pe
888
889 ! IF(nkp > para_env%num_pe) THEN
890 ! num_proc_per_kp = para_env%num_pe
891 ! ELSE
892 ! num_proc_per_kp = para_env%num_pe/nkp
893 ! END IF
894
895 color_sub_kp = para_env%mepos/num_proc_per_kp
896 ALLOCATE (para_env_sub_kp)
897 CALL para_env_sub_kp%from_split(para_env, color_sub_kp)
898
899 ! grid_2d(1) = 1
900 ! grid_2d(2) = para_env_sub_kp%num_pe
901
902 NULLIFY (blacs_env_sub_kp)
903 ! CALL cp_blacs_env_create(blacs_env=blacs_env_sub_kp, para_env=para_env_sub_kp, grid_2d=grid_2d)
904 CALL cp_blacs_env_create(blacs_env=blacs_env_sub_kp, para_env=para_env_sub_kp)
905
906 NULLIFY (fm_struct_sub_kp)
907 CALL cp_fm_struct_create(fm_struct_sub_kp, context=blacs_env_sub_kp, nrow_global=dimen_ri, &
908 ncol_global=dimen_ri, para_env=para_env_sub_kp)
909
910 CALL cp_blacs_env_release(blacs_env_sub_kp)
911
912 ! IF(nkp > para_env%num_pe) THEN
913 ! every processor has all ikp's
914 ikp_local = -1
915 first_ikp_local = 1
916 ! ELSE
917 ! ikp_local = 0
918 ! first_ikp_local = 1
919 ! DO ikp = 1, nkp
920 ! IF(MOD(ikp-1, para_env%num_pe/num_proc_per_kp) == color_sub_kp) THEN
921 ! ikp_local = ikp
922 ! first_ikp_local = ikp
923 ! END IF
924 ! END DO
925 ! END IF
926
927 CALL mp_para_env_release(para_env_sub_kp)
928
929 CALL timestop(handle)
930
931 END SUBROUTINE get_sub_para_kp
932
933! **************************************************************************************************
934!> \brief ...
935!> \param cfm_mo_coeff ...
936!> \param index_to_cell_3c ...
937!> \param cell_to_index_3c ...
938!> \param do_ic_model ...
939!> \param do_kpoints_cubic_RPA ...
940!> \param do_kpoints_from_Gamma ...
941!> \param do_ri_Sigma_x ...
942!> \param has_mat_P_blocks ...
943!> \param wkp_W ...
944!> \param cfm_mat_Q ...
945!> \param cfm_mat_Minv_L_kpoints ...
946!> \param cfm_mat_L_kpoints ...
947!> \param fm_mat_Minv_L_gamma ...
948!> \param fm_matrix_Minv ...
949!> \param fm_matrix_Minv_Vtrunc_Minv ...
950!> \param cfm_mat_RI_global_work ...
951!> \param fm_mat_work ...
952!> \param mat_dm ...
953!> \param mat_L ...
954!> \param mat_MinvVMinv ...
955!> \param mat_P_omega ...
956!> \param mat_P_omega_kp ...
957!> \param t_3c_M ...
958!> \param t_3c_O ...
959!> \param t_3c_O_compressed ...
960!> \param t_3c_O_ind ...
961!> \param mat_work ...
962!> \param qs_env ...
963! **************************************************************************************************
964 SUBROUTINE dealloc_im_time(cfm_mo_coeff, index_to_cell_3c, &
965 cell_to_index_3c, do_ic_model, &
966 do_kpoints_cubic_RPA, do_kpoints_from_Gamma, do_ri_Sigma_x, &
967 has_mat_P_blocks, &
968 wkp_W, cfm_mat_Q, cfm_mat_Minv_L_kpoints, cfm_mat_L_kpoints, &
969 fm_mat_Minv_L_gamma, &
970 fm_matrix_Minv, fm_matrix_Minv_Vtrunc_Minv, &
971 cfm_mat_RI_global_work, fm_mat_work, mat_dm, mat_L, &
972 mat_MinvVMinv, mat_P_omega, mat_P_omega_kp, &
973 t_3c_M, t_3c_O, t_3c_O_compressed, t_3c_O_ind, &
974 mat_work, qs_env)
975
976 TYPE(cp_cfm_type), ALLOCATABLE, DIMENSION(:), &
977 INTENT(INOUT) :: cfm_mo_coeff
978 INTEGER, ALLOCATABLE, DIMENSION(:, :), &
979 INTENT(INOUT) :: index_to_cell_3c
980 INTEGER, ALLOCATABLE, DIMENSION(:, :, :), &
981 INTENT(INOUT) :: cell_to_index_3c
982 LOGICAL, INTENT(IN) :: do_ic_model, do_kpoints_cubic_rpa, &
983 do_kpoints_from_gamma, do_ri_sigma_x
984 LOGICAL, ALLOCATABLE, DIMENSION(:, :, :, :, :), &
985 INTENT(INOUT) :: has_mat_p_blocks
986 REAL(kind=dp), ALLOCATABLE, DIMENSION(:), &
987 INTENT(INOUT) :: wkp_w
988 TYPE(cp_cfm_type), INTENT(INOUT) :: cfm_mat_q
989 TYPE(cp_cfm_type), ALLOCATABLE, DIMENSION(:) :: cfm_mat_minv_l_kpoints, cfm_mat_l_kpoints
990 TYPE(cp_fm_type), INTENT(INOUT) :: fm_mat_minv_l_gamma
991 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:, :) :: fm_matrix_minv, &
992 fm_matrix_minv_vtrunc_minv
993 TYPE(cp_cfm_type), INTENT(INOUT) :: cfm_mat_ri_global_work
994 TYPE(cp_fm_type), INTENT(INOUT) :: fm_mat_work
995 TYPE(dbcsr_p_type), INTENT(INOUT) :: mat_dm, mat_l, mat_minvvminv
996 TYPE(dbcsr_p_type), ALLOCATABLE, &
997 DIMENSION(:, :, :), INTENT(INOUT) :: mat_p_omega
998 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: mat_p_omega_kp
999 TYPE(dbt_type) :: t_3c_m
1000 TYPE(dbt_type), ALLOCATABLE, DIMENSION(:, :) :: t_3c_o
1001 TYPE(hfx_compression_type), ALLOCATABLE, &
1002 DIMENSION(:, :, :), INTENT(INOUT) :: t_3c_o_compressed
1003 TYPE(block_ind_type), ALLOCATABLE, &
1004 DIMENSION(:, :, :), INTENT(INOUT) :: t_3c_o_ind
1005 TYPE(dbcsr_type), POINTER :: mat_work
1006 TYPE(qs_environment_type), POINTER :: qs_env
1007
1008 CHARACTER(LEN=*), PARAMETER :: routinen = 'dealloc_im_time'
1009
1010 INTEGER :: cut_memory, handle, i_kp, i_mem, i_size, &
1011 ispin, j_size, jquad, unused
1012
1013 CALL timeset(routinen, handle)
1014
1015 IF (ALLOCATED(cfm_mo_coeff)) THEN
1016 DO ispin = 1, SIZE(cfm_mo_coeff)
1017 CALL cp_cfm_release(cfm_mo_coeff(ispin))
1018 END DO
1019 DEALLOCATE (cfm_mo_coeff)
1020 END IF
1021 IF (ALLOCATED(cfm_mat_minv_l_kpoints)) THEN
1022 DO i_kp = 1, SIZE(cfm_mat_minv_l_kpoints)
1023 IF (ASSOCIATED(cfm_mat_minv_l_kpoints(i_kp)%matrix_struct)) THEN
1024 CALL cp_cfm_release(cfm_mat_minv_l_kpoints(i_kp))
1025 END IF
1026 END DO
1027 DEALLOCATE (cfm_mat_minv_l_kpoints)
1028 END IF
1029 IF (ALLOCATED(cfm_mat_l_kpoints)) THEN
1030 DO i_kp = 1, SIZE(cfm_mat_l_kpoints)
1031 IF (ASSOCIATED(cfm_mat_l_kpoints(i_kp)%matrix_struct)) CALL cp_cfm_release(cfm_mat_l_kpoints(i_kp))
1032 END DO
1033 DEALLOCATE (cfm_mat_l_kpoints)
1034 END IF
1035 CALL cp_fm_release(fm_mat_minv_l_gamma)
1036
1037 IF (do_kpoints_cubic_rpa .OR. do_kpoints_from_gamma) THEN
1038 CALL cp_fm_release(fm_matrix_minv_vtrunc_minv)
1039 CALL cp_fm_release(fm_matrix_minv)
1040 END IF
1041
1042 CALL cp_fm_release(fm_mat_work)
1043
1044 IF (.NOT. (do_kpoints_cubic_rpa .OR. do_kpoints_from_gamma)) THEN
1045 CALL dbcsr_release(mat_work)
1046 DEALLOCATE (mat_work)
1047 END IF
1048
1049 IF (ASSOCIATED(mat_l%matrix)) THEN
1050 CALL dbcsr_release(mat_l%matrix)
1051 DEALLOCATE (mat_l%matrix)
1052 END IF
1053
1054 IF (do_ri_sigma_x .OR. do_ic_model) THEN
1055 CALL dbcsr_release(mat_minvvminv%matrix)
1056 DEALLOCATE (mat_minvvminv%matrix)
1057 END IF
1058 IF (do_ri_sigma_x) THEN
1059 CALL dbcsr_release(mat_dm%matrix)
1060 DEALLOCATE (mat_dm%matrix)
1061 END IF
1062
1063 DEALLOCATE (index_to_cell_3c, cell_to_index_3c)
1064
1065 IF (ALLOCATED(mat_p_omega)) THEN
1066 DO ispin = 1, SIZE(mat_p_omega, 3)
1067 DO i_kp = 1, SIZE(mat_p_omega, 2)
1068 DO jquad = 1, SIZE(mat_p_omega, 1)
1069 CALL dbcsr_deallocate_matrix(mat_p_omega(jquad, i_kp, ispin)%matrix)
1070 END DO
1071 END DO
1072 END DO
1073 DEALLOCATE (mat_p_omega)
1074 END IF
1075
1076 DO j_size = 1, SIZE(t_3c_o, 2)
1077 DO i_size = 1, SIZE(t_3c_o, 1)
1078 CALL dbt_destroy(t_3c_o(i_size, j_size))
1079 END DO
1080 END DO
1081
1082 DEALLOCATE (t_3c_o)
1083 CALL dbt_destroy(t_3c_m)
1084
1085 DEALLOCATE (has_mat_p_blocks)
1086
1087 IF (do_kpoints_cubic_rpa .OR. do_kpoints_from_gamma) THEN
1088 CALL cp_cfm_release(cfm_mat_q)
1089 CALL cp_cfm_release(cfm_mat_ri_global_work)
1090 CALL dbcsr_deallocate_matrix_set(mat_p_omega_kp)
1091 DEALLOCATE (wkp_w)
1092 END IF
1093
1094 cut_memory = SIZE(t_3c_o_compressed, 3)
1095
1096 DEALLOCATE (t_3c_o_ind)
1097 DO i_mem = 1, cut_memory
1098 DO j_size = 1, SIZE(t_3c_o_compressed, 2)
1099 DO i_size = 1, SIZE(t_3c_o_compressed, 1)
1100 CALL dealloc_containers(t_3c_o_compressed(i_size, j_size, i_mem), unused)
1101 END DO
1102 END DO
1103 END DO
1104 DEALLOCATE (t_3c_o_compressed)
1105
1106 IF (do_kpoints_from_gamma) THEN
1107 CALL kpoint_release(qs_env%mp2_env%ri_rpa_im_time%kpoints_G)
1108 IF (qs_env%mp2_env%ri_g0w0%do_kpoints_Sigma) THEN
1109 CALL kpoint_release(qs_env%mp2_env%ri_rpa_im_time%kpoints_Sigma)
1110 CALL kpoint_release(qs_env%mp2_env%ri_rpa_im_time%kpoints_Sigma_no_xc)
1111 END IF
1112 END IF
1113
1114 CALL timestop(handle)
1115
1116 END SUBROUTINE dealloc_im_time
1117
1118! **************************************************************************************************
1119!> \brief ...
1120!> \param mat_P_omega ...
1121!> \param mat_L ...
1122!> \param mat_work ...
1123!> \param eps_filter_im_time ...
1124!> \param fm_mat_work ...
1125!> \param dimen_RI ...
1126!> \param dimen_RI_red ...
1127!> \param fm_mat_L ...
1128!> \param fm_mat_Q ...
1129! **************************************************************************************************
1130 SUBROUTINE contract_p_omega_with_mat_l(mat_P_omega, mat_L, mat_work, eps_filter_im_time, fm_mat_work, dimen_RI, &
1131 dimen_RI_red, fm_mat_L, fm_mat_Q)
1132
1133 TYPE(dbcsr_type), INTENT(IN) :: mat_p_omega, mat_l
1134 TYPE(dbcsr_type), INTENT(INOUT) :: mat_work
1135 REAL(kind=dp), INTENT(IN) :: eps_filter_im_time
1136 TYPE(cp_fm_type), INTENT(INOUT) :: fm_mat_work
1137 INTEGER, INTENT(IN) :: dimen_ri, dimen_ri_red
1138 TYPE(cp_fm_type), INTENT(IN) :: fm_mat_l, fm_mat_q
1139
1140 CHARACTER(LEN=*), PARAMETER :: routinen = 'contract_P_omega_with_mat_L'
1141
1142 INTEGER :: handle
1143
1144 CALL timeset(routinen, handle)
1145
1146 ! multiplication with RI metric/Coulomb operator
1147 CALL dbcsr_multiply("N", "T", 1.0_dp, mat_p_omega, mat_l, &
1148 0.0_dp, mat_work, filter_eps=eps_filter_im_time)
1149
1150 CALL copy_dbcsr_to_fm(mat_work, fm_mat_work)
1151
1152 CALL parallel_gemm('N', 'N', dimen_ri_red, dimen_ri_red, dimen_ri, 1.0_dp, fm_mat_l, fm_mat_work, &
1153 0.0_dp, fm_mat_q)
1154
1155 ! Reset mat_work to save memory
1156 CALL dbcsr_set(mat_work, 0.0_dp)
1157 CALL dbcsr_filter(mat_work, 1.0_dp)
1158
1159 CALL timestop(handle)
1160
1161 END SUBROUTINE contract_p_omega_with_mat_l
1162
1163END MODULE rpa_util
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
Handles all functions related to the CELL.
Definition cell_types.F:15
subroutine, public get_cell(cell, alpha, beta, gamma, deth, orthorhombic, abc, periodic, h, h_inv, symmetry_id, tag)
Get informations about a simulation cell.
Definition cell_types.F:234
methods related to the blacs parallel environment
subroutine, public cp_blacs_env_release(blacs_env)
releases the given blacs_env
subroutine, public cp_blacs_env_create(blacs_env, para_env, blacs_grid_layout, blacs_repeatable, row_major, grid_2d)
allocates and initializes a type that represent a blacs context
Represents a complex full matrix distributed on many processors.
subroutine, public cp_cfm_copy_general(source, destination, para_env)
General copy of a cfm matrix to another cfm matrix. Uses non-blocking MPI rather than ScaLAPACK.
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_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
Creates a new full matrix with the given structure.
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 dbcsr_deallocate_matrix(matrix)
...
subroutine, public dbcsr_multiply(transa, transb, alpha, matrix_a, matrix_b, beta, matrix_c, first_row, last_row, first_column, last_column, first_k, last_k, retain_sparsity, filter_eps, flop)
...
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_filter(matrix, eps)
...
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_release(matrix)
...
DBCSR operations in CP2K.
subroutine, public copy_dbcsr_to_fm(matrix, fm, plan, check_plan)
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_transpose(matrix, matrixt)
transposes a matrix matrixt = matrix ^ T
subroutine, public cp_fm_syrk(uplo, trans, k, alpha, matrix_a, ia, ja, beta, matrix_c)
performs a rank-k update of a symmetric matrix_c matrix_c = beta * matrix_c + alpha * matrix_a * tran...
various cholesky decomposition related routines
subroutine, public cp_fm_cholesky_decompose(matrix, n, info_out)
used to replace a symmetric positive def. matrix M with its cholesky decomposition U: M = U^T * U,...
represent the structure of a full matrix
subroutine, public cp_fm_struct_create(fmstruct, para_env, context, nrow_global, ncol_global, nrow_block, ncol_block, descriptor, first_p_pos, local_leading_dimension, template_fmstruct, square_blocks, force_block)
allocates and initializes a full matrix structure
subroutine, public cp_fm_struct_release(fmstruct)
releases a full matrix structure
represent a full matrix distributed on many processors
Definition cp_fm_types.F:15
subroutine, public cp_fm_copy_general(source, destination, para_env)
General copy of a fm matrix to another fm matrix. Uses non-blocking MPI rather than ScaLAPACK.
subroutine, public cp_fm_get_info(matrix, name, nrow_global, ncol_global, nrow_block, ncol_block, nrow_local, ncol_local, row_indices, col_indices, local_data, context, nrow_locals, ncol_locals, matrix_struct, para_env)
returns all kind of information about the full matrix
subroutine, public cp_fm_get_diag(matrix, diag, n_active)
returns the diagonal elements of a fm
subroutine, public cp_fm_to_fm_submat_general(source, destination, nrows, ncols, s_firstrow, s_firstcol, d_firstrow, d_firstcol, global_context)
General copy of a submatrix of fm matrix to a submatrix of another fm matrix. The two matrices can ha...
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, nrow, ncol, set_zero)
creates a new full matrix with the given structure
This is the start of a dbt_api, all publically needed functions are exported here....
Definition dbt_api.F:17
Counters to determine the performance of parallel DGEMMs.
subroutine, public dgemm_counter_start(dgemm_counter)
start timer of the counter
subroutine, public dgemm_counter_stop(dgemm_counter, size1, size2, size3)
stop timer of the counter and provide matrix sizes
Types and set/get functions for HFX.
Definition hfx_types.F:16
subroutine, public dealloc_containers(data, memory_usage)
...
Definition hfx_types.F:2902
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public wfc_mm_style_syrk
integer, parameter, public wfc_mm_style_gemm
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Types and basic routines needed for a kpoint calculation.
subroutine, public kpoint_release(kpoint)
Release a kpoint environment, deallocate all data.
subroutine, public get_kpoint_info(kpoint, kp_scheme, nkp_grid, kp_shift, symmetry, verbose, full_grid, use_real_wfn, eps_geo, parallel_group_size, kp_range, nkp, xkp, wkp, para_env, blacs_env_all, para_env_kp, para_env_inter_kp, blacs_env, kp_env, kp_aux_env, mpools, iogrp, nkp_groups, kp_dist, cell_to_index, index_to_cell, sab_nl, sab_nl_nosym, inversion_symmetry_only, symmetry_backend, symmetry_reduction_method, gamma_centered, lattice_fft)
Retrieve information from a kpoint environment.
Definition of mathematical constants and functions.
complex(kind=dp), parameter, public z_zero
Interface to the message passing library MPI.
subroutine, public mp_para_env_release(para_env)
releases the para object (to be called when you don't want anymore the shared copy of this object)
Routines to calculate MP2 energy with laplace approach.
Definition mp2_laplace.F:13
subroutine, public calc_fm_mat_s_laplace(fm_mat_s, homo, virtual, eigenval, dajquad)
...
Definition mp2_laplace.F:39
basic linear algebra operations for full matrixes
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, mimic, 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, sab_cneo, 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, matrix_vhxc, 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, xcint_weights, 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, rhoz_cneo_set, ecoul_1c, rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_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.
Routines treating GW and RPA calculations with kpoints.
subroutine, public compute_wkp_w(qs_env, wkp_w, wkp_v, kpoints, h_inv, periodic)
...
Utility functions for RPA calculations.
Definition rpa_util.F:13
subroutine, public dealloc_im_time(cfm_mo_coeff, index_to_cell_3c, cell_to_index_3c, do_ic_model, do_kpoints_cubic_rpa, do_kpoints_from_gamma, do_ri_sigma_x, has_mat_p_blocks, wkp_w, cfm_mat_q, cfm_mat_minv_l_kpoints, cfm_mat_l_kpoints, fm_mat_minv_l_gamma, fm_matrix_minv, fm_matrix_minv_vtrunc_minv, cfm_mat_ri_global_work, fm_mat_work, mat_dm, mat_l, mat_minvvminv, mat_p_omega, mat_p_omega_kp, t_3c_m, t_3c_o, t_3c_o_compressed, t_3c_o_ind, mat_work, qs_env)
...
Definition rpa_util.F:975
subroutine, public compute_erpa_by_freq_int(dimen_ri, diag_qomega, fm_mat_q, para_env_rpa, erpa, wjquad)
Factorize epsilon in place and accumulate the frequency-weighted RPA energy.
Definition rpa_util.F:812
subroutine, public alloc_im_time(qs_env, para_env, dimen_ri, dimen_ri_red, num_integ_points, nspins, create_cfm_mo_coeff, fm_mat_q, cfm_mo_coeff, cfm_matrix_minv_l_kpoints, cfm_matrix_l_kpoints, fm_matrix_minv_l_gamma, mat_p_global, t_3c_o, matrix_s, kpoints, eps_filter_im_time, cut_memory, nkp, num_cells_dm, num_3c_repl, size_p, ikp_local, index_to_cell_3c, cell_to_index_3c, col_blk_size, do_ic_model, do_kpoints_cubic_rpa, do_kpoints_from_gamma, do_ri_sigma_x, my_open_shell, has_mat_p_blocks, wkp_w, cfm_mat_q, cfm_mat_minv_l_kpoints, cfm_mat_l_kpoints, fm_mat_minv_l_gamma, cfm_mat_ri_global_work, fm_mat_work, mat_dm, mat_l, mat_m_p_munu_occ, mat_m_p_munu_virt, mat_minvvminv, mat_p_omega, mat_p_omega_kp, mat_work, mo_coeff)
...
Definition rpa_util.F:145
subroutine, public calc_mat_q(fm_mat_s, do_ri_sos_laplace_mp2, first_cycle, virtual, eigenval, homo, omega, omega_old, jquad, mm_style, dimen_ri, dimen_ia, alpha, fm_mat_q, fm_mat_q_gemm, do_bse, fm_mat_q_static_bse_gemm, dgemm_counter, num_integ_points, count_ev_sc_gw)
...
Definition rpa_util.F:592
subroutine, public contract_p_omega_with_mat_l(mat_p_omega, mat_l, mat_work, eps_filter_im_time, fm_mat_work, dimen_ri, dimen_ri_red, fm_mat_l, fm_mat_q)
...
Definition rpa_util.F:1132
subroutine, public remove_scaling_factor_rpa(fm_mat_s, virtual, eigenval_last, homo, omega_old)
...
Definition rpa_util.F:642
subroutine, public calc_fm_mat_s_rpa(fm_mat_s, first_cycle, virtual, eigenval, homo, omega, omega_old)
...
Definition rpa_util.F:692
Type defining parameters related to the simulation cell.
Definition cell_types.F:60
represent a blacs multidimensional parallel environment (for the mpi corrispective see cp_paratypes/m...
Represent a complex full matrix.
keeps the information about the structure of a full matrix
represent a full matrix
Contains information about kpoints.
stores all the informations relevant to an mpi environment