gen_wavf.F90 13.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!     This module generates the cmt coefficients and eigenvectors z   !
!     at all kpoints nkpt from the irreducible kpoints nkpti          !
!     and writes them out in cmt and z, respectively.                 !
!                                                 M.Betzinger(09/07)  !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
      MODULE m_gen_wavf

      CONTAINS

      SUBROUTINE gen_wavf (&
     &          nkpti,kpts,it,sym,&
     &          atoms,el_eig,ello_eig,cell,&
     &          dimension,hybrid,vr0,&
Daniel Wortmann's avatar
Daniel Wortmann committed
16
     &          hybdat,&
17
     &          noco,oneD,mpi,irank2,&
Daniel Wortmann's avatar
Daniel Wortmann committed
18 19
     &          input,jsp,&
     &          zmat)
20 21 22 23 24 25 26 27 28 29 30 31


      ! nkpti      ::     number of irreducible k-points
      ! nkpt       ::     number of all k-points 

      USE m_radfun
      USE m_radflo
      USE m_abcof
      USE m_trafo     ,ONLY: waveftrafo_genwavf
      USE m_util      ,ONLY: modulo1
      USE m_olap
      USE m_types
32
      USE m_hyb_abcrot
Daniel Wortmann's avatar
Daniel Wortmann committed
33
      USE m_io_hybrid
34
      IMPLICIT NONE
Daniel Wortmann's avatar
Daniel Wortmann committed
35 36 37

      TYPE(t_hybdat),INTENT(INOUT)   :: hybdat
      TYPE(t_mpi),INTENT(IN)         :: mpi
38
      TYPE(t_dimension),INTENT(IN)   :: dimension
Daniel Wortmann's avatar
Daniel Wortmann committed
39 40 41 42 43 44 45 46
      TYPE(t_oneD),INTENT(IN)        :: oneD
      TYPE(t_hybrid),INTENT(IN)      :: hybrid
      TYPE(t_input),INTENT(IN)       :: input
      TYPE(t_noco),INTENT(IN)        :: noco
      TYPE(t_sym),INTENT(IN)         :: sym
      TYPE(t_cell),INTENT(IN)        :: cell
      TYPE(t_kpts),INTENT(IN)        :: kpts
      TYPE(t_atoms),INTENT(IN)       :: atoms
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63

!     - - scalars - -
      INTEGER,INTENT(IN)      ::  nkpti ,it    

!     scalars for abcoff

!     scalars for apws
      INTEGER,INTENT(IN)      :: jsp

!     - - arrays - -
      INTEGER,INTENT(IN)      ::  irank2(nkpti)


      REAL,INTENT(IN)         ::  vr0(:,:,:)!(jmtd,ntype,jspd)
      
      REAL,INTENT(IN)         ::  el_eig(0:atoms%lmaxd,atoms%ntype)
      REAL,INTENT(IN)         ::  ello_eig(atoms%nlod,atoms%ntype)
64
      TYPE(t_mat),INTENT(IN)  :: zmat(:) !for all kpoints 
65 66

  !     - - local scalars - - 
Daniel Wortmann's avatar
Daniel Wortmann committed
67 68
      INTEGER                 ::  ilo,idum ,m
      COMPLEX                 ::  cdum
Daniel Wortmann's avatar
Daniel Wortmann committed
69
      TYPE(t_mat)             :: zhlp
Daniel Wortmann's avatar
Daniel Wortmann committed
70 71
      INTEGER                 ::  ikpt0,ikpt,itype,iop,ispin,ieq,indx,iatom
      INTEGER                 ::  i,j,l ,ll,lm,ng,ok
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
      COMPLEX                 ::  img=(0d0,1d0)

!     local scalars for radfun
      INTEGER                 ::  nodem,noded
      REAL                    ::  wronk

!     reduced dimension for parallel calculation
      INTEGER                 ::  lower, upper
      LOGICAL                 ::  found

!     - - local arrays - -
      INTEGER                 ::  rrot(3,3,sym%nsym)
      INTEGER                 ::  map_lo(atoms%nlod)
      INTEGER                 ::  iarr(0:atoms%lmaxd,atoms%ntype)
      COMPLEX,ALLOCATABLE     ::  acof(:,:,:),bcof(:,:,:),ccof(:,:,:,:)
