eigen.F90 16.2 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,&
Daniel Wortmann's avatar
Daniel Wortmann committed
12
       it,eig_id,results,v,vx)
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
    !*********************************************************************
    !     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
    !**********************************************************************
    USE m_constants, ONLY : pi_const,sfp_const
    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
31
    USE m_pot_io
32
    USE m_eigen_diag
Daniel Wortmann's avatar
Daniel Wortmann committed
33
    USE m_add_vnonlocal
34
    USE m_subvxc
Daniel Wortmann's avatar
Daniel Wortmann committed
35
    !USE m_hsefunctional
36
    USE m_util
Daniel Wortmann's avatar
Daniel Wortmann committed
37 38
    USE m_io_hybrid
    !USE m_icorrkeys
39
    USE m_eig66_io, ONLY : open_eig, write_eig, close_eig,read_eig
40
    USE m_xmlOutput
41 42 43
#ifdef CPP_MPI
    USE m_mpi_bc_pot
#endif
44 45 46 47 48

    IMPLICIT NONE
    TYPE(t_results),INTENT(INOUT):: results
    TYPE(t_xcpot),INTENT(IN)     :: xcpot
    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 53 54 55 56
    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
57
    TYPE(t_banddos),INTENT(IN)   :: banddos
58
    TYPE(t_jij),INTENT(IN)       :: jij
Daniel Wortmann's avatar
Daniel Wortmann committed
59
    TYPE(t_sym),INTENT(IN)       :: sym  
60 61 62 63
    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
64
    TYPE(t_atoms),INTENT(INOUT)  :: atoms!in u_setup n_u might be modified
Daniel Wortmann's avatar
Daniel Wortmann committed
65
    TYPE(t_potden),INTENT(INOUT) :: v,vx
66 67 68 69 70
#ifdef CPP_MPI
    INCLUDE 'mpif.h'
#endif
    !     ..
    !     .. Scalar Arguments ..
71
    INTEGER,INTENT(IN) :: it
72 73 74 75 76 77
    INTEGER,INTENT(INOUT):: eig_id
    !     ..
    !-odim
    !+odim
    !     ..
    !     .. Local Scalars ..
78
    INTEGER jsp,nk,nred,ne_all,n_u_in,ne_found
Daniel Wortmann's avatar
Daniel Wortmann committed
79 80 81 82
    INTEGER ne,matsize  ,nrec,lh0
    INTEGER nspins,isp,i,j,err
    INTEGER mlotot,mlolotot
    LOGICAL l_wu,l_file,l_real,l_zref
83
    
84 85 86 87
    !     ..
    !     .. Local Arrays ..
    INTEGER, PARAMETER :: lmaxb=3
    INTEGER, ALLOCATABLE :: matind(:,:),kveclo(:)
88
    INTEGER, ALLOCATABLE :: nv2(:)
89
    REAL,    ALLOCATABLE :: bkpt(:)
90
    REAL,    ALLOCATABLE :: eig(:)
91

92
    COMPLEX, ALLOCATABLE :: vs_mmp(:,:,:,:)
93 94 95
    TYPE(t_tlmplm)  :: td
    TYPE(t_usdus)   :: ud
    TYPE(t_lapw)    :: lapw
96
    TYPE(t_enpara)  :: enpara
97 98
    TYPE(t_zMat)    :: zMat
    TYPE(t_hamOvlp) :: hamOvlp
Daniel Wortmann's avatar
Daniel Wortmann committed
99
    TYPE(T_mat)     :: olap
100
    !
Daniel Wortmann's avatar
Daniel Wortmann committed
101
    INTEGER fh,nn,n
102 103
    INTEGER ierr(3)

Daniel Wortmann's avatar
Daniel Wortmann committed
104

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

Daniel Wortmann's avatar
Daniel Wortmann committed
139
    
140 141 142 143 144
    fh = 0
    !
    ! look, if WU diagonalisation
    !
    IF (it.LT.input%isec1) THEN
145
       IF (mpi%irank.EQ.0) WRITE (6,FMT=8110) it,input%isec1
146
8110   FORMAT (' IT=',i4,'  ISEC1=',i4,' standard diagonalization')
147
       l_wu = .FALSE.
148
    ELSE
149
       IF (mpi%irank.EQ.0) WRITE (6,FMT=8120) it,input%isec1
150
8120   FORMAT (' IT=',i4,'  ISEC1=',i4,' reduced diagonalization')
151
       l_wu = .TRUE.
152
    END IF
Daniel Wortmann's avatar
Daniel Wortmann committed
153 154 155 156 157
   
    !IF (mpi%irank.EQ.0) THEN
    !   CALL readPotential(stars,vacuum,atoms,sphhar,input,sym,POT_ARCHIVE_TYPE_TOT_const,&
    !                      v%iter,v%mt,v%pw,v%vacz,v%vacxy)
    !END IF
