eigen.F90 18.6 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)
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
33 34
    USE m_eigen_hf_init
    USE m_eigen_hf_setup
35 36 37 38 39
    USE m_hsfock
    USE m_subvxc
    USE m_hsefunctional
    USE m_hybridmix    , ONLY: amix_pbe0,amix_hf
    USE m_util
40
    USE m_icorrkeys
41
    USE m_eig66_io, ONLY : open_eig, write_eig, close_eig,read_eig
42
    USE m_xmlOutput
43 44 45
#ifdef CPP_MPI
    USE m_mpi_bc_pot
#endif
46 47 48 49 50

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

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

Daniel Wortmann's avatar
Daniel Wortmann committed
105

106 107
    !     .. variables for HF or hybrid functional calculation ..
    !
Daniel Wortmann's avatar
Daniel Wortmann committed
108
    TYPE(t_hybdat)          :: hybdat
109
    INTEGER                 ::  comm(kpts%nkpt),irank2(kpts%nkpt),isize2(kpts%nkpt)
110 111 112
    REAL,    ALLOCATABLE    ::  eig_irr(:,:),vr0(:,:,:)

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

Daniel Wortmann's avatar
Daniel Wortmann committed
142
    
143 144 145 146 147
    fh = 0
    !
    ! look, if WU diagonalisation
    !
    IF (it.LT.input%isec1) THEN
148
       IF (mpi%irank.EQ.0) WRITE (6,FMT=8110) it,input%isec1
149
8110   FORMAT (' IT=',i4,'  ISEC1=',i4,' standard diagonalization')
150
       l_wu = .FALSE.
151
    ELSE
152
       IF (mpi%irank.EQ.0) WRITE (6,FMT=8120) it,input%isec1
153
8120   FORMAT (' IT=',i4,'  ISEC1=',i4,' reduced diagonalization')
154
       l_wu = .TRUE.
155 156 157 158
    END IF
    !
    ! load potential from file pottot (=unit 8)
    !
159
    ALLOCATE ( vr0(atoms%jmtd,atoms%ntype,DIMENSION%jspd) ) ; vr0 = 0
Daniel Wortmann's avatar
Daniel Wortmann committed
160 161 162 163 164
   
    !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
165 166
#ifdef CPP_MPI
    CALL mpi_bc_pot(mpi,stars,sphhar,atoms,input,vacuum,&
Daniel Wortmann's avatar
Daniel Wortmann committed
167
                    v%iter,v%mt,v%pw,v%vacz,v%vacxy)
168 169
#endif

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

Daniel Wortmann's avatar
Daniel Wortmann committed
174
   
175 176 177
    !
    ! set energy parameters (normally to that, what we read in)
    !
Daniel Wortmann's avatar
Daniel Wortmann committed
178 179
    CALL lodpot(mpi,atoms,sphhar,obsolete,vacuum,&
            input, v%mt,v%vacz, enpara_in, enpara)
180
    !
181
   
Daniel Wortmann's avatar
Daniel Wortmann committed
182
    CALL eigen_hf_init(hybrid,kpts,atoms,input,dimension,hybdat,irank2,isize2)
183 184 185 186

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

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

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

Daniel Wortmann's avatar
Daniel Wortmann committed
191 192

#if ( defined(CPP_MPI))
193
    IF (mpi%n_size > 1) l_zref = .FALSE.
194
    IF ( hybrid%l_calhf ) THEN
195
       CALL judft_error("BUG parallelization in HF case must be fixed")
Daniel Wortmann's avatar
Daniel Wortmann committed
196 197
       !n_start  = 1
       !n_stride = 1
198 199
    END IF
#endif
Daniel Wortmann's avatar
Daniel Wortmann committed
200 201
    !Count number of matrix columns on this PE
    n=0
202
    DO i=1+mpi%n_rank,DIMENSION%nbasfcn,mpi%n_size
Daniel Wortmann's avatar
Daniel Wortmann committed
203
       n=n+1
204
    ENDDO
Daniel Wortmann's avatar
Daniel Wortmann committed
205
    IF (mpi%n_size>1) THEN
206
       matsize = DIMENSION%nbasfcn * n
Daniel Wortmann's avatar
Daniel Wortmann committed
207
    ELSE
208 209 210 211 212
       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
213
    ENDIF
214 215
    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
216

Daniel Wortmann's avatar
Daniel Wortmann committed
217 218
    IF (.not.hybrid%l_calhf) THEN
       eig_id=open_eig(&
219 220 221 222
         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,&
223
         l_orb=banddos%l_orb)
Daniel Wortmann's avatar
Daniel Wortmann committed
224
    endif
225
    IF (l_real) THEN
226
       ALLOCATE ( hamOvlp%a_r(matsize), stat = err )
