cdnval.F90 16.9 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 :: iErr,ivac,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
157
    CALL usdus%init(atoms,input%jspins)
158
    CALL denCoeffs%init(atoms,sphhar,jsp_start,jsp_end)
159 160 161
    !---> 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.)
162
    CALL force%init1(input,atoms)
163
    CALL orb%init(atoms,noco,jsp_start,jsp_end)
164
    CALL mcd%init1(banddos,dimension,input,atoms)
165 166
    CALL slab%init(banddos,dimension,atoms,cell)
    CALL orbcomp%init(banddos,dimension,atoms)
167

168
    IF ((denCoeffsOffdiag%l_fmpl).AND.(.not.noco%l_mperp)) CALL juDFT_error("for fmpl set noco%l_mperp = T!" ,calledby ="cdnval")
169
    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")
170

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

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

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

186
    DO iType = 1,atoms%ntype
187
       DO ispin = jsp_start, jsp_end
188
          CALL genMTBasis(atoms,enpara,vTot,mpi,iType,ispin,l_write,usdus,f(:,:,0:,ispin),g(:,:,0:,ispin),flo(:,:,:,ispin))
189
       END DO
190 191 192
       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,&
193
                                  dimension%msh,vTot%mt(:,0,:,:),f,g)
194
    END DO
195
    DEALLOCATE (f,g,flo)
196

197 198 199
    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(:))))
200
    ALLOCATE (eig(MAXVAL(cdnvalKLoop%noccbd(:))))
201
    jsp = MERGE(1,jspin,noco%l_noco)
202

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

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

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

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

222 223 224 225
       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)
226
       END IF
227

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

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

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

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

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

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

247 248 249 250 251
       !     ----> 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
252

253 254 255
       !--->    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
256
          IF (.NOT.((jspin.EQ.2) .AND. noco%l_noco)) THEN
257
             CALL q_int_sl(jspin,stars,atoms,sym,cell,noccbd,lapw,slab,oneD,zMat)
258
          END IF
259
       END IF
260

261 262 263 264
       !--->    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,&
265
                         gVacMap,we,ikpt,jspin,vTot%vacz(:,:,jspin),noccbd,lapw,enpara%evac0,eig,&
266
                         den,regCharges%qvac,regCharges%qvlay,regCharges%qstars,zMat)
267
          END IF
268 269 270 271 272 273
          !--->       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))
274
             END DO
275 276
          END DO
       END IF
277

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

281
       DO ispin = jsp_start,jsp_end
282
          IF (input%l_f) CALL force%init2(noccbd,input,atoms)
283 284 285
          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)
286
          IF (atoms%n_u.GT.0) CALL n_mat(atoms,sym,noccbd,usdus,ispin,we,eigVecCoeffs,den%mmpMat(:,:,:,jspin))
287

288 289 290 291 292
          !--->       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,&
293
                         skip_t,cdnvalKLoop%l_evp,eigVecCoeffs,usdus,regCharges,mcd,banddos%l_mcd)
294

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

300 301 302 303
          !--->    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)
304

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

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

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

          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)
322 323
          END IF

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

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

330
199    CONTINUE
331
       IF ((banddos%dos.OR.banddos%vacdos.OR.input%cdinf)) THEN
332
          !--dw    since z is no longer an argument of cdninf sympsi has to be called here!
333
          IF (banddos%ndir.GT.0) CALL sympsi(lapw,jspin,sym,dimension,nbands,cell,eig,noco,ksym,jsym,zMat)
334

335
          CALL write_dos(eig_id,ikpt,jspin,regCharges,slab,orbcomp,ksym,jsym,mcd%mcd)
336
       END IF
337
    END DO !---> end of k-point loop
338

339
#ifdef CPP_MPI
340
    DO ispin = jsp_start,jsp_end
341
       CALL mpi_col_den(mpi,sphhar,atoms,oneD,stars,vacuum,input,noco,ispin,regCharges,&
342
                        results,denCoeffs,orb,denCoeffsOffdiag,den,den%mmpMat(:,:,:,jspin))
343
    END DO
344
#endif
345

346
    IF (mpi%irank==0) THEN
347
       CALL cdnmt(dimension%jspd,atoms,sphhar,noco,jsp_start,jsp_end,&
348
                  enpara,vTot%mt(:,0,:,:),denCoeffs,usdus,orb,denCoeffsOffdiag,moments,den%mt)
349 350

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

352 353 354 355 356 357
       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)
358
             CALL checkDOPAll(input,dimension,sphhar,stars,atoms,sym,vacuum,oneD,cell,den,ispin)
359
          END IF
360

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

364
       END DO ! end of loop ispin = jsp_start,jsp_end
365
       CALL closeXMLElement('mtCharges')
366 367 368 369 370 371 372 373 374 375

       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

376
    END IF ! end of (mpi%irank==0)
377
#ifdef CPP_MPI
378
    CALL MPI_BARRIER(mpi%mpi_comm,iErr) ! Synchronizes the RMA operations
379
#endif
380

381 382
    CALL timestop("cdnval")

383 384
  END SUBROUTINE cdnval
END MODULE m_cdnval