hsfock.F90 11.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
MODULE m_hsfock
  USE m_judft
! c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c
!     This module is the driver routine for the calculation of the Hartree    c
!     Fock exchange term by using the mixed basis set.                        c
!                                                                             c
!     hsfock                                                                  c
!         |                                                                   c
!         |- symm.F:                                                          c
!         |  calculates the irreducible representation                        c
!         |                                                                   c
!         |- wavefproducts.F:                 s      s*                       c
!         |  computes the repsentation of phi    phi       in the mixed basis c
!         |                                  n,k    n',k+q                    c
!         |                                                                   c
!         |- exchange.F:                                                      c
!         |  calculates valence-valence part of the exchange matrix (mat_ex), c
!         |                                                                   c
!         |- exchange_core.F                                                  c
!         |  calculate valence-core contribution                              c
!                                                                             c
!     variables:                                                              c
Daniel Wortmann's avatar
Daniel Wortmann committed
23 24
!         kpts%nkptf   :=   number of kpoints                                      c
!         kpts%nkpt   :=   number of irreducible kpoints                          c
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
!         nbands  :=   number of bands for which the exchange matrix (mat_ex) c
!                      in the space of the wavefunctions is calculated        c
!         te_hfex :=   hf exchange contribution to the total energy           c
!         mnobd   :=   maximum number of occupied bands                       c
!         parent  :=   parent(ikpt) points to the symmetry equivalent point   c
!                      under the little group of kpoint nk                    c
!         symop   :=   symop(ikpt) points to the symmetry operation, which    c
!                      maps parent(ikpt) on ikpt                              c
!                                                                             c
!                                                                             c
!                                               M.Betzinger (09/07)           c
! c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c
      CONTAINS

      SUBROUTINE hsfock(&
Daniel Wortmann's avatar
Daniel Wortmann committed
40
     &             nk,atoms,hybrid,lapw,dimension,&
Daniel Wortmann's avatar
Daniel Wortmann committed
41
     &             kpts,jsp,input,&
Daniel Wortmann's avatar
Daniel Wortmann committed
42
     &             hybdat,&
Daniel Wortmann's avatar
Daniel Wortmann committed
43 44
     &             eig_irr,sym,&
     &             cell,noco,&
45
     &             results,&
Daniel Wortmann's avatar
Daniel Wortmann committed
46
     &             it,mnobd,&
47
     &             xcpot,&
Daniel Wortmann's avatar
Daniel Wortmann committed
48
     &             mpi,irank2,isize2,comm)
49 50 51 52 53 54 55 56 57

      USE m_symm_hf       ,ONLY: symm_hf
      USE m_util          ,ONLY: intgrf,intgrf_init
      USE m_exchange_valence_hf
      USE m_exchange_core
      USE m_symmetrizeh
      USE m_wrapper
      USE m_hsefunctional ,ONLY: exchange_vccvHSE,exchange_ccccHSE
      USE m_types
Daniel Wortmann's avatar
Daniel Wortmann committed
58
      USE m_io_hybrid
59
      IMPLICIT NONE
Daniel Wortmann's avatar
Daniel Wortmann committed
60
      TYPE(t_hybdat),INTENT(IN)       :: hybdat
61
      TYPE(t_results),INTENT(INOUT)   :: results
Daniel Wortmann's avatar
Daniel Wortmann committed
62 63 64 65 66 67 68 69 70 71 72
      TYPE(t_xcpot),INTENT(IN)        :: xcpot
      TYPE(t_mpi),INTENT(IN)          :: mpi
      TYPE(t_dimension),INTENT(IN)    :: dimension
      TYPE(t_hybrid),INTENT(INOUT)    :: 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(IN)         :: lapw
73 74 75 76 77

!     - scalars -
      INTEGER,INTENT(IN)      :: jsp 
      INTEGER,INTENT(IN)      :: it
      INTEGER,INTENT(IN)      :: irank2 ,isize2,comm
Daniel Wortmann's avatar
Daniel Wortmann committed
78 79
      INTEGER,INTENT(IN)      :: nk
      INTEGER,INTENT(IN)      :: mnobd
Daniel Wortmann's avatar
Daniel Wortmann committed
80
    
