u_ham.F90 16.9 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 18 19 20 21
MODULE m_uham
  USE m_juDFT
  !-------------------------------------------------------------------+
  !     For details see Eq.(21) of Shick et al. PRB 60, 10765 (1999)  |
  !     Sets up the LDA + U Hamilton matrix with eigenvalues in the   |
  !     diagonal:                                                     |
  !  s     ---       *s,j'  s,j    ..   *s,j'  s,j    s            s |
  ! H    = >      [ A      A    + <u|u> B      B    ] V     + d    e  |
  !  j',j  -- m,m'   l,m'   l,m          l,m'   l,m    m,m'    j,j' j |
  !                                                                   |
  !                                                  G.B. Oct. 2000   |
  !                                                                   |
  ! Version for 1st variation to be called from hssphn.               |
  ! now the Hamiltonmatrix is close packed aa()  and ar,ai and br,bi  |
  ! are provided instead of ahelp and bhelp.              Feb. 2001   |
Daniel Wortmann's avatar
Daniel Wortmann committed
22 23
  !-------------------------------------------------------------------|
  ! Extension to multiple U per atom type by G.M. 2017                |
24 25
  !-------------------------------------------------------------------+
CONTAINS
Daniel Wortmann's avatar
Daniel Wortmann committed
26
  SUBROUTINE u_ham(atoms, input,lapw,jsp,n,i_u,invsfct,&
27
       ar,ai,br,bi,vs_mmp,lmaxb, alo,blo,clo, n_size,n_rank,usp,ud,&
28
       noco,iintsp,jintsp,chi11,chi22,chi21, nkvecprevat,iilo,locol,l_real,aa_r,aa_c)
29 30 31 32 33 34 35 36 37 38

    USE m_types
    IMPLICIT NONE
    TYPE(t_input),INTENT(IN)   :: input
    TYPE(t_noco),INTENT(IN)    :: noco
    TYPE(t_atoms),INTENT(IN)   :: atoms
    TYPE(t_lapw),INTENT(IN)    :: lapw
    !     ..
    !     .. Scalar Arguments ..    
    INTEGER, INTENT (IN) :: lmaxb  
Daniel Wortmann's avatar
Daniel Wortmann committed
39
    INTEGER, INTENT (IN) :: jsp,n,i_u
40 41 42 43 44 45 46
    INTEGER, INTENT (IN) :: n_size,n_rank ,usp
    INTEGER, INTENT (IN) :: iintsp,jintsp
    INTEGER, INTENT (INOUT) :: nkvecprevat,iilo,locol
    REAL,    INTENT (IN) :: invsfct
    COMPLEX, INTENT (IN) :: chi11,chi22,chi21
    !     ..
    !     .. Array Arguments ..
Daniel Wortmann's avatar
Daniel Wortmann committed
47
    TYPE(t_usdus),INTENT(IN) :: ud
48 49 50 51 52
    REAL,    INTENT (IN) :: ar(:,0:,:),ai(:,0:,:) !(dimension%nvd,0:dimension%lmd,ab_dim)
    REAL,    INTENT (IN) :: br(:,0:,:),bi(:,0:,:) !(dimension%nvd,0:dimension%lmd,ab_dim)
    COMPLEX, INTENT (IN) :: alo(-atoms%llod:,:,:,:)!(-llod:llod,2*(2*llod+1),nlod,ab_dim)
    COMPLEX, INTENT (IN) :: blo(-atoms%llod:,:,:,:)!(-llod:llod,2*(2*llod+1),nlod,ab_dim)
    COMPLEX, INTENT (IN) :: clo(-atoms%llod:,:,:,:)!(-llod:llod,2*(2*llod+1),nlod,ab_dim)
Daniel Wortmann's avatar
Daniel Wortmann committed
53
    COMPLEX, INTENT (IN) :: vs_mmp(-lmaxb:lmaxb,-lmaxb:lmaxb,atoms%n_u,input%jspins)
54

Daniel Wortmann's avatar
Daniel Wortmann committed
55
    LOGICAL, INTENT(IN) :: l_real
