-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathEQUILIBRIUM.f90
294 lines (238 loc) · 10.4 KB
/
EQUILIBRIUM.f90
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
!########################################################
! program : HMIPT
! TYPE : Main program
! PURPOSE : Solve the Hubbard model using DMFT-IPT
! AUTHORS : Adriano Amaricci
!########################################################
module EQUILIBRIUM
USE VARS_GLOBAL
USE IPT_SOPT
USE IPT_MATS
implicit none
private
!Equilibrium Function
complex(8),allocatable,dimension(:) :: sigma_,fg_,fg0_,sold
type(matsubara_gf) :: sm_,fm_,f0m_
real(8),allocatable,dimension(:) :: wr_,nk_,wm_
public :: solve_equilibrium_ipt
public :: update_equilibrium_weiss_field
public :: get_equilibrium_localgf
!public :: get_equilibrium_impuritygf
contains
subroutine solve_equilibrium_ipt()
integer :: i,j,loop
logical :: converged
complex(8) :: zeta
real(8) :: n,z,wmax_
if(mpiID==0)then
call msg("Solving Equilibrium problem:")
call create_data_dir("Equilibrium")
!
allocate(fg_(L))
allocate(sigma_(L))
allocate(fg0_(L))
allocate(sold(L))
!
call allocate_gf(fm_,L)
call allocate_gf(f0m_,L)
call allocate_gf(sm_,L)
!
allocate(wr_(L),nk_(Lk),wm_(L))
!
wmax_= min(20.d0,wmax)
wr_ = linspace(-wmax_,wmax_,L)
wm_ = pi/beta*real(2*arange(1,L)-1,8)
!
sigma_=zero ; sold=sigma_
loop=0 ; converged=.false.
do while (.not.converged)
loop=loop+1
write(*,"(A,i5)",advance="no")"DMFT-loop",loop
do i=1,L
zeta = cmplx(wr_(i),eps) - sigma_(i)
fg_(i) = sum_overk_zeta(zeta,epsik,wt)
enddo
n = sum(aimag(fg_)*fermi(wr_,beta))/sum(aimag(fg_))
fg0_ = one/(one/fg_ + sigma_)
sigma_= solve_ipt_sopt(fg0_,wr_)
sigma_= weight*sigma_ + (1.d0-weight)*sold
sold = sigma_
converged=check_convergence(sigma_,eps_error,nsuccess,nloop)
call splot("Equilibrium/nVSiloop.ipt",loop,n,append=TT)
enddo
call close_file("Equilibrium/nVSiloop.ipt")
call splot("Equilibrium/DOS.ipt",wr_,-aimag(fg_)/pi)
call splot("Equilibrium/G_realw.ipt",wr_,fg_)
call splot("Equilibrium/G0_realw.ipt",wr_,fg0_)
call splot("Equilibrium/Sigma_realw.ipt",wr_,sigma_)
sm_%iw=zero ; sold=sm_%iw
loop=0 ; converged=.false.
do while (.not.converged)
loop=loop+1
write(*,"(A,i5)",advance="no")"DMFT-loop",loop
do i=1,L
zeta = xi*wm_(i) - sm_%iw(i)
fm_%iw(i) = sum_overk_zeta(zeta,epsik,wt)
enddo
call fftgf_iw2tau(fm_%iw,fm_%tau,beta)
n =-real(fm_%tau(L))
f0m_%iw= one/(one/fm_%iw + sm_%iw)
sm_%iw = solve_ipt_matsubara(f0m_%iw)
sm_%iw = weight*sm_%iw + (1.d0-weight)*sold ; sold=sm_%iw
converged=check_convergence(sm_%iw,eps_error,Nsuccess,Nloop)
z=1.d0 - dimag(sm_%iw(1))/wm_(1);z=1.d0/z
call splot("Equilibrium/zetaVSiloop.ipt",iloop,z,append=TT)
call splot("Equilibrium/nmVSiloop.ipt",loop,n,append=TT)
enddo
call close_file("Equilibrium/nmVSiloop.ipt")
call close_file("Equilibrium/zetaVSiloop.ipt")
call splot("Equilibrium/G_iw.ipt",wm_,fm_%iw)
call splot("Equilibrium/G0_iw.ipt",wm_,f0m_%iw)
call splot("Equilibrium/Sigma_iw.ipt",wm_,sm_%iw)
!Save G0(w):
call splot(trim(irdG0wfile),wr_,fg0_) !interacting bath DOS
call splot(trim(irdG0iwfile),wm_,f0m_%iw)
call splot(trim(irdnkfile),epsik,nk_)
nk_ = square_lattice_momentum_distribution(Lk)
call splot("Equilibrium/nkVSepsk.ipt",epsik,nk_)
call system("mv *.err Equilibrium/")
endif
contains
function square_lattice_momentum_distribution(Lk) result(nk)
integer,parameter :: M=4096
integer :: Lk
integer :: ik,i
type(matsubara_gf) :: gm
real(8) :: nk(Lk)
call allocate_gf(gm,L)
do ik=1,Lk
gm%iw=one/(xi*wm_ - epsik(ik) - sm_%iw)
call fftgf_iw2tau(gm%iw,gm%tau,beta)
nk(ik)=-gm%tau(L)
enddo
end function square_lattice_momentum_distribution
end subroutine solve_equilibrium_ipt
!********************************************************************
!********************************************************************
!********************************************************************
!+-------------------------------------------------------------------+
!PURPOSE : Solve the equilibrium case
!+-------------------------------------------------------------------+
subroutine get_equilibrium_localgf()
integer :: i,j,ik
complex(8) :: A,zetan
real(8) :: w,n
complex(8) :: funcM(L),sigmaM(L)
real(8) :: funcT(0:L)
if(mpiID==0)then
!Get Sret(w) = FFT(Sret(t-t'))
forall(i=0:nstep,j=0:nstep) sf%ret%t(i-j)=heaviside(t(i-j))*(Sigma%gtr(i,j)-Sigma%less(i,j))
sf%ret%t=exa*sf%ret%t ; call fftgf_rt2rw(sf%ret%t,sf%ret%w,nstep) ; sf%ret%w=dt*sf%ret%w
!Get locGret(w)
gf%ret%w=zero
do i=1,2*nstep
w=wr(i)
zetan=cmplx(w,eps,8)-sf%ret%w(i) !-eqsbfret(i)
do ik=1,Lk
gf%ret%w(i)=gf%ret%w(i)+wt(ik)/(zetan-epsik(ik))
enddo
enddo
!Get locG<(w/t),locG>(w/t)
gf%less%w=less_component_w(gf%ret%w,wr,beta)
gf%gtr%w=gtr_component_w(gf%ret%w,wr,beta)
call fftgf_rw2rt(gf%less%w,gf%less%t,nstep) ; gf%less%t=exa*fmesh/pi2*gf%less%t
call fftgf_rw2rt(gf%gtr%w,gf%gtr%t,nstep) ; gf%gtr%t=exa*fmesh/pi2*gf%gtr%t
forall(i=0:nstep,j=0:nstep)
locG%less(i,j) = gf%less%t(i-j)
locG%gtr(i,j) = gf%gtr%t(i-j)
gf%ret%t(i-j) = heaviside(t(i-j))*(locG%gtr(i,j)-locG%less(i,j))
end forall
!This is just to get n(k)
call get_matsubara_gf_from_dos(wr,sf%ret%w,sigmaM,beta)
do ik=1,Lk
funcM=zero
do i=1,L
w=pi/beta*dble(2*i-1) ; zetan=cmplx(0.d0,w,8) - sigmaM(i)
funcM(i)=one/(zetan - epsik(ik))
enddo
call fftgf_iw2tau(funcM,funcT,beta)
n=-funcT(L)
nk(:,ik)=n
enddo
endif
call MPI_BCAST(locG%less,(nstep+1)**2,MPI_DOUBLE_COMPLEX,0,MPI_COMM_WORLD,mpiERR)
call MPI_BCAST(locG%gtr,(nstep+1)**2,MPI_DOUBLE_COMPLEX,0,MPI_COMM_WORLD,mpiERR)
call MPI_BCAST(nk,(nstep+1)*Lk,MPI_DOUBLE_PRECISION,0,MPI_COMM_WORLD,mpiERR)
call splot('nkVSepsk.ipt',epsik,nk(nstep/2,:),append=TT)
call splot('locSM_iw.ipt',wm,sigmaM,append=TT)
call splot("eqG_w.ipt",wr,gf%ret%w,append=TT)
call splot("eqSigma_w.ipt",wr,sf%ret%w,append=TT)
return
end subroutine get_equilibrium_localgf
!******************************************************************
!******************************************************************
!******************************************************************
subroutine update_equilibrium_weiss_field
integer :: M,i,j,k,itau,jtau,NN
real(8) :: R,deg
real(8) :: w,A,An
forall(i=0:nstep,j=0:nstep)
gf%ret%t(i-j) = heaviside(t(i-j))*(locG%gtr(i,j)-locG%less(i,j))
sf%ret%t(i-j) = heaviside(t(i-j))*(Sigma%gtr(i,j)-Sigma%less(i,j))
end forall
if(heaviside(0.d0)==1.d0)gf%ret%t(0)=gf%ret%t(0)/2.d0
if(heaviside(0.d0)==1.d0)sf%ret%t(0)=sf%ret%t(0)/2.d0
call fftgf_rt2rw(gf%ret%t,gf%ret%w,nstep) ; gf%ret%w=gf%ret%w*dt ; call swap_fftrt2rw(gf%ret%w)
call fftgf_rt2rw(sf%ret%t,sf%ret%w,nstep) ; sf%ret%w=sf%ret%w*dt ; call swap_fftrt2rw(sf%ret%w)
gf0%ret%w = one/(one/gf%ret%w + sf%ret%w)
gf0%less%w = less_component_w(gf0%ret%w,wr,beta)
gf0%gtr%w = gtr_component_w(gf0%ret%w,wr,beta)
! call splot("updateG0ret_w.ipt",wr,gf0%ret%w,append=TT)
! call splot("updateG0less_w.ipt",wr,gf0%less%w,append=TT)
! call splot("updateG0gtr_w.ipt",wr,gf0%gtr%w,append=TT)
call fftgf_rw2rt(gf0%less%w,gf0%less%t,nstep) ; gf0%less%t=exa*fmesh/pi2*gf0%less%t
call fftgf_rw2rt(gf0%gtr%w, gf0%gtr%t,nstep) ; gf0%gtr%t =exa*fmesh/pi2*gf0%gtr%t
call fftgf_rw2rt(gf0%ret%w, gf0%ret%t,nstep) ; gf0%ret%t =exa*fmesh/pi2*gf0%ret%t
forall(i=0:nstep,j=0:nstep)
G0%less(i,j)= gf0%less%t(i-j)
G0%gtr(i,j) = gf0%gtr%t(i-j)
end forall
! call splot("updateG0ret_t.ipt",t,gf0%ret%t,append=TT)
! call splot("G0less3D",t(0:nstep)/dt,t(0:nstep)/dt,G0less(0:nstep,0:nstep))
! call splot("G0gtr3D",t(0:nstep)/dt,t(0:nstep)/dt,G0gtr(0:nstep,0:nstep))
! !PLus this:
! forall(i=0:nstep,j=0:nstep)
! G0ret(i,j)=heaviside(t(i-j))*(G0gtr(i,j) - G0less(i,j))
! gf0%ret%t(i-j)=G0ret(i,j)
! end forall
! call fftgf_rt2rw(gf0%ret%t,gf0%less%w,nstep) ; gf0%less%w=gf0%less%w*dt ; call swap_fftrt2rw(gf0%less%w)
end subroutine update_equilibrium_weiss_field
!********************************************************************
!********************************************************************
!********************************************************************
! subroutine get_equilibrium_impuritygf
! integer :: i,j,itau
! real(8) :: A,w
! forall(i=0:nstep,j=0:nstep)
! gf0%ret%t(i-j)=heaviside(t(i-j))*(G0gtr(i,j) - G0less(i,j))
! sf%ret%t(i-j)=heaviside(t(i-j))*(Sgtr(i,j) - Sless(i,j))
! end forall
! if(heaviside(0.d0)==1.d0)gf0%ret%t(0)=gf0%ret%t(0)/2.d0
! if(heaviside(0.d0)==1.d0)sf%ret%t(0)=sf%ret%t(0)/2.d0
! call fftgf_rt2rw(gf0%ret%t,gf0%ret%w,nstep) ; gf0%ret%w=gf0%ret%w*dt ; call swap_fftrt2rw(gf0%ret%w) !swap because F(t) are not oscillating in this formalism:
! call fftgf_rt2rw(sf%ret%t,sf%ret%w,nstep) ; sf%ret%w=dt*sf%ret%w ; call swap_fftrt2rw(sf%ret%w) !swap because F(t) are not oscillating in this formalism:
! gf%ret%w = one/(one/gf0%ret%w - sf%ret%w)
! do i=1,2*nstep
! w = wr(i)
! A=-aimag(gf%ret%w(i))/pi
! gf%less%w(i)= pi2*xi*fermi(w,beta)*A
! gf%gtr%w(i) = pi2*xi*(fermi(w,beta)-1.d0)*A
! enddo
! call fftgf_rw2rt(gf%less%w,gf%less%t,nstep) ; gf%less%t=fmesh/pi2*gf%less%t ; gf%less%t=gf%less%t*exa
! call fftgf_rw2rt(gf%gtr%w,gf%gtr%t,nstep) ; gf%gtr%t =fmesh/pi2*gf%gtr%t ; gf%gtr%t=gf%gtr%t*exa
! forall(i=0:nstep,j=0:nstep)
! impGless(i,j)= gf%less%t(i-j)
! impGgtr(i,j) = gf%gtr%t(i-j)
! end forall
! end subroutine get_equilibrium_impuritygf
end module EQUILIBRIUM