113#include "./base/base_uses.f90"
119 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_collocate_density'
139 MODULE PROCEDURE calculate_rho_core_r3d_rs
140 MODULE PROCEDURE calculate_rho_core_c1d_gs
144 MODULE PROCEDURE calculate_rho_resp_all_r3d_rs, calculate_rho_resp_all_c1d_gs
159 CHARACTER(len=*),
PARAMETER :: routinen =
'calculate_rho_nlcc'
161 INTEGER :: atom_a, handle, iatom, iexp_nlcc, ikind, &
162 ithread, j, n, natom, nc, nexp_nlcc, &
163 ni, npme, nthread, subpatch_pattern
164 INTEGER,
DIMENSION(:),
POINTER :: atom_list, cores, nct_nlcc
166 REAL(kind=
dp) :: alpha, eps_rho_rspace, radius
167 REAL(kind=
dp),
DIMENSION(3) :: ra
168 REAL(kind=
dp),
DIMENSION(:),
POINTER :: alpha_nlcc
169 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: cval_nlcc, pab
177 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
180 CALL timeset(routinen, handle)
182 NULLIFY (cell, dft_control, pab, particle_set, atomic_kind_set, &
183 qs_kind_set, atom_list, pw_env, rs_rho, auxbas_pw_pool, cores)
186 atomic_kind_set=atomic_kind_set, &
187 qs_kind_set=qs_kind_set, &
189 dft_control=dft_control, &
190 particle_set=particle_set, &
192 CALL pw_env_get(pw_env, auxbas_rs_grid=rs_rho, &
193 auxbas_pw_pool=auxbas_pw_pool)
197 eps_rho_rspace = dft_control%qs_control%eps_rho_rspace
199 DO ikind = 1,
SIZE(atomic_kind_set)
200 CALL get_atomic_kind(atomic_kind_set(ikind), natom=natom, atom_list=atom_list)
201 CALL get_qs_kind(qs_kind_set(ikind), gth_potential=gth_potential)
203 IF (.NOT.
ASSOCIATED(gth_potential)) cycle
204 CALL get_potential(potential=gth_potential, nlcc_present=nlcc, nexp_nlcc=nexp_nlcc, &
205 alpha_nlcc=alpha_nlcc, nct_nlcc=nct_nlcc, cval_nlcc=cval_nlcc)
207 IF (.NOT. nlcc) cycle
209 DO iexp_nlcc = 1, nexp_nlcc
211 alpha = alpha_nlcc(iexp_nlcc)
212 nc = nct_nlcc(iexp_nlcc)
215 ALLOCATE (pab(ni, 1))
229 pab(1, 1) = cval_nlcc(1, iexp_nlcc)
232 pab(n, 1) = cval_nlcc(2, iexp_nlcc)/alpha**2
234 pab(n, 1) = cval_nlcc(2, iexp_nlcc)/alpha**2
236 pab(n, 1) = cval_nlcc(2, iexp_nlcc)/alpha**2
239 pab(n, 1) = cval_nlcc(3, iexp_nlcc)/alpha**4
241 pab(n, 1) = cval_nlcc(3, iexp_nlcc)/alpha**4
243 pab(n, 1) = cval_nlcc(3, iexp_nlcc)/alpha**4
245 pab(n, 1) = 2._dp*cval_nlcc(3, iexp_nlcc)/alpha**4
247 pab(n, 1) = 2._dp*cval_nlcc(3, iexp_nlcc)/alpha**4
249 pab(n, 1) = 2._dp*cval_nlcc(3, iexp_nlcc)/alpha**4
252 pab(n, 1) = cval_nlcc(4, iexp_nlcc)/alpha**6
254 pab(n, 1) = cval_nlcc(4, iexp_nlcc)/alpha**6
256 pab(n, 1) = cval_nlcc(4, iexp_nlcc)/alpha**6
258 pab(n, 1) = 3._dp*cval_nlcc(4, iexp_nlcc)/alpha**6
260 pab(n, 1) = 3._dp*cval_nlcc(4, iexp_nlcc)/alpha**6
262 pab(n, 1) = 3._dp*cval_nlcc(4, iexp_nlcc)/alpha**6
264 pab(n, 1) = 3._dp*cval_nlcc(4, iexp_nlcc)/alpha**6
266 pab(n, 1) = 3._dp*cval_nlcc(4, iexp_nlcc)/alpha**6
268 pab(n, 1) = 3._dp*cval_nlcc(4, iexp_nlcc)/alpha**6
270 pab(n, 1) = 6._dp*cval_nlcc(4, iexp_nlcc)/alpha**6
272 CALL cp_abort(__location__, &
273 "Only 1, 2, 3, 4 are supported as the "// &
274 "value of j in calculate_rho_nlcc")
277 IF (dft_control%nspins == 2) pab = pab*0.5_dp
280 atom_a = atom_list(iatom)
281 ra(:) =
pbc(particle_set(atom_a)%r, cell)
282 IF (rs_rho%desc%parallel .AND. .NOT. rs_rho%desc%distributed)
THEN
284 IF (
modulo(iatom, rs_rho%desc%group_size) == rs_rho%desc%my_pos)
THEN
297 atom_a = atom_list(iatom)
298 ra(:) =
pbc(particle_set(atom_a)%r, cell)
302 ra=ra, rb=ra, rp=ra, &
303 zetp=1/(2*alpha**2), eps=eps_rho_rspace, &
304 pab=pab, o1=0, o2=0, &
305 prefactor=1.0_dp, cutoff=0.0_dp)
308 [0.0_dp, 0.0_dp, 0.0_dp], 1.0_dp, pab, 0, 0, rs_rho, &
310 use_subpatch=.true., subpatch_pattern=subpatch_pattern)
320 IF (
ASSOCIATED(cores))
THEN
326 CALL timestop(handle)
340 CHARACTER(len=*),
PARAMETER :: routinen =
'calculate_ppl_grid'
342 INTEGER :: atom_a, handle, iatom, ikind, ithread, &
343 j, lppl, n, natom, ni, npme, nthread, &
345 INTEGER,
DIMENSION(:),
POINTER :: atom_list, cores
346 REAL(kind=
dp) :: alpha, eps_rho_rspace, radius
347 REAL(kind=
dp),
DIMENSION(3) :: ra
348 REAL(kind=
dp),
DIMENSION(:),
POINTER :: cexp_ppl
349 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: pab
357 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
360 CALL timeset(routinen, handle)
362 NULLIFY (cell, dft_control, pab, atomic_kind_set, qs_kind_set, particle_set, &
363 atom_list, pw_env, rs_rho, auxbas_pw_pool, cores)
366 atomic_kind_set=atomic_kind_set, &
367 qs_kind_set=qs_kind_set, &
369 dft_control=dft_control, &
370 particle_set=particle_set, &
372 CALL pw_env_get(pw_env, auxbas_rs_grid=rs_rho, &
373 auxbas_pw_pool=auxbas_pw_pool)
377 eps_rho_rspace = dft_control%qs_control%eps_rho_rspace
379 DO ikind = 1,
SIZE(atomic_kind_set)
380 CALL get_atomic_kind(atomic_kind_set(ikind), natom=natom, atom_list=atom_list)
381 CALL get_qs_kind(qs_kind_set(ikind), gth_potential=gth_potential)
383 IF (.NOT.
ASSOCIATED(gth_potential)) cycle
384 CALL get_potential(potential=gth_potential, alpha_ppl=alpha, nexp_ppl=lppl, cexp_ppl=cexp_ppl)
389 ALLOCATE (pab(ni, 1))
403 pab(1, 1) = cexp_ppl(1)
406 pab(n, 1) = cexp_ppl(2)
408 pab(n, 1) = cexp_ppl(2)
410 pab(n, 1) = cexp_ppl(2)
413 pab(n, 1) = cexp_ppl(3)
415 pab(n, 1) = cexp_ppl(3)
417 pab(n, 1) = cexp_ppl(3)
419 pab(n, 1) = 2._dp*cexp_ppl(3)
421 pab(n, 1) = 2._dp*cexp_ppl(3)
423 pab(n, 1) = 2._dp*cexp_ppl(3)
426 pab(n, 1) = cexp_ppl(4)
428 pab(n, 1) = cexp_ppl(4)
430 pab(n, 1) = cexp_ppl(4)
432 pab(n, 1) = 3._dp*cexp_ppl(4)
434 pab(n, 1) = 3._dp*cexp_ppl(4)
436 pab(n, 1) = 3._dp*cexp_ppl(4)
438 pab(n, 1) = 3._dp*cexp_ppl(4)
440 pab(n, 1) = 3._dp*cexp_ppl(4)
442 pab(n, 1) = 3._dp*cexp_ppl(4)
444 pab(n, 1) = 6._dp*cexp_ppl(4)
446 CALL cp_abort(__location__, &
447 "Only 1, 2, 3, 4 are supported as the "// &
448 "value of j in calculate_ppl_grid")
453 atom_a = atom_list(iatom)
454 ra(:) =
pbc(particle_set(atom_a)%r, cell)
455 IF (rs_rho%desc%parallel .AND. .NOT. rs_rho%desc%distributed)
THEN
457 IF (
modulo(iatom, rs_rho%desc%group_size) == rs_rho%desc%my_pos)
THEN
471 atom_a = atom_list(iatom)
472 ra(:) =
pbc(particle_set(atom_a)%r, cell)
477 lb_min=0, lb_max=0, &
478 ra=ra, rb=ra, rp=ra, &
479 zetp=alpha, eps=eps_rho_rspace, &
480 pab=pab, o1=0, o2=0, &
481 prefactor=1.0_dp, cutoff=0.0_dp)
484 [0.0_dp, 0.0_dp, 0.0_dp], 1.0_dp, pab, 0, 0, rs_rho, &
486 use_subpatch=.true., subpatch_pattern=subpatch_pattern)
495 IF (
ASSOCIATED(cores))
THEN
501 CALL timestop(handle)
521 lri_coef, total_rho, basis_type, exact_1c_terms, pmat, atomlist)
527 REAL(kind=
dp),
INTENT(OUT) :: total_rho
528 CHARACTER(len=*),
INTENT(IN) :: basis_type
529 LOGICAL,
INTENT(IN) :: exact_1c_terms
531 INTEGER,
DIMENSION(:),
OPTIONAL :: atomlist
533 CHARACTER(len=*),
PARAMETER :: routinen =
'calculate_lri_rho_elec'
535 INTEGER :: atom_a, group_size, handle, iatom, igrid_level, ikind, ipgf, iset, jpgf, jset, &
536 m1, maxco, maxsgf_set, my_pos, na1, natom, nb1, ncoa, ncob, nseta, offset, sgfa, sgfb
537 INTEGER,
DIMENSION(:),
POINTER :: atom_list, la_max, la_min, npgfa, nsgfa
538 INTEGER,
DIMENSION(:, :),
POINTER :: first_sgfa
540 LOGICAL,
ALLOCATABLE,
DIMENSION(:) :: map_it
541 LOGICAL,
ALLOCATABLE,
DIMENSION(:, :) :: map_it2
542 REAL(kind=
dp) :: eps_rho_rspace, radius, zetp
543 REAL(kind=
dp),
DIMENSION(3) :: ra
544 REAL(kind=
dp),
DIMENSION(:),
POINTER :: aci
545 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: p_block, pab, sphi_a, work, zeta
556 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
560 NULLIFY (aci, atomic_kind_set, qs_kind_set, atom_list, cell, &
561 dft_control, first_sgfa, gridlevel_info, la_max, &
562 la_min, lri_basis_set, npgfa, nsgfa, &
563 pab, particle_set, pw_env, pw_pools, rs_grid, rs_rho, sphi_a, &
566 CALL timeset(routinen, handle)
568 IF (exact_1c_terms)
THEN
569 cpassert(
PRESENT(pmat))
572 CALL get_qs_env(qs_env=qs_env, qs_kind_set=qs_kind_set, &
573 atomic_kind_set=atomic_kind_set, &
574 cell=cell, particle_set=particle_set, &
576 dft_control=dft_control)
578 eps_rho_rspace = dft_control%qs_control%eps_rho_rspace
579 gridlevel_info => pw_env%gridlevel_info
582 cpassert(
ASSOCIATED(pw_env))
583 CALL pw_env_get(pw_env=pw_env, rs_grids=rs_rho, pw_pools=pw_pools)
590 DO igrid_level = 1, gridlevel_info%ngrid_levels
596 maxco=maxco, basis_type=basis_type)
598 ALLOCATE (pab(maxco, 1))
600 my_pos = mgrid_rspace(1)%pw_grid%para%group%mepos
601 group_size = mgrid_rspace(1)%pw_grid%para%group%num_pe
603 DO ikind = 1,
SIZE(atomic_kind_set)
605 CALL get_atomic_kind(atomic_kind_set(ikind), natom=natom, atom_list=atom_list)
606 CALL get_qs_kind(qs_kind_set(ikind), basis_set=lri_basis_set, basis_type=basis_type)
610 lmin=la_min, zet=zeta, nset=nseta, npgf=npgfa, &
611 sphi=sphi_a, first_sgf=first_sgfa, nsgf_set=nsgfa)
614 atom_a = atom_list(iatom)
615 IF (
PRESENT(atomlist))
THEN
616 IF (atomlist(atom_a) == 0) cycle
618 ra(:) =
pbc(particle_set(atom_a)%r, cell)
619 aci => lri_coef(ikind)%acoef(iatom, :)
621 m1 = maxval(npgfa(1:nseta))
622 ALLOCATE (map_it(m1))
626 DO ipgf = 1, npgfa(iset)
628 rs_grid => rs_rho(igrid_level)
629 map_it(ipgf) =
map_gaussian_here(rs_grid, cell%h_inv, ra, offset, group_size, my_pos)
633 IF (any(map_it(1:npgfa(iset))))
THEN
634 sgfa = first_sgfa(1, iset)
635 ncoa = npgfa(iset)*
ncoset(la_max(iset))
636 m1 = sgfa + nsgfa(iset) - 1
637 ALLOCATE (work(nsgfa(iset), 1))
638 work(1:nsgfa(iset), 1) = aci(sgfa:m1)
641 CALL dgemm(
"N",
"N", ncoa, 1, nsgfa(iset), 1.0_dp, lri_basis_set%sphi(1, sgfa), &
642 SIZE(lri_basis_set%sphi, 1), work(1, 1),
SIZE(work, 1), 0.0_dp, pab(1, 1), &
645 DO ipgf = 1, npgfa(iset)
646 na1 = (ipgf - 1)*
ncoset(la_max(iset))
648 rs_grid => rs_rho(igrid_level)
649 IF (map_it(ipgf))
THEN
651 lb_min=0, lb_max=0, &
652 ra=ra, rb=ra, rp=ra, &
653 zetp=zeta(ipgf, iset), eps=eps_rho_rspace, &
654 prefactor=1.0_dp, cutoff=1.0_dp)
657 zeta=zeta(ipgf, iset), &
658 la_min=la_min(iset), &
659 lb_max=0, zetb=0.0_dp, lb_min=0, &
660 ra=ra, rab=[0.0_dp, 0.0_dp, 0.0_dp], &
662 pab=pab, o1=na1, o2=0, &
678 IF (exact_1c_terms)
THEN
683 maxsgf_set=maxsgf_set, &
685 ALLOCATE (pab(maxco, maxco), work(maxco, maxsgf_set))
687 DO ikind = 1,
SIZE(atomic_kind_set)
688 CALL get_atomic_kind(atomic_kind_set(ikind), natom=natom, atom_list=atom_list)
689 CALL get_qs_kind(qs_kind_set(ikind), basis_set=orb_basis_set, basis_type=
"ORB")
691 lmin=la_min, zet=zeta, nset=nseta, npgf=npgfa, &
692 sphi=sphi_a, first_sgf=first_sgfa, nsgf_set=nsgfa)
694 atom_a = atom_list(iatom)
695 ra(:) =
pbc(particle_set(atom_a)%r, cell)
696 CALL dbcsr_get_block_p(matrix=pmat, row=atom_a, col=atom_a, block=p_block, found=found)
697 m1 = maxval(npgfa(1:nseta))
698 ALLOCATE (map_it2(m1, m1))
703 DO ipgf = 1, npgfa(iset)
704 DO jpgf = 1, npgfa(jset)
705 zetp = zeta(ipgf, iset) + zeta(jpgf, jset)
707 rs_grid => rs_rho(igrid_level)
708 map_it2(ipgf, jpgf) =
map_gaussian_here(rs_grid, cell%h_inv, ra, offset, group_size, my_pos)
713 IF (any(map_it2(1:npgfa(iset), 1:npgfa(jset))))
THEN
714 ncoa = npgfa(iset)*
ncoset(la_max(iset))
715 sgfa = first_sgfa(1, iset)
716 ncob = npgfa(jset)*
ncoset(la_max(jset))
717 sgfb = first_sgfa(1, jset)
719 CALL dgemm(
"N",
"N", ncoa, nsgfa(jset), nsgfa(iset), &
720 1.0_dp, sphi_a(1, sgfa),
SIZE(sphi_a, 1), &
721 p_block(sgfa, sgfb),
SIZE(p_block, 1), &
722 0.0_dp, work(1, 1), maxco)
723 CALL dgemm(
"N",
"T", ncoa, ncob, nsgfa(jset), &
724 1.0_dp, work(1, 1), maxco, &
725 sphi_a(1, sgfb),
SIZE(sphi_a, 1), &
726 0.0_dp, pab(1, 1), maxco)
727 DO ipgf = 1, npgfa(iset)
728 DO jpgf = 1, npgfa(jset)
729 zetp = zeta(ipgf, iset) + zeta(jpgf, jset)
731 rs_grid => rs_rho(igrid_level)
733 na1 = (ipgf - 1)*
ncoset(la_max(iset))
734 nb1 = (jpgf - 1)*
ncoset(la_max(jset))
736 IF (map_it2(ipgf, jpgf))
THEN
738 la_max=la_max(iset), &
739 lb_min=la_min(jset), &
740 lb_max=la_max(jset), &
741 ra=ra, rb=ra, rp=ra, &
742 zetp=zetp, eps=eps_rho_rspace, &
743 prefactor=1.0_dp, cutoff=1.0_dp)
746 la_max(iset), zeta(ipgf, iset), la_min(iset), &
747 la_max(jset), zeta(jpgf, jset), la_min(jset), &
748 ra, [0.0_dp, 0.0_dp, 0.0_dp], 1.0_dp, pab, na1, nb1, &
761 DEALLOCATE (pab, work)
767 DO igrid_level = 1, gridlevel_info%ngrid_levels
768 CALL pw_zero(mgrid_rspace(igrid_level))
770 pw=mgrid_rspace(igrid_level))
773 DO igrid_level = 1, gridlevel_info%ngrid_levels
774 CALL pw_zero(mgrid_gspace(igrid_level))
776 mgrid_gspace(igrid_level))
777 CALL pw_axpy(mgrid_gspace(igrid_level), lri_rho_g)
786 CALL timestop(handle)
799 SUBROUTINE calculate_rho_core_r3d_rs (rho_core, total_rho, qs_env, calpha, ccore, only_nopaw)
802 REAL(KIND=
dp),
INTENT(OUT) :: total_rho
804 REAL(kind=
dp),
DIMENSION(:),
OPTIONAL :: calpha, ccore
805 LOGICAL,
INTENT(IN),
OPTIONAL :: only_nopaw
807 CHARACTER(len=*),
PARAMETER :: routinen =
'calculate_rho_core'
809 INTEGER :: atom_a, handle, iatom, ikind, ithread, &
810 j, natom, npme, nthread, &
812 INTEGER,
DIMENSION(:),
POINTER :: atom_list, cores
813 LOGICAL :: my_only_nopaw, paw_atom
814 REAL(kind=
dp) :: alpha, eps_rho_rspace, radius
815 REAL(kind=
dp),
DIMENSION(3) :: ra
816 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: pab
824 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
827 CALL timeset(routinen, handle)
828 NULLIFY (cell, dft_control, pab, atomic_kind_set, qs_kind_set, particle_set, &
829 atom_list, pw_env, rs_rho, auxbas_pw_pool, cores)
832 my_only_nopaw = .false.
833 IF (
PRESENT(only_nopaw)) my_only_nopaw = only_nopaw
834 IF (
PRESENT(calpha))
THEN
835 cpassert(
PRESENT(ccore))
839 atomic_kind_set=atomic_kind_set, &
840 qs_kind_set=qs_kind_set, &
842 dft_control=dft_control, &
843 particle_set=particle_set, &
845 CALL pw_env_get(pw_env, auxbas_rs_grid=rs_rho, &
846 auxbas_pw_pool=auxbas_pw_pool)
850 eps_rho_rspace = dft_control%qs_control%eps_rho_rspace
852 DO ikind = 1,
SIZE(atomic_kind_set)
853 CALL get_atomic_kind(atomic_kind_set(ikind), natom=natom, atom_list=atom_list)
854 IF (
PRESENT(calpha))
THEN
855 alpha = calpha(ikind)
856 pab(1, 1) = ccore(ikind)
858 CALL get_qs_kind(qs_kind_set(ikind), paw_atom=paw_atom)
859 IF (my_only_nopaw .AND. paw_atom) cycle
860 CALL get_qs_kind(qs_kind_set(ikind), alpha_core_charge=alpha, &
861 ccore_charge=pab(1, 1))
864 IF (my_only_nopaw .AND. paw_atom) cycle
865 IF (alpha == 0.0_dp .OR. pab(1, 1) == 0.0_dp) cycle
875 IF (rs_rho%desc%parallel .AND. .NOT. rs_rho%desc%distributed)
THEN
877 IF (
modulo(iatom, rs_rho%desc%group_size) == rs_rho%desc%my_pos)
THEN
891 atom_a = atom_list(iatom)
892 ra(:) =
pbc(particle_set(atom_a)%r, cell)
895 lb_min=0, lb_max=0, &
896 ra=ra, rb=ra, rp=ra, &
897 zetp=alpha, eps=eps_rho_rspace, &
898 pab=pab, o1=0, o2=0, &
899 prefactor=-1.0_dp, cutoff=0.0_dp)
902 [0.0_dp, 0.0_dp, 0.0_dp], -1.0_dp, pab, 0, 0, rs_rho, &
904 use_subpatch=.true., subpatch_pattern=subpatch_pattern)
911 IF (
ASSOCIATED(cores))
THEN
916 CALL auxbas_pw_pool%create_pw(rhoc_r)
924 CALL auxbas_pw_pool%give_back_pw(rhoc_r)
926 CALL timestop(handle)
928 END SUBROUTINE calculate_rho_core_r3d_rs
938 SUBROUTINE calculate_rho_core_c1d_gs (rho_core, total_rho, qs_env, calpha, ccore, only_nopaw)
941 REAL(KIND=
dp),
INTENT(OUT) :: total_rho
943 REAL(kind=
dp),
DIMENSION(:),
OPTIONAL :: calpha, ccore
944 LOGICAL,
INTENT(IN),
OPTIONAL :: only_nopaw
946 CHARACTER(len=*),
PARAMETER :: routinen =
'calculate_rho_core'
948 INTEGER :: atom_a, handle, iatom, ikind, ithread, &
949 j, natom, npme, nthread, &
951 INTEGER,
DIMENSION(:),
POINTER :: atom_list, cores
952 LOGICAL :: my_only_nopaw, paw_atom
953 REAL(kind=
dp) :: alpha, eps_rho_rspace, radius
954 REAL(kind=
dp),
DIMENSION(3) :: ra
955 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: pab
963 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
966 CALL timeset(routinen, handle)
967 NULLIFY (cell, dft_control, pab, atomic_kind_set, qs_kind_set, particle_set, &
968 atom_list, pw_env, rs_rho, auxbas_pw_pool, cores)
971 my_only_nopaw = .false.
972 IF (
PRESENT(only_nopaw)) my_only_nopaw = only_nopaw
973 IF (
PRESENT(calpha))
THEN
974 cpassert(
PRESENT(ccore))
978 atomic_kind_set=atomic_kind_set, &
979 qs_kind_set=qs_kind_set, &
981 dft_control=dft_control, &
982 particle_set=particle_set, &
984 CALL pw_env_get(pw_env, auxbas_rs_grid=rs_rho, &
985 auxbas_pw_pool=auxbas_pw_pool)
989 eps_rho_rspace = dft_control%qs_control%eps_rho_rspace
991 DO ikind = 1,
SIZE(atomic_kind_set)
992 CALL get_atomic_kind(atomic_kind_set(ikind), natom=natom, atom_list=atom_list)
993 IF (
PRESENT(calpha))
THEN
994 alpha = calpha(ikind)
995 pab(1, 1) = ccore(ikind)
997 CALL get_qs_kind(qs_kind_set(ikind), paw_atom=paw_atom)
998 IF (my_only_nopaw .AND. paw_atom) cycle
999 CALL get_qs_kind(qs_kind_set(ikind), alpha_core_charge=alpha, &
1000 ccore_charge=pab(1, 1))
1003 IF (my_only_nopaw .AND. paw_atom) cycle
1004 IF (alpha == 0.0_dp .OR. pab(1, 1) == 0.0_dp) cycle
1014 IF (rs_rho%desc%parallel .AND. .NOT. rs_rho%desc%distributed)
THEN
1016 IF (
modulo(iatom, rs_rho%desc%group_size) == rs_rho%desc%my_pos)
THEN
1030 atom_a = atom_list(iatom)
1031 ra(:) =
pbc(particle_set(atom_a)%r, cell)
1032 subpatch_pattern = 0
1034 lb_min=0, lb_max=0, &
1035 ra=ra, rb=ra, rp=ra, &
1036 zetp=alpha, eps=eps_rho_rspace, &
1037 pab=pab, o1=0, o2=0, &
1038 prefactor=-1.0_dp, cutoff=0.0_dp)
1041 [0.0_dp, 0.0_dp, 0.0_dp], -1.0_dp, pab, 0, 0, rs_rho, &
1043 use_subpatch=.true., subpatch_pattern=subpatch_pattern)
1050 IF (
ASSOCIATED(cores))
THEN
1055 CALL auxbas_pw_pool%create_pw(rhoc_r)
1063 CALL auxbas_pw_pool%give_back_pw(rhoc_r)
1065 CALL timestop(handle)
1067 END SUBROUTINE calculate_rho_core_c1d_gs
1082 INTEGER,
INTENT(IN) :: beta, lambda
1084 CHARACTER(len=*),
PARAMETER :: routinen =
'calculate_drho_core'
1086 INTEGER :: atom_a, dabqadb_func, handle, iatom, &
1087 ikind, ithread, j, natom, npme, &
1088 nthread, subpatch_pattern
1089 INTEGER,
DIMENSION(:),
POINTER :: atom_list, cores
1090 REAL(kind=
dp) :: alpha, eps_rho_rspace, radius
1091 REAL(kind=
dp),
DIMENSION(3) :: ra
1092 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: pab
1100 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
1103 CALL timeset(routinen, handle)
1104 NULLIFY (cell, dft_control, pab, atomic_kind_set, qs_kind_set, particle_set, &
1105 atom_list, pw_env, rs_rho, auxbas_pw_pool, cores)
1106 ALLOCATE (pab(1, 1))
1109 atomic_kind_set=atomic_kind_set, &
1110 qs_kind_set=qs_kind_set, &
1112 dft_control=dft_control, &
1113 particle_set=particle_set, &
1115 CALL pw_env_get(pw_env, auxbas_rs_grid=rs_rho, &
1116 auxbas_pw_pool=auxbas_pw_pool)
1120 eps_rho_rspace = dft_control%qs_control%eps_rho_rspace
1130 cpabort(
"invalid beta")
1132 DO ikind = 1,
SIZE(atomic_kind_set)
1133 CALL get_atomic_kind(atomic_kind_set(ikind), natom=natom, atom_list=atom_list)
1135 alpha_core_charge=alpha, ccore_charge=pab(1, 1))
1137 IF (alpha == 0.0_dp .OR. pab(1, 1) == 0.0_dp) cycle
1147 IF (rs_rho%desc%parallel .AND. .NOT. rs_rho%desc%distributed)
THEN
1149 IF (
modulo(iatom, rs_rho%desc%group_size) == rs_rho%desc%my_pos)
THEN
1163 atom_a = atom_list(iatom)
1164 IF (atom_a /= lambda) cycle
1165 ra(:) =
pbc(particle_set(atom_a)%r, cell)
1166 subpatch_pattern = 0
1168 lb_min=0, lb_max=0, &
1169 ra=ra, rb=ra, rp=ra, &
1170 zetp=alpha, eps=eps_rho_rspace, &
1171 pab=pab, o1=0, o2=0, &
1172 prefactor=-1.0_dp, cutoff=0.0_dp)
1175 [0.0_dp, 0.0_dp, 0.0_dp], -1.0_dp, pab, 0, 0, rs_rho, &
1176 radius=radius, ga_gb_function=dabqadb_func, &
1177 use_subpatch=.true., subpatch_pattern=subpatch_pattern)
1184 IF (
ASSOCIATED(cores))
THEN
1189 CALL auxbas_pw_pool%create_pw(rhoc_r)
1195 CALL auxbas_pw_pool%give_back_pw(rhoc_r)
1197 CALL timestop(handle)
1214 INTEGER,
INTENT(IN) :: iatom_in
1216 CHARACTER(len=*),
PARAMETER :: routinen =
'calculate_rho_single_gaussian'
1218 INTEGER :: atom_a, handle, iatom, npme, &
1220 REAL(kind=
dp) :: eps_rho_rspace, radius
1221 REAL(kind=
dp),
DIMENSION(3) :: ra
1222 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: pab
1230 CALL timeset(routinen, handle)
1231 NULLIFY (cell, dft_control, pab, pw_env, rs_rho, auxbas_pw_pool)
1233 ALLOCATE (pab(1, 1))
1237 dft_control=dft_control, &
1239 CALL pw_env_get(pw_env, auxbas_rs_grid=rs_rho, &
1240 auxbas_pw_pool=auxbas_pw_pool)
1243 eps_rho_rspace = dft_control%qs_control%eps_rho_rspace
1249 IF (rs_rho%desc%parallel .AND. .NOT. rs_rho%desc%distributed)
THEN
1250 IF (
modulo(iatom, rs_rho%desc%group_size) == rs_rho%desc%my_pos)
THEN
1258 atom_a = qs_env%qmmm_env_qm%image_charge_pot%image_mm_list(iatom)
1259 ra(:) =
pbc(qs_env%qmmm_env_qm%image_charge_pot%particles_all(atom_a)%r, cell)
1260 subpatch_pattern = 0
1262 lb_min=0, lb_max=0, &
1263 ra=ra, rb=ra, rp=ra, &
1264 zetp=qs_env%qmmm_env_qm%image_charge_pot%eta, &
1265 eps=eps_rho_rspace, &
1266 pab=pab, o1=0, o2=0, &
1267 prefactor=1.0_dp, cutoff=0.0_dp)
1270 0, 0, 0.0_dp, 0, ra, [0.0_dp, 0.0_dp, 0.0_dp], 1.0_dp, pab, 0, 0, rs_rho, &
1272 use_subpatch=.true., subpatch_pattern=subpatch_pattern)
1277 CALL auxbas_pw_pool%create_pw(rhoc_r)
1283 CALL auxbas_pw_pool%give_back_pw(rhoc_r)
1285 CALL timestop(handle)
1303 REAL(kind=
dp),
DIMENSION(:),
POINTER :: coeff
1304 REAL(kind=
dp),
INTENT(OUT),
OPTIONAL :: total_rho_metal
1307 CHARACTER(len=*),
PARAMETER :: routinen =
'calculate_rho_metal'
1309 INTEGER :: atom_a, handle, iatom, j, natom, npme, &
1311 INTEGER,
DIMENSION(:),
POINTER :: cores
1312 REAL(kind=
dp) :: eps_rho_rspace, radius
1313 REAL(kind=
dp),
DIMENSION(3) :: ra
1314 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: pab
1322 CALL timeset(routinen, handle)
1324 NULLIFY (cell, dft_control, pab, pw_env, rs_rho, auxbas_pw_pool, cores)
1326 ALLOCATE (pab(1, 1))
1330 dft_control=dft_control, &
1332 CALL pw_env_get(pw_env, auxbas_rs_grid=rs_rho, &
1333 auxbas_pw_pool=auxbas_pw_pool)
1336 eps_rho_rspace = dft_control%qs_control%eps_rho_rspace
1339 natom =
SIZE(qs_env%qmmm_env_qm%image_charge_pot%image_mm_list)
1346 IF (rs_rho%desc%parallel .AND. .NOT. rs_rho%desc%distributed)
THEN
1347 IF (
modulo(iatom, rs_rho%desc%group_size) == rs_rho%desc%my_pos)
THEN
1360 atom_a = qs_env%qmmm_env_qm%image_charge_pot%image_mm_list(iatom)
1361 ra(:) =
pbc(qs_env%qmmm_env_qm%image_charge_pot%particles_all(atom_a)%r, cell)
1362 subpatch_pattern = 0
1364 lb_min=0, lb_max=0, &
1365 ra=ra, rb=ra, rp=ra, &
1366 zetp=qs_env%qmmm_env_qm%image_charge_pot%eta, &
1367 eps=eps_rho_rspace, &
1368 pab=pab, o1=0, o2=0, &
1369 prefactor=coeff(iatom), cutoff=0.0_dp)
1372 0, qs_env%qmmm_env_qm%image_charge_pot%eta, &
1373 0, 0, 0.0_dp, 0, ra, [0.0_dp, 0.0_dp, 0.0_dp], coeff(iatom), pab, 0, 0, rs_rho, &
1375 use_subpatch=.true., subpatch_pattern=subpatch_pattern)
1379 DEALLOCATE (pab, cores)
1381 CALL auxbas_pw_pool%create_pw(rhoc_r)
1385 IF (
PRESENT(total_rho_metal))
THEN
1391 CALL auxbas_pw_pool%give_back_pw(rhoc_r)
1393 CALL timestop(handle)
1411 REAL(kind=
dp),
INTENT(IN) :: eta
1412 INTEGER,
INTENT(IN) :: iatom_in
1414 CHARACTER(len=*),
PARAMETER :: routinen =
'calculate_rho_resp_single'
1416 INTEGER :: handle, iatom, npme, subpatch_pattern
1417 REAL(kind=
dp) :: eps_rho_rspace, radius
1418 REAL(kind=
dp),
DIMENSION(3) :: ra
1419 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: pab
1428 CALL timeset(routinen, handle)
1429 NULLIFY (cell, dft_control, pab, pw_env, rs_rho, auxbas_pw_pool, &
1432 ALLOCATE (pab(1, 1))
1436 dft_control=dft_control, &
1437 particle_set=particle_set, &
1439 CALL pw_env_get(pw_env, auxbas_rs_grid=rs_rho, &
1440 auxbas_pw_pool=auxbas_pw_pool)
1443 eps_rho_rspace = dft_control%qs_control%eps_rho_rspace
1449 IF (rs_rho%desc%parallel .AND. .NOT. rs_rho%desc%distributed)
THEN
1450 IF (
modulo(iatom, rs_rho%desc%group_size) == rs_rho%desc%my_pos)
THEN
1458 ra(:) =
pbc(particle_set(iatom)%r, cell)
1459 subpatch_pattern = 0
1461 lb_min=0, lb_max=0, &
1462 ra=ra, rb=ra, rp=ra, &
1463 zetp=eta, eps=eps_rho_rspace, &
1464 pab=pab, o1=0, o2=0, &
1465 prefactor=1.0_dp, cutoff=0.0_dp)
1468 [0.0_dp, 0.0_dp, 0.0_dp], 1.0_dp, pab, 0, 0, rs_rho, &
1470 use_subpatch=.true., subpatch_pattern=subpatch_pattern)
1475 CALL auxbas_pw_pool%create_pw(rhoc_r)
1481 CALL auxbas_pw_pool%give_back_pw(rhoc_r)
1483 CALL timestop(handle)
1499 SUBROUTINE calculate_rho_resp_all_r3d_rs (rho_resp, coeff, natom, eta, qs_env)
1502 REAL(KIND=
dp),
DIMENSION(:),
POINTER :: coeff
1503 INTEGER,
INTENT(IN) :: natom
1504 REAL(KIND=
dp),
INTENT(IN) :: eta
1507 CHARACTER(len=*),
PARAMETER :: routinen =
'calculate_rho_resp_all'
1509 INTEGER :: handle, iatom, j, npme, subpatch_pattern
1510 INTEGER,
DIMENSION(:),
POINTER :: cores
1511 REAL(kind=
dp) :: eps_rho_rspace, radius
1512 REAL(kind=
dp),
DIMENSION(3) :: ra
1513 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: pab
1522 CALL timeset(routinen, handle)
1524 NULLIFY (cell, cores, dft_control, pab, pw_env, rs_rho, auxbas_pw_pool, &
1527 ALLOCATE (pab(1, 1))
1531 dft_control=dft_control, &
1532 particle_set=particle_set, &
1534 CALL pw_env_get(pw_env, auxbas_rs_grid=rs_rho, &
1535 auxbas_pw_pool=auxbas_pw_pool)
1538 eps_rho_rspace = dft_control%qs_control%eps_rho_rspace
1546 IF (rs_rho%desc%parallel .AND. .NOT. rs_rho%desc%distributed)
THEN
1547 IF (
modulo(iatom, rs_rho%desc%group_size) == rs_rho%desc%my_pos)
THEN
1560 ra(:) =
pbc(particle_set(iatom)%r, cell)
1561 subpatch_pattern = 0
1563 lb_min=0, lb_max=0, &
1564 ra=ra, rb=ra, rp=ra, &
1565 zetp=eta, eps=eps_rho_rspace, &
1566 pab=pab, o1=0, o2=0, &
1567 prefactor=coeff(iatom), cutoff=0.0_dp)
1571 0, 0, 0.0_dp, 0, ra, [0.0_dp, 0.0_dp, 0.0_dp], coeff(iatom), pab, 0, 0, rs_rho, &
1573 use_subpatch=.true., subpatch_pattern=subpatch_pattern)
1577 DEALLOCATE (pab, cores)
1579 CALL auxbas_pw_pool%create_pw(rhoc_r)
1584 CALL auxbas_pw_pool%give_back_pw(rhoc_r)
1586 CALL timestop(handle)
1588 END SUBROUTINE calculate_rho_resp_all_r3d_rs
1601 SUBROUTINE calculate_rho_resp_all_c1d_gs (rho_resp, coeff, natom, eta, qs_env)
1604 REAL(KIND=
dp),
DIMENSION(:),
POINTER :: coeff
1605 INTEGER,
INTENT(IN) :: natom
1606 REAL(KIND=
dp),
INTENT(IN) :: eta
1609 CHARACTER(len=*),
PARAMETER :: routinen =
'calculate_rho_resp_all'
1611 INTEGER :: handle, iatom, j, npme, subpatch_pattern
1612 INTEGER,
DIMENSION(:),
POINTER :: cores
1613 REAL(kind=
dp) :: eps_rho_rspace, radius
1614 REAL(kind=
dp),
DIMENSION(3) :: ra
1615 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: pab
1624 CALL timeset(routinen, handle)
1626 NULLIFY (cell, cores, dft_control, pab, pw_env, rs_rho, auxbas_pw_pool, &
1629 ALLOCATE (pab(1, 1))
1633 dft_control=dft_control, &
1634 particle_set=particle_set, &
1636 CALL pw_env_get(pw_env, auxbas_rs_grid=rs_rho, &
1637 auxbas_pw_pool=auxbas_pw_pool)
1640 eps_rho_rspace = dft_control%qs_control%eps_rho_rspace
1648 IF (rs_rho%desc%parallel .AND. .NOT. rs_rho%desc%distributed)
THEN
1649 IF (
modulo(iatom, rs_rho%desc%group_size) == rs_rho%desc%my_pos)
THEN
1662 ra(:) =
pbc(particle_set(iatom)%r, cell)
1663 subpatch_pattern = 0
1665 lb_min=0, lb_max=0, &
1666 ra=ra, rb=ra, rp=ra, &
1667 zetp=eta, eps=eps_rho_rspace, &
1668 pab=pab, o1=0, o2=0, &
1669 prefactor=coeff(iatom), cutoff=0.0_dp)
1673 0, 0, 0.0_dp, 0, ra, [0.0_dp, 0.0_dp, 0.0_dp], coeff(iatom), pab, 0, 0, rs_rho, &
1675 use_subpatch=.true., subpatch_pattern=subpatch_pattern)
1679 DEALLOCATE (pab, cores)
1681 CALL auxbas_pw_pool%create_pw(rhoc_r)
1686 CALL auxbas_pw_pool%give_back_pw(rhoc_r)
1688 CALL timestop(handle)
1690 END SUBROUTINE calculate_rho_resp_all_c1d_gs
1718 ks_env, soft_valid, compute_tau, compute_grad, &
1719 basis_type, der_type, idir, task_list_external, pw_env_external)
1721 TYPE(
dbcsr_type),
OPTIONAL,
TARGET :: matrix_p
1723 POINTER :: matrix_p_kp
1726 REAL(kind=
dp),
INTENT(OUT),
OPTIONAL :: total_rho
1728 LOGICAL,
INTENT(IN),
OPTIONAL :: soft_valid, compute_tau, compute_grad
1729 CHARACTER(LEN=*),
INTENT(IN),
OPTIONAL :: basis_type
1730 INTEGER,
INTENT(IN),
OPTIONAL :: der_type, idir
1732 TYPE(
pw_env_type),
OPTIONAL,
POINTER :: pw_env_external
1734 CHARACTER(len=*),
PARAMETER :: routinen =
'calculate_rho_elec'
1736 CHARACTER(LEN=default_string_length) :: my_basis_type
1737 INTEGER :: ga_gb_function, handle, ilevel, img, &
1739 LOGICAL :: any_distributed, my_compute_grad, &
1740 my_compute_tau, my_soft_valid
1741 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_images
1748 CALL timeset(routinen, handle)
1750 NULLIFY (matrix_images, dft_control, pw_env, rs_rho, task_list)
1753 my_compute_tau = .false.
1754 IF (
PRESENT(compute_tau)) my_compute_tau = compute_tau
1755 my_compute_grad = .false.
1756 IF (
PRESENT(compute_grad)) my_compute_grad = compute_grad
1757 IF (
PRESENT(der_type))
THEN
1758 SELECT CASE (der_type)
1780 cpabort(
"Unknown der_type")
1782 ELSE IF (my_compute_tau)
THEN
1784 ELSE IF (my_compute_grad)
THEN
1785 cpassert(
PRESENT(idir))
1794 cpabort(
"invalid idir")
1801 my_basis_type =
"ORB"
1802 IF (
PRESENT(basis_type)) my_basis_type = basis_type
1803 cpassert(my_basis_type ==
"ORB" .OR.
PRESENT(task_list_external))
1806 my_soft_valid = .false.
1807 IF (
PRESENT(soft_valid)) my_soft_valid = soft_valid
1808 IF (
PRESENT(task_list_external))
THEN
1809 task_list => task_list_external
1810 ELSE IF (my_soft_valid)
THEN
1811 CALL get_ks_env(ks_env, task_list_soft=task_list)
1815 cpassert(
ASSOCIATED(task_list))
1818 IF (
PRESENT(pw_env_external))
THEN
1819 pw_env => pw_env_external
1823 cpassert(
ASSOCIATED(pw_env))
1827 nlevels =
SIZE(rs_rho)
1828 group = rs_rho(1)%desc%group
1831 any_distributed = .false.
1832 DO ilevel = 1, nlevels
1833 any_distributed = any_distributed .OR. rs_rho(ilevel)%desc%distributed
1837 CALL get_ks_env(ks_env, dft_control=dft_control)
1838 nimages = dft_control%nimages
1839 ALLOCATE (matrix_images(nimages))
1840 IF (
PRESENT(matrix_p_kp))
THEN
1841 cpassert(.NOT.
PRESENT(matrix_p))
1843 matrix_images(img)%matrix => matrix_p_kp(img)%matrix
1846 cpassert(
PRESENT(matrix_p) .AND. nimages == 1)
1847 matrix_images(1)%matrix => matrix_p
1851 IF (any_distributed)
THEN
1856 DEALLOCATE (matrix_images)
1860 ga_gb_function=ga_gb_function, &
1861 pab_blocks=task_list%pab_buffer, &
1868 CALL timestop(handle)
1885 soft_valid, basis_type)
1887 TYPE(
dbcsr_type),
OPTIONAL,
TARGET :: matrix_p
1889 POINTER :: matrix_p_kp
1893 LOGICAL,
INTENT(IN),
OPTIONAL :: soft_valid
1894 CHARACTER(LEN=*),
INTENT(IN),
OPTIONAL :: basis_type
1896 CHARACTER(len=*),
PARAMETER :: routinen =
'calculate_drho_elec'
1898 CHARACTER(LEN=default_string_length) :: my_basis_type
1899 INTEGER :: bcol, brow, dabqadb_func, handle, iatom, iatom_old, idir, igrid_level, ikind, &
1900 ikind_old, img, img_old, ipgf, iset, iset_old, itask, ithread, jatom, jatom_old, jkind, &
1901 jkind_old, jpgf, jset, jset_old, maxco, maxsgf_set, na1, na2, natoms, nb1, nb2, ncoa, &
1902 ncob, nimages, nseta, nsetb, ntasks, nthread, sgfa, sgfb
1903 INTEGER,
DIMENSION(:),
POINTER :: la_max, la_min, lb_max, lb_min, npgfa, &
1905 INTEGER,
DIMENSION(:, :),
POINTER :: first_sgfa, first_sgfb
1906 LOGICAL :: atom_pair_changed, distributed_rs_grids, &
1907 do_kp, found, my_soft, use_subpatch
1908 REAL(kind=
dp) :: eps_rho_rspace, f, prefactor, radius, &
1910 REAL(kind=
dp),
DIMENSION(3) :: ra, rab, rab_inv, rb, rp
1911 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: p_block, pab, sphi_a, sphi_b, work, &
1913 REAL(kind=
dp),
DIMENSION(:, :, :),
POINTER :: pabt, workt
1914 TYPE(
atom_pair_type),
DIMENSION(:),
POINTER :: atom_pair_recv, atom_pair_send
1924 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
1929 TYPE(
task_type),
DIMENSION(:),
POINTER :: tasks
1931 CALL timeset(routinen, handle)
1933 cpassert(
PRESENT(matrix_p) .OR.
PRESENT(matrix_p_kp))
1934 do_kp =
PRESENT(matrix_p_kp)
1936 NULLIFY (cell, dft_control, orb_basis_set, deltap, qs_kind_set, &
1937 sab_orb, particle_set, rs_rho, pw_env, rs_descs, la_max, la_min, &
1938 lb_max, lb_min, npgfa, npgfb, nsgfa, nsgfb, p_block, sphi_a, &
1939 sphi_b, zeta, zetb, first_sgfa, first_sgfb, tasks, pabt, workt)
1943 IF (
PRESENT(soft_valid)) my_soft = soft_valid
1945 IF (
PRESENT(basis_type))
THEN
1946 my_basis_type = basis_type
1948 my_basis_type =
"ORB"
1952 qs_kind_set=qs_kind_set, &
1954 dft_control=dft_control, &
1955 particle_set=particle_set, &
1959 SELECT CASE (my_basis_type)
1962 task_list=task_list, &
1963 task_list_soft=task_list_soft)
1966 task_list_soft=task_list_soft)
1967 CALL get_admm_env(qs_env%admm_env, task_list_aux_fit=task_list)
1971 gridlevel_info => pw_env%gridlevel_info
1977 maxsgf_set=maxsgf_set, &
1978 basis_type=my_basis_type)
1979 CALL reallocate(pabt, 1, maxco, 1, maxco, 0, nthread - 1)
1980 CALL reallocate(workt, 1, maxco, 1, maxsgf_set, 0, nthread - 1)
1983 nimages = dft_control%nimages
1984 cpassert(nimages == 1 .OR. do_kp)
1986 natoms =
SIZE(particle_set)
1989 IF (my_soft) task_list => task_list_soft
1990 cpassert(
ASSOCIATED(task_list))
1991 tasks => task_list%tasks
1992 atom_pair_send => task_list%atom_pair_send
1993 atom_pair_recv => task_list%atom_pair_recv
1994 ntasks = task_list%ntasks
1997 cpassert(
ASSOCIATED(pw_env))
1998 CALL pw_env_get(pw_env, rs_descs=rs_descs, rs_grids=rs_rho)
1999 DO igrid_level = 1, gridlevel_info%ngrid_levels
2000 distributed_rs_grids = rs_rho(igrid_level)%desc%distributed
2003 eps_rho_rspace = dft_control%qs_control%eps_rho_rspace
2008 ALLOCATE (deltap(nimages))
2009 IF (distributed_rs_grids)
THEN
2016 CALL dbcsr_copy(deltap(img)%matrix, matrix_p_kp(img)%matrix, &
2020 CALL dbcsr_copy(deltap(1)%matrix, matrix_p, name=
"DeltaP")
2025 deltap(img)%matrix => matrix_p_kp(img)%matrix
2028 deltap(1)%matrix => matrix_p
2033 IF (distributed_rs_grids)
THEN
2035 atom_pair_send=atom_pair_send, atom_pair_recv=atom_pair_recv, &
2036 nimages=nimages, scatter=.true.)
2042 pab => pabt(:, :, ithread)
2043 work => workt(:, :, ithread)
2045 loop_xyz:
DO idir = 1, 3
2047 DO igrid_level = 1, gridlevel_info%ngrid_levels
2051 iatom_old = -1; jatom_old = -1; iset_old = -1; jset_old = -1
2052 ikind_old = -1; jkind_old = -1; img_old = -1
2053 loop_tasks:
DO itask = 1, ntasks
2056 igrid_level = tasks(itask)%grid_level
2057 img = tasks(itask)%image
2058 iatom = tasks(itask)%iatom
2059 jatom = tasks(itask)%jatom
2060 iset = tasks(itask)%iset
2061 jset = tasks(itask)%jset
2062 ipgf = tasks(itask)%ipgf
2063 jpgf = tasks(itask)%jpgf
2065 ikind = particle_set(iatom)%atomic_kind%kind_number
2066 jkind = particle_set(jatom)%atomic_kind%kind_number
2068 IF (iatom /= iatom_old .OR. jatom /= jatom_old .OR. img /= img_old)
THEN
2070 IF (iatom /= iatom_old) ra(:) =
pbc(particle_set(iatom)%r, cell)
2072 IF (iatom <= jatom)
THEN
2080 IF (ikind /= ikind_old)
THEN
2082 CALL get_qs_kind(qs_kind_set(ikind), basis_set=orb_basis_set, &
2083 basis_type=
"ORB_SOFT")
2085 CALL get_qs_kind(qs_kind_set(ikind), basis_set=orb_basis_set, &
2086 basis_type=my_basis_type)
2089 first_sgf=first_sgfa, &
2099 IF (jkind /= jkind_old)
THEN
2101 CALL get_qs_kind(qs_kind_set(jkind), basis_set=orb_basis_set, &
2102 basis_type=
"ORB_SOFT")
2104 CALL get_qs_kind(qs_kind_set(jkind), basis_set=orb_basis_set, &
2105 basis_type=my_basis_type)
2108 first_sgf=first_sgfb, &
2119 row=brow, col=bcol, block=p_block, found=found)
2127 atom_pair_changed = .true.
2131 atom_pair_changed = .false.
2135 IF (atom_pair_changed .OR. iset_old /= iset .OR. jset_old /= jset)
THEN
2137 ncoa = npgfa(iset)*
ncoset(la_max(iset))
2138 sgfa = first_sgfa(1, iset)
2139 ncob = npgfb(jset)*
ncoset(lb_max(jset))
2140 sgfb = first_sgfb(1, jset)
2142 IF (iatom <= jatom)
THEN
2143 CALL dgemm(
"N",
"N", ncoa, nsgfb(jset), nsgfa(iset), &
2144 1.0_dp, sphi_a(1, sgfa),
SIZE(sphi_a, 1), &
2145 p_block(sgfa, sgfb),
SIZE(p_block, 1), &
2146 0.0_dp, work(1, 1), maxco)
2147 CALL dgemm(
"N",
"T", ncoa, ncob, nsgfb(jset), &
2148 1.0_dp, work(1, 1), maxco, &
2149 sphi_b(1, sgfb),
SIZE(sphi_b, 1), &
2150 0.0_dp, pab(1, 1), maxco)
2152 CALL dgemm(
"N",
"N", ncob, nsgfa(iset), nsgfb(jset), &
2153 1.0_dp, sphi_b(1, sgfb),
SIZE(sphi_b, 1), &
2154 p_block(sgfb, sgfa),
SIZE(p_block, 1), &
2155 0.0_dp, work(1, 1), maxco)
2156 CALL dgemm(
"N",
"T", ncob, ncoa, nsgfa(iset), &
2157 1.0_dp, work(1, 1), maxco, &
2158 sphi_a(1, sgfa),
SIZE(sphi_a, 1), &
2159 0.0_dp, pab(1, 1), maxco)
2167 rab(:) = tasks(itask)%rab
2168 rb(:) = ra(:) + rab(:)
2169 zetp = zeta(ipgf, iset) + zetb(jpgf, jset)
2171 f = zetb(jpgf, jset)/zetp
2172 rp(:) = ra(:) + f*rab(:)
2173 prefactor = exp(-zeta(ipgf, iset)*f*dot_product(rab, rab))
2175 lb_min=lb_min(jset), lb_max=lb_max(jset), &
2176 ra=ra, rb=rb, rp=rp, &
2177 zetp=zeta(ipgf, iset), eps=eps_rho_rspace, &
2178 prefactor=prefactor, cutoff=1.0_dp)
2180 na1 = (ipgf - 1)*
ncoset(la_max(iset)) + 1
2181 na2 = ipgf*
ncoset(la_max(iset))
2182 nb1 = (jpgf - 1)*
ncoset(lb_max(jset)) + 1
2183 nb2 = jpgf*
ncoset(lb_max(jset))
2186 IF (iatom == jatom .AND. img == 1)
THEN
2193 IF (rs_rho(igrid_level)%desc%distributed)
THEN
2195 IF (tasks(itask)%dist_type == 2)
THEN
2196 use_subpatch = .true.
2198 use_subpatch = .false.
2201 use_subpatch = .false.
2212 cpabort(
"invalid idir")
2215 IF (iatom <= jatom)
THEN
2217 la_max(iset), zeta(ipgf, iset), la_min(iset), &
2218 lb_max(jset), zetb(jpgf, jset), lb_min(jset), &
2219 ra, rab, scale, pab, na1 - 1, nb1 - 1, &
2220 rs_rho(igrid_level), &
2221 radius=radius, ga_gb_function=dabqadb_func, &
2222 use_subpatch=use_subpatch, subpatch_pattern=tasks(itask)%subpatch_pattern)
2226 lb_max(jset), zetb(jpgf, jset), lb_min(jset), &
2227 la_max(iset), zeta(ipgf, iset), la_min(iset), &
2228 rb, rab_inv, scale, pab, nb1 - 1, na1 - 1, &
2229 rs_rho(igrid_level), &
2230 radius=radius, ga_gb_function=dabqadb_func, &
2231 use_subpatch=use_subpatch, subpatch_pattern=tasks(itask)%subpatch_pattern)
2236 CALL density_rs2pw(pw_env, rs_rho, drho(idir), drho_gspace(idir))
2241 IF (distributed_rs_grids)
THEN
2245 NULLIFY (deltap(img)%matrix)
2250 DEALLOCATE (pabt, workt)
2252 CALL timestop(handle)
2272 soft_valid, basis_type, beta, lambda)
2274 TYPE(
dbcsr_type),
OPTIONAL,
TARGET :: matrix_p
2276 POINTER :: matrix_p_kp
2280 LOGICAL,
INTENT(IN),
OPTIONAL :: soft_valid
2281 CHARACTER(LEN=*),
INTENT(IN),
OPTIONAL :: basis_type
2282 INTEGER,
INTENT(IN) :: beta, lambda
2284 CHARACTER(len=*),
PARAMETER :: routinen =
'calculate_drho_elec_dR'
2286 CHARACTER(LEN=default_string_length) :: my_basis_type
2287 INTEGER :: bcol, brow, dabqadb_func, handle, iatom, iatom_old, igrid_level, ikind, &
2288 ikind_old, img, img_old, ipgf, iset, iset_old, itask, ithread, jatom, jatom_old, jkind, &
2289 jkind_old, jpgf, jset, jset_old, maxco, maxsgf_set, na1, na2, natoms, nb1, nb2, ncoa, &
2290 ncob, nimages, nseta, nsetb, ntasks, nthread, sgfa, sgfb
2291 INTEGER,
DIMENSION(:),
POINTER :: la_max, la_min, lb_max, lb_min, npgfa, &
2293 INTEGER,
DIMENSION(:, :),
POINTER :: first_sgfa, first_sgfb
2294 LOGICAL :: atom_pair_changed, distributed_rs_grids, &
2295 do_kp, found, my_soft, use_subpatch
2296 REAL(kind=
dp) :: eps_rho_rspace, f, prefactor, radius, &
2298 REAL(kind=
dp),
DIMENSION(3) :: ra, rab, rab_inv, rb, rp
2299 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: p_block, pab, sphi_a, sphi_b, work, &
2301 REAL(kind=
dp),
DIMENSION(:, :, :),
POINTER :: pabt, workt
2302 TYPE(
atom_pair_type),
DIMENSION(:),
POINTER :: atom_pair_recv, atom_pair_send
2310 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
2315 TYPE(
task_type),
DIMENSION(:),
POINTER :: tasks
2317 CALL timeset(routinen, handle)
2319 cpassert(
PRESENT(matrix_p) .OR.
PRESENT(matrix_p_kp))
2320 do_kp =
PRESENT(matrix_p_kp)
2322 NULLIFY (cell, dft_control, orb_basis_set, deltap, qs_kind_set, &
2323 particle_set, rs_rho, pw_env, rs_descs, la_max, la_min, lb_max, &
2324 lb_min, npgfa, npgfb, nsgfa, nsgfb, p_block, sphi_a, sphi_b, &
2325 zeta, zetb, first_sgfa, first_sgfb, tasks, pabt, workt)
2329 IF (
PRESENT(soft_valid)) my_soft = soft_valid
2331 IF (
PRESENT(basis_type))
THEN
2332 my_basis_type = basis_type
2334 my_basis_type =
"ORB"
2338 qs_kind_set=qs_kind_set, &
2340 dft_control=dft_control, &
2341 particle_set=particle_set, &
2344 SELECT CASE (my_basis_type)
2347 task_list=task_list, &
2348 task_list_soft=task_list_soft)
2351 task_list_soft=task_list_soft)
2352 CALL get_admm_env(qs_env%admm_env, task_list_aux_fit=task_list)
2356 gridlevel_info => pw_env%gridlevel_info
2362 maxsgf_set=maxsgf_set, &
2363 basis_type=my_basis_type)
2364 CALL reallocate(pabt, 1, maxco, 1, maxco, 0, nthread - 1)
2365 CALL reallocate(workt, 1, maxco, 1, maxsgf_set, 0, nthread - 1)
2368 nimages = dft_control%nimages
2369 cpassert(nimages == 1 .OR. do_kp)
2371 natoms =
SIZE(particle_set)
2374 IF (my_soft) task_list => task_list_soft
2375 cpassert(
ASSOCIATED(task_list))
2376 tasks => task_list%tasks
2377 atom_pair_send => task_list%atom_pair_send
2378 atom_pair_recv => task_list%atom_pair_recv
2379 ntasks = task_list%ntasks
2382 cpassert(
ASSOCIATED(pw_env))
2383 CALL pw_env_get(pw_env, rs_descs=rs_descs, rs_grids=rs_rho)
2384 DO igrid_level = 1, gridlevel_info%ngrid_levels
2385 distributed_rs_grids = rs_rho(igrid_level)%desc%distributed
2388 eps_rho_rspace = dft_control%qs_control%eps_rho_rspace
2393 ALLOCATE (deltap(nimages))
2394 IF (distributed_rs_grids)
THEN
2401 CALL dbcsr_copy(deltap(img)%matrix, matrix_p_kp(img)%matrix, &
2405 CALL dbcsr_copy(deltap(1)%matrix, matrix_p, name=
"DeltaP")
2410 deltap(img)%matrix => matrix_p_kp(img)%matrix
2413 deltap(1)%matrix => matrix_p
2418 IF (distributed_rs_grids)
THEN
2420 atom_pair_send=atom_pair_send, atom_pair_recv=atom_pair_recv, &
2421 nimages=nimages, scatter=.true.)
2427 pab => pabt(:, :, ithread)
2428 work => workt(:, :, ithread)
2430 DO igrid_level = 1, gridlevel_info%ngrid_levels
2434 iatom_old = -1; jatom_old = -1; iset_old = -1; jset_old = -1
2435 ikind_old = -1; jkind_old = -1; img_old = -1
2436 loop_tasks:
DO itask = 1, ntasks
2439 igrid_level = tasks(itask)%grid_level
2440 img = tasks(itask)%image
2441 iatom = tasks(itask)%iatom
2442 jatom = tasks(itask)%jatom
2443 iset = tasks(itask)%iset
2444 jset = tasks(itask)%jset
2445 ipgf = tasks(itask)%ipgf
2446 jpgf = tasks(itask)%jpgf
2448 ikind = particle_set(iatom)%atomic_kind%kind_number
2449 jkind = particle_set(jatom)%atomic_kind%kind_number
2451 IF (iatom /= iatom_old .OR. jatom /= jatom_old .OR. img /= img_old)
THEN
2453 IF (iatom /= iatom_old) ra(:) =
pbc(particle_set(iatom)%r, cell)
2455 IF (iatom <= jatom)
THEN
2463 IF (ikind /= ikind_old)
THEN
2465 CALL get_qs_kind(qs_kind_set(ikind), basis_set=orb_basis_set, &
2466 basis_type=
"ORB_SOFT")
2468 CALL get_qs_kind(qs_kind_set(ikind), basis_set=orb_basis_set, &
2469 basis_type=my_basis_type)
2472 first_sgf=first_sgfa, &
2482 IF (jkind /= jkind_old)
THEN
2484 CALL get_qs_kind(qs_kind_set(jkind), basis_set=orb_basis_set, &
2485 basis_type=
"ORB_SOFT")
2487 CALL get_qs_kind(qs_kind_set(jkind), basis_set=orb_basis_set, &
2488 basis_type=my_basis_type)
2491 first_sgf=first_sgfb, &
2502 row=brow, col=bcol, block=p_block, found=found)
2510 atom_pair_changed = .true.
2514 atom_pair_changed = .false.
2518 IF (atom_pair_changed .OR. iset_old /= iset .OR. jset_old /= jset)
THEN
2520 ncoa = npgfa(iset)*
ncoset(la_max(iset))
2521 sgfa = first_sgfa(1, iset)
2522 ncob = npgfb(jset)*
ncoset(lb_max(jset))
2523 sgfb = first_sgfb(1, jset)
2525 IF (iatom <= jatom)
THEN
2526 CALL dgemm(
"N",
"N", ncoa, nsgfb(jset), nsgfa(iset), &
2527 1.0_dp, sphi_a(1, sgfa),
SIZE(sphi_a, 1), &
2528 p_block(sgfa, sgfb),
SIZE(p_block, 1), &
2529 0.0_dp, work(1, 1), maxco)
2530 CALL dgemm(
"N",
"T", ncoa, ncob, nsgfb(jset), &
2531 1.0_dp, work(1, 1), maxco, &
2532 sphi_b(1, sgfb),
SIZE(sphi_b, 1), &
2533 0.0_dp, pab(1, 1), maxco)
2535 CALL dgemm(
"N",
"N", ncob, nsgfa(iset), nsgfb(jset), &
2536 1.0_dp, sphi_b(1, sgfb),
SIZE(sphi_b, 1), &
2537 p_block(sgfb, sgfa),
SIZE(p_block, 1), &
2538 0.0_dp, work(1, 1), maxco)
2539 CALL dgemm(
"N",
"T", ncob, ncoa, nsgfa(iset), &
2540 1.0_dp, work(1, 1), maxco, &
2541 sphi_a(1, sgfa),
SIZE(sphi_a, 1), &
2542 0.0_dp, pab(1, 1), maxco)
2550 rab(:) = tasks(itask)%rab
2551 rb(:) = ra(:) + rab(:)
2552 zetp = zeta(ipgf, iset) + zetb(jpgf, jset)
2554 f = zetb(jpgf, jset)/zetp
2555 rp(:) = ra(:) + f*rab(:)
2556 prefactor = exp(-zeta(ipgf, iset)*f*dot_product(rab, rab))
2558 lb_min=lb_min(jset), lb_max=lb_max(jset), &
2559 ra=ra, rb=rb, rp=rp, &
2560 zetp=zetp, eps=eps_rho_rspace, &
2561 prefactor=prefactor, cutoff=1.0_dp)
2563 na1 = (ipgf - 1)*
ncoset(la_max(iset)) + 1
2564 na2 = ipgf*
ncoset(la_max(iset))
2565 nb1 = (jpgf - 1)*
ncoset(lb_max(jset)) + 1
2566 nb2 = jpgf*
ncoset(lb_max(jset))
2569 IF (iatom == jatom .AND. img == 1)
THEN
2576 IF (rs_rho(igrid_level)%desc%distributed)
THEN
2578 IF (tasks(itask)%dist_type == 2)
THEN
2579 use_subpatch = .true.
2581 use_subpatch = .false.
2584 use_subpatch = .false.
2595 cpabort(
"invalid beta")
2598 IF (iatom <= jatom)
THEN
2599 IF (iatom == lambda)
THEN
2601 la_max(iset), zeta(ipgf, iset), la_min(iset), &
2602 lb_max(jset), zetb(jpgf, jset), lb_min(jset), &
2603 ra, rab, scale, pab, na1 - 1, nb1 - 1, &
2604 rsgrid=rs_rho(igrid_level), &
2605 ga_gb_function=dabqadb_func, radius=radius, &
2606 use_subpatch=use_subpatch, &
2607 subpatch_pattern=tasks(itask)%subpatch_pattern)
2609 IF (jatom == lambda)
THEN
2611 la_max(iset), zeta(ipgf, iset), la_min(iset), &
2612 lb_max(jset), zetb(jpgf, jset), lb_min(jset), &
2613 ra, rab, scale, pab, na1 - 1, nb1 - 1, &
2614 rsgrid=rs_rho(igrid_level), &
2615 ga_gb_function=dabqadb_func + 3, radius=radius, &
2616 use_subpatch=use_subpatch, &
2617 subpatch_pattern=tasks(itask)%subpatch_pattern)
2621 IF (jatom == lambda)
THEN
2623 lb_max(jset), zetb(jpgf, jset), lb_min(jset), &
2624 la_max(iset), zeta(ipgf, iset), la_min(iset), &
2625 rb, rab_inv, scale, pab, nb1 - 1, na1 - 1, &
2626 rs_rho(igrid_level), &
2627 ga_gb_function=dabqadb_func, radius=radius, &
2628 use_subpatch=use_subpatch, &
2629 subpatch_pattern=tasks(itask)%subpatch_pattern)
2631 IF (iatom == lambda)
THEN
2633 lb_max(jset), zetb(jpgf, jset), lb_min(jset), &
2634 la_max(iset), zeta(ipgf, iset), la_min(iset), &
2635 rb, rab_inv, scale, pab, nb1 - 1, na1 - 1, &
2636 rs_rho(igrid_level), &
2637 ga_gb_function=dabqadb_func + 3, radius=radius, &
2638 use_subpatch=use_subpatch, &
2639 subpatch_pattern=tasks(itask)%subpatch_pattern)
2648 IF (distributed_rs_grids)
THEN
2652 NULLIFY (deltap(img)%matrix)
2657 DEALLOCATE (pabt, workt)
2659 CALL timestop(handle)
2682 atomic_kind_set, qs_kind_set, cell, dft_control, particle_set, &
2683 pw_env, required_function, basis_type)
2688 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
2693 INTEGER,
INTENT(IN) :: required_function
2694 CHARACTER(LEN=*),
INTENT(IN),
OPTIONAL :: basis_type
2696 CHARACTER(LEN=*),
PARAMETER :: routinen =
'collocate_single_gaussian'
2698 CHARACTER(LEN=default_string_length) :: my_basis_type
2699 INTEGER :: group_size, handle, i, iatom, igrid_level, ikind, ipgf, iset, maxco, maxsgf_set, &
2700 my_index, my_pos, na1, na2, natom, ncoa, nseta, offset, sgfa
2701 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: where_is_the_point
2702 INTEGER,
DIMENSION(:),
POINTER :: la_max, la_min, npgfa, nsgfa
2703 INTEGER,
DIMENSION(:, :),
POINTER :: first_sgfa
2705 REAL(kind=
dp) :: dab, eps_rho_rspace, radius, scale
2706 REAL(kind=
dp),
DIMENSION(3) :: ra
2707 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: pab, sphi_a, zeta
2716 IF (
PRESENT(basis_type))
THEN
2717 my_basis_type = basis_type
2719 my_basis_type =
"ORB"
2722 CALL timeset(routinen, handle)
2724 NULLIFY (orb_basis_set, pab, la_max, la_min, npgfa, nsgfa, sphi_a, &
2725 zeta, first_sgfa, rs_rho, pw_pools)
2728 cpassert(
ASSOCIATED(pw_env))
2729 CALL pw_env_get(pw_env, rs_grids=rs_rho, pw_pools=pw_pools, &
2730 gridlevel_info=gridlevel_info)
2736 DO igrid_level = 1, gridlevel_info%ngrid_levels
2740 eps_rho_rspace = dft_control%qs_control%eps_rho_rspace
2745 maxsgf_set=maxsgf_set, &
2746 basis_type=my_basis_type)
2748 ALLOCATE (pab(maxco, 1))
2751 group = mgrid_rspace(1)%pw_grid%para%group
2752 my_pos = mgrid_rspace(1)%pw_grid%para%group%mepos
2753 group_size = mgrid_rspace(1)%pw_grid%para%group%num_pe
2754 ALLOCATE (where_is_the_point(0:group_size - 1))
2757 ikind = particle_set(iatom)%atomic_kind%kind_number
2758 CALL get_qs_kind(qs_kind_set(ikind), basis_set=orb_basis_set, basis_type=my_basis_type)
2760 first_sgf=first_sgfa, &
2768 ra(:) =
pbc(particle_set(iatom)%r, cell)
2773 ncoa = npgfa(iset)*
ncoset(la_max(iset))
2774 sgfa = first_sgfa(1, iset)
2778 DO i = 1, nsgfa(iset)
2779 IF (offset + i == required_function)
THEN
2788 pab(1:ncoa, 1) = sphi_a(1:ncoa, sgfa + my_index - 1)
2790 DO ipgf = 1, npgfa(iset)
2792 na1 = (ipgf - 1)*
ncoset(la_max(iset)) + 1
2793 na2 = ipgf*
ncoset(la_max(iset))
2798 IF (
map_gaussian_here(rs_rho(igrid_level), cell%h_inv, ra, offset, group_size, my_pos))
THEN
2800 lb_min=0, lb_max=0, ra=ra, rb=ra, rp=ra, &
2801 zetp=zeta(ipgf, iset), eps=eps_rho_rspace, &
2802 prefactor=1.0_dp, cutoff=1.0_dp)
2806 ra, [0.0_dp, 0.0_dp, 0.0_dp], &
2807 scale, pab, na1 - 1, 0, rs_rho(igrid_level), &
2815 offset = offset + nsgfa(iset)
2821 DO igrid_level = 1, gridlevel_info%ngrid_levels
2823 mgrid_rspace(igrid_level))
2827 DO igrid_level = 1, gridlevel_info%ngrid_levels
2829 mgrid_gspace(igrid_level))
2830 CALL pw_axpy(mgrid_gspace(igrid_level), rho_gspace)
2842 CALL timestop(handle)
2865 atomic_kind_set, qs_kind_set, cell, dft_control, particle_set, &
2868 INTEGER,
INTENT(IN) :: ivector
2872 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
2877 CHARACTER(LEN=*),
INTENT(IN),
OPTIONAL :: basis_type
2879 CHARACTER(LEN=*),
PARAMETER :: routinen =
'calculate_wavefunction'
2881 INTEGER :: handle, i, nao
2883 REAL(kind=
dp) :: eps_rho_rspace
2884 REAL(kind=
dp),
DIMENSION(:),
POINTER :: eigenvector
2886 CALL timeset(routinen, handle)
2889 ALLOCATE (eigenvector(nao))
2894 eps_rho_rspace = dft_control%qs_control%eps_rho_rspace
2897 atomic_kind_set, qs_kind_set, cell, particle_set, pw_env, &
2898 eps_rho_rspace, basis_type)
2900 DEALLOCATE (eigenvector)
2902 CALL timestop(handle)
2927 atomic_kind_set, qs_kind_set, cell, particle_set, pw_env, &
2928 eps_rho_rspace, basis_type)
2929 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: vector
2933 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
2937 REAL(kind=
dp),
INTENT(IN) :: eps_rho_rspace
2938 CHARACTER(LEN=*),
INTENT(IN),
OPTIONAL :: basis_type
2940 CHARACTER(LEN=*),
PARAMETER :: routinen =
'collocate_function'
2942 CHARACTER(LEN=default_string_length) :: my_basis_type
2943 INTEGER :: group_size, handle, i, iatom, igrid_level, ikind, ipgf, iset, maxco, maxsgf_set, &
2944 my_pos, na1, na2, natom, ncoa, nseta, offset, sgfa
2945 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: where_is_the_point
2946 INTEGER,
DIMENSION(:),
POINTER :: la_max, la_min, npgfa, nsgfa
2947 INTEGER,
DIMENSION(:, :),
POINTER :: first_sgfa
2948 REAL(kind=
dp) :: dab, radius, scale
2949 REAL(kind=
dp),
DIMENSION(3) :: ra
2950 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: pab, sphi_a, work, zeta
2959 CALL timeset(routinen, handle)
2961 IF (
PRESENT(basis_type))
THEN
2962 my_basis_type = basis_type
2964 my_basis_type =
"ORB"
2967 NULLIFY (orb_basis_set, pab, work, la_max, la_min, &
2968 npgfa, nsgfa, sphi_a, zeta, first_sgfa, rs_rho, pw_pools)
2971 cpassert(
ASSOCIATED(pw_env))
2972 CALL pw_env_get(pw_env, rs_grids=rs_rho, pw_pools=pw_pools, &
2973 gridlevel_info=gridlevel_info)
2979 DO igrid_level = 1, gridlevel_info%ngrid_levels
2987 maxsgf_set=maxsgf_set, &
2988 basis_type=my_basis_type)
2990 ALLOCATE (pab(maxco, 1))
2991 ALLOCATE (work(maxco, 1))
2994 group = mgrid_rspace(1)%pw_grid%para%group
2995 my_pos = mgrid_rspace(1)%pw_grid%para%group%mepos
2996 group_size = mgrid_rspace(1)%pw_grid%para%group%num_pe
2997 ALLOCATE (where_is_the_point(0:group_size - 1))
3000 ikind = particle_set(iatom)%atomic_kind%kind_number
3001 CALL get_qs_kind(qs_kind_set(ikind), basis_set=orb_basis_set, basis_type=my_basis_type)
3003 first_sgf=first_sgfa, &
3011 ra(:) =
pbc(particle_set(iatom)%r, cell)
3016 ncoa = npgfa(iset)*
ncoset(la_max(iset))
3017 sgfa = first_sgfa(1, iset)
3019 DO i = 1, nsgfa(iset)
3020 work(i, 1) = vector(offset + i)
3023 CALL dgemm(
"N",
"N", ncoa, 1, nsgfa(iset), &
3024 1.0_dp, sphi_a(1, sgfa),
SIZE(sphi_a, 1), &
3025 work(1, 1),
SIZE(work, 1), &
3026 0.0_dp, pab(1, 1),
SIZE(pab, 1))
3028 DO ipgf = 1, npgfa(iset)
3030 na1 = (ipgf - 1)*
ncoset(la_max(iset)) + 1
3031 na2 = ipgf*
ncoset(la_max(iset))
3036 IF (
map_gaussian_here(rs_rho(igrid_level), cell%h_inv, ra, offset, group_size, my_pos))
THEN
3038 lb_min=0, lb_max=0, ra=ra, rb=ra, rp=ra, &
3039 zetp=zeta(ipgf, iset), eps=eps_rho_rspace, &
3040 prefactor=1.0_dp, cutoff=1.0_dp)
3044 ra, [0.0_dp, 0.0_dp, 0.0_dp], &
3045 scale, pab, na1 - 1, 0, rs_rho(igrid_level), &
3051 offset = offset + nsgfa(iset)
3057 DO igrid_level = 1, gridlevel_info%ngrid_levels
3059 mgrid_rspace(igrid_level))
3063 DO igrid_level = 1, gridlevel_info%ngrid_levels
3065 mgrid_gspace(igrid_level))
3066 CALL pw_axpy(mgrid_gspace(igrid_level), rho_gspace)
3079 CALL timestop(handle)
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
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.
Types and set/get functions for auxiliary density matrix methods.
subroutine, public get_admm_env(admm_env, mo_derivs_aux_fit, mos_aux_fit, sab_aux_fit, sab_aux_fit_asymm, sab_aux_fit_vs_orb, matrix_s_aux_fit, matrix_s_aux_fit_kp, matrix_s_aux_fit_vs_orb, matrix_s_aux_fit_vs_orb_kp, task_list_aux_fit, matrix_ks_aux_fit, matrix_ks_aux_fit_kp, matrix_ks_aux_fit_im, matrix_ks_aux_fit_dft, matrix_ks_aux_fit_hfx, matrix_ks_aux_fit_dft_kp, matrix_ks_aux_fit_hfx_kp, rho_aux_fit, rho_aux_fit_buffer, admm_dm)
Get routine for the ADMM env.
All kind of helpful little routines.
real(kind=dp) function, public exp_radius_very_extended(la_min, la_max, lb_min, lb_max, pab, o1, o2, ra, rb, rp, zetp, eps, prefactor, cutoff, epsabs)
computes the radius of the Gaussian outside of which it is smaller than eps
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.
subroutine, public get_atomic_kind(atomic_kind, fist_potential, element_symbol, name, mass, kind_number, natom, atom_list, rcov, rvdw, z, qeff, apol, cpol, mm_radius, shell, shell_active, damping)
Get attributes of an atomic kind.
subroutine, public get_gto_basis_set(gto_basis_set, name, aliases, norm_type, kind_radius, ncgf, nset, nsgf, cgf_symbol, sgf_symbol, norm_cgf, set_radius, lmax, lmin, lx, ly, lz, m, ncgf_set, npgf, nsgf_set, nshell, cphi, pgf_radius, sphi, scon, zet, first_cgf, first_sgf, l, last_cgf, last_sgf, n, gcc, maxco, maxl, maxpgf, maxsgf_set, maxshell, maxso, nco_sum, npgf_sum, nshell_sum, maxder, short_kind_radius, npgf_seg_sum, ccon)
...
Handles all functions related to the CELL.
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
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)
...
DBCSR operations in CP2K.
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_get_element(matrix, irow_global, icol_global, alpha, local)
returns an element of a fm this value is valid on every cpu using this call is expensive
Definition of the atomic potential types.
integer function, public gaussian_gridlevel(gridlevel_info, exponent)
...
Fortran API for the grid package, which is written in C.
integer, parameter, public grid_func_core_x
integer, parameter, public grid_func_dab_z
subroutine, public grid_collocate_task_list(task_list, ga_gb_function, pab_blocks, rs_grids)
Collocate all tasks of in given list onto given grids.
integer, parameter, public grid_func_dzdx
integer, parameter, public grid_func_dzdz
integer, parameter, public grid_func_dydz
integer, parameter, public grid_func_dxdy
integer, parameter, public grid_func_dabpadb_y
integer, parameter, public grid_func_dab_y
integer, parameter, public grid_func_dxdx
integer, parameter, public grid_func_dadb
integer, parameter, public grid_func_dydy
integer, parameter, public grid_func_dabpadb_z
integer, parameter, public grid_func_dabpadb_x
integer, parameter, public grid_func_dx
integer, parameter, public grid_func_dz
integer, parameter, public grid_func_ab
integer, parameter, public grid_func_core_y
integer, parameter, public grid_func_dab_x
subroutine, public collocate_pgf_product(la_max, zeta, la_min, lb_max, zetb, lb_min, ra, rab, scale, pab, o1, o2, rsgrid, ga_gb_function, radius, use_subpatch, subpatch_pattern)
low level collocation of primitive gaussian functions
integer, parameter, public grid_func_core_z
integer, parameter, public grid_func_dy
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public default_string_length
contains the types and subroutines for dealing with the lri_env lri : local resolution of the identit...
Utility routines for the memory handling.
Interface to the message passing library MPI.
Provides Cartesian and spherical orbital pointers and indices.
integer, dimension(:), allocatable, public ncoset
integer, dimension(:, :, :), allocatable, public coset
Define the data structure for the particle information.
container for various plainwaves related things
subroutine, public pw_env_get(pw_env, pw_pools, cube_info, gridlevel_info, auxbas_pw_pool, auxbas_grid, auxbas_rs_desc, auxbas_rs_grid, rs_descs, rs_grids, xc_pw_pool, vdw_pw_pool, poisson_env, interp_section)
returns the various attributes of the pw env
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
Calculate the plane wave density by collocating the primitive Gaussian functions (pgf).
subroutine, public calculate_drho_elec_dr(matrix_p, matrix_p_kp, drho, drho_gspace, qs_env, soft_valid, basis_type, beta, lambda)
Computes the gradient wrt. nuclear coordinates of a density on the grid The density is given in terms...
subroutine, public calculate_drho_elec(matrix_p, matrix_p_kp, drho, drho_gspace, qs_env, soft_valid, basis_type)
computes the gradient of the density corresponding to a given density matrix on the grid
subroutine, public calculate_rho_elec(matrix_p, matrix_p_kp, rho, rho_gspace, total_rho, ks_env, soft_valid, compute_tau, compute_grad, basis_type, der_type, idir, task_list_external, pw_env_external)
computes the density corresponding to a given density matrix on the grid
subroutine, public collocate_function(vector, rho, rho_gspace, atomic_kind_set, qs_kind_set, cell, particle_set, pw_env, eps_rho_rspace, basis_type)
maps a given function on the grid
subroutine, public calculate_rho_metal(rho_metal, coeff, total_rho_metal, qs_env)
computes the image charge density on the grid (including coeffcients)
subroutine, public calculate_rho_resp_single(rho_gb, qs_env, eta, iatom_in)
collocate a single Gaussian on the grid for periodic RESP fitting
subroutine, public calculate_rho_nlcc(rho_nlcc, qs_env)
computes the density of the non-linear core correction on the grid
subroutine, public calculate_lri_rho_elec(lri_rho_g, lri_rho_r, qs_env, lri_coef, total_rho, basis_type, exact_1c_terms, pmat, atomlist)
Collocates the fitted lri density on a grid.
subroutine, public collocate_single_gaussian(rho, rho_gspace, atomic_kind_set, qs_kind_set, cell, dft_control, particle_set, pw_env, required_function, basis_type)
maps a single gaussian on the grid
subroutine, public calculate_rho_single_gaussian(rho_gb, qs_env, iatom_in)
collocate a single Gaussian on the grid
subroutine, public calculate_ppl_grid(vppl, qs_env)
computes the local pseudopotential (without erf term) on the grid
subroutine, public calculate_wavefunction(mo_vectors, ivector, rho, rho_gspace, atomic_kind_set, qs_kind_set, cell, dft_control, particle_set, pw_env, basis_type)
maps a given wavefunction on the grid
subroutine, public calculate_drho_core(drho_core, qs_env, beta, lambda)
Computes the derivative of the density of the core charges with respect to the nuclear coordinates on...
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, mimic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, matrix_vhxc, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, rhoz_cneo_set, ecoul_1c, rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, do_rixs, tb_tblite)
Get the QUICKSTEP environment.
Define the quickstep kind type and their sub types.
subroutine, public get_qs_kind(qs_kind, basis_set, basis_type, ncgf, nsgf, all_potential, tnadd_potential, gth_potential, sgp_potential, upf_potential, cneo_potential, se_parameter, dftb_parameter, xtb_parameter, dftb3_param, zatom, zeff, elec_conf, mao, lmax_dftb, alpha_core_charge, ccore_charge, core_charge, core_charge_radius, paw_proj_set, paw_atom, hard_radius, hard0_radius, max_rad_local, covalent_radius, vdw_radius, gpw_type_forced, harmonics, max_iso_not0, max_s_harm, grid_atom, ngrid_ang, ngrid_rad, lmax_rho0, dft_plus_u_atom, l_of_dft_plus_u, n_of_dft_plus_u, u_minus_j, hund_j, u_of_dft_plus_u, j_of_dft_plus_u, alpha_of_dft_plus_u, beta_of_dft_plus_u, j0_of_dft_plus_u, occupation_of_dft_plus_u, dispersion, bs_occupation, magnetization, no_optimize, addel, laddel, naddel, orbitals, max_scf, eps_scf, smear, u_ramping, u_minus_j_target, eps_u_ramping, proj_shell_charge, lr_atom, do_mtlr, u_j_loop, ao_coef, init_u_ramping_each_scf, reltmat, ghost, monovalent, floating, name, element_symbol, pao_basis_size, pao_model_file, pao_potentials, pao_descriptors, nelec)
Get attributes of an atomic kind.
subroutine, public get_qs_kind_set(qs_kind_set, all_potential_present, tnadd_potential_present, gth_potential_present, sgp_potential_present, paw_atom_present, dft_plus_u_atom_present, maxcgf, maxsgf, maxco, maxco_proj, maxgtops, maxlgto, maxlprj, maxnset, maxsgf_set, ncgf, npgf, nset, nsgf, nshell, maxpol, maxlppl, maxlppnl, maxppnl, nelectron, maxder, max_ngrid_rad, max_sph_harm, maxg_iso_not0, lmax_rho0, basis_rcut, do_mtlr_present, basis_type, total_zeff_corr, npgf_seg, cneo_potential_present, nkind_q, natom_q)
Get attributes of an atomic kind set.
subroutine, public get_ks_env(ks_env, v_hartree_rspace, s_mstruct_changed, rho_changed, exc_accint, potential_changed, forces_up_to_date, complex_ks, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, kinetic, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, matrix_vhxc, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_ks_im_kp, rho, rho_xc, vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, vee, neighbor_list_id, sab_orb, sab_all, sac_ae, sac_ppl, sac_lri, sap_ppnl, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_vdw, sab_scp, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, task_list, task_list_soft, kpoints, do_kpoints, atomic_kind_set, qs_kind_set, cell, cell_ref, use_ref_cell, particle_set, energy, force, local_particles, local_molecules, molecule_kind_set, molecule_set, subsys, cp_subsys, virial, results, atprop, nkind, natom, dft_control, dbcsr_dist, distribution_2d, pw_env, para_env, blacs_env, nelectron_total, nelectron_spin)
...
Define the neighbor list data types and the corresponding functionality.
pure logical function, public map_gaussian_here(rs_grid, h_inv, ra, offset, group_size, my_pos)
...
subroutine, public transfer_rs2pw(rs, pw)
...
subroutine, public rs_grid_zero(rs)
Initialize grid to zero.
Transfers densities from PW to RS grids and potentials from PW to RS.
subroutine, public density_rs2pw(pw_env, rs_rho, rho, rho_gspace)
given partial densities on the realspace multigrids, computes the full density on the plane wave grid...
generate the tasks lists used by collocate and integrate routines
subroutine, public rs_scatter_matrices(src_matrices, dest_buffer, task_list, group)
Scatters dbcsr matrix blocks and receives them into a buffer as needed before collocation.
subroutine, public rs_distribute_matrix(rs_descs, pmats, atom_pair_send, atom_pair_recv, nimages, scatter, hmats)
redistributes the matrix so that it can be used in realspace operations i.e. according to the task li...
subroutine, public rs_copy_to_buffer(src_matrices, dest_buffer, task_list)
Copies the DBCSR blocks into buffer, replaces rs_scatter_matrix for non-distributed grids.
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
contained for different pw related things
to create arrays of pools
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
Provides all information about a quickstep kind.
calculation environment to calculate the ks matrix, holds all the needed vars. assumes that the core ...