56 57
    REAL,    OPTIONAL,INTENT (INOUT),ALLOCATABLE :: aa_r(:)!(matsize)
    COMPLEX, OPTIONAL,INTENT (INOUT),ALLOCATABLE :: aa_c(:)!(matsize)
58

59 60
    !     ..
    !     .. Local Scalars ..
Daniel Wortmann's avatar
Daniel Wortmann committed
61 62
    INTEGER  m,mp,ispin,itype,l,igp,ll,llm,nvv,ii,lp,lop,ig
    INTEGER matel0,locol0,lo,nkvec,nkvecp,nkvecprevlo,nkend
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
    INTEGER igp_m,i_invsf,nc
    COMPLEX chihlp
    REAL    dd,uulo,dulo,ulolo
    !     ..
    !     .. Local Arrays
    REAL, ALLOCATABLE :: ar_help(:,:),ai_help(:,:),va_help(:)
    REAL, ALLOCATABLE :: br_help(:,:),bi_help(:,:),vb_help(:)
    REAL, ALLOCATABLE :: cr_help(:,:),ci_help(:,:)
    COMPLEX, ALLOCATABLE :: ax(:,:),bx(:,:),cx(:,:)
    COMPLEX, ALLOCATABLE :: wa_help(:),wb_help(:),wc_help(:)
    COMPLEX, ALLOCATABLE :: wd_help(:),we_help(:)


    INTRINSIC cmplx,conjg

Daniel Wortmann's avatar
Daniel Wortmann committed
78 79
    l = atoms%lda_u(i_u)%l

80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
    i_invsf = NINT(invsfct)
    nvv = lapw%nv(jsp)
    IF (noco%l_ss)  nvv = lapw%nv(jintsp)

    ALLOCATE ( ar_help(nvv,-l:l),ai_help(nvv,-l:l),va_help(-l:l),&
         br_help(nvv,-l:l),bi_help(nvv,-l:l),vb_help(-l:l) )
    !
    !-----------------------------------------------------------------------
    !
    !                __      mm'    *lm'                    __      mm'    *lm' . .
    ! A_help(G',m) = >     V       A     and B_help(G',m) = >     V       B    <u|u>
    !                --m'   l,n,s   G'                      --m'   l,n,s   G'
    !
    !------------------------------------------------------------------------
    ll = l * (l+1)
    DO m = -l,l
       DO mp = -l,l
Daniel Wortmann's avatar
Daniel Wortmann committed
97
          va_help(mp) = REAL(vs_mmp(m,mp,i_u,jsp)) * invsfct
98
          vb_help(mp) = va_help(mp) * ud%ddn(l,n,jsp)
Daniel Wortmann's avatar
Daniel Wortmann committed
99
       END DO
100 101 102 103 104 105 106 107 108 109 110 111

       DO ig = 1, nvv
          ar_help(ig,m) = 0.0
          ai_help(ig,m) = 0.0
          br_help(ig,m) = 0.0
          bi_help(ig,m) = 0.0

          DO mp = -l,l
             ar_help(ig,m) = ar_help(ig,m) + va_help(mp) * ar(ig,ll+mp,jintsp)
             ai_help(ig,m) = ai_help(ig,m) - va_help(mp) * ai(ig,ll+mp,jintsp)
             br_help(ig,m) = br_help(ig,m) + vb_help(mp) * br(ig,ll+mp,jintsp)
             bi_help(ig,m) = bi_help(ig,m) - vb_help(mp) * bi(ig,ll+mp,jintsp)
Daniel Wortmann's avatar
Daniel Wortmann committed
112 113
          END DO
       END DO
114 115

       DO mp = -l,l
Daniel Wortmann's avatar
Daniel Wortmann committed
116
          va_help(mp) = AIMAG(vs_mmp(m,mp,i_u,jsp)) * invsfct
117
          vb_help(mp) = va_help(mp) * ud%ddn(l,n,jsp)
Daniel Wortmann's avatar
Daniel Wortmann committed
118 119
       END DO

