The Elk Code
potxcir.f90
Go to the documentation of this file.
1 
2 ! Copyright (C) 2018 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 potxcir(xctype_,rhoir_,magir_,tauir_,exir_,ecir_,vxcir_,bxcir_, &
7  wxcir_)
8 use modmain
9 use modxcifc
10 implicit none
11 ! arguments
12 integer, intent(in) :: xctype_(3)
13 real(8), intent(in) :: rhoir_(ngtot),magir_(ngtot,ndmag),tauir_(ngtot,nspinor)
14 real(8), intent(out) :: exir_(ngtot),ecir_(ngtot)
15 real(8), intent(out) :: vxcir_(ngtot),bxcir_(ngtot,ndmag),wxcir_(ngtot)
16 ! local variables
17 integer n,i
18 real(8) t0,t1,t2,t3,t4
19 ! allocatable arrays
20 real(8), allocatable :: rhoup(:),rhodn(:)
21 real(8), allocatable :: gvrho(:,:),gvup(:,:),gvdn(:,:)
22 real(8), allocatable :: grho(:),gup(:),gdn(:)
23 real(8), allocatable :: g2rho(:),g2up(:),g2dn(:)
24 real(8), allocatable :: g3rho(:),g3up(:),g3dn(:)
25 real(8), allocatable :: grho2(:),gup2(:),gdn2(:),gupdn(:)
26 real(8), allocatable :: vx(:),vxup(:),vxdn(:)
27 real(8), allocatable :: vc(:),vcup(:),vcdn(:)
28 real(8), allocatable :: dxdgr2(:),dxdgu2(:),dxdgd2(:),dxdgud(:)
29 real(8), allocatable :: dcdgr2(:),dcdgu2(:),dcdgd2(:),dcdgud(:)
30 real(8), allocatable :: dxdg2r(:),dxdg2u(:),dxdg2d(:)
31 real(8), allocatable :: dcdg2r(:),dcdg2u(:),dcdg2d(:)
32 real(8), allocatable :: dtdr(:),dtdru(:),dtdrd(:)
33 real(8), allocatable :: wx(:),wxup(:),wxdn(:)
34 real(8), allocatable :: wc(:),wcup(:),wcdn(:)
35 n=ngtot
36 if (spinpol) then
37  allocate(rhoup(n),rhodn(n))
38  allocate(vxup(n),vxdn(n),vcup(n),vcdn(n))
39  if (xcgrad == 1) then
40  allocate(grho(n),gup(n),gdn(n))
41  allocate(g2up(n),g2dn(n))
42  allocate(g3rho(n),g3up(n),g3dn(n))
43  else if (xcgrad == 2) then
44  allocate(g2up(n),g2dn(n))
45  allocate(gvup(n,3),gvdn(n,3))
46  allocate(gup2(n),gdn2(n),gupdn(n))
47  allocate(dxdgu2(n),dxdgd2(n),dxdgud(n))
48  allocate(dcdgu2(n),dcdgd2(n),dcdgud(n))
49  else if (any(xcgrad == [3,4,5,6])) then
50  allocate(g2up(n),g2dn(n))
51  allocate(gvup(n,3),gvdn(n,3))
52  allocate(gup2(n),gdn2(n),gupdn(n))
53  allocate(dxdgu2(n),dxdgd2(n),dxdgud(n))
54  allocate(dcdgu2(n),dcdgd2(n),dcdgud(n))
55  allocate(dxdg2u(n),dxdg2d(n))
56  allocate(dcdg2u(n),dcdg2d(n))
57  allocate(dtdru(n),dtdrd(n))
58  allocate(wxup(n),wxdn(n),wcup(n),wcdn(n))
59  end if
60 else
61  allocate(vx(n),vc(n))
62  if (xcgrad == 1) then
63  allocate(grho(n),g2rho(n),g3rho(n))
64  else if (xcgrad == 2) then
65  allocate(g2rho(n),gvrho(n,3),grho2(n))
66  allocate(dxdgr2(n),dcdgr2(n))
67  else if (any(xcgrad == [3,4,5,6])) then
68  allocate(g2rho(n),gvrho(n,3),grho2(n))
69  allocate(dxdgr2(n),dcdgr2(n))
70  allocate(dxdg2r(n),dcdg2r(n))
71  allocate(dtdr(n),wx(n),wc(n))
72  end if
73 end if
74 if (spinpol) then
75 !------------------------!
76 ! spin-polarised !
77 !------------------------!
78  if (ncmag) then
79 ! non-collinear
80  if (xcgrad == 0) then
81 ! LSDA
82  do i=1,n
83  t0=rhoir_(i)
84  t1=sqrt(magir_(i,1)**2+magir_(i,2)**2+magir_(i,3)**2)*sxcscf
85  rhoup(i)=0.5d0*(t0+t1)
86  rhodn(i)=0.5d0*(t0-t1)
87  end do
88  else
89 ! functionals which require gradients
90  do i=1,n
91  t0=rhoir_(i)
92  t1=sqrt(magir_(i,1)**2+magir_(i,2)**2+magir_(i,3)**2+dncgga)*sxcscf
93  rhoup(i)=0.5d0*(t0+t1)
94  rhodn(i)=0.5d0*(t0-t1)
95  end do
96  end if
97  else
98 ! collinear
99  do i=1,n
100  t0=rhoir_(i)
101  t1=magir_(i,1)*sxcscf
102  rhoup(i)=0.5d0*(t0+t1)
103  rhodn(i)=0.5d0*(t0-t1)
104  end do
105  end if
106  if (xcgrad < 1) then
107 ! LSDA
108  call xcifc(xctype_,n,tempa=swidth,rhoup=rhoup,rhodn=rhodn,ex=exir_, &
109  ec=ecir_,vxup=vxup,vxdn=vxdn,vcup=vcup,vcdn=vcdn)
110  else if (xcgrad == 1) then
111 ! GGA
112  call ggair_sp_1(rhoup,rhodn,grho,gup,gdn,g2up,g2dn,g3rho,g3up,g3dn)
113  call xcifc(xctype_,n,rhoup=rhoup,rhodn=rhodn,grho=grho,gup=gup,gdn=gdn, &
114  g2up=g2up,g2dn=g2dn,g3rho=g3rho,g3up=g3up,g3dn=g3dn,ex=exir_,ec=ecir_, &
115  vxup=vxup,vxdn=vxdn,vcup=vcup,vcdn=vcdn)
116  else if (xcgrad == 2) then
117 ! GGA
118  call ggair_sp_2a(rhoup,rhodn,g2up,g2dn,gvup,gvdn,gup2,gdn2,gupdn)
119  call xcifc(xctype_,n,rhoup=rhoup,rhodn=rhodn,gup2=gup2,gdn2=gdn2, &
120  gupdn=gupdn,ex=exir_,ec=ecir_,vxup=vxup,vxdn=vxdn,vcup=vcup,vcdn=vcdn, &
121  dxdgu2=dxdgu2,dxdgd2=dxdgd2,dxdgud=dxdgud,dcdgu2=dcdgu2,dcdgd2=dcdgd2, &
122  dcdgud=dcdgud)
123  call ggair_sp_2b(g2up,g2dn,gvup,gvdn,vxup,vxdn,vcup,vcdn,dxdgu2,dxdgd2, &
124  dxdgud,dcdgu2,dcdgd2,dcdgud)
125  else if (any(xcgrad == [3,4,5])) then
126 ! meta-GGA with energy
127  call ggair_sp_2a(rhoup,rhodn,g2up,g2dn,gvup,gvdn,gup2,gdn2,gupdn)
128 ! enforce the von Weizsacker lower bound
129  call k_vwlb(n,rhoup,gup2,tauir_(:,1))
130  call k_vwlb(n,rhodn,gdn2,tauir_(:,2))
131  call xcifc(xctype_,n,rhoup=rhoup,rhodn=rhodn,g2up=g2up,g2dn=g2dn, &
132  gup2=gup2,gdn2=gdn2,gupdn=gupdn,tauup=tauir_(:,1),taudn=tauir_(:,2), &
133  ex=exir_,ec=ecir_,vxup=vxup,vxdn=vxdn,vcup=vcup,vcdn=vcdn,dxdgu2=dxdgu2, &
134  dxdgd2=dxdgd2,dxdgud=dxdgud,dcdgu2=dcdgu2,dcdgd2=dcdgd2,dcdgud=dcdgud, &
135  dxdg2u=dxdg2u,dxdg2d=dxdg2d,dcdg2u=dcdg2u,dcdg2d=dcdg2d,wxup=wxup, &
136  wxdn=wxdn,wcup=wcup,wcdn=wcdn)
137  call ggair_sp_2b(g2up,g2dn,gvup,gvdn,vxup,vxdn,vcup,vcdn,dxdgu2,dxdgd2, &
138  dxdgud,dcdgu2,dcdgd2,dcdgud)
139 ! determine δτ(r')/δρ(r) using an approximate kinetic energy density functional
140  if (any(xcgrad == [4,5])) then
141  call xcifc(ktype,n,rhoup=rhoup,rhodn=rhodn,g2up=g2up,g2dn=g2dn,gup2=gup2,&
142  gdn2=gdn2,tauup=tauir_(:,1),taudn=tauir_(:,2),dtdru=dtdru,dtdrd=dtdrd, &
143  dtdgu2=dxdgu2,dtdgd2=dxdgd2,dtdg2u=dxdg2u,dtdg2d=dxdg2d,wxup=dcdgu2, &
144  wxdn=dcdgd2)
145  call ggair_4(gvup,vxup,vcup,wxup,wcup,dtdru,dxdgu2)
146  call ggair_4(gvdn,vxdn,vcdn,wxdn,wcdn,dtdrd,dxdgd2)
147  if (kgrad == 3) then
148  call ggair_3(vxup,vcup,wxup,wcup,dxdg2u)
149  call ggair_3(vxdn,vcdn,wxdn,wcdn,dxdg2d)
150  end if
151  wxcir_(1:n)=0.5d0*(wxup(1:n)+wxdn(1:n)+wcup(1:n)+wcdn(1:n))
152  end if
153  else if (xcgrad == 6) then
154 ! potential-only meta-GGA
155  call ggair_sp_2a(rhoup,rhodn,g2up,g2dn,gvup,gvdn,gup2,gdn2,gupdn)
156  call xcifc(xctype_,n,c_tb09=c_tb09,rhoup=rhoup,rhodn=rhodn,g2up=g2up, &
157  g2dn=g2dn,gup2=gup2,gdn2=gdn2,gupdn=gupdn,tauup=tauir_(:,1), &
158  taudn=tauir_(:,2),vxup=vxup,vxdn=vxdn,vcup=vcup,vcdn=vcdn,dxdgu2=dxdgu2, &
159  dxdgd2=dxdgd2,dxdgud=dxdgud,dcdgu2=dcdgu2,dcdgd2=dcdgd2,dcdgud=dcdgud, &
160  dxdg2u=dxdg2u,dxdg2d=dxdg2d,dcdg2u=dcdg2u,dcdg2d=dcdg2d,wxup=wxup, &
161  wxdn=wxdn,wcup=wcup,wcdn=wcdn)
162  exir_(1:n)=0.d0; ecir_(1:n)=0.d0
163  wxcir_(1:n)=0.d0
164  end if
165 ! hybrid functionals
166  if (hybrid) then
167  t1=1.d0-hybridc
168 ! scale exchange part of energy
169  exir_(1:n)=t1*exir_(1:n)
170 ! scale exchange part of potential
171  vxup(1:n)=t1*vxup(1:n)
172  vxdn(1:n)=t1*vxdn(1:n)
173  end if
174  if (ncmag) then
175 ! non-collinear: spin rotate the local exchange potential
176  do i=1,n
177  t1=vxup(i)+vcup(i)
178  t2=vxdn(i)+vcdn(i)
179  vxcir_(i)=0.5d0*(t1+t2)
180 ! determine the exchange-correlation magnetic field
181  t3=0.5d0*(t1-t2)
182  t4=rhoup(i)-rhodn(i)
183  if (abs(t4) > 1.d-8) t4=t3/t4
184  bxcir_(i,1:ndmag)=magir_(i,1:ndmag)*t4
185  end do
186  else
187 ! collinear
188  do i=1,n
189  t1=vxup(i)+vcup(i)
190  t2=vxdn(i)+vcdn(i)
191  vxcir_(i)=0.5d0*(t1+t2)
192  bxcir_(i,1)=0.5d0*(t1-t2)
193  end do
194  end if
195 ! scale field if required
196  if (tssxc) bxcir_(1:n,1:ndmag)=bxcir_(1:n,1:ndmag)*sxcscf
197 else
198 !--------------------------!
199 ! spin-unpolarised !
200 !--------------------------!
201  if (xcgrad < 1) then
202  call xcifc(xctype_,n,tempa=swidth,rho=rhoir_,ex=exir_,ec=ecir_,vx=vx,vc=vc)
203  else if (xcgrad == 1) then
204  call ggair_1(rhoir_,grho,g2rho,g3rho)
205  call xcifc(xctype_,n,rho=rhoir_,grho=grho,g2rho=g2rho,g3rho=g3rho,ex=exir_,&
206  ec=ecir_,vx=vx,vc=vc)
207  else if (xcgrad == 2) then
208  call ggair_2a(rhoir_,g2rho,gvrho,grho2)
209  call xcifc(xctype_,n,rho=rhoir_,grho2=grho2,ex=exir_,ec=ecir_,vx=vx,vc=vc, &
210  dxdgr2=dxdgr2,dcdgr2=dcdgr2)
211  call ggair_2b(g2rho,gvrho,vx,vc,dxdgr2,dcdgr2)
212  else if (any(xcgrad == [3,4,5])) then
213  call ggair_2a(rhoir_,g2rho,gvrho,grho2)
214 ! enforce the von Weizsacker lower bound
215  call k_vwlb(n,rhoir_,grho2,tauir_)
216  call xcifc(xctype_,n,rho=rhoir_,g2rho=g2rho,grho2=grho2,tau=tauir_, &
217  ex=exir_,ec=ecir_,vx=vx,vc=vc,dxdgr2=dxdgr2,dcdgr2=dcdgr2,dxdg2r=dxdg2r, &
218  dcdg2r=dcdg2r,wx=wx,wc=wc)
219  call ggair_2b(g2rho,gvrho,vx,vc,dxdgr2,dcdgr2)
220 ! determine δτ(r')/δρ(r) using an approximate kinetic energy density functional
221  if (any(xcgrad == [4,5])) then
222  call xcifc(ktype,n,rho=rhoir_,g2rho=g2rho,grho2=grho2,tau=tauir_, &
223  dtdr=dtdr,dtdgr2=dxdgr2,dtdg2r=dxdg2r,wx=dcdgr2)
224  call ggair_4(gvrho,vx,vc,wx,wc,dtdr,dxdgr2)
225  if (kgrad == 3) then
226  call ggair_3(vx,vc,wx,wc,dxdg2r)
227  end if
228  wxcir_(1:n)=wx(1:n)+wc(1:n)
229  end if
230  else if (xcgrad == 6) then
231  call ggair_2a(rhoir_,g2rho,gvrho,grho2)
232  call xcifc(xctype_,n,c_tb09=c_tb09,rho=rhoir_,g2rho=g2rho,grho2=grho2, &
233  tau=tauir_,vx=vx,vc=vc,dxdgr2=dxdgr2,dcdgr2=dcdgr2,dxdg2r=dxdg2r, &
234  dcdg2r=dcdg2r,wx=wx,wc=wc)
235  exir_(1:n)=0.d0; ecir_(1:n)=0.d0
236  wxcir_(1:n)=0.d0
237  end if
238 ! hybrid functionals
239  if (hybrid) then
240  t1=1.d0-hybridc
241 ! scale exchange part of energy
242  exir_(1:n)=t1*exir_(1:n)
243 ! scale exchange part of potential
244  vxcir_(1:n)=t1*vx(1:n)+vc(1:n)
245  else
246  vxcir_(1:n)=vx(1:n)+vc(1:n)
247  end if
248 end if
249 if (spinpol) then
250  deallocate(rhoup,rhodn,vxup,vxdn,vcup,vcdn)
251  if (xcgrad == 1) then
252  deallocate(grho,gup,gdn,g2up,g2dn,g3rho,g3up,g3dn)
253  else if (xcgrad == 2) then
254  deallocate(g2up,g2dn)
255  deallocate(gvup,gvdn)
256  deallocate(gup2,gdn2,gupdn)
257  deallocate(dxdgu2,dxdgd2,dxdgud)
258  deallocate(dcdgu2,dcdgd2,dcdgud)
259  else if (any(xcgrad == [3,4,5,6])) then
260  deallocate(g2up,g2dn)
261  deallocate(gvup,gvdn)
262  deallocate(gup2,gdn2,gupdn)
263  deallocate(dxdgu2,dxdgd2,dxdgud)
264  deallocate(dcdgu2,dcdgd2,dcdgud)
265  deallocate(dxdg2u,dxdg2d)
266  deallocate(dcdg2u,dcdg2d)
267  deallocate(dtdru,dtdrd)
268  deallocate(wxup,wxdn,wcup,wcdn)
269  end if
270 else
271  deallocate(vx,vc)
272  if (xcgrad == 1) then
273  deallocate(grho,g2rho,g3rho)
274  else if (xcgrad == 2) then
275  deallocate(g2rho,gvrho,grho2)
276  deallocate(dxdgr2,dcdgr2)
277  else if (any(xcgrad == [3,4,5,6])) then
278  deallocate(g2rho,gvrho,grho2)
279  deallocate(dxdgr2,dcdgr2,dxdg2r,dcdg2r)
280  deallocate(dtdr,wx,wc)
281  end if
282 end if
283 end subroutine
284 
subroutine ggair_2a(rho, g2rho, gvrho, grho2)
Definition: ggair_2a.f90:10
subroutine ggair_sp_2b(g2up, g2dn, gvup, gvdn, vxup, vxdn, vcup, vcdn, dxdgu2, dxdgd2, dxdgud, dcdgu2, dcdgd2, dcdgud)
Definition: ggair_sp_2b.f90:11
integer, dimension(3) ktype
Definition: modmain.f90:606
pure subroutine k_vwlb(n, rho, grho2, tau)
Definition: k_vwlb.f90:7
subroutine ggair_4(gvrho, vx, vc, wx, wc, dtdr, dtdgr2)
Definition: ggair_4.f90:7
subroutine ggair_sp_1(rhoup, rhodn, grho, gup, gdn, g2up, g2dn, g3rho, g3up, g3dn)
Definition: ggair_sp_1.f90:10
subroutine ggair_2b(g2rho, gvrho, vx, vc, dxdgr2, dcdgr2)
Definition: ggair_2b.f90:10
logical spinpol
Definition: modmain.f90:228
logical hybrid
Definition: modmain.f90:1152
real(8) sxcscf
Definition: modmain.f90:668
real(8) swidth
Definition: modmain.f90:895
real(8) dncgga
Definition: modmain.f90:604
logical tssxc
Definition: modmain.f90:666
subroutine ggair_3(vx, vc, wx, wc, dtdg2r)
Definition: ggair_3.f90:7
real(8) c_tb09
Definition: modmain.f90:678
integer kgrad
Definition: modmain.f90:610
subroutine ggair_sp_2a(rhoup, rhodn, g2up, g2dn, gvup, gvdn, gup2, gdn2, gupdn)
Definition: ggair_sp_2a.f90:10
subroutine ggair_1(rho, grho, g2rho, g3rho)
Definition: ggair_1.f90:10
logical ncmag
Definition: modmain.f90:240
subroutine potxcir(xctype_, rhoir_, magir_, tauir_, exir_, ecir_, vxcir_, bxcir_, wxcir_)
Definition: potxcir.f90:8
subroutine xcifc(xctype, n, c_tb09, tempa, rho, rhoup, rhodn, grho, gup, gdn, g2rho, g2up, g2dn, g3rho, g3up, g3dn, grho2, gup2, gdn2, gupdn, tau, tauup, taudn, ex, ec, vx, vc, vxup, vxdn, vcup, vcdn, dxdgr2, dxdgu2, dxdgd2, dxdgud, dcdgr2, dcdgu2, dcdgd2, dcdgud, dxdg2r, dxdg2u, dxdg2d, dcdg2r, dcdg2u, dcdg2d, wx, wxup, wxdn, wc, wcup, wcdn, dtdr, dtdru, dtdrd, dtdgr2, dtdgu2, dtdgd2, dtdg2r, dtdg2u, dtdg2d)
Definition: modxcifc.f90:20
real(8) hybridc
Definition: modmain.f90:1154
integer xcgrad
Definition: modmain.f90:602