The Elk Code
eliashberg.f90
Go to the documentation of this file.
1 
2 ! Copyright (C) 2011 A. Sanna 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 !BOP
7 ! !ROUTINE: eliashberg
8 ! !INTERFACE:
9 subroutine eliashberg
10 ! !USES:
11 use modmain
12 use modphonon
13 use modomp
14 ! !DESCRIPTION:
15 ! Calculates the superconducting gap within Eliashberg theory. This
16 ! implementation is isotropic and assumes a flat density of states. The
17 ! Eliashberg function $\alpha^2F$ is required as input for this calculation.
18 !
19 ! !REVISION HISTORY:
20 ! Created December 2010 (Antonio Sanna)
21 ! Modified, June 2011 (JKD)
22 !EOP
23 !BOC
24 implicit none
25 ! local variables
26 ! maximum allowed number of Matsubara frequencies
27 integer, parameter :: maxwf=40000
28 ! maximum number of iterations
29 integer, parameter :: maxit=1000
30 integer nwf,nwfcl,nin,nout
31 integer itemp,it,i,m,n,nthd
32 ! convergence tolerance
33 real(8), parameter :: eps=1.d-12
34 ! mixing paramter
35 real(8), parameter :: beta=0.5d0
36 real(8) lambda,wlog,wrms,tc
37 real(8) wfmax,tmin,tmax,dtemp,temp
38 real(8) dw,dmu,sm,a,b,t0,t1
39 ! allocatable arrays
40 real(8), allocatable :: w(:),a2f(:),wf(:),l(:)
41 real(8), allocatable :: d0(:),d(:),z0(:),z(:),r(:)
42 complex(8), allocatable :: zin(:),uin(:),zout(:),uout(:)
43 ! initialise universal variables
44 call init0
45 call init1
46 allocate(w(nwplot),a2f(nwplot))
47 ! read in the Eliashberg function
48 call readalpha2f(w,a2f)
49 dw=(w(nwplot)-w(1))/dble(nwplot)
50 ! compute the McMillan parameters
51 call mcmillan(w,a2f,lambda,wlog,wrms,tc)
52 ! Matsubara frequency cut-off
53 wfmax=20.d0*wrms
54 ! minumum temperature
55 tmin=tc/6.d0
56 if (tmin < 1.d-2) tmin=0.1d0
57 ! maximum temperature
58 tmax=5.d0*tc
59 if (tmax < 1.d0) tmax=1.d0
60 ! temperature step size
61 dtemp=(tmax-tmin)/dble(ntemp)
62 ! maximum number of fermionic Matsubara frequencies
63 nwf=nint(wfmax/(twopi*kboltz*dtemp))
64 if (nwf < 1) nwf=1
65 if (nwf > maxwf) nwf=maxwf
66 allocate(wf(-nwf:nwf))
67 allocate(l(-2*nwf:2*nwf))
68 allocate(d0(0:nwf),d(0:nwf))
69 allocate(z0(0:nwf),z(0:nwf))
70 allocate(r(0:nwf))
71 allocate(zin(0:nwf),uin(0:nwf))
72 ! generate output points for continuation on the real axis
73 nout=4*nwplot
74 allocate(zout(nout),uout(nout))
75 do i=1,nout
76  zout(i)=2.d0*dble(i-1)*dw
77 end do
78 ! open files for writing
79 open(62,file='ELIASHBERG.OUT',form='FORMATTED')
80 open(63,file='ELIASHBERG_IA.OUT',form='FORMATTED')
81 open(64,file='ELIASHBERG_GAP_T.OUT',form='FORMATTED')
82 open(65,file='ELIASHBERG_GAP_RA.OUT',form='FORMATTED')
83 open(66,file='ELIASHBERG_Z_RA.OUT',form='FORMATTED')
84 call writebox(62,"Eliashberg equations")
85 write(62,*)
86 write(62,'("Temperature range : ",2G18.10)') tmin,tmax
87 write(62,'("Number of temperature steps : ",I6)') ntemp
88 write(62,'("Number of output frequencies : ",I8)') nout
89 write(62,'("Fermionic Matsubara frequency cut-off")')
90 write(62,'(" phonons : ",G18.10)') wfmax
91 write(62,'(" Coulomb : ",G18.10)') 2.d0*wrms
92 flush(62)
93 d0(:)=1.d-4
94 z0(:)=1.d0
95 ! main loop over temperature
96 do itemp=1,ntemp
97  write(*,'("Info(eliashberg): temperature step ",I6," of ",I6)') itemp,ntemp
98  temp=dble(itemp)*dtemp+tmin
99  write(62,*)
100  write(62,'("Temperature (kelvin) : ",G18.10)') temp
101  t0=pi*kboltz*temp
102 ! number of Matsubara frequencies
103  nwf=nint(wfmax/(2.d0*t0))
104  if (nwf > maxwf) nwf=maxwf
105  nwfcl=nint(2.d0*wrms/(2.d0*t0))
106  if (nwfcl < 1) nwfcl=1
107  if (nwfcl > nwf) nwfcl=nwf
108  write(62,'("Number of Matsubara frequencies")')
109  write(62,'(" phonons : ",I8)') nwf
110  write(62,'(" Coulomb : ",I8)') nwfcl
111 ! make Pade approximant input points same as Matsubara frequencies
112  nin=nwf
113 ! generate fermionic Matsubara frequencies
114  do m=-nwf,nwf
115  wf(m)=t0*dble(2*m+1)
116  end do
117 ! compute lambda
118  call holdthd(4*nwf+1,nthd)
119 !$OMP PARALLEL DO DEFAULT(SHARED) &
120 !$OMP PRIVATE(t1,sm,i) &
121 !$OMP SCHEDULE(DYNAMIC) &
122 !$OMP NUM_THREADS(nthd)
123  do m=-2*nwf,2*nwf
124  t1=(t0*dble(2*m))**2
125  sm=0.d0
126  do i=1,nwplot
127  sm=sm+w(i)*a2f(i)/(w(i)**2+t1)
128  end do
129  l(m)=2.d0*sm*dw
130  end do
131 !$OMP END PARALLEL DO
132  call freethd(nthd)
133 ! begin iteration loop
134  do it=1,maxit
135  do m=0,nwf
136  r(m)=sqrt((wf(m)**2+d0(m)**2)*z0(m)**2)
137  end do
138  do n=0,nwf
139  sm=0.d0
140  do m=0,nwf-1
141  sm=sm+(l(n-m)-l(n+m+1))*z0(m)*wf(m)/r(m)
142  end do
143  z(n)=t0*sm/wf(n)
144  end do
145  z(0:nwf)=z(0:nwf)+1.d0
146  z0(0:nwf)=z(0:nwf)
147 ! Coulomb part of summation
148  dmu=0.d0
149  do n=0,nwfcl
150  dmu=dmu+mustar*d0(n)*z(n)/r(n)
151  end do
152  dmu=dmu*2.d0
153 ! Gap
154  do n=0,nwf
155  sm=0.d0
156  do m=0,nwf-1
157  sm=sm+(l(n-m)+l(n+m+1))*d0(m)*z(m)/r(m)
158  end do
159  d(n)=t0*(sm-dmu)/z(n)
160  end do
161 ! mix old and new gap functions
162  d(0:nwf)=beta*d(0:nwf)+(1.d0-beta)*d0(0:nwf)
163  sm=0.d0
164  do m=0,nwf
165  sm=sm+abs(d0(m)-d(m))
166  end do
167  sm=sm/dble(2*nwf)
168  d0(0:nwf)=d(0:nwf)
169  if (sm <= eps) then
170  write(62,'("Eliashberg equations converged in ",I6," iterations")') it
171  goto 10
172  end if
173 ! end iteration loop
174  end do
175  write(*,*)
176  write(*,'("Warning(eliashberg): failed to converge: possibly close to T_c")')
177  write(62,'("Failed to converge: possibly close to T_c")')
178 10 continue
179  flush(62)
180  do n=-nwf,nwf
181  if (n >= 0) then
182  m=n
183  else
184  m=-n-1
185  end if
186  write(63,'(3G18.10)') wf(n),d(m),z(m)
187  end do
188  write(63,*)
189  flush(63)
190  write(64,'(3G18.10)') temp,d(0),z(0)
191  flush(64)
192 ! analytic continuation to real axis
193  do m=0,nin
194  zin(m)=cmplx(0.d0,wf(m),8)
195  uin(m)=d(m)
196  end do
197  call pade(nin,zin,uin,nout,zout,uout)
198  do i=1,nout
199  a=dble(uout(i))
200  b=aimag(uout(i))
201  write(65,'(3G18.10)') dble(zout(i)),a,b
202  end do
203  write(65,*)
204  flush(65)
205  do m=0,nin
206  uin(m)=z(m)
207  end do
208  call pade(nin,zin,uin,nout,zout,uout)
209  do i=1,nout
210  a=dble(uout(i))
211  b=aimag(uout(i))
212  write(66,'(3G18.10)') dble(zout(i)),a,b
213  end do
214  write(66,*)
215  flush(66)
216 ! end loop over temperatures
217 end do
218 close(62); close(63); close(64); close(65); close(66)
219 write(*,*)
220 write(*,'("Info(eliashberg):")')
221 write(*,'(" calculation information written to ELIASHBERG.OUT")')
222 write(*,'(" gap and Z functions on the imaginary axis written to &
223  &ELIASHBERG_IA.OUT")')
224 write(*,'(" gap vs. temperature written to ELIASHBERG_GAP_T.OUT")')
225 write(*,'(" gap function on the real axis written to ELIASHBERG_GAP_RA.OUT")')
226 write(*,'(" Z function on the real axis written to ELIASHBERG_Z_RA.OUT")')
227 deallocate(w,a2f,wf,l)
228 deallocate(d0,d,z0,z,r)
229 deallocate(zin,uin,zout,uout)
230 end subroutine
231 !EOC
232 
real(8), parameter twopi
Definition: modmain.f90:1233
subroutine mcmillan(w, a2f, lambda, wlog, wrms, tc)
Definition: mcmillan.f90:7
Definition: modomp.f90:6
real(8), parameter kboltz
Definition: modmain.f90:1263
real(8), parameter pi
Definition: modmain.f90:1232
real(8) mustar
Definition: modphonon.f90:23
subroutine readalpha2f(w, a2f)
Definition: readalpha2f.f90:7
integer ntemp
Definition: modphonon.f90:25
subroutine init1
Definition: init1.f90:10
subroutine writebox(fnum, str)
Definition: writebox.f90:7
pure subroutine pade(ni, zi, ui, no, zo, uo)
Definition: pade.f90:10
subroutine freethd(nthd)
Definition: modomp.f90:106
subroutine holdthd(nloop, nthd)
Definition: modomp.f90:78
subroutine eliashberg
Definition: eliashberg.f90:10
subroutine init0
Definition: init0.f90:10
integer nwplot
Definition: modmain.f90:1073