The Elk Code
 
Loading...
Searching...
No Matches
eveqnit.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
6subroutine eveqnit(nmatp,ngp,igpig,vpl,vgpl,vgpc,apwalm,evalfv,evecfv)
7use modmain
8use modomp
9implicit none
10! arguments
11integer, intent(in) :: nmatp,ngp,igpig(ngkmax)
12real(8), intent(in) :: vpl(3),vgpl(3,ngkmax),vgpc(3,ngkmax)
13complex(8), intent(in) :: apwalm(ngkmax,apwordmax,lmmaxapw,natmtot)
14real(8), intent(out) :: evalfv(nstfv)
15complex(8), intent(out) :: evecfv(nmatmax,nstfv)
16! local variables
17integer ns,ist,it,j
18integer is,ias,nthd
19integer lwork,info
20real(8) rmax,t1
21real(8) ts1,ts0
22! allocatable arrays
23real(8), allocatable :: w(:),rwork(:)
24complex(8), allocatable :: h(:,:),o(:,:),hv(:,:),ov(:,:)
25complex(8), allocatable :: u(:,:),hu(:,:),ou(:,:)
26complex(8), allocatable :: hs(:,:),os(:,:),work(:)
27! external functions
28real(8), external :: ddot
29ns=2*nstfv
30if (iscl >= 2) then
31! read in the eigenvalues/vectors from file
32 call getevalfv(filext,0,vpl,evalfv)
33 call getevecfv(filext,0,vpl,vgpl,evecfv)
34else
35! initialise the eigenvectors to canonical basis vectors
36 evecfv(1:nmatp,1:nstfv)=0.d0
37 do ist=1,nstfv
38 evecfv(ist,ist)=1.d0
39 end do
40end if
41! compute Hamiltonian and overlap matrices
42call timesec(ts0)
43allocate(h(nmatp,nmatp),o(nmatp,nmatp))
44call holdthd(2,nthd)
45!$OMP PARALLEL SECTIONS DEFAULT(SHARED) &
46!$OMP PRIVATE(j,ias,is) &
47!$OMP NUM_THREADS(nthd)
48!$OMP SECTION
49! Hamiltonian
50call hmlistl(ngp,igpig,vgpc,nmatp,h)
51do j=ngp+1,nmatp
52 h(1:j,j)=0.d0
53end do
54do ias=1,natmtot
55 is=idxis(ias)
56 call hmlaa(tefvr,is,ias,ngp,apwalm(:,:,:,ias),nmatp,h)
57 call hmlalo(is,ias,ngp,apwalm(:,:,:,ias),nmatp,h)
58 call hmllolo(is,ias,ngp,nmatp,h)
59end do
60!$OMP SECTION
61! overlap
62call olpistl(ngp,igpig,nmatp,o)
63do j=ngp+1,nmatp
64 o(1:j,j)=0.d0
65end do
66do ias=1,natmtot
67 is=idxis(ias)
68 call olpaa(tefvr,is,ngp,apwalm(:,:,:,ias),nmatp,o)
69 call olpalo(is,ias,ngp,apwalm(:,:,:,ias),nmatp,o)
70 call olplolo(is,ias,ngp,nmatp,o)
71end do
72!$OMP END PARALLEL SECTIONS
73call freethd(nthd)
74call timesec(ts1)
75!$OMP ATOMIC
76timemat=timemat+ts1-ts0
77call timesec(ts0)
78allocate(w(ns),rwork(3*ns))
79allocate(hv(nmatp,nstfv),ov(nmatp,nstfv))
80allocate(u(nmatp,nstfv),hu(nmatp,nstfv),ou(nmatp,nstfv))
81allocate(hs(ns,ns),os(ns,ns))
82lwork=2*ns
83allocate(work(lwork))
84call holdthd(nstfv,nthd)
85! iteration loop
86!$OMP PARALLEL DEFAULT(SHARED) &
87!$OMP PRIVATE(it,ist,t1) &
88!$OMP NUM_THREADS(nthd)
89do it=1,maxitefv
90!$OMP SINGLE
91 rmax=0.d0
92!$OMP END SINGLE
93!$OMP DO SCHEDULE(DYNAMIC)
94 do ist=1,nstfv
95! operate with O on the current eigenvector
96 call zhemv('U',nmatp,zone,o,nmatp,evecfv(:,ist),1,zzero,ov(:,ist),1)
97! normalise the eigenvector
98 t1=ddot(2*nmatp,evecfv(:,ist),1,ov(:,ist),1)
99 if (t1 > 0.d0) then
100 t1=1.d0/sqrt(t1)
101 call zdscal(nmatp,t1,evecfv(:,ist),1)
102 call zdscal(nmatp,t1,ov(:,ist),1)
103 end if
104! operate with H on the current eigenvector
105 call zhemv('U',nmatp,zone,h,nmatp,evecfv(:,ist),1,zzero,hv(:,ist),1)
106! estimate the eigenvalue
107 t1=ddot(2*nmatp,evecfv(:,ist),1,hv(:,ist),1)
108 if ((iscl <= 1).and.(it == 1)) then
109 evalfv(ist)=t1
110 else
111 evalfv(ist)=(1.d0-befvit)*evalfv(ist)+befvit*t1
112 end if
113! compute the residual |u> = (H - eO)|v>
114 call zcopy(nmatp,hv(:,ist),1,u(:,ist),1)
115 t1=-evalfv(ist)
116 u(1:nmatp,ist)=u(1:nmatp,ist)+t1*ov(1:nmatp,ist)
117! apply the overlap matrix to the residual
118 call zhemv('U',nmatp,zone,o,nmatp,u(:,ist),1,zzero,ou(:,ist),1)
119! compute the overlap of the residual with itself
120 t1=ddot(2*nmatp,u(:,ist),1,ou(:,ist),1)
121!$OMP ATOMIC
122 rmax=max(rmax,t1)
123! normalise the residual
124 if (t1 > 0.d0) then
125 t1=1.d0/sqrt(t1)
126 call zdscal(nmatp,t1,u(:,ist),1)
127 call zdscal(nmatp,t1,ou(:,ist),1)
128 end if
129! apply the Hamiltonian matrix to the residual
130 call zhemv('U',nmatp,zone,h,nmatp,u(:,ist),1,zzero,hu(:,ist),1)
131 end do
132!$OMP END DO
133! compute the Hamiltonian and overlap matrices in the subspace formed by the
134! eigenvectors and their residuals
135!$OMP DO SCHEDULE(DYNAMIC)
136 do ist=1,nstfv
137 call zgemv('C',nmatp,nstfv,zone,evecfv,nmatmax,hv(:,ist),1,zzero, &
138 hs(1,ist),1)
139 call zgemv('C',nmatp,nstfv,zone,evecfv,nmatmax,hu(:,ist),1,zzero, &
140 hs(1,nstfv+ist),1)
141 call zgemv('C',nmatp,nstfv,zone,u,nmatp,hu(:,ist),1,zzero, &
142 hs(nstfv+1,nstfv+ist),1)
143 end do
144!$OMP END DO NOWAIT
145!$OMP DO SCHEDULE(DYNAMIC)
146 do ist=1,nstfv
147 call zgemv('C',nmatp,nstfv,zone,evecfv,nmatmax,ov(:,ist),1,zzero, &
148 os(1,ist),1)
149 call zgemv('C',nmatp,nstfv,zone,evecfv,nmatmax,ou(:,ist),1,zzero, &
150 os(1,nstfv+ist),1)
151 call zgemv('C',nmatp,nstfv,zone,u,nmatp,ou(:,ist),1,zzero, &
152 os(nstfv+1,nstfv+ist),1)
153 end do
154!$OMP END DO
155! solve the generalised eigenvalue problem in the subspace (one thread only)
156!$OMP SINGLE
157 call zhegv(1,'V','U',ns,hs,ns,os,ns,w,work,lwork,rwork,info)
158!$OMP END SINGLE
159 if (info /= 0) exit
160! construct the new eigenvectors
161!$OMP DO SCHEDULE(DYNAMIC)
162 do ist=1,nstfv
163 call zgemv('N',nmatp,nstfv,zone,evecfv,nmatmax,hs(1,ist),1,zzero, &
164 ov(:,ist),1)
165 call zgemv('N',nmatp,nstfv,zone,u,nmatp,hs(nstfv+1,ist),1,zone,ov(:,ist),1)
166 end do
167!$OMP END DO
168!$OMP DO SCHEDULE(DYNAMIC)
169 do ist=1,nstfv
170 call zcopy(nmatp,ov(:,ist),1,evecfv(:,ist),1)
171 end do
172!$OMP END DO
173! check for convergence
174!$OMP SINGLE
175 rmax=sqrt(abs(rmax)/dble(nmatp))
176!$OMP END SINGLE
177 if ((it >= minitefv).and.(rmax < epsefvit)) exit
178! end iteration loop
179end do
180!$OMP END PARALLEL
181call freethd(nthd)
182deallocate(w,rwork,h,o,hv,ov)
183deallocate(u,hu,ou,hs,os,work)
184call timesec(ts1)
185!$OMP ATOMIC
186timefv=timefv+ts1-ts0
187end subroutine
188
subroutine eveqnit(nmatp, ngp, igpig, vpl, vgpl, vgpc, apwalm, evalfv, evecfv)
Definition eveqnit.f90:7
subroutine getevalfv(fext, ikp, vpl, evalfv)
Definition getevalfv.f90:7
subroutine getevecfv(fext, ikp, vpl, vgpl, evecfv)
Definition getevecfv.f90:10
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
pure subroutine hmlistl(ngp, igpig, vgpc, ld, h)
Definition hmlistl.f90:10
pure subroutine hmllolo(is, ias, ngp, ld, h)
Definition hmllolo.f90:7
complex(8), parameter zzero
Definition modmain.f90:1238
character(256) filext
Definition modmain.f90:1300
complex(8), parameter zone
Definition modmain.f90:1238
integer, dimension(maxatoms *maxspecies) idxis
Definition modmain.f90:44
real(8) timemat
Definition modmain.f90:1214
real(8) timefv
Definition modmain.f90:1216
real(8) befvit
Definition modmain.f90:872
integer minitefv
Definition modmain.f90:870
real(8) epsefvit
Definition modmain.f90:874
logical tefvr
Definition modmain.f90:865
integer iscl
Definition modmain.f90:1048
integer maxitefv
Definition modmain.f90:870
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
pure subroutine olpistl(ngp, igpig, ld, o)
Definition olpistl.f90:10
pure subroutine olplolo(is, ias, ngp, ld, o)
Definition olplolo.f90:7
subroutine timesec(ts)
Definition timesec.f90:10