read_core.F90 18.5 KB
Newer Older
1 2 3 4 5 6 7 8
      MODULE m_read_core

      ! read core radial wavefunctions from corebas
      ! corebas is written in cored.F
      ! (core basis functions can be read in once during an iteration) 

      CONTAINS

Daniel Wortmann's avatar
Daniel Wortmann committed
9
      SUBROUTINE read_core( atoms, hybdat )
10 11 12 13 14


    USE m_types
      IMPLICIT NONE

Daniel Wortmann's avatar
Daniel Wortmann committed
15 16
      TYPE(t_hybdat),INTENT(INOUT)   :: hybdat
      TYPE(t_atoms),INTENT(IN)       :: atoms
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


      ! - local scalars -
      INTEGER                            ::  ncst
      INTEGER                            ::  ok,itype,i,idum,l

      REAL                               ::  rdum
      REAL                               ::  weight1,weight2
      ! - local arrays -
      INTEGER,ALLOCATABLE                ::  nindxcr(:,:)
      INTEGER,ALLOCATABLE                ::  l_qn(:,:),n_qn(:,:)

      REAL,ALLOCATABLE                   ::  j_qn(:,:)
      REAL,ALLOCATABLE                   ::  core1r(:,:,:,:),&
     &                                       core2r(:,:,:,:)


      OPEN(UNIT=77,FILE='corebas',FORM='unformatted')
      READ(77) ncst


      ALLOCATE( n_qn(0:ncst,atoms%ntype) , l_qn(0:ncst,atoms%ntype) , &
     &          j_qn(0:ncst,atoms%ntype) , stat=ok )
      IF( ok .ne. 0 ) STOP 'mhsfock: failure allocation n_qn,l_qn,j_qn'
      ALLOCATE( nindxcr(0:ncst,atoms%ntype),stat = ok )
      IF( ok .ne. 0 ) STOP 'mhsfock: failure allocation nindxcr'

      nindxcr = 0
Daniel Wortmann's avatar
Daniel Wortmann committed
45
      hybdat%lmaxc   = 0
46 47 48 49 50 51 52 53 54
      l_qn    = 0
      ncst    = 0
      DO itype=1,atoms%ntype
        READ(77) ncst
        IF( ncst .eq. 0 ) CYCLE
        DO i=1,ncst
          READ(77) n_qn(i,itype),l_qn(i,itype),j_qn(i,itype)
          nindxcr(l_qn(i,itype),itype) = nindxcr(l_qn(i,itype),itype)+1
        END DO
Daniel Wortmann's avatar
Daniel Wortmann committed
55
        hybdat%lmaxc(itype) = maxval(l_qn(:,itype))
56 57 58 59
      END DO



Daniel Wortmann's avatar
Daniel Wortmann committed
60 61
      ALLOCATE( core1r(atoms%jmtd,0:maxval(hybdat%lmaxc),maxval(nindxcr),atoms%ntype) )
      ALLOCATE( core2r(atoms%jmtd,0:maxval(hybdat%lmaxc),maxval(nindxcr),atoms%ntype) )
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
      core1r = 0
      core2r = 0
      REWIND(77)

      DEALLOCATE( nindxcr )
      ALLOCATE( nindxcr(0:maxval(l_qn),atoms%ntype))
      nindxcr = 0
      READ(77) idum
      DO itype=1,atoms%ntype
        READ(77) ncst
        DO i=1,ncst
          nindxcr(l_qn(i,itype),itype) = nindxcr(l_qn(i,itype),itype)+1
          READ(77) idum,idum,rdum,core1r(:atoms%jri(itype),l_qn(i,itype),&
     &                            nindxcr(l_qn(i,itype),itype),itype),&
     &                            core2r(:atoms%jri(itype),l_qn(i,itype),&
     &                            nindxcr(l_qn(i,itype),itype),itype)
        END DO
      END DO



