slomat.F90 14 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 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 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
MODULE m_slomat
  !***********************************************************************
  ! updates the overlap matrix with the contributions from the local
  ! orbitals.
  !                                                p.kurz sept. 1996
  !***********************************************************************
CONTAINS
  SUBROUTINE slomat(&
       atoms, ntyp,na,lapw,con1,n_size,n_rank,&
       gk,rph,cph,f,g,kvec,usp,ud, alo1,blo1,clo1,noco,&
       ab_dim,iintsp,jintsp,chi11,chi22,chi21, iilo,locol,nkvecprevat,bb)
    !***********************************************************************
    ! iilo is the starting position for the LO-contribution of atom 'na'
    !      in the Hamilton-matrix minus 1 (starting from (nv+1)*nv/2)
    ! nkvecprevat gives the number of G-vectors already processed on other
    !             atoms (each l-LO gives (2l+1)*invsfact G-vectors)
    ! nkvecprevlo gives the number of G-vectors already processed on this
    !             atoms due to other lo's (appears in hlomat only)
    ! locol stores the number of columns already processed; on parallel
    !       computers this decides, whether the LO-contribution is
    !       done on this node                                          gb00
    !
    ! function legpol() at end of module
    !***********************************************************************
#include"cpp_double.h" 
    USE m_constants,ONLY: fpi_const
    USE m_types
    IMPLICIT NONE
    TYPE(t_noco),INTENT(IN)   :: noco
    TYPE(t_atoms),INTENT(IN)  :: atoms
    TYPE(t_lapw),INTENT(IN)   :: lapw
    !     ..
    !     .. Scalar Arguments ..
    INTEGER, INTENT (IN) :: na,ntyp,n_size,n_rank 
    INTEGER, INTENT (IN) :: ab_dim,iintsp,jintsp
    COMPLEX, INTENT (IN) :: chi11,chi22,chi21
    REAL,    INTENT (IN) :: con1
    INTEGER, INTENT (INOUT) :: iilo,nkvecprevat,locol
    INTEGER, INTENT(IN)  :: usp
    !     ..
    !     .. Array Arguments ..
    INTEGER,INTENT (IN) :: kvec(:,:)!(2*llod_1),nlod  )
    REAL,   INTENT (IN) :: alo1(atoms%nlod),blo1(atoms%nlod),clo1(atoms%nlod) 
    REAL,   INTENT (IN) :: gk(:,:,:)!(dimension%nvd,3,ab_dim)
    REAL,   INTENT (IN) :: rph(:,:),cph(:,:)!(nvd,ab_dim)
    REAL,   INTENT (IN) :: f(:,0:,:,:)!(dimension%nvd,0:atoms%lmaxd,atoms%ntypd,ab_dim)
    REAL,   INTENT (IN) :: g(:,0:,:,:)!(dimension%nvd,0:atoms%lmaxd,atoms%ntypd,ab_dim)
    TYPE(t_usdus),INTENT(IN):: ud
#ifdef CPP_INVERSION
    REAL,    INTENT (INOUT) :: bb(:)!(matsize)
#else
    COMPLEX, INTENT (INOUT) :: bb(:)!(matsize)
#endif
    !     ..
    !     .. Local Scalars ..
    REAL con,dotp,fact1,fact2,fact3,fl2p1
    INTEGER invsfct,k ,l,l2p1,lo,lop,lp,nkvec,nkvecat,nkvecp,kp
    INTEGER iilo_s,locol_s,nkvecprevat_s,ic,ii,ij,n
    COMPLEX chihlp
    !     ..
    !     .. Local Arrays ..
    COMPLEX, ALLOCATABLE :: bhelp(:)
    !     ..
    !$OMP MASTER

    IF ((atoms%invsat(na).EQ.0) .OR. (atoms%invsat(na).EQ.1)) THEN
       !--->    if this atom is the first of two atoms related by inversion,
       !--->    the contributions to the overlap matrix of both atoms are added
       !--->    at once. where it is made use of the fact, that the sum of
       !--->    these contributions is twice the real part of the contribution
       !--->    of each atom. note, that in this case there are twice as many
       !--->    (2*(2*l+1)) k-vectors (compare abccoflo and comments there).
       IF (atoms%invsat(na).EQ.0) invsfct = 1
       IF (atoms%invsat(na).EQ.1) invsfct = 2
       !+noco
       IF (noco%l_ss) THEN
          iilo_s = iilo
          locol_s = locol
          nkvecprevat_s = nkvecprevat ! save for other interstitial spin loops
          ic = 0                                        ! update b-matrix
          DO lo = 1,atoms%nlo(ntyp)
             ic = ic + invsfct* (2*atoms%llo(lo,ntyp)+1)
          ENDDO
          k = ic*(lapw%nv(jintsp)+nkvecprevat) + (ic+1)*ic/2
          ALLOCATE ( bhelp(k) )       ! initialize help-array 
          bhelp=cmplx(0.,0.)
          iilo = 0
       ENDIF
       !-noco
       con = con1* ((atoms%rmt(ntyp))**2)/2.0
       nkvecat = 0
       DO lo = 1,atoms%nlo(ntyp)
          l = atoms%llo(lo,ntyp)
          l2p1 = 2*l + 1
          fl2p1 = l2p1/fpi_const
