checkolap.F90 12.8 KB
Newer Older
1 2 3 4
      MODULE m_checkolap

      CONTAINS

Daniel Wortmann's avatar
Daniel Wortmann committed
5 6 7
      SUBROUTINE checkolap(atoms,hybdat,&
     &                  hybrid,&
     &                  nkpti,kpts,&
8 9
     &                  dimension,mpi,irank2,skip_kpt,&
     &                  input,sym,noco,&
Daniel Wortmann's avatar
Daniel Wortmann committed
10
     &                  cell,lapw,jsp)
11 12 13 14
      USE m_util     , ONLY: intgrf,intgrf_init,chr,sphbessel,harmonicsr
      USE m_constants
      USE m_apws
      USE m_types
Daniel Wortmann's avatar
Daniel Wortmann committed
15
      USE m_io_hybrid
16 17
      IMPLICIT NONE

Daniel Wortmann's avatar
Daniel Wortmann committed
18 19
      TYPE(t_hybdat),INTENT(IN)   :: hybdat

20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
      TYPE(t_mpi),INTENT(IN)         :: mpi
      TYPE(t_dimension),INTENT(IN)   :: dimension
      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
      TYPE(t_lapw),INTENT(INOUT)     :: lapw

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


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

Daniel Wortmann's avatar
Daniel Wortmann committed
39
   
40 41 42 43
      LOGICAL, INTENT(IN)     ::  skip_kpt(nkpti)

      ! - local scalars -
      INTEGER                 ::  i,itype,iatom,ikpt,ineq,igpt,iband
Daniel Wortmann's avatar
Daniel Wortmann committed
44
      INTEGER                 ::  irecl_cmt
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
      INTEGER                 ::  j,m
      INTEGER                 ::  l
      INTEGER                 :: lm,lm1
      INTEGER                 ::  n,nred

      REAL                    ::  rdum,rdum1
      REAL                    ::  qnorm

      COMPLEX                 ::  cexp,cdum
      COMPLEX , PARAMETER     ::  img = (0d0,1d0)

      ! -local arrays -
      INTEGER                 ::  iarr(2),gpt(3)
      INTEGER                 ::  matind(dimension%nbasfcn,2)  
      INTEGER , ALLOCATABLE   ::  olapcv_loc(:,:,:,:,:)

      REAL                    ::  sphbes(0:atoms%lmaxd)
      REAL                    ::  q(3)
      REAL                    ::  integrand(atoms%jmtd)
      REAL                    ::  bkpt(3) 
Daniel Wortmann's avatar
Daniel Wortmann committed
65
      REAL                    ::  rarr(maxval(hybdat%nbands))
66 67 68
      REAL                    ::  rtaual(3)
      REAL    , ALLOCATABLE   ::  olapcb(:)
      REAL    , ALLOCATABLE   :: olapcv_avg(:,:,:,:),olapcv_max(:,:,:,:)
Daniel Wortmann's avatar
Daniel Wortmann committed
69
      TYPE(t_mat),ALLOCATABLE :: z(:)
70 71 72 73 74 75 76 77 78 79 80 81

      COMPLEX                 ::  cmt(dimension%neigd,hybrid%maxlmindx,atoms%nat,nkpti)
      COMPLEX                 ::  y((atoms%lmaxd+1)**2)
      COMPLEX , ALLOCATABLE   ::  olapcv(:,:),olapww(:,:)
      COMPLEX , ALLOCATABLE   ::  carr1(:,:),carr2(:,:),carr3(:,:)

      CHARACTER, PARAMETER    ::  lchar(0:38) =&
     &          (/'s','p','d','f','g','h','i','j','k','l','m','n','o',&
     &            'x','x','x','x','x','x','x','x','x','x','x','x','x',&
     &            'x','x','x','x','x','x','x','x','x','x','x','x','x' /)
      LOGICAL                 ::  l_mism = .true.

