The Elk Code
 
Loading...
Searching...
No Matches
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
6subroutine oepresk(ik,vclcv,vclvv)
7use modmain
8use modomp
9implicit none
10! arguments
11integer, intent(in) :: ik
12complex(8), intent(in) :: vclcv(ncrmax,natmtot,nstsv,nkpt)
13complex(8), intent(in) :: vclvv(nstsv,nstsv,nkpt)
14! local variables
15integer ist,jst,idm
16integer is,ia,ias,ic,m
17integer nrc,nrci,npc,nthd
18real(8) de
19complex(8) z1,z2
20! automatic arrays
21complex(4) wfcr(npcmtmax,2),cfmt1(npcmtmax),cvfmt1(npcmtmax,ndmag)
22! allocatable arrays
23complex(8), allocatable :: apwalm(:,:,:,:),evecfv(:,:),evecsv(:,:)
24complex(4), allocatable :: wfmt(:,:,:,:),wfir(:,:,:)
25complex(4), allocatable :: cfmt2(:,:),cfir2(:)
26complex(4), allocatable :: cvfmt2(:,:,:),cvfir2(:,:)
27! external functions
28complex(8), external :: rcfinp,rcfmtinp
29! get the eigenvalues/vectors from file for input k-point
30allocate(evecfv(nmatmax,nstfv),evecsv(nstsv,nstsv))
31call getevalsv(filext,ik,vkl(:,ik),evalsv(:,ik))
32call getevecfv(filext,ik,vkl(:,ik),vgkl(:,:,:,ik),evecfv)
33call getevecsv(filext,ik,vkl(:,ik),evecsv)
34! find the matching coefficients
35allocate(apwalm(ngkmax,apwordmax,lmmaxapw,natmtot))
36call match(ngk(1,ik),vgkc(:,:,1,ik),gkc(:,1,ik),sfacgk(:,:,1,ik),apwalm)
37! calculate the wavefunctions for all states
38allocate(wfmt(npcmtmax,natmtot,nspinor,nstsv),wfir(ngtot,nspinor,nstsv))
39call genwfsv_sp(.false.,.false.,nstsv,[0],ngridg,igfft,ngk(1,ik),igkig(:,1,ik),&
40 apwalm,evecfv,evecsv,wfmt,ngtot,wfir)
41deallocate(apwalm,evecfv,evecsv)
42call 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!-----------------------------------------------------------!
51do 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
101end do
102!--------------------------------------------------------------!
103! valence-conduction overlap density and magnetisation !
104!--------------------------------------------------------------!
105allocate(cfmt2(npcmtmax,natmtot),cfir2(ngtot))
106if (spinpol) then
107 allocate(cvfmt2(npcmtmax,natmtot,ndmag),cvfir2(ngtot,ndmag))
108end if
109!$OMP DO SCHEDULE(DYNAMIC)
110do 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
143end do
144!$OMP END DO
145deallocate(cfmt2,cfir2)
146if (spinpol) deallocate(cvfmt2,cvfir2)
147!$OMP END PARALLEL
148call freethd(nthd)
149deallocate(wfmt,wfir)
150
151contains
152
153pure subroutine rcfadd(z,cfmt,cfir,rfmt,rfir)
154implicit none
155! arguments
156complex(8), intent(in) :: z
157complex(4), intent(in) :: cfmt(npcmtmax,natmtot),cfir(ngtot)
158real(8), intent(inout) :: rfmt(npcmtmax,natmtot),rfir(ngtot)
159! local variables
160integer is,ias
161do ias=1,natmtot
162 is=idxis(ias)
163 call rcadd(npcmt(is),z,cfmt(:,ias),rfmt(:,ias))
164end do
165call rcadd(ngtot,z,cfir,rfir)
166end subroutine
167
168pure subroutine rcadd(n,z,cv,rv)
169implicit none
170! arguments
171integer, intent(in) :: n
172complex(8), intent(in) :: z
173complex(4), intent(in) :: cv(n)
174real(8), intent(out) :: rv(n)
175! local variables
176integer i
177real(8) a,b
178a=z%re
179b=-z%im
180if (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
188else
189 if (abs(b) > 1.d-12) rv(1:n)=rv(1:n)+b*aimag(cv(1:n))
190end if
191end subroutine
192
193end subroutine
194
subroutine gencfrm(wfmt11, wfmt12, wfir11, wfir12, wfmt21, wfmt22, wfir21, wfir22, crhomt, crhoir, cmagmt, cmagir)
Definition gencfrm.f90:8
subroutine gencrho(tsh, tspc, ngt, wfmt1, wfir1, wfmt2, wfir2, crhomt, crhoir)
Definition gencrho.f90:7
pure subroutine gencrm(n, wf11, wf12, wf21, wf22, crho, ld, cmag)
Definition gencrm.f90:7
subroutine genwfsv_sp(tsh, tgp, nst, idx, ngridg_, igfft_, ngp, igpig, apwalm, evecfv, evecsv, wfmt, ld, wfir)
Definition genwfsv_sp.f90:8
subroutine getevalsv(fext, ikp, vpl, evalsv_)
Definition getevalsv.f90:7
subroutine getevecfv(fext, ikp, vpl, vgpl, evecfv)
Definition getevecfv.f90:10
subroutine getevecsv(fext, ikp, vpl, evecsv)
Definition getevecsv.f90:7
subroutine match(ngp, vgpc, gpc, sfacgp, apwalm)
Definition match.f90:10
real(8), dimension(:,:,:,:), allocatable vgkc
Definition modmain.f90:505
real(8), dimension(:,:), allocatable evalcr
Definition modmain.f90:934
real(8), dimension(:), allocatable wkpt
Definition modmain.f90:475
integer ngtot
Definition modmain.f90:390
integer, dimension(3) ngridg
Definition modmain.f90:386
real(8), dimension(:,:,:), allocatable gkc
Definition modmain.f90:507
real(8) efermi
Definition modmain.f90:904
integer nspinor
Definition modmain.f90:267
integer, dimension(maxspecies) natoms
Definition modmain.f90:36
character(256) filext
Definition modmain.f90:1300
logical, dimension(maxstsp, maxspecies) spcore
Definition modmain.f90:127
real(8), dimension(:,:), allocatable dbxir
Definition modmain.f90:1145
real(8), dimension(:,:), allocatable bxir
Definition modmain.f90:1143
integer, dimension(maxatoms, maxspecies) idxas
Definition modmain.f90:42
logical spinpol
Definition modmain.f90:228
complex(8), parameter zi
Definition modmain.f90:1239
integer, dimension(:,:), allocatable ngk
Definition modmain.f90:497
integer, dimension(:,:,:), allocatable igkig
Definition modmain.f90:501
integer, dimension(maxspecies) nrcmt
Definition modmain.f90:173
integer, dimension(maxatoms *maxspecies) idxis
Definition modmain.f90:44
integer lradstp
Definition modmain.f90:171
integer, dimension(maxspecies) nstsp
Definition modmain.f90:113
integer lmmaxapw
Definition modmain.f90:199
integer apwordmax
Definition modmain.f90:760
real(8) swidth
Definition modmain.f90:892
real(8), dimension(:,:), allocatable wr2cmt
Definition modmain.f90:189
real(8), dimension(:), allocatable vxir
Definition modmain.f90:1143
real(8), dimension(:,:,:,:), allocatable vgkl
Definition modmain.f90:503
integer, dimension(maxspecies) npcmt
Definition modmain.f90:214
integer, dimension(:), allocatable igfft
Definition modmain.f90:406
integer nmatmax
Definition modmain.f90:848
integer, dimension(maxstsp, maxspecies) ksp
Definition modmain.f90:125
real(8), dimension(:,:,:), allocatable bxmt
Definition modmain.f90:1143
real(8), dimension(:,:), allocatable vkl
Definition modmain.f90:471
integer ngkmax
Definition modmain.f90:499
real(8), dimension(:,:), allocatable dvxmt
Definition modmain.f90:1145
real(8) occmax
Definition modmain.f90:898
real(8), dimension(:,:), allocatable vxmt
Definition modmain.f90:1143
integer nstfv
Definition modmain.f90:884
complex(8), dimension(:,:,:,:), allocatable sfacgk
Definition modmain.f90:509
integer, dimension(maxspecies) nrcmti
Definition modmain.f90:211
integer nspecies
Definition modmain.f90:34
real(8), dimension(:), allocatable dvxir
Definition modmain.f90:1145
real(8), dimension(:,:,:), allocatable dbxmt
Definition modmain.f90:1145
real(8), dimension(:,:), allocatable evalsv
Definition modmain.f90:918
subroutine holdthd(nloop, nthd)
Definition modomp.f90:78
subroutine freethd(nthd)
Definition modomp.f90:106
pure subroutine rcadd(n, z, cv, rv)
Definition oepresk.f90:169
pure subroutine rcfadd(z, cfmt, cfir, rfmt, rfir)
Definition oepresk.f90:154
subroutine oepresk(ik, vclcv, vclvv)
Definition oepresk.f90:7
pure complex(8) function rcfmtinp(nr, nri, wr, rfmt, cfmt)
Definition rcfmtinp.f90:7
pure subroutine wavefcr(tsh, lrstp, is, ia, ist, m, ld, wfcr)
Definition wavefcr.f90:7