#ifdef CPP_APW
          fact1 = (con**2)* fl2p1 * (&
               alo1(lo)* (  alo1(lo) + &
               2*clo1(lo)*   ud%uulon(lo,ntyp,usp) ) +&
               blo1(lo)* (  blo1(lo)*     ud%ddn(l,ntyp,usp) +&
               2*clo1(lo)*   ud%dulon(lo,ntyp,usp) ) +&
               clo1(lo)*    clo1(lo)*ud%uloulopn(lo,lo,ntyp,usp) )
#else
          fact1 = (con**2)* fl2p1 * (&
               alo1(lo)* (  alo1(lo) + &
               2*clo1(lo) * ud%uulon(lo,ntyp,usp) ) +&
               blo1(lo)* (  blo1(lo) * ud%ddn(l, ntyp,usp) +&
               2*clo1(lo) * ud%dulon(lo,ntyp,usp) ) +&
               clo1(lo)*    clo1(lo) )
#endif
          DO nkvec = 1,invsfct* (2*l+1)
             !+t3e
             locol = locol + 1
             IF (mod(locol-1,n_size).EQ.n_rank) THEN
                !-t3e
                k = kvec(nkvec,lo)
                !--->          calculate the overlap matrix elements with the regular
                !--->          flapw basis-functions
                DO kp = 1,lapw%nv(jintsp)
                   iilo = iilo + 1
                   fact2 = con * fl2p1 * (&
                        f(kp,l,ntyp,jintsp)* ( alo1(lo) + &
                        clo1(lo)*ud%uulon(lo,ntyp,usp))+&
                        g(kp,l,ntyp,jintsp)* ( blo1(lo) * ud%ddn(l,ntyp,usp)+&
                        clo1(lo)*ud%dulon(lo,ntyp,usp)))
                   dotp = gk(k,1,iintsp) * gk(kp,1,jintsp) + &
                        gk(k,2,iintsp) * gk(kp,2,jintsp) +&
                        gk(k,3,iintsp) * gk(kp,3,jintsp)
#ifdef CPP_INVERSION
                   bb(iilo) = bb(iilo) + invsfct*fact2 * legpol(l,dotp) *&
                        ( rph(k,iintsp)*rph(kp,jintsp) +&
                        cph(k,iintsp)*cph(kp,jintsp) )
#else
                   IF (.not.noco%l_ss) THEN
                      bb(iilo) = bb(iilo) + invsfct*fact2 * legpol(l,dotp) *&
                           cmplx( ( rph(k,iintsp)*rph(kp,jintsp) +&
                           cph(k,iintsp)*cph(kp,jintsp) ) ,&
                           ( cph(k,iintsp)*rph(kp,jintsp) -&
                           rph(k,iintsp)*cph(kp,jintsp) ) )
                   ELSE 
                      bhelp(iilo) = invsfct*fact2*legpol(l,dotp) *&
                           cmplx( ( rph(k,iintsp)*rph(kp,jintsp) +&
                           cph(k,iintsp)*cph(kp,jintsp) ) ,&
                           ( cph(k,iintsp)*rph(kp,jintsp) -&
                           rph(k,iintsp)*cph(kp,jintsp) ) )
                   ENDIF
