40 USE dbt_api,
ONLY: dbt_destroy,&
62#include "./base/base_uses.f90"
68 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'rpa_util'
130 SUBROUTINE alloc_im_time(qs_env, para_env, dimen_RI, dimen_RI_red, num_integ_points, nspins, &
131 fm_mat_Q, fm_mo_coeff_occ, fm_mo_coeff_virt, &
132 fm_matrix_Minv_L_kpoints, fm_matrix_L_kpoints, mat_P_global, &
133 t_3c_O, matrix_s, kpoints, eps_filter_im_time, &
134 cut_memory, nkp, num_cells_dm, num_3c_repl, &
139 do_ic_model, do_kpoints_cubic_RPA, &
140 do_kpoints_from_Gamma, do_ri_Sigma_x, my_open_shell, &
141 has_mat_P_blocks, wkp_W, &
142 cfm_mat_Q, fm_mat_Minv_L_kpoints, fm_mat_L_kpoints, &
143 fm_mat_RI_global_work, fm_mat_work, fm_mo_coeff_occ_scaled, &
144 fm_mo_coeff_virt_scaled, mat_dm, mat_L, mat_M_P_munu_occ, mat_M_P_munu_virt, &
145 mat_MinvVMinv, mat_P_omega, mat_P_omega_kp, &
146 mat_work, mo_coeff, fm_scaled_dm_occ_tau, fm_scaled_dm_virt_tau, homo, nmo)
150 INTEGER,
INTENT(IN) :: dimen_ri, dimen_ri_red, &
151 num_integ_points, nspins
153 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_mo_coeff_occ, fm_mo_coeff_virt
154 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: fm_matrix_minv_l_kpoints, &
157 TYPE(dbt_type),
ALLOCATABLE,
DIMENSION(:, :), &
158 INTENT(INOUT) :: t_3c_o
161 REAL(kind=
dp),
INTENT(IN) :: eps_filter_im_time
162 INTEGER,
INTENT(IN) :: cut_memory
163 INTEGER,
INTENT(OUT) :: nkp, num_cells_dm, num_3c_repl, size_p, &
165 INTEGER,
ALLOCATABLE,
DIMENSION(:, :),
INTENT(OUT) :: index_to_cell_3c
166 INTEGER,
ALLOCATABLE,
DIMENSION(:, :, :), &
167 INTENT(OUT) :: cell_to_index_3c
168 INTEGER,
DIMENSION(:),
POINTER :: col_blk_size
169 LOGICAL,
INTENT(IN) :: do_ic_model, do_kpoints_cubic_rpa, &
170 do_kpoints_from_gamma, do_ri_sigma_x, &
172 LOGICAL,
ALLOCATABLE,
DIMENSION(:, :, :, :, :), &
173 INTENT(OUT) :: has_mat_p_blocks
174 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:), &
177 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: fm_mat_minv_l_kpoints, fm_mat_l_kpoints
178 TYPE(
cp_fm_type),
INTENT(OUT) :: fm_mat_ri_global_work, fm_mat_work, &
179 fm_mo_coeff_occ_scaled, &
180 fm_mo_coeff_virt_scaled
181 TYPE(
dbcsr_p_type),
INTENT(OUT) :: mat_dm, mat_l, mat_m_p_munu_occ, &
182 mat_m_p_munu_virt, mat_minvvminv
184 DIMENSION(:, :, :) :: mat_p_omega
185 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: mat_p_omega_kp
187 TYPE(
cp_fm_type),
DIMENSION(:),
INTENT(IN) :: mo_coeff
188 TYPE(
cp_fm_type),
INTENT(OUT) :: fm_scaled_dm_occ_tau, &
189 fm_scaled_dm_virt_tau
190 INTEGER,
DIMENSION(:),
INTENT(IN) :: homo
191 INTEGER,
INTENT(IN) :: nmo
193 CHARACTER(LEN=*),
PARAMETER :: routinen =
'alloc_im_time'
195 INTEGER :: cell_grid_dm(3), first_ikp_local, &
196 handle, i_dim, i_kp, ispin, jquad, &
197 nspins_p_omega, periodic(3)
198 INTEGER,
DIMENSION(:),
POINTER :: row_blk_size
199 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: wkp_v
203 CALL timeset(routinen, handle)
205 ALLOCATE (fm_mo_coeff_occ(nspins), fm_mo_coeff_virt(nspins))
207 CALL cp_fm_create(fm_scaled_dm_occ_tau, mo_coeff(1)%matrix_struct)
210 CALL cp_fm_create(fm_scaled_dm_virt_tau, mo_coeff(1)%matrix_struct)
213 DO ispin = 1,
SIZE(mo_coeff)
214 CALL create_occ_virt_mo_coeffs(fm_mo_coeff_occ(ispin), fm_mo_coeff_virt(ispin), mo_coeff(ispin), &
218 num_3c_repl =
SIZE(t_3c_o, 2)
220 IF (do_kpoints_cubic_rpa)
THEN
224 cell_grid_dm(i_dim) = (kpoints%nkp_grid(i_dim)/2)*2 - 1
226 num_cells_dm = cell_grid_dm(1)*cell_grid_dm(2)*cell_grid_dm(3)
227 ALLOCATE (index_to_cell_3c(3,
SIZE(kpoints%index_to_cell, 2)))
228 cpassert(
SIZE(kpoints%index_to_cell, 1) == 3)
229 index_to_cell_3c(:, :) = kpoints%index_to_cell(:, :)
230 ALLOCATE (cell_to_index_3c(lbound(kpoints%cell_to_index, 1):ubound(kpoints%cell_to_index, 1), &
231 lbound(kpoints%cell_to_index, 2):ubound(kpoints%cell_to_index, 2), &
232 lbound(kpoints%cell_to_index, 3):ubound(kpoints%cell_to_index, 3)))
233 cell_to_index_3c(:, :, :) = kpoints%cell_to_index(:, :, :)
236 ALLOCATE (index_to_cell_3c(3, 1))
237 index_to_cell_3c(:, 1) = 0
238 ALLOCATE (cell_to_index_3c(0:0, 0:0, 0:0))
239 cell_to_index_3c(0, 0, 0) = 1
243 IF (do_kpoints_cubic_rpa .OR. do_kpoints_from_gamma)
THEN
245 CALL get_sub_para_kp(fm_struct_sub_kp, para_env, dimen_ri, ikp_local, first_ikp_local)
255 IF (do_kpoints_cubic_rpa .OR. do_kpoints_from_gamma)
THEN
259 CALL get_cell(cell=cell, periodic=periodic)
264 CALL compute_wkp_w(qs_env, wkp_w, wkp_v, kpoints, cell%h_inv, periodic)
271 IF (do_kpoints_cubic_rpa)
THEN
272 size_p = max(num_cells_dm/2 + 1, nkp)
273 ELSE IF (do_kpoints_from_gamma)
THEN
274 size_p = max(3**(periodic(1) + periodic(2) + periodic(3)), nkp)
280 IF (my_open_shell) nspins_p_omega = 2
282 ALLOCATE (mat_p_omega(num_integ_points, size_p, nspins_p_omega))
283 DO ispin = 1, nspins_p_omega
285 DO jquad = 1, num_integ_points
286 NULLIFY (mat_p_omega(jquad, i_kp, ispin)%matrix)
287 ALLOCATE (mat_p_omega(jquad, i_kp, ispin)%matrix)
288 CALL dbcsr_create(matrix=mat_p_omega(jquad, i_kp, ispin)%matrix, &
289 template=mat_p_global%matrix)
290 CALL dbcsr_set(mat_p_omega(jquad, i_kp, ispin)%matrix, 0.0_dp)
295 IF (do_kpoints_cubic_rpa .OR. do_kpoints_from_gamma)
THEN
296 CALL alloc_mat_p_omega(mat_p_omega_kp, 2, size_p, mat_p_global%matrix)
299 CALL cp_fm_create(fm_mo_coeff_occ_scaled, fm_mo_coeff_occ(1)%matrix_struct)
300 CALL cp_fm_to_fm(fm_mo_coeff_occ(1), fm_mo_coeff_occ_scaled)
301 CALL cp_fm_set_all(matrix=fm_mo_coeff_occ_scaled, alpha=0.0_dp)
303 CALL cp_fm_create(fm_mo_coeff_virt_scaled, fm_mo_coeff_virt(1)%matrix_struct)
304 CALL cp_fm_to_fm(fm_mo_coeff_virt(1), fm_mo_coeff_virt_scaled)
305 CALL cp_fm_set_all(matrix=fm_mo_coeff_virt_scaled, alpha=0.0_dp)
307 IF (do_kpoints_cubic_rpa .OR. do_kpoints_from_gamma)
THEN
308 CALL cp_fm_create(fm_mat_ri_global_work, fm_matrix_minv_l_kpoints(1, 1)%matrix_struct)
309 CALL cp_fm_to_fm(fm_matrix_minv_l_kpoints(1, 1), fm_mat_ri_global_work)
313 ALLOCATE (has_mat_p_blocks(num_cells_dm/2 + 1, cut_memory, cut_memory, num_3c_repl, num_3c_repl))
314 has_mat_p_blocks = .true.
316 IF (do_kpoints_cubic_rpa .OR. do_kpoints_from_gamma)
THEN
317 CALL reorder_mat_l(fm_mat_minv_l_kpoints, fm_matrix_minv_l_kpoints, fm_mat_q%matrix_struct, para_env, mat_l, &
318 mat_p_global%matrix, dimen_ri, dimen_ri_red, first_ikp_local, ikp_local, fm_struct_sub_kp, &
319 allocate_mat_l=.false.)
321 CALL reorder_mat_l(fm_mat_l_kpoints, fm_matrix_l_kpoints, fm_mat_q%matrix_struct, para_env, mat_l, &
322 mat_p_global%matrix, dimen_ri, dimen_ri_red, first_ikp_local, ikp_local, fm_struct_sub_kp)
327 CALL reorder_mat_l(fm_mat_minv_l_kpoints, fm_matrix_minv_l_kpoints, fm_mat_q%matrix_struct, para_env, mat_l, &
328 mat_p_global%matrix, dimen_ri, dimen_ri_red, first_ikp_local)
332 IF (dimen_ri == dimen_ri_red)
THEN
340 ncol_global=dimen_ri_red, nrow_global=dimen_ri)
350 IF (.NOT. (do_kpoints_cubic_rpa .OR. do_kpoints_from_gamma))
THEN
351 CALL dbcsr_get_info(mat_l%matrix, col_blk_size=col_blk_size, row_blk_size=row_blk_size)
356 CALL dbcsr_create(mat_work, template=mat_l%matrix, row_blk_size=col_blk_size, col_blk_size=row_blk_size)
359 IF (do_ri_sigma_x .OR. do_ic_model)
THEN
361 NULLIFY (mat_minvvminv%matrix)
362 ALLOCATE (mat_minvvminv%matrix)
363 CALL dbcsr_create(mat_minvvminv%matrix, template=mat_p_global%matrix)
364 CALL dbcsr_set(mat_minvvminv%matrix, 0.0_dp)
367 IF (.NOT. do_kpoints_from_gamma)
THEN
370 CALL dbcsr_multiply(
"T",
"N", 1.0_dp, mat_l%matrix, mat_l%matrix, &
371 0.0_dp, mat_minvvminv%matrix, filter_eps=eps_filter_im_time)
377 IF (do_ri_sigma_x)
THEN
379 NULLIFY (mat_dm%matrix)
380 ALLOCATE (mat_dm%matrix)
381 CALL dbcsr_create(mat_dm%matrix, template=matrix_s(1)%matrix)
385 CALL timestop(handle)
397 SUBROUTINE create_occ_virt_mo_coeffs(fm_mo_coeff_occ, fm_mo_coeff_virt, mo_coeff, &
400 TYPE(
cp_fm_type),
INTENT(OUT) :: fm_mo_coeff_occ, fm_mo_coeff_virt
402 INTEGER,
INTENT(IN) :: nmo, homo
404 CHARACTER(LEN=*),
PARAMETER :: routinen =
'create_occ_virt_mo_coeffs'
406 INTEGER :: handle, icol_global, irow_global
408 CALL timeset(routinen, handle)
410 CALL cp_fm_create(fm_mo_coeff_occ, mo_coeff%matrix_struct)
415 DO irow_global = 1, nmo
416 DO icol_global = homo + 1, nmo
421 CALL cp_fm_create(fm_mo_coeff_virt, mo_coeff%matrix_struct)
426 DO irow_global = 1, nmo
427 DO icol_global = 1, homo
432 CALL timestop(handle)
434 END SUBROUTINE create_occ_virt_mo_coeffs
443 SUBROUTINE alloc_mat_p_omega(mat_P_omega, num_integ_points, size_P, template)
444 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: mat_p_omega
445 INTEGER,
INTENT(IN) :: num_integ_points, size_p
448 CHARACTER(LEN=*),
PARAMETER :: routinen =
'alloc_mat_P_omega'
450 INTEGER :: handle, i_kp, jquad
452 CALL timeset(routinen, handle)
454 NULLIFY (mat_p_omega)
457 DO jquad = 1, num_integ_points
458 ALLOCATE (mat_p_omega(jquad, i_kp)%matrix)
459 CALL dbcsr_create(matrix=mat_p_omega(jquad, i_kp)%matrix, &
461 CALL dbcsr_set(mat_p_omega(jquad, i_kp)%matrix, 0.0_dp)
465 CALL timestop(handle)
467 END SUBROUTINE alloc_mat_p_omega
484 SUBROUTINE reorder_mat_l(fm_mat_L, fm_matrix_Minv_L_kpoints, fm_struct_template, para_env, mat_L, mat_template, &
485 dimen_RI, dimen_RI_red, first_ikp_local, ikp_local, fm_struct_sub_kp, allocate_mat_L)
486 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: fm_mat_l, fm_matrix_minv_l_kpoints
491 INTEGER,
INTENT(IN) :: dimen_ri, dimen_ri_red, first_ikp_local
492 INTEGER,
OPTIONAL :: ikp_local
494 LOGICAL,
INTENT(IN),
OPTIONAL :: allocate_mat_l
496 CHARACTER(LEN=*),
PARAMETER :: routinen =
'reorder_mat_L'
498 INTEGER :: handle, ikp, j_size, nblk
499 INTEGER,
DIMENSION(:),
POINTER :: col_blk_size, row_blk_size
500 LOGICAL :: do_kpoints, my_allocate_mat_l
503 TYPE(
cp_fm_type) :: fm_mat_l_transposed, fmdummy
505 CALL timeset(routinen, handle)
508 IF (
PRESENT(ikp_local) .AND.
PRESENT(fm_struct_sub_kp))
THEN
514 IF (dimen_ri == dimen_ri_red)
THEN
515 fm_struct => fm_struct_template
518 CALL cp_fm_struct_create(fm_struct, nrow_global=dimen_ri_red, ncol_global=dimen_ri, template_fmstruct=fm_struct_template)
522 ALLOCATE (fm_mat_l(
SIZE(fm_matrix_minv_l_kpoints, 1),
SIZE(fm_matrix_minv_l_kpoints, 2)))
523 DO ikp = 1,
SIZE(fm_matrix_minv_l_kpoints, 1)
524 DO j_size = 1,
SIZE(fm_matrix_minv_l_kpoints, 2)
526 IF (ikp == first_ikp_local .OR. ikp_local == -1)
THEN
527 CALL cp_fm_create(fm_mat_l(ikp, j_size), fm_struct_sub_kp)
538 IF (dimen_ri == dimen_ri_red)
THEN
539 fm_struct => fm_mat_l(first_ikp_local, 1)%matrix_struct
546 template_fmstruct=fm_mat_l(first_ikp_local, 1)%matrix_struct)
560 DO ikp = 1,
SIZE(fm_matrix_minv_l_kpoints, 1)
561 DO j_size = 1,
SIZE(fm_matrix_minv_l_kpoints, 2)
563 IF (ikp_local == ikp .OR. ikp_local == -1)
THEN
564 CALL cp_fm_copy_general(fm_matrix_minv_l_kpoints(ikp, j_size), fm_mat_l_transposed, para_env)
565 CALL cp_fm_to_fm(fm_mat_l_transposed, fm_mat_l(ikp, j_size))
570 CALL cp_fm_copy_general(fm_matrix_minv_l_kpoints(ikp, j_size), fm_mat_l_transposed, blacs_env%para_env)
581 my_allocate_mat_l = .true.
582 IF (
PRESENT(allocate_mat_l)) my_allocate_mat_l = allocate_mat_l
584 IF (my_allocate_mat_l)
THEN
586 NULLIFY (mat_l%matrix)
587 ALLOCATE (mat_l%matrix)
588 IF (dimen_ri == dimen_ri_red)
THEN
591 CALL dbcsr_get_info(mat_template, nblkrows_total=nblk, col_blk_size=col_blk_size)
593 CALL calculate_equal_blk_size(row_blk_size, dimen_ri_red, nblk)
595 CALL dbcsr_create(mat_l%matrix, template=mat_template, row_blk_size=row_blk_size, col_blk_size=col_blk_size)
597 DEALLOCATE (row_blk_size)
600 IF (.NOT. (do_kpoints))
THEN
606 CALL timestop(handle)
608 END SUBROUTINE reorder_mat_l
616 SUBROUTINE calculate_equal_blk_size(blk_size_new, dimen_RI_red, nblk)
617 INTEGER,
DIMENSION(:),
POINTER :: blk_size_new
618 INTEGER,
INTENT(IN) :: dimen_ri_red, nblk
620 INTEGER :: col_per_blk, remainder
622 NULLIFY (blk_size_new)
623 ALLOCATE (blk_size_new(nblk))
625 remainder = mod(dimen_ri_red, nblk)
626 col_per_blk = dimen_ri_red/nblk
629 IF (remainder > 0) blk_size_new(1:remainder) = col_per_blk + 1
630 blk_size_new(remainder + 1:nblk) = col_per_blk
632 END SUBROUTINE calculate_equal_blk_size
657 SUBROUTINE calc_mat_q(fm_mat_S, do_ri_sos_laplace_mp2, first_cycle, virtual, &
658 Eigenval, homo, omega, omega_old, jquad, mm_style, dimen_RI, dimen_ia, alpha, fm_mat_Q, fm_mat_Q_gemm, &
659 do_bse, fm_mat_Q_static_bse_gemm, dgemm_counter, &
660 num_integ_points, count_ev_sc_GW)
662 LOGICAL,
INTENT(IN) :: do_ri_sos_laplace_mp2, first_cycle
663 INTEGER,
INTENT(IN) :: virtual
664 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: eigenval
665 INTEGER,
INTENT(IN) :: homo
666 REAL(kind=
dp),
INTENT(IN) :: omega, omega_old
667 INTEGER,
INTENT(IN) :: jquad, mm_style, dimen_ri, dimen_ia
668 REAL(kind=
dp),
INTENT(IN) :: alpha
669 TYPE(
cp_fm_type),
INTENT(IN) :: fm_mat_q, fm_mat_q_gemm
670 LOGICAL,
INTENT(IN) :: do_bse
671 TYPE(
cp_fm_type),
INTENT(IN) :: fm_mat_q_static_bse_gemm
673 INTEGER,
INTENT(IN) :: num_integ_points, count_ev_sc_gw
675 CHARACTER(LEN=*),
PARAMETER :: routinen =
'calc_mat_Q'
679 CALL timeset(routinen, handle)
681 IF (do_ri_sos_laplace_mp2)
THEN
686 homo, omega, omega_old)
689 CALL contract_s_to_q(mm_style, dimen_ri, dimen_ia, alpha, fm_mat_s, fm_mat_q_gemm, &
690 fm_mat_q, dgemm_counter)
695 IF (do_bse .AND. jquad == num_integ_points .AND. count_ev_sc_gw == 1)
THEN
696 CALL cp_fm_to_fm(fm_mat_q_gemm, fm_mat_q_static_bse_gemm)
698 CALL timestop(handle)
712 INTEGER,
INTENT(IN) :: virtual
713 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: eigenval_last
714 INTEGER,
INTENT(IN) :: homo
715 REAL(kind=
dp),
INTENT(IN) :: omega_old
717 CHARACTER(LEN=*),
PARAMETER :: routinen =
'remove_scaling_factor_rpa'
719 INTEGER :: avirt, handle, i_global, iib, iocc, &
721 INTEGER,
DIMENSION(:),
POINTER :: col_indices
722 REAL(kind=
dp) :: eigen_diff
724 CALL timeset(routinen, handle)
728 ncol_local=ncol_local, &
729 col_indices=col_indices)
733 DO iib = 1, ncol_local
734 i_global = col_indices(iib)
736 iocc = max(1, i_global - 1)/virtual + 1
737 avirt = i_global - (iocc - 1)*virtual
738 eigen_diff = eigenval_last(avirt + homo) - eigenval_last(iocc)
740 fm_mat_s%local_data(:, iib) = fm_mat_s%local_data(:, iib)/ &
741 sqrt(eigen_diff/(eigen_diff**2 + omega_old**2))
745 CALL timestop(handle)
762 LOGICAL,
INTENT(IN) :: first_cycle
763 INTEGER,
INTENT(IN) :: virtual
764 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: eigenval
765 INTEGER,
INTENT(IN) :: homo
766 REAL(kind=
dp),
INTENT(IN) :: omega, omega_old
768 CHARACTER(LEN=*),
PARAMETER :: routinen =
'calc_fm_mat_S_rpa'
770 INTEGER :: avirt, handle, i_global, iib, iocc, &
772 INTEGER,
DIMENSION(:),
POINTER :: col_indices
773 REAL(kind=
dp) :: eigen_diff
775 CALL timeset(routinen, handle)
779 ncol_local=ncol_local, &
780 col_indices=col_indices)
783 IF (first_cycle)
THEN
788 DO iib = 1, ncol_local
789 i_global = col_indices(iib)
791 iocc = max(1, i_global - 1)/virtual + 1
792 avirt = i_global - (iocc - 1)*virtual
793 eigen_diff = eigenval(avirt + homo) - eigenval(iocc)
795 fm_mat_s%local_data(:, iib) = fm_mat_s%local_data(:, iib)* &
796 sqrt(eigen_diff/(eigen_diff**2 + omega**2))
804 DO iib = 1, ncol_local
805 i_global = col_indices(iib)
807 iocc = max(1, i_global - 1)/virtual + 1
808 avirt = i_global - (iocc - 1)*virtual
809 eigen_diff = eigenval(avirt + homo) - eigenval(iocc)
811 fm_mat_s%local_data(:, iib) = fm_mat_s%local_data(:, iib)* &
812 sqrt((eigen_diff**2 + omega_old**2)/(eigen_diff**2 + omega**2))
817 CALL timestop(handle)
832 SUBROUTINE contract_s_to_q(mm_style, dimen_RI, dimen_ia, alpha, fm_mat_S, fm_mat_Q_gemm, &
833 fm_mat_Q, dgemm_counter)
835 INTEGER,
INTENT(IN) :: mm_style, dimen_ri, dimen_ia
836 REAL(kind=
dp),
INTENT(IN) :: alpha
837 TYPE(
cp_fm_type),
INTENT(IN) :: fm_mat_s, fm_mat_q_gemm, fm_mat_q
840 CHARACTER(LEN=*),
PARAMETER :: routinen =
'contract_S_to_Q'
844 CALL timeset(routinen, handle)
847 SELECT CASE (mm_style)
850 CALL parallel_gemm(transa=
"N", transb=
"T", m=dimen_ri, n=dimen_ri, k=dimen_ia, alpha=alpha, &
851 matrix_a=fm_mat_s, matrix_b=fm_mat_s, beta=0.0_dp, &
852 matrix_c=fm_mat_q_gemm)
855 CALL cp_fm_syrk(uplo=
'U', trans=
'N', k=dimen_ia, alpha=alpha, matrix_a=fm_mat_s, &
856 ia=1, ja=1, beta=0.0_dp, matrix_c=fm_mat_q_gemm)
865 fm_mat_q_gemm%matrix_struct%context)
867 CALL timestop(handle)
869 END SUBROUTINE contract_s_to_q
879 INTEGER,
INTENT(IN) :: dimen_ri
880 REAL(kind=
dp),
DIMENSION(dimen_RI),
INTENT(OUT) :: trace_qomega
883 CHARACTER(LEN=*),
PARAMETER :: routinen =
'Q_trace_and_add_unit_matrix'
885 INTEGER :: handle, i_global, iib, j_global, jjb, &
886 ncol_local, nrow_local
887 INTEGER,
DIMENSION(:),
POINTER :: col_indices, row_indices
890 CALL timeset(routinen, handle)
893 nrow_local=nrow_local, &
894 ncol_local=ncol_local, &
895 row_indices=row_indices, &
896 col_indices=col_indices, &
900 trace_qomega = 0.0_dp
903 DO jjb = 1, ncol_local
904 j_global = col_indices(jjb)
905 DO iib = 1, nrow_local
906 i_global = row_indices(iib)
907 IF (j_global == i_global .AND. i_global <= dimen_ri)
THEN
908 trace_qomega(i_global) = fm_mat_q%local_data(iib, jjb)
909 fm_mat_q%local_data(iib, jjb) = fm_mat_q%local_data(iib, jjb) + 1.0_dp
913 CALL para_env%sum(trace_qomega)
915 CALL timestop(handle)
930 INTEGER,
INTENT(IN) :: dimen_ri
931 REAL(kind=
dp),
DIMENSION(dimen_RI),
INTENT(IN) :: trace_qomega
934 REAL(kind=
dp),
INTENT(INOUT) :: erpa
935 REAL(kind=
dp),
INTENT(IN) :: wjquad
937 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_Erpa_by_freq_int'
939 INTEGER :: handle, i_global, iib, info_chol, &
940 j_global, jjb, ncol_local, nrow_local
941 INTEGER,
DIMENSION(:),
POINTER :: col_indices, row_indices
942 REAL(kind=
dp) :: fcomega
943 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: q_log
945 CALL timeset(routinen, handle)
948 nrow_local=nrow_local, &
949 ncol_local=ncol_local, &
950 row_indices=row_indices, &
951 col_indices=col_indices)
955 IF (info_chol .NE. 0)
THEN
956 CALL cp_warn(__location__, &
957 "The Cholesky decomposition before inverting the RPA matrix / dielectric "// &
958 "function failed. "// &
959 "In case of low-scaling RPA/GW, decreasing EPS_FILTER in the &LOW_SCALING "// &
961 "increase the overall accuracy making the matrix positive definite. "// &
965 cpassert(info_chol == 0)
967 ALLOCATE (q_log(dimen_ri))
971 DO jjb = 1, ncol_local
972 j_global = col_indices(jjb)
973 DO iib = 1, nrow_local
974 i_global = row_indices(iib)
975 IF (j_global == i_global .AND. i_global <= dimen_ri)
THEN
976 q_log(i_global) = 2.0_dp*log(fm_mat_q%local_data(iib, jjb))
980 CALL para_env_rpa%sum(q_log)
986 IF (
modulo(iib, para_env_rpa%num_pe) /= para_env_rpa%mepos) cycle
987 fcomega = fcomega + (q_log(iib) - trace_qomega(iib))/2.0_dp
989 erpa = erpa + fcomega*wjquad
993 CALL timestop(handle)
1005 SUBROUTINE get_sub_para_kp(fm_struct_sub_kp, para_env, dimen_RI, &
1006 ikp_local, first_ikp_local)
1009 INTEGER,
INTENT(IN) :: dimen_ri
1010 INTEGER,
INTENT(OUT) :: ikp_local, first_ikp_local
1012 CHARACTER(len=*),
PARAMETER :: routinen =
'get_sub_para_kp'
1014 INTEGER :: color_sub_kp, handle, num_proc_per_kp
1018 CALL timeset(routinen, handle)
1023 num_proc_per_kp = para_env%num_pe
1031 color_sub_kp = para_env%mepos/num_proc_per_kp
1032 ALLOCATE (para_env_sub_kp)
1033 CALL para_env_sub_kp%from_split(para_env, color_sub_kp)
1038 NULLIFY (blacs_env_sub_kp)
1042 NULLIFY (fm_struct_sub_kp)
1043 CALL cp_fm_struct_create(fm_struct_sub_kp, context=blacs_env_sub_kp, nrow_global=dimen_ri, &
1044 ncol_global=dimen_ri, para_env=para_env_sub_kp)
1065 CALL timestop(handle)
1067 END SUBROUTINE get_sub_para_kp
1105 fm_scaled_dm_occ_tau, fm_scaled_dm_virt_tau, index_to_cell_3c, &
1106 cell_to_index_3c, do_ic_model, &
1107 do_kpoints_cubic_RPA, do_kpoints_from_Gamma, do_ri_Sigma_x, &
1109 wkp_W, cfm_mat_Q, fm_mat_Minv_L_kpoints, fm_mat_L_kpoints, &
1110 fm_matrix_Minv, fm_matrix_Minv_Vtrunc_Minv, &
1111 fm_mat_RI_global_work, fm_mat_work, &
1112 fm_mo_coeff_occ_scaled, fm_mo_coeff_virt_scaled, mat_dm, mat_L, &
1113 mat_MinvVMinv, mat_P_omega, mat_P_omega_kp, &
1114 t_3c_M, t_3c_O, t_3c_O_compressed, t_3c_O_ind, &
1117 TYPE(
cp_fm_type),
DIMENSION(:),
INTENT(INOUT) :: fm_mo_coeff_occ, fm_mo_coeff_virt
1118 TYPE(
cp_fm_type),
INTENT(INOUT) :: fm_scaled_dm_occ_tau, &
1119 fm_scaled_dm_virt_tau
1120 INTEGER,
ALLOCATABLE,
DIMENSION(:, :), &
1121 INTENT(INOUT) :: index_to_cell_3c
1122 INTEGER,
ALLOCATABLE,
DIMENSION(:, :, :), &
1123 INTENT(INOUT) :: cell_to_index_3c
1124 LOGICAL,
INTENT(IN) :: do_ic_model, do_kpoints_cubic_rpa, &
1125 do_kpoints_from_gamma, do_ri_sigma_x
1126 LOGICAL,
ALLOCATABLE,
DIMENSION(:, :, :, :, :), &
1127 INTENT(INOUT) :: has_mat_p_blocks
1128 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:), &
1129 INTENT(INOUT) :: wkp_w
1131 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: fm_mat_minv_l_kpoints, fm_mat_l_kpoints, &
1133 fm_matrix_minv_vtrunc_minv
1134 TYPE(
cp_fm_type),
INTENT(INOUT) :: fm_mat_ri_global_work, fm_mat_work, &
1135 fm_mo_coeff_occ_scaled, &
1136 fm_mo_coeff_virt_scaled
1137 TYPE(
dbcsr_p_type),
INTENT(INOUT) :: mat_dm, mat_l, mat_minvvminv
1139 DIMENSION(:, :, :),
INTENT(INOUT) :: mat_p_omega
1140 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: mat_p_omega_kp
1141 TYPE(dbt_type) :: t_3c_m
1142 TYPE(dbt_type),
ALLOCATABLE,
DIMENSION(:, :) :: t_3c_o
1144 DIMENSION(:, :, :),
INTENT(INOUT) :: t_3c_o_compressed
1146 DIMENSION(:, :, :),
INTENT(INOUT) :: t_3c_o_ind
1150 CHARACTER(LEN=*),
PARAMETER :: routinen =
'dealloc_im_time'
1152 INTEGER :: cut_memory, handle, i_kp, i_mem, i_size, &
1153 ispin, j_size, jquad, nspins, unused
1154 LOGICAL :: my_open_shell
1156 CALL timeset(routinen, handle)
1158 nspins =
SIZE(fm_mo_coeff_occ)
1159 my_open_shell = (nspins == 2)
1163 DO ispin = 1,
SIZE(fm_mo_coeff_occ)
1173 IF (do_kpoints_cubic_rpa .OR. do_kpoints_from_gamma)
THEN
1180 IF (.NOT. (do_kpoints_cubic_rpa .OR. do_kpoints_from_gamma))
THEN
1182 DEALLOCATE (mat_work)
1186 DEALLOCATE (mat_l%matrix)
1188 IF (do_ri_sigma_x .OR. do_ic_model)
THEN
1190 DEALLOCATE (mat_minvvminv%matrix)
1192 IF (do_ri_sigma_x)
THEN
1194 DEALLOCATE (mat_dm%matrix)
1197 DEALLOCATE (index_to_cell_3c, cell_to_index_3c)
1199 IF (
ALLOCATED(mat_p_omega))
THEN
1200 DO ispin = 1,
SIZE(mat_p_omega, 3)
1201 DO i_kp = 1,
SIZE(mat_p_omega, 2)
1202 DO jquad = 1,
SIZE(mat_p_omega, 1)
1207 DEALLOCATE (mat_p_omega)
1210 DO i_size = 1,
SIZE(t_3c_o, 1)
1211 DO j_size = 1,
SIZE(t_3c_o, 2)
1212 CALL dbt_destroy(t_3c_o(i_size, j_size))
1217 CALL dbt_destroy(t_3c_m)
1219 DEALLOCATE (has_mat_p_blocks)
1221 IF (do_kpoints_cubic_rpa .OR. do_kpoints_from_gamma)
THEN
1228 cut_memory =
SIZE(t_3c_o_compressed, 3)
1230 DEALLOCATE (t_3c_o_ind)
1231 DO i_size = 1,
SIZE(t_3c_o_compressed, 1)
1232 DO j_size = 1,
SIZE(t_3c_o_compressed, 2)
1233 DO i_mem = 1, cut_memory
1238 DEALLOCATE (t_3c_o_compressed)
1240 IF (do_kpoints_from_gamma)
THEN
1242 IF (qs_env%mp2_env%ri_g0w0%do_kpoints_Sigma)
THEN
1244 CALL kpoint_release(qs_env%mp2_env%ri_rpa_im_time%kpoints_Sigma_no_xc)
1248 CALL timestop(handle)
1265 dimen_RI_red, fm_mat_L, fm_mat_Q)
1267 TYPE(
dbcsr_type),
INTENT(IN) :: mat_p_omega, mat_l
1269 REAL(kind=
dp),
INTENT(IN) :: eps_filter_im_time
1270 TYPE(
cp_fm_type),
INTENT(INOUT) :: fm_mat_work
1271 INTEGER,
INTENT(IN) :: dimen_ri, dimen_ri_red
1272 TYPE(
cp_fm_type),
INTENT(IN) :: fm_mat_l, fm_mat_q
1274 CHARACTER(LEN=*),
PARAMETER :: routinen =
'contract_P_omega_with_mat_L'
1278 CALL timeset(routinen, handle)
1282 0.0_dp, mat_work, filter_eps=eps_filter_im_time)
1286 CALL parallel_gemm(
'N',
'N', dimen_ri_red, dimen_ri_red, dimen_ri, 1.0_dp, fm_mat_l, fm_mat_work, &
1293 CALL timestop(handle)
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
Handles all functions related to the CELL.
subroutine, public get_cell(cell, alpha, beta, gamma, deth, orthorhombic, abc, periodic, h, h_inv, symmetry_id, tag)
Get informations about a simulation cell.
methods related to the blacs parallel environment
subroutine, public cp_blacs_env_release(blacs_env)
releases the given blacs_env
subroutine, public cp_blacs_env_create(blacs_env, para_env, blacs_grid_layout, blacs_repeatable, row_major, grid_2d)
allocates and initializes a type that represent a blacs context
Represents a complex full matrix distributed on many processors.
subroutine, public cp_cfm_create(matrix, matrix_struct, name)
Creates a new full matrix with the given structure.
subroutine, public cp_cfm_release(matrix)
Releases a full matrix.
subroutine, public cp_cfm_set_all(matrix, alpha, beta)
Set all elements of the full matrix to alpha. Besides, set all diagonal matrix elements to beta (if g...
subroutine, public dbcsr_deallocate_matrix(matrix)
...
subroutine, public dbcsr_multiply(transa, transb, alpha, matrix_a, matrix_b, beta, matrix_c, first_row, last_row, first_column, last_column, first_k, last_k, retain_sparsity, filter_eps, flop)
...
subroutine, public dbcsr_get_info(matrix, nblkrows_total, nblkcols_total, nfullrows_total, nfullcols_total, nblkrows_local, nblkcols_local, nfullrows_local, nfullcols_local, my_prow, my_pcol, local_rows, local_cols, proc_row_dist, proc_col_dist, row_blk_size, col_blk_size, row_blk_offset, col_blk_offset, distribution, name, matrix_type, group)
...
subroutine, public dbcsr_filter(matrix, eps)
...
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_release(matrix)
...
DBCSR operations in CP2K.
subroutine, public copy_dbcsr_to_fm(matrix, fm)
Copy a DBCSR matrix to a BLACS matrix.
subroutine, public copy_fm_to_dbcsr(fm, matrix, keep_sparsity)
Copy a BLACS matrix to a dbcsr matrix.
basic linear algebra operations for full matrices
subroutine, public cp_fm_transpose(matrix, matrixt)
transposes a matrix matrixt = matrix ^ T
subroutine, public cp_fm_syrk(uplo, trans, k, alpha, matrix_a, ia, ja, beta, matrix_c)
performs a rank-k update of a symmetric matrix_c matrix_c = beta * matrix_c + alpha * matrix_a * tran...
various cholesky decomposition related routines
subroutine, public cp_fm_cholesky_decompose(matrix, n, info_out)
used to replace a symmetric positive def. matrix M with its cholesky decomposition U: M = U^T * U,...
represent the structure of a full matrix
subroutine, public cp_fm_struct_create(fmstruct, para_env, context, nrow_global, ncol_global, nrow_block, ncol_block, descriptor, first_p_pos, local_leading_dimension, template_fmstruct, square_blocks, force_block)
allocates and initializes a full matrix structure
subroutine, public cp_fm_struct_release(fmstruct)
releases a full matrix structure
represent a full matrix distributed on many processors
subroutine, public cp_fm_copy_general(source, destination, para_env)
General copy of a fm matrix to another fm matrix. Uses non-blocking MPI rather than ScaLAPACK.
subroutine, public cp_fm_get_info(matrix, name, nrow_global, ncol_global, nrow_block, ncol_block, nrow_local, ncol_local, row_indices, col_indices, local_data, context, nrow_locals, ncol_locals, matrix_struct, para_env)
returns all kind of information about the full matrix
subroutine, public cp_fm_to_fm_submat_general(source, destination, nrows, ncols, s_firstrow, s_firstcol, d_firstrow, d_firstcol, global_context)
General copy of a submatrix of fm matrix to a submatrix of another fm matrix. The two matrices can ha...
subroutine, public cp_fm_set_all(matrix, alpha, beta)
set all elements of a matrix to the same value, and optionally the diagonal to a different one
subroutine, public cp_fm_set_element(matrix, irow_global, icol_global, alpha)
sets an element of a matrix
subroutine, public cp_fm_create(matrix, matrix_struct, name, use_sp)
creates a new full matrix with the given structure
This is the start of a dbt_api, all publically needed functions are exported here....
Counters to determine the performance of parallel DGEMMs.
subroutine, public dgemm_counter_start(dgemm_counter)
start timer of the counter
subroutine, public dgemm_counter_stop(dgemm_counter, size1, size2, size3)
stop timer of the counter and provide matrix sizes
Types and set/get functions for HFX.
subroutine, public dealloc_containers(data, memory_usage)
...
Defines the basic variable types.
integer, parameter, public dp
Types and basic routines needed for a kpoint calculation.
subroutine, public kpoint_release(kpoint)
Release a kpoint environment, deallocate all data.
subroutine, public get_kpoint_info(kpoint, kp_scheme, nkp_grid, kp_shift, symmetry, verbose, full_grid, use_real_wfn, eps_geo, parallel_group_size, kp_range, nkp, xkp, wkp, para_env, blacs_env_all, para_env_kp, para_env_inter_kp, blacs_env, kp_env, kp_aux_env, mpools, iogrp, nkp_groups, kp_dist, cell_to_index, index_to_cell, sab_nl, sab_nl_nosym)
Retrieve information from a kpoint environment.
Definition of mathematical constants and functions.
complex(kind=dp), parameter, public z_zero
Interface to the message passing library MPI.
subroutine, public mp_para_env_release(para_env)
releases the para object (to be called when you don't want anymore the shared copy of this object)
Routines to calculate MP2 energy with laplace approach.
subroutine, public calc_fm_mat_s_laplace(fm_mat_s, homo, virtual, eigenval, dajquad)
...
basic linear algebra operations for full matrixes
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, ecoul_1c, rho0_s_rs, rho0_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs)
Get the QUICKSTEP environment.
Routines treating GW and RPA calculations with kpoints.
subroutine, public compute_wkp_w(qs_env, wkp_w, wkp_v, kpoints, h_inv, periodic)
...
Utility functions for RPA calculations.
subroutine, public compute_erpa_by_freq_int(dimen_ri, trace_qomega, fm_mat_q, para_env_rpa, erpa, wjquad)
...
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)
...
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)
...
subroutine, public q_trace_and_add_unit_matrix(dimen_ri, trace_qomega, fm_mat_q)
...
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)
...
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)
...
subroutine, public remove_scaling_factor_rpa(fm_mat_s, virtual, eigenval_last, homo, omega_old)
...
subroutine, public calc_fm_mat_s_rpa(fm_mat_s, first_cycle, virtual, eigenval, homo, omega, omega_old)
...
Type defining parameters related to the simulation cell.
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
Contains information about kpoints.
stores all the informations relevant to an mpi environment