eigen.F90 15.7 KB
Newer Older
1 2 3 4 5 6
!--------------------------------------------------------------------------------
! 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.
!--------------------------------------------------------------------------------

7
MODULE m_eigen
8
  USE m_juDFT
9 10
CONTAINS
  SUBROUTINE eigen(mpi,stars,sphhar,atoms,obsolete,xcpot,&
11
       sym,kpts,DIMENSION, vacuum, input, cell, enpara_in,banddos, noco,jij, oneD,hybrid,&
12
       it,eig_id,inDen,results,vTot,vx)
13 14 15 16 17 18 19
    !*********************************************************************
    !     sets up and solves the eigenvalue problem for a basis of lapws.
    !
    ! nv,   nvd     ... actual length & dimension of EV without LO's
    ! nmat, nbasfcn                                   including LO's
    !        g. bihlmayer '96
    !**********************************************************************
20
    USE m_constants
21 22 23 24 25 26 27 28 29 30 31
    USE m_types
    USE m_lodpot
    USE m_tlmplm
    USE m_tlmplm_store
    USE m_apws
    USE m_hsmt
    USE m_hsint
    USE m_hsvac
    USE m_od_hsvac
    USE m_usetup
    USE m_eigen_diag
Daniel Wortmann's avatar
Daniel Wortmann committed
32
    USE m_add_vnonlocal
33
    USE m_subvxc
Daniel Wortmann's avatar
Daniel Wortmann committed
34
    !USE m_hsefunctional
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
40 41 42 43 44

    IMPLICIT NONE
    TYPE(t_results),INTENT(INOUT):: results
    TYPE(t_xcpot),INTENT(IN)     :: xcpot
    TYPE(t_mpi),INTENT(IN)       :: mpi
45
    TYPE(t_dimension),INTENT(IN) :: DIMENSION
46
    TYPE(t_oneD),INTENT(IN)      :: oneD
47
    TYPE(t_hybrid),INTENT(INOUT) :: hybrid
48 49 50 51 52
    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
53
    TYPE(t_banddos),INTENT(IN)   :: banddos
54
    TYPE(t_jij),INTENT(IN)       :: jij
Daniel Wortmann's avatar
Daniel Wortmann committed
55
    TYPE(t_sym),INTENT(IN)       :: sym  
56 57 58 59
    TYPE(t_stars),INTENT(IN)     :: stars
    TYPE(t_cell),INTENT(IN)      :: cell
    TYPE(t_kpts),INTENT(IN)      :: kpts
    TYPE(t_sphhar),INTENT(IN)    :: sphhar
60
    TYPE(t_atoms),INTENT(IN)     :: atoms
61
    TYPE(t_potden),INTENT(IN)    :: inDen
62
    TYPE(t_potden),INTENT(INOUT) :: vTot,vx
63 64 65 66 67
#ifdef CPP_MPI
    INCLUDE 'mpif.h'
#endif
    !     ..
    !     .. Scalar Arguments ..
68
    INTEGER,INTENT(IN) :: it
69 70 71 72 73 74
    INTEGER,INTENT(INOUT):: eig_id
    !     ..
    !-odim
    !+odim
    !     ..
    !     .. Local Scalars ..
75
    INTEGER jsp,nk,nred,ne_all,ne_found
Daniel Wortmann's avatar
Daniel Wortmann committed
76 77 78 79
    INTEGER ne,matsize  ,nrec,lh0
    INTEGER nspins,isp,i,j,err
    INTEGER mlotot,mlolotot
    LOGICAL l_wu,l_file,l_real,l_zref
80
    
81 82 83
    !     ..
    !     .. Local Arrays ..
    INTEGER, ALLOCATABLE :: matind(:,:),kveclo(:)
84
    INTEGER, ALLOCATABLE :: nv2(:)
85
    REAL,    ALLOCATABLE :: bkpt(:)
86
    REAL,    ALLOCATABLE :: eig(:)
87

88 89 90
    TYPE(t_tlmplm)  :: td
    TYPE(t_usdus)   :: ud
    TYPE(t_lapw)    :: lapw
91
    TYPE(t_enpara)  :: enpara
92 93
    TYPE(t_zMat)    :: zMat
    TYPE(t_hamOvlp) :: hamOvlp
Daniel Wortmann's avatar
Daniel Wortmann committed
94
    TYPE(T_mat)     :: olap
95
    !
