eigen.F90 8.53 KB
Newer Older
1 2 3 4 5
!--------------------------------------------------------------------------------
! 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.
!--------------------------------------------------------------------------------
Daniel Wortmann's avatar
Daniel Wortmann committed
6 7 8
!<@brief
!<The eigen routine sets up and solves the generalized eigenvalue problem
!More description at end of file
9
MODULE m_eigen
10
  USE m_juDFT
11
CONTAINS
Daniel Wortmann's avatar
Daniel Wortmann committed
12 13 14 15 16 17 18 19
  !>The eigenvalue problem is constructed and solved in this routine. The following steps are performed:
  !> 1. Preparation: generate energy parameters, open eig-file
  !> 2. CALL to mt_setup() : this constructs the local Hamiltonian (i.e. the Hamiltonian in the \f$ u,\dot u, u_{lo} \f$ basis) LDA+U is also added here
  !> 3. within the (collinear)spin and k-point loop: CALL to eigen_hssetup() to generate the matrices, CALL to eigen_diag() to perform diagonalization 
  !> 4. writing (saving) of eigenvectors
  !>
  !> The matrices generated and diagonalized here are of type m_mat as defined in m_types_mat. 
  !>@author D. Wortmann
20
  SUBROUTINE eigen(mpi,stars,sphhar,atoms,obsolete,xcpot,&
21
       sym,kpts,DIMENSION, vacuum, input, cell, enpara_in,banddos, noco,jij, oneD,hybrid,&
Daniel Wortmann's avatar
Daniel Wortmann committed
22 23
       it,eig_id,results,v,vx)
    USE m_constants, ONLY : pi_const,sfp_const
24 25
    USE m_types
    USE m_lodpot
Daniel Wortmann's avatar
Daniel Wortmann committed
26
  
27
    USE m_apws
Daniel Wortmann's avatar
Daniel Wortmann committed
28 29
    USE m_eigen_hssetup
    USE m_pot_io
30
    USE m_eigen_diag
Daniel Wortmann's avatar
Daniel Wortmann committed
31
    USE m_add_vnonlocal
32
    USE m_subvxc
Daniel Wortmann's avatar
Daniel Wortmann committed
33
    !USE m_hsefunctional
Daniel Wortmann's avatar
Daniel Wortmann committed
34
    USE m_mt_setup
35
    USE m_util
Daniel Wortmann's avatar
Daniel Wortmann committed
36 37
    USE m_io_hybrid
    !USE m_icorrkeys
38
    USE m_eig66_io, ONLY : open_eig, write_eig, close_eig,read_eig
39
    USE m_xmlOutput
Daniel Wortmann's avatar
Daniel Wortmann committed
40 41 42
#ifdef CPP_MPI
    USE m_mpi_bc_pot
#endif
43 44 45 46 47

    IMPLICIT NONE
    TYPE(t_results),INTENT(INOUT):: results
    TYPE(t_xcpot),INTENT(IN)     :: xcpot
    TYPE(t_mpi),INTENT(IN)       :: mpi
48
    TYPE(t_dimension),INTENT(IN) :: DIMENSION
49
    TYPE(t_oneD),INTENT(IN)      :: oneD
50
    TYPE(t_hybrid),INTENT(INOUT) :: hybrid
51 52 53 54 55
    TYPE(t_enpara),INTENT(INOUT) :: enpara_in
    TYPE(t_obsolete),INTENT(IN)  :: obsolete
    TYPE(t_input),INTENT(IN)     :: input
    TYPE(t_vacuum),INTENT(IN)    :: vacuum
    TYPE(t_noco),INTENT(IN)      :: noco
56
    TYPE(t_banddos),INTENT(IN)   :: banddos
57
    TYPE(t_jij),INTENT(IN)       :: jij
Daniel Wortmann's avatar
Daniel Wortmann committed
58
    TYPE(t_sym),INTENT(IN)       :: sym  
59 60 61 62
    TYPE(t_stars),INTENT(IN)     :: stars
    TYPE(t_cell),INTENT(IN)      :: cell
    TYPE(t_kpts),INTENT(IN)      :: kpts
    TYPE(t_sphhar),INTENT(IN)    :: sphhar