Daniel Wortmann's avatar
Daniel Wortmann committed
82 83 84 85 86
      ALLOCATE(z(nkpti))
      DO ikpt=1,nkpti
         call z(ikpt)%alloc(sym%invs,dimension%nbasfcn,dimension%neigd)
      ENDDO
      
87 88 89 90
      IF ( mpi%irank == 0 ) WRITE(6,'(//A)') '### checkolap ###'

      cmt = 0
    
Daniel Wortmann's avatar
Daniel Wortmann committed
91 92
      ! initialize gridf -> was done in eigen_HF_init
      !CALL intgrf_init(atoms%ntype,atoms%jmtd,atoms%jri,atoms%dx,atoms%rmsh,hybdat%gridf)
93 94 95 96 97 98

      ! read in cmt
      DO ikpt = 1,nkpti
#ifdef CPP_MPI
        IF ( skip_kpt(ikpt) ) CYCLE
#endif
Daniel Wortmann's avatar
Daniel Wortmann committed
99 100 101
        call read_cmt(cmt(:,:,:,ikpt),ikpt)
     END DO
     
102 103 104 105
      IF ( mpi%irank == 0 ) WRITE(6,'(/A)') ' Overlap <core|core>'
      DO itype=1,atoms%ntype
        IF(atoms%ntype.gt.1 .AND. mpi%irank==0) &
     &     WRITE(6,'(A,I3)') ' Atom type',itype
Daniel Wortmann's avatar
Daniel Wortmann committed
106 107
        DO l=0,hybdat%lmaxc(itype)
          DO i=1,hybdat%nindxc(l,itype)
108 109 110
            IF ( mpi%irank == 0 )&
     &        WRITE(6,'(1x,I1,A,2X)',advance='no') i+l,lchar(l)
            DO j=1,i
Daniel Wortmann's avatar
Daniel Wortmann committed
111 112
              integrand =  hybdat%core1(:,i,l,itype)*hybdat%core1(:,j,l,itype)&
     &                  +  hybdat%core2(:,i,l,itype)*hybdat%core2(:,j,l,itype)
113
              IF ( mpi%irank == 0 ) WRITE(6,'(F10.6)', advance='no')&
Daniel Wortmann's avatar
Daniel Wortmann committed
114
     &           intgrf(integrand,atoms%jri,atoms%jmtd,atoms%rmsh,atoms%dx,atoms%ntype,itype,hybdat%gridf)
115 116 117 118 119 120 121
            END DO
            IF ( mpi%irank == 0 ) WRITE(6,*)
          END DO 
        END DO
      END DO

      IF ( mpi%irank == 0 ) WRITE(6,'(/A)') ' Overlap <core|basis>'
Daniel Wortmann's avatar
Daniel Wortmann committed
122 123 124 125
      ALLOCATE( olapcb(hybrid%maxindx),olapcv(maxval(hybdat%nbands),nkpti),&
     &          olapcv_avg(  -hybdat%lmaxcd:hybdat%lmaxcd,hybdat%maxindxc,0:hybdat%lmaxcd,atoms%ntype),&
     &          olapcv_max(  -hybdat%lmaxcd:hybdat%lmaxcd,hybdat%maxindxc,0:hybdat%lmaxcd,atoms%ntype),&
     &          olapcv_loc(2,-hybdat%lmaxcd:hybdat%lmaxcd,hybdat%maxindxc,0:hybdat%lmaxcd,atoms%ntype) )
126 127 128 129

      DO itype=1,atoms%ntype
        IF(atoms%ntype.gt.1 .AND. mpi%irank==0) &
     &     WRITE(6,'(A,I3)') ' Atom type',itype
Daniel Wortmann's avatar
Daniel Wortmann committed
130
        DO l=0,hybdat%lmaxc(itype)
