prp_qfft.f90 8.58 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 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
      MODULE m_prpqfft
      use m_juDFT
      CONTAINS
      SUBROUTINE prp_qfft(&
     &                    stars,&
     &                    cell,noco,&
     &                    input)
!*********************************************************************
!     This subroutine prepares the necessary variables and checks
!     to calculate the plane wave chargedensity in the interstitial
!     (subroutine pwden.f) by fast fourier transform (FFT).
!     In certain cases rkmax is slightly reajusted to perform
!     a quick FFT based on powers   (2**P) * (3**Q) * (5**R) only.
!
!     dimensions kd(i)d for charge denisity box are checked.
!        s. bluegel, JRCAT, Feb. 97
!
!     subroutine boxdim added to subroutine to treat non-orthogonal
!     lattice systems.
!        s.bluegel, IFF, 18.Nov.97
!*********************************************************************
!
      USE m_ifft, ONLY : ifft235
      USE m_boxdim
      USE m_types
      IMPLICIT NONE
!
!---> Arguments
!
      TYPE(t_stars),INTENT(INOUT)  :: stars
      TYPE(t_cell),INTENT(IN)      :: cell
      TYPE(t_noco),INTENT(IN)      :: noco
      TYPE(t_input),INTENT(INOUT)  :: input  !<rkmax might be modified
!
!
!---> local variables
!
44
      INTEGER ksfft,mq1,mq2,mq3,istr,iofile,ng2_fft,kmxq2_fft
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 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 110 111 112 113 114 115 116 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
      REAL    arltv1,arltv2,arltv3,rknew
!
!---> intrinsic functions
!    
      INTRINSIC int,min
!
!---> data statement
!
      REAL gmaxp
      DATA gmaxp /2.0/
!
!------->          BACKGROUND       
!
!        Determine the limits  for the charge density fft-box
!        The charge density is the  square of the wavefunction.
!        Since the largest G-vector of the wavefunction is
!        given by |G + k| < rkmax, the largest G -vector gmaxq
!        contributing the charge-density is exactly :
!        gmaxq = gmaxp*rkmax,  with gmaxp =2. 
!        Therefore the box dimension must be  determined by :
!        m(i) >= gmaxp * rkmax*a(i)/(2*pi), where a(i) is the 
!        magnitude of the ith basis vector. (this is only true
!        for <a(i)|a(j)> = 0 for i .ne. j., otherwise see boxdim)
!        REMEMBER: gmax used through out the FLAPW code can be
!        larger than gmaxp*rkmax. 
!
!
!------->          ABBREVIATIONS
!
!   ksfft=(0,1) : KEY OF SELECTING FFT-PRDOGRAM AND RADIX-TYPE
!                      0  PROGRAM, RADIX-2 ONLY
!                      1  PROGRAM, RADIX-2, RADIX-3,RADIX-5
!   iofile      : device number for in and output
!   gmax        : actually used gmax troughtout the FLAPW code
!   gmaxq       : cut-off wavevector for charge density
!   rkmax       : cut-off for |g+k|
!   gmaxp       : gmaxp = gmaxq/rkmax, ideal: gmaxp=2
!   kq1,2,3d    : dimensions of the charge density fft-box
!                 ( in positive fft domain )
!   mq1,2,3     : actual size of the charge density fft-box
!                 ( in positive fft domain )
!   nq3_fft     : number of stars in the charge density sphere
!   kmxq_fft    : number of g-vectors in the charge density sphere
!   arltv(i)    : length of reciprical lattice vector along
!                 direction (i)
!
!---> Determine dimensions of fft-box of size mq1, mq2, mq3,
!     for which |G(mq1,mq2,mq3)| < Gmaxp*Kmax
!
      CALL boxdim(&
     &            cell%bmat,&
     &            arltv1,arltv2,arltv3)
!
      mq1 = int( gmaxp*input%rkmax/arltv1 ) + 1
      mq2 = int( gmaxp*input%rkmax/arltv2 ) + 1
      mq3 = int( gmaxp*input%rkmax/arltv3 ) + 1

!---> add + 1 in spin spiral calculation, to make sure that all G's are 
!---> still within the FFT-box after being shifted by the spin spiral
!---> q-vector.
      IF (noco%l_ss) THEN
         mq1 = mq1 + 1
         mq2 = mq2 + 1
         mq3 = mq3 + 1
      ENDIF         
!
!----> fft done in positive domain 
!      (Remember number of grid points not 2*m+1 because of cyclic 
!       boundary condition)
!
      mq1 = mq1 + mq1
      mq2 = mq2 + mq2
      mq3 = mq3 + mq3