Daniel Wortmann's avatar
Daniel Wortmann committed
87
      
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
      COMPLEX,ALLOCATABLE     ::  cmt(:,:,:),cmthlp(:,:,:)


!     local arrays for abcof1
!       COMPLEX                 ::  a(nvd,0:lmd,natd,nkpti),b(nvd,0:lmd,natd,nkpti)

!     local arrays for radfun
      REAL                    ::  vr(atoms%jmtd,atoms%ntype,dimension%jspd)
      REAL,ALLOCATABLE        ::  f(:,:,:),df(:,:,:)


!     local arrays for radflo
      REAL                    ::  flo(atoms%jmtd,2,atoms%nlod)
      REAL                    ::  uuilon(atoms%nlod,atoms%ntype),duilon(atoms%nlod,atoms%ntype)
      REAL                    ::  ulouilopn(atoms%nlod,atoms%nlod,atoms%ntype)
Daniel Wortmann's avatar
Daniel Wortmann committed
103
   
104 105

!     local arrays for apws
Daniel Wortmann's avatar
Daniel Wortmann committed
106 107
      REAL                    :: bkpt(3) 

108 109 110
      INTEGER                 ::  irecl_cmt,irecl_z


Daniel Wortmann's avatar
Daniel Wortmann committed
111
      TYPE(t_lapw) :: lapw(kpts%nkptf)
112 113
      TYPE(t_usdus):: usdus

Daniel Wortmann's avatar
Daniel Wortmann committed
114
      !CALL CPU_TIME(time1)
Daniel Wortmann's avatar
Daniel Wortmann committed
115
      call usdus%init(atoms,dimension%jspd)
116
      call zhlp%alloc(zmat(1)%l_real,zmat(1)%matsize1,zmat(1)%matsize2)
Daniel Wortmann's avatar
Daniel Wortmann committed
117 118

      
119 120 121 122 123 124 125 126 127 128 129
      ! setup rotations in reciprocal space
      DO iop=1,sym%nsym
        IF( iop .le. sym%nop ) THEN
          rrot(:,:,iop) = transpose( sym%mrot(:,:,sym%invtab(iop)) )
        ELSE
          rrot(:,:,iop) = -rrot(:,:,iop-sym%nop)
        END IF
      END DO

      ! generate G-vectors, which fulfill |k+G|<rkmax
      ! for all k-points
Daniel Wortmann's avatar
Daniel Wortmann committed
130
      DO ikpt=1,kpts%nkptf
Daniel Wortmann's avatar
Daniel Wortmann committed
131
         CALL lapw(ikpt)%init(input,noco, kpts,atoms,sym,ikpt,cell,sym%zrfs)
132 133 134 135 136 137 138 139

      END DO

      ! read in spherical component of the potential from
      ! the previous iteration
      ! eigen_hf writes spherical component in file vr0
      ! if it = 1 vr0 is identical to the potential of the
      ! previous calculation
140
      vr = vr0
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


!       ALLOCATE ( z_out(nbasfcn,neigd,nkpti),stat=ok )
!       IF ( ok .ne. 0) STOP 'gen_wavf: failure allocation z'
!       z_out = 0
!       z_out(:,:,:nkpti) = z_in


      ! calculate radial basis functions belonging to the
      ! potential vr stored in bas1 and bas2
      ! bas1 denotes the large component
      ! bas2    "     "  small component

      ALLOCATE( f(atoms%jmtd,2,0:atoms%lmaxd), df(atoms%jmtd,2,0:atoms%lmaxd) )
      f    = 0
      df   = 0
      iarr = 2
      DO itype=1,atoms%ntype
        if ( mpi%irank == 0 ) WRITE (6,FMT=8000) itype
        ng = atoms%jri(itype)
        DO l=0,atoms%lmax(itype)
           CALL radfun(l,itype,1,el_eig(l,itype),vr(:,itype,jsp),&
                atoms,f(:,:,l),df(:,:,l),usdus,nodem,noded,wronk)
          IF ( mpi%irank == 0 ) WRITE (6,FMT=8010) l,el_eig(l,itype),&
               usdus%us(l,itype,1),usdus%dus(l,itype,1),nodem,usdus%uds(l,itype,1),&
               usdus%duds(l,itype,1),noded,usdus%ddn(l,itype,1),wronk

