cdnval.F90 17.3 KB
Newer Older
1 2 3 4
MODULE m_cdnval
  use m_juDFT
CONTAINS
  SUBROUTINE cdnval(eig_id, mpi,kpts,jspin,sliceplot,noco, input,banddos,cell,atoms,enpara,stars,&
5
                    vacuum,dimension,sphhar,sym,obsolete,vTot,oneD,coreSpecInput,cdnvalKLoop,den,regCharges,results,&
6 7
                    moments,mcd,slab)

8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
    !     ***********************************************************
    !         this subroutin is a modified version of cdnval.F.
    !         it calculates a layer charge distribution and an orbital
    !         composition for each state in a film.
    !         this information is written in the  'ek_orbcomp'  file
    !                                    Yu.Koroteev  01.12.2003
    !     ***********************************************************
    !     flapw7 valence density generator
    !                                         c.l.fu
    !     zelec used to calculate ne - 6.12.95 r.pentcheva
    !
    !     changed subroutine to allow parallel writing of vacdos&dosinp
    !     used temporary direct access file 84,tmp_dos to store data used
    !     in cdninf
    !     call of cdninf changed, sympsi is called from cdnval now
    !     look for 'ifdef CPP_MPI' -blocks!               d.wortmann 6.5.99
    !
    !******** ABBREVIATIONS ************************************************
    !     nbands   : number of bands in the energy window
    !     noccbd   : number of occupied bands
    !     slice    : when set to .true. the charge density of a enery range
    !                (slice) or a single state is calculated
    !     e1s,e2s  : (used if slice) energy range for the slice. if both
    !                are set to 0.0 the charge density of the band nr. nnne
    !                is calculated
    !     pallst   : (used if slice) if set to .true. bands above the
    !                Fermi-Energy are taken into account
    !     nnne     : (used if slice) number of the band of which the charge
    !                density is calculated if e1s and e2s are 0.0
    !     kk       : (used if slice) if set to 0 all k-points are used to
    !                calculate the charge density of the slice, otherwise
    !                only k-points kk is taken into account
    !     nslibd   : number of bands in slice
    !     ener     : band energy averaged over all bands and k-points,
    !                wheighted with the l-like charge of each atom type
    !     sqal     : l-like charge of each atom type. sum over all k-points
    !                and bands
    !***********************************************************************
46

47
    USE m_eig66_io
48
    USE m_genMTBasis
49
    USE m_calcDenCoeffs
50 51 52 53 54 55 56 57 58 59 60
    USE m_mcdinit
    USE m_sympsi
    USE m_eparas      ! energy parameters and partial charges
    USE m_qal21       ! off-diagonal part of partial charges
    USE m_abcof
    USE m_nmat        ! calculate density matrix for LDA + U
    USE m_vacden
    USE m_pwden
    USE m_forcea8
    USE m_forcea12
    USE m_forcea21
61
    USE m_checkdopall
62
    USE m_cdnmt       ! calculate the density and orbital moments etc.
63 64 65
    USE m_orbmom      ! coeffd for orbital moments
    USE m_qmtsl       ! These subroutines divide the input%film into vacuum%layers
    USE m_qintsl      ! (slabs) and intergate the DOS in these vacuum%layers
66
    USE m_orbcomp     ! calculate orbital composition (like p_x,p_y,p_z)
67
    USE m_abcrot2
68 69 70
    USE m_corespec, only : l_cs    ! calculation of core spectra (EELS)
    USE m_corespec_io, only : corespec_init
    USE m_corespec_eval, only : corespec_gaunt,corespec_rme,corespec_dos,corespec_ddscs
71
#ifdef CPP_MPI
72
    USE m_mpi_col_den ! collect density data from parallel nodes
73 74
#endif
    USE m_types
75
    USE m_xmlOutput
76
    IMPLICIT NONE
77 78 79 80
    TYPE(t_results),       INTENT(INOUT) :: results
    TYPE(t_mpi),           INTENT(IN)    :: mpi
    TYPE(t_dimension),     INTENT(IN)    :: dimension
    TYPE(t_oneD),          INTENT(IN)    :: oneD
