The Elk Code
vmatmtdu.f90
Go to the documentation of this file.
1 
2 ! Copyright (C) 2007 F. Bultmark, F. Cricchio and L. Nordstrom.
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 vmatmtdu
7 use modmain
8 use moddftu
9 use modtest
10 implicit none
11 ! local variables
12 integer ispn,jspn
13 integer is,ia,ias,idu
14 integer l,m1,m2,m3,m4
15 integer ll,nm,lma,lmb
16 integer lm1,lm2,lm3,lm4
17 real(8) u,j,n,n0
18 real(8) mg(3),mg0(3)
19 real(8) v,edc,sm
20 complex(8) zsm,z1,z2
21 ! automatic arrays
22 real(8) vee(-lmaxdm:lmaxdm,-lmaxdm:lmaxdm,-lmaxdm:lmaxdm,-lmaxdm:lmaxdm)
23 complex(8) dm(lmmaxdm,nspinor,lmmaxdm,nspinor)
24 complex(8) dms(nspinor,nspinor)
25 ! zero the DFT+U energy for each atom
26 engyadu(:,:)=0.d0
27 do idu=1,ndftu
28  is=isldu(1,idu)
29  l=isldu(2,idu)
30  ll=l*(l+1)+1
31  nm=2*l+1
32  lma=l**2+1; lmb=lma+2*l
33 ! calculate the Coulomb matrix elements
34  call genveedu(idu,u,j,vee)
35  if ((abs(u) < 1.d-10).and.(abs(j) < 1.d-10)) cycle
36 ! begin loop over atoms
37  do ia=1,natoms(is)
38  ias=idxas(ia,is)
39 ! copy the density matrix for this atom
40  dm(:,:,:,:)=dmatmt(:,:,:,:,ias)
41 ! spin-unpolarised: scale density matrix so that it represents one spin channel
42 ! (thanks to Mike Bruckhoff for this)
43  if (.not.spinpol) dm(:,:,:,:)=0.5d0*dm(:,:,:,:)
44 ! trace of density matrix for each spin
45  dms(:,:)=0.d0
46  do ispn=1,nspinor
47  do jspn=1,nspinor
48  zsm=0.d0
49  do lm1=lma,lmb
50  zsm=zsm+dm(lm1,ispn,lm1,jspn)
51  end do
52  dms(ispn,jspn)=dms(ispn,jspn)+zsm
53  end do
54  end do
55 ! trace over spin
56  n=dble(dms(1,1))
57  if (spinpol) n=n+dble(dms(2,2))
58  n0=n/dble(nspinor*nm)
59 ! magnetisation
60  if (spinpol) then
61  mg(:)=0.d0
62  mg(3)=dble(dms(1,1)-dms(2,2))
63 ! non-collinear terms
64  if (ncmag) then
65  mg(1)=dble(dms(1,2)+dms(2,1))
66  mg(2)=dble(zi*(dms(1,2)-dms(2,1)))
67  end if
68  mg0(:)=mg(:)/dble(nspinor*nm)
69  end if
70 !---------------------------------!
71 ! around mean field (AFM) !
72 !---------------------------------!
73  if (dftu == 2) then
74 ! modify density matrices
75  do lm1=lma,lmb
76  if (spinpol) then
77  dm(lm1,1,lm1,1)=dm(lm1,1,lm1,1)-(n0+mg0(3))
78  dm(lm1,2,lm1,2)=dm(lm1,2,lm1,2)-(n0-mg0(3))
79 ! non-collinear terms
80  if (ncmag) then
81  dm(lm1,1,lm1,2)=dm(lm1,1,lm1,2)-(mg0(1)-zi*mg0(2))
82  dm(lm1,2,lm1,1)=dm(lm1,2,lm1,1)-(mg0(1)+zi*mg0(2))
83  end if
84  else
85 ! spin-unpolarised case
86  dm(lm1,1,lm1,1)=dm(lm1,1,lm1,1)-n0
87  end if
88  end do
89  end if
90 !------------------------------------!
91 ! DFT+U potential and energy !
92 !------------------------------------!
93 ! begin loops over m1 and m2
94  do m1=-l,l
95  lm1=ll+m1
96  do m2=-l,l
97  lm2=ll+m2
98 ! begin loops over m3 and m4
99  do m3=-l,l
100  lm3=ll+m3
101  do m4=-l,l
102  lm4=ll+m4
103  v=vee(m1,m3,m2,m4)
104  do ispn=1,nspinor
105  do jspn=1,nspinor
106  z1=dm(lm2,ispn,lm1,ispn)*dm(lm4,jspn,lm3,jspn)
107  z2=dm(lm4,jspn,lm1,ispn)*dm(lm2,ispn,lm3,jspn)
108  engyadu(ia,idu)=engyadu(ia,idu)+dble(z1-z2)*v
109  vmatmt(lm1,ispn,lm2,ispn,ias)=vmatmt(lm1,ispn,lm2,ispn,ias) &
110  +dm(lm4,jspn,lm3,jspn)*v
111  vmatmt(lm1,ispn,lm4,jspn,ias)=vmatmt(lm1,ispn,lm4,jspn,ias) &
112  -dm(lm2,ispn,lm3,jspn)*v
113  end do
114  end do
115 ! end loops over m3 and m4
116  end do
117  end do
118 ! end loops over m1 and m2
119  end do
120  end do
121 ! multiply energy by factor 1/2
122  engyadu(ia,idu)=0.5d0*engyadu(ia,idu)
123 !-----------------------------------------------------------------!
124 ! fully localised limit (FLL) double counting corrections !
125 !-----------------------------------------------------------------!
126  if (dftu == 1) then
127  if (spinpol) then
128 ! spin-polarised
129  if (ncmag) then
130 ! non-collinear case
131 ! correction to the energy
132  edc=0.5d0*u*n*(n-1.d0)
133  edc=edc-0.5d0*j*dble(dms(1,1)*(dms(1,1)-1.d0))
134  edc=edc-0.5d0*j*dble(dms(2,2)*(dms(2,2)-1.d0))
135  edc=edc-0.5d0*j*dble(dms(1,2)*dms(2,1))
136  edc=edc-0.5d0*j*dble(dms(2,1)*dms(1,2))
137 ! correction to the potential
138  do lm1=lma,lmb
139  vmatmt(lm1,1,lm1,1,ias)=vmatmt(lm1,1,lm1,1,ias) &
140  -u*(n-0.5d0)+j*(dms(1,1)-0.5d0)
141  vmatmt(lm1,2,lm1,2,ias)=vmatmt(lm1,2,lm1,2,ias) &
142  -u*(n-0.5d0)+j*(dms(2,2)-0.5d0)
143  vmatmt(lm1,1,lm1,2,ias)=vmatmt(lm1,1,lm1,2,ias)+j*dms(1,2)
144  vmatmt(lm1,2,lm1,1,ias)=vmatmt(lm1,2,lm1,1,ias)+j*dms(2,1)
145  end do
146  else
147 ! collinear case
148 ! correction to the energy
149  edc=0.5d0*u*n*(n-1.d0)
150  edc=edc-0.5d0*j*dble(dms(1,1)*(dms(1,1)-1.d0))
151  edc=edc-0.5d0*j*dble(dms(2,2)*(dms(2,2)-1.d0))
152 ! correction to the potential
153  do lm1=lma,lmb
154  vmatmt(lm1,1,lm1,1,ias)=vmatmt(lm1,1,lm1,1,ias) &
155  -u*(n-0.5d0)+j*(dms(1,1)-0.5d0)
156  vmatmt(lm1,2,lm1,2,ias)=vmatmt(lm1,2,lm1,2,ias) &
157  -u*(n-0.5d0)+j*(dms(2,2)-0.5d0)
158  end do
159  end if
160  else
161 ! spin-unpolarised
162 ! correction to the energy
163  edc=0.5d0*u*n*(n-1.d0)
164  edc=edc-0.5d0*j*n*(n-1.d0)
165 ! correction to the potential
166  do lm1=lma,lmb
167  vmatmt(lm1,1,lm1,1,ias)=vmatmt(lm1,1,lm1,1,ias)-u*(n-0.5d0) &
168  +j*(n-0.5d0)
169  end do
170  end if
171  engyadu(ia,idu)=engyadu(ia,idu)-edc
172  end if
173 !---------------------------------------------------------!
174 ! subtract DFT+U potential contribution to energy !
175 !---------------------------------------------------------!
176 ! trace of dmatmt times vmatmt
177  sm=0.d0
178  do ispn=1,nspinor
179  do lm1=lma,lmb
180  do jspn=1,nspinor
181  do lm2=lma,lmb
182  sm=sm+dble(dm(lm1,ispn,lm2,jspn)*vmatmt(lm2,jspn,lm1,ispn,ias))
183  end do
184  end do
185  end do
186  end do
187  engyadu(ia,idu)=engyadu(ia,idu)-sm
188 ! end loop over atoms
189  end do
190 ! end loop over species
191 end do
192 ! write DFT+U energy for each atom to test file
193 call writetest(800,'DFT+U energy for each atom',nv=natmmax*ndftu,tol=1.d-4, &
194  rva=engyadu)
195 ! write U and J parameters to test file
196 call writetest(810,'U and J parameters',nv=2*ndftu,tol=1.d-4,rva=ujdu)
197 end subroutine
198 
subroutine writetest(id, descr, nv, iv, iva, tol, rv, rva, zv, zva)
Definition: modtest.f90:16
integer natmmax
Definition: modmain.f90:38
logical spinpol
Definition: modmain.f90:228
integer, dimension(maxatoms, maxspecies) idxas
Definition: modmain.f90:42
subroutine vmatmtdu
Definition: vmatmtdu.f90:7
complex(8), dimension(:,:,:,:,:), allocatable dmatmt
Definition: moddftu.f90:16
subroutine genveedu(idu, u, j, vee)
Definition: genveedu.f90:10
integer, dimension(2, maxdftu) isldu
Definition: moddftu.f90:40
integer ndftu
Definition: moddftu.f90:38
real(8), dimension(:,:), allocatable engyadu
Definition: moddftu.f90:44
complex(8), dimension(:,:,:,:,:), allocatable vmatmt
Definition: moddftu.f90:20
integer, dimension(maxspecies) natoms
Definition: modmain.f90:36
integer dftu
Definition: moddftu.f90:32
complex(8), parameter zi
Definition: modmain.f90:1240
real(8), dimension(2, maxdftu) ujdu
Definition: moddftu.f90:42
logical ncmag
Definition: modmain.f90:240