Daniel Wortmann's avatar
Daniel Wortmann committed
168 169 170 171
          hybdat%bas1(1:ng,1,l,itype) =  f(1:ng,1,l)
          hybdat%bas2(1:ng,1,l,itype) =  f(1:ng,2,l)
          hybdat%bas1(1:ng,2,l,itype) = df(1:ng,1,l)
          hybdat%bas2(1:ng,2,l,itype) = df(1:ng,2,l)
172

Daniel Wortmann's avatar
Daniel Wortmann committed
173 174 175 176
            hybdat%bas1_MT(1,l,itype) =   usdus%us(l,itype,1)
          hybdat%drbas1_MT(1,l,itype) =  usdus%dus(l,itype,1)
            hybdat%bas1_MT(2,l,itype) =  usdus%uds(l,itype,1)
          hybdat%drbas1_MT(2,l,itype) = usdus%duds(l,itype,1)
177 178 179 180 181 182 183 184 185 186 187
        END DO

        IF (atoms%nlo(itype).GE.1) THEN
          CALL radflo( atoms,itype,jsp,&
     &                 ello_eig,vr(:,itype,jsp),&
     &                 f,df,mpi,&
     &                 usdus,&
     &                 uuilon,duilon,ulouilopn,flo)

          DO ilo=1,atoms%nlo(itype)
            iarr(atoms%llo(ilo,itype),itype) = iarr(atoms%llo(ilo,itype),itype) + 1
Daniel Wortmann's avatar
Daniel Wortmann committed
188
            hybdat%bas1(1:ng,iarr(atoms%llo(ilo,itype),itype),atoms%llo(ilo,itype),itype)&
189
     &                                                = flo(1:ng,1,ilo)
Daniel Wortmann's avatar
Daniel Wortmann committed
190
            hybdat%bas2(1:ng,iarr(atoms%llo(ilo,itype),itype),atoms%llo(ilo,itype),itype)&
191 192
     &                                                = flo(1:ng,2,ilo)

Daniel Wortmann's avatar
Daniel Wortmann committed
193
              hybdat%bas1_MT(iarr(atoms%llo(ilo,itype),itype),atoms%llo(ilo,itype),itype)&
194
     &                                                = usdus%ulos(ilo,itype,1)
Daniel Wortmann's avatar
Daniel Wortmann committed
195
            hybdat%drbas1_MT(iarr(atoms%llo(ilo,itype),itype),atoms%llo(ilo,itype),itype)&
196 197 198 199 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
     &                                                = usdus%dulos(ilo,itype,1)
          END DO

        END IF
      END DO
      DEALLOCATE (f,df)
#if CPP_DEBUG
      ! consistency check
      IF( .not. all(iarr .eq. hybrid%nindx ) ) STOP 'gen_wavf: counting error'
#endif

 8000    FORMAT (1x,/,/,' wavefunction parameters for atom type',i3,':',&
     &          /,t32,'radial function',t79,'energy derivative',/,t3,&
     &          'l',t8,'energy',t26,'value',t39,'derivative',t53,&
     &          'nodes',t68,'value',t81,'derivative',t95,'nodes',t107,&
     &          'norm',t119,'wronskian')
 8010    FORMAT (i3,f10.5,2 (5x,1p,2e16.7,i5),1p,2e16.7)


      ! determine boundaries for parallel calculations
      lower = 1
      upper = nkpti
      found = .false.
#     ifdef CPP_MPI
        DO ikpt = 1, nkpti
          IF ( irank2(ikpt) == 0 .AND. .not. found ) THEN
            lower = ikpt
            found = .true.
          ELSE IF ( irank2(ikpt) /= 0 .AND. found ) THEN
            upper = ikpt-1
            EXIT
          END IF
        END DO
#     else
        found = .true.
#     endif
      IF ( .not. found ) THEN
        upper = 0
      END IF


Daniel Wortmann's avatar
Daniel Wortmann committed
237
    
238 239 240 241 242 243 244 245 246 247 248 249 250
      ! calculate wavefunction expansion in the the MT region
      ! (acof,bcof,ccof) and APW-basis coefficients
      ! (a,b,bascofold_lo) at irred. kpoints

