HF_init.F90 3.52 KB
Newer Older
Daniel Wortmann's avatar
Daniel Wortmann committed
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 33 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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91

MODULE m_hf_init
  !
  !     preparations for HF and hybrid functional calculation
  !
CONTAINS
  SUBROUTINE hf_init(hybrid,kpts,atoms,input,DIMENSION,hybdat,irank2,isize2,l_real)
    USE m_types
    USE m_read_core
    USE m_util
    USE m_io_hybrid
    IMPLICIT NONE
    TYPE(t_hybrid),INTENT(INOUT)     :: hybrid
    TYPE(t_kpts),INTENT(IN)          :: kpts
    TYPE(t_atoms),INTENT(IN)         :: atoms
    TYPE(t_input),INTENT(IN)         :: input
    TYPE(t_dimension),INTENT(IN)     :: DIMENSION
    INTEGER,INTENT(OUT)              :: irank2(:),isize2(:)
    TYPE(t_hybdat),INTENT(OUT)       :: hybdat
    LOGICAL,INTENT(IN)               :: l_real
    
    
    
    INTEGER:: itype,ieq,l,m,i,nk,l1,l2,m1,m2,ok
    
    

    
    !initialize hybdat%gridf for radial integration
    CALL intgrf_init(atoms%ntype,atoms%jmtd,atoms%jri,atoms%dx,atoms%rmsh,hybdat%gridf)
    
    !Alloc variables
    ALLOCATE(hybdat%lmaxc(atoms%ntype))
    ALLOCATE(hybdat%bas1(atoms%jmtd,hybrid%maxindx,0:atoms%lmaxd,atoms%ntype))
    ALLOCATE(hybdat%bas2(atoms%jmtd,hybrid%maxindx,0:atoms%lmaxd,atoms%ntype))
    ALLOCATE(hybdat%bas1_MT(hybrid%maxindx,0:atoms%lmaxd,atoms%ntype))
    ALLOCATE(hybdat%drbas1_MT(hybrid%maxindx,0:atoms%lmaxd,atoms%ntype))
    
    !sym%tau = oneD%ods%tau

    ! preparations for core states
    CALL core_init(dimension,input,atoms, hybdat%lmaxcd,hybdat%maxindxc)
    ALLOCATE( hybdat%nindxc(0:hybdat%lmaxcd,atoms%ntype), stat = ok )
    IF( ok .ne. 0 ) STOP 'eigen_hf: failure allocation hybdat%nindxc'
    ALLOCATE( hybdat%core1(atoms%jmtd,hybdat%maxindxc,0:hybdat%lmaxcd,atoms%ntype), stat=ok )
    IF( ok .ne. 0 ) STOP 'eigen_hf: failure allocation core1'
    ALLOCATE( hybdat%core2(atoms%jmtd,hybdat%maxindxc,0:hybdat%lmaxcd,atoms%ntype), stat=ok )
    IF( ok .ne. 0 ) STOP 'eigen_hf: failure allocation core2'
    ALLOCATE( hybdat%eig_c(hybdat%maxindxc,0:hybdat%lmaxcd,atoms%ntype), stat=ok      )
    IF( ok .ne. 0 ) STOP 'eigen_hf: failure allocation hybdat%eig_c'
    hybdat%nindxc = 0 ; hybdat%core1 = 0 ; hybdat%core2 = 0 ; hybdat%eig_c = 0

    ! pre-calculate gaunt coefficients

    hybdat%maxfac   = max(2*atoms%lmaxd+hybrid%maxlcutm1+1,2*hybdat%lmaxcd+2*atoms%lmaxd+1)
    ALLOCATE ( hybdat%fac( 0:hybdat%maxfac),hybdat%sfac( 0:hybdat%maxfac),stat=ok)
    IF( ok .ne. 0 ) STOP 'eigen_hf: failure allocation fac,hybdat%sfac'
    hybdat%fac(0)   = 1
    hybdat%sfac(0)  = 1
    DO i=1,hybdat%maxfac
       hybdat%fac(i)    = hybdat%fac(i-1)*i            ! hybdat%fac(i)    = i!
       hybdat%sfac(i)   = hybdat%sfac(i-1)*sqrt(i*1d0) ! hybdat%sfac(i)   = sqrt(i!)
    END DO


    ALLOCATE ( hybdat%gauntarr( 2, 0:atoms%lmaxd, 0:atoms%lmaxd, 0:hybrid%maxlcutm1, -atoms%lmaxd:atoms%lmaxd ,-hybrid%maxlcutm1:hybrid%maxlcutm1 ),stat=ok)
    IF( ok .ne. 0 ) STOP 'eigen: failure allocation hybdat%gauntarr'
    hybdat%gauntarr = 0
    DO l2 = 0,atoms%lmaxd
       DO l1 = 0,atoms%lmaxd
          DO l = abs(l1-l2),min(l1+l2,hybrid%maxlcutm1)
             DO m = -l,l
                DO m1 = -l1,l1
                   m2 = m1 + m ! Gaunt condition -m1+m2-m = 0
                   IF(abs(m2).le.l2) hybdat%gauntarr(1,l1,l2,l,m1,m) = gaunt(l1,l2,l,m1,m2,m,hybdat%maxfac,hybdat%fac,hybdat%sfac)
                   m2 = m1 - m ! switch role of l2-index
                   IF(abs(m2).le.l2) hybdat%gauntarr(2,l1,l2,l,m1,m) = gaunt(l2,l1,l,m2,m1,m,hybdat%maxfac,hybdat%fac,hybdat%sfac)
                END DO
             END DO
          END DO
       END DO
    END DO



    irank2   = 0
    isize2   = 1
    !skip_kpt = .false.

  END SUBROUTINE hf_init
END MODULE m_hf_init