227
    ELSE
228
       ALLOCATE ( hamOvlp%a_c(matsize), stat = err )
229
    ENDIF
230 231 232 233 234
    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
235
    IF (l_real) THEN
236
       ALLOCATE ( hamOvlp%b_r(matsize), stat = err )
237
    ELSE
238
       ALLOCATE ( hamOvlp%b_c(matsize), stat = err )
239
    ENDIF
240

241 242 243 244 245
    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
246 247 248 249

    hamOvlp%l_real = l_real
    hamOvlp%matsize = matsize

250
    ALLOCATE (  matind(DIMENSION%nbasfcn,2) )
251 252 253 254 255 256 257
    !
    !--->    loop over spins
    nspins = input%jspins
    IF (noco%l_noco) nspins = 1
    !
    !  ..
    !  LDA+U
258
    n_u_in=atoms%n_u
259 260
    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
261
       CALL u_setup(sym,atoms,lmaxb,sphhar,input, enpara%el0(0:,:,:),v%mt,mpi, vs_mmp,results)
262 263 264 265 266 267 268
    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
269
       CALL eigen_HF_setup(hybrid,input,sym,kpts,dimension,atoms,mpi,noco,cell,oneD,results,jsp,eig_id,&
Daniel Wortmann's avatar
Daniel Wortmann committed
270
         hybdat,irank2,it,l_real,vr0)  
271 272 273 274 275 276 277

       !
       !--->       set up k-point independent t(l'm',lm) matrices
       !
       CALL timestart("tlmplm")
       err=0
       j = 1 ; IF (noco%l_noco) j = 2
278 279 280 281
       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
282 283 284 285
       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)
286
       ALLOCATE(td%ind(0:DIMENSION%lmd,0:DIMENSION%lmd,atoms%ntype,j),stat=err )
287 288 289 290 291
       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
292
       CALL tlmplm(sphhar,atoms,DIMENSION,enpara, jsp,1,mpi, v%mt(1,0,1,jsp),lh0,input, td,ud)
293
       IF (input%l_f) CALL write_tlmplm(td,vs_mmp,atoms%n_u>0,1,jsp,input%jspins)
294 295 296 297 298 299 300 301 302
       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
303
          CALL tlmplm(sphhar,atoms,DIMENSION,enpara,isp,isp,mpi, v%mt(1,0,1,isp),lh0,input, td,ud)
304
          IF (input%l_f) CALL write_tlmplm(td,vs_mmp,atoms%n_u>0,2,2,input%jspins)
305 306 307 308
          CALL timestop("tlmplm")
       ENDIF
       !

309
#ifdef CPP_MPI
310 311
       ! check that all sending operations are completed
       IF ( hybrid%l_calhf ) CALL MPI_WAITALL(sndreqd,sndreq,MPI_STATUSES_IGNORE,ierr)
312
#endif
313

Daniel Wortmann's avatar
Daniel Wortmann committed
314
       k_loop:DO nk = mpi%n_start,kpts%nkpt,mpi%n_stride
315
#if defined(CPP_MPI)&&defined(CPP_NEVER)
316 317 318 319
          IF ( hybrid%l_calhf ) THEN
             ! jump to next k-point if this process is not present in communicator
             IF ( comm(nk) == MPI_COMM_NULL ) CYCLE
             ! allocate buffer for communication of the results
Daniel Wortmann's avatar
Daniel Wortmann committed
320
             IF ( irank2(nk) /= 0 ) CALL work_dist_reserve_buffer( hybdat%nbands(nk) )
321
          END IF
322
#endif
323 324

          nrec =  kpts%nkpt*(jsp-1) + nk
Daniel Wortmann's avatar
Daniel Wortmann committed
325
          nrec = mpi%n_size*(nrec-1) + mpi%n_rank + 1
326 327 328
          !
          !--->         set up lapw list
          !
329 330
          CALL timestart("Setup of LAPW")
          CALL apws(DIMENSION,input,noco, kpts,nk,cell,l_zref, mpi%n_size,jsp, bkpt,lapw,matind,nred)
331

332
          CALL timestop("Setup of LAPW")
333 334 335 336 337 338 339 340
          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
          !
341
          CALL timestart("Interstitial Hamiltonian&Overlap")
Daniel Wortmann's avatar
Daniel Wortmann committed
342
          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)
343

344
          CALL timestop("Interstitial Hamiltonian&Overlap")
345 346 347
          !
          !--->         update with sphere terms
          !
348 349 350
          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
351
                  lmaxb, noco,cell, lapw, bkpt,v%mt, vs_mmp, oneD,ud, kveclo,td,l_real,hamOvlp)
352
             CALL timestop("MT Hamiltonian&Overlap")
