force_a21.F90 16.9 KB
Newer Older
1 2
MODULE m_forcea21
CONTAINS
3 4
  SUBROUTINE force_a21(input,atoms,DIMENSION,nobd,sym,oneD,cell,&
                       we,jsp,epar,ne,eig,usdus,eigVecCoeffs,force,results)
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

    ! ************************************************************
    ! 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
28
    USE m_constants
29
    IMPLICIT NONE
30 31 32 33 34 35 36 37 38 39
    TYPE(t_input),INTENT(IN)        :: input
    TYPE(t_force),INTENT(INOUT)     :: force
    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
    TYPE(t_eigVecCoeffs),INTENT(IN) :: eigVecCoeffs
40 41
    !     ..
    !     .. Scalar Arguments ..
42
    INTEGER, INTENT (IN) :: nobd
43 44 45
    INTEGER, INTENT (IN) :: ne,jsp
    !     ..
    !     .. Array Arguments ..
Daniel Wortmann's avatar
Daniel Wortmann committed
46
    REAL,    INTENT (IN) :: we(nobd),epar(0:atoms%lmaxd,atoms%ntype)
47
    REAL,    INTENT (IN) :: eig(DIMENSION%neigd)  
48 49 50
    !     ..
    !     .. Local Scalars ..
    COMPLEX dtd,dtu,utd,utu
51
    INTEGER lo, mlotot, mlolotot, mlot_d, mlolot_d
Daniel Wortmann's avatar
Daniel Wortmann committed
52
    INTEGER i,ie,im,in,l1,l2,ll1,ll2,lm1,lm2,m1,m2,n,natom,m,i_u
53 54
    INTEGER natrun,is,isinv,j,irinv,it
    REAL   ,PARAMETER:: zero=0.0
55
    COMPLEX,PARAMETER:: czero=CMPLX(0.,0.)
56 57
    !     ..
    !     .. Local Arrays ..
Daniel Wortmann's avatar
Daniel Wortmann committed
58
    COMPLEX, ALLOCATABLE :: v_mmp(:,:,:)
59 60 61 62 63 64 65 66 67
    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
68 69 70 71 72
    mlotot = 0 ; mlolotot = 0
    DO n = 1, atoms%ntype
       mlotot = mlotot + atoms%nlo(n)
       mlolotot = mlolotot + atoms%nlo(n)*(atoms%nlo(n)+1)/2
    ENDDO
73 74 75 76 77 78
    mlot_d = MAX(mlotot,1)
    mlolot_d = MAX(mlolotot,1)
    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,mlot_d,1),&
         tlmplm%tdulo(0:DIMENSION%lmd,-atoms%llod:atoms%llod,mlot_d,1),&
79
         tlmplm%tuloulo(-atoms%llod:atoms%llod,-atoms%llod:atoms%llod,mlolot_d,1),&
Daniel Wortmann's avatar
Daniel Wortmann committed
80
         a21(3,atoms%nat),b4(3,atoms%nat),tlmplm%ind(0:DIMENSION%lmd,0:DIMENSION%lmd,atoms%ntype,1) )
81
    !
Daniel Wortmann's avatar
Daniel Wortmann committed
82
    IF(atoms%n_u.GT.0) THEN
83
       ALLOCATE(v_mmp(-lmaxU_const:lmaxU_const,-lmaxU_const:lmaxU_const,atoms%n_u))
Daniel Wortmann's avatar
Daniel Wortmann committed
84 85 86 87 88
       v_mmp = CMPLX(0.0,0.0)
       CALL read_tlmplm_vs_mmp(jsp,atoms%n_u,v_mmp)
    END IF

    i_u = 1
89 90 91 92 93 94 95
    natom = 1
    DO  n = 1,atoms%ntype
       IF (atoms%l_geo(n)) THEN
          forc_a21(:) = czero
          forc_b4(:) = czero


