The Elk Code
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 
6 subroutine genspfxcr(tsh,fxcmt,fxcir)
7 use modmain
8 use modtddft
9 use modfxcifc
10 implicit none
11 ! arguments
12 logical, intent(in) :: tsh
13 real(8), intent(out) :: fxcmt(npmtmax,natmtot,4,4),fxcir(ngtot,4,4)
14 ! local variables
15 integer idm,is,ias
16 integer nr,nri,ir,np,i,j,n
17 real(8) t1
18 ! allocatable arrays
19 real(8), allocatable :: rho(:),rhoup(:),rhodn(:)
20 real(8), allocatable :: mag(:,:),magu(:,:),magm(:)
21 real(8), allocatable :: bxc(:,:),bxcp(:)
22 real(8), allocatable :: fxcuu(:),fxcud(:),fxcdd(:)
23 real(8), allocatable :: fxc(:,:,:)
24 if (.not.spinpol) then
25  write(*,*)
26  write(*,'("Error(genspfxcr): spin-unpolarised calculation")')
27  write(*,*)
28  stop
29 end if
30 ! allocate local arrays
31 n=npmtmax
32 allocate(rho(n),mag(n,ndmag))
33 allocate(bxc(n,ndmag),fxc(n,4,4))
34 n=max(n,ngtot)
35 allocate(rhoup(n),rhodn(n))
36 allocate(magu(3,n),magm(n),bxcp(n))
37 allocate(fxcuu(n),fxcud(n),fxcdd(n))
38 !---------------------------!
39 ! muffin-tin kernel !
40 !---------------------------!
41 do 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 ρ↑=(ρ+|m|)/2 and ρ↓=(ρ-|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 ρ↑=(ρ+|m|)/2 and ρ↓=(ρ-|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
105 end do
106 !-----------------------------!
107 ! interstitial kernel !
108 !-----------------------------!
109 if (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
124 else
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
140 end if
141 ! compute f_xc in U(2) x U(2) basis
142 call 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
145 call tfm2213(ngtot,fxcuu,fxcud,fxcdd,magu,magm,bxcp,ngtot,fxcir)
146 deallocate(rho,mag,bxc,fxc)
147 deallocate(rhoup,rhodn)
148 deallocate(magu,magm,bxcp)
149 deallocate(fxcuu,fxcud,fxcdd)
150 
151 contains
152 
153 pure subroutine tfm2213(n,fxcuu,fxcud,fxcdd,magu,magm,bxcp,ld,fxc)
154 implicit none
155 ! arguments
156 integer, intent(in) :: n
157 real(8), intent(in) :: fxcuu(n),fxcud(n),fxcdd(n)
158 real(8), intent(in) :: magu(3,n),magm(n),bxcp(n)
159 integer, intent(in) :: ld
160 real(8), intent(out) :: fxc(ld,4,4)
161 ! local variables
162 integer i
163 real(8) t1,t2
164 do i=1,n
165 ! charge-charge
166  fxc(i,1,1)=0.25d0*(fxcuu(i)+2.d0*fxcud(i)+fxcdd(i))
167 ! charge-spin
168  t1=0.25d0*(fxcuu(i)-fxcdd(i))
169  fxc(i,1,2)=t1*magu(1,i)
170  fxc(i,1,3)=t1*magu(2,i)
171  fxc(i,1,4)=t1*magu(3,i)
172 ! spin-spin
173  if (magm(i) > 1.d-14) then
174  t1=bxcp(i)/magm(i)
175  else
176  t1=0.d0
177  end if
178  t2=0.25d0*(fxcuu(i)-2.d0*fxcud(i)+fxcdd(i))-t1
179  fxc(i,2,2)=t2*magu(1,i)*magu(1,i)+t1
180  fxc(i,2,3)=t2*magu(1,i)*magu(2,i)
181  fxc(i,2,4)=t2*magu(1,i)*magu(3,i)
182  fxc(i,3,3)=t2*magu(2,i)*magu(2,i)+t1
183  fxc(i,3,4)=t2*magu(2,i)*magu(3,i)
184  fxc(i,4,4)=t2*magu(3,i)*magu(3,i)+t1
185 end do
186 end subroutine
187 
188 end subroutine
189 
subroutine genspfxcr(tsh, fxcmt, fxcir)
Definition: genspfxcr.f90:7
logical spinpol
Definition: modmain.f90:228
real(8), dimension(:), pointer, contiguous rhoir
Definition: modmain.f90:614
integer ndmag
Definition: modmain.f90:238
integer, dimension(maxspecies) npmt
Definition: modmain.f90:213
subroutine rbsht(nr, nri, rfmt1, rfmt2)
Definition: rbsht.f90:7
real(8), dimension(:,:), pointer, contiguous rhomt
Definition: modmain.f90:614
real(8), dimension(:,:,:), allocatable bxcmt
Definition: modmain.f90:636
real(8), dimension(:,:,:), pointer, contiguous magmt
Definition: modmain.f90:616
real(8), dimension(:,:), allocatable bxcir
Definition: modmain.f90:636
integer, dimension(maxatoms *maxspecies) idxis
Definition: modmain.f90:44
subroutine rfsht(nr, nri, rfmt1, rfmt2)
Definition: rfsht.f90:7
subroutine fxcifc(fxctype, n, rho, rhoup, rhodn, fxc, fxcuu, fxcud, fxcdd)
Definition: modfxcifc.f90:13
real(8), dimension(:,:), pointer, contiguous magir
Definition: modmain.f90:616
logical ncmag
Definition: modmain.f90:240
integer, dimension(3) fxctype
Definition: modtddft.f90:12
integer, dimension(maxspecies) nrmti
Definition: modmain.f90:211
pure subroutine tfm2213(n, fxcuu, fxcud, fxcdd, magu, magm, bxcp, ld, fxc)
Definition: genspfxcr.f90:154
integer, dimension(maxspecies) nrmt
Definition: modmain.f90:150