-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsparse_ir_io.f90
223 lines (223 loc) · 6.14 KB
/
sparse_ir_io.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
!----------------------------------------------------------------------
MODULE sparse_ir_io
!----------------------------------------------------------------------
!
USE sparse_ir
!
IMPLICIT NONE
!
PRIVATE
!
INTEGER, PARAMETER :: DP = KIND(0d0)
!
PUBLIC :: read_ir
!
CONTAINS
!
!-----------------------------------------------------------------------
FUNCTION read_ir(unit, beta, positive_only) RESULT(obj)
!-----------------------------------------------------------------------
!!
!! This function calls read_v1
!! to read the file including the ir-basis objects.
!!
!
INTEGER, INTENT(IN) :: unit
!! Unit number
REAL(KIND = DP), INTENT(IN) :: beta
!! inverse temperature
LOGICAL, INTENT(IN), OPTIONAL :: positive_only
!! if true, take the Matsubara frequencies
!! only from the positive region
!
TYPE(IR) :: obj
!! to contain all the ir-basis objects from the file
CHARACTER(LEN = 100) :: tmp_str
!! dummy for characters
INTEGER :: version
!! version number
!
READ(unit,*) tmp_str, version
IF (version == 1) then
IF ((.NOT. PRESENT(positive_only))) then
obj = read_v1(unit, beta)
ELSE
obj = read_v1(unit, beta, positive_only)
ENDIF
ELSE
WRITE(*, *) "Invalid version number", version
STOP "Stopping..."
ENDIF
!-----------------------------------------------------------------------
END FUNCTION read_ir
!-----------------------------------------------------------------------
!
!-----------------------------------------------------------------------
FUNCTION read_v1(unit, beta, positive_only) RESULT(obj)
!-----------------------------------------------------------------------
!!
!! This function reads the file to get the ir-basis objects.
!! (version 1)
!!
!
INTEGER, INTENT(IN) :: unit
!! Unit number
REAL(KIND = DP), INTENT(IN) :: beta
!! inverse temperature
LOGICAL, INTENT(IN), OPTIONAL :: positive_only
!! if true, take the Matsubara frequencies
!! only from the positive region
!
REAL(KIND = DP), PARAMETER :: rtol = 1e-20
!!
TYPE(IR) :: obj
!! to contain all the ir-basis objects from the file
CHARACTER(LEN = 100) :: tmp_str
!! dummy for characters
INTEGER :: i
!! counter
INTEGER :: l
!! counter
INTEGER :: t
!! counter
INTEGER :: n
!! counter
INTEGER :: size
!! total number of IR basis functions (size of s)
INTEGER :: ntau
!! total number of sampling points of imaginary time
INTEGER :: nfreq_f
!! total number of sampling Matsubara freqs (Fermionic)
INTEGER :: nfreq_b
!! total number of sampling Matsubara freqs (Bosonic)
INTEGER :: nomega
!! total number of sampling points of real frequency
INTEGER, ALLOCATABLE :: freq_f(:)
!! integer part of sampling Matsubara freqs (Fermion)
INTEGER, ALLOCATABLE :: freq_b(:)
!! integer part of sampling Matsubara freqs (Boson)
REAL(KIND = DP) :: rtmp
!! dummy for real variables
REAL(KIND = DP) :: rtmp2
!! dummy for real variables
REAL(KIND = DP) :: lambda
!! lambda = 10^{nlambda},
!! which determines maximum sampling point of real frequency
REAL(KIND = DP) :: eps
!! eps = 10^{-ndigit}
REAL(KIND = DP), ALLOCATABLE :: s(:)
!! singular values
REAL(KIND = DP), ALLOCATABLE :: tau(:)
!! sampling points of imaginary time (dimenisonless)
REAL(KIND = DP), ALLOCATABLE :: omega(:)
!! sampling points of real frequency (dimenisonless)
REAL(KIND = DP), ALLOCATABLE :: u(:, :)
!! dimensionless ir-basis functions of tau
REAL(KIND = DP), ALLOCATABLE :: v(:, :)
!! this may be not used after getting dlr
REAL(KIND = DP), ALLOCATABLE :: dlr(:, :)
!! change-of-basis matrix from IR basis to DLR basis
!! dlr(i, l) = - s(l) * v(i, l)
COMPLEX(KIND = DP), ALLOCATABLE :: uhat_f(:, :)
!! dimensionless ir-basis functions of Matsubara freqs
COMPLEX(KIND = DP), ALLOCATABLE :: uhat_b(:, :)
!! dimensionless ir-basis functions of Matsubara freqs
!
READ(unit,*) tmp_str, lambda
READ(unit,*) tmp_str, eps
!
! Singular values
READ(unit,*)
READ(unit,*) size
ALLOCATE(s(size))
DO i=1, size
READ(unit, *) s(i)
ENDDO
!
! Sampling times
READ(unit,*)
READ(unit,*) ntau
ALLOCATE(tau(ntau))
DO i=1, ntau
READ(unit, *) tau(i)
ENDDO
!
! Basis functions on sampling times
READ(unit,*)
ALLOCATE(u(ntau, size))
DO l = 1, size
DO t = 1, ntau
READ(unit, *) rtmp
u(t, l) = rtmp
ENDDO
ENDDO
!
! Sampling frequencies (F)
READ(unit,*)
READ(unit,*) nfreq_f
ALLOCATE(freq_f(nfreq_f))
DO i=1, nfreq_f
READ(unit, *) freq_f(i)
ENDDO
!
READ(unit,*)
ALLOCATE(uhat_f(nfreq_f, size))
DO l = 1, size
DO n = 1, nfreq_f
READ(unit, *) rtmp, rtmp2
uhat_f(n, l) = CMPLX(rtmp, rtmp2, KIND = DP)
ENDDO
ENDDO
!
! Sampling frequencies (B)
READ(unit,*)
READ(unit,*) nfreq_b
ALLOCATE(freq_b(nfreq_b))
DO i=1, nfreq_b
READ(unit, *) freq_b(i)
ENDDO
!
READ(unit,*)
ALLOCATE(uhat_b(nfreq_b, size))
DO l = 1, size
DO n = 1, nfreq_b
READ(unit, *) rtmp, rtmp2
uhat_b(n, l) = CMPLX(rtmp, rtmp2, KIND = DP)
ENDDO
ENDDO
!
! Sampling poles on real frequencies
READ(unit,*)
READ(unit,*) nomega
ALLOCATE(omega(nomega))
DO i=1, nomega
READ(unit, *) omega(i)
ENDDO
!
! Right singular functions on sampling poles
READ(unit,*)
ALLOCATE(v(nomega, size))
ALLOCATE(dlr(nomega, size))
DO l = 1, size
DO i = 1, nomega
READ(unit, *) rtmp
v(i, l) = rtmp
dlr(i, l) = - s(l) * v(i, l)
ENDDO
ENDDO
!
IF ((.NOT. PRESENT(positive_only))) then
CALL init_ir(obj, beta, lambda, eps, s, tau, freq_f, freq_b, u, uhat_f, uhat_b, omega, v, dlr, 1d-16)
ELSE
CALL init_ir(obj, beta, lambda, eps, s, tau, freq_f, freq_b, u, uhat_f, uhat_b, omega, v, dlr, 1d-16, positive_only)
ENDIF
!
DEALLOCATE(s, tau, u, freq_f, uhat_f, freq_b, uhat_b, omega, v, dlr)
!
!-----------------------------------------------------------------------
END FUNCTION read_v1
!-----------------------------------------------------------------------
!
!-----------------------------------------------------------------------
END MODULE sparse_ir_io
!-----------------------------------------------------------------------