120 121 122 123 124 125
       DO ig = 1, nvv
          DO mp = -l,l
             ar_help(ig,m) = ar_help(ig,m) + va_help(mp) * ai(ig,ll+mp,jintsp)
             ai_help(ig,m) = ai_help(ig,m) + va_help(mp) * ar(ig,ll+mp,jintsp)
             br_help(ig,m) = br_help(ig,m) + vb_help(mp) * bi(ig,ll+mp,jintsp)
             bi_help(ig,m) = bi_help(ig,m) + vb_help(mp) * br(ig,ll+mp,jintsp)
Daniel Wortmann's avatar
Daniel Wortmann committed
126 127 128
          END DO
       END DO
    END DO
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
    !
    IF (noco%l_ss) nvv = lapw%nv(iintsp)
    !
    !--------------------------------------------
    !
    !  l,n,s    --        m   lm          m   lm
    ! H      =  >   A_help   A    + B_help   B
    !  G G'     --m       G'  G           G'  G 
    !
    !--------------------------------------------
    nc = 0
    DO ig = n_rank+1, nvv, n_size
       nc = nc + 1
       !
       IF (noco%l_ss) THEN
Daniel Wortmann's avatar
Daniel Wortmann committed
144 145
          IF (n_size > 1) CALL juDFT_error("U+SS+EV-PAR", calledby ="u_ham")
          IF ((iintsp.EQ.1).AND.(jintsp.EQ.1)) THEN     !---> spin-up spin-up part
146 147 148
             igp_m = ig
             chihlp = chi11
             ii = (ig-1)*(ig)/2
Daniel Wortmann's avatar
Daniel Wortmann committed
149
          ELSE IF ((iintsp.EQ.2).AND.(jintsp.EQ.2)) THEN !---> spin-down spin-down part
150 151 152 153 154 155 156 157
             igp_m = ig
             chihlp = chi22
             ii = (lapw%nv(1)+atoms%nlotot+ig-1)*(lapw%nv(1)+atoms%nlotot+ig)/2 + &
                  lapw%nv(1)+atoms%nlotot
          ELSE                                          !---> spin-down spin-up part
             igp_m = lapw%nv(1)
             chihlp = chi21
             ii = (lapw%nv(1)+atoms%nlotot+ig-1)*(lapw%nv(1)+atoms%nlotot+ig)/2
Daniel Wortmann's avatar
Daniel Wortmann committed
158
          END IF
159 160 161 162 163 164 165 166 167 168
       ELSE                                             ! no spin-spiral
          chihlp = CMPLX(1.0,0.0)
          igp_m = ig
          !          ii = ig * (ig - 1) / 2
          ii = nc*(nc-1)/2*n_size - (nc-1)*(n_size-n_rank-1)
       ENDIF

       DO m = -l,l
          llm = ll + m

169 170 171
          if (l_real) THEN
             DO igp = 1, igp_m
                aa_r(ii+igp) = aa_r(ii+igp) + &
Daniel Wortmann's avatar
Daniel Wortmann committed
172 173 174
                               ar_help(igp,m) * ar(ig,llm,iintsp) + br_help(igp,m) * br(ig,llm,iintsp) - &
                               ai_help(igp,m) * ai(ig,llm,iintsp) - bi_help(igp,m) * bi(ig,llm,iintsp) 
             END DO ! igp 
175 176 177
          ELSE
             DO igp = 1, igp_m
                aa_c(ii+igp) = aa_c(ii+igp) + chihlp * CMPLX(&
Daniel Wortmann's avatar
Daniel Wortmann committed
178 179 180 181 182 183 184 185
                               ar_help(igp,m) * ar(ig,llm,iintsp) + br_help(igp,m) * br(ig,llm,iintsp) - &
                               ai_help(igp,m) * ai(ig,llm,iintsp) - bi_help(igp,m) * bi(ig,llm,iintsp) , &
                               ar_help(igp,m) * ai(ig,llm,iintsp) + br_help(igp,m) * bi(ig,llm,iintsp) + &
                               ai_help(igp,m) * ar(ig,llm,iintsp) + bi_help(igp,m) * br(ig,llm,iintsp))
             END DO
          END IF
       END DO   ! m
    END DO     ! ig = 1, nvv
