hsmt.F90 4.79 KB
Newer Older
1 2 3 4
MODULE m_hsmt
  USE m_juDFT
  IMPLICIT NONE
CONTAINS
Daniel Wortmann's avatar
Daniel Wortmann committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
  !> Setup of MT-part of the Hamiltonian and the overlap matrix
  !!
  !! Here the MT-components are added to the matrices.
  !! 1. The spherical part in hsmt_sph()
  !! 2. The non-spherical part in hsmt_nonsph()
  !! 3. The lo-part in hsmt_lo()
  !!
  !! - In the case of a noco-calculation (but not spin-spiral), first a temporary matrix is set-up
  !! for each atom in its local spin-frame and this matrix is the rotated into the global frame and added to the full matrix
  !! - In the spin-spiral case, a loop over the global spin is performed and the four parts of the matrix are calculated one-by-one
  !! @todo
  !! The off-diagonal contribution in first-variation soc and constraint calculations is still missing
  
  SUBROUTINE hsmt(atoms,sym,enpara,&
       ispin,input,mpi,noco,cell,lapw,usdus,td,smat,hmat)
20 21
    USE m_hsmt_nonsph
    USE m_hsmt_sph
Daniel Wortmann's avatar
Daniel Wortmann committed
22 23
    use m_hsmt_lo
    USE m_hsmt_distspins
24
    USE m_types
25
    USE m_hsmt_fjgj
Daniel Wortmann's avatar
Daniel Wortmann committed
26 27 28
    USE m_hsmt_spinor
    USE m_hsmt_soc_offdiag
    USE m_hsmt_offdiag
29
    IMPLICIT NONE
30 31 32 33 34 35 36
    TYPE(t_mpi),INTENT(IN)        :: mpi
    TYPE(t_input),INTENT(IN)      :: input
    TYPE(t_noco),INTENT(IN)       :: noco
    TYPE(t_sym),INTENT(IN)        :: sym
    TYPE(t_cell),INTENT(IN)       :: cell
    TYPE(t_atoms),INTENT(IN)      :: atoms
    TYPE(t_enpara),INTENT(IN)     :: enpara
Daniel Wortmann's avatar
Daniel Wortmann committed
37 38 39 40
    TYPE(t_lapw),INTENT(IN)       :: lapw 
    TYPE(t_tlmplm),INTENT(IN)     :: td
    TYPE(t_usdus),INTENT(IN)      :: usdus
    CLASS(t_mat),INTENT(INOUT)    :: smat(:,:),hmat(:,:)
41 42
    !     ..
    !     .. Scalar Arguments ..
Daniel Wortmann's avatar
Daniel Wortmann committed
43 44 45 46
    INTEGER, INTENT (IN) :: ispin  
    
    !locals
    REAL, ALLOCATABLE    :: fj(:,:,:),gj(:,:,:)
47

Daniel Wortmann's avatar
Daniel Wortmann committed
48 49
    INTEGER :: iintsp,jintsp,n
    COMPLEX :: chi(2,2),chi_one
50

Daniel Wortmann's avatar
Daniel Wortmann committed
51
    TYPE(t_mat)::smat_tmp,hmat_tmp
52 53

    !
Daniel Wortmann's avatar
Daniel Wortmann committed
54 55 56
    IF (noco%l_noco.AND..NOT.noco%l_ss) THEN
       CALL smat_tmp%alloc(smat(1,1)%l_real,smat(1,1)%matsize1,smat(1,1)%matsize2)
       CALL hmat_tmp%alloc(smat(1,1)%l_real,smat(1,1)%matsize1,smat(1,1)%matsize2)
57
    ENDIF
