30 dbcsr_type_no_symmetry
84#include "./base/base_uses.f90"
90 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'gw_large_cell_Gamma_ri_rs'
111 CHARACTER(LEN=*),
PARAMETER :: routinen =
'gw_calc_large_cell_Gamma_ri_rs'
114 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_sigma_x_gamma, fm_w_time
115 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :, :) :: fm_sigma_c_gamma_time
117 CALL timeset(routinen, handle)
141 CALL atomic_basis_at_grid_point(qs_env, bs_env, bs_env%ri_rs%grid_points, &
142 bs_env%ri_rs%mat_phi_mu_l)
157 CALL compute_coeff_z_lp(qs_env, bs_env, bs_env%ri_rs%grid_points, &
158 bs_env%ri_rs%mat_phi_mu_l, bs_env%ri_rs%mat_Z_lP)
159 bs_env%ri_rs%grid_built = .true.
170 CALL get_mat_chi_gamma_tau(bs_env, bs_env%mat_chi_Gamma_tau, &
171 bs_env%ri_rs%mat_phi_mu_l, bs_env%ri_rs%mat_Z_lP)
177 CALL get_w_mic(bs_env, qs_env, bs_env%mat_chi_Gamma_tau, fm_w_time)
187 CALL compute_sigma_x(bs_env, qs_env, bs_env%ri_rs%mat_phi_mu_l, &
188 bs_env%ri_rs%mat_Z_lP, fm_sigma_x_gamma)
197 CALL compute_sigma_c(bs_env, fm_w_time, bs_env%ri_rs%mat_phi_mu_l, &
198 bs_env%ri_rs%mat_Z_lP, fm_sigma_c_gamma_time)
209 CALL timestop(handle)
221 SUBROUTINE atomic_basis_at_grid_point(qs_env, bs_env, ri_rs_grid_points, mat_phi_mu_l)
225 REAL(kind=
dp),
ALLOCATABLE,
INTENT(INOUT) :: ri_rs_grid_points(:, :)
228 CHARACTER(LEN=*),
PARAMETER :: routinen =
'atomic_basis_at_grid_point'
230 INTEGER :: c_size, chunk_size, dimen_orb, handle, i, i_blk, iatom, natom, npcol, nprow, &
231 num_grid_chunks, r_end, r_start, total_grid_npts
232 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: first_sgf
233 INTEGER,
DIMENSION(:),
POINTER :: c_blk_sizes, col_dist, r_blk_sizes, &
235 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: atom_col_buffer
242 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
244 CALL timeset(routinen, handle)
250 CALL get_qs_env(qs_env, cell=cell, atomic_kind_set=atomic_kind_set, &
251 qs_kind_set=qs_kind_set, particle_set=particle_set, &
254 natom =
SIZE(particle_set)
255 total_grid_npts =
SIZE(ri_rs_grid_points, 2)
258 ALLOCATE (first_sgf(natom + 1))
266 ALLOCATE (c_blk_sizes(natom))
268 c_blk_sizes(iatom) = first_sgf(iatom + 1) - first_sgf(iatom)
272 num_grid_chunks = ceiling(real(total_grid_npts, kind=
dp)/real(chunk_size, kind=
dp))
273 ALLOCATE (r_blk_sizes(num_grid_chunks))
274 r_blk_sizes = chunk_size
275 IF (mod(total_grid_npts, chunk_size) /= 0)
THEN
276 r_blk_sizes(num_grid_chunks) = mod(total_grid_npts, chunk_size)
280 CALL get_qs_env(qs_env, dbcsr_dist=dbcsr_dist_ks)
285 ALLOCATE (row_dist(num_grid_chunks))
286 DO i = 1, num_grid_chunks
287 row_dist(i) = mod(i - 1, nprow)
290 ALLOCATE (col_dist(natom))
292 col_dist(i) = mod(i - 1, npcol)
297 row_dist=row_dist, col_dist=col_dist)
299 CALL dbcsr_create(mat_phi_mu_l, name=
"phi_val_sparse", dist=dist, &
300 matrix_type=dbcsr_type_no_symmetry, &
301 row_blk_size=r_blk_sizes, col_blk_size=c_blk_sizes)
307 DO iatom = para_env%mepos + 1, natom, para_env%num_pe
309 c_size = c_blk_sizes(iatom)
312 ALLOCATE (atom_col_buffer(total_grid_npts, c_size))
313 atom_col_buffer = 0.0_dp
318 CALL fill_phi_for_atom(atom_col_buffer, ri_rs_grid_points, total_grid_npts, &
319 iatom, particle_set, qs_kind_set, cell, &
320 r2_threshold=bs_env%ri_rs%radius_ao_per_atom(iatom)**2)
323 DO i_blk = 1, num_grid_chunks
324 r_start = (i_blk - 1)*chunk_size + 1
325 r_end = min(i_blk*chunk_size, total_grid_npts)
328 IF (maxval(abs(atom_col_buffer(r_start:r_end, 1:c_size))) > bs_env%eps_filter)
THEN
330 block=atom_col_buffer(r_start:r_end, 1:c_size))
334 DEALLOCATE (atom_col_buffer)
341 IF (bs_env%unit_nr > 0)
THEN
342 WRITE (bs_env%unit_nr, *)
"Done with evaluation of phi"
348 DEALLOCATE (first_sgf, r_blk_sizes, c_blk_sizes, row_dist, col_dist)
351 CALL timestop(handle)
353 END SUBROUTINE atomic_basis_at_grid_point
372 SUBROUTINE fill_phi_for_atom(phi_val, ri_rs_grid, npts, iatom, &
373 particle_set, qs_kind_set, cell, r2_threshold)
375 REAL(kind=
dp),
INTENT(INOUT) :: phi_val(:, :)
376 INTEGER,
INTENT(IN) :: npts
377 REAL(kind=
dp),
INTENT(IN) :: ri_rs_grid(3, npts)
378 INTEGER,
INTENT(IN) :: iatom
380 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
382 REAL(kind=
dp),
INTENT(IN) :: r2_threshold
384 CHARACTER(LEN=*),
PARAMETER :: routinen =
'fill_phi_for_atom'
386 INTEGER :: first_sgf, handle, i_pt, ico, iend_co, ikind, ipgf, iset, isgf, ishell, &
387 istart_co, ix, ix_max, ix_min, iy, iy_max, iy_min, iz, iz_max, iz_min, l, last_sgf, lx, &
388 ly, lz, n_cart_total, row_idx
389 REAL(kind=
dp) :: alpha, cell_vector(3), dist_vec(3), &
390 dist_vec_raw(3), exp_val, poly, r2, &
392 REAL(kind=
dp),
DIMENSION(3, 3) :: hmat
395 CALL timeset(routinen, handle)
398 ikind = particle_set(iatom)%atomic_kind%kind_number
399 CALL get_qs_kind(qs_kind_set(ikind), basis_set=orb_basis_set, basis_type=
"ORB")
402 IF (.NOT.
ASSOCIATED(orb_basis_set))
THEN
403 CALL timestop(handle)
407 IF (cell%perd(1) == 1) then; ix_min = -1; ix_max = 1; else; ix_min = 0; ix_max = 0
409 IF (cell%perd(2) == 1) then; iy_min = -1; iy_max = 1; else; iy_min = 0; iy_max = 0
411 IF (cell%perd(3) == 1) then; iz_min = -1; iz_max = 1; else; iz_min = 0; iz_max = 0
414 r_atom = particle_set(iatom)%r
427 dist_vec_raw = ri_rs_grid(:, i_pt) - r_atom
429 DO ix = ix_min, ix_max
430 DO iy = iy_min, iy_max
431 DO iz = iz_min, iz_max
433 cell_vector(1:3) = matmul(hmat, real([ix, iy, iz],
dp))
435 dist_vec = dist_vec_raw - cell_vector
437 r2 = dot_product(dist_vec, dist_vec)
439 IF (r2 > r2_threshold) cycle
441 DO iset = 1, orb_basis_set%nset
442 n_cart_total =
ncoset(orb_basis_set%lmax(iset))
444 DO ishell = 1, orb_basis_set%nshell(iset)
445 l = orb_basis_set%l(ishell, iset)
446 istart_co =
ncoset(l - 1) + 1
449 first_sgf = orb_basis_set%first_sgf(ishell, iset)
450 last_sgf = orb_basis_set%last_sgf(ishell, iset)
452 DO ipgf = 1, orb_basis_set%npgf(iset)
453 alpha = orb_basis_set%zet(ipgf, iset)
454 exp_val = exp(-alpha*r2)
456 DO isgf = first_sgf, last_sgf
457 DO ico = istart_co, iend_co
458 row_idx = (ipgf - 1)*n_cart_total + ico
459 weight = orb_basis_set%sphi(row_idx, isgf)
463 poly = (dist_vec(1)**lx)*(dist_vec(2)**ly)*(dist_vec(3)**lz)
465 phi_val(i_pt, isgf) = phi_val(i_pt, isgf) + (weight*poly*exp_val)
478 CALL timestop(handle)
480 END SUBROUTINE fill_phi_for_atom
491 SUBROUTINE compute_coeff_z_lp(qs_env, bs_env, ri_rs_grid_points, mat_phi_mu_l, mat_Z_lP)
496 REAL(kind=
dp),
ALLOCATABLE,
INTENT(INOUT) :: ri_rs_grid_points(:, :)
497 TYPE(
dbcsr_type),
INTENT(INOUT) :: mat_phi_mu_l
500 CHARACTER(LEN=*),
PARAMETER :: key =
'PROPERTIES%BANDSTRUCTURE%GW%PRINT%RESTART', &
501 routinen =
'compute_coeff_Z_lP'
503 INTEGER :: atom_j_mepos, atom_j_stride, atom_p, atom_p_start, atom_p_stride, col_end, &
504 col_start, current_chunk_size, g, group_handle, handle, handle_dpotrf, handle_dpotrs, &
505 handle_dsyrk, i, i_blk, ikind, info, j, j_ri, l, loc_idx, loc_ptr, max_ao_size, &
506 max_loc_ri, my_group, n_ao_total, n_grid_total, n_groups, n_loc_ri, n_local_grid, &
507 n_procs_per_atom, natom, nkind, npcol_phi, num_grid_chunks, p_loop_atom, r_end, r_start, &
509 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: local_grid_idx, row_offset
510 INTEGER,
DIMENSION(:),
POINTER :: col_dist_ri, r_blk_sizes, ri_blk_sizes, &
512 REAL(kind=
dp) :: cutoff_ri, cutoff_ri_2, d_sp, dist2_min, &
513 r2_threshold, r_c, t1, t2, t3
514 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: cutoff_ri_per_atom, cutoff_ri_per_kind, &
516 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: d_local, d_lp_local, phi_local, &
518 REAL(kind=
dp),
DIMENSION(3) :: dist_vec_raw, pos_p
529 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
532 CALL timeset(routinen, handle)
536 CALL get_qs_env(qs_env, para_env=para_env, particle_set=particle_set, input=input, &
537 cell=cell, qs_kind_set=qs_kind_set, atomic_kind_set=atomic_kind_set)
547 n_procs_per_atom = min(bs_env%ri_rs%n_procs_per_atom_z_lp, para_env%num_pe)
548 IF (n_procs_per_atom < 1) n_procs_per_atom = 1
550 NULLIFY (para_env_sub, blacs_env_sub)
551 IF (n_procs_per_atom > 1)
THEN
552 n_groups = para_env%num_pe/n_procs_per_atom
553 my_group = min(para_env%mepos/n_procs_per_atom, n_groups - 1)
554 ALLOCATE (para_env_sub)
555 CALL para_env_sub%from_split(para_env, my_group)
557 atom_p_start = my_group + 1
558 atom_p_stride = n_groups
559 atom_j_mepos = para_env_sub%mepos
560 atom_j_stride = para_env_sub%num_pe
562 atom_p_start = para_env%mepos + 1
563 atom_p_stride = para_env%num_pe
568 natom =
SIZE(bs_env%i_RI_start_from_atom)
569 n_ao_total = bs_env%i_ao_end_from_atom(natom)
570 n_grid_total =
SIZE(ri_rs_grid_points, 2)
575 CALL dbcsr_get_info(mat_phi_mu_l, row_blk_size=r_blk_sizes, distribution=dist_phi)
577 group=group_handle, npcols=npcol_phi)
579 num_grid_chunks =
SIZE(r_blk_sizes)
581 ALLOCATE (row_offset(num_grid_chunks))
583 DO i_blk = 2, num_grid_chunks
584 row_offset(i_blk) = row_offset(i_blk - 1) + r_blk_sizes(i_blk - 1)
587 ALLOCATE (ri_blk_sizes(natom), col_dist_ri(natom))
589 ri_blk_sizes(atom_p) = bs_env%i_RI_end_from_atom(atom_p) - bs_env%i_RI_start_from_atom(atom_p) + 1
590 col_dist_ri(atom_p) = mod(atom_p - 1, npcol_phi)
595 IF (bs_env%ri_rs%Z_lP_exists)
THEN
597 distribution=dist_z, &
599 IF (bs_env%unit_nr > 0)
THEN
600 WRITE (bs_env%unit_nr,
'(T2,A,T57,A,F7.1,A)') &
601 'Read Z_lP from file ',
' Execution time',
m_walltime() - t1,
' s'
602 WRITE (bs_env%unit_nr,
'(A)')
' '
606 CALL dbcsr_create(mat_z_lp, name=
"mat_Z_lP", dist=dist_z, &
607 matrix_type=dbcsr_type_no_symmetry, &
608 row_blk_size=r_blk_sizes, col_blk_size=ri_blk_sizes)
611 DO j = 1,
SIZE(bs_env%i_ao_start_from_atom)
612 max_ao_size = max(max_ao_size, bs_env%i_ao_end_from_atom(j) - bs_env%i_ao_start_from_atom(j) + 1)
614 max_loc_ri = maxval(ri_blk_sizes)
620 nkind =
SIZE(atomic_kind_set)
621 ALLOCATE (cutoff_ri_per_atom(natom))
623 IF (bs_env%ri_rs%cutoff_radius_ri_rs > 0.0_dp)
THEN
624 cutoff_ri_per_atom(:) = bs_env%ri_rs%cutoff_radius_ri_rs
626 r_c = bs_env%ri_metric%cutoff_radius
627 DO p_loop_atom = 1, natom
628 cutoff_ri_per_atom(p_loop_atom) = &
629 r_c + bs_env%ri_rs%radius_ao_per_atom(p_loop_atom)
633 ALLOCATE (cutoff_ri_per_kind(nkind))
634 cutoff_ri_per_kind(:) = 0.0_dp
635 IF (bs_env%unit_nr > 0)
THEN
636 DO p_loop_atom = 1, natom
637 ikind = particle_set(p_loop_atom)%atomic_kind%kind_number
638 cutoff_ri_per_kind(ikind) = max(cutoff_ri_per_kind(ikind), &
639 cutoff_ri_per_atom(p_loop_atom))
641 WRITE (bs_env%unit_nr,
'(T2,A)')
'Per-kind maximum RI-RS sphere cutoff (Bohr):'
642 WRITE (bs_env%unit_nr,
'(T4,A4,A14)')
'Kind',
'max cutoff_ri'
644 WRITE (bs_env%unit_nr,
'(T4,A4,F14.4)') &
645 atomic_kind_set(ikind)%element_symbol, &
646 cutoff_ri_per_kind(ikind)
648 WRITE (bs_env%unit_nr,
'(A)')
' '
649 DEALLOCATE (cutoff_ri_per_kind)
657 basis_j=bs_env%basis_set_AO, basis_k=bs_env%basis_set_AO, &
658 basis_i=bs_env%basis_set_RI)
665 DO atom_p = atom_p_start, natom, atom_p_stride
667 n_loc_ri = ri_blk_sizes(atom_p)
668 pos_p(:) = particle_set(atom_p)%r(:)
670 cutoff_ri = cutoff_ri_per_atom(atom_p)
671 cutoff_ri_2 = cutoff_ri**2
677 DO l = 1, n_grid_total
678 dist_vec_raw =
pbc(ri_rs_grid_points(1:3, l), pos_p(1:3), cell)
679 dist2_min = dot_product(dist_vec_raw, dist_vec_raw)
680 IF (dist2_min <= cutoff_ri_2) n_local_grid = n_local_grid + 1
683 ALLOCATE (local_grid_idx(n_local_grid))
686 DO l = 1, n_grid_total
687 dist_vec_raw =
pbc(ri_rs_grid_points(1:3, l), pos_p(1:3), cell)
688 dist2_min = dot_product(dist_vec_raw, dist_vec_raw)
689 IF (dist2_min <= cutoff_ri_2)
THEN
690 n_local_grid = n_local_grid + 1
691 local_grid_idx(n_local_grid) = l
702 ALLOCATE (sphere_grid(3, n_local_grid))
703 DO loc_idx = 1, n_local_grid
704 sphere_grid(:, loc_idx) = ri_rs_grid_points(:, local_grid_idx(loc_idx))
707 ALLOCATE (phi_local(n_local_grid, n_ao_total))
710 DO source_atom = 1, natom
711 dist_vec_raw =
pbc(particle_set(source_atom)%r(:), pos_p(:), cell)
712 d_sp = norm2(dist_vec_raw)
713 IF (d_sp > bs_env%ri_rs%radius_ao_per_atom(source_atom) + cutoff_ri) cycle
715 col_start = bs_env%i_ao_start_from_atom(source_atom)
716 col_end = bs_env%i_ao_end_from_atom(source_atom)
717 r2_threshold = bs_env%ri_rs%radius_ao_per_atom(source_atom)**2
719 CALL fill_phi_for_atom(phi_local(:, col_start:col_end), sphere_grid, &
720 n_local_grid, source_atom, particle_set, qs_kind_set, &
724 DEALLOCATE (sphere_grid)
731 ALLOCATE (d_lp_local(n_local_grid, n_loc_ri))
736 CALL compute_d_lp(bs_env, ctx_3c, cell, phi_local, d_lp_local, n_local_grid, &
737 n_loc_ri, atom_p, max_ao_size, atom_j_mepos, atom_j_stride)
741 IF (n_procs_per_atom > 1)
THEN
742 CALL para_env_sub%sum(d_lp_local)
750 ALLOCATE (d_vec_local(n_local_grid))
752 IF (n_procs_per_atom == 1)
THEN
756 ALLOCATE (d_local(n_local_grid, n_local_grid))
759 CALL timeset(routinen//
"_dsyrk", handle_dsyrk)
760 CALL dsyrk(
"L",
"N", n_local_grid, n_ao_total, 1.0_dp, phi_local, &
761 n_local_grid, 0.0_dp, d_local, n_local_grid)
762 CALL timestop(handle_dsyrk)
768 DO i = 1, n_local_grid
769 d_local(i, i) = d_local(i, i)**2
770 d_vec_local(i) = 1.0_dp/sqrt(max(d_local(i, i), 1.0e-16_dp))
771 d_local(i, i) = (d_local(i, i)*d_vec_local(i)**2) + bs_env%ri_rs%tikhonov
779 DO j = 1, n_local_grid
780 DO i = j + 1, n_local_grid
781 d_local(i, j) = d_local(i, j)**2
782 d_local(i, j) = d_local(i, j)*d_vec_local(i)*d_vec_local(j)
783 d_local(j, i) = d_local(i, j)
795 DO i = 1, n_local_grid
796 d_vec_local(i) = 0.0_dp
798 d_vec_local(i) = d_vec_local(i) + phi_local(i, j)*phi_local(i, j)
800 d_vec_local(i) = 1.0_dp/max(d_vec_local(i), 1.0e-16_dp)
812 DO j_ri = 1, n_loc_ri
813 DO i = 1, n_local_grid
814 d_lp_local(i, j_ri) = d_lp_local(i, j_ri)*d_vec_local(i)
822 IF (n_procs_per_atom == 1)
THEN
823 CALL timeset(routinen//
"_dpotrf", handle_dpotrf)
824 CALL dpotrf(
'L', n_local_grid, d_local, n_local_grid, info)
825 CALL timestop(handle_dpotrf)
826 CALL timeset(routinen//
"_dpotrs", handle_dpotrs)
827 CALL dpotrs(
'L', n_local_grid, n_loc_ri, d_local, n_local_grid, &
828 d_lp_local, n_local_grid, info)
829 CALL timestop(handle_dpotrs)
833 n_local_grid, n_ao_total, n_loc_ri, &
834 bs_env%ri_rs%tikhonov, &
835 para_env_sub, blacs_env_sub, &
836 fm_struct_d, fm_struct_b, fm_d, fm_b, info)
846 DO j_ri = 1, n_loc_ri
847 DO i = 1, n_local_grid
848 d_lp_local(i, j_ri) = d_lp_local(i, j_ri)*d_vec_local(i)
862 IF (n_procs_per_atom == 1 .OR. para_env_sub%mepos == 0)
THEN
863 ALLOCATE (z_blk(maxval(r_blk_sizes), n_loc_ri))
866 DO i_blk = 1, num_grid_chunks
867 r_start = row_offset(i_blk) + 1
868 r_end = row_offset(i_blk) + r_blk_sizes(i_blk)
869 current_chunk_size = r_blk_sizes(i_blk)
873 DO WHILE (loc_ptr <= n_local_grid)
874 g = local_grid_idx(loc_ptr)
876 z_blk(g - r_start + 1, 1:n_loc_ri) = d_lp_local(loc_ptr, 1:n_loc_ri)
877 loc_ptr = loc_ptr + 1
880 IF (maxval(abs(z_blk(1:current_chunk_size, 1:n_loc_ri))) > bs_env%eps_filter)
THEN
882 block=z_blk(1:current_chunk_size, 1:n_loc_ri))
889 DEALLOCATE (d_vec_local, d_lp_local)
890 DEALLOCATE (local_grid_idx, phi_local)
894 DEALLOCATE (cutoff_ri_per_atom)
899 IF (bs_env%unit_nr > 0)
THEN
900 WRITE (bs_env%unit_nr,
'(T2,A,T57,A,F7.1,A)') &
901 'Computed Z_lP ',
' Execution time',
m_walltime() - t1,
' s'
902 WRITE (bs_env%unit_nr,
'(A)')
' '
913 DEALLOCATE (row_offset, ri_blk_sizes, col_dist_ri)
916 IF (n_procs_per_atom > 1)
THEN
918 CALL para_env_sub%free()
919 DEALLOCATE (para_env_sub)
922 DEALLOCATE (ri_rs_grid_points)
924 CALL timestop(handle)
926 END SUBROUTINE compute_coeff_z_lp
949 SUBROUTINE compute_d_lp(bs_env, ctx, cell, phi_val, d_lp, n_grid_total, n_loc_ri, atom_P, &
950 max_ao_size, atom_j_mepos, atom_j_stride)
955 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(IN) :: phi_val
956 INTEGER,
INTENT(IN) :: n_grid_total, n_loc_ri
957 REAL(kind=
dp),
INTENT(INOUT) :: d_lp(n_grid_total, n_loc_ri)
958 INTEGER,
INTENT(IN) :: atom_p, max_ao_size, atom_j_mepos, &
961 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_d_lp'
962 INTEGER,
PARAMETER :: grid_chunk = 1024
964 INTEGER :: atom_j, atom_k, c, handle, handle_dgemm, ix_max, ix_min, ix_r, ix_s, iy_max, &
965 iy_min, iy_r, iy_s, iz_max, iz_min, iz_r, iz_s, j, jk_idx, jsize, jstart, k, ksize, &
966 kstart, l, l0, natom, ri
967 INTEGER,
DIMENSION(3) :: cell_r_vec, cell_s_vec
968 LOGICAL :: any_kept, screened
969 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: d_lp_prv, int_2d_prv, rho_chunk
970 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :) :: int_3c_prv, int_3c_sum
973 CALL timeset(routinen, handle)
975 natom =
SIZE(bs_env%i_ao_start_from_atom)
977 IF (cell%perd(1) == 1) then; ix_min = -1; ix_max = 1; else; ix_min = 0; ix_max = 0
979 IF (cell%perd(2) == 1) then; iy_min = -1; iy_max = 1; else; iy_min = 0; iy_max = 0
981 IF (cell%perd(3) == 1) then; iz_min = -1; iz_max = 1; else; iz_min = 0; iz_max = 0
993 ALLOCATE (int_3c_prv(max_ao_size, max_ao_size, n_loc_ri))
994 ALLOCATE (int_3c_sum(max_ao_size, max_ao_size, n_loc_ri))
995 ALLOCATE (int_2d_prv(max_ao_size*max_ao_size, n_loc_ri))
996 ALLOCATE (rho_chunk(grid_chunk, max_ao_size*max_ao_size))
997 ALLOCATE (d_lp_prv(n_grid_total, n_loc_ri))
998 d_lp_prv(:, :) = 0.0_dp
1008 DO atom_j = atom_j_mepos + 1, natom, atom_j_stride
1009 DO atom_k = 1, natom
1010 jstart = bs_env%i_ao_start_from_atom(atom_j)
1011 jsize = bs_env%i_ao_end_from_atom(atom_j) - jstart + 1
1012 kstart = bs_env%i_ao_start_from_atom(atom_k)
1013 ksize = bs_env%i_ao_end_from_atom(atom_k) - kstart + 1
1015 int_3c_sum(1:jsize, 1:ksize, 1:n_loc_ri) = 0.0_dp
1018 DO ix_r = ix_min, ix_max
1019 DO iy_r = iy_min, iy_max
1020 DO iz_r = iz_min, iz_max
1021 cell_r_vec = [ix_r, iy_r, iz_r]
1022 DO ix_s = ix_min, ix_max
1023 DO iy_s = iy_min, iy_max
1024 DO iz_s = iz_min, iz_max
1025 cell_s_vec = [ix_s, iy_s, iz_s]
1027 int_3c_prv(1:jsize, 1:ksize, 1:n_loc_ri) = 0.0_dp
1030 int_3c_prv(1:jsize, 1:ksize, 1:n_loc_ri), ctx, ws, &
1031 atom_j=atom_j, atom_k=atom_k, atom_i=atom_p, &
1032 cell_j=cell_r_vec, cell_k=cell_s_vec, cell_i=[0, 0, 0], &
1037 int_3c_sum(1:jsize, 1:ksize, 1:n_loc_ri) = &
1038 int_3c_sum(1:jsize, 1:ksize, 1:n_loc_ri) + &
1039 int_3c_prv(1:jsize, 1:ksize, 1:n_loc_ri)
1047 IF (.NOT. any_kept) cycle
1053 jk_idx = (k - 1)*jsize + j
1054 int_2d_prv(jk_idx, ri) = int_3c_sum(j, k, ri)
1061 DO l0 = 1, n_grid_total, grid_chunk
1062 c = min(grid_chunk, n_grid_total - l0 + 1)
1065 jk_idx = (k - 1)*jsize + j
1067 rho_chunk(l, jk_idx) = phi_val(l0 + l - 1, jstart + j - 1)* &
1068 phi_val(l0 + l - 1, kstart + k - 1)
1072 CALL timeset(routinen//
"_dgemm", handle_dgemm)
1073 CALL dgemm(
"N",
"N", c, n_loc_ri, jsize*ksize, &
1074 1.0_dp, rho_chunk, grid_chunk, &
1075 int_2d_prv, max_ao_size*max_ao_size, &
1076 1.0_dp, d_lp_prv(l0, 1), n_grid_total)
1077 CALL timestop(handle_dgemm)
1084 d_lp(1:n_grid_total, 1:n_loc_ri) = d_lp(1:n_grid_total, 1:n_loc_ri) + &
1085 d_lp_prv(1:n_grid_total, 1:n_loc_ri)
1088 DEALLOCATE (int_3c_prv, int_3c_sum, int_2d_prv, rho_chunk, d_lp_prv)
1093 CALL timestop(handle)
1095 END SUBROUTINE compute_d_lp
1105 SUBROUTINE get_mat_chi_gamma_tau(bs_env, mat_chi_Gamma_tau, mat_phi_mu_l, mat_Z_lP)
1108 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: mat_chi_gamma_tau
1109 TYPE(
dbcsr_type),
INTENT(INOUT) :: mat_phi_mu_l, mat_z_lp
1111 CHARACTER(LEN=*),
PARAMETER :: routinen =
'get_mat_chi_Gamma_tau'
1113 INTEGER :: handle, i, i_t, ispin, npcol
1114 INTEGER,
DIMENSION(:),
POINTER :: blk_ao, blk_grid, dist_col_grid, &
1116 REAL(kind=
dp) :: t1, tau
1118 TYPE(
dbcsr_type) :: matrix_chi_grid, matrix_chi_grid_spin, &
1119 matrix_g_occ_grid, matrix_g_vir_grid
1121 CALL timeset(routinen, handle)
1126 CALL dbcsr_get_info(mat_phi_mu_l, distribution=dist_phi, row_blk_size=blk_grid, col_blk_size=blk_ao)
1130 ALLOCATE (dist_col_grid(
SIZE(blk_grid)))
1131 DO i = 1,
SIZE(blk_grid)
1132 dist_col_grid(i) = mod(i - 1, npcol)
1136 row_dist=dist_row_grid, col_dist=dist_col_grid)
1138 CALL dbcsr_create(matrix_g_occ_grid,
"G_occ_grid", dist_grid_grid, dbcsr_type_no_symmetry, blk_grid, blk_grid)
1139 CALL dbcsr_create(matrix_g_vir_grid,
"G_vir_grid", dist_grid_grid, dbcsr_type_no_symmetry, blk_grid, blk_grid)
1140 CALL dbcsr_create(matrix_chi_grid,
"chi_grid", dist_grid_grid, dbcsr_type_no_symmetry, blk_grid, blk_grid)
1141 CALL dbcsr_create(matrix_chi_grid_spin,
"chi_grid_spin", dist_grid_grid, dbcsr_type_no_symmetry, blk_grid, blk_grid)
1146 DO i_t = 1, bs_env%num_time_freq_points
1149 tau = bs_env%imag_time_points(i_t)
1155 DO ispin = 1, bs_env%n_spin
1159 CALL build_g_grid(bs_env, tau, ispin, .true., .false., mat_phi_mu_l, &
1160 matrix_g_occ_grid, bs_env%eps_filter)
1164 CALL build_g_grid(bs_env, tau, ispin, .false., .true., mat_phi_mu_l, &
1165 matrix_g_vir_grid, bs_env%eps_filter)
1171 CALL hadamard_product(matrix_g_occ_grid, matrix_g_vir_grid, matrix_chi_grid_spin, bs_env%spin_degeneracy)
1174 CALL dbcsr_add(matrix_chi_grid, matrix_chi_grid_spin, 1.0_dp, 1.0_dp)
1185 mat_chi_gamma_tau(i_t)%matrix, bs_env%eps_filter)
1187 IF (bs_env%unit_nr > 0)
THEN
1188 WRITE (bs_env%unit_nr,
'(T2,A,I13,A,I3,A,F7.1,A)') &
1189 χτ
'Computed (i,k=0) for time point', i_t,
' /', bs_env%num_time_freq_points, &
1203 DEALLOCATE (dist_col_grid)
1205 IF (bs_env%unit_nr > 0)
WRITE (bs_env%unit_nr,
'(A)')
' '
1207 CALL timestop(handle)
1209 END SUBROUTINE get_mat_chi_gamma_tau
1223 SUBROUTINE build_g_grid(bs_env, tau, ispin, occ, vir, mat_phi_mu_l, matrix_G_grid, eps_filter)
1226 REAL(kind=
dp),
INTENT(IN) :: tau
1227 INTEGER,
INTENT(IN) :: ispin
1228 LOGICAL,
INTENT(IN) :: occ, vir
1229 TYPE(
dbcsr_type),
INTENT(INOUT) :: mat_phi_mu_l, matrix_g_grid
1230 REAL(kind=
dp),
INTENT(IN) :: eps_filter
1232 CHARACTER(LEN=*),
PARAMETER :: routinen =
'build_G_grid'
1235 INTEGER,
DIMENSION(:),
POINTER :: blk_ao, dist_row_ao
1240 CALL timeset(routinen, handle)
1244 fm_g => bs_env%fm_Gocc
1246 fm_g => bs_env%fm_Gvir
1251 CALL g_occ_vir(bs_env, tau, fm_g, ispin, occ=occ, vir=vir)
1256 CALL dbcsr_create(matrix_g_ao, name=
"G_ao", dist=dist_ao_ao, &
1257 matrix_type=dbcsr_type_no_symmetry, &
1258 row_blk_size=blk_ao, col_blk_size=blk_ao)
1265 CALL contract_a_b_a(
"N",
"T", mat_phi_mu_l, matrix_g_ao, matrix_g_grid, eps_filter)
1270 CALL timestop(handle)
1272 END SUBROUTINE build_g_grid
1284 SUBROUTINE contract_a_b_a(transA_left, transA_right, matrix_A, matrix_B, matrix_out, eps_filter)
1286 CHARACTER(LEN=1),
INTENT(IN) :: transa_left, transa_right
1287 TYPE(
dbcsr_type),
INTENT(INOUT) :: matrix_a, matrix_b, matrix_out
1288 REAL(kind=
dp),
INTENT(IN) :: eps_filter
1290 CHARACTER(LEN=*),
PARAMETER :: routinen =
'contract_A_B_A'
1295 CALL timeset(routinen, handle)
1299 IF (transa_left ==
"N" .AND. transa_right ==
"T")
THEN
1302 0.0_dp, matrix_tmp, filter_eps=eps_filter)
1304 0.0_dp, matrix_out, filter_eps=eps_filter)
1306 ELSE IF (transa_left ==
"T" .AND. transa_right ==
"N")
THEN
1309 0.0_dp, matrix_tmp, filter_eps=eps_filter)
1311 0.0_dp, matrix_out, filter_eps=eps_filter)
1313 cpabort(
"Unsupported transposition pair in contract_A_B_A")
1318 CALL timestop(handle)
1330 SUBROUTINE hadamard_product(matrix_A, matrix_B, matrix_C, fac)
1332 TYPE(
dbcsr_type),
INTENT(INOUT) :: matrix_a, matrix_b, matrix_c
1333 REAL(kind=
dp),
INTENT(IN) ::
fac
1335 CHARACTER(LEN=*),
PARAMETER :: routinen =
'hadamard_product'
1337 INTEGER :: col, handle, row
1339 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: blk_b, blk_c
1342 CALL timeset(routinen, handle)
1353 blk_c(:, :) =
fac*blk_c(:, :)*blk_b(:, :)
1356 blk_c(:, :) = 0.0_dp
1361 CALL timestop(handle)
1363 END SUBROUTINE hadamard_product
1374 TYPE(
dbcsr_type),
INTENT(INOUT) :: matrix_a, matrix_b
1375 REAL(kind=
dp),
INTENT(IN) ::
fac
1377 CHARACTER(LEN=*),
PARAMETER :: routinen =
'hadamard_product_inplace'
1379 INTEGER :: col, handle, row
1381 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: blk_a, blk_b
1384 CALL timeset(routinen, handle)
1393 blk_a(:, :) =
fac*blk_a(:, :)*blk_b(:, :)
1396 blk_a(:, :) = 0.0_dp
1401 CALL timestop(handle)
1413 SUBROUTINE compute_w(bs_env, qs_env, mat_chi_Gamma_tau, fm_W_time)
1416 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: mat_chi_gamma_tau
1417 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_w_time
1419 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_W'
1421 INTEGER :: handle, i_t, j_w
1423 TYPE(
cp_fm_type) :: fm_m_inv_v_sqrt, fm_v, fm_v_sqrt
1425 CALL timeset(routinen, handle)
1433 CALL cp_fm_create(fm_v_sqrt, bs_env%fm_RI_RI%matrix_struct)
1434 CALL cp_fm_create(fm_m_inv_v_sqrt, bs_env%fm_RI_RI%matrix_struct)
1437 CALL compute_v_minvvsqrt(bs_env, qs_env, fm_v, fm_v_sqrt, fm_m_inv_v_sqrt)
1440 DO j_w = 1, bs_env%num_time_freq_points
1446 CALL compute_fm_w_freq(bs_env, bs_env%fm_chi_Gamma_freq, fm_v_sqrt, &
1447 fm_m_inv_v_sqrt, bs_env%fm_W_MIC_freq)
1456 IF (bs_env%unit_nr > 0)
THEN
1457 WRITE (bs_env%unit_nr,
'(T2,A,T55,A,F10.1,A)') &
1458 τ
'Computed W(i),',
' Execution time',
m_walltime() - t1,
' s'
1471 CALL cp_fm_create(bs_env%fm_W_MIC_freq_zero, bs_env%fm_W_MIC_freq%matrix_struct)
1475 DO i_t = 1, bs_env%num_time_freq_points
1478 bs_env%imag_time_weights_freq_zero(i_t), fm_w_time(i_t))
1481 CALL fm_write(bs_env%fm_W_MIC_freq_zero, 0,
"W_freq_rtp", qs_env)
1483 IF (bs_env%unit_nr > 0)
THEN
1484 WRITE (bs_env%unit_nr,
'(T2,A,T55,A,F10.1,A)') &
1485 'Computed W(0),',
' Execution time',
m_walltime() - t1,
' s'
1489 IF (bs_env%unit_nr > 0)
WRITE (bs_env%unit_nr,
'(A)')
' '
1491 CALL timestop(handle)
1493 END SUBROUTINE compute_w
1504 SUBROUTINE compute_v_minvvsqrt(bs_env, qs_env, fm_V, fm_V_sqrt, fm_Minv_Vsqrt)
1507 TYPE(
cp_fm_type),
INTENT(INOUT) :: fm_v, fm_v_sqrt, fm_minv_vsqrt
1509 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_V_MinvVsqrt'
1511 INTEGER :: handle, info, n_ri, ndep
1515 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: fm_m
1516 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: mat_v_kp
1518 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
1520 CALL timeset(routinen, handle)
1528 CALL get_qs_env(qs_env=qs_env, particle_set=particle_set, cell=cell, &
1529 qs_kind_set=qs_kind_set, atomic_kind_set=atomic_kind_set)
1531 ALLOCATE (mat_v_kp(1:1, 1:2))
1532 NULLIFY (mat_v_kp(1, 1)%matrix, mat_v_kp(1, 2)%matrix)
1533 ALLOCATE (mat_v_kp(1, 1)%matrix, mat_v_kp(1, 2)%matrix)
1535 CALL dbcsr_create(mat_v_kp(1, 1)%matrix, template=bs_env%mat_RI_RI%matrix)
1537 CALL dbcsr_set(mat_v_kp(1, 1)%matrix, 0.0_dp)
1540 CALL dbcsr_create(mat_v_kp(1, 2)%matrix, template=bs_env%mat_RI_RI%matrix)
1542 CALL dbcsr_set(mat_v_kp(1, 2)%matrix, 0.0_dp)
1544 bs_env%kpoints_chi_eps_W%nkp_grid = bs_env%nkp_grid_chi_eps_W_orig
1547 particle_set, qs_kind_set, atomic_kind_set, &
1555 DEALLOCATE (mat_v_kp)
1561 do_kpoints=.false., regularization_ri=bs_env%regularization_RI)
1572 CALL cp_fm_power(fm_m(1, 1), fm_work, -1.0_dp, bs_env%eps_eigval_mat_RI, ndep)
1582 CALL clean_lower_part(fm_v_sqrt)
1584 CALL cp_fm_power(fm_v, fm_v_sqrt, 0.5_dp, bs_env%eps_eigval_mat_RI, ndep)
1590 CALL parallel_gemm(
"N",
"T", n_ri, n_ri, n_ri, 1.0_dp, fm_m(1, 1), fm_v_sqrt, &
1591 0.0_dp, fm_minv_vsqrt)
1596 CALL timestop(handle)
1598 END SUBROUTINE compute_v_minvvsqrt
1609 SUBROUTINE compute_fm_w_freq(bs_env, fm_chi_freq_j, fm_V_sqrt, fm_Minv_Vsqrt, fm_W_freq_j)
1611 TYPE(
cp_fm_type),
INTENT(IN) :: fm_chi_freq_j, fm_v_sqrt, fm_minv_vsqrt
1612 TYPE(
cp_fm_type),
INTENT(INOUT) :: fm_w_freq_j
1614 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_fm_W_freq'
1616 INTEGER :: handle, info, n_ri, ndep
1619 CALL timeset(routinen, handle)
1623 CALL cp_fm_create(fm_eps_freq_j, fm_chi_freq_j%matrix_struct)
1624 CALL cp_fm_create(fm_work, fm_chi_freq_j%matrix_struct)
1631 fm_chi_freq_j, fm_minv_vsqrt, 0.0_dp, fm_work)
1635 fm_minv_vsqrt, fm_work, 0.0_dp, fm_eps_freq_j)
1638 CALL fm_add_on_diag(fm_eps_freq_j, 1.0_dp)
1656 CALL cp_fm_power(fm_eps_freq_j, fm_work, -1.0_dp, bs_env%eps_eigval_mat_RI, ndep)
1661 CALL fm_add_on_diag(fm_eps_freq_j, -1.0_dp)
1664 CALL parallel_gemm(
'N',
'N', n_ri, n_ri, n_ri, 1.0_dp, fm_eps_freq_j, fm_v_sqrt, &
1668 CALL parallel_gemm(
'T',
'N', n_ri, n_ri, n_ri, 1.0_dp, fm_v_sqrt, fm_work, &
1669 0.0_dp, fm_w_freq_j)
1675 CALL timestop(handle)
1677 END SUBROUTINE compute_fm_w_freq
1685 SUBROUTINE fm_add_on_diag(fm, alpha)
1687 REAL(kind=
dp),
INTENT(IN) :: alpha
1689 CHARACTER(LEN=*),
PARAMETER :: routinen =
'fm_add_on_diag'
1691 INTEGER :: handle, i_global, i_row, j_col, &
1692 j_global, ncol_local, nrow_local
1693 INTEGER,
DIMENSION(:),
POINTER :: col_indices, row_indices
1695 CALL timeset(routinen, handle)
1698 nrow_local=nrow_local, &
1699 ncol_local=ncol_local, &
1700 row_indices=row_indices, &
1701 col_indices=col_indices)
1703 DO j_col = 1, ncol_local
1704 j_global = col_indices(j_col)
1705 DO i_row = 1, nrow_local
1706 i_global = row_indices(i_row)
1707 IF (j_global == i_global)
THEN
1708 fm%local_data(i_row, j_col) = fm%local_data(i_row, j_col) + alpha
1713 CALL timestop(handle)
1715 END SUBROUTINE fm_add_on_diag
1721 SUBROUTINE clean_lower_part(fm_mat)
1724 CHARACTER(LEN=*),
PARAMETER :: routinen =
'clean_lower_part'
1726 INTEGER :: handle, i_row, j_col, j_global, &
1727 ncol_local, nrow_local
1728 INTEGER,
DIMENSION(:),
POINTER :: col_indices, row_indices
1730 CALL timeset(routinen, handle)
1733 nrow_local=nrow_local, ncol_local=ncol_local, &
1734 row_indices=row_indices, col_indices=col_indices)
1736 DO j_col = 1, ncol_local
1737 j_global = col_indices(j_col)
1738 DO i_row = 1, nrow_local
1739 IF (j_global < row_indices(i_row)) fm_mat%local_data(i_row, j_col) = 0.0_dp
1743 CALL timestop(handle)
1745 END SUBROUTINE clean_lower_part
1756 SUBROUTINE compute_sigma_x(bs_env, qs_env, mat_phi_mu_l, mat_Z_lP, fm_Sigma_x_Gamma)
1760 TYPE(
dbcsr_type),
INTENT(INOUT) :: mat_phi_mu_l, mat_z_lp
1761 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_sigma_x_gamma
1763 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_Sigma_x'
1765 INTEGER :: handle, ispin
1766 INTEGER,
DIMENSION(:),
POINTER :: blk_aux, blk_grid, dist_col_grid, &
1769 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: fm_vtr_gamma
1771 TYPE(
dbcsr_type) :: mat_sigma_x_gamma, matrix_d_grid, &
1772 matrix_sigma_x_grid, matrix_v_aux, &
1775 CALL timeset(routinen, handle)
1779 ALLOCATE (fm_sigma_x_gamma(bs_env%n_spin))
1780 DO ispin = 1, bs_env%n_spin
1781 CALL cp_fm_create(fm_sigma_x_gamma(ispin), bs_env%fm_s_Gamma%matrix_struct)
1784 CALL dbcsr_create(mat_sigma_x_gamma, template=bs_env%mat_ao_ao%matrix)
1796 bs_env%trunc_coulomb, do_kpoints=.false.)
1801 CALL dbcsr_create(matrix_v_aux,
"V_aux", dist_aux_aux, dbcsr_type_no_symmetry, blk_aux, blk_aux)
1802 CALL dbcsr_create(matrix_v_grid,
"V_grid", dist_grid_grid, dbcsr_type_no_symmetry, blk_grid, blk_grid)
1804 CALL copy_fm_to_dbcsr(fm_vtr_gamma(1, 1), matrix_v_aux, keep_sparsity=.false.)
1807 CALL contract_a_b_a(
"N",
"T", mat_z_lp, matrix_v_aux, matrix_v_grid, bs_env%eps_filter)
1813 DO ispin = 1, bs_env%n_spin
1818 CALL dbcsr_create(matrix_d_grid,
"D_grid", dist_grid_grid, dbcsr_type_no_symmetry, blk_grid, blk_grid)
1819 CALL build_g_grid(bs_env, 0.0_dp, ispin, .true., .false., mat_phi_mu_l, matrix_d_grid, bs_env%eps_filter)
1823 CALL dbcsr_create(matrix_sigma_x_grid, template=matrix_v_grid)
1824 CALL hadamard_product(matrix_d_grid, matrix_v_grid, matrix_sigma_x_grid, 1.0_dp)
1830 CALL contract_a_b_a(
"T",
"N", mat_phi_mu_l, matrix_sigma_x_grid, mat_sigma_x_gamma, bs_env%eps_filter)
1840 IF (bs_env%unit_nr > 0)
THEN
1841 WRITE (bs_env%unit_nr,
'(T2,A,T58,A,F7.1,A)') &
1842 Σ
'Computed ^x(k=0),',
' Execution time',
m_walltime() - t1,
' s'
1843 WRITE (bs_env%unit_nr,
'(A)')
' '
1850 m1=mat_sigma_x_gamma, m2=matrix_v_grid)
1855 CALL timestop(handle)
1857 END SUBROUTINE compute_sigma_x
1868 SUBROUTINE compute_sigma_c(bs_env, fm_W_time, mat_phi_mu_l, mat_Z_lP, fm_Sigma_c_Gamma_time)
1871 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_w_time
1872 TYPE(
dbcsr_type),
INTENT(INOUT) :: mat_phi_mu_l, mat_z_lp
1873 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :, :) :: fm_sigma_c_gamma_time
1875 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_Sigma_c'
1877 INTEGER :: handle, i_t, ispin
1878 INTEGER,
DIMENSION(:),
POINTER :: blk_aux, blk_grid, dist_col_grid, &
1880 REAL(kind=
dp) :: t1, tau
1882 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: mat_sigma_neg_tau, mat_sigma_pos_tau
1883 TYPE(
dbcsr_type) :: matrix_g_occ_grid, matrix_g_vir_grid, matrix_sigma_neg_grid, &
1884 matrix_sigma_pos_grid, matrix_w_aux, matrix_w_grid
1886 CALL timeset(routinen, handle)
1895 NULLIFY (mat_sigma_neg_tau, mat_sigma_pos_tau)
1896 ALLOCATE (mat_sigma_neg_tau(bs_env%num_time_freq_points, bs_env%n_spin))
1897 ALLOCATE (mat_sigma_pos_tau(bs_env%num_time_freq_points, bs_env%n_spin))
1899 DO i_t = 1, bs_env%num_time_freq_points
1900 DO ispin = 1, bs_env%n_spin
1901 ALLOCATE (mat_sigma_neg_tau(i_t, ispin)%matrix)
1902 ALLOCATE (mat_sigma_pos_tau(i_t, ispin)%matrix)
1903 CALL dbcsr_create(mat_sigma_neg_tau(i_t, ispin)%matrix, template=bs_env%mat_ao_ao%matrix)
1904 CALL dbcsr_create(mat_sigma_pos_tau(i_t, ispin)%matrix, template=bs_env%mat_ao_ao%matrix)
1911 DO i_t = 1, bs_env%num_time_freq_points
1912 tau = bs_env%imag_time_points(i_t)
1917 CALL dbcsr_create(matrix_w_aux,
"W_aux", dist_aux_aux, dbcsr_type_no_symmetry, blk_aux, blk_aux)
1918 CALL dbcsr_create(matrix_w_grid,
"W_grid", dist_grid_grid, dbcsr_type_no_symmetry, blk_grid, blk_grid)
1923 CALL contract_a_b_a(
"N",
"T", mat_z_lp, matrix_w_aux, matrix_w_grid, bs_env%eps_filter)
1927 DO ispin = 1, bs_env%n_spin
1933 CALL dbcsr_create(matrix_g_occ_grid,
"G_occ_grid", dist_grid_grid, dbcsr_type_no_symmetry, blk_grid, blk_grid)
1934 CALL dbcsr_create(matrix_g_vir_grid,
"G_vir_grid", dist_grid_grid, dbcsr_type_no_symmetry, blk_grid, blk_grid)
1938 CALL build_g_grid(bs_env, tau, ispin, .true., .false., mat_phi_mu_l, matrix_g_occ_grid, bs_env%eps_filter)
1942 CALL build_g_grid(bs_env, tau, ispin, .false., .true., mat_phi_mu_l, matrix_g_vir_grid, bs_env%eps_filter)
1949 CALL dbcsr_create(matrix_sigma_neg_grid, template=matrix_w_grid)
1950 CALL dbcsr_create(matrix_sigma_pos_grid, template=matrix_w_grid)
1953 CALL hadamard_product(matrix_g_occ_grid, matrix_w_grid, matrix_sigma_neg_grid, 1.0_dp)
1956 CALL hadamard_product(matrix_g_vir_grid, matrix_w_grid, matrix_sigma_pos_grid, 1.0_dp)
1968 CALL contract_a_b_a(
"T",
"N", mat_phi_mu_l, matrix_sigma_neg_grid, &
1969 mat_sigma_neg_tau(i_t, ispin)%matrix, bs_env%eps_filter)
1970 CALL dbcsr_scale(mat_sigma_neg_tau(i_t, ispin)%matrix, -1.0_dp)
1973 CALL contract_a_b_a(
"T",
"N", mat_phi_mu_l, matrix_sigma_pos_grid, &
1974 mat_sigma_pos_tau(i_t, ispin)%matrix, bs_env%eps_filter)
1980 IF (bs_env%unit_nr > 0)
THEN
1981 WRITE (bs_env%unit_nr,
'(T2,A,I10,A,I3,A,F7.1,A)') &
1982 Στ
'Computed ^c(i,k=0) for time point ', i_t,
' /', bs_env%num_time_freq_points, &
1993 IF (bs_env%unit_nr > 0)
WRITE (bs_env%unit_nr,
'(A)')
' '
1999 mat_sigma_pos_tau, mat_sigma_neg_tau)
2010 CALL timestop(handle)
2012 END SUBROUTINE compute_sigma_c
2025 TYPE(
dbcsr_type),
INTENT(IN) :: matrix_template
2026 CHARACTER(LEN=*),
INTENT(IN) :: dim_type
2028 INTEGER,
DIMENSION(:),
INTENT(OUT),
POINTER :: blk_sizes, mapped_dist
2030 CHARACTER(LEN=*),
PARAMETER :: routinen =
'setup_square_topology'
2032 INTEGER :: handle, i, np, npcols, nprows
2033 INTEGER,
DIMENSION(:),
POINTER :: col_blk, col_dist, row_blk, row_dist
2036 CALL timeset(routinen, handle)
2038 CALL dbcsr_get_info(matrix_template, distribution=dist_template, &
2039 row_blk_size=row_blk, col_blk_size=col_blk)
2041 nprows=nprows, npcols=npcols)
2043 IF (trim(dim_type) ==
'ROW')
THEN
2045 blk_sizes => row_blk
2047 ALLOCATE (mapped_dist(
SIZE(blk_sizes)))
2048 DO i = 1,
SIZE(blk_sizes)
2049 mapped_dist(i) = mod(i - 1, np)
2052 row_dist=row_dist, col_dist=mapped_dist)
2054 ELSE IF (trim(dim_type) ==
'COL')
THEN
2056 blk_sizes => col_blk
2058 ALLOCATE (mapped_dist(
SIZE(blk_sizes)))
2059 DO i = 1,
SIZE(blk_sizes)
2060 mapped_dist(i) = mod(i - 1, np)
2063 row_dist=mapped_dist, col_dist=col_dist)
2066 CALL timestop(handle)
2084 INTEGER,
DIMENSION(:),
INTENT(INOUT),
OPTIONAL, &
2085 POINTER :: mapped_dist
2086 TYPE(
dbcsr_type),
INTENT(INOUT),
OPTIONAL :: m1, m2, m3, m4
2088 CHARACTER(LEN=*),
PARAMETER :: routinen =
'release_dbcsr_topology_and_matrices'
2092 CALL timeset(routinen, handle)
2095 IF (
PRESENT(mapped_dist))
THEN
2096 IF (
ASSOCIATED(mapped_dist))
THEN
2097 DEALLOCATE (mapped_dist)
2098 NULLIFY (mapped_dist)
2106 CALL timestop(handle)
static GRID_HOST_DEVICE double fac(const int i)
Factorial function, e.g. fac(5) = 5! = 120.
static void dgemm(const char transa, const char transb, const int m, const int n, const int k, const double alpha, const double *a, const int lda, const double *b, const int ldb, const double beta, double *c, const int ldc)
Convenient wrapper to hide Fortran nature of dgemm_, swapping a and b.
Define the atomic kind types and their sub types.
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.
constants for the different operators of the 2c-integrals
integer, parameter, public operator_coulomb
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
subroutine, public dbcsr_distribution_release(dist)
...
subroutine, public dbcsr_scale(matrix, alpha_scalar)
...
subroutine, public dbcsr_distribution_new(dist, template, group, pgrid, row_dist, col_dist, reuse_arrays)
...
subroutine, public dbcsr_deallocate_matrix(matrix)
...
logical function, public dbcsr_iterator_blocks_left(iterator)
...
subroutine, public dbcsr_iterator_stop(iterator)
...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_get_block_p(matrix, row, col, block, found, row_size, col_size)
...
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_iterator_next_block(iterator, row, column, block, block_number_argument_has_been_removed, row_size, col_size, row_offset, col_offset, transposed)
...
subroutine, public dbcsr_binary_write(matrix, filepath)
...
subroutine, public dbcsr_finalize(matrix)
...
subroutine, public dbcsr_iterator_start(iterator, matrix, shared, dynamic, dynamic_byrows)
...
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_release(matrix)
...
subroutine, public dbcsr_binary_read(filepath, distribution, matrix_new)
...
subroutine, public dbcsr_put_block(matrix, row, col, block, summation)
...
subroutine, public dbcsr_add(matrix_a, matrix_b, alpha_scalar, beta_scalar)
...
subroutine, public dbcsr_distribution_get(dist, row_dist, col_dist, nrows, ncols, has_threads, group, mynode, numnodes, nprows, npcols, myprow, mypcol, pgrid, subgroups_defined, prow_group, pcol_group)
...
subroutine, public dbcsr_reserve_all_blocks(matrix)
Reserves all blocks.
DBCSR operations in CP2K.
integer, save, public max_elements_per_block
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_scale_and_add(alpha, matrix_a, beta, matrix_b)
calc A <- alpha*A + beta*B optimized for alpha == 1.0 (just add beta*B) and beta == 0....
subroutine, public cp_fm_uplo_to_full(matrix, work, uplo)
given a triangular matrix according to uplo, computes the corresponding full matrix
various cholesky decomposition related routines
subroutine, public cp_fm_cholesky_invert(matrix, n, info_out)
used to replace the cholesky decomposition by the inverse
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,...
used for collecting some of the diagonalization schemes available for cp_fm_type. cp_fm_power also mo...
subroutine, public cp_fm_power(matrix, work, exponent, threshold, n_dependent, verbose, eigvals)
...
represent the structure of a full matrix
represent a full matrix distributed on many processors
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_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
various routines to log and control the output. The idea is that decisions about where to log should ...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer, parameter, public cp_p_file
integer function, public cp_print_key_should_output(iteration_info, basis_section, print_key_path, used_print_key, first_time)
returns what should be done with the given property if btest(res,cp_p_store) then the property should...
Utility method to build 3-center integrals for small cell GW.
subroutine, public build_3c_integral_block_ctx(int_3c, ctx, ws, atom_j, atom_k, atom_i, cell_j, cell_k, cell_i, j_offset, k_offset, i_offset, screened)
Computes the 3c integral block (mu(atom_j) nu(atom_k) | P(atom_i)) for ONE atom triple,...
subroutine, public gw_3c_ws_create(ws, ctx)
Creates a per-thread 3c workspace: libint object + LIBXSMM contraction buffers.
subroutine, public gw_3c_ws_release(ws)
Releases a per-thread 3c workspace.
subroutine, public gw_3c_ctx_release(ctx)
Releases the shared 3c-integral context.
subroutine, public gw_3c_ctx_create(ctx, qs_env, potential_parameter, basis_j, basis_k, basis_i)
Builds the shared 3c-integral context: screening radii, basis maxima, contracted sphi tables,...
GW using RI-RS Approximation for molecules.
subroutine, public release_dbcsr_topology_and_matrices(dist, mapped_dist, m1, m2, m3, m4)
DBCSR matrices deallocation.
subroutine, public hadamard_product_inplace(matrix_a, matrix_b, fac)
In-place Hadamard A <- fac * (A ◦ B). Value mutation only (no block insert/delete),...
subroutine, public contract_a_b_a(transa_left, transa_right, matrix_a, matrix_b, matrix_out, eps_filter)
Generalized routine to compute OUT = A * B * A^T OR OUT = A^T * B * A using DBCSR.
subroutine, public gw_calc_large_cell_gamma_ri_rs(qs_env, bs_env)
GW calculation using RI-RS formalism for molecules.
subroutine, public setup_square_topology(matrix_template, dim_type, square_dist, blk_sizes, mapped_dist)
DBCSR Topology Generation.
Routines from paper [Graml2024].
subroutine, public compute_fm_chi_gamma_freq(bs_env, fm_chi_gamma_freq, j_w, mat_chi_gamma_tau)
...
subroutine, public delete_unnecessary_files(bs_env)
...
subroutine, public fill_fm_sigma_c_gamma_time(fm_sigma_c_gamma_time, bs_env, mat_sigma_pos_tau, mat_sigma_neg_tau)
...
subroutine, public fm_write(fm, matrix_index, matrix_name, qs_env)
...
subroutine, public compute_qp_energies(bs_env, qs_env, fm_sigma_x_gamma, fm_sigma_c_gamma_time)
...
subroutine, public multiply_fm_w_mic_time_with_minv_gamma(bs_env, qs_env, fm_w_mic_time)
...
subroutine, public get_w_mic(bs_env, qs_env, mat_chi_gamma_tau, fm_w_mic_time)
...
subroutine, public g_occ_vir(bs_env, tau, fm_g_gamma, ispin, occ, vir)
...
subroutine, public create_fm_w_mic_time(bs_env, fm_w_mic_time)
...
subroutine, public fourier_transform_w_to_t(bs_env, fm_w_mic_time, fm_w_mic_freq_j, j_w)
...
GW using RI-RS Approximation for molecules.
subroutine, public ri_rs_grid_assembler(qs_env, bs_env, ri_rs_grid_points)
Compute grid points for RI-RS Right now based on Ivan and Xavier implementation JCP 150,...
subroutine, public precompute_ri_rs_radii(qs_env, bs_env)
Compute per-atom AO and RI basis radii from the most diffuse Gaussian primitive in the AO ("ORB") and...
subroutine, public get_basis_offsets(particle_set, qs_kind_set, first_sgf, total_sgf)
Computes the AO basis offsets: first_sgf(iatom) is the global index of the first spherical Gaussian f...
subroutine, public solve_d_lp_distributed(phi_local, d_vec, d_lp, n_loc, n_ao, n_rhs, tikhonov, para_env_sub, blacs_env_sub, fm_struct_d, fm_struct_b, fm_d, fm_b, info)
Distributed pdpotrf/pdpotrs solve of D x = b for one atom of the RI-RS Z_lP build (Phase B,...
subroutine, public de_init_bs_env(qs_env, bs_env)
Releases the memory-heavy GW intermediates that cannot be freed in bs_env_release,...
Defines the basic variable types.
integer, parameter, public dp
Routines to compute the Coulomb integral V_(alpha beta)(k) for a k-point k using lattice summation in...
subroutine, public build_2c_coulomb_matrix_kp(matrix_v_kp, kpoints, basis_type, cell, particle_set, qs_kind_set, atomic_kind_set, size_lattice_sum, operator_type, ikp_start, ikp_end)
...
Machine interface based on Fortran 2003 and POSIX.
real(kind=dp) function, public m_walltime()
returns time from a real-time clock, protected against rolling early/easily
Interface to the message passing library MPI.
Framework for 2c-integrals for RI.
subroutine, public ri_2c_integral_mat(qs_env, fm_matrix_minv_l_kpoints, fm_matrix_l, dimen_ri, ri_metric, do_kpoints, kpoints, put_mat_ks_env, regularization_ri, ikp_ext, do_build_cell_index)
...
Provides Cartesian and spherical orbital pointers and indices.
integer, dimension(:), allocatable, public ncoset
integer, dimension(:, :), allocatable, public indco
basic linear algebra operations for full matrixes
Define the data structure for the particle information.
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, mimic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, matrix_vhxc, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, rhoz_cneo_set, ecoul_1c, rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, do_rixs, tb_tblite)
Get the QUICKSTEP environment.
Define the quickstep kind type and their sub types.
subroutine, public get_qs_kind(qs_kind, basis_set, basis_type, ncgf, nsgf, all_potential, tnadd_potential, gth_potential, sgp_potential, upf_potential, cneo_potential, se_parameter, dftb_parameter, xtb_parameter, dftb3_param, zatom, zeff, elec_conf, mao, lmax_dftb, alpha_core_charge, ccore_charge, core_charge, core_charge_radius, paw_proj_set, paw_atom, hard_radius, hard0_radius, max_rad_local, covalent_radius, vdw_radius, gpw_type_forced, harmonics, max_iso_not0, max_s_harm, grid_atom, ngrid_ang, ngrid_rad, lmax_rho0, dft_plus_u_atom, l_of_dft_plus_u, n_of_dft_plus_u, u_minus_j, hund_j, u_of_dft_plus_u, j_of_dft_plus_u, alpha_of_dft_plus_u, beta_of_dft_plus_u, j0_of_dft_plus_u, occupation_of_dft_plus_u, dispersion, bs_occupation, magnetization, no_optimize, addel, laddel, naddel, orbitals, max_scf, eps_scf, smear, u_ramping, u_minus_j_target, eps_u_ramping, proj_shell_charge, lr_atom, do_mtlr, u_j_loop, ao_coef, init_u_ramping_each_scf, reltmat, ghost, monovalent, floating, name, element_symbol, pao_basis_size, pao_model_file, pao_potentials, pao_descriptors, nelec)
Get attributes of an atomic kind.
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
represent a blacs multidimensional parallel environment (for the mpi corrispective see cp_paratypes/m...
keeps the information about the structure of a full matrix
type of a logger, at the moment it contains just a print level starting at which level it should be l...
Shared read-only context for repeated 3-center integral block builds: screening parameters,...
Per-thread workspace for 3-center integral block builds: libint object + contraction buffers....
stores all the informations relevant to an mpi environment
Provides all information about a quickstep kind.