Daniel Wortmann's avatar
Daniel Wortmann committed
63 64
    TYPE(t_atoms),INTENT(INOUT)  :: atoms!in u_setup n_u might be modified
    TYPE(t_potden),INTENT(INOUT) :: v,vx
65 66 67 68 69
#ifdef CPP_MPI
    INCLUDE 'mpif.h'
#endif
    !     ..
    !     .. Scalar Arguments ..
70
    INTEGER,INTENT(IN) :: it
71 72 73 74 75 76
    INTEGER,INTENT(INOUT):: eig_id
    !     ..
    !-odim
    !+odim
    !     ..
    !     .. Local Scalars ..
77
    INTEGER jsp,nk,nred,ne_all,ne_found
Daniel Wortmann's avatar
Daniel Wortmann committed
78 79
    INTEGER ne  ,lh0
    INTEGER isp,i,j,err
Daniel Wortmann's avatar
Daniel Wortmann committed
80
    LOGICAL l_wu,l_file,l_real,l_zref
81
    
82 83
    !     ..
    !     .. Local Arrays ..
Daniel Wortmann's avatar
Daniel Wortmann committed
84
    INTEGER, PARAMETER :: lmaxb=3
85
    REAL,    ALLOCATABLE :: bkpt(:)
86
    REAL,    ALLOCATABLE :: eig(:)
87

Daniel Wortmann's avatar
Daniel Wortmann committed
88
    COMPLEX, ALLOCATABLE :: vs_mmp(:,:,:,:)
89 90 91
    TYPE(t_tlmplm)  :: td
    TYPE(t_usdus)   :: ud
    TYPE(t_lapw)    :: lapw
92
    TYPE(t_enpara)  :: enpara
Daniel Wortmann's avatar
Daniel Wortmann committed
93 94
    CLASS(t_Mat),ALLOCATABLE    :: zMat
    CLASS(t_mat),ALLOCATABLE    :: hmat,smat
Daniel Wortmann's avatar
Daniel Wortmann committed
95
    TYPE(T_mat)     :: olap
96
    !
Daniel Wortmann's avatar
Daniel Wortmann committed
97
    INTEGER nn,n
98 99
    INTEGER ierr(3)

Daniel Wortmann's avatar
Daniel Wortmann committed
100

101 102
    !     .. variables for HF or hybrid functional calculation ..
    !
103
    INTEGER                 ::  comm(kpts%nkpt),irank2(kpts%nkpt),isize2(kpts%nkpt)
Daniel Wortmann's avatar
Daniel Wortmann committed
104
    
105 106
    !
    !
107
    ! --> Allocate
108
    !
Daniel Wortmann's avatar
Daniel Wortmann committed
109 110
    call ud%init(atoms,DIMENSION%jspd)
    ALLOCATE ( eig(DIMENSION%neigd),bkpt(3) )
Daniel Wortmann's avatar
Daniel Wortmann committed
111
   
112 113
    !
    ! --> some parameters first
Daniel Wortmann's avatar
Daniel Wortmann committed
114
    
Daniel Wortmann's avatar
Daniel Wortmann committed
115 116
    l_real=sym%invs.AND..NOT.noco%l_noco
    !check if z-reflection trick can be used
117

Daniel Wortmann's avatar
Daniel Wortmann committed
118 119 120 121 122 123 124 125
    l_zref=(sym%zrfs.AND.(SUM(ABS(kpts%bk(3,:kpts%nkpt))).LT.1e-9).AND..NOT.noco%l_noco) 
    IF (mpi%n_size > 1) l_zref = .FALSE.
 
#ifdef CPP_MPI
    CALL mpi_bc_pot(mpi,stars,sphhar,atoms,input,vacuum,&
                    v%iter,v%mt,v%pw,v%vacz,v%vacxy)
#endif
    IF (mpi%irank.EQ.0) CALL openXMLElementFormPoly('iteration',(/'numberForCurrentRun','overallNumber      '/),(/it,v%iter/),&
126
                                                    RESHAPE((/19,13,5,5/),(/2,2/)))