186 187 188 189 190 191 192 193 194 195
    !--------------------------------------------------------------------------
    !
    !     local orbitals (if there are any with same l on this atom) 
    !                    for the meaning of iilo etc. see slomat
    !
    !--------------------------------------------------------------------------
    nkvecprevlo = 0
    !
    DO lo = 1, atoms%nlo(n)
       IF (l.EQ.atoms%llo(lo,n)) THEN
Daniel Wortmann's avatar
Daniel Wortmann committed
196
          IF (n_size > 1)  CALL juDFT_error("U+LO+EV-PAR", calledby="u_ham")
197 198 199 200 201 202 203 204 205 206 207
          !
          !--->    calculate the contribution to H (G_lo,G): help arrays
          !
          ALLOCATE ( cr_help(nvv,-l:l),ci_help(nvv,-l:l) )
          uulo =  ud%uulon(lo,n,usp) ! * invsfct
          dulo =  ud%dulon(lo,n,usp) ! * invsfct
          matel0 = iilo
          locol0 = locol
          ll = l * (l+1)
          DO m = -l,l
             DO mp = -l,l
Daniel Wortmann's avatar
Daniel Wortmann committed
208 209 210
                va_help(mp) = REAL(vs_mmp(m,mp,i_u,jsp)) * uulo
                vb_help(mp) = REAL(vs_mmp(m,mp,i_u,jsp)) * dulo
             END DO
211 212 213 214 215 216 217 218
             DO ig = 1, nvv
                cr_help(ig,m) = 0.0
                ci_help(ig,m) = 0.0
                DO mp = -l,l
                   cr_help(ig,m) = cr_help(ig,m) + va_help(mp) * ar(ig,ll+mp,jintsp)
                   ci_help(ig,m) = ci_help(ig,m) - va_help(mp) * ai(ig,ll+mp,jintsp)
                   cr_help(ig,m) = cr_help(ig,m) + vb_help(mp) * br(ig,ll+mp,jintsp)
                   ci_help(ig,m) = ci_help(ig,m) - vb_help(mp) * bi(ig,ll+mp,jintsp)
Daniel Wortmann's avatar
Daniel Wortmann committed
219 220
                END DO
             END DO
221
             DO mp = -l,l
Daniel Wortmann's avatar
Daniel Wortmann committed
222 223 224
                va_help(mp) = AIMAG(vs_mmp(m,mp,i_u,jsp)) * uulo
                vb_help(mp) = AIMAG(vs_mmp(m,mp,i_u,jsp)) * dulo
             END DO
225 226 227 228 229 230
             DO ig = 1, nvv
                DO mp = -l,l
                   cr_help(ig,m) = cr_help(ig,m) + va_help(mp) * ai(ig,ll+mp,jintsp)
                   ci_help(ig,m) = ci_help(ig,m) + va_help(mp) * ar(ig,ll+mp,jintsp)
                   cr_help(ig,m) = cr_help(ig,m) + vb_help(mp) * bi(ig,ll+mp,jintsp)
                   ci_help(ig,m) = ci_help(ig,m) + vb_help(mp) * br(ig,ll+mp,jintsp)
Daniel Wortmann's avatar
Daniel Wortmann committed
231 232 233
                END DO
             END DO
          END DO
234 235 236 237 238 239 240 241 242 243
          !
          !--->    now add to H (G_lo,G)
          !
          DO m = -l,l
             iilo = matel0
             locol = locol0
             DO nkvec = 1,i_invsf* (2*l+1)
                locol = locol + 1
                IF (MOD(locol-1,n_size).EQ.n_rank) THEN
                   !-t3e
244 245 246 247
                   IF (l_real) THEN
                      DO ig = 1,nvv
                         iilo = iilo + 1
                         aa_r(iilo) = aa_r(iilo) + &
Daniel Wortmann's avatar
Daniel Wortmann committed
248 249 250 251
                                      ar_help(ig,m) * REAL(alo(m,nkvec,lo,iintsp)) + br_help(ig,m) * REAL(blo(m,nkvec,lo,iintsp)) + &
                                      cr_help(ig,m) * REAL(clo(m,nkvec,lo,iintsp)) - ai_help(ig,m) *AIMAG(alo(m,nkvec,lo,iintsp)) - &
                                      bi_help(ig,m) *AIMAG(blo(m,nkvec,lo,iintsp)) - ci_help(ig,m) *AIMAG(clo(m,nkvec,lo,iintsp))
                      END DO                     ! jump to end of row:
