hybrid.F90 5.22 KB
Newer Older
1 2 3 4 5 6
!--------------------------------------------------------------------------------
! Copyright (c) 2016 Peter Grünberg Institut, Forschungszentrum Jülich, Germany
! This file is part of FLEUR and available as free software under the conditions
! of the MIT license as expressed in the LICENSE file in more detail.
!--------------------------------------------------------------------------------

Daniel Wortmann's avatar
Daniel Wortmann committed
7
MODULE m_calc_hybrid
8

Daniel Wortmann's avatar
Daniel Wortmann committed
9
  USE m_judft
10

Daniel Wortmann's avatar
Daniel Wortmann committed
11
CONTAINS
12

13 14
  SUBROUTINE calc_hybrid(eig_id,hybrid,kpts,atoms,input,DIMENSION,mpi,noco,cell,oneD,&
                         enpara,results,sym,xcpot,v,iter,iterHF)
15

Daniel Wortmann's avatar
Daniel Wortmann committed
16 17 18 19 20 21 22 23
    USE m_types
    USE m_mixedbasis
    USE m_coulombmatrix
    USE m_hf_init
    USE m_hf_setup
    USE m_hsfock
    USE m_eig66_io
    USE m_io_hybrid
24

Daniel Wortmann's avatar
Daniel Wortmann committed
25
    IMPLICIT NONE
26 27 28 29 30 31 32 33

    TYPE(t_xcpot_inbuild), INTENT(IN)    :: xcpot
    TYPE(t_mpi),           INTENT(IN)    :: mpi
    TYPE(t_dimension),     INTENT(IN)    :: DIMENSION
    TYPE(t_oneD),          INTENT(IN)    :: oneD
    TYPE(t_hybrid),        INTENT(INOUT) :: hybrid
    TYPE(t_input),         INTENT(IN)    :: input
    TYPE(t_noco),          INTENT(IN)    :: noco
34
    TYPE(t_enpara),        INTENT(IN)    :: enpara
35 36 37 38 39 40 41
    TYPE(t_results),       INTENT(INOUT) :: results
    TYPE(t_sym),           INTENT(IN)    :: sym  
    TYPE(t_cell),          INTENT(IN)    :: cell
    TYPE(t_kpts),          INTENT(IN)    :: kpts
    TYPE(t_atoms),         INTENT(IN)    :: atoms
    TYPE(t_potden),        INTENT(IN)    :: v

42 43
    INTEGER,               INTENT(IN)    :: iter
    INTEGER,               INTENT(INOUT) :: iterHF
44
    INTEGER,               INTENT(IN)    :: eig_id
45 46

    ! local variables
47
    INTEGER           :: jsp,nk,nred
48 49 50 51 52 53 54 55 56
    TYPE(t_hybdat)    :: hybdat
    type(t_lapw)      :: lapw
    LOGICAL           :: init_vex=.TRUE. !In first call we have to init v_nonlocal
    LOGICAL           :: l_restart=.FALSE.
    LOGICAL           :: l_zref

    INTEGER           :: comm(kpts%nkpt),irank2(kpts%nkpt),isize2(kpts%nkpt)
    REAL              :: bkpt(3)
    REAL, ALLOCATABLE :: eig_irr(:,:)
57 58

    INQUIRE(file="v_x.mat",exist=hybrid%l_addhf)
59
    CALL open_hybrid_io1(DIMENSION,sym%invs)
60 61 62 63 64

    IF (kpts%nkptf==0) THEN
       CALL judft_error("kpoint-set of full BZ not available",&
                        hint="to generate kpts in the full BZ you should specify a k-mesh in inp.xml")
    END IF
Daniel Wortmann's avatar
Daniel Wortmann committed
65 66
    
    !Check if new non-local potential shall be generated
67 68
    hybrid%l_subvxc = hybrid%l_hybrid.AND.(.NOT.xcpot%is_name("exx"))
    !If this is the first iteration loop we can not calculate a new non-local potential
69 70
    hybrid%l_calhf = (results%last_distance.GE.0.0).AND.(results%last_distance.LT.input%minDistance)
    IF(.NOT.hybrid%l_calhf) THEN
71
       hybrid%l_subvxc = hybrid%l_subvxc.AND.hybrid%l_addhf
Daniel Wortmann's avatar
Daniel Wortmann committed
72 73
       RETURN
    ENDIF
74

75
    !Check if we are converged well enough to calculate a new potential
