eigen.F90 8.08 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
  IMPLICIT NONE
12
CONTAINS
Daniel Wortmann's avatar
Daniel Wortmann committed
13 14 15 16 17 18 19 20
  !>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
21
  SUBROUTINE eigen(mpi,stars,sphhar,atoms,obsolete,xcpot,sym,kpts,DIMENSION,vacuum,input,&
22
                   cell,enpara,banddos,noco,oneD,hybrid,iter,eig_id,results,inden,v,vx)
23

Daniel Wortmann's avatar
Daniel Wortmann committed
24
    USE m_constants, ONLY : pi_const,sfp_const
25 26
    USE m_types
    USE m_apws
Daniel Wortmann's avatar
Daniel Wortmann committed
27 28
    USE m_eigen_hssetup
    USE m_pot_io
29
    USE m_eigen_diag
Daniel Wortmann's avatar
Daniel Wortmann committed
30
    USE m_add_vnonlocal
31
    USE m_subvxc
Daniel Wortmann's avatar
Daniel Wortmann committed
32
    !USE m_hsefunctional
Daniel Wortmann's avatar
Daniel Wortmann committed
33
    USE m_mt_setup
34
    USE m_util
Daniel Wortmann's avatar
Daniel Wortmann committed
35 36
    USE m_io_hybrid
    !USE m_icorrkeys
37
    USE m_eig66_io, ONLY : open_eig, write_eig, close_eig,read_eig
38
    USE m_xmlOutput
Daniel Wortmann's avatar
Daniel Wortmann committed
39
#ifdef CPP_MPI
40
    USE m_mpi_bc_potden
Daniel Wortmann's avatar
Daniel Wortmann committed
41
#endif
42
    USE m_symmetrize_matrix
43

44
    
45 46
    IMPLICIT NONE
    TYPE(t_results),INTENT(INOUT):: results
47
    CLASS(t_xcpot),INTENT(IN)    :: xcpot
48
    TYPE(t_mpi),INTENT(IN)       :: mpi
49
    TYPE(t_dimension),INTENT(IN) :: DIMENSION
50
    TYPE(t_oneD),INTENT(IN)      :: oneD
51
    TYPE(t_hybrid),INTENT(INOUT) :: hybrid
52
    TYPE(t_enpara),INTENT(INOUT) :: enpara
53 54 55 56
    TYPE(t_obsolete),INTENT(IN)  :: obsolete
    TYPE(t_input),INTENT(IN)     :: input
    TYPE(t_vacuum),INTENT(IN)    :: vacuum
    TYPE(t_noco),INTENT(IN)      :: noco
57
    TYPE(t_banddos),INTENT(IN)   :: banddos
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
63 64 65 66
    TYPE(t_atoms),INTENT(IN)     :: atoms
    TYPE(t_potden),INTENT(IN)    :: inden,vx
    TYPE(t_potden),INTENT(INOUT) :: v    !u_setup will modify the potential matrix
   
67 68 69 70 71
#ifdef CPP_MPI
    INCLUDE 'mpif.h'
#endif
    !     ..
    !     .. Scalar Arguments ..
72
    INTEGER,INTENT(IN)    :: iter
73
    INTEGER,INTENT(IN)    :: eig_id
74 75 76 77 78
    !     ..
    !-odim
    !+odim
    !     ..
    !     .. Local Scalars ..
79
    INTEGER jsp,nk,nred,ne_all,ne_found
80
    INTEGER ne,lh0
Daniel Wortmann's avatar
Daniel Wortmann committed
81
    INTEGER isp,i,j,err
Daniel Wortmann's avatar
Daniel Wortmann committed
82
    LOGICAL l_wu,l_file,l_real,l_zref
83
    
84 85
    !     ..
    !     .. Local Arrays ..
Daniel Wortmann's avatar
Daniel Wortmann committed
86
    INTEGER, PARAMETER :: lmaxb=3
87
    REAL,    ALLOCATABLE :: bkpt(:)
88
    REAL,    ALLOCATABLE :: eig(:)
89

Daniel Wortmann's avatar
Daniel Wortmann committed
90
    COMPLEX, ALLOCATABLE :: vs_mmp(:,:,:,:)
