od_hsvac.F90 13.1 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,jij,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 34
    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_jij),INTENT(IN)        :: jij
    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
35 36 37 38 39 40 41 42 43
    !     ..
    !     .. 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)
44
    INTEGER, INTENT (OUT):: nv2(DIMENSION%jspd)
45
    REAL,    INTENT (INOUT) :: vz(vacuum%nmzd,2,4)
46
    REAL,    INTENT (IN) :: evac(2,DIMENSION%jspd)
47 48
    REAL,    INTENT (IN) :: bkpt(3)

49
    LOGICAL, INTENT(IN)  :: l_real
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
    !     ..
    !     .. 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(:,:,:)
    ! l_J auxiliary potential array
    COMPLEX, ALLOCATABLE :: vxy1(:,:,:)
    !     ..
76 77
    ic  = CMPLX(0.,1.)
    d2 = SQRT(cell%omtil/cell%area)
78 79 80 81

    IF (jij%l_J) ALLOCATE (vxy1(vacuum%nmzxyd,n2d_1-1,2))

    ALLOCATE (&
82
         ai(-vM:vM,DIMENSION%nv2d,DIMENSION%nvd),bi(-vM:vM,DIMENSION%nv2d,DIMENSION%nvd),&
83
         nvp(DIMENSION%nv2d,DIMENSION%jspd),ind(stars%ng2,DIMENSION%nv2d,DIMENSION%jspd),&
84 85 86 87 88 89
         kvac3(DIMENSION%nv2d,DIMENSION%jspd),map1(DIMENSION%nvd,DIMENSION%jspd),&
         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),&
         a(-vM:vM,DIMENSION%nvd,DIMENSION%jspd),b(-vM:vM,DIMENSION%nvd,DIMENSION%jspd),&
90
         bess(-vM:vM),dbss(-vM:vM),bess1(-vM:vM),&
91 92 93
         ddnv(-vM:vM,DIMENSION%nv2d,DIMENSION%jspd),dudz(-vM:vM,DIMENSION%nv2d,DIMENSION%jspd),&
         duz(-vM:vM,DIMENSION%nv2d,DIMENSION%jspd),&
         udz(-vM:vM,DIMENSION%nv2d,DIMENSION%jspd),uz(-vM:vM,DIMENSION%nv2d,DIMENSION%jspd) )
94 95 96 97 98 99 100 101 102 103 104 105 106

    !--->     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
107
          ENDDO
108
          nv2(jspin) = nv2(jspin) + 1
109
          IF (nv2(jspin)>DIMENSION%nv2d)  CALL juDFT_error("dimension%nv2d",calledby ="od_hsvac")
110 111
          kvac3(nv2(jspin),jspin) = lapw%k3(k,jspin)
          map1(k,jspin) = nv2(jspin)
112
       END DO k_loop
113

114
       DO ik = 1,DIMENSION%nv2d
115
          nvp(ik,jspin) = 0
116
          DO i = 1,stars%ng2
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
             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
       !--->         for J-coeff. we average the up-up and down-down parts
       !--->         and off-diagonal elements of the potential matrix to zero
       IF (jij%l_J) THEN
          vz(:,ivac,1) = (vz(:,ivac,1) + vz(:,ivac,2))/2.
          vz(:,ivac,2) =  vz(:,ivac,1)
          vz(:,ivac,3) = 0.0
          vz(:,ivac,4) = 0.0
       END IF
    ENDIF

    DO ipot = 1,npot

       IF (noco%l_noco) THEN
          IF (.NOT.jij%l_J) THEN
             READ (25)((vxy(imz,k,ivac), imz=1,vacuum%nmzxy),k=1,n2d_1-1)
          END IF
          !--->  l_J we want to average the diagonal elements of the pot. matrix
          IF (jij%l_J .AND. ipot.EQ.1) THEN
             READ (25)((vxy(imz,k,ivac), imz=1,vacuum%nmzxy),k=1,n2d_1-1)
             READ (25)((vxy1(imz,k,ivac), imz=1,vacuum%nmzxy),k=1,n2d_1-1)
             vxy(:,:,ivac) = (vxy(:,:,ivac)+vxy1(:,:,ivac))/2.
          END IF

          IF (jij%l_J .AND. ipot.EQ.3) THEN
             READ (25)((vxy(imz,k,ivac), imz=1,vacuum%nmzxy),k=1,n2d_1-1)
          END IF