81
    TYPE(t_enpara),        INTENT(IN)    :: enpara
82 83 84 85 86 87 88 89 90 91 92 93 94 95
    TYPE(t_obsolete),      INTENT(IN)    :: obsolete
    TYPE(t_banddos),       INTENT(IN)    :: banddos
    TYPE(t_sliceplot),     INTENT(IN)    :: sliceplot
    TYPE(t_input),         INTENT(IN)    :: input
    TYPE(t_vacuum),        INTENT(IN)    :: vacuum
    TYPE(t_noco),          INTENT(IN)    :: noco
    TYPE(t_sym),           INTENT(IN)    :: sym
    TYPE(t_stars),         INTENT(IN)    :: stars
    TYPE(t_cell),          INTENT(IN)    :: cell
    TYPE(t_kpts),          INTENT(IN)    :: kpts
    TYPE(t_sphhar),        INTENT(IN)    :: sphhar
    TYPE(t_atoms),         INTENT(IN)    :: atoms
    TYPE(t_coreSpecInput), INTENT(IN)    :: coreSpecInput
    TYPE(t_potden),        INTENT(IN)    :: vTot
96
    TYPE(t_cdnvalKLoop),   INTENT(IN)    :: cdnvalKLoop
97 98 99
    TYPE(t_potden),        INTENT(INOUT) :: den
    TYPE(t_regionCharges), INTENT(INOUT) :: regCharges
    TYPE(t_moments),       INTENT(INOUT) :: moments
100 101
    TYPE(t_mcd),           INTENT(INOUT) :: mcd
    TYPE(t_slab),          INTENT(INOUT) :: slab
102

103
    !     .. Scalar Arguments ..
104
    INTEGER, INTENT(IN)              :: eig_id,jspin
105 106 107 108

#ifdef CPP_MPI
    INCLUDE 'mpif.h'
#endif
109

110
    !     .. Local Scalars ..
111
    INTEGER :: ikpt,jsp_start,jsp_end,ispin,jsp
112
    INTEGER :: i,ie,ivac,j,k,l,ilo,nbands,noccbd,iType
113 114
    INTEGER :: skip_t,skip_tt
    INTEGER :: nStart,nEnd,nbasfcn
115
    LOGICAL :: l_orbcomprot,l_real, l_write
116

117
    !     ...Local Arrays ..
118
    INTEGER, ALLOCATABLE :: jsym(:),ksym(:)
119
    REAL,    ALLOCATABLE :: we(:)
120
    REAL,    ALLOCATABLE :: eig(:)
121
    REAL,    ALLOCATABLE :: f(:,:,:,:),g(:,:,:,:),flo(:,:,:,:) ! radial functions
122

123
    TYPE (t_lapw)             :: lapw
124 125 126
    TYPE (t_orb)              :: orb
    TYPE (t_denCoeffs)        :: denCoeffs
    TYPE (t_denCoeffsOffdiag) :: denCoeffsOffdiag
127
    TYPE (t_force)            :: force
128
    TYPE (t_eigVecCoeffs)     :: eigVecCoeffs
129 130
    TYPE (t_usdus)            :: usdus
    TYPE (t_zMat)             :: zMat
131
    TYPE (t_orbcomp)          :: orbcomp
132
    TYPE (t_gVacMap)          :: gVacMap
133

134 135
    CALL timestart("cdnval")

136
    l_real = sym%invs.AND.(.NOT.noco%l_soc).AND.(.NOT.noco%l_noco)
Gregor Michalicek's avatar
Gregor Michalicek committed
137

138 139 140 141 142 143 144 145 146 147 148
    IF (noco%l_mperp) THEN
       !--->    when the off-diag. part of the desinsity matrix, i.e. m_x and
       !--->    m_y, is calculated inside the muffin-tins (l_mperp = T), cdnval
       !--->    is called only once. therefore, several spin loops have been
       !--->    added. if l_mperp = F, these loops run only from jspin - jspin.
       jsp_start = 1
       jsp_end   = 2
    ELSE
       jsp_start = jspin
       jsp_end   = jspin
    ENDIF
