wann_ujugaunt.F 14.6 KB
Newer Older
1 2 3 4 5 6
!--------------------------------------------------------------------------------
! Copyright (c) 2016 Peter Grünberg Institut, Forschungszentrum Jülich, Germany
! This file is part of FLEUR and available as free software under the conditions
! of the MIT license as expressed in the LICENSE file in more detail.
!--------------------------------------------------------------------------------

7 8 9 10 11 12 13 14 15 16 17
      module m_wann_ujugaunt
      contains     
      SUBROUTINE wann_ujugaunt(
c***********************************************************************
c    wann_ujugaunt calculates integrals of radial wave functions with
c    bessel functions and multiplies them with an angular factor.
c    Calculating them only once gives some speed-up of wann_mmkb_sph.
c    Frank Freimuth, October 2006
c*********************************************************************** 
     >                          llod,nntot,kdiff,lmax,
     >                          ntype,ntypd,bbmat,bmat,
Daniel Wortmann's avatar
Daniel Wortmann committed
18 19
     >                          nlod,nlo,llo,flo,flo_b,f,f_b,g,g_b,
     >                          jri,rmsh,dx,jmtd,
20 21
     >                          lmaxd,lmd,
     <                          ujug,ujdg,djug,djdg,ujulog,djulog,
Daniel Wortmann's avatar
Daniel Wortmann committed
22
     <                          ulojug,ulojdg,ulojulog,l_q,sign_q)
23 24 25 26
      use m_constants, only : pimach
      use m_matmul   , only : matmul3,matmul3r
      use m_sphbes
      use m_ylm
27
      use m_types, only : od_inp, od_sym
28 29
      use m_intgr, only : intgr3
      use m_gaunt, only: gaunt1
Daniel Wortmann's avatar
Daniel Wortmann committed
30

31 32 33 34 35 36 37 38 39 40 41 42 43
      IMPLICIT NONE
      integer, intent (in)  :: llod
      INTEGER, INTENT (IN)  :: nntot,ntype,ntypd
      INTEGER, INTENT (IN)  :: lmaxd,jmtd,lmd
      real,    intent (in)  :: kdiff(:,:) !(3,nntot)
      real,    intent (in)  :: bbmat(:,:) !(3,3)
      real,    intent (in)  :: bmat(:,:) !(3,3)
      integer, intent (in)  :: lmax(:) !(ntypd)
      integer, intent (in)  :: nlod
      integer, intent (in)  :: jri(:) !(ntypd)
      integer, intent (in)  :: nlo(:) !(ntypd)
      integer, intent (in)  :: llo(:,:) !(nlod,ntypd)    
      real,    intent (in)  :: f(:,:,:,0:) !(ntypd,jmtd,2,0:lmaxd)
Daniel Wortmann's avatar
Daniel Wortmann committed
44
      real,    intent (in)  :: f_b(:,:,:,0:) !(ntypd,jmtd,2,0:lmaxd)
45
      real,    intent (in)  :: g(:,:,:,0:) !(ntypd,jmtd,2,0:lmaxd)
Daniel Wortmann's avatar
Daniel Wortmann committed
46
      real,    intent (in)  :: g_b(:,:,:,0:) !(ntypd,jmtd,2,0:lmaxd)
47
      real,    intent (in)  :: flo(:,:,:,:) !(ntypd,jmtd,2,nlod)
Daniel Wortmann's avatar
Daniel Wortmann committed
48
      real,    intent (in)  :: flo_b(:,:,:,:) !(ntypd,jmtd,2,nlod)
49 50 51
      real,    intent (in)  :: rmsh(:,:) !(jmtd,ntypd)
      real,    intent (in)  :: dx(:) !(ntypd)

Daniel Wortmann's avatar
Daniel Wortmann committed
52 53 54
      logical,    intent (in)  :: l_q    ! if true, we deal with q points
      integer,    intent (in)  :: sign_q  ! if we deal with q points, we might pick up an additional sign

