The Elk Code
genvbmatk.f90
Go to the documentation of this file.
1 
2 ! Copyright (C) 2014 K. Krieger, 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 genvbmatk(vmt,vir,bmt,bir,ngp,igpig,wfmt,ld,wfgp,vbmat)
7 use modmain
8 use moddftu
9 use modomp
10 implicit none
11 ! arguments
12 ! the potential and field are multiplied by the radial integration weights in
13 ! the muffin-tin and by the characteristic function in the interstitial region
14 real(8), intent(in) :: vmt(npcmtmax,natmtot),vir(ngtc)
15 real(8), intent(in) :: bmt(npcmtmax,natmtot,ndmag),bir(ngtc,ndmag)
16 integer, intent(in) :: ngp(nspnfv),igpig(ngkmax,nspnfv)
17 complex(4), intent(in) :: wfmt(npcmtmax,natmtot,nspinor,nstsv)
18 integer, intent(in) :: ld
19 complex(4), intent(in) :: wfgp(ld,nspinor,nstsv)
20 complex(8), intent(out) :: vbmat(nstsv,nstsv)
21 ! local variables
22 integer ist,jst,nj,ispn,jspn
23 integer is,ias,nrc,nrci,nrco
24 integer npc,npc2,ipco
25 integer ld1,ld2,n,igp,nthd
26 ! automatic arrays
27 complex(4) wfmt1(npcmtmax,2),wfmt2(npcmtmax,2),y(nstsv)
28 complex(4) wfir1(ngtc,nspinor),wfir2(ngtc,nspinor),c(ngkmax)
29 ! external functions
30 real(4), external :: sdot
31 ld1=npcmtmax*natmtot*nspinor
32 ld2=ld*nspinor
33 ! zero the upper triangular matrix elements
34 do jst=1,nstsv
35  vbmat(1:jst,jst)=0.d0
36 end do
37 call holdthd(nstsv,nthd)
38 !$OMP PARALLEL DEFAULT(SHARED) &
39 !$OMP PRIVATE(wfmt1,wfmt2,wfir1,wfir2,y,c) &
40 !$OMP PRIVATE(jst,nj,ias,is,npc,npc2) &
41 !$OMP PRIVATE(nrc,nrci,nrco,ipco) &
42 !$OMP PRIVATE(ispn,jspn,igp,n) &
43 !$OMP NUM_THREADS(nthd)
44 !-------------------------!
45 ! muffin-tin part !
46 !-------------------------!
47 !$OMP DO SCHEDULE(DYNAMIC)
48 do jst=1,nstsv
49  nj=jst-1
50  do ias=1,natmtot
51  is=idxis(ias)
52  npc=npcmt(is)
53  npc2=npc*2
54 ! apply local potential and magnetic field to spinor wavefunction
55  if (ncmag) then
56 ! non-collinear case
57  call vbmk1(npc,vmt(:,ias),bmt(:,ias,1),bmt(:,ias,2),bmt(:,ias,3), &
58  wfmt(:,ias,1,jst),wfmt(:,ias,2,jst),wfmt1,wfmt1(:,2))
59  else
60 ! collinear case
61  call vbmk2(npc,vmt(:,ias),bmt(:,ias,1),wfmt(:,ias,1,jst), &
62  wfmt(:,ias,2,jst),wfmt1,wfmt1(:,2))
63  end if
64 ! apply muffin-tin DFT+U potential matrix if required
65  if (dftu /= 0) then
66  if (any(tvmmt(0:lmaxdm,ias))) then
67  nrc=nrcmt(is)
68  nrci=nrcmti(is)
69  nrco=nrc-nrci
70  ipco=npcmti(is)+1
71 ! multiply wavefunction by radial integration weights
72  wfmt2(1:npc,1)=wfmt(1:npc,ias,1,jst)
73  wfmt2(1:npc,2)=wfmt(1:npc,ias,2,jst)
74  call cfcmtwr(nrc,nrci,wr2cmt(:,is),wfmt2(1,1))
75  call cfcmtwr(nrc,nrci,wr2cmt(:,is),wfmt2(1,2))
76  call cgemm('N','N',lmmaxi,nrci,lmmaxi,cone,vmatmti(1,1,1,1,ias), &
77  lmmaxi,wfmt2(1,1),lmmaxi,cone,wfmt1(1,1),lmmaxi)
78  call cgemm('N','N',lmmaxo,nrco,lmmaxo,cone,vmatmto(1,1,1,1,ias), &
79  lmmaxo,wfmt2(ipco,1),lmmaxo,cone,wfmt1(ipco,1),lmmaxo)
80  call cgemm('N','N',lmmaxi,nrci,lmmaxi,cone,vmatmti(1,1,2,2,ias), &
81  lmmaxi,wfmt2(1,2),lmmaxi,cone,wfmt1(1,2),lmmaxi)
82  call cgemm('N','N',lmmaxo,nrco,lmmaxo,cone,vmatmto(1,1,2,2,ias), &
83  lmmaxo,wfmt2(ipco,2),lmmaxo,cone,wfmt1(ipco,2),lmmaxo)
84  if (ncmag) then
85  call cgemm('N','N',lmmaxi,nrci,lmmaxi,cone,vmatmti(1,1,1,2,ias), &
86  lmmaxi,wfmt2(1,2),lmmaxi,cone,wfmt1(1,1),lmmaxi)
87  call cgemm('N','N',lmmaxo,nrco,lmmaxo,cone,vmatmto(1,1,1,2,ias), &
88  lmmaxo,wfmt2(ipco,2),lmmaxo,cone,wfmt1(ipco,1),lmmaxo)
89  call cgemm('N','N',lmmaxi,nrci,lmmaxi,cone,vmatmti(1,1,2,1,ias), &
90  lmmaxi,wfmt2(1,1),lmmaxi,cone,wfmt1(1,2),lmmaxi)
91  call cgemm('N','N',lmmaxo,nrco,lmmaxo,cone,vmatmto(1,1,2,1,ias), &
92  lmmaxo,wfmt2(ipco,1),lmmaxo,cone,wfmt1(ipco,2),lmmaxo)
93  end if
94  end if
95  end if
96 ! compute the inner products
97  call cgemv('C',npc,nj,cone,wfmt(1,ias,1,1),ld1,wfmt1(1,1),1,czero,y,1)
98  call cgemv('C',npc,nj,cone,wfmt(1,ias,2,1),ld1,wfmt1(1,2),1,cone,y,1)
99  vbmat(1:nj,jst)=vbmat(1:nj,jst)+y(1:nj)
100  vbmat(jst,jst)=vbmat(jst,jst) &
101  +sdot(npc2,wfmt(1,ias,1,jst),1,wfmt1(1,1),1) &
102  +sdot(npc2,wfmt(1,ias,2,jst),1,wfmt1(1,2),1)
103  end do
104 end do
105 !$OMP END DO
106 !---------------------------!
107 ! interstitial part !
108 !---------------------------!
109 !$OMP DO SCHEDULE(DYNAMIC)
110 do jst=1,nstsv
111  nj=jst-1
112 ! Fourier transform wavefunction to real-space
113  do ispn=1,nspinor
114  jspn=jspnfv(ispn)
115  wfir1(1:ngtc,ispn)=0.e0
116  do igp=1,ngp(jspn)
117  wfir1(igfc(igpig(igp,jspn)),ispn)=wfgp(igp,ispn,jst)
118  end do
119  call cfftifc(3,ngdgc,1,wfir1(:,ispn))
120  end do
121 ! apply local potential and magnetic field to spinor wavefunction
122  if (ncmag) then
123 ! non-collinear case
124  call vbmk1(ngtc,vir,bir,bir(:,2),bir(:,3),wfir1,wfir1(:,2),wfir2,wfir2(:,2))
125  else
126 ! collinear case
127  call vbmk2(ngtc,vir,bir,wfir1,wfir1(:,2),wfir2,wfir2(:,2))
128  end if
129  do ispn=1,nspinor
130  jspn=jspnfv(ispn)
131  n=ngp(jspn)
132 ! Fourier transform to G+p-space
133  call cfftifc(3,ngdgc,-1,wfir2(:,ispn))
134  do igp=1,n
135  c(igp)=wfir2(igfc(igpig(igp,jspn)),ispn)
136  end do
137  call cgemv('C',n,nj,cone,wfgp(1,ispn,1),ld2,c,1,czero,y,1)
138  vbmat(1:nj,jst)=vbmat(1:nj,jst)+y(1:nj)
139  vbmat(jst,jst)=vbmat(jst,jst)+sdot(2*n,wfgp(1,ispn,jst),1,c,1)
140  end do
141 end do
142 !$OMP END DO
143 !$OMP END PARALLEL
144 call freethd(nthd)
145 ! lower triangular part
146 do ist=1,nstsv
147  do jst=1,ist-1
148  vbmat(ist,jst)=conjg(vbmat(jst,ist))
149  end do
150 end do
151 
152 contains
153 
154 pure subroutine vbmk1(n,v,b1,b2,b3,wf11,wf12,wf21,wf22)
155 implicit none
156 ! arguments
157 integer, intent(in) :: n
158 real(8), intent(in) :: v(n),b1(n),b2(n),b3(n)
159 complex(4), intent(in) :: wf11(n),wf12(n)
160 complex(4), intent(out) :: wf21(n),wf22(n)
161 ! local variables
162 integer i
163 !$OMP SIMD SIMDLEN(8)
164 do i=1,n
165  wf21(i)=(v(i)+b3(i))*wf11(i)+cmplx(b1(i),-b2(i),8)*wf12(i)
166  wf22(i)=(v(i)-b3(i))*wf12(i)+cmplx(b1(i),b2(i),8)*wf11(i)
167 end do
168 end subroutine
169 
170 pure subroutine vbmk2(n,v,b,wf11,wf12,wf21,wf22)
171 implicit none
172 ! arguments
173 integer, intent(in) :: n
174 real(8), intent(in) :: v(n),b(n)
175 complex(4), intent(in) :: wf11(n),wf12(n)
176 complex(4), intent(out) :: wf21(n),wf22(n)
177 ! local variables
178 integer i
179 !$OMP SIMD SIMDLEN(8)
180 do i=1,n
181  wf21(i)=(v(i)+b(i))*wf11(i)
182  wf22(i)=(v(i)-b(i))*wf12(i)
183 end do
184 end subroutine
185 
186 end subroutine
187 
integer, dimension(maxspecies) npcmt
Definition: modmain.f90:214
integer lmmaxo
Definition: modmain.f90:203
complex(4), dimension(:,:,:,:,:), allocatable vmatmti
Definition: moddftu.f90:22
complex(4), parameter czero
Definition: modmain.f90:1239
Definition: modomp.f90:6
complex(4), parameter cone
Definition: modmain.f90:1239
subroutine cfftifc(nd, n, sgn, c)
Definition: cfftifc_fftw.f90:7
complex(4), dimension(:,:,:,:,:), allocatable vmatmto
Definition: moddftu.f90:22
pure subroutine vbmk2(n, v, b, wf11, wf12, wf21, wf22)
Definition: genvbmatk.f90:171
integer, dimension(:), allocatable igfc
Definition: modmain.f90:410
logical, dimension(:,:), allocatable tvmmt
Definition: moddftu.f90:26
real(8), dimension(:,:), allocatable wr2cmt
Definition: modmain.f90:189
pure subroutine vbmk1(n, v, b1, b2, b3, wf11, wf12, wf21, wf22)
Definition: genvbmatk.f90:155
integer, dimension(maxspecies) npcmti
Definition: modmain.f90:214
integer, dimension(maxatoms *maxspecies) idxis
Definition: modmain.f90:44
integer lmmaxi
Definition: modmain.f90:207
integer dftu
Definition: moddftu.f90:32
integer, dimension(3) ngdgc
Definition: modmain.f90:388
subroutine freethd(nthd)
Definition: modomp.f90:106
subroutine holdthd(nloop, nthd)
Definition: modomp.f90:78
integer, dimension(maxspecies) nrcmt
Definition: modmain.f90:173
integer, dimension(maxspecies) nrcmti
Definition: modmain.f90:211
subroutine genvbmatk(vmt, vir, bmt, bir, ngp, igpig, wfmt, ld, wfgp, vbmat)
Definition: genvbmatk.f90:7
integer, parameter lmaxdm
Definition: moddftu.f90:13
logical ncmag
Definition: modmain.f90:240
pure subroutine cfcmtwr(nr, nri, wr, cfmt)
Definition: cfcmtwr.f90:7
integer, dimension(2) jspnfv
Definition: modmain.f90:291