The Elk Code
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 
7 subroutine eveqnsv(ngp,igpig,vgpc,apwalm,evalfv,evecfv,evalsv_,evecsv)
8 use modmain
9 use moddftu
10 use modomp
11 implicit none
12 ! arguments
13 integer, intent(in) :: ngp,igpig(ngkmax)
14 real(8), intent(in) :: vgpc(3,ngkmax)
15 complex(8), intent(in) :: apwalm(ngkmax,apwordmax,lmmaxapw,natmtot)
16 real(8), intent(in) :: evalfv(nstfv)
17 complex(8), intent(in) :: evecfv(nmatmax,nstfv)
18 real(8), intent(out) :: evalsv_(nstsv)
19 complex(8), intent(out) :: evecsv(nstsv,nstsv)
20 ! local variables
21 logical todsb,socz
22 integer ld,ist,jst,ispn,is,ias
23 integer nrc,nrci,nrco,irco,irc
24 integer l,lm,nm,npc,npc2,npci,ipco
25 integer ngp2,igp,i0,i1,i,j,nj,nthd
26 real(8) ca,cb,a(3),asp(3,3),b(3),t1
27 real(8) ts0,ts1
28 complex(8) z1,z2,z3
29 complex(4) c1
30 ! automatic arrays
31 complex(8) wfmt2(npcmtmax),wfmt4(npcmtmax,3)
32 complex(8) wfmt31(npcmtmax),wfmt32(npcmtmax),wfmt33(npcmtmax)
33 complex(4) wfmt5(npcmtmax),wfgp1(ngkmax),wfgp2(ngkmax),wfgp3(ngkmax)
34 complex(4) wfir1(ngtc),wfir2(ngtc),y(nstfv)
35 ! allocatable arrays
36 complex(4), allocatable :: wfmt0(:,:),wfgp0(:,:)
37 complex(8), allocatable :: wfmt1(:,:)
38 ! external functions
39 real(4), external :: sdot
40 ! no calculation of second-variational eigenvectors
41 if (.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
48 end if
49 call timesec(ts0)
50 ! coupling constant of the external A-field (-1/c)
51 ca=-1.d0/solsc
52 if (tafield) a(1:3)=ca*afieldc(1:3)
53 if (tafsp) asp(1:3,1:3)=ca*afspc(1:3,1:3)
54 ! coupling constant of the external field (gₑ/4c)
55 cb=gfacte/(4.d0*solsc)
56 ! check if the off-diagonal spin block of the Hamiltonian is required
57 todsb=(spinpol.and.(ncmag.or.spinorb))
58 ! special case of spin-orbit coupling and collinear magnetism
59 socz=(spinorb.and.cmagz)
61 ! zero the second-variational Hamiltonian (stored in the eigenvector array)
62 evecsv(1:nstsv,1:nstsv)=0.d0
63 ! set the diagonal elements equal to the first-variational eigenvalues
64 do ispn=1,nspinor
65  do ist=1,nstfv
66  i=nstfv*(ispn-1)+ist
67  evecsv(i,i)=evalfv(ist)
68  end do
69 end do
70 call 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,i1,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
82 allocate(wfmt0(npcmtmax,nstfv),wfmt1(npcmtmax,nstfv))
83 !$OMP END SINGLE
84 ! begin loop over atoms
85 do 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 minus 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)+1; i1=i0+lmmaxi-1
143  wfmt31(i0:i1)=wfmt31(i0:i1)+t1*wfmt4(i0:i1,3)
144  wfmt32(i0:i1)=wfmt32(i0:i1)-t1*wfmt4(i0:i1,3)
145  wfmt33(i0:i1)=wfmt33(i0:i1)+t1*(wfmt4(i0:i1,1)-zi*wfmt4(i0:i1,2))
146  end do
147 ! outer part of muffin-tin
148  do irc=irco,nrc
149  t1=socfr(irc,ias)
150  i0=npci+lmmaxo*(irc-irco)+1; i1=i0+lmmaxo-1
151  wfmt31(i0:i1)=wfmt31(i0:i1)+t1*wfmt4(i0:i1,3)
152  wfmt32(i0:i1)=wfmt32(i0:i1)-t1*wfmt4(i0:i1,3)
153  wfmt33(i0:i1)=wfmt33(i0:i1)+t1*(wfmt4(i0:i1,1)-zi*wfmt4(i0:i1,2))
154  end do
155  end if
156 ! B-field-orbit coupling
157  if (bforb) then
158  do i=1,npc
159  z1=b(1)*wfmt4(i,1)+b(2)*wfmt4(i,2)+b(3)*wfmt4(i,3)
160  wfmt31(i)=wfmt31(i)+z1
161  wfmt32(i)=wfmt32(i)+z1
162  end do
163  end if
164  end if
165  else
166  wfmt31(1:npc)=0.d0
167  end if
168 ! apply muffin-tin DFT+U potential matrix if required
169  if (tvmatmt) then
170  do l=0,lmaxdm
171  if (tvmmt(l,ias)) then
172  nm=2*l+1
173  lm=l**2+1
174  i=npci+lm
175  if (l <= lmaxi) &
176  call zgemm('N','N',nm,nrci,nm,zone,vmatmt(lm,1,lm,1,ias),ld, &
177  wfmt1(lm,jst),lmmaxi,zone,wfmt31(lm),lmmaxi)
178  call zgemm('N','N',nm,nrco,nm,zone,vmatmt(lm,1,lm,1,ias),ld, &
179  wfmt1(i,jst),lmmaxo,zone,wfmt31(i),lmmaxo)
180  if (spinpol) then
181  if (l <= lmaxi) &
182  call zgemm('N','N',nm,nrci,nm,zone,vmatmt(lm,2,lm,2,ias),ld, &
183  wfmt1(lm,jst),lmmaxi,zone,wfmt32(lm),lmmaxi)
184  call zgemm('N','N',nm,nrco,nm,zone,vmatmt(lm,2,lm,2,ias),ld, &
185  wfmt1(i,jst),lmmaxo,zone,wfmt32(i),lmmaxo)
186  if (todsb) then
187  if (l <= lmaxi) &
188  call zgemm('N','N',nm,nrci,nm,zone,vmatmt(lm,1,lm,2,ias),ld, &
189  wfmt1(lm,jst),lmmaxi,zone,wfmt33(lm),lmmaxi)
190  call zgemm('N','N',nm,nrco,nm,zone,vmatmt(lm,1,lm,2,ias),ld, &
191  wfmt1(i,jst),lmmaxo,zone,wfmt33(i),lmmaxo)
192  end if
193  end if
194  end if
195  end do
196  end if
197 ! apply vector potential if required
198  if (tafield.or.tafsp) then
199  call gradzfmt(nrc,nrci,rlcmt(:,-1,is),wcrcmt(:,:,is),wfmt1(:,jst), &
200  npcmtmax,wfmt4)
201  if (tafield) then
202  do i=1,npc
203  z1=a(1)*wfmt4(i,1)+a(2)*wfmt4(i,2)+a(3)*wfmt4(i,3)
204  z1=cmplx(z1%im,-z1%re,8)
205  wfmt31(i)=wfmt31(i)+z1
206  if (spinpol) wfmt32(i)=wfmt32(i)+z1
207  end do
208  end if
209 ! apply spin-dependent vector potential if required
210  if (tafsp) then
211  do i=1,npc
212  z3=asp(1,3)*wfmt4(i,1)+asp(2,3)*wfmt4(i,2)+asp(3,3)*wfmt4(i,3)
213  z3=cmplx(z3%im,-z3%re,8)
214  wfmt31(i)=wfmt31(i)+z3
215  wfmt32(i)=wfmt32(i)-z3
216  if (ncmag) then
217  z1=asp(1,1)*wfmt4(i,1)+asp(2,1)*wfmt4(i,2)+asp(3,1)*wfmt4(i,3)
218  z2=asp(1,2)*wfmt4(i,1)+asp(2,2)*wfmt4(i,2)+asp(3,2)*wfmt4(i,3)
219  wfmt33(i)=wfmt33(i)+cmplx(z1%im,-z1%re,8)-z2
220  end if
221  end do
222  end if
223  end if
224 ! add to second-variational Hamiltonian matrix
225  nj=jst-1
226 ! upper diagonal block
227  wfmt5(1:npc)=wfmt31(1:npc)
228  call cgemv('C',npc,nj,cone,wfmt0,npcmtmax,wfmt5,1,czero,y,1)
229  evecsv(1:nj,jst)=evecsv(1:nj,jst)+y(1:nj)
230  evecsv(jst,jst)=evecsv(jst,jst)+sdot(npc2,wfmt0(:,jst),1,wfmt5,1)
231  if (spinpol) then
232  j=jst+nstfv
233 ! lower diagonal block
234  wfmt5(1:npc)=wfmt32(1:npc)
235  call cgemv('C',npc,nj,cone,wfmt0,npcmtmax,wfmt5,1,czero,y,1)
236  evecsv(nstfv+1:nstfv+nj,j)=evecsv(nstfv+1:nstfv+nj,j)+y(1:nj)
237  evecsv(j,j)=evecsv(j,j)+sdot(npc2,wfmt0(:,jst),1,wfmt5,1)
238 ! off-diagonal block
239  if (todsb) then
240  wfmt5(1:npc)=wfmt33(1:npc)
241  call cgemv('C',npc,nstfv,cone,wfmt0,npcmtmax,wfmt5,1,czero,y,1)
242  evecsv(1:nstfv,j)=evecsv(1:nstfv,j)+y(1:nstfv)
243  end if
244  end if
245 ! end loop over states
246  end do
247 !$OMP END DO
248 ! end loop over atoms
249 end do
250 !$OMP SINGLE
251 deallocate(wfmt0,wfmt1)
252 !$OMP END SINGLE
253 !---------------------------!
254 ! interstitial part !
255 !---------------------------!
256 if (spinpol.or.tafield) then
257 !$OMP SINGLE
258  if (socz) todsb=.false.
259  ngp2=ngp*2
260  allocate(wfgp0(ngp,nstfv))
261 !$OMP END SINGLE
262 ! make single-precision copy of wavefunction
263 !$OMP DO SCHEDULE(DYNAMIC)
264  do ist=1,nstfv
265  wfgp0(1:ngp,ist)=evecfv(1:ngp,ist)
266  end do
267 !$OMP END DO
268 ! begin loop over states
269 !$OMP DO SCHEDULE(DYNAMIC)
270  do jst=1,nstfv
271  wfir1(1:ngtc)=0.e0
272  do igp=1,ngp
273  wfir1(igfc(igpig(igp)))=wfgp0(igp,jst)
274  end do
275 ! Fourier transform wavefunction to real-space
276  call cfftifc(3,ngdgc,1,wfir1)
277 ! multiply with magnetic field and transform to G-space
278  if (spinpol) then
279  wfir2(1:ngtc)=bsirc(1:ngtc,ndmag)*wfir1(1:ngtc)
280  call cfftifc(3,ngdgc,-1,wfir2)
281  do igp=1,ngp
282  wfgp1(igp)=wfir2(igfc(igpig(igp)))
283  end do
284  wfgp2(1:ngp)=-wfgp1(1:ngp)
285  if (ncmag) then
286  wfir2(1:ngtc)=cmplx(bsirc(1:ngtc,1),-bsirc(1:ngtc,2),8)*wfir1(1:ngtc)
287  call cfftifc(3,ngdgc,-1,wfir2)
288  do igp=1,ngp
289  wfgp3(igp)=wfir2(igfc(igpig(igp)))
290  end do
291  end if
292  else
293  wfgp1(1:ngp)=0.e0
294  end if
295 ! apply vector potential if required
296  if (tafield) then
297  wfir1(1:ngtc)=0.e0
298  do igp=1,ngp
299  t1=a(1)*vgpc(1,igp)+a(2)*vgpc(2,igp)+a(3)*vgpc(3,igp)
300  wfir1(igfc(igpig(igp)))=t1*wfgp0(igp,jst)
301  end do
302  call cfftifc(3,ngdgc,1,wfir1)
303  wfir1(1:ngtc)=wfir1(1:ngtc)*cfrc(1:ngtc)
304  call cfftifc(3,ngdgc,-1,wfir1)
305  do igp=1,ngp
306  c1=wfir1(igfc(igpig(igp)))
307  wfgp1(igp)=wfgp1(igp)+c1
308  if (spinpol) wfgp2(igp)=wfgp2(igp)+c1
309  end do
310  end if
311 ! apply spin-dependent vector potential if required
312  if (tafsp) then
313  do j=1,3
314  if (sum(abs(asp(1:3,j))) < 1.d-8) cycle
315  wfir1(1:ngtc)=0.e0
316  do igp=1,ngp
317  t1=asp(1,j)*vgpc(1,igp)+asp(2,j)*vgpc(2,igp)+asp(3,j)*vgpc(3,igp)
318  wfir1(igfc(igpig(igp)))=t1*wfgp0(igp,jst)
319  end do
320  call cfftifc(3,ngdgc,1,wfir1)
321  wfir1(1:ngtc)=wfir1(1:ngtc)*cfrc(1:ngtc)
322  call cfftifc(3,ngdgc,-1,wfir1)
323  if (j == 1) then
324  do igp=1,ngp
325  wfgp3(igp)=wfgp3(igp)+wfir1(igfc(igpig(igp)))
326  end do
327  else if (j == 2) then
328  do igp=1,ngp
329  c1=wfir1(igfc(igpig(igp)))
330  wfgp3(igp)=wfgp3(igp)+cmplx(c1%im,-c1%re,4)
331  end do
332  else
333  do igp=1,ngp
334  c1=wfir1(igfc(igpig(igp)))
335  wfgp1(igp)=wfgp1(igp)+c1
336  wfgp2(igp)=wfgp2(igp)-c1
337  end do
338  end if
339  end do
340  end if
341 ! add to second-variational Hamiltonian matrix
342  nj=jst-1
343 ! upper diagonal block
344  call cgemv('C',ngp,nj,cone,wfgp0,ngp,wfgp1,1,czero,y,1)
345  evecsv(1:nj,jst)=evecsv(1:nj,jst)+y(1:nj)
346  evecsv(jst,jst)=evecsv(jst,jst)+sdot(ngp2,wfgp0(:,jst),1,wfgp1,1)
347  if (spinpol) then
348  j=jst+nstfv
349 ! lower diagonal block
350  call cgemv('C',ngp,nj,cone,wfgp0,ngp,wfgp2,1,czero,y,1)
351  evecsv(nstfv+1:nstfv+nj,j)=evecsv(nstfv+1:nstfv+nj,j)+y(1:nj)
352  evecsv(j,j)=evecsv(j,j)+sdot(ngp2,wfgp0(:,jst),1,wfgp2,1)
353 ! off-diagonal block
354  if (todsb) then
355  call cgemv('C',ngp,nstfv,cone,wfgp0,ngp,wfgp3,1,czero,y,1)
356  evecsv(1:nstfv,j)=evecsv(1:nstfv,j)+y(1:nstfv)
357  end if
358  end if
359 ! end loop over states
360  end do
361 !$OMP END DO
362 !$OMP SINGLE
363  deallocate(wfgp0)
364 !$OMP END SINGLE
365 end if
366 !$OMP END PARALLEL
367 call freethd(nthd)
368 if (ncmag.or.spinorb.or.(.not.spinpol)) then
369 ! spins are coupled; or spin-unpolarised: full diagonalisation
370  call zheevdi(nstsv,nstsv,evecsv,evalsv_)
371 else
372 ! spins not coupled: block diagonalise H
373  call zheevdi(nstfv,nstsv,evecsv,evalsv_)
374  evecsv(nstfv+1:nstsv,1:nstfv)=0.d0
375  evecsv(1:nstfv,nstfv+1:nstsv)=0.d0
376  i=nstfv+1
377  call zheevdi(nstfv,nstsv,evecsv(i,i),evalsv_(i))
378 end if
379 call timesec(ts1)
380 !$OMP ATOMIC
381 timesv=timesv+ts1-ts0
382 end subroutine
383 
real(8), dimension(3, 3) afspc
Definition: modmain.f90:333
integer, dimension(maxspecies) npcmt
Definition: modmain.f90:216
integer lmmaxo
Definition: modmain.f90:205
logical spinpol
Definition: modmain.f90:230
integer, parameter lmmaxdm
Definition: moddftu.f90:15
integer ndmag
Definition: modmain.f90:240
complex(4), parameter czero
Definition: modmain.f90:1239
logical tevecsv
Definition: modmain.f90:917
Definition: modomp.f90:6
subroutine gradzfmt(nr, nri, ri, wcr, zfmt, ld, gzfmt)
Definition: gradzfmt.f90:10
real(8), dimension(:,:), allocatable bdmta
Definition: modmain.f90:643
complex(4), parameter cone
Definition: modmain.f90:1239
complex(8), parameter zone
Definition: modmain.f90:1240
integer lmaxo
Definition: modmain.f90:203
subroutine zfsht(nr, nri, zfmt1, zfmt2)
Definition: zfsht.f90:10
pure subroutine lopzflmn(lmax, n, ld, zflm, zlflm1, zlflm2, zlflm3)
Definition: lopzflmn.f90:7
subroutine cfftifc(nd, n, sgn, c)
Definition: cfftifc_fftw.f90:7
logical bforb
Definition: modmain.f90:236
subroutine zheevdi(n, ld, a, w)
Definition: zheevdi.f90:7
integer, dimension(:), allocatable igfc
Definition: modmain.f90:413
real(8), dimension(:,:,:), allocatable rlcmt
Definition: modmain.f90:183
logical cmagz
Definition: modmain.f90:244
subroutine eveqnsv(ngp, igpig, vgpc, apwalm, evalfv, evecfv, evalsv_, evecsv)
Definition: eveqnsv.f90:8
logical tvmatmt
Definition: moddftu.f90:25
integer nspinor
Definition: modmain.f90:269
complex(8), dimension(:,:,:,:,:), allocatable vmatmt
Definition: moddftu.f90:21
real(8), parameter gfacte
Definition: modmain.f90:1277
real(8), dimension(3) afieldc
Definition: modmain.f90:327
logical, dimension(:,:), allocatable tvmmt
Definition: moddftu.f90:27
real(8) solsc
Definition: modmain.f90:1253
subroutine wfmtfv(ias, ngp, apwalm, evecfv, wfmt)
Definition: wfmtfv.f90:10
real(8), dimension(:,:), allocatable wr2cmt
Definition: modmain.f90:191
integer, dimension(maxspecies) npcmti
Definition: modmain.f90:216
integer, dimension(maxatoms *maxspecies) idxis
Definition: modmain.f90:44
integer lmmaxi
Definition: modmain.f90:209
real(8), dimension(:,:,:), allocatable wcrcmt
Definition: modmain.f90:195
subroutine timesec(ts)
Definition: timesec.f90:10
subroutine zbsht(nr, nri, zfmt1, zfmt2)
Definition: zbsht.f90:10
integer, dimension(3) ngdgc
Definition: modmain.f90:391
logical tbdip
Definition: modmain.f90:646
logical spinorb
Definition: modmain.f90:232
pure subroutine zcfmtwr(nr, nri, wr, zfmt, cfmt)
Definition: zcfmtwr.f90:7
subroutine freethd(nthd)
Definition: modomp.f90:112
subroutine holdthd(nloop, nthd)
Definition: modomp.f90:78
real(8) timesv
Definition: modmain.f90:1221
complex(8), parameter zi
Definition: modmain.f90:1240
logical tafsp
Definition: modmain.f90:331
real(8), dimension(:), allocatable cfrc
Definition: modmain.f90:441
integer, dimension(maxspecies) nrcmt
Definition: modmain.f90:175
integer, dimension(maxspecies) nrcmti
Definition: modmain.f90:213
integer, parameter lmaxdm
Definition: moddftu.f90:14
logical ncmag
Definition: modmain.f90:242
logical tafield
Definition: modmain.f90:324
real(8), dimension(:,:), pointer, contiguous bsirc
Definition: modmain.f90:663
real(8), dimension(3) bfieldc
Definition: modmain.f90:271
real(8), dimension(:,:,:), pointer, contiguous bsmt
Definition: modmain.f90:659
real(8), dimension(:,:), allocatable socfr
Definition: modmain.f90:673
integer lmaxi
Definition: modmain.f90:207