solve_hf.f90 8.27 KB
Newer Older
Marco Govoni's avatar
Marco Govoni committed
1
!
2
! Copyright (C) 2015-2017 M. Govoni 
Marco Govoni's avatar
Marco Govoni committed
3
4
5
6
7
8
9
10
11
12
! This file is distributed under the terms of the
! GNU General Public License. See the file `License'
! in the root directory of the present distribution,
! or http://www.gnu.org/copyleft/gpl.txt .
!
! This file is part of WEST.
!
! Contributors to this file: 
! Marco Govoni
!
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
!----------------------------------------------------------------------------
SUBROUTINE solve_hf ( )
  !----------------------------------------------------------------------------
  !
  USE control_flags,   ONLY : gamma_only
  !
  IMPLICIT NONE
  !
  IF( gamma_only ) THEN
    CALL solve_hf_gamma( )
  ELSE
    CALL solve_hf_k( )
  ENDIF
  !
END SUBROUTINE
!
Marco Govoni's avatar
Marco Govoni committed
29
!-----------------------------------------------------------------------
30
SUBROUTINE solve_hf_gamma( )
Marco Govoni's avatar
Marco Govoni committed
31
32
33
34
35
36
  !-----------------------------------------------------------------------
  !
  ! ... This subroutine solves the DBS problem for GAMMA, at non-zero freqeuncies. 
  ! ... Perturbations are distributed according to the POT mpi_communicator
  !
  USE kinds,                ONLY : DP 
37
  USE westcom,              ONLY : west_prefix,n_pdep_eigen_to_use,n_lanczos,qp_bandrange,iks_l2g,&
Marco Govoni's avatar
Marco Govoni committed
38
39
40
41
42
43
44
45
46
47
48
49
50
                                 & n_secant_maxiter,n_imfreq,nbnd_occ,trev_secant,l_enable_gwetot,exx_etot, &
                                 & sigma_exx, sigma_vxcl, sigma_vxcnl, sigma_hf
  USE mp_global,            ONLY : my_image_id,nimage,inter_image_comm,intra_bgrp_comm, &
                                 & root_bgrp,me_bgrp,me_image,root_image
  USE mp_world,             ONLY : nproc,mpime,root,world_comm
  USE mp,                   ONLY : mp_bcast,mp_barrier
  USE io_global,            ONLY : stdout, ionode
  USE pwcom,                ONLY : et,nks,current_spin,isk,xk,nbnd,lsda,g2kin,current_k
  USE wavefunctions_module, ONLY : evc,psic,psic_nc
  USE io_files,             ONLY : tmp_dir
  USE io_push,              ONLY : io_push_title,io_push_bar
  USE noncollin_module,     ONLY : noncolin,npol 
  USE constants,            ONLY : rytoev
51
  USE west_io,              ONLY : serial_table_output
Marco Govoni's avatar
Marco Govoni committed
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
  USE distribution_center,  ONLY : pert
  USE funct,                ONLY : get_exx_fraction,dft_is_hybrid
  USE klist,                ONLY : wk
  USE wfreq_io,             ONLY : writeout_solvehf 
  !
  IMPLICIT NONE
  !
  ! Workspace
  !
  CHARACTER(LEN=5) :: myglobk
  INTEGER :: ib, iks 
  REAL(DP),ALLOCATABLE :: out_tab(:,:)
  INTEGER :: nbndval
  REAL(DP),ALLOCATABLE :: sigma_exx_all_occupied(:,:)
  ! 
  CALL start_clock('solve_hf')
  !
  CALL io_push_title("Hartree-Fock Exact E(X)change")
  !
  ! Get SIGMA Vxc
  !
  CALL calc_vxc(sigma_vxcl,sigma_vxcnl)
  !
  ! Get SIGMA EXX
  !
77
  CALL calc_exx2(sigma_exx, qp_bandrange(1), qp_bandrange(2))
Marco Govoni's avatar
Marco Govoni committed
78
79
80
81
82
83
  !
  ! Get SIGMA X
  !
  sigma_hf(:,:) = sigma_exx(:,:) - sigma_vxcl(:,:) - sigma_vxcnl(:,:)
  !
  CALL writeout_solvehf( sigma_hf(qp_bandrange(1),1), qp_bandrange(2)-qp_bandrange(1)+1, nks  )
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
 !
 ! Output it per k-point
 !
 ALLOCATE(out_tab(qp_bandrange(2)-qp_bandrange(1)+1,6))
 DO iks=1,nks
    DO ib = qp_bandrange(1), qp_bandrange(2)
       out_tab( ib - qp_bandrange(1) + 1, 1) = REAL( ib, KIND=DP) 
       out_tab( ib - qp_bandrange(1) + 1, 2) = et(ib,iks) * rytoev
       out_tab( ib - qp_bandrange(1) + 1, 3) = sigma_exx(ib,iks) * rytoev
       out_tab( ib - qp_bandrange(1) + 1, 4) = sigma_vxcl(ib,iks) * rytoev
       out_tab( ib - qp_bandrange(1) + 1, 5) = sigma_vxcnl(ib,iks) * rytoev
       out_tab( ib - qp_bandrange(1) + 1, 6) = ( et(ib,iks) + sigma_hf(ib,iks) ) * rytoev
    ENDDO
    WRITE(myglobk,'(i5.5)') iks_l2g(iks)
    !
    CALL serial_table_output(mpime==root,4000,'ehf_K'//myglobk,out_tab,&
    & qp_bandrange(2)-qp_bandrange(1)+1,6,&
    & (/'      band','    E0[eV]','    Sx[eV]','  Vxcl[eV]',' Vxcnl[eV]','   EHF[eV]'/))
 ENDDO
 DEALLOCATE(out_tab)
  !
  ! Compute the exact exchange energy (used to calculate total GW energy) 
  !
  IF( l_enable_gwetot) THEN
     !
     nbndval = MIN( MAXVAL( nbnd_occ(:) ), nbnd ) 
     ALLOCATE(sigma_exx_all_occupied(nbndval,nks))
     !
112
     CALL calc_exx2( sigma_exx_all_occupied, 1, nbndval ) 
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
     !
     exx_etot = 0._DP
     DO iks = 1, nks 
        DO ib = 1, nbnd_occ(iks) 
           exx_etot = exx_etot + sigma_exx_all_occupied( ib, iks) * wk(iks) / 2._DP
        ENDDO
     ENDDO
     !
     DEALLOCATE( sigma_exx_all_occupied )  
     !
  ENDIF
  !
  !DEALLOCATE( sigma_exx  )
  !DEALLOCATE( sigma_vxcl )
  !DEALLOCATE( sigma_vxcnl)
  !DEALLOCATE( sigma_hf   )
  !
  CALL stop_clock( "solve_hf" )
  !
END SUBROUTINE
!
!-----------------------------------------------------------------------
SUBROUTINE solve_hf_k( )
  !-----------------------------------------------------------------------
  !
  ! ... This subroutine solves the DBS problem for GAMMA, at non-zero freqeuncies. 
  ! ... Perturbations are distributed according to the POT mpi_communicator
  !
  USE kinds,                ONLY : DP 
142
  USE westcom,              ONLY : west_prefix,n_pdep_eigen_to_use,n_lanczos,qp_bandrange,iks_l2g,&
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
                                 & n_secant_maxiter,n_imfreq,nbnd_occ,trev_secant,l_enable_gwetot,exx_etot, &
                                 & sigma_exx, sigma_vxcl, sigma_vxcnl, sigma_hf
  USE mp_global,            ONLY : my_image_id,nimage,inter_image_comm,intra_bgrp_comm, &
                                 & root_bgrp,me_bgrp,me_image,root_image
  USE mp_world,             ONLY : nproc,mpime,root,world_comm
  USE mp,                   ONLY : mp_bcast,mp_barrier
  USE io_global,            ONLY : stdout, ionode
  USE pwcom,                ONLY : et,nks,current_spin,isk,xk,nbnd,lsda,g2kin,current_k
  USE wavefunctions_module, ONLY : evc,psic,psic_nc
  USE io_files,             ONLY : tmp_dir
  USE io_push,              ONLY : io_push_title,io_push_bar
  USE noncollin_module,     ONLY : noncolin,npol 
  USE constants,            ONLY : rytoev
  USE west_io,              ONLY : serial_table_output
  USE distribution_center,  ONLY : pert
  USE funct,                ONLY : get_exx_fraction,dft_is_hybrid
  USE klist,                ONLY : wk
  USE wfreq_io,             ONLY : writeout_solvehf 
  USE types_bz_grid,        ONLY : k_grid
  !
  IMPLICIT NONE
  !
  ! Workspace
  !
  CHARACTER(LEN=5) :: myglobk
  INTEGER :: ib, iks 
  REAL(DP),ALLOCATABLE :: out_tab(:,:)
  INTEGER :: nbndval
  REAL(DP),ALLOCATABLE :: sigma_exx_all_occupied(:,:)
  ! 
  CALL start_clock('solve_hf')
  !
  CALL io_push_title("Hartree-Fock Exact E(X)change")
  !
  ! Get SIGMA Vxc
  !
  CALL calc_vxc(sigma_vxcl,sigma_vxcnl)
  !
  ! Get SIGMA EXX
  !
183
  CALL calc_exx2(sigma_exx, qp_bandrange(1), qp_bandrange(2))
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
  !
  ! Get SIGMA X
  !
  sigma_hf(:,:) = sigma_exx(:,:) - sigma_vxcl(:,:) - sigma_vxcnl(:,:)
  !
  CALL writeout_solvehf( sigma_hf(qp_bandrange(1),1), qp_bandrange(2)-qp_bandrange(1)+1, k_grid%nps  )
  !
  ! Output it per k-point
  !
  ALLOCATE(out_tab(qp_bandrange(2)-qp_bandrange(1)+1,6))
  DO iks=1,k_grid%nps
     DO ib = qp_bandrange(1), qp_bandrange(2)
        out_tab( ib - qp_bandrange(1) + 1, 1) = REAL( ib, KIND=DP) 
        out_tab( ib - qp_bandrange(1) + 1, 2) = et(ib,iks) * rytoev
        out_tab( ib - qp_bandrange(1) + 1, 3) = sigma_exx(ib,iks) * rytoev
        out_tab( ib - qp_bandrange(1) + 1, 4) = sigma_vxcl(ib,iks) * rytoev
        out_tab( ib - qp_bandrange(1) + 1, 5) = sigma_vxcnl(ib,iks) * rytoev
        out_tab( ib - qp_bandrange(1) + 1, 6) = ( et(ib,iks) + sigma_hf(ib,iks) ) * rytoev
     ENDDO
     WRITE(myglobk,'(i5.5)') iks_l2g(iks)
     !
     CALL serial_table_output(mpime==root,4000,'ehf_K'//myglobk,out_tab,&
     & qp_bandrange(2)-qp_bandrange(1)+1,6,&
     & (/'      band','    E0[eV]','    Sx[eV]','  Vxcl[eV]',' Vxcnl[eV]','   EHF[eV]'/))
  ENDDO
  DEALLOCATE(out_tab)
Marco Govoni's avatar
Marco Govoni committed
210
211
212
213
214
215
  !
  ! Compute the exact exchange energy (used to calculate total GW energy) 
  !
  IF( l_enable_gwetot) THEN
     !
     nbndval = MIN( MAXVAL( nbnd_occ(:) ), nbnd ) 
216
     ALLOCATE(sigma_exx_all_occupied(nbndval,k_grid%nps))
Marco Govoni's avatar
Marco Govoni committed
217
     !
218
     CALL calc_exx2( sigma_exx_all_occupied, 1, nbndval ) 
Marco Govoni's avatar
Marco Govoni committed
219
220
     !
     exx_etot = 0._DP
221
     DO iks = 1, k_grid%nps
Marco Govoni's avatar
Marco Govoni committed
222
        DO ib = 1, nbnd_occ(iks) 
223
           exx_etot = exx_etot + sigma_exx_all_occupied( ib, iks) * k_grid%weight(iks) / 2._DP
Marco Govoni's avatar
Marco Govoni committed
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
        ENDDO
     ENDDO
     !
     DEALLOCATE( sigma_exx_all_occupied )  
     !
  ENDIF
  !
  !DEALLOCATE( sigma_exx  )
  !DEALLOCATE( sigma_vxcl )
  !DEALLOCATE( sigma_vxcnl)
  !DEALLOCATE( sigma_hf   )
  !
  CALL stop_clock( "solve_hf" )
  !
END SUBROUTINE