The Elk Code
wfmtsv.f90
Go to the documentation of this file.
1 
2 ! Copyright (C) 2021 J. K. Dewhurst, S. Sharma and E. K. U. Gross.
3 ! This file is distributed under the terms of the GNU General Public License.
4 ! See the file COPYING for license details.
5 
6 subroutine wfmtsv(tsh,lrstp,is,ias,nst,idx,ngp,apwalm,evecfv,evecsv,ld,wfmt)
7 use modmain
8 use modomp
9 implicit none
10 ! arguments
11 logical, intent(in) :: tsh
12 integer, intent(in) :: lrstp,is,ias,nst,idx(*),ngp(nspnfv)
13 complex(8), intent(in) :: apwalm(ngkmax,apwordmax,lmmaxapw,natmtot,nspnfv)
14 complex(8), intent(in) :: evecfv(nmatmax,nstfv,nspnfv),evecsv(nstsv,nstsv)
15 integer, intent(in) :: ld
16 complex(8), intent(out) :: wfmt(ld,nspinor,nst)
17 ! local variables
18 logical tasv
19 integer io,ilo,ispn,jspn
20 integer nr,nri,nro,iro
21 integer l,lm,np,npi
22 integer n,p,i,j,k,nthd
23 complex(8) zq(2),z
24 ! automatic arrays
25 complex(8) x(nstfv,nspnfv),y(nlmwf(is),nspinor,nst)
26 ! external functions
27 complex(8), external :: zdotu
28 iro=nrmti(is)+lrstp
29 if (lrstp == 1) then
30  nr=nrmt(is)
31  nri=nrmti(is)
32  np=npmt(is)
33  npi=npmti(is)
34 else
35  nr=nrcmt(is)
36  nri=nrcmti(is)
37  np=npcmt(is)
38  npi=npcmti(is)
39 end if
40 nro=nr-nri
41 ! de-phasing factor for spin-spirals
42 if (ssdph) then
43  zq(1)=zqss(ias)
44  zq(2)=conjg(zq(1))
45 end if
46 ! check if all the second-variational wavefunctions should be calculated
47 tasv=(idx(1) == 0)
48 call holdthd(nst,nthd)
49 !-----------------------!
50 ! APW functions !
51 !-----------------------!
52 !$OMP PARALLEL DEFAULT(SHARED) &
53 !$OMP PRIVATE(p,l,lm,io,ispn,jspn) &
54 !$OMP PRIVATE(n,i,j,k,z,ilo) &
55 !$OMP NUM_THREADS(nthd)
56 p=0
57 do l=0,lmaxo
58  do lm=l**2+1,(l+1)**2
59  do io=1,apword(l,is)
60  p=p+1
61  if (tevecsv) then
62  do jspn=1,nspnfv
63  n=ngp(jspn)
64 !$OMP DO SCHEDULE(DYNAMIC)
65  do j=1,nstfv
66  x(j,jspn)=zdotu(n,evecfv(:,j,jspn),1,apwalm(:,io,lm,ias,jspn),1)
67  end do
68 !$OMP END DO
69  end do
70 ! loop only over required states
71 !$OMP DO SCHEDULE(DYNAMIC)
72  do j=1,nst
73 ! index to state in evecsv
74  if (tasv) then; k=j; else; k=idx(j); end if
75  y(p,1,j)=zdotu(nstfv,evecsv(1,k),1,x,1)
76  if (spinpol) then
77  jspn=jspnfv(2)
78  y(p,2,j)=zdotu(nstfv,evecsv(nstfv+1,k),1,x(1,jspn),1)
79  end if
80  end do
81 !$OMP END DO
82  else
83 !$OMP DO SCHEDULE(DYNAMIC)
84  do j=1,nst
85  if (tasv) then; k=j; else; k=idx(j); end if
86  y(p,1,j)=zdotu(ngp(1),evecfv(:,k,1),1,apwalm(:,io,lm,ias,1),1)
87  end do
88 !$OMP END DO
89  end if
90  end do
91  end do
92 end do
93 !$OMP DO SCHEDULE(DYNAMIC)
94 do j=1,nst
95  wfmt(1:np,1:nspinor,j)=0.d0
96  do ispn=1,nspinor
97  p=0
98  do l=0,lmaxo
99  do lm=l**2+1,(l+1)**2
100  i=npi+lm
101  do io=1,apword(l,is)
102  p=p+1
103  z=y(p,ispn,j)
104  if (abs(z%re)+abs(z%im) < epswf) cycle
105  if (ssdph) z=z*zq(ispn)
106  if (l <= lmaxi) then
107  call zfzrf(nri,z,apwfr(1,1,io,l,ias),lmmaxi,wfmt(lm,ispn,j))
108  end if
109  call zfzrf(nro,z,apwfr(iro,1,io,l,ias),lmmaxo,wfmt(i,ispn,j))
110  end do
111  end do
112  end do
113  end do
114 end do
115 !$OMP END DO
116 !---------------------------------!
117 ! local-orbital functions !
118 !---------------------------------!
119 p=0
120 do ilo=1,nlorb(is)
121  l=lorbl(ilo,is)
122  do lm=l**2+1,(l+1)**2
123  p=p+1
124  i=idxlo(lm,ilo,ias)
125  if (tevecsv) then
126  do jspn=1,nspnfv
127  n=ngp(jspn)
128  x(1:nstfv,jspn)=evecfv(n+i,1:nstfv,jspn)
129  end do
130 !$OMP DO SCHEDULE(DYNAMIC)
131  do j=1,nst
132  if (tasv) then; k=j; else; k=idx(j); end if
133  y(p,1,j)=zdotu(nstfv,evecsv(1,k),1,x,1)
134  if (spinpol) then
135  jspn=jspnfv(2)
136  y(p,2,j)=zdotu(nstfv,evecsv(nstfv+1,k),1,x(1,jspn),1)
137  end if
138  end do
139 !$OMP END DO
140  else
141  do j=1,nst
142  if (tasv) then; k=j; else; k=idx(j); end if
143  y(p,1,j)=evecfv(ngp(1)+i,k,1)
144  end do
145  end if
146  end do
147 end do
148 !$OMP DO SCHEDULE(DYNAMIC)
149 do j=1,nst
150  do ispn=1,nspinor
151  p=0
152  do ilo=1,nlorb(is)
153  l=lorbl(ilo,is)
154  do lm=l**2+1,(l+1)**2
155  p=p+1
156  i=npi+lm
157  z=y(p,ispn,j)
158  if (abs(z%re)+abs(z%im) < epswf) cycle
159  if (ssdph) z=z*zq(ispn)
160  if (l <= lmaxi) then
161  call zfzrf(nri,z,lofr(1,1,ilo,ias),lmmaxi,wfmt(lm,ispn,j))
162  end if
163  call zfzrf(nro,z,lofr(iro,1,ilo,ias),lmmaxo,wfmt(i,ispn,j))
164  end do
165  end do
166 ! convert to spherical coordinates if required
167  if (.not.tsh) call zbshtip(nr,nri,wfmt(:,ispn,j))
168  end do
169 end do
170 !$OMP END DO
171 !$OMP END PARALLEL
172 call freethd(nthd)
173 
174 contains
175 
176 pure subroutine zfzrf(n,z,rf,ld,zf)
177 implicit none
178 ! arguments
179 integer, intent(in) :: n
180 complex(8), intent(in) :: z
181 real(8), intent(in) :: rf(lrstp,n)
182 integer, intent(in) :: ld
183 complex(8), intent(inout) :: zf(ld,n)
184 zf(1,1:n)=zf(1,1:n)+z*rf(1,1:n)
185 end subroutine
186 
187 end subroutine
188 
pure subroutine zfzrf(n, ld1, rf, ld2, zf)
Definition: dwfmtfv.f90:66
integer, dimension(maxspecies) npcmt
Definition: modmain.f90:214
integer, dimension(maxspecies) nlorb
Definition: modmain.f90:786
integer, dimension(:,:,:), allocatable idxlo
Definition: modmain.f90:855
real(8), dimension(:,:,:,:), allocatable lofr
Definition: modmain.f90:814
integer lmmaxo
Definition: modmain.f90:203
logical spinpol
Definition: modmain.f90:228
integer, dimension(maxspecies) npmt
Definition: modmain.f90:213
logical tevecsv
Definition: modmain.f90:923
Definition: modomp.f90:6
integer lmaxo
Definition: modmain.f90:201
complex(8), dimension(:), allocatable zqss
Definition: modmain.f90:287
subroutine zbshtip(nr, nri, zfmt)
Definition: zbshtip.f90:7
integer, dimension(0:maxlapw, maxspecies) apword
Definition: modmain.f90:758
logical ssdph
Definition: modmain.f90:285
integer, dimension(maxspecies) npcmti
Definition: modmain.f90:214
integer lmmaxi
Definition: modmain.f90:207
real(8), parameter epswf
Definition: modmain.f90:845
subroutine freethd(nthd)
Definition: modomp.f90:106
subroutine holdthd(nloop, nthd)
Definition: modomp.f90:78
real(8), dimension(:,:,:,:,:), allocatable apwfr
Definition: modmain.f90:774
integer, dimension(maxspecies) nrcmt
Definition: modmain.f90:173
integer, dimension(maxspecies) nrcmti
Definition: modmain.f90:211
integer, dimension(maxspecies) npmti
Definition: modmain.f90:213
integer, dimension(maxlorb, maxspecies) lorbl
Definition: modmain.f90:796
subroutine wfmtsv(tsh, lrstp, is, ias, nst, idx, ngp, apwalm, evecfv, evecsv, ld, wfmt)
Definition: wfmtsv.f90:7
integer, dimension(maxspecies) nrmti
Definition: modmain.f90:211
integer, dimension(2) jspnfv
Definition: modmain.f90:291
integer, dimension(maxspecies) nrmt
Definition: modmain.f90:150
integer lmaxi
Definition: modmain.f90:205