od_hsvac.F90 12 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
MODULE m_od_hsvac
8
  USE m_juDFT
9 10
CONTAINS
  SUBROUTINE od_hsvac(&
11
       vacuum,stars,DIMENSION, oneD,atoms, jsp,input,vxy,vz,evac,cell,&
12
       bkpt,lapw, MM,vM,m_cyl,n2d_1, n_size,n_rank,sym,noco,nv2,l_real,hamOvlp)
13 14 15 16 17 18 19 20 21 22

    !     subroutine for calculating the hamiltonian and overlap matrices in
    !     the vacuum in the case of 1-dimensional calculations
    !     Y. Mokrousov June 2002             

    USE m_cylbes
    USE m_dcylbs
    USE m_od_vacfun
    USE m_types
    IMPLICIT NONE
23 24 25 26 27 28 29 30 31 32 33
    TYPE(t_dimension),INTENT(IN)  :: DIMENSION
    TYPE(t_oneD),INTENT(IN)       :: oneD
    TYPE(t_input),INTENT(IN)      :: input
    TYPE(t_vacuum),INTENT(IN)     :: vacuum
    TYPE(t_noco),INTENT(IN)       :: noco
    TYPE(t_sym),INTENT(IN)        :: sym
    TYPE(t_stars),INTENT(IN)      :: stars
    TYPE(t_cell),INTENT(IN)       :: cell
    TYPE(t_atoms),INTENT(IN)      :: atoms
    TYPE(t_lapw),INTENT(IN)       :: lapw
    TYPE(t_hamOvlp),INTENT(INOUT) :: hamOvlp
34 35 36 37 38 39 40 41 42
    !     ..
    !     .. Scalar Arguments ..
    INTEGER, INTENT (IN) :: vM
    INTEGER, INTENT (IN) :: MM 
    INTEGER, INTENT (IN) :: jsp ,n_size,n_rank,n2d_1 
    INTEGER, INTENT (IN) :: m_cyl
    !     ..
    !     .. Array Arguments ..
    COMPLEX, INTENT (INOUT) :: vxy(vacuum%nmzxyd,n2d_1-1,2)
43
    INTEGER, INTENT (OUT):: nv2(input%jspins)
44
    REAL,    INTENT (INOUT) :: vz(vacuum%nmzd,2,4)
45
    REAL,    INTENT (IN) :: evac(2,input%jspins)
46 47
    REAL,    INTENT (IN) :: bkpt(3)

48
    LOGICAL, INTENT(IN)  :: l_real
49

50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
    !     ..
    !     .. Local Scalars ..
    COMPLEX hij,sij,apw_lo,exp1,exp2,exp3,am,bm,ic
    REAL    d2,wronk,gr,gphi,qq,x,y
    INTEGER i,i2,ii,ik,j,jk,k,jspin,ipot,npot,ii0 ,l,i3,imz,m
    INTEGER jspin1,jspin2,jmax,irec2,irec3,ivac,ind1,gi
    INTEGER i_start,nc,nc_0,rotax,chiral,zi,m1,z,indm,indl
    !     ..
    !     .. Local Arrays ..

    INTEGER, ALLOCATABLE :: nvp(:,:),ind(:,:,:)
    INTEGER, ALLOCATABLE :: kvac3(:,:),map1(:,:)
    COMPLEX, ALLOCATABLE :: tddv(:,:,:,:)
    COMPLEX, ALLOCATABLE :: tduv(:,:,:,:)
    COMPLEX, ALLOCATABLE :: tudv(:,:,:,:)
    COMPLEX, ALLOCATABLE :: tuuv(:,:,:,:)
    COMPLEX, ALLOCATABLE ::  a(:,:,:),b(:,:,:)
    COMPLEX, ALLOCATABLE :: ai(:,:,:),bi(:,:,:)
    REAL, ALLOCATABLE :: bess(:),dbss(:),bess1(:)
    REAL, ALLOCATABLE :: ddnv(:,:,:),dudz(:,:,:)
    REAL, ALLOCATABLE :: duz(:,:,:)
    REAL, ALLOCATABLE :: udz(:,:,:),uz(:,:,:)
    !     ..
73 74
    ic  = CMPLX(0.,1.)
    d2 = SQRT(cell%omtil/cell%area)
75

76
 
