-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexchange-matrix.f95
218 lines (208 loc) · 6.59 KB
/
exchange-matrix.f95
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
Subroutine exchangematrix(N,nband,ninter,Ng,xg,wg,Na,wa,rho,&
lrho,Ls,LegMat,FormMat,tFormMat,Vxc,hr1,thr13,wVxc)
Implicit none
integer::l,i,j,k,N,nband,ninter,Ng,lrho,Na,Lambda,Ls,p,q,wVxc
double precision:: integrateVxc,density
double precision, dimension(:)::wg(Ng),xg(Ng),wa(Na),hr1(ninter)
double precision, dimension(:,:)::Matrix(N,N),FormMat(5,Ng),tFormMat(4,Ng)
double precision, dimension(:,:)::LegMat(2*Ls+1,Na),thr13(Ng,ninter)
double precision, dimension(:,:,:)::rho(lrho+1,N,N),Vxc(2*Ls+1,nband+1,N),DensityM(Ng,ninter,Na)
Vxc=0.d0
!! Density Matrix
if(wVxc==0 .or. wVxc==1)then
DensityM=0.d0
do p=1,Ng
do k=1,ninter
do q=1,Na
DensityM(p,k,q)=density(p,k,q,rho,lrho,N,LegMat,Ls,Na,FormMat,Ng,ninter)
if(DensityM(p,k,q)<0) then
if(abs(DensityM(p,k,q))>10E-11)then
print*, 'the density at point (k,p,q)',k,p,q,'is not positive !!',DensityM(p,k,q)
stop
endif
DensityM(p,k,q)=0.d0
else
DensityM(p,k,q)=(DensityM(p,k,q))**(1.d0/3.d0)
endif
enddo
enddo
enddo
elseif(wVxc==2)then !!this case is done just for the oda
DensityM=0.d0
do p=1,Ng
do k=1,ninter
do q=1,Na
DensityM(p,k,q)=density(p,k,q,rho,lrho,N,LegMat,Ls,Na,FormMat,Ng,ninter)
DensityM(p,k,q)=abs(DensityM(p,k,q))**(1.d0/3.d0)
enddo
enddo
enddo
endif
if(wVxc==0)return
!do k=1,ninter
!print*,k, DensityM(1,k,1),DensityM(Ng,k,1)
!enddo
!stop
!! Exchange correlation energy Matrix
do 3 l=0,2*Ls
Matrix=0.d0
do i=1,3
do j=0,i-1
Matrix(4-i,4-j)=integrateVxc(Na,wa,Ng,xg,wg,1,&
Lambda(i),Lambda(j),l,LegMat,Ls,&
FormMat,tFormMat,ninter,thr13,hr1,DensityM)
enddo
enddo
do k=2,ninter-1
do i=1,4
do j=0,i-1
Matrix(4*k-i,4*k-j)=integrateVxc(Na,wa,Ng,xg,wg,k,&
Lambda(i),Lambda(j),l,LegMat,Ls,&
FormMat,tFormMat,ninter,thr13,hr1,DensityM)
enddo
enddo
enddo
do i=2,4
do j=1,i-1
Matrix(4*ninter-i,4*ninter-j)=integrateVxc(Na,wa,Ng,xg,wg,&
ninter,Lambda(i),Lambda(j),l,LegMat,Ls,&
FormMat,tFormMat,ninter,thr13,hr1,DensityM)
enddo
enddo
do k=2,ninter
Matrix(4*k-4,4*k-4)=integrateVxc(Na,wa,Ng,xg,wg,&
k-1,2,2,l,LegMat,Ls,&
FormMat,tFormMat,ninter,thr13,hr1,DensityM)+&
integrateVxc(Na,wa,Ng,xg,wg,&
k,1,1,l,LegMat,Ls,&
FormMat,tFormMat,ninter,thr13,hr1,DensityM)
enddo
do k=1,ninter
do i=1,3
Matrix(4*k-i,4*k-i)=integrateVxc(Na,wa,Ng,xg,wg,k,&
Lambda(i),Lambda(i),l,LegMat,Ls,&
FormMat,tFormMat,ninter,thr13,hr1,DensityM)
enddo
enddo
do j=1,N
do i=1,j
if(max(1,j-nband)<=i) Vxc(l+1,nband+1+i-j,j)=Matrix(i,j)
enddo
enddo
3 enddo
end subroutine
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
function integrateVxc(Na,wa,Ng,xg,wg,k,i,j,l,LegMat,Ls,&
FormMat,tFormMat,ninter,thr13,hr1,DensityM)
Implicit none
integer::i,j,l,p,q,Na,Ng,Ls,k,ninter
double precision::integrateVxc
double precision, dimension(:)::wa(Na),wg(Ng),xg(Ng),hr1(ninter)
double precision, dimension(:,:)::LegMat(2*Ls+1,Na),FormMat(5,Ng),tFormMat(4,Ng),thr13(Ng,ninter)
double precision, dimension(:,:,:)::DensityM(Ng,ninter,Na)
integrateVxc=0.d0
if(k==1) then
do p=1,Ng
do q=1,Na
integrateVxc=integrateVxc+wg(p)*wa(q)*DensityM(p,k,q)*&
LegMat(l+1,q)*tFormMat(i-1,p)*&
FormMat(j,p)*thr13(p,1)
enddo
enddo
else
do p=1,Ng
do q=1,Na
integrateVxc=integrateVxc+wg(p)*wa(q)*DensityM(p,k,q)*&
LegMat(l+1,q)*FormMat(i,p)*&
FormMat(j,p)*thr13(p,k)/(xg(p)*hr1(k)+1.d0)
enddo
enddo
integrateVxc=hr1(k)*integrateVxc
endif
end function
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
function density(p,k,q,rho,lrho,N,LegMat,Ls,Na,FormMat,Ng,ninter)
Implicit none
integer::l,i,j,k,Lambda,lrho,Ls,Na,q,p,Ng,ninter,N
double precision:: density
double precision,dimension(:,:)::LegMat(2*Ls+1,Na),FormMat(5,Ng)
double precision,dimension(:,:,:)::rho(lrho+1,N,N)
density=0.d0
if(k==1) then
do l=0,lrho
do i=0,3
do j=0,3
density=density+rho(l+1,4-i,4-j)*FormMat(Lambda(i),p)*&
FormMat(Lambda(j),p)*LegMat(l+1,q)
enddo
enddo
enddo
elseif(k==ninter)then
do l=0,lrho
do i=1,4
do j=1,4
density=density+rho(l+1,4*ninter-i,4*ninter-j)*FormMat(Lambda(i),p)*&
FormMat(Lambda(j),p)*LegMat(l+1,q)
enddo
enddo
enddo
else
!if(p.ne. 1 .and. p.ne. Ng) then
do l=0,lrho
do i=0,4
do j=0,4
density=density+rho(l+1,4*k-i,4*k-j)*FormMat(Lambda(i),p)*&
FormMat(Lambda(j),p)*LegMat(l+1,q)
enddo
enddo
enddo
!elseif(p==1) then
! do l=0,lrho
! density=density+rho(l+1,4*k-4,4*k-4)*4.d0*LegMat(l+1,q)
! enddo
!elseif(p==Ng) then
! do l=0,lrho
! density=density+rho(l+1,4*k,4*k)*4.d0*LegMat(l+1,q)
! enddo
!endif
endif
end function
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
function density1(p,k,q,rho,lrho,N,pi,FormMat,Ng,ninter)
!! this function is buit just for plotting and the number q is passed now as a double precision poit not as an index
Implicit none
integer::l,i,j,k,Lambda,lrho,p,Ng,ninter,N
double precision:: density,pi,q,density1,legendre
double precision,dimension(:,:)::FormMat(5,Ng)
double precision,dimension(:,:,:)::rho(lrho+1,N,N)
density=0.d0
if(k==1) then
do l=0,lrho
do i=0,3
do j=0,3
density=density+rho(l+1,4-i,4-j)*FormMat(Lambda(i),p)*&
FormMat(Lambda(j),p)*sqrt(2.d0*dble(l)+1.d0)*Legendre(l,q)
enddo
enddo
enddo
elseif(k==ninter)then
do l=0,lrho
do i=1,4
do j=1,4
density=density+rho(l+1,4*ninter-i,4*ninter-j)*FormMat(Lambda(i),p)*&
FormMat(Lambda(j),p)*sqrt(2.d0*dble(l)+1.d0)*Legendre(l,q)
enddo
enddo
enddo
else
do l=0,lrho
do i=0,4
do j=0,4
density=density+rho(l+1,4*k-i,4*k-j)*FormMat(Lambda(i),p)*&
FormMat(Lambda(j),p)*sqrt(2.d0*dble(l)+1.d0)*Legendre(l,q)
enddo
enddo
enddo
endif
density1=density/sqrt(4.d0*pi)
end function