cdnval.F90 15.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
    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
59
    USE m_checkdopall
60
    USE m_cdnmt       ! calculate the density and orbital moments etc.
61 62 63
    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
64
    USE m_orbcomp     ! calculate orbital composition (like p_x,p_y,p_z)
65
    USE m_abcrot2
66 67 68
    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
69
#ifdef CPP_MPI
70
    USE m_mpi_col_den ! collect density data from parallel nodes
71 72
#endif
    USE m_types
73
    USE m_xmlOutput
74
    IMPLICIT NONE
75 76 77 78
    TYPE(t_results),       INTENT(INOUT) :: results
    TYPE(t_mpi),           INTENT(IN)    :: mpi
    TYPE(t_dimension),     INTENT(IN)    :: dimension
    TYPE(t_oneD),          INTENT(IN)    :: oneD
79
    TYPE(t_enpara),        INTENT(IN)    :: enpara
80 81 82 83 84 85 86 87 88 89 90 91 92 93
    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
94
    TYPE(t_cdnvalKLoop),   INTENT(IN)    :: cdnvalKLoop
95 96 97
    TYPE(t_potden),        INTENT(INOUT) :: den
    TYPE(t_regionCharges), INTENT(INOUT) :: regCharges
    TYPE(t_moments),       INTENT(INOUT) :: moments
98 99
    TYPE(t_mcd),           INTENT(INOUT) :: mcd
    TYPE(t_slab),          INTENT(INOUT) :: slab
100

101
    ! Scalar Arguments
102
    INTEGER, INTENT(IN)              :: eig_id,jspin
103 104 105 106

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

108
    ! Local Scalars
109
    INTEGER :: ikpt,jsp_start,jsp_end,ispin,jsp
110
    INTEGER :: iErr,ivac,nbands,noccbd,iType
111 112
    INTEGER :: skip_t,skip_tt
    INTEGER :: nStart,nEnd,nbasfcn
113
    LOGICAL :: l_orbcomprot,l_real, l_write
114

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

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

132 133
    CALL timestart("cdnval")

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

136
    IF (noco%l_mperp) THEN
137 138 139 140
       ! 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.
141 142 143 144 145 146
       jsp_start = 1
       jsp_end   = 2
    ELSE
       jsp_start = jspin
       jsp_end   = jspin
    ENDIF
147 148 149 150 151 152 153 154
    ! if l_mperp = F, these variables are only needed for one spin
    ! 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))
    ALLOCATE (flo(atoms%jmtd,2,atoms%nlod,dimension%jspd))
    ALLOCATE (jsym(dimension%neigd),ksym(dimension%neigd))

    ! Initializations
155
    CALL usdus%init(atoms,input%jspins)
156
    CALL denCoeffs%init(atoms,sphhar,jsp_start,jsp_end)
157 158
    ! 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).
159
    CALL denCoeffsOffdiag%init(atoms,noco,sphhar,.FALSE.)
160
    CALL force%init1(input,atoms)
161
    CALL orb%init(atoms,noco,jsp_start,jsp_end)
162
    CALL mcd%init1(banddos,dimension,input,atoms)
163 164
    CALL slab%init(banddos,dimension,atoms,cell)
    CALL orbcomp%init(banddos,dimension,atoms)
165

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

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

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

182 183
    l_write = input%cdinf.AND.mpi%irank==0

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

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

201
    DO ikpt = cdnvalKLoop%ikptStart, cdnvalKLoop%nkptExtended, cdnvalKLoop%ikptIncrement
202

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

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

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

220 221 222 223
       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)
224
       END IF
225

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

233
       eig(1:noccbd) = results%eig(nStart:nEnd,ikpt,jsp)
234

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

237 238
       IF (noccbd.EQ.0) GO TO 199

239
       we(:noccbd) = 2.0 * we(:noccbd) / input%jspins ! add in spin-doubling factor
240

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

244 245
       ! valence density in the interstitial region
       IF (.NOT.((jspin.EQ.2).AND.noco%l_noco)) THEN
246 247
          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)
248 249 250
          ! 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
251
             CALL q_int_sl(jspin,stars,atoms,sym,cell,noccbd,lapw,slab,oneD,zMat)
252
          END IF
253
       END IF
254

255
       ! valence density in the vacuum region
256
       IF (input%film) THEN
257
          IF (.NOT.((jspin.EQ.2).AND.noco%l_noco)) THEN
258
             CALL vacden(vacuum,dimension,stars,oneD, kpts,input,sym,cell,atoms,noco,banddos,&
259
                         gVacMap,we,ikpt,jspin,vTot%vacz(:,:,jspin),noccbd,lapw,enpara%evac0,eig,&
260
                         den,regCharges%qvac,regCharges%qvlay,regCharges%qstars,zMat)
261
          END IF
