The Elk Code
forcek.f90
Go to the documentation of this file.
1 
2 ! Copyright (C) 2002-2006 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 !BOP
7 ! !ROUTINE: forcek
8 ! !INTERFACE:
9 subroutine forcek(ik,forceibs)
10 ! !USES:
11 use modmain
12 use modomp
13 ! !INPUT/OUTPUT PARAMETERS:
14 ! ik : reduced k-point number (in,integer)
15 ! forceibs : IBS force (inout,real(3,natmtot))
16 ! !DESCRIPTION:
17 ! Computes the {\bf k}-dependent contribution to the incomplete basis set
18 ! (IBS) force. See the calling routine {\tt force} for a full description.
19 !
20 ! !REVISION HISTORY:
21 ! Created June 2006 (JKD)
22 ! Updated for spin-spiral case, May 2007 (Francesco Cricchio and JKD)
23 !EOP
24 !BOC
25 implicit none
26 ! arguments
27 integer, intent(in) :: ik
28 real(8), intent(inout) :: forceibs(3,natmtot)
29 ! local variables
30 integer ispn0,ispn1,ispn,jspn
31 integer n,nm,is,ias,ist,jst
32 integer j1,j2,j3,ig,i,j,l,nthd
33 real(8) v1,v2,v3,sm,t1
34 complex(8) z1,z2
35 ! automatic arrays
36 real(8) evalfv(nstfv,nspnfv)
37 complex(8) vh(nmatmax),vo(nmatmax)
38 complex(8) ffv(nstfv,nstfv),y(nstfv)
39 ! allocatable arrays
40 integer, allocatable :: ijg(:,:)
41 real(8), allocatable :: dp(:,:)
42 complex(8), allocatable :: apwalm(:,:,:,:),evecfv(:,:,:),evecsv(:,:)
43 complex(8), allocatable :: h(:,:),o(:,:),dlh(:,:),dlo(:,:)
44 ! external functions
45 complex(8), external :: zdotc
46 ! allocate local arrays
47 allocate(ijg(nmatmax,nmatmax),dp(nmatmax,nmatmax))
48 allocate(apwalm(ngkmax,apwordmax,lmmaxapw,natmtot))
49 allocate(evecfv(nmatmax,nstfv,nspnfv))
50 allocate(h(nmatmax,nmatmax),o(nmatmax,nmatmax))
51 allocate(dlh(nmatmax,nmatmax),dlo(nmatmax,nmatmax))
52 ! get the eigenvalues/vectors from file
53 call getevalfv(filext,ik,vkl(:,ik),evalfv)
54 call getevecfv(filext,ik,vkl(:,ik),vgkl(:,:,:,ik),evecfv)
55 if (tevecsv) then
56  allocate(evecsv(nstsv,nstsv))
57  call getevecsv(filext,ik,vkl(:,ik),evecsv)
58 end if
59 ! loop over first-variational spin components
60 do jspn=1,nspnfv
61  if (spinsprl) then
62  ispn0=jspn; ispn1=jspn
63  else
64  ispn0=1; ispn1=nspinor
65  end if
66  n=ngk(jspn,ik)
67  nm=nmat(jspn,ik)
68  do j=1,n
69  ig=igkig(j,jspn,ik)
70  j1=ivg(1,ig); j2=ivg(2,ig); j3=ivg(3,ig)
71  v1=0.5d0*vgkc(1,j,jspn,ik)
72  v2=0.5d0*vgkc(2,j,jspn,ik)
73  v3=0.5d0*vgkc(3,j,jspn,ik)
74  do i=1,j
75  ig=igkig(i,jspn,ik)
76  ijg(i,j)=ivgig(ivg(1,ig)-j1,ivg(2,ig)-j2,ivg(3,ig)-j3)
77  dp(i,j)=vgkc(1,i,jspn,ik)*v1+vgkc(2,i,jspn,ik)*v2+vgkc(3,i,jspn,ik)*v3
78  end do
79  end do
80 ! find the matching coefficients
81  call match(n,vgkc(:,:,jspn,ik),gkc(:,jspn,ik),sfacgk(:,:,jspn,ik),apwalm)
82 ! zero the local-orbital-local-orbital contribution
83  do j=n+1,nm
84  dlh(n+1:j,j)=0.d0
85  dlo(n+1:j,j)=0.d0
86  end do
87 ! loop over species and atoms
88  do ias=1,natmtot
89  is=idxis(ias)
90 ! Hamiltonian and overlap matrices
91  do j=1,nm
92  h(1:j,j)=0.d0
93  end do
94  call hmlaa(.false.,is,ias,n,apwalm(:,:,:,ias),nmatmax,h)
95  call hmlalo(is,ias,n,apwalm(:,:,:,ias),nmatmax,h)
96  do j=1,nm
97  o(1:j,j)=0.d0
98  end do
99  call olpaa(.false.,is,n,apwalm(:,:,:,ias),nmatmax,o)
100  call olpalo(is,ias,n,apwalm(:,:,:,ias),nmatmax,o)
101 ! loop over Cartesian directions
102  do l=1,3
103 ! APW-APW contribution
104  do j=1,n
105  do i=1,j
106  ig=ijg(i,j)
107  t1=vgc(l,ig)
108  z1=-ffacg(ig,is)*conjg(sfacg(ig,ias))
109  z2=t1*(dp(i,j)*z1+h(i,j))
110  dlh(i,j)=cmplx(-z2%im,z2%re,8)
111  z2=t1*(z1+o(i,j))
112  dlo(i,j)=cmplx(-z2%im,z2%re,8)
113  end do
114  end do
115 ! APW-local-orbital contribution
116  do j=n+1,nm
117  do i=1,n
118  t1=vgkc(l,i,jspn,ik)
119  z1=t1*h(i,j)
120  dlh(i,j)=cmplx(-z1%im,z1%re,8)
121  z1=t1*o(i,j)
122  dlo(i,j)=cmplx(-z1%im,z1%re,8)
123  end do
124  end do
125 ! compute the force matrix elements in the first-variational basis
126  call holdthd(nstfv,nthd)
127 !$OMP PARALLEL DO DEFAULT(SHARED) &
128 !$OMP PRIVATE(vh,vo,t1,ist,z1,z2) &
129 !$OMP SCHEDULE(DYNAMIC) &
130 !$OMP NUM_THREADS(nthd)
131  do jst=1,nstfv
132  call zhemv('U',nm,zone,dlh,nmatmax,evecfv(:,jst,jspn),1,zzero,vh,1)
133  call zhemv('U',nm,zone,dlo,nmatmax,evecfv(:,jst,jspn),1,zzero,vo,1)
134  t1=evalfv(jst,jspn)
135  do ist=1,nstfv
136  z1=zdotc(nm,evecfv(:,ist,jspn),1,vh,1)
137  z2=zdotc(nm,evecfv(:,ist,jspn),1,vo,1)
138  ffv(ist,jst)=z1-t1*z2
139  end do
140  end do
141 !$OMP END PARALLEL DO
142  call freethd(nthd)
143 ! compute the force using the second-variational coefficients if required
144  sm=0.d0
145  if (tevecsv) then
146 ! spin-polarised case
147  do j=1,nstsv
148  do ispn=ispn0,ispn1
149  i=(ispn-1)*nstfv+1
150  call zgemv('N',nstfv,nstfv,zone,ffv,nstfv,evecsv(i,j),1,zzero,y,1)
151  z1=zdotc(nstfv,evecsv(i,j),1,y,1)
152  sm=sm+occsv(j,ik)*z1%re
153  end do
154  end do
155  else
156 ! spin-unpolarised case
157  do j=1,nstsv
158  sm=sm+occsv(j,ik)*dble(ffv(j,j))
159  end do
160  end if
161  forceibs(l,ias)=forceibs(l,ias)+wkpt(ik)*sm
162 ! end loop over Cartesian components
163  end do
164 ! end loop over atoms and species
165  end do
166 ! end loop over first-variational spins
167 end do
168 deallocate(ijg,dp,apwalm,evecfv)
169 deallocate(h,o,dlh,dlo)
170 if (tevecsv) deallocate(evecsv)
171 end subroutine
172 !EOC
173 
complex(8), dimension(:,:), allocatable sfacg
Definition: modmain.f90:430
subroutine getevecsv(fext, ikp, vpl, evecsv)
Definition: getevecsv.f90:7
character(256) filext
Definition: modmain.f90:1301
integer lmmaxapw
Definition: modmain.f90:199
integer ngkmax
Definition: modmain.f90:499
integer, dimension(:,:,:), allocatable ivgig
Definition: modmain.f90:402
subroutine getevecfv(fext, ikp, vpl, vgpl, evecfv)
Definition: getevecfv.f90:10
logical tevecsv
Definition: modmain.f90:923
subroutine forcek(ik, forceibs)
Definition: forcek.f90:10
subroutine match(ngp, vgpc, gpc, sfacgp, apwalm)
Definition: match.f90:10
logical spinsprl
Definition: modmain.f90:283
Definition: modomp.f90:6
subroutine hmlaa(thr, is, ias, ngp, apwalm, ld, h)
Definition: hmlaa.f90:10
complex(8), parameter zone
Definition: modmain.f90:1240
complex(8), dimension(:,:,:,:), allocatable sfacgk
Definition: modmain.f90:509
real(8), dimension(:,:), allocatable vgc
Definition: modmain.f90:420
integer, dimension(:,:), allocatable nmat
Definition: modmain.f90:851
subroutine olpaa(tor, is, ngp, apwalm, ld, o)
Definition: olpaa.f90:7
integer nstsv
Definition: modmain.f90:889
integer, dimension(:,:), allocatable ngk
Definition: modmain.f90:497
real(8), dimension(:), allocatable wkpt
Definition: modmain.f90:475
pure subroutine olpalo(is, ias, ngp, apwalm, ld, o)
Definition: olpalo.f90:7
real(8), dimension(:,:,:,:), allocatable vgkl
Definition: modmain.f90:503
real(8), dimension(:,:), allocatable ffacg
Definition: modmain.f90:432
real(8), dimension(:,:), allocatable occsv
Definition: modmain.f90:905
subroutine getevalfv(fext, ikp, vpl, evalfv)
Definition: getevalfv.f90:7
integer nspinor
Definition: modmain.f90:267
real(8), dimension(:,:,:,:), allocatable vgkc
Definition: modmain.f90:505
integer, dimension(:,:), allocatable ivg
Definition: modmain.f90:400
complex(8), parameter zzero
Definition: modmain.f90:1240
real(8), dimension(:,:), allocatable vkl
Definition: modmain.f90:471
integer apwordmax
Definition: modmain.f90:760
integer, dimension(maxatoms *maxspecies) idxis
Definition: modmain.f90:44
real(8), dimension(:,:,:), allocatable gkc
Definition: modmain.f90:507
subroutine freethd(nthd)
Definition: modomp.f90:106
subroutine holdthd(nloop, nthd)
Definition: modomp.f90:78
integer, dimension(:,:,:), allocatable igkig
Definition: modmain.f90:501
pure subroutine hmlalo(is, ias, ngp, apwalm, ld, h)
Definition: hmlalo.f90:7