IffGit has a new shared runner for building Docker images in GitLab CI. Visit https://iffgit.fz-juelich.de/examples/ci-docker-in-docker for more details.

eigen.F90 18.4 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
Daniel Wortmann's avatar
Daniel Wortmann committed
43
    USE m_io_hybrid
44
45
46
#ifdef CPP_MPI
    USE m_mpi_bc_pot
#endif
47
48
49
50
51

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

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

Daniel Wortmann's avatar
Daniel Wortmann committed
107

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

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

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

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

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

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

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

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

Daniel Wortmann's avatar
Daniel Wortmann committed
193
194

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

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

243
244
245
246
247
    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
248
249
250
251

    hamOvlp%l_real = l_real
    hamOvlp%matsize = matsize

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

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

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

Daniel Wortmann's avatar
Daniel Wortmann committed
316
       k_loop:DO nk = mpi%n_start,kpts%nkpt,mpi%n_stride
317
#if defined(CPP_MPI)&&defined(CPP_NEVER)
318
319
320
321
          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
322
             IF ( irank2(nk) /= 0 ) CALL work_dist_reserve_buffer( hybdat%nbands(nk) )
323
          END IF
324
#endif
325
326

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

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

346
          CALL timestop("Interstitial Hamiltonian&Overlap")
347
348
349
          !
          !--->         update with sphere terms
          !
350
351
352
          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
353
                  lmaxb, noco,cell, lapw, bkpt,v%mt, vs_mmp, oneD,ud, kveclo,td,l_real,hamOvlp)
354
             CALL timestop("MT Hamiltonian&Overlap")
355
356
          ENDIF
          !
357
          IF( hybrid%l_hybrid ) THEN
Daniel Wortmann's avatar
Daniel Wortmann committed
358
359
360
361
362
             !write overlap matrix b to direct access file olap
             print *,"Wrong overlap matrix used, fix this later"
             call olap%from_packed(dimension%nbasfcn,l_real,hamovlp%b_r,hamovlp%b_c)
             call write_olap(olap,nrec)
            
363

Daniel Wortmann's avatar
Daniel Wortmann committed
364
             CALL hsfock(nk,atoms,hybrid,lapw,DIMENSION,kpts,jsp,input,hybdat,eig_irr,&
Daniel Wortmann's avatar
Daniel Wortmann committed
365
366
                  sym,cell,noco,results,it,maxval(hybdat%nobd),xcpot,&
                  mpi,irank2(nk),isize2(nk),comm(nk), hamovlp)
367
368
369
370

             IF ( irank2(nk) /= 0 ) CYCLE

             IF( hybrid%l_subvxc ) THEN
Daniel Wortmann's avatar
Daniel Wortmann committed
371
372
373
                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)
374
375
             END IF

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

          IF (noco%l_noco) CLOSE (25)

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

434
#if defined(CPP_MPI)&&defined(CPP_NEVER)
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
          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
450
          IF (l_real) THEN
451
             DEALLOCATE ( zMat%z_r )
452
          ELSE
453
             DEALLOCATE ( zMat%z_c )
454
ENDIF
455
456
457
458
459
460
461
462
463
464
465
466
467
          !
       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 )
468
    DEALLOCATE (matind)
469
470
471
472
473
    IF (l_real) THEN
       DEALLOCATE(hamOvlp%a_r,hamOvlp%b_r)
    ELSE
       DEALLOCATE(hamOvlp%a_c,hamOvlp%b_c)
    ENDIF
474
475
476
477
478
479
#ifdef CPP_NEVER
    IF( hybrid%l_calhf ) THEN
       DEALLOCATE( fac,sfac,gauntarr )
       DEALLOCATE( nindxc,core1,core2,nbasm,eig_c )
    END IF
#endif
480
#if defined(CPP_MPI)&&defined(CPP_NEVER)
481
    IF ( hybrid%l_calhf ) DEALLOCATE (nkpt_EIBZ)
482
#endif
483

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

#ifdef CPP_MPI
499
    CALL MPI_BARRIER(mpi%MPI_COMM,ierr)
500
#endif
Daniel Wortmann's avatar
Daniel Wortmann committed
501
    !IF (hybrid%l_hybrid.OR.hybrid%l_calhf) CALL close_eig(eig_id)
502
    atoms%n_u=n_u_in
503
504


505
    IF( input%jspins .EQ. 1 .AND. hybrid%l_hybrid ) THEN
506
507
508
       results%te_hfex%valence = 2*results%te_hfex%valence
       results%te_hfex%core    = 2*results%te_hfex%core
    END IF
509
510
    enpara_in%epara_min = MINVAL(enpara%el0)
    enpara_in%epara_min = MIN(MINVAL(enpara%ello0),enpara_in%epara_min)
511
!    enpara_in=enpara
512
513
  END SUBROUTINE eigen
END MODULE m_eigen