158 159
#ifdef CPP_MPI
    CALL mpi_bc_pot(mpi,stars,sphhar,atoms,input,vacuum,&
Daniel Wortmann's avatar
Daniel Wortmann committed
160
                    v%iter,v%mt,v%pw,v%vacz,v%vacxy)
161 162
#endif

163
999 CONTINUE
Daniel Wortmann's avatar
Daniel Wortmann committed
164
    IF (mpi%irank.EQ.0) CALL openXMLElementFormPoly('iteration',(/'numberForCurrentRun','overallNumber      '/),(/it,v%iter/),&
165
                                                    RESHAPE((/19,13,5,5/),(/2,2/)))
166

Daniel Wortmann's avatar
Daniel Wortmann committed
167
   
168 169 170
    !
    ! set energy parameters (normally to that, what we read in)
    !
Daniel Wortmann's avatar
Daniel Wortmann committed
171 172
    CALL lodpot(mpi,atoms,sphhar,obsolete,vacuum,&
            input, v%mt,v%vacz, enpara_in, enpara)
173
    !
Daniel Wortmann's avatar
Daniel Wortmann committed
174

175 176 177 178

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

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

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

Daniel Wortmann's avatar
Daniel Wortmann committed
183 184

#if ( defined(CPP_MPI))
185
    IF (mpi%n_size > 1) l_zref = .FALSE.
186
    IF ( hybrid%l_calhf ) THEN
187
       CALL judft_error("BUG parallelization in HF case must be fixed")
Daniel Wortmann's avatar
Daniel Wortmann committed
188 189
       !n_start  = 1
       !n_stride = 1
190 191
    END IF
#endif
Daniel Wortmann's avatar
Daniel Wortmann committed
192 193
    !Count number of matrix columns on this PE
    n=0
194
    DO i=1+mpi%n_rank,DIMENSION%nbasfcn,mpi%n_size
Daniel Wortmann's avatar
Daniel Wortmann committed
195
       n=n+1
196
    ENDDO
Daniel Wortmann's avatar
Daniel Wortmann committed
197
    IF (mpi%n_size>1) THEN
198
       matsize = DIMENSION%nbasfcn * n
Daniel Wortmann's avatar
Daniel Wortmann committed
199
    ELSE
200 201 202 203 204
       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
205
    ENDIF
206 207
    IF (matsize<2) CALL judft_error("Wrong size of matrix",calledby="eigen",hint="Your basis might be too large or the parallelization fail or ??")
    ne = MAX(5,DIMENSION%neigd)
Daniel Wortmann's avatar
Daniel Wortmann committed
208

Daniel Wortmann's avatar
Daniel Wortmann committed
209 210
    IF (.not.hybrid%l_calhf) THEN
       eig_id=open_eig(&
211 212 213 214
         mpi%mpi_comm,DIMENSION%nbasfcn,DIMENSION%neigd,kpts%nkpt,DIMENSION%jspd,atoms%lmaxd,&
         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,&
215
         l_orb=banddos%l_orb)
Daniel Wortmann's avatar
Daniel Wortmann committed
216
    endif
217
    IF (l_real) THEN
218
       ALLOCATE ( hamOvlp%a_r(matsize), stat = err )
219
    ELSE
220
       ALLOCATE ( hamOvlp%a_c(matsize), stat = err )
221
    ENDIF
222 223 224 225 226
    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
227
    IF (l_real) THEN
228
       ALLOCATE ( hamOvlp%b_r(matsize), stat = err )
229
    ELSE
230
       ALLOCATE ( hamOvlp%b_c(matsize), stat = err )
231
    ENDIF
232

233 234 235 236 237
    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
238 239 240 241

    hamOvlp%l_real = l_real
    hamOvlp%matsize = matsize

242
    ALLOCATE (  matind(DIMENSION%nbasfcn,2) )
243 244 245 246 247 248 249
    !
    !--->    loop over spins
    nspins = input%jspins
    IF (noco%l_noco) nspins = 1
    !
    !  ..
    !  LDA+U
250
    n_u_in=atoms%n_u
251 252
    IF ((atoms%n_u.GT.0)) THEN
       ALLOCATE( vs_mmp(-lmaxb:lmaxb,-lmaxb:lmaxb,atoms%n_u,input%jspins) )
Daniel Wortmann's avatar
Daniel Wortmann committed
253
       CALL u_setup(sym,atoms,lmaxb,sphhar,input, enpara%el0(0:,:,:),v%mt,mpi, vs_mmp,results)
