The Elk Code
 
Loading...
Searching...
No Matches
genspfxcr.f90
Go to the documentation of this file.
1
2! Copyright (C) 2012 S. Sharma, J. K. Dewhurst 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 genspfxcr(tsh,fxcmt,fxcir)
7use modmain
8use modtddft
9use modfxcifc
10implicit none
11! arguments
12logical, intent(in) :: tsh
13real(8), intent(out) :: fxcmt(npmtmax,natmtot,4,4),fxcir(ngtot,4,4)
14! local variables
15integer idm,is,ias
16integer nr,nri,ir,np,i,j,n
17real(8) t1
18! allocatable arrays
19real(8), allocatable :: rho(:),rhoup(:),rhodn(:)
20real(8), allocatable :: mag(:,:),magu(:,:),magm(:)
21real(8), allocatable :: bxc(:,:),bxcp(:)
22real(8), allocatable :: fxcuu(:),fxcud(:),fxcdd(:)
23real(8), allocatable :: fxc(:,:,:)
24if (.not.spinpol) then
25 write(*,*)
26 write(*,'("Error(genspfxcr): spin-unpolarised calculation")')
27 write(*,*)
28 stop
29end if
30! allocate local arrays
31n=npmtmax
32allocate(rho(n),mag(n,ndmag))
33allocate(bxc(n,ndmag),fxc(n,4,4))
34n=max(n,ngtot)
35allocate(rhoup(n),rhodn(n))
36allocate(magu(3,n),magm(n),bxcp(n))
37allocate(fxcuu(n),fxcud(n),fxcdd(n))
38!---------------------------!
39! muffin-tin kernel !
40!---------------------------!
41do ias=1,natmtot
42 is=idxis(ias)
43 nr=nrmt(is)
44 nri=nrmti(is)
45 np=npmt(is)
46! compute the density in spherical coordinates
47 call rbsht(nr,nri,rhomt(:,ias),rho)
48 do idm=1,ndmag
49! magnetisation in spherical coordinates
50 call rbsht(nr,nri,magmt(:,ias,idm),mag(:,idm))
51! B_xc in spherical coordinates
52 call rbsht(nr,nri,bxcmt(:,ias,idm),bxc(:,idm))
53 end do
54 if (ncmag) then
55! non-collinear (use Kubler's trick)
56 do i=1,np
57! compute |m|
58 magm(i)=sqrt(mag(i,1)**2+mag(i,2)**2+mag(i,3)**2)
59! compute rhoup=(rho+|m|)/2 and rhodn=(rho-|m|)/2
60 rhoup(i)=0.5d0*(rho(i)+magm(i))
61 rhodn(i)=0.5d0*(rho(i)-magm(i))
62! unit vector m/|m|
63 t1=1.d0/(magm(i)+1.d-8)
64 magu(1,i)=t1*mag(i,1)
65 magu(2,i)=t1*mag(i,2)
66 magu(3,i)=t1*mag(i,3)
67! compute B_xc.(m/|m|)
68 bxcp(i)=bxc(i,1)*magu(1,i)+bxc(i,2)*magu(2,i)+bxc(i,3)*magu(3,i)
69 end do
70 else
71! collinear
72 do i=1,np
73! compute |m| = |m_z|
74 magm(i)=abs(mag(i,1))
75! compute rhoup=(rho+|m|)/2 and rhodn=(rho-|m|)/2
76 rhoup(i)=0.5d0*(rho(i)+magm(i))
77 rhodn(i)=0.5d0*(rho(i)-magm(i))
78! unit vector m/|m|
79 magu(1,i)=0.d0
80 magu(2,i)=0.d0
81 if (mag(i,1) > 0.d0) then
82 magu(3,i)=1.d0
83 else
84 magu(3,i)=-1.d0
85 end if
86! compute B_xc.(m/|m|)
87 bxcp(i)=bxc(i,1)*magu(3,i)
88 end do
89 end if
90! compute f_xc in U(2) x U(2) basis
91 call fxcifc(fxctype,n=np,rhoup=rhoup,rhodn=rhodn,fxcuu=fxcuu,fxcud=fxcud, &
92 fxcdd=fxcdd)
93! transform f_xc to O(1) x O(3) basis (upper triangular part)
94 call tfm2213(np,fxcuu,fxcud,fxcdd,magu,magm,bxcp,npmtmax,fxc)
95 do i=1,4
96 do j=i,4
97 if (tsh) then
98! convert to spherical harmonics if required
99 call rfsht(nr,nri,fxc(:,i,j),fxcmt(:,ias,i,j))
100 else
101 fxcmt(1:np,ias,i,j)=fxc(1:np,i,j)
102 end if
103 end do
104 end do
105end do
106!-----------------------------!
107! interstitial kernel !
108!-----------------------------!
109if (ncmag) then
110! non-collinear
111 do ir=1,ngtot
112 magm(ir)=sqrt(magir(ir,1)**2+magir(ir,2)**2+magir(ir,3)**2)
113 rhoup(ir)=0.5d0*(rhoir(ir)+magm(ir))
114 rhodn(ir)=0.5d0*(rhoir(ir)-magm(ir))
115 t1=1.d0/(magm(ir)+1.d-8)
116 magu(1,ir)=t1*magir(ir,1)
117 magu(2,ir)=t1*magir(ir,2)
118 magu(3,ir)=t1*magir(ir,3)
119! compute B_xc.(m/|m|)
120 bxcp(ir)=bxcir(ir,1)*magu(1,ir) &
121 +bxcir(ir,2)*magu(2,ir) &
122 +bxcir(ir,3)*magu(3,ir)
123 end do
124else
125! collinear
126 do ir=1,ngtot
127 magm(ir)=abs(magir(ir,1))
128 rhoup(ir)=0.5d0*(rhoir(ir)+magm(ir))
129 rhodn(ir)=0.5d0*(rhoir(ir)-magm(ir))
130 magu(1,ir)=0.d0
131 magu(2,ir)=0.d0
132 if (magir(ir,1) > 0.d0) then
133 magu(3,ir)=1.d0
134 else
135 magu(3,ir)=-1.d0
136 end if
137! compute B_xc.(m/|m|)
138 bxcp(ir)=bxcir(ir,1)*magu(3,ir)
139 end do
140end if
141! compute f_xc in U(2) x U(2) basis
142call fxcifc(fxctype,n=ngtot,rhoup=rhoup,rhodn=rhodn,fxcuu=fxcuu,fxcud=fxcud, &
143 fxcdd=fxcdd)
144! transform f_xc to O(1) x O(3) basis
145call tfm2213(ngtot,fxcuu,fxcud,fxcdd,magu,magm,bxcp,ngtot,fxcir)
146deallocate(rho,mag,bxc,fxc)
147deallocate(rhoup,rhodn)
148deallocate(magu,magm,bxcp)
149deallocate(fxcuu,fxcud,fxcdd)
150return
151
152contains
153
154pure subroutine tfm2213(n,fxcuu,fxcud,fxcdd,magu,magm,bxcp,ld,fxc)
155implicit none
156! arguments
157integer, intent(in) :: n
158real(8), intent(in) :: fxcuu(n),fxcud(n),fxcdd(n)
159real(8), intent(in) :: magu(3,n),magm(n),bxcp(n)
160integer, intent(in) :: ld
161real(8), intent(out) :: fxc(ld,4,4)
162! local variables
163integer i
164real(8) t1,t2
165do i=1,n
166! charge-charge
167 fxc(i,1,1)=0.25d0*(fxcuu(i)+2.d0*fxcud(i)+fxcdd(i))
168! charge-spin
169 t1=0.25d0*(fxcuu(i)-fxcdd(i))
170 fxc(i,1,2)=t1*magu(1,i)
171 fxc(i,1,3)=t1*magu(2,i)
172 fxc(i,1,4)=t1*magu(3,i)
173! spin-spin
174 if (magm(i) > 1.d-14) then
175 t1=bxcp(i)/magm(i)
176 else
177 t1=0.d0
178 end if
179 t2=0.25d0*(fxcuu(i)-2.d0*fxcud(i)+fxcdd(i))-t1
180 fxc(i,2,2)=t2*magu(1,i)*magu(1,i)+t1
181 fxc(i,2,3)=t2*magu(1,i)*magu(2,i)
182 fxc(i,2,4)=t2*magu(1,i)*magu(3,i)
183 fxc(i,3,3)=t2*magu(2,i)*magu(2,i)+t1
184 fxc(i,3,4)=t2*magu(2,i)*magu(3,i)
185 fxc(i,4,4)=t2*magu(3,i)*magu(3,i)+t1
186end do
187end subroutine
188
189end subroutine
190
subroutine genspfxcr(tsh, fxcmt, fxcir)
Definition genspfxcr.f90:7
pure subroutine tfm2213(n, fxcuu, fxcud, fxcdd, magu, magm, bxcp, ld, fxc)
subroutine fxcifc(fxctype, n, rho, rhoup, rhodn, fxc, fxcuu, fxcud, fxcdd)
Definition modfxcifc.f90:13
integer, dimension(maxspecies) nrmti
Definition modmain.f90:211
real(8), dimension(:,:,:), allocatable bxcmt
Definition modmain.f90:636
logical ncmag
Definition modmain.f90:240
real(8), dimension(:,:,:), pointer, contiguous magmt
Definition modmain.f90:616
integer, dimension(maxspecies) nrmt
Definition modmain.f90:150
real(8), dimension(:), pointer, contiguous rhoir
Definition modmain.f90:614
logical spinpol
Definition modmain.f90:228
real(8), dimension(:,:), allocatable bxcir
Definition modmain.f90:636
integer, dimension(maxatoms *maxspecies) idxis
Definition modmain.f90:44
real(8), dimension(:,:), pointer, contiguous magir
Definition modmain.f90:616
integer, dimension(maxspecies) npmt
Definition modmain.f90:213
real(8), dimension(:,:), pointer, contiguous rhomt
Definition modmain.f90:614
integer ndmag
Definition modmain.f90:238
integer, dimension(3) fxctype
Definition modtddft.f90:12
subroutine rbsht(nr, nri, rfmt1, rfmt2)
Definition rbsht.f90:7
subroutine rfsht(nr, nri, rfmt1, rfmt2)
Definition rfsht.f90:7