mkgylm.f 11.6 KB
Newer Older
1 2 3 4 5
!--------------------------------------------------------------------------------
! 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.
!--------------------------------------------------------------------------------
6 7 8
      MODULE m_mkgylm
      CONTAINS
      SUBROUTINE mkgylm(
9 10 11
     >     jspins,rv,thet,nsp,nspd,jspd,
     >     rh,rhdr,rhdt,rhdf,rhdrr,rhdtt,rhdff,
     >     rhdtf,rhdrt,rhdrf,grad)
12 13
c.....------------------------------------------------------------------
c     by use of charge density and its polar coord. gradient components
14 15
c     c    calculate agr and others used to evaluate gradient
c     c    contributions to potential and energy. t.a. 1996.
16 17
c.....------------------------------------------------------------------
c     ro=sum(ro*ylh), rdr=sum(drr*ylh), drdr=sum(ddrr*ylh),
18 19 20 21
c     c    rdt=sum(ro*ylht1), rdtt=sum(ro*ylht2), ...
c     c    rdf=sum(ro*ylhf1), rdff=sum(ro*ylhf2), ...
c     c    rdtf=sum(ro*ylhtf), rdff=sum(ro*ylhf2), ...
c     c    rdrt=sum(drr*ylht1),rdrf=sum(drr*ylhf1),
22 23

c     agr: abs(grad(ro)), g2r: laplacian(ro),
24 25
c     c    gggr: grad(ro)*grad(agr),
c     c    grgru,d: grad(ro)*grad(rou),for rod., gzgr: grad(zeta)*grad(ro).
26 27 28

c     dagrr,-t,-f: d(agr)/dr, d(agr)/dth/r, d(agr)/dfi/r/sint.
c.....------------------------------------------------------------------
29
      USE m_types
30
      IMPLICIT NONE
31 32
C     ..
C     .. Arguments ..
33 34 35 36 37 38 39 40
      INTEGER, INTENT (IN) :: nspd,jspd
      REAL,    INTENT (IN) :: rv
      REAL,    INTENT (IN) :: thet(nspd)
      REAL,    INTENT (IN) :: rh(nspd,jspd),rhdr(nspd,jspd)
      REAL,    INTENT (IN) :: rhdf(nspd,jspd),rhdrr(nspd,jspd)
      REAL,    INTENT (IN) :: rhdtt(nspd,jspd),rhdff(nspd,jspd)
      REAL,    INTENT (IN) :: rhdtf(nspd,jspd),rhdrt(nspd,jspd)
      REAL,    INTENT (IN) :: rhdrf(nspd,jspd),rhdt(nspd,jspd)
41 42 43 44
      TYPE(t_gradients),INTENT(OUT) ::grad
      
C     ..
C     .. Locals ..
45 46
      INTEGER i,jspins,nsp
      REAL    chsml, dagrf,dagrfd,dagrfu,dagrr,dagrrd,dagrru,dagrt,
47 48 49 50 51
     +     dagrtd,dagrtu,drdr,dzdfs,dzdr,dzdtr,grf,grfd,grfu,grr,
     +     grrd,grru,grt,grtd,grtu,rdf,rdfd,rdff,rdffd,rdffu,rdfu,
     +     rdr,rdrd,rdrf,rdrfd,rdrfu,rdrrd,rdrru,rdrt,rdrtd,rdrtu,
     +     rdru,rdt,rdtd,rdtf,rdtfd,rdtfu,rdtt,rdttd,rdttu,rdtu,
     +     ro,ro2,rod,rou,rv1,rv2,rv3,rvsin1,sint1,sint2,tant1
52 53 54 55 56 57 58

      chsml = 1.e-10

      rv1 = rv
      rv2 = rv1**2
      rv3 = rv1**3

59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
      IF (ALLOCATED(grad%sigma)) THEN
