The Elk Code
gradwf2.f90
Go to the documentation of this file.
1 
2 ! Copyright (C) 2002-2005 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 gradwf2(ik,gwf2mt,gwf2ir)
7 use modmain
8 implicit none
9 ! arguments
10 integer, intent(in) :: ik
11 real(8), intent(inout) :: gwf2mt(npmtmax,natmtot),gwf2ir(ngtot)
12 ! local variables
13 integer ispn,jspn,nst,ist,jst
14 integer is,ia,ias,nrc,nrci,npc
15 integer igk,ifg,i
16 real(8) wo
17 complex(8) z1
18 ! automatic arrays
19 integer idx(nstsv)
20 complex(8) gwfmt(npcmtmax,3),zfmt(npcmtmax)
21 ! allocatable arrays
22 complex(8), allocatable :: apwalm(:,:,:,:,:),evecfv(:,:),evecsv(:,:)
23 complex(8), allocatable :: wfmt(:,:,:,:),wfgk(:,:,:),zfft(:)
24 ! find the matching coefficients
25 allocate(apwalm(ngkmax,apwordmax,lmmaxapw,natmtot,nspnfv))
26 allocate(evecfv(nmatmax,nstfv),evecsv(nstsv,nstsv))
27 do ispn=1,nspnfv
28  call match(ngk(ispn,ik),vgkc(:,:,ispn,ik),gkc(:,ispn,ik),sfacgk(:,:,ispn,ik),&
29  apwalm(:,:,:,:,ispn))
30 end do
31 ! get the eigenvectors from file
32 call getevecfv(filext,ik,vkl(:,ik),vgkl(:,:,:,ik),evecfv)
33 call getevecsv(filext,ik,vkl(:,ik),evecsv)
34 ! count and index the occupied states
35 nst=0
36 do ist=1,nstsv
37  if (abs(occsv(ist,ik)) < epsocc) cycle
38  nst=nst+1
39  idx(nst)=ist
40 end do
41 ! calculate the second-variational wavefunctions for occupied states
42 allocate(wfmt(npcmtmax,natmtot,nspinor,nst),wfgk(ngkmax,nspinor,nst))
43 call genwfsv(.true.,.true.,nst,idx,ngdgc,igfc,ngk(:,ik),igkig(:,:,ik),apwalm, &
44  evecfv,evecsv,wfmt,ngkmax,wfgk)
45 deallocate(apwalm,evecfv,evecsv)
46 !-------------------------!
47 ! muffin-tin part !
48 !-------------------------!
49 do ist=1,nst
50  jst=idx(ist)
51  wo=wkpt(ik)*occsv(jst,ik)
52  do ispn=1,nspinor
53  do is=1,nspecies
54  nrc=nrcmt(is)
55  nrci=nrcmti(is)
56  npc=npcmt(is)
57  do ia=1,natoms(is)
58  ias=idxas(ia,is)
59 ! compute the gradient of the wavefunction
60  call gradzfmt(nrc,nrci,rlcmt(:,-1,is),wcrcmt(:,:,is), &
61  wfmt(:,ias,ispn,ist),npcmtmax,gwfmt)
62  do i=1,3
63 ! convert gradient from spherical harmonics to spherical coordinates
64  call zbsht(nrc,nrci,gwfmt(:,i),zfmt)
65 ! add to total
66  gwf2mt(1:npc,ias)=gwf2mt(1:npc,ias) &
67  +wo*(dble(zfmt(1:npc))**2+aimag(zfmt(1:npc))**2)
68  end do
69  end do
70  end do
71  end do
72 end do
73 deallocate(wfmt)
74 !---------------------------!
75 ! interstitial part !
76 !---------------------------!
77 allocate(zfft(ngtc))
78 do ist=1,nst
79  jst=idx(ist)
80  wo=wkpt(ik)*occsv(jst,ik)/omega
81  do ispn=1,nspinor
82  jspn=jspnfv(ispn)
83 ! compute gradient of wavefunction
84  do i=1,3
85  zfft(1:ngtc)=0.d0
86  do igk=1,ngk(jspn,ik)
87  ifg=igfc(igkig(igk,jspn,ik))
88  z1=wfgk(igk,ispn,ist)
89  zfft(ifg)=vgkc(i,igk,jspn,ik)*cmplx(-z1%im,z1%re,8)
90  end do
91  call zfftifc(3,ngdgc,1,zfft)
92  gwf2ir(1:ngtc)=gwf2ir(1:ngtc) &
93  +wo*(dble(zfft(1:ngtc))**2+aimag(zfft(1:ngtc))**2)
94  end do
95  end do
96 end do
97 deallocate(wfgk,zfft)
98 end subroutine
99 
integer nmatmax
Definition: modmain.f90:853
subroutine gradwf2(ik, gwf2mt, gwf2ir)
Definition: gradwf2.f90:7
integer, dimension(maxspecies) npcmt
Definition: modmain.f90:214
subroutine getevecsv(fext, ikp, vpl, evecsv)
Definition: getevecsv.f90:7
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 ngtc
Definition: modmain.f90:392
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
real(8) omega
Definition: modmain.f90:20
subroutine match(ngp, vgpc, gpc, sfacgp, apwalm)
Definition: match.f90:10
subroutine gradzfmt(nr, nri, ri, wcr, zfmt, ld, gzfmt)
Definition: gradzfmt.f90:10
real(8) epsocc
Definition: modmain.f90:903
complex(8), dimension(:,:,:,:), allocatable sfacgk
Definition: modmain.f90:509
integer, dimension(:,:), allocatable ngk
Definition: modmain.f90:497
subroutine zfftifc(nd, n, sgn, z)
Definition: zfftifc_fftw.f90:7
real(8), dimension(:), allocatable wkpt
Definition: modmain.f90:475
real(8), dimension(:,:,:,:), allocatable vgkl
Definition: modmain.f90:503
integer, dimension(:), allocatable igfc
Definition: modmain.f90:410
real(8), dimension(:,:,:), allocatable rlcmt
Definition: modmain.f90:181
real(8), dimension(:,:), allocatable occsv
Definition: modmain.f90:905
integer nspinor
Definition: modmain.f90:267
real(8), dimension(:,:,:,:), allocatable vgkc
Definition: modmain.f90:505
real(8), dimension(:,:), allocatable vkl
Definition: modmain.f90:471
integer, dimension(maxspecies) natoms
Definition: modmain.f90:36
integer apwordmax
Definition: modmain.f90:760
real(8), dimension(:,:,:), allocatable wcrcmt
Definition: modmain.f90:193
subroutine zbsht(nr, nri, zfmt1, zfmt2)
Definition: zbsht.f90:10
real(8), dimension(:,:,:), allocatable gkc
Definition: modmain.f90:507
integer, dimension(3) ngdgc
Definition: modmain.f90:388
integer nspecies
Definition: modmain.f90:34
integer, dimension(maxspecies) nrcmt
Definition: modmain.f90:173
integer, dimension(maxspecies) nrcmti
Definition: modmain.f90:211
integer, dimension(:,:,:), allocatable igkig
Definition: modmain.f90:501
integer nstfv
Definition: modmain.f90:887
integer, dimension(2) jspnfv
Definition: modmain.f90:291
integer nspnfv
Definition: modmain.f90:289