Daniel Wortmann's avatar
Daniel Wortmann committed
96
          CALL read_tlmplm(n,jsp,atoms%nlo,&
97
               tlmplm%tuu(:,n,1),tlmplm%tud(:,n,1),tlmplm%tdu(:,n,1),tlmplm%tdd(:,n,1),&
Daniel Wortmann's avatar
Daniel Wortmann committed
98
               tlmplm%ind(:,:,n,1),tlmplm%tuulo(:,:,:,1),tlmplm%tuloulo(:,:,:,1),tlmplm%tdulo(:,:,:,1))
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

          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
139 140 141 142
                                  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))
143 144 145
                               END IF
                               DO i = 1,3
                                  a21(i,natrun) = a21(i,natrun) + 2.0*&
146 147 148 149
                                       AIMAG( CONJG(eigVecCoeffs%acof(ie,lm1,natrun,jsp)) *utu*force%aveccof(i,ie,lm2,natrun)&
                                       +CONJG(eigVecCoeffs%acof(ie,lm1,natrun,jsp)) *utd*force%bveccof(i,ie,lm2,natrun)&
                                       +CONJG(eigVecCoeffs%bcof(ie,lm1,natrun,jsp)) *dtu*force%aveccof(i,ie,lm2,natrun)&
                                       +CONJG(eigVecCoeffs%bcof(ie,lm1,natrun,jsp)) *dtd*force%bveccof(i,ie,lm2,natrun))*we(ie)/atoms%neq(n)
150 151 152 153 154 155 156 157 158 159 160
                                  !   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
161 162 163 164 165 166 167 168 169 170 171 172
                   in = tlmplm%ind(lm1,lm1,n,1)
                   IF (in.NE.-9999) THEN
                      utu = -eig(ie)
                      utd = 0.0
                      dtu = 0.0
                      dtd = utu*usdus%ddn(l1,n,jsp)
                   ELSE
                      utu = epar(l1,n)-eig(ie)
                      utd = 0.5
                      dtu = 0.5
                      dtd = utu*usdus%ddn(l1,n,jsp)
                   END IF
173 174 175
                   DO i = 1,3
                      DO natrun = natom,natom + atoms%neq(n) - 1
                         a21(i,natrun) = a21(i,natrun) + 2.0*&
176 177 178 179
                              AIMAG(CONJG(eigVecCoeffs%acof(ie,lm1,natrun,jsp)) *utu*force%aveccof(i,ie,lm1,natrun)&
                              +CONJG(eigVecCoeffs%acof(ie,lm1,natrun,jsp)) *utd*force%bveccof(i,ie,lm1,natrun)&
                              +CONJG(eigVecCoeffs%bcof(ie,lm1,natrun,jsp)) *dtu*force%aveccof(i,ie,lm1,natrun)&
                              +CONJG(eigVecCoeffs%bcof(ie,lm1,natrun,jsp)) *dtd*force%bveccof(i,ie,lm1,natrun)&
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
                              )*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
          !
195
          CALL force_a21_lo(nobd,atoms,jsp,n,we,eig,ne,eigVecCoeffs,force,tlmplm,usdus,a21)
196

Daniel Wortmann's avatar
Daniel Wortmann committed
197
          IF ((atoms%n_u.GT.0).AND.(i_u.LE.atoms%n_u)) THEN
198
             CALL force_a21_U(nobd,atoms,i_u,n,jsp,we,ne,usdus,v_mmp,eigVecCoeffs,force,a21)
Daniel Wortmann's avatar
Daniel Wortmann committed
199
          END IF
200 201 202 203 204 205 206 207 208 209 210
          IF (input%l_useapw) THEN
             ! -> 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(&
211 212
                                 CONJG(eigVecCoeffs%acof(ie,lm1,natrun,jsp)*usdus%us(l1,n,jsp)&
                                 +eigVecCoeffs%bcof(ie,lm1,natrun,jsp)*usdus%uds(l1,n,jsp))*&
213 214 215 216
                                 (force%aveccof(i,ie,lm1,natrun)*usdus%dus(l1,n,jsp)&
                                 +force%bveccof(i,ie,lm1,natrun)*usdus%duds(l1,n,jsp) )&
                                 -CONJG(force%aveccof(i,ie,lm1,natrun)*usdus%us(l1,n,jsp)&
                                 +force%bveccof(i,ie,lm1,natrun)*usdus%uds(l1,n,jsp) )*&
217 218
                                 (eigVecCoeffs%acof(ie,lm1,natrun,jsp)*usdus%dus(l1,n,jsp)&
                                 +eigVecCoeffs%bcof(ie,lm1,natrun,jsp)*usdus%duds(l1,n,jsp)) )
