The Elk Code
genexpmat.f90
Go to the documentation of this file.
1 
2 ! Copyright (C) 2008 J. K. Dewhurst, S. Sharma and C. Ambrosch-Draxl.
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 genexpmat(vpl,expmt,emat)
7 use modmain
8 implicit none
9 ! arguments
10 real(8), intent(in) :: vpl(3)
11 complex(8), intent(in) :: expmt(npcmtmax,natmtot)
12 complex(8), intent(out) :: emat(nstsv,nstsv)
13 ! local variables
14 integer ist,jst,ispn,i,j,k,l
15 integer is,ia,ias,nrc,nrci
16 integer npc,ngp,ngpq,igp,ifg
17 real(8) vpc(3),vpql(3),vpqc(3),t1
18 complex(8) z1
19 ! allocatable arrays
20 integer, allocatable :: igpig(:),igpqig(:)
21 real(8), allocatable :: vgpl(:,:),vgpc(:,:),gpc(:)
22 real(8), allocatable :: vgpql(:,:),vgpqc(:,:),gpqc(:)
23 complex(8), allocatable :: sfacgp(:,:),sfacgpq(:,:)
24 complex(8), allocatable :: apwalm1(:,:,:,:),apwalm2(:,:,:,:)
25 complex(8), allocatable :: evecfv1(:,:),evecfv2(:,:)
26 complex(8), allocatable :: evecsv1(:,:),evecsv2(:,:)
27 complex(8), allocatable :: wfmt1(:),wfmt2(:,:)
28 complex(8), allocatable :: zfir(:),z(:),em(:,:)
29 ! external functions
30 complex(8), external :: zfmtinp,zdotc
31 ! check if q-vector is zero
32 t1=abs(vecql(1))+abs(vecql(2))+abs(vecql(3))
33 if (t1 < epslat) then
34  emat(:,:)=0.d0
35  do i=1,nstsv
36  emat(i,i)=1.d0
37  end do
38  return
39 end if
40 ! allocate local arrays
41 allocate(igpig(ngkmax),igpqig(ngkmax))
42 allocate(vgpl(3,ngkmax),vgpc(3,ngkmax),gpc(ngkmax))
43 allocate(vgpql(3,ngkmax),vgpqc(3,ngkmax),gpqc(ngkmax))
44 allocate(sfacgp(ngkmax,natmtot),sfacgpq(ngkmax,natmtot))
45 allocate(apwalm1(ngkmax,apwordmax,lmmaxapw,natmtot))
46 allocate(apwalm2(ngkmax,apwordmax,lmmaxapw,natmtot))
47 allocate(evecfv1(nmatmax,nstfv),evecfv2(nmatmax,nstfv))
48 if (tevecsv) then
49  allocate(evecsv1(nstsv,nstsv),evecsv2(nstsv,nstsv))
50 end if
51 allocate(wfmt1(npcmtmax),wfmt2(npcmtmax,nstfv))
52 allocate(zfir(ngtot),z(ngkmax),em(nstfv,nstfv))
53 ! p-vector in Cartesian coordinates
54 call r3mv(bvec,vpl,vpc)
55 ! generate the G+p-vectors
56 call gengkvec(ngvc,ivg,vgc,vpl,vpc,gkmax,ngkmax,ngp,igpig,vgpl,vgpc,gpc)
57 ! generate the structure factors
58 call gensfacgp(ngp,vgpc,ngkmax,sfacgp)
59 ! find the matching coefficients for k-point p
60 call match(ngp,vgpc,gpc,sfacgp,apwalm1)
61 ! get the eigenvectors for k-point p
62 call getevecfv(filext,0,vpl,vgpl,evecfv1)
63 ! p+q-vector in lattice coordinates
64 vpql(:)=vpl(:)+vecql(:)
65 ! p+q-vector in Cartesian coordinates
66 call r3mv(bvec,vpql,vpqc)
67 ! generate the G+p+q-vectors
68 call gengkvec(ngvc,ivg,vgc,vpql,vpqc,gkmax,ngkmax,ngpq,igpqig,vgpql,vgpqc,gpqc)
69 ! generate the structure factors
70 call gensfacgp(ngpq,vgpqc,ngkmax,sfacgpq)
71 ! find the matching coefficients for k-point p+q
72 call match(ngpq,vgpqc,gpqc,sfacgpq,apwalm2)
73 ! get the eigenvectors for k-point p+q
74 call getevecfv(filext,0,vpql,vgpql,evecfv2)
75 ! set the first-variational matrix element array to zero
76 em(:,:)=0.d0
77 !------------------------------------!
78 ! muffin-tin matrix elements !
79 !------------------------------------!
80 do is=1,nspecies
81  nrc=nrcmt(is)
82  nrci=nrcmti(is)
83  npc=npcmt(is)
84  do ia=1,natoms(is)
85  ias=idxas(ia,is)
86  do ist=1,nstfv
87 ! calculate the wavefunction for k-point p+q
88  call wfmtfv(ias,ngpq,apwalm2(:,:,:,ias),evecfv2(:,ist),wfmt1)
89 ! convert from spherical harmonics to spherical coordinates
90  call zbsht(nrc,nrci,wfmt1,wfmt2(:,ist))
91 ! multiply by exp(-iq.r) (conjugate because zfmtinp conjugates first function)
92  wfmt1(1:npc)=conjg(expmt(1:npc,ias))*wfmt2(1:npc,ist)
93 ! convert from spherical coordinates to spherical harmonics
94  call zfsht(nrc,nrci,wfmt1,wfmt2(:,ist))
95  end do
96  do jst=1,nstfv
97 ! calculate the wavefunction for k-point p
98  call wfmtfv(ias,ngp,apwalm1(:,:,:,ias),evecfv1(:,jst),wfmt1)
99  do ist=1,nstfv
100  em(ist,jst)=em(ist,jst)+zfmtinp(nrc,nrci,wr2cmt(:,is),wfmt2(:,ist), &
101  wfmt1)
102  end do
103  end do
104 ! end loops over atoms and species
105  end do
106 end do
107 !--------------------------------------!
108 ! interstitial matrix elements !
109 !--------------------------------------!
110 ! compute interstitial wavefunctions for k-point p
111 do jst=1,nstfv
112  zfir(:)=0.d0
113  do igp=1,ngp
114  ifg=igfft(igpig(igp))
115  zfir(ifg)=evecfv1(igp,jst)
116  end do
117 ! Fourier transform wavefunction to real-space
118  call zfftifc(3,ngridg,1,zfir)
119 ! multiply with the characteristic function
120  zfir(:)=zfir(:)*cfunir(:)
121 ! Fourier transform back to G-space
122  call zfftifc(3,ngridg,-1,zfir)
123 ! store as wavefunction with G+p+q index
124  do igp=1,ngpq
125  ifg=igfft(igpqig(igp))
126  z(igp)=zfir(ifg)
127  end do
128 ! add to the first-variational matrix elements
129  do ist=1,nstfv
130  em(ist,jst)=em(ist,jst)+zdotc(ngpq,evecfv2(:,ist),1,z,1)
131  end do
132 end do
133 !-------------------------------------------!
134 ! second-variational matrix elements !
135 !-------------------------------------------!
136 if (tevecsv) then
137 ! get the second-variational eigenvectors
138  call getevecsv(filext,0,vpl,evecsv1)
139  call getevecsv(filext,0,vpql,evecsv2)
140  do i=1,nstsv
141  do j=1,nstsv
142  z1=0.d0
143  k=0
144  do ispn=1,nspinor
145  do ist=1,nstfv
146  k=k+1
147  l=(ispn-1)*nstfv
148  do jst=1,nstfv
149  l=l+1
150  z1=z1+em(ist,jst)*conjg(evecsv2(k,i))*evecsv1(l,j)
151  end do
152  end do
153  end do
154  emat(i,j)=z1
155  end do
156  end do
157 else
158  emat(:,:)=em(:,:)
159 end if
160 deallocate(igpig,igpqig,vgpl,vgpc,gpc)
161 deallocate(vgpql,vgpqc,gpqc,sfacgp,sfacgpq)
162 deallocate(apwalm1,apwalm2,evecfv1,evecfv2)
163 if (tevecsv) deallocate(evecsv1,evecsv2)
164 deallocate(wfmt1,wfmt2,zfir,z,em)
165 end subroutine
166 
integer nmatmax
Definition: modmain.f90:853
integer, dimension(maxspecies) npcmt
Definition: modmain.f90:214
subroutine getevecsv(fext, ikp, vpl, evecsv)
Definition: getevecsv.f90:7
subroutine genexpmat(vpl, expmt, emat)
Definition: genexpmat.f90:7
integer, dimension(3) ngridg
Definition: modmain.f90:386
character(256) filext
Definition: modmain.f90:1301
pure subroutine gensfacgp(ngp, vgpc, ld, sfacgp)
Definition: gensfacgp.f90:10
integer ngtot
Definition: modmain.f90:390
integer lmmaxapw
Definition: modmain.f90:199
integer, dimension(maxatoms, maxspecies) idxas
Definition: modmain.f90:42
integer ngkmax
Definition: modmain.f90:499
subroutine getevecfv(fext, ikp, vpl, vgpl, evecfv)
Definition: getevecfv.f90:10
logical tevecsv
Definition: modmain.f90:923
subroutine match(ngp, vgpc, gpc, sfacgp, apwalm)
Definition: match.f90:10
subroutine zfsht(nr, nri, zfmt1, zfmt2)
Definition: zfsht.f90:10
real(8), dimension(3) vecql
Definition: modmain.f90:1104
integer ngvc
Definition: modmain.f90:398
real(8), dimension(:,:), allocatable vgc
Definition: modmain.f90:420
subroutine zfftifc(nd, n, sgn, z)
Definition: zfftifc_fftw.f90:7
integer, dimension(:), allocatable igfft
Definition: modmain.f90:406
real(8), dimension(:), allocatable cfunir
Definition: modmain.f90:436
integer nspinor
Definition: modmain.f90:267
real(8), dimension(3, 3) bvec
Definition: modmain.f90:16
integer, dimension(:,:), allocatable ivg
Definition: modmain.f90:400
subroutine wfmtfv(ias, ngp, apwalm, evecfv, wfmt)
Definition: wfmtfv.f90:10
pure subroutine gengkvec(ngv, ivg, vgc, vkl, vkc, gkmax, ngkmax, ngk, igkig, vgkl, vgkc, gkc)
Definition: gengkvec.f90:11
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
subroutine zbsht(nr, nri, zfmt1, zfmt2)
Definition: zbsht.f90:10
integer nspecies
Definition: modmain.f90:34
real(8) gkmax
Definition: modmain.f90:495
integer, dimension(maxspecies) nrcmt
Definition: modmain.f90:173
integer, dimension(maxspecies) nrcmti
Definition: modmain.f90:211
pure subroutine r3mv(a, x, y)
Definition: r3mv.f90:10
integer nstfv
Definition: modmain.f90:887