Daniel Wortmann's avatar
Daniel Wortmann committed
83
      ALLOCATE( hybdat%nindxc(0:maxval(hybdat%lmaxc),atoms%ntype),stat=ok )
84
      IF( ok .ne. 0 ) STOP 'mhsfock: failure allocation nindxc'
Daniel Wortmann's avatar
Daniel Wortmann committed
85
      ALLOCATE( hybdat%core1(atoms%jmtd,0:maxval(hybdat%lmaxc),maxval(nindxcr(0,:),&
86 87
     &                nint((maxval(nindxcr)/2.0))),atoms%ntype),stat=ok )
      IF( ok .ne. 0 ) STOP 'mhsfock: failure allocation core1'
Daniel Wortmann's avatar
Daniel Wortmann committed
88
      ALLOCATE( hybdat%core2(atoms%jmtd,0:maxval(hybdat%lmaxc),maxval(nindxcr(0,:),&
89 90
     &                nint((maxval(nindxcr)/2.0))),atoms%ntype),stat=ok )
      IF( ok .ne. 0 ) STOP 'mhsfock: failure allocation core2'
Daniel Wortmann's avatar
Daniel Wortmann committed
91
      hybdat%nindxc = 0 ; hybdat%core1 = 0 ; hybdat%core2 = 0
92 93 94 95

      ! average over core states that only differ in j
      ! core functions with l-qn equal 0 doesnot change during averaging

Daniel Wortmann's avatar
Daniel Wortmann committed
96
      hybdat%nindxc(0,:) = nindxcr(0,:)
97
      DO itype=1,atoms%ntype
Daniel Wortmann's avatar
Daniel Wortmann committed
98 99 100 101
        hybdat%core1(:,0,:hybdat%nindxc(0,itype),itype)&
     &    = core1r(:,0,:hybdat%nindxc(0,itype),itype)
        hybdat%core2(:,0,:hybdat%nindxc(0,itype),itype)&
     &    = core2r(:,0,:hybdat%nindxc(0,itype),itype)
102 103 104 105
      END DO


      DO itype=1,atoms%ntype
Daniel Wortmann's avatar
Daniel Wortmann committed
106
        DO l=1,hybdat%lmaxc(itype)
107 108 109 110
          weight1 = 2*(l-0.5) + 1
          weight2 = 2*(l+0.5) + 1
          IF( modulo(nindxcr(l,itype),2) .eq. 0 ) THEN
            DO i=1,nindxcr(l,itype),2
Daniel Wortmann's avatar
Daniel Wortmann committed
111 112
              hybdat%nindxc(l,itype) = hybdat%nindxc(l,itype) + 1
              hybdat%core1(:atoms%jri(itype),l,hybdat%nindxc(l,itype),itype) =&
113 114 115
     &                        (weight1*core1r(:atoms%jri(itype),l,i  ,itype) +&
     &                         weight2*core1r(:atoms%jri(itype),l,i+1,itype))&
     &                        / (weight1+weight2)
Daniel Wortmann's avatar
Daniel Wortmann committed
116
              hybdat%core2(:atoms%jri(itype),l,hybdat%nindxc(l,itype),itype) =&
117 118 119 120 121 122
     &                        (weight1*core2r(:atoms%jri(itype),l,i  ,itype) +&
     &                         weight2*core2r(:atoms%jri(itype),l,i+1,itype))&
     &                        / (weight1+weight2)
            END DO
          ELSE
            DO i=1,nindxcr(l,itype)-1,2
Daniel Wortmann's avatar
Daniel Wortmann committed
123 124
              hybdat%nindxc(l,itype) = hybdat%nindxc(l,itype) + 1
              hybdat%core1(:atoms%jri(itype),l,hybdat%nindxc(l,itype),itype) =&
125 126 127
     &                        (weight1*core1r(:atoms%jri(itype),l,i  ,itype) +&
     &                         weight2*core1r(:atoms%jri(itype),l,i+1,itype))&
     &                        / (weight1+weight2)