55 56 57 58 59 60 61 62 63 64 65
      complex, intent (out) :: ujug(0:,0:,:,:) !(0:lmd,0:lmd,1:ntype,1:nntot)
      complex, intent (out) :: ujdg(0:,0:,:,:) !(0:lmd,0:lmd,1:ntype,1:nntot)
      complex, intent (out) :: djug(0:,0:,:,:) !(0:lmd,0:lmd,1:ntype,1:nntot)
      complex, intent (out) :: djdg(0:,0:,:,:) !(0:lmd,0:lmd,1:ntype,1:nntot)
      complex, intent (out) :: ujulog(0:,:,-llod:,:,:) !(0:lmd,nlod,-llod:llod,1:ntype,1:nntot)
      complex, intent (out) :: djulog(0:,:,-llod:,:,:) !(0:lmd,nlod,-llod:llod,1:ntype,1:nntot)
      complex, intent (out) :: ulojug(0:,:,-llod:,:,:) !(0:lmd,nlod,-llod:llod,1:ntype,1:nntot)
      complex, intent (out) :: ulojdg(0:,:,-llod:,:,:) !(0:lmd,nlod,-llod:llod,1:ntype,1:nntot)
      complex, intent (out) :: ulojulog(:,-llod:,:,-llod:,:,:) !(1:nlod,-llod:llod,1:nlod,-llod:llod,1:ntype,1:nntot)

      real, allocatable :: djd(:,:,:),ujd(:,:,:),uju(:,:,:)
Daniel Wortmann's avatar
Daniel Wortmann committed
66
      real, allocatable :: dju(:,:,:)
67
      real, allocatable :: ujulo(:,:,:),djulo(:,:,:),ulojulo(:,:,:)
Daniel Wortmann's avatar
Daniel Wortmann committed
68
      real, allocatable :: uloju(:,:,:),ulojd(:,:,:)
69 70 71 72 73 74 75
      integer           :: ikpt_b,i,lwn,n,lpp,lop,lo,l,lp
      integer           :: lmini,lmaxi,m,mp,llpp,mpp
      integer           :: lmpp,lminp,lmaxp,lm,lpmp
      real              :: rk,bpt(3),gs,jlpp(0:lmaxd)
      real              :: jj(0:lmaxd,jmtd),x(jmtd)
      real              :: bkrot(3)
      complex           :: ylmpp((lmaxd+1)**2),factor,ic
Daniel Wortmann's avatar
Daniel Wortmann committed
76
      complex           :: factor2
77 78 79 80 81

      ic = cmplx(0.,1.)

      allocate( djd(0:lmaxd,0:lmaxd,0:lmaxd) )
      allocate( ujd(0:lmaxd,0:lmaxd,0:lmaxd) )
Daniel Wortmann's avatar
Daniel Wortmann committed
82
      allocate( dju(0:lmaxd,0:lmaxd,0:lmaxd) )
83 84 85 86
      allocate( uju(0:lmaxd,0:lmaxd,0:lmaxd) ) 

      allocate( ujulo(nlod,0:lmaxd,0:lmaxd) )
      allocate( djulo(nlod,0:lmaxd,0:lmaxd) )
Daniel Wortmann's avatar
Daniel Wortmann committed
87 88
      allocate( uloju(nlod,0:lmaxd,0:lmaxd) )
      allocate( ulojd(nlod,0:lmaxd,0:lmaxd) )
89 90 91 92 93 94 95 96 97 98 99 100 101 102

      allocate( ulojulo(nlod,nlod,0:lmaxd) )

      ujug = cmplx(0.0,0.0)
      ujdg = cmplx(0.0,0.0)
      djug = cmplx(0.0,0.0)
      djdg = cmplx(0.0,0.0)

      ujulog = cmplx(0.0,0.0)
      djulog = cmplx(0.0,0.0)
      ulojug = cmplx(0.0,0.0)
      ulojdg = cmplx(0.0,0.0)

      ulojulog = cmplx(0.0,0.0)
Daniel Wortmann's avatar
Daniel Wortmann committed
103
      
104 105
      do ikpt_b=1,nntot
        bpt(:)=kdiff(:,ikpt_b)
106
        rk = sqrt(dot_product(bpt,matmul(bbmat,bpt)))
Daniel Wortmann's avatar
Daniel Wortmann committed
107 108
        !write(*,*)'ujugaunt rk',rk

109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
        do n=1,ntype
         lwn = lmax(n)
c...generate the j_lpp(br) on the radial grid   
         do i = 1,jri(n)
           gs = rk*rmsh(i,n)
           call sphbes(lwn,gs,jlpp)
           jj(:,i) = jlpp(:)
         enddo
         do lpp = 0,lwn   ! lpp is the ang. momentum of the bessel function
c***************************************************************************
c...the local orbitals overlaps
c***************************************************************************
          if (nlo(n).GE.1) then
           do lop = 1,nlo(n)
            do lo = 1,nlo(n)
             l = llo(lo,n)
             lp = llo(lop,n)
             lmini = abs(lp - l)
             lmaxi = lp + l