219
                         END DO
220 221 222
                      END DO
                   END DO
                END DO
223 224 225 226 227 228 229 230
                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(&
231 232
                                 CONJG( eigVecCoeffs%acof(ie,lm1,natrun,jsp)* usdus%us(l1,n,jsp)&
                                 + eigVecCoeffs%bcof(ie,lm1,natrun,jsp)* usdus%uds(l1,n,jsp) ) *&
233
                                 force%cveccof(i,m,ie,lo,natrun)*usdus%dulos(lo,n,jsp)&
234
                                 + CONJG(eigVecCoeffs%ccof(m,ie,lo,natrun,jsp)*usdus%ulos(lo,n,jsp)) *&
235 236 237 238 239
                                 ( force%aveccof(i,ie,lm1,natrun)* usdus%dus(l1,n,jsp)&
                                 + force%bveccof(i,ie,lm1,natrun)* usdus%duds(l1,n,jsp)&
                                 + force%cveccof(i,m,ie,lo,natrun)*usdus%dulos(lo,n,jsp) )  &
                                 - (CONJG( force%aveccof(i,ie,lm1,natrun) *usdus%us(l1,n,jsp)&
                                 + force%bveccof(i,ie,lm1,natrun) *usdus%uds(l1,n,jsp) ) *&
240
                                 eigVecCoeffs%ccof(m,ie,lo,natrun,jsp)  *usdus%dulos(lo,n,jsp)&
241
                                 + CONJG(force%cveccof(i,m,ie,lo,natrun)*usdus%ulos(lo,n,jsp)) *&
242 243 244
                                 ( eigVecCoeffs%acof(ie,lm1,natrun,jsp)*usdus%dus(l1,n,jsp)&
                                 + eigVecCoeffs%bcof(ie,lm1,natrun,jsp)*usdus%duds(l1,n,jsp)&
                                 + eigVecCoeffs%ccof(m,ie,lo,natrun,jsp)*usdus%dulos(lo,n,jsp) ) ) )  
245 246
                         END DO
                      ENDDO
247 248
                   ENDDO
                ENDDO
249 250
             END DO
          ENDIF
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
          !
          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)

277 278
             gvint=MATMUL(cell%bmat,vec)/tpi_const
             gvint2=MATMUL(cell%bmat,vec2)/tpi_const
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
             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
323 324
             starsum=MATMUL(cell%amat,vecsum)
             starsum2=MATMUL(cell%amat,vecsum2)
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
             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
347
             results%force(i,n,jsp) = results%force(i,n,jsp) + REAL(forc_a21(i) + forc_b4(i))
348 349
             force%f_a21(i,n)     = force%f_a21(i,n)     + forc_a21(i)
             force%f_b4(i,n)      = force%f_b4(i,n)      + forc_b4(i)
350 351 352 353 354 355 356
          END DO
          !
          !     write result moved to force_a8
          !
          !         write(*,*) a21(:,n) 
       ENDIF                                            !  IF (atoms%l_geo(n)) ...
       natom = natom + atoms%neq(n)
357
    ENDDO
358
    !
Daniel Wortmann's avatar
Daniel Wortmann committed
359
    DEALLOCATE (tlmplm%tdd,tlmplm%tuu,tlmplm%tdu,tlmplm%tud,tlmplm%tuulo,tlmplm%tdulo,tlmplm%tuloulo,tlmplm%ind,a21,b4)
360 361 362

  END SUBROUTINE force_a21
END MODULE m_forcea21