262 263 264
          ! perform Brillouin zone integration and summation over the
          ! bands in order to determine the vacuum energy parameters.
          DO ispin = jsp_start, jsp_end
265 266 267
             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))
268
             END DO
269 270
          END DO
       END IF
271

272
       ! valence density in the atomic spheres
273 274
       CALL eigVecCoeffs%init(dimension,atoms,noco,jspin,noccbd)
       DO ispin = jsp_start,jsp_end
275
          IF (input%l_f) CALL force%init2(noccbd,input,atoms)
276 277 278
          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)
279
          IF (atoms%n_u.GT.0) CALL n_mat(atoms,sym,noccbd,usdus,ispin,we,eigVecCoeffs,den%mmpMat(:,:,:,jspin))
280

281 282 283 284 285
          ! perform Brillouin zone integration and summation over the
          ! bands in order to determine the energy parameters for each
          ! atom and angular momentum
          CALL eparas(ispin,atoms,noccbd,mpi,ikpt,noccbd,we,eig,&
                      skip_t,cdnvalKLoop%l_evp,eigVecCoeffs,usdus,regCharges,mcd,banddos%l_mcd)
286

287 288
          IF (noco%l_mperp.AND.(ispin == jsp_end)) THEN
             CALL qal_21(dimension,atoms,input,noccbd,noco,eigVecCoeffs,denCoeffsOffdiag,regCharges)
289
          END IF
290

291 292 293
          ! 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
294
             CALL q_mt_sl(ispin,atoms,noccbd,ikpt,noccbd,skip_t,noccbd,eigVecCoeffs,usdus,slab)
295

296
             INQUIRE (file='orbcomprot',exist=l_orbcomprot)
297
             IF (l_orbcomprot) CALL abcrot2(atoms,noccbd,eigVecCoeffs,ispin) ! rotate ab-coeffs
298

299 300
             CALL orb_comp(ispin,noccbd,atoms,noccbd,usdus,eigVecCoeffs,orbcomp)
          END IF
301 302

          CALL calcDenCoeffs(atoms,sphhar,sym,we,noccbd,eigVecCoeffs,ispin,denCoeffs)
303 304 305

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

306 307
          IF (input%l_f) CALL force%addContribsA21A12(input,atoms,dimension,sym,cell,oneD,enpara,&
                                                      usdus,eigVecCoeffs,noccbd,ispin,eig,we,results)
308

309 310
          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)
311
       END DO ! end loop over ispin
312
       IF (noco%l_mperp) CALL denCoeffsOffdiag%calcCoefficients(atoms,sphhar,sym,eigVecCoeffs,we,noccbd)
313

314
199    CONTINUE
315
       IF ((banddos%dos.OR.banddos%vacdos.OR.input%cdinf)) THEN
316
          ! since z is no longer an argument of cdninf sympsi has to be called here!
317
          IF (banddos%ndir.GT.0) CALL sympsi(lapw,jspin,sym,dimension,nbands,cell,eig,noco,ksym,jsym,zMat)
318

319
          CALL write_dos(eig_id,ikpt,jspin,regCharges,slab,orbcomp,ksym,jsym,mcd%mcd)
320
       END IF
321
    END DO ! end of k-point loop
322

323
#ifdef CPP_MPI
324
    DO ispin = jsp_start,jsp_end
325
       CALL mpi_col_den(mpi,sphhar,atoms,oneD,stars,vacuum,input,noco,ispin,regCharges,&
326
                        results,denCoeffs,orb,denCoeffsOffdiag,den,den%mmpMat(:,:,:,jspin))
327
    END DO
328
#endif
329

330
    IF (mpi%irank==0) THEN
331
       CALL cdnmt(dimension%jspd,atoms,sphhar,noco,jsp_start,jsp_end,&
332
                  enpara,vTot%mt(:,0,:,:),denCoeffs,usdus,orb,denCoeffsOffdiag,moments,den%mt)
333
       IF (l_cs) CALL corespec_ddscs(jspin,input%jspins)
334 335 336 337
       DO ispin = jsp_start,jsp_end
          IF (input%cdinf) THEN
             WRITE (6,FMT=8210) ispin
8210         FORMAT (/,5x,'check continuity of cdn for spin=',i2)
338
             CALL checkDOPAll(input,dimension,sphhar,stars,atoms,sym,vacuum,oneD,cell,den,ispin)
339
          END IF
340
          IF (input%l_f) CALL force_a8(input,atoms,sphhar,ispin,vTot%mt(:,:,:,ispin),den%mt,force,results)
341
       END DO
342
       CALL closeXMLElement('mtCharges')
343
    END IF
344

345
#ifdef CPP_MPI
346
    CALL MPI_BARRIER(mpi%mpi_comm,iErr) ! Synchronizes the RMA operations
347
#endif
348

349 350
    CALL timestop("cdnval")

351 352
  END SUBROUTINE cdnval
END MODULE m_cdnval