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, oneD,atoms, jsp,input,vxy,vz,evac,cell,&
12
       bkpt,lapw, MM,vM,m_cyl,n2d_1, n_size,n_rank,sym,noco,nococonv,nv2,l_real,hamOvlp)
13 14 15

    !     subroutine for calculating the hamiltonian and overlap matrices in
    !     the vacuum in the case of 1-dimensional calculations
16
    !     Y. Mokrousov June 2002
17 18 19 20 21 22

    USE m_cylbes
    USE m_dcylbs
    USE m_od_vacfun
    USE m_types
    IMPLICIT NONE
23

24 25 26 27
    TYPE(t_oneD),INTENT(IN)       :: oneD
    TYPE(t_input),INTENT(IN)      :: input
    TYPE(t_vacuum),INTENT(IN)     :: vacuum
    TYPE(t_noco),INTENT(IN)       :: noco
28
    TYPE(t_nococonv),INTENT(IN)   :: nococonv
29 30 31 32 33 34
    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
    !     ..
    !     .. Scalar Arguments ..
    INTEGER, INTENT (IN) :: vM
38 39
    INTEGER, INTENT (IN) :: MM
    INTEGER, INTENT (IN) :: jsp ,n_size,n_rank,n2d_1
40 41 42 43
    INTEGER, INTENT (IN) :: m_cyl
    !     ..
    !     .. Array Arguments ..
    COMPLEX, INTENT (INOUT) :: vxy(vacuum%nmzxyd,n2d_1-1,2)
44
    INTEGER, INTENT (OUT):: nv2(input%jspins)
45
    REAL,    INTENT (INOUT) :: vz(vacuum%nmzd,2,4)
46
    REAL,    INTENT (IN) :: evac(2,input%jspins)
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
    !     ..
    !     .. 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(:,:,:)
    !     ..
74 75
    ic  = CMPLX(0.,1.)
    d2 = SQRT(cell%omtil/cell%area)
76

77

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

    !--->     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
104
          ENDDO
105
          nv2(jspin) = nv2(jspin) + 1
106
          IF (nv2(jspin)>lapw%dim_nv2d())  CALL juDFT_error("lapw%dim_nv2d()",calledby ="od_hsvac")
107 108
          kvac3(nv2(jspin),jspin) = lapw%k3(k,jspin)
          map1(k,jspin) = nv2(jspin)
109
       END DO k_loop
110

111
       DO ik = 1,lapw%dim_nv2d()
112
          nvp(ik,jspin) = 0
113
          DO i = 1,stars%ng2
114 115 116 117 118 119 120 121 122 123 124 125
             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

126
    npot = 1
127 128 129 130 131 132 133 134 135 136 137
    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
138
          READ (25)((vxy(imz,k,ivac), imz=1,vacuum%nmzxy),k=1,n2d_1-1)
139 140 141 142 143 144
          !--->  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(&
145
            m_cyl,cell,vacuum,stars,&
146
            jsp,input,noco,nococonv,ipot,oneD,n2d_1, ivac,evac(1,1),bkpt,MM,vM,&
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
            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)
165 166 167 168
                      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)
169 170 171 172 173 174
                   END DO
                END IF
             ENDDO

          ENDDO  ! jspin

175
       ELSE
176 177 178 179 180 181 182 183 184

          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
185
                CALL cylbes(vM,qq,bess)
186 187
                CALL dcylbs(vM,qq,bess,dbss)
                DO m = -vM,vM
188
                   wronk = uz(m,i2,jsp)*dudz(m,i2,jsp) - udz(m,i2,jsp)*duz(m,i2,jsp)
189 190
                   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)
191

192 193
                   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)
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210

                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
211
             i_start = MOD(MOD(n_rank - (lapw%nv(1)+atoms%nlotot),n_size) + n_size,n_size)
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
          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
229
                !     overlap: only  (g-g') parallel=0
230 231 232
                IF (map1(j,jspin).EQ.ik) THEN
                   sij = (0.0,0.0)
                   DO m = -vM,vM
233 234
                      sij = sij + CONJG(a(m,i,jspin))*a(m,j,jspin) &
                           +CONJG(b(m,i,jspin))*b(m,j,jspin) *ddnv(m,ik,jspin1)
235
                   END DO
236
                   IF (l_real) THEN
237
                      hamOvlp%b_r(ii) = hamOvlp%b_r(ii) + REAL(sij)
238
                   ELSE
239
                      hamOvlp%b_c(ii) = hamOvlp%b_c(ii) + sij
240
                   ENDIF
241 242 243 244 245
                END IF
             ENDDO
             ii = ii0 + i
             sij = (0.0,0.0)
             DO m = -vM,vM
246 247
                sij = sij + CONJG(a(m,i,jspin))*a(m,i,jspin)+ &
                     CONJG(b(m,i,jspin))*b(m,i,jspin)*ddnv(m,ik,jspin1)
248 249
             END DO

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

276 277
       ai(:,:,:) = CMPLX(0.,0.)
       bi(:,:,:) = CMPLX(0.,0.)
278 279 280

       DO ik = 1,nv2(jspin1)
          DO jk = 1,nv2(jspin2)
281
             i3 = kvac3(ik,jspin1) - kvac3(jk,jspin2)
282 283 284 285 286 287 288 289
             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) +&
290
                                 CONJG(a(m,i,jspin1))*tuuv(m,l,ik,jk) + CONJG(b(m,i,jspin1))*tduv(m,l,ik,jk)
291
                            bi(l,jk,i) = bi(l,jk,i) +&
292
                                 CONJG(a(m,i,jspin1))*tudv(m,l,ik,jk) + CONJG(b(m,i,jspin1))*tddv(m,l,ik,jk)
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

                         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)
318
             hij = CMPLX(0.,0.)
319 320 321
             DO l = -vM,vM
                hij = hij + ai(l,jk,i)*a(l,j,jspin2) + bi(l,jk,i)*b(l,j,jspin2)
             END DO
322
             IF (l_real) THEN
323
                hamOvlp%a_r(ii) = hamOvlp%a_r(ii) + REAL(hij)
324
             ELSE
325
                hamOvlp%a_c(ii) = hamOvlp%a_c(ii) + hij
326
             ENDIF
327 328 329 330 331 332 333 334 335 336
          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