81 82

      !     -  arrays -
Daniel Wortmann's avatar
Daniel Wortmann committed
83
      REAL,INTENT(IN)         ::  eig_irr(dimension%neigd,kpts%nkpt)
Daniel Wortmann's avatar
Daniel Wortmann committed
84
      
Daniel Wortmann's avatar
Daniel Wortmann committed
85
     
86 87 88
  

!     - local scalars -
Daniel Wortmann's avatar
Daniel Wortmann committed
89
      INTEGER                 ::  i,j,ic,ic1,l,itype,n,nn
90 91 92 93 94
      INTEGER                 ::  iband,iband1,iband2
      INTEGER                 ::  ikpt,ikpt0
      INTEGER                 ::  irec
      INTEGER                 ::  irecl_olap,irecl_z,irecl_vx
      INTEGER                 ::  maxndb
Daniel Wortmann's avatar
Daniel Wortmann committed
95
      INTEGER                 ::  nddb
96 97 98 99 100 101 102 103
      INTEGER                 ::  nsymop
      INTEGER                 ::  nkpt_EIBZ
      INTEGER                 ::  ncstd
      INTEGER                 ::  ok

      REAL                    ::  a_ex
!     - local arrays -
      INTEGER                 ::  gpt(3,lapw%nv(jsp))
Daniel Wortmann's avatar
Daniel Wortmann committed
104 105
      INTEGER                 ::  degenerat(hybrid%ne_eig(nk))
      INTEGER                 ::  nsest(hybrid%nbands(nk)),indx_sest(hybrid%nbands(nk),hybrid%nbands(nk))
106 107 108 109 110 111 112

      INTEGER,ALLOCATABLE     ::  parent(:),symop(:)
      INTEGER,ALLOCATABLE     ::  psym(:)
      INTEGER,ALLOCATABLE     ::  pointer_EIBZ(:)
      INTEGER,ALLOCATABLE     ::  n_q(:)

      REAL                    ::  wl_iks(dimension%neigd,kpts%nkptf)
113
    
Daniel Wortmann's avatar
Daniel Wortmann committed
114
      TYPE(t_mat)             :: olap,trafo,invtrafo,ex,tmp,v_x,z
115 116 117 118 119 120 121 122 123 124 125 126 127 128
      COMPLEX                 ::  exch(dimension%neigd,dimension%neigd)
      COMPLEX,ALLOCATABLE     ::  carr(:)
      COMPLEX,ALLOCATABLE     ::  rep_c(:,:,:,:,:)

      
      CALL timestart("total time hsfock")
      CALL timestart("symm_hf")
    

      !
      ! preparations
      !
      
      ! initialize gridf for radial integration
Daniel Wortmann's avatar
Daniel Wortmann committed
129
      !CALL intgrf_init(atoms%ntype,atoms%jmtd,atoms%jri,atoms%dx,atoms%rmsh,hybdat%gridf)
130 131 132 133

      !
      ! initialize weighting factor for HF exchange part
      !
134
      a_ex=xcpot%get_exchange_weight()
135 136 137 138


      ! write k1,k2,k3 in gpt
      DO i=1,lapw%nv(jsp)
Daniel Wortmann's avatar
Daniel Wortmann committed
139
        gpt(:,i) = (/lapw%k1(i,jsp),lapw%k2(i,jsp),lapw%k3(i,jsp)/)
140 141
      END DO

Daniel Wortmann's avatar
Daniel Wortmann committed
142
      
143
      ! read in lower triangle part of overlap matrix from direct acces file olap
Daniel Wortmann's avatar
Daniel Wortmann committed
144
      call olap%alloc(sym%invs,dimension%nbasfcn)
Daniel Wortmann's avatar
Daniel Wortmann committed
145 146
      call read_olap(olap, kpts%nkpt*(jsp-1) + nk)
      if (.not.olap%l_real) olap%data_c=conjg(olap%data_c)
147 148

      IF( hybrid%l_calhf ) THEN
Daniel Wortmann's avatar
Daniel Wortmann committed
149 150
        ncstd = sum( (/ ( (hybdat%nindxc(l,itype)*(2*l+1)*atoms%neq(itype),&
     &             l=0,hybdat%lmaxc(itype)), itype = 1,atoms%ntype) /) )