163
          IF (jij%l_J .AND. ipot.EQ.3) vxy(:,:,ivac)=CMPLX(0.,0.)
164 165 166 167 168 169

       ENDIF ! loco

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

       CALL od_vacfun(&
170
            m_cyl,cell,vacuum,DIMENSION,stars,&
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
            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)
190 191 192 193
                      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)
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
                   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) 
214 215
                   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)
216

217 218
                   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)
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235

                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
236
             i_start = MOD(MOD(n_rank - (lapw%nv(1)+atoms%nlotot),n_size) + n_size,n_size)
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
          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
258 259
                      sij = sij + CONJG(a(m,i,jspin))*a(m,j,jspin) &
                           +CONJG(b(m,i,jspin))*b(m,j,jspin) *ddnv(m,ik,jspin1)
260
                   END DO
261
                   IF (l_real) THEN 
262
                      hamOvlp%b_r(ii) = hamOvlp%b_r(ii) + REAL(sij)
263
                   ELSE
264
                      hamOvlp%b_c(ii) = hamOvlp%b_c(ii) + sij
265
                   ENDIF
266 267 268 269 270
                END IF
             ENDDO
             ii = ii0 + i
             sij = (0.0,0.0)
             DO m = -vM,vM
271 272
                sij = sij + CONJG(a(m,i,jspin))*a(m,i,jspin)+ &
                     CONJG(b(m,i,jspin))*b(m,i,jspin)*ddnv(m,ik,jspin1)
273 274
             END DO

275
             IF (l_real) THEN
276
                hamOvlp%b_r(ii) = hamOvlp%b_r(ii) + REAL(sij)
277
             ELSE 
278
                hamOvlp%b_c(ii) = hamOvlp%b_c(ii) + sij
279 280
             ENDIF
          ENDDO
281 282 283 284 285 286 287 288 289 290 291 292
       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
293
          i_start = MOD(MOD(n_rank - (lapw%nv(1)+atoms%nlotot),n_size) + n_size,n_size)
294 295 296 297
       ELSEIF (ipot.EQ.3) THEN
          jspin1 = 2
          jspin2 = 1
          nc = nc_0
298
          i_start = MOD(MOD(n_rank - (lapw%nv(1)+atoms%nlotot),n_size) + n_size,n_size)
299 300
       ENDIF

301 302
       ai(:,:,:) = CMPLX(0.,0.)
       bi(:,:,:) = CMPLX(0.,0.)
303 304 305 306 307 308 309 310 311 312 313 314

       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) +&
315
                                 CONJG(a(m,i,jspin1))*tuuv(m,l,ik,jk) + CONJG(b(m,i,jspin1))*tduv(m,l,ik,jk)
316
                            bi(l,jk,i) = bi(l,jk,i) +&
317
                                 CONJG(a(m,i,jspin1))*tudv(m,l,ik,jk) + CONJG(b(m,i,jspin1))*tddv(m,l,ik,jk)
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

                         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)
343
             hij = CMPLX(0.,0.)
344 345 346
             DO l = -vM,vM
                hij = hij + ai(l,jk,i)*a(l,j,jspin2) + bi(l,jk,i)*b(l,j,jspin2)
             END DO
347
             IF (l_real) THEN
348
                hamOvlp%a_r(ii) = hamOvlp%a_r(ii) + REAL(hij)
349
             ELSE 
350
                hamOvlp%a_c(ii) = hamOvlp%a_c(ii) + hij
351
             ENDIF
352 353 354 355 356 357 358 359 360 361 362 363
          END DO
       END DO

    ENDDO !ipot

    IF (jij%l_J) DEALLOCATE (vxy1)

    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