131 132 133 134
          IF(l.gt.atoms%lmax(itype)) EXIT ! very improbable case
          IF ( mpi%irank == 0 ) &
     &        WRITE(6,"(9X,'u(',A,')',4X,'udot(',A,')',:,3X,'ulo(',A,"//&
     &                "') ...')") (lchar(l),i=1,min(3,hybrid%nindx(l,itype)))
Daniel Wortmann's avatar
Daniel Wortmann committed
135
          DO i=1,hybdat%nindxc(l,itype)
136 137 138 139
            IF ( mpi%irank == 0 )&
     &        WRITE(6,'(1x,I1,A,2X)',advance='no') i+l,lchar(l)
            DO j=1,hybrid%nindx(l,itype)

Daniel Wortmann's avatar
Daniel Wortmann committed
140 141
              integrand = hybdat%core1(:,i,l,itype)*hybdat%bas1(:,j,l,itype)&
     &                  + hybdat%core2(:,i,l,itype)*hybdat%bas2(:,j,l,itype)
142 143

              olapcb(j) = &
Daniel Wortmann's avatar
Daniel Wortmann committed
144
     &              intgrf(integrand,atoms%jri,atoms%jmtd,atoms%rmsh,atoms%dx,atoms%ntype,itype,hybdat%gridf)
145 146 147 148 149 150 151 152 153 154 155 156

              IF ( mpi%irank == 0 )&
     &          WRITE(6,'(F10.6)',advance='no') olapcb(j)
            END DO

            lm    = sum ( (/ (hybrid%nindx(j,itype)*(2*j+1),j=0,l-1) /) )
            iatom = sum(atoms%neq(1:itype-1))+1 ! take first of group of equivalent atoms
            DO m=-l,l
              olapcv = 0
              DO j=1,hybrid%nindx(l,itype)
                lm = lm + 1
                olapcv(:,:) = olapcv(:,:) + &
Daniel Wortmann's avatar
Daniel Wortmann committed
157
     &                        olapcb(j)*cmt(:maxval(hybdat%nbands),lm,iatom,:nkpti)
158 159 160 161 162
              END DO
              rdum                      = sum    ( abs(olapcv(:,:))**2 )
              rdum1                     = maxval ( abs(olapcv(:,:))    )
              iarr                      = maxloc ( abs(olapcv(:,:))    )
              olapcv_avg(  m,i,l,itype) = &
Daniel Wortmann's avatar
Daniel Wortmann committed
163
     &                sqrt( rdum / nkpti / sum(hybdat%nbands(:nkpti)) * nkpti )
164 165 166 167 168 169 170 171 172 173 174 175 176
              olapcv_max(  m,i,l,itype) = rdum1
              olapcv_loc(:,m,i,l,itype) = iarr
            END DO
            IF ( mpi%irank == 0 ) WRITE(6,*)

          END DO
        END DO
      END DO

      IF( mpi%irank == 0 ) THEN
        WRITE(6,'(/A)') ' Average overlap <core|val>'
        DO itype=1,atoms%ntype
          IF(atoms%ntype.gt.1) write(6,'(A,I3)') ' Atom type',itype
Daniel Wortmann's avatar
Daniel Wortmann committed
177 178
          DO l=0,hybdat%lmaxc(itype)
            DO i=1,hybdat%nindxc(l,itype)
