The Elk Code
wfmtsv_sp.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_sp(tsh,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) :: 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(4), intent(out) :: wfmt(ld,nspinor,nst)
17 ! local variables
18 logical tasv
19 integer io,ilo,ispn,jspn
20 integer nrc,nrci,nrco,irco
21 integer npc,npci,ipco
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(4) cfmt(npcmtmax),c(2*lmaxo+1)
28 ! external functions
29 complex(8), external :: zdotu
30 nrc=nrcmt(is)
31 nrci=nrcmti(is)
32 nrco=nrc-nrci
33 irco=nrci+1
34 npc=npcmt(is)
35 npci=npcmti(is)
36 ipco=npci+1
37 ! de-phasing factor for spin-spirals
38 if (ssdph) then
39  zq(1)=zqss(ias)
40  zq(2)=conjg(zq(1))
41 end if
42 ! check if all the second-variational wavefunctions should be calculated
43 tasv=(idx(1) == 0)
44 call holdthd(nst,nthd)
45 !-----------------------!
46 ! APW functions !
47 !-----------------------!
48 !$OMP PARALLEL DEFAULT(SHARED) &
49 !$OMP PRIVATE(cfmt,c,p,l,lma,lmb,io,lm) &
50 !$OMP PRIVATE(ispn,jspn,n,i,j,k,nm,ilo) &
51 !$OMP NUM_THREADS(nthd)
52 p=0
53 do l=0,lmaxo
54  lma=l**2+1; lmb=lma+2*l
55  do io=1,apword(l,is)
56  do lm=lma,lmb
57  p=p+1
58  if (tevecsv) then
59  do jspn=1,nspnfv
60  n=ngp(jspn)
61 !$OMP DO SCHEDULE(DYNAMIC)
62  do j=1,nstfv
63  x(j,jspn)=zdotu(n,evecfv(:,j,jspn),1,apwalm(:,io,lm,ias,jspn),1)
64  end do
65 !$OMP END DO
66  end do
67 ! loop only over required states
68 !$OMP DO SCHEDULE(DYNAMIC)
69  do j=1,nst
70 ! index to state in evecsv
71  k=merge(j,idx(j),tasv)
72  y(p,1,j)=zdotu(nstfv,evecsv(1,k),1,x,1)
73  if (spinpol) then
74  jspn=jspnfv(2)
75  y(p,2,j)=zdotu(nstfv,evecsv(nstfv+1,k),1,x(1,jspn),1)
76  end if
77  end do
78 !$OMP END DO
79  else
80 !$OMP DO SCHEDULE(DYNAMIC)
81  do j=1,nst
82  k=merge(j,idx(j),tasv)
83  y(p,1,j)=zdotu(ngp(1),evecfv(:,k,1),1,apwalm(:,io,lm,ias,1),1)
84  end do
85 !$OMP END DO
86  end if
87  end do
88  end do
89 end do
90 !$OMP DO SCHEDULE(DYNAMIC)
91 do j=1,nst
92  wfmt(1:npc,1:nspinor,j)=0.e0
93  do ispn=1,nspinor
94  p=0
95  do l=0,lmaxo
96  nm=2*l+1
97  lma=l**2+1
98  do io=1,apword(l,is)
99  do lm=1,nm
100  p=p+1
101  c(lm)=y(p,ispn,j)
102  end do
103  if (ssdph) c(1:nm)=c(1:nm)*zq(ispn)
104  if (l <= lmaxi) &
105  call cfcrf(nm,nrci,apwfr_sp(1,io,l,ias),c,lmmaxi,wfmt(lma,ispn,j))
106  call cfcrf(nm,nrco,apwfr_sp(irco,io,l,ias),c,lmmaxo, &
107  wfmt(npci+lma,ispn,j))
108  end do
109  end do
110  end do
111 end do
112 !$OMP END DO
113 !---------------------------------!
114 ! local-orbital functions !
115 !---------------------------------!
116 p=0
117 do ilo=1,nlorb(is)
118  l=lorbl(ilo,is)
119  do lm=l**2+1,(l+1)**2
120  p=p+1
121  i=idxlo(lm,ilo,ias)
122  if (tevecsv) then
123  do jspn=1,nspnfv
124  n=ngp(jspn)
125  x(1:nstfv,jspn)=evecfv(n+i,1:nstfv,jspn)
126  end do
127 !$OMP DO SCHEDULE(DYNAMIC)
128  do j=1,nst
129  k=merge(j,idx(j),tasv)
130  y(p,1,j)=zdotu(nstfv,evecsv(1,k),1,x,1)
131  if (spinpol) then
132  jspn=jspnfv(2)
133  y(p,2,j)=zdotu(nstfv,evecsv(nstfv+1,k),1,x(1,jspn),1)
134  end if
135  end do
136 !$OMP END DO
137  else
138  do j=1,nst
139  k=merge(j,idx(j),tasv)
140  y(p,1,j)=evecfv(ngp(1)+i,k,1)
141  end do
142  end if
143  end do
144 end do
145 !$OMP DO SCHEDULE(DYNAMIC)
146 do j=1,nst
147  do ispn=1,nspinor
148  p=0
149  do ilo=1,nlorb(is)
150  l=lorbl(ilo,is)
151  nm=2*l+1
152  lma=l**2+1
153  do lm=1,nm
154  p=p+1
155  c(lm)=y(p,ispn,j)
156  end do
157  if (ssdph) c(1:nm)=c(1:nm)*zq(ispn)
158  if (l <= lmaxi) &
159  call cfcrf(nm,nrci,lofr_sp(1,ilo,ias),c,lmmaxi,wfmt(lma,ispn,j))
160  call cfcrf(nm,nrco,lofr_sp(irco,ilo,ias),c,lmmaxo,wfmt(npci+lma,ispn,j))
161  end do
162 ! convert to spherical coordinates if required
163  if (.not.tsh) then
164  cfmt(1:npc)=wfmt(1:npc,ispn,j)
165  call cgemm('N','N',lmmaxi,nrci,lmmaxi,cone,cbshti,lmmaxi,cfmt,lmmaxi, &
166  czero,wfmt(:,ispn,j),lmmaxi)
167  call cgemm('N','N',lmmaxo,nrco,lmmaxo,cone,cbshto,lmmaxo,cfmt(ipco), &
168  lmmaxo,czero,wfmt(ipco,ispn,j),lmmaxo)
169  end if
170  end do
171 end do
172 !$OMP END DO
173 !$OMP END PARALLEL
174 call freethd(nthd)
175 
176 contains
177 
178 pure subroutine cfcrf(m,n,rf,c,ld,cf)
179 implicit none
180 ! arguments
181 integer, intent(in) :: m,n
182 real(4), intent(in) :: rf(n)
183 complex(4), intent(in) :: c(m)
184 integer, intent(in) :: ld
185 complex(4), intent(inout) :: cf(ld,n)
186 ! local variables
187 integer i
188 do i=1,m
189  cf(i,1:n)=cf(i,1:n)+c(i)*rf(1:n)
190 end do
191 end subroutine
192 
193 end subroutine
194 
integer, dimension(maxspecies) npcmt
Definition: modmain.f90:214
integer, dimension(maxspecies) nlorb
Definition: modmain.f90:784
integer, dimension(:,:,:), allocatable idxlo
Definition: modmain.f90:851
integer lmmaxo
Definition: modmain.f90:203
logical spinpol
Definition: modmain.f90:228
complex(4), parameter czero
Definition: modmain.f90:1226
logical tevecsv
Definition: modmain.f90:912
real(4), dimension(:,:,:), allocatable lofr_sp
Definition: modmain.f90:814
Definition: modomp.f90:6
complex(4), parameter cone
Definition: modmain.f90:1226
complex(8), dimension(:), allocatable zqss
Definition: modmain.f90:287
integer, dimension(0:maxlapw, maxspecies) apword
Definition: modmain.f90:756
logical ssdph
Definition: modmain.f90:285
integer, dimension(maxspecies) npcmti
Definition: modmain.f90:214
integer lmmaxi
Definition: modmain.f90:207
real(4), dimension(:,:,:,:), allocatable apwfr_sp
Definition: modmain.f90:774
subroutine wfmtsv_sp(tsh, is, ias, nst, idx, ngp, apwalm, evecfv, evecsv, ld, wfmt)
Definition: wfmtsv_sp.f90:7
complex(4), dimension(:,:), allocatable cbshti
Definition: modmain.f90:579
subroutine freethd(nthd)
Definition: modomp.f90:112
subroutine holdthd(nloop, nthd)
Definition: modomp.f90:78
complex(4), dimension(:,:), allocatable cbshto
Definition: modmain.f90:580
integer, dimension(maxspecies) nrcmt
Definition: modmain.f90:173
integer, dimension(maxspecies) nrcmti
Definition: modmain.f90:211
integer, dimension(maxlorb, maxspecies) lorbl
Definition: modmain.f90:794
pure subroutine cfcrf(m, n, rf, c, ld, cf)
Definition: wfmtsv_sp.f90:179
integer, dimension(2) jspnfv
Definition: modmain.f90:291
integer lmaxi
Definition: modmain.f90:205