252 253 254 255
                   ELSE
                      DO ig = 1,nvv
                         iilo = iilo + 1
                         aa_c(iilo) = aa_c(iilo) + CMPLX(&
Daniel Wortmann's avatar
Daniel Wortmann committed
256 257 258 259 260 261
                                      ar_help(ig,m) * REAL(alo(m,nkvec,lo,iintsp)) + br_help(ig,m) * REAL(blo(m,nkvec,lo,iintsp)) + &
                                      cr_help(ig,m) * REAL(clo(m,nkvec,lo,iintsp)) - ai_help(ig,m) *AIMAG(alo(m,nkvec,lo,iintsp)) - &
                                      bi_help(ig,m) *AIMAG(blo(m,nkvec,lo,iintsp)) - ci_help(ig,m) *AIMAG(clo(m,nkvec,lo,iintsp)) , &
                                      ai_help(ig,m) * REAL(alo(m,nkvec,lo,iintsp)) + bi_help(ig,m) * REAL(blo(m,nkvec,lo,iintsp)) + &
                                      ci_help(ig,m) * REAL(clo(m,nkvec,lo,iintsp)) + ar_help(ig,m) *AIMAG(alo(m,nkvec,lo,iintsp)) + &
                                      br_help(ig,m) *AIMAG(blo(m,nkvec,lo,iintsp)) + cr_help(ig,m) *AIMAG(clo(m,nkvec,lo,iintsp)) )
262 263
                      ENDDO                     ! jump to end of row:
                   ENDIF
264 265 266 267
                   iilo = iilo + nkvecprevat + nkvecprevlo + nkvec 
                ENDIF
             ENDDO
          ENDDO
Daniel Wortmann's avatar
Daniel Wortmann committed
268
          DEALLOCATE (cr_help,ci_help)
269 270 271
          !
          !--->    calculate the contribution to H (G_lo,G_lo)
          !
Daniel Wortmann's avatar
Daniel Wortmann committed
272 273
          ALLOCATE (ax(-l:l,2*(2*atoms%llod+1)),wc_help(-l:l), bx(-l:l,2*(2*atoms%llod+1)),wd_help(-l:l))
          ALLOCATE (cx(-l:l,2*(2*atoms%llod+1)),we_help(-l:l), wa_help(-l:l),wb_help(-l:l))
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292

          iilo = matel0
          locol = locol0
          DO nkvec = 1,i_invsf* (2*l+1)
             locol = locol + 1
             IF (MOD(locol-1,n_size).EQ.n_rank) THEN
                iilo = iilo + nvv + nkvecprevat
                !
                !---> with other LOs
                !
                DO lop = 1, lo
                   lp = atoms%llo(lop,n)
                   IF (l.EQ.lp) THEN
                      dd    = ud%ddn(l,n,jsp)       ! * invsfct
                      ulolo = ud%uloulopn(lo,lop,n,usp) ! * invsfct
                      nkend = (2*lp+1) * i_invsf
                      IF (lop.EQ.lo) nkend = nkvec
                      DO m = -l,l
                         DO mp = -l,l
Daniel Wortmann's avatar
Daniel Wortmann committed
293 294 295 296 297 298
                            wa_help(mp) = vs_mmp(m,mp,i_u,jsp) ! * invsfct
                            wb_help(mp) = vs_mmp(m,mp,i_u,jsp) * dd
                            wc_help(mp) = vs_mmp(m,mp,i_u,jsp) * uulo
                            wd_help(mp) = vs_mmp(m,mp,i_u,jsp) * dulo
                            we_help(mp) = vs_mmp(m,mp,i_u,jsp) * ulolo
                         END DO
299 300 301 302 303
                         DO nkvecp = 1, nkend
                            ax(m,nkvecp) = CMPLX(0.0,0.0)
                            bx(m,nkvecp) = CMPLX(0.0,0.0)
                            cx(m,nkvecp) = CMPLX(0.0,0.0)
                            DO mp = -l,l