!       CALL cpu_time(time2)
!       WRITE(*,*) 'time for generating radial functions',time2-time1

      ALLOCATE( acof(dimension%neigd,0:dimension%lmd,atoms%nat),stat=ok )
      IF( ok .ne. 0 ) STOP 'gen_wavf: failure allocation acof'
      ALLOCATE( bcof(dimension%neigd,0:dimension%lmd,atoms%nat),stat=ok )
      IF( ok .ne. 0 ) STOP 'gen_wavf: failure allocation bcof'
      ALLOCATE( ccof(-atoms%llod:atoms%llod,dimension%neigd,atoms%nlod,atoms%nat),stat=ok )
      IF( ok .ne. 0 ) STOP 'gen_wavf: failure allocation ccof'
Daniel Wortmann's avatar
Daniel Wortmann committed
251
      ALLOCATE ( cmt(dimension%neigd,hybrid%maxlmindx,atoms%nat), stat=ok)
252
      IF(  ok .ne. 0 ) STOP 'gen_wavf: Failure allocation cmt'
Daniel Wortmann's avatar
Daniel Wortmann committed
253
      ALLOCATE ( cmthlp(dimension%neigd,hybrid%maxlmindx,atoms%nat), stat=ok)
254
      IF( ok .ne. 0) STOP 'gen_wavf: failure allocation cmthlp'
Daniel Wortmann's avatar
Daniel Wortmann committed
255
    
Daniel Wortmann's avatar
Daniel Wortmann committed
256
   
257 258 259 260 261 262 263

      DO ikpt0 = lower, upper

        acof = 0; bcof = 0; ccof = 0

        ! abcof calculates the wavefunction coefficients
        ! stored in acof,bcof,ccof
Daniel Wortmann's avatar
Daniel Wortmann committed
264
        lapw(ikpt0)%nmat=lapw(ikpt0)%nv(jsp)+atoms%nlotot
265
        CALL abcof(&
Daniel Wortmann's avatar
Daniel Wortmann committed
266 267
              input,atoms,sym, cell, lapw(ikpt0), &
              hybrid%nbands(ikpt0),usdus,noco,jsp,&!hybdat%kveclo_eig(:,ikpt0),&
Daniel Wortmann's avatar
Daniel Wortmann committed
268
              oneD,acof(: hybrid%nbands(ikpt0),:,:),bcof(: hybrid%nbands(ikpt0),:,:),ccof(:,: hybrid%nbands(ikpt0),:,:),&
Daniel Wortmann's avatar
Daniel Wortmann committed
269
              zmat(ikpt0))
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
        

! call was ...
          ! gpt(1,:,:,ikpt0),gpt(2,:,:,ikpt0),&
          ! gpt(3,:,:,ikpt0),ngpt(:,ikpt0),&!k1hlp,k2hlp,k3hlp,nvhlp,&
          !    ngpt(jsp,ikpt0)+nbands(ikpt0),z(:,:,ikpt0),&!nvhlp(jsp)+ &
          !   &usdus,&
          !    noco,&
          !    jsp,kveclo_eig(:ikpt0),oneD,oneD,&
          !    acof(:nbands(ikpt0),:,:),&
          !    bcof(:nbands(ikpt0),:,:),ccof(:,:nbands(ikpt0),:,:) )

        ! MT wavefunction coefficients are calculated in a local coordinate system
        ! rotate them in the global one

285
        CALL hyb_abcrot(&
Daniel Wortmann's avatar
Daniel Wortmann committed
286
                hybrid,atoms,hybrid%nbands(ikpt0),&
Daniel Wortmann's avatar
Daniel Wortmann committed
287
                 sym,&
288
                cell,oneD,&
Daniel Wortmann's avatar
Daniel Wortmann committed
289 290
                acof(: hybrid%nbands(ikpt0),:,:),bcof(: hybrid%nbands(ikpt0),:,:),&
                ccof(:,: hybrid%nbands(ikpt0),:,:) )
291 292 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 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 343 344 345 346 347 348 349 350 351

!       CALL cpu_time(time3)

