The Elk Code
genwfpw.f90
Go to the documentation of this file.
1 
2 ! Copyright (C) 2012 J. K. Dewhurst, S. Sharma 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 genwfpw(vpl,ngp,igpig,vgpl,vgpc,gpc,sfacgp,nhp,vhpc,hpc,sfachp,wfpw)
7 use modmain
8 use modpw
9 implicit none
10 ! arguments
11 real(8), intent(in) :: vpl(3)
12 integer, intent(in) :: ngp(nspnfv),igpig(ngkmax,nspnfv)
13 real(8), intent(in) :: vgpl(3,ngkmax,nspnfv),vgpc(3,ngkmax,nspnfv)
14 real(8), intent(in) :: gpc(ngkmax,nspnfv)
15 complex(8), intent(in) :: sfacgp(ngkmax,natmtot,nspnfv)
16 integer, intent(in) :: nhp(nspnfv)
17 real(8), intent(in) :: vhpc(3,nhkmax,nspnfv),hpc(nhkmax,nspnfv)
18 complex(8), intent(in) :: sfachp(nhkmax,natmtot,nspnfv)
19 complex(8), intent(out) :: wfpw(nhkmax,nspinor,nstsv)
20 ! local variables
21 integer ispn0,ispn1,ispn,jspn
22 integer ist,is,ia,ias,igp,ihp
23 integer nrc,nrci,irco,irc
24 integer l,lm,n,i
25 real(8) v1,v2,v3,t0,t1
26 complex(8) zsm,z1,z2,z3
27 ! automatic arrays
28 real(8) jl(0:lmaxo,nrcmtmax)
29 complex(8) ylm(lmmaxo)
30 ! allocatable arrays
31 complex(8), allocatable :: apwalm(:,:,:,:,:),evecfv(:,:,:),evecsv(:,:)
32 complex(8), allocatable :: wfmt(:,:,:,:),wfgp(:,:,:)
33 allocate(apwalm(ngkmax,apwordmax,lmmaxapw,natmtot,nspnfv))
34 allocate(evecfv(nmatmax,nstfv,nspnfv),evecsv(nstsv,nstsv))
35 allocate(wfmt(npcmtmax,natmtot,nspinor,nstsv))
36 allocate(wfgp(ngkmax,nspinor,nstsv))
37 ! get the eigenvectors from file
38 call getevecfv(filext,0,vpl,vgpl,evecfv)
39 call getevecsv(filext,0,vpl,evecsv)
40 ! find the matching coefficients
41 do ispn=1,nspnfv
42  call match(ngp(ispn),vgpc(:,:,ispn),gpc(:,ispn),sfacgp(:,:,ispn), &
43  apwalm(:,:,:,:,ispn))
44 end do
45 ! calculate the second-variational wavefunctions for all states
46 call genwfsv(.true.,.true.,nstsv,[0],ngridg,igfft,ngp,igpig,apwalm,evecfv, &
47  evecsv,wfmt,ngkmax,wfgp)
48 deallocate(apwalm,evecfv,evecsv)
49 ! zero the plane wave coefficients
50 wfpw(:,:,:)=0.d0
51 !---------------------------!
52 ! interstitial part !
53 !---------------------------!
54 do jspn=1,nspnfv
55  if (spinsprl) then
56  ispn0=jspn; ispn1=jspn
57  else
58  ispn0=1; ispn1=nspinor
59  end if
60  i=1
61  do ihp=1,nhp(jspn)
62  v1=vhpc(1,ihp,jspn); v2=vhpc(2,ihp,jspn); v3=vhpc(3,ihp,jspn)
63  do igp=i,ngp(jspn)
64  t1=abs(v1-vgpc(1,igp,jspn)) &
65  +abs(v2-vgpc(2,igp,jspn)) &
66  +abs(v3-vgpc(3,igp,jspn))
67  if (t1 < epslat) then
68  wfpw(ihp,ispn0:ispn1,:)=wfgp(igp,ispn0:ispn1,:)
69  if (igp == i) i=i+1
70  exit
71  end if
72  end do
73  end do
74 end do
75 !-------------------------!
76 ! muffin-tin part !
77 !-------------------------!
78 t0=1.d0/sqrt(omega)
79 ! remove continuation of interstitial function into muffin-tin
80 do jspn=1,nspnfv
81  if (spinsprl) then
82  ispn0=jspn; ispn1=jspn
83  else
84  ispn0=1; ispn1=nspinor
85  end if
86 ! loop over G+p-vectors
87  do igp=1,ngp(jspn)
88 ! generate the conjugate spherical harmonics 4π iˡ Yₗₘ(G+p)*
89  call genylmv(.true.,lmaxo,vgpc(:,igp,jspn),ylm)
90  ylm(:)=conjg(ylm(:))
91  do is=1,nspecies
92  nrc=nrcmt(is)
93  nrci=nrcmti(is)
94  irco=nrci+1
95 ! generate spherical Bessel functions
96  do irc=1,nrci
97  t1=gpc(igp,jspn)*rcmt(irc,is)
98  call sbessel(lmaxi,t1,jl(:,irc))
99  end do
100  do irc=irco,nrc
101  t1=gpc(igp,jspn)*rcmt(irc,is)
102  call sbessel(lmaxo,t1,jl(:,irc))
103  end do
104 ! loop over atoms
105  do ia=1,natoms(is)
106  ias=idxas(ia,is)
107  z1=t0*sfacgp(igp,ias,jspn)
108  do ist=1,nstsv
109  do ispn=ispn0,ispn1
110  z2=z1*wfgp(igp,ispn,ist)
111  i=1
112  do irc=1,nrci
113  do l=0,lmaxi
114  n=2*l
115  lm=l**2+1
116  z3=jl(l,irc)*z2
117  wfmt(i:i+n,ias,ispn,ist)=wfmt(i:i+n,ias,ispn,ist) &
118  -z3*ylm(lm:lm+n)
119  i=i+n+1
120  end do
121  end do
122  do irc=irco,nrc
123  do l=0,lmaxo
124  n=2*l
125  lm=l**2+1
126  z3=jl(l,irc)*z2
127  wfmt(i:i+n,ias,ispn,ist)=wfmt(i:i+n,ias,ispn,ist) &
128  -z3*ylm(lm:lm+n)
129  i=i+n+1
130  end do
131  end do
132  end do
133  end do
134  end do
135  end do
136  end do
137 end do
138 ! Fourier transform the muffin-tin wavefunctions
139 do jspn=1,nspnfv
140  if (spinsprl) then
141  ispn0=jspn; ispn1=jspn
142  else
143  ispn0=1; ispn1=nspinor
144  end if
145 ! loop over H+p-vectors
146  do ihp=1,nhp(jspn)
147 ! generate the spherical harmonics 4π (-i)ˡ Yₗₘ(H+p)
148  call genylmv(.true.,lmaxo,vhpc(:,ihp,jspn),ylm)
149  do is=1,nspecies
150  nrc=nrcmt(is)
151  nrci=nrcmti(is)
152  irco=nrci+1
153 ! generate spherical Bessel functions
154  do irc=1,nrci
155  t1=hpc(ihp,jspn)*rcmt(irc,is)
156  call sbessel(lmaxi,t1,jl(:,irc))
157  end do
158  do irc=irco,nrc
159  t1=hpc(ihp,jspn)*rcmt(irc,is)
160  call sbessel(lmaxo,t1,jl(:,irc))
161  end do
162  do ia=1,natoms(is)
163  ias=idxas(ia,is)
164 ! conjugate structure factor
165  z1=t0*conjg(sfachp(ihp,ias,jspn))
166 ! loop over states
167  do ist=1,nstsv
168  do ispn=ispn0,ispn1
169  zsm=0.d0
170  i=1
171  do irc=1,nrci
172  z2=jl(0,irc)*wfmt(i,ias,ispn,ist)*ylm(1)
173  i=i+1
174  do l=1,lmaxi
175  n=2*l
176  lm=l**2+1
177  z2=z2+jl(l,irc)*sum(wfmt(i:i+n,ias,ispn,ist)*ylm(lm:lm+n))
178  i=i+n+1
179  end do
180  zsm=zsm+wr2cmt(irc,is)*z2
181  end do
182  do irc=irco,nrc
183  z2=jl(0,irc)*wfmt(i,ias,ispn,ist)*ylm(1)
184  i=i+1
185  do l=1,lmaxo
186  n=2*l
187  lm=l**2+1
188  z2=z2+jl(l,irc)*sum(wfmt(i:i+n,ias,ispn,ist)*ylm(lm:lm+n))
189  i=i+n+1
190  end do
191  zsm=zsm+wr2cmt(irc,is)*z2
192  end do
193 ! add to the H+p wavefunction
194  wfpw(ihp,ispn,ist)=wfpw(ihp,ispn,ist)+z1*zsm
195  end do
196  end do
197  end do
198  end do
199  end do
200 end do
201 deallocate(wfmt,wfgp)
202 end subroutine
203 
integer nmatmax
Definition: modmain.f90:853
real(8), dimension(:,:), allocatable rcmt
Definition: modmain.f90:177
subroutine sbessel(lmax, x, jl)
Definition: sbessel.f90:10
subroutine getevecsv(fext, ikp, vpl, evecsv)
Definition: getevecsv.f90:7
integer npcmtmax
Definition: modmain.f90:216
integer, dimension(3) ngridg
Definition: modmain.f90:386
character(256) filext
Definition: modmain.f90:1301
subroutine genwfsv(tsh, tgp, nst, idx, ngridg_, igfft_, ngp, igpig, apwalm, evecfv, evecsv, wfmt, ld, wfir)
Definition: genwfsv.f90:11
integer lmmaxapw
Definition: modmain.f90:199
integer, dimension(maxatoms, maxspecies) idxas
Definition: modmain.f90:42
subroutine getevecfv(fext, ikp, vpl, vgpl, evecfv)
Definition: getevecfv.f90:10
real(8) omega
Definition: modmain.f90:20
subroutine match(ngp, vgpc, gpc, sfacgp, apwalm)
Definition: match.f90:10
logical spinsprl
Definition: modmain.f90:283
pure subroutine genylmv(t4pil, lmax, v, ylm)
Definition: genylmv.f90:10
integer, dimension(:), allocatable igfft
Definition: modmain.f90:406
subroutine genwfpw(vpl, ngp, igpig, vgpl, vgpc, gpc, sfacgp, nhp, vhpc, hpc, sfachp, wfpw)
Definition: genwfpw.f90:7
integer, dimension(maxspecies) natoms
Definition: modmain.f90:36
integer apwordmax
Definition: modmain.f90:760
real(8), dimension(:,:), allocatable wr2cmt
Definition: modmain.f90:189
real(8) epslat
Definition: modmain.f90:24
Definition: modpw.f90:6
integer nspecies
Definition: modmain.f90:34
integer, dimension(maxspecies) nrcmt
Definition: modmain.f90:173
integer, dimension(maxspecies) nrcmti
Definition: modmain.f90:211
integer nstfv
Definition: modmain.f90:887
integer lmaxi
Definition: modmain.f90:205