The Elk Code
genspchi0.f90
Go to the documentation of this file.
1 
2 ! Copyright (C) 2012 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 !BOP
7 ! !ROUTINE: genspchi0
8 ! !INTERFACE:
9 subroutine genspchi0(ik,lock,vqpl,jlgqr,ylmgq,sfacgq,chi0)
10 ! !USES:
11 use modmain
12 use modomp
13 ! !INPUT/OUTPUT PARAMETERS:
14 ! ik : k-point from non-reduced set (in,integer)
15 ! lock : OpenMP locks for frequency index of chi0 (in,integer(nwrf))
16 ! vqpl : input q-point in lattice coordinates (in,real(3))
17 ! jlgqr : spherical Bessel functions evaluated on the coarse radial mesh for
18 ! all species and G+q-vectors (in,real(njcmax,nspecies,ngrf))
19 ! ylmgq : spherical harmonics of the G+q-vectors (in,complex(lmmaxo,ngrf))
20 ! sfacgq : structure factors of G+q-vectors (in,complex(ngrf,natmtot))
21 ! chi0 : spin-dependent Kohn-Sham response function in G-space
22 ! (out,complex(ngrf,4,ngrf,4,nwrf))
23 ! !DESCRIPTION:
24 ! Computes the spin-dependent Kohn-Sham response function:
25 ! \begin{align*}
26 ! \chi_{\alpha\beta,\alpha'\beta'}({\bf r},{\bf r}',\omega)
27 ! & \equiv\frac{\delta\rho_{\alpha\beta}({\bf r},\omega)}
28 ! {\delta v_{\alpha'\beta'}({\bf r}',\omega)} \\
29 ! & =\frac{1}{N_k}\sum_{i{\bf k},j{\bf k}'}(f_{i{\bf k}}-f_{j{\bf k}'})
30 ! \frac{\langle i{\bf k}|\hat{\rho}_{\beta\alpha}({\bf r})|j{\bf k}'\rangle
31 ! \langle j{\bf k}'|\hat{\rho}_{\alpha'\beta'}({\bf r}')|i{\bf k}\rangle}
32 ! {w+(\varepsilon_{i{\bf k}}-\varepsilon_{j{\bf k}'})+i\eta},
33 ! \end{align*}
34 ! where $\alpha$ and $\beta$ are spin-coordinates, $N_k$ is the number of
35 ! $k$-points, $f_{i{\bf k}}$ are the occupation numbers, $v$ is the Kohn-Sham
36 ! potential and $\hat{\rho}$ is the spin-density operator. With translational
37 ! symmetry in mind, we adopt the following convention for its Fourier
38 ! transform:
39 ! $$ \chi_{\alpha\beta,\alpha'\beta'}({\bf G},{\bf G}',{\bf q},\omega)=
40 ! \frac{1}{\Omega}\int d^3r\,d^3r'\,e^{-i({\bf G}+{\bf q})\cdot{\bf r}}
41 ! e^{i({\bf G}'+{\bf q})\cdot{\bf r}'}
42 ! \chi_{\alpha\beta,\alpha'\beta'}({\bf r},{\bf r}',\omega). $$
43 ! Let
44 ! $$ Z_{i{\bf k},j{\bf k}+{\bf q}}^{\alpha\beta}({\bf G})\equiv
45 ! \int d^3r\,e^{i({\bf G}+{\bf q})\cdot{\bf r}}
46 ! \varphi_{j{\bf k}+{\bf q},\alpha}^*({\bf r})
47 ! \varphi_{i{\bf k},\beta}({\bf r}) $$
48 ! then the response function in $G$-space can be written
49 ! $$ \chi_{\alpha\beta,\alpha'\beta'}({\bf G},{\bf G}',{\bf q},\omega)=
50 ! \frac{1}{N_k\Omega}\sum_{i{\bf k},j{\bf k}+{\bf q}}
51 ! (f_{i{\bf k}}-f_{j{\bf k}})
52 ! \frac{\left[Z_{i{\bf k},j{\bf k}+{\bf q}}^{\alpha\beta}({\bf G})\right]^*
53 ! Z_{i{\bf k},j{\bf k}+{\bf q}}^{\alpha'\beta'}({\bf G}')}
54 ! {w+(\varepsilon_{i{\bf k}}-\varepsilon_{j{\bf k}+{\bf q}})+i\eta}. $$
55 !
56 ! !REVISION HISTORY:
57 ! Created March 2012 (SS and JKD)
58 !EOP
59 !BOC
60 implicit none
61 ! local variables
62 integer, intent(in) :: ik
63 integer(omp_lock_kind), intent(inout) :: lock(nwrf)
64 real(8), intent(in) :: vqpl(3),jlgqr(njcmax,nspecies,ngrf)
65 complex(8), intent(in) :: ylmgq(lmmaxo,ngrf),sfacgq(ngrf,natmtot)
66 complex(8), intent(inout) :: chi0(ngrf,4,ngrf,4,nwrf)
67 ! local variables
68 logical tz(4)
69 integer isym,jk,jkq,iw
70 integer nst,nstq,ist,jst,kst,lst
71 integer ig,jg,a,b,i,j,nthd
72 real(8) vkql(3),ei,ej,eij,t1
73 complex(8) z1
74 ! automatic arrays
75 integer idx(nstsv),idxq(nstsv)
76 integer ngp(nspnfv),ngpq(nspnfv)
77 ! allocatable arrays
78 integer, allocatable :: igpig(:,:),igpqig(:,:)
79 complex(4), allocatable :: wfmt(:,:,:,:),wfir(:,:,:)
80 complex(4), allocatable :: wfmtq(:,:,:,:),wfirq(:,:,:)
81 complex(4), allocatable :: crhomt(:,:),crhoir(:)
82 complex(8), allocatable :: zrhoig(:,:),zw(:),c(:,:,:,:)
83 if (.not.spinpol) then
84  write(*,*)
85  write(*,'("Error(genspchi0): spin-unpolarised calculation")')
86  write(*,*)
87  stop
88 end if
89 ! k+q-vector in lattice coordinates
90 vkql(1:3)=vkl(1:3,ik)+vqpl(1:3)
91 ! equivalent reduced k-points for k and k+q
92 jk=ivkik(ivk(1,ik),ivk(2,ik),ivk(3,ik))
93 call findkpt(vkql,isym,jkq)
94 ! count and index states at k and k+q in energy window
95 nst=0
96 do ist=1,nstsv
97  if (abs(evalsv(ist,jk)-efermi) > emaxrf) cycle
98  nst=nst+1
99  idx(nst)=ist
100 end do
101 nstq=0
102 do ist=1,nstsv
103  if (abs(evalsv(ist,jkq)-efermi) > emaxrf) cycle
104  nstq=nstq+1
105  idxq(nstq)=ist
106 end do
107 ! generate the wavefunctions for all states at k and k+q in energy window
108 allocate(igpig(ngkmax,nspnfv))
109 allocate(wfmt(npcmtmax,natmtot,nspinor,nst),wfir(ngtc,nspinor,nst))
110 call genwfsvp_sp(.false.,.false.,nst,idx,ngdgc,igfc,vkl(:,ik),ngp,igpig,wfmt, &
111  ngtc,wfir)
112 deallocate(igpig)
113 allocate(igpqig(ngkmax,nspnfv))
114 allocate(wfmtq(npcmtmax,natmtot,nspinor,nstq),wfirq(ngtc,nspinor,nstq))
115 call genwfsvp_sp(.false.,.false.,nstq,idxq,ngdgc,igfc,vkql,ngpq,igpqig,wfmtq, &
116  ngtc,wfirq)
117 deallocate(igpqig)
118 call holdthd(nst,nthd)
119 !$OMP PARALLEL DEFAULT(SHARED) &
120 !$OMP PRIVATE(crhomt,crhoir,zrhoig,zw,c) &
121 !$OMP PRIVATE(jst,kst,lst,ei,ej,eij,t1) &
122 !$OMP PRIVATE(iw,i,j,a,b,tz,ig,jg,z1) &
123 !$OMP NUM_THREADS(nthd)
124 allocate(crhomt(npcmtmax,natmtot),crhoir(ngtc))
125 allocate(zrhoig(ngrf,4),zw(nwrf),c(ngrf,4,ngrf,4))
126 !$OMP DO SCHEDULE(DYNAMIC)
127 do ist=1,nst
128  kst=idx(ist)
129  ei=evalsv(kst,jk)
130  do jst=1,nstq
131  lst=idxq(jst)
132  t1=wkptnr*omega*(occsv(kst,jk)-occsv(lst,jkq))
133  if (abs(t1) < 1.d-8) cycle
134  ej=evalsv(lst,jkq)
135  eij=ei-ej
136 ! frequency-dependent part in response function formula for all frequencies
137  do iw=1,nwrf
138  zw(iw)=t1/(eij+wrf(iw))
139  end do
140 ! compute the complex density in G+q-space
141  i=0
142  do a=1,2
143  do b=1,2
144  i=i+1
145 ! find which contributions are zero for collinear case
146  tz(i)=.false.
147  if (.not.ncmag) then
148  if (((a == 1).and.(kst > nstfv)).or. &
149  ((a == 2).and.(kst <= nstfv)).or. &
150  ((b == 1).and.(lst > nstfv)).or. &
151  ((b == 2).and.(lst <= nstfv))) then
152  tz(i)=.true.
153  cycle
154  end if
155  end if
156  call gencrho(.true.,.false.,ngtc,wfmt(:,:,a,ist),wfir(:,a,ist), &
157  wfmtq(:,:,b,jst),wfirq(:,b,jst),crhomt,crhoir)
158  call zftcf(ngrf,jlgqr,ylmgq,ngrf,sfacgq,crhomt,crhoir,zrhoig(:,i))
159  end do
160  end do
161 ! Hermitian part of matrix
162  do j=1,4
163  if (tz(j)) cycle
164  do jg=1,ngrf
165  z1=conjg(zrhoig(jg,j))
166  do i=1,4
167  if (tz(i)) cycle
168  do ig=1,ngrf
169  c(ig,i,jg,j)=zrhoig(ig,i)*z1
170  end do
171  end do
172  end do
173  end do
174  do iw=1,nwrf
175  z1=zw(iw)
176  call omp_set_lock(lock(iw))
177  do j=1,4
178  if (tz(j)) cycle
179  do jg=1,ngrf
180  do i=1,4
181  if (tz(i)) cycle
182  call zaxpy(ngrf,z1,c(:,i,jg,j),1,chi0(:,i,jg,j,iw),1)
183  end do
184  end do
185  end do
186  call omp_unset_lock(lock(iw))
187  end do
188 ! end loop over jst
189  end do
190 ! end loop over ist
191 end do
192 !$OMP END DO
193 deallocate(crhomt,crhoir,zrhoig,zw,c)
194 !$OMP END PARALLEL
195 call freethd(nthd)
196 deallocate(wfmt,wfmtq,wfir,wfirq)
197 end subroutine
198 !EOC
199 
real(8) efermi
Definition: modmain.f90:907
integer npcmtmax
Definition: modmain.f90:216
real(8), dimension(:,:), allocatable evalsv
Definition: modmain.f90:921
integer ngtc
Definition: modmain.f90:392
logical spinpol
Definition: modmain.f90:228
subroutine genwfsvp_sp(tsh, tgp, nst, idx, ngridg_, igfft_, vpl, ngp, igpig, wfmt, ld, wfir)
Definition: genwfsvp_sp.f90:8
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
Definition: modomp.f90:6
complex(8), dimension(:), allocatable wrf
Definition: modmain.f90:1170
integer, dimension(:,:,:), allocatable ivkik
Definition: modmain.f90:467
subroutine genspchi0(ik, lock, vqpl, jlgqr, ylmgq, sfacgq, chi0)
Definition: genspchi0.f90:10
real(8) emaxrf
Definition: modmain.f90:1162
subroutine zftcf(ngp, jlgpr, ylmgp, ld, sfacgp, cfmt, cfir, zfgp)
Definition: zftcf.f90:7
integer, dimension(:), allocatable igfc
Definition: modmain.f90:410
real(8), dimension(:,:), allocatable occsv
Definition: modmain.f90:905
integer nspinor
Definition: modmain.f90:267
real(8), dimension(:,:), allocatable vkl
Definition: modmain.f90:471
integer, dimension(3) ngdgc
Definition: modmain.f90:388
subroutine freethd(nthd)
Definition: modomp.f90:106
subroutine holdthd(nloop, nthd)
Definition: modomp.f90:78
real(8) wkptnr
Definition: modmain.f90:477
subroutine findkpt(vpl, isym, ik)
Definition: findkpt.f90:7
logical ncmag
Definition: modmain.f90:240
integer nstfv
Definition: modmain.f90:887
integer, dimension(:,:), allocatable ivk
Definition: modmain.f90:465