Daniel Wortmann's avatar
Daniel Wortmann committed
127
   
128 129 130
    !
    ! set energy parameters (normally to that, what we read in)
    !
Daniel Wortmann's avatar
Daniel Wortmann committed
131
    CALL lodpot(mpi,atoms,sphhar,obsolete,vacuum,&
Daniel Wortmann's avatar
Daniel Wortmann committed
132
            input, v%mt,v%vacz, enpara_in, enpara)
133
    !
Daniel Wortmann's avatar
Daniel Wortmann committed
134 135
    
     eig_id=open_eig(&
136
          mpi%mpi_comm,DIMENSION%nbasfcn,DIMENSION%neigd,kpts%nkpt,DIMENSION%jspd,atoms%lmaxd,&
137 138 139
         atoms%nlod,atoms%ntype,atoms%nlotot,noco%l_noco,.TRUE.,l_real,noco%l_soc,.FALSE.,&
         mpi%n_size,layers=vacuum%layers,nstars=vacuum%nstars,ncored=DIMENSION%nstd,&
         nsld=atoms%nat,nat=atoms%nat,l_dos=banddos%dos.OR.input%cdinf,l_mcd=banddos%l_mcd,&
140
         l_orb=banddos%l_orb)
Daniel Wortmann's avatar
Daniel Wortmann committed
141 142 143 144 145 146 147 148
     !
     !---> set up and solve the eigenvalue problem
     !--->    loop over spins
     !--->       set up k-point independent t(l'm',lm) matrices
     !
     CALL mt_setup(atoms,sym,sphhar,input,noco,enpara,v,mpi,results,DIMENSION,td,ud)
   
    DO jsp = 1,MERGE(1,input%jspins,noco%l_noco)
Daniel Wortmann's avatar
Daniel Wortmann committed
149
       k_loop:DO nk = mpi%n_start,kpts%nkpt,mpi%n_stride
150 151 152

          !
          !--->         set up lapw list
Daniel Wortmann's avatar
Daniel Wortmann committed
153 154 155 156 157 158 159
        
          CALL lapw%init(input,noco, kpts,atoms,sym,nk,cell,l_zref, mpi)
          call timestart("Setup of H&S matrices")
          CALL eigen_hssetup(jsp,mpi,DIMENSION,hybrid,enpara,input,vacuum,noco,jij,sym,&
               stars,cell,sphhar,atoms,ud,td,v,lapw,l_real,smat,hmat)
          CALL timestop("Setup of H&S matrices")
        
160
          IF( hybrid%l_hybrid ) THEN
Daniel Wortmann's avatar
Daniel Wortmann committed
161 162
             !write overlap matrix b to direct access file olap
             print *,"Wrong overlap matrix used, fix this later"
Daniel Wortmann's avatar
Daniel Wortmann committed
163 164
             !call write_olap(smat,nrec)
             STOP "TODO"
165
             PRINT *,"BASIS:",lapw%nv(jsp),atoms%nlotot
Daniel Wortmann's avatar
Daniel Wortmann committed
166
             !if (hybrid%l_addhf) CALL add_Vnonlocal(nk,hybrid,dimension, kpts,jsp,results,xcpot,hamovlp)
Daniel Wortmann's avatar
Daniel Wortmann committed
167 168
             
             
169
             IF( hybrid%l_subvxc ) THEN
Daniel Wortmann's avatar
Daniel Wortmann committed
170 171 172
                !CALL subvxc(lapw,kpts%bk(:,nk),DIMENSION,input,jsp,v%mt(:,0,:,:),atoms,ud,hybrid,enpara%el0,enpara%ello0,&
                 !    sym, atoms%nlotot,kveclo, cell,sphhar, stars, xcpot,mpi,&
                 !    oneD,  hamovlp,vx)
173 174
             END IF

175
          END IF ! hybrid%l_hybrid
Daniel Wortmann's avatar
Daniel Wortmann committed
176 177 178 179 180
          l_wu=.FALSE.
          ne_all=DIMENSION%neigd
          if (allocated(zmat)) deallocate(zmat)
          CALL eigen_diag(hmat,smat,ne_all,eig,zMat)
          DEALLOCATE(hmat,smat)