!
!---> fft's are usually fastest for low primes
!     (restrict kqid to: kwid=  (2**P) * (3**Q) * (5**R)
!
      iofile = 6
      ksfft  = 1
      stars%kq1_fft = ifft235 (iofile,ksfft,mq1,gmaxp)
      stars%kq2_fft = ifft235 (iofile,ksfft,mq2,gmaxp)
      stars%kq3_fft = ifft235 (iofile,ksfft,mq3,gmaxp)
!+gb
!      kq1_fft = mq1
!      kq2_fft = mq2
!      kq3_fft = mq3
!
!---> For mq = 2**P, FFT is very fast. If mq very close to 2**P
!     choose this, even 2**P < mq . Therefore:
!     factor 0.5 added by S.B. 21.Aug.97 
!
      rknew = min( real( stars%kq1_fft )*arltv1, real( stars%kq2_fft )*arltv2, &
     &             real( stars%kq3_fft )*arltv3)
      rknew = 0.5 * rknew / gmaxp
      IF (rknew.LT.input%rkmax) THEN
         WRITE (6,'('' rkmax and true gmax recalculated '')')
         WRITE (6,2100) input%rkmax, rknew, rknew*rknew
         WRITE (6,2200) gmaxp*rknew, gmaxp*rknew*gmaxp*rknew
         input%rkmax = rknew
      ENDIF
!
!-----> gmax => gmaxp*rkmax 
!       (otherwise too few elements in arrays defined in strng1)
!
      IF (2*input%rkmax.GT.stars%gmax) THEN
         WRITE (6,'('' gmax must be at least 2*rkmax'')')
         WRITE (6,'('' increase gmax , or reduce rkmax'')')
         WRITE (6,'('' rkmax ='',f10.3,''  gmax ='',f10.3)') input%rkmax,stars%gmax
         CALL juDFT_error("rkmax,gmax",calledby ="prp_qfft",hint&
     &        ="gmax must be at least 2*rkmax")
      ENDIF
!
!     mq1 = kq1_fft
!     mq2 = kq2_fft
!     mq3 = kq3_fft
!
161

162 163 164 165 166 167 168 169 170 171 172 173
!
!-----> how many stars are in charge density sphere?
!       assume stars are ordered according to length
!
!---> 3d stars
      stars%ng3_fft = 0
      DO istr = 1 , stars%ng3
         IF ( stars%sk3(istr).LE.gmaxp*input%rkmax ) THEN
            stars%ng3_fft = istr
         ENDIF
      ENDDO
!---> 2d stars
174
      ng2_fft = 0
175 176
      DO istr = 1 , stars%ng2
         IF ( stars%sk2(istr).LE.gmaxp*input%rkmax ) THEN
177
            ng2_fft = istr
178 179 180 181 182 183 184 185 186 187
         ENDIF
      ENDDO
!
      IF ( stars%ng3_fft.EQ.0 ) THEN
         WRITE(6,'('' presumably ng3 too small '')')
         WRITE(6,'('' sk3max, gmaxp*rkmax '', 2f10.6)') &
     &                stars%sk3(stars%ng3),gmaxp*input%rkmax
         CALL juDFT_error("presumably ng3 too small","prp_qfft")
      ENDIF
!
188
      IF ( stars%ng3_fft.GT.stars%ng3 ) THEN
189
         WRITE(6,'('' nq3_fft > n3d '')')
190
         WRITE(6,'('' nq3_fft, n3d '',2i10)') stars%ng3_fft, stars%ng3
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
          CALL juDFT_error("nq3_fft > n3d",calledby="prp_qfft")
      ENDIF
!
!-----> check that all nq3_fft stars fit into the charge density FFT-box
!
      DO istr = 1 , stars%ng3_fft
        IF ( ( 2*stars%kv3(1,istr).GT.stars%kq1_fft ) .OR.&
     &       ( 2*stars%kv3(2,istr).GT.stars%kq2_fft ) .OR.&
     &       ( 2*stars%kv3(3,istr).GT.stars%kq3_fft ) ) THEN
          WRITE (6,'('' not all nq3_fft stars in chg. den. FFT box'')')
          WRITE (6,'('' inconsistency in def.s see also strgn1'')')
          WRITE (6,'('' mq1d,mq2d,mq3d,kv1,kv2,kv3 '',6i5)')&
     &                  stars%kq1_fft,stars%kq2_fft,stars%kq3_fft,2*stars%kv3(1,istr),2*stars%kv3(2,istr),&
     &                                 2*stars%kv3(3,istr)
          CALL juDFT_error("not all nq3_fft stars in chg. den. FFT box",&
     &         calledby ="prp_qfft")
        ENDIF
      ENDDO
!
!-----> how many G-vectors belong to these nq3_fft stars                    
!
!---> 3d vectors
      stars%kmxq_fft = 0
      DO istr = 1 , stars%ng3_fft
         stars%kmxq_fft = stars%kmxq_fft + stars%nstr(istr)
      ENDDO
217
      IF ( stars%kmxq_fft .GT. stars%kq1_fft*stars%kq2_fft*stars%kq3_fft ) THEN
218
         WRITE (6,'('' array dimensions in later subroutines too'',&
219
     &             '' small'',2i10)') stars%kmxq_fft,stars%kq1_fft*stars%kq2_fft*stars%kq3_fft
220 221
      ENDIF
!---> 2d vectors
222 223 224
      kmxq2_fft = 0
      DO istr = 1 , ng2_fft
         kmxq2_fft = kmxq2_fft + stars%nstr2(istr)
225
      ENDDO
226
      IF ( kmxq2_fft .GT. stars%kq1_fft*stars%kq2_fft ) THEN
227
         WRITE (6,'('' array dimensions in later subroutines too'',&
228
     &             '' small'',2i10)') kmxq2_fft,stars%kq1_fft*stars%kq2_fft
229 230 231 232 233 234 235 236 237 238 239
      ENDIF

!
 2100 FORMAT (/,1x,'old rkmax   =',f10.5, '(a.u.)**(-1) ==>  new rkmax '&
     &      ,'  =',f10.5,'(a.u.)**(-1) ',/,t38,'==>  new E_cut(wf)   =',&
     &            f10.5,' Ry')
 2200 FORMAT (/,1x,'true gmax   =',f10.5, '(a.u.)**(-1)',&
     &       /,t38,'==>  new E_cut(chg)  =', f10.5,' Ry')

      END SUBROUTINE prp_qfft
      END MODULE m_prpqfft