Daniel Wortmann's avatar
Daniel Wortmann committed
128
              hybdat%core2(:atoms%jri(itype),l,hybdat%nindxc(l,itype),itype) =&
129 130 131 132
     &                        (weight1*core2r(:atoms%jri(itype),l,i  ,itype) +&
     &                         weight2*core2r(:atoms%jri(itype),l,i+1,itype))&
     &                        / (weight1+weight2)
            END DO
Daniel Wortmann's avatar
Daniel Wortmann committed
133 134
              hybdat%nindxc(l,itype) = hybdat%nindxc(l,itype) + 1
              hybdat%core1(:atoms%jri(itype),l,hybdat%nindxc(l,itype),itype)&
135
     &          = core1r(:atoms%jri(itype),l,nindxcr(l,itype),itype)
Daniel Wortmann's avatar
Daniel Wortmann committed
136
              hybdat%core2(:atoms%jri(itype),l,hybdat%nindxc(l,itype),itype)&
137 138 139 140 141 142 143 144
     &          = core2r(:atoms%jri(itype),l,nindxcr(l,itype),itype)
          END IF

        END DO
      END DO

      DEALLOCATE( nindxcr, core1r,core2r )

Daniel Wortmann's avatar
Daniel Wortmann committed
145
      hybdat%maxindxc = maxval(hybdat%nindxc)
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 226 227 228 229 230 231 232 233 234 235 236 237 238 239 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 301 302 303 304 305 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 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
      CLOSE(77)

      END SUBROUTINE read_core







      SUBROUTINE corewf( atoms,jsp,input,dimension,&
     &                   vr, lmaxcd,maxindxc,mpi, lmaxc,nindxc,core1,core2,eig_c)
      USE m_types
      IMPLICIT NONE

      TYPE(t_mpi),INTENT(IN)   :: mpi
      TYPE(t_dimension),INTENT(IN)   :: dimension
      TYPE(t_input),INTENT(IN)   :: input
      TYPE(t_atoms),INTENT(IN)   :: atoms

      ! - scalars -
      INTEGER,INTENT(IN)        ::  jsp  
      INTEGER,INTENT(IN)        :: lmaxcd
      INTEGER,INTENT(INOUT)     ::  maxindxc

      ! -arrays -
      INTEGER,INTENT(INOUT)     ::  lmaxc(:)
      INTEGER,INTENT(INOUT)     ::  nindxc(0:lmaxcd,atoms%ntype)

      REAL   , INTENT(IN)       ::  vr(:,:,:)!(atoms%jmtd,atoms%ntypd,dimension%jspd)
      REAL   , INTENT(INOUT)    ::  core1(:,:,0:,:) !(atoms%jmtd,maxindxc,0:lmaxcd,atoms%ntype)
     REAL   , INTENT(INOUT)     ::  core2(:,:,0:,:) !(jmtd,maxindxc,0:lmaxcd,ntype)

      REAL   , INTENT(INOUT)    ::  eig_c(maxindxc,0:lmaxcd,atoms%ntype)

      ! - local scalars -
      INTEGER                   ::  ncstd
      INTEGER                   ::  ok,itype,i,j,idum,l

      REAL                      ::  rdum
      REAL                      ::  weight1,weight2
      ! - local arrays -
      INTEGER,ALLOCATABLE       ::  nindxcr(:,:)
      INTEGER,ALLOCATABLE       ::  l_qn(:,:),n_qn(:,:)

      REAL,ALLOCATABLE          ::  j_qn(:,:)
      REAL,ALLOCATABLE          ::  core1r(:,:,:,:),core2r(:,:,:,:)
      REAL,ALLOCATABLE          ::  core11r(:,:,:,:),core22r(:,:,:,:)
      REAL,ALLOCATABLE          ::  eig_cr(:,:,:)

      ncstd = maxval(atoms%ncst)
      ALLOCATE( nindxcr(0:ncstd,atoms%ntype),stat = ok )

      ! generate relativistic core wave functions( ->core1r,core2r )
      CALL calcorewf( dimension,input,jsp,atoms,&
     &                ncstd,vr,&
     &                lmaxc,nindxcr,core1r,core2r,eig_cr,mpi)


      nindxc = 0

      ! average over core states that only differ in j
      ! core functions with l-qn equal 0 doesnot change during the average process
 
      nindxc(0,:) = nindxcr(0,:)
      DO itype=1,atoms%ntype
        core1(:,:nindxc(0,itype),0,itype)&
     &    = core1r(:,0,:nindxc(0,itype),itype)
        core2(:,:nindxc(0,itype),0,itype)&
     &    = core2r(:,0,:nindxc(0,itype),itype)
        eig_c(:nindxc(0,itype),0,itype)&
     &    = eig_cr(0,:nindxc(0,itype),itype)
      END DO


      DO itype=1,atoms%ntype
        DO l=1,lmaxc(itype)
          weight1 = 2*(l-0.5) + 1
          weight2 = 2*(l+0.5) + 1
          IF( modulo(nindxcr(l,itype),2) .eq. 0 ) THEN
            DO i=1,nindxcr(l,itype),2
              nindxc(l,itype) = nindxc(l,itype) + 1
              core1(:atoms%jri(itype),nindxc(l,itype),l,itype) =&
     &                       (weight1*core1r(:atoms%jri(itype),l,i  ,itype) +&
     &                        weight2*core1r(:atoms%jri(itype),l,i+1,itype))&
     &                       / (weight1+weight2)
              core2(:atoms%jri(itype),nindxc(l,itype),l,itype) =&
     &                       (weight1*core2r(:atoms%jri(itype),l,i  ,itype) + &
     &                        weight2*core2r(:atoms%jri(itype),l,i+1,itype))&
     &                       / (weight1+weight2)

              eig_c(nindxc(l,itype),l,itype) =&
     &                       (weight1*eig_cr(l,i,itype) +&
     &                        weight2*eig_cr(l,i+1,itype))&
     &                       / (weight1+weight2)
            END DO
          ELSE
            DO i=1,nindxcr(l,itype)-1,2
              nindxc(l,itype) = nindxc(l,itype) + 1
              core1(:atoms%jri(itype),nindxc(l,itype),l,itype) =&
     &                       (weight1*core1r(:atoms%jri(itype),l,i  ,itype) +&
     &                        weight2*core1r(:atoms%jri(itype),l,i+1,itype))&
     &                       / (weight1+weight2)
              core2(:atoms%jri(itype),nindxc(l,itype),l,itype) =&
     &                       (weight1*core2r(:atoms%jri(itype),l,i  ,itype) + &
     &                        weight2*core2r(:atoms%jri(itype),l,i+1,itype))&
     &                       / (weight1+weight2)

              eig_c(nindxc(l,itype),l,itype) =&
     &                       (weight1*eig_cr(l,i,itype) +&
     &                        weight2*eig_cr(l,i+1,itype))&
     &                       / (weight1+weight2)
            END DO
            nindxc(l,itype) = nindxc(l,itype) + 1
            core1(:atoms%jri(itype),nindxc(l,itype),l,itype)&
     &        = core1r(:atoms%jri(itype),l,nindxcr(l,itype),itype)
            core2(:atoms%jri(itype),nindxc(l,itype),l,itype)&
     &        = core2r(:atoms%jri(itype),l,nindxcr(l,itype),itype)
            eig_c(nindxc(l,itype),l,itype)&
     &        = eig_cr(l,nindxcr(l,itype),itype)
          END IF

        END DO
      END DO

      DEALLOCATE( nindxcr,core1r,core2r,eig_cr )

      IF( maxindxc .ne. maxval(nindxc) )&
     &   STOP 'corewf: counting error nindxc'


      END SUBROUTINE corewf


      SUBROUTINE calcorewf(dimension,input,jspin,atoms,&
     &                     ncstd,vr,&
     &                     lmaxc,nindxcr,core1,core2,eig_c,mpi)


      USE m_intgr, ONLY : intgr3,intgr0,intgr1
      USE m_constants, ONLY : c_light
      USE m_setcor
      USE m_differ
      USE m_types
      IMPLICIT NONE

      TYPE(t_mpi),INTENT(IN)   :: mpi
      TYPE(t_dimension),INTENT(IN)   :: dimension
      TYPE(t_input),INTENT(IN)   :: input
      TYPE(t_atoms),INTENT(IN)   :: atoms

      !  - scalars -
      INTEGER, INTENT (IN) :: ncstd
      INTEGER, INTENT (IN) :: jspin   
      INTEGER, INTENT (OUT):: lmaxc(:)

      !  - arrays - 
      INTEGER, INTENT (OUT):: nindxcr(0:ncstd,atoms%ntype)
      REAL   , INTENT (IN) :: vr(:,:,:)!(atoms%jmtd,atoms%ntypd,dimension%jspd)
      REAL   , ALLOCATABLE :: core1(:,:,:,:),core2(:,:,:,:)
      REAL   , ALLOCATABLE :: eig_c(:,:,:)

      !  - local scalars -
      INTEGER              :: i,j,itype,korb,ncmsh,nst,ierr
      REAL                 :: e,fj,fl,fn,t2,c,bmu,weight
      REAL                 :: d,dxx,rn,rnot,z,t1,rr 
      LOGICAL, SAVE        :: first = .true.

      !  - local arrays -
      INTEGER              :: kappa(dimension%nstd),nprnc(dimension%nstd)
      REAL                 :: vrd(dimension%msh)
      REAL                 :: occ(dimension%nstd),occ_h(dimension%nstd,2),a(dimension%msh),b(dimension%msh)
      REAL,ALLOCATABLE,SAVE:: vr0(:,:,:)

      !   - intrinsic functions -
      INTRINSIC exp,iabs,isign

      c = c_light(1.0)

      IF( first ) THEN
         ALLOCATE( vr0(atoms%jmtd,atoms%ntype,dimension%jspd) )
      END IF

      IF ( input%frcor ) THEN
        IF ( first ) THEN
          vr0   = vr
          first = .false.
        END IF
      ELSE
        vr0   = vr
        first = .false.
      END IF


      ! this loop determines the dimensions

      lmaxc = 0; nindxcr = 0
      DO itype = 1,atoms%ntype
        z    = atoms%zatom(itype)
        dxx  = atoms%dx(itype)
        bmu  = 0.0
        CALL setcor( itype,input%jspins,atoms,input,bmu,&
     &               nst,kappa,nprnc,occ_h)

        IF ((bmu > 99.)) THEN
          occ(1:nst) = input%jspins *  occ_h(1:nst,jspin)
        ELSE
          occ(1:nst) = occ_h(1:nst,1) 
        END IF
        rnot  = atoms%rmsh(1,itype)
        d     = exp(atoms%dx(itype))
        ncmsh = nint( log( (atoms%rmt(itype)+10.0)/rnot ) / dxx + 1 )
        ncmsh = min( ncmsh, dimension%msh )
        rn = rnot* (d** (ncmsh-1))

        nst = atoms%ncst(itype)

        DO 80 korb = 1,nst
          IF (occ(korb).EQ.0) GOTO 80
            fn = nprnc(korb)
            fj = iabs(kappa(korb)) - .5e0
            weight = 2*fj + 1.e0
            IF (bmu > 99.) weight = occ(korb)
            fl = fj + (.5e0)*isign(1,kappa(korb))
            e = -2* (z/ (fn+fl))**2

            nindxcr(NINT(fl),itype) = nindxcr(NINT(fl),itype) + 1
            lmaxc(itype)            = max(lmaxc(itype),NINT(fl))
   80   END DO

      END DO



      ALLOCATE( core1(atoms%jmtd,0:maxval(lmaxc),maxval(nindxcr),atoms%ntype) )
      ALLOCATE( core2(atoms%jmtd,0:maxval(lmaxc),maxval(nindxcr),atoms%ntype) )
      ALLOCATE( eig_c(0:maxval(lmaxc),maxval(nindxcr),atoms%ntype) )

      core1   = 0; core2 =0
      nindxcr = 0
      DO itype = 1,atoms%ntype
        z    = atoms%zatom(itype)
        dxx  = atoms%dx(itype)
        bmu  = 0.0
        CALL setcor(itype,input%jspins,atoms,input,bmu,nst,kappa,nprnc,occ_h)

        IF ((bmu > 99.)) THEN
          occ(1:nst) = input%jspins *  occ_h(1:nst,jspin)
        ELSE
          occ(1:nst) = occ_h(1:nst,1) 
        END IF
        rnot  = atoms%rmsh(1,itype)
        d     = exp(atoms%dx(itype))
        ncmsh = nint( log( (atoms%rmt(itype)+10.0)/rnot ) / dxx + 1 )
        ncmsh = min( ncmsh, dimension%msh )
        rn = rnot* (d** (ncmsh-1))
        IF ( mpi%irank == 0 ) THEN
          WRITE(6 ,FMT=8000) z,rnot,dxx,atoms%jri(itype)
          WRITE(16,FMT=8000) z,rnot,dxx,atoms%jri(itype)
        END IF
        DO j = 1,atoms%jri(itype)
          vrd(j) = vr0(j,itype,jspin)
        END DO

        if (input%l_core_confpot) THEN

           ! linear extension of the potential with slope t1 / a.u.
           t1=0.125
           t2=vrd(atoms%jri(itype))/atoms%rmt(itype)-atoms%rmt(itype)*t1
           rr = atoms%rmt(itype)
        else
           t2 = vrd(atoms%jri(itype)) / ( atoms%jri(itype) - ncmsh )
        endif
        IF ( atoms%jri(itype) .LT. ncmsh) THEN
          DO i = atoms%jri(itype) + 1,ncmsh
             if (input%l_core_confpot) THEN
                rr = d*rr
                vrd(i) = rr*( t2 + rr*t1 )
             else
            vrd(i) = vrd(atoms%jri(itype)) + t2* (i-atoms%jri(itype))
         endif