Daniel Wortmann's avatar
Daniel Wortmann committed
96
    INTEGER fh,nn,n
97 98
    INTEGER ierr(3)

Daniel Wortmann's avatar
Daniel Wortmann committed
99

100 101
    !     .. variables for HF or hybrid functional calculation ..
    !
102
    INTEGER                 ::  comm(kpts%nkpt),irank2(kpts%nkpt),isize2(kpts%nkpt)
Daniel Wortmann's avatar
Daniel Wortmann committed
103
    
104
#ifdef CPP_MPI
Daniel Wortmann's avatar
Daniel Wortmann committed
105
    INTEGER   :: sndreqd,sndreq(mpi%isize*kpts%nkpt)
106 107 108
#endif
    !
    !
109
    ! --> Allocate
110
    !
Daniel Wortmann's avatar
Daniel Wortmann committed
111 112 113
    call ud%init(atoms,DIMENSION%jspd)
    ALLOCATE ( nv2(DIMENSION%jspd) )
    ALLOCATE ( eig(DIMENSION%neigd),bkpt(3) )
Daniel Wortmann's avatar
Daniel Wortmann committed
114
   
115 116 117 118 119
    !
    ! --> some parameters first
    !
    !     determine the total number of lo's : nlotot
    !
Daniel Wortmann's avatar
Daniel Wortmann committed
120 121 122
    mlotot =sum(atoms%nlo)
  
    mlolotot = 0
Daniel Wortmann's avatar
Daniel Wortmann committed
123 124
    DO nn = 1, atoms%ntype
       mlolotot = mlolotot + atoms%nlo(nn)*(atoms%nlo(nn)+1)/2
125
    ENDDO
Daniel Wortmann's avatar
Daniel Wortmann committed
126
    ALLOCATE ( kveclo(atoms%nlotot) )
127
    !     ..
Daniel Wortmann's avatar
Daniel Wortmann committed
128
    
129
    l_real=sym%invs.AND..NOT.noco%l_noco.and..not.(noco%l_soc.and.atoms%n_u>0)
130
    IF (noco%l_soc.AND.l_real.AND.hybrid%l_hybrid ) THEN
131
       CALL juDFT_error('hybrid functional + SOC + inv.symmetry is not tested', calledby='eigen')
132
    END IF
133

Daniel Wortmann's avatar
Daniel Wortmann committed
134
    
135 136 137 138 139
    fh = 0
    !
    ! look, if WU diagonalisation
    !
    IF (it.LT.input%isec1) THEN
140
       IF (mpi%irank.EQ.0) WRITE (6,FMT=8110) it,input%isec1
141
8110   FORMAT (' IT=',i4,'  ISEC1=',i4,' standard diagonalization')
142
       l_wu = .FALSE.
143
    ELSE
144
       IF (mpi%irank.EQ.0) WRITE (6,FMT=8120) it,input%isec1
145
8120   FORMAT (' IT=',i4,'  ISEC1=',i4,' reduced diagonalization')
146
       l_wu = .TRUE.
147
    END IF
148

149
999 CONTINUE
150
    IF (mpi%irank.EQ.0) CALL openXMLElementFormPoly('iteration',(/'numberForCurrentRun','overallNumber      '/),(/it,vTot%iter/),&
151
                                                    RESHAPE((/19,13,5,5/),(/2,2/)))
152

Daniel Wortmann's avatar
Daniel Wortmann committed
153
   
154 155 156
    !
    ! set energy parameters (normally to that, what we read in)
    !
Daniel Wortmann's avatar
Daniel Wortmann committed
157
    CALL lodpot(mpi,atoms,sphhar,obsolete,vacuum,&
158
            input, vTot%mt,vTot%vacz, enpara_in, enpara)
159
    !
Daniel Wortmann's avatar
Daniel Wortmann committed
160

161 162 163 164

    !---> set up and solve the eigenvalue problem
    !---> loop over energy windows

Daniel Wortmann's avatar
Daniel Wortmann committed
165
!check if z-reflection trick can be used
166

167
    l_zref=(sym%zrfs.AND.(SUM(ABS(kpts%bk(3,:kpts%nkpt))).LT.1e-9).AND..NOT.noco%l_noco) 
168

Daniel Wortmann's avatar
Daniel Wortmann committed
169 170

#if ( defined(CPP_MPI))
171
    IF (mpi%n_size > 1) l_zref = .FALSE.