151 152 153 154 155 156 157 158 159 160
        IF( nk .eq. 1 .and. mpi%irank == 0 )&
     &      WRITE(*,*) 'calculate new HF matrix'
        IF( nk .eq. 1 .and. jsp .eq. 1 .and. input%imix .gt. 10)&
     &      CALL system('rm -f broyd*')
        ! calculate all symmetrie operations, which yield k invariant

        ALLOCATE( parent(kpts%nkptf),symop(kpts%nkptf) ,stat=ok)
        IF( ok .ne. 0 ) STOP 'mhsfock: failure allocation parent/symop'
        parent = 0 ; symop = 0

Daniel Wortmann's avatar
Daniel Wortmann committed
161
        CALL symm_hf( kpts,nk,sym,&
Daniel Wortmann's avatar
Daniel Wortmann committed
162 163
     &             dimension,hybdat,eig_irr,&
     &             atoms,hybrid,cell,&
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
     &             lapw,jsp,&
     &             gpt,&
     &             mpi,irank2,&
     &             nsymop,psym,nkpt_EIBZ,n_q,parent,&
     &             symop,degenerat,pointer_EIBZ,maxndb,nddb,&
     &             nsest,indx_sest,rep_c)

        CALL timestop("symm_hf")
        ! remove weights(wtkpt) in w_iks
        DO ikpt=1,kpts%nkptf
          DO iband=1,dimension%neigd
            ikpt0 = kpts%bkp(ikpt)
            wl_iks(iband,ikpt) = results%w_iks(iband,ikpt0,jsp) /&
     &                           ( kpts%wtkpt(ikpt0) * kpts%nkptf )
          END DO
        END DO

        !
        ! calculate contribution from valence electrons to the
        ! HF exchange
        CALL timestart("valence exchange calculation")

Daniel Wortmann's avatar
Daniel Wortmann committed
186
        ex%l_real=sym%invs
Daniel Wortmann's avatar
Daniel Wortmann committed
187
        CALL exchange_valence_hf(& 
Daniel Wortmann's avatar
Daniel Wortmann committed
188
     &            nk,kpts,nkpt_EIBZ, sym,atoms,hybrid,&
Daniel Wortmann's avatar
Daniel Wortmann committed
189
     &            cell, dimension,input,jsp, hybdat, mnobd, lapw,&
190
     &            eig_irr,results,parent,pointer_EIBZ,n_q,wl_iks,&
Daniel Wortmann's avatar
Daniel Wortmann committed
191
     &            it,xcpot,&
192 193
     &            noco,nsest,indx_sest,&
     &            mpi,irank2,isize2,comm,&
194
     &            ex)
195
       
196 197 198 199 200 201 202 203 204 205

        DEALLOCATE ( rep_c )
        CALL timestop("valence exchange calculation")

        CALL timestart("core exchange calculation")
        ! do the rest of the calculation only on master
        IF ( irank2 /= 0 ) RETURN

  
        ! calculate contribution from the core states to the HF exchange
206
        IF ( xcpot%is_name("hse") .OR. xcpot%is_name("vhse") ) THEN
207 208
#ifdef CPP_NEVER           
          CALL exchange_vccvHSE(&
Daniel Wortmann's avatar
Daniel Wortmann committed
209
     &                 nk,atoms,&
Daniel Wortmann's avatar
Daniel Wortmann committed
210 211 212 213 214
     &                 hybrid,hybdat,&
     &                 dimension,jsp,&
     &                 lapw,&
     &                 nsymop,nsest,indx_sest,mpi,&
     &                 a_ex,results,&
215 216
     &                 mat_ex%core )
          CALL exchange_ccccHSE(&
Daniel Wortmann's avatar
Daniel Wortmann committed
217
     &                 nk,obsolete,atoms,hybdat,&
Daniel Wortmann's avatar
Daniel Wortmann committed
218 219 220
     &                 ncstd,&
     &                 kpts(:,nk),&
     &                 sym,a_ex,mpi,&
221 222 223 224 225
     &                 results%core )