149
    !---> if l_mperp = F, these variables are only needed for one spin
150 151 152
    !---> at a time, otherwise for both spins:
    ALLOCATE ( f(atoms%jmtd,2,0:atoms%lmaxd,jsp_start:jsp_end) )      ! Deallocation before mpi_col_den
    ALLOCATE ( g(atoms%jmtd,2,0:atoms%lmaxd,jsp_start:jsp_end) )
153
    ALLOCATE ( flo(atoms%jmtd,2,atoms%nlod,dimension%jspd) )
154
    ALLOCATE ( jsym(dimension%neigd),ksym(dimension%neigd) )
155

156
    ! --> Initializations
Gregor Michalicek's avatar
Gregor Michalicek committed
157

158
    CALL usdus%init(atoms,input%jspins)
159
    CALL denCoeffs%init(atoms,sphhar,jsp_start,jsp_end)
160 161 162
    !---> The last entry in denCoeffsOffdiag%init is l_fmpl. It is meant as a switch to a plot of the full magnet.
    !---> density without the atomic sphere approximation for the magnet. density. It is not completely implemented (lo's missing).
    CALL denCoeffsOffdiag%init(atoms,noco,sphhar,.FALSE.)
163
    CALL force%init1(input,atoms)
164
    CALL orb%init(atoms,noco,jsp_start,jsp_end)
165
    CALL mcd%init1(banddos,dimension,input,atoms)
166 167
    CALL slab%init(banddos,dimension,atoms,cell)
    CALL orbcomp%init(banddos,dimension,atoms)
168

169
    IF ((denCoeffsOffdiag%l_fmpl).AND.(.not.noco%l_mperp)) CALL juDFT_error("for fmpl set noco%l_mperp = T!" ,calledby ="cdnval")
170
    IF ((banddos%ndir.EQ.-3).AND.banddos%dos.AND.oneD%odi%d1) CALL juDFT_error("layer-resolved feature does not work with 1D",calledby ="cdnval")
171

172
! calculation of core spectra (EELS) initializations -start-
173
    CALL corespec_init(input,atoms,coreSpecInput)
Gregor Michalicek's avatar
Gregor Michalicek committed
174
    IF(l_cs.AND.(mpi%isize.NE.1)) CALL juDFT_error('EELS + MPI not implemented', calledby = 'cdnval')
175 176
    IF(l_cs.AND.jspin.EQ.1) CALL corespec_gaunt()
! calculation of core spectra (EELS) initializations -end-
177

178 179 180
    IF (mpi%irank==0) THEN
       WRITE (6,FMT=8000) jspin
       WRITE (16,FMT=8000) jspin
181
       CALL openXMLElementPoly('mtCharges',(/'spin'/),(/jspin/))
182
    END IF
183 184
8000 FORMAT (/,/,10x,'valence density: spin=',i2)

185 186
    l_write = input%cdinf.AND.mpi%irank==0

187
    DO iType = 1,atoms%ntype
188
       DO ispin = jsp_start, jsp_end
189
          CALL genMTBasis(atoms,enpara,vTot,mpi,iType,ispin,l_write,usdus,f(:,:,0:,ispin),g(:,:,0:,ispin),flo(:,:,:,ispin))
190
       END DO
191 192 193
       IF (noco%l_mperp) CALL denCoeffsOffdiag%addRadFunScalarProducts(atoms,f,g,flo,iType)
       IF (banddos%l_mcd) CALL mcd_init(atoms,input,dimension,vTot%mt(:,0,:,:),g,f,mcd,iType,jspin)
       IF(l_cs) CALL corespec_rme(atoms,input,iType,dimension%nstd,input%jspins,jspin,results%ef,&
194
                                  dimension%msh,vTot%mt(:,0,:,:),f,g)
195
    END DO
196
    DEALLOCATE (f,g,flo)
197

198 199 200
    skip_tt = dot_product(enpara%skiplo(:atoms%ntype,jspin),atoms%neq(:atoms%ntype))
    IF (noco%l_soc.OR.noco%l_noco)  skip_tt = 2 * skip_tt
    ALLOCATE (we(MAXVAL(cdnvalKLoop%noccbd(:))))
201
    ALLOCATE (eig(MAXVAL(cdnvalKLoop%noccbd(:))))
202
    jsp = MERGE(1,jspin,noco%l_noco)
203

204
    DO ikpt = cdnvalKLoop%ikptStart, cdnvalKLoop%nkptExtended, cdnvalKLoop%ikptIncrement
205

206 207
       IF (ikpt.GT.kpts%nkpt) THEN
#ifdef CPP_MPI
208
          CALL MPI_BARRIER(mpi%mpi_comm,ie) ! Synchronizes the RMA operations
209 210 211 212 213 214
#endif
          EXIT
       END IF

       CALL lapw%init(input,noco, kpts,atoms,sym,ikpt,cell,.false., mpi)
       skip_t = skip_tt
215 216 217 218 219
       noccbd = cdnvalKLoop%noccbd(ikpt)
       nStart = cdnvalKLoop%nStart(ikpt)
       nEnd = cdnvalKLoop%nEnd(ikpt)

       we=0.0
220 221
       IF(noccbd.GT.0) we(1:noccbd) = results%w_iks(nStart:nEnd,ikpt,jsp)
       IF ((sliceplot%slice).AND.(input%pallst)) we(:) = kpts%wtkpt(ikpt)
222

223 224 225 226
       IF (cdnvalKLoop%l_evp) THEN
          IF (nStart > skip_tt) skip_t = 0
          IF (nEnd <= skip_tt) skip_t = noccbd
          IF ((nStart <= skip_tt).AND.(nEnd > skip_tt)) skip_t = mod(skip_tt,noccbd)
227
       END IF
228

229
       nbasfcn = MERGE(lapw%nv(1)+lapw%nv(2)+2*atoms%nlotot,lapw%nv(1)+atoms%nlotot,noco%l_noco)
230
       CALL zMat%init(l_real,nbasfcn,noccbd)
231
       CALL read_eig(eig_id,ikpt,jsp,n_start=nStart,n_end=nEnd,neig=nbands,zmat=zMat)
232
#ifdef CPP_MPI
233
       CALL MPI_BARRIER(mpi%mpi_comm,ie) ! Synchronizes the RMA operations
234
#endif
235

236
       eig(1:noccbd) = results%eig(nStart:nEnd,ikpt,jsp)
237

238
       CALL gVacMap%init(dimension,sym,atoms,vacuum,stars,lapw,input,cell,kpts,enpara,vTot,ikpt,jspin)
239

240 241
       IF (noccbd.EQ.0) GO TO 199

242 243 244 245
       !     ----> add in spin-doubling factor
       we(:noccbd) = 2.0 * we(:noccbd) / input%jspins

       !--->    valence density in the interstitial and vacuum region
246 247
       !--->    has to be called only once (if jspin=1) in the non-collinear case

248 249 250 251 252
       !     ----> valence density in the interstitial region
       IF (.NOT.((jspin.EQ.2) .AND. noco%l_noco)) THEN
          CALL pwden(stars,kpts,banddos,oneD,input,mpi,noco,cell,atoms,sym,ikpt,&
                     jspin,lapw,noccbd,we,eig,den,regCharges%qis,results,force%f_b8,zMat)
       END IF
253

254 255 256
       !--->    charge of each valence state in this k-point of the SBZ
       !--->    in the layer interstitial region of the film
       IF (banddos%dos.AND.(banddos%ndir.EQ.-3)) THEN
257
          IF (.NOT.((jspin.EQ.2) .AND. noco%l_noco)) THEN
258
             CALL q_int_sl(jspin,stars,atoms,sym,cell,noccbd,lapw,slab,oneD,zMat)
259
          END IF
260
       END IF
261

262 263 264 265
       !--->    valence density in the vacuum region
       IF (input%film) THEN
          IF (.NOT.((jspin.EQ.2) .AND. noco%l_noco)) THEN
             CALL vacden(vacuum,dimension,stars,oneD, kpts,input, cell,atoms,noco,banddos,&
266
                         gVacMap,we,ikpt,jspin,vTot%vacz(:,:,jspin),noccbd,lapw,enpara%evac0,eig,&
267
                         den,regCharges%qvac,regCharges%qvlay,regCharges%qstars,zMat)
268
          END IF
269 270 271 272 273 274
          !--->       perform Brillouin zone integration and summation over the
          !--->       bands in order to determine the vacuum energy parameters.
          DO ispin = jsp_start,jsp_end
             DO ivac = 1,vacuum%nvac
                regCharges%pvac(ivac,ispin)=regCharges%pvac(ivac,ispin)+dot_product(eig(:noccbd)*regCharges%qvac(:noccbd,ivac,ikpt,ispin),we(:noccbd))
                regCharges%svac(ivac,ispin)=regCharges%svac(ivac,ispin)+dot_product(regCharges%qvac(:noccbd,ivac,ikpt,ispin),we(:noccbd))
275
             END DO
276 277
          END DO
       END IF
278

279 280
       !--->    valence density in the atomic spheres
       CALL eigVecCoeffs%init(dimension,atoms,noco,jspin,noccbd)
281

282
       DO ispin = jsp_start,jsp_end
283
          IF (input%l_f) CALL force%init2(noccbd,input,atoms)
284 285 286
          CALL abcof(input,atoms,sym,cell,lapw,noccbd,usdus,noco,ispin,oneD,&
                     eigVecCoeffs%acof(:,0:,:,ispin),eigVecCoeffs%bcof(:,0:,:,ispin),&
                     eigVecCoeffs%ccof(-atoms%llod:,:,:,:,ispin),zMat,eig,force)
287
          IF (atoms%n_u.GT.0) CALL n_mat(atoms,sym,noccbd,usdus,ispin,we,eigVecCoeffs,den%mmpMat(:,:,:,jspin))
288

289 290 291 292 293
          !--->       perform Brillouin zone integration and summation over the
          !--->       bands in order to determine the energy parameters for each
          !--->       atom and angular momentum
          IF (.not.sliceplot%slice) THEN
             CALL eparas(ispin,atoms,noccbd,mpi,ikpt,noccbd,we,eig,&
294
                         skip_t,cdnvalKLoop%l_evp,eigVecCoeffs,usdus,regCharges,mcd,banddos%l_mcd)
295

296 297
             IF (noco%l_mperp.AND.(ispin == jsp_end)) THEN
                CALL qal_21(dimension,atoms,input,noccbd,noco,eigVecCoeffs,denCoeffsOffdiag,regCharges)
298
             END IF
299
          END IF
300

301 302 303 304
          !--->    layer charge of each valence state in this k-point of the SBZ
          !--->    from the mt-sphere region of the film
          IF (banddos%dos.AND.(banddos%ndir.EQ.-3))  THEN
             CALL q_mt_sl(ispin,atoms,noccbd,ikpt,noccbd,skip_t,noccbd,eigVecCoeffs,usdus,slab)
305

306
             INQUIRE (file='orbcomprot',exist=l_orbcomprot)
307
             IF (l_orbcomprot) CALL abcrot2(atoms,noccbd,eigVecCoeffs,ispin) ! rotate ab-coeffs
308

309 310
             CALL orb_comp(ispin,noccbd,atoms,noccbd,usdus,eigVecCoeffs,orbcomp)
          END IF
311 312

          CALL calcDenCoeffs(atoms,sphhar,sym,we,noccbd,eigVecCoeffs,ispin,denCoeffs)
313 314 315 316 317 318 319 320 321 322

          IF (noco%l_soc) CALL orbmom(atoms,noccbd,we,ispin,eigVecCoeffs,orb)

          IF (input%l_f) THEN
             IF (.not.input%l_useapw) THEN
                CALL force_a12(atoms,noccbd,sym,dimension,cell,oneD,&
                               we,ispin,noccbd,usdus,eigVecCoeffs,force,results)
             ENDIF
             CALL force_a21(input,atoms,dimension,noccbd,sym,oneD,cell,we,ispin,&
                            enpara%el0(0:,:,ispin),noccbd,eig,usdus,eigVecCoeffs,force,results)
323 324
          END IF

325 326 327 328 329
          IF(l_cs) THEN
             CALL corespec_dos(atoms,usdus,ispin,dimension%lmd,kpts%nkpt,ikpt,dimension%neigd,&
                               noccbd,results%ef,banddos%sig_dos,eig,we,eigVecCoeffs)
          END IF
       END DO !--->    end loop over ispin
330

331
       IF (noco%l_mperp) CALL denCoeffsOffdiag%calcCoefficients(atoms,sphhar,sym,eigVecCoeffs,we,noccbd)
332

333 334 335 336 337 338
199    CONTINUE
       IF ((banddos%dos .OR. banddos%vacdos .OR. input%cdinf)  ) THEN
          CALL timestart("cdnval: write_info")
          !--->    calculate charge distribution of each state (l-character ...)
          !--->    and write the information to the files dosinp and vacdos
          !--->    for dos and bandstructure plots
339

340
          !--dw    since z is no longer an argument of cdninf sympsi has to be called here!
341
          IF (banddos%ndir.GT.0) CALL sympsi(lapw,jspin,sym,dimension,nbands,cell,eig,noco,ksym,jsym,zMat)
342

343
          CALL write_dos(eig_id,ikpt,jspin,regCharges,slab,orbcomp,ksym,jsym,mcd%mcd)
344 345

          CALL timestop("cdnval: write_info")
346
       END IF
347
    END DO !---> end of k-point loop
348

349
#ifdef CPP_MPI
350
    DO ispin = jsp_start,jsp_end
351
       CALL mpi_col_den(mpi,sphhar,atoms,oneD,stars,vacuum,input,noco,ispin,regCharges,&
352
                        results,denCoeffs,orb,denCoeffsOffdiag,den,den%mmpMat(:,:,:,jspin))
353
    END DO
354
#endif
355

356
    IF (mpi%irank==0) THEN
357
       CALL cdnmt(dimension%jspd,atoms,sphhar,noco,jsp_start,jsp_end,&
358
                  enpara,vTot%mt(:,0,:,:),denCoeffs,usdus,orb,denCoeffsOffdiag,moments,den%mt)
359 360

       IF(l_cs) CALL corespec_ddscs(jspin,input%jspins)
361

362 363 364 365 366 367
       DO ispin = jsp_start,jsp_end

          !--->      check continuity of charge density
          IF (input%cdinf) THEN
             WRITE (6,FMT=8210) ispin
8210         FORMAT (/,5x,'check continuity of cdn for spin=',i2)
368
             CALL checkDOPAll(input,dimension,sphhar,stars,atoms,sym,vacuum,oneD,cell,den,ispin)
369
          END IF
370

371
          !--->      forces of equ. A8 of Yu et al.
372
          IF ((input%l_f)) CALL force_a8(input,atoms,sphhar,ispin,vTot%mt(:,:,:,ispin),den%mt,force,results)
373

374
       END DO ! end of loop ispin = jsp_start,jsp_end
375
       CALL closeXMLElement('mtCharges')
376 377 378 379 380 381 382 383 384 385

       IF(vacuum%nvac.EQ.1) THEN
          den%vacz(:,2,:) = den%vacz(:,1,:)
          IF (sym%invs) THEN
             den%vacxy(:,:,2,:) = CONJG(den%vacxy(:,:,1,:))
          ELSE
             den%vacxy(:,:,2,:) = den%vacxy(:,:,1,:)
          END IF
       END IF

386
    END IF ! end of (mpi%irank==0)
387
#ifdef CPP_MPI
388
    CALL MPI_BARRIER(mpi%mpi_comm,ie) ! Synchronizes the RMA operations
389
#endif
390

391 392
    CALL timestop("cdnval")

393 394
  END SUBROUTINE cdnval
END MODULE m_cdnval