force_a21.F90 16 KB
Newer Older
1 2 3 4 5 6 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 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
MODULE m_forcea21
CONTAINS
  SUBROUTINE force_a21(&
       atoms,dimension,nobd,sym, loplod,oneD,cell,&
       we,jsp,epar,ne,eig,usdus,&
       acof,bcof,ccof,aveccof,bveccof,cveccof, results,f_a21,f_b4)

    ! ************************************************************
    ! Pulay 2nd and 3rd (A17+A20) term force contribution a la Rici
    ! combined
    ! NOTE: we do NOT include anymore  the i**l factors
    ! in the alm,blm coming from to_pulay. Therefore, we can
    ! use matrixelements from file 28,38 DIRECTLY
    ! note: present version only yields forces for
    ! highest energy window (=valence states)
    ! if also semicore forces are wanted the tmas and tmat files
    ! have to be saved, indexed and properly used here in force_a21
    ! 22/june/97: probably we found symmetrization error replacing
    ! now S^-1 by S (IS instead of isinv)
    ! ************************************************************
    !
    ! Force contribution B4 added following
    ! Madsen, Blaha, Schwarz, Sjostedt, Nordstrom
    ! GMadsen FZJ 20/3-01
    !
    USE m_forcea21lo
    USE m_forcea21U
    USE m_tlmplm_store
    USE m_types
    IMPLICIT NONE

    TYPE(t_results),INTENT(INOUT):: results
    TYPE(t_dimension),INTENT(IN) :: dimension
    TYPE(t_oneD),INTENT(IN)      :: oneD
    TYPE(t_sym),INTENT(IN)       :: sym
    TYPE(t_cell),INTENT(IN)      :: cell
    TYPE(t_atoms),INTENT(IN)     :: atoms
    TYPE(t_usdus),INTENT(IN)     :: usdus
    !     ..
    !     .. Scalar Arguments ..
    INTEGER, INTENT (IN) :: nobd  
    INTEGER, INTENT (IN) :: loplod 
    INTEGER, INTENT (IN) :: ne,jsp
    !     ..
    !     .. Array Arguments ..
    REAL,    INTENT (IN) :: we(nobd),epar(0:atoms%lmaxd,atoms%ntypd)
    REAL,    INTENT (IN) :: eig(dimension%neigd)  
    COMPLEX, INTENT (INOUT) :: f_a21(3,atoms%ntypd),f_b4(3,atoms%ntypd)
    COMPLEX, INTENT (IN) :: acof(nobd,0:atoms%lmaxd*(atoms%lmaxd+2) ,atoms%natd)
    COMPLEX, INTENT (IN) :: bcof(nobd,0:atoms%lmaxd*(atoms%lmaxd+2),atoms%natd )
    COMPLEX, INTENT (IN) :: ccof(-atoms%llod:atoms%llod,nobd,atoms%nlod,atoms%natd)
    COMPLEX, INTENT (IN) :: aveccof(3,nobd,0:atoms%lmaxd*(atoms%lmaxd+2),atoms%natd )
    COMPLEX, INTENT (IN) :: bveccof(3,nobd,0:atoms%lmaxd*(atoms%lmaxd+2),atoms%natd )
    COMPLEX, INTENT (IN) :: cveccof(3,-atoms%llod:atoms%llod,nobd,atoms%nlod,atoms%natd)
    !     ..
    !     .. Local Scalars ..
    INTEGER, PARAMETER :: lmaxb=3
    COMPLEX dtd,dtu,utd,utu
    INTEGER lo 
    INTEGER i,ie,im,in,l1,l2,ll1,ll2,lm1,lm2,m1,m2,n,natom
    INTEGER natrun,is,isinv,j,irinv,it
    REAL   ,PARAMETER:: zero=0.0
    COMPLEX,PARAMETER:: czero=cmplx(0.,0.)
    !     ..
    !     .. Local Arrays ..
    COMPLEX, ALLOCATABLE :: v_mmp(:,:)
    REAL,    ALLOCATABLE :: a21(:,:),b4(:,:)
    COMPLEX forc_a21(3),forc_b4(3)
    REAL starsum(3),starsum2(3),gvint(3),gvint2(3)
    REAL vec(3),vec2(3),vecsum(3),vecsum2(3)

    TYPE(t_tlmplm)::tlmplm
    !     ..
    !     ..
    !dimension%lmplmd = (dimension%lmd* (dimension%lmd+3))/2
    ALLOCATE ( tlmplm%tdd(0:dimension%lmplmd,atoms%ntype,1),tlmplm%tuu(0:dimension%lmplmd,atoms%ntype,1),&
         tlmplm%tdu(0:dimension%lmplmd,atoms%ntype,1),tlmplm%tud(0:dimension%lmplmd,atoms%ntype,1),&
         tlmplm%tuulo(0:dimension%lmd,-atoms%llod:atoms%llod,atoms%nlod,1),&
         tlmplm%tdulo(0:dimension%lmd,-atoms%llod:atoms%llod,atoms%nlod,1),&
         tlmplm%tuloulo(-atoms%llod:atoms%llod,-atoms%llod:atoms%llod,loplod,1),&
         v_mmp(-lmaxb:lmaxb,-lmaxb:lmaxb),&
         a21(3,atoms%natd),b4(3,atoms%natd),tlmplm%ind(0:dimension%lmd,0:dimension%lmd,atoms%ntype,1) )
    !
    natom = 1
    DO  n = 1,atoms%ntype
       IF (atoms%l_geo(n)) THEN
          forc_a21(:) = czero
          forc_b4(:) = czero


          call read_tlmplm(n,jsp,atoms%nlo,atoms%lda_u%l.ge.0,&
               tlmplm%tuu(:,n,1),tlmplm%tud(:,n,1),tlmplm%tdu(:,n,1),tlmplm%tdd(:,n,1),&
               tlmplm%ind(:,:,n,1),tlmplm%tuulo(:,:,:,1),tlmplm%tuloulo(:,:,:,1),tlmplm%tdulo(:,:,:,1),v_mmp)

          DO natrun = natom,natom + atoms%neq(n) - 1
             a21(:,natrun) = zero
             b4(:,natrun) = zero

          END DO
          !
          DO ie = 1,ne
             !
             !
             DO l1 = 0,atoms%lmax(n)
                ll1 = l1* (l1+1)
                DO m1 = -l1,l1
                   lm1 = ll1 + m1
                   DO l2 = 0,atoms%lmax(n)
                      !
                      ll2 = l2* (l2+1)
                      DO m2 = -l2,l2
                         lm2 = ll2 + m2
                         DO natrun = natom,natom + atoms%neq(n) - 1
                            in = tlmplm%ind(lm1,lm2,n,1)
                            IF (in.NE.-9999) THEN
                               IF (in.GE.0) THEN
                                  !
                                  ! ATTENTION: the matrix elements tuu,tdu,tud,tdd
                                  ! as calculated in tlmplm are the COMPLEX CONJUGATE
                                  ! of the non-spherical matrix elements because in the
                                  ! matrix building routine hssphn (or similar routines)
                                  ! the COMPLEX CONJUGATE of alm,blm is calculated (to
                                  ! save complex operations presumably)
                                  ! Her, A20 is formulated in the usual way therefore
                                  ! we have to take the COMPLEX CONJUGATE versions
                                  ! of tuu,tdu,tud,tdd as compared to hssphn!
                                  !
                                  utu = tlmplm%tuu(in,n,1)
                                  dtu = tlmplm%tdu(in,n,1)
                                  utd = tlmplm%tud(in,n,1)
                                  dtd = tlmplm%tdd(in,n,1)
                               ELSE
                                  im = -in
                                  utu = conjg(tlmplm%tuu(im,n,1))
                                  dtd = conjg(tlmplm%tdd(im,n,1))
                                  utd = conjg(tlmplm%tdu(im,n,1))
                                  dtu = conjg(tlmplm%tud(im,n,1))
                               END IF
                               DO i = 1,3
                                  a21(i,natrun) = a21(i,natrun) + 2.0*&
                                       aimag( conjg(acof(ie,lm1,natrun)) *utu*aveccof(i,ie,lm2,natrun)&
                                       +conjg(acof(ie,lm1,natrun)) *utd*bveccof(i,ie,lm2,natrun)&
                                       +conjg(bcof(ie,lm1,natrun)) *dtu*aveccof(i,ie,lm2,natrun)&
                                       +conjg(bcof(ie,lm1,natrun)) *dtd*bveccof(i,ie,lm2,natrun))*we(ie)/atoms%neq(n)
                                  !   END i loop
                               END DO
                            END IF
                            !   END natrun
                         END DO
                         !
                         !   END m2 loop
                      END DO
                      !   END l2 loop
                   END DO
                   !+gu 20.11.97
                   utu = epar(l1,n)-eig(ie)
                   utd = 0.5
                   dtu = 0.5
                   dtd = utu*usdus%ddn(l1,n,jsp)
                   DO i = 1,3
                      DO natrun = natom,natom + atoms%neq(n) - 1
                         a21(i,natrun) = a21(i,natrun) + 2.0*&
                              aimag(conjg(acof(ie,lm1,natrun)) *utu*aveccof(i,ie,lm1,natrun)&
                              +conjg(acof(ie,lm1,natrun)) *utd*bveccof(i,ie,lm1,natrun)&
                              +conjg(bcof(ie,lm1,natrun)) *dtu*aveccof(i,ie,lm1,natrun)&
                              +conjg(bcof(ie,lm1,natrun)) *dtd*bveccof(i,ie,lm1,natrun)&
                              )*we(ie) /atoms%neq(n)
                      END DO
                      !
                      !-gu
                      ! END  i loop
                   END DO
                   !   END m1 loop
                END DO
                !   END l1 loop
             END DO
             !   END ie loop
          END DO
          !
          !--->    add the local orbital and U contribution to a21
          !
          CALL force_a21_lo(nobd,atoms, loplod,jsp,n,we,eig,ne,&
               acof,bcof,ccof,aveccof,bveccof,cveccof, tlmplm,usdus, a21)

          CALL force_a21_U(nobd,atoms,lmaxb,n,jsp,we,ne, usdus,v_mmp,&
               acof,bcof,ccof,aveccof,bveccof,cveccof, a21)

