stden.f90 19.5 KB
Newer Older
1 2 3 4 5 6 7 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
      MODULE m_stden
      USE m_juDFT
!     ************************************************************
!     generate flapw starting density by superposition of
!     atomic densities. the non-spherical terms inside
!     the spheres are obtained by a least squares fit
!     and the interstitial and vacuum warping terms are calculated
!     by a fast fourier transform.
!     e. wimmer   nov. 1984       c.l.fu diagonized 1987
!     *************************************************************
      CONTAINS
        SUBROUTINE stden(mpi,&
             &                 sphhar,stars,atoms,sym,&
             &                 DIMENSION,vacuum,&
             &                 input,&
             &                 cell,&
             &                 xcpot,&
             &                 obsolete,&
             &                 oneD)
          USE m_sphpts
          USE m_constants
          USE m_enpara,    ONLY : w_enpara
          USE m_xcall,     ONLY : vxcall
          USE m_qsf
          USE m_checkdop
          USE m_cdnovlp
          USE m_wrtdop
          USE m_qfix
          USE m_atom2
          USE m_types
          USE m_cylpts
          USE m_points
33
          USE m_juDFT_init
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
          IMPLICIT NONE
          !     ..
          TYPE(t_mpi),INTENT(IN)      :: mpi
          TYPE(t_atoms),INTENT(IN)    :: atoms
          TYPE(t_dimension),INTENT(IN):: DIMENSION
          TYPE(t_sphhar),INTENT(IN)   :: sphhar
          TYPE(t_obsolete),INTENT(IN) :: obsolete
          TYPE(t_sym),INTENT(IN)      :: sym
          TYPE(t_stars),INTENT(IN)    :: stars
          TYPE(t_oneD),INTENT(IN)     :: oneD
          TYPE(t_input),INTENT(IN)    :: input
          TYPE(t_vacuum),INTENT(IN)   :: vacuum
          TYPE(t_cell),INTENT(IN)     :: cell
          TYPE(t_xcpot),INTENT(IN)    :: xcpot
          

          TYPE(t_enpara)   :: enpara
          CHARACTER*8 :: name(10)
          !-odim
          !+odim
          !     ..
          !     .. Local Scalars ..
          REAL d,del,fix,h,r,rnot,sign,z,bm,qdel
          REAL denz1(1),vacxpot(1),vacpot(1) 
          INTEGER i,iter,ivac,iza,j,jr,k,n,n1,npd,ispin 
          INTEGER nw,ilo,natot,icorr_dummy,nat 
          COMPLEX czero
          !     ..
          !     .. Local Arrays ..
          COMPLEX, ALLOCATABLE :: qpw(:,:),rhtxy(:,:,:,:)
          REAL,    ALLOCATABLE :: rho(:,:,:,:),rht(:,:,:),vbar(:,:)
          REAL,    ALLOCATABLE :: xp(:,:),rat(:,:),eig(:,:,:),sigm(:)
          REAL,    ALLOCATABLE :: rh(:,:,:),rh1(:,:,:),rhoss(:,:)
          REAL,    ALLOCATABLE :: vacpar(:)
          INTEGER lnum(DIMENSION%nstd,atoms%ntypd),nst(atoms%ntypd) 
69 70
          INTEGER jrc(atoms%ntypd)
          LOGICAL l_found(0:3),llo_found(atoms%nlod),l_enpara,l_st
71 72 73 74 75 76 77
          CHARACTER*8 name_l(10)
          !     ..
          !     .. Intrinsic Functions ..
          INTRINSIC abs,exp
          !     ..
          !     .. Data statements ..
          DATA del/1.e-6/