353 354
          ENDIF
          !
355
          IF( hybrid%l_hybrid ) THEN
356

Daniel Wortmann's avatar
Daniel Wortmann committed
357
             CALL hsfock(nk,atoms,hybrid,lapw,DIMENSION,kpts,jsp,input,hybdat,eig_irr,&
Daniel Wortmann's avatar
Daniel Wortmann committed
358 359
                  sym,cell,noco,results,it,maxval(hybdat%nobd),xcpot,&
                  mpi,irank2(nk),isize2(nk),comm(nk), hamovlp)
360 361 362 363

             IF ( irank2(nk) /= 0 ) CYCLE

             IF( hybrid%l_subvxc ) THEN
Daniel Wortmann's avatar
Daniel Wortmann committed
364 365 366
                CALL subvxc(lapw,kpts%bk(:,nk),DIMENSION,input,jsp,vr0,atoms,ud,hybrid,enpara%el0,enpara%ello0,&
                     sym, atoms%nlotot,kveclo, cell,sphhar, stars, xcpot,mpi,&
                     oneD,  hamovlp)
367 368
             END IF

369
          END IF ! hybrid%l_hybrid
370 371 372
          !
          !--->         update with vacuum terms
          !
373
          CALL timestart("Vacuum Hamiltonian&Overlap")
374
          IF (input%film .AND. .NOT.oneD%odi%d1) THEN
Daniel Wortmann's avatar
Daniel Wortmann committed
375
             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
376
                  bkpt,lapw,sym, noco,jij, mpi%n_size,mpi%n_rank,nv2,l_real,hamOvlp)
377
          ELSEIF (oneD%odi%d1) THEN
Daniel Wortmann's avatar
Daniel Wortmann committed
378
             CALL od_hsvac(vacuum,stars,DIMENSION, oneD,atoms, jsp,input,v%vacxy(1,1,1,jsp),v%vacz, &
379
                  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
380
                  mpi%n_size,mpi%n_rank,sym,noco,jij,nv2,l_real,hamOvlp)
381
          END IF
382
          CALL timestop("Vacuum Hamiltonian&Overlap")
383 384 385 386

          IF (noco%l_noco) CLOSE (25)

          !write overlap matrix b to direct access file olap
387 388 389
          INQUIRE(file='olap',exist=l_file)
          IF (l_file) THEN
             IF (l_real) THEN
390
                OPEN(88,file='olap',form='unformatted',access='direct', recl=matsize*8)
391
                WRITE(88,rec=nrec) hamOvlp%b_r
392
                CLOSE(88)
393
             ELSE
394
                OPEN(88,file='olap',form='unformatted',access='direct', recl=matsize*16)
395
                WRITE(88,rec=nrec) hamOvlp%b_c
396
                CLOSE(88)
397 398
             ENDIF
          ENDIF
399

400
       
401
          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
402
               nred,mpi%sub_comm, sym,l_zref,matind,kveclo, noco,cell,bkpt,enpara%el0,jij,l_wu,&
403
               oneD,td,ud, eig,ne_found,hamOvlp,zMat)
404
          
405 406 407 408
          !
          !--->         output results
          !
          CALL timestart("EV output")
409
          ne_all=ne_found
410 411
#if defined(CPP_MPI)
          !Collect number of all eigenvalues
Daniel Wortmann's avatar
Daniel Wortmann committed
412
          CALL MPI_ALLREDUCE(ne_found,ne_all,1,MPI_INTEGER,MPI_SUM, mpi%sub_comm,ierr)
413
          ne_all=MIN(DIMENSION%neigd,ne_all)
414 415
#endif
          !jij%eig_l = 0.0 ! need not be used, if hdf-file is present
416 417 418
          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))
419
             ELSE
420
                zMat%z_c(:lapw%nmat,:ne_found) = CMPLX(0.0,0.0)
421
             ENDIF
422
          ENDIF
Daniel Wortmann's avatar
Daniel Wortmann committed
423
	  zmat%nbands=ne_found
424
          CALL write_eig(eig_id, nk,jsp,ne_found,ne_all,lapw%nv(jsp),lapw%nmat,&
425 426
                  lapw%k1(:lapw%nv(jsp),jsp),lapw%k2 (:lapw%nv(jsp),jsp),lapw%k3(:lapw%nv(jsp),jsp),&
                  bkpt, kpts%wtkpt(nk),eig(:ne_found),enpara%el0(0:,:,jsp), enpara%ello0(:,:,jsp),enpara%evac0(:,jsp),&
427
                  atoms%nlotot,kveclo,mpi%n_size,mpi%n_rank,zMat)
428
          IF (noco%l_noco) THEN