Daniel Wortmann's avatar
Daniel Wortmann committed
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
    
    ALLOCATE(fj(MAXVAL(lapw%nv),0:atoms%lmaxd,MERGE(2,1,noco%l_noco)))
    ALLOCATE(gj(MAXVAL(lapw%nv),0:atoms%lmaxd,MERGE(2,1,noco%l_noco)))

    iintsp=1;jintsp=1;chi_one=1.0 !Defaults in non-noco case
       DO n=1,atoms%ntype
          CALL timestart("fjgj coefficients")
          CALL hsmt_fjgj(input,atoms,cell,lapw,noco,usdus,n,ispin,fj,gj)
          CALL timestop("fjgj coefficients")
          IF (.NOT.noco%l_noco) THEN
             !This is for collinear calculations: the (1,1) element of the matrices is all
             !that is needed and allocated
             CALL hsmt_sph(n,atoms,mpi,ispin,input,noco,cell,1,1,chi_one,lapw,&
                  enpara%el0,td%e_shift,usdus,fj,gj,smat(1,1),hmat(1,1))
             
             CALL hsmt_nonsph(n,mpi,sym,atoms,ispin,1,1,chi_one,noco,cell,lapw,td,fj,gj,hmat(1,1))
             CALL hsmt_lo(input,atoms,sym,cell,mpi,noco,lapw,usdus,td,fj,gj,n,chi_one,ispin,iintsp,jintsp,hmat(1,1),smat(1,1))
          ELSEIF(noco%l_noco.AND..NOT.noco%l_ss) THEN
             !The NOCO but non-spinspiral setup follows:
             !The Matrix-elements are first calculated in the local frame of the atom and
             !stored in tmp-variables. Then these are distributed (rotated) into the 2x2
             !global spin-matrices.
             CALL hmat_tmp%clear();CALL smat_tmp%clear()
             CALL hsmt_sph(n,atoms,mpi,ispin,input,noco,cell,1,1,chi_one,lapw,enpara%el0,td%e_shift,usdus,fj,gj,smat_tmp,hmat_tmp)
             CALL hsmt_nonsph(n,mpi,sym,atoms,ispin,1,1,chi_one,noco,cell,lapw,td,fj,gj,hmat_tmp)
             CALL hsmt_lo(input,atoms,sym,cell,mpi,noco,lapw,usdus,td,fj,gj,n,chi_one,ispin,iintsp,jintsp,hmat_tmp,smat_tmp)
             CALL hsmt_spinor(ispin,n,noco,chi)
             CALL hsmt_distspins(chi,smat_tmp,smat)
             CALL hsmt_distspins(chi,hmat_tmp,hmat)
             !Add off-diagonal contributions to Hamiltonian if needed
             IF (ispin==1.and.noco%l_soc) &
                  CALL hsmt_soc_offdiag(n,atoms,mpi,noco,lapw,usdus,td,fj,gj,hmat)
             IF (noco%l_constr) &
                  CALL hsmt_offdiag(n,atoms,mpi,ispin,noco,lapw,td,usdus,fj,gj,hmat)
92
          ELSE
Daniel Wortmann's avatar
Daniel Wortmann committed
93 94 95 96 97 98 99 100 101
             !In the spin-spiral case the loop over the interstitial=global spin has to
             !be performed explicitely
             CALL hsmt_spinor(ispin,n,noco,chi)
             DO iintsp=1,2
                DO jintsp=1,2
                   CALL hsmt_sph(n,atoms,mpi,ispin,input,noco,cell,iintsp,jintsp,chi(iintsp,jintsp),lapw,enpara%el0,td%e_shift,usdus,fj,gj,smat(iintsp,jintsp),hmat(iintsp,jintsp))
                   CALL hsmt_nonsph(n,mpi,sym,atoms,ispin,iintsp,jintsp,chi(iintsp,jintsp),noco,cell,lapw,td,fj,gj,hmat(iintsp,jintsp))
                ENDDO
             ENDDO
102
          ENDIF
Daniel Wortmann's avatar
Daniel Wortmann committed
103 104
          
    END DO
105

Daniel Wortmann's avatar
Daniel Wortmann committed
106
    
107 108 109
    RETURN
  END SUBROUTINE hsmt
END MODULE m_hsmt