254 255 256 257 258 259 260
    ELSE
       ALLOCATE( vs_mmp(-lmaxb:-lmaxb,-lmaxb:-lmaxb,1,2) )
    ENDIF
    !
    !--->    loop over k-points: each can be a separate task

    DO jsp = 1,nspins
Daniel Wortmann's avatar
Daniel Wortmann committed
261
       
262 263 264 265 266 267 268

       !
       !--->       set up k-point independent t(l'm',lm) matrices
       !
       CALL timestart("tlmplm")
       err=0
       j = 1 ; IF (noco%l_noco) j = 2
269 270 271 272
       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
273 274 275 276
       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)
277
       ALLOCATE(td%ind(0:DIMENSION%lmd,0:DIMENSION%lmd,atoms%ntype,j),stat=err )
278 279 280 281 282
       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
283
       lh0=1
Daniel Wortmann's avatar
Daniel Wortmann committed
284
       CALL tlmplm(sphhar,atoms,DIMENSION,enpara, jsp,1,mpi, v%mt(1,0,1,jsp),lh0,input, td,ud)
285
       IF (input%l_f) CALL write_tlmplm(td,vs_mmp,atoms%n_u>0,1,jsp,input%jspins)
286 287 288 289 290 291 292 293 294
       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")
Daniel Wortmann's avatar
Daniel Wortmann committed
295
          CALL tlmplm(sphhar,atoms,DIMENSION,enpara,isp,isp,mpi, v%mt(1,0,1,isp),lh0,input, td,ud)
296
          IF (input%l_f) CALL write_tlmplm(td,vs_mmp,atoms%n_u>0,2,2,input%jspins)
297 298 299 300
          CALL timestop("tlmplm")
       ENDIF
       !

301
#ifdef CPP_MPI
302 303
       ! check that all sending operations are completed
       IF ( hybrid%l_calhf ) CALL MPI_WAITALL(sndreqd,sndreq,MPI_STATUSES_IGNORE,ierr)
304
#endif
305

Daniel Wortmann's avatar
Daniel Wortmann committed
306
       k_loop:DO nk = mpi%n_start,kpts%nkpt,mpi%n_stride
307 308 309 310 311

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

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

316
          CALL timestop("Setup of LAPW")
317 318 319 320 321 322 323 324
          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
          !
325
          CALL timestart("Interstitial Hamiltonian&Overlap")
Daniel Wortmann's avatar
Daniel Wortmann committed
326
          CALL hsint(input,noco,jij,stars, v%pw(:,jsp),lapw,jsp, mpi%n_size,mpi%n_rank,kpts%bk(:,nk),cell,atoms,l_real,hamOvlp)
327

328
          CALL timestop("Interstitial Hamiltonian&Overlap")
329 330 331
          !
          !--->         update with sphere terms
          !
332 333 334
          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,&
Daniel Wortmann's avatar
Daniel Wortmann committed
335
                  lmaxb, noco,cell, lapw, bkpt,v%mt, vs_mmp, oneD,ud, kveclo,td,l_real,hamOvlp)
336
             CALL timestop("MT Hamiltonian&Overlap")
337 338
          ENDIF
          !
339
          IF( hybrid%l_hybrid ) THEN
Daniel Wortmann's avatar
Daniel Wortmann committed
340 341
             !write overlap matrix b to direct access file olap
             print *,"Wrong overlap matrix used, fix this later"
Daniel Wortmann's avatar
Daniel Wortmann committed
342
             call olap%from_packed(l_real,dimension%nbasfcn,hamovlp%b_r,hamovlp%b_c)
Daniel Wortmann's avatar
Daniel Wortmann committed
343 344
             call write_olap(olap,nrec)
            
Daniel Wortmann's avatar
Daniel Wortmann committed
345 346 347
             if (hybrid%l_addhf) CALL add_Vnonlocal(nk,hybrid,dimension, kpts,jsp,results,xcpot,hamovlp)
             
             
348 349 350
             IF ( irank2(nk) /= 0 ) CYCLE

             IF( hybrid%l_subvxc ) THEN
Daniel Wortmann's avatar
Daniel Wortmann committed
351
                CALL subvxc(lapw,kpts%bk(:,nk),DIMENSION,input,jsp,v%mt(:,0,:,:),atoms,ud,hybrid,enpara%el0,enpara%ello0,&
Daniel Wortmann's avatar
Daniel Wortmann committed
352
                     sym, atoms%nlotot,kveclo, cell,sphhar, stars, xcpot,mpi,&
Daniel Wortmann's avatar
Daniel Wortmann committed
353
                     oneD,  hamovlp,vx)
354 355
             END IF

356
          END IF ! hybrid%l_hybrid
357 358 359
          !
          !--->         update with vacuum terms
          !
360
          CALL timestart("Vacuum Hamiltonian&Overlap")
361
          IF (input%film .AND. .NOT.oneD%odi%d1) THEN
