kptgen_hybrid.f 8.61 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 8
      MODULE m_kptgen_hybrid

9 10
      USE m_juDFT

11 12
      CONTAINS
      
Daniel Wortmann's avatar
Daniel Wortmann committed
13 14
! this programm generates an aequdistant kpoint set including the
! Gamma point; it is reduced to IBZ and written in kpts (M.B.)
15

Daniel Wortmann's avatar
Daniel Wortmann committed
16
      !Modified for types D.W.
17 18


Daniel Wortmann's avatar
Daniel Wortmann committed
19 20
      SUBROUTINE kptgen_hybrid(kpts,invs,l_soc,nop,mrot,tau)
      USE m_types
21 22
      IMPLICIT NONE

Daniel Wortmann's avatar
Daniel Wortmann committed
23
      TYPE(t_kpts),INTENT(INOUT)::kpts
24 25 26 27 28 29 30 31
      ! - scalars -
      INTEGER, INTENT(IN)   ::  nop
      LOGICAL, INTENT(IN)   ::  invs
      LOGICAL, INTENT(IN)   ::  l_soc
      ! - local arrays -
      INTEGER, INTENT(IN)   ::  mrot(3,3,nop)
      REAL   , INTENT(IN)   ::  tau(3,nop)
      ! - local scalars -
Daniel Wortmann's avatar
Daniel Wortmann committed
32 33 34
      INTEGER               ::  i,j,k,nkpt
      INTEGER               ::  ikpt,ikpt0,nkpti
      INTEGER               ::  nsym
35 36 37 38 39 40 41 42 43
      ! - local arrays -
      INTEGER,ALLOCATABLE   ::  rot(:,:,:),rrot(:,:,:)
      INTEGER,ALLOCATABLE   ::  invtab(:)
      INTEGER,ALLOCATABLE   ::  neqkpt(:)
      INTEGER,ALLOCATABLE   ::  pkpt(:,:,:),kptp(:),symkpt(:),iarr(:),
     &                          iarr2(:)
      REAL,ALLOCATABLE      ::  rtau(:,:)
      REAL,ALLOCATABLE      ::  bk(:,:),bkhlp(:,:)
      REAL,ALLOCATABLE      ::  rarr(:)
Daniel Wortmann's avatar
Daniel Wortmann committed
44
      LOGICAL               ::  ldum
45

Daniel Wortmann's avatar
Daniel Wortmann committed
46
      nkpt=kpts%nkpt3(1)*kpts%nkpt3(2)*kpts%nkpt3(3)
47 48 49
      ALLOCATE( bk(3,nkpt),bkhlp(3,nkpt) )

      ikpt = 0
Daniel Wortmann's avatar
Daniel Wortmann committed
50 51 52
      DO i=0,kpts%nkpt3(1)-1
        DO j=0,kpts%nkpt3(2)-1
          DO k=0,kpts%nkpt3(3)-1
53
            ikpt       = ikpt + 1
Daniel Wortmann's avatar
Daniel Wortmann committed
54 55
            bk(:,ikpt) = (/ 1.0*i/kpts%nkpt3(1),1.0*j/kpts%nkpt3(2),
     &                                     1.0*k/kpts%nkpt3(3) /)
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
          END DO
        END DO
      END DO
      
      IF( ikpt .ne. nkpt) STOP 'failure: number of k-points'

      IF( invs .or. l_soc ) THEN
        nsym = nop
      ELSE
        nsym = 2*nop
      END IF
      
      ALLOCATE( rot(3,3,nsym),rtau(3,nsym) )

      DO i=1,nop
         rot(:,:,i) = mrot(:,:,i)
        rtau(  :,i) = tau(:,i)
      END DO

      DO i = nop+1,nsym
         rot(:,:,i) =  rot(:,:,i-nop)
        rtau(  :,i)   = rtau(  :,i-nop)
      END DO

      IF(any(rot(:,:,1)-reshape((/1,0,0,0,1,0,0,0,1/),(/3,3/)).ne.0))
     &  STOP 'kptgen: First symmetry operation is not the identity.'

      ALLOCATE( rrot(3,3,nsym),invtab(nsym) )    

      invtab = 0

      DO i = 1,nop
        DO j = 1,nop

          IF(    all(    matmul(rot(:,:,i),rot(:,:,j))
     &               .eq.reshape((/1,0,0,0,1,0,0,0,1/),(/3,3/)))
     &     .and.all(modulo(matmul(rot(:,:,i),rtau(:,j))+rtau(:,i),1.0)
     &               .lt.1d-10)                                  )THEN
            IF(invtab(i).ne.0) STOP 'kptgen: inverse operation
     &                              & already defined.'
            invtab(i)   = j
            rrot(:,:,i) = transpose_int ( rot(:,:,j) ) ! temporary fix for ifc
          END IF
        END DO
        IF(invtab(i).eq.0) STOP 'kptgen: inverse operation not found.'
        
      END DO


      DO i = nop+1,nsym
         rrot(:,:,i) = - rrot(:,:,i-nop)
      END DO

      ALLOCATE ( kptp(nkpt),symkpt(nkpt),rarr(3),iarr2(3),iarr(nkpt) )