172
    IF ( hybrid%l_calhf ) THEN
173
       CALL judft_error("BUG parallelization in HF case must be fixed")
Daniel Wortmann's avatar
Daniel Wortmann committed
174 175
       !n_start  = 1
       !n_stride = 1
176 177
    END IF
#endif
Daniel Wortmann's avatar
Daniel Wortmann committed
178 179
    !Count number of matrix columns on this PE
    n=0
180
    DO i=1+mpi%n_rank,DIMENSION%nbasfcn,mpi%n_size
Daniel Wortmann's avatar
Daniel Wortmann committed
181
       n=n+1
182
    ENDDO
Daniel Wortmann's avatar
Daniel Wortmann committed
183
    IF (mpi%n_size>1) THEN
184
       matsize = DIMENSION%nbasfcn * n
Daniel Wortmann's avatar
Daniel Wortmann committed
185
    ELSE
186 187 188 189 190
       IF (MOD(DIMENSION%nbasfcn,2)==0 ) THEN !same formula, division by 2 different to avail int overflow
          matsize = (DIMENSION%nbasfcn+1)*(DIMENSION%nbasfcn/2)
       ELSE
          matsize = ((DIMENSION%nbasfcn+1)/2)*DIMENSION%nbasfcn
       ENDIF
Daniel Wortmann's avatar
Daniel Wortmann committed
191
    ENDIF
192 193 194 195
    IF (matsize<2) THEN
       CALL judft_error("Wrong size of matrix",calledby="eigen",&
                        hint="Your basis might be too large or the parallelization fail or ??")
    END IF
196
    ne = DIMENSION%neigd
Daniel Wortmann's avatar
Daniel Wortmann committed
197

198 199
    eig_id=open_eig(&
          mpi%mpi_comm,DIMENSION%nbasfcn,DIMENSION%neigd,kpts%nkpt,DIMENSION%jspd,atoms%lmaxd,&
200 201 202
         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,&
203
         l_orb=banddos%l_orb)
204
    IF (l_real) THEN
205
       ALLOCATE ( hamOvlp%a_r(matsize), stat = err )
206
    ELSE
207
       ALLOCATE ( hamOvlp%a_c(matsize), stat = err )
208
    ENDIF
