30 dbcsr_type_no_symmetry
84#include "./base/base_uses.f90"
90 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'gw_large_cell_Gamma_ri_rs'
107 CHARACTER(LEN=*),
PARAMETER :: routinen =
'gw_calc_large_cell_Gamma_ri_rs'
110 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_sigma_x_gamma, fm_w_time
111 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :, :) :: fm_sigma_c_gamma_time
113 CALL timeset(routinen, handle)
137 CALL atomic_basis_at_grid_point(qs_env, bs_env, bs_env%ri_rs%grid_points, &
138 bs_env%ri_rs%mat_phi_mu_l)
153 CALL compute_coeff_z_lp(qs_env, bs_env, bs_env%ri_rs%grid_points, &
154 bs_env%ri_rs%mat_phi_mu_l, bs_env%ri_rs%mat_Z_lP)
165 CALL get_mat_chi_gamma_tau(bs_env, bs_env%mat_chi_Gamma_tau, &
166 bs_env%ri_rs%mat_phi_mu_l, bs_env%ri_rs%mat_Z_lP)
172 CALL get_w_mic(bs_env, qs_env, bs_env%mat_chi_Gamma_tau, fm_w_time)
182 CALL compute_sigma_x(bs_env, qs_env, bs_env%ri_rs%mat_phi_mu_l, &
183 bs_env%ri_rs%mat_Z_lP, fm_sigma_x_gamma)
192 CALL compute_sigma_c(bs_env, fm_w_time, bs_env%ri_rs%mat_phi_mu_l, &
193 bs_env%ri_rs%mat_Z_lP, fm_sigma_c_gamma_time)
204 CALL timestop(handle)
216 SUBROUTINE atomic_basis_at_grid_point(qs_env, bs_env, ri_rs_grid_points, mat_phi_mu_l)
220 REAL(kind=
dp),
ALLOCATABLE,
INTENT(INOUT) :: ri_rs_grid_points(:, :)
223 CHARACTER(LEN=*),
PARAMETER :: routinen =
'atomic_basis_at_grid_point'
225 INTEGER :: c_size, chunk_size, dimen_orb, handle, i, i_blk, iatom, natom, npcol, nprow, &
226 num_grid_chunks, r_end, r_start, total_grid_npts
227 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: first_sgf
228 INTEGER,
DIMENSION(:),
POINTER :: c_blk_sizes, col_dist, col_dist_ks, &
229 r_blk_sizes, row_dist, row_dist_ks
230 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: atom_col_buffer
237 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
239 CALL timeset(routinen, handle)
245 CALL get_qs_env(qs_env, cell=cell, atomic_kind_set=atomic_kind_set, &
246 qs_kind_set=qs_kind_set, particle_set=particle_set, &
249 natom =
SIZE(particle_set)
250 total_grid_npts =
SIZE(ri_rs_grid_points, 2)
253 ALLOCATE (first_sgf(natom + 1))
261 ALLOCATE (c_blk_sizes(natom))
263 c_blk_sizes(iatom) = first_sgf(iatom + 1) - first_sgf(iatom)
267 num_grid_chunks = ceiling(real(total_grid_npts, kind=
dp)/real(chunk_size, kind=
dp))
268 ALLOCATE (r_blk_sizes(num_grid_chunks))
269 r_blk_sizes = chunk_size
270 IF (mod(total_grid_npts, chunk_size) /= 0)
THEN
271 r_blk_sizes(num_grid_chunks) = mod(total_grid_npts, chunk_size)
275 CALL get_qs_env(qs_env, dbcsr_dist=dbcsr_dist_ks)
280 nprow = maxval(row_dist_ks) + 1
281 npcol = maxval(col_dist_ks) + 1
283 ALLOCATE (row_dist(num_grid_chunks))
284 DO i = 1, num_grid_chunks
285 row_dist(i) = mod(i - 1, nprow)
288 ALLOCATE (col_dist(natom))
290 col_dist(i) = mod(i - 1, npcol)
295 row_dist=row_dist, col_dist=col_dist)
297 CALL dbcsr_create(mat_phi_mu_l, name=
"phi_val_sparse", dist=dist, &
298 matrix_type=dbcsr_type_no_symmetry, &
299 row_blk_size=r_blk_sizes, col_blk_size=c_blk_sizes)
305 DO iatom = para_env%mepos + 1, natom, para_env%num_pe
307 c_size = c_blk_sizes(iatom)
310 ALLOCATE (atom_col_buffer(total_grid_npts, c_size))
311 atom_col_buffer = 0.0_dp
316 CALL fill_phi_for_atom(atom_col_buffer, ri_rs_grid_points, total_grid_npts, &
317 iatom, particle_set, qs_kind_set, cell, &
318 r2_threshold=bs_env%ri_rs%radius_ao_per_atom(iatom)**2)
321 DO i_blk = 1, num_grid_chunks
322 r_start = (i_blk - 1)*chunk_size + 1
323 r_end = min(i_blk*chunk_size, total_grid_npts)
326 IF (maxval(abs(atom_col_buffer(r_start:r_end, 1:c_size))) > bs_env%eps_filter)
THEN
328 block=atom_col_buffer(r_start:r_end, 1:c_size))
332 DEALLOCATE (atom_col_buffer)
339 IF (bs_env%unit_nr > 0)
THEN
340 WRITE (bs_env%unit_nr, *)
"Done with evaluation of phi"
346 DEALLOCATE (first_sgf, r_blk_sizes, c_blk_sizes, row_dist, col_dist)
349 CALL timestop(handle)
351 END SUBROUTINE atomic_basis_at_grid_point
370 SUBROUTINE fill_phi_for_atom(phi_val, ri_rs_grid, npts, iatom, &
371 particle_set, qs_kind_set, cell, r2_threshold)
373 REAL(kind=
dp),
INTENT(INOUT) :: phi_val(:, :)
374 INTEGER,
INTENT(IN) :: npts
375 REAL(kind=
dp),
INTENT(IN) :: ri_rs_grid(3, npts)
376 INTEGER,
INTENT(IN) :: iatom
378 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
380 REAL(kind=
dp),
INTENT(IN) :: r2_threshold
382 INTEGER :: first_sgf, i_pt, ico, iend_co, ikind, ipgf, iset, isgf, ishell, istart_co, ix, &
383 ix_max, ix_min, iy, iy_max, iy_min, iz, iz_max, iz_min, l, last_sgf, lx, ly, lz, &
384 n_cart_total, row_idx
385 REAL(kind=
dp) :: alpha, cell_vector(3), dist_vec(3), &
386 dist_vec_raw(3), exp_val, poly, r2, &
388 REAL(kind=
dp),
DIMENSION(3, 3) :: hmat
392 ikind = particle_set(iatom)%atomic_kind%kind_number
393 CALL get_qs_kind(qs_kind_set(ikind), basis_set=orb_basis_set, basis_type=
"ORB")
396 IF (.NOT.
ASSOCIATED(orb_basis_set))
RETURN
398 IF (cell%perd(1) == 1) then; ix_min = -1; ix_max = 1; else; ix_min = 0; ix_max = 0;
END IF
399 IF (cell%perd(2) == 1) then; iy_min = -1; iy_max = 1; else; iy_min = 0; iy_max = 0;
END IF
400 IF (cell%perd(3) == 1) then; iz_min = -1; iz_max = 1; else; iz_min = 0; iz_max = 0;
END IF
402 r_atom = particle_set(iatom)%r
415 dist_vec_raw = ri_rs_grid(:, i_pt) - r_atom
417 DO ix = ix_min, ix_max
418 DO iy = iy_min, iy_max
419 DO iz = iz_min, iz_max
421 cell_vector(1:3) = matmul(hmat, real([ix, iy, iz],
dp))
423 dist_vec = dist_vec_raw - cell_vector
425 r2 = dot_product(dist_vec, dist_vec)
427 IF (r2 > r2_threshold) cycle
429 DO iset = 1, orb_basis_set%nset
430 n_cart_total =
ncoset(orb_basis_set%lmax(iset))
432 DO ishell = 1, orb_basis_set%nshell(iset)
433 l = orb_basis_set%l(ishell, iset)
434 istart_co =
ncoset(l - 1) + 1
437 first_sgf = orb_basis_set%first_sgf(ishell, iset)
438 last_sgf = orb_basis_set%last_sgf(ishell, iset)
440 DO ipgf = 1, orb_basis_set%npgf(iset)
441 alpha = orb_basis_set%zet(ipgf, iset)
442 exp_val = exp(-alpha*r2)
444 DO isgf = first_sgf, last_sgf
445 DO ico = istart_co, iend_co
446 row_idx = (ipgf - 1)*n_cart_total + ico
447 weight = orb_basis_set%sphi(row_idx, isgf)
451 poly = (dist_vec(1)**lx)*(dist_vec(2)**ly)*(dist_vec(3)**lz)
453 phi_val(i_pt, isgf) = phi_val(i_pt, isgf) + (weight*poly*exp_val)
466 END SUBROUTINE fill_phi_for_atom
477 SUBROUTINE compute_coeff_z_lp(qs_env, bs_env, ri_rs_grid_points, mat_phi_mu_l, mat_Z_lP)
482 REAL(kind=
dp),
ALLOCATABLE,
INTENT(INOUT) :: ri_rs_grid_points(:, :)
483 TYPE(
dbcsr_type),
INTENT(INOUT) :: mat_phi_mu_l
486 CHARACTER(LEN=*),
PARAMETER :: key =
'PROPERTIES%BANDSTRUCTURE%GW%PRINT%RESTART', &
487 routinen =
'compute_coeff_Z_lP'
489 INTEGER :: atom_j_mepos, atom_j_stride, atom_p, atom_p_start, atom_p_stride, col_end, &
490 col_start, current_chunk_size, g, group_handle, handle, i, i_blk, ikind, info, j, j_ri, &
491 l, loc_idx, loc_ptr, max_ao_size, max_loc_ri, my_group, n_ao_total, n_grid_total, &
492 n_groups, n_loc_ri, n_local_grid, n_procs_per_atom, natom, nkind, num_grid_chunks, &
493 p_loop_atom, r_end, r_start, source_atom
494 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: local_grid_idx, row_offset
495 INTEGER,
DIMENSION(:),
POINTER :: col_dist_phi, col_dist_ri, r_blk_sizes, &
496 ri_blk_sizes, row_dist_grid
497 REAL(kind=
dp) :: cutoff_ri, cutoff_ri_2, d_sp, dist2_min, &
498 r2_threshold, r_c, t1, t2, t3
499 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: cutoff_ri_per_atom, cutoff_ri_per_kind, &
501 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: d_local, d_lp_local, phi_local, &
503 REAL(kind=
dp),
DIMENSION(3) :: dist_vec_raw, pos_p
514 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
517 CALL timeset(routinen, handle)
521 CALL get_qs_env(qs_env, para_env=para_env, particle_set=particle_set, input=input, &
522 cell=cell, qs_kind_set=qs_kind_set, atomic_kind_set=atomic_kind_set)
532 n_procs_per_atom = min(bs_env%ri_rs%n_procs_per_atom_z_lp, para_env%num_pe)
533 IF (n_procs_per_atom < 1) n_procs_per_atom = 1
535 NULLIFY (para_env_sub, blacs_env_sub)
536 IF (n_procs_per_atom > 1)
THEN
537 n_groups = para_env%num_pe/n_procs_per_atom
538 my_group = min(para_env%mepos/n_procs_per_atom, n_groups - 1)
539 ALLOCATE (para_env_sub)
540 CALL para_env_sub%from_split(para_env, my_group)
542 atom_p_start = my_group + 1
543 atom_p_stride = n_groups
544 atom_j_mepos = para_env_sub%mepos
545 atom_j_stride = para_env_sub%num_pe
547 atom_p_start = para_env%mepos + 1
548 atom_p_stride = para_env%num_pe
553 natom =
SIZE(bs_env%i_RI_start_from_atom)
554 n_ao_total = bs_env%i_ao_end_from_atom(natom)
555 n_grid_total =
SIZE(ri_rs_grid_points, 2)
560 CALL dbcsr_get_info(mat_phi_mu_l, row_blk_size=r_blk_sizes, distribution=dist_phi)
563 num_grid_chunks =
SIZE(r_blk_sizes)
565 ALLOCATE (row_offset(num_grid_chunks))
567 DO i_blk = 2, num_grid_chunks
568 row_offset(i_blk) = row_offset(i_blk - 1) + r_blk_sizes(i_blk - 1)
571 ALLOCATE (ri_blk_sizes(natom), col_dist_ri(natom))
573 ri_blk_sizes(atom_p) = bs_env%i_RI_end_from_atom(atom_p) - bs_env%i_RI_start_from_atom(atom_p) + 1
574 col_dist_ri(atom_p) = mod(atom_p - 1, maxval(col_dist_phi) + 1)
579 IF (bs_env%ri_rs%Z_lP_exists)
THEN
581 distribution=dist_z, &
583 IF (bs_env%unit_nr > 0)
THEN
584 WRITE (bs_env%unit_nr,
'(T2,A,T57,A,F7.1,A)') &
585 'Read Z_lP from file ',
' Execution time',
m_walltime() - t1,
' s'
586 WRITE (bs_env%unit_nr,
'(A)')
' '
590 CALL dbcsr_create(mat_z_lp, name=
"mat_Z_lP", dist=dist_z, &
591 matrix_type=dbcsr_type_no_symmetry, &
592 row_blk_size=r_blk_sizes, col_blk_size=ri_blk_sizes)
595 DO j = 1,
SIZE(bs_env%i_ao_start_from_atom)
596 max_ao_size = max(max_ao_size, bs_env%i_ao_end_from_atom(j) - bs_env%i_ao_start_from_atom(j) + 1)
598 max_loc_ri = maxval(ri_blk_sizes)
604 nkind =
SIZE(atomic_kind_set)
605 ALLOCATE (cutoff_ri_per_atom(natom))
607 IF (bs_env%ri_rs%cutoff_radius_ri_rs > 0.0_dp)
THEN
608 cutoff_ri_per_atom(:) = bs_env%ri_rs%cutoff_radius_ri_rs
610 r_c = bs_env%ri_metric%cutoff_radius
611 DO p_loop_atom = 1, natom
612 cutoff_ri_per_atom(p_loop_atom) = &
613 r_c + bs_env%ri_rs%radius_ao_per_atom(p_loop_atom)
617 ALLOCATE (cutoff_ri_per_kind(nkind))
618 cutoff_ri_per_kind(:) = 0.0_dp
619 IF (bs_env%unit_nr > 0)
THEN
620 DO p_loop_atom = 1, natom
621 ikind = particle_set(p_loop_atom)%atomic_kind%kind_number
622 cutoff_ri_per_kind(ikind) = max(cutoff_ri_per_kind(ikind), &
623 cutoff_ri_per_atom(p_loop_atom))
625 WRITE (bs_env%unit_nr,
'(T2,A)')
'Per-kind maximum RI-RS sphere cutoff (Bohr):'
626 WRITE (bs_env%unit_nr,
'(T4,A4,A14)')
'Kind',
'max cutoff_ri'
628 WRITE (bs_env%unit_nr,
'(T4,A4,F14.4)') &
629 atomic_kind_set(ikind)%element_symbol, &
630 cutoff_ri_per_kind(ikind)
632 WRITE (bs_env%unit_nr,
'(A)')
' '
633 DEALLOCATE (cutoff_ri_per_kind)
641 basis_j=bs_env%basis_set_AO, basis_k=bs_env%basis_set_AO, &
642 basis_i=bs_env%basis_set_RI)
649 DO atom_p = atom_p_start, natom, atom_p_stride
651 n_loc_ri = ri_blk_sizes(atom_p)
652 pos_p(:) = particle_set(atom_p)%r(:)
654 cutoff_ri = cutoff_ri_per_atom(atom_p)
655 cutoff_ri_2 = cutoff_ri**2
661 DO l = 1, n_grid_total
662 dist_vec_raw =
pbc(ri_rs_grid_points(1:3, l), pos_p(1:3), cell)
663 dist2_min = dot_product(dist_vec_raw, dist_vec_raw)
664 IF (dist2_min <= cutoff_ri_2) n_local_grid = n_local_grid + 1
667 ALLOCATE (local_grid_idx(n_local_grid))
670 DO l = 1, n_grid_total
671 dist_vec_raw =
pbc(ri_rs_grid_points(1:3, l), pos_p(1:3), cell)
672 dist2_min = dot_product(dist_vec_raw, dist_vec_raw)
673 IF (dist2_min <= cutoff_ri_2)
THEN
674 n_local_grid = n_local_grid + 1
675 local_grid_idx(n_local_grid) = l
686 ALLOCATE (sphere_grid(3, n_local_grid))
687 DO loc_idx = 1, n_local_grid
688 sphere_grid(:, loc_idx) = ri_rs_grid_points(:, local_grid_idx(loc_idx))
691 ALLOCATE (phi_local(n_local_grid, n_ao_total))
694 DO source_atom = 1, natom
695 dist_vec_raw =
pbc(particle_set(source_atom)%r(:), pos_p(:), cell)
696 d_sp = norm2(dist_vec_raw)
697 IF (d_sp > bs_env%ri_rs%radius_ao_per_atom(source_atom) + cutoff_ri) cycle
699 col_start = bs_env%i_ao_start_from_atom(source_atom)
700 col_end = bs_env%i_ao_end_from_atom(source_atom)
701 r2_threshold = bs_env%ri_rs%radius_ao_per_atom(source_atom)**2
703 CALL fill_phi_for_atom(phi_local(:, col_start:col_end), sphere_grid, &
704 n_local_grid, source_atom, particle_set, qs_kind_set, &
708 DEALLOCATE (sphere_grid)
715 ALLOCATE (d_lp_local(n_local_grid, n_loc_ri))
720 CALL compute_d_lp(bs_env, ctx_3c, cell, phi_local, d_lp_local, n_local_grid, &
721 n_loc_ri, atom_p, max_ao_size, atom_j_mepos, atom_j_stride)
725 IF (n_procs_per_atom > 1)
THEN
726 CALL para_env_sub%sum(d_lp_local)
734 ALLOCATE (d_vec_local(n_local_grid))
736 IF (n_procs_per_atom == 1)
THEN
740 ALLOCATE (d_local(n_local_grid, n_local_grid))
743 CALL dsyrk(
"L",
"N", n_local_grid, n_ao_total, 1.0_dp, phi_local, &
744 n_local_grid, 0.0_dp, d_local, n_local_grid)
750 DO i = 1, n_local_grid
751 d_local(i, i) = d_local(i, i)**2
752 d_vec_local(i) = 1.0_dp/sqrt(max(d_local(i, i), 1.0e-16_dp))
753 d_local(i, i) = (d_local(i, i)*d_vec_local(i)**2) + bs_env%ri_rs%tikhonov
761 DO j = 1, n_local_grid
762 DO i = j + 1, n_local_grid
763 d_local(i, j) = d_local(i, j)**2
764 d_local(i, j) = d_local(i, j)*d_vec_local(i)*d_vec_local(j)
765 d_local(j, i) = d_local(i, j)
777 DO i = 1, n_local_grid
778 d_vec_local(i) = 0.0_dp
780 d_vec_local(i) = d_vec_local(i) + phi_local(i, j)*phi_local(i, j)
782 d_vec_local(i) = 1.0_dp/max(d_vec_local(i), 1.0e-16_dp)
794 DO j_ri = 1, n_loc_ri
795 DO i = 1, n_local_grid
796 d_lp_local(i, j_ri) = d_lp_local(i, j_ri)*d_vec_local(i)
804 IF (n_procs_per_atom == 1)
THEN
805 CALL dpotrf(
'L', n_local_grid, d_local, n_local_grid, info)
806 CALL dpotrs(
'L', n_local_grid, n_loc_ri, d_local, n_local_grid, &
807 d_lp_local, n_local_grid, info)
811 n_local_grid, n_ao_total, n_loc_ri, &
812 bs_env%ri_rs%tikhonov, &
813 para_env_sub, blacs_env_sub, &
814 fm_struct_d, fm_struct_b, fm_d, fm_b, info)
824 DO j_ri = 1, n_loc_ri
825 DO i = 1, n_local_grid
826 d_lp_local(i, j_ri) = d_lp_local(i, j_ri)*d_vec_local(i)
840 IF (n_procs_per_atom == 1 .OR. para_env_sub%mepos == 0)
THEN
841 ALLOCATE (z_blk(maxval(r_blk_sizes), n_loc_ri))
844 DO i_blk = 1, num_grid_chunks
845 r_start = row_offset(i_blk) + 1
846 r_end = row_offset(i_blk) + r_blk_sizes(i_blk)
847 current_chunk_size = r_blk_sizes(i_blk)
851 DO WHILE (loc_ptr <= n_local_grid)
852 g = local_grid_idx(loc_ptr)
854 z_blk(g - r_start + 1, 1:n_loc_ri) = d_lp_local(loc_ptr, 1:n_loc_ri)
855 loc_ptr = loc_ptr + 1
858 IF (maxval(abs(z_blk(1:current_chunk_size, 1:n_loc_ri))) > bs_env%eps_filter)
THEN
860 block=z_blk(1:current_chunk_size, 1:n_loc_ri))
867 DEALLOCATE (d_vec_local, d_lp_local)
868 DEALLOCATE (local_grid_idx, phi_local)
872 DEALLOCATE (cutoff_ri_per_atom)
877 IF (bs_env%unit_nr > 0)
THEN
878 WRITE (bs_env%unit_nr,
'(T2,A,T57,A,F7.1,A)') &
879 'Computed Z_lP ',
' Execution time',
m_walltime() - t1,
' s'
880 WRITE (bs_env%unit_nr,
'(A)')
' '
891 DEALLOCATE (row_offset, ri_blk_sizes, col_dist_ri)
894 IF (n_procs_per_atom > 1)
THEN
896 CALL para_env_sub%free()
897 DEALLOCATE (para_env_sub)
900 DEALLOCATE (ri_rs_grid_points)
902 CALL timestop(handle)
904 END SUBROUTINE compute_coeff_z_lp
927 SUBROUTINE compute_d_lp(bs_env, ctx, cell, phi_val, d_lp, n_grid_total, n_loc_ri, atom_P, &
928 max_ao_size, atom_j_mepos, atom_j_stride)
933 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(IN) :: phi_val
934 INTEGER,
INTENT(IN) :: n_grid_total, n_loc_ri
935 REAL(kind=
dp),
INTENT(INOUT) :: d_lp(n_grid_total, n_loc_ri)
936 INTEGER,
INTENT(IN) :: atom_p, max_ao_size, atom_j_mepos, &
939 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_d_lp'
940 INTEGER,
PARAMETER :: grid_chunk = 1024
942 INTEGER :: atom_j, atom_k, c, handle, ix_max, ix_min, ix_r, ix_s, iy_max, iy_min, iy_r, &
943 iy_s, iz_max, iz_min, iz_r, iz_s, j, jk_idx, jsize, jstart, k, ksize, kstart, l, l0, &
945 INTEGER,
DIMENSION(3) :: cell_r_vec, cell_s_vec
946 LOGICAL :: any_kept, screened
947 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: int_2d_prv, rho_chunk
948 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :) :: int_3c_prv, int_3c_sum
951 CALL timeset(routinen, handle)
953 natom =
SIZE(bs_env%i_ao_start_from_atom)
955 IF (cell%perd(1) == 1) then; ix_min = -1; ix_max = 1; else; ix_min = 0; ix_max = 0;
END IF
956 IF (cell%perd(2) == 1) then; iy_min = -1; iy_max = 1; else; iy_min = 0; iy_max = 0;
END IF
957 IF (cell%perd(3) == 1) then; iz_min = -1; iz_max = 1; else; iz_min = 0; iz_max = 0;
END IF
968 ALLOCATE (int_3c_prv(max_ao_size, max_ao_size, n_loc_ri))
969 ALLOCATE (int_3c_sum(max_ao_size, max_ao_size, n_loc_ri))
970 ALLOCATE (int_2d_prv(max_ao_size*max_ao_size, n_loc_ri))
971 ALLOCATE (rho_chunk(grid_chunk, max_ao_size*max_ao_size))
981 DO atom_j = atom_j_mepos + 1, natom, atom_j_stride
983 jstart = bs_env%i_ao_start_from_atom(atom_j)
984 jsize = bs_env%i_ao_end_from_atom(atom_j) - jstart + 1
985 kstart = bs_env%i_ao_start_from_atom(atom_k)
986 ksize = bs_env%i_ao_end_from_atom(atom_k) - kstart + 1
988 int_3c_sum(1:jsize, 1:ksize, 1:n_loc_ri) = 0.0_dp
991 DO ix_r = ix_min, ix_max
992 DO iy_r = iy_min, iy_max
993 DO iz_r = iz_min, iz_max
994 cell_r_vec = [ix_r, iy_r, iz_r]
995 DO ix_s = ix_min, ix_max
996 DO iy_s = iy_min, iy_max
997 DO iz_s = iz_min, iz_max
998 cell_s_vec = [ix_s, iy_s, iz_s]
1000 int_3c_prv(1:jsize, 1:ksize, 1:n_loc_ri) = 0.0_dp
1003 int_3c_prv(1:jsize, 1:ksize, 1:n_loc_ri), ctx, ws, &
1004 atom_j=atom_j, atom_k=atom_k, atom_i=atom_p, &
1005 cell_j=cell_r_vec, cell_k=cell_s_vec, cell_i=[0, 0, 0], &
1010 int_3c_sum(1:jsize, 1:ksize, 1:n_loc_ri) = &
1011 int_3c_sum(1:jsize, 1:ksize, 1:n_loc_ri) + &
1012 int_3c_prv(1:jsize, 1:ksize, 1:n_loc_ri)
1020 IF (.NOT. any_kept) cycle
1026 jk_idx = (k - 1)*jsize + j
1027 int_2d_prv(jk_idx, ri) = int_3c_sum(j, k, ri)
1034 DO l0 = 1, n_grid_total, grid_chunk
1035 c = min(grid_chunk, n_grid_total - l0 + 1)
1038 jk_idx = (k - 1)*jsize + j
1040 rho_chunk(l, jk_idx) = phi_val(l0 + l - 1, jstart + j - 1)* &
1041 phi_val(l0 + l - 1, kstart + k - 1)
1045 CALL dgemm(
"N",
"N", c, n_loc_ri, jsize*ksize, &
1046 1.0_dp, rho_chunk, grid_chunk, &
1047 int_2d_prv, max_ao_size*max_ao_size, &
1048 1.0_dp, d_lp(l0, 1), n_grid_total)
1054 DEALLOCATE (int_3c_prv, int_3c_sum, int_2d_prv, rho_chunk)
1059 CALL timestop(handle)
1061 END SUBROUTINE compute_d_lp
1071 SUBROUTINE get_mat_chi_gamma_tau(bs_env, mat_chi_Gamma_tau, mat_phi_mu_l, mat_Z_lP)
1074 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: mat_chi_gamma_tau
1075 TYPE(
dbcsr_type),
INTENT(INOUT) :: mat_phi_mu_l, mat_z_lp
1077 CHARACTER(LEN=*),
PARAMETER :: routinen =
'get_mat_chi_Gamma_tau'
1079 INTEGER :: handle, i, i_t, ispin, npcol
1080 INTEGER,
DIMENSION(:),
POINTER :: blk_ao, blk_grid, dist_col_ao, &
1081 dist_col_grid, dist_row_grid
1082 REAL(kind=
dp) :: t1, tau
1084 TYPE(
dbcsr_type) :: matrix_chi_grid, matrix_chi_grid_spin, &
1085 matrix_g_occ_grid, matrix_g_vir_grid
1087 CALL timeset(routinen, handle)
1092 CALL dbcsr_get_info(mat_phi_mu_l, distribution=dist_phi, row_blk_size=blk_grid, col_blk_size=blk_ao)
1096 npcol = maxval(dist_col_ao) + 1
1099 ALLOCATE (dist_col_grid(
SIZE(blk_grid)))
1100 DO i = 1,
SIZE(blk_grid)
1101 dist_col_grid(i) = mod(i - 1, npcol)
1105 row_dist=dist_row_grid, col_dist=dist_col_grid)
1107 CALL dbcsr_create(matrix_g_occ_grid,
"G_occ_grid", dist_grid_grid, dbcsr_type_no_symmetry, blk_grid, blk_grid)
1108 CALL dbcsr_create(matrix_g_vir_grid,
"G_vir_grid", dist_grid_grid, dbcsr_type_no_symmetry, blk_grid, blk_grid)
1109 CALL dbcsr_create(matrix_chi_grid,
"chi_grid", dist_grid_grid, dbcsr_type_no_symmetry, blk_grid, blk_grid)
1110 CALL dbcsr_create(matrix_chi_grid_spin,
"chi_grid_spin", dist_grid_grid, dbcsr_type_no_symmetry, blk_grid, blk_grid)
1115 DO i_t = 1, bs_env%num_time_freq_points
1118 tau = bs_env%imag_time_points(i_t)
1124 DO ispin = 1, bs_env%n_spin
1128 CALL build_g_grid(bs_env, tau, ispin, .true., .false., mat_phi_mu_l, &
1129 matrix_g_occ_grid, bs_env%eps_filter)
1133 CALL build_g_grid(bs_env, tau, ispin, .false., .true., mat_phi_mu_l, &
1134 matrix_g_vir_grid, bs_env%eps_filter)
1140 CALL hadamard_product(matrix_g_occ_grid, matrix_g_vir_grid, matrix_chi_grid_spin, bs_env%spin_degeneracy)
1143 CALL dbcsr_add(matrix_chi_grid, matrix_chi_grid_spin, 1.0_dp, 1.0_dp)
1153 CALL contract_a_b_a(
"T",
"N", mat_z_lp, matrix_chi_grid, &
1154 mat_chi_gamma_tau(i_t)%matrix, bs_env%eps_filter)
1156 IF (bs_env%unit_nr > 0)
THEN
1157 WRITE (bs_env%unit_nr,
'(T2,A,I13,A,I3,A,F7.1,A)') &
1158 χτ
'Computed (i,k=0) for time point', i_t,
' /', bs_env%num_time_freq_points, &
1172 DEALLOCATE (dist_col_grid)
1174 IF (bs_env%unit_nr > 0)
WRITE (bs_env%unit_nr,
'(A)')
' '
1176 CALL timestop(handle)
1178 END SUBROUTINE get_mat_chi_gamma_tau
1192 SUBROUTINE build_g_grid(bs_env, tau, ispin, occ, vir, mat_phi_mu_l, matrix_G_grid, eps_filter)
1195 REAL(kind=
dp),
INTENT(IN) :: tau
1196 INTEGER,
INTENT(IN) :: ispin
1197 LOGICAL,
INTENT(IN) :: occ, vir
1198 TYPE(
dbcsr_type),
INTENT(INOUT) :: mat_phi_mu_l, matrix_g_grid
1199 REAL(kind=
dp),
INTENT(IN) :: eps_filter
1201 CHARACTER(LEN=*),
PARAMETER :: routinen =
'build_G_grid'
1204 INTEGER,
DIMENSION(:),
POINTER :: blk_ao, dist_row_ao
1209 CALL timeset(routinen, handle)
1213 fm_g => bs_env%fm_Gocc
1215 fm_g => bs_env%fm_Gvir
1220 CALL g_occ_vir(bs_env, tau, fm_g, ispin, occ=occ, vir=vir)
1223 CALL setup_square_topology(mat_phi_mu_l,
'COL', dist_ao_ao, blk_ao, dist_row_ao)
1225 CALL dbcsr_create(matrix_g_ao, name=
"G_ao", dist=dist_ao_ao, &
1226 matrix_type=dbcsr_type_no_symmetry, &
1227 row_blk_size=blk_ao, col_blk_size=blk_ao)
1234 CALL contract_a_b_a(
"N",
"T", mat_phi_mu_l, matrix_g_ao, matrix_g_grid, eps_filter)
1237 CALL release_dbcsr_topology_and_matrices(dist=dist_ao_ao, mapped_dist=dist_row_ao, m1=matrix_g_ao)
1239 CALL timestop(handle)
1241 END SUBROUTINE build_g_grid
1253 SUBROUTINE contract_a_b_a(transA_left, transA_right, matrix_A, matrix_B, matrix_out, eps_filter)
1255 CHARACTER(LEN=1),
INTENT(IN) :: transa_left, transa_right
1256 TYPE(
dbcsr_type),
INTENT(INOUT) :: matrix_a, matrix_b, matrix_out
1257 REAL(kind=
dp),
INTENT(IN) :: eps_filter
1259 CHARACTER(LEN=*),
PARAMETER :: routinen =
'contract_A_B_A'
1264 CALL timeset(routinen, handle)
1268 IF (transa_left ==
"N" .AND. transa_right ==
"T")
THEN
1271 0.0_dp, matrix_tmp, filter_eps=eps_filter)
1273 0.0_dp, matrix_out, filter_eps=eps_filter)
1275 ELSE IF (transa_left ==
"T" .AND. transa_right ==
"N")
THEN
1278 0.0_dp, matrix_tmp, filter_eps=eps_filter)
1280 0.0_dp, matrix_out, filter_eps=eps_filter)
1282 cpabort(
"Unsupported transposition pair in contract_A_B_A")
1287 CALL timestop(handle)
1289 END SUBROUTINE contract_a_b_a
1299 SUBROUTINE hadamard_product(matrix_A, matrix_B, matrix_C, fac)
1301 TYPE(
dbcsr_type),
INTENT(INOUT) :: matrix_a, matrix_b, matrix_c
1302 REAL(kind=
dp),
INTENT(IN) ::
fac
1304 CHARACTER(LEN=*),
PARAMETER :: routinen =
'hadamard_product'
1306 INTEGER :: col, handle, row
1308 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: blk_b, blk_c
1311 CALL timeset(routinen, handle)
1322 blk_c(:, :) =
fac*blk_c(:, :)*blk_b(:, :)
1325 blk_c(:, :) = 0.0_dp
1330 CALL timestop(handle)
1332 END SUBROUTINE hadamard_product
1342 SUBROUTINE compute_w(bs_env, qs_env, mat_chi_Gamma_tau, fm_W_time)
1345 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: mat_chi_gamma_tau
1346 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_w_time
1348 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_W'
1350 INTEGER :: handle, i_t, j_w
1352 TYPE(
cp_fm_type) :: fm_m_inv_v_sqrt, fm_v, fm_v_sqrt
1354 CALL timeset(routinen, handle)
1362 CALL cp_fm_create(fm_v_sqrt, bs_env%fm_RI_RI%matrix_struct)
1363 CALL cp_fm_create(fm_m_inv_v_sqrt, bs_env%fm_RI_RI%matrix_struct)
1366 CALL compute_v_minvvsqrt(bs_env, qs_env, fm_v, fm_v_sqrt, fm_m_inv_v_sqrt)
1369 DO j_w = 1, bs_env%num_time_freq_points
1375 CALL compute_fm_w_freq(bs_env, bs_env%fm_chi_Gamma_freq, fm_v_sqrt, &
1376 fm_m_inv_v_sqrt, bs_env%fm_W_MIC_freq)
1385 IF (bs_env%unit_nr > 0)
THEN
1386 WRITE (bs_env%unit_nr,
'(T2,A,T55,A,F10.1,A)') &
1387 τ
'Computed W(i),',
' Execution time',
m_walltime() - t1,
' s'
1400 CALL cp_fm_create(bs_env%fm_W_MIC_freq_zero, bs_env%fm_W_MIC_freq%matrix_struct)
1404 DO i_t = 1, bs_env%num_time_freq_points
1407 bs_env%imag_time_weights_freq_zero(i_t), fm_w_time(i_t))
1410 CALL fm_write(bs_env%fm_W_MIC_freq_zero, 0,
"W_freq_rtp", qs_env)
1412 IF (bs_env%unit_nr > 0)
THEN
1413 WRITE (bs_env%unit_nr,
'(T2,A,T55,A,F10.1,A)') &
1414 'Computed W(0),',
' Execution time',
m_walltime() - t1,
' s'
1418 IF (bs_env%unit_nr > 0)
WRITE (bs_env%unit_nr,
'(A)')
' '
1420 CALL timestop(handle)
1422 END SUBROUTINE compute_w
1433 SUBROUTINE compute_v_minvvsqrt(bs_env, qs_env, fm_V, fm_V_sqrt, fm_Minv_Vsqrt)
1436 TYPE(
cp_fm_type),
INTENT(INOUT) :: fm_v, fm_v_sqrt, fm_minv_vsqrt
1438 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_V_MinvVsqrt'
1440 INTEGER :: handle, info, n_ri, ndep
1444 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: fm_m
1445 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: mat_v_kp
1447 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
1449 CALL timeset(routinen, handle)
1457 CALL get_qs_env(qs_env=qs_env, particle_set=particle_set, cell=cell, &
1458 qs_kind_set=qs_kind_set, atomic_kind_set=atomic_kind_set)
1460 ALLOCATE (mat_v_kp(1:1, 1:2))
1461 NULLIFY (mat_v_kp(1, 1)%matrix, mat_v_kp(1, 2)%matrix)
1462 ALLOCATE (mat_v_kp(1, 1)%matrix, mat_v_kp(1, 2)%matrix)
1464 CALL dbcsr_create(mat_v_kp(1, 1)%matrix, template=bs_env%mat_RI_RI%matrix)
1466 CALL dbcsr_set(mat_v_kp(1, 1)%matrix, 0.0_dp)
1469 CALL dbcsr_create(mat_v_kp(1, 2)%matrix, template=bs_env%mat_RI_RI%matrix)
1471 CALL dbcsr_set(mat_v_kp(1, 2)%matrix, 0.0_dp)
1473 bs_env%kpoints_chi_eps_W%nkp_grid = bs_env%nkp_grid_chi_eps_W_orig
1476 particle_set, qs_kind_set, atomic_kind_set, &
1484 DEALLOCATE (mat_v_kp)
1490 do_kpoints=.false., regularization_ri=bs_env%regularization_RI)
1501 CALL cp_fm_power(fm_m(1, 1), fm_work, -1.0_dp, bs_env%eps_eigval_mat_RI, ndep)
1511 CALL clean_lower_part(fm_v_sqrt)
1513 CALL cp_fm_power(fm_v, fm_v_sqrt, 0.5_dp, bs_env%eps_eigval_mat_RI, ndep)
1519 CALL parallel_gemm(
"N",
"T", n_ri, n_ri, n_ri, 1.0_dp, fm_m(1, 1), fm_v_sqrt, &
1520 0.0_dp, fm_minv_vsqrt)
1525 CALL timestop(handle)
1527 END SUBROUTINE compute_v_minvvsqrt
1538 SUBROUTINE compute_fm_w_freq(bs_env, fm_chi_freq_j, fm_V_sqrt, fm_Minv_Vsqrt, fm_W_freq_j)
1540 TYPE(
cp_fm_type),
INTENT(IN) :: fm_chi_freq_j, fm_v_sqrt, fm_minv_vsqrt
1541 TYPE(
cp_fm_type),
INTENT(INOUT) :: fm_w_freq_j
1543 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_fm_W_freq'
1545 INTEGER :: handle, info, n_ri, ndep
1548 CALL timeset(routinen, handle)
1552 CALL cp_fm_create(fm_eps_freq_j, fm_chi_freq_j%matrix_struct)
1553 CALL cp_fm_create(fm_work, fm_chi_freq_j%matrix_struct)
1560 fm_chi_freq_j, fm_minv_vsqrt, 0.0_dp, fm_work)
1564 fm_minv_vsqrt, fm_work, 0.0_dp, fm_eps_freq_j)
1567 CALL fm_add_on_diag(fm_eps_freq_j, 1.0_dp)
1585 CALL cp_fm_power(fm_eps_freq_j, fm_work, -1.0_dp, bs_env%eps_eigval_mat_RI, ndep)
1590 CALL fm_add_on_diag(fm_eps_freq_j, -1.0_dp)
1593 CALL parallel_gemm(
'N',
'N', n_ri, n_ri, n_ri, 1.0_dp, fm_eps_freq_j, fm_v_sqrt, &
1597 CALL parallel_gemm(
'T',
'N', n_ri, n_ri, n_ri, 1.0_dp, fm_v_sqrt, fm_work, &
1598 0.0_dp, fm_w_freq_j)
1604 CALL timestop(handle)
1606 END SUBROUTINE compute_fm_w_freq
1614 SUBROUTINE fm_add_on_diag(fm, alpha)
1616 REAL(kind=
dp),
INTENT(IN) :: alpha
1618 CHARACTER(LEN=*),
PARAMETER :: routinen =
'fm_add_on_diag'
1620 INTEGER :: handle, i_global, i_row, j_col, &
1621 j_global, ncol_local, nrow_local
1622 INTEGER,
DIMENSION(:),
POINTER :: col_indices, row_indices
1624 CALL timeset(routinen, handle)
1627 nrow_local=nrow_local, &
1628 ncol_local=ncol_local, &
1629 row_indices=row_indices, &
1630 col_indices=col_indices)
1632 DO j_col = 1, ncol_local
1633 j_global = col_indices(j_col)
1634 DO i_row = 1, nrow_local
1635 i_global = row_indices(i_row)
1636 IF (j_global == i_global)
THEN
1637 fm%local_data(i_row, j_col) = fm%local_data(i_row, j_col) + alpha
1642 CALL timestop(handle)
1644 END SUBROUTINE fm_add_on_diag
1650 SUBROUTINE clean_lower_part(fm_mat)
1653 CHARACTER(LEN=*),
PARAMETER :: routinen =
'clean_lower_part'
1655 INTEGER :: handle, i_row, j_col, j_global, &
1656 ncol_local, nrow_local
1657 INTEGER,
DIMENSION(:),
POINTER :: col_indices, row_indices
1659 CALL timeset(routinen, handle)
1662 nrow_local=nrow_local, ncol_local=ncol_local, &
1663 row_indices=row_indices, col_indices=col_indices)
1665 DO j_col = 1, ncol_local
1666 j_global = col_indices(j_col)
1667 DO i_row = 1, nrow_local
1668 IF (j_global < row_indices(i_row)) fm_mat%local_data(i_row, j_col) = 0.0_dp
1672 CALL timestop(handle)
1674 END SUBROUTINE clean_lower_part
1685 SUBROUTINE compute_sigma_x(bs_env, qs_env, mat_phi_mu_l, mat_Z_lP, fm_Sigma_x_Gamma)
1689 TYPE(
dbcsr_type),
INTENT(INOUT) :: mat_phi_mu_l, mat_z_lp
1690 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_sigma_x_gamma
1692 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_Sigma_x'
1694 INTEGER :: handle, ispin
1695 INTEGER,
DIMENSION(:),
POINTER :: blk_aux, blk_grid, dist_col_grid, &
1698 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: fm_vtr_gamma
1700 TYPE(
dbcsr_type) :: mat_sigma_x_gamma, matrix_d_grid, &
1701 matrix_sigma_x_grid, matrix_v_aux, &
1704 CALL timeset(routinen, handle)
1708 ALLOCATE (fm_sigma_x_gamma(bs_env%n_spin))
1709 DO ispin = 1, bs_env%n_spin
1710 CALL cp_fm_create(fm_sigma_x_gamma(ispin), bs_env%fm_s_Gamma%matrix_struct)
1713 CALL dbcsr_create(mat_sigma_x_gamma, template=bs_env%mat_ao_ao%matrix)
1718 CALL setup_square_topology(mat_phi_mu_l,
'ROW', dist_grid_grid, blk_grid, dist_col_grid)
1719 CALL setup_square_topology(mat_z_lp,
'COL', dist_aux_aux, blk_aux, dist_row_aux)
1725 bs_env%trunc_coulomb, do_kpoints=.false.)
1730 CALL dbcsr_create(matrix_v_aux,
"V_aux", dist_aux_aux, dbcsr_type_no_symmetry, blk_aux, blk_aux)
1731 CALL dbcsr_create(matrix_v_grid,
"V_grid", dist_grid_grid, dbcsr_type_no_symmetry, blk_grid, blk_grid)
1733 CALL copy_fm_to_dbcsr(fm_vtr_gamma(1, 1), matrix_v_aux, keep_sparsity=.false.)
1736 CALL contract_a_b_a(
"N",
"T", mat_z_lp, matrix_v_aux, matrix_v_grid, bs_env%eps_filter)
1742 DO ispin = 1, bs_env%n_spin
1747 CALL dbcsr_create(matrix_d_grid,
"D_grid", dist_grid_grid, dbcsr_type_no_symmetry, blk_grid, blk_grid)
1748 CALL build_g_grid(bs_env, 0.0_dp, ispin, .true., .false., mat_phi_mu_l, matrix_d_grid, bs_env%eps_filter)
1752 CALL dbcsr_create(matrix_sigma_x_grid, template=matrix_v_grid)
1753 CALL hadamard_product(matrix_d_grid, matrix_v_grid, matrix_sigma_x_grid, 1.0_dp)
1759 CALL contract_a_b_a(
"T",
"N", mat_phi_mu_l, matrix_sigma_x_grid, mat_sigma_x_gamma, bs_env%eps_filter)
1769 IF (bs_env%unit_nr > 0)
THEN
1770 WRITE (bs_env%unit_nr,
'(T2,A,T58,A,F7.1,A)') &
1771 Σ
'Computed ^x(k=0),',
' Execution time',
m_walltime() - t1,
' s'
1772 WRITE (bs_env%unit_nr,
'(A)')
' '
1778 CALL release_dbcsr_topology_and_matrices(dist=dist_grid_grid, mapped_dist=dist_col_grid, &
1779 m1=mat_sigma_x_gamma, m2=matrix_v_grid)
1780 CALL release_dbcsr_topology_and_matrices(dist=dist_aux_aux, mapped_dist=dist_row_aux)
1784 CALL timestop(handle)
1786 END SUBROUTINE compute_sigma_x
1797 SUBROUTINE compute_sigma_c(bs_env, fm_W_time, mat_phi_mu_l, mat_Z_lP, fm_Sigma_c_Gamma_time)
1800 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_w_time
1801 TYPE(
dbcsr_type),
INTENT(INOUT) :: mat_phi_mu_l, mat_z_lp
1802 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :, :) :: fm_sigma_c_gamma_time
1804 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_Sigma_c'
1806 INTEGER :: handle, i_t, ispin
1807 INTEGER,
DIMENSION(:),
POINTER :: blk_aux, blk_grid, dist_col_grid, &
1809 REAL(kind=
dp) :: t1, tau
1811 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: mat_sigma_neg_tau, mat_sigma_pos_tau
1812 TYPE(
dbcsr_type) :: matrix_g_occ_grid, matrix_g_vir_grid, matrix_sigma_neg_grid, &
1813 matrix_sigma_pos_grid, matrix_w_aux, matrix_w_grid
1815 CALL timeset(routinen, handle)
1820 CALL setup_square_topology(mat_phi_mu_l,
'ROW', dist_grid_grid, blk_grid, dist_col_grid)
1821 CALL setup_square_topology(mat_z_lp,
'COL', dist_aux_aux, blk_aux, dist_row_aux)
1824 NULLIFY (mat_sigma_neg_tau, mat_sigma_pos_tau)
1825 ALLOCATE (mat_sigma_neg_tau(bs_env%num_time_freq_points, bs_env%n_spin))
1826 ALLOCATE (mat_sigma_pos_tau(bs_env%num_time_freq_points, bs_env%n_spin))
1828 DO i_t = 1, bs_env%num_time_freq_points
1829 DO ispin = 1, bs_env%n_spin
1830 ALLOCATE (mat_sigma_neg_tau(i_t, ispin)%matrix)
1831 ALLOCATE (mat_sigma_pos_tau(i_t, ispin)%matrix)
1832 CALL dbcsr_create(mat_sigma_neg_tau(i_t, ispin)%matrix, template=bs_env%mat_ao_ao%matrix)
1833 CALL dbcsr_create(mat_sigma_pos_tau(i_t, ispin)%matrix, template=bs_env%mat_ao_ao%matrix)
1840 DO i_t = 1, bs_env%num_time_freq_points
1841 tau = bs_env%imag_time_points(i_t)
1846 CALL dbcsr_create(matrix_w_aux,
"W_aux", dist_aux_aux, dbcsr_type_no_symmetry, blk_aux, blk_aux)
1847 CALL dbcsr_create(matrix_w_grid,
"W_grid", dist_grid_grid, dbcsr_type_no_symmetry, blk_grid, blk_grid)
1852 CALL contract_a_b_a(
"N",
"T", mat_z_lp, matrix_w_aux, matrix_w_grid, bs_env%eps_filter)
1856 DO ispin = 1, bs_env%n_spin
1862 CALL dbcsr_create(matrix_g_occ_grid,
"G_occ_grid", dist_grid_grid, dbcsr_type_no_symmetry, blk_grid, blk_grid)
1863 CALL dbcsr_create(matrix_g_vir_grid,
"G_vir_grid", dist_grid_grid, dbcsr_type_no_symmetry, blk_grid, blk_grid)
1867 CALL build_g_grid(bs_env, tau, ispin, .true., .false., mat_phi_mu_l, matrix_g_occ_grid, bs_env%eps_filter)
1871 CALL build_g_grid(bs_env, tau, ispin, .false., .true., mat_phi_mu_l, matrix_g_vir_grid, bs_env%eps_filter)
1878 CALL dbcsr_create(matrix_sigma_neg_grid, template=matrix_w_grid)
1879 CALL dbcsr_create(matrix_sigma_pos_grid, template=matrix_w_grid)
1882 CALL hadamard_product(matrix_g_occ_grid, matrix_w_grid, matrix_sigma_neg_grid, 1.0_dp)
1885 CALL hadamard_product(matrix_g_vir_grid, matrix_w_grid, matrix_sigma_pos_grid, 1.0_dp)
1897 CALL contract_a_b_a(
"T",
"N", mat_phi_mu_l, matrix_sigma_neg_grid, &
1898 mat_sigma_neg_tau(i_t, ispin)%matrix, bs_env%eps_filter)
1899 CALL dbcsr_scale(mat_sigma_neg_tau(i_t, ispin)%matrix, -1.0_dp)
1902 CALL contract_a_b_a(
"T",
"N", mat_phi_mu_l, matrix_sigma_pos_grid, &
1903 mat_sigma_pos_tau(i_t, ispin)%matrix, bs_env%eps_filter)
1909 IF (bs_env%unit_nr > 0)
THEN
1910 WRITE (bs_env%unit_nr,
'(T2,A,I10,A,I3,A,F7.1,A)') &
1911 Στ
'Computed ^c(i,k=0) for time point ', i_t,
' /', bs_env%num_time_freq_points, &
1922 IF (bs_env%unit_nr > 0)
WRITE (bs_env%unit_nr,
'(A)')
' '
1928 mat_sigma_pos_tau, mat_sigma_neg_tau)
1935 CALL release_dbcsr_topology_and_matrices(dist=dist_grid_grid, mapped_dist=dist_col_grid)
1936 CALL release_dbcsr_topology_and_matrices(dist=dist_aux_aux, mapped_dist=dist_row_aux)
1939 CALL timestop(handle)
1941 END SUBROUTINE compute_sigma_c
1952 SUBROUTINE setup_square_topology(matrix_template, dim_type, square_dist, blk_sizes, mapped_dist)
1954 TYPE(
dbcsr_type),
INTENT(IN) :: matrix_template
1955 CHARACTER(LEN=*),
INTENT(IN) :: dim_type
1957 INTEGER,
DIMENSION(:),
INTENT(OUT),
POINTER :: blk_sizes, mapped_dist
1960 INTEGER,
DIMENSION(:),
POINTER :: col_blk, col_dist, row_blk, row_dist
1963 CALL dbcsr_get_info(matrix_template, distribution=dist_template, &
1964 row_blk_size=row_blk, col_blk_size=col_blk)
1967 IF (trim(dim_type) ==
'ROW')
THEN
1969 blk_sizes => row_blk
1970 np = maxval(col_dist) + 1
1971 ALLOCATE (mapped_dist(
SIZE(blk_sizes)))
1972 DO i = 1,
SIZE(blk_sizes)
1973 mapped_dist(i) = mod(i - 1, np)
1976 row_dist=row_dist, col_dist=mapped_dist)
1978 ELSE IF (trim(dim_type) ==
'COL')
THEN
1980 blk_sizes => col_blk
1981 np = maxval(row_dist) + 1
1982 ALLOCATE (mapped_dist(
SIZE(blk_sizes)))
1983 DO i = 1,
SIZE(blk_sizes)
1984 mapped_dist(i) = mod(i - 1, np)
1987 row_dist=mapped_dist, col_dist=col_dist)
1990 END SUBROUTINE setup_square_topology
2002 SUBROUTINE release_dbcsr_topology_and_matrices(dist, mapped_dist, m1, m2, m3, m4)
2006 INTEGER,
DIMENSION(:),
INTENT(INOUT),
OPTIONAL, &
2007 POINTER :: mapped_dist
2008 TYPE(
dbcsr_type),
INTENT(INOUT),
OPTIONAL :: m1, m2, m3, m4
2011 IF (
PRESENT(mapped_dist))
THEN
2012 IF (
ASSOCIATED(mapped_dist))
THEN
2013 DEALLOCATE (mapped_dist)
2014 NULLIFY (mapped_dist)
2022 END SUBROUTINE release_dbcsr_topology_and_matrices
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 gw_calc_large_cell_gamma_ri_rs(qs_env, bs_env)
GW calculation using RI-RS formalism for molecules.
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)
Helper for OMP threads to fill phi_val column values.
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....
subroutine, public de_init_bs_env(bs_env)
...
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, 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, 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, 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.