#ifdef CPP_APW
          ! -> B4 force
          DO ie = 1,ne
             DO l1 = 0,atoms%lmax(n)
                ll1 = l1* (l1+1)
                DO m1 = -l1,l1
                   lm1 = ll1 + m1
                   DO i = 1,3
                      DO natrun = natom,natom + atoms%neq(n) - 1
                         b4(i,natrun) = b4(i,natrun) + 0.5 *&
                              we(ie)/atoms%neq(n)*atoms%rmt(n)**2*aimag(&
                              conjg(acof(ie,lm1,natrun)*usdus%us(l1,n,jsp)&
                              +bcof(ie,lm1,natrun)*usdus%uds(l1,n,jsp))*&
                              (aveccof(i,ie,lm1,natrun)*usdus%dus(l1,n,jsp)&
                              +bveccof(i,ie,lm1,natrun)*usdus%duds(l1,n,jsp) )&
                              -conjg(aveccof(i,ie,lm1,natrun)*usdus%us(l1,n,jsp)&
                              +bveccof(i,ie,lm1,natrun)*usdus%uds(l1,n,jsp) )*&
                              (acof(ie,lm1,natrun)*usdus%dus(l1,n,jsp)&
                              +bcof(ie,lm1,natrun)*usdus%duds(l1,n,jsp)) )
                      END DO
                   END DO
                END DO
             END DO
             DO lo = 1,atoms%nlo(n)
                l1 = atoms%llo(lo,n)
                DO m = -l1,l1
                   lm1 = l1* (l1+1) + m
                   do i=1,3
                      DO natrun = natom,natom + atoms%neq(n) - 1
                         b4(i,natrun) = b4(i,natrun) + 0.5 *&
                              we(ie)/atoms%neq(n)*atoms%rmt(n)**2*aimag(&
                              conjg( acof(ie,lm1,natrun)* usdus%us(l1,n,jsp)&
                              + bcof(ie,lm1,natrun)* usdus%uds(l1,n,jsp) ) *&
                              cveccof(i,m,ie,lo,natrun)*usdus%dulos(lo,n,jsp)&
                              + conjg(ccof(m,ie,lo,natrun)*usdus%ulos(lo,n,jsp)) *&
                              ( aveccof(i,ie,lm1,natrun)* usdus%dus(l1,n,jsp)&
                              + bveccof(i,ie,lm1,natrun)* usdus%duds(l1,n,jsp)&
                              + cveccof(i,m,ie,lo,natrun)*usdus%dulos(lo,n,jsp) )  &
                              - (conjg( aveccof(i,ie,lm1,natrun) *usdus%us(l1,n,jsp)&
                              + bveccof(i,ie,lm1,natrun) *usdus%uds(l1,n,jsp) ) *&
                              ccof(m,ie,lo,natrun)  *usdus%dulos(lo,n,jsp)&
                              + conjg(cveccof(i,m,ie,lo,natrun)*usdus%ulos(lo,n,jsp)) *&
                              ( acof(ie,lm1,natrun)*usdus%dus(l1,n,jsp)&
                              + bcof(ie,lm1,natrun)*usdus%duds(l1,n,jsp)&
                              + ccof(m,ie,lo,natrun)*usdus%dulos(lo,n,jsp) ) ) )  
                      END DO
                   ENDDO
                ENDDO
             ENDDO
          END DO