c..the gaunt conditions
             if ((mod(l+lp+lpp,2).eq.1) .or. (lpp.LT.lmini) .or.
     +             (lpp.gt.lmaxi)) then
               ulojulo(lo,lop,lpp) = 0. 
             else 
              do i = 1,jri(n)
Daniel Wortmann's avatar
Daniel Wortmann committed
134 135
                x(i) = ( flo(n,i,1,lo)*flo_b(n,i,1,lop)+
     +                   flo(n,i,2,lo)*flo_b(n,i,2,lop) )*jj(lpp,i)
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
              enddo 
              call intgr3(x,rmsh(1:,n),dx(n),jri(n),ulojulo(lo,lop,lpp))
             endif
            enddo
           enddo
          endif ! local orbitals 
c**************************************************************************
c...overlaps of the apws only
c**************************************************************************
          do lp = 0,lwn
           do l = 0,lwn
            lmini = abs(lp-l)
            lmaxi = lp + l
c..gaunt conditions
            if ((mod(l+lp+lpp,2).eq.1) .or. (lpp.LT.lmini) .or.
     +             (lpp.gt.lmaxi)) then
             uju(l,lp,lpp) = 0.
             ujd(l,lp,lpp) = 0.
Daniel Wortmann's avatar
Daniel Wortmann committed
154
             dju(l,lp,lpp) = 0.
155 156 157
             djd(l,lp,lpp) = 0.
            else
             do i = 1,jri(n)
Daniel Wortmann's avatar
Daniel Wortmann committed
158 159
                x(i) = ( f(n,i,1,l)*f_b(n,i,1,lp)+
     +                   f(n,i,2,l)*f_b(n,i,2,lp) )*jj(lpp,i)
160 161 162 163
             enddo      
             call intgr3(x,rmsh(1:,n),dx(n),jri(n),uju(l,lp,lpp))

             do i = 1,jri(n)
Daniel Wortmann's avatar
Daniel Wortmann committed
164 165
                x(i) = ( f(n,i,1,l)*g_b(n,i,1,lp)+
     +                   f(n,i,2,l)*g_b(n,i,2,lp) )*jj(lpp,i)
166 167 168 169
             enddo      
             call intgr3(x,rmsh(1:,n),dx(n),jri(n),ujd(l,lp,lpp))

             do i = 1,jri(n)
Daniel Wortmann's avatar
Daniel Wortmann committed
170 171 172 173 174 175 176 177
                x(i) = ( g(n,i,1,l)*f_b(n,i,1,lp)+
     +                   g(n,i,2,l)*f_b(n,i,2,lp) )*jj(lpp,i)
             enddo      
             call intgr3(x,rmsh(1:,n),dx(n),jri(n),dju(l,lp,lpp))

             do i = 1,jri(n)
                x(i) = ( g(n,i,1,l)*g_b(n,i,1,lp)+
     +                   g(n,i,2,l)*g_b(n,i,2,lp) )*jj(lpp,i)
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
             enddo     
             call intgr3(x,rmsh(1:,n),dx(n),jri(n),djd(l,lp,lpp))
            endif
           enddo ! l

c********************************************************************
c...overlaps of the lo's with the apws 
c********************************************************************
           if (nlo(n).GE.1) then
            do lo = 1,nlo(n)
             l = llo(lo,n)
             lmini = abs(lp-l)
             lmaxi = lp + l
c..gaunt conditions
             if ((mod(l+lp+lpp,2).eq.1) .OR. (lpp.lt.lmini) .or.
     +             (lpp.gt.lmaxi)) then
               ujulo(lo,lp,lpp) = 0.
               djulo(lo,lp,lpp) = 0.
Daniel Wortmann's avatar
Daniel Wortmann committed
196 197
               uloju(lo,lp,lpp) = 0.
               ulojd(lo,lp,lpp) = 0.
198 199
             else
              do i = 1,jri(n)
Daniel Wortmann's avatar
Daniel Wortmann committed
200 201
               x(i) = ( flo(n,i,1,lo)*f_b(n,i,1,lp)+
     +                  flo(n,i,2,lo)*f_b(n,i,2,lp) )*jj(lpp,i)
202 203 204
              enddo 
              call intgr3(x,rmsh(1:,n),dx(n),jri(n),ujulo(lo,lp,lpp))
              do i = 1,jri(n)
Daniel Wortmann's avatar
Daniel Wortmann committed
205 206
               x(i) = ( flo(n,i,1,lo)*g_b(n,i,1,lp)+
     +                  flo(n,i,2,lo)*g_b(n,i,2,lp) )*jj(lpp,i)