78
          PARAMETER (czero=(0.0,0.0),l_st=.true.)
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
          !     ..
          !
          IF (input%jspins > DIMENSION%jspd)  CALL juDFT_error("input%jspins > dimension%jspd",calledby&
               &     ="stden")
          ALLOCATE ( rho(atoms%jmtd,0:sphhar%nlhd,atoms%ntypd,DIMENSION%jspd) )

          ALLOCATE ( qpw(stars%n3d,DIMENSION%jspd),rhtxy(vacuum%nmzxyd,oneD%odi%n2d-1,2,DIMENSION%jspd) )
          ALLOCATE ( xp(3,DIMENSION%nspd),rat(DIMENSION%msh,atoms%ntypd),eig(DIMENSION%nstd,DIMENSION%jspd,atoms%ntypd) )
          ALLOCATE ( rh(DIMENSION%msh,atoms%ntypd,DIMENSION%jspd),rh1(DIMENSION%msh,atoms%ntypd,DIMENSION%jspd) )
          ALLOCATE ( enpara%ello0(atoms%nlod,atoms%ntypd,input%jspins),vacpar(2) )
          ALLOCATE ( enpara%el0(0:3,atoms%ntypd,input%jspins))   
          ALLOCATE ( enpara%lchange(0:3,atoms%ntypd,input%jspins))
          ALLOCATE ( enpara%skiplo(atoms%ntypd,input%jspins))
          ALLOCATE ( enpara%llochg(atoms%nlod,atoms%ntypd,input%jspins))
          ALLOCATE ( enpara%enmix(input%jspins))
94
          ALLOCATE ( enpara%evac0(2,dimension%jspd))
95
          ALLOCATE ( enpara%lchg_v(2,dimension%jspd))
96 97 98
          ALLOCATE ( rht(vacuum%nmzd,2,DIMENSION%jspd),vbar(2,atoms%ntypd),sigm(vacuum%nmzd) )
          ALLOCATE ( rhoss(DIMENSION%msh,DIMENSION%jspd) )
          enpara%enmix=1.0
99
          rho = 0.0
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
          IF (mpi%irank == 0) THEN

             !--->    if sigma is not 0.0, then divide this charge among all atoms
             IF ( ABS(input%efield%sigma).LT. 1.e-6) THEN
                qdel = 0.0
             ELSE
                natot = 0
                DO n=1,atoms%ntype
                   IF (atoms%zatom(n).GE.1.0) natot = natot + atoms%neq(n)
                ENDDO
                qdel = 2.*input%efield%sigma/natot
             ENDIF
             !
             WRITE (6,FMT=8000)
8000         FORMAT (/,/,/,' superposition of atomic densities',/,/,&
                  &       ' original atomic densities:',/)
             DO n = 1,atoms%ntype
                r = atoms%rmsh(1,n)
                d = EXP(atoms%dx(n))
                !         DO i = 1, msh
                !            rat(i,n) = r
                !            r = r*d
                !         ENDDO
                jrc(n) = 0
                DO WHILE (r < atoms%rmt(n) + 20.0) 
                   IF ( jrc(n) > DIMENSION%msh )   CALL juDFT_error&
                        &           ("increase msh in fl7para!",calledby ="stden")
                   jrc(n) = jrc(n) + 1
                   rat(jrc(n),n) = r
                   r = r*d
                ENDDO
             ENDDO
             !
             ! Generate the atomic charge densities
             !
             DO n = 1,atoms%ntype
                z = atoms%zatom(n)
                r = atoms%rmt(n)
                h = atoms%dx(n)
                jr = atoms%jri(n)
                IF (input%jspins.EQ.2) THEN
                   bm = atoms%bmu(n)
                ELSE
                   bm = 0.
                ENDIF
                !--->    check whether this atom has been done already
                DO n1 = 1,n - 1
                   IF (ABS(z-atoms%zatom(n1)).GT.del) GO TO 40
                   IF (ABS(r-atoms%rmt(n1)).GT.del) GO TO 40
                   IF (ABS(h-atoms%dx(n1)).GT.del) GO TO 40
                   IF (ABS(bm-atoms%bmu(n1)).GT.del) GO TO 40
                   IF (jr.NE.atoms%jri(n1)) GO TO 40
                   DO ispin = 1, input%jspins
                      DO i = 1,jrc(n) ! dimension%msh
                         rh(i,n,ispin) = rh(i,n1,ispin)
                      ENDDO
                   ENDDO
                   nst(n) = nst(n1)
                   vbar(1,n) = vbar(1,n1)
                   vbar(input%jspins,n) = vbar(input%jspins,n1)
                   DO i = 1, nst(n1)
                      lnum(i,n)  = lnum(i,n1)
                      eig(i,1,n) = eig(i,1,n1)
                      eig(i,input%jspins,n) = eig(i,input%jspins,n1)
                   ENDDO
                   GO TO 70