!       WRITE(*,*) 'time for abcoff and abcrot',time3-time2


!       CALL cpu_time(time2)


        ! decorate acof, bcof, ccof with coefficient i**l and store them
        ! in the field cmt(neigd,nkpt,maxlmindx,nat), i.e.
        ! where maxlmindx subsumes l,m and nindx

        cmt   = 0
        iatom = 0
        DO itype=1,atoms%ntype
          DO ieq=1,atoms%neq(itype)
            iatom   = iatom + 1
            indx    = 0
            DO l=0,atoms%lmax(itype)
              ll   = l*(l+1)
              cdum = img**l

              ! determine number of local orbitals with quantum number l
              ! map returns the number of the local orbital of quantum
              ! number l in the list of all local orbitals of the atom type
              idum   = 0
              map_lo = 0
              IF( hybrid%nindx(l,itype) .gt.2) THEN
                DO j=1,atoms%nlo(itype)
                  IF( atoms%llo(j,itype) .eq. l) THEN
                    idum = idum + 1
                    map_lo(idum) = j
                  END IF
                END DO
              END IF



              DO M=-l,l
                lm=ll+M
                DO i=1,hybrid%nindx(l,itype)
                  indx = indx + 1
                  IF( i .eq. 1 ) THEN
                    cmt(:,indx,iatom) =cdum*acof(:,lm,iatom)
                  ELSEIF ( i .eq. 2 ) THEN
                    cmt(:,indx,iatom) =cdum*bcof(:,lm,iatom)
                  ELSE
                    idum = i - 2
                    cmt(:,indx,iatom) =cdum*ccof(M,:,map_lo(idum),iatom)
                  END IF
                END DO
              END DO
            END DO

          END DO
        END DO

!       CALL cpu_time(time3)

        ! write cmt at irreducible k-points in direct-access file cmt
Daniel Wortmann's avatar
Daniel Wortmann committed
352
        call write_cmt(cmt,ikpt0)
353
        call zhlp%alloc(zmat(1)%l_real,zmat(1)%matsize1,zmat(1)%matsize2)
Daniel Wortmann's avatar
Daniel Wortmann committed
354 355
        
        IF (zhlp%l_real) THEN
356
           zhlp%data_r=zmat(ikpt0)%data_r
357
        ELSE
358
           zhlp%data_c=zmat(ikpt0)%data_c
Daniel Wortmann's avatar
Daniel Wortmann committed
359 360
        end IF
        call write_z(zhlp,ikpt0)
361 362 363 364
       

        ! generate wavefunctions coefficients at all k-points from
        ! irreducible k-points
Daniel Wortmann's avatar
Daniel Wortmann committed
365 366
        
        DO ikpt=1,kpts%nkptf
367 368
          IF ( kpts%bkp(ikpt) .eq. ikpt0 .and. ikpt0 .ne. ikpt ) THEN
            iop = kpts%bksym(ikpt)
Daniel Wortmann's avatar
Daniel Wortmann committed
369
              CALL waveftrafo_genwavf( cmthlp,zhlp%data_r,zhlp%data_c,&
370
     &                 cmt(:,:,:),zmat(1)%l_real,zmat(ikpt0)%data_r(:,:),zmat(ikpt0)%data_c(:,:),ikpt0,iop,atoms,&
371
     &                 hybrid,kpts,sym,&
Daniel Wortmann's avatar
Daniel Wortmann committed
372
     &                 jsp,dimension,hybrid%nbands(ikpt0),&
Daniel Wortmann's avatar
Daniel Wortmann committed
373
     &                 cell,lapw(ikpt0),lapw(ikpt),.true.)
374

Daniel Wortmann's avatar
Daniel Wortmann committed
375
              call write_cmt(cmthlp,ikpt)
Daniel Wortmann's avatar
Daniel Wortmann committed
376
              call write_z(zhlp,ikpt)
377 378 379 380 381 382 383
          END IF
        END DO  !ikpt
      END DO !ikpt0

      DEALLOCATE( acof,bcof,ccof )
      DEALLOCATE( cmt,cmthlp)

Daniel Wortmann's avatar
Daniel Wortmann committed
384
     
385 386 387
      END SUBROUTINE gen_wavf

      END MODULE m_gen_wavf