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,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_e/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,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 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)-zi*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)-zi*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=a(1)*wfmt4(i,1)+a(2)*wfmt4(i,2)+a(3)*wfmt4(i,3)
211  z1=cmplx(z1%im,-z1%re,8)
212  wfmt31(i)=wfmt31(i)+z1
213  if (spinpol) wfmt32(i)=wfmt32(i)+z1
214  end do
215  end if
216 ! apply spin-dependent vector potential if required
217  if (tafsp) then
218  do i=1,npc
219  z3=asp(1,3)*wfmt4(i,1)+asp(2,3)*wfmt4(i,2)+asp(3,3)*wfmt4(i,3)
220  z3=cmplx(z3%im,-z3%re,8)
221  wfmt31(i)=wfmt31(i)+z3
222  wfmt32(i)=wfmt32(i)-z3
223  if (ncmag) then
224  z1=asp(1,1)*wfmt4(i,1)+asp(2,1)*wfmt4(i,2)+asp(3,1)*wfmt4(i,3)
225  z2=asp(1,2)*wfmt4(i,1)+asp(2,2)*wfmt4(i,2)+asp(3,2)*wfmt4(i,3)
226  wfmt33(i)=wfmt33(i)+cmplx(z1%im,-z1%re,8)-z2
227  end if
228  end do
229  end if
230  end if
231 ! add to second-variational Hamiltonian matrix
232  nj=jst-1
233 ! upper diagonal block
234  wfmt5(1:npc)=wfmt31(1:npc)
235  call cgemv('C',npc,nj,cone,wfmt0,npcmtmax,wfmt5,1,czero,y,1)
236  evecsv(1:nj,jst)=evecsv(1:nj,jst)+y(1:nj)
237  evecsv(jst,jst)=evecsv(jst,jst)+sdot(npc2,wfmt0(:,jst),1,wfmt5,1)
238  if (spinpol) then
239  j=jst+nstfv
240 ! lower diagonal block
241  wfmt5(1:npc)=wfmt32(1:npc)
242  call cgemv('C',npc,nj,cone,wfmt0,npcmtmax,wfmt5,1,czero,y,1)
243  evecsv(nstfv+1:nstfv+nj,j)=evecsv(nstfv+1:nstfv+nj,j)+y(1:nj)
244  evecsv(j,j)=evecsv(j,j)+sdot(npc2,wfmt0(:,jst),1,wfmt5,1)
245 ! off-diagonal block
246  if (todsb) then
247  wfmt5(1:npc)=wfmt33(1:npc)
248  call cgemv('C',npc,nstfv,cone,wfmt0,npcmtmax,wfmt5,1,czero,y,1)
249  evecsv(1:nstfv,j)=evecsv(1:nstfv,j)+y(1:nstfv)
250  end if
251  end if
252 ! end loop over states
253  end do
254 !$OMP END DO
255 ! end loop over atoms
256 end do
257 !$OMP SINGLE
258 deallocate(wfmt0,wfmt1)
259 !$OMP END SINGLE
260 !---------------------------!
261 ! interstitial part !
262 !---------------------------!
263 if (spinpol.or.tafield) then
264 !$OMP SINGLE
265  if (socz) todsb=.false.
266  ngp2=ngp*2
267  allocate(wfgp0(ngp,nstfv))
268 !$OMP END SINGLE
269 ! make single-precision copy of wavefunction
270 !$OMP DO SCHEDULE(DYNAMIC)
271  do ist=1,nstfv
272  wfgp0(1:ngp,ist)=evecfv(1:ngp,ist)
273  end do
274 !$OMP END DO
275 ! begin loop over states
276 !$OMP DO SCHEDULE(DYNAMIC)
277  do jst=1,nstfv
278  wfir1(1:ngtc)=0.e0
279  do igp=1,ngp
280  wfir1(igfc(igpig(igp)))=wfgp0(igp,jst)
281  end do
282 ! Fourier transform wavefunction to real-space
283  call cfftifc(3,ngdgc,1,wfir1)
284 ! multiply with magnetic field and transform to G-space
285  if (spinpol) then
286  wfir2(1:ngtc)=bsirc(1:ngtc,ndmag)*wfir1(1:ngtc)
287  call cfftifc(3,ngdgc,-1,wfir2)
288  do igp=1,ngp
289  wfgp1(igp)=wfir2(igfc(igpig(igp)))
290  end do
291  wfgp2(1:ngp)=-wfgp1(1:ngp)
292  if (ncmag) then
293  wfir2(1:ngtc)=cmplx(bsirc(1:ngtc,1),-bsirc(1:ngtc,2),8)*wfir1(1:ngtc)
294  call cfftifc(3,ngdgc,-1,wfir2)
295  do igp=1,ngp
296  wfgp3(igp)=wfir2(igfc(igpig(igp)))
297  end do
298  end if
299  else
300  wfgp1(1:ngp)=0.e0
301  end if
302 ! apply vector potential if required
303  if (tafield) then
304  wfir1(1:ngtc)=0.e0
305  do igp=1,ngp
306  t1=a(1)*vgpc(1,igp)+a(2)*vgpc(2,igp)+a(3)*vgpc(3,igp)
307  wfir1(igfc(igpig(igp)))=t1*wfgp0(igp,jst)
308  end do
309  call cfftifc(3,ngdgc,1,wfir1)
310  wfir1(1:ngtc)=wfir1(1:ngtc)*cfrc(1:ngtc)
311  call cfftifc(3,ngdgc,-1,wfir1)
312  do igp=1,ngp
313  c1=wfir1(igfc(igpig(igp)))
314  wfgp1(igp)=wfgp1(igp)+c1
315  if (spinpol) wfgp2(igp)=wfgp2(igp)+c1
316  end do
317  end if
318 ! apply spin-dependent vector potential if required
319  if (tafsp) then
320  do j=1,3
321  if (sum(abs(asp(1:3,j))) < 1.d-8) cycle
322  wfir1(1:ngtc)=0.e0
323  do igp=1,ngp
324  t1=asp(1,j)*vgpc(1,igp)+asp(2,j)*vgpc(2,igp)+asp(3,j)*vgpc(3,igp)
325  wfir1(igfc(igpig(igp)))=t1*wfgp0(igp,jst)
326  end do
327  call cfftifc(3,ngdgc,1,wfir1)
328  wfir1(1:ngtc)=wfir1(1:ngtc)*cfrc(1:ngtc)
329  call cfftifc(3,ngdgc,-1,wfir1)
330  if (j == 1) then
331  do igp=1,ngp
332  wfgp3(igp)=wfgp3(igp)+wfir1(igfc(igpig(igp)))
333  end do
334  else if (j == 2) then
335  do igp=1,ngp
336  c1=wfir1(igfc(igpig(igp)))
337  wfgp3(igp)=wfgp3(igp)+cmplx(c1%im,-c1%re,4)
338  end do
339  else
340  do igp=1,ngp
341  c1=wfir1(igfc(igpig(igp)))
342  wfgp1(igp)=wfgp1(igp)+c1
343  wfgp2(igp)=wfgp2(igp)-c1
344  end do
345  end if
346  end do
347  end if
348 ! add to second-variational Hamiltonian matrix
349  nj=jst-1
350 ! upper diagonal block
351  call cgemv('C',ngp,nj,cone,wfgp0,ngp,wfgp1,1,czero,y,1)
352  evecsv(1:nj,jst)=evecsv(1:nj,jst)+y(1:nj)
353  evecsv(jst,jst)=evecsv(jst,jst)+sdot(ngp2,wfgp0(:,jst),1,wfgp1,1)
354  if (spinpol) then
355  j=jst+nstfv
356 ! lower diagonal block
357  call cgemv('C',ngp,nj,cone,wfgp0,ngp,wfgp2,1,czero,y,1)
358  evecsv(nstfv+1:nstfv+nj,j)=evecsv(nstfv+1:nstfv+nj,j)+y(1:nj)
359  evecsv(j,j)=evecsv(j,j)+sdot(ngp2,wfgp0(:,jst),1,wfgp2,1)
360 ! off-diagonal block
361  if (todsb) then
362  call cgemv('C',ngp,nstfv,cone,wfgp0,ngp,wfgp3,1,czero,y,1)
363  evecsv(1:nstfv,j)=evecsv(1:nstfv,j)+y(1:nstfv)
364  end if
365  end if
366 ! end loop over states
367  end do
368 !$OMP END DO
369 !$OMP SINGLE
370  deallocate(wfgp0)
371 !$OMP END SINGLE
372 end if
373 !$OMP END PARALLEL
374 call freethd(nthd)
375 if (ncmag.or.spinorb.or.(.not.spinpol)) then
376 ! spins are coupled; or spin-unpolarised: full diagonalisation
377  call eveqnzh(nstsv,nstsv,evecsv,evalsv_)
378 else
379 ! spins not coupled: block diagonalise H
380  call eveqnzh(nstfv,nstsv,evecsv,evalsv_)
381  evecsv(nstfv+1:nstsv,1:nstfv)=0.d0
382  evecsv(1:nstfv,nstfv+1:nstsv)=0.d0
383  i=nstfv+1
384  call eveqnzh(nstfv,nstsv,evecsv(i,i),evalsv_(i))
385 end if
386 call timesec(ts1)
387 !$OMP ATOMIC
388 timesv=timesv+ts1-ts0
389 end subroutine
390 
real(8), dimension(3, 3) afspc
Definition: modmain.f90:331
integer, dimension(maxspecies) npcmt
Definition: modmain.f90:214
integer lmmaxo
Definition: modmain.f90:203
logical spinpol
Definition: modmain.f90:228
integer, parameter lmmaxdm
Definition: moddftu.f90:14
integer ndmag
Definition: modmain.f90:238
complex(4), parameter czero
Definition: modmain.f90:1239
logical tevecsv
Definition: modmain.f90:923
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:640
complex(4), parameter cone
Definition: modmain.f90:1239
complex(8), parameter zone
Definition: modmain.f90:1240
integer lmaxo
Definition: modmain.f90:201
subroutine zfsht(nr, nri, zfmt1, zfmt2)
Definition: zfsht.f90:10
subroutine eveqnzh(n, ld, a, w)
Definition: eveqnzh.f90:7
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:234
integer, dimension(:), allocatable igfc
Definition: modmain.f90:410
real(8), dimension(:,:,:), allocatable rlcmt
Definition: modmain.f90:181
logical cmagz
Definition: modmain.f90:242
subroutine eveqnsv(ngp, igpig, vgpc, apwalm, evalfv, evecfv, evalsv_, evecsv)
Definition: eveqnsv.f90:8
logical tvmatmt
Definition: moddftu.f90:24
integer nspinor
Definition: modmain.f90:267
complex(8), dimension(:,:,:,:,:), allocatable vmatmt
Definition: moddftu.f90:20
real(8), parameter gfacte
Definition: modmain.f90:1277
real(8), dimension(3) afieldc
Definition: modmain.f90:325
logical, dimension(:,:), allocatable tvmmt
Definition: moddftu.f90:26
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:189
integer, dimension(maxspecies) npcmti
Definition: modmain.f90:214
integer, dimension(maxatoms *maxspecies) idxis
Definition: modmain.f90:44
integer lmmaxi
Definition: modmain.f90:207
real(8), dimension(:,:,:), allocatable wcrcmt
Definition: modmain.f90:193
subroutine timesec(ts)
Definition: timesec.f90:10
subroutine zbsht(nr, nri, zfmt1, zfmt2)
Definition: zbsht.f90:10
integer, dimension(3) ngdgc
Definition: modmain.f90:388
logical tbdip
Definition: modmain.f90:643
logical spinorb
Definition: modmain.f90:230
pure subroutine zcfmtwr(nr, nri, wr, zfmt, cfmt)
Definition: zcfmtwr.f90:7
subroutine freethd(nthd)
Definition: modomp.f90:106
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:329
real(8), dimension(:), allocatable cfrc
Definition: modmain.f90:438
integer, dimension(maxspecies) nrcmt
Definition: modmain.f90:173
integer, dimension(maxspecies) nrcmti
Definition: modmain.f90:211
integer, parameter lmaxdm
Definition: moddftu.f90:13
logical ncmag
Definition: modmain.f90:240
logical tafield
Definition: modmain.f90:322
real(8), dimension(:,:), pointer, contiguous bsirc
Definition: modmain.f90:660
real(8), dimension(3) bfieldc
Definition: modmain.f90:269
real(8), dimension(:,:,:), pointer, contiguous bsmt
Definition: modmain.f90:656
real(8), dimension(:,:), allocatable socfr
Definition: modmain.f90:670
integer lmaxi
Definition: modmain.f90:205