30 dbcsr_type_no_symmetry
89#include "./base/base_uses.f90"
95 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'gw_non_periodic_ri_rs'
113 CHARACTER(LEN=*),
PARAMETER :: routinen =
'gw_calc_non_periodic_ri_rs'
116 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_sigma_x_gamma, fm_w_time
117 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :, :) :: fm_sigma_c_gamma_time
119 CALL timeset(routinen, handle)
146 CALL atomic_basis_at_grid_point(qs_env, bs_env, bs_env%ri_rs%grid_points, &
147 bs_env%ri_rs%mat_phi_mu_l)
162 CALL compute_coeff_z_lp(qs_env, bs_env, bs_env%ri_rs%grid_points, &
163 bs_env%ri_rs%mat_phi_mu_l, bs_env%ri_rs%mat_Z_lP)
174 CALL get_mat_chi_gamma_tau(bs_env, bs_env%mat_chi_Gamma_tau, &
175 bs_env%ri_rs%mat_phi_mu_l, bs_env%ri_rs%mat_Z_lP)
181 CALL compute_w(bs_env, qs_env, bs_env%mat_chi_Gamma_tau, fm_w_time)
191 CALL compute_sigma_x(bs_env, qs_env, bs_env%ri_rs%mat_phi_mu_l, &
192 bs_env%ri_rs%mat_Z_lP, fm_sigma_x_gamma)
201 CALL compute_sigma_c(bs_env, fm_w_time, bs_env%ri_rs%mat_phi_mu_l, &
202 bs_env%ri_rs%mat_Z_lP, fm_sigma_c_gamma_time)
213 CALL timestop(handle)
233 CHARACTER(LEN=*),
PARAMETER :: routinen =
'precompute_ri_rs_radii'
235 INTEGER :: handle, i, iatom, ikind, j, natom, nkind
236 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: kind_of
238 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: alpha_min_ao_kind, alpha_min_ri_kind
239 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: zet_ao, zet_ri
243 CALL timeset(routinen, handle)
245 CALL get_qs_env(qs_env, nkind=nkind, atomic_kind_set=atomic_kind_set, &
246 particle_set=particle_set)
247 natom =
SIZE(particle_set)
249 eps = bs_env%eps_filter
251 ALLOCATE (alpha_min_ao_kind(nkind), alpha_min_ri_kind(nkind))
252 alpha_min_ao_kind = huge(1.0_dp)
253 alpha_min_ri_kind = huge(1.0_dp)
256 zet_ao => bs_env%basis_set_AO(ikind)%gto_basis_set%zet
257 zet_ri => bs_env%basis_set_RI(ikind)%gto_basis_set%zet
259 DO i = 1,
SIZE(zet_ao, 1)
260 DO j = 1,
SIZE(zet_ao, 2)
261 IF (zet_ao(i, j) > 1.0e-3_dp) &
262 alpha_min_ao_kind(ikind) = min(alpha_min_ao_kind(ikind), zet_ao(i, j))
265 DO i = 1,
SIZE(zet_ri, 1)
266 DO j = 1,
SIZE(zet_ri, 2)
267 IF (zet_ri(i, j) > 1.0e-3_dp) &
268 alpha_min_ri_kind(ikind) = min(alpha_min_ri_kind(ikind), zet_ri(i, j))
275 ALLOCATE (bs_env%ri_rs%radius_ao_per_atom(natom))
276 ALLOCATE (bs_env%ri_rs%radius_ri_per_atom(natom))
278 ikind = kind_of(iatom)
279 bs_env%ri_rs%radius_ao_per_atom(iatom) = sqrt(-log(eps)/alpha_min_ao_kind(ikind))
280 bs_env%ri_rs%radius_ri_per_atom(iatom) = sqrt(-log(eps)/alpha_min_ri_kind(ikind))
283 IF (bs_env%unit_nr > 0)
THEN
284 WRITE (bs_env%unit_nr,
'(T2,A)')
'Per-kind RI-RS basis radii (Bohr):'
285 WRITE (bs_env%unit_nr,
'(T4,A6,2X,A4,2A14)')
'Kind',
'Elem',
'r_AO',
'r_RI'
287 WRITE (bs_env%unit_nr,
'(T4,I6,2X,A4,2F14.4)') &
289 atomic_kind_set(ikind)%element_symbol, &
290 sqrt(-log(eps)/alpha_min_ao_kind(ikind)), &
291 sqrt(-log(eps)/alpha_min_ri_kind(ikind))
293 WRITE (bs_env%unit_nr,
'(A)')
' '
296 DEALLOCATE (alpha_min_ao_kind, alpha_min_ri_kind, kind_of)
298 CALL timestop(handle)
315 REAL(kind=
dp),
ALLOCATABLE,
INTENT(OUT) :: ri_rs_grid_points(:, :)
317 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ri_rs_grid_assembler'
319 INTEGER :: atom_idx, end_idx, handle, ikind, j, &
320 natom, nkind, start_idx, &
322 INTEGER,
ALLOCATABLE :: atom_to_kind(:), ri_rs_grid_offsets(:)
323 REAL(kind=
dp) :: atomic_center(3)
327 CALL timeset(routinen, handle)
330 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set, particle_set=particle_set)
332 nkind =
SIZE(atomic_kind_set)
333 natom =
SIZE(particle_set)
336 CALL build_grid_cache(bs_env, atomic_kind_set)
339 ALLOCATE (ri_rs_grid_offsets(natom + 1))
340 ALLOCATE (atom_to_kind(natom))
344 DO j = 1,
SIZE(atomic_kind_set(ikind)%atom_list)
345 atom_idx = atomic_kind_set(ikind)%atom_list(j)
346 atom_to_kind(atom_idx) = ikind
347 ri_rs_grid_offsets(atom_idx) = total_grid_npts + 1
348 total_grid_npts = total_grid_npts + bs_env%ri_rs%grid_cache(ikind)%npts
352 ri_rs_grid_offsets(natom + 1) = total_grid_npts + 1
354 IF (bs_env%unit_nr > 0)
THEN
355 WRITE (bs_env%unit_nr, fmt=
"(T2,A,T69,I12)") &
356 'Total grid points used for RI-RS:', total_grid_npts
357 WRITE (bs_env%unit_nr,
"(A)")
' '
361 ALLOCATE (ri_rs_grid_points(3, total_grid_npts))
369 DO atom_idx = 1, natom
370 ikind = atom_to_kind(atom_idx)
371 atomic_center(:) = particle_set(atom_idx)%r(:)
373 start_idx = ri_rs_grid_offsets(atom_idx)
374 end_idx = start_idx + bs_env%ri_rs%grid_cache(ikind)%npts - 1
377 ri_rs_grid_points(1, start_idx:end_idx) = bs_env%ri_rs%grid_cache(ikind)%raw_points(1, :) + atomic_center(1)
378 ri_rs_grid_points(2, start_idx:end_idx) = bs_env%ri_rs%grid_cache(ikind)%raw_points(2, :) + atomic_center(2)
379 ri_rs_grid_points(3, start_idx:end_idx) = bs_env%ri_rs%grid_cache(ikind)%raw_points(3, :) + atomic_center(3)
385 IF (
ALLOCATED(bs_env%ri_rs%grid_cache))
THEN
387 IF (
ALLOCATED(bs_env%ri_rs%grid_cache(ikind)%raw_points))
DEALLOCATE (bs_env%ri_rs%grid_cache(ikind)%raw_points)
389 DEALLOCATE (bs_env%ri_rs%grid_cache)
392 DEALLOCATE (atom_to_kind, ri_rs_grid_offsets)
393 CALL timestop(handle)
403 SUBROUTINE build_grid_cache(bs_env, atomic_kind_set)
408 CHARACTER(LEN=default_path_length) :: filename, full_path, line
409 CHARACTER(LEN=default_string_length) :: atom_sym, suffix
410 INTEGER :: colon_idx, i, ierr, ikind, iunit, nkind
411 REAL(kind=
dp) :: pt(3)
414 IF (bs_env%ri_rs%grid_select == 1)
THEN
415 suffix =
"_def2-tzvp-rs.ion"
416 ELSE IF (bs_env%ri_rs%grid_select == 2)
THEN
417 suffix =
"_cc-pvtz-rs.ion"
419 cpabort(
"Unknown grid_select value. Valid options are 1 (def2-TZVPP) or 2 (cc-pVTZ).")
422 nkind =
SIZE(atomic_kind_set)
423 IF (.NOT.
ALLOCATED(bs_env%ri_rs%grid_cache))
ALLOCATE (bs_env%ri_rs%grid_cache(nkind))
426 atom_sym = trim(atomic_kind_set(ikind)%element_symbol)
427 filename = trim(atom_sym)//trim(suffix)
429 full_path =
"ri_rs_grid/"//trim(filename)
431 CALL open_file(file_name=trim(full_path), unit_number=iunit, &
432 file_action=
"READ", file_status=
"OLD")
435 bs_env%ri_rs%grid_cache(ikind)%npts = 0
437 READ (iunit,
'(A)', iostat=ierr) line
439 IF (index(line,
'n points') > 0)
THEN
440 colon_idx = index(line,
':')
441 READ (line(colon_idx + 1:), *) bs_env%ri_rs%grid_cache(ikind)%npts
447 ALLOCATE (bs_env%ri_rs%grid_cache(ikind)%raw_points(3, bs_env%ri_rs%grid_cache(ikind)%npts))
451 READ (iunit,
'(A)', iostat=ierr) line
453 IF (index(line,
'<grid_points>') > 0)
EXIT
457 DO i = 1, bs_env%ri_rs%grid_cache(ikind)%npts
458 READ (iunit, *, iostat=ierr) pt(1), pt(2), pt(3)
460 cpabort(
"Unexpected EOF in grid file ")
462 bs_env%ri_rs%grid_cache(ikind)%raw_points(:, i) = pt(:)
468 END SUBROUTINE build_grid_cache
478 SUBROUTINE atomic_basis_at_grid_point(qs_env, bs_env, ri_rs_grid_points, mat_phi_mu_l)
482 REAL(kind=
dp),
ALLOCATABLE,
INTENT(INOUT) :: ri_rs_grid_points(:, :)
485 CHARACTER(LEN=*),
PARAMETER :: routinen =
'atomic_basis_at_grid_point'
487 INTEGER :: c_size, chunk_size, dimen_orb, handle, i, i_blk, iatom, natom, npcol, nprow, &
488 num_grid_chunks, r_end, r_start, total_grid_npts
489 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: first_sgf
490 INTEGER,
DIMENSION(:),
POINTER :: c_blk_sizes, col_dist, col_dist_ks, &
491 r_blk_sizes, row_dist, row_dist_ks
492 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: atom_col_buffer
499 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
501 CALL timeset(routinen, handle)
506 CALL get_qs_env(qs_env, cell=cell, atomic_kind_set=atomic_kind_set, &
507 qs_kind_set=qs_kind_set, particle_set=particle_set, &
510 natom =
SIZE(particle_set)
511 total_grid_npts =
SIZE(ri_rs_grid_points, 2)
514 ALLOCATE (first_sgf(natom + 1))
522 ALLOCATE (c_blk_sizes(natom))
524 c_blk_sizes(iatom) = first_sgf(iatom + 1) - first_sgf(iatom)
528 num_grid_chunks = ceiling(real(total_grid_npts, kind=
dp)/real(chunk_size, kind=
dp))
529 ALLOCATE (r_blk_sizes(num_grid_chunks))
530 r_blk_sizes = chunk_size
531 IF (mod(total_grid_npts, chunk_size) /= 0)
THEN
532 r_blk_sizes(num_grid_chunks) = mod(total_grid_npts, chunk_size)
536 CALL get_qs_env(qs_env, dbcsr_dist=dbcsr_dist_ks)
541 nprow = maxval(row_dist_ks) + 1
542 npcol = maxval(col_dist_ks) + 1
544 ALLOCATE (row_dist(num_grid_chunks))
545 DO i = 1, num_grid_chunks
546 row_dist(i) = mod(i - 1, nprow)
549 ALLOCATE (col_dist(natom))
551 col_dist(i) = mod(i - 1, npcol)
556 row_dist=row_dist, col_dist=col_dist)
558 CALL dbcsr_create(mat_phi_mu_l, name=
"phi_val_sparse", dist=dist, &
559 matrix_type=dbcsr_type_no_symmetry, &
560 row_blk_size=r_blk_sizes, col_blk_size=c_blk_sizes)
566 DO iatom = para_env%mepos + 1, natom, para_env%num_pe
568 c_size = c_blk_sizes(iatom)
571 ALLOCATE (atom_col_buffer(total_grid_npts, c_size))
572 atom_col_buffer = 0.0_dp
577 CALL fill_phi_for_atom(atom_col_buffer, ri_rs_grid_points, total_grid_npts, &
578 iatom, particle_set, qs_kind_set, cell, &
579 bs_env%ri_rs%radius_ao_per_atom(iatom)**2)
582 DO i_blk = 1, num_grid_chunks
583 r_start = (i_blk - 1)*chunk_size + 1
584 r_end = min(i_blk*chunk_size, total_grid_npts)
587 IF (maxval(abs(atom_col_buffer(r_start:r_end, 1:c_size))) > bs_env%eps_filter)
THEN
589 block=atom_col_buffer(r_start:r_end, 1:c_size))
593 DEALLOCATE (atom_col_buffer)
603 DEALLOCATE (first_sgf, r_blk_sizes, c_blk_sizes, row_dist, col_dist)
606 CALL timestop(handle)
608 END SUBROUTINE atomic_basis_at_grid_point
622 SUBROUTINE fill_phi_for_atom(phi_val, ri_rs_grid, npts, iatom, &
623 particle_set, qs_kind_set, cell, r2_threshold)
625 REAL(kind=
dp),
INTENT(INOUT) :: phi_val(:, :)
626 INTEGER,
INTENT(IN) :: npts
627 REAL(kind=
dp),
INTENT(IN) :: ri_rs_grid(3, npts)
628 INTEGER,
INTENT(IN) :: iatom
630 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
632 REAL(kind=
dp),
INTENT(IN) :: r2_threshold
634 INTEGER :: first_sgf, i_pt, ico, iend_co, ikind, &
635 ipgf, iset, isgf, ishell, istart_co, &
636 l, last_sgf, lx, ly, lz, n_cart_total, &
638 REAL(kind=
dp) :: alpha, dist_vec(3), exp_val, poly, r2, &
643 ikind = particle_set(iatom)%atomic_kind%kind_number
644 CALL get_qs_kind(qs_kind_set(ikind), basis_set=orb_basis_set, basis_type=
"ORB")
645 IF (.NOT.
ASSOCIATED(orb_basis_set))
RETURN
647 r_atom = particle_set(iatom)%r
657 dist_vec =
pbc(ri_rs_grid(:, i_pt) - r_atom, cell)
658 r2 = dot_product(dist_vec, dist_vec)
659 IF (r2 > r2_threshold) cycle
661 DO iset = 1, orb_basis_set%nset
662 n_cart_total =
ncoset(orb_basis_set%lmax(iset))
664 DO ishell = 1, orb_basis_set%nshell(iset)
665 l = orb_basis_set%l(ishell, iset)
666 istart_co =
ncoset(l - 1) + 1
669 first_sgf = orb_basis_set%first_sgf(ishell, iset)
670 last_sgf = orb_basis_set%last_sgf(ishell, iset)
672 DO ipgf = 1, orb_basis_set%npgf(iset)
673 alpha = orb_basis_set%zet(ipgf, iset)
674 exp_val = exp(-alpha*r2)
676 DO isgf = first_sgf, last_sgf
677 DO ico = istart_co, iend_co
678 row_idx = (ipgf - 1)*n_cart_total + ico
679 weight = orb_basis_set%sphi(row_idx, isgf)
683 poly = (dist_vec(1)**lx)*(dist_vec(2)**ly)*(dist_vec(3)**lz)
685 phi_val(i_pt, isgf) = phi_val(i_pt, isgf) + (weight*poly*exp_val)
695 END SUBROUTINE fill_phi_for_atom
708 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
709 INTEGER,
INTENT(OUT) :: first_sgf(:), total_sgf
711 CHARACTER(LEN=*),
PARAMETER :: routinen =
'get_basis_offsets'
713 INTEGER :: handle, iatom, ikind, nsgf
715 CALL timeset(routinen, handle)
718 DO iatom = 1,
SIZE(particle_set)
719 first_sgf(iatom) = total_sgf + 1
720 ikind = particle_set(iatom)%atomic_kind%kind_number
721 CALL get_qs_kind(qs_kind_set(ikind), nsgf=nsgf, basis_type=
"ORB")
722 total_sgf = total_sgf + nsgf
724 first_sgf(
SIZE(particle_set) + 1) = total_sgf + 1
726 CALL timestop(handle)
739 SUBROUTINE compute_coeff_z_lp(qs_env, bs_env, ri_rs_grid_points, mat_phi_mu_l, mat_Z_lP)
744 REAL(kind=
dp),
ALLOCATABLE,
INTENT(INOUT) :: ri_rs_grid_points(:, :)
745 TYPE(
dbcsr_type),
INTENT(INOUT) :: mat_phi_mu_l
748 CHARACTER(LEN=*),
PARAMETER :: key =
'PROPERTIES%BANDSTRUCTURE%GW%PRINT%RESTART', &
749 routinen =
'compute_coeff_Z_lP'
751 INTEGER :: atom_j_mepos, atom_j_stride, atom_p, atom_p_start, atom_p_stride, col_end, &
752 col_start, current_chunk_size, g, group_handle, handle, i, i_blk, ikind, info, j, j_ri, &
753 l, loc_idx, loc_ptr, max_ao_size, max_loc_ri, my_group, n_ao_total, n_grid_total, &
754 n_groups, n_loc_ri, n_local_grid, n_procs_per_atom, natom, nkind, num_grid_chunks, &
755 p_loop_atom, r_end, r_start, source_atom
756 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: local_grid_idx, row_offset
757 INTEGER,
DIMENSION(:),
POINTER :: col_dist_phi, col_dist_ri, r_blk_sizes, &
758 ri_blk_sizes, row_dist_grid
759 REAL(kind=
dp) :: cutoff_ri, d_sp, dist, r2_threshold, &
761 REAL(kind=
dp),
ALLOCATABLE :: cutoff_ri_per_kind(:)
762 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: cutoff_ri_per_atom, d_vec_local
763 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: d_local, d_lp_local, phi_local, &
765 REAL(kind=
dp),
DIMENSION(3) :: pos_p
776 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
779 CALL timeset(routinen, handle)
783 CALL get_qs_env(qs_env, para_env=para_env, particle_set=particle_set, input=input, &
784 qs_kind_set=qs_kind_set, cell=cell, atomic_kind_set=atomic_kind_set)
794 n_procs_per_atom = min(bs_env%ri_rs%n_procs_per_atom_z_lp, para_env%num_pe)
795 IF (n_procs_per_atom < 1) n_procs_per_atom = 1
797 NULLIFY (para_env_sub, blacs_env_sub)
798 IF (n_procs_per_atom > 1)
THEN
799 n_groups = para_env%num_pe/n_procs_per_atom
800 my_group = min(para_env%mepos/n_procs_per_atom, n_groups - 1)
801 ALLOCATE (para_env_sub)
802 CALL para_env_sub%from_split(para_env, my_group)
804 atom_p_start = my_group + 1
805 atom_p_stride = n_groups
806 atom_j_mepos = para_env_sub%mepos
807 atom_j_stride = para_env_sub%num_pe
809 atom_p_start = para_env%mepos + 1
810 atom_p_stride = para_env%num_pe
815 natom =
SIZE(bs_env%i_RI_start_from_atom)
816 n_ao_total = bs_env%i_ao_end_from_atom(natom)
817 n_grid_total =
SIZE(ri_rs_grid_points, 2)
822 CALL dbcsr_get_info(mat_phi_mu_l, row_blk_size=r_blk_sizes, distribution=dist_phi)
825 num_grid_chunks =
SIZE(r_blk_sizes)
827 ALLOCATE (row_offset(num_grid_chunks))
829 DO i_blk = 2, num_grid_chunks
830 row_offset(i_blk) = row_offset(i_blk - 1) + r_blk_sizes(i_blk - 1)
833 ALLOCATE (ri_blk_sizes(natom), col_dist_ri(natom))
835 ri_blk_sizes(atom_p) = bs_env%i_RI_end_from_atom(atom_p) - bs_env%i_RI_start_from_atom(atom_p) + 1
836 col_dist_ri(atom_p) = mod(atom_p - 1, maxval(col_dist_phi) + 1)
841 IF (bs_env%ri_rs%Z_lP_exists)
THEN
843 distribution=dist_z, &
845 IF (bs_env%unit_nr > 0)
THEN
846 WRITE (bs_env%unit_nr,
'(T2,A,T57,A,F7.1,A)') &
847 'Read Z_lP from file ',
' Execution time',
m_walltime() - t1,
' s'
848 WRITE (bs_env%unit_nr,
'(A)')
' '
852 CALL dbcsr_create(mat_z_lp, name=
"mat_Z_lP", dist=dist_z, &
853 matrix_type=dbcsr_type_no_symmetry, &
854 row_blk_size=r_blk_sizes, col_blk_size=ri_blk_sizes)
857 DO j = 1,
SIZE(bs_env%i_ao_start_from_atom)
858 max_ao_size = max(max_ao_size, bs_env%i_ao_end_from_atom(j) - bs_env%i_ao_start_from_atom(j) + 1)
860 max_loc_ri = maxval(ri_blk_sizes)
866 nkind =
SIZE(atomic_kind_set)
867 ALLOCATE (cutoff_ri_per_atom(natom))
869 IF (bs_env%ri_rs%cutoff_radius_ri_rs > 0.0_dp)
THEN
870 cutoff_ri_per_atom(:) = bs_env%ri_rs%cutoff_radius_ri_rs
872 r_c = bs_env%ri_metric%cutoff_radius
873 DO p_loop_atom = 1, natom
874 cutoff_ri_per_atom(p_loop_atom) = &
875 r_c + bs_env%ri_rs%radius_ao_per_atom(p_loop_atom)
879 ALLOCATE (cutoff_ri_per_kind(nkind))
880 cutoff_ri_per_kind(:) = 0.0_dp
881 IF (bs_env%unit_nr > 0)
THEN
882 WRITE (bs_env%unit_nr,
'(T2,A)')
'Per-kind maximum RI-RS sphere cutoff (Bohr):'
883 WRITE (bs_env%unit_nr,
'(T4,A4,A14)')
'Kind',
'max cutoff_ri'
885 DO p_loop_atom = 1, natom
886 ikind = particle_set(p_loop_atom)%atomic_kind%kind_number
887 cutoff_ri_per_kind(ikind) = max(cutoff_ri_per_kind(ikind), &
888 cutoff_ri_per_atom(p_loop_atom))
891 WRITE (bs_env%unit_nr,
'(T4,A4,F14.4)') &
892 atomic_kind_set(ikind)%element_symbol, &
893 cutoff_ri_per_kind(ikind)
895 WRITE (bs_env%unit_nr,
'(A)')
' '
897 DEALLOCATE (cutoff_ri_per_kind)
904 basis_j=bs_env%basis_set_AO, basis_k=bs_env%basis_set_AO, &
905 basis_i=bs_env%basis_set_RI)
913 DO atom_p = atom_p_start, natom, atom_p_stride
915 n_loc_ri = ri_blk_sizes(atom_p)
916 pos_p(:) = particle_set(atom_p)%r(:)
918 cutoff_ri = cutoff_ri_per_atom(atom_p)
924 DO l = 1, n_grid_total
925 dist = sqrt(sum((ri_rs_grid_points(1:3, l) - pos_p(1:3))**2))
926 IF (dist <= cutoff_ri) n_local_grid = n_local_grid + 1
929 ALLOCATE (local_grid_idx(n_local_grid))
932 DO l = 1, n_grid_total
933 dist = sqrt(sum((ri_rs_grid_points(1:3, l) - pos_p(1:3))**2))
934 IF (dist <= cutoff_ri)
THEN
935 n_local_grid = n_local_grid + 1
936 local_grid_idx(n_local_grid) = l
947 ALLOCATE (sphere_grid(3, n_local_grid))
948 DO loc_idx = 1, n_local_grid
949 sphere_grid(:, loc_idx) = ri_rs_grid_points(:, local_grid_idx(loc_idx))
952 ALLOCATE (phi_local(n_local_grid, n_ao_total))
955 DO source_atom = 1, natom
956 d_sp = norm2(particle_set(source_atom)%r(:) - pos_p(:))
957 IF (d_sp > bs_env%ri_rs%radius_ao_per_atom(source_atom) + cutoff_ri) cycle
959 col_start = bs_env%i_ao_start_from_atom(source_atom)
960 col_end = bs_env%i_ao_end_from_atom(source_atom)
961 r2_threshold = bs_env%ri_rs%radius_ao_per_atom(source_atom)**2
963 CALL fill_phi_for_atom(phi_local(:, col_start:col_end), sphere_grid, &
964 n_local_grid, source_atom, particle_set, qs_kind_set, &
968 DEALLOCATE (sphere_grid)
976 ALLOCATE (d_lp_local(n_local_grid, n_loc_ri))
979 CALL compute_d_lp(bs_env, ctx_3c, phi_local, d_lp_local, n_local_grid, &
980 n_loc_ri, atom_p, max_ao_size, atom_j_mepos, atom_j_stride)
984 IF (n_procs_per_atom > 1)
THEN
985 CALL para_env_sub%sum(d_lp_local)
991 ALLOCATE (d_vec_local(n_local_grid))
993 IF (n_procs_per_atom == 1)
THEN
997 ALLOCATE (d_local(n_local_grid, n_local_grid))
1000 CALL dsyrk(
"L",
"N", n_local_grid, n_ao_total, 1.0_dp, phi_local, &
1001 n_local_grid, 0.0_dp, d_local, n_local_grid)
1007 DO i = 1, n_local_grid
1008 d_local(i, i) = d_local(i, i)**2
1009 d_vec_local(i) = 1.0_dp/sqrt(max(d_local(i, i), 1.0e-16_dp))
1010 d_local(i, i) = (d_local(i, i)*d_vec_local(i)**2) + bs_env%ri_rs%tikhonov
1018 DO j = 1, n_local_grid
1019 DO i = j + 1, n_local_grid
1020 d_local(i, j) = d_local(i, j)**2
1021 d_local(i, j) = d_local(i, j)*d_vec_local(i)*d_vec_local(j)
1022 d_local(j, i) = d_local(i, j)
1034 DO i = 1, n_local_grid
1035 d_vec_local(i) = 0.0_dp
1036 DO j = 1, n_ao_total
1037 d_vec_local(i) = d_vec_local(i) + phi_local(i, j)*phi_local(i, j)
1039 d_vec_local(i) = 1.0_dp/max(d_vec_local(i), 1.0e-16_dp)
1051 DO j_ri = 1, n_loc_ri
1052 DO i = 1, n_local_grid
1053 d_lp_local(i, j_ri) = d_lp_local(i, j_ri)*d_vec_local(i)
1061 IF (n_procs_per_atom == 1)
THEN
1062 CALL dpotrf(
'L', n_local_grid, d_local, n_local_grid, info)
1063 CALL dpotrs(
'L', n_local_grid, n_loc_ri, d_local, n_local_grid, &
1064 d_lp_local, n_local_grid, info)
1065 DEALLOCATE (d_local)
1068 n_local_grid, n_ao_total, n_loc_ri, &
1069 bs_env%ri_rs%tikhonov, &
1070 para_env_sub, blacs_env_sub, &
1071 fm_struct_d, fm_struct_b, fm_d, fm_b, info)
1081 DO j_ri = 1, n_loc_ri
1082 DO i = 1, n_local_grid
1083 d_lp_local(i, j_ri) = d_lp_local(i, j_ri)*d_vec_local(i)
1097 IF (n_procs_per_atom == 1 .OR. para_env_sub%mepos == 0)
THEN
1098 ALLOCATE (z_blk(maxval(r_blk_sizes), n_loc_ri))
1101 DO i_blk = 1, num_grid_chunks
1102 r_start = row_offset(i_blk) + 1
1103 r_end = row_offset(i_blk) + r_blk_sizes(i_blk)
1104 current_chunk_size = r_blk_sizes(i_blk)
1108 DO WHILE (loc_ptr <= n_local_grid)
1109 g = local_grid_idx(loc_ptr)
1111 z_blk(g - r_start + 1, 1:n_loc_ri) = d_lp_local(loc_ptr, 1:n_loc_ri)
1112 loc_ptr = loc_ptr + 1
1115 IF (maxval(abs(z_blk(1:current_chunk_size, 1:n_loc_ri))) > bs_env%eps_filter)
THEN
1117 block=z_blk(1:current_chunk_size, 1:n_loc_ri))
1124 DEALLOCATE (d_vec_local, d_lp_local)
1125 DEALLOCATE (local_grid_idx, phi_local)
1129 DEALLOCATE (cutoff_ri_per_atom)
1135 IF (bs_env%unit_nr > 0)
THEN
1136 WRITE (bs_env%unit_nr,
'(T2,A,T57,A,F7.1,A)') &
1137 'Computed Z_lP ',
' Execution time',
m_walltime() - t1,
' s'
1138 WRITE (bs_env%unit_nr,
'(A)')
' '
1144 CALL dbcsr_binary_write(matrix=mat_z_lp, filepath=trim(bs_env%prefix)//
"Z_lP.matrix")
1149 DEALLOCATE (row_offset, ri_blk_sizes, col_dist_ri)
1152 IF (n_procs_per_atom > 1)
THEN
1154 CALL para_env_sub%free()
1155 DEALLOCATE (para_env_sub)
1158 DEALLOCATE (ri_rs_grid_points)
1160 CALL timestop(handle)
1162 END SUBROUTINE compute_coeff_z_lp
1182 SUBROUTINE compute_d_lp(bs_env, ctx, phi_val, d_lp, n_grid_total, n_loc_ri, atom_P, &
1183 max_ao_size, atom_j_mepos, atom_j_stride)
1187 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(IN) :: phi_val
1188 INTEGER,
INTENT(IN) :: n_grid_total, n_loc_ri
1189 REAL(kind=
dp),
INTENT(INOUT) :: d_lp(n_grid_total, n_loc_ri)
1190 INTEGER,
INTENT(IN) :: atom_p, max_ao_size, atom_j_mepos, &
1193 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_d_lp'
1194 INTEGER,
PARAMETER :: grid_chunk = 1024
1196 INTEGER :: atom_j, atom_k, c, handle, j, jk_idx, &
1197 jsize, jstart, k, ksize, kstart, l, &
1200 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: int_2d_prv, rho_chunk
1201 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :) :: int_3c_prv
1204 CALL timeset(routinen, handle)
1213 ALLOCATE (int_3c_prv(max_ao_size, max_ao_size, n_loc_ri))
1214 ALLOCATE (int_2d_prv(max_ao_size*max_ao_size, n_loc_ri))
1215 ALLOCATE (rho_chunk(grid_chunk, max_ao_size*max_ao_size))
1223 DO atom_j = atom_j_mepos + 1,
SIZE(bs_env%i_ao_start_from_atom), atom_j_stride
1224 DO atom_k = 1,
SIZE(bs_env%i_ao_start_from_atom)
1225 jstart = bs_env%i_ao_start_from_atom(atom_j)
1226 jsize = bs_env%i_ao_end_from_atom(atom_j) - jstart + 1
1227 kstart = bs_env%i_ao_start_from_atom(atom_k)
1228 ksize = bs_env%i_ao_end_from_atom(atom_k) - kstart + 1
1230 int_3c_prv(1:jsize, 1:ksize, 1:n_loc_ri) = 0.0_dp
1235 ctx, ws, atom_j=atom_j, atom_k=atom_k, atom_i=atom_p, &
1244 jk_idx = (k - 1)*jsize + j
1245 int_2d_prv(jk_idx, ri) = int_3c_prv(j, k, ri)
1252 DO l0 = 1, n_grid_total, grid_chunk
1253 c = min(grid_chunk, n_grid_total - l0 + 1)
1256 jk_idx = (k - 1)*jsize + j
1258 rho_chunk(l, jk_idx) = phi_val(l0 + l - 1, jstart + j - 1)* &
1259 phi_val(l0 + l - 1, kstart + k - 1)
1263 CALL dgemm(
"N",
"N", c, n_loc_ri, jsize*ksize, &
1264 1.0_dp, rho_chunk, grid_chunk, &
1265 int_2d_prv, max_ao_size*max_ao_size, &
1266 1.0_dp, d_lp(l0, 1), n_grid_total)
1272 DEALLOCATE (int_3c_prv, int_2d_prv, rho_chunk)
1277 CALL timestop(handle)
1279 END SUBROUTINE compute_d_lp
1308 tikhonov, para_env_sub, blacs_env_sub, &
1309 fm_struct_D, fm_struct_b, fm_D, fm_b, info)
1311 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(IN) :: phi_local
1312 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: d_vec
1313 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(INOUT) :: d_lp
1314 INTEGER,
INTENT(IN) :: n_loc, n_ao, n_rhs
1315 REAL(kind=
dp),
INTENT(IN) :: tikhonov
1319 TYPE(
cp_fm_type),
INTENT(INOUT) :: fm_d, fm_b
1320 INTEGER,
INTENT(OUT) :: info
1322 CHARACTER(LEN=*),
PARAMETER :: routinen =
'solve_D_lp_distributed'
1324 INTEGER :: handle, i_loc, ig, j_loc, jg, &
1325 ncol_local, nrow_local
1326 INTEGER,
DIMENSION(:),
POINTER :: col_indices, row_indices
1327 REAL(kind=
dp),
CONTIGUOUS,
DIMENSION(:, :), &
1328 POINTER :: local_data
1330 CALL timeset(routinen, handle)
1333 NULLIFY (fm_struct_d, fm_struct_b)
1335 context=blacs_env_sub, &
1336 nrow_global=n_loc, ncol_global=n_loc)
1338 context=blacs_env_sub, &
1339 nrow_global=n_loc, ncol_global=n_rhs)
1349 CALL cp_fm_get_info(fm_d, nrow_local=nrow_local, ncol_local=ncol_local, &
1350 row_indices=row_indices, col_indices=col_indices, &
1351 local_data=local_data)
1353 IF (nrow_local > 0 .AND. ncol_local > 0)
THEN
1355 INTEGER,
PARAMETER :: ntile = 1024
1356 INTEGER :: ib, ie, jb, je, mb, kb, ti, tj
1357 REAL(kind=
dp),
ALLOCATABLE :: gram_t(:, :), phi_cols_t(:, :), phi_rows_t(:, :)
1358 ALLOCATE (phi_rows_t(ntile, n_ao), phi_cols_t(n_ao, ntile), gram_t(ntile, ntile))
1359 DO ib = 1, nrow_local, ntile
1360 ie = min(ib + ntile - 1, nrow_local)
1367 phi_rows_t(ti, j_loc) = phi_local(row_indices(ib + ti - 1), j_loc)
1371 DO jb = 1, ncol_local, ntile
1372 je = min(jb + ntile - 1, ncol_local)
1379 phi_cols_t(i_loc, tj) = phi_local(col_indices(jb + tj - 1), i_loc)
1383 CALL dgemm(
'N',
'N', mb, kb, n_ao, &
1384 1.0_dp, phi_rows_t, ntile, phi_cols_t, n_ao, &
1385 0.0_dp, gram_t, ntile)
1391 jg = col_indices(jb + tj - 1)
1393 ig = row_indices(ib + ti - 1)
1394 local_data(ib + ti - 1, jb + tj - 1) = &
1395 gram_t(ti, tj)*gram_t(ti, tj)*d_vec(ig)*d_vec(jg)
1397 local_data(ib + ti - 1, jb + tj - 1) = &
1398 local_data(ib + ti - 1, jb + tj - 1) + tikhonov
1405 DEALLOCATE (phi_rows_t, phi_cols_t, gram_t)
1416 cpabort(
"pdpotrf failed in solve_D_lp_distributed")
1422 cpabort(
"pdpotrs failed in solve_D_lp_distributed")
1433 CALL timestop(handle)
1445 SUBROUTINE get_mat_chi_gamma_tau(bs_env, mat_chi_Gamma_tau, mat_phi_mu_l, mat_Z_lP)
1447 TYPE(post_scf_bandstructure_type),
POINTER :: bs_env
1448 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: mat_chi_gamma_tau
1449 TYPE(dbcsr_type),
INTENT(INOUT) :: mat_phi_mu_l, mat_z_lp
1451 CHARACTER(LEN=*),
PARAMETER :: routinen =
'get_mat_chi_Gamma_tau'
1453 INTEGER :: handle, i, i_t, ispin, npcol
1454 INTEGER,
DIMENSION(:),
POINTER :: blk_ao, blk_grid, dist_col_ao, &
1455 dist_col_grid, dist_row_grid
1456 REAL(kind=dp) :: t1, tau
1457 TYPE(dbcsr_distribution_type) :: dist_grid_grid, dist_phi
1458 TYPE(dbcsr_type) :: matrix_chi_grid, matrix_chi_grid_spin, &
1459 matrix_g_occ_grid, matrix_g_vir_grid
1461 CALL timeset(routinen, handle)
1466 CALL dbcsr_get_info(mat_phi_mu_l, distribution=dist_phi, row_blk_size=blk_grid, col_blk_size=blk_ao)
1467 CALL dbcsr_distribution_get(dist_phi, row_dist=dist_row_grid, col_dist=dist_col_ao)
1470 npcol = maxval(dist_col_ao) + 1
1473 ALLOCATE (dist_col_grid(
SIZE(blk_grid)))
1474 DO i = 1,
SIZE(blk_grid)
1475 dist_col_grid(i) = mod(i - 1, npcol)
1478 CALL dbcsr_distribution_new(dist_grid_grid, template=dist_phi, &
1479 row_dist=dist_row_grid, col_dist=dist_col_grid)
1481 CALL dbcsr_create(matrix_g_occ_grid,
"G_occ_grid", dist_grid_grid, dbcsr_type_no_symmetry, blk_grid, blk_grid)
1482 CALL dbcsr_create(matrix_g_vir_grid,
"G_vir_grid", dist_grid_grid, dbcsr_type_no_symmetry, blk_grid, blk_grid)
1483 CALL dbcsr_create(matrix_chi_grid,
"chi_grid", dist_grid_grid, dbcsr_type_no_symmetry, blk_grid, blk_grid)
1484 CALL dbcsr_create(matrix_chi_grid_spin,
"chi_grid_spin", dist_grid_grid, dbcsr_type_no_symmetry, blk_grid, blk_grid)
1489 DO i_t = 1, bs_env%num_time_freq_points
1492 tau = bs_env%imag_time_points(i_t)
1493 CALL dbcsr_set(matrix_chi_grid, 0.0_dp)
1498 DO ispin = 1, bs_env%n_spin
1502 CALL build_g_grid(bs_env, tau, ispin, .true., .false., mat_phi_mu_l, &
1503 matrix_g_occ_grid, bs_env%eps_filter)
1507 CALL build_g_grid(bs_env, tau, ispin, .false., .true., mat_phi_mu_l, &
1508 matrix_g_vir_grid, bs_env%eps_filter)
1514 CALL hadamard_product(matrix_g_occ_grid, matrix_g_vir_grid, matrix_chi_grid_spin, bs_env%spin_degeneracy)
1517 CALL dbcsr_add(matrix_chi_grid, matrix_chi_grid_spin, 1.0_dp, 1.0_dp)
1527 CALL contract_a_b_a(
"T",
"N", mat_z_lp, matrix_chi_grid, &
1528 mat_chi_gamma_tau(i_t)%matrix, bs_env%eps_filter)
1530 IF (bs_env%unit_nr > 0)
THEN
1531 WRITE (bs_env%unit_nr,
'(T2,A,I13,A,I3,A,F7.1,A)') &
1532 χτ
'Computed (i,k=0) for time point', i_t,
' /', bs_env%num_time_freq_points, &
1533 ', Execution time', m_walltime() - t1,
' s'
1541 CALL dbcsr_release(matrix_g_occ_grid)
1542 CALL dbcsr_release(matrix_g_vir_grid)
1543 CALL dbcsr_release(matrix_chi_grid)
1544 CALL dbcsr_release(matrix_chi_grid_spin)
1545 CALL dbcsr_distribution_release(dist_grid_grid)
1546 DEALLOCATE (dist_col_grid)
1548 IF (bs_env%unit_nr > 0)
WRITE (bs_env%unit_nr,
'(A)')
' '
1550 CALL timestop(handle)
1552 END SUBROUTINE get_mat_chi_gamma_tau
1566 SUBROUTINE build_g_grid(bs_env, tau, ispin, occ, vir, mat_phi_mu_l, matrix_G_grid, eps_filter)
1568 TYPE(post_scf_bandstructure_type),
POINTER :: bs_env
1569 REAL(kind=dp),
INTENT(IN) :: tau
1570 INTEGER,
INTENT(IN) :: ispin
1571 LOGICAL,
INTENT(IN) :: occ, vir
1572 TYPE(dbcsr_type),
INTENT(INOUT) :: mat_phi_mu_l, matrix_g_grid
1573 REAL(kind=dp),
INTENT(IN) :: eps_filter
1575 CHARACTER(LEN=*),
PARAMETER :: routinen =
'build_G_grid'
1578 INTEGER,
DIMENSION(:),
POINTER :: blk_ao, dist_row_ao
1579 TYPE(cp_fm_type),
POINTER :: fm_g
1580 TYPE(dbcsr_distribution_type) :: dist_ao_ao
1581 TYPE(dbcsr_type) :: matrix_g_ao
1583 CALL timeset(routinen, handle)
1587 fm_g => bs_env%fm_Gocc
1589 fm_g => bs_env%fm_Gvir
1594 CALL g_occ_vir(bs_env, tau, fm_g, ispin, occ=occ, vir=vir)
1597 CALL setup_square_topology(mat_phi_mu_l,
'COL', dist_ao_ao, blk_ao, dist_row_ao)
1599 CALL dbcsr_create(matrix_g_ao, name=
"G_ao", dist=dist_ao_ao, &
1600 matrix_type=dbcsr_type_no_symmetry, &
1601 row_blk_size=blk_ao, col_blk_size=blk_ao)
1604 CALL copy_fm_to_dbcsr(fm_g, matrix_g_ao, keep_sparsity=.false.)
1608 CALL contract_a_b_a(
"N",
"T", mat_phi_mu_l, matrix_g_ao, matrix_g_grid, eps_filter)
1611 CALL release_dbcsr_topology_and_matrices(dist=dist_ao_ao, mapped_dist=dist_row_ao, m1=matrix_g_ao)
1613 CALL timestop(handle)
1615 END SUBROUTINE build_g_grid
1627 SUBROUTINE contract_a_b_a(transA_left, transA_right, matrix_A, matrix_B, matrix_out, eps_filter)
1629 CHARACTER(LEN=1),
INTENT(IN) :: transa_left, transa_right
1630 TYPE(dbcsr_type),
INTENT(INOUT) :: matrix_a, matrix_b, matrix_out
1631 REAL(kind=dp),
INTENT(IN) :: eps_filter
1633 CHARACTER(LEN=*),
PARAMETER :: routinen =
'contract_A_B_A'
1636 TYPE(dbcsr_type) :: matrix_tmp
1638 CALL timeset(routinen, handle)
1640 CALL dbcsr_create(matrix_tmp, template=matrix_a)
1642 IF (transa_left ==
"N" .AND. transa_right ==
"T")
THEN
1644 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, matrix_a, matrix_b, &
1645 0.0_dp, matrix_tmp, filter_eps=eps_filter)
1646 CALL dbcsr_multiply(
"N",
"T", 1.0_dp, matrix_tmp, matrix_a, &
1647 0.0_dp, matrix_out, filter_eps=eps_filter)
1649 ELSE IF (transa_left ==
"T" .AND. transa_right ==
"N")
THEN
1651 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, matrix_b, matrix_a, &
1652 0.0_dp, matrix_tmp, filter_eps=eps_filter)
1653 CALL dbcsr_multiply(
"T",
"N", 1.0_dp, matrix_a, matrix_tmp, &
1654 0.0_dp, matrix_out, filter_eps=eps_filter)
1656 cpabort(
"Unsupported transposition pair in contract_A_B_A")
1659 CALL dbcsr_release(matrix_tmp)
1661 CALL timestop(handle)
1663 END SUBROUTINE contract_a_b_a
1673 SUBROUTINE hadamard_product(matrix_A, matrix_B, matrix_C, fac)
1675 TYPE(dbcsr_type),
INTENT(INOUT) :: matrix_a, matrix_b, matrix_c
1676 REAL(kind=dp),
INTENT(IN) ::
fac
1678 CHARACTER(LEN=*),
PARAMETER :: routinen =
'hadamard_product'
1680 INTEGER :: col, handle, row
1682 REAL(kind=dp),
DIMENSION(:, :),
POINTER :: blk_b, blk_c
1683 TYPE(dbcsr_iterator_type) :: iter
1685 CALL timeset(routinen, handle)
1687 CALL dbcsr_copy(matrix_c, matrix_a)
1689 CALL dbcsr_iterator_start(iter, matrix_c)
1690 DO WHILE (dbcsr_iterator_blocks_left(iter))
1691 CALL dbcsr_iterator_next_block(iter, row, col, blk_c)
1693 CALL dbcsr_get_block_p(matrix_b, row, col, blk_b, found)
1696 blk_c(:, :) =
fac*blk_c(:, :)*blk_b(:, :)
1699 blk_c(:, :) = 0.0_dp
1702 CALL dbcsr_iterator_stop(iter)
1704 CALL timestop(handle)
1706 END SUBROUTINE hadamard_product
1716 SUBROUTINE compute_w(bs_env, qs_env, mat_chi_Gamma_tau, fm_W_time)
1717 TYPE(post_scf_bandstructure_type),
POINTER :: bs_env
1718 TYPE(qs_environment_type),
POINTER :: qs_env
1719 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: mat_chi_gamma_tau
1720 TYPE(cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_w_time
1722 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_W'
1724 INTEGER :: handle, i_t, j_w
1726 TYPE(cp_fm_type) :: fm_m_inv_v_sqrt, fm_v, fm_v_sqrt
1728 CALL timeset(routinen, handle)
1732 CALL create_fm_w_mic_time(bs_env, fm_w_time)
1735 CALL cp_fm_create(fm_v, bs_env%fm_RI_RI%matrix_struct)
1736 CALL cp_fm_create(fm_v_sqrt, bs_env%fm_RI_RI%matrix_struct)
1737 CALL cp_fm_create(fm_m_inv_v_sqrt, bs_env%fm_RI_RI%matrix_struct)
1740 CALL compute_v_minvvsqrt(bs_env, qs_env, fm_v, fm_v_sqrt, fm_m_inv_v_sqrt)
1743 DO j_w = 1, bs_env%num_time_freq_points
1745 CALL compute_fm_chi_gamma_freq(bs_env, bs_env%fm_chi_Gamma_freq, j_w, mat_chi_gamma_tau)
1749 CALL compute_fm_w_freq(bs_env, bs_env%fm_chi_Gamma_freq, fm_v_sqrt, &
1750 fm_m_inv_v_sqrt, bs_env%fm_W_MIC_freq)
1753 CALL fourier_transform_w_to_t(bs_env, fm_w_time, bs_env%fm_W_MIC_freq, j_w)
1757 CALL multiply_fm_w_mic_time_with_minv_gamma(bs_env, qs_env, fm_w_time)
1759 IF (bs_env%unit_nr > 0)
THEN
1760 WRITE (bs_env%unit_nr,
'(T2,A,T55,A,F10.1,A)') &
1761 τ
'Computed W(i),',
' Execution time', m_walltime() - t1,
' s'
1764 CALL dbcsr_deallocate_matrix_set(mat_chi_gamma_tau)
1767 CALL cp_fm_release(fm_v)
1768 CALL cp_fm_release(fm_v_sqrt)
1769 CALL cp_fm_release(fm_m_inv_v_sqrt)
1772 IF (bs_env%rtp_method == rtp_method_bse)
THEN
1774 CALL cp_fm_create(bs_env%fm_W_MIC_freq_zero, bs_env%fm_W_MIC_freq%matrix_struct)
1776 CALL cp_fm_set_all(bs_env%fm_W_MIC_freq_zero, 0.0_dp)
1778 DO i_t = 1, bs_env%num_time_freq_points
1780 CALL cp_fm_scale_and_add(1.0_dp, bs_env%fm_W_MIC_freq_zero, &
1781 bs_env%imag_time_weights_freq_zero(i_t), fm_w_time(i_t))
1784 CALL fm_write(bs_env%fm_W_MIC_freq_zero, 0,
"W_freq_rtp", qs_env)
1786 IF (bs_env%unit_nr > 0)
THEN
1787 WRITE (bs_env%unit_nr,
'(T2,A,T55,A,F10.1,A)') &
1788 'Computed W(0),',
' Execution time', m_walltime() - t1,
' s'
1792 IF (bs_env%unit_nr > 0)
WRITE (bs_env%unit_nr,
'(A)')
' '
1794 CALL timestop(handle)
1796 END SUBROUTINE compute_w
1807 SUBROUTINE compute_v_minvvsqrt(bs_env, qs_env, fm_V, fm_V_sqrt, fm_Minv_Vsqrt)
1808 TYPE(post_scf_bandstructure_type),
POINTER :: bs_env
1809 TYPE(qs_environment_type),
POINTER :: qs_env
1810 TYPE(cp_fm_type),
INTENT(INOUT) :: fm_v, fm_v_sqrt, fm_minv_vsqrt
1812 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_V_MinvVsqrt'
1814 INTEGER :: handle, info, n_ri, ndep
1815 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
1816 TYPE(cell_type),
POINTER :: cell
1817 TYPE(cp_fm_type) :: fm_work
1818 TYPE(cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: fm_m
1819 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: mat_v_kp
1820 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
1821 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
1823 CALL timeset(routinen, handle)
1826 CALL cp_fm_create(fm_work, fm_v%matrix_struct)
1831 CALL get_qs_env(qs_env=qs_env, particle_set=particle_set, cell=cell, &
1832 qs_kind_set=qs_kind_set, atomic_kind_set=atomic_kind_set)
1834 ALLOCATE (mat_v_kp(1:1, 1:2))
1835 NULLIFY (mat_v_kp(1, 1)%matrix, mat_v_kp(1, 2)%matrix)
1836 ALLOCATE (mat_v_kp(1, 1)%matrix, mat_v_kp(1, 2)%matrix)
1838 CALL dbcsr_create(mat_v_kp(1, 1)%matrix, template=bs_env%mat_RI_RI%matrix)
1839 CALL dbcsr_reserve_all_blocks(mat_v_kp(1, 1)%matrix)
1840 CALL dbcsr_set(mat_v_kp(1, 1)%matrix, 0.0_dp)
1843 CALL dbcsr_create(mat_v_kp(1, 2)%matrix, template=bs_env%mat_RI_RI%matrix)
1844 CALL dbcsr_reserve_all_blocks(mat_v_kp(1, 2)%matrix)
1845 CALL dbcsr_set(mat_v_kp(1, 2)%matrix, 0.0_dp)
1847 bs_env%kpoints_chi_eps_W%nkp_grid = bs_env%nkp_grid_chi_eps_W_orig
1849 CALL build_2c_coulomb_matrix_kp(mat_v_kp, bs_env%kpoints_chi_eps_W,
"RI_AUX", cell, &
1850 particle_set, qs_kind_set, atomic_kind_set, &
1851 bs_env%size_lattice_sum_V, operator_coulomb, 1, 1)
1854 CALL copy_dbcsr_to_fm(mat_v_kp(1, 1)%matrix, fm_v)
1856 CALL dbcsr_deallocate_matrix(mat_v_kp(1, 1)%matrix)
1857 CALL dbcsr_deallocate_matrix(mat_v_kp(1, 2)%matrix)
1858 DEALLOCATE (mat_v_kp)
1863 CALL ri_2c_integral_mat(qs_env, fm_m, fm_v, n_ri, bs_env%ri_metric, &
1864 do_kpoints=.false., regularization_ri=bs_env%regularization_RI)
1869 CALL cp_fm_cholesky_decompose(fm_m(1, 1), info_out=info)
1871 CALL cp_fm_cholesky_invert(fm_m(1, 1))
1872 CALL cp_fm_uplo_to_full(fm_m(1, 1), fm_work)
1875 CALL cp_fm_power(fm_m(1, 1), fm_work, -1.0_dp, bs_env%eps_eigval_mat_RI, ndep)
1876 CALL cp_fm_to_fm(fm_work, fm_m(1, 1))
1882 CALL cp_fm_to_fm(fm_v, fm_v_sqrt)
1883 CALL cp_fm_cholesky_decompose(fm_v_sqrt, info_out=info)
1885 CALL clean_lower_part(fm_v_sqrt)
1887 CALL cp_fm_power(fm_v, fm_v_sqrt, 0.5_dp, bs_env%eps_eigval_mat_RI, ndep)
1893 CALL parallel_gemm(
"N",
"T", n_ri, n_ri, n_ri, 1.0_dp, fm_m(1, 1), fm_v_sqrt, &
1894 0.0_dp, fm_minv_vsqrt)
1896 CALL cp_fm_release(fm_m)
1897 CALL cp_fm_release(fm_work)
1899 CALL timestop(handle)
1901 END SUBROUTINE compute_v_minvvsqrt
1912 SUBROUTINE compute_fm_w_freq(bs_env, fm_chi_freq_j, fm_V_sqrt, fm_Minv_Vsqrt, fm_W_freq_j)
1913 TYPE(post_scf_bandstructure_type),
POINTER :: bs_env
1914 TYPE(cp_fm_type),
INTENT(IN) :: fm_chi_freq_j, fm_v_sqrt, fm_minv_vsqrt
1915 TYPE(cp_fm_type),
INTENT(INOUT) :: fm_w_freq_j
1917 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_fm_W_freq'
1919 INTEGER :: handle, info, n_ri, ndep
1920 TYPE(cp_fm_type) :: fm_eps_freq_j, fm_work
1922 CALL timeset(routinen, handle)
1926 CALL cp_fm_create(fm_eps_freq_j, fm_chi_freq_j%matrix_struct)
1927 CALL cp_fm_create(fm_work, fm_chi_freq_j%matrix_struct)
1933 CALL parallel_gemm(
'N',
'N', n_ri, n_ri, n_ri, 1.0_dp, &
1934 fm_chi_freq_j, fm_minv_vsqrt, 0.0_dp, fm_work)
1937 CALL parallel_gemm(
'T',
'N', n_ri, n_ri, n_ri, 1.0_dp, &
1938 fm_minv_vsqrt, fm_work, 0.0_dp, fm_eps_freq_j)
1941 CALL fm_add_on_diag(fm_eps_freq_j, 1.0_dp)
1944 CALL cp_fm_uplo_to_full(fm_eps_freq_j, fm_work)
1951 CALL cp_fm_cholesky_decompose(fm_eps_freq_j, info_out=info)
1955 CALL cp_fm_cholesky_invert(fm_eps_freq_j)
1956 CALL cp_fm_uplo_to_full(fm_eps_freq_j, fm_work)
1959 CALL cp_fm_power(fm_eps_freq_j, fm_work, -1.0_dp, bs_env%eps_eigval_mat_RI, ndep)
1960 CALL cp_fm_to_fm(fm_work, fm_eps_freq_j)
1964 CALL fm_add_on_diag(fm_eps_freq_j, -1.0_dp)
1967 CALL parallel_gemm(
'N',
'N', n_ri, n_ri, n_ri, 1.0_dp, fm_eps_freq_j, fm_v_sqrt, &
1971 CALL parallel_gemm(
'T',
'N', n_ri, n_ri, n_ri, 1.0_dp, fm_v_sqrt, fm_work, &
1972 0.0_dp, fm_w_freq_j)
1975 CALL cp_fm_release(fm_work)
1976 CALL cp_fm_release(fm_eps_freq_j)
1978 CALL timestop(handle)
1980 END SUBROUTINE compute_fm_w_freq
1988 SUBROUTINE fm_add_on_diag(fm, alpha)
1989 TYPE(cp_fm_type),
INTENT(INOUT) :: fm
1990 REAL(kind=dp),
INTENT(IN) :: alpha
1992 CHARACTER(LEN=*),
PARAMETER :: routinen =
'fm_add_on_diag'
1994 INTEGER :: handle, i_global, i_row, j_col, &
1995 j_global, ncol_local, nrow_local
1996 INTEGER,
DIMENSION(:),
POINTER :: col_indices, row_indices
1998 CALL timeset(routinen, handle)
2000 CALL cp_fm_get_info(matrix=fm, &
2001 nrow_local=nrow_local, &
2002 ncol_local=ncol_local, &
2003 row_indices=row_indices, &
2004 col_indices=col_indices)
2006 DO j_col = 1, ncol_local
2007 j_global = col_indices(j_col)
2008 DO i_row = 1, nrow_local
2009 i_global = row_indices(i_row)
2010 IF (j_global == i_global)
THEN
2011 fm%local_data(i_row, j_col) = fm%local_data(i_row, j_col) + alpha
2016 CALL timestop(handle)
2018 END SUBROUTINE fm_add_on_diag
2024 SUBROUTINE clean_lower_part(fm_mat)
2025 TYPE(cp_fm_type) :: fm_mat
2027 CHARACTER(LEN=*),
PARAMETER :: routinen =
'clean_lower_part'
2029 INTEGER :: handle, i_row, j_col, j_global, &
2030 ncol_local, nrow_local
2031 INTEGER,
DIMENSION(:),
POINTER :: col_indices, row_indices
2033 CALL timeset(routinen, handle)
2035 CALL cp_fm_get_info(matrix=fm_mat, &
2036 nrow_local=nrow_local, ncol_local=ncol_local, &
2037 row_indices=row_indices, col_indices=col_indices)
2039 DO j_col = 1, ncol_local
2040 j_global = col_indices(j_col)
2041 DO i_row = 1, nrow_local
2042 IF (j_global < row_indices(i_row)) fm_mat%local_data(i_row, j_col) = 0.0_dp
2046 CALL timestop(handle)
2048 END SUBROUTINE clean_lower_part
2059 SUBROUTINE compute_sigma_x(bs_env, qs_env, mat_phi_mu_l, mat_Z_lP, fm_Sigma_x_Gamma)
2061 TYPE(post_scf_bandstructure_type),
POINTER :: bs_env
2062 TYPE(qs_environment_type),
POINTER :: qs_env
2063 TYPE(dbcsr_type),
INTENT(INOUT) :: mat_phi_mu_l, mat_z_lp
2064 TYPE(cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_sigma_x_gamma
2066 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_Sigma_x'
2068 INTEGER :: handle, ispin
2069 INTEGER,
DIMENSION(:),
POINTER :: blk_aux, blk_grid, dist_col_grid, &
2072 TYPE(cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: fm_vtr_gamma
2073 TYPE(dbcsr_distribution_type) :: dist_aux_aux, dist_grid_grid
2074 TYPE(dbcsr_type) :: mat_sigma_x_gamma, matrix_d_grid, &
2075 matrix_sigma_x_grid, matrix_v_aux, &
2078 CALL timeset(routinen, handle)
2082 ALLOCATE (fm_sigma_x_gamma(bs_env%n_spin))
2083 DO ispin = 1, bs_env%n_spin
2084 CALL cp_fm_create(fm_sigma_x_gamma(ispin), bs_env%fm_s_Gamma%matrix_struct)
2087 CALL dbcsr_create(mat_sigma_x_gamma, template=bs_env%mat_ao_ao%matrix)
2092 CALL setup_square_topology(mat_phi_mu_l,
'ROW', dist_grid_grid, blk_grid, dist_col_grid)
2093 CALL setup_square_topology(mat_z_lp,
'COL', dist_aux_aux, blk_aux, dist_row_aux)
2098 CALL ri_2c_integral_mat(qs_env, fm_vtr_gamma, bs_env%fm_RI_RI, bs_env%n_RI, &
2099 bs_env%trunc_coulomb, do_kpoints=.false.)
2102 CALL multiply_fm_w_mic_time_with_minv_gamma(bs_env, qs_env, fm_vtr_gamma(:, 1))
2104 CALL dbcsr_create(matrix_v_aux,
"V_aux", dist_aux_aux, dbcsr_type_no_symmetry, blk_aux, blk_aux)
2105 CALL dbcsr_create(matrix_v_grid,
"V_grid", dist_grid_grid, dbcsr_type_no_symmetry, blk_grid, blk_grid)
2107 CALL copy_fm_to_dbcsr(fm_vtr_gamma(1, 1), matrix_v_aux, keep_sparsity=.false.)
2110 CALL contract_a_b_a(
"N",
"T", mat_z_lp, matrix_v_aux, matrix_v_grid, bs_env%eps_filter)
2111 CALL dbcsr_release(matrix_v_aux)
2116 DO ispin = 1, bs_env%n_spin
2121 CALL dbcsr_create(matrix_d_grid,
"D_grid", dist_grid_grid, dbcsr_type_no_symmetry, blk_grid, blk_grid)
2122 CALL build_g_grid(bs_env, 0.0_dp, ispin, .true., .false., mat_phi_mu_l, matrix_d_grid, bs_env%eps_filter)
2126 CALL dbcsr_create(matrix_sigma_x_grid, template=matrix_v_grid)
2127 CALL hadamard_product(matrix_d_grid, matrix_v_grid, matrix_sigma_x_grid, 1.0_dp)
2129 CALL dbcsr_release(matrix_d_grid)
2133 CALL contract_a_b_a(
"T",
"N", mat_phi_mu_l, matrix_sigma_x_grid, mat_sigma_x_gamma, bs_env%eps_filter)
2134 CALL dbcsr_scale(mat_sigma_x_gamma, -1.0_dp)
2136 CALL dbcsr_release(matrix_sigma_x_grid)
2139 CALL copy_dbcsr_to_fm(mat_sigma_x_gamma, fm_sigma_x_gamma(ispin))
2143 IF (bs_env%unit_nr > 0)
THEN
2144 WRITE (bs_env%unit_nr,
'(T2,A,T58,A,F7.1,A)') &
2145 Σ
'Computed ^x(k=0),',
' Execution time', m_walltime() - t1,
' s'
2146 WRITE (bs_env%unit_nr,
'(A)')
' '
2152 CALL release_dbcsr_topology_and_matrices(dist=dist_grid_grid, mapped_dist=dist_col_grid, &
2153 m1=mat_sigma_x_gamma, m2=matrix_v_grid)
2154 CALL release_dbcsr_topology_and_matrices(dist=dist_aux_aux, mapped_dist=dist_row_aux)
2156 CALL cp_fm_release(fm_vtr_gamma)
2158 CALL timestop(handle)
2160 END SUBROUTINE compute_sigma_x
2171 SUBROUTINE compute_sigma_c(bs_env, fm_W_time, mat_phi_mu_l, mat_Z_lP, fm_Sigma_c_Gamma_time)
2173 TYPE(post_scf_bandstructure_type),
POINTER :: bs_env
2174 TYPE(cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_w_time
2175 TYPE(dbcsr_type),
INTENT(INOUT) :: mat_phi_mu_l, mat_z_lp
2176 TYPE(cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :, :) :: fm_sigma_c_gamma_time
2178 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_Sigma_c'
2180 INTEGER :: handle, i_t, ispin
2181 INTEGER,
DIMENSION(:),
POINTER :: blk_aux, blk_grid, dist_col_grid, &
2183 REAL(kind=dp) :: t1, tau
2184 TYPE(dbcsr_distribution_type) :: dist_aux_aux, dist_grid_grid
2185 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: mat_sigma_neg_tau, mat_sigma_pos_tau
2186 TYPE(dbcsr_type) :: matrix_g_occ_grid, matrix_g_vir_grid, matrix_sigma_neg_grid, &
2187 matrix_sigma_pos_grid, matrix_w_aux, matrix_w_grid
2189 CALL timeset(routinen, handle)
2194 CALL setup_square_topology(mat_phi_mu_l,
'ROW', dist_grid_grid, blk_grid, dist_col_grid)
2195 CALL setup_square_topology(mat_z_lp,
'COL', dist_aux_aux, blk_aux, dist_row_aux)
2198 NULLIFY (mat_sigma_neg_tau, mat_sigma_pos_tau)
2199 ALLOCATE (mat_sigma_neg_tau(bs_env%num_time_freq_points, bs_env%n_spin))
2200 ALLOCATE (mat_sigma_pos_tau(bs_env%num_time_freq_points, bs_env%n_spin))
2202 DO i_t = 1, bs_env%num_time_freq_points
2203 DO ispin = 1, bs_env%n_spin
2204 ALLOCATE (mat_sigma_neg_tau(i_t, ispin)%matrix)
2205 ALLOCATE (mat_sigma_pos_tau(i_t, ispin)%matrix)
2206 CALL dbcsr_create(mat_sigma_neg_tau(i_t, ispin)%matrix, template=bs_env%mat_ao_ao%matrix)
2207 CALL dbcsr_create(mat_sigma_pos_tau(i_t, ispin)%matrix, template=bs_env%mat_ao_ao%matrix)
2214 DO i_t = 1, bs_env%num_time_freq_points
2215 tau = bs_env%imag_time_points(i_t)
2220 CALL dbcsr_create(matrix_w_aux,
"W_aux", dist_aux_aux, dbcsr_type_no_symmetry, blk_aux, blk_aux)
2221 CALL dbcsr_create(matrix_w_grid,
"W_grid", dist_grid_grid, dbcsr_type_no_symmetry, blk_grid, blk_grid)
2223 CALL copy_fm_to_dbcsr(fm_w_time(i_t), matrix_w_aux, keep_sparsity=.false.)
2226 CALL contract_a_b_a(
"N",
"T", mat_z_lp, matrix_w_aux, matrix_w_grid, bs_env%eps_filter)
2228 CALL dbcsr_release(matrix_w_aux)
2230 DO ispin = 1, bs_env%n_spin
2236 CALL dbcsr_create(matrix_g_occ_grid,
"G_occ_grid", dist_grid_grid, dbcsr_type_no_symmetry, blk_grid, blk_grid)
2237 CALL dbcsr_create(matrix_g_vir_grid,
"G_vir_grid", dist_grid_grid, dbcsr_type_no_symmetry, blk_grid, blk_grid)
2241 CALL build_g_grid(bs_env, tau, ispin, .true., .false., mat_phi_mu_l, matrix_g_occ_grid, bs_env%eps_filter)
2245 CALL build_g_grid(bs_env, tau, ispin, .false., .true., mat_phi_mu_l, matrix_g_vir_grid, bs_env%eps_filter)
2252 CALL dbcsr_create(matrix_sigma_neg_grid, template=matrix_w_grid)
2253 CALL dbcsr_create(matrix_sigma_pos_grid, template=matrix_w_grid)
2256 CALL hadamard_product(matrix_g_occ_grid, matrix_w_grid, matrix_sigma_neg_grid, 1.0_dp)
2259 CALL hadamard_product(matrix_g_vir_grid, matrix_w_grid, matrix_sigma_pos_grid, 1.0_dp)
2262 CALL dbcsr_release(matrix_g_occ_grid)
2263 CALL dbcsr_release(matrix_g_vir_grid)
2271 CALL contract_a_b_a(
"T",
"N", mat_phi_mu_l, matrix_sigma_neg_grid, &
2272 mat_sigma_neg_tau(i_t, ispin)%matrix, bs_env%eps_filter)
2273 CALL dbcsr_scale(mat_sigma_neg_tau(i_t, ispin)%matrix, -1.0_dp)
2276 CALL contract_a_b_a(
"T",
"N", mat_phi_mu_l, matrix_sigma_pos_grid, &
2277 mat_sigma_pos_tau(i_t, ispin)%matrix, bs_env%eps_filter)
2280 CALL dbcsr_release(matrix_sigma_neg_grid)
2281 CALL dbcsr_release(matrix_sigma_pos_grid)
2283 IF (bs_env%unit_nr > 0)
THEN
2284 WRITE (bs_env%unit_nr,
'(T2,A,I10,A,I3,A,F7.1,A)') &
2285 Στ
'Computed ^c(i) for time point ', i_t,
' /', bs_env%num_time_freq_points, &
2286 ', Execution time', m_walltime() - t1,
' s'
2292 CALL dbcsr_release(matrix_w_grid)
2296 IF (bs_env%unit_nr > 0)
WRITE (bs_env%unit_nr,
'(A)')
' '
2301 CALL fill_fm_sigma_c_gamma_time(fm_sigma_c_gamma_time, bs_env, &
2302 mat_sigma_pos_tau, mat_sigma_neg_tau)
2304 CALL cp_fm_release(fm_w_time)
2306 CALL dbcsr_deallocate_matrix_set(mat_sigma_neg_tau)
2307 CALL dbcsr_deallocate_matrix_set(mat_sigma_pos_tau)
2309 CALL release_dbcsr_topology_and_matrices(dist=dist_grid_grid, mapped_dist=dist_col_grid)
2310 CALL release_dbcsr_topology_and_matrices(dist=dist_aux_aux, mapped_dist=dist_row_aux)
2312 CALL delete_unnecessary_files(bs_env)
2313 CALL timestop(handle)
2315 END SUBROUTINE compute_sigma_c
2326 SUBROUTINE setup_square_topology(matrix_template, dim_type, square_dist, blk_sizes, mapped_dist)
2328 TYPE(dbcsr_type),
INTENT(IN) :: matrix_template
2329 CHARACTER(LEN=*),
INTENT(IN) :: dim_type
2330 TYPE(dbcsr_distribution_type),
INTENT(OUT) :: square_dist
2331 INTEGER,
DIMENSION(:),
INTENT(OUT),
POINTER :: blk_sizes, mapped_dist
2334 INTEGER,
DIMENSION(:),
POINTER :: col_blk, col_dist, row_blk, row_dist
2335 TYPE(dbcsr_distribution_type) :: dist_template
2337 CALL dbcsr_get_info(matrix_template, distribution=dist_template, &
2338 row_blk_size=row_blk, col_blk_size=col_blk)
2339 CALL dbcsr_distribution_get(dist_template, row_dist=row_dist, col_dist=col_dist)
2341 IF (trim(dim_type) ==
'ROW')
THEN
2343 blk_sizes => row_blk
2344 np = maxval(col_dist) + 1
2345 ALLOCATE (mapped_dist(
SIZE(blk_sizes)))
2346 DO i = 1,
SIZE(blk_sizes)
2347 mapped_dist(i) = mod(i - 1, np)
2349 CALL dbcsr_distribution_new(square_dist, template=dist_template, &
2350 row_dist=row_dist, col_dist=mapped_dist)
2352 ELSE IF (trim(dim_type) ==
'COL')
THEN
2354 blk_sizes => col_blk
2355 np = maxval(row_dist) + 1
2356 ALLOCATE (mapped_dist(
SIZE(blk_sizes)))
2357 DO i = 1,
SIZE(blk_sizes)
2358 mapped_dist(i) = mod(i - 1, np)
2360 CALL dbcsr_distribution_new(square_dist, template=dist_template, &
2361 row_dist=mapped_dist, col_dist=col_dist)
2364 END SUBROUTINE setup_square_topology
2376 SUBROUTINE release_dbcsr_topology_and_matrices(dist, mapped_dist, m1, m2, m3, m4)
2378 TYPE(dbcsr_distribution_type),
INTENT(INOUT), &
2380 INTEGER,
DIMENSION(:),
INTENT(INOUT),
OPTIONAL, &
2381 POINTER :: mapped_dist
2382 TYPE(dbcsr_type),
INTENT(INOUT),
OPTIONAL :: m1, m2, m3, m4
2384 IF (
PRESENT(dist))
CALL dbcsr_distribution_release(dist)
2385 IF (
PRESENT(mapped_dist))
THEN
2386 IF (
ASSOCIATED(mapped_dist))
THEN
2387 DEALLOCATE (mapped_dist)
2388 NULLIFY (mapped_dist)
2391 IF (
PRESENT(m1))
CALL dbcsr_release(m1)
2392 IF (
PRESENT(m2))
CALL dbcsr_release(m2)
2393 IF (
PRESENT(m3))
CALL dbcsr_release(m3)
2394 IF (
PRESENT(m4))
CALL dbcsr_release(m4)
2396 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.
subroutine, public get_atomic_kind_set(atomic_kind_set, atom_of_kind, kind_of, natom_of_kind, maxatom, natom, nshell, fist_potential_present, shell_present, shell_adiabatic, shell_check_distance, damping_present)
Get attributes of an atomic kind set.
Handles all functions related to the 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.
Utility routines to open and close files. Tracking of preconnections.
subroutine, public open_file(file_name, file_status, file_form, file_action, file_position, file_pad, unit_number, debug, skip_get_unit_number, file_access)
Opens the requested file using a free unit number.
subroutine, public close_file(unit_number, file_status, keep_preconnection)
Close an open file given by its logical unit number. Optionally, keep the file and unit preconnected.
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_solve(matrix, matrixb, n, info_out)
solves A*X = B for X, given the Cholesky decomposition U of the symmetric positive def....
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
subroutine, public cp_fm_struct_create(fmstruct, para_env, context, nrow_global, ncol_global, nrow_block, ncol_block, descriptor, first_p_pos, local_leading_dimension, template_fmstruct, square_blocks, force_block)
allocates and initializes a full matrix structure
subroutine, public cp_fm_struct_release(fmstruct)
releases a full matrix structure
represent a full matrix distributed on many processors
subroutine, public cp_fm_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_submatrix(fm, new_values, start_row, start_col, n_rows, n_cols, alpha, beta, transpose)
sets a submatrix of a full matrix fm(start_row:start_row+n_rows,start_col:start_col+n_cols) = alpha*o...
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
subroutine, public cp_fm_get_submatrix(fm, target_m, start_row, start_col, n_rows, n_cols, transpose)
gets a submatrix of a full matrix op(target_m)(1:n_rows,1:n_cols) =fm(start_row:start_row+n_rows,...
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,...
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 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 gw_calc_non_periodic_ri_rs(qs_env, bs_env)
GW calculation using RI-RS formalism for molecules.
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
integer, parameter, public default_string_length
integer, parameter, public default_path_length
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.