!
          END DO
        END IF

        nst = atoms%ncst(itype)


        DO 90 korb = 1,nst
          IF (occ(korb).EQ.0) GOTO 90
            fn = nprnc(korb)
            fj = iabs(kappa(korb)) - .5e0
            weight = 2*fj + 1.e0
            IF (bmu > 99.) weight = occ(korb)
            fl = fj + (.5e0)*isign(1,kappa(korb))
            e = -2* (z/ (fn+fl))**2
            CALL differ(fn,fl,fj,c,z,dxx,rnot,rn,d,ncmsh,vrd, e, a,b,ierr)

            nindxcr(NINT(fl),itype) = nindxcr(NINT(fl),itype) + 1


            core1(:atoms%jri(itype),NINT(fl),nindxcr(NINT(fl),itype),itype)&
     &                                                 =  a(:atoms%jri(itype))
            core2(:atoms%jri(itype),NINT(fl),nindxcr(NINT(fl),itype),itype)&
     &                                                 =  b(:atoms%jri(itype))

            eig_c(NINT(fl),nindxcr(NINT(fl),itype),itype) = e

            IF ( mpi%irank == 0 ) THEN
              WRITE (6,FMT=8010) fn,fl,fj,e,weight
              WRITE (16,FMT=8010) fn,fl,fj,e,weight
            END IF
            IF (ierr.NE.0) STOP 'error in core-level routine'


   90   END DO

      END DO


 8000 FORMAT (/,/,10x,'z=',f4.0,5x,'r(1)=',e14.6,5x,'dx=',f8.6,5x,&
     &       'm.t.index=',i4,/,15x,'n',4x,'l',5x,'j',4x,'energy',7x,&
     &       'weight')
 8010 FORMAT (12x,2f5.0,f6.1,f10.4,f10.0)

      END SUBROUTINE calcorewf