Daniel Wortmann's avatar
Daniel Wortmann committed
362
             CALL hsvac(vacuum,stars,DIMENSION, atoms, jsp,input,v%vacxy(1,1,1,jsp),v%vacz,enpara%evac0,cell, &
Daniel Wortmann's avatar
Daniel Wortmann committed
363
                  bkpt,lapw,sym, noco,jij, mpi%n_size,mpi%n_rank,nv2,l_real,hamOvlp)
364
          ELSEIF (oneD%odi%d1) THEN
Daniel Wortmann's avatar
Daniel Wortmann committed
365
             CALL od_hsvac(vacuum,stars,DIMENSION, oneD,atoms, jsp,input,v%vacxy(1,1,1,jsp),v%vacz, &
366
                  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
367
                  mpi%n_size,mpi%n_rank,sym,noco,jij,nv2,l_real,hamOvlp)
368
          END IF
369
          CALL timestop("Vacuum Hamiltonian&Overlap")
370 371 372

          IF (noco%l_noco) CLOSE (25)

Daniel Wortmann's avatar
Daniel Wortmann committed
373 374 375
         
          
          
376
          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
377
               nred,mpi%sub_comm, sym,l_zref,matind,kveclo, noco,cell,bkpt,enpara%el0,jij,l_wu,&
378
               oneD,td,ud, eig,ne_found,hamOvlp,zMat)
379
          
380 381 382 383
          !
          !--->         output results
          !
          CALL timestart("EV output")
384
          ne_all=ne_found
385 386
#if defined(CPP_MPI)
          !Collect number of all eigenvalues
Daniel Wortmann's avatar
Daniel Wortmann committed
387
          CALL MPI_ALLREDUCE(ne_found,ne_all,1,MPI_INTEGER,MPI_SUM, mpi%sub_comm,ierr)
388
          ne_all=MIN(DIMENSION%neigd,ne_all)
389 390
#endif
          !jij%eig_l = 0.0 ! need not be used, if hdf-file is present
391 392 393
          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))
394
             ELSE
395
                zMat%z_c(:lapw%nmat,:ne_found) = CMPLX(0.0,0.0)
396
             ENDIF
397
          ENDIF
Daniel Wortmann's avatar
Daniel Wortmann committed
398
	  zmat%nbands=ne_found
399
          CALL write_eig(eig_id, nk,jsp,ne_found,ne_all,lapw%nv(jsp),lapw%nmat,&
400
                  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
401 402
                  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)
403
          IF (noco%l_noco) THEN
404
             CALL write_eig(eig_id, nk,2,ne_found,ne_all,lapw%nv(2),lapw%nmat,&
405
                  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
406 407
                  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)
408
          ENDIF
409 410 411 412
#if defined(CPP_MPI)
          !RMA synchronization
          CALL MPI_BARRIER(mpi%MPI_COMM,ierr)
#endif
413 414 415

          CALL timestop("EV output")
          !#ifdef CPP_MPI
416
          IF (l_real) THEN
417
             DEALLOCATE ( zMat%z_r )
418
          ELSE
419
             DEALLOCATE ( zMat%z_c )
420
ENDIF
421 422 423 424 425 426 427 428
          !
       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
    DEALLOCATE( vs_mmp )
429
    DEALLOCATE (matind)
430 431 432 433 434
    IF (l_real) THEN
       DEALLOCATE(hamOvlp%a_r,hamOvlp%b_r)
    ELSE
       DEALLOCATE(hamOvlp%a_c,hamOvlp%b_c)
    ENDIF
435
#if defined(CPP_MPI)&&defined(CPP_NEVER)
436
    IF ( hybrid%l_calhf ) DEALLOCATE (nkpt_EIBZ)
437
#endif
438

Daniel Wortmann's avatar
Daniel Wortmann committed
439
  
440
#ifdef CPP_MPI
441
    CALL MPI_BARRIER(mpi%MPI_COMM,ierr)
442
#endif
Daniel Wortmann's avatar
Daniel Wortmann committed
443
    !IF (hybrid%l_hybrid.OR.hybrid%l_calhf) CALL close_eig(eig_id)
444
    atoms%n_u=n_u_in
445 446


447
    IF( input%jspins .EQ. 1 .AND. hybrid%l_hybrid ) THEN
448 449 450
       results%te_hfex%valence = 2*results%te_hfex%valence
       results%te_hfex%core    = 2*results%te_hfex%core
    END IF
451 452
    enpara_in%epara_min = MINVAL(enpara%el0)
    enpara_in%epara_min = MIN(MINVAL(enpara%ello0),enpara_in%epara_min)
453
!    enpara_in=enpara
454 455
  END SUBROUTINE eigen
END MODULE m_eigen