julia.f90 15.9 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 9 10 11
      MODULE m_julia
      use m_juDFT
      CONTAINS
      SUBROUTINE julia(&
     &                 sym,cell,input,noco,banddos,&
12
     &                 kpts,l_q,l_fillArrays)
13 14 15 16 17 18 19 20 21 22 23
!----------------------------------------------------------------------+
! Generate a k-point file with approx. nkpt k-pts or a Monkhorst-Pack  |
! set with nmod(i) divisions in i=x,y,z direction. Interface to kptmop |
! and kpttet routines of the MD-programm.                              |
!                                                          G.B. 07/01  |
!----------------------------------------------------------------------+

      USE m_constants
      USE m_bravais
      USE m_divi
      USE m_brzone
24
      USE m_brzone2
25 26 27 28 29
      USE m_kptmop
      USE m_kpttet
      USE m_bandstr1
      use m_types
      IMPLICIT NONE
Daniel Wortmann's avatar
Daniel Wortmann committed
30
      TYPE(t_sym),INTENT(IN)      :: sym
31
      TYPE(t_cell),INTENT(IN)     :: cell
Daniel Wortmann's avatar
Daniel Wortmann committed
32
      TYPE(t_input),INTENT(IN)    :: input
33 34 35 36
      TYPE(t_noco),INTENT(IN)     :: noco
      TYPE(t_banddos),INTENT(IN)  :: banddos
      TYPE(t_kpts),INTENT(INOUT)  :: kpts

37
      LOGICAL, INTENT (IN) :: l_q, l_fillArrays