#endif   
          !
          DO natrun = natom,natom + atoms%neq(n) - 1
             !
             !  to complete summation over stars of k now sum
             !  over all operations which leave (k+G)*R(natrun)*taual(natrun)
             !  invariant. We sum over ALL these operations and not only
             !  the ones needed for the actual star of k. Should be
             !  ok if we divide properly by the number of operations
             !  First, we find operation S where RS=T. T -like R- leaves
             !  the above scalar product invariant (if S=1 then R=T).
             !  R is the operation which generates position of equivalent atom
             !  out of position of representative
             !  S=R^(-1) T
             !  number of ops which leave (k+G)*op*taual invariant: invarind
             !  index of inverse operation of R: irinv
             !  index of operation T: invarop
             !  now, we calculate index of operation S: is
             !
             !  note, that vector in expression A17,A20 + A21 is a
             !  reciprocal lattice vector! other transformation rules
             !
             !  transform recip vector g-g' into internal coordinates

             vec(:) = a21(:,natrun)
             vec2(:) = b4(:,natrun)

             gvint=matmul(cell%bmat,vec)
             gvint2=matmul(cell%bmat,vec2)
             vecsum(:) = zero
             vecsum2(:) = zero

             !-gb2002
             !            irinv = invtab(ngopr(natrun))
             !            DO it = 1,invarind(natrun)
             !               is = multab(irinv,invarop(natrun,it))
             !c  note, actually we need the inverse of S but -in principle
             !c  because {S} is a group and we sum over all S- S should also
             !c  work; to be lucid we take the inverse:
             !                isinv = invtab(is)
             !!               isinv = is
             ! Rotation is alreadt done in to_pulay, here we work only in the
             ! coordinate system of the representative atom (natom):
             !!        
             DO it = 1,sym%invarind(natom)
                is =sym%invarop(natom,it)
                isinv = sym%invtab(is)
                IF (oneD%odi%d1) isinv = oneD%ods%ngopr(natom)
                !-gb 2002
                !  now we have the wanted index of operation with which we have
                !  to rotate gv. Note gv is given in cart. coordinates but
                !  mrot acts on internal ones
                DO i = 1,3
                   vec(i) = zero
                   vec2(i) = zero
                   DO j = 1,3
                      IF (.NOT.oneD%odi%d1) THEN
                         vec(i) = vec(i) + sym%mrot(i,j,isinv)*gvint(j)
                         vec2(i) = vec2(i) + sym%mrot(i,j,isinv)*gvint2(j)
                      ELSE
                         vec(i) = vec(i) + oneD%ods%mrot(i,j,isinv)*gvint(j)
                         vec2(i) = vec2(i) + oneD%ods%mrot(i,j,isinv)*gvint2(j)
                      END IF
                   END DO
                END DO
                DO i = 1,3
                   vecsum(i) = vecsum(i) + vec(i)
                   vecsum2(i) = vecsum2(i) + vec2(i)
                END DO
                !   end operator loop
             END DO
             !
             !   transform from internal to cart. coordinates
             starsum=matmul(cell%amat,vecsum)
             starsum2=matmul(cell%amat,vecsum2)
             DO i = 1,3
                forc_a21(i) = forc_a21(i) + starsum(i)/sym%invarind(natrun)
                forc_b4(i) = forc_b4(i) + starsum2(i)/sym%invarind(natrun)
             END DO
             !
             !  natrun loop end
          END DO
          !
          !     sum to existing forces
          !
          !  NOTE: force() IS REAL AND THEREFORE TAKES ONLY THE
          !  REAL PART OF forc_a21(). IN GENERAL, FORCE MUST BE
          !  REAL AFTER k-STAR SUMMATION. NOW, WE PUT THE PROPER
          !  OPERATIONS INTO REAL SPACE. PROBLEM: WHAT HAPPENS
          !  IF IN REAL SPACE THERE IS NO INVERSION ANY MORE?
          !  BUT WE HAVE INVERSION IN k-SPACE DUE TO TIME REVERSAL
          !  SYMMETRY, E(k)=E(-k)
          !  WE ARGUE THAT k-SPACE INVERSION IS AUTOMATICALLY TAKEN
          !  INTO ACCOUNT IF FORCE = (1/2)(forc_a21+conjg(forc_a21))
          !  BECAUSE TIME REVERSAL SYMMETRY MEANS THAT conjg(PSI)
          !  IS ALSO A SOLUTION OF SCHR. EQU. IF PSI IS ONE.
          DO i = 1,3
             results%force(i,n,jsp) = results%force(i,n,jsp) + real(forc_a21(i) + forc_b4(i))
             f_a21(i,n)     = f_a21(i,n)     + forc_a21(i)
             f_b4(i,n)      = f_b4(i,n)      + forc_b4(i)
          END DO
          !
          !     write result moved to force_a8
          !
          !         write(*,*) a21(:,n) 
       ENDIF                                            !  IF (atoms%l_geo(n)) ...
       natom = natom + atoms%neq(n)
    enddo
    !
    DEALLOCATE (tlmplm%tdd,tlmplm%tuu,tlmplm%tdu,tlmplm%tud,tlmplm%tuulo,tlmplm%tdulo,tlmplm%tuloulo,v_mmp,tlmplm%ind,a21,b4)

  END SUBROUTINE force_a21
END MODULE m_forcea21