77
    ALLOCATE (&
78
         ai(-vM:vM,DIMENSION%nv2d,DIMENSION%nvd),bi(-vM:vM,DIMENSION%nv2d,DIMENSION%nvd),&
79 80
         nvp(DIMENSION%nv2d,input%jspins),ind(stars%ng2,DIMENSION%nv2d,input%jspins),&
         kvac3(DIMENSION%nv2d,input%jspins),map1(DIMENSION%nvd,input%jspins),&
81 82 83 84
         tddv(-vM:vM,-vM:vM,DIMENSION%nv2d,DIMENSION%nv2d),&
         tduv(-vM:vM,-vM:vM,DIMENSION%nv2d,DIMENSION%nv2d),&
         tudv(-vM:vM,-vM:vM,DIMENSION%nv2d,DIMENSION%nv2d),&
         tuuv(-vM:vM,-vM:vM,DIMENSION%nv2d,DIMENSION%nv2d),&
85
         a(-vM:vM,DIMENSION%nvd,input%jspins),b(-vM:vM,DIMENSION%nvd,input%jspins),&
86
         bess(-vM:vM),dbss(-vM:vM),bess1(-vM:vM),&
87 88 89
         ddnv(-vM:vM,DIMENSION%nv2d,input%jspins),dudz(-vM:vM,DIMENSION%nv2d,input%jspins),&
         duz(-vM:vM,DIMENSION%nv2d,input%jspins),&
         udz(-vM:vM,DIMENSION%nv2d,input%jspins),uz(-vM:vM,DIMENSION%nv2d,input%jspins) )
90 91 92 93 94 95 96 97 98 99 100 101 102

    !--->     set up mapping function from 3d-->1d lapws
    !--->            creating arrays ind and nvp

    DO jspin = 1,input%jspins

       nv2(jspin) = 0
       k_loop:DO  k = 1,lapw%nv(jspin)
          DO  j = 1,nv2(jspin)
             IF (lapw%k3(k,jspin).EQ.kvac3(j,jspin)) THEN
                map1(k,jspin) = j
                CYCLE k_loop
             END IF
103
          ENDDO
104
          nv2(jspin) = nv2(jspin) + 1
105
          IF (nv2(jspin)>DIMENSION%nv2d)  CALL juDFT_error("dimension%nv2d",calledby ="od_hsvac")
106 107
          kvac3(nv2(jspin),jspin) = lapw%k3(k,jspin)
          map1(k,jspin) = nv2(jspin)
108
       END DO k_loop
109

110
       DO ik = 1,DIMENSION%nv2d
111
          nvp(ik,jspin) = 0
112
          DO i = 1,stars%ng2
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
             ind(i,ik,jspin) = 0
          END DO
       END DO

       DO k = 1,lapw%nv(jspin)
          ik = map1(k,jspin)
          nvp(ik,jspin) = nvp(ik,jspin) + 1
          ind(nvp(ik,jspin),ik,jspin) = k
       END DO

    ENDDO

    npot = 1      
    ivac = 1

    IF (noco%l_noco) THEN
       !--->         load the non-warping part of the potential
       READ (25)((vz(imz,ivac,ipot),imz=1,vacuum%nmzd),ipot=1,4)
       npot = 3
    ENDIF

    DO ipot = 1,npot

       IF (noco%l_noco) THEN
137
          READ (25)((vxy(imz,k,ivac), imz=1,vacuum%nmzxy),k=1,n2d_1-1)
138 139 140 141 142 143
          !--->  l_J we want to average the diagonal elements of the pot. matrix
       ENDIF ! loco

       !     get the wavefunctions and set up the tuuv, etc matrices

       CALL od_vacfun(&
144
            m_cyl,cell,vacuum,DIMENSION,stars,&
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
            jsp,input,noco,ipot,oneD,n2d_1, ivac,evac(1,1),bkpt,MM,vM,&
            vxy(1,1,ivac),vz,kvac3,nv2, tuuv,tddv,tudv,tduv,uz,duz,udz,dudz,ddnv)

       IF (noco%l_noco) THEN

          DO jspin = 1,input%jspins

             DO k = 1,lapw%nv(jspin)
                irec3 = stars%ig(lapw%k1(k,jspin),lapw%k2(k,jspin),lapw%k3(k,jspin))
                IF (irec3.NE.0) THEN
                   irec2 = stars%ig2(irec3)
                   gr = stars%sk2(irec2)
                   gphi = stars%phi2(irec2)
                   i2 = map1(k,jspin)
                   qq = gr*cell%z1
                   CALL cylbes(vM,qq,bess)
                   CALL dcylbs(vM,qq,bess,dbss)
                   DO m = -vM,vM
                      wronk = uz(m,i2,jspin)*dudz(m,i2,jspin) - udz(m,i2,jspin)*duz(m,i2,jspin)