207 208
              enddo 
              call intgr3(x,rmsh(1:,n),dx(n),jri(n),djulo(lo,lp,lpp))
Daniel Wortmann's avatar
Daniel Wortmann committed
209 210 211 212 213 214 215 216 217 218
              do i = 1,jri(n)
               x(i) = ( flo_b(n,i,1,lo)*f(n,i,1,lp)+
     +                  flo_b(n,i,2,lo)*f(n,i,2,lp) )*jj(lpp,i)
              enddo 
              call intgr3(x,rmsh(1:,n),dx(n),jri(n),uloju(lo,lp,lpp))
              do i = 1,jri(n)
               x(i) = ( flo_b(n,i,1,lo)*g(n,i,1,lp)+
     +                  flo_b(n,i,2,lo)*g(n,i,2,lp) )*jj(lpp,i)
              enddo 
              call intgr3(x,rmsh(1:,n),dx(n),jri(n),ulojd(lo,lp,lpp))
219 220 221 222 223 224 225 226
             endif
            enddo !lo  
           endif  ! local orbitals  
          enddo !lp
         enddo !lpp
c********************************************************************
c       multiply with gaunt-coefficient (apw-apw)
c********************************************************************
227
         bkrot=matmul(bpt,bmat)
228 229 230 231 232 233 234 235 236
         call ylm4(lwn,bkrot,ylmpp)
         do l = 0,lwn
          do m = -l,l
           lm=l*(l+1)+m  
           do lp = 0,lwn
            do mp = -lp,lp
             lpmp=lp*(lp+1)+mp  
             do lpp = 0,lwn
               llpp = lpp*(lpp+1)
Daniel Wortmann's avatar
Daniel Wortmann committed
237

238
               mpp = mp - m
Daniel Wortmann's avatar
Daniel Wortmann committed
239

240 241 242 243 244
               lmpp = llpp + mpp 
               lmini = abs(l-lpp)
               lmaxi = l+lpp
               if ((lmini.le.lp).and.(lp.le.lmaxi).and.
     &            (mod(l+lp+lpp,2).eq.0).and.(abs(mpp).LE.lpp))then  
Daniel Wortmann's avatar
Daniel Wortmann committed
245
                  
246 247
                  factor=conjg(ylmpp(lmpp+1))*(ic**(l+lpp-lp))*
     *                     gaunt1(lp,lpp,l,mp,mpp,m,lmaxd)
Daniel Wortmann's avatar
Daniel Wortmann committed
248 249 250 251 252 253 254

c                  if(factor.ne.0 .and. uju(l,lp,lpp).ne.0)
c     >               write(*,*)lpp,lp,l,mp,m

                  if(l_q) then
                    factor=(sign_q**lpp)*factor            ! additional sign for q points
                  endif
255 256 257 258 259 260
     
                ujug(lpmp,lm,n,ikpt_b)=ujug(lpmp,lm,n,ikpt_b)+
     +               factor*uju(l,lp,lpp)
                ujdg(lpmp,lm,n,ikpt_b)=ujdg(lpmp,lm,n,ikpt_b)+
     +               factor*ujd(l,lp,lpp)
                djug(lpmp,lm,n,ikpt_b)=djug(lpmp,lm,n,ikpt_b)+
Daniel Wortmann's avatar
Daniel Wortmann committed
261
     +               factor*dju(l,lp,lpp)
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
                djdg(lpmp,lm,n,ikpt_b)=djdg(lpmp,lm,n,ikpt_b)+
     +               factor*djd(l,lp,lpp)
              
               endif
              enddo  ! lpp
            enddo ! mp
           enddo  ! lp
          enddo  ! m
         enddo   ! l
c******************************************************************
c       multiply with the gaunt-coefficient (apw-lo)
c******************************************************************
         if (nlo(n).ge.1) then 
         do lo = 1,nlo(n) 
          l = llo(lo,n)
          do m = -l,l
           lm=l*(l+1)+m  
           do lp = 0,lwn
            do mp = -lp,lp
              lpmp=lp*(lp+1)+mp 
              do lpp = 0,lwn
               llpp = lpp*(lpp+1)
               lmini = abs(l-lpp)
               lmaxi = l+lpp
               lminp = abs(lp-lpp)
               lmaxp = lp+lpp
               if ((lmini.le.lp).and.(lp.le.lmaxi).and.
     &            (mod(l+lp+lpp,2).eq.0).and.(abs(mp-m).LE.lpp)) then
                mpp = mp - m
                lmpp = llpp + mpp
                factor=conjg(ylmpp(lmpp+1))*(ic**(l+lpp-lp))*
     *                   gaunt1(lp,lpp,l,mp,mpp,m,lmaxd)