181 182 183 184 185 186
          !
          !--->         output results
          !
          CALL timestart("EV output")
#if defined(CPP_MPI)
          !Collect number of all eigenvalues
Daniel Wortmann's avatar
Daniel Wortmann committed
187
          ne_found=ne_all
Daniel Wortmann's avatar
Daniel Wortmann committed
188
          CALL MPI_ALLREDUCE(ne_found,ne_all,1,MPI_INTEGER,MPI_SUM, mpi%sub_comm,ierr)
189
          ne_all=MIN(DIMENSION%neigd,ne_all)
Daniel Wortmann's avatar
Daniel Wortmann committed
190 191 192
#else
          ne_found=ne_all
#endif          
193
          !jij%eig_l = 0.0 ! need not be used, if hdf-file is present
194 195
          IF (.NOT.l_real) THEN
             IF (.NOT.jij%l_J) THEN
Daniel Wortmann's avatar
Daniel Wortmann committed
196
                zMat%data_c(:lapw%nmat,:ne_found) = CONJG(zMat%data_c(:lapw%nmat,:ne_found))
197
             ELSE
Daniel Wortmann's avatar
Daniel Wortmann committed
198
                zMat%data_c(:lapw%nmat,:ne_found) = CMPLX(0.0,0.0)
199
             ENDIF
200
          ENDIF
Daniel Wortmann's avatar
Daniel Wortmann committed
201
    	  CALL write_eig(eig_id, nk,jsp,ne_found,ne_all,lapw%nv(jsp),lapw%nmat,&
Daniel Wortmann's avatar
Daniel Wortmann committed
202
                  bkpt, kpts%wtkpt(nk),eig(:ne_found),el=enpara%el0(0:,:,jsp),ello=enpara%ello0(:,:,jsp),evac=enpara%evac0(:,jsp),&
Daniel Wortmann's avatar
Daniel Wortmann committed
203
                  nlotot=atoms%nlotot,n_start=mpi%n_size,n_end=mpi%n_rank,zmat=zMat)
204
          IF (noco%l_noco) THEN
205
             CALL write_eig(eig_id, nk,2,ne_found,ne_all,lapw%nv(2),lapw%nmat,&
Daniel Wortmann's avatar
Daniel Wortmann committed
206
                  bkpt, kpts%wtkpt(nk),eig(:ne_found),el=enpara%el0(0:,:,2),ello= enpara%ello0(:,:,2),evac=enpara%evac0(:,2),&
Daniel Wortmann's avatar
Daniel Wortmann committed
207
                  nlotot=atoms%nlotot)
208
          ENDIF
209 210 211 212
#if defined(CPP_MPI)
          !RMA synchronization
          CALL MPI_BARRIER(mpi%MPI_COMM,ierr)
#endif
213 214 215 216 217 218 219

          CALL timestop("EV output")
          !
       END DO  k_loop

    END DO ! spin loop ends

Daniel Wortmann's avatar
Daniel Wortmann committed
220
  
221
#ifdef CPP_MPI
222
    CALL MPI_BARRIER(mpi%MPI_COMM,ierr)
223
#endif
Daniel Wortmann's avatar
Daniel Wortmann committed
224
    !IF (hybrid%l_hybrid.OR.hybrid%l_calhf) CALL close_eig(eig_id)
Daniel Wortmann's avatar
Daniel Wortmann committed
225
  
226

227
    IF( input%jspins .EQ. 1 .AND. hybrid%l_hybrid ) THEN
228 229 230
       results%te_hfex%valence = 2*results%te_hfex%valence
       results%te_hfex%core    = 2*results%te_hfex%core
    END IF
231 232
    enpara_in%epara_min = MINVAL(enpara%el0)
    enpara_in%epara_min = MIN(MINVAL(enpara%ello0),enpara_in%epara_min)
233 234
  END SUBROUTINE eigen
END MODULE m_eigen
Daniel Wortmann's avatar
Daniel Wortmann committed
235