209 210 211 212 213
    IF (err.NE.0) THEN
       WRITE (*,*) 'eigen: an error occured during allocation of'
       WRITE (*,*) 'the Hamilton Matrix: ',err,'  size: ',matsize
       CALL juDFT_error("eigen: Error during allocation of Hamilton" //"matrix",calledby ="eigen")
    ENDIF
214 215
    IF (l_real) THEN 
       ALLOCATE ( hamOvlp%b_c(0))
216
       ALLOCATE ( hamOvlp%b_r(matsize), stat = err )
217 218
    ELSE   
       ALLOCATE ( hamOvlp%b_r(0))
219
       ALLOCATE ( hamOvlp%b_c(matsize), stat = err )
220
    ENDIF
221

222 223 224 225 226
    IF (err.NE.0) THEN
       WRITE (*,*) 'eigen: an error occured during allocation of'
       WRITE (*,*) 'the overlap Matrix: ',err,'  size: ',matsize
       CALL juDFT_error("eigen: Error during allocation of overlap " //"matrix",calledby ="eigen")
    ENDIF
227 228 229 230

    hamOvlp%l_real = l_real
    hamOvlp%matsize = matsize

231
    ALLOCATE (  matind(DIMENSION%nbasfcn,2) )
232 233 234 235
    !
    !--->    loop over spins
    nspins = input%jspins
    IF (noco%l_noco) nspins = 1
236 237

    ! LDA+U
238
    IF ((atoms%n_u.GT.0)) THEN
239
       CALL u_setup(sym,atoms,sphhar,input,enpara%el0(0:,:,:),inDen,vTot,mpi,results)
240
    END IF
241

242
    !--->    loop over k-points: each can be a separate task
243
    DO jsp = 1,nspins
Daniel Wortmann's avatar
Daniel Wortmann committed
244
       
245 246 247 248 249 250 251

       !
       !--->       set up k-point independent t(l'm',lm) matrices
       !
       CALL timestart("tlmplm")
       err=0
       j = 1 ; IF (noco%l_noco) j = 2
252 253 254 255
       ALLOCATE(td%tuu(0:DIMENSION%lmplmd,atoms%ntype,j),stat=err)
       ALLOCATE(td%tud(0:DIMENSION%lmplmd,atoms%ntype,j),stat=err)
       ALLOCATE(td%tdd(0:DIMENSION%lmplmd,atoms%ntype,j),stat=err)
       ALLOCATE(td%tdu(0:DIMENSION%lmplmd,atoms%ntype,j),stat=err)
Daniel Wortmann's avatar
Daniel Wortmann committed
256 257 258 259
       mlotot = MAX(mlotot,1) 
       ALLOCATE(td%tdulo(0:DIMENSION%lmd,-atoms%llod:atoms%llod,mlotot,j),stat=err)
       ALLOCATE(td%tuulo(0:DIMENSION%lmd,-atoms%llod:atoms%llod,mlotot,j),stat=err)
       ALLOCATE(td%tuloulo(-atoms%llod:atoms%llod,-atoms%llod:atoms%llod,MAX(mlolotot,1),j), stat=err)
260
       ALLOCATE(td%ind(0:DIMENSION%lmd,0:DIMENSION%lmd,atoms%ntype,j),stat=err )
261 262 263 264 265
       IF (err.NE.0) THEN
          WRITE (*,*) 'eigen: an error occured during allocation of'
          WRITE (*,*) 'the tlmplm%tuu, tlmplm%tdd etc.: ',err,'  size: ',mlotot
          CALL juDFT_error("eigen: Error during allocation of tlmplm, tdd  etc.",calledby ="eigen")
       ENDIF
Daniel Wortmann's avatar
Daniel Wortmann committed
266
       lh0=1
267 268
       CALL tlmplm(sphhar,atoms,DIMENSION,enpara, jsp,1,mpi, vTot%mt(1,0,1,jsp),lh0,input, td,ud)
       IF (input%l_f) CALL write_tlmplm(td,vTot%mmpMat,atoms%n_u>0,1,jsp,input%jspins)
269 270 271 272 273 274 275 276 277
       CALL timestop("tlmplm")

       !---> pk non-collinear
       !--->       call tlmplm again for the second spin direction in
       !--->       each MT, because the t-matrices are needed for both
       !--->       spins at once in hsmt
       IF (noco%l_noco) THEN
          isp = 2
          CALL timestart("tlmplm")
278 279
          CALL tlmplm(sphhar,atoms,DIMENSION,enpara,isp,isp,mpi, vTot%mt(1,0,1,isp),lh0,input, td,ud)
          IF (input%l_f) CALL write_tlmplm(td,vTot%mmpMat,atoms%n_u>0,2,2,input%jspins)
280 281 282 283
          CALL timestop("tlmplm")
       ENDIF
       !

284
#ifdef CPP_MPI
285 286
       ! check that all sending operations are completed
       IF ( hybrid%l_calhf ) CALL MPI_WAITALL(sndreqd,sndreq,MPI_STATUSES_IGNORE,ierr)
287
#endif
288

Daniel Wortmann's avatar
Daniel Wortmann committed
289
       k_loop:DO nk = mpi%n_start,kpts%nkpt,mpi%n_stride
290 291 292 293 294

          nrec =  kpts%nkpt*(jsp-1) + nk
          !
          !--->         set up lapw list
          !
295
          CALL timestart("Setup of LAPW")
296

297
          CALL apws(DIMENSION,input,noco, kpts,nk,cell,l_zref, mpi%n_size,jsp, bkpt,lapw,matind,nred)
298

299
          CALL timestop("Setup of LAPW")
300 301 302 303 304 305 306 307
          IF (noco%l_noco) THEN
             !--->         the file potmat contains the 2x2 matrix-potential in
             !--->         the interstitial region and the vacuum
             OPEN (25,FILE='potmat',FORM='unformatted', STATUS='old')
          ENDIF
          !
          !--->         set up interstitial hamiltonian and overlap matrices
          !
308
          CALL timestart("Interstitial Hamiltonian&Overlap")
309
          CALL hsint(input,noco,jij,stars, vTot%pw(:,jsp),lapw,jsp, mpi%n_size,mpi%n_rank,kpts%bk(:,nk),cell,atoms,l_real,hamOvlp)
310

311
          CALL timestop("Interstitial Hamiltonian&Overlap")
312 313 314
          !
          !--->         update with sphere terms
          !
315 316 317
          IF (.NOT.l_wu) THEN
             CALL timestart("MT Hamiltonian&Overlap")
             CALL hsmt(DIMENSION,atoms,sphhar,sym,enpara, mpi%SUB_COMM,mpi%n_size,mpi%n_rank,jsp,input,mpi,&
318
                  lmaxU_const, noco,cell, lapw, bkpt,vTot%mt,vTot%mmpMat, oneD,ud, kveclo,td,l_real,hamOvlp)
319
             CALL timestop("MT Hamiltonian&Overlap")
320 321
          ENDIF
          !
322
          IF( hybrid%l_hybrid ) THEN
Daniel Wortmann's avatar
Daniel Wortmann committed
323 324
             !write overlap matrix b to direct access file olap
             print *,"Wrong overlap matrix used, fix this later"
Daniel Wortmann's avatar
Daniel Wortmann committed
325
             call olap%from_packed(l_real,dimension%nbasfcn,hamovlp%b_r,hamovlp%b_c)
Daniel Wortmann's avatar
Daniel Wortmann committed
326
             call write_olap(olap,nrec)
327
             PRINT *,"BASIS:",lapw%nv(jsp),atoms%nlotot
Daniel Wortmann's avatar
Daniel Wortmann committed
328 329 330
             if (hybrid%l_addhf) CALL add_Vnonlocal(nk,hybrid,dimension, kpts,jsp,results,xcpot,hamovlp)
             
             
331
             IF( hybrid%l_subvxc ) THEN
332
                CALL subvxc(lapw,kpts%bk(:,nk),DIMENSION,input,jsp,vTot%mt(:,0,:,:),atoms,ud,hybrid,enpara%el0,enpara%ello0,&
Daniel Wortmann's avatar
Daniel Wortmann committed
333
                     sym, atoms%nlotot,kveclo, cell,sphhar, stars, xcpot,mpi,&
Daniel Wortmann's avatar
Daniel Wortmann committed
334
                     oneD,  hamovlp,vx)
335 336
             END IF

337
          END IF ! hybrid%l_hybrid
338 339 340
          !
          !--->         update with vacuum terms
          !
341
          CALL timestart("Vacuum Hamiltonian&Overlap")
342
          IF (input%film .AND. .NOT.oneD%odi%d1) THEN
343
             CALL hsvac(vacuum,stars,DIMENSION, atoms, jsp,input,vTot%vacxy(1,1,1,jsp),vTot%vacz,enpara%evac0,cell, &
Daniel Wortmann's avatar
Daniel Wortmann committed
344
                  bkpt,lapw,sym, noco,jij, mpi%n_size,mpi%n_rank,nv2,l_real,hamOvlp)
345
          ELSEIF (oneD%odi%d1) THEN
346
             CALL od_hsvac(vacuum,stars,DIMENSION, oneD,atoms, jsp,input,vTot%vacxy(1,1,1,jsp),vTot%vacz, &
347
                  enpara%evac0,cell, bkpt,lapw, oneD%odi%M,oneD%odi%mb,oneD%odi%m_cyl,oneD%odi%n2d, &
Daniel Wortmann's avatar
Daniel Wortmann committed
348
                  mpi%n_size,mpi%n_rank,sym,noco,jij,nv2,l_real,hamOvlp)
349
          END IF
350
          CALL timestop("Vacuum Hamiltonian&Overlap")
351 352 353

          IF (noco%l_noco) CLOSE (25)

Daniel Wortmann's avatar
Daniel Wortmann committed
354 355 356
         
          
          
357
          CALL eigen_diag(jsp,eig_id,it,atoms,DIMENSION,matsize,mpi, mpi%n_rank,mpi%n_size,ne,nk,lapw,input,&
Daniel Wortmann's avatar
Daniel Wortmann committed
358
               nred,mpi%sub_comm, sym,l_zref,matind,kveclo, noco,cell,bkpt,enpara%el0,jij,l_wu,&
359
               oneD,td,ud, eig,ne_found,hamOvlp,zMat)
360
          
361 362 363 364
          !
          !--->         output results
          !
          CALL timestart("EV output")
365
          ne_all=ne_found
366 367
#if defined(CPP_MPI)
          !Collect number of all eigenvalues
Daniel Wortmann's avatar
Daniel Wortmann committed
368
          CALL MPI_ALLREDUCE(ne_found,ne_all,1,MPI_INTEGER,MPI_SUM, mpi%sub_comm,ierr)
369
          ne_all=MIN(DIMENSION%neigd,ne_all)
370 371
#endif
          !jij%eig_l = 0.0 ! need not be used, if hdf-file is present
372 373 374
          IF (.NOT.l_real) THEN
             IF (.NOT.jij%l_J) THEN
                zMat%z_c(:lapw%nmat,:ne_found) = CONJG(zMat%z_c(:lapw%nmat,:ne_found))
375
             ELSE
376
                zMat%z_c(:lapw%nmat,:ne_found) = CMPLX(0.0,0.0)
377
             ENDIF
378
          ENDIF
Daniel Wortmann's avatar
Daniel Wortmann committed
379
	  zmat%nbands=ne_found
380
          CALL write_eig(eig_id, nk,jsp,ne_found,ne_all,lapw%nv(jsp),lapw%nmat,&
381
                  lapw%k1(:lapw%nv(jsp),jsp),lapw%k2 (:lapw%nv(jsp),jsp),lapw%k3(:lapw%nv(jsp),jsp),&
Daniel Wortmann's avatar
Daniel Wortmann committed
382 383
                  bkpt, kpts%wtkpt(nk),eig(:ne_found),el=enpara%el0(0:,:,jsp),ello=enpara%ello0(:,:,jsp),evac=enpara%evac0(:,jsp),&
                  nlotot=atoms%nlotot,kveclo=kveclo,n_start=mpi%n_size,n_end=mpi%n_rank,zmat=zMat)
384
          IF (noco%l_noco) THEN
385
             CALL write_eig(eig_id, nk,2,ne_found,ne_all,lapw%nv(2),lapw%nmat,&
386
                  lapw%k1(:lapw%nv(2),2),lapw%k2 (:lapw%nv(2),2),lapw%k3(:lapw%nv(2),2),&
Daniel Wortmann's avatar
Daniel Wortmann committed
387 388
                  bkpt, kpts%wtkpt(nk),eig(:ne_found),el=enpara%el0(0:,:,2),ello= enpara%ello0(:,:,2),evac=enpara%evac0(:,2),&
                  nlotot=atoms%nlotot,kveclo=kveclo)
389
          ENDIF
390 391 392 393
#if defined(CPP_MPI)
          !RMA synchronization
          CALL MPI_BARRIER(mpi%MPI_COMM,ierr)
#endif
394 395 396

          CALL timestop("EV output")
          !#ifdef CPP_MPI
397
          IF (l_real) THEN
398
             DEALLOCATE ( zMat%z_r )
399
          ELSE
400
             DEALLOCATE ( zMat%z_c )
401
ENDIF
402 403 404 405 406 407 408
          !
       END DO  k_loop

       DEALLOCATE (td%tuu,td%tud,td%tdu,td%tdd)
       DEALLOCATE (td%ind,td%tuulo,td%tdulo)
       DEALLOCATE (td%tuloulo)
    END DO ! spin loop ends
409
    DEALLOCATE (matind)
410 411 412 413 414
    IF (l_real) THEN
       DEALLOCATE(hamOvlp%a_r,hamOvlp%b_r)
    ELSE
       DEALLOCATE(hamOvlp%a_c,hamOvlp%b_c)
    ENDIF
415
#if defined(CPP_MPI)&&defined(CPP_NEVER)
416
    IF ( hybrid%l_calhf ) DEALLOCATE (nkpt_EIBZ)
417
#endif
418

Daniel Wortmann's avatar
Daniel Wortmann committed
419
  
420
#ifdef CPP_MPI
421
    CALL MPI_BARRIER(mpi%MPI_COMM,ierr)
422
#endif
Daniel Wortmann's avatar
Daniel Wortmann committed
423
    !IF (hybrid%l_hybrid.OR.hybrid%l_calhf) CALL close_eig(eig_id)
424

425
    IF( input%jspins .EQ. 1 .AND. hybrid%l_hybrid ) THEN
426 427 428
       results%te_hfex%valence = 2*results%te_hfex%valence
       results%te_hfex%core    = 2*results%te_hfex%core
    END IF
429 430
    enpara_in%epara_min = MINVAL(enpara%el0)
    enpara_in%epara_min = MIN(MINVAL(enpara%ello0),enpara_in%epara_min)
431
!    enpara_in=enpara
432 433
  END SUBROUTINE eigen
END MODULE m_eigen