Daniel Wortmann's avatar
Daniel Wortmann committed
294 295 296
                if(l_q) then
                  factor=(sign_q**lpp)*factor            ! additional sign for q points
                endif
297 298 299 300 301 302 303 304 305 306 307 308 309

                ujulog(lpmp,lo,m,n,ikpt_b)=ujulog(lpmp,lo,m,n,ikpt_b)+
     +               factor*ujulo(lo,lp,lpp)
                djulog(lpmp,lo,m,n,ikpt_b)=djulog(lpmp,lo,m,n,ikpt_b)+
     +               factor*djulo(lo,lp,lpp)
               endif

               if ((lminp.le.l).and.(l.le.lmaxp).and.
     &            (mod(l+lp+lpp,2).eq.0).and.(abs(m-mp).LE.lpp)) then
                mpp = m - mp
                lmpp = llpp + mpp
                factor=conjg(ylmpp(lmpp+1))*(ic**(lp+lpp-l))*
     *                   gaunt1(l,lpp,lp,m,mpp,mp,lmaxd)
Daniel Wortmann's avatar
Daniel Wortmann committed
310 311 312 313
                if(l_q) then
                   factor=(sign_q**lpp)*factor
                endif
             
314
                ulojug(lpmp,lo,m,n,ikpt_b)=ulojug(lpmp,lo,m,n,ikpt_b)+
Daniel Wortmann's avatar
Daniel Wortmann committed
315
     +               factor*uloju(lo,lp,lpp)         
316
                ulojdg(lpmp,lo,m,n,ikpt_b)=ulojdg(lpmp,lo,m,n,ikpt_b)+
Daniel Wortmann's avatar
Daniel Wortmann committed
317
     +               factor*ulojd(lo,lp,lpp)        
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
               endif
              enddo  ! lpp
            enddo ! mp
           enddo  ! lp
          enddo ! m lo
         enddo  ! lo
c*************************************************************
c         multiply with the gaunt-coefficient (lo-lo)
c*************************************************************
         do lo = 1,nlo(n)
          l = llo(lo,n)
          do m = -l,l
           lm=l*(l+1)+m  
           do lop = 1,nlo(n)
            lp = llo(lop,n)
            do mp = -lp,lp
              lpmp=lp*(lp+1)+mp 
              do lpp = 0,lwn
               llpp = lpp*(lpp+1)
               mpp = mp - m 
               lmpp = llpp + mpp
               lmini = abs(l-lpp)
               lmaxi = l+lpp
               if ((lmini.le.lp).and.(lp.le.lmaxi).and.
     &            (mod(l+lp+lpp,2).eq.0).and.(abs(mpp).LE.lpp))then  
Daniel Wortmann's avatar
Daniel Wortmann committed
343 344 345 346 347 348 349 350
                  
                  factor= conjg(ylmpp(lmpp+1))*(ic**(l+lpp-lp))*
     *                 gaunt1(lp,lpp,l,mp,mpp,m,lmaxd)
                  if(l_q) then
                    factor=(sign_q**lpp)*factor            ! additional sign for q points
                  endif

                  ulojulog(lop,mp,lo,m,n,ikpt_b)=
351
     =                 ulojulog(lop,mp,lo,m,n,ikpt_b)+
Daniel Wortmann's avatar
Daniel Wortmann committed
352 353 354 355
     +                    ulojulo(lo,lop,lpp)*factor
!     +                 conjg(ylmpp(lmpp+1))*(ic**(l+lpp-lp))*
!     *                 gaunt1(lp,lpp,l,mp,mpp,m,lmaxd)*
!     *                      ulojulo(lo,lop,lpp)
356 357 358 359 360 361 362 363 364 365
               endif
              enddo  ! lpp
            enddo ! mp lop
           enddo  ! lop
          enddo ! m lo
         enddo  ! lo           
         endif ! local orbitals on this atom
        enddo !ntype
      enddo !ikpt_b   
      deallocate(djd,ujd,uju,ujulo,djulo,ulojulo)
Daniel Wortmann's avatar
Daniel Wortmann committed
366
      deallocate(dju,uloju,ulojd)
367 368 369

      end subroutine wann_ujugaunt
      end module m_wann_ujugaunt