-
Notifications
You must be signed in to change notification settings - Fork 1
/
VCA_GF_SHARED.f90
298 lines (278 loc) · 8.32 KB
/
VCA_GF_SHARED.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
295
296
297
298
MODULE VCA_GF_SHARED
USE SF_CONSTANTS, only:one,xi,zero,pi
USE SF_TIMER
USE SF_IOTOOLS, only: str,free_unit,reg,free_units,txtfy
USE SF_ARRAYS, only: arange,linspace
USE SF_LINALG, only: inv,eigh,eye
USE SF_SP_LINALG, only: sp_lanc_tridiag
USE VCA_INPUT_VARS
USE VCA_VARS_GLOBAL
USE VCA_IO !< this contains the routine to print GF,Sigma and G0
USE VCA_EIGENSPACE
USE VCA_SETUP
USE VCA_BATH_FUNCTIONS
USE VCA_HAMILTONIAN
USE VCA_AUX_FUNX
!
implicit none
!Lanczos shared variables
!=========================================================
complex(8),dimension(:),allocatable :: state_cvec
real(8) :: state_e,max_exc
!Frequency and time arrays:
!=========================================================
real(8),dimension(:),allocatable :: wm,tau,wr,vm
!AUX GF
!=========================================================
complex(8),allocatable,dimension(:,:) :: auxGmats,auxGreal
contains
!+------------------------------------------------------------------+
!PURPOSE : Allocate arrays and setup frequencies and times
!+------------------------------------------------------------------+
subroutine allocate_grids
integer :: i
if(.not.allocated(wm))allocate(wm(Lmats))
if(.not.allocated(vm))allocate(vm(0:Lmats)) !bosonic frequencies
if(.not.allocated(wr))allocate(wr(Lreal))
if(.not.allocated(tau))allocate(tau(0:Ltau))
!print*,beta
wm = pi/beta*(2*arange(1,Lmats)-1)
do i=0,Lmats
vm(i) = pi/beta*2*i
enddo
wr = linspace(wini,wfin,Lreal)
tau(0:)= linspace(0.d0,beta,Ltau+1)
end subroutine allocate_grids
subroutine deallocate_grids
if(allocated(wm))deallocate(wm)
if(allocated(vm))deallocate(vm)
if(allocated(tau))deallocate(tau)
if(allocated(wr))deallocate(wr)
end subroutine deallocate_grids
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
!++++++++++++++++++COMPUTATIONAL ROUTINE: TQL2++++++++++++++++++++++++
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
!---------------------------------------------------------------------
! PURPOSE computes all eigenvalues/vectors, real symmetric tridiagonal matrix.
! This subroutine finds the eigenvalues and eigenvectors of a symmetric
! tridiagonal matrix by the QL method. The eigenvectors of a full
! symmetric matrix can also be found if TRED2 has been used to reduce this
! full matrix to tridiagonal form.
! Parameters:
! Input, integer ( kind = 4 ) N, the order of the matrix.
!
! Input/output, real ( kind = 8 ) D(N). On input, the diagonal elements of
! the matrix. On output, the eigenvalues in ascending order. If an error
! exit is made, the eigenvalues are correct but unordered for indices
! 1,2,...,IERR-1.
!
! Input/output, real ( kind = 8 ) E(N). On input, E(2:N) contains the
! subdiagonal elements of the input matrix, and E(1) is arbitrary.
! On output, E has been destroyed.
!
! Input, real ( kind = 8 ) Z(N,N). On input, the transformation matrix
! produced in the reduction by TRED2, if performed. If the eigenvectors of
! the tridiagonal matrix are desired, Z must contain the identity matrix.
! On output, Z contains the orthonormal eigenvectors of the symmetric
! tridiagonal (or full) matrix. If an error exit is made, Z contains
! the eigenvectors associated with the stored eigenvalues.
!
! Output, integer ( kind = 4 ) IERR, error flag.
! 0, normal return,
! J, if the J-th eigenvalue has not been determined after
! 30 iterations.
!
!---------------------------------------------------------------------
subroutine tql2 ( n, d, e, z, ierr )
integer :: n
real(8) :: c
real(8) :: c2
real(8) :: c3
real(8) :: d(n)
real(8) :: dl1
real(8) :: e(n)
real(8) :: el1
real(8) :: f
real(8) :: g
real(8) :: h
integer ( kind = 4 ) i
integer ( kind = 4 ) ierr
integer ( kind = 4 ) ii
integer ( kind = 4 ) j
integer ( kind = 4 ) k
integer ( kind = 4 ) l
integer ( kind = 4 ) l1
integer ( kind = 4 ) l2
integer ( kind = 4 ) m
integer ( kind = 4 ) mml
real(8) :: p
real(8) :: r
real(8) :: s
real(8) :: s2
real(8) :: tst1
real(8) :: tst2
real(8) :: z(n,n)
ierr = 0
if ( n == 1 ) then
return
end if
do i = 2, n
e(i-1) = e(i)
end do
f = 0.0D+00
tst1 = 0.0D+00
e(n) = 0.0D+00
do l = 1, n
j = 0
h = abs ( d(l) ) + abs ( e(l) )
tst1 = max ( tst1, h )
!
! Look for a small sub-diagonal element.
!
do m = l, n
tst2 = tst1 + abs ( e(m) )
if ( tst2 == tst1 ) then
exit
end if
end do
if ( m == l ) then
go to 220
end if
130 continue
if ( 30 <= j ) then
ierr = l
return
end if
j = j + 1
!
! Form shift.
!
l1 = l + 1
l2 = l1 + 1
g = d(l)
p = ( d(l1) - g ) / ( 2.0D+00 * e(l) )
r = pythag ( p, 1.0D+00 )
d(l) = e(l) / ( p + sign ( r, p ) )
d(l1) = e(l) * ( p + sign ( r, p ) )
dl1 = d(l1)
h = g - d(l)
d(l2:n) = d(l2:n) - h
f = f + h
!
! QL transformation.
!
p = d(m)
c = 1.0D+00
c2 = c
el1 = e(l1)
s = 0.0D+00
mml = m - l
do ii = 1, mml
c3 = c2
c2 = c
s2 = s
i = m - ii
g = c * e(i)
h = c * p
r = pythag ( p, e(i) )
e(i+1) = s * r
s = e(i) / r
c = p / r
p = c * d(i) - s * g
d(i+1) = h + s * ( c * g + s * d(i) )
!
! Form vector.
!
do k = 1, n
h = z(k,i+1)
z(k,i+1) = s * z(k,i) + c * h
z(k,i) = c * z(k,i) - s * h
end do
end do
p = - s * s2 * c3 * el1 * e(l) / dl1
e(l) = s * p
d(l) = c * p
tst2 = tst1 + abs ( e(l) )
if ( tst2 > tst1 ) then
go to 130
end if
220 continue
d(l) = d(l) + f
end do
!
! Order eigenvalues and eigenvectors.
!
do ii = 2, n
i = ii - 1
k = i
p = d(i)
do j = ii, n
if ( d(j) < p ) then
k = j
p = d(j)
end if
end do
if ( k /= i ) then
d(k) = d(i)
d(i) = p
do j = 1, n
call r8_swap ( z(j,i), z(j,k) )
end do
end if
end do
return
end subroutine tql2
!---------------------------------------------------------------------
! PURPOSE: computes SQRT ( A * A + B * B ) carefully.
! The formula
! PYTHAG = sqrt ( A * A + B * B )
! is reasonably accurate, but can fail if, for example, A**2 is larger
! than the machine overflow. The formula can lose most of its accuracy
! if the sum of the squares is very large or very small.
! Parameters:
! Input, real(8) :: A, B, the two legs of a right triangle.
! Output, real(8) :: PYTHAG, the length of the hypotenuse.
!---------------------------------------------------------------------
function pythag ( a, b )
implicit none
real(8) :: a
real(8) :: b
real(8) :: p
real(8) :: pythag
real(8) :: r
real(8) :: s
real(8) :: t
real(8) :: u
p = max ( abs ( a ), abs ( b ) )
if ( p /= 0.0D+00 ) then
r = ( min ( abs ( a ), abs ( b ) ) / p )**2
do
t = 4.0D+00 + r
if ( t == 4.0D+00 ) then
exit
end if
s = r / t
u = 1.0D+00 + 2.0D+00 * s
p = u * p
r = ( s / u )**2 * r
end do
end if
pythag = p
return
end function pythag
!---------------------------------------------------------------------
! PURPOSE: swaps two R8's.
! Parameters:
! Input/output, real(8) :: X, Y. On output, the values of X and
! Y have been interchanged.
!---------------------------------------------------------------------
subroutine r8_swap ( x, y )
real(8) :: x
real(8) :: y
real(8) :: z
z = x
x = y
y = z
return
end subroutine r8_swap
END MODULE VCA_GF_SHARED