#endif
          STOP "HSE not implemented in hsfock"
        ELSE
          CALL exchange_vccv1(&
Daniel Wortmann's avatar
Daniel Wortmann committed
226
     &                 nk,atoms,&
Daniel Wortmann's avatar
Daniel Wortmann committed
227 228 229 230 231
     &                 hybrid,hybdat,&
     &                 dimension,jsp,&
     &                 lapw,&
     &                 nsymop,nsest,indx_sest,mpi,&
     &                 a_ex,results,&
Daniel Wortmann's avatar
Daniel Wortmann committed
232
     &                 ex)
233
          CALL exchange_cccc(&
Daniel Wortmann's avatar
Daniel Wortmann committed
234
     &                 nk,atoms,hybdat,&
Daniel Wortmann's avatar
Daniel Wortmann committed
235
     &                 ncstd,&
236 237 238 239 240 241 242 243 244
     &                 sym,kpts,a_ex,mpi,&
     &                 results )
        END IF

        DEALLOCATE( n_q )
        CALL timestop("core exchange calculation")

        CALL timestart("time for performing T^-1*mat_ex*T^-1*")
        !calculate trafo from wavefunctions to APW basis
Daniel Wortmann's avatar
Daniel Wortmann committed
245
        IF( dimension%neigd .lt. hybrid%nbands(nk) ) STOP 'mhsfock: neigd  < nbands(nk) ; &&
Daniel Wortmann's avatar
Daniel Wortmann committed
246
     &trafo from wavefunctions to APW requires at least nbands(nk) '
247

Daniel Wortmann's avatar
Daniel Wortmann committed
248
        call z%alloc(olap%l_real,dimension%nbasfcn,dimension%neigd)
249

Daniel Wortmann's avatar
Daniel Wortmann committed
250 251
        call read_z(z,nk) !what about spin?
      
252 253
        ! calculate trafo
        ic = lapw%nv(jsp) + atoms%nlotot
Daniel Wortmann's avatar
Daniel Wortmann committed
254
        z%matsize1=ic
Daniel Wortmann's avatar
Daniel Wortmann committed
255
        z%matsize2=hybrid%nbands(nk)
Daniel Wortmann's avatar
Daniel Wortmann committed
256 257 258 259 260
        olap%matsize1=ic
        olap%matsize2=ic
        
        call olap%multiply(z,trafo)
        
Daniel Wortmann's avatar
Daniel Wortmann committed
261
        call invtrafo%alloc(olap%l_real,hybrid%nbands(nk),ic)
262 263 264 265 266 267 268 269 270 271 272 273
        CALL trafo%TRANSPOSE(invtrafo)
       
        DO i=1,hybrid%nbands(nk)
           DO j=1,i-1
              IF (ex%l_real) THEN
                 ex%data_r(i,j)=ex%data_r(j,i)
              ELSE
                 ex%data_c(i,j)=conjg(ex%data_c(j,i))
              END IF
           ENDDO
        ENDDO

Daniel Wortmann's avatar
Daniel Wortmann committed
274 275 276 277
        
        CALL ex%multiply(invtrafo,tmp)
        CALL trafo%multiply(tmp,v_x)
        
278 279
        CALL timestop("time for performing T^-1*mat_ex*T^-1*")

280
        
281
        CALL symmetrizeh(atoms,&
Daniel Wortmann's avatar
Daniel Wortmann committed
282
     &                   kpts%bkf(:,nk),dimension,jsp,lapw,gpt,&
Daniel Wortmann's avatar
Daniel Wortmann committed
283
     &                   sym,hybdat%kveclo_eig,&
284 285 286 287 288
     &                   cell,nsymop,psym,&
     &                   v_x )



Daniel Wortmann's avatar
Daniel Wortmann committed
289 290
          CALL write_v_x(v_x,kpts%nkpt*(jsp-1) + nk)
     END IF ! hybrid%l_calhf
Daniel Wortmann's avatar
Daniel Wortmann committed
291
     
Daniel Wortmann's avatar
Daniel Wortmann committed
292 293 294
  
       
       
295 296 297 298 299 300
      CALL timestop("total time hsfock")

      END SUBROUTINE hsfock


      END MODULE m_hsfock