Daniel Wortmann's avatar
Daniel Wortmann committed
110
      ALLOCATE ( pkpt(kpts%nkpt3(1)+1,kpts%nkpt3(2)+1,kpts%nkpt3(3)+1) )
111 112
      pkpt = 0
      DO ikpt = 1,nkpt
Daniel Wortmann's avatar
Daniel Wortmann committed
113
        iarr2 = nint ( bk(:,ikpt) * kpts%nkpt3 ) + 1
114 115 116
        pkpt(iarr2(1),iarr2(2),iarr2(3)) = ikpt
      END DO

Daniel Wortmann's avatar
Daniel Wortmann committed
117 118 119
      pkpt(kpts%nkpt3(1)+1,    :     ,    :     ) = pkpt(1,:,:)
      pkpt(    :     ,kpts%nkpt3(2)+1,    :     ) = pkpt(:,1,:)
      pkpt(    :     ,    :     ,kpts%nkpt3(3)+1) = pkpt(:,:,1)
120
      
121 122 123 124
      IF(any(pkpt.eq.0)) THEN
         CALL juDFT_error('kptgen: Definition of pkpt-pointer failed.',
     &                    calledby='kptgen_hybrid')
      END IF
125 126 127 128 129 130 131
      iarr = 1
      ldum = .false.
      DO i = 1,nkpt
        IF(iarr(i).eq.0) CYCLE
        kptp(i)   = i
        symkpt(i) = 1
        DO k = 2,nsym
Daniel Wortmann's avatar
Daniel Wortmann committed
132
          rarr  = matmul(rrot(:,:,k),bk(:,i)) * kpts%nkpt3
133 134 135 136 137 138
          iarr2 = nint(rarr)
          IF(any(abs(iarr2-rarr).gt.1d-10)) THEN
            WRITE(6,'(A,I3,A)') 'kptgen: Symmetry operation',k,
     &                        ' incompatible with k-point set.'
            ldum = .true.
          END IF
Daniel Wortmann's avatar
Daniel Wortmann committed
139 140
          iarr2 = modulo(iarr2,kpts%nkpt3) + 1
          IF(any(iarr2.gt.kpts%nkpt3)) 
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
     &    STOP 'kptgen: pointer indices exceed pointer dimensions.'
          j     = pkpt(iarr2(1),iarr2(2),iarr2(3))
          IF(j.eq.0) STOP 'kptgen: k-point index is zero (bug?)'
          IF(iarr(j).eq.0.or.j.eq.i) CYCLE
          iarr(j)   = 0
          kptp(j)   = i
          symkpt(j) = k
        END DO
      END DO
      IF(ldum) 
     &STOP 'kptgen: Some symmetry operations are incompatible
     & with k-point set.'
      i = 0
      DO ikpt = 1,nkpt
        IF(iarr(ikpt).eq.1) THEN
          i          = i + 1
          iarr(ikpt) = i
        END IF
      END DO
      nkpti = i
      DO ikpt = 1,nkpt
        IF(iarr(ikpt).eq.0) THEN
          i          = i + 1
          iarr(ikpt) = i
        END IF
      END DO
      bk(:,iarr)   = bk
      kptp         = iarr(kptp)
      kptp(iarr)   = kptp
      symkpt(iarr) = symkpt
Daniel Wortmann's avatar
Daniel Wortmann committed
171 172 173
      DO i=1,kpts%nkpt3(1)+1 
        DO j=1,kpts%nkpt3(2)+1
          DO k=1,kpts%nkpt3(3)+1 
174 175 176 177
            pkpt(i,j,k) = iarr(pkpt(i,j,k))
          END DO
        END DO
      END DO
Daniel Wortmann's avatar
Daniel Wortmann committed
178
   