91 92 93
    TYPE(t_tlmplm)  :: td
    TYPE(t_usdus)   :: ud
    TYPE(t_lapw)    :: lapw
Daniel Wortmann's avatar
Daniel Wortmann committed
94 95
    CLASS(t_Mat),ALLOCATABLE    :: zMat
    CLASS(t_mat),ALLOCATABLE    :: hmat,smat
Daniel Wortmann's avatar
Daniel Wortmann committed
96
    TYPE(T_mat)     :: olap
97
    !
Daniel Wortmann's avatar
Daniel Wortmann committed
98
    INTEGER nn,n
99
    INTEGER ierr(3)
100
    INTEGER :: neigBuffer(kpts%nkpt,input%jspins)
Daniel Wortmann's avatar
Daniel Wortmann committed
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
    
Daniel Wortmann's avatar
Daniel Wortmann committed
105
    call ud%init(atoms,DIMENSION%jspd)
106
    ALLOCATE (eig(DIMENSION%neigd),bkpt(3))
Daniel Wortmann's avatar
Daniel Wortmann committed
107
    
Daniel Wortmann's avatar
Daniel Wortmann committed
108 109
    l_real=sym%invs.AND..NOT.noco%l_noco
    !check if z-reflection trick can be used
110

Daniel Wortmann's avatar
Daniel Wortmann committed
111 112 113 114
    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
115
    CALL mpi_bc_potden(mpi,stars,sphhar,atoms,input,vacuum,oneD,noco,v)
Daniel Wortmann's avatar
Daniel Wortmann committed
116
#endif
117
    !IF (mpi%irank.EQ.0) CALL openXMLElementFormPoly('iteration',(/'numberForCurrentRun','overallNumber      '/),(/iter,v%iter/),&
118
    !                                                RESHAPE((/19,13,5,5/),(/2,2/)))
Daniel Wortmann's avatar
Daniel Wortmann committed
119
    
120 121 122 123
    !---> 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,inden,v,mpi,results,DIMENSION,td,ud)
Gregor Michalicek's avatar
Gregor Michalicek committed
124

125
    neigBuffer = 0
Gregor Michalicek's avatar
Gregor Michalicek committed
126
    results%neig = 0
127
    results%eig = 1.0e300
Gregor Michalicek's avatar
Gregor Michalicek committed
128

Daniel Wortmann's avatar
Daniel Wortmann committed
129
    DO jsp = 1,MERGE(1,input%jspins,noco%l_noco)
Daniel Wortmann's avatar
Daniel Wortmann committed
130
       k_loop:DO nk = mpi%n_start,kpts%nkpt,mpi%n_stride
131 132 133

          !
          !--->         set up lapw list
Daniel Wortmann's avatar
Daniel Wortmann committed
134 135 136
        
          CALL lapw%init(input,noco, kpts,atoms,sym,nk,cell,l_zref, mpi)
          call timestart("Setup of H&S matrices")
137
          CALL eigen_hssetup(jsp,mpi,DIMENSION,hybrid,enpara,input,vacuum,noco,sym,&
Daniel Wortmann's avatar
Daniel Wortmann committed
138 139 140
               stars,cell,sphhar,atoms,ud,td,v,lapw,l_real,smat,hmat)
          CALL timestop("Setup of H&S matrices")
        
141
          IF( hybrid%l_hybrid ) THEN
Daniel Wortmann's avatar
Daniel Wortmann committed
142 143
             !write overlap matrix b to direct access file olap
             print *,"Wrong overlap matrix used, fix this later"
Daniel Wortmann's avatar
Daniel Wortmann committed
144
             !call write_olap(smat,nrec)
145 146
             PRINT *,"TODO"
!             STOP "TODO"
147
             PRINT *,"BASIS:",lapw%nv(jsp),atoms%nlotot
Daniel Wortmann's avatar
Daniel Wortmann committed
148
             !if (hybrid%l_addhf) CALL add_Vnonlocal(nk,hybrid,dimension, kpts,jsp,results,xcpot,hamovlp)
Daniel Wortmann's avatar
Daniel Wortmann committed
149 150
             
             
151
             IF( hybrid%l_subvxc ) THEN
Daniel Wortmann's avatar
Daniel Wortmann committed
152 153 154
                !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)
