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

    ! ************************************************************
    ! 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
27 28 29 30 31
    USE m_types_setup
    USE m_types_misc
    USE m_types_usdus
    USE m_types_tlmplm
    USE m_types_cdnval
32
    USE m_constants
33
    USE m_juDFT
34
    IMPLICIT NONE
35 36 37 38 39 40 41 42 43
    TYPE(t_input),INTENT(IN)        :: input
    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
44 45 46 47 48
    !     ..
    !     .. Scalar Arguments ..
    INTEGER, INTENT (IN) :: ne,jsp
    !     ..
    !     .. Array Arguments ..
49 50 51 52 53 54 55
    REAL,    INTENT(IN)    :: we(ne),epar(0:atoms%lmaxd,atoms%ntype)
    REAL,    INTENT(IN)    :: eig(DIMENSION%neigd)
    COMPLEX, INTENT(IN)    :: aveccof(3,ne,0:atoms%lmaxd*(atoms%lmaxd+2),atoms%nat)
    COMPLEX, INTENT(IN)    :: bveccof(3,ne,0:atoms%lmaxd*(atoms%lmaxd+2),atoms%nat)
    COMPLEX, INTENT(IN)    :: cveccof(3,-atoms%llod:atoms%llod,ne,atoms%nlod,atoms%nat)
    COMPLEX, INTENT(INOUT) :: f_a21(3,atoms%ntype)
    COMPLEX, INTENT(INOUT) :: f_b4(3,atoms%ntype)
56 57 58
    !     ..
    !     .. Local Scalars ..
    COMPLEX dtd,dtu,utd,utu
59
    INTEGER lo, mlotot, mlolotot, mlot_d, mlolot_d
Daniel Wortmann's avatar
Daniel Wortmann committed
60
    INTEGER i,ie,im,in,l1,l2,ll1,ll2,lm1,lm2,m1,m2,n,natom,m,i_u
61 62
    INTEGER natrun,is,isinv,j,irinv,it
    REAL   ,PARAMETER:: zero=0.0
63
    COMPLEX,PARAMETER:: czero=CMPLX(0.,0.)
64 65
    !     ..
    !     .. Local Arrays ..
Daniel Wortmann's avatar
Daniel Wortmann committed
66
    COMPLEX, ALLOCATABLE :: v_mmp(:,:,:)
67 68 69 70 71 72
    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
73 74 75

    CALL timestart("force_a21")

76
    !dimension%lmplmd = (dimension%lmd* (dimension%lmd+3))/2
77 78 79 80 81
    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
82 83 84 85 86 87
    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),&
88
         tlmplm%tuloulo(-atoms%llod:atoms%llod,-atoms%llod:atoms%llod,mlolot_d,1),&
89
         a21(3,atoms%nat),b4(3,atoms%nat),tlmplm%ind(0:DIMENSION%lmd,0:DIMENSION%lmd,atoms%ntype,1) )
90
    !
Daniel Wortmann's avatar
Daniel Wortmann committed
91
    IF(atoms%n_u.GT.0) THEN
92
       ALLOCATE(v_mmp(-lmaxU_const:lmaxU_const,-lmaxU_const:lmaxU_const,atoms%n_u))
Daniel Wortmann's avatar
Daniel Wortmann committed
93 94 95 96 97
       v_mmp = CMPLX(0.0,0.0)
       CALL read_tlmplm_vs_mmp(jsp,atoms%n_u,v_mmp)
    END IF

    i_u = 1
98 99 100 101 102 103 104
    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
105
          CALL read_tlmplm(n,jsp,atoms%nlo,&
106
               tlmplm%tuu(:,n,1),tlmplm%tud(:,n,1),tlmplm%tdu(:,n,1),tlmplm%tdd(:,n,1),&
Daniel Wortmann's avatar
Daniel Wortmann committed
107
               tlmplm%ind(:,:,n,1),tlmplm%tuulo(:,:,:,1),tlmplm%tuloulo(:,:,:,1),tlmplm%tdulo(:,:,:,1))
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

          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
148 149 150 151
                                  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))
152 153 154
                               END IF
                               DO i = 1,3
                                  a21(i,natrun) = a21(i,natrun) + 2.0*&
155 156 157 158
                                       AIMAG( CONJG(eigVecCoeffs%acof(ie,lm1,natrun,jsp)) *utu*aveccof(i,ie,lm2,natrun)&
                                       +CONJG(eigVecCoeffs%acof(ie,lm1,natrun,jsp)) *utd*bveccof(i,ie,lm2,natrun)&
                                       +CONJG(eigVecCoeffs%bcof(ie,lm1,natrun,jsp)) *dtu*aveccof(i,ie,lm2,natrun)&
                                       +CONJG(eigVecCoeffs%bcof(ie,lm1,natrun,jsp)) *dtd*bveccof(i,ie,lm2,natrun))*we(ie)/atoms%neq(n)
159 160 161 162 163 164 165 166 167 168 169
                                  !   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
170 171 172 173 174 175 176 177 178 179 180 181
                   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
182 183 184
                   DO i = 1,3
                      DO natrun = natom,natom + atoms%neq(n) - 1
                         a21(i,natrun) = a21(i,natrun) + 2.0*&
185 186 187 188
                              AIMAG(CONJG(eigVecCoeffs%acof(ie,lm1,natrun,jsp)) *utu*aveccof(i,ie,lm1,natrun)&
                              +CONJG(eigVecCoeffs%acof(ie,lm1,natrun,jsp)) *utd*bveccof(i,ie,lm1,natrun)&
                              +CONJG(eigVecCoeffs%bcof(ie,lm1,natrun,jsp)) *dtu*aveccof(i,ie,lm1,natrun)&
                              +CONJG(eigVecCoeffs%bcof(ie,lm1,natrun,jsp)) *dtd*bveccof(i,ie,lm1,natrun)&
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
                              )*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
          !
204
          CALL force_a21_lo(atoms,jsp,n,we,eig,ne,eigVecCoeffs,aveccof,bveccof,cveccof,tlmplm,usdus,a21)
205

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

286 287
             gvint=MATMUL(cell%bmat,vec)/tpi_const
             gvint2=MATMUL(cell%bmat,vec2)/tpi_const
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
             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
332 333
             starsum=MATMUL(cell%amat,vecsum)
             starsum2=MATMUL(cell%amat,vecsum2)
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
             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
356
             results%force(i,n,jsp) = results%force(i,n,jsp) + REAL(forc_a21(i) + forc_b4(i))
357 358
             f_a21(i,n)     = f_a21(i,n)     + forc_a21(i)
             f_b4(i,n)      = f_b4(i,n)      + forc_b4(i)
359 360 361 362 363 364 365
          END DO
          !
          !     write result moved to force_a8
          !
          !         write(*,*) a21(:,n) 
       ENDIF                                            !  IF (atoms%l_geo(n)) ...
       natom = natom + atoms%neq(n)
366
    ENDDO
367 368

    CALL timestop("force_a21")
369 370 371

  END SUBROUTINE force_a21
END MODULE m_forcea21