Daniel Wortmann's avatar
Daniel Wortmann committed
304 305 306 307 308 309 310 311 312 313 314 315 316
                               ax(m,nkvecp) = ax(m,nkvecp) + &
                                              CONJG(alo(mp,nkvecp,lop,jintsp)) * wa_help(mp) + &
                                              CONJG(clo(mp,nkvecp,lop,jintsp)) * wc_help(mp)
                               bx(m,nkvecp) = bx(m,nkvecp) + &
                                              CONJG(blo(mp,nkvecp,lop,jintsp)) * wb_help(mp) + &
                                              CONJG(clo(mp,nkvecp,lop,jintsp)) * wd_help(mp)
                               cx(m,nkvecp) = cx(m,nkvecp) + &
                                              CONJG(alo(mp,nkvecp,lop,jintsp)) * wc_help(mp) + &
                                              CONJG(blo(mp,nkvecp,lop,jintsp)) * wd_help(mp) + &
                                              CONJG(clo(mp,nkvecp,lop,jintsp)) * we_help(mp)
                            END DO
                         END DO
                      END DO
317 318 319 320 321
                      !
                      !---> add to H, special bound for contribution of lo with with itself
                      !
                      DO nkvecp = 1,nkend  
                         iilo = iilo + 1
322
                         IF (l_real) THEN
323
                         DO m = -l,l
324
                            aa_r(iilo) = aa_r(iilo) + &
Daniel Wortmann's avatar
Daniel Wortmann committed
325 326 327 328 329 330 331
                                         REAL(alo(m,nkvec,lo,iintsp))* REAL(ax(m,nkvecp)) + &
                                         REAL(blo(m,nkvec,lo,iintsp))* REAL(bx(m,nkvecp)) + &
                                         REAL(clo(m,nkvec,lo,iintsp))* REAL(cx(m,nkvecp)) - &
                                         AIMAG(alo(m,nkvec,lo,iintsp))*AIMAG(ax(m,nkvecp)) - &
                                         AIMAG(blo(m,nkvec,lo,iintsp))*AIMAG(bx(m,nkvecp)) - &
                                         AIMAG(clo(m,nkvec,lo,iintsp))*AIMAG(cx(m,nkvecp)) 
                         END DO
332 333
                      ELSE
                         DO m = -l,l
Daniel Wortmann's avatar
Daniel Wortmann committed
334 335 336 337 338 339
                            aa_c(iilo) = aa_c(iilo) + alo(m,nkvec,lo,iintsp) * ax(m,nkvecp) + &
                                                      blo(m,nkvec,lo,iintsp) * bx(m,nkvecp) + &
                                                      clo(m,nkvec,lo,iintsp) * cx(m,nkvecp) 
                         END DO
                      END IF
                      END DO
340 341
                   ELSE
                      iilo = iilo + i_invsf * (2*lp+1) ! = nkvecprevlo
Daniel Wortmann's avatar
Daniel Wortmann committed
342 343
                   END IF                               ! l = lp
                END DO
344
                !
Daniel Wortmann's avatar
Daniel Wortmann committed
345
             END IF ! T3e
346 347
             !-t3e
          END DO
Daniel Wortmann's avatar
Daniel Wortmann committed
348
          DEALLOCATE (ax,bx,cx,wa_help,wb_help,wc_help,wd_help,we_help)
349 350 351 352 353 354 355
          nkvecprevlo = nkvecprevlo + i_invsf * (2*l+1)
       ELSE
          lp = i_invsf * (2*atoms%llo(lo,n)+1)
          iilo = iilo + (nvv + nkvecprevlo + nkvecprevat) * lp
          iilo = iilo + (lp+1) * lp / 2
          nkvecprevlo = nkvecprevlo + lp
          locol = locol + lp
Daniel Wortmann's avatar
Daniel Wortmann committed
356 357
       END IF  ! end of if(l=atoms%llo(lo,n))
    END DO     ! end of lo = 1,atoms%nlo loop
358 359 360 361 362 363
    nkvecprevat = nkvecprevat + nkvecprevlo

    DEALLOCATE ( ar_help,ai_help,br_help,bi_help,va_help,vb_help )
    !
  END SUBROUTINE u_ham
END MODULE m_uham