179 180 181 182 183 184 185 186 187 188
              WRITE(6,'(1x,I1,A,2X)',advance='no') i+l,lchar(l)
              WRITE(6,'('//chr(2*l+1)//'F10.6)') &
     &                                        olapcv_avg(-l:l,i,l,itype)
            END DO
          END DO
        END DO

        WRITE(6,'(/A)') ' Maximum overlap <core|val> at (band/kpoint)'
        DO itype=1,atoms%ntype
          IF(atoms%ntype.gt.1) write(6,'(A,I3)') ' Atom type',itype
Daniel Wortmann's avatar
Daniel Wortmann committed
189 190
          DO l=0,hybdat%lmaxc(itype)
            DO i=1,hybdat%nindxc(l,itype)
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 217 218 219 220
              WRITE(6,'(1x,I1,A,2X)',advance='no') i+l,lchar(l)
              WRITE(6,'('//chr(2*l+1)//&
     &                 '(F10.6,'' ('',I3.3,''/'',I4.3,'')''))')&
     &                          (olapcv_max(  m,i,l,itype),&
     &                           olapcv_loc(:,m,i,l,itype),m=-l,l)
            END DO
          END DO
        END DO
      END IF ! mpi%irank == 0

      DEALLOCATE (olapcb,olapcv,olapcv_avg,olapcv_max,olapcv_loc)

      IF ( mpi%irank == 0 ) WRITE(6,'(/A)') ' Overlap <basis|basis>'

      DO itype=1,atoms%ntype
        IF(atoms%ntype.gt.1 .AND. mpi%irank==0) &
     &     WRITE(6,'(A,I3)') ' Atom type',itype
        DO l=0,atoms%lmax(itype)
          DO i=1,hybrid%nindx(l,itype)
            IF ( mpi%irank == 0 ) THEN
              SELECT CASE(i)
               CASE(1)
                 WRITE(6,'(1x,''   u('',A,'')'')',advance='no') lchar(l)
               CASE(2)
                 WRITE(6,'(1x,''udot('',A,'')'')',advance='no') lchar(l)
               CASE DEFAULT
                 WRITE(6,'(1x,'' ulo('',A,'')'')',advance='no') lchar(l)
              END SELECT
            END IF
            DO j=1,i
Daniel Wortmann's avatar
Daniel Wortmann committed
221 222
              integrand = hybdat%bas1(:,i,l,itype)*hybdat%bas1(:,j,l,itype)&
     &                  + hybdat%bas2(:,i,l,itype)*hybdat%bas2(:,j,l,itype)
223 224

              IF ( mpi%irank == 0 ) WRITE(6,'(F10.6)',advance='no')&
Daniel Wortmann's avatar
Daniel Wortmann committed
225
     &              intgrf(integrand,atoms%jri,atoms%jmtd,atoms%rmsh,atoms%dx,atoms%ntype,itype,hybdat%gridf)
226 227 228 229 230 231 232 233 234 235
            END DO
            IF ( mpi%irank == 0 ) WRITE(6,*)
          END DO
        END DO
      END DO

      IF( .not. l_mism ) RETURN

      IF ( mpi%irank == 0 ) WRITE(6,'(/A)') &
     &          'Mismatch of wave functions at the MT-sphere boundaries'
Daniel Wortmann's avatar
Daniel Wortmann committed
236 237 238
      ALLOCATE (carr1(maxval(hybdat%nbands),(atoms%lmaxd+1)**2))
      ALLOCATE (carr2(maxval(hybdat%nbands),(atoms%lmaxd+1)**2))
      ALLOCATE (carr3(maxval(hybdat%nbands),(atoms%lmaxd+1)**2))
239
      DO ikpt = 1,nkpti
Daniel Wortmann's avatar
Daniel Wortmann committed
240
         call read_z(z(ikpt),ikpt)
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
      END DO

      iatom = 0
      DO itype = 1,atoms%ntype
        DO ineq = 1,atoms%neq(itype)
          iatom = iatom + 1
          IF ( mpi%irank == 0 ) THEN
            if(atoms%nat.gt.1) WRITE(6,'(2X,A,I3)') 'Atom',iatom
            WRITE(6,'(2X,A)') 'k-point    average      (   maximum    )'
          END IF

          DO ikpt = 1,nkpti
#ifdef CPP_MPI
            IF ( skip_kpt(ikpt) ) CYCLE
#endif
            carr1 = 0; carr2 = 0; carr3 = 0

            ! calculate k1,k2,k3
            CALL apws(dimension,input,noco,&
     &                kpts,ikpt,cell,&
     &                sym%zrfs,1,jsp,bkpt,lapw,&
     &                matind,nred)

            ! PW part
            DO igpt = 1,lapw%nv(jsp)
              gpt(1) = lapw%k1(igpt,jsp)
              gpt(2) = lapw%k2(igpt,jsp)
              gpt(3) = lapw%k3(igpt,jsp)

              cexp = exp(img * 2*pi_const * &
     &                   dot_product(kpts%bkf(:,ikpt)+gpt,atoms%taual(:,iatom)) )
              q    = matmul(kpts%bkf(:,ikpt)+gpt,cell%bmat)

              qnorm = sqrt(sum(q**2))
              call sphbessel(sphbes,atoms%rmt(itype)*qnorm,atoms%lmax(itype))
              call harmonicsr(y,q,atoms%lmax(itype))
              y  = conjg(y)
              lm = 0
              DO l = 0,atoms%lmax(itype)
                cdum = 4*pi_const*img**l/sqrt(cell%omtil) * sphbes(l) * cexp
                DO m = -l,l
                  lm = lm + 1
Daniel Wortmann's avatar
Daniel Wortmann committed
283
                  DO iband = 1,hybdat%nbands(ikpt)
Daniel Wortmann's avatar
Daniel Wortmann committed
284 285 286 287 288 289
                     if (z(1)%l_real) THEN
                        carr2(iband,lm) = carr2(iband,lm) + cdum * z(ikpt)%data_r(igpt,iband) * y(lm)
                     Else
                        carr2(iband,lm) = carr2(iband,lm) + cdum * z(ikpt)%data_c(igpt,iband) * y(lm)
                     END if
                  end DO
290 291 292 293 294 295 296 297 298 299 300 301
                END DO
              END DO
            END DO

            ! MT
            lm  = 0
            lm1 = 0
            DO l = 0,atoms%lmax(itype)
              DO m = -l,l
                lm = lm + 1
                DO n = 1,hybrid%nindx(l,itype)
                  lm1  = lm1 + 1
Daniel Wortmann's avatar
Daniel Wortmann committed
302 303
                  rdum = hybdat%bas1(atoms%jri(itype),n,l,itype) / atoms%rmt(itype)
                  DO iband = 1,hybdat%nbands(ikpt)
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
                    carr3(iband,lm) = carr3(iband,lm) + cmt(iband,lm1,iatom,ikpt) * rdum
                  END DO
                END DO
              END DO
            END DO
            carr1 = carr2 - carr3

            rarr = 0
            lm   = 0
            DO l = 0,atoms%lmax(itype)
              DO m = -l,l
                lm   = lm + 1
                rarr = rarr + abs(carr1(:,lm))**2
              END DO
            END DO
            rarr = sqrt ( rarr / (4*pi_const) )
 !           IF ( irank2(ikpt) == 0 ) THEN
 !             WRITE(outtext,'(I6,4X,F14.12,''  ('',F14.12,'')'')') &
 !    &              ikpt,sum(rarr(:1)**2/nbands(ikpt)),maxval(rarr(:1))
 !             CALL writeout(outtext,mpi%irank)
 !           END IF
!             IF( iatom .eq. 6 ) THEN
!               cdum = exp(2*pi*img*dot_product(bkf(:,ikpt),(/0d0,0d0,1d0/) ))
!               lm = 0 
!               DO l = 0,lmax(itype)
!                 DO m = -l,l
!                   lm = lm + 1
!                   DO iband = 1,nbands(ikpt)
!                     WRITE(700+ikpt,'(3i4,6f15.10)') iband,l,m,carr2(iband,lm),carr3(iband,lm),
!      &                                              carr2(iband,lm)/(carr3(iband,lm))
!                   END DO
!                 END DO
!               END DO
!             END IF

          END DO
        END DO
      END DO


      END SUBROUTINE checkolap

      END MODULE m_checkolap