Skip to content

Commit

Permalink
Backport changes to CPU integral code (#425)
Browse files Browse the repository at this point in the history
- pass angular moment instead array offset to integral evaluator
  • Loading branch information
awvwgk authored Jan 25, 2021
1 parent cfc1342 commit ef68d3b
Show file tree
Hide file tree
Showing 6 changed files with 261 additions and 398 deletions.
136 changes: 0 additions & 136 deletions src/aespot.f90
Original file line number Diff line number Diff line change
Expand Up @@ -1112,140 +1112,4 @@ subroutine gfn2broyden_out(n,istart,nbr,q_in,dipm,qp)
end subroutine gfn2broyden_out


! dsint: computes the gradient of the dipole/qpole integral contribution
! thr : integral cutoff according to prefactor from Gaussian product theorem
! nat : # of atoms
! nao : # of spherical AOs (SAOs)
! nbf : # of Cartesian AOs (CAOs)
! at(nat) : atomic numbers of atoms
! xyz(3,nat) : cartesian coordinates
! caoshell : map shell of atom to index in CAO space (lowest Cart. component is taken), dimension: (5,nat)
! saoshell : map shell of atom to index in SAO space (lowest m_l component is taken), dimension: (5,nat)
! primcount : index of first primitive (over entire system) of given CAO, dimension: nbf
subroutine dsint(nShell,hData,thr,nat,nao,nbf,at,xyz,sqrab,caoshell,saoshell,nprim,primcount, &
& alp,cont,H,g)
use xtb_mctc_constants, only : pi
use xtb_intgrad
implicit none
integer, intent(in) :: nShell(:)
type(THamiltonianData), intent(in) :: hData
real(wp),intent(in) :: thr
integer, intent(in) :: nat
integer, intent(in) :: nao
integer, intent(in) :: nbf
integer, intent(in) :: at(nat)
real(wp),intent(in) :: xyz(3,nat)
real(wp),intent(in) :: sqrab(nat*(nat+1)/2)
integer, intent(in) :: caoshell(:,:)
integer, intent(in) :: saoshell(:,:)
integer, intent(in) :: nprim(:)
integer, intent(in) :: primcount(:)
real(wp),intent(in) :: alp(:)
real(wp),intent(in) :: cont(:)
real(wp),intent(in) :: H(nao,nao)
real(wp),intent(inout) :: g(3,nat)

integer itt(0:3)
parameter (itt=(/0,1,4,10/))
real(wp) tmp1,tmp2,tmp3,step,step2,step3,s00r,s00l,s00,alpj
real(wp) skj,r1,r2,tt,t1,t2,t3,t4
real(wp) thr2,f,ci,cc,cj,alpi,rab2,ab,est
real(wp) f1,f2,tmp(6,6),r(3)
real(wp) stmp,ral(3,3),rar(3,3),rbl(3,3),pre
real(wp) dtmp,qtmp,rbr(3,3),r2l(3),r2r(3),qqa(6,6,6,3)
real(wp) ss(6,6,3),ddc(3,6,6,3),qqc(6,6,6,3),dda(3,6,6,3)
integer i,j,k,l,m,ii,jj,ll,kk,ki,kj,kl,km,mi,mj,ij,lin,jshmax
integer ip,jp,iat,jat,izp,jzp,ish,jsh,icao,jcao,iao,jao,ixyz
integer ishtyp,jshtyp,iptyp,jptyp,naoi,naoj,mli,mlj,iprim,jprim
real(wp) :: dumdum(3),dum,sdq(6,6),sdqg(3,6,6)

! call timing(t1,t3)
!$omp parallel private (iat,jat,ixyz,izp,cc,ci,rab2,jzp,ish,ishtyp, &
!$omp& icao,naoi,iptyp,jsh,jshmax,jshtyp,jcao,naoj,jptyp, &
!$omp& sdq,sdqg,est,alpi,alpj,ab,iprim,jprim,ip,jp, &
!$omp& mli,mlj,dum,dumdum,tmp,stmp, &
!$omp& iao,jao,ii,jj,k ) reduction (+:g )
!$omp do schedule(dynamic)
do iat = 1,nat
izp = at(iat)
do jat = 1,iat-1
! if (jat.eq.iat) cycle
jzp = at(jat)
r = xyz(:,iat)-xyz(:,jat)
rab2 = sum( r**2 )
! ints < 1.d-9 for RAB > 40 Bohr
if (rab2.gt.2000) cycle
do ish = 1,nShell(izp)
ishtyp = hData%angShell(ish,izp)
icao = caoshell(ish,iat)
naoi = llao(ishtyp)
iptyp = itt(ishtyp)
jshmax = nShell(jzp)
! if(iat.eq.jat) jshmax = ish
do jsh = 1,jshmax ! jshells
jshtyp = hData%angShell(jsh,jzp)
jcao = caoshell(jsh,jat)
naoj = llao(jshtyp)
jptyp = itt(jshtyp)
! we go through the primitives
! (because the screening is the same for all of them)
sdqg = 0;sdq = 0
do ip = 1,nprim(icao+1)
iprim = ip+primcount(icao+1)
! exponent the same for each l component
alpi = alp(iprim)
do jp = 1,nprim(jcao+1)
jprim = jp+primcount(jcao+1)
! exponent the same for each l component
alpj = alp(jprim)
est = alpi*alpj*rab2/(alpi+alpj)
if(est.gt.thr) cycle
!--------------- compute gradient ----------
! now compute integrals for different components of i(e.g., px,py,pz)
do mli = 1,naoi
iprim = ip+primcount(icao+mli)
! coefficients NOT the same
! (contain CAO2SAO lin. comb. coefficients)
ci = cont(iprim)
do mlj = 1,naoj
jprim = jp+primcount(jcao+mlj)
cc = cont(jprim)*ci
dum = 0;dumdum = 0
call build_ds_ints(xyz(:,iat),xyz(:,jat), &
& alpi,alpj,iptyp+mli,jptyp+mlj, &
& dum,dumdum)
sdq(mlj,mli) = sdq(mlj,mli)+dum*cc
sdqg(:,mlj,mli) = sdqg(:,mlj,mli) &
& + dumdum(:)*cc
enddo ! mlj : Cartesian component of j prims
enddo ! mli : Cartesian component of i prims
enddo ! jp : loop over j prims
enddo ! ip : loop over i prims
do ixyz = 1,3
! transform from CAO to SAO, only transform the gradient
tmp(1:6,1:6) = sdqg(ixyz,1:6,1:6)
call dtrf2(tmp,ishtyp,jshtyp)
sdqg(ixyz,1:6,1:6) = tmp(1:6,1:6)
enddo
do ii = 1,llao2(ishtyp)
iao = ii+saoshell(ish,iat)
do jj = 1,llao2(jshtyp)
jao = jj+saoshell(jsh,jat)
do ixyz = 1,3
stmp = sdqg(ixyz,jj,ii)*2*H(jao,iao)
g(ixyz,iat) = g(ixyz,iat)+stmp
g(ixyz,jat) = g(ixyz,jat)-stmp
enddo ! ixyz
enddo
enddo
enddo ! jsh : loop over shells on jat
enddo ! ish : loop over shells on iat
enddo ! jat
enddo ! iat
!$omp end do
!$omp end parallel
! call timing(t2,t4)
! call prtime(6,t2-t1,t4-t3,'dqint5')
end subroutine dsint

end module xtb_aespot
Loading

0 comments on commit ef68d3b

Please sign in to comment.