!     Contracted gradients for libxc are needed only
         IF (jspins==1) THEN
            DO i=1,nsp
               rdru  = rhdr(i,1)
               rdtu  = rhdt(i,1)
               rdfu  = rhdf(i,1)
               grad%sigma(1,i)=rdru*rdru+rdtu*rdtu+rdfu*rdfu
            ENDDO
         ELSE
            DO i=1,nsp
               rdru  = rhdr(i,1)
               rdtu  = rhdt(i,1)
               rdfu  = rhdf(i,1)
               rdrd  = rhdr(i,2)
               rdtd  = rhdt(i,2)
               rdfd  = rhdf(i,2)
               grad%sigma(1,i)=rdru*rdru+rdtu*rdtu+rdfu*rdfu
               grad%sigma(2,i)=rdru*rdrd+rdtu*rdtd+rdfu*rdfd
               grad%sigma(3,i)=rdrd*rdrd+rdtd*rdtd+rdfd*rdfd
            ENDDO
         ENDIF
81
      ELSE
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 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 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 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 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 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 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
!     Old code for in-build xcpots
         IF (jspins.EQ.1) THEN

            points_1 : DO i = 1,nsp

            grad%agrt(i)   = 0.0
            grad%agru(i)  = 0.0
            grad%agrd(i)  = 0.0
            grad%g2rt(i)   = 0.0
            grad%g2ru(i)  = 0.0
            grad%g2rd(i)  = 0.0
            grad%gggrt(i)  = 0.0
            grad%gggru(i) = 0.0
            grad%gggrd(i) = 0.0
            grad%grgru(i) = 0.0
            grad%grgrd(i) = 0.0
            grad%gzgr(i)  = 0.0

            ro = rh(i,1)

            IF (ro.LT.chsml) CYCLE points_1
            sint1 = sin(thet(i))
            sint2 = sint1**2
            tant1 = tan(thet(i))
            rvsin1 = rv1*sint1
            

            rou   = ro/2
            rdru  = rhdr(i,1)/2
            rdtu  = rhdt(i,1)/2
            rdfu  = rhdf(i,1)/2
            rdrru = rhdrr(i,1)/2
            rdttu = rhdtt(i,1)/2
            rdffu = rhdff(i,1)/2
            rdtfu = rhdtf(i,1)/2
            rdrtu = rhdrt(i,1)/2
            rdrfu = rhdrf(i,1)/2
            
            rod = rou
            rdrd = rdru
            rdtd = rdtu
            rdfd = rdfu
            rdrrd = rdrru
            rdttd = rdttu
            rdffd = rdffu
            rdtfd = rdtfu
            rdrtd = rdrtu
            rdrfd = rdrfu
            
            rdr = rdru + rdrd
            rdt = rdtu + rdtd
            rdf = rdfu + rdfd
            drdr = rdrru + rdrrd
            rdtt = rdttu + rdttd
            rdff = rdffu + rdffd
            rdtf = rdtfu + rdtfd
            rdrt = rdrtu + rdrtd
            rdrf = rdrfu + rdrfd
            
            ro2 = ro**2
            
            grr = rdr
            grt = rdt/rv1
            grf = rdf/rvsin1
            
            grad%agrt(i) = sqrt(grr**2+grt**2+grf**2)

            IF (grad%agrt(i).LT.chsml) CYCLE points_1

            dagrr = (rdr*drdr*rv3+rdt* (rdrt*rv1-rdt)+
     +           rdf* (rdrf*rv1-rdf)/sint2)/grad%agrt(i)/rv3

            dagrt =(rdr*rdrt*rv2+rdt*rdtt+rdf* (-rdf/tant1+rdtf)/sint2)/
     +           (grad%agrt(i)*rv3)

            dagrf = (rdr*rdrf*rv2+rdt*rdtf+rdf*rdff/sint2)/
     +           (grad%agrt(i)*rv3*sint1)

            grad%g2rt(i)=drdr+2.0*rdr/rv1+
     +           (rdtt+rdt/tant1+rdff/sint2)/rv2


            dzdr = ((rdru-rdrd)*ro- (rou-rod)*rdr)/ro2