#endif
                END DO
                !--->          calculate the overlap matrix elements with other local
                !--->          orbitals at the same atom, if they have the same l
                iilo = iilo + nkvecprevat
                DO lop = 1, (lo-1)
                   lp = atoms%llo(lop,ntyp)
                   IF (l.EQ.lp) THEN
                      fact3 = con**2 * fl2p1 * (&
                           alo1(lop)*(alo1(lo) + &
                           clo1(lo)*ud%uulon(lo,ntyp,usp))+&
                           blo1(lop)*(blo1(lo)*ud%ddn(l,ntyp,usp) +&
                           clo1(lo)*ud%dulon(lo,ntyp,usp))+&
                           clo1(lop)*(alo1(lo)*ud%uulon(lop,ntyp,usp)+&
                           blo1(lo)*ud%dulon(lop,ntyp,usp)+&
                           clo1(lo)*ud%uloulopn(lop,lo,ntyp,usp)))
                      DO nkvecp = 1,invsfct* (2*lp+1)
                         iilo = iilo + 1
                         kp = kvec(nkvecp,lop) !
                         dotp = gk(k,1,iintsp) * gk(kp,1,jintsp) +&
                              gk(k,2,iintsp) * gk(kp,2,jintsp) +&
                              gk(k,3,iintsp) * gk(kp,3,jintsp)
#ifdef CPP_INVERSION
                         bb(iilo) =bb(iilo)+invsfct*fact3*legpol(l,dotp)* &
                              ( rph(k,iintsp)*rph(kp,jintsp) +&
                              cph(k,iintsp)*cph(kp,jintsp) )
#else
                         IF (.not.noco%l_ss) THEN
                            bb(iilo) =bb(iilo)+invsfct*fact3*legpol(l,dotp)*&
                                 cmplx( ( rph(k,iintsp)*rph(kp,jintsp) +&
                                 cph(k,iintsp)*cph(kp,jintsp) ) ,&
                                 ( cph(k,iintsp)*rph(kp,jintsp) -&
                                 rph(k,iintsp)*cph(kp,jintsp) ) )
                         ELSE 
                            bhelp(iilo) = invsfct*fact3*legpol(l,dotp)*&
                                 cmplx( ( rph(k,iintsp)*rph(kp,jintsp) +&
                                 cph(k,iintsp)*cph(kp,jintsp) ) ,&
                                 ( cph(k,iintsp)*rph(kp,jintsp) -&
                                 rph(k,iintsp)*cph(kp,jintsp) ) )
                         ENDIF
#endif
                      END DO
                   ELSE
                      iilo = iilo + invsfct* (2*lp+1)
                   END IF
                END DO
                !--->          calculate the overlap matrix elements of one local
                !--->          orbital with itself
                DO nkvecp = 1,nkvec
                   iilo = iilo + 1
                   kp = kvec(nkvecp,lo)
                   dotp = gk(k,1,iintsp) * gk(kp,1,jintsp) +&
                        gk(k,2,iintsp) * gk(kp,2,jintsp) +&
                        gk(k,3,iintsp) * gk(kp,3,jintsp)
#ifdef CPP_INVERSION
                   bb(iilo) = bb(iilo) + invsfct*fact1*legpol(l,dotp) *&
                        ( rph(k,iintsp)*rph(kp,jintsp) +&
                        cph(k,iintsp)*cph(kp,jintsp) )
#else
                   IF (.not.noco%l_ss) THEN
                      bb(iilo) = bb(iilo) + invsfct*fact1*legpol(l,dotp)*&
                           cmplx( ( rph(k,iintsp)*rph(kp,jintsp) +&
                           cph(k,iintsp)*cph(kp,jintsp) ) ,&
                           ( cph(k,iintsp)*rph(kp,jintsp) -&
                           rph(k,iintsp)*cph(kp,jintsp) ) )
                   ELSE 
                      bhelp(iilo) = invsfct*fact1*legpol(l,dotp)*&
                           cmplx( ( rph(k,iintsp)*rph(kp,jintsp) +&
                           cph(k,iintsp)*cph(kp,jintsp) ) ,&
                           ( cph(k,iintsp)*rph(kp,jintsp) -&
                           rph(k,iintsp)*cph(kp,jintsp) ) )
                   ENDIF
