The Elk Code
hmldbsek.f90
Go to the documentation of this file.
1 
2 ! Copyright (C) 2010 S. Sharma, J. K. Dewhurst and E. K. U. Gross.
3 ! This file is distributed under the terms of the GNU General Public License.
4 ! See the file COPYING for license details.
5 
6 subroutine hmldbsek(ik2)
7 use modmain
8 use modomp
9 implicit none
10 ! arguments
11 integer, intent(in) :: ik2
12 ! local variables
13 integer ik1,ist1,ist2,jst1,jst2
14 integer i1,i2,j1,j2,a1,a2,b1,b2
15 integer iv(3),iq,ig,jg,nthd
16 real(8) vl(3),vc(3),t0,t1,t2
17 complex(8) z1
18 ! automatic arrays
19 integer ngp(nspnfv)
20 ! allocatable arrays
21 integer, allocatable :: igpig(:,:)
22 real(8), allocatable :: vgqc(:,:),gqc(:),gclgq(:),jlgqr(:,:,:)
23 complex(8), allocatable :: ylmgq(:,:),sfacgq(:,:)
24 complex(4), allocatable :: wfmt1(:,:,:,:),wfir1(:,:,:)
25 complex(4), allocatable :: wfmt2(:,:,:,:),wfir2(:,:,:)
26 complex(4), allocatable :: crhomt(:,:),crhoir(:)
27 complex(8), allocatable :: zvv(:,:,:),zcc(:,:,:)
28 complex(8), allocatable :: zvc(:,:,:),zcv(:,:,:)
29 complex(8), allocatable :: epsi(:,:,:)
30 allocate(igpig(ngkmax,nspnfv))
31 allocate(vgqc(3,ngrf),gqc(ngrf),gclgq(ngrf))
32 allocate(jlgqr(njcmax,nspecies,ngrf))
33 allocate(ylmgq(lmmaxo,ngrf),sfacgq(ngrf,natmtot))
34 allocate(wfmt1(npcmtmax,natmtot,nspinor,nstsv),wfir1(ngtc,nspinor,nstsv))
35 allocate(wfmt2(npcmtmax,natmtot,nspinor,nstsv),wfir2(ngtc,nspinor,nstsv))
36 allocate(zvv(ngrf,nvbse,nvbse),zcc(ngrf,ncbse,ncbse))
37 allocate(epsi(ngrf,ngrf,nwrf))
38 if (bsefull) then
39  allocate(zvc(ngrf,nvbse,ncbse))
40  allocate(zcv(ngrf,ncbse,nvbse))
41 end if
42 ! generate the wavefunctions for all states of k-point ik2
43 call genwfsvp_sp(.false.,.false.,nstsv,[0],ngdgc,igfc,vkl(:,ik2),ngp,igpig, &
44  wfmt2,ngtc,wfir2)
45 ! begin loop over ik1
46 do ik1=1,nkptnr
47 ! generate the wavefunctions for all states of k-point ik1
48  call genwfsvp_sp(.false.,.false.,nstsv,[0],ngdgc,igfc,vkl(:,ik1),ngp,igpig, &
49  wfmt1,ngtc,wfir1)
50 ! determine equivalent q-vector in first Brillouin zone
51  iv(:)=ivk(:,ik1)-ivk(:,ik2)
52  iv(:)=modulo(iv(:),ngridk(:))
53  iq=ivqiq(iv(1),iv(2),iv(3))
54 ! q-vector in lattice and Cartesian coordinates
55  vl(:)=vkl(:,ik1)-vkl(:,ik2)
56  vc(:)=vkc(:,ik1)-vkc(:,ik2)
57 ! generate the G+q-vectors and related functions
58  call gengqf(ngrf,vc,vgqc,gqc,jlgqr,ylmgq,sfacgq)
59 ! generate the regularised Coulomb Green's function in G+q-space
60  call gengclgq(.true.,iq,ngrf,gqc,gclgq)
61 ! symmetrise the Coulomb Green's function
62  gclgq(:)=sqrt(gclgq(:))
63 ! compute the <v|exp(-i(G+q).r)|v'> matrix elements
64  call holdthd(nvbse,nthd)
65 !$OMP PARALLEL DEFAULT(SHARED) &
66 !$OMP PRIVATE(crhomt,crhoir,ist1,ist2,i2) &
67 !$OMP NUM_THREADS(nthd)
68  allocate(crhomt(npcmtmax,natmtot),crhoir(ngtc))
69 !$OMP DO SCHEDULE(DYNAMIC)
70  do i1=1,nvbse
71  ist1=istbse(i1,ik1)
72  do i2=1,nvbse
73  ist2=istbse(i2,ik2)
74  call gencrho(.true.,.true.,ngtc,wfmt2(:,:,:,ist2),wfir2(:,:,ist2), &
75  wfmt1(:,:,:,ist1),wfir1(:,:,ist1),crhomt,crhoir)
76  call zftcf(ngrf,jlgqr,ylmgq,ngrf,sfacgq,crhomt,crhoir,zvv(:,i1,i2))
77  end do
78  end do
79 !$OMP END DO
80  deallocate(crhomt,crhoir)
81 !$OMP END PARALLEL
82  call freethd(nthd)
83 ! compute the <c|exp(-i(G+q).r)|c'> matrix elements
84  call holdthd(ncbse,nthd)
85 !$OMP PARALLEL DEFAULT(SHARED) &
86 !$OMP PRIVATE(crhomt,crhoir,jst1,jst2,j2) &
87 !$OMP NUM_THREADS(nthd)
88  allocate(crhomt(npcmtmax,natmtot),crhoir(ngtc))
89 !$OMP DO SCHEDULE(DYNAMIC)
90  do j1=1,ncbse
91  jst1=jstbse(j1,ik1)
92  do j2=1,ncbse
93  jst2=jstbse(j2,ik2)
94  call gencrho(.true.,.true.,ngtc,wfmt2(:,:,:,jst2),wfir2(:,:,jst2), &
95  wfmt1(:,:,:,jst1),wfir1(:,:,jst1),crhomt,crhoir)
96  call zftcf(ngrf,jlgqr,ylmgq,ngrf,sfacgq,crhomt,crhoir,zcc(:,j1,j2))
97  end do
98  end do
99 !$OMP END DO
100  deallocate(crhomt,crhoir)
101 !$OMP END PARALLEL
102  call freethd(nthd)
103 ! matrix elements for full BSE kernel if required
104  if (bsefull) then
105 ! compute the <v|exp(-i(G+q).r)|c'> matrix elements
106  call holdthd(nvbse,nthd)
107 !$OMP PARALLEL DEFAULT(SHARED) &
108 !$OMP PRIVATE(crhomt,crhoir,ist1,jst2,j2) &
109 !$OMP NUM_THREADS(nthd)
110  allocate(crhomt(npcmtmax,natmtot),crhoir(ngtc))
111 !$OMP DO SCHEDULE(DYNAMIC)
112  do i1=1,nvbse
113  ist1=istbse(i1,ik1)
114  do j2=1,ncbse
115  jst2=jstbse(j2,ik2)
116  call gencrho(.true.,.true.,ngtc,wfmt2(:,:,:,jst2),wfir2(:,:,jst2), &
117  wfmt1(:,:,:,ist1),wfir1(:,:,ist1),crhomt,crhoir)
118  call zftcf(ngrf,jlgqr,ylmgq,ngrf,sfacgq,crhomt,crhoir,zvc(:,i1,j2))
119  end do
120  end do
121 !$OMP END DO
122  deallocate(crhomt,crhoir)
123 !$OMP END PARALLEL
124  call freethd(nthd)
125 ! compute the <c|exp(-i(G+q).r)|v'> matrix elements
126  call holdthd(ncbse,nthd)
127 !$OMP PARALLEL DEFAULT(SHARED) &
128 !$OMP PRIVATE(crhomt,crhoir,jst1,ist2,i2) &
129 !$OMP NUM_THREADS(nthd)
130  allocate(crhomt(npcmtmax,natmtot),crhoir(ngtc))
131 !$OMP DO SCHEDULE(DYNAMIC)
132  do j1=1,ncbse
133  jst1=jstbse(j1,ik1)
134  do i2=1,nvbse
135  ist2=istbse(i2,ik2)
136  call gencrho(.true.,.true.,ngtc,wfmt2(:,:,:,ist2),wfir2(:,:,ist2), &
137  wfmt1(:,:,:,jst1),wfir1(:,:,jst1),crhomt,crhoir)
138  call zftcf(ngrf,jlgqr,ylmgq,ngrf,sfacgq,crhomt,crhoir,zcv(:,j1,i2))
139  end do
140  end do
141 !$OMP END DO
142  deallocate(crhomt,crhoir)
143 !$OMP END PARALLEL
144  call freethd(nthd)
145  end if
146 ! get RPA inverse dielectric function from file
147 ! this is the symmetric version: ϵ⁻¹ = 1 - v¹⸍² χ₀ v¹⸍²
148  call getcfgq('EPSINV.OUT',vl,ngrf,nwrf,epsi)
149  t0=wkptnr*omega
150  do i1=1,nvbse
151  do j1=1,ncbse
152  a1=ijkbse(i1,j1,ik1)
153  do i2=1,nvbse
154  do j2=1,ncbse
155  a2=ijkbse(i2,j2,ik2)
156  z1=0.d0
157  do ig=1,ngrf
158  t1=t0*gclgq(ig)
159  do jg=1,ngrf
160  t2=t1*gclgq(jg)
161  z1=z1+t2*epsi(ig,jg,1)*conjg(zcc(ig,j1,j2))*zvv(jg,i1,i2)
162  end do
163  end do
164  hmlbse(a1,a2)=hmlbse(a1,a2)-z1
165 ! compute off-diagonal blocks if required
166  if (bsefull) then
167  b1=a1+nbbse
168  b2=a2+nbbse
169  hmlbse(b1,b2)=hmlbse(b1,b2)+conjg(z1)
170  z1=0.d0
171  do ig=1,ngrf
172  t1=t0*gclgq(ig)
173  do jg=1,ngrf
174  t2=t1*gclgq(jg)
175  z1=z1+t2*epsi(ig,jg,1)*conjg(zcv(ig,j1,i2))*zvc(jg,i1,j2)
176  end do
177  end do
178  hmlbse(a1,b2)=hmlbse(a1,b2)-z1
179  hmlbse(b1,a2)=hmlbse(b1,a2)+conjg(z1)
180  end if
181 ! end loop over i2 and j2
182  end do
183  end do
184 ! end loop over i1 and j1
185  end do
186  end do
187 ! end loop over ik1
188 end do
189 deallocate(igpig,vgqc,gqc,gclgq,jlgqr)
190 deallocate(ylmgq,sfacgq)
191 deallocate(wfmt1,wfmt2,wfir1,wfir2)
192 deallocate(zvv,zcc,epsi)
193 if (bsefull) deallocate(zvc,zcv)
194 end subroutine
195 
integer nwrf
Definition: modmain.f90:1168
integer npcmtmax
Definition: modmain.f90:216
integer lmmaxo
Definition: modmain.f90:203
integer ngtc
Definition: modmain.f90:392
subroutine genwfsvp_sp(tsh, tgp, nst, idx, ngridg_, igfft_, vpl, ngp, igpig, wfmt, ld, wfir)
Definition: genwfsvp_sp.f90:8
subroutine gengqf(ng, vqpc, vgqc, gqc, jlgqr, ylmgq, sfacgq)
Definition: gengqf.f90:7
integer ngkmax
Definition: modmain.f90:499
real(8) omega
Definition: modmain.f90:20
subroutine gencrho(tsh, tspc, ngt, wfmt1, wfir1, wfmt2, wfir2, crhomt, crhoir)
Definition: gencrho.f90:7
integer, dimension(:,:,:), allocatable ijkbse
Definition: modmain.f90:1199
Definition: modomp.f90:6
integer nbbse
Definition: modmain.f90:1191
integer ngrf
Definition: modmain.f90:1164
integer nkptnr
Definition: modmain.f90:463
subroutine getcfgq(fname, vpl, ng, m, cf)
Definition: getcfgq.f90:7
integer, dimension(:,:), allocatable jstbse
Definition: modmain.f90:1197
real(8), dimension(:,:), allocatable vkc
Definition: modmain.f90:473
pure subroutine gengclgq(treg, iq, ngq, gqc, gclgq)
Definition: gengclgq.f90:7
integer nstsv
Definition: modmain.f90:889
subroutine zftcf(ngp, jlgpr, ylmgp, ld, sfacgp, cfmt, cfir, zfgp)
Definition: zftcf.f90:7
integer, dimension(:), allocatable igfc
Definition: modmain.f90:410
integer, dimension(3) ngridk
Definition: modmain.f90:448
integer nspinor
Definition: modmain.f90:267
integer, dimension(:,:,:), allocatable ivqiq
Definition: modmain.f90:531
real(8), dimension(:,:), allocatable vkl
Definition: modmain.f90:471
integer, dimension(3) ngdgc
Definition: modmain.f90:388
integer nspecies
Definition: modmain.f90:34
subroutine freethd(nthd)
Definition: modomp.f90:106
subroutine holdthd(nloop, nthd)
Definition: modomp.f90:78
integer njcmax
Definition: modmain.f90:1173
complex(8), dimension(:,:), allocatable hmlbse
Definition: modmain.f90:1201
logical bsefull
Definition: modmain.f90:1206
real(8) wkptnr
Definition: modmain.f90:477
subroutine hmldbsek(ik2)
Definition: hmldbsek.f90:7
integer natmtot
Definition: modmain.f90:40
integer nvbse
Definition: modmain.f90:1179
integer ncbse
Definition: modmain.f90:1179
integer, dimension(:,:), allocatable ivk
Definition: modmain.f90:465
integer, dimension(:,:), allocatable istbse
Definition: modmain.f90:1195