40                 CONTINUE
                ENDDO
                !--->    new atom
                rnot = atoms%rmsh(1,n)
                IF (z.LT.1.0) THEN
                   DO ispin = 1, input%jspins
                      DO i = 1,jrc(n) ! dimension%msh
                         rh(i,n,ispin) = 1.e-10
                      ENDDO
                   ENDDO
                ELSE
                   CALL atom2(&
                        &                 DIMENSION,atoms,xcpot,input,n,jrc(n),rnot,qdel,&
                        &                 rhoss,nst(n),lnum(1,n),eig(1,1,n),vbar(1,n))
                   DO ispin = 1, input%jspins
                      DO i = 1, jrc(n) ! dimension%msh
                         rh(i,n,ispin) = rhoss(i,ispin)
                      ENDDO
                   ENDDO
                END IF
                !--->    list atomic density
                iza = atoms%zatom(n) + 0.0001
                WRITE (6,FMT=8030) namat_const(iza)
8030            FORMAT (/,/,' atom: ',a2,/)
8040            FORMAT (4 (3x,i5,f8.5,f12.6))
70              CONTINUE
             ENDDO

             !roa+
             !..use cdnovlp to generate total density out of atom densities...
             !
             DO ispin = 1, input%jspins
                nat = 1
                DO  n = 1,atoms%ntype
                   DO  i = 1, jrc(n)
                      rh1(i,n,ispin) = rh(i,n,ispin)*fpi_const*rat(i,n)**2
                   ENDDO
                   rh1(jrc(n):DIMENSION%msh,n,ispin) = 0.0
                   !..prepare spherical mt charge
                   DO i = 1,atoms%jri(n)
                      rho(i,0,n,ispin) = rh(i,n,ispin)*sfp_const*atoms%rmsh(i,n)**2
                   ENDDO
                   !..reset nonspherical mt charge
                   DO k = 1,sphhar%nlh(atoms%ntypsy(nat))
                      DO j = 1,atoms%jri(n)
                         rho(j,k,n,ispin) = 0.e0
                      ENDDO
                   ENDDO
                   nat = nat + atoms%neq(n)
                ENDDO
             ENDDO ! ispin

             qpw(:,:) = czero ; rht(:,:,:) = 0.e0 ; rhtxy(:,:,:,:) = czero

          ENDIF ! mpi%irank == 0
          DO ispin = 1, input%jspins
             CALL cdnovlp(mpi,&
                  &               sphhar,stars,atoms,sym,&
                  &               DIMENSION,vacuum,&
                  &               cell,&
226
                  &               input,oneD,l_st,&
227 228 229 230 231 232 233 234 235 236 237 238
                  &               ispin,rh1(:,:,ispin),&
                  &               qpw,rhtxy,rho,rht)
             !roa-
             !-spinloop
          ENDDO
          IF ( mpi%irank == 0 ) THEN
             !
             ! Check the normalization of total density
             !
             CALL qfix(&
                  &          stars,atoms,sym,vacuum,&
                  &          sphhar,input,cell,oneD,&
239
                  &          qpw,rhtxy,rho,rht,.FALSE.,&
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
                  &          fix)
             !
             ! Write superposed density onto density file
             !
             iter = 1
             name_l(:) = name(:)
             name_l(10) = 'ordered*'    ! always create ordered start density
             OPEN (71,file='cdn1',form='unformatted',status='new')
             CALL wrtdop(&
                  &            stars,vacuum,atoms,sphhar,&
                  &            input,sym,&
                  &            71,&
                  &            iter,rho,qpw,rht,rhtxy)
             CLOSE (71)
             !
             ! Check continuity
             !
             IF (atoms%ntype<100)THEN
                DO ispin = 1,input%jspins
                   WRITE (6,'(a8,i2)') 'spin No.',ispin
                   IF (input%film .AND. .NOT.oneD%odi%d1) THEN
                      !         ---> vacuum boundaries
                      npd = MIN(DIMENSION%nspd,25)
                      CALL points(xp,npd)
                      DO ivac = 1,vacuum%nvac
                         sign = 3. - 2.*ivac
                         DO j = 1,npd
                            xp(3,j) = sign*cell%z1/cell%amat(3,3)
                         ENDDO
                         CALL checkdop(&
                              &                    xp,npd,0,0,ivac,1,ispin,.TRUE.,DIMENSION,atoms,&
                              &                    sphhar,stars,sym,&
                              &                    vacuum,cell,oneD,&
                              &                    qpw,rho,rhtxy,rht)
                      ENDDO
                   ELSEIF (oneD%odi%d1) THEN
                      !-odim
                      npd = MIN(DIMENSION%nspd,25)
                      CALL cylpts(xp,npd,cell%z1)
                      CALL checkdop(&
                           &          xp,npd,0,0,vacuum%nvac,1,ispin,.TRUE.,DIMENSION,atoms,&
                           &          sphhar,stars,sym,&
                           &          vacuum,cell,oneD,&
                           &          qpw,rho,rhtxy,rht)
                      !+odim
                   END IF
                   !         ---> m.t. boundaries
                   nat = 1
                   DO n = 1,atoms%ntype
                      CALL sphpts(xp,DIMENSION%nspd,atoms%rmt(n),atoms%pos(1,nat))
                      CALL checkdop(&
                           &                   xp,DIMENSION%nspd,n,nat,0,-1,ispin,.TRUE.,&
                           &                   dimension,atoms,sphhar,stars,sym,&
                           &                   vacuum,cell,oneD,&
                           &                   qpw,rho,rhtxy,rht)
                      nat = nat + atoms%neq(n)
                   ENDDO
                ENDDO
             ENDIF
             l_enpara = .FALSE.
             INQUIRE (file='enpara',exist=l_enpara)
