The Elk Code
 
Loading...
Searching...
No Matches
eveqnsv.f90
Go to the documentation of this file.
1
2! Copyright (C) 2002-2010 J. K. Dewhurst, S. Sharma, C. Ambrosch-Draxl,
3! F. Bultmark, F. Cricchio and L. Nordstrom.
4! This file is distributed under the terms of the GNU General Public License.
5! See the file COPYING for license details.
6
7subroutine eveqnsv(ngp,igpig,vgpc,apwalm,evalfv,evecfv,evalsv_,evecsv)
8use modmain
9use moddftu
10use modomp
11implicit none
12! arguments
13integer, intent(in) :: ngp,igpig(ngkmax)
14real(8), intent(in) :: vgpc(3,ngkmax)
15complex(8), intent(in) :: apwalm(ngkmax,apwordmax,lmmaxapw,natmtot)
16real(8), intent(in) :: evalfv(nstfv)
17complex(8), intent(in) :: evecfv(nmatmax,nstfv)
18real(8), intent(out) :: evalsv_(nstsv)
19complex(8), intent(out) :: evecsv(nstsv,nstsv)
20! local variables
21logical todsb,socz
22integer ld,ist,jst,ispn,is,ias
23integer nrc,nrci,nrco,irco,irc
24integer l,lm,nm,npc,npc2,npci,ipco
25integer ngp2,igp,i0,i,j,nj,nthd
26real(8) ca,cb,a(3),asp(3,3),b(3),t1
27real(8) ts0,ts1
28complex(8) z1,z2,z3
29complex(4) c1
30! automatic arrays
31complex(8) wfmt2(npcmtmax),wfmt4(npcmtmax,3)
32complex(8) wfmt31(npcmtmax),wfmt32(npcmtmax),wfmt33(npcmtmax)
33complex(4) wfmt5(npcmtmax),wfgp1(ngkmax),wfgp2(ngkmax),wfgp3(ngkmax)
34complex(4) wfir1(ngtc),wfir2(ngtc),y(nstfv)
35! allocatable arrays
36complex(4), allocatable :: wfmt0(:,:),wfgp0(:,:)
37complex(8), allocatable :: wfmt1(:,:)
38! external functions
39real(4), external :: sdot
40! no calculation of second-variational eigenvectors
41if (.not.tevecsv) then
42 evalsv_(1:nstsv)=evalfv(1:nstsv)
43 evecsv(1:nstsv,1:nstsv)=0.d0
44 do i=1,nstsv
45 evecsv(i,i)=1.d0
46 end do
47 return
48end if
49call timesec(ts0)
50! coupling constant of the external A-field (-1/c)
51ca=-1.d0/solsc
52if (tafield) a(1:3)=ca*afieldc(1:3)
53if (tafsp) asp(1:3,1:3)=ca*afspc(1:3,1:3)
54! coupling constant of the external field (g_e/4c)
55cb=gfacte/(4.d0*solsc)
56! check if the off-diagonal spin block of the Hamiltonian is required
57todsb=(spinpol.and.(ncmag.or.spinorb))
58! special case of spin-orbit coupling and collinear magnetism
59socz=(spinorb.and.cmagz)
61! zero the second-variational Hamiltonian (stored in the eigenvector array)
62evecsv(1:nstsv,1:nstsv)=0.d0
63! set the diagonal elements equal to the first-variational eigenvalues
64do ispn=1,nspinor
65 do ist=1,nstfv
66 i=nstfv*(ispn-1)+ist
67 evecsv(i,i)=evalfv(ist)
68 end do
69end do
70call holdthd(nstfv,nthd)
71!$OMP PARALLEL DEFAULT(SHARED) &
72!$OMP PRIVATE(wfmt2,wfmt31,wfmt32,wfmt33,wfmt4,wfmt5) &
73!$OMP PRIVATE(wfir1,wfir2,wfgp1,wfgp2,wfgp3,y) &
74!$OMP PRIVATE(ias,is,nrc,nrci,nrco,irco,npc,npc2) &
75!$OMP PRIVATE(npci,ipco,b,ist,jst,irc,t1,i0,i,j) &
76!$OMP PRIVATE(z1,z2,z3,l,nm,lm,nj,igp,c1) &
77!$OMP NUM_THREADS(nthd)
78!-------------------------!
79! muffin-tin part !
80!-------------------------!
81!$OMP SINGLE
82allocate(wfmt0(npcmtmax,nstfv),wfmt1(npcmtmax,nstfv))
83!$OMP END SINGLE
84! begin loop over atoms
85do ias=1,natmtot
86 is=idxis(ias)
87 nrc=nrcmt(is)
88 nrci=nrcmti(is)
89 nrco=nrc-nrci
90 irco=nrci+1
91 npc=npcmt(is)
92 npc2=npc*2
93 npci=npcmti(is)
94 ipco=npci+1
95! B-field-orbit coupling
96 if (bforb) then
97 if (tbdip) then
98! external plus average muffin-tin dipole field
99 b(1:3)=cb*(bfieldc(1:3)+bdmta(1:3,ias))
100 else
101! external field only
102 b(1:3)=cb*bfieldc(1:3)
103 end if
104 end if
105! compute the first-variational wavefunctions
106!$OMP DO SCHEDULE(DYNAMIC)
107 do ist=1,nstfv
108 call wfmtfv(ias,ngp,apwalm(:,:,:,ias),evecfv(:,ist),wfmt1(:,ist))
109! multiply wavefunction by integration weights and store as single-precision
110 call zcfmtwr(nrc,nrci,wr2cmt(:,is),wfmt1(:,ist),wfmt0(:,ist))
111 end do
112!$OMP END DO
113! begin loop over states
114!$OMP DO SCHEDULE(DYNAMIC)
115 do jst=1,nstfv
116 if (spinpol) then
117! convert wavefunction to spherical coordinates
118 call zbsht(nrc,nrci,wfmt1(:,jst),wfmt2)
119! apply Kohn-Sham effective magnetic field
120 wfmt32(1:npc)=bsmt(1:npc,ias,ndmag)*wfmt2(1:npc)
121! convert to spherical harmonics
122 call zfsht(nrc,nrci,wfmt32,wfmt31)
123! non-collinear magnetic field
124 if (socz) then
125 wfmt33(1:npc)=0.d0
126 else if (ncmag) then
127 wfmt32(1:npc)=cmplx(bsmt(1:npc,ias,1),-bsmt(1:npc,ias,2),8)*wfmt2(1:npc)
128 call zfsht(nrc,nrci,wfmt32,wfmt33)
129 end if
130 wfmt32(1:npc)=-wfmt31(1:npc)
131! apply spin-orbit or B-field-orbit coupling if required
132 if (spinorb.or.bforb) then
133 call lopzflmn(lmaxi,nrci,lmmaxi,wfmt1(1,jst),wfmt4,wfmt4(1,2), &
134 wfmt4(1,3))
135 call lopzflmn(lmaxo,nrco,lmmaxo,wfmt1(ipco,jst),wfmt4(ipco,1), &
136 wfmt4(ipco,2),wfmt4(ipco,3))
137! spin-orbit coupling
138 if (spinorb) then
139! inner part of muffin-tin
140 do irc=1,nrci
141 t1=socfr(irc,ias)
142 i0=lmmaxi*(irc-1)
143 do i=i0+1,i0+lmmaxi
144 wfmt31(i)=wfmt31(i)+t1*wfmt4(i,3)
145 wfmt32(i)=wfmt32(i)-t1*wfmt4(i,3)
146 wfmt33(i)=wfmt33(i)+t1*(wfmt4(i,1)+zmi*wfmt4(i,2))
147 end do
148 end do
149! outer part of muffin-tin
150 do irc=irco,nrc
151 t1=socfr(irc,ias)
152 i0=npci+lmmaxo*(irc-irco)
153 do i=i0+1,i0+lmmaxo
154 wfmt31(i)=wfmt31(i)+t1*wfmt4(i,3)
155 wfmt32(i)=wfmt32(i)-t1*wfmt4(i,3)
156 wfmt33(i)=wfmt33(i)+t1*(wfmt4(i,1)+zmi*wfmt4(i,2))
157 end do
158 end do
159 end if
160! B-field-orbit coupling
161 if (bforb) then
162 do i=1,npc
163 z1=b(1)*wfmt4(i,1)+b(2)*wfmt4(i,2)+b(3)*wfmt4(i,3)
164 wfmt31(i)=wfmt31(i)+z1
165 wfmt32(i)=wfmt32(i)+z1
166 end do
167 end if
168 end if
169 else
170 wfmt31(1:npc)=0.d0
171 end if
172! apply muffin-tin DFT+U potential matrix if required
173 if (tvmatmt) then
174 do l=0,lmaxdm
175 if (tvmmt(l,ias)) then
176 nm=2*l+1
177 lm=l**2+1
178 i=npci+lm
179 if (l <= lmaxi) then
180 call zgemm('N','N',nm,nrci,nm,zone,vmatmt(lm,1,lm,1,ias),ld, &
181 wfmt1(lm,jst),lmmaxi,zone,wfmt31(lm),lmmaxi)
182 end if
183 call zgemm('N','N',nm,nrco,nm,zone,vmatmt(lm,1,lm,1,ias),ld, &
184 wfmt1(i,jst),lmmaxo,zone,wfmt31(i),lmmaxo)
185 if (spinpol) then
186 if (l <= lmaxi) then
187 call zgemm('N','N',nm,nrci,nm,zone,vmatmt(lm,2,lm,2,ias),ld, &
188 wfmt1(lm,jst),lmmaxi,zone,wfmt32(lm),lmmaxi)
189 end if
190 call zgemm('N','N',nm,nrco,nm,zone,vmatmt(lm,2,lm,2,ias),ld, &
191 wfmt1(i,jst),lmmaxo,zone,wfmt32(i),lmmaxo)
192 if (todsb) then
193 if (l <= lmaxi) then
194 call zgemm('N','N',nm,nrci,nm,zone,vmatmt(lm,1,lm,2,ias),ld, &
195 wfmt1(lm,jst),lmmaxi,zone,wfmt33(lm),lmmaxi)
196 end if
197 call zgemm('N','N',nm,nrco,nm,zone,vmatmt(lm,1,lm,2,ias),ld, &
198 wfmt1(i,jst),lmmaxo,zone,wfmt33(i),lmmaxo)
199 end if
200 end if
201 end if
202 end do
203 end if
204! apply vector potential if required
205 if (tafield.or.tafsp) then
206 call gradzfmt(nrc,nrci,rlcmt(:,-1,is),wcrcmt(:,:,is),wfmt1(:,jst), &
207 npcmtmax,wfmt4)
208 if (tafield) then
209 do i=1,npc
210 z1=zmi*(a(1)*wfmt4(i,1)+a(2)*wfmt4(i,2)+a(3)*wfmt4(i,3))
211 wfmt31(i)=wfmt31(i)+z1
212 if (spinpol) wfmt32(i)=wfmt32(i)+z1
213 end do
214 end if
215! apply spin-dependent vector potential if required
216 if (tafsp) then
217 do i=1,npc
218 z3=zmi*(asp(1,3)*wfmt4(i,1)+asp(2,3)*wfmt4(i,2)+asp(3,3)*wfmt4(i,3))
219 wfmt31(i)=wfmt31(i)+z3
220 wfmt32(i)=wfmt32(i)-z3
221 if (ncmag) then
222 z1=asp(1,1)*wfmt4(i,1)+asp(2,1)*wfmt4(i,2)+asp(3,1)*wfmt4(i,3)
223 z2=asp(1,2)*wfmt4(i,1)+asp(2,2)*wfmt4(i,2)+asp(3,2)*wfmt4(i,3)
224 wfmt33(i)=wfmt33(i)+zmi*z1-z2
225 end if
226 end do
227 end if
228 end if
229! add to second-variational Hamiltonian matrix
230 nj=jst-1
231! upper diagonal block
232 wfmt5(1:npc)=wfmt31(1:npc)
233 call cgemv('C',npc,nj,cone,wfmt0,npcmtmax,wfmt5,1,czero,y,1)
234 evecsv(1:nj,jst)=evecsv(1:nj,jst)+y(1:nj)
235 evecsv(jst,jst)=evecsv(jst,jst)+sdot(npc2,wfmt0(:,jst),1,wfmt5,1)
236 if (spinpol) then
237 j=jst+nstfv
238! lower diagonal block
239 wfmt5(1:npc)=wfmt32(1:npc)
240 call cgemv('C',npc,nj,cone,wfmt0,npcmtmax,wfmt5,1,czero,y,1)
241 evecsv(nstfv+1:nstfv+nj,j)=evecsv(nstfv+1:nstfv+nj,j)+y(1:nj)
242 evecsv(j,j)=evecsv(j,j)+sdot(npc2,wfmt0(:,jst),1,wfmt5,1)
243! off-diagonal block
244 if (todsb) then
245 wfmt5(1:npc)=wfmt33(1:npc)
246 call cgemv('C',npc,nstfv,cone,wfmt0,npcmtmax,wfmt5,1,czero,y,1)
247 evecsv(1:nstfv,j)=evecsv(1:nstfv,j)+y(1:nstfv)
248 end if
249 end if
250! end loop over states
251 end do
252!$OMP END DO
253! end loop over atoms
254end do
255!$OMP SINGLE
256deallocate(wfmt0,wfmt1)
257!$OMP END SINGLE
258!---------------------------!
259! interstitial part !
260!---------------------------!
261if (spinpol.or.tafield) then
262!$OMP SINGLE
263 if (socz) todsb=.false.
264 ngp2=ngp*2
265 allocate(wfgp0(ngp,nstfv))
266!$OMP END SINGLE
267! make single-precision copy of wavefunction
268!$OMP DO SCHEDULE(DYNAMIC)
269 do ist=1,nstfv
270 wfgp0(1:ngp,ist)=evecfv(1:ngp,ist)
271 end do
272!$OMP END DO
273! begin loop over states
274!$OMP DO SCHEDULE(DYNAMIC)
275 do jst=1,nstfv
276 wfir1(1:ngtc)=0.e0
277 do igp=1,ngp
278 wfir1(igfc(igpig(igp)))=wfgp0(igp,jst)
279 end do
280! Fourier transform wavefunction to real-space
281 call cfftifc(3,ngdgc,1,wfir1)
282! multiply with magnetic field and transform to G-space
283 if (spinpol) then
284 wfir2(1:ngtc)=bsirc(1:ngtc,ndmag)*wfir1(1:ngtc)
285 call cfftifc(3,ngdgc,-1,wfir2)
286 do igp=1,ngp
287 wfgp1(igp)=wfir2(igfc(igpig(igp)))
288 end do
289 wfgp2(1:ngp)=-wfgp1(1:ngp)
290 if (ncmag) then
291 wfir2(1:ngtc)=cmplx(bsirc(1:ngtc,1),-bsirc(1:ngtc,2),8)*wfir1(1:ngtc)
292 call cfftifc(3,ngdgc,-1,wfir2)
293 do igp=1,ngp
294 wfgp3(igp)=wfir2(igfc(igpig(igp)))
295 end do
296 end if
297 else
298 wfgp1(1:ngp)=0.e0
299 end if
300! apply vector potential if required
301 if (tafield) then
302 wfir1(1:ngtc)=0.e0
303 do igp=1,ngp
304 t1=a(1)*vgpc(1,igp)+a(2)*vgpc(2,igp)+a(3)*vgpc(3,igp)
305 wfir1(igfc(igpig(igp)))=t1*wfgp0(igp,jst)
306 end do
307 call cfftifc(3,ngdgc,1,wfir1)
308 wfir1(1:ngtc)=wfir1(1:ngtc)*cfrc(1:ngtc)
309 call cfftifc(3,ngdgc,-1,wfir1)
310 do igp=1,ngp
311 c1=wfir1(igfc(igpig(igp)))
312 wfgp1(igp)=wfgp1(igp)+c1
313 if (spinpol) wfgp2(igp)=wfgp2(igp)+c1
314 end do
315 end if
316! apply spin-dependent vector potential if required
317 if (tafsp) then
318 do j=1,3
319 if (sum(abs(asp(1:3,j))) < 1.d-8) cycle
320 wfir1(1:ngtc)=0.e0
321 do igp=1,ngp
322 t1=asp(1,j)*vgpc(1,igp)+asp(2,j)*vgpc(2,igp)+asp(3,j)*vgpc(3,igp)
323 wfir1(igfc(igpig(igp)))=t1*wfgp0(igp,jst)
324 end do
325 call cfftifc(3,ngdgc,1,wfir1)
326 wfir1(1:ngtc)=wfir1(1:ngtc)*cfrc(1:ngtc)
327 call cfftifc(3,ngdgc,-1,wfir1)
328 if (j == 1) then
329 do igp=1,ngp
330 wfgp3(igp)=wfgp3(igp)+wfir1(igfc(igpig(igp)))
331 end do
332 else if (j == 2) then
333 do igp=1,ngp
334 c1=wfir1(igfc(igpig(igp)))
335 wfgp3(igp)=wfgp3(igp)+cmi*c1
336 end do
337 else
338 do igp=1,ngp
339 c1=wfir1(igfc(igpig(igp)))
340 wfgp1(igp)=wfgp1(igp)+c1
341 wfgp2(igp)=wfgp2(igp)-c1
342 end do
343 end if
344 end do
345 end if
346! add to second-variational Hamiltonian matrix
347 nj=jst-1
348! upper diagonal block
349 call cgemv('C',ngp,nj,cone,wfgp0,ngp,wfgp1,1,czero,y,1)
350 evecsv(1:nj,jst)=evecsv(1:nj,jst)+y(1:nj)
351 evecsv(jst,jst)=evecsv(jst,jst)+sdot(ngp2,wfgp0(:,jst),1,wfgp1,1)
352 if (spinpol) then
353 j=jst+nstfv
354! lower diagonal block
355 call cgemv('C',ngp,nj,cone,wfgp0,ngp,wfgp2,1,czero,y,1)
356 evecsv(nstfv+1:nstfv+nj,j)=evecsv(nstfv+1:nstfv+nj,j)+y(1:nj)
357 evecsv(j,j)=evecsv(j,j)+sdot(ngp2,wfgp0(:,jst),1,wfgp2,1)
358! off-diagonal block
359 if (todsb) then
360 call cgemv('C',ngp,nstfv,cone,wfgp0,ngp,wfgp3,1,czero,y,1)
361 evecsv(1:nstfv,j)=evecsv(1:nstfv,j)+y(1:nstfv)
362 end if
363 end if
364! end loop over states
365 end do
366!$OMP END DO
367!$OMP SINGLE
368 deallocate(wfgp0)
369!$OMP END SINGLE
370end if
371!$OMP END PARALLEL
372call freethd(nthd)
373if (ncmag.or.spinorb.or.(.not.spinpol)) then
374! spins are coupled; or spin-unpolarised: full diagonalisation
375 call eveqnzh(nstsv,nstsv,evecsv,evalsv_)
376else
377! spins not coupled: block diagonalise H
378 call eveqnzh(nstfv,nstsv,evecsv,evalsv_)
379 evecsv(nstfv+1:nstsv,1:nstfv)=0.d0
380 evecsv(1:nstfv,nstfv+1:nstsv)=0.d0
381 i=nstfv+1
382 call eveqnzh(nstfv,nstsv,evecsv(i,i),evalsv_(i))
383end if
384call timesec(ts1)
385!$OMP ATOMIC
386timesv=timesv+ts1-ts0
387end subroutine
388
subroutine cfftifc(nd, n, sgn, c)
subroutine eveqnsv(ngp, igpig, vgpc, apwalm, evalfv, evecfv, evalsv_, evecsv)
Definition eveqnsv.f90:8
subroutine eveqnzh(n, ld, a, w)
Definition eveqnzh.f90:7
subroutine gradzfmt(nr, nri, ri, wcr, zfmt, ld, gzfmt)
Definition gradzfmt.f90:10
pure subroutine lopzflmn(lmax, n, ld, zflm, zlflm1, zlflm2, zlflm3)
Definition lopzflmn.f90:7
logical, dimension(:,:), allocatable tvmmt
Definition moddftu.f90:26
integer, parameter lmmaxdm
Definition moddftu.f90:14
complex(8), dimension(:,:,:,:,:), allocatable vmatmt
Definition moddftu.f90:20
integer, parameter lmaxdm
Definition moddftu.f90:13
logical tvmatmt
Definition moddftu.f90:24
real(8), parameter gfacte
Definition modmain.f90:1276
real(8), dimension(3) bfieldc
Definition modmain.f90:269
logical tbdip
Definition modmain.f90:643
logical ncmag
Definition modmain.f90:240
complex(4), parameter czero
Definition modmain.f90:1236
complex(8), parameter zmi
Definition modmain.f90:1239
integer nspinor
Definition modmain.f90:267
real(8), dimension(:), allocatable cfrc
Definition modmain.f90:438
integer, dimension(3) ngdgc
Definition modmain.f90:388
complex(4), parameter cmi
Definition modmain.f90:1237
real(8), dimension(3) afieldc
Definition modmain.f90:325
integer, dimension(maxspecies) npcmti
Definition modmain.f90:214
integer lmmaxi
Definition modmain.f90:207
logical spinpol
Definition modmain.f90:228
integer, dimension(maxspecies) nrcmt
Definition modmain.f90:173
complex(8), parameter zone
Definition modmain.f90:1238
logical spinorb
Definition modmain.f90:230
integer, dimension(:), allocatable igfc
Definition modmain.f90:410
integer, dimension(maxatoms *maxspecies) idxis
Definition modmain.f90:44
logical tafield
Definition modmain.f90:322
real(8), dimension(3, 3) afspc
Definition modmain.f90:331
real(8), dimension(:,:,:), allocatable rlcmt
Definition modmain.f90:181
logical tafsp
Definition modmain.f90:329
real(8), dimension(:,:), allocatable wr2cmt
Definition modmain.f90:189
logical cmagz
Definition modmain.f90:242
real(8), dimension(:,:,:), allocatable wcrcmt
Definition modmain.f90:193
logical bforb
Definition modmain.f90:234
integer, dimension(maxspecies) npcmt
Definition modmain.f90:214
complex(4), parameter cone
Definition modmain.f90:1236
real(8), dimension(:,:), allocatable socfr
Definition modmain.f90:670
real(8), dimension(:,:), allocatable bdmta
Definition modmain.f90:640
integer lmaxo
Definition modmain.f90:201
real(8) solsc
Definition modmain.f90:1252
real(8), dimension(:,:), pointer, contiguous bsirc
Definition modmain.f90:660
integer lmaxi
Definition modmain.f90:205
integer lmmaxo
Definition modmain.f90:203
real(8), dimension(:,:,:), pointer, contiguous bsmt
Definition modmain.f90:656
integer, dimension(maxspecies) nrcmti
Definition modmain.f90:211
real(8) timesv
Definition modmain.f90:1218
integer ndmag
Definition modmain.f90:238
logical tevecsv
Definition modmain.f90:920
subroutine holdthd(nloop, nthd)
Definition modomp.f90:78
subroutine freethd(nthd)
Definition modomp.f90:106
subroutine timesec(ts)
Definition timesec.f90:10
subroutine wfmtfv(ias, ngp, apwalm, evecfv, wfmt)
Definition wfmtfv.f90:10
subroutine zbsht(nr, nri, zfmt1, zfmt2)
Definition zbsht.f90:10
pure subroutine zcfmtwr(nr, nri, wr, zfmt, cfmt)
Definition zcfmtwr.f90:7
subroutine zfsht(nr, nri, zfmt1, zfmt2)
Definition zfsht.f90:10