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 np,npi,ipo
22 integer l,lm,lma,lmb,nm
23 integer n,p,i,j,k,nthd
24 complex(8) zq(2)
25 ! automatic arrays
26 complex(8) x(nstfv,nspnfv),y(nlmwf(is),nspinor,nst)
27 complex(8) zfmt(npmtmax),z(2*lmaxo+1)
28 ! external functions
29 complex(8), external :: zdotu
30 iro=nrmti(is)+lrstp
31 if (lrstp == 1) then
32  nr=nrmt(is)
33  nri=nrmti(is)
34  np=npmt(is)
35  npi=npmti(is)
36 else
37  nr=nrcmt(is)
38  nri=nrcmti(is)
39  np=npcmt(is)
40  npi=npcmti(is)
41 end if
42 nro=nr-nri
43 ipo=npi+1
44 ! de-phasing factor for spin-spirals
45 if (ssdph) then
46  zq(1)=zqss(ias)
47  zq(2)=conjg(zq(1))
48 end if
49 ! check if all the second-variational wavefunctions should be calculated
50 tasv=(idx(1) == 0)
51 call holdthd(nst,nthd)
52 !-----------------------!
53 ! APW functions !
54 !-----------------------!
55 !$OMP PARALLEL DEFAULT(SHARED) &
56 !$OMP PRIVATE(zfmt,z,p,l,lma,lmb,io,lm) &
57 !$OMP PRIVATE(ispn,jspn,n,i,j,k,nm,ilo) &
58 !$OMP NUM_THREADS(nthd)
59 p=0
60 do l=0,lmaxo
61  lma=l**2+1; lmb=lma+2*l
62  do io=1,apword(l,is)
63  do lm=lma,lmb
64  p=p+1
65  if (tevecsv) then
66  do jspn=1,nspnfv
67  n=ngp(jspn)
68 !$OMP DO SCHEDULE(DYNAMIC)
69  do j=1,nstfv
70  x(j,jspn)=zdotu(n,evecfv(:,j,jspn),1,apwalm(:,io,lm,ias,jspn),1)
71  end do
72 !$OMP END DO
73  end do
74 ! loop only over required states
75 !$OMP DO SCHEDULE(DYNAMIC)
76  do j=1,nst
77 ! index to state in evecsv
78  k=merge(j,idx(j),tasv)
79  y(p,1,j)=zdotu(nstfv,evecsv(1,k),1,x,1)
80  if (spinpol) then
81  jspn=jspnfv(2)
82  y(p,2,j)=zdotu(nstfv,evecsv(nstfv+1,k),1,x(1,jspn),1)
83  end if
84  end do
85 !$OMP END DO
86  else
87 !$OMP DO SCHEDULE(DYNAMIC)
88  do j=1,nst
89  k=merge(j,idx(j),tasv)
90  y(p,1,j)=zdotu(ngp(1),evecfv(:,k,1),1,apwalm(:,io,lm,ias,1),1)
91  end do
92 !$OMP END DO
93  end if
94  end do
95  end do
96 end do
97 !$OMP DO SCHEDULE(DYNAMIC)
98 do j=1,nst
99  wfmt(1:np,1:nspinor,j)=0.d0
100  do ispn=1,nspinor
101  p=0
102  do l=0,lmaxo
103  nm=2*l+1
104  lma=l**2+1
105  do io=1,apword(l,is)
106  do lm=1,nm
107  p=p+1
108  z(lm)=y(p,ispn,j)
109  end do
110  if (ssdph) z(1:nm)=z(1:nm)*zq(ispn)
111  if (l <= lmaxi) &
112  call zfzrf(nm,nri,apwfr(1,1,io,l,ias),z,lmmaxi,wfmt(lma,ispn,j))
113  call zfzrf(nm,nro,apwfr(iro,1,io,l,ias),z,lmmaxo,wfmt(npi+lma,ispn,j))
114  end do
115  end do
116  end do
117 end do
118 !$OMP END DO
119 !---------------------------------!
120 ! local-orbital functions !
121 !---------------------------------!
122 p=0
123 do ilo=1,nlorb(is)
124  l=lorbl(ilo,is)
125  do lm=l**2+1,(l+1)**2
126  p=p+1
127  i=idxlo(lm,ilo,ias)
128  if (tevecsv) then
129  do jspn=1,nspnfv
130  n=ngp(jspn)
131  x(1:nstfv,jspn)=evecfv(n+i,1:nstfv,jspn)
132  end do
133 !$OMP DO SCHEDULE(DYNAMIC)
134  do j=1,nst
135  k=merge(j,idx(j),tasv)
136  y(p,1,j)=zdotu(nstfv,evecsv(1,k),1,x,1)
137  if (spinpol) then
138  jspn=jspnfv(2)
139  y(p,2,j)=zdotu(nstfv,evecsv(nstfv+1,k),1,x(1,jspn),1)
140  end if
141  end do
142 !$OMP END DO
143  else
144  do j=1,nst
145  k=merge(j,idx(j),tasv)
146  y(p,1,j)=evecfv(ngp(1)+i,k,1)
147  end do
148  end if
149  end do
150 end do
151 !$OMP DO SCHEDULE(DYNAMIC)
152 do j=1,nst
153  do ispn=1,nspinor
154  p=0
155  do ilo=1,nlorb(is)
156  l=lorbl(ilo,is)
157  nm=2*l+1
158  lma=l**2+1
159  do lm=1,nm
160  p=p+1
161  z(lm)=y(p,ispn,j)
162  end do
163  if (ssdph) z(1:nm)=z(1:nm)*zq(ispn)
164  if (l <= lmaxi) &
165  call zfzrf(nm,nri,lofr(1,1,ilo,ias),z,lmmaxi,wfmt(lma,ispn,j))
166  call zfzrf(nm,nro,lofr(iro,1,ilo,ias),z,lmmaxo,wfmt(npi+lma,ispn,j))
167  end do
168 ! convert to spherical coordinates if required
169  if (.not.tsh) then
170  zfmt(1:np)=wfmt(1:np,ispn,j)
171  call zgemm('N','N',lmmaxi,nri,lmmaxi,zone,zbshti,lmmaxi,zfmt,lmmaxi, &
172  zzero,wfmt(:,ispn,j),lmmaxi)
173  call zgemm('N','N',lmmaxo,nro,lmmaxo,zone,zbshto,lmmaxo,zfmt(ipo),lmmaxo,&
174  zzero,wfmt(ipo,ispn,j),lmmaxo)
175  end if
176  end do
177 end do
178 !$OMP END DO
179 !$OMP END PARALLEL
180 call freethd(nthd)
181 
182 contains
183 
184 pure subroutine zfzrf(m,n,rf,z,ld,zf)
185 implicit none
186 ! arguments
187 integer, intent(in) :: m,n
188 real(8), intent(in) :: rf(lrstp,n)
189 complex(8), intent(in) :: z(m)
190 integer, intent(in) :: ld
191 complex(8), intent(inout) :: zf(ld,n)
192 ! local variables
193 integer i
194 do i=1,m
195  zf(i,1:n)=zf(i,1:n)+z(i)*rf(1,1:n)
196 end do
197 end subroutine
198 
199 end subroutine
200 
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:784
integer, dimension(:,:,:), allocatable idxlo
Definition: modmain.f90:851
real(8), dimension(:,:,:,:), allocatable lofr
Definition: modmain.f90:812
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:912
Definition: modomp.f90:6
complex(8), parameter zone
Definition: modmain.f90:1227
complex(8), dimension(:), allocatable zqss
Definition: modmain.f90:287
integer, dimension(0:maxlapw, maxspecies) apword
Definition: modmain.f90:756
complex(8), parameter zzero
Definition: modmain.f90:1227
logical ssdph
Definition: modmain.f90:285
integer, dimension(maxspecies) npcmti
Definition: modmain.f90:214
integer lmmaxi
Definition: modmain.f90:207
subroutine freethd(nthd)
Definition: modomp.f90:112
subroutine holdthd(nloop, nthd)
Definition: modomp.f90:78
complex(8), dimension(:,:), allocatable zbshto
Definition: modmain.f90:575
real(8), dimension(:,:,:,:,:), allocatable apwfr
Definition: modmain.f90:772
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:794
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
complex(8), dimension(:,:), allocatable zbshti
Definition: modmain.f90:571
integer, dimension(2) jspnfv
Definition: modmain.f90:291
integer, dimension(maxspecies) nrmt
Definition: modmain.f90:150
integer lmaxi
Definition: modmain.f90:205