#endif
                END DO
             ENDIF ! mod(locol-1,n_size) = nrank 
             !-t3e
          END DO
          nkvecat = nkvecat + invsfct* (2*l+1)
       END DO
       nkvecprevat = nkvecprevat + nkvecat
       !+noco
       IF (noco%l_ss) THEN
          IF ( iintsp.EQ.1 .AND. jintsp.EQ.1 ) THEN     !---> spin-up spin-up part
             chihlp = chi11
             n = lapw%nv(1) + nkvecprevat_s
             ij = (n+1)*n/2
          ELSEIF ( iintsp.EQ.2 .AND. jintsp.EQ.2 ) THEN !---> spin-down spin-down part
             chihlp = chi22
             n = lapw%nv(1) + lapw%nv(iintsp) + atoms%nlotot + nkvecprevat_s
             ij = (n+1)*n/2 + lapw%nv(1) + atoms%nlotot
          ELSE                                          !---> spin-down spin-up part
             chihlp = chi21
             n = lapw%nv(1) + lapw%nv(iintsp) + atoms%nlotot + nkvecprevat_s
             ij = (n+1)*n/2 
          ENDIF

          ic = 0                                        ! update b-matrix
          DO lo = 1,atoms%nlo(ntyp)
             ic = ic + invsfct* (2*atoms%llo(lo,ntyp)+1)
          ENDDO
          IF (.not.( iintsp.EQ.1 .AND. jintsp.EQ.2 )) THEN
             ii = 0
             DO k = 1, ic
                n = k + lapw%nv(jintsp) + nkvecprevat_s
#ifndef CPP_INVERSION
                bb(ij+1:ij+n-1)=bb(ij+1:ij+n-1)+chihlp*bhelp(ii+1:ii+n-1)
                IF (.not.(iintsp.EQ.2 .AND. jintsp.EQ.1 )) THEN
                   bb(ij+n)=bb(ij+n)+chihlp*bhelp(ii+n)
                ENDIF
#endif
                ii = ii + n
                ij = ij + n + (lapw%nv(3-jintsp)+atoms%nlotot)*(iintsp-1)
             ENDDO
          ELSE                                         ! special treatment for up-down:
             n = lapw%nv(1) + atoms%nlotot
             ii = 0
             DO k = 1, ic
                ij = (n+1)*n/2 + lapw%nv(1) + k + nkvecprevat_s
                DO kp = 1, k + lapw%nv(jintsp) + nkvecprevat_s
                   ii = ii + 1
                   bb(ij) = bb(ij) +  chihlp *conjg( bhelp(ii) )
                   ij = ij + lapw%nv(1) + kp + atoms%nlotot
                ENDDO
             ENDDO
          ENDIF
          !          n1=nv(jintsp)+1
          !          n2=n1+nv(jintsp)+2
          !          n3=n2+nv(jintsp)+3
          !          do n = 1,nv(jintsp)+(nlotot/2)
          !           write(4,'(8f15.8)') bhelp(n),bhelp(n1+n),bhelp(n2+n),bhelp(n3+n)
          !          enddo
          DEALLOCATE ( bhelp )
          IF (.not.( iintsp.EQ.2 .AND. jintsp.EQ.2 )) THEN
             iilo = iilo_s
             locol = locol_s             ! restore for other loops
             nkvecprevat = nkvecprevat_s
          ENDIF
       ENDIF ! noco%l_ss
       !-noco
    END IF
    !$OMP END MASTER
  END SUBROUTINE slomat
  !===========================================================================
  REAL FUNCTION legpol(l,arg)
    !
    IMPLICIT NONE
    !     ..
    !     .. Scalar Arguments ..
    REAL arg
    INTEGER l
    !     ..
    !     .. Local Scalars ..
    INTEGER lp
    !     ..
    !     .. Local Arrays ..
    REAL plegend(0:l)
    !     ..
    plegend(0) = 1.0
    IF (l.GE.1) THEN
       plegend(1) = arg
       DO lp = 1,l - 1
          plegend(lp+1) = (lp+lp+1)*arg*plegend(lp)/ (lp+1) -lp*plegend(lp-1)/ (lp+1)
       END DO
    END IF
    legpol = plegend(l)
  END FUNCTION legpol
  !===========================================================================
END MODULE m_slomat