The Elk Code
oepresk.f90
Go to the documentation of this file.
1 
2 ! Copyright (C) 2002-2007 J. K. Dewhurst, S. Sharma and C. Ambrosch-Draxl.
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 oepresk(ik,vclcv,vclvv)
7 use modmain
8 use modomp
9 implicit none
10 ! arguments
11 integer, intent(in) :: ik
12 complex(8), intent(in) :: vclcv(ncrmax,natmtot,nstsv,nkpt)
13 complex(8), intent(in) :: vclvv(nstsv,nstsv,nkpt)
14 ! local variables
15 integer ist,jst,idm
16 integer is,ia,ias,ic,m
17 integer nrc,nrci,npc,nthd
18 real(8) de
19 complex(8) z1,z2
20 ! automatic arrays
21 complex(4) wfcr(npcmtmax,2),cfmt1(npcmtmax),cvfmt1(npcmtmax,ndmag)
22 ! allocatable arrays
23 complex(8), allocatable :: apwalm(:,:,:,:),evecfv(:,:),evecsv(:,:)
24 complex(4), allocatable :: wfmt(:,:,:,:),wfir(:,:,:)
25 complex(4), allocatable :: cfmt2(:,:),cfir2(:)
26 complex(4), allocatable :: cvfmt2(:,:,:),cvfir2(:,:)
27 ! external functions
28 complex(8), external :: rcfinp,rcfmtinp
29 ! get the eigenvalues/vectors from file for input k-point
30 allocate(evecfv(nmatmax,nstfv),evecsv(nstsv,nstsv))
31 call getevalsv(filext,ik,vkl(:,ik),evalsv(:,ik))
32 call getevecfv(filext,ik,vkl(:,ik),vgkl(:,:,:,ik),evecfv)
33 call getevecsv(filext,ik,vkl(:,ik),evecsv)
34 ! find the matching coefficients
35 allocate(apwalm(ngkmax,apwordmax,lmmaxapw,natmtot))
36 call match(ngk(1,ik),vgkc(:,:,1,ik),gkc(:,1,ik),sfacgk(:,:,1,ik),apwalm)
37 ! calculate the wavefunctions for all states
38 allocate(wfmt(npcmtmax,natmtot,nspinor,nstsv),wfir(ngtot,nspinor,nstsv))
39 call genwfsv_sp(.false.,.false.,nstsv,[0],ngridg,igfft,ngk(1,ik),igkig(:,1,ik),&
40  apwalm,evecfv,evecsv,wfmt,ngtot,wfir)
41 deallocate(apwalm,evecfv,evecsv)
42 call holdthd(nstsv,nthd)
43 !$OMP PARALLEL DEFAULT(SHARED) &
44 !$OMP PRIVATE(cfmt1,cvfmt1,cfmt2,cfir2,cvfmt2,cvfir2) &
45 !$OMP PRIVATE(is,ia,ias,nrc,nrci,npc) &
46 !$OMP PRIVATE(ic,ist,jst,m,z1,z2,idm,de) &
47 !$OMP NUM_THREADS(nthd)
48 !-----------------------------------------------------------!
49 ! core-conduction overlap density and magnetisation !
50 !-----------------------------------------------------------!
51 do is=1,nspecies
52  nrc=nrcmt(is)
53  nrci=nrcmti(is)
54  npc=npcmt(is)
55  do ia=1,natoms(is)
56  ias=idxas(ia,is)
57  ic=0
58  do ist=1,nstsp(is)
59  if (.not.spcore(ist,is)) cycle
60  do m=-ksp(ist,is),ksp(ist,is)-1
61  ic=ic+1
62 ! pass in m-1/2 to wavefcr
63 !$OMP SINGLE
64  call wavefcr(.false.,lradstp,is,ia,ist,m,npcmtmax,wfcr)
65 !$OMP END SINGLE
66 !$OMP DO SCHEDULE(DYNAMIC)
67  do jst=1,nstsv
68  if (evalsv(jst,ik) < efermi) cycle
69  if (spinpol) then
70 ! compute the complex density and magnetisation
71  call gencrm(npc,wfcr,wfcr(:,2),wfmt(:,ias,1,jst),wfmt(:,ias,2,jst),&
72  cfmt1,npcmtmax,cvfmt1)
73  else
74 ! compute the complex density
75  cfmt1(1:npc)=conjg(wfcr(1:npc,1))*wfmt(1:npc,ias,1,jst)
76  end if
77  z1=conjg(vclcv(ic,ias,jst,ik))
78  z2=rcfmtinp(nrc,nrci,wr2cmt(:,is),vxmt(:,ias),cfmt1)
79  z1=z1-conjg(z2)
80  do idm=1,ndmag
81  z2=rcfmtinp(nrc,nrci,wr2cmt(:,is),bxmt(:,ias,idm),cvfmt1(:,idm))
82  z1=z1-conjg(z2)
83  end do
84  de=evalcr(ist,ias)-evalsv(jst,ik)
85  z1=z1*occmax*wkpt(ik)/(de+zi*swidth)
86 ! residuals for exchange potential and field
87 !$OMP CRITICAL(oepresk_)
88  call rcadd(npc,z1,cfmt1,dvxmt(:,ias))
89  do idm=1,ndmag
90  call rcadd(npc,z1,cvfmt1(:,idm),dbxmt(:,ias,idm))
91  end do
92 !$OMP END CRITICAL(oepresk_)
93 ! end loop over jst
94  end do
95 !$OMP END DO
96  end do
97 ! end loop over ist
98  end do
99 ! end loops over atoms and species
100  end do
101 end do
102 !--------------------------------------------------------------!
103 ! valence-conduction overlap density and magnetisation !
104 !--------------------------------------------------------------!
105 allocate(cfmt2(npcmtmax,natmtot),cfir2(ngtot))
106 if (spinpol) then
107  allocate(cvfmt2(npcmtmax,natmtot,ndmag),cvfir2(ngtot,ndmag))
108 end if
109 !$OMP DO SCHEDULE(DYNAMIC)
110 do ist=1,nstsv
111  if (evalsv(ist,ik) > efermi) cycle
112  do jst=1,nstsv
113  if (evalsv(jst,ik) < efermi) cycle
114  if (spinpol) then
115 ! compute the complex density and magnetisation
116  call gencfrm(wfmt(:,:,1,ist),wfmt(:,:,2,ist),wfir(:,1,ist),wfir(:,2,ist),&
117  wfmt(:,:,1,jst),wfmt(:,:,2,jst),wfir(:,1,jst),wfir(:,2,jst),cfmt2,cfir2,&
118  cvfmt2,cvfir2)
119  else
120 ! compute the complex density
121  call gencrho(.false.,.true.,ngtot,wfmt(:,:,:,ist),wfir(:,:,ist), &
122  wfmt(:,:,:,jst),wfir(:,:,jst),cfmt2,cfir2)
123  end if
124  z1=conjg(vclvv(ist,jst,ik))
125  z2=rcfinp(vxmt,vxir,cfmt2,cfir2)
126  z1=z1-conjg(z2)
127  do idm=1,ndmag
128  z2=rcfinp(bxmt(:,:,idm),bxir(:,idm),cvfmt2(:,:,idm),cvfir2(:,idm))
129  z1=z1-conjg(z2)
130  end do
131  de=evalsv(ist,ik)-evalsv(jst,ik)
132  z1=z1*occmax*wkpt(ik)/(de+zi*swidth)
133 ! add to residuals for exchange potential and field
134 !$OMP CRITICAL(oepresk_)
135  call rcfadd(z1,cfmt2,cfir2,dvxmt,dvxir)
136  do idm=1,ndmag
137  call rcfadd(z1,cvfmt2(:,:,idm),cvfir2(:,idm),dbxmt(:,:,idm),dbxir(:,idm))
138  end do
139 !$OMP END CRITICAL(oepresk_)
140 ! end loop over jst
141  end do
142 ! end loop over ist
143 end do
144 !$OMP END DO
145 deallocate(cfmt2,cfir2)
146 if (spinpol) deallocate(cvfmt2,cvfir2)
147 !$OMP END PARALLEL
148 call freethd(nthd)
149 deallocate(wfmt,wfir)
150 
151 contains
152 
153 pure subroutine rcfadd(z,cfmt,cfir,rfmt,rfir)
154 implicit none
155 ! arguments
156 complex(8), intent(in) :: z
157 complex(4), intent(in) :: cfmt(npcmtmax,natmtot),cfir(ngtot)
158 real(8), intent(inout) :: rfmt(npcmtmax,natmtot),rfir(ngtot)
159 ! local variables
160 integer is,ias
161 do ias=1,natmtot
162  is=idxis(ias)
163  call rcadd(npcmt(is),z,cfmt(:,ias),rfmt(:,ias))
164 end do
165 call rcadd(ngtot,z,cfir,rfir)
166 end subroutine
167 
168 pure subroutine rcadd(n,z,cv,rv)
169 implicit none
170 ! arguments
171 integer, intent(in) :: n
172 complex(8), intent(in) :: z
173 complex(4), intent(in) :: cv(n)
174 real(8), intent(out) :: rv(n)
175 ! local variables
176 integer i
177 real(8) a,b
178 a=z%re
179 b=-z%im
180 if (abs(a) > 1.d-12) then
181  if (abs(b) > 1.d-12) then
182  do i=1,n
183  rv(i)=rv(i)+a*real(cv(i))+b*aimag(cv(i))
184  end do
185  else
186  rv(1:n)=rv(1:n)+a*real(cv(1:n))
187  end if
188 else
189  if (abs(b) > 1.d-12) rv(1:n)=rv(1:n)+b*aimag(cv(1:n))
190 end if
191 end subroutine
192 
193 end subroutine
194 
integer nmatmax
Definition: modmain.f90:853
real(8) efermi
Definition: modmain.f90:907
integer, dimension(maxstsp, maxspecies) ksp
Definition: modmain.f90:125
integer, dimension(maxspecies) npcmt
Definition: modmain.f90:214
subroutine getevecsv(fext, ikp, vpl, evecsv)
Definition: getevecsv.f90:7
integer, dimension(3) ngridg
Definition: modmain.f90:386
character(256) filext
Definition: modmain.f90:1301
real(8), dimension(:,:), allocatable evalsv
Definition: modmain.f90:921
integer ngtot
Definition: modmain.f90:390
logical spinpol
Definition: modmain.f90:228
integer lmmaxapw
Definition: modmain.f90:199
subroutine oepresk(ik, vclcv, vclvv)
Definition: oepresk.f90:7
integer, dimension(maxatoms, maxspecies) idxas
Definition: modmain.f90:42
pure subroutine rcfadd(z, cfmt, cfir, rfmt, rfir)
Definition: oepresk.f90:154
subroutine gencfrm(wfmt11, wfmt12, wfir11, wfir12, wfmt21, wfmt22, wfir21, wfir22, crhomt, crhoir, cmagmt, cmagir)
Definition: gencfrm.f90:8
integer ngkmax
Definition: modmain.f90:499
subroutine getevecfv(fext, ikp, vpl, vgpl, evecfv)
Definition: getevecfv.f90:10
subroutine gencrho(tsh, tspc, ngt, wfmt1, wfir1, wfmt2, wfir2, crhomt, crhoir)
Definition: gencrho.f90:7
subroutine getevalsv(fext, ikp, vpl, evalsv_)
Definition: getevalsv.f90:7
subroutine match(ngp, vgpc, gpc, sfacgp, apwalm)
Definition: match.f90:10
Definition: modomp.f90:6
real(8) swidth
Definition: modmain.f90:895
real(8), dimension(:,:), allocatable evalcr
Definition: modmain.f90:937
real(8), dimension(:,:,:), allocatable bxmt
Definition: modmain.f90:1146
real(8), dimension(:), allocatable vxir
Definition: modmain.f90:1146
real(8), dimension(:), allocatable dvxir
Definition: modmain.f90:1148
real(8), dimension(:,:), allocatable bxir
Definition: modmain.f90:1146
complex(8), dimension(:,:,:,:), allocatable sfacgk
Definition: modmain.f90:509
logical, dimension(maxstsp, maxspecies) spcore
Definition: modmain.f90:127
integer, dimension(:,:), allocatable ngk
Definition: modmain.f90:497
real(8), dimension(:), allocatable wkpt
Definition: modmain.f90:475
integer, dimension(:), allocatable igfft
Definition: modmain.f90:406
real(8) occmax
Definition: modmain.f90:901
subroutine genwfsv_sp(tsh, tgp, nst, idx, ngridg_, igfft_, ngp, igpig, apwalm, evecfv, evecsv, wfmt, ld, wfir)
Definition: genwfsv_sp.f90:8
real(8), dimension(:,:,:,:), allocatable vgkl
Definition: modmain.f90:503
pure subroutine wavefcr(tsh, lrstp, is, ia, ist, m, ld, wfcr)
Definition: wavefcr.f90:7
pure subroutine rcadd(n, z, cv, rv)
Definition: oepresk.f90:169
integer lradstp
Definition: modmain.f90:171
integer nspinor
Definition: modmain.f90:267
real(8), dimension(:,:), allocatable dvxmt
Definition: modmain.f90:1148
real(8), dimension(:,:,:,:), allocatable vgkc
Definition: modmain.f90:505
real(8), dimension(:,:), allocatable vkl
Definition: modmain.f90:471
integer, dimension(maxspecies) natoms
Definition: modmain.f90:36
integer apwordmax
Definition: modmain.f90:760
real(8), dimension(:,:,:), allocatable dbxmt
Definition: modmain.f90:1148
real(8), dimension(:,:), allocatable wr2cmt
Definition: modmain.f90:189
integer, dimension(maxatoms *maxspecies) idxis
Definition: modmain.f90:44
pure subroutine gencrm(n, wf11, wf12, wf21, wf22, crho, ld, cmag)
Definition: gencrm.f90:7
real(8), dimension(:,:,:), allocatable gkc
Definition: modmain.f90:507
real(8), dimension(:,:), allocatable dbxir
Definition: modmain.f90:1148
integer nspecies
Definition: modmain.f90:34
subroutine freethd(nthd)
Definition: modomp.f90:106
subroutine holdthd(nloop, nthd)
Definition: modomp.f90:78
integer, dimension(maxspecies) nstsp
Definition: modmain.f90:113
complex(8), parameter zi
Definition: modmain.f90:1240
integer, dimension(maxspecies) nrcmt
Definition: modmain.f90:173
integer, dimension(maxspecies) nrcmti
Definition: modmain.f90:211
real(8), dimension(:,:), allocatable vxmt
Definition: modmain.f90:1146
integer, dimension(:,:,:), allocatable igkig
Definition: modmain.f90:501
integer nstfv
Definition: modmain.f90:887