76
#if defined(CPP_MPI)&&defined(CPP_NEVER)
77 78 79
    CALL judft_error("Hybrid functionals do not work in parallel version yet")
    CALL MPI_BCAST(results%last_distance .... 
#endif
80 81

    CALL open_hybrid_io1b(DIMENSION,sym%invs)
82
    hybrid%l_addhf = .TRUE.
83

84 85 86
    !In first iteration allocate some memory
    IF (init_vex) THEN
       ALLOCATE(hybrid%ne_eig(kpts%nkpt),hybrid%nbands(kpts%nkpt),hybrid%nobd(kpts%nkptf))
87
       ALLOCATE(hybrid%nbasm(kpts%nkptf))
88
       ALLOCATE(hybrid%div_vv(DIMENSION%neigd,kpts%nkpt,input%jspins))
89 90
       init_vex=.FALSE.
    END IF
91

92 93 94
    hybrid%l_subvxc = (hybrid%l_subvxc.AND.hybrid%l_addhf)
    IF(.NOT.ALLOCATED(results%w_iks)) ALLOCATE (results%w_iks(DIMENSION%neigd2,kpts%nkpt,DIMENSION%jspd))

Daniel Wortmann's avatar
Daniel Wortmann committed
95 96
    IF (.NOT.hybrid%l_calhf) RETURN !use existing non-local potential

97 98
    iterHF = iterHF + 1

99 100
    !Delete broyd files
    CALL system("rm broyd*")
101

Daniel Wortmann's avatar
Daniel Wortmann committed
102 103
    !check if z-reflection trick can be used

104
    l_zref = (sym%zrfs.AND.(SUM(ABS(kpts%bk(3,:kpts%nkpt))).LT.1e-9).AND..NOT.noco%l_noco)
105

Daniel Wortmann's avatar
Daniel Wortmann committed
106
    CALL timestart("Preparation for Hybrid functionals")
107 108
!    CALL juDFT_WARN ("Hybrid functionals not working in this version")

Daniel Wortmann's avatar
Daniel Wortmann committed
109 110
    !construct the mixed-basis
    CALL timestart("generation of mixed basis")
111
    CALL mixedbasis(atoms,kpts,dimension,input,cell,sym,xcpot,hybrid,enpara,mpi,v,l_restart)
Daniel Wortmann's avatar
Daniel Wortmann committed
112 113
    CALL timestop("generation of mixed basis")

114
    CALL open_hybrid_io2(hybrid,DIMENSION,atoms,sym%invs)
Daniel Wortmann's avatar
Daniel Wortmann committed
115 116 117 118

    CALL timestart("generation of coulomb matrix")
    CALL coulombmatrix(mpi,atoms,kpts,cell,sym,hybrid,xcpot,l_restart)
    CALL timestop("generation of coulomb matrix")
119

Daniel Wortmann's avatar
Daniel Wortmann committed
120 121
    CALL hf_init(hybrid,kpts,atoms,input,DIMENSION,hybdat,irank2,isize2,sym%invs)
    CALL timestop("Preparation for Hybrid functionals")
122

123
    CALL timestart("Calculation of non-local HF potential")
Daniel Wortmann's avatar
Daniel Wortmann committed
124
    DO jsp = 1,input%jspins
125
       CALL HF_setup(hybrid,input,sym,kpts,dimension,atoms,mpi,noco,cell,oneD,results,jsp,enpara,eig_id,&
126
                     hybdat,irank2,iterHF,sym%invs,v%mt(:,0,:,:),eig_irr)
Daniel Wortmann's avatar
Daniel Wortmann committed
127

128
       DO nk = mpi%n_start,kpts%nkpt,mpi%n_stride
Daniel Wortmann's avatar
Daniel Wortmann committed
129
          CALL lapw%init(input,noco, kpts,atoms,sym,nk,cell,l_zref)
Daniel Wortmann's avatar
Daniel Wortmann committed
130
  
131
          CALL hsfock(nk,atoms,hybrid,lapw,DIMENSION,kpts,jsp,input,hybdat,eig_irr,sym,cell,&
132
                      noco,results,iterHF,MAXVAL(hybrid%nobd),xcpot,mpi,irank2(nk),isize2(nk),comm(nk))
Daniel Wortmann's avatar
Daniel Wortmann committed
133 134
       END DO
    END DO
135
    CALL timestop("Calculation of non-local HF potential")
Daniel Wortmann's avatar
Daniel Wortmann committed
136
    CALL close_eig(eig_id)
137
  END SUBROUTINE calc_hybrid
Daniel Wortmann's avatar
Daniel Wortmann committed
138
END MODULE m_calc_hybrid