The Elk Code
 
Loading...
Searching...
No Matches
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:
9subroutine forcek(ik,forceibs)
10! !USES:
11use modmain
12use 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
25implicit none
26! arguments
27integer, intent(in) :: ik
28real(8), intent(inout) :: forceibs(3,natmtot)
29! local variables
30integer ispn0,ispn1,ispn,jspn
31integer n,nm,is,ias,ist,jst
32integer j1,j2,j3,ig,i,j,l,nthd
33real(8) v1,v2,v3,sm,t1
34complex(8) z1,z2
35! automatic arrays
36real(8) evalfv(nstfv,nspnfv)
37complex(8) vh(nmatmax),vo(nmatmax)
38complex(8) ffv(nstfv,nstfv),y(nstfv)
39! allocatable arrays
40integer, allocatable :: ijg(:,:)
41real(8), allocatable :: dp(:,:)
42complex(8), allocatable :: apwalm(:,:,:,:),evecfv(:,:,:),evecsv(:,:)
43complex(8), allocatable :: h(:,:),o(:,:),dlh(:,:),dlo(:,:)
44! external functions
45complex(8), external :: zdotc
46! allocate local arrays
47allocate(ijg(nmatmax,nmatmax),dp(nmatmax,nmatmax))
48allocate(apwalm(ngkmax,apwordmax,lmmaxapw,natmtot))
49allocate(evecfv(nmatmax,nstfv,nspnfv))
50allocate(h(nmatmax,nmatmax),o(nmatmax,nmatmax))
51allocate(dlh(nmatmax,nmatmax),dlo(nmatmax,nmatmax))
52! get the eigenvalues/vectors from file
53call getevalfv(filext,ik,vkl(:,ik),evalfv)
54call getevecfv(filext,ik,vkl(:,ik),vgkl(:,:,:,ik),evecfv)
55if (tevecsv) then
56 allocate(evecsv(nstsv,nstsv))
57 call getevecsv(filext,ik,vkl(:,ik),evecsv)
58end if
59! loop over first-variational spin components
60do 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)=zi*z2
111 z2=t1*(z1+o(i,j))
112 dlo(i,j)=zi*z2
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)=zi*z1
121 z1=t1*o(i,j)
122 dlo(i,j)=zi*z1
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
167end do
168deallocate(ijg,dp,apwalm,evecfv)
169deallocate(h,o,dlh,dlo)
170if (tevecsv) deallocate(evecsv)
171end subroutine
172!EOC
173
subroutine forcek(ik, forceibs)
Definition forcek.f90:10
subroutine getevalfv(fext, ikp, vpl, evalfv)
Definition getevalfv.f90:7
subroutine getevecfv(fext, ikp, vpl, vgpl, evecfv)
Definition getevecfv.f90:10
subroutine getevecsv(fext, ikp, vpl, evecsv)
Definition getevecsv.f90:7
subroutine hmlaa(thr, is, ias, ngp, apwalm, ld, h)
Definition hmlaa.f90:10
pure subroutine hmlalo(is, ias, ngp, apwalm, ld, h)
Definition hmlalo.f90:7
subroutine match(ngp, vgpc, gpc, sfacgp, apwalm)
Definition match.f90:10
real(8), dimension(:,:,:,:), allocatable vgkc
Definition modmain.f90:505
real(8), dimension(:), allocatable wkpt
Definition modmain.f90:475
complex(8), parameter zzero
Definition modmain.f90:1238
real(8), dimension(:,:,:), allocatable gkc
Definition modmain.f90:507
integer nspinor
Definition modmain.f90:267
character(256) filext
Definition modmain.f90:1300
complex(8), parameter zi
Definition modmain.f90:1239
integer, dimension(:,:), allocatable ngk
Definition modmain.f90:497
integer, dimension(:,:,:), allocatable igkig
Definition modmain.f90:501
real(8), dimension(:,:), allocatable ffacg
Definition modmain.f90:432
complex(8), parameter zone
Definition modmain.f90:1238
integer, dimension(maxatoms *maxspecies) idxis
Definition modmain.f90:44
complex(8), dimension(:,:), allocatable sfacg
Definition modmain.f90:430
integer lmmaxapw
Definition modmain.f90:199
integer apwordmax
Definition modmain.f90:760
real(8), dimension(:,:,:,:), allocatable vgkl
Definition modmain.f90:503
integer nstsv
Definition modmain.f90:886
logical spinsprl
Definition modmain.f90:283
integer, dimension(:,:), allocatable ivg
Definition modmain.f90:400
real(8), dimension(:,:), allocatable vkl
Definition modmain.f90:471
integer ngkmax
Definition modmain.f90:499
integer, dimension(:,:), allocatable nmat
Definition modmain.f90:846
real(8), dimension(:,:), allocatable vgc
Definition modmain.f90:420
complex(8), dimension(:,:,:,:), allocatable sfacgk
Definition modmain.f90:509
real(8), dimension(:,:), allocatable occsv
Definition modmain.f90:902
integer, dimension(:,:,:), allocatable ivgig
Definition modmain.f90:402
logical tevecsv
Definition modmain.f90:920
subroutine holdthd(nloop, nthd)
Definition modomp.f90:78
subroutine freethd(nthd)
Definition modomp.f90:106
subroutine olpaa(tor, is, ngp, apwalm, ld, o)
Definition olpaa.f90:7
pure subroutine olpalo(is, ias, ngp, apwalm, ld, o)
Definition olpalo.f90:7