429
             CALL write_eig(eig_id, nk,2,ne_found,ne_all,lapw%nv(2),lapw%nmat,&
430
                  lapw%k1(:lapw%nv(2),2),lapw%k2 (:lapw%nv(2),2),lapw%k3(:lapw%nv(2),2),&
431
                  bkpt, kpts%wtkpt(nk),eig(:ne_found),enpara%el0(0:,:,2), enpara%ello0(:,:,2),enpara%evac0(:,2),&
432 433
                  atoms%nlotot,kveclo)
          ENDIF
434 435 436 437
#if defined(CPP_MPI)
          !RMA synchronization
          CALL MPI_BARRIER(mpi%MPI_COMM,ierr)
#endif
438

439
#if defined(CPP_MPI)&&defined(CPP_NEVER)
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454
          IF ( hybrid%l_calhf ) THEN
             IF ( isize2(nk) == 1 ) THEN
                WRITE(*,'(a,i6,a,i6,a)') 'HF: kpt ', nk, ' was done by rank ', mpi%irank, '.'
             ELSE
                WRITE(*,'(a,i6,a,i6,a,i6,a)')&
                     'HF: kpt ', nk, ' was done by rank ', mpi%irank, ' and ', isize2(nk)-1, ' more.'
             END IF
             !                ELSE
             !                  WRITE(*,'(a,i6,a,i6,a)')        '    kpt ', nk, ' was done by rank ', irank, '.'
          END IF
          !#             else
          !                WRITE (*,*) 'pe: ',irank,' wrote ',nrec
#             endif
          CALL timestop("EV output")
          !#ifdef CPP_MPI
455
          IF (l_real) THEN
456
             DEALLOCATE ( zMat%z_r )
457
          ELSE
458
             DEALLOCATE ( zMat%z_c )
459
ENDIF
460 461 462 463 464 465 466 467 468 469 470 471 472
          !
       END DO  k_loop

       DEALLOCATE (td%tuu,td%tud,td%tdu,td%tdd)
       DEALLOCATE (td%ind,td%tuulo,td%tdulo)
       DEALLOCATE (td%tuloulo)
#ifdef CPP_NEVER
       IF ( hybrid%l_calhf ) THEN
          DEALLOCATE ( eig_irr,kveclo_eig )
       END IF
#endif
    END DO ! spin loop ends
    DEALLOCATE( vs_mmp )
473
    DEALLOCATE (matind)
474 475 476 477 478
    IF (l_real) THEN
       DEALLOCATE(hamOvlp%a_r,hamOvlp%b_r)
    ELSE
       DEALLOCATE(hamOvlp%a_c,hamOvlp%b_c)
    ENDIF
479 480 481 482 483 484
#ifdef CPP_NEVER
    IF( hybrid%l_calhf ) THEN
       DEALLOCATE( fac,sfac,gauntarr )
       DEALLOCATE( nindxc,core1,core2,nbasm,eig_c )
    END IF
#endif
485
#if defined(CPP_MPI)&&defined(CPP_NEVER)
486
    IF ( hybrid%l_calhf ) DEALLOCATE (nkpt_EIBZ)
487
#endif
488

Daniel Wortmann's avatar
Daniel Wortmann committed
489
  
490
    !     hf: write out radial potential vr0
491
    IF (hybrid%l_hybrid.OR.hybrid%l_calhf) THEN
492 493
       OPEN(unit=120,file='vr0',form='unformatted')
       DO isp=1,DIMENSION%jspd
Daniel Wortmann's avatar
Daniel Wortmann committed
494
          DO nn=1,atoms%ntype
495
             DO i=1,atoms%jmtd
Daniel Wortmann's avatar
Daniel Wortmann committed
496
                WRITE(120) vr0(i,nn,isp)
497 498 499 500 501 502 503
             END DO
          END DO
       END DO
       CLOSE(120)
    ENDIF

#ifdef CPP_MPI
504
    CALL MPI_BARRIER(mpi%MPI_COMM,ierr)
505
#endif
Daniel Wortmann's avatar
Daniel Wortmann committed
506
    !IF (hybrid%l_hybrid.OR.hybrid%l_calhf) CALL close_eig(eig_id)
507
    atoms%n_u=n_u_in
508 509


510
    IF( input%jspins .EQ. 1 .AND. hybrid%l_hybrid ) THEN
511 512 513
       results%te_hfex%valence = 2*results%te_hfex%valence
       results%te_hfex%core    = 2*results%te_hfex%core
    END IF
514 515
    enpara_in%epara_min = MINVAL(enpara%el0)
    enpara_in%epara_min = MIN(MINVAL(enpara%ello0),enpara_in%epara_min)
516
!    enpara_in=enpara
517 518
  END SUBROUTINE eigen
END MODULE m_eigen