From c1c684b0e731cb5a8445735c70bea8159ea39947 Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Tue, 5 May 2015 14:22:38 +0200 Subject: [PATCH] >50% acceleration of int.f90 --- src/Pseudo_integrals/int.f90 | 223 ++++++++++++++++++++--------------- tests/unit_test/unit_test.py | 2 +- 2 files changed, 129 insertions(+), 96 deletions(-) diff --git a/src/Pseudo_integrals/int.f90 b/src/Pseudo_integrals/int.f90 index f7b35817..1fdb2c4d 100644 --- a/src/Pseudo_integrals/int.f90 +++ b/src/Pseudo_integrals/int.f90 @@ -1898,114 +1898,147 @@ end !! !! M_n(x) modified spherical bessel function !! - double precision function int_prod_bessel(l,gam,n,m,a,b,arg) - implicit none - integer n,k,m,q,l,kcp - double precision gam,dblefact,fact,pi,a,b - double precision int,intold,sum,coef_nk,crochet,u,int_prod_bessel_large,freal,arg - logical done - u=(a+b)/(2.d0*dsqrt(gam)) - freal=dexp(-arg) +double precision function int_prod_bessel(l,gam,n,m,a,b,arg) - if(a.eq.0.d0.and.b.eq.0.d0)then - if(n.ne.0.or.m.ne.0)then - int_prod_bessel=0.d0 - return - endif - int_prod_bessel=crochet(l,gam)*freal - return - endif + implicit none + integer n,k,m,q,l,kcp + double precision gam,dblefact,fact,pi,a,b + double precision int,intold,sum,coef_nk,crochet,u,int_prod_bessel_large,freal,arg + double precision dump - if(u.gt.6.d0)then - int_prod_bessel=int_prod_bessel_large(l,gam,n,m,a,b,arg) + double precision, allocatable :: temp_array(:) + + logical done + + u=(a+b)/(2.d0*dsqrt(gam)) + freal=dexp(-arg) + + if(a.eq.0.d0.and.b.eq.0.d0)then + if(n.ne.0.or.m.ne.0)then + int_prod_bessel=0.d0 return + endif + + int_prod_bessel=crochet(l,gam)*freal + return + endif + + if(u.gt.6.d0)then + int_prod_bessel=int_prod_bessel_large(l,gam,n,m,a,b,arg) + return + endif + + if(a.ne.0.d0.and.b.ne.0.d0)then + + q=0 + intold=-1.d0 + int=0.d0 + done=.false. + kcp=0 + + allocate( temp_array(0:101)) + + do while (.not.done) + + kcp=kcp+1 + sum=0.d0 + + dump = a**n + do k=q,q+1 + temp_array(k) = coef_nk(n,k)*dump*(a**(2*k)) + enddo + + do k=0,q + sum=sum+temp_array(k)*coef_nk(m,q-k)*b**(m-2*k+2*q) + enddo + + int=int+sum*crochet(2*q+n+m+l,gam) + + if(dabs(int-intold).lt.1d-15)then + done=.true. + else + + q=q+1 + intold=int endif - if(a.ne.0.d0.and.b.ne.0.d0)then + enddo + + deallocate(temp_array) - q=0 - intold=-1.d0 - int=0.d0 - done=.false. - kcp=0 - do while (.not.done) - kcp=kcp+1 - sum=0.d0 - do k=0,q - sum=sum+coef_nk(n,k)*coef_nk(m,q-k)*a**(n+2*k)*b**(m-2*k+2*q) - enddo - int=int+sum*crochet(2*q+n+m+l,gam) - if(dabs(int-intold).lt.1d-15)then + int_prod_bessel=int*freal + + if(kcp.gt.100)then + print*,'**WARNING** bad convergence in int_prod_bessel' + endif + + return + endif + + if(a.eq.0.d0.and.b.ne.0.d0)then + + if(n.ne.0)then + int_prod_bessel=0.d0 + return + endif + + q=0 + intold=-1.d0 + int=0.d0 + done=.false. + kcp=0 + + do while (.not.done) + + kcp=kcp+1 + int=int+coef_nk(m,q)*b**(m+2*q)*crochet(2*q+m+l,gam) + + if(dabs(int-intold).lt.1d-15)then + done=.true. + else + q=q+1 + intold=int + endif + + enddo + + int_prod_bessel=int*freal + if(kcp.gt.100)stop '**WARNING** bad convergence in int_prod_bessel' + return + endif + + if(a.ne.0.d0.and.b.eq.0.d0)then + if(m.ne.0)then + int_prod_bessel=0.d0 + return + endif + + q=0 + intold=-1.d0 + int=0.d0 + done=.false. + kcp=0 + + do while (.not.done) + kcp=kcp+1 + int=int+coef_nk(n,q)*a**(n+2*q)*crochet(2*q+n+l,gam) + if(dabs(int-intold).lt.1d-15)then done=.true. - else + else q=q+1 intold=int - endif - enddo - int_prod_bessel=int*freal - if(kcp.gt.100)then - print*,'**WARNING** bad convergence in int_prod_bessel' -! else -! print*,'kcp=',kcp - endif - return endif + enddo + + int_prod_bessel=int*freal + if(kcp.gt.100)stop '**WARNING** bad convergence in int_prod_bessel' + return - if(a.eq.0.d0.and.b.ne.0.d0)then - if(n.ne.0)then - int_prod_bessel=0.d0 - return - endif + endif - q=0 - intold=-1.d0 - int=0.d0 - done=.false. - kcp=0 - do while (.not.done) - kcp=kcp+1 - int=int+coef_nk(m,q)*b**(m+2*q)*crochet(2*q+m+l,gam) - if(dabs(int-intold).lt.1d-15)then - done=.true. - else - q=q+1 - intold=int - endif - enddo - int_prod_bessel=int*freal - if(kcp.gt.100)stop '**WARNING** bad convergence in int_prod_bessel' - return - endif - - if(a.ne.0.d0.and.b.eq.0.d0)then - if(m.ne.0)then - int_prod_bessel=0.d0 - return - endif - - q=0 - intold=-1.d0 - int=0.d0 - done=.false. - kcp=0 - do while (.not.done) - kcp=kcp+1 - int=int+coef_nk(n,q)*a**(n+2*q)*crochet(2*q+n+l,gam) - if(dabs(int-intold).lt.1d-15)then - done=.true. - else - q=q+1 - intold=int - endif - enddo - int_prod_bessel=int*freal - if(kcp.gt.100)stop '**WARNING** bad convergence in int_prod_bessel' - return - endif - - stop 'pb in int_prod_bessel!!' - end + stop 'pb in int_prod_bessel!!' +end double precision function int_prod_bessel_large(l,gam,n,m,a,b,arg) implicit none diff --git a/tests/unit_test/unit_test.py b/tests/unit_test/unit_test.py index b2881c92..23e831ec 100755 --- a/tests/unit_test/unit_test.py +++ b/tests/unit_test/unit_test.py @@ -169,7 +169,7 @@ def run_hf(geo, basis, mult=1, pseudo=False, remove_after_sucess=True): ref_energy["sto-3g"]["methane"] = Energy(-39.7267433402, None) ref_energy["vdz"]["SO2"] = Energy(None, -41.48912297776174) - ref_energy["vdz"]["HBO"] = Energy(None, -19.1198251160) + ref_energy["vdz"]["HBO"] = Energy(None, -19.11982540413317) # ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~ # # G l o b a l _ v a r i a b l e #