Daniel Wortmann's avatar
Daniel Wortmann committed
473
      SUBROUTINE core_init( dimension,input,atoms, lmaxcd,maxindxc)
474 475 476 477 478 479 480 481 482


      USE m_intgr, ONLY : intgr3,intgr0,intgr1
      USE m_constants, ONLY : c_light
      USE m_setcor
      USE m_differ
      USE m_types
      IMPLICIT NONE

Daniel Wortmann's avatar
Daniel Wortmann committed
483 484 485 486
      TYPE(t_dimension),INTENT(IN)   :: dimension
      TYPE(t_input),INTENT(IN)       :: input
      TYPE(t_atoms),INTENT(IN)       :: atoms
      INTEGER,INTENT(OUT)            :: maxindxc,lmaxcd
487

Daniel Wortmann's avatar
Daniel Wortmann committed
488
      
489 490 491 492 493 494 495
      !  - local scalars -
      INTEGER              :: i,j,itype,korb,ncmsh,nst,ierr
      REAL                 :: e,fj,fl,fn,t,bmu,c
      REAL                 :: d,dxx,rn,rnot,z,t1,rr 

      !  - local arrays -
      INTEGER              :: kappa(dimension%nstd),nprnc(dimension%nstd)
Daniel Wortmann's avatar
Daniel Wortmann committed
496
      INTEGER              :: nindxcr(0:dimension%nstd,atoms%ntype) 