38 39 40 41 42 43 44 45 46 47 48 49 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 76 77 78 79 80
   
      INTEGER, PARAMETER :: nop48  = 48
      INTEGER, PARAMETER :: mface  = 51
      INTEGER, PARAMETER :: mdir   = 10
      INTEGER, PARAMETER :: nbsz   =  3
      INTEGER, PARAMETER :: ibfile =  6
      INTEGER, PARAMETER :: nv48   = (2*nbsz+1)**3+48

      INTEGER ndiv3              ! max. number of tetrahedrons (< 6*(kpts%nkpt+1)
      INTEGER ntet               ! actual number of tetrahedrons 
      REAL, ALLOCATABLE :: vkxyz(:,:) ! vector of kpoint generated; in cartesian representation
      REAL, ALLOCATABLE ::  wghtkp(:) !   associated with k-points for BZ integration
      INTEGER, ALLOCATABLE :: ntetra(:,:) ! corners of the tetrahedrons
      REAL, ALLOCATABLE ::  voltet(:)     ! voulmes of the tetrahedrons
      REAL, ALLOCATABLE :: vktet(:,:)     !

      REAL    divis(4)           ! Used to find more accurate representation of k-points
                                 ! vklmn(i,kpt)/divis(i) and weights as wght(kpt)/divis(4)
      INTEGER nkstar             ! number of stars for k-points generated in full stars
      REAL    bltv(3,3)          ! cartesian Bravais lattice basis (a.u.)
      REAL    rltv(3,3)          ! reciprocal lattice basis (2\pi/a.u.)
      REAL    ccr(3,3,nop48)     ! rotation matrices in cartesian repr.
      REAL    rlsymr(3,3,nop48)  ! rotation matrices in reciprocal lattice basis representation
      REAL    talfa(3,nop48)     ! translation vector associated with (non-symmorphic)
                                 ! symmetry elements in Bravais lattice representation
      INTEGER ncorn,nedge,nface  ! number of corners, faces and edges of the IBZ
      REAL    fnorm(3,mface)     ! normal vector of the planes bordering the IBZ
      REAL    fdist(mface)       ! distance vector of the planes bordering t IBZ
      REAL    cpoint(3,mface)    ! cartesian coordinates of corner points of IBZ
      REAL    xvec(3)            ! arbitrary vector lying in the IBZ

      INTEGER idsyst   ! crystal system identification in MDDFT programs
      INTEGER idtype   ! lattice type identification in MDDFT programs

      INTEGER idimens  ! number of dimensions for k-point set (2 or 3)
      INTEGER nreg     ! 1 kpoints in full BZ; 0 kpoints in irrBZ
      INTEGER nfulst   ! 1 kpoints ordered in full stars
                       !    (meaningful only for nreg =1; full BZ)
      INTEGER nbound   ! 0 no primary points on BZ boundary;
                       ! 1 with boundary points (not for BZ integration!!!)
      INTEGER ikzero   ! 0 no shift of k-points;
                       ! 1 shift of k-points for better use of sym in irrBZ
      REAL    kzero(3)           ! shifting vector to bring one k-point to or 
Daniel Wortmann's avatar
Daniel Wortmann committed
81
                                 ! away from (0,0,0) (for even/odd nkpt3)
82

Daniel Wortmann's avatar
Daniel Wortmann committed
83
      INTEGER i,j,k,l,idiv,mkpt,addSym,nsym
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 110 111 112
      INTEGER iofile,iokpt,kpri,ktest,kmidtet
      INTEGER idivis(3)
      LOGICAL random,trias
      REAL help(3),binv(3,3),rlsymr1(3,3),ccr1(3,3)

      random = .false.  ! do not use random tetra-points

!------------------------------------------------------------
!
!        idsyst         idtype 
!
!   1  cubic          primitive
!   2  tetragonal     body centered
!   3  orthorhombic   face centered
!   4  hexagonal      A-face centered
!   5  trigonal       B-face centered
!   6  monoclinic     C-face centered
!   7  triclinic 
!
! --->   for 2 dimensions only the following Bravais lattices exist:
!
!    TYPE                    EQUIVALENT 3-DIM        idsyst/idtype
!   square               = p-tetragonal ( 1+2 axis )      2/1
!   rectangular          = p-orthorhomb ( 1+2 axis )      3/1
!   centered rectangular = c-face-orthorhomb( 1+2 axis)   3/6
!   hexagonal            = p-hexagonal  ( 1+2 axis )      4/1
!   oblique              = p-monoclinic ( 1+2 axis )      6/1
!
!------------------------------------------------------------
113

114
      IF(l_q) THEN
Daniel Wortmann's avatar
Daniel Wortmann committed
115 116 117
         trias=input%tria
         if (input%tria) call judft_error("tria=T not implemented for q-point generator",calledby='julia')
         !input%tria=.false.
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
      ENDIF
       
      IF (cell%latnam.EQ.'squ') THEN
        idsyst = 2
        idtype = 1
        IF (.not.input%film) THEN
          IF (abs(cell%amat(1,1)-cell%amat(3,3)) < 0.0000001) THEN
            idsyst = 1
            idtype = 1
          ENDIF
        ENDIF
      END IF
      IF (cell%latnam.EQ.'p-r') THEN
        idsyst = 3
        idtype = 1
      END IF
      IF ((cell%latnam.EQ.'c-b').OR.(cell%latnam.EQ.'c-r')) THEN
        idsyst = 3
        idtype = 6
      END IF
      IF ((cell%latnam.EQ.'hex').OR.(cell%latnam.EQ.'hx3')) THEN
        idsyst = 4
        idtype = 1
      END IF
      IF (cell%latnam.EQ.'obl') THEN
        idsyst = 6
        idtype = 1
      END IF
      IF (cell%latnam.EQ.'any') THEN
        CALL bravais(&
     &               cell%amat,&
     &               idsyst,idtype) 
      ENDIF
Daniel Wortmann's avatar
Daniel Wortmann committed
151 152
      nsym = sym%nop
      IF (input%film) nsym = sym%nop2        
153 154 155 156
!
!-------------------- Want to make a Bandstructure ? --------
!
      IF (banddos%ndir == -4) THEN
157
         CALL bandstr1(idsyst,idtype,cell%bmat,kpts,input,l_fillArrays,banddos)
158
         RETURN
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
      ENDIF
!
!-------------------- Some variables we do not use ----------
!
      iofile = 6
      iokpt  = 6
      kpri   = 0 ! 3
      ktest  = 0 ! 5
      kmidtet = 0
      nreg    = 0
      nfulst  = 0
      ikzero  = 0
      kzero(1) = 0.0 ; kzero(2) = 0.0 ; kzero(3) = 0.0 
      nbound  = 0
      IF (input%tria) THEN
        IF (input%film) nbound  = 1
!        IF ((idsyst==1).AND.(idtype==1)) nbound  = 1
!        IF ((idsyst==2).AND.(idtype==1)) nbound  = 1
!        IF ((idsyst==3).AND.(idtype==1)) nbound  = 1
!        IF ((idsyst==3).AND.(idtype==6)) nbound  = 1
!        IF ((idsyst==4).AND.(idtype==1)) nbound  = 1
        IF (nbound == 0) random = .true.
      ENDIF
      idimens = 3
      IF (input%film) idimens = 2
!
!--------------------- Lattice information ------------------

      DO j = 1,3
        DO k = 1,3
          bltv(j,k) = cell%amat(k,j)
          binv(j,k) = cell%bmat(k,j)/tpi_const
          rltv(j,k) = cell%bmat(k,j)
Daniel Wortmann's avatar
Daniel Wortmann committed
192
          DO i = 1,nsym
193 194 195 196 197
            rlsymr(k,j,i) = real( sym%mrot(j,k,i) )
          ENDDO
        ENDDO
      ENDDO

198
      ccr = 0.0
Daniel Wortmann's avatar
Daniel Wortmann committed
199
      DO i = 1,nsym
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
        DO j = 1,3
          talfa(j,i) = 0.0
          DO k = 1,3
            talfa(j,i) = bltv(j,k) * sym%tau(k,i)
            help(k) = 0.0
            DO l = 1,3
              help(k) =  help(k) + rlsymr(l,k,i) * binv(j,l)
            ENDDO
          ENDDO
          DO k = 1,3
           ccr(j,k,i) = 0.0
           DO l = 1,3
              ccr(j,k,i) = ccr(j,k,i) + bltv(l,k) * help(l)
            ENDDO
          ENDDO
        ENDDO
!      write (*,'(3f12.6)') ((ccr(j,k,i),j=1,3),k=1,3)
!      write (*,*)
      ENDDO
Daniel Wortmann's avatar
Daniel Wortmann committed
219
      DO i = 1,nsym
220 221 222 223 224 225 226 227 228 229
        rlsymr1(:,:) = rlsymr(:,:,i)
           ccr1(:,:) =    ccr(:,:,i)
        DO j = 1,3
          DO k = 1,3
            rlsymr(k,j,i) = rlsymr1(j,k)
               ccr(k,j,i) =    ccr1(j,k)
          ENDDO
        ENDDO
      ENDDO

Daniel Wortmann's avatar
Daniel Wortmann committed
230
      IF ((.not.noco%l_ss).AND.(.not.noco%l_soc).AND.(2*nsym<nop48)) THEN
231 232 233

        IF ( (input%film.AND.(.not.sym%invs2)).OR.&
     &     ((.not.input%film).AND.(.not.sym%invs)) ) THEN
234 235 236 237 238
           addSym = 0
           ! Note: We have to add the negative of each symmetry operation
           !       to exploit time reversal symmetry. However, if the new
           !       symmetry operation is the identity matrix it is excluded.
           !       This is the case iff it is (-Id) + a translation vector.
Daniel Wortmann's avatar
Daniel Wortmann committed
239
           DO i = 1, nsym
240 241
              ! This test assumes that ccr(:,:,1) is the identity matrix.
              IF(.NOT.ALL(ABS(ccr(:,:,1)+ccr(:,:,i)).LT.10e-10) ) THEN
Daniel Wortmann's avatar
Daniel Wortmann committed
242 243
                 ccr(:,:,nsym+addSym+1 ) = -ccr(:,:,i)
                 rlsymr(:,:,nsym+addSym+1 ) = -rlsymr(:,:,i)
244 245 246
                 addSym = addSym + 1
              END IF
           END DO
Daniel Wortmann's avatar
Daniel Wortmann committed
247
           nsym = nsym + addSym
248 249 250 251
        ENDIF

      ENDIF

252
! brzone and brzone2 find the corner-points, the edges, and the
253
! faces of the irreducible wedge of the brillouin zone (IBZ).
254 255 256 257 258 259 260 261
! In these subroutines many special cases can occur. Due to this the very 
! sophisticated old routine brzone had a few bugs. The new routine
! brzone2 was written with a different algorithm that is slightly slower
! but should be more stable. To make comparisons possible the old
! routine is only commented out. Both routines are directly 
! interchangable. GM, 2016.

!      CALL brzone(&
Daniel Wortmann's avatar
Daniel Wortmann committed
262
!     &            rltv,nsym,ccr,mface,nbsz,nv48,&
263 264 265 266
!     &            cpoint,&
!     &            xvec,ncorn,nedge,nface,fnorm,fdist)

      CALL brzone2(&
Daniel Wortmann's avatar
Daniel Wortmann committed
267
     &            rltv,nsym,ccr,mface,nbsz,nv48,&
268 269 270
     &            cpoint,&
     &            xvec,ncorn,nedge,nface,fnorm,fdist)

271

272 273 274 275 276 277 278 279
      IF ( input%tria.AND.random ) THEN
!
!       Calculate the points for tetrahedron method
!      
        mkpt = kpts%nkpt
        ndiv3 = 6*(mkpt+1)
        ALLOCATE (vkxyz(3,mkpt),wghtkp(mkpt) )
        ALLOCATE ( voltet(ndiv3),vktet(3,mkpt),ntetra(4,ndiv3) )
280
        vkxyz = 0.0
281 282 283 284
        CALL kpttet(&
     &              iofile,ibfile,iokpt,&
     &              kpri,ktest,kmidtet,mkpt,ndiv3,&
     &              nreg,nfulst,rltv,cell%omtil,&
Daniel Wortmann's avatar
Daniel Wortmann committed
285
     &              nsym,ccr,mdir,mface,&
286 287 288 289 290 291 292
     &              ncorn,nface,fdist,fnorm,cpoint,&
     &              voltet,ntetra,ntet,vktet,&
     &              kpts%nkpt,&
     &              divis,vkxyz,wghtkp)
      ELSE
!
!       If just the total number of k-points is given, determine 
Daniel Wortmann's avatar
Daniel Wortmann committed
293
!       the divisions in each direction (nkpt3):
294 295 296
!
!        IF (tria) THEN
!            nkpt = nkpt/4
Daniel Wortmann's avatar
Daniel Wortmann committed
297
!            nkpt3(:) = nkpt3(:) / 2
298
!        ENDIF
Daniel Wortmann's avatar
Daniel Wortmann committed
299
        IF (sum(kpts%nkpt3).EQ.0) THEN
300 301
          CALL divi(&
     &              kpts%nkpt,cell%bmat,input%film,sym%nop,sym%nop2,&
Daniel Wortmann's avatar
Daniel Wortmann committed
302
     &              kpts%nkpt3)
303
        ENDIF
304

305 306 307
!
!       Now calculate Monkhorst-Pack k-points:
!
Daniel Wortmann's avatar
Daniel Wortmann committed
308 309
        IF (kpts%nkpt3(2).EQ.0) kpts%nkpt3(2) = kpts%nkpt3(1)
        IF ((.not.input%film).AND.(kpts%nkpt3(3).EQ.0)) kpts%nkpt3(3) = kpts%nkpt3(2)
310
        IF (nbound.EQ.1) THEN
Daniel Wortmann's avatar
Daniel Wortmann committed
311 312
           mkpt = (2*kpts%nkpt3(1)+1)*(2*kpts%nkpt3(2)+1)
           IF (.not.input%film) mkpt = mkpt*(2*kpts%nkpt3(3)+1)
313
        ELSE
Daniel Wortmann's avatar
Daniel Wortmann committed
314 315
           mkpt = kpts%nkpt3(1)*kpts%nkpt3(2)
           IF (.not.input%film) mkpt = mkpt*kpts%nkpt3(3)
316 317
        ENDIF
        ALLOCATE (vkxyz(3,mkpt),wghtkp(mkpt) )
318
        vkxyz = 0.0
319 320 321

        CALL kptmop(&
     &              iofile,iokpt,kpri,ktest,&
Daniel Wortmann's avatar
Daniel Wortmann committed
322
     &              idsyst,idtype,kpts%nkpt3,ikzero,kzero,&
323 324
     &              rltv,bltv,nreg,nfulst,nbound,idimens,&
     &              xvec,fnorm,fdist,ncorn,nface,nedge,cpoint,&
Daniel Wortmann's avatar
Daniel Wortmann committed
325
     &              nsym,ccr,rlsymr,talfa,mkpt,mface,mdir,&
326 327 328
     &              kpts%nkpt,divis,vkxyz,nkstar,wghtkp)

      ENDIF
329

330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
!
      idivis(1) = int(divis(1)) 
      idivis(2) = int(divis(2)) 
      idivis(3) = int(divis(3)) 
      idiv = lcm(3,idivis)
!      WRITE (*,'(2i5)') nkpt,idiv
      IF (idiv.GE.200) idiv = 1
      DO j=1,kpts%nkpt
!        WRITE (*,'(4f10.5)') (vkxyz(i,j),i=1,3),wghtkp(j)
        wghtkp(j) = wghtkp(j) * divis(4)
        DO k = 1,3
          help(k) = 0.0
          DO l = 1,3
             help(k) = help(k) + cell%amat(l,k) * vkxyz(l,j)
          ENDDO
        ENDDO
        DO i=1,3
          vkxyz(i,j) = help(i) * idiv / tpi_const
        ENDDO
      ENDDO
!
! if (l_q) write qpts file:
!
      IF(l_q)THEN
         IF(input%film) CALL juDFT_error("For the case of input%film q-points "//&
     &                 "generator not implemented!",calledby ="julia")
    
        OPEN(113,file='qpts',form='formatted',status='new')
        WRITE(113,'(i5)') kpts%nkpt+1
        WRITE(113,8050) 0.,0.,0.
        DO j = 1, kpts%nkpt
           WRITE (113,FMT=8050) (vkxyz(i,j)/real(idiv),i=1,3)
        ENDDO
        CLOSE(113)
Daniel Wortmann's avatar
Daniel Wortmann committed
364
        !input%tria=trias
365 366 367 368 369
        RETURN
      ENDIF
 8050 FORMAT (2(f14.10,1x),f14.10)

!
370
! write k-points file or write data into arrays
371
!
372 373 374 375 376

      IF (l_fillArrays) THEN
         IF (ALLOCATED(kpts%bk)) THEN
            DEALLOCATE(kpts%bk)
         END IF
Daniel Wortmann's avatar
Daniel Wortmann committed
377 378
         IF (ALLOCATED(kpts%wtkpt)) THEN
            DEALLOCATE(kpts%wtkpt)
379
         END IF
Daniel Wortmann's avatar
Daniel Wortmann committed
380
         ALLOCATE(kpts%bk(3,kpts%nkpt),kpts%wtkpt(kpts%nkpt))
381
         IF (idiv.NE.0) kpts%posScale = REAL(idiv)
382
         DO j = 1, kpts%nkpt
383 384 385
            kpts%bk(1,j) = vkxyz(1,j)
            kpts%bk(2,j) = vkxyz(2,j)
            kpts%bk(3,j) = vkxyz(3,j)
Daniel Wortmann's avatar
Daniel Wortmann committed
386
            kpts%wtkpt(j) = wghtkp(j)
387
         END DO
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404
         IF (input%tria.AND.random) THEN
            kpts%ntet = ntet
            IF (ALLOCATED(kpts%ntetra)) THEN
               DEALLOCATE(kpts%ntetra)
            END IF
            IF (ALLOCATED(kpts%voltet)) THEN
               DEALLOCATE(kpts%voltet)
            END IF
            ALLOCATE(kpts%ntetra(4,kpts%ntet))
            ALLOCATE(kpts%voltet(kpts%ntet))
            DO j = 1, ntet
               DO i = 1, 4
                  kpts%ntetra(i,j) = ntetra(i,j)
               END DO
               kpts%voltet(j) = ABS(voltet(j))
            END DO
         END IF
405
      ELSE
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
         OPEN (41,file='kpts',form='formatted',status='new')
         IF (input%film) THEN
            WRITE (41,FMT=8110) kpts%nkpt,real(idiv),.false.
            DO j=kpts%nkpt,1,-1
               WRITE (41,FMT=8040) (vkxyz(i,j),i=1,2),wghtkp(j)
            END DO
         ELSE
            WRITE (41,FMT=8100) kpts%nkpt,real(idiv)
            DO j = 1, kpts%nkpt
               WRITE (41,FMT=8040) (vkxyz(i,j),i=1,3),wghtkp(j)
            END DO
            IF (input%tria.AND.random) THEN
               WRITE (41,'(i5)') ntet
               WRITE (41,'(4(4i6,4x))') ((ntetra(i,j),i=1,4),j=1,ntet)
               WRITE (41,'(4f20.13)') (ABS(voltet(j)),j=1,ntet)
            END IF
         END IF
 8100    FORMAT (i5,f20.10)
 8110    FORMAT (i5,f20.10,3x,l1)
 8040    FORMAT (4f10.5)
         CLOSE (41)

428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466
      END IF

      DEALLOCATE ( vkxyz,wghtkp )
      IF (input%tria.AND..not.input%film)  DEALLOCATE ( voltet,vktet,ntetra )
      RETURN

      CONTAINS

      INTEGER FUNCTION lcm( n, ints )
! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!     Compute least common multiple (lcm) of n positive integers.
! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!===> Arguments
      INTEGER :: n
      INTEGER :: ints(n)

!===> Variables
      INTEGER :: i,j,m
! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

      IF ( any( ints(1:n)<= 0 ) ) THEN
        m = 0
      ELSE
        m = maxval( ints(1:n) )
        DO i = 1, n
          DO j = 1, ints(i)/2
            IF ( mod( m*j,ints(i) ) == 0 ) EXIT
          END DO
          m = m*j
        ENDDO
      ENDIF

      lcm = m

      RETURN
      END FUNCTION lcm

      END SUBROUTINE julia
      END MODULE m_julia