!--   >      dzdtr,dzdfs vanish by definition.

            dzdtr = 0.0
            dzdfs = 0.0

            grad%gggrt(i) = grr*dagrr + grt*dagrt + grf*dagrf

            grad%gzgr(i) = dzdr*grr + dzdtr*grt + dzdfs*grf

            grru = rdru
            grtu = rdtu/rv1
            grfu = rdfu/rvsin1

            grad%agru(i) = sqrt(grru**2+grtu**2+grfu**2)

            dagrru = (rdru*rdrru*rv3+rdtu* (rdrtu*rv1-rdtu)+
     +           rdfu* (rdrfu*rv1-rdfu)/sint2)/grad%agru(i)/rv3

            dagrtu = (rdru*rdrtu*rv2+rdtu*rdttu+
     +           rdfu* (-rdfu/tant1+rdtfu)/sint2)/ (grad%agru(i)*rv3)

            dagrfu = (rdru*rdrfu*rv2+rdtu*rdtfu+rdfu*rdffu/sint2)/
     +           (grad%agru(i)*rv3*sint1)

            grad%g2ru(i) = rdrru + 2.e0*rdru/rv1 +
     +           (rdttu+rdtu/tant1+rdffu/sint2)/rv2

            grad%gggru(i) = grru*dagrru + grtu*dagrtu + grfu*dagrfu

            grad%grgru(i) = grr*grru + grt*grtu + grf*grfu

            grrd = rdrd
            grtd = rdtd/rv1
            grfd = rdfd/rvsin1

            grad%agrd(i) = sqrt(grrd**2+grtd**2+grfd**2)

            dagrrd = (rdrd*rdrrd*rv3+rdtd* (rdrtd*rv1-rdtd)+
     +           rdfd* (rdrfd*rv1-rdfd)/sint2)/grad%agrd(i)/rv3

            dagrtd = (rdrd*rdrtd*rv2+rdtd*rdttd+
     +           rdfd* (-rdfd/tant1+rdtfd)/sint2)/ (grad%agrd(i)*rv3)

            dagrfd = (rdrd*rdrfd*rv2+rdtd*rdtfd+rdfd*rdffd/sint2)/
     +           (grad%agrd(i)*rv3*sint1)

            grad%g2rd(i) = rdrrd + 2*rdrd/rv1 +
     +           (rdttd+rdtd/tant1+rdffd/sint2)/rv2

            grad%gggrd(i) = grrd*dagrrd + grtd*dagrtd + grfd*dagrfd

            grad%grgrd(i) = grr*grrd + grt*grtd + grf*grfd


            ENDDO points_1

         ELSE

            points_2 : DO i = 1,nsp

            grad%agrt(i) = 0.0
            grad%agru(i) = 0.0
            grad%agrd(i) = 0.0
            grad%g2rt(i) = 0.0
            grad%g2ru(i) = 0.0
            grad%g2rd(i) = 0.0
            grad%gggrt(i) = 0.0
            grad%gggru(i) = 0.0
            grad%gggrd(i) = 0.0
            grad%grgru(i) = 0.0
            grad%grgrd(i) = 0.0
            grad%gzgr(i) = 0.0
            
            ro = rh(i,1) + rh(i,jspins)
            
            IF (ro.LT.chsml) CYCLE points_2
            
            sint1 = sin(thet(i))
            sint2 = sint1**2
            tant1 = tan(thet(i))
            rvsin1 = rv1*sint1
            
            rou = rh(i,1)
            rdru = rhdr(i,1)
            rdtu = rhdt(i,1)
            rdfu = rhdf(i,1)
            rdrru = rhdrr(i,1)
            rdttu = rhdtt(i,1)
            rdffu = rhdff(i,1)
            rdtfu = rhdtf(i,1)
            rdrtu = rhdrt(i,1)
            rdrfu = rhdrf(i,1)
            
            rod = rh(i,jspins)
            rdrd = rhdr(i,jspins)
            rdtd = rhdt(i,jspins)
            rdfd = rhdf(i,jspins)
            rdrrd = rhdrr(i,jspins)
            rdttd = rhdtt(i,jspins)
            rdffd = rhdff(i,jspins)
            rdtfd = rhdtf(i,jspins)
            rdrtd = rhdrt(i,jspins)
            rdrfd = rhdrf(i,jspins)
            
            rdr = rdru + rdrd
            rdt = rdtu + rdtd
            rdf = rdfu + rdfd
            drdr = rdrru + rdrrd
            rdtt = rdttu + rdttd
            rdff = rdffu + rdffd
            rdtf = rdtfu + rdtfd
            rdrt = rdrtu + rdrtd
            rdrf = rdrfu + rdrfd
            
            ro2 = ro**2
            
            grr = rdr
            grt = rdt/rv1
            grf = rdf/rvsin1
            
            grad%agrt(i) = sqrt(grr**2+grt**2+grf**2)
            
            IF (grad%agrt(i).LT.chsml) CYCLE points_2
            
            dagrr = (rdr*drdr*rv3+rdt* (rdrt*rv1-rdt)+
     +        rdf* (rdrf*rv1-rdf)/sint2)/grad%agrt(i)/rv3
            
            dagrt =(rdr*rdrt*rv2+rdt*rdtt+rdf* (-rdf/tant1+rdtf)/sint2)/
     +           (grad%agrt(i)*rv3)
            
            dagrf = (rdr*rdrf*rv2+rdt*rdtf+rdf*rdff/sint2)/
     +           (grad%agrt(i)*rv3*sint1)
            
            grad%g2rt(i)=drdr+2.0*rdr/rv1+(rdtt+rdt/tant1+rdff/sint2)/rv2
            
            dzdr = ((rdru-rdrd)*ro- (rou-rod)*rdr)/ro2
            