179 180 181 182 183 184 185 186
      ALLOCATE( neqkpt(nkpti) )
      neqkpt = 0
      DO ikpt0 = 1,nkpti
        DO ikpt = 1,nkpt
          IF( kptp(ikpt) .eq. ikpt0 ) neqkpt(ikpt0) = neqkpt(ikpt0) + 1
        END DO
      END DO

Daniel Wortmann's avatar
Daniel Wortmann committed
187 188 189 190 191
!     Do not do any IO, but store in kpts
      kpts%nkpt=nkpti
      if (allocated(kpts%bk)) deallocate(kpts%bk)
      if (allocated(kpts%wtkpt)) deallocate(kpts%wtkpt)
      ALLOCATE(kpts%bk(3,kpts%nkpt),kpts%wtkpt(kpts%nkpt))
192

Daniel Wortmann's avatar
Daniel Wortmann committed
193
      
194
      DO ikpt=1,nkpti
Daniel Wortmann's avatar
Daniel Wortmann committed
195 196
         kpts%bk(:,ikpt)=bk(:,ikpt)
         kpts%wtkpt(ikpt)=neqkpt(ikpt)
197
      END DO
Daniel Wortmann's avatar
Daniel Wortmann committed
198 199
      kpts%posScale=1.0
      
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 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 277 278 279 280 281 282 283
      CONTAINS

      ! Returns least common multiple of the integers iarr(1:n).
      FUNCTION kgv(iarr,n)
      IMPLICIT NONE
      INTEGER              :: kgv
      INTEGER, INTENT(IN)  :: n,iarr(n)
      LOGICAL              :: lprim(2:maxval(iarr))
      INTEGER, ALLOCATABLE :: prim(:),expo(:)
      INTEGER              :: nprim,marr
      INTEGER              :: i,j,ia,k
      ! Determine prime numbers
      marr  = maxval(iarr)
      lprim = .true.
      DO i = 2,marr
        j = 2
        DO WHILE (i*j.le.marr)
          lprim(i*j) = .false.
          j          = j + 1
        END DO
      END DO
      nprim = count(lprim)
      ALLOCATE ( prim(nprim),expo(nprim) )
      j = 0
      DO i = 2,marr
        IF(lprim(i)) THEN
          j       = j + 1
          prim(j) = i
        END IF
      END DO
      ! Determine least common multiple
      expo = 0
      DO i = 1,n
        ia = iarr(i)
        IF(ia.eq.0) CYCLE
        DO j = 1,nprim
          k = 0
          DO WHILE(ia/prim(j)*prim(j).eq.ia)
            k  = k + 1
            ia = ia / prim(j)
          END DO
          expo(j) = max(expo(j),k)
        END DO
      END DO
      kgv = 1
      DO j = 1,nprim
        kgv = kgv * prim(j)**expo(j)
      END DO
      DEALLOCATE ( prim,expo )
      END FUNCTION kgv
      

c     ifc seems to have problems transposing integer arrays. this is a fix.
      FUNCTION transpose_int ( a )
      IMPLICIT NONE
      integer transpose_int(3,3),a(3,3)
      integer i,j
      DO i = 1,3
        DO j = 1,3
          transpose_int(i,j) = a(j,i)
        END DO
      END DO
      END FUNCTION transpose_int

c     function modulo1 maps kpoint into first BZ
      FUNCTION modulo1(kpoint,nkpt,a,b,c)

      IMPLICIT NONE

      INTEGER,INTENT(IN)  :: nkpt,a,b,c
      REAL, INTENT(IN)    :: kpoint(3)
      REAL                :: modulo1(3)
      INTEGER             :: help(3),nkpt3(3)

      nkpt3 = (/a,b,c/)
      modulo1 = kpoint*nkpt3
      help    = nint(modulo1)
      IF(any(abs(help-modulo1).gt.1d-8)) THEN
        modulo1 = kpoint*nkpt3
        WRITE(*,*) modulo1
        help    = nint(modulo1)
        WRITE(*,*) help
        WRITE(6,'(A,F5.3,2('','',F5.3),A)') 'modulo1: argument (',
     &           kpoint,') is not an element of the k-point set.'
284 285 286
        CALL juDFT_error(
     +     'modulo1: argument not an element of k-point set.', 
     +     calledby = 'kptgen_hybrid:modulo1')
287 288 289 290 291 292 293 294
      END IF
      modulo1 = modulo(help,nkpt3)*1d0/nkpt3

      END FUNCTION modulo1

      END SUBROUTINE kptgen_hybrid
      
      END MODULE m_kptgen_hybrid