497
      REAL                 :: occ(dimension%nstd),occ_h(dimension%nstd,2),a(dimension%msh),b(dimension%msh)
Daniel Wortmann's avatar
Daniel Wortmann committed
498
      INTEGER              :: lmaxc(atoms%ntype)
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513


      !   - intrinsic functions -
      INTRINSIC exp,iabs,isign

      c = c_light(1.0)


      ! this loop determines the dimensions

      lmaxc = 0; nindxcr = 0
      DO itype = 1,atoms%ntype
        z    = atoms%zatom(itype)
        dxx  = atoms%dx(itype)
        bmu  = 0.0
Daniel Wortmann's avatar
Daniel Wortmann committed
514
        CALL setcor(itype,input%jspins,atoms,input,bmu, nst,kappa,nprnc,occ_h)
515 516 517 518 519 520 521 522 523 524 525

        occ(1:nst) = occ_h(1:nst,1) 

        rnot  = atoms%rmsh(1,itype)
        d     = exp(atoms%dx(itype))
        ncmsh = nint( log( (atoms%rmt(itype)+10.0)/rnot ) / dxx + 1 )
        ncmsh = min( ncmsh, dimension%msh )
        rn = rnot* (d** (ncmsh-1))

        nst = atoms%ncst(itype)

Daniel Wortmann's avatar
Daniel Wortmann committed
526 527
        DO  korb = 1,nst
          IF (occ(korb).EQ.0) CYCLE
528 529 530 531 532 533 534 535
            fn = nprnc(korb)
            fj = iabs(kappa(korb)) - .5e0

            fl = fj + (.5e0)*isign(1,kappa(korb))
            e = -2* (z/ (fn+fl))**2

            nindxcr(NINT(fl),itype) = nindxcr(NINT(fl),itype) + 1
            lmaxc(itype)            = max(lmaxc(itype),NINT(fl))
Daniel Wortmann's avatar
Daniel Wortmann committed
536
         END DO
537 538 539 540 541 542 543 544 545 546 547

      END DO

      lmaxcd   = maxval(lmaxc)
      maxindxc = maxval(nindxcr(0,:),nint((maxval(nindxcr)/2.0)))



      END SUBROUTINE core_init

      END MODULE m_read_core