(git:9cbee8b)
Loading...
Searching...
No Matches
rpa_main.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 Routines to calculate RI-RPA energy
10!> \par History
11!> 06.2012 created [Mauro Del Ben]
12!> 04.2015 GW routines added [Jan Wilhelm]
13!> 10.2015 Cubic-scaling RPA routines added [Jan Wilhelm]
14!> 10.2018 Cubic-scaling SOS-MP2 added [Frederick Stein]
15!> 03.2019 Refactoring [Frederick Stein]
16! **************************************************************************************************
18 USE bibliography, ONLY: &
25 USE cp_cfm_types, ONLY: cp_cfm_type
26 USE cp_dbcsr_api, ONLY: dbcsr_add,&
35 USE cp_fm_types, ONLY: cp_fm_create,&
40 USE dbt_api, ONLY: dbt_type
47 maxsize,&
49 USE hfx_types, ONLY: block_ind_type,&
56 USE kinds, ONLY: dp,&
57 int_8
58 USE kpoint_types, ONLY: kpoint_type
59 USE machine, ONLY: m_flush,&
61 USE mathconstants, ONLY: pi,&
62 z_zero
63 USE message_passing, ONLY: mp_comm_type,&
67 USE mp2_grids, ONLY: get_clenshaw_grid,&
70 USE mp2_ri_grad_util, ONLY: array2fm
71 USE mp2_types, ONLY: mp2_type,&
79 USE rpa_grad, ONLY: rpa_grad_copy_q,&
85 USE rpa_gw, ONLY: allocate_matrices_gw,&
111 calc_mat_q,&
116 USE util, ONLY: get_limit
117#include "./base/base_uses.f90"
118
119 IMPLICIT NONE
120
121 PRIVATE
122
123 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'rpa_main'
124
125 PUBLIC :: rpa_ri_compute_en
126
127CONTAINS
128
129! **************************************************************************************************
130!> \brief ...
131!> \param qs_env ...
132!> \param Erpa ...
133!> \param mp2_env ...
134!> \param BIb_C ...
135!> \param BIb_C_gw ...
136!> \param BIb_C_bse_ij ...
137!> \param BIb_C_bse_ab ...
138!> \param para_env ...
139!> \param para_env_sub ...
140!> \param color_sub ...
141!> \param gd_array ...
142!> \param gd_B_virtual ...
143!> \param gd_B_all ...
144!> \param gd_B_occ_bse ...
145!> \param gd_B_virt_bse ...
146!> \param mo_coeff ...
147!> \param fm_matrix_PQ ...
148!> \param fm_matrix_L_kpoints ...
149!> \param fm_matrix_Minv_L_kpoints ...
150!> \param fm_matrix_Minv ...
151!> \param fm_matrix_Minv_Vtrunc_Minv ...
152!> \param kpoints ...
153!> \param Eigenval ...
154!> \param nmo ...
155!> \param homo ...
156!> \param dimen_RI ...
157!> \param dimen_RI_red ...
158!> \param gw_corr_lev_occ ...
159!> \param gw_corr_lev_virt ...
160!> \param bse_lev_virt ...
161!> \param unit_nr ...
162!> \param do_ri_sos_laplace_mp2 ...
163!> \param my_do_gw ...
164!> \param do_im_time ...
165!> \param do_bse ...
166!> \param matrix_s ...
167!> \param mat_munu ...
168!> \param mat_P_global ...
169!> \param t_3c_M ...
170!> \param t_3c_O ...
171!> \param t_3c_O_compressed ...
172!> \param t_3c_O_ind ...
173!> \param starts_array_mc ...
174!> \param ends_array_mc ...
175!> \param starts_array_mc_block ...
176!> \param ends_array_mc_block ...
177!> \param calc_forces ...
178! **************************************************************************************************
179 SUBROUTINE rpa_ri_compute_en(qs_env, Erpa, mp2_env, BIb_C, BIb_C_gw, BIb_C_bse_ij, BIb_C_bse_ab, &
180 para_env, para_env_sub, color_sub, &
181 gd_array, gd_B_virtual, gd_B_all, gd_B_occ_bse, gd_B_virt_bse, &
182 mo_coeff, fm_matrix_PQ, fm_matrix_L_kpoints, fm_matrix_Minv_L_kpoints, &
183 fm_matrix_Minv, fm_matrix_Minv_Vtrunc_Minv, kpoints, &
184 Eigenval, nmo, homo, dimen_RI, dimen_RI_red, gw_corr_lev_occ, gw_corr_lev_virt, &
185 bse_lev_virt, &
186 unit_nr, do_ri_sos_laplace_mp2, my_do_gw, do_im_time, do_bse, matrix_s, &
187 mat_munu, mat_P_global, t_3c_M, t_3c_O, t_3c_O_compressed, t_3c_O_ind, &
188 starts_array_mc, ends_array_mc, &
189 starts_array_mc_block, ends_array_mc_block, calc_forces)
190
191 TYPE(qs_environment_type), POINTER :: qs_env
192 REAL(kind=dp), INTENT(OUT) :: erpa
193 TYPE(mp2_type), INTENT(INOUT) :: mp2_env
194 TYPE(three_dim_real_array), DIMENSION(:), &
195 INTENT(INOUT) :: bib_c, bib_c_gw, bib_c_bse_ij, &
196 bib_c_bse_ab
197 TYPE(mp_para_env_type), POINTER :: para_env, para_env_sub
198 INTEGER, INTENT(INOUT) :: color_sub
199 TYPE(group_dist_d1_type), INTENT(INOUT) :: gd_array
200 TYPE(group_dist_d1_type), DIMENSION(:), &
201 INTENT(INOUT) :: gd_b_virtual
202 TYPE(group_dist_d1_type), INTENT(INOUT) :: gd_b_all
203 TYPE(group_dist_d1_type), DIMENSION(:), &
204 INTENT(INOUT) :: gd_b_occ_bse, gd_b_virt_bse
205 TYPE(cp_fm_type), DIMENSION(:), INTENT(IN) :: mo_coeff
206 TYPE(cp_fm_type), INTENT(IN) :: fm_matrix_pq
207 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:, :) :: fm_matrix_l_kpoints, &
208 fm_matrix_minv_l_kpoints, &
209 fm_matrix_minv, &
210 fm_matrix_minv_vtrunc_minv
211 TYPE(kpoint_type), POINTER :: kpoints
212 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :), &
213 INTENT(INOUT) :: eigenval
214 INTEGER, INTENT(IN) :: nmo
215 INTEGER, DIMENSION(:), INTENT(IN) :: homo
216 INTEGER, INTENT(IN) :: dimen_ri, dimen_ri_red
217 INTEGER, DIMENSION(:), INTENT(IN) :: gw_corr_lev_occ, gw_corr_lev_virt, &
218 bse_lev_virt
219 INTEGER, INTENT(IN) :: unit_nr
220 LOGICAL, INTENT(IN) :: do_ri_sos_laplace_mp2, my_do_gw, &
221 do_im_time, do_bse
222 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s
223 TYPE(dbcsr_p_type), INTENT(IN) :: mat_munu
224 TYPE(dbcsr_p_type), INTENT(INOUT) :: mat_p_global
225 TYPE(dbt_type) :: t_3c_m
226 TYPE(dbt_type), ALLOCATABLE, DIMENSION(:, :) :: t_3c_o
227 TYPE(hfx_compression_type), ALLOCATABLE, &
228 DIMENSION(:, :, :), INTENT(INOUT) :: t_3c_o_compressed
229 TYPE(block_ind_type), ALLOCATABLE, &
230 DIMENSION(:, :, :), INTENT(INOUT) :: t_3c_o_ind
231 INTEGER, ALLOCATABLE, DIMENSION(:), INTENT(IN) :: starts_array_mc, ends_array_mc, &
232 starts_array_mc_block, &
233 ends_array_mc_block
234 LOGICAL, INTENT(IN) :: calc_forces
235
236 CHARACTER(LEN=*), PARAMETER :: routinen = 'rpa_ri_compute_en'
237
238 INTEGER :: best_integ_group_size, best_num_integ_point, color_rpa_group, dimen_nm_gw, &
239 dimen_virt_square, handle, handle2, handle3, ierr, iib, input_num_integ_groups, &
240 integ_group_size, ispin, jjb, min_integ_group_size, my_group_l_end, my_group_l_size, &
241 my_group_l_start, my_nm_gw_end, my_nm_gw_size, my_nm_gw_start, ncol_block_mat, ngroup, &
242 nrow_block_mat, nspins, num_integ_group, num_integ_points, pos_integ_group
243 INTEGER(KIND=int_8) :: mem
244 INTEGER, ALLOCATABLE, DIMENSION(:) :: dimen_homo_square, dimen_ia, my_ab_comb_bse_end, &
245 my_ab_comb_bse_size, my_ab_comb_bse_start, my_ia_end, my_ia_size, my_ia_start, &
246 my_ij_comb_bse_end, my_ij_comb_bse_size, my_ij_comb_bse_start, virtual
247 LOGICAL :: do_kpoints_from_gamma, do_minimax_quad, &
248 my_open_shell, skip_integ_group_opt
249 REAL(kind=dp) :: allowed_memory, avail_mem, e_range, emax, emin, mem_for_iak, mem_for_qk, &
250 mem_min, mem_per_group, mem_per_rank, mem_per_repl, mem_real
251 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :) :: eigenval_kp
252 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:) :: fm_mat_q, fm_mat_q_gemm, fm_mat_s, &
253 fm_mat_s_ab_bse, fm_mat_s_gw, &
254 fm_mat_s_ij_bse
255 TYPE(cp_fm_type), DIMENSION(1) :: fm_mat_r_gw
256 TYPE(mp_para_env_type), POINTER :: para_env_rpa
257 TYPE(two_dim_real_array), ALLOCATABLE, &
258 DIMENSION(:) :: bib_c_2d, bib_c_2d_bse_ab, &
259 bib_c_2d_bse_ij, bib_c_2d_gw
260
261 CALL timeset(routinen, handle)
262
263 CALL cite_reference(delben2013)
264 CALL cite_reference(delben2015)
265
266 IF (mp2_env%ri_rpa%exchange_correction == rpa_exchange_axk) THEN
267 CALL cite_reference(bates2013)
268 ELSE IF (mp2_env%ri_rpa%exchange_correction == rpa_exchange_sosex) THEN
269 CALL cite_reference(freeman1977)
270 CALL cite_reference(gruneis2009)
271 END IF
272 IF (mp2_env%ri_rpa%do_rse) THEN
273 CALL cite_reference(ren2011)
274 CALL cite_reference(ren2013)
275 END IF
276
277 IF (my_do_gw) THEN
278 CALL cite_reference(wilhelm2016a)
279 CALL cite_reference(wilhelm2017)
280 CALL cite_reference(wilhelm2018)
281 END IF
282
283 IF (do_im_time) THEN
284 CALL cite_reference(wilhelm2016b)
285 END IF
286
287 nspins = SIZE(homo)
288 my_open_shell = (nspins == 2)
289 ALLOCATE (virtual(nspins), dimen_ia(nspins), my_ia_end(nspins), my_ia_start(nspins), my_ia_size(nspins))
290 virtual(:) = nmo - homo(:)
291 dimen_ia(:) = virtual(:)*homo(:)
292
293 ALLOCATE (eigenval_kp(nmo, 1, nspins))
294 eigenval_kp(:, 1, :) = eigenval(:, :)
295
296 IF (do_im_time) mp2_env%ri_rpa%minimax_quad = .true.
297 do_minimax_quad = mp2_env%ri_rpa%minimax_quad
298
299 IF (do_ri_sos_laplace_mp2) THEN
300 num_integ_points = mp2_env%ri_laplace%n_quadrature
301 input_num_integ_groups = mp2_env%ri_laplace%num_integ_groups
302
303 ! check the range for the minimax approximation
304 e_range = mp2_env%e_range
305 IF (mp2_env%e_range <= 1.0_dp .OR. mp2_env%e_gap <= 0.0_dp) THEN
306 emin = huge(dp)
307 emax = 0.0_dp
308 DO ispin = 1, nspins
309 IF (homo(ispin) > 0) THEN
310 emin = min(emin, 2.0_dp*(eigenval(homo(ispin) + 1, ispin) - eigenval(homo(ispin), ispin)))
311 emax = max(emax, 2.0_dp*(maxval(eigenval(:, ispin)) - minval(eigenval(:, ispin))))
312 END IF
313 END DO
314 e_range = emax/emin
315 END IF
316 IF (e_range < 2.0_dp) e_range = 2.0_dp
317 ierr = 0
318 CALL check_exp_minimax_range(num_integ_points, e_range, ierr)
319 IF (ierr /= 0) THEN
320 jjb = num_integ_points - 1
321 DO iib = 1, jjb
322 num_integ_points = num_integ_points - 1
323 ierr = 0
324 CALL check_exp_minimax_range(num_integ_points, e_range, ierr)
325 IF (ierr == 0) EXIT
326 END DO
327 END IF
328 cpassert(num_integ_points >= 1)
329 ELSE
330 num_integ_points = mp2_env%ri_rpa%rpa_num_quad_points
331 input_num_integ_groups = mp2_env%ri_rpa%rpa_num_integ_groups
332 IF (my_do_gw .AND. do_minimax_quad) THEN
333 IF (num_integ_points > 34) THEN
334 IF (unit_nr > 0) THEN
335 CALL cp_warn(__location__, &
336 "The required number of quadrature point exceeds the maximum possible in the "// &
337 "Minimax quadrature scheme. The number of quadrature point has been reset to 30.")
338 END IF
339 num_integ_points = 30
340 END IF
341 ELSE
342 IF (do_minimax_quad .AND. num_integ_points > 20) THEN
343 IF (unit_nr > 0) THEN
344 CALL cp_warn(__location__, &
345 "The required number of quadrature point exceeds the maximum possible in the "// &
346 "Minimax quadrature scheme. The number of quadrature point has been reset to 20.")
347 END IF
348 num_integ_points = 20
349 END IF
350 END IF
351 END IF
352 allowed_memory = mp2_env%mp2_memory
353
354 CALL get_group_dist(gd_array, color_sub, my_group_l_start, my_group_l_end, my_group_l_size)
355
356 ngroup = para_env%num_pe/para_env_sub%num_pe
357
358 ! for imaginary time or periodic GW or BSE, we use all processors for a single frequency/time point
359 IF (do_im_time .OR. mp2_env%ri_g0w0%do_periodic .OR. do_bse) THEN
360
361 integ_group_size = ngroup
362 best_num_integ_point = num_integ_points
363
364 ELSE
365
366 ! Calculate available memory and create integral group according to that
367 ! mem_for_iaK is the memory needed for storing the 3 centre integrals
368 mem_for_iak = real(sum(dimen_ia), kind=dp)*dimen_ri_red*8.0_dp/(1024_dp**2)
369 mem_for_qk = real(dimen_ri_red, kind=dp)*nspins*dimen_ri_red*8.0_dp/(1024_dp**2)
370
371 CALL m_memory(mem)
372 mem_real = (mem + 1024*1024 - 1)/(1024*1024)
373 CALL para_env%min(mem_real)
374
375 mem_per_rank = 0.0_dp
376
377 ! B_ia_P
378 mem_per_repl = mem_for_iak
379 ! Q (regular and for dgemm)
380 mem_per_repl = mem_per_repl + 2.0_dp*mem_for_qk
381
382 IF (calc_forces) CALL rpa_grad_needed_mem(homo, virtual, dimen_ri_red, mem_per_rank, mem_per_repl, do_ri_sos_laplace_mp2)
383 CALL rpa_exchange_needed_mem(mp2_env, homo, virtual, dimen_ri_red, para_env, mem_per_rank, mem_per_repl)
384
385 mem_min = mem_per_repl/para_env%num_pe + mem_per_rank
386
387 IF (unit_nr > 0) THEN
388 WRITE (unit_nr, '(T3,A,T68,F9.2,A4)') 'RI_INFO| Minimum required memory per MPI process:', mem_min, ' MiB'
389 WRITE (unit_nr, '(T3,A,T68,F9.2,A4)') 'RI_INFO| Available memory per MPI process:', mem_real, ' MiB'
390 END IF
391
392 ! Use only the allowed amount of memory
393 mem_real = min(mem_real, allowed_memory)
394 ! For the memory estimate, we require the amount of required memory per replication group and the available memory
395 mem_real = mem_real - mem_per_rank
396
397 mem_per_group = mem_real*para_env_sub%num_pe
398
399 ! here we try to find the best rpa/laplace group size
400 skip_integ_group_opt = .false.
401
402 ! Check the input number of integration groups
403 IF (input_num_integ_groups > 0) THEN
404 IF (num_integ_points < input_num_integ_groups) THEN
405 IF (mod(ngroup, input_num_integ_groups) == 0) THEN
406 best_integ_group_size = ngroup/input_num_integ_groups
407 best_num_integ_point = (num_integ_points + input_num_integ_groups - 1)/input_num_integ_groups
408 skip_integ_group_opt = .true.
409 ELSE
410 IF (unit_nr > 0) WRITE (unit_nr, '(T3,A)') 'Total number of groups not multiple of NUM_INTEG_GROUPS'
411 END IF
412 ELSE
413 IF (unit_nr > 0) WRITE (unit_nr, '(T3,A)') 'Too many integration groups for the given number of quadrature points'
414 END IF
415 END IF
416
417 IF (.NOT. skip_integ_group_opt) THEN
418 best_integ_group_size = ngroup
419 best_num_integ_point = num_integ_points
420
421 min_integ_group_size = max(1, ngroup/num_integ_points)
422
423 integ_group_size = min_integ_group_size - 1
424 DO iib = min_integ_group_size + 1, ngroup
425 integ_group_size = integ_group_size + 1
426
427 ! check that the ngroup is a multiple of integ_group_size
428 IF (mod(ngroup, integ_group_size) /= 0) cycle
429
430 ! check for memory
431 avail_mem = integ_group_size*mem_per_group
432 IF (avail_mem < mem_per_repl) cycle
433
434 ! check that the integration groups have the same size
435 num_integ_group = ngroup/integ_group_size
436
437 best_num_integ_point = (num_integ_points + num_integ_group - 1)/num_integ_group
438 best_integ_group_size = integ_group_size
439
440 EXIT
441
442 END DO
443 END IF
444
445 integ_group_size = best_integ_group_size
446
447 END IF
448
449 IF (unit_nr > 0 .AND. .NOT. do_im_time) THEN
450 IF (do_ri_sos_laplace_mp2) THEN
451 WRITE (unit=unit_nr, fmt="(T3,A,T75,i6)") &
452 "RI_INFO| Group size for laplace numerical integration:", integ_group_size*para_env_sub%num_pe
453 WRITE (unit=unit_nr, fmt="(T3,A)") &
454 "INTEG_INFO| MINIMAX approximation"
455 WRITE (unit=unit_nr, fmt="(T3,A,T75,i6)") &
456 "INTEG_INFO| Number of integration points:", num_integ_points
457 WRITE (unit=unit_nr, fmt="(T3,A,T75,i6)") &
458 "INTEG_INFO| Max. number of integration points per Laplace group:", best_num_integ_point
459 ELSE
460 WRITE (unit=unit_nr, fmt="(T3,A,T75,i6)") &
461 "RI_INFO| Group size for frequency integration:", integ_group_size*para_env_sub%num_pe
462 IF (do_minimax_quad) THEN
463 WRITE (unit=unit_nr, fmt="(T3,A)") &
464 "INTEG_INFO| MINIMAX quadrature"
465 ELSE
466 WRITE (unit=unit_nr, fmt="(T3,A)") &
467 "INTEG_INFO| Clenshaw-Curtius quadrature"
468 END IF
469 WRITE (unit=unit_nr, fmt="(T3,A,T75,i6)") &
470 "INTEG_INFO| Number of integration points:", num_integ_points
471 WRITE (unit=unit_nr, fmt="(T3,A,T75,i6)") &
472 "INTEG_INFO| Max. number of integration points per RPA group:", best_num_integ_point
473 END IF
474 CALL m_flush(unit_nr)
475 END IF
476
477 num_integ_group = ngroup/integ_group_size
478
479 pos_integ_group = mod(color_sub, integ_group_size)
480 color_rpa_group = color_sub/integ_group_size
481
482 CALL timeset(routinen//"_reorder", handle2)
483
484 ! not necessary for imaginary time
485
486 ALLOCATE (bib_c_2d(nspins))
487
488 IF (.NOT. do_im_time) THEN
489
490 ! reorder the local data in such a way to help the next stage of matrix creation
491 ! now the data inside the group are divided into a ia x K matrix
492 DO ispin = 1, nspins
493 CALL calculate_bib_c_2d(bib_c_2d(ispin)%array, bib_c(ispin)%array, para_env_sub, dimen_ia(ispin), &
494 homo(ispin), virtual(ispin), gd_b_virtual(ispin), &
495 my_ia_size(ispin), my_ia_start(ispin), my_ia_end(ispin), my_group_l_size)
496
497 DEALLOCATE (bib_c(ispin)%array)
498 CALL release_group_dist(gd_b_virtual(ispin))
499
500 END DO
501
502 ! in the GW case, BIb_C_2D_gw is an nm x K matrix, with n: number of corr GW levels, m=nmo
503 IF (my_do_gw) THEN
504 ALLOCATE (bib_c_2d_gw(nspins))
505
506 CALL timeset(routinen//"_reorder_gw", handle3)
507
508 dimen_nm_gw = nmo*(gw_corr_lev_occ(1) + gw_corr_lev_virt(1))
509
510 ! The same for open shell
511 DO ispin = 1, nspins
512 CALL calculate_bib_c_2d(bib_c_2d_gw(ispin)%array, bib_c_gw(ispin)%array, para_env_sub, dimen_nm_gw, &
513 gw_corr_lev_occ(ispin) + gw_corr_lev_virt(ispin), nmo, gd_b_all, &
514 my_nm_gw_size, my_nm_gw_start, my_nm_gw_end, my_group_l_size)
515 DEALLOCATE (bib_c_gw(ispin)%array)
516 END DO
517
518 CALL release_group_dist(gd_b_all)
519
520 CALL timestop(handle3)
521
522 END IF
523 END IF
524
525 IF (do_bse) THEN
526
527 CALL timeset(routinen//"_reorder_bse1", handle3)
528
529 ALLOCATE (bib_c_2d_bse_ij(nspins), bib_c_2d_bse_ab(nspins))
530 ALLOCATE (dimen_homo_square(nspins))
531 ALLOCATE (my_ij_comb_bse_size(nspins), my_ij_comb_bse_start(nspins), my_ij_comb_bse_end(nspins))
532 ALLOCATE (my_ab_comb_bse_size(nspins), my_ab_comb_bse_start(nspins), my_ab_comb_bse_end(nspins))
533
534 ! We do not implement an explicit bse_lev_occ different to homo here, because the small number of occupied levels
535 ! does not critically influence the memory
536 DO ispin = 1, nspins
537 dimen_homo_square(ispin) = homo(ispin)**2
538 CALL calculate_bib_c_2d(bib_c_2d_bse_ij(ispin)%array, bib_c_bse_ij(ispin)%array, para_env_sub, &
539 dimen_homo_square(ispin), homo(ispin), homo(ispin), gd_b_occ_bse(ispin), &
540 my_ij_comb_bse_size(ispin), my_ij_comb_bse_start(ispin), &
541 my_ij_comb_bse_end(ispin), my_group_l_size)
542 DEALLOCATE (bib_c_bse_ij(ispin)%array)
543 CALL release_group_dist(gd_b_occ_bse(ispin))
544 END DO
545
546 CALL timestop(handle3)
547
548 CALL timeset(routinen//"_reorder_bse2", handle3)
549
550 ! bse_lev_virt(ispin) (hence dimen_virt_square) and gd_B_virt_bse(ispin) are per-spin
551 DO ispin = 1, nspins
552 dimen_virt_square = bse_lev_virt(ispin)**2
553 CALL calculate_bib_c_2d(bib_c_2d_bse_ab(ispin)%array, bib_c_bse_ab(ispin)%array, para_env_sub, &
554 dimen_virt_square, bse_lev_virt(ispin), bse_lev_virt(ispin), gd_b_virt_bse(ispin), &
555 my_ab_comb_bse_size(ispin), my_ab_comb_bse_start(ispin), &
556 my_ab_comb_bse_end(ispin), my_group_l_size)
557 DEALLOCATE (bib_c_bse_ab(ispin)%array)
558 CALL release_group_dist(gd_b_virt_bse(ispin))
559 END DO
560
561 CALL timestop(handle3)
562
563 END IF
564
565 CALL timestop(handle2)
566
567 IF (num_integ_group > 1) THEN
568 ALLOCATE (para_env_rpa)
569 CALL para_env_rpa%from_split(para_env, color_rpa_group)
570 ELSE
571 para_env_rpa => para_env
572 END IF
573
574 ! now create the matrices needed for the calculation, Q, S and G
575 ! Q and G will have omega dependence
576
577 IF (do_im_time) THEN
578 ALLOCATE (fm_mat_q(nspins), fm_mat_q_gemm(1), fm_mat_s(1))
579 ELSE
580 ALLOCATE (fm_mat_q(nspins), fm_mat_q_gemm(nspins), fm_mat_s(nspins))
581 END IF
582
583 CALL create_integ_mat(bib_c_2d, para_env, para_env_sub, color_sub, ngroup, integ_group_size, &
584 dimen_ri_red, dimen_ia, color_rpa_group, &
585 mp2_env%block_size_row, mp2_env%block_size_col, unit_nr, &
586 my_ia_size, my_ia_start, my_ia_end, &
587 my_group_l_size, my_group_l_start, my_group_l_end, &
588 para_env_rpa, fm_mat_s, nrow_block_mat, ncol_block_mat, &
589 dimen_ia_for_block_size=dimen_ia(1), &
590 do_im_time=do_im_time, fm_mat_q_gemm=fm_mat_q_gemm, fm_mat_q=fm_mat_q, qs_env=qs_env)
591
592 DEALLOCATE (bib_c_2d, my_ia_end, my_ia_size, my_ia_start)
593
594 ! for GW, we need other matrix fm_mat_S, always allocate the container to prevent crying compilers
595 ALLOCATE (fm_mat_s_gw(nspins))
596 IF (my_do_gw .AND. .NOT. do_im_time) THEN
597
598 CALL create_integ_mat(bib_c_2d_gw, para_env, para_env_sub, color_sub, ngroup, integ_group_size, &
599 dimen_ri_red, [dimen_nm_gw, dimen_nm_gw], color_rpa_group, &
600 mp2_env%block_size_row, mp2_env%block_size_col, unit_nr, &
601 [my_nm_gw_size, my_nm_gw_size], [my_nm_gw_start, my_nm_gw_start], [my_nm_gw_end, my_nm_gw_end], &
602 my_group_l_size, my_group_l_start, my_group_l_end, &
603 para_env_rpa, fm_mat_s_gw, nrow_block_mat, ncol_block_mat, &
604 fm_mat_q(1)%matrix_struct%context, fm_mat_q(1)%matrix_struct%context, &
605 fm_mat_q=fm_mat_r_gw)
606 DEALLOCATE (bib_c_2d_gw)
607
608 END IF
609
610 ! for Bethe-Salpeter, we need other matrix fm_mat_S (per spin; the ab slab dimension is spin-independent)
611 IF (do_bse) THEN
612 ALLOCATE (fm_mat_s_ij_bse(nspins), fm_mat_s_ab_bse(nspins))
613 CALL create_integ_mat(bib_c_2d_bse_ij, para_env, para_env_sub, color_sub, ngroup, integ_group_size, &
614 dimen_ri_red, dimen_homo_square, color_rpa_group, &
615 mp2_env%block_size_row, mp2_env%block_size_col, unit_nr, &
616 my_ij_comb_bse_size, my_ij_comb_bse_start, my_ij_comb_bse_end, &
617 my_group_l_size, my_group_l_start, my_group_l_end, &
618 para_env_rpa, fm_mat_s_ij_bse, nrow_block_mat, ncol_block_mat, &
619 fm_mat_q(1)%matrix_struct%context, fm_mat_q(1)%matrix_struct%context)
620
621 CALL create_integ_mat(bib_c_2d_bse_ab, para_env, para_env_sub, color_sub, ngroup, integ_group_size, &
622 dimen_ri_red, [(bse_lev_virt(ispin)**2, ispin=1, nspins)], color_rpa_group, &
623 mp2_env%block_size_row, mp2_env%block_size_col, unit_nr, &
624 my_ab_comb_bse_size, my_ab_comb_bse_start, my_ab_comb_bse_end, &
625 my_group_l_size, my_group_l_start, my_group_l_end, &
626 para_env_rpa, fm_mat_s_ab_bse, nrow_block_mat, ncol_block_mat, &
627 fm_mat_q(1)%matrix_struct%context, fm_mat_q(1)%matrix_struct%context)
628
629 END IF
630
631 do_kpoints_from_gamma = qs_env%mp2_env%ri_rpa_im_time%do_kpoints_from_Gamma
632 IF (do_kpoints_from_gamma) THEN
633 CALL get_bandstruc_and_k_dependent_mos(qs_env, eigenval_kp)
634 END IF
635
636 ! Now start the RPA calculation
637 ! fm_mo_coeff_occ, fm_mo_coeff_virt will be deallocated here
638 CALL rpa_num_int(qs_env, erpa, mp2_env, para_env, para_env_rpa, para_env_sub, unit_nr, &
639 homo, virtual, dimen_ri, dimen_ri_red, dimen_ia, dimen_nm_gw, &
640 eigenval_kp, num_integ_points, num_integ_group, color_rpa_group, &
641 fm_matrix_pq, fm_mat_s, fm_mat_q_gemm, fm_mat_q, fm_mat_s_gw, fm_mat_r_gw(1), &
642 fm_mat_s_ij_bse, fm_mat_s_ab_bse, &
643 my_do_gw, do_bse, gw_corr_lev_occ, gw_corr_lev_virt, &
644 bse_lev_virt, &
645 do_minimax_quad, &
646 do_im_time, mo_coeff, &
647 fm_matrix_l_kpoints, fm_matrix_minv_l_kpoints, &
648 fm_matrix_minv, fm_matrix_minv_vtrunc_minv, mat_munu, mat_p_global, &
649 t_3c_m, t_3c_o, t_3c_o_compressed, t_3c_o_ind, &
650 starts_array_mc, ends_array_mc, &
651 starts_array_mc_block, ends_array_mc_block, &
652 matrix_s, do_kpoints_from_gamma, kpoints, gd_array, color_sub, &
653 do_ri_sos_laplace_mp2=do_ri_sos_laplace_mp2, calc_forces=calc_forces)
654
655 CALL release_group_dist(gd_array)
656
657 IF (num_integ_group > 1) CALL mp_para_env_release(para_env_rpa)
658
659 IF (.NOT. do_im_time) THEN
660 CALL cp_fm_release(fm_mat_q_gemm)
661 CALL cp_fm_release(fm_mat_s)
662 END IF
663 CALL cp_fm_release(fm_mat_q)
664
665 IF (my_do_gw .AND. .NOT. do_im_time) THEN
666 CALL cp_fm_release(fm_mat_s_gw)
667 CALL cp_fm_release(fm_mat_r_gw(1))
668 END IF
669
670 IF (do_bse) THEN
671 DO ispin = 1, nspins
672 CALL cp_fm_release(fm_mat_s_ij_bse(ispin))
673 CALL cp_fm_release(fm_mat_s_ab_bse(ispin))
674 END DO
675 DEALLOCATE (fm_mat_s_ij_bse, fm_mat_s_ab_bse)
676 END IF
677
678 CALL timestop(handle)
679
680 END SUBROUTINE rpa_ri_compute_en
681
682! **************************************************************************************************
683!> \brief reorder the local data in such a way to help the next stage of matrix creation;
684!> now the data inside the group are divided into a ia x K matrix (BIb_C_2D);
685!> Subroutine created to avoid massive double coding
686!> \param BIb_C_2D ...
687!> \param BIb_C ...
688!> \param para_env_sub ...
689!> \param dimen_ia ...
690!> \param homo ...
691!> \param virtual ...
692!> \param gd_B_virtual ...
693!> \param my_ia_size ...
694!> \param my_ia_start ...
695!> \param my_ia_end ...
696!> \param my_group_L_size ...
697!> \author Jan Wilhelm, 03/2015
698! **************************************************************************************************
699 SUBROUTINE calculate_bib_c_2d(BIb_C_2D, BIb_C, para_env_sub, dimen_ia, homo, virtual, &
700 gd_B_virtual, &
701 my_ia_size, my_ia_start, my_ia_end, my_group_L_size)
702
703 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :), &
704 INTENT(OUT) :: bib_c_2d
705 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :), &
706 INTENT(IN) :: bib_c
707 TYPE(mp_para_env_type), INTENT(IN) :: para_env_sub
708 INTEGER, INTENT(IN) :: dimen_ia, homo, virtual
709 TYPE(group_dist_d1_type), INTENT(INOUT) :: gd_b_virtual
710 INTEGER :: my_ia_size, my_ia_start, my_ia_end, &
711 my_group_l_size
712
713 INTEGER, PARAMETER :: occ_chunk = 128
714
715 INTEGER :: ia_global, iib, itmp(2), jjb, my_b_size, my_b_virtual_start, occ_high, occ_low, &
716 proc_receive, proc_send, proc_shift, rec_b_size, rec_b_virtual_end, rec_b_virtual_start
717 REAL(kind=dp), ALLOCATABLE, DIMENSION(:), TARGET :: bib_c_rec_1d
718 REAL(kind=dp), DIMENSION(:, :, :), POINTER :: bib_c_rec
719
720 itmp = get_limit(dimen_ia, para_env_sub%num_pe, para_env_sub%mepos)
721 my_ia_start = itmp(1)
722 my_ia_end = itmp(2)
723 my_ia_size = my_ia_end - my_ia_start + 1
724
725 CALL get_group_dist(gd_b_virtual, para_env_sub%mepos, sizes=my_b_size, starts=my_b_virtual_start)
726
727 ! reorder data
728 ALLOCATE (bib_c_2d(my_group_l_size, my_ia_size))
729
730!$OMP PARALLEL DO DEFAULT(NONE) PRIVATE(jjB,ia_global) &
731!$OMP SHARED(homo,my_B_size,virtual,my_B_virtual_start,my_ia_start,my_ia_end,BIb_C,BIb_C_2D,&
732!$OMP my_group_L_size)
733 DO iib = 1, homo
734 DO jjb = 1, my_b_size
735 ia_global = (iib - 1)*virtual + my_b_virtual_start + jjb - 1
736 IF (ia_global >= my_ia_start .AND. ia_global <= my_ia_end) THEN
737 bib_c_2d(1:my_group_l_size, ia_global - my_ia_start + 1) = bib_c(1:my_group_l_size, jjb, iib)
738 END IF
739 END DO
740 END DO
741
742 IF (para_env_sub%num_pe > 1) THEN
743 ALLOCATE (bib_c_rec_1d(int(my_group_l_size, int_8)*maxsize(gd_b_virtual)*min(homo, occ_chunk)))
744 DO proc_shift = 1, para_env_sub%num_pe - 1
745 proc_send = modulo(para_env_sub%mepos + proc_shift, para_env_sub%num_pe)
746 proc_receive = modulo(para_env_sub%mepos - proc_shift, para_env_sub%num_pe)
747
748 CALL get_group_dist(gd_b_virtual, proc_receive, rec_b_virtual_start, rec_b_virtual_end, rec_b_size)
749
750 ! do this in chunks to avoid high memory overhead
751 DO occ_low = 1, homo, occ_chunk
752 occ_high = min(homo, occ_low + occ_chunk - 1)
753 bib_c_rec(1:my_group_l_size, 1:rec_b_size, 1:occ_high - occ_low + 1) => &
754 bib_c_rec_1d(1:int(my_group_l_size, int_8)*rec_b_size*(occ_high - occ_low + 1))
755 CALL para_env_sub%sendrecv(bib_c(:, :, occ_low:occ_high), proc_send, &
756 bib_c_rec(:, :, 1:occ_high - occ_low + 1), proc_receive)
757!$OMP PARALLEL DO DEFAULT(NONE) PRIVATE(jjB,ia_global) &
758!$OMP SHARED(occ_low,occ_high,rec_B_size,virtual,rec_B_virtual_start,my_ia_start,my_ia_end,BIb_C_rec,BIb_C_2D,&
759!$OMP my_group_L_size)
760 DO iib = occ_low, occ_high
761 DO jjb = 1, rec_b_size
762 ia_global = (iib - 1)*virtual + rec_b_virtual_start + jjb - 1
763 IF (ia_global >= my_ia_start .AND. ia_global <= my_ia_end) THEN
764 bib_c_2d(1:my_group_l_size, ia_global - my_ia_start + 1) = bib_c_rec(1:my_group_l_size, jjb, iib - occ_low + 1)
765 END IF
766 END DO
767 END DO
768 END DO
769
770 END DO
771 DEALLOCATE (bib_c_rec_1d)
772 END IF
773
774 END SUBROUTINE calculate_bib_c_2d
775
776! **************************************************************************************************
777!> \brief ...
778!> \param BIb_C_2D ...
779!> \param para_env ...
780!> \param para_env_sub ...
781!> \param color_sub ...
782!> \param ngroup ...
783!> \param integ_group_size ...
784!> \param dimen_RI ...
785!> \param dimen_ia ...
786!> \param color_rpa_group ...
787!> \param ext_row_block_size ...
788!> \param ext_col_block_size ...
789!> \param unit_nr ...
790!> \param my_ia_size ...
791!> \param my_ia_start ...
792!> \param my_ia_end ...
793!> \param my_group_L_size ...
794!> \param my_group_L_start ...
795!> \param my_group_L_end ...
796!> \param para_env_RPA ...
797!> \param fm_mat_S ...
798!> \param nrow_block_mat ...
799!> \param ncol_block_mat ...
800!> \param blacs_env_ext ...
801!> \param blacs_env_ext_S ...
802!> \param dimen_ia_for_block_size ...
803!> \param do_im_time ...
804!> \param fm_mat_Q_gemm ...
805!> \param fm_mat_Q ...
806!> \param qs_env ...
807! **************************************************************************************************
808 SUBROUTINE create_integ_mat(BIb_C_2D, para_env, para_env_sub, color_sub, ngroup, integ_group_size, &
809 dimen_RI, dimen_ia, color_rpa_group, &
810 ext_row_block_size, ext_col_block_size, unit_nr, &
811 my_ia_size, my_ia_start, my_ia_end, &
812 my_group_L_size, my_group_L_start, my_group_L_end, &
813 para_env_RPA, fm_mat_S, nrow_block_mat, ncol_block_mat, &
814 blacs_env_ext, blacs_env_ext_S, dimen_ia_for_block_size, &
815 do_im_time, fm_mat_Q_gemm, fm_mat_Q, qs_env)
816
817 TYPE(two_dim_real_array), DIMENSION(:), &
818 INTENT(INOUT) :: bib_c_2d
819 TYPE(mp_para_env_type), INTENT(IN) :: para_env, para_env_sub
820 INTEGER, INTENT(IN) :: color_sub, ngroup, integ_group_size, &
821 dimen_ri
822 INTEGER, DIMENSION(:), INTENT(IN) :: dimen_ia
823 INTEGER, INTENT(IN) :: color_rpa_group, ext_row_block_size, &
824 ext_col_block_size, unit_nr
825 INTEGER, DIMENSION(:), INTENT(IN) :: my_ia_size, my_ia_start, my_ia_end
826 INTEGER, INTENT(IN) :: my_group_l_size, my_group_l_start, &
827 my_group_l_end
828 TYPE(mp_para_env_type), INTENT(IN), POINTER :: para_env_rpa
829 TYPE(cp_fm_type), DIMENSION(:), INTENT(INOUT) :: fm_mat_s
830 INTEGER, INTENT(INOUT) :: nrow_block_mat, ncol_block_mat
831 TYPE(cp_blacs_env_type), OPTIONAL, POINTER :: blacs_env_ext, blacs_env_ext_s
832 INTEGER, INTENT(IN), OPTIONAL :: dimen_ia_for_block_size
833 LOGICAL, INTENT(IN), OPTIONAL :: do_im_time
834 TYPE(cp_fm_type), DIMENSION(:), OPTIONAL :: fm_mat_q_gemm, fm_mat_q
835 TYPE(qs_environment_type), INTENT(IN), OPTIONAL, &
836 POINTER :: qs_env
837
838 CHARACTER(LEN=*), PARAMETER :: routinen = 'create_integ_mat'
839
840 INTEGER :: col_row_proc_ratio, grid_2d(2), handle, &
841 iproc, iproc_col, iproc_row, ispin, &
842 mepos_in_rpa_group
843 INTEGER, ALLOCATABLE, DIMENSION(:, :) :: group_grid_2_mepos
844 LOGICAL :: my_blacs_ext, my_blacs_s_ext, &
845 my_do_im_time
846 TYPE(cp_blacs_env_type), POINTER :: blacs_env, blacs_env_q
847 TYPE(cp_fm_struct_type), POINTER :: fm_struct
848 TYPE(group_dist_d1_type) :: gd_ia, gd_l
849
850 CALL timeset(routinen, handle)
851
852 cpassert(PRESENT(blacs_env_ext) .OR. PRESENT(dimen_ia_for_block_size))
853
854 my_blacs_ext = .false.
855 IF (PRESENT(blacs_env_ext)) my_blacs_ext = .true.
856
857 my_blacs_s_ext = .false.
858 IF (PRESENT(blacs_env_ext_s)) my_blacs_s_ext = .true.
859
860 my_do_im_time = .false.
861 IF (PRESENT(do_im_time)) my_do_im_time = do_im_time
862
863 NULLIFY (blacs_env)
864 ! create the RPA blacs env
865 IF (my_blacs_s_ext) THEN
866 blacs_env => blacs_env_ext_s
867 ELSE
868 IF (para_env_rpa%num_pe > 1) THEN
869 col_row_proc_ratio = max(1, dimen_ia_for_block_size/dimen_ri)
870
871 iproc_col = min(max(int(sqrt(real(para_env_rpa%num_pe*col_row_proc_ratio, kind=dp))), 1), para_env_rpa%num_pe) + 1
872 DO iproc = 1, para_env_rpa%num_pe
873 iproc_col = iproc_col - 1
874 IF (mod(para_env_rpa%num_pe, iproc_col) == 0) EXIT
875 END DO
876
877 iproc_row = para_env_rpa%num_pe/iproc_col
878 grid_2d(1) = iproc_row
879 grid_2d(2) = iproc_col
880 ELSE
881 grid_2d = 1
882 END IF
883 CALL cp_blacs_env_create(blacs_env=blacs_env, para_env=para_env_rpa, grid_2d=grid_2d)
884
885 IF (unit_nr > 0 .AND. .NOT. my_do_im_time) THEN
886 WRITE (unit=unit_nr, fmt="(T3,A,T75,i6)") &
887 "MATRIX_INFO| Number row processes:", grid_2d(1)
888 WRITE (unit=unit_nr, fmt="(T3,A,T75,i6)") &
889 "MATRIX_INFO| Number column processes:", grid_2d(2)
890 END IF
891
892 ! define the block_size for the row
893 IF (ext_row_block_size > 0) THEN
894 nrow_block_mat = ext_row_block_size
895 ELSE
896 nrow_block_mat = max(1, dimen_ri/grid_2d(1)/2)
897 END IF
898
899 ! define the block_size for the column
900 IF (ext_col_block_size > 0) THEN
901 ncol_block_mat = ext_col_block_size
902 ELSE
903 ncol_block_mat = max(1, dimen_ia_for_block_size/grid_2d(2)/2)
904 END IF
905
906 IF (unit_nr > 0 .AND. .NOT. my_do_im_time) THEN
907 WRITE (unit=unit_nr, fmt="(T3,A,T75,i6)") &
908 "MATRIX_INFO| Row block size:", nrow_block_mat
909 WRITE (unit=unit_nr, fmt="(T3,A,T75,i6)") &
910 "MATRIX_INFO| Column block size:", ncol_block_mat
911 END IF
912 END IF
913
914 IF (.NOT. my_do_im_time) THEN
915 DO ispin = 1, SIZE(bib_c_2d)
916 NULLIFY (fm_struct)
917 IF (my_blacs_ext) THEN
918 CALL cp_fm_struct_create(fm_struct, context=blacs_env, nrow_global=dimen_ri, &
919 ncol_global=dimen_ia(ispin), para_env=para_env_rpa)
920 ELSE
921 CALL cp_fm_struct_create(fm_struct, context=blacs_env, nrow_global=dimen_ri, &
922 ncol_global=dimen_ia(ispin), para_env=para_env_rpa, &
923 nrow_block=nrow_block_mat, ncol_block=ncol_block_mat, force_block=.true.)
924
925 END IF ! external blacs_env
926
927 CALL create_group_dist(gd_ia, my_ia_start(ispin), my_ia_end(ispin), my_ia_size(ispin), para_env_rpa)
928 CALL create_group_dist(gd_l, my_group_l_start, my_group_l_end, my_group_l_size, para_env_rpa)
929
930 ! create the info array
931
932 mepos_in_rpa_group = mod(color_sub, integ_group_size)
933 ALLOCATE (group_grid_2_mepos(0:integ_group_size - 1, 0:para_env_sub%num_pe - 1))
934 group_grid_2_mepos = 0
935 group_grid_2_mepos(mepos_in_rpa_group, para_env_sub%mepos) = para_env_rpa%mepos
936 CALL para_env_rpa%sum(group_grid_2_mepos)
937
938 CALL array2fm(bib_c_2d(ispin)%array, fm_struct, my_group_l_start, my_group_l_end, &
939 my_ia_start(ispin), my_ia_end(ispin), gd_l, gd_ia, &
940 group_grid_2_mepos, ngroup, para_env_sub%num_pe, fm_mat_s(ispin), &
941 integ_group_size, color_rpa_group)
942
943 DEALLOCATE (group_grid_2_mepos)
944 CALL cp_fm_struct_release(fm_struct)
945
946 ! deallocate the info array
947 CALL release_group_dist(gd_l)
948 CALL release_group_dist(gd_ia)
949
950 ! sum the local data across processes belonging to different RPA group.
951 IF (para_env_rpa%num_pe /= para_env%num_pe) THEN
952 block
953 TYPE(mp_comm_type) :: comm_exchange
954 comm_exchange = fm_mat_s(ispin)%matrix_struct%context%interconnect(para_env)
955 CALL comm_exchange%sum(fm_mat_s(ispin)%local_data)
956 CALL comm_exchange%free()
957 END block
958 END IF
959 END DO
960 END IF
961
962 IF (PRESENT(fm_mat_q_gemm) .AND. .NOT. my_do_im_time) THEN
963 ! create the Q matrix dimen_RIxdimen_RI where the result of the mat-mat-mult will be stored
964 NULLIFY (fm_struct)
965 CALL cp_fm_struct_create(fm_struct, context=blacs_env, nrow_global=dimen_ri, &
966 ncol_global=dimen_ri, para_env=para_env_rpa, &
967 nrow_block=nrow_block_mat, ncol_block=ncol_block_mat, force_block=.true.)
968 DO ispin = 1, SIZE(fm_mat_q_gemm)
969 CALL cp_fm_create(fm_mat_q_gemm(ispin), fm_struct, name="fm_mat_Q_gemm")
970 END DO
971 CALL cp_fm_struct_release(fm_struct)
972 END IF
973
974 IF (PRESENT(fm_mat_q)) THEN
975 NULLIFY (blacs_env_q)
976 IF (my_blacs_ext) THEN
977 blacs_env_q => blacs_env_ext
978 ELSE IF (para_env_rpa%num_pe == para_env%num_pe .AND. PRESENT(qs_env)) THEN
979 CALL get_qs_env(qs_env, blacs_env=blacs_env_q)
980 ELSE
981 CALL cp_blacs_env_create(blacs_env=blacs_env_q, para_env=para_env_rpa)
982 END IF
983 NULLIFY (fm_struct)
984 CALL cp_fm_struct_create(fm_struct, context=blacs_env_q, nrow_global=dimen_ri, &
985 ncol_global=dimen_ri, para_env=para_env_rpa)
986 DO ispin = 1, SIZE(fm_mat_q)
987 CALL cp_fm_create(fm_mat_q(ispin), fm_struct, name="fm_mat_Q", set_zero=.true.)
988 END DO
989
990 CALL cp_fm_struct_release(fm_struct)
991
992 IF (.NOT. (my_blacs_ext .OR. (para_env_rpa%num_pe == para_env%num_pe .AND. PRESENT(qs_env)))) THEN
993 CALL cp_blacs_env_release(blacs_env_q)
994 END IF
995 END IF
996
997 ! release blacs_env
998 IF (.NOT. my_blacs_s_ext) THEN
999 CALL cp_blacs_env_release(blacs_env)
1000 ELSE
1001 NULLIFY (blacs_env)
1002 END IF
1003
1004 CALL timestop(handle)
1005
1006 END SUBROUTINE create_integ_mat
1007
1008! **************************************************************************************************
1009!> \brief ...
1010!> \param qs_env ...
1011!> \param Erpa ...
1012!> \param mp2_env ...
1013!> \param para_env ...
1014!> \param para_env_RPA ...
1015!> \param para_env_sub ...
1016!> \param unit_nr ...
1017!> \param homo ...
1018!> \param virtual ...
1019!> \param dimen_RI ...
1020!> \param dimen_RI_red ...
1021!> \param dimen_ia ...
1022!> \param dimen_nm_gw ...
1023!> \param Eigenval ...
1024!> \param num_integ_points ...
1025!> \param num_integ_group ...
1026!> \param color_rpa_group ...
1027!> \param fm_matrix_PQ ...
1028!> \param fm_mat_S ...
1029!> \param fm_mat_Q_gemm ...
1030!> \param fm_mat_Q ...
1031!> \param fm_mat_S_gw ...
1032!> \param fm_mat_R_gw ...
1033!> \param fm_mat_S_ij_bse ...
1034!> \param fm_mat_S_ab_bse ...
1035!> \param my_do_gw ...
1036!> \param do_bse ...
1037!> \param gw_corr_lev_occ ...
1038!> \param gw_corr_lev_virt ...
1039!> \param bse_lev_virt ...
1040!> \param do_minimax_quad ...
1041!> \param do_im_time ...
1042!> \param mo_coeff ...
1043!> \param fm_matrix_L_kpoints ...
1044!> \param fm_matrix_Minv_L_kpoints ...
1045!> \param fm_matrix_Minv ...
1046!> \param fm_matrix_Minv_Vtrunc_Minv ...
1047!> \param mat_munu ...
1048!> \param mat_P_global ...
1049!> \param t_3c_M ...
1050!> \param t_3c_O ...
1051!> \param t_3c_O_compressed ...
1052!> \param t_3c_O_ind ...
1053!> \param starts_array_mc ...
1054!> \param ends_array_mc ...
1055!> \param starts_array_mc_block ...
1056!> \param ends_array_mc_block ...
1057!> \param matrix_s ...
1058!> \param do_kpoints_from_Gamma ...
1059!> \param kpoints ...
1060!> \param gd_array ...
1061!> \param color_sub ...
1062!> \param do_ri_sos_laplace_mp2 ...
1063!> \param calc_forces ...
1064! **************************************************************************************************
1065 SUBROUTINE rpa_num_int(qs_env, Erpa, mp2_env, para_env, para_env_RPA, para_env_sub, unit_nr, &
1066 homo, virtual, dimen_RI, dimen_RI_red, dimen_ia, dimen_nm_gw, &
1067 Eigenval, num_integ_points, num_integ_group, color_rpa_group, &
1068 fm_matrix_PQ, fm_mat_S, fm_mat_Q_gemm, fm_mat_Q, fm_mat_S_gw, fm_mat_R_gw, &
1069 fm_mat_S_ij_bse, fm_mat_S_ab_bse, &
1070 my_do_gw, do_bse, gw_corr_lev_occ, gw_corr_lev_virt, &
1071 bse_lev_virt, &
1072 do_minimax_quad, do_im_time, mo_coeff, &
1073 fm_matrix_L_kpoints, fm_matrix_Minv_L_kpoints, &
1074 fm_matrix_Minv, fm_matrix_Minv_Vtrunc_Minv, mat_munu, mat_P_global, &
1075 t_3c_M, t_3c_O, t_3c_O_compressed, t_3c_O_ind, &
1076 starts_array_mc, ends_array_mc, &
1077 starts_array_mc_block, ends_array_mc_block, &
1078 matrix_s, do_kpoints_from_Gamma, kpoints, gd_array, color_sub, &
1079 do_ri_sos_laplace_mp2, calc_forces)
1080
1081 TYPE(qs_environment_type), POINTER :: qs_env
1082 REAL(kind=dp), INTENT(OUT) :: erpa
1083 TYPE(mp2_type) :: mp2_env
1084 TYPE(mp_para_env_type), POINTER :: para_env, para_env_rpa, para_env_sub
1085 INTEGER, INTENT(IN) :: unit_nr
1086 INTEGER, DIMENSION(:), INTENT(IN) :: homo, virtual
1087 INTEGER, INTENT(IN) :: dimen_ri, dimen_ri_red
1088 INTEGER, DIMENSION(:), INTENT(IN) :: dimen_ia
1089 INTEGER, INTENT(IN) :: dimen_nm_gw
1090 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :), &
1091 INTENT(INOUT) :: eigenval
1092 INTEGER, INTENT(IN) :: num_integ_points, num_integ_group, &
1093 color_rpa_group
1094 TYPE(cp_fm_type), INTENT(IN) :: fm_matrix_pq
1095 TYPE(cp_fm_type), DIMENSION(:), INTENT(INOUT) :: fm_mat_s
1096 TYPE(cp_fm_type), DIMENSION(:), INTENT(IN) :: fm_mat_q_gemm, fm_mat_q, fm_mat_s_gw
1097 TYPE(cp_fm_type), INTENT(IN) :: fm_mat_r_gw
1098 TYPE(cp_fm_type), DIMENSION(:), INTENT(IN) :: fm_mat_s_ij_bse, fm_mat_s_ab_bse
1099 LOGICAL, INTENT(IN) :: my_do_gw, do_bse
1100 INTEGER, DIMENSION(:), INTENT(IN) :: gw_corr_lev_occ, gw_corr_lev_virt, &
1101 bse_lev_virt
1102 LOGICAL, INTENT(IN) :: do_minimax_quad, do_im_time
1103 TYPE(cp_fm_type), DIMENSION(:), INTENT(IN) :: mo_coeff
1104 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:, :) :: fm_matrix_l_kpoints, &
1105 fm_matrix_minv_l_kpoints, &
1106 fm_matrix_minv, &
1107 fm_matrix_minv_vtrunc_minv
1108 TYPE(dbcsr_p_type), INTENT(IN) :: mat_munu
1109 TYPE(dbcsr_p_type), INTENT(INOUT) :: mat_p_global
1110 TYPE(dbt_type), INTENT(INOUT) :: t_3c_m
1111 TYPE(dbt_type), ALLOCATABLE, DIMENSION(:, :), &
1112 INTENT(INOUT) :: t_3c_o
1113 TYPE(hfx_compression_type), ALLOCATABLE, &
1114 DIMENSION(:, :, :), INTENT(INOUT) :: t_3c_o_compressed
1115 TYPE(block_ind_type), ALLOCATABLE, &
1116 DIMENSION(:, :, :), INTENT(INOUT) :: t_3c_o_ind
1117 INTEGER, ALLOCATABLE, DIMENSION(:), INTENT(IN) :: starts_array_mc, ends_array_mc, &
1118 starts_array_mc_block, &
1119 ends_array_mc_block
1120 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s
1121 LOGICAL :: do_kpoints_from_gamma
1122 TYPE(kpoint_type), POINTER :: kpoints
1123 TYPE(group_dist_d1_type), INTENT(IN) :: gd_array
1124 INTEGER, INTENT(IN) :: color_sub
1125 LOGICAL, INTENT(IN) :: do_ri_sos_laplace_mp2, calc_forces
1126
1127 CHARACTER(LEN=*), PARAMETER :: routinen = 'rpa_num_int'
1128
1129 COMPLEX(KIND=dp), ALLOCATABLE, &
1130 DIMENSION(:, :, :, :) :: vec_sigma_c_gw
1131 INTEGER :: count_ev_sc_gw, cut_memory, group_size_p, gw_corr_lev_tot, handle, handle3, i, &
1132 ikp_local, ispin, iter_evgw, iter_sc_gw0, j, jquad, min_bsize, mm_style, nkp, &
1133 nkp_self_energy, nmo, nspins, num_3c_repl, num_cells_dm, num_fit_points, pspin, qspin, &
1134 size_p
1135 INTEGER(int_8) :: dbcsr_nflop
1136 INTEGER, ALLOCATABLE, DIMENSION(:, :) :: index_to_cell_3c
1137 INTEGER, ALLOCATABLE, DIMENSION(:, :, :) :: cell_to_index_3c
1138 INTEGER, DIMENSION(:), POINTER :: col_blk_size, prim_blk_sizes, &
1139 ri_blk_sizes
1140 LOGICAL :: do_apply_ic_corr_to_gw, do_gw_im_time, do_ic_model, do_kpoints_cubic_rpa, &
1141 do_periodic, do_print, do_ri_sigma_x, exit_ev_gw, first_cycle, &
1142 first_cycle_periodic_correction, my_open_shell, print_ic_values
1143 LOGICAL, ALLOCATABLE, DIMENSION(:, :, :, :, :) :: has_mat_p_blocks
1144 REAL(kind=dp) :: a_scaling, alpha, dbcsr_time, e_exchange, e_exchange_corr, eps_filter, &
1145 eps_filter_im_time, ext_scaling, fermi_level_offset, fermi_level_offset_input, &
1146 my_flop_rate, omega, omega_max_fit, omega_old, tau, tau_old
1147 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: delta_corr, e_fermi, tau_tj, tau_wj, tj, &
1148 trace_qomega, vec_omega_fit_gw, wj, &
1149 wkp_w
1150 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: vec_w_gw, weights_cos_tf_t_to_w, &
1151 weights_cos_tf_w_to_t, &
1152 weights_sin_tf_t_to_w
1153 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :) :: eigenval_last, eigenval_scf, &
1154 vec_sigma_x_gw
1155 TYPE(cp_cfm_type) :: cfm_mat_q
1156 TYPE(cp_fm_type) :: fm_mat_q_static_bse_gemm, fm_mat_ri_global_work, fm_mat_work, &
1157 fm_mo_coeff_occ_scaled, fm_mo_coeff_virt_scaled, fm_scaled_dm_occ_tau, &
1158 fm_scaled_dm_virt_tau
1159 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:) :: fm_mat_s_gw_work, fm_mat_s_ia_bse, &
1160 fm_mat_w, fm_mo_coeff_occ, &
1161 fm_mo_coeff_virt
1162 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:, :) :: fm_mat_l_kpoints, fm_mat_minv_l_kpoints
1163 TYPE(dbcsr_p_type) :: mat_dm, mat_l, mat_m_p_munu_occ, &
1164 mat_m_p_munu_virt, mat_minvvminv
1165 TYPE(dbcsr_p_type), ALLOCATABLE, &
1166 DIMENSION(:, :, :) :: mat_p_omega
1167 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_berry_im_mo_mo, &
1168 matrix_berry_re_mo_mo
1169 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: mat_p_omega_kp
1170 TYPE(dbcsr_type), POINTER :: mat_w, mat_work
1171 TYPE(dbt_type) :: t_3c_overl_int_ao_mo
1172 TYPE(dbt_type), ALLOCATABLE, DIMENSION(:) :: t_3c_overl_int_gw_ao, &
1173 t_3c_overl_int_gw_ri, &
1174 t_3c_overl_nnp_ic, &
1175 t_3c_overl_nnp_ic_reflected
1176 TYPE(dgemm_counter_type) :: dgemm_counter
1177 TYPE(hfx_compression_type), ALLOCATABLE, &
1178 DIMENSION(:) :: t_3c_o_mo_compressed
1179 TYPE(im_time_force_type) :: force_data
1180 TYPE(rpa_exchange_work_type) :: exchange_work
1181 TYPE(rpa_grad_type) :: rpa_grad
1182 TYPE(rpa_sigma_type) :: rpa_sigma
1183 TYPE(two_dim_int_array), ALLOCATABLE, DIMENSION(:) :: t_3c_o_mo_ind
1184
1185 CALL timeset(routinen, handle)
1186
1187 nspins = SIZE(homo)
1188 nmo = homo(1) + virtual(1)
1189
1190 my_open_shell = (nspins == 2)
1191
1192 do_gw_im_time = my_do_gw .AND. do_im_time
1193 do_ri_sigma_x = mp2_env%ri_g0w0%do_ri_Sigma_x
1194 do_ic_model = mp2_env%ri_g0w0%do_ic_model
1195 print_ic_values = mp2_env%ri_g0w0%print_ic_values
1196 do_periodic = mp2_env%ri_g0w0%do_periodic
1197 do_kpoints_cubic_rpa = mp2_env%ri_rpa_im_time%do_im_time_kpoints
1198
1199 ! For SOS-MP2 only gemm is implemented
1200 mm_style = wfc_mm_style_gemm
1201 IF (.NOT. do_ri_sos_laplace_mp2) mm_style = mp2_env%ri_rpa%mm_style
1202
1203 IF (my_do_gw) THEN
1204 ext_scaling = 0.2_dp
1205 omega_max_fit = mp2_env%ri_g0w0%omega_max_fit
1206 fermi_level_offset_input = mp2_env%ri_g0w0%fermi_level_offset
1207 iter_evgw = mp2_env%ri_g0w0%iter_evGW
1208 iter_sc_gw0 = mp2_env%ri_g0w0%iter_sc_GW0
1209 IF ((.NOT. do_im_time)) THEN
1210 IF (iter_sc_gw0 /= 1 .AND. iter_evgw /= 1) cpabort("Mixed scGW0/evGW not implemented.")
1211 ! in case of scGW0 with the N^4 algorithm, we use the evGW code but use the DFT eigenvalues for W
1212 IF (iter_sc_gw0 /= 1) iter_evgw = iter_sc_gw0
1213 END IF
1214 ELSE
1215 ext_scaling = 0.0_dp
1216 iter_evgw = 1
1217 iter_sc_gw0 = 1
1218 END IF
1219
1220 IF (do_kpoints_cubic_rpa .AND. do_ri_sos_laplace_mp2) THEN
1221 cpabort("RI-SOS-Laplace-MP2 with k-point-sampling is not implemented.")
1222 END IF
1223
1224 do_apply_ic_corr_to_gw = .false.
1225 IF (mp2_env%ri_g0w0%ic_corr_list(1)%array(1) > 0.0_dp) do_apply_ic_corr_to_gw = .true.
1226
1227 IF (do_im_time) THEN
1228 cpassert(do_minimax_quad .OR. do_ri_sos_laplace_mp2)
1229
1230 group_size_p = mp2_env%ri_rpa_im_time%group_size_P
1231 cut_memory = mp2_env%ri_rpa_im_time%cut_memory
1232 eps_filter = mp2_env%ri_rpa_im_time%eps_filter
1233 eps_filter_im_time = mp2_env%ri_rpa_im_time%eps_filter* &
1234 mp2_env%ri_rpa_im_time%eps_filter_factor
1235
1236 min_bsize = mp2_env%ri_rpa_im_time%min_bsize
1237
1238 CALL alloc_im_time(qs_env, para_env, dimen_ri, dimen_ri_red, &
1239 num_integ_points, nspins, fm_mat_q(1), fm_mo_coeff_occ, fm_mo_coeff_virt, &
1240 fm_matrix_minv_l_kpoints, fm_matrix_l_kpoints, mat_p_global, &
1241 t_3c_o, matrix_s, kpoints, eps_filter_im_time, &
1242 cut_memory, nkp, num_cells_dm, num_3c_repl, &
1243 size_p, ikp_local, &
1244 index_to_cell_3c, &
1245 cell_to_index_3c, &
1246 col_blk_size, &
1247 do_ic_model, do_kpoints_cubic_rpa, &
1248 do_kpoints_from_gamma, do_ri_sigma_x, my_open_shell, &
1249 has_mat_p_blocks, wkp_w, &
1250 cfm_mat_q, fm_mat_minv_l_kpoints, fm_mat_l_kpoints, &
1251 fm_mat_ri_global_work, fm_mat_work, fm_mo_coeff_occ_scaled, &
1252 fm_mo_coeff_virt_scaled, mat_dm, mat_l, mat_m_p_munu_occ, mat_m_p_munu_virt, &
1253 mat_minvvminv, mat_p_omega, mat_p_omega_kp, mat_work, mo_coeff, &
1254 fm_scaled_dm_occ_tau, fm_scaled_dm_virt_tau, homo, nmo)
1255
1256 IF (calc_forces) CALL init_im_time_forces(force_data, fm_matrix_pq, t_3c_m, unit_nr, mp2_env, qs_env)
1257
1258 IF (my_do_gw) THEN
1259
1260 CALL dbcsr_get_info(mat_p_global%matrix, &
1261 row_blk_size=ri_blk_sizes)
1262
1263 CALL dbcsr_get_info(matrix_s(1)%matrix, &
1264 row_blk_size=prim_blk_sizes)
1265
1266 gw_corr_lev_tot = gw_corr_lev_occ(1) + gw_corr_lev_virt(1)
1267
1268 IF (.NOT. do_kpoints_cubic_rpa) THEN
1269 CALL allocate_matrices_gw_im_time(gw_corr_lev_occ, gw_corr_lev_virt, homo, nmo, &
1270 num_integ_points, unit_nr, &
1271 ri_blk_sizes, do_ic_model, &
1272 para_env, fm_mat_w, fm_mat_q(1), &
1273 mo_coeff, &
1274 t_3c_overl_int_ao_mo, t_3c_o_mo_compressed, t_3c_o_mo_ind, &
1275 t_3c_overl_int_gw_ri, t_3c_overl_int_gw_ao, &
1276 starts_array_mc, ends_array_mc, &
1277 t_3c_overl_nnp_ic, t_3c_overl_nnp_ic_reflected, &
1278 matrix_s, mat_w, t_3c_o, &
1279 t_3c_o_compressed, t_3c_o_ind, &
1280 qs_env)
1281
1282 END IF
1283 END IF
1284
1285 END IF
1286 IF (do_ic_model) THEN
1287 ! image charge model only implemented for cubic scaling GW
1288 cpassert(do_gw_im_time)
1289 cpassert(.NOT. do_periodic)
1290 IF (cut_memory /= 1) cpabort("For IC, use MEMORY_CUT 1 in the LOW_SCALING section.")
1291 END IF
1292
1293 ALLOCATE (e_fermi(nspins))
1294 IF (do_minimax_quad .OR. do_ri_sos_laplace_mp2) THEN
1295 do_print = .NOT. do_ic_model
1296 CALL get_minimax_grid(para_env, unit_nr, homo, eigenval, num_integ_points, do_im_time, &
1297 do_ri_sos_laplace_mp2, do_print, &
1298 tau_tj, tau_wj, qs_env, do_gw_im_time, &
1299 do_kpoints_cubic_rpa, e_fermi(1), tj, wj, &
1300 weights_cos_tf_t_to_w, weights_cos_tf_w_to_t, weights_sin_tf_t_to_w, &
1301 qs_env%mp2_env%ri_g0w0%regularization_minimax)
1302
1303 !For sos_laplace_mp2 and low-scaling RPA, potentially need to store/retrieve the initial weights
1304 IF (qs_env%mp2_env%ri_rpa_im_time%keep_quad) THEN
1305 CALL keep_initial_quad(tj, wj, tau_tj, tau_wj, weights_cos_tf_t_to_w, &
1306 weights_cos_tf_w_to_t, do_ri_sos_laplace_mp2, do_im_time, &
1307 num_integ_points, unit_nr, qs_env)
1308 END IF
1309 ELSE
1310 IF (calc_forces) cpabort("Forces with Clenshaw-Curtis grid not implemented.")
1311 CALL get_clenshaw_grid(para_env, para_env_rpa, unit_nr, homo, virtual, eigenval, num_integ_points, &
1312 num_integ_group, color_rpa_group, fm_mat_s, my_do_gw, &
1313 ext_scaling, a_scaling, tj, wj)
1314 END IF
1315
1316 ! This array is needed for RPA
1317 IF (.NOT. do_ri_sos_laplace_mp2) THEN
1318 ALLOCATE (trace_qomega(dimen_ri_red))
1319 END IF
1320
1321 IF (do_ri_sos_laplace_mp2 .AND. .NOT. do_im_time) THEN
1322 alpha = 1.0_dp
1323 ELSE IF (my_open_shell .OR. do_ri_sos_laplace_mp2) THEN
1324 alpha = 2.0_dp
1325 ELSE
1326 alpha = 4.0_dp
1327 END IF
1328 IF (my_do_gw) THEN
1329 CALL allocate_matrices_gw(vec_sigma_c_gw, color_rpa_group, dimen_nm_gw, &
1330 gw_corr_lev_occ, gw_corr_lev_virt, homo, &
1331 nmo, num_integ_group, num_integ_points, unit_nr, &
1332 gw_corr_lev_tot, num_fit_points, omega_max_fit, &
1333 do_minimax_quad, do_periodic, do_ri_sigma_x,.NOT. do_im_time, &
1334 first_cycle_periodic_correction, &
1335 a_scaling, eigenval, tj, vec_omega_fit_gw, vec_sigma_x_gw, &
1336 delta_corr, eigenval_last, eigenval_scf, vec_w_gw, &
1337 fm_mat_s_gw, fm_mat_s_gw_work, &
1338 para_env, mp2_env, kpoints, nkp, nkp_self_energy, &
1339 do_kpoints_cubic_rpa, do_kpoints_from_gamma)
1340
1341 IF (do_bse) THEN
1342
1343 CALL cp_fm_create(fm_mat_q_static_bse_gemm, fm_mat_q_gemm(1)%matrix_struct)
1344 CALL cp_fm_to_fm(fm_mat_q_gemm(1), fm_mat_q_static_bse_gemm)
1345 CALL cp_fm_set_all(fm_mat_q_static_bse_gemm, 0.0_dp)
1346
1347 END IF
1348
1349 END IF
1350
1351 IF (calc_forces .AND. .NOT. do_im_time) CALL rpa_grad_create(rpa_grad, fm_mat_q(1), &
1352 fm_mat_s, homo, virtual, mp2_env, eigenval(:, 1, :), &
1353 unit_nr, do_ri_sos_laplace_mp2)
1354 IF (.NOT. do_im_time .AND. .NOT. do_ri_sos_laplace_mp2) THEN
1355 CALL exchange_work%create(qs_env, para_env_sub, mat_munu, dimen_ri_red, &
1356 fm_mat_s, fm_mat_q(1), fm_mat_q_gemm(1), homo, virtual)
1357 END IF
1358 erpa = 0.0_dp
1359 IF (mp2_env%ri_rpa%exchange_correction /= rpa_exchange_none) e_exchange = 0.0_dp
1360 first_cycle = .true.
1361 omega_old = 0.0_dp
1362 CALL dgemm_counter_init(dgemm_counter, unit_nr, mp2_env%ri_rpa%print_dgemm_info)
1363
1364 DO count_ev_sc_gw = 1, iter_evgw
1365 dbcsr_time = 0.0_dp
1366 dbcsr_nflop = 0
1367
1368 IF (do_ic_model) cycle
1369
1370 ! reset some values, important when doing eigenvalue self-consistent GW
1371 IF (my_do_gw) THEN
1372 erpa = 0.0_dp
1373 vec_sigma_c_gw = z_zero
1374 first_cycle = .true.
1375 END IF
1376
1377 ! calculate Q_PQ(it)
1378 IF (do_im_time) THEN ! not using Imaginary time
1379
1380 IF (.NOT. do_kpoints_cubic_rpa) THEN
1381 DO ispin = 1, nspins
1382 e_fermi(ispin) = (eigenval(homo(ispin), 1, ispin) + eigenval(homo(ispin) + 1, 1, ispin))*0.5_dp
1383 END DO
1384 END IF
1385
1386 tau = 0.0_dp
1387 tau_old = 0.0_dp
1388
1389 IF (unit_nr > 0) WRITE (unit=unit_nr, fmt="(/T3,A,T66,i15)") &
1390 "MEMORY_INFO| Memory cut:", cut_memory
1391 IF (unit_nr > 0) WRITE (unit=unit_nr, fmt="(T3,A,T66,ES15.2)") &
1392 "SPARSITY_INFO| Eps filter for M virt/occ tensors:", eps_filter
1393 IF (unit_nr > 0) WRITE (unit=unit_nr, fmt="(T3,A,T66,ES15.2)") &
1394 "SPARSITY_INFO| Eps filter for P matrix:", eps_filter_im_time
1395 IF (unit_nr > 0) WRITE (unit=unit_nr, fmt="(T3,A,T66,i15)") &
1396 "SPARSITY_INFO| Minimum tensor block size:", min_bsize
1397
1398 ! for evGW, we have to ensure that mat_P_omega is zero
1399 CALL zero_mat_p_omega(mat_p_omega(:, :, 1))
1400
1401 ! compute the matrix Q(it) and Fourier transform it directly to mat_P_omega(iw)
1402 CALL compute_mat_p_omega(mat_p_omega(:, :, 1), fm_scaled_dm_occ_tau, &
1403 fm_scaled_dm_virt_tau, fm_mo_coeff_occ(1), fm_mo_coeff_virt(1), &
1404 fm_mo_coeff_occ_scaled, fm_mo_coeff_virt_scaled, &
1405 mat_p_global, matrix_s, 1, &
1406 t_3c_m, t_3c_o, t_3c_o_compressed, t_3c_o_ind, &
1407 starts_array_mc, ends_array_mc, &
1408 starts_array_mc_block, ends_array_mc_block, &
1409 weights_cos_tf_t_to_w, tj, tau_tj, e_fermi(1), eps_filter, alpha, &
1410 eps_filter_im_time, eigenval(:, 1, 1), nmo, &
1411 num_integ_points, cut_memory, &
1412 unit_nr, mp2_env, para_env, &
1413 qs_env, do_kpoints_from_gamma, &
1414 index_to_cell_3c, cell_to_index_3c, &
1415 has_mat_p_blocks, do_ri_sos_laplace_mp2, &
1416 dbcsr_time, dbcsr_nflop)
1417
1418 ! the same for open shell, use fm_mo_coeff_occ_beta and fm_mo_coeff_virt_beta
1419 IF (my_open_shell) THEN
1420 CALL zero_mat_p_omega(mat_p_omega(:, :, 2))
1421 CALL compute_mat_p_omega(mat_p_omega(:, :, 2), fm_scaled_dm_occ_tau, &
1422 fm_scaled_dm_virt_tau, fm_mo_coeff_occ(2), &
1423 fm_mo_coeff_virt(2), &
1424 fm_mo_coeff_occ_scaled, fm_mo_coeff_virt_scaled, &
1425 mat_p_global, matrix_s, 2, &
1426 t_3c_m, t_3c_o, t_3c_o_compressed, t_3c_o_ind, &
1427 starts_array_mc, ends_array_mc, &
1428 starts_array_mc_block, ends_array_mc_block, &
1429 weights_cos_tf_t_to_w, tj, tau_tj, e_fermi(2), eps_filter, alpha, &
1430 eps_filter_im_time, eigenval(:, 1, 2), nmo, &
1431 num_integ_points, cut_memory, &
1432 unit_nr, mp2_env, para_env, &
1433 qs_env, do_kpoints_from_gamma, &
1434 index_to_cell_3c, cell_to_index_3c, &
1435 has_mat_p_blocks, do_ri_sos_laplace_mp2, &
1436 dbcsr_time, dbcsr_nflop)
1437
1438 !For RPA, we sum up the P matrices. If no force needed, can clean-up the beta spin one
1439 IF (.NOT. do_ri_sos_laplace_mp2) THEN
1440 DO j = 1, SIZE(mat_p_omega, 2)
1441 DO i = 1, SIZE(mat_p_omega, 1)
1442 CALL dbcsr_add(mat_p_omega(i, j, 1)%matrix, mat_p_omega(i, j, 2)%matrix, 1.0_dp, 1.0_dp)
1443 IF (.NOT. calc_forces) CALL dbcsr_clear(mat_p_omega(i, j, 2)%matrix)
1444 END DO
1445 END DO
1446 END IF
1447 END IF ! my_open_shell
1448
1449 END IF ! do im time
1450
1451 IF (mp2_env%ri_rpa%sigma_param /= sigma_none) THEN
1452 CALL rpa_sigma_create(rpa_sigma, mp2_env%ri_rpa%sigma_param, fm_mat_q(1), unit_nr, para_env)
1453 END IF
1454
1455 DO jquad = 1, num_integ_points
1456 IF (modulo(jquad, num_integ_group) /= color_rpa_group) cycle
1457
1458 CALL timeset(routinen//"_RPA_matrix_operations", handle3)
1459
1460 IF (do_ri_sos_laplace_mp2) THEN
1461 omega = tau_tj(jquad)
1462 ELSE
1463 IF (do_minimax_quad) THEN
1464 omega = tj(jquad)
1465 ELSE
1466 omega = a_scaling/tan(tj(jquad))
1467 END IF
1468 END IF ! do_ri_sos_laplace_mp2
1469
1470 IF (do_im_time) THEN
1471 ! in case we do imag time, we already calculated fm_mat_Q by a Fourier transform from im. time
1472
1473 IF (.NOT. (do_kpoints_cubic_rpa .OR. do_kpoints_from_gamma)) THEN
1474
1475 DO ispin = 1, SIZE(mat_p_omega, 3)
1476 CALL contract_p_omega_with_mat_l(mat_p_omega(jquad, 1, ispin)%matrix, mat_l%matrix, mat_work, &
1477 eps_filter_im_time, fm_mat_work, dimen_ri, dimen_ri_red, &
1478 fm_mat_minv_l_kpoints(1, 1), fm_mat_q(ispin))
1479 END DO
1480 END IF
1481
1482 ELSE
1483 IF (unit_nr > 0) WRITE (unit=unit_nr, fmt="(T3, A, 1X, I3, 1X, A, 1X, I3)") &
1484 "INTEG_INFO| Started with Integration point", jquad, "of", num_integ_points
1485
1486 IF (first_cycle .AND. count_ev_sc_gw > 1) THEN
1487 IF (iter_sc_gw0 == 1) THEN
1488 DO ispin = 1, nspins
1489 CALL remove_scaling_factor_rpa(fm_mat_s(ispin), virtual(ispin), &
1490 eigenval_last(:, 1, ispin), homo(ispin), omega_old)
1491 END DO
1492 ELSE
1493 DO ispin = 1, nspins
1494 CALL remove_scaling_factor_rpa(fm_mat_s(ispin), virtual(ispin), &
1495 eigenval_scf(:, 1, ispin), homo(ispin), omega_old)
1496 END DO
1497 END IF
1498 END IF
1499
1500 IF (iter_sc_gw0 > 1) THEN
1501 DO ispin = 1, nspins
1502 CALL calc_mat_q(fm_mat_s(ispin), do_ri_sos_laplace_mp2, first_cycle, virtual(ispin), &
1503 eigenval_scf(:, 1, ispin), homo(ispin), omega, omega_old, jquad, mm_style, &
1504 dimen_ri_red, dimen_ia(ispin), alpha, fm_mat_q(ispin), &
1505 fm_mat_q_gemm(ispin), do_bse, fm_mat_q_static_bse_gemm, dgemm_counter, &
1506 num_integ_points, count_ev_sc_gw)
1507 END DO
1508
1509 ! For SOS-MP2 we need both matrices separately
1510 IF (.NOT. do_ri_sos_laplace_mp2) THEN
1511 DO ispin = 2, nspins
1512 CALL cp_fm_scale_and_add(alpha=1.0_dp, matrix_a=fm_mat_q(1), beta=1.0_dp, matrix_b=fm_mat_q(ispin))
1513 END DO
1514 END IF
1515 ELSE
1516 DO ispin = 1, nspins
1517 CALL calc_mat_q(fm_mat_s(ispin), do_ri_sos_laplace_mp2, first_cycle, virtual(ispin), &
1518 eigenval(:, 1, ispin), homo(ispin), omega, omega_old, jquad, mm_style, &
1519 dimen_ri_red, dimen_ia(ispin), alpha, fm_mat_q(ispin), &
1520 fm_mat_q_gemm(ispin), do_bse, fm_mat_q_static_bse_gemm, dgemm_counter, &
1521 num_integ_points, count_ev_sc_gw)
1522 END DO
1523 ! For open-shell BSE: the static screened-Coulomb polarizability is the
1524 ! sum over both spin channels. calc_mat_Q overwrites fm_mat_Q_static_bse_gemm
1525 ! per spin, so rebuild it here as the explicit spin sum at omega=0.
1526 IF (do_bse .AND. nspins > 1 .AND. jquad == num_integ_points .AND. &
1527 count_ev_sc_gw == 1) THEN
1528 CALL cp_fm_set_all(fm_mat_q_static_bse_gemm, 0.0_dp)
1529 DO ispin = 1, nspins
1530 CALL cp_fm_scale_and_add(1.0_dp, fm_mat_q_static_bse_gemm, &
1531 1.0_dp, fm_mat_q_gemm(ispin))
1532 END DO
1533 END IF
1534
1535 ! For SOS-MP2 we need both matrices separately
1536 IF (.NOT. do_ri_sos_laplace_mp2) THEN
1537 DO ispin = 2, nspins
1538 CALL cp_fm_scale_and_add(alpha=1.0_dp, matrix_a=fm_mat_q(1), beta=1.0_dp, matrix_b=fm_mat_q(ispin))
1539 END DO
1540 END IF
1541
1542 END IF
1543
1544 END IF ! im time
1545
1546 ! Calculate RPA exchange energy correction
1547 IF (mp2_env%ri_rpa%exchange_correction /= rpa_exchange_none) THEN
1548 e_exchange_corr = 0.0_dp
1549 CALL exchange_work%compute(fm_mat_q(1), eigenval(:, 1, :), fm_mat_s, omega, e_exchange_corr, mp2_env)
1550
1551 ! Evaluate the final exchange energy correction
1552 e_exchange = e_exchange + e_exchange_corr*wj(jquad)
1553 END IF
1554
1555 ! for developing Sigma functional closed and open shell are taken cared for
1556 IF (mp2_env%ri_rpa%sigma_param /= sigma_none) THEN
1557 CALL rpa_sigma_matrix_spectral(rpa_sigma, fm_mat_q(1), wj(jquad), para_env_rpa)
1558 END IF
1559
1560 IF (do_ri_sos_laplace_mp2) THEN
1561
1562 CALL sos_mp2_postprocessing(fm_mat_q, erpa, tau_wj(jquad))
1563
1564 IF (calc_forces .AND. .NOT. do_im_time) CALL rpa_grad_matrix_operations(mp2_env, rpa_grad, do_ri_sos_laplace_mp2, &
1565 fm_mat_q, fm_mat_q_gemm, dgemm_counter, fm_mat_s, omega, homo, virtual, &
1566 eigenval(:, 1, :), tau_wj(jquad), unit_nr)
1567 ELSE
1568 IF (calc_forces .AND. .NOT. do_im_time) CALL rpa_grad_copy_q(fm_mat_q(1), rpa_grad)
1569
1570 CALL q_trace_and_add_unit_matrix(dimen_ri_red, trace_qomega, fm_mat_q(1))
1571
1572 IF (do_kpoints_cubic_rpa .OR. do_kpoints_from_gamma) THEN
1573 CALL invert_eps_compute_w_and_erpa_kp(dimen_ri, num_integ_points, jquad, nkp, count_ev_sc_gw, para_env, &
1574 erpa, tau_tj, tj, wj, weights_cos_tf_w_to_t, &
1575 wkp_w, do_gw_im_time, do_ri_sigma_x, do_kpoints_from_gamma, &
1576 cfm_mat_q, ikp_local, &
1577 mat_p_omega(:, :, 1), mat_p_omega_kp, qs_env, eps_filter_im_time, unit_nr, &
1578 kpoints, fm_mat_minv_l_kpoints, fm_mat_l_kpoints, &
1579 fm_mat_w, fm_mat_ri_global_work, mat_minvvminv, &
1580 fm_matrix_minv, fm_matrix_minv_vtrunc_minv)
1581 ELSE
1582 CALL compute_erpa_by_freq_int(dimen_ri_red, trace_qomega, fm_mat_q(1), para_env_rpa, erpa, wj(jquad))
1583 END IF
1584
1585 IF (calc_forces .AND. .NOT. do_im_time) CALL rpa_grad_matrix_operations(mp2_env, rpa_grad, do_ri_sos_laplace_mp2, &
1586 fm_mat_q, fm_mat_q_gemm, dgemm_counter, fm_mat_s, omega, homo, virtual, &
1587 eigenval(:, 1, :), wj(jquad), unit_nr)
1588 END IF ! do_ri_sos_laplace_mp2
1589
1590 ! save omega and reset the first_cycle flag
1591 first_cycle = .false.
1592 omega_old = omega
1593
1594 CALL timestop(handle3)
1595
1596 IF (my_do_gw) THEN
1597
1598 CALL get_fermi_level_offset(fermi_level_offset, fermi_level_offset_input, eigenval(:, 1, :), homo)
1599
1600 ! do_im_time = TRUE means low-scaling calculation
1601 IF (do_im_time) THEN
1602 ! only for molecules
1603 IF (.NOT. (do_kpoints_cubic_rpa .OR. do_kpoints_from_gamma)) THEN
1604 CALL compute_w_cubic_gw(fm_mat_w, fm_mat_q(1), fm_mat_work, dimen_ri, fm_mat_minv_l_kpoints, num_integ_points, &
1605 tj, tau_tj, weights_cos_tf_w_to_t, jquad, omega)
1606 END IF
1607 ELSE
1608 CALL compute_gw_self_energy(vec_sigma_c_gw, dimen_nm_gw, dimen_ri_red, gw_corr_lev_occ, &
1609 gw_corr_lev_virt, homo, jquad, nmo, num_fit_points, &
1610 do_im_time, do_periodic, first_cycle_periodic_correction, &
1611 fermi_level_offset, &
1612 omega, eigenval(:, 1, :), delta_corr, vec_omega_fit_gw, vec_w_gw, wj, &
1613 fm_mat_q(1), fm_mat_r_gw, fm_mat_s_gw, &
1614 fm_mat_s_gw_work, mo_coeff(1), para_env, &
1615 para_env_rpa, matrix_berry_im_mo_mo, matrix_berry_re_mo_mo, &
1616 kpoints, qs_env, mp2_env)
1617 END IF
1618 END IF
1619
1620 IF (unit_nr > 0) CALL m_flush(unit_nr)
1621 CALL para_env_rpa%sync() ! sync to see output
1622
1623 END DO ! jquad
1624
1625 IF (mp2_env%ri_rpa%sigma_param /= sigma_none) THEN
1626 CALL finalize_rpa_sigma(rpa_sigma, unit_nr, mp2_env%ri_rpa%e_sigma_corr, para_env, do_minimax_quad)
1627 IF (do_minimax_quad) mp2_env%ri_rpa%e_sigma_corr = mp2_env%ri_rpa%e_sigma_corr/2.0_dp
1628 CALL para_env%sum(mp2_env%ri_rpa%e_sigma_corr)
1629 END IF
1630
1631 CALL para_env%sum(erpa)
1632
1633 IF (.NOT. (do_ri_sos_laplace_mp2)) THEN
1634 erpa = erpa/(pi*2.0_dp)
1635 IF (do_minimax_quad) erpa = erpa/2.0_dp
1636 END IF
1637
1638 IF (mp2_env%ri_rpa%exchange_correction /= rpa_exchange_none) THEN
1639 CALL para_env%sum(e_exchange)
1640 e_exchange = e_exchange/(pi*2.0_dp)
1641 IF (do_minimax_quad) e_exchange = e_exchange/2.0_dp
1642 mp2_env%ri_rpa%ener_exchange = e_exchange
1643 END IF
1644
1645 IF (calc_forces .AND. do_ri_sos_laplace_mp2 .AND. do_im_time) THEN
1646 IF (my_open_shell) THEN
1647 pspin = 1
1648 qspin = 2
1649 CALL calc_laplace_loop_forces(force_data, mat_p_omega(:, 1, :), t_3c_m, t_3c_o(1, 1), &
1650 t_3c_o_compressed(1, 1, :), t_3c_o_ind(1, 1, :), fm_scaled_dm_occ_tau, &
1651 fm_scaled_dm_virt_tau, fm_mo_coeff_occ, fm_mo_coeff_virt, &
1652 fm_mo_coeff_occ_scaled, fm_mo_coeff_virt_scaled, &
1653 starts_array_mc, ends_array_mc, starts_array_mc_block, &
1654 ends_array_mc_block, num_integ_points, nmo, eigenval(:, 1, :), &
1655 tau_tj, tau_wj, cut_memory, pspin, qspin, my_open_shell, &
1656 unit_nr, dbcsr_time, dbcsr_nflop, mp2_env, qs_env)
1657 pspin = 2
1658 qspin = 1
1659 CALL calc_laplace_loop_forces(force_data, mat_p_omega(:, 1, :), t_3c_m, t_3c_o(1, 1), &
1660 t_3c_o_compressed(1, 1, :), t_3c_o_ind(1, 1, :), fm_scaled_dm_occ_tau, &
1661 fm_scaled_dm_virt_tau, fm_mo_coeff_occ, fm_mo_coeff_virt, &
1662 fm_mo_coeff_occ_scaled, fm_mo_coeff_virt_scaled, &
1663 starts_array_mc, ends_array_mc, starts_array_mc_block, &
1664 ends_array_mc_block, num_integ_points, nmo, eigenval(:, 1, :), &
1665 tau_tj, tau_wj, cut_memory, pspin, qspin, my_open_shell, &
1666 unit_nr, dbcsr_time, dbcsr_nflop, mp2_env, qs_env)
1667
1668 ELSE
1669 pspin = 1
1670 qspin = 1
1671 CALL calc_laplace_loop_forces(force_data, mat_p_omega(:, 1, :), t_3c_m, t_3c_o(1, 1), &
1672 t_3c_o_compressed(1, 1, :), t_3c_o_ind(1, 1, :), fm_scaled_dm_occ_tau, &
1673 fm_scaled_dm_virt_tau, fm_mo_coeff_occ, fm_mo_coeff_virt, &
1674 fm_mo_coeff_occ_scaled, fm_mo_coeff_virt_scaled, &
1675 starts_array_mc, ends_array_mc, starts_array_mc_block, &
1676 ends_array_mc_block, num_integ_points, nmo, eigenval(:, 1, :), &
1677 tau_tj, tau_wj, cut_memory, pspin, qspin, my_open_shell, &
1678 unit_nr, dbcsr_time, dbcsr_nflop, mp2_env, qs_env)
1679 END IF
1680 CALL calc_post_loop_forces(force_data, unit_nr, qs_env)
1681 END IF !laplace SOS-MP2
1682
1683 IF (calc_forces .AND. do_im_time .AND. .NOT. do_ri_sos_laplace_mp2) THEN
1684 DO ispin = 1, nspins
1685 CALL calc_rpa_loop_forces(force_data, mat_p_omega(:, 1, :), t_3c_m, t_3c_o(1, 1), &
1686 t_3c_o_compressed(1, 1, :), t_3c_o_ind(1, 1, :), fm_scaled_dm_occ_tau, &
1687 fm_scaled_dm_virt_tau, fm_mo_coeff_occ, fm_mo_coeff_virt, &
1688 fm_mo_coeff_occ_scaled, fm_mo_coeff_virt_scaled, &
1689 starts_array_mc, ends_array_mc, starts_array_mc_block, &
1690 ends_array_mc_block, num_integ_points, nmo, eigenval(:, 1, :), &
1691 e_fermi(ispin), weights_cos_tf_t_to_w, weights_cos_tf_w_to_t, tj, &
1692 wj, tau_tj, cut_memory, ispin, my_open_shell, unit_nr, dbcsr_time, &
1693 dbcsr_nflop, mp2_env, qs_env)
1694 END DO
1695 CALL calc_post_loop_forces(force_data, unit_nr, qs_env)
1696 END IF
1697
1698 IF (do_im_time) THEN
1699
1700 my_flop_rate = real(dbcsr_nflop, dp)/(1.0e09_dp*dbcsr_time)
1701 IF (unit_nr > 0) WRITE (unit=unit_nr, fmt="(/T3,A,T73,ES8.2)") &
1702 "PERFORMANCE| DBCSR total number of flops:", real(dbcsr_nflop*para_env%num_pe, dp)
1703 IF (unit_nr > 0) WRITE (unit=unit_nr, fmt="(T3,A,T66,F15.2)") &
1704 "PERFORMANCE| DBCSR total execution time:", dbcsr_time
1705 IF (unit_nr > 0) WRITE (unit=unit_nr, fmt="(T3,A,T66,F15.2)") &
1706 "PERFORMANCE| DBCSR flop rate (Gflops / MPI rank):", my_flop_rate
1707
1708 ELSE
1709
1710 CALL dgemm_counter_write(dgemm_counter, para_env)
1711
1712 END IF
1713
1714 ! GW: for low-scaling calculation: Compute self-energy Sigma(i*tau), Sigma(i*omega)
1715 ! for low-scaling and ordinary-scaling: analytic continuation from Sigma(iw) -> Sigma(w)
1716 ! and correction of quasiparticle energies e_n^GW
1717 IF (my_do_gw) THEN
1718
1719 CALL compute_qp_energies(vec_sigma_c_gw, count_ev_sc_gw, gw_corr_lev_occ, &
1720 gw_corr_lev_tot, gw_corr_lev_virt, homo, &
1721 nmo, num_fit_points, num_integ_points, &
1722 unit_nr, do_apply_ic_corr_to_gw, do_im_time, &
1723 do_periodic, do_ri_sigma_x, first_cycle_periodic_correction, &
1724 e_fermi, eps_filter, fermi_level_offset, &
1725 delta_corr, eigenval, &
1726 eigenval_last, eigenval_scf, iter_sc_gw0, exit_ev_gw, tau_tj, tj, &
1727 vec_omega_fit_gw, vec_sigma_x_gw, mp2_env%ri_g0w0%ic_corr_list, &
1728 weights_cos_tf_t_to_w, weights_sin_tf_t_to_w, &
1729 fm_mo_coeff_occ_scaled, fm_mo_coeff_virt_scaled, fm_mo_coeff_occ, &
1730 fm_mo_coeff_virt, fm_scaled_dm_occ_tau, fm_scaled_dm_virt_tau, &
1731 mo_coeff(1), fm_mat_w, para_env, para_env_rpa, mat_dm, mat_minvvminv, &
1732 t_3c_o, t_3c_m, t_3c_overl_int_ao_mo, t_3c_o_compressed, t_3c_o_mo_compressed, &
1733 t_3c_o_ind, t_3c_o_mo_ind, &
1734 t_3c_overl_int_gw_ri, t_3c_overl_int_gw_ao, &
1735 matrix_berry_im_mo_mo, matrix_berry_re_mo_mo, mat_w, matrix_s, &
1736 kpoints, mp2_env, qs_env, nkp_self_energy, do_kpoints_cubic_rpa, &
1737 starts_array_mc, ends_array_mc)
1738
1739 ! if HOMO-LUMO gap differs by less than mp2_env%ri_g0w0%eps_ev_sc_iter, exit ev sc GW loop
1740 IF (exit_ev_gw) EXIT
1741
1742 END IF ! my_do_gw if
1743
1744 END DO ! evGW loop
1745
1746 IF (do_ic_model) THEN
1747
1748 IF (my_open_shell) THEN
1749
1750 CALL calculate_ic_correction(eigenval(:, 1, 1), mat_minvvminv%matrix, &
1751 t_3c_overl_nnp_ic(1), t_3c_overl_nnp_ic_reflected(1), &
1752 gw_corr_lev_tot, &
1753 gw_corr_lev_occ(1), gw_corr_lev_virt(1), homo(1), unit_nr, &
1754 print_ic_values, para_env, do_alpha=.true.)
1755
1756 CALL calculate_ic_correction(eigenval(:, 1, 2), mat_minvvminv%matrix, &
1757 t_3c_overl_nnp_ic(2), t_3c_overl_nnp_ic_reflected(2), &
1758 gw_corr_lev_tot, &
1759 gw_corr_lev_occ(2), gw_corr_lev_virt(2), homo(2), unit_nr, &
1760 print_ic_values, para_env, do_beta=.true.)
1761
1762 ELSE
1763
1764 CALL calculate_ic_correction(eigenval(:, 1, 1), mat_minvvminv%matrix, &
1765 t_3c_overl_nnp_ic(1), t_3c_overl_nnp_ic_reflected(1), &
1766 gw_corr_lev_tot, &
1767 gw_corr_lev_occ(1), gw_corr_lev_virt(1), homo(1), unit_nr, &
1768 print_ic_values, para_env)
1769
1770 END IF
1771
1772 END IF
1773
1774 ! postprocessing after GW for Bethe-Salpeter
1775 IF (do_bse) THEN
1776 ! Check used GW flavor; in Case of evGW we use W0 for BSE
1777 ! Use environment variable, since local iter_evGW is overwritten if evGW0 is invoked
1778 IF (mp2_env%ri_g0w0%iter_evGW > 1) THEN
1779 IF (unit_nr > 0) THEN
1780 CALL cp_warn(__location__, &
1781 "BSE@evGW applies W0, i.e. screening with DFT energies to the BSE!")
1782 END IF
1783 END IF
1784 ! Create a per-spin copy of fm_mat_S for usage in BSE
1785 ALLOCATE (fm_mat_s_ia_bse(nspins))
1786 DO ispin = 1, nspins
1787 CALL cp_fm_create(fm_mat_s_ia_bse(ispin), fm_mat_s(ispin)%matrix_struct)
1788 CALL cp_fm_to_fm(fm_mat_s(ispin), fm_mat_s_ia_bse(ispin))
1789 ! Remove energy/frequency factor from 3c-Integral for BSE
1790 IF (iter_sc_gw0 == 1) THEN
1791 CALL remove_scaling_factor_rpa(fm_mat_s_ia_bse(ispin), virtual(ispin), &
1792 eigenval_last(:, 1, ispin), homo(ispin), omega)
1793 ELSE
1794 CALL remove_scaling_factor_rpa(fm_mat_s_ia_bse(ispin), virtual(ispin), &
1795 eigenval_scf(:, 1, ispin), homo(ispin), omega)
1796 END IF
1797 END DO
1798 ! Main routine for all BSE postprocessing
1799 CALL start_bse_calculation(fm_mat_s_ia_bse, fm_mat_s_ij_bse, fm_mat_s_ab_bse, &
1800 fm_mat_q_static_bse_gemm, &
1801 eigenval, eigenval_scf, &
1802 homo, virtual, dimen_ri, dimen_ri_red, bse_lev_virt, &
1803 gd_array, color_sub, mp2_env, qs_env, mo_coeff, unit_nr)
1804 ! Release per-spin BSE-copy of fm_mat_S
1805 DO ispin = 1, nspins
1806 CALL cp_fm_release(fm_mat_s_ia_bse(ispin))
1807 END DO
1808 DEALLOCATE (fm_mat_s_ia_bse)
1809 END IF
1810
1811 IF (my_do_gw) THEN
1812 CALL deallocate_matrices_gw(fm_mat_s_gw_work, vec_w_gw, vec_sigma_c_gw, vec_omega_fit_gw, &
1813 mp2_env%ri_g0w0%vec_Sigma_x_minus_vxc_gw, &
1814 eigenval_last, eigenval_scf, do_periodic, matrix_berry_re_mo_mo, matrix_berry_im_mo_mo, &
1815 kpoints, vec_sigma_x_gw,.NOT. do_im_time)
1816 END IF
1817
1818 IF (do_im_time) THEN
1819
1820 CALL dealloc_im_time(fm_mo_coeff_occ, fm_mo_coeff_virt, &
1821 fm_scaled_dm_occ_tau, fm_scaled_dm_virt_tau, index_to_cell_3c, &
1822 cell_to_index_3c, do_ic_model, &
1823 do_kpoints_cubic_rpa, do_kpoints_from_gamma, do_ri_sigma_x, &
1824 has_mat_p_blocks, &
1825 wkp_w, cfm_mat_q, fm_mat_minv_l_kpoints, fm_mat_l_kpoints, &
1826 fm_matrix_minv, fm_matrix_minv_vtrunc_minv, fm_mat_ri_global_work, fm_mat_work, &
1827 fm_mo_coeff_occ_scaled, fm_mo_coeff_virt_scaled, mat_dm, mat_l, &
1828 mat_minvvminv, mat_p_omega, mat_p_omega_kp, &
1829 t_3c_m, t_3c_o, t_3c_o_compressed, t_3c_o_ind, mat_work, qs_env)
1830
1831 IF (my_do_gw) THEN
1832 CALL deallocate_matrices_gw_im_time(weights_cos_tf_w_to_t, weights_sin_tf_t_to_w, do_ic_model, &
1833 do_kpoints_cubic_rpa, fm_mat_w, &
1834 t_3c_overl_int_ao_mo, t_3c_o_mo_compressed, t_3c_o_mo_ind, &
1835 t_3c_overl_int_gw_ri, t_3c_overl_int_gw_ao, &
1836 t_3c_overl_nnp_ic, t_3c_overl_nnp_ic_reflected, &
1837 mat_w, qs_env)
1838 END IF
1839
1840 END IF
1841
1842 IF (.NOT. do_im_time .AND. .NOT. do_ri_sos_laplace_mp2) CALL exchange_work%release()
1843
1844 IF (.NOT. do_ri_sos_laplace_mp2) THEN
1845 DEALLOCATE (tj)
1846 DEALLOCATE (wj)
1847 DEALLOCATE (trace_qomega)
1848 END IF
1849
1850 IF (do_im_time .OR. do_ri_sos_laplace_mp2) THEN
1851 DEALLOCATE (tau_tj)
1852 DEALLOCATE (tau_wj)
1853 END IF
1854
1855 IF (do_im_time .AND. calc_forces) THEN
1856 CALL im_time_force_release(force_data)
1857 END IF
1858
1859 IF (calc_forces .AND. .NOT. do_im_time) CALL rpa_grad_finalize(rpa_grad, mp2_env, para_env_sub, para_env, &
1860 qs_env, gd_array, color_sub, do_ri_sos_laplace_mp2, &
1861 homo, virtual)
1862
1863 CALL timestop(handle)
1864
1865 END SUBROUTINE rpa_num_int
1866
1867END MODULE rpa_main
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
collects all references to literature in CP2K as new algorithms / method are included from literature...
integer, save, public wilhelm2016b
integer, save, public delben2015
integer, save, public wilhelm2016a
integer, save, public wilhelm2018
integer, save, public delben2013
integer, save, public ren2013
integer, save, public wilhelm2017
integer, save, public ren2011
integer, save, public gruneis2009
integer, save, public freeman1977
integer, save, public bates2013
Main routines for GW + Bethe-Salpeter for computing electronic excitations.
Definition bse_main.F:14
subroutine, public start_bse_calculation(fm_mat_s_ia_bse, fm_mat_s_ij_bse, fm_mat_s_ab_bse, fm_mat_q_static_bse_gemm, eigenval, eigenval_scf, homo, virtual, dimen_ri, dimen_ri_red, bse_lev_virt, gd_array, color_sub, mp2_env, qs_env, mo_coeff, unit_nr)
Main subroutine managing BSE calculations.
Definition bse_main.F:90
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 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_clear(matrix)
...
subroutine, public dbcsr_add(matrix_a, matrix_b, alpha_scalar, beta_scalar)
...
Basic linear algebra operations for full matrices.
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....
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_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.
elemental subroutine, public dgemm_counter_init(dgemm_counter, unit_nr, print_info)
Initialize a dgemm_counter.
subroutine, public dgemm_counter_write(dgemm_counter, para_env)
calculate and print flop rates
Types to describe group distributions.
elemental integer function, public maxsize(this)
...
Types and set/get functions for HFX.
Definition hfx_types.F:16
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public rpa_exchange_none
integer, parameter, public sigma_none
integer, parameter, public rpa_exchange_sosex
integer, parameter, public wfc_mm_style_gemm
integer, parameter, public rpa_exchange_axk
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public int_8
Definition kinds.F:54
integer, parameter, public dp
Definition kinds.F:34
Types and basic routines needed for a kpoint calculation.
Machine interface based on Fortran 2003 and POSIX.
Definition machine.F:17
subroutine, public m_memory(mem)
Returns the total amount of memory [bytes] in use, if known, zero otherwise.
Definition machine.F:440
subroutine, public m_flush(lunit)
flushes units if the &GLOBAL flag is set accordingly
Definition machine.F:124
Definition of mathematical constants and functions.
real(kind=dp), parameter, public pi
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 the minimax coefficients in order to approximate 1/x as a sum over exponential ...
Definition minimax_exp.F:29
subroutine, public check_exp_minimax_range(k, rc, ierr)
Check that a minimax approximation is available for given input k, Rc. ierr == 0: everything ok ierr ...
Routines to calculate frequency and time grids (integration points and weights) for correlation metho...
Definition mp2_grids.F:14
subroutine, public get_minimax_grid(para_env, unit_nr, homo, eigenval, num_integ_points, do_im_time, do_ri_sos_laplace_mp2, do_print, tau_tj, tau_wj, qs_env, do_gw_im_time, do_kpoints_cubic_rpa, e_fermi, tj, wj, weights_cos_tf_t_to_w, weights_cos_tf_w_to_t, weights_sin_tf_t_to_w, regularization)
...
Definition mp2_grids.F:76
subroutine, public get_clenshaw_grid(para_env, para_env_rpa, unit_nr, homo, virtual, eigenval, num_integ_points, num_integ_group, color_rpa_group, fm_mat_s, my_do_gw, ext_scaling, a_scaling, tj, wj)
...
Definition mp2_grids.F:310
Routines to calculate MP2 energy with laplace approach.
Definition mp2_laplace.F:13
subroutine, public sos_mp2_postprocessing(fm_mat_q, erpa, tau_wjquad)
...
Definition mp2_laplace.F:81
Routines for calculating RI-MP2 gradients.
subroutine, public array2fm(mat2d, fm_struct, my_start_row, my_end_row, my_start_col, my_end_col, gd_row, gd_col, group_grid_2_mepos, ngroup_row, ngroup_col, fm_mat, integ_group_size, color_group, do_release_mat)
redistribute local part of array to fm
Types needed for MP2 calculations.
Definition mp2_types.F:14
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, 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.
Auxiliary routines needed for RPA-exchange given blacs_env to another.
subroutine, public rpa_exchange_needed_mem(mp2_env, homo, virtual, dimen_ri, para_env, mem_per_rank, mem_per_repl)
...
Routines to calculate RI-RPA and SOS-MP2 gradients.
Definition rpa_grad.F:13
subroutine, public rpa_grad_finalize(rpa_grad, mp2_env, para_env_sub, para_env, qs_env, gd_array, color_sub, do_ri_sos_laplace_mp2, homo, virtual)
...
Definition rpa_grad.F:2034
subroutine, public rpa_grad_copy_q(fm_mat_q, rpa_grad)
...
Definition rpa_grad.F:713
pure subroutine, public rpa_grad_needed_mem(homo, virtual, dimen_ri, mem_per_rank, mem_per_repl, do_ri_sos_laplace_mp2)
Calculates the necessary minimum memory for the Gradient code ion MiB.
Definition rpa_grad.F:122
subroutine, public rpa_grad_create(rpa_grad, fm_mat_q, fm_mat_s, homo, virtual, mp2_env, eigenval, unit_nr, do_ri_sos_laplace_mp2)
Creates the arrays of a rpa_grad_type.
Definition rpa_grad.F:168
subroutine, public rpa_grad_matrix_operations(mp2_env, rpa_grad, do_ri_sos_laplace_mp2, fm_mat_q, fm_mat_q_gemm, dgemm_counter, fm_mat_s, omega, homo, virtual, eigenval, weight, unit_nr)
...
Definition rpa_grad.F:738
Routines to calculate image charge corrections.
Definition rpa_gw_ic.F:13
subroutine, public calculate_ic_correction(eigenval, mat_sinvvsinv, t_3c_overl_nnp_ic, t_3c_overl_nnp_ic_reflected, gw_corr_lev_tot, gw_corr_lev_occ, gw_corr_lev_virt, homo, unit_nr, print_ic_values, para_env, do_alpha, do_beta)
...
Definition rpa_gw_ic.F:58
Routines treating GW and RPA calculations with kpoints.
subroutine, public invert_eps_compute_w_and_erpa_kp(dimen_ri, num_integ_points, jquad, nkp, count_ev_sc_gw, para_env, erpa, tau_tj, tj, wj, weights_cos_tf_w_to_t, wkp_w, do_gw_im_time, do_ri_sigma_x, do_kpoints_from_gamma, cfm_mat_q, ikp_local, mat_p_omega, mat_p_omega_kp, qs_env, eps_filter_im_time, unit_nr, kpoints, fm_mat_minv_l_kpoints, fm_matrix_l_kpoints, fm_mat_w, fm_mat_ri_global_work, mat_minvvminv, fm_matrix_minv, fm_matrix_minv_vtrunc_minv)
...
subroutine, public get_bandstruc_and_k_dependent_mos(qs_env, eigenval_kp)
...
Routines for GW, continuous development [Jan Wilhelm].
Definition rpa_gw.F:14
subroutine, public deallocate_matrices_gw(fm_mat_s_gw_work, vec_w_gw, vec_sigma_c_gw, vec_omega_fit_gw, vec_sigma_x_minus_vxc_gw, eigenval_last, eigenval_scf, do_periodic, matrix_berry_re_mo_mo, matrix_berry_im_mo_mo, kpoints, vec_sigma_x_gw, my_do_gw)
...
Definition rpa_gw.F:615
subroutine, public allocate_matrices_gw(vec_sigma_c_gw, color_rpa_group, dimen_nm_gw, gw_corr_lev_occ, gw_corr_lev_virt, homo, nmo, num_integ_group, num_integ_points, unit_nr, gw_corr_lev_tot, num_fit_points, omega_max_fit, do_minimax_quad, do_periodic, do_ri_sigma_x, my_do_gw, first_cycle_periodic_correction, a_scaling, eigenval, tj, vec_omega_fit_gw, vec_sigma_x_gw, delta_corr, eigenval_last, eigenval_scf, vec_w_gw, fm_mat_s_gw, fm_mat_s_gw_work, para_env, mp2_env, kpoints, nkp, nkp_self_energy, do_kpoints_cubic_rpa, do_kpoints_from_gamma)
...
Definition rpa_gw.F:350
subroutine, public compute_gw_self_energy(vec_sigma_c_gw, dimen_nm_gw, dimen_ri, gw_corr_lev_occ, gw_corr_lev_virt, homo, jquad, nmo, num_fit_points, do_im_time, do_periodic, first_cycle_periodic_correction, fermi_level_offset, omega, eigenval, delta_corr, vec_omega_fit_gw, vec_w_gw, wj, fm_mat_q, fm_mat_r_gw, fm_mat_s_gw, fm_mat_s_gw_work, mo_coeff, para_env, para_env_rpa, matrix_berry_im_mo_mo, matrix_berry_re_mo_mo, kpoints, qs_env, mp2_env)
...
Definition rpa_gw.F:809
subroutine, public get_fermi_level_offset(fermi_level_offset, fermi_level_offset_input, eigenval, homo)
...
Definition rpa_gw.F:913
subroutine, public allocate_matrices_gw_im_time(gw_corr_lev_occ, gw_corr_lev_virt, homo, nmo, num_integ_points, unit_nr, ri_blk_sizes, do_ic_model, para_env, fm_mat_w, fm_mat_q, mo_coeff, t_3c_overl_int_ao_mo, t_3c_o_mo_compressed, t_3c_o_mo_ind, t_3c_overl_int_gw_ri, t_3c_overl_int_gw_ao, starts_array_mc, ends_array_mc, t_3c_overl_nnp_ic, t_3c_overl_nnp_ic_reflected, matrix_s, mat_w, t_3c_overl_int, t_3c_o_compressed, t_3c_o_ind, qs_env)
...
Definition rpa_gw.F:204
subroutine, public deallocate_matrices_gw_im_time(weights_cos_tf_w_to_t, weights_sin_tf_t_to_w, do_ic_model, do_kpoints_cubic_rpa, fm_mat_w, t_3c_overl_int_ao_mo, t_3c_o_mo_compressed, t_3c_o_mo_ind, t_3c_overl_int_gw_ri, t_3c_overl_int_gw_ao, t_3c_overl_nnp_ic, t_3c_overl_nnp_ic_reflected, mat_w, qs_env)
...
Definition rpa_gw.F:690
subroutine, public compute_qp_energies(vec_sigma_c_gw, count_ev_sc_gw, gw_corr_lev_occ, gw_corr_lev_tot, gw_corr_lev_virt, homo, nmo, num_fit_points, num_integ_points, unit_nr, do_apply_ic_corr_to_gw, do_im_time, do_periodic, do_ri_sigma_x, first_cycle_periodic_correction, e_fermi, eps_filter, fermi_level_offset, delta_corr, eigenval, eigenval_last, eigenval_scf, iter_sc_gw0, exit_ev_gw, tau_tj, tj, vec_omega_fit_gw, vec_sigma_x_gw, ic_corr_list, weights_cos_tf_t_to_w, weights_sin_tf_t_to_w, fm_mo_coeff_occ_scaled, fm_mo_coeff_virt_scaled, fm_mo_coeff_occ, fm_mo_coeff_virt, fm_scaled_dm_occ_tau, fm_scaled_dm_virt_tau, mo_coeff, fm_mat_w, para_env, para_env_rpa, mat_dm, mat_minvvminv, t_3c_o, t_3c_m, t_3c_overl_int_ao_mo, t_3c_o_compressed, t_3c_o_mo_compressed, t_3c_o_ind, t_3c_o_mo_ind, t_3c_overl_int_gw_ri, t_3c_overl_int_gw_ao, matrix_berry_im_mo_mo, matrix_berry_re_mo_mo, mat_w, matrix_s, kpoints, mp2_env, qs_env, nkp_self_energy, do_kpoints_cubic_rpa, starts_array_mc, ends_array_mc)
...
Definition rpa_gw.F:1234
subroutine, public compute_w_cubic_gw(fm_mat_w, fm_mat_q, fm_mat_work, dimen_ri, fm_mat_l, num_integ_points, tj, tau_tj, weights_cos_tf_w_to_t, jquad, omega)
...
Definition rpa_gw.F:955
Routines needed for cubic-scaling RPA and SOS-Laplace-MP2 forces.
subroutine, public calc_laplace_loop_forces(force_data, mat_p_omega, t_3c_m, t_3c_o, t_3c_o_compressed, t_3c_o_ind, fm_scaled_dm_occ_tau, fm_scaled_dm_virt_tau, fm_mo_coeff_occ, fm_mo_coeff_virt, fm_mo_coeff_occ_scaled, fm_mo_coeff_virt_scaled, starts_array_mc, ends_array_mc, starts_array_mc_block, ends_array_mc_block, num_integ_points, nmo, eigenval, tau_tj, tau_wj, cut_memory, pspin, qspin, open_shell, unit_nr, dbcsr_time, dbcsr_nflop, mp2_env, qs_env)
Updates the cubic-scaling SOS-Laplace-MP2 contribution to the forces at each quadrature point.
subroutine, public calc_post_loop_forces(force_data, unit_nr, qs_env)
All the forces that can be calculated after the loop on the Laplace quaradture, using terms collected...
subroutine, public calc_rpa_loop_forces(force_data, mat_p_omega, t_3c_m, t_3c_o, t_3c_o_compressed, t_3c_o_ind, fm_scaled_dm_occ_tau, fm_scaled_dm_virt_tau, fm_mo_coeff_occ, fm_mo_coeff_virt, fm_mo_coeff_occ_scaled, fm_mo_coeff_virt_scaled, starts_array_mc, ends_array_mc, starts_array_mc_block, ends_array_mc_block, num_integ_points, nmo, eigenval, e_fermi, weights_cos_tf_t_to_w, weights_cos_tf_w_to_t, tj, wj, tau_tj, cut_memory, ispin, open_shell, unit_nr, dbcsr_time, dbcsr_nflop, mp2_env, qs_env)
Updates the cubic-scaling RPA contribution to the forces at each quadrature point....
subroutine, public keep_initial_quad(tj, wj, tau_tj, tau_wj, weights_cos_tf_t_to_w, weights_cos_tf_w_to_t, do_laplace, do_im_time, num_integ_points, unit_nr, qs_env)
Overwrites the "optimal" Laplace quadrature with that of the first step.
subroutine, public init_im_time_forces(force_data, fm_matrix_pq, t_3c_m, unit_nr, mp2_env, qs_env)
Initializes and pre-calculates all needed tensors for the forces.
Types needed for cubic-scaling RPA and SOS-Laplace-MP2 forces.
subroutine, public im_time_force_release(force_data)
Cleans everything up.
Routines for low-scaling RPA/GW with imaginary time.
Definition rpa_im_time.F:13
subroutine, public zero_mat_p_omega(mat_p_omega)
...
subroutine, public compute_mat_p_omega(mat_p_omega, fm_scaled_dm_occ_tau, fm_scaled_dm_virt_tau, fm_mo_coeff_occ, fm_mo_coeff_virt, fm_mo_coeff_occ_scaled, fm_mo_coeff_virt_scaled, mat_p_global, matrix_s, ispin, t_3c_m, t_3c_o, t_3c_o_compressed, t_3c_o_ind, starts_array_mc, ends_array_mc, starts_array_mc_block, ends_array_mc_block, weights_cos_tf_t_to_w, tj, tau_tj, e_fermi, eps_filter, alpha, eps_filter_im_time, eigenval, nmo, num_integ_points, cut_memory, unit_nr, mp2_env, para_env, qs_env, do_kpoints_from_gamma, index_to_cell_3c, cell_to_index_3c, has_mat_p_blocks, do_ri_sos_laplace_mp2, dbcsr_time, dbcsr_nflop)
...
Routines to calculate RI-RPA energy.
Definition rpa_main.F:17
subroutine, public rpa_ri_compute_en(qs_env, erpa, mp2_env, bib_c, bib_c_gw, bib_c_bse_ij, bib_c_bse_ab, para_env, para_env_sub, color_sub, gd_array, gd_b_virtual, gd_b_all, gd_b_occ_bse, gd_b_virt_bse, mo_coeff, fm_matrix_pq, fm_matrix_l_kpoints, fm_matrix_minv_l_kpoints, fm_matrix_minv, fm_matrix_minv_vtrunc_minv, kpoints, eigenval, nmo, homo, dimen_ri, dimen_ri_red, gw_corr_lev_occ, gw_corr_lev_virt, bse_lev_virt, unit_nr, do_ri_sos_laplace_mp2, my_do_gw, do_im_time, do_bse, matrix_s, mat_munu, mat_p_global, t_3c_m, t_3c_o, t_3c_o_compressed, t_3c_o_ind, starts_array_mc, ends_array_mc, starts_array_mc_block, ends_array_mc_block, calc_forces)
...
Definition rpa_main.F:190
Routines to calculate RI-RPA energy and Sigma correction to the RPA energies using the cubic spline b...
subroutine, public rpa_sigma_create(rpa_sigma, sigma_param, fm_mat_q, unit_nr, para_env)
... Collect the Q(w) (fm_mat_Q) matrix to create rpa_sigma a derived type variable....
subroutine, public finalize_rpa_sigma(rpa_sigma, unit_nr, e_sigma_corr, para_env, do_minimax_quad)
... Save the calculated value of E_c correction to the global variable and memory clean.
subroutine, public rpa_sigma_matrix_spectral(rpa_sigma, fm_mat_q, wj, para_env_rpa)
... Diagonalize and store the eigenvalues of fm_mat_Q in rpa_sigmasigma_eigenvalue.
Utility functions for RPA calculations.
Definition rpa_util.F:13
subroutine, public compute_erpa_by_freq_int(dimen_ri, trace_qomega, fm_mat_q, para_env_rpa, erpa, wjquad)
...
Definition rpa_util.F:929
subroutine, public alloc_im_time(qs_env, para_env, dimen_ri, dimen_ri_red, num_integ_points, nspins, fm_mat_q, fm_mo_coeff_occ, fm_mo_coeff_virt, fm_matrix_minv_l_kpoints, fm_matrix_l_kpoints, 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, fm_mat_minv_l_kpoints, fm_mat_l_kpoints, fm_mat_ri_global_work, fm_mat_work, fm_mo_coeff_occ_scaled, fm_mo_coeff_virt_scaled, 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, fm_scaled_dm_occ_tau, fm_scaled_dm_virt_tau, homo, nmo)
...
Definition rpa_util.F:147
subroutine, public dealloc_im_time(fm_mo_coeff_occ, fm_mo_coeff_virt, fm_scaled_dm_occ_tau, fm_scaled_dm_virt_tau, 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, fm_mat_minv_l_kpoints, fm_mat_l_kpoints, fm_matrix_minv, fm_matrix_minv_vtrunc_minv, fm_mat_ri_global_work, fm_mat_work, fm_mo_coeff_occ_scaled, fm_mo_coeff_virt_scaled, 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:1116
subroutine, public q_trace_and_add_unit_matrix(dimen_ri, trace_qomega, fm_mat_q)
...
Definition rpa_util.F:878
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:661
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:1266
subroutine, public remove_scaling_factor_rpa(fm_mat_s, virtual, eigenval_last, homo, omega_old)
...
Definition rpa_util.F:711
All kind of helpful little routines.
Definition util.F:14
pure integer function, dimension(2), public get_limit(m, n, me)
divide m entries into n parts, return size of part me
Definition util.F:333
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