The Elk Code
gwsefmk.f90
Go to the documentation of this file.
1 
2 ! Copyright (C) 2016 A. Davydov, A. Sanna, J. K. Dewhurst, S. Sharma and
3 ! E. K. U. Gross. This file is distributed under the terms of the GNU General
4 ! Public License. See the file COPYING for license details.
5 
6 subroutine gwsefmk(ikp,vmt,vir,bmt,bir,se)
7 use modmain
8 use modgw
9 use modomp
10 implicit none
11 ! arguments
12 integer, intent(in) :: ikp
13 real(8), intent(in) :: vmt(npcmtmax,natmtot),vir(ngtc)
14 real(8), intent(in) :: bmt(npcmtmax,natmtot,ndmag),bir(ngtc,ndmag)
15 complex(8), intent(out) :: se(nstsv,nstsv,0:nwfm)
16 ! local variables
17 integer ik,jk,ist1,ist2,ist3
18 integer iv(3),iq,ig0,ig1,ig,jg
19 integer iw,jw,it,nthd
20 real(8) vl(3),vc(3),wo,t1,t2
21 complex(4) c1,c2
22 ! automatic arrays
23 integer(omp_lock_kind) lock(nwgw)
24 real(8) vgqc(3,ngvc),gqc(ngvc),gclgq(ngvc)
25 complex(8) zfgq(ngrf)
26 complex(4) cvclmt(npcmtmax,natmtot),cvclir(ngtc)
27 complex(4) y(max(nstsv,nwgw))
28 ! allocatable arrays
29 real(8), allocatable :: jlgqr(:,:,:),jlgqrmt(:,:,:)
30 complex(8), allocatable :: apwalm(:,:,:,:),evecfv(:,:),evecsv(:,:)
31 complex(8), allocatable :: ylmgq(:,:),sfacgq(:,:)
32 complex(4), allocatable :: wfmt1(:,:,:,:),wfir1(:,:,:)
33 complex(4), allocatable :: wfmt2(:,:,:,:),wfir2(:,:,:)
34 complex(4), allocatable :: crhomt(:,:,:),crhoir(:,:)
35 complex(4), allocatable :: crgq(:,:,:),gs(:,:),stau(:,:,:),wc(:,:)
36 complex(8), allocatable :: epsi(:,:,:),v(:,:)
37 ! external functions
38 complex(8), external :: zcfinp
39 ! allocate local arrays
40 allocate(jlgqr(njcmax,nspecies,ngrf),jlgqrmt(0:lnpsd,ngvc,nspecies))
41 allocate(apwalm(ngkmax,apwordmax,lmmaxapw,natmtot))
42 allocate(ylmgq(lmmaxo,ngvc),sfacgq(ngvc,natmtot))
43 allocate(evecfv(nmatmax,nstfv),evecsv(nstsv,nstsv))
44 allocate(wfmt1(npcmtmax,natmtot,nspinor,nstsv),wfir1(ngtc,nspinor,nstsv))
45 allocate(wfmt2(npcmtmax,natmtot,nspinor,nstsv),wfir2(ngtc,nspinor,nstsv))
46 allocate(crhomt(npcmtmax,natmtot,nstsv),crhoir(ngtc,nstsv))
47 allocate(crgq(nstsv,ngrf,nstsv),gs(nwgw,nstsv),stau(nstsv,nstsv,nwgw))
48 allocate(epsi(ngrf,ngrf,nwrf),v(nstsv,nstsv))
49 ! initialise the OpenMP locks
50 do it=1,nwgw
51  call omp_init_lock(lock(it))
52 end do
53 ! get the eigenvectors from file for input reduced k-point
54 call getevecfv(filext,ikp,vkl(:,ikp),vgkl(:,:,:,ikp),evecfv)
55 call getevecsv(filext,ikp,vkl(:,ikp),evecsv)
56 ! find the matching coefficients
57 call match(ngk(1,ikp),vgkc(:,:,1,ikp),gkc(:,1,ikp),sfacgk(:,:,1,ikp),apwalm)
58 ! calculate the wavefunctions for all states of the input k-point
59 call genwfsv_sp(.false.,.true.,nstsv,[0],ngdgc,igfc,ngk(1,ikp),igkig(:,1,ikp), &
60  apwalm,evecfv,evecsv,wfmt1,ngtc,wfir1)
61 ! local -V_xc and -B_xc matrix elements
62 if (spinpol) then
63  call genvbmatk(vmt,vir,bmt,bir,ngk(1,ikp),igkig(:,1,ikp),wfmt1,ngtc,wfir1,v)
64 else
65  call genvmatk(vmt,vir,ngk(1,ikp),igkig(:,1,ikp),wfmt1,ngtc,wfir1,v)
66 end if
67 ! Fourier transform wavefunctions to real-space
68 call cftwfir(ngk(1,ikp),igkig(:,1,ikp),wfir1)
69 ! add the core Fock matrix elements
70 call vclcore(wfmt1,v)
71 ! zero the self-energy matrix elements in tau-space
72 stau(1:nstsv,1:nstsv,1:nwgw)=0.e0
73 ! loop over non-reduced k-point set
74 do ik=1,nkptnr
75 ! equivalent reduced k-point
76  jk=ivkik(ivk(1,ik),ivk(2,ik),ivk(3,ik))
77 ! determine the q-vector
78  iv(1:3)=ivk(1:3,ikp)-ivk(1:3,ik)
79  iv(1:3)=modulo(iv(1:3),ngridk(1:3))
80 ! check if the q-point is in user-defined set
81  iv(1:3)=iv(1:3)*ngridq(1:3)
82  if (any(mod(iv(1:3),ngridk(1:3)) /= 0)) cycle
83  iv(1:3)=iv(1:3)/ngridk(1:3)
84  iq=ivqiq(iv(1),iv(2),iv(3))
85  vl(1:3)=vkl(1:3,ikp)-vkl(1:3,ik)
86  vc(1:3)=vkc(1:3,ikp)-vkc(1:3,ik)
87  do ig=1,ngvc
88 ! determine the G+q-vectors
89  vgqc(1:3,ig)=vgc(1:3,ig)+vc(1:3)
90 ! G+q-vector length
91  gqc(ig)=sqrt(vgqc(1,ig)**2+vgqc(2,ig)**2+vgqc(3,ig)**2)
92 ! spherical harmonics for G+q-vectors
93  call genylmv(.true.,lmaxo,vgqc(:,ig),ylmgq(:,ig))
94  end do
95 ! structure factors for G+q
96  call gensfacgp(ngvc,vgqc,ngvc,sfacgq)
97 ! generate the regularised Coulomb Green's function in G+q-space
98  call gengclgq(.true.,iq,ngvc,gqc,gclgq)
99 ! compute the required spherical Bessel functions
100  call genjlgprmt(lnpsd,ngvc,gqc,ngvc,jlgqrmt)
101  call genjlgpr(ngrf,gqc,jlgqr)
102 ! find the matching coefficients
103  call match(ngk(1,ik),vgkc(:,:,1,ik),gkc(:,1,ik),sfacgk(:,:,1,ik),apwalm)
104 ! get the eigenvectors from file for non-reduced k-point
105  call getevecfv(filext,0,vkl(:,ik),vgkl(:,:,1,ik),evecfv)
106  call getevecsv(filext,0,vkl(:,ik),evecsv)
107 ! calculate the wavefunctions for all states
108  call genwfsv_sp(.false.,.false.,nstsv,[0],ngdgc,igfc,ngk(1,ik),igkig(:,1,ik),&
109  apwalm,evecfv,evecsv,wfmt2,ngtc,wfir2)
110  call holdthd(nstsv,nthd)
111 !$OMP PARALLEL DEFAULT(SHARED) &
112 !$OMP PRIVATE(cvclmt,cvclir,zfgq) &
113 !$OMP PRIVATE(ist1,ist2,ist3,wo,t1,iw) &
114 !$OMP NUM_THREADS(nthd)
115 ! determine the complex densities and Fourier transform to G+q-space
116  do ist3=1,nstsv
117 !$OMP DO SCHEDULE(DYNAMIC)
118  do ist1=1,nstsv
119  call gencrho(.true.,.true.,ngtc,wfmt2(:,:,:,ist3),wfir2(:,:,ist3), &
120  wfmt1(:,:,:,ist1),wfir1(:,:,ist1),crhomt(:,:,ist1),crhoir(:,ist1))
121  call zftcf(ngrf,jlgqr,ylmgq,ngvc,sfacgq,crhomt(:,:,ist1),crhoir(:,ist1), &
122  zfgq)
123  crgq(ist1,1:ngrf,ist3)=conjg(zfgq(1:ngrf))
124  end do
125 !$OMP END DO
126 !--------------------------------------!
127 ! valence Fock matrix elements !
128 !--------------------------------------!
129  wo=wqptnr*occsv(ist3,jk)/occmax
130  if (abs(wo) < epsocc) cycle
131 !$OMP DO SCHEDULE(DYNAMIC)
132  do ist2=1,nstsv
133 ! calculate the Coulomb potential
134  call gencvclmt(nrcmt,nrcmti,nrcmtmax,rlcmt,wprcmt,npcmtmax, &
135  crhomt(:,:,ist2),cvclmt)
136  call cpotcoul(nrcmt,nrcmti,npcmt,nrcmtmax,rlcmt,ngdgc,igfc,ngvc,gqc, &
137  gclgq,ngvc,jlgqrmt,ylmgq,sfacgq,crhoir(:,ist2),npcmtmax,cvclmt,cvclir)
138  cvclir(1:ngtc)=cvclir(1:ngtc)*cfrc(1:ngtc)
139  do ist1=1,ist2
140  v(ist1,ist2)=v(ist1,ist2) &
141  -wo*zcfinp(crhomt(:,:,ist1),crhoir(:,ist1),cvclmt,cvclir)
142  end do
143  end do
144 !$OMP END DO
145  end do
146 !-------------------------------------!
147 ! correlation matrix elements !
148 !-------------------------------------!
149 ! generate Gₛ in state and tau-space
150 !$OMP DO SCHEDULE(DYNAMIC)
151  do ist1=1,nstsv
152  t1=efermi-evalsv(ist1,jk)
153  gs(1:nwgw,ist1)=0.e0
154  do iw=-nwfm,nwfm,2
155  gs(iwfft(iw),ist1)=1.e0/cmplx(t1,wgw(iw),4)
156  end do
157  call cfftifc(1,nwgw,1,gs(:,ist1))
158  end do
159 !$OMP END DO
160 !$OMP END PARALLEL
161  call freethd(nthd)
162 ! get RPA inverse dielectric function from file
163 ! this is the symmetric version: ϵ⁻¹ = 1 - v¹⸍² χ₀ v¹⸍²
164  call getcfgq('EPSINV.OUT',vl,ngrf,nwrf,epsi)
165 ! symmetrise the Coulomb Green's function
166  gclgq(1:ngrf)=sqrt(gclgq(1:ngrf))
167  call holdthd(ngrf,nthd)
168 !$OMP PARALLEL DEFAULT(SHARED) &
169 !$OMP PRIVATE(wc,y,ig0,ig1,t1,t2,ig) &
170 !$OMP PRIVATE(iw,jw,it,ist2,ist3,c2) &
171 !$OMP NUM_THREADS(nthd)
172  allocate(wc(nwgw,ngrf))
173 !$OMP DO SCHEDULE(DYNAMIC)
174  do jg=1,ngrf
175 ! if the real part of epsi is exactly zero then there is no entry for this
176 ! particular G'+q-vector so we cycle to the next
177  if (dble(epsi(jg,jg,1)) == 0.d0) cycle
178 ! determine the range of ig from the desired matrix bandwidth
179  if (mbwgrf >= 0) then
180  ig0=max(jg-mbwgrf,1)
181  ig1=min(jg+mbwgrf,ngrf)
182  else
183  ig0=1; ig1=ngrf
184  end if
185 ! subtract one from ϵ⁻¹ to leave just the correlation part
186  epsi(jg,jg,1:nwrf)=epsi(jg,jg,1:nwrf)-1.d0
187 ! compute the correlation part of the screened interaction W_c
188  t1=gclgq(jg)
189  do ig=ig0,ig1
190  t2=t1*gclgq(ig)
191  wc(1:nwgw,ig)=0.e0
192  do iw=-nwbs,nwbs,2
193  jw=(iw+nwbs)/2+1
194  wc(iwfft(iw),ig)=t2*epsi(ig,jg,jw)
195  end do
196 ! Fourier transform W_c to tau-space
197  call cfftifc(1,nwgw,1,wc(:,ig))
198  end do
199 ! loop over tau-points
200  do it=1,nwgw
201  do ist3=1,nstsv
202  c1=gs(it,ist3)
203  y(1:nstsv)=0.e0
204  do ig=ig0,ig1
205  c2=c1*wc(it,ig)
206  y(1:nstsv)=y(1:nstsv)+c2*crgq(1:nstsv,ig,ist3)
207  end do
208  call omp_set_lock(lock(it))
209  if (tsediag) then
210 ! compute only the diagonal elements of the self-energy
211  do ist2=1,nstsv
212  c2=conjg(crgq(ist2,jg,ist3))
213  stau(ist2,ist2,it)=stau(ist2,ist2,it)+c2*y(ist2)
214  end do
215  else
216 ! compute the full self-energy matrix
217  do ist2=1,nstsv
218  c2=conjg(crgq(ist2,jg,ist3))
219  stau(1:nstsv,ist2,it)=stau(1:nstsv,ist2,it)+c2*y(1:nstsv)
220  end do
221  end if
222  call omp_unset_lock(lock(it))
223  end do
224  end do
225  end do
226 !$OMP END DO
227  deallocate(wc)
228 !$OMP END PARALLEL
229  call freethd(nthd)
230 ! end loop over k-points
231 end do
232 ! destroy the OpenMP locks
233 do it=1,nwgw
234  call omp_destroy_lock(lock(it))
235 end do
236 ! Fourier transform the self-energy to frequency space, multiply by GW diagram
237 ! prefactor and store in output array
239 call holdthd(nstsv,nthd)
240 !$OMP PARALLEL DO DEFAULT(SHARED) &
241 !$OMP PRIVATE(y,ist1,iw,jw) &
242 !$OMP NUM_THREADS(nthd) &
243 !$OMP SCHEDULE(DYNAMIC)
244 do ist2=1,nstsv
245  do ist1=1,nstsv
246  y(1:nwgw)=stau(ist1,ist2,1:nwgw)
247  call cfftifc(1,nwgw,-1,y)
248  do iw=-nwfm,nwfm,2
249  jw=(iw+nwfm)/2
250  se(ist1,ist2,jw)=t1*y(iwfft(iw))
251  end do
252  end do
253 end do
254 !$OMP END PARALLEL DO
255 call freethd(nthd)
256 ! add the local potential and Fock matrix elements to the self-energy for each
257 ! Matsubara frequency
258 call holdthd(nwfm+1,nthd)
259 !$OMP PARALLEL DO DEFAULT(SHARED) &
260 !$OMP PRIVATE(ist1,ist2) &
261 !$OMP SCHEDULE(DYNAMIC) &
262 !$OMP NUM_THREADS(nthd)
263 do iw=0,nwfm
264  do ist2=1,nstsv
265  do ist1=1,ist2
266  se(ist1,ist2,iw)=se(ist1,ist2,iw)+v(ist1,ist2)
267  end do
268  do ist1=ist2+1,nstsv
269  se(ist1,ist2,iw)=se(ist1,ist2,iw)+conjg(v(ist2,ist1))
270  end do
271  end do
272 end do
273 !$OMP END PARALLEL DO
274 call freethd(nthd)
275 deallocate(jlgqr,jlgqrmt)
276 deallocate(ylmgq,sfacgq,apwalm,evecfv,evecsv)
277 deallocate(wfmt1,wfir1,wfmt2,wfir2)
278 deallocate(crhomt,crhoir,gs,stau,crgq,epsi,v)
279 end subroutine
280 
integer nmatmax
Definition: modmain.f90:853
real(8) efermi
Definition: modmain.f90:907
subroutine gencvclmt(nrmt_, nrmti_, ld1, rl, wpr, ld2, crhomt, cvclmt)
Definition: gencvclmt.f90:7
integer, dimension(maxspecies) npcmt
Definition: modmain.f90:214
integer, dimension(:), allocatable iwfft
Definition: modgw.f90:17
subroutine getevecsv(fext, ikp, vpl, evecsv)
Definition: getevecsv.f90:7
integer nwrf
Definition: modmain.f90:1168
character(256) filext
Definition: modmain.f90:1301
pure subroutine gensfacgp(ngp, vgpc, ld, sfacgp)
Definition: gensfacgp.f90:10
real(8), dimension(:,:), allocatable evalsv
Definition: modmain.f90:921
integer lmmaxo
Definition: modmain.f90:203
logical spinpol
Definition: modmain.f90:228
integer lmmaxapw
Definition: modmain.f90:199
integer mbwgrf
Definition: modmain.f90:1166
integer ngkmax
Definition: modmain.f90:499
subroutine getevecfv(fext, ikp, vpl, vgpl, evecfv)
Definition: getevecfv.f90:10
real(8) wqptnr
Definition: modmain.f90:551
real(8) omega
Definition: modmain.f90:20
subroutine gencrho(tsh, tspc, ngt, wfmt1, wfir1, wfmt2, wfir2, crhomt, crhoir)
Definition: gencrho.f90:7
subroutine match(ngp, vgpc, gpc, sfacgp, apwalm)
Definition: match.f90:10
Definition: modomp.f90:6
real(8), parameter kboltz
Definition: modmain.f90:1263
real(8) epsocc
Definition: modmain.f90:903
integer, dimension(:,:,:), allocatable ivkik
Definition: modmain.f90:467
integer nwbs
Definition: modgw.f90:21
integer lmaxo
Definition: modmain.f90:201
integer nkptnr
Definition: modmain.f90:463
pure subroutine genylmv(t4pil, lmax, v, ylm)
Definition: genylmv.f90:10
subroutine getcfgq(fname, vpl, ng, m, cf)
Definition: getcfgq.f90:7
complex(8), dimension(:,:,:,:), allocatable sfacgk
Definition: modmain.f90:509
subroutine cfftifc(nd, n, sgn, c)
Definition: cfftifc_fftw.f90:7
real(8), dimension(:,:), allocatable vkc
Definition: modmain.f90:473
subroutine vclcore(wfmt, vmat)
Definition: vclcore.f90:7
real(8), dimension(:,:), allocatable vgc
Definition: modmain.f90:420
integer nrcmtmax
Definition: modmain.f90:175
pure subroutine gengclgq(treg, iq, ngq, gqc, gclgq)
Definition: gengclgq.f90:7
integer, dimension(:,:), allocatable ngk
Definition: modmain.f90:497
subroutine genvmatk(vmt, vir, ngp, igpig, wfmt, ld, wfgp, vmat)
Definition: genvmatk.f90:7
real(8) occmax
Definition: modmain.f90:901
subroutine genwfsv_sp(tsh, tgp, nst, idx, ngridg_, igfft_, ngp, igpig, apwalm, evecfv, evecsv, wfmt, ld, wfir)
Definition: genwfsv_sp.f90:8
subroutine zftcf(ngp, jlgpr, ylmgp, ld, sfacgp, cfmt, cfir, zfgp)
Definition: zftcf.f90:7
real(8), dimension(:,:,:,:), allocatable vgkl
Definition: modmain.f90:503
integer, dimension(:), allocatable igfc
Definition: modmain.f90:410
subroutine gwsefmk(ikp, vmt, vir, bmt, bir, se)
Definition: gwsefmk.f90:7
real(8), dimension(:,:,:), allocatable rlcmt
Definition: modmain.f90:181
real(8) tempk
Definition: modmain.f90:684
integer, dimension(3) ngridk
Definition: modmain.f90:448
real(8), dimension(:,:), allocatable occsv
Definition: modmain.f90:905
real(8), dimension(:,:,:), allocatable wprcmt
Definition: modmain.f90:191
integer nspinor
Definition: modmain.f90:267
real(8), dimension(:), allocatable wgw
Definition: modgw.f90:23
integer, dimension(:,:,:), allocatable ivqiq
Definition: modmain.f90:531
real(8), dimension(:,:,:,:), allocatable vgkc
Definition: modmain.f90:505
integer, dimension(3) ngridq
Definition: modmain.f90:515
real(8), dimension(:,:), allocatable vkl
Definition: modmain.f90:471
subroutine cpotcoul(nrmt_, nrmti_, npmt_, ld1, rl, ngridg_, igfft_, ngp, gpc, gclgp, ld2, jlgprmt, ylmgp, sfacgp, crhoir, ld3, cvclmt, cvclir)
Definition: cpotcoul.f90:8
Definition: modgw.f90:6
integer apwordmax
Definition: modmain.f90:760
real(8), dimension(:,:,:), allocatable gkc
Definition: modmain.f90:507
integer, dimension(3) ngdgc
Definition: modmain.f90:388
subroutine genjlgpr(ngp, gpc, jlgpr)
Definition: genjlgpr.f90:7
integer lnpsd
Definition: modmain.f90:628
integer nspecies
Definition: modmain.f90:34
subroutine freethd(nthd)
Definition: modomp.f90:106
subroutine holdthd(nloop, nthd)
Definition: modomp.f90:78
subroutine genjlgprmt(lmax, ngp, gpc, ld, jlgprmt)
Definition: genjlgprmt.f90:10
integer njcmax
Definition: modmain.f90:1173
subroutine cftwfir(ngp, igpig, wfir)
Definition: cftwfir.f90:7
real(8), dimension(:), allocatable cfrc
Definition: modmain.f90:438
integer, dimension(maxspecies) nrcmt
Definition: modmain.f90:173
integer, dimension(maxspecies) nrcmti
Definition: modmain.f90:211
subroutine genvbmatk(vmt, vir, bmt, bir, ngp, igpig, wfmt, ld, wfgp, vbmat)
Definition: genvbmatk.f90:7
integer, dimension(:,:,:), allocatable igkig
Definition: modmain.f90:501
integer nstfv
Definition: modmain.f90:887
integer, dimension(:,:), allocatable ivk
Definition: modmain.f90:465
logical tsediag
Definition: modgw.f90:27