164 165 166 167
                      a(m,k,jspin)=EXP(-CMPLX(0.0,m*gphi))*(ic**m)*&
                           CMPLX(dudz(m,i2,jspin)*bess(m)- udz(m,i2,jspin)*gr*dbss(m),0.0) /(d2*wronk)
                      b(m,k,jspin)=EXP(-CMPLX(0.0,m*gphi))*(ic**m)*&
                           CMPLX(-duz(m,i2,jspin)*bess(m)+ uz(m,i2,jspin)*gr*dbss(m),0.0) /(d2*wronk)
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
                   END DO
                END IF
             ENDDO

          ENDDO  ! jspin

       ELSE 

          DO k = 1,lapw%nv(jsp)
             irec3 = stars%ig(lapw%k1(k,jsp),lapw%k2(k,jsp),lapw%k3(k,jsp))
             IF (irec3.NE.0) THEN
                irec2 = stars%ig2(irec3)
                gr = stars%sk2(irec2)
                gphi = stars%phi2(irec2)
                i2 = map1(k,jsp)
                qq = gr*cell%z1
                CALL cylbes(vM,qq,bess) 
                CALL dcylbs(vM,qq,bess,dbss)
                DO m = -vM,vM
                   wronk = uz(m,i2,jsp)*dudz(m,i2,jsp) - udz(m,i2,jsp)*duz(m,i2,jsp) 
188 189
                   a(m,k,1)=EXP(-CMPLX(0.0,m*gphi))*(ic**m)*&
                        CMPLX(dudz(m,i2,jsp)*bess(m)- udz(m,i2,jsp)*gr*dbss(m),0.0) /(d2*wronk)
190

191 192
                   b(m,k,1)=EXP(-CMPLX(0.0,m*gphi))*(ic**m)*&
                        CMPLX(-duz(m,i2,jsp)*bess(m)+ uz(m,i2,jsp)*gr*dbss(m),0.0) /(d2*wronk)
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209

                END DO
             END IF
          ENDDO

       ENDIF ! loco
       !     update hamiltonian and overlap matrices

       IF (ipot.EQ.1 .OR. ipot.EQ.2) THEN
          jspin = ipot
          !+gb||
          IF (ipot.EQ.1) THEN
             nc = 0
             i_start = n_rank
          ELSE
             nc = nc + atoms%nlotot
             nc_0 = nc