c     dzdtr,dzdfs vanish by definition.
            dzdtr = 0.0
            dzdfs = 0.0
            
            grad%gggrt(i) = grr*dagrr + grt*dagrt + grf*dagrf
            
            grad%gzgr(i) = dzdr*grr + dzdtr*grt + dzdfs*grf
            
            grru = rdru
            grtu = rdtu/rv1
            grfu = rdfu/rvsin1
            
            grad%agru(i) = sqrt(grru**2+grtu**2+grfu**2)
            
            dagrru = (rdru*rdrru*rv3+rdtu* (rdrtu*rv1-rdtu)+
     +           rdfu* (rdrfu*rv1-rdfu)/sint2)/grad%agru(i)/rv3
            
            dagrtu = (rdru*rdrtu*rv2+rdtu*rdttu+
     +           rdfu* (-rdfu/tant1+rdtfu)/sint2)/ (grad%agru(i)*rv3)
            
            dagrfu = (rdru*rdrfu*rv2+rdtu*rdtfu+rdfu*rdffu/sint2)/
     +           (grad%agru(i)*rv3*sint1)
            
            grad%g2ru(i) = rdrru + 2.e0*rdru/rv1 +
     +        (rdttu+rdtu/tant1+rdffu/sint2)/rv2
            
            grad%gggru(i) = grru*dagrru + grtu*dagrtu + grfu*dagrfu
            
            grad%grgru(i) = grr*grru + grt*grtu + grf*grfu
            
            
            grrd = rdrd
            grtd = rdtd/rv1
            grfd = rdfd/rvsin1
            
            grad%agrd(i) = sqrt(grrd**2+grtd**2+grfd**2)
            
            dagrrd = (rdrd*rdrrd*rv3+rdtd* (rdrtd*rv1-rdtd)+
     +           rdfd* (rdrfd*rv1-rdfd)/sint2)/grad%agrd(i)/rv3
            
            dagrtd = (rdrd*rdrtd*rv2+rdtd*rdttd+
     +           rdfd* (-rdfd/tant1+rdtfd)/sint2)/ (grad%agrd(i)*rv3)
            
            dagrfd = (rdrd*rdrfd*rv2+rdtd*rdtfd+rdfd*rdffd/sint2)/
     +           (grad%agrd(i)*rv3*sint1)
            
            
            
            grad%g2rd(i) = rdrrd + 2*rdrd/rv1 +
     +           (rdttd+rdtd/tant1+rdffd/sint2)/rv2
            
            grad%gggrd(i) = grrd*dagrrd + grtd*dagrtd + grfd*dagrfd
            
            grad%grgrd(i) = grr*grrd + grt*grtd + grf*grfd
            
            
            ENDDO points_2

         ENDIF
362 363 364 365
      ENDIF
      RETURN
      END SUBROUTINE mkgylm
      END MODULE m_mkgylm