301
             l_enpara = l_enpara.OR.input%l_inpXML
302 303 304
             !
             ! set up parameters for enpara-file
             !
305
             IF ((juDFT_was_argument("-genEnpara")).AND..NOT.l_enpara) THEN
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436
                OPEN (40,file='enpara',form='formatted',status='unknown')
                enpara%lchange = .TRUE.
                enpara%llochg = .TRUE.
                
                DO ispin = 1, input%jspins
                   !
                   ! vacpar is taken as highest occupied level from atomic eigenvalues
                   ! vacpar (+0.3)  serves as fermi level for film or bulk
                   !
                   vacpar(1) = -999.9
                   DO n = 1,atoms%ntype
                      vacpar(1) = MAX( vacpar(1),eig(nst(n),ispin,n) )
                   ENDDO
                   IF (.NOT.input%film) vacpar(1) = vacpar(1) + 0.4
                   vacpar(2) = vacpar(1)


                   DO n = 1,atoms%ntype
                      enpara%skiplo(n,ispin) = 0
                      DO i = 0, 3
                         l_found(i) = .FALSE.
                         enpara%el0(i,n,ispin) = vacpar(1)
                      ENDDO
                      DO i = 1, atoms%nlo(n)
                         llo_found(i) = .FALSE.
                         enpara%ello0(i,n,ispin) = vacpar(1) - 1.5
                      ENDDO
                      !
                      ! take energy-parameters from atomic calculation
                      !
                      DO i = nst(n), 1,-1 
                         IF (.NOT.input%film) eig(i,ispin,n) = eig(i,ispin,n) + 0.4

                         IF (.NOT.l_found(lnum(i,n)).AND.(lnum(i,n).LE.3)) THEN
                            enpara%el0(lnum(i,n),n,ispin) = eig(i,ispin,n)
                            IF (enpara%el0(lnum(i,n),n,ispin).LT.input%ellow) THEN
                               enpara%el0(lnum(i,n),n,ispin) = vacpar(1)
                               l_found(lnum(i,n))  = .TRUE.
                            ENDIF
                            IF (enpara%el0(lnum(i,n),n,ispin).LT.input%elup) THEN
                               l_found(lnum(i,n))  = .TRUE.
                            ENDIF
                         ELSE
                            IF (l_found(lnum(i,n)).AND.(atoms%nlo(n).GT.0)) THEN
                               DO ilo = 1,atoms%nlo(n) 
                                  IF (atoms%llo(ilo,n).EQ.lnum(i,n)) THEN
                                     IF ( .NOT.llo_found(ilo) ) THEN
                                        enpara%ello0(ilo,n,ispin) = eig(i,ispin,n)
                                        IF (( enpara%ello0(ilo,n,ispin).GT.input%elup).OR.&
                                             &                      ( enpara%ello0(ilo,n,ispin).LT.input%ellow)) THEN
                                           enpara%ello0(ilo,n,ispin)= vacpar(1)
                                        ELSEIF (atoms%l_dulo(ilo,n)) THEN
                                           enpara%ello0(ilo,n,ispin)= enpara%el0(atoms%llo(ilo,n),n,ispin)
                                        ELSE
                                           enpara%skiplo(n,ispin) = enpara%skiplo(n,ispin) + 2*atoms%llo(ilo,n)+1
                                        ENDIF
                                        llo_found(ilo) = .TRUE.
                                        IF ((enpara%el0(atoms%llo(ilo,n),n,ispin)-enpara%ello0(ilo,n,ispin).LT.0.5)&
                                                                 .AND.(atoms%llo(ilo,n).GE.0)) THEN
                                           enpara%el0(atoms%llo(ilo,n),n,ispin) = vacpar(1)
                                           IF (atoms%l_dulo(ilo,n)) &
                                                &                              enpara%ello0(ilo,n,ispin)= enpara%el0(atoms%llo(ilo,n),n,ispin)
                                        ENDIF
                                     ENDIF
                                  ENDIF
                               ENDDO
                            ENDIF
                         ENDIF

                      ENDDO
                      IF (obsolete%lepr.EQ.1) THEN
                         DO i = 0, 3
                            enpara%el0(i,n,ispin) = enpara%el0(i,n,ispin) - vbar(ispin,n)
                         ENDDO
                         DO ilo = 1,atoms%nlo(n)
                            enpara%ello0(ilo,n,ispin) = enpara%ello0(ilo,n,ispin) - vbar(ispin,n)
                         ENDDO
                      ENDIF
                   ENDDO  ! atom types

                   IF (input%film) THEN
                      ! get guess for vacuum parameters
                      ! YM : in 1D case should be modified, but also not that bad like this
                      !
                      !           generate coulomb potential by integrating inward to z1
                      !
                      DO ivac = 1, vacuum%nvac
                         icorr_dummy = MIN(MAX(xcpot%icorr,0),5)  ! use LDA for this purpose
                         DO i=1,vacuum%nmz
                            sigm(i) = (i-1)*vacuum%delz*rht(i,ivac,ispin)
                         ENDDO
                         CALL qsf(vacuum%delz,sigm,vacpar(ivac),vacuum%nmz,0)
                         denz1(1) = rht(1,ivac,ispin)          ! get estimate for potential at
                         CALL  vxcall(6,icorr_dummy,input%krla,1,&    !               vacuum boundary&
                         &                     1,1,denz1,&
                              &                     vacxpot,vacpot)
                         ! seems to be the best choice for 1D not to substract vacpar
                         IF (.NOT.oneD%odi%d1) THEN
                            vacpot(1) = vacpot(1) - fpi_const*vacpar(ivac)
                         END IF
                         IF (obsolete%lepr.EQ.1) THEN
                            vacpar(ivac) = -0.2 - vacpot(1)
                            WRITE (6,'(" vacuum",i2," reference energy =",f12.6)')&
                                 &                 ivac,vacpot
                         ELSE
                            vacpar(ivac) = vacpot(1)
                         ENDIF
                      ENDDO
                      IF (vacuum%nvac.EQ.1) vacpar(2) = vacpar(1)

                   ENDIF
                   IF (obsolete%lepr.EQ.1) THEN
                      enpara%enmix = 0.3
                   ELSE
                      enpara%enmix = 1.0
                   ENDIF
                   !
                   ! write enpara-file
                   !
                   enpara%evac0(:,ispin)=vacpar(:SIZE(enpara%evac0,1))
                   CALL w_enpara(&
                        &                  atoms,ispin,input%film,enpara,&
                        &                  16)

                ENDDO  ! ispin


                CLOSE (40)
             ENDIF
             DEALLOCATE ( qpw,rhtxy,rht,xp,rat,eig,rh,rh1 )
             DEALLOCATE ( rhoss,vacpar,vbar,sigm )
437 438
             DEALLOCATE ( enpara%ello0,enpara%el0,enpara%lchange)
             DEALLOCATE ( enpara%skiplo,enpara%llochg,enpara%enmix,enpara%evac0)
439 440 441 442 443
          ENDIF ! mpi%irank == 0
          DEALLOCATE ( rho )
          !
        END SUBROUTINE stden
      END MODULE m_stden