210
             i_start = MOD(MOD(n_rank - (lapw%nv(1)+atoms%nlotot),n_size) + n_size,n_size)
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
          ENDIF

          DO  i = i_start+1,lapw%nv(jspin),n_size
             ik = map1(i,jspin)
             nc = nc + 1
             IF (ipot.EQ.1) THEN
                jspin = 1
                ii0 = nc*(nc-1)/2*n_size- (nc-1)*(n_size-n_rank-1)
             ELSEIF (ipot.EQ.2) THEN
                jspin = 2
                ii0=nc*(nc-1)/2*n_size-(nc-1)*(n_size-n_rank-1)+&
                     lapw%nv(1)+atoms%nlotot
             ENDIF
             jspin1 = jsp
             IF (noco%l_noco) jspin1 = jspin
             DO j = 1,i - 1
                ii = ii0 + j
                !     overlap: only  (g-g') parallel=0        
                IF (map1(j,jspin).EQ.ik) THEN
                   sij = (0.0,0.0)
                   DO m = -vM,vM
232 233
                      sij = sij + CONJG(a(m,i,jspin))*a(m,j,jspin) &
                           +CONJG(b(m,i,jspin))*b(m,j,jspin) *ddnv(m,ik,jspin1)
234
                   END DO
235
                   IF (l_real) THEN 
236
                      hamOvlp%b_r(ii) = hamOvlp%b_r(ii) + REAL(sij)
237
                   ELSE
238
                      hamOvlp%b_c(ii) = hamOvlp%b_c(ii) + sij
239
                   ENDIF
240 241 242 243 244
                END IF
             ENDDO
             ii = ii0 + i
             sij = (0.0,0.0)
             DO m = -vM,vM
245 246
                sij = sij + CONJG(a(m,i,jspin))*a(m,i,jspin)+ &
                     CONJG(b(m,i,jspin))*b(m,i,jspin)*ddnv(m,ik,jspin1)
247 248
             END DO

249
             IF (l_real) THEN
250
                hamOvlp%b_r(ii) = hamOvlp%b_r(ii) + REAL(sij)
251
             ELSE 
252
                hamOvlp%b_c(ii) = hamOvlp%b_c(ii) + sij
253 254
             ENDIF
          ENDDO
255 256 257 258 259 260 261 262 263 264 265 266
       ENDIF ! ipot.eq.1.or.2
       !   hamiltonian update 
       !   for the noncylindr. contributions we use the cutoff of m_cyl        
       IF (ipot.EQ.1) THEN
          jspin1 = 1
          jspin2 = 1
          nc = 0
          i_start = n_rank
       ELSEIF (ipot.EQ.2) THEN
          jspin1 = 2
          jspin2 = 2
          nc = nc_0
267
          i_start = MOD(MOD(n_rank - (lapw%nv(1)+atoms%nlotot),n_size) + n_size,n_size)
268 269 270 271
       ELSEIF (ipot.EQ.3) THEN
          jspin1 = 2
          jspin2 = 1
          nc = nc_0
272
          i_start = MOD(MOD(n_rank - (lapw%nv(1)+atoms%nlotot),n_size) + n_size,n_size)
273 274
       ENDIF

275 276
       ai(:,:,:) = CMPLX(0.,0.)
       bi(:,:,:) = CMPLX(0.,0.)
277 278 279 280 281 282 283 284 285 286 287 288

       DO ik = 1,nv2(jspin1)
          DO jk = 1,nv2(jspin2)
             i3 = kvac3(ik,jspin1) - kvac3(jk,jspin2) 
             DO l = -vM,vM
                DO m = -vM,vM
                   IF (l.EQ.m .OR. (iabs(m).LE.m_cyl .AND. iabs(l).LE.m_cyl)) THEN
                      ind1 = oneD%ig1(i3,m-l)
                      IF (ind1.NE.0) THEN
                         DO gi = 1,nvp(ik,jspin1)
                            i = ind(gi,ik,jspin1)
                            ai(l,jk,i) = ai(l,jk,i) +&
289
                                 CONJG(a(m,i,jspin1))*tuuv(m,l,ik,jk) + CONJG(b(m,i,jspin1))*tduv(m,l,ik,jk)
290
                            bi(l,jk,i) = bi(l,jk,i) +&
291
                                 CONJG(a(m,i,jspin1))*tudv(m,l,ik,jk) + CONJG(b(m,i,jspin1))*tddv(m,l,ik,jk)
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

                         END DO
                      END IF
                   END IF   ! noncyl. contributions
                END DO
             END DO
          END DO
       END DO

       DO i = i_start+1, lapw%nv(jspin1), n_size
          ik = map1(i,jspin1)
          nc = nc + 1
          IF (ipot.EQ.1) THEN
             ii0 = nc*(nc-1)/2*n_size- (nc-1)*(n_size-n_rank-1)
             jmax = i
          ELSEIF (ipot.EQ.2) THEN
             ii0 = nc*(nc-1)/2*n_size- (nc-1)*(n_size-n_rank-1) + lapw%nv(1)+atoms%nlotot
             jmax = i
          ELSEIF (ipot.EQ.3) THEN
             ii0 = nc*(nc-1)/2*n_size- (nc-1)*(n_size-n_rank-1)
             jmax = lapw%nv(jspin2)
          ENDIF
          DO j = 1,jmax
             ii = ii0 + j
             jk = map1(j,jspin2)
317
             hij = CMPLX(0.,0.)
318 319 320
             DO l = -vM,vM
                hij = hij + ai(l,jk,i)*a(l,j,jspin2) + bi(l,jk,i)*b(l,j,jspin2)
             END DO
321
             IF (l_real) THEN
322
                hamOvlp%a_r(ii) = hamOvlp%a_r(ii) + REAL(hij)
323
             ELSE 
324
                hamOvlp%a_c(ii) = hamOvlp%a_c(ii) + hij
325
             ENDIF
326 327 328 329 330 331 332 333 334 335
          END DO
       END DO

    ENDDO !ipot

    DEALLOCATE (ai,bi,nvp,ind,kvac3,map1, tddv,tduv,tudv,tuuv,a,b,bess,dbss,bess1, ddnv,dudz,duz,udz,uz )

    RETURN
  END SUBROUTINE od_hsvac
END MODULE m_od_hsvac