155 156
             END IF

157
          END IF ! hybrid%l_hybrid
Daniel Wortmann's avatar
Daniel Wortmann committed
158 159 160
          l_wu=.FALSE.
          ne_all=DIMENSION%neigd
          if (allocated(zmat)) deallocate(zmat)
161 162 163
          !Try to symmetrize matrix
          CALL symmetrize_matrix(mpi,noco,kpts,nk,hmat,smat)
          
164
          CALL eigen_diag(hmat,smat,nk,jsp,iter,ne_all,eig,zMat)
Daniel Wortmann's avatar
Daniel Wortmann committed
165
          DEALLOCATE(hmat,smat)
166 167 168 169 170 171
          !
          !--->         output results
          !
          CALL timestart("EV output")
#if defined(CPP_MPI)
          !Collect number of all eigenvalues
Daniel Wortmann's avatar
Daniel Wortmann committed
172
          ne_found=ne_all
Daniel Wortmann's avatar
Daniel Wortmann committed
173
          CALL MPI_ALLREDUCE(ne_found,ne_all,1,MPI_INTEGER,MPI_SUM, mpi%sub_comm,ierr)
174
          ne_all=MIN(DIMENSION%neigd,ne_all)
Daniel Wortmann's avatar
Daniel Wortmann committed
175 176 177
#else
          ne_found=ne_all
#endif          
Daniel Wortmann's avatar
Daniel Wortmann committed
178
          IF (.NOT.zmat%l_real) THEN
Gregor Michalicek's avatar
Gregor Michalicek committed
179
             zMat%data_c(:lapw%nmat,:ne_found) = CONJG(zMat%data_c(:lapw%nmat,:ne_found))
180
          ENDIF
Gregor Michalicek's avatar
Gregor Michalicek committed
181 182
          CALL write_eig(eig_id, nk,jsp,ne_found,ne_all,&
                         eig(:ne_found),n_start=mpi%n_size,n_end=mpi%n_rank,zmat=zMat)
183
          neigBuffer(nk,jsp) = ne_found
184 185 186 187
#if defined(CPP_MPI)
          !RMA synchronization
          CALL MPI_BARRIER(mpi%MPI_COMM,ierr)
#endif
188 189 190 191 192
          CALL timestop("EV output")
       END DO  k_loop
    END DO ! spin loop ends

#ifdef CPP_MPI
193
    CALL MPI_ALLREDUCE(neigBuffer,results%neig,kpts%nkpt*input%jspins,MPI_INTEGER,MPI_SUM,mpi%sub_comm,ierr)
194
    CALL MPI_BARRIER(mpi%MPI_COMM,ierr)
Gregor Michalicek's avatar
Gregor Michalicek committed
195
#else
196
    results%neig(:,:) = neigBuffer(:,:)
197
#endif
198 199 200 201 202 203 204 205 206

    ! Sorry for the following strange workaround to fill the results%eig array.
    ! At some point someone should have a closer look at how the eigenvalues are
    ! distributed and fill the array without using the eigenvalue-IO.
    DO jsp = 1,MERGE(1,input%jspins,noco%l_noco)
       DO nk = 1,kpts%nkpt
          CALL read_eig(eig_id,nk,jsp,results%neig(nk,jsp),results%eig(:,nk,jsp))
#ifdef CPP_MPI
          CALL MPI_BARRIER(mpi%MPI_COMM,ierr)
207
#endif
208 209 210
       END DO
    END DO

Daniel Wortmann's avatar
Daniel Wortmann committed
211
    !IF (hybrid%l_hybrid.OR.hybrid%l_calhf) CALL close_eig(eig_id)
212

213
    IF( input%jspins .EQ. 1 .AND. hybrid%l_hybrid ) THEN
214 215 216
       results%te_hfex%valence = 2*results%te_hfex%valence
       results%te_hfex%core    = 2*results%te_hfex%core
    END IF
217 218
    enpara%epara_min = MINVAL(enpara%el0)
    enpara%epara_min = MIN(MINVAL(enpara%ello0),enpara%epara_min)
219 220
  END SUBROUTINE eigen
END MODULE m_eigen
Daniel Wortmann's avatar
Daniel Wortmann committed
221