The Elk Code
 
Loading...
Searching...
No Matches
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
6subroutine genvbmatk(vmt,vir,bmt,bir,ngp,igpig,wfmt,ld,wfgp,vbmat)
7use modmain
8use moddftu
9use modomp
10implicit 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
14real(8), intent(in) :: vmt(npcmtmax,natmtot),vir(ngtc)
15real(8), intent(in) :: bmt(npcmtmax,natmtot,ndmag),bir(ngtc,ndmag)
16integer, intent(in) :: ngp(nspnfv),igpig(ngkmax,nspnfv)
17complex(4), intent(in) :: wfmt(npcmtmax,natmtot,nspinor,nstsv)
18integer, intent(in) :: ld
19complex(4), intent(in) :: wfgp(ld,nspinor,nstsv)
20complex(8), intent(out) :: vbmat(nstsv,nstsv)
21! local variables
22integer ist,jst,nj,ispn,jspn
23integer is,ias,nrc,nrci,nrco
24integer npc,npc2,ipco
25integer ld1,ld2,n,igp,nthd
26! automatic arrays
27complex(4) wfmt1(npcmtmax,2),wfmt2(npcmtmax,2),y(nstsv)
28complex(4) wfir1(ngtc,nspinor),wfir2(ngtc,nspinor),c(ngkmax)
29! external functions
30real(4), external :: sdot
31ld1=npcmtmax*natmtot*nspinor
32ld2=ld*nspinor
33! zero the upper triangular matrix elements
34do jst=1,nstsv
35 vbmat(1:jst,jst)=0.d0
36end do
37call holdthd(nstsv,nthd)
38!$OMP PARALLEL DEFAULT(SHARED) &
39!$OMP PRIVATE(wfmt1,wfmt2,wfir1,wfir2,y,c) &
40!$OMP PRIVATE(jst,nj,ias,is,nrc) &
41!$OMP PRIVATE(nrci,nrco,npc,npc2) &
42!$OMP PRIVATE(ipco,ispn,jspn,igp,n) &
43!$OMP NUM_THREADS(nthd)
44!-------------------------!
45! muffin-tin part !
46!-------------------------!
47!$OMP DO SCHEDULE(DYNAMIC)
48do jst=1,nstsv
49 nj=jst-1
50 do ias=1,natmtot
51 is=idxis(ias)
52 nrc=nrcmt(is)
53 nrci=nrcmti(is)
54 nrco=nrc-nrci
55 npc=npcmt(is)
56 npc2=npc*2
57 ipco=npcmti(is)+1
58! apply local potential and magnetic field to spinor wavefunction
59 if (ncmag) then
60! non-collinear case
61 call vbmk1(npc,vmt(:,ias),bmt(:,ias,1),bmt(:,ias,2),bmt(:,ias,3), &
62 wfmt(:,ias,1,jst),wfmt(:,ias,2,jst),wfmt1,wfmt1(:,2))
63 else
64! collinear case
65 call vbmk2(npc,vmt(:,ias),bmt(:,ias,1),wfmt(:,ias,1,jst), &
66 wfmt(:,ias,2,jst),wfmt1,wfmt1(:,2))
67 end if
68! apply muffin-tin DFT+U potential matrix if required
69 if (dftu /= 0) then
70 if (any(tvmmt(0:lmaxdm,ias))) then
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
104end do
105!$OMP END DO
106!---------------------------!
107! interstitial part !
108!---------------------------!
109!$OMP DO SCHEDULE(DYNAMIC)
110do 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
141end do
142!$OMP END DO
143!$OMP END PARALLEL
144call freethd(nthd)
145! lower triangular part
146do ist=1,nstsv
147 do jst=1,ist-1
148 vbmat(ist,jst)=conjg(vbmat(jst,ist))
149 end do
150end do
151return
152
153contains
154
155pure subroutine vbmk1(n,v,b1,b2,b3,wf11,wf12,wf21,wf22)
156implicit none
157! arguments
158integer, intent(in) :: n
159real(8), intent(in) :: v(n),b1(n),b2(n),b3(n)
160complex(4), intent(in) :: wf11(n),wf12(n)
161complex(4), intent(out) :: wf21(n),wf22(n)
162! local variables
163integer i
164!$OMP SIMD SIMDLEN(8)
165do i=1,n
166 wf21(i)=(v(i)+b3(i))*wf11(i)+cmplx(b1(i),-b2(i),8)*wf12(i)
167 wf22(i)=(v(i)-b3(i))*wf12(i)+cmplx(b1(i),b2(i),8)*wf11(i)
168end do
169end subroutine
170
171pure subroutine vbmk2(n,v,b,wf11,wf12,wf21,wf22)
172implicit none
173! arguments
174integer, intent(in) :: n
175real(8), intent(in) :: v(n),b(n)
176complex(4), intent(in) :: wf11(n),wf12(n)
177complex(4), intent(out) :: wf21(n),wf22(n)
178! local variables
179integer i
180!$OMP SIMD SIMDLEN(8)
181do i=1,n
182 wf21(i)=(v(i)+b(i))*wf11(i)
183 wf22(i)=(v(i)-b(i))*wf12(i)
184end do
185end subroutine
186
187end subroutine
188
pure subroutine cfcmtwr(nr, nri, wr, cfmt)
Definition cfcmtwr.f90:7
subroutine cfftifc(nd, n, sgn, c)
pure subroutine vbmk2(n, v, b, wf11, wf12, wf21, wf22)
subroutine genvbmatk(vmt, vir, bmt, bir, ngp, igpig, wfmt, ld, wfgp, vbmat)
Definition genvbmatk.f90:7
pure subroutine vbmk1(n, v, b1, b2, b3, wf11, wf12, wf21, wf22)
logical, dimension(:,:), allocatable tvmmt
Definition moddftu.f90:26
integer dftu
Definition moddftu.f90:32
complex(4), dimension(:,:,:,:,:), allocatable vmatmto
Definition moddftu.f90:22
integer, parameter lmaxdm
Definition moddftu.f90:13
complex(4), dimension(:,:,:,:,:), allocatable vmatmti
Definition moddftu.f90:22
logical ncmag
Definition modmain.f90:240
complex(4), parameter czero
Definition modmain.f90:1236
integer, dimension(3) ngdgc
Definition modmain.f90:388
integer, dimension(maxspecies) npcmti
Definition modmain.f90:214
integer lmmaxi
Definition modmain.f90:207
integer, dimension(maxspecies) nrcmt
Definition modmain.f90:173
integer, dimension(:), allocatable igfc
Definition modmain.f90:410
integer, dimension(maxatoms *maxspecies) idxis
Definition modmain.f90:44
real(8), dimension(:,:), allocatable wr2cmt
Definition modmain.f90:189
integer, dimension(maxspecies) npcmt
Definition modmain.f90:214
complex(4), parameter cone
Definition modmain.f90:1236
integer, dimension(2) jspnfv
Definition modmain.f90:291
integer lmmaxo
Definition modmain.f90:203
integer, dimension(maxspecies) nrcmti
Definition modmain.f90:211
subroutine holdthd(nloop, nthd)
Definition modomp.f90:78
subroutine freethd(nthd)
Definition modomp.f90:106