(git:27c966b)
Loading...
Searching...
No Matches
gw_nevanlinna.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief Nevanlinna analytic continuation of the GW correlation self-energy from the imaginary
10!> to the real frequency axis, following J. Fei, C.-N. Yeh, E. Gull, PRL 126, 056402 (2021).
11!> Minus the correlation self-energy maps the upper half plane into itself. After a Moebius
12!> map onto the unit disk the interpolation becomes a Schur problem whose solution is
13!> causal by construction. The Schur recursion loses digits quickly and is therefore done
14!> in double-double arithmetic (about 31 significant digits, module double_double), so that
15!> no quadruple-precision support of the compiler is needed; the evaluation is stable in
16!> double precision.
17!> \par History
18!> 11.2026 created
19! **************************************************************************************************
21 USE bibliography, ONLY: fei2021,&
22 cite_reference
23 USE double_double, ONLY: &
26 USE kinds, ONLY: dp
27 USE mathlib, ONLY: diag_complex
28#include "./base/base_uses.f90"
29
30 IMPLICIT NONE
31
32 PRIVATE
33
34 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'gw_nevanlinna'
35
36 ! imaginary shifts delta*max|Sigma| tried in turn until the samples admit an interpolant
37 REAL(KIND=dp), DIMENSION(9), PARAMETER :: nevanlinna_deltas = [0.0_dp, 1.0e-14_dp, 1.0e-12_dp, &
38 1.0e-10_dp, 1.0e-8_dp, 1.0e-6_dp, &
39 1.0e-4_dp, 1.0e-3_dp, 1.0e-2_dp]
40 REAL(KIND=dp), PARAMETER :: tiny_schur = 1.0e-40_dp
41
44
45! **************************************************************************************************
46!> \brief Parameters of the quasiparticle solution with the Nevanlinna continuation; they are set
47!> in set_heuristic_parameters (gw_utils.F) and stay zero for the Padé continuation
48! **************************************************************************************************
50 ! relative SVD cutoff of the least-squares minimax weights of Σ^c(iτ) -> Σ^c(iω); the
51 ! truncated SVD keeps Σ^c(iω) causal, which the Nevanlinna interpolant requires
52 REAL(kind=dp) :: rcond_weights = 0.0_dp
53 ! fit windows: the lowest k >= window_min_points imaginary frequencies, with the highest one
54 ! in [window_freq_min, window_freq_max]; the quasiparticle energy is the median over windows
55 INTEGER :: window_min_points = 0
56 REAL(kind=dp) :: window_freq_min = 0.0_dp, &
57 window_freq_max = 0.0_dp
58 ! a level is marked unstable if its window solutions spread more than window_spread
59 REAL(kind=dp) :: window_spread = 0.0_dp
60 ! Newton search from the DFT eigenvalue with steps of at most qp_newton_max_step, then the
61 ! solution of largest weight Z within qp_maxz_radius of the Newton solution
62 REAL(kind=dp) :: qp_newton_max_step = 0.0_dp, &
63 qp_maxz_radius = 0.0_dp
65
66! **************************************************************************************************
67!> \brief Schur parameters of one Nevanlinna interpolant
68! **************************************************************************************************
70 LOGICAL :: solvable = .false.
71 LOGICAL :: mirrored = .false.
72 INTEGER :: n = 0
73 REAL(kind=dp) :: delta = 0.0_dp
74 REAL(kind=dp) :: pick_min = 0.0_dp
75 COMPLEX(KIND=dp), DIMENSION(:), ALLOCATABLE :: xis, phis
76 END TYPE nevanlinna_type
77
78CONTAINS
79
80! **************************************************************************************************
81!> \brief Builds the Nevanlinna interpolant of y(x). If the samples are not causal within the
82!> accuracy of the data, a small imaginary shift -i*delta*max|y| is added, with delta taken
83!> from a fixed ladder; nev%solvable is .FALSE. if no delta of the ladder works.
84!> \param nev the interpolant
85!> \param x sample points, all in the upper or all in the lower half plane
86!> \param y values of the correlation self-energy at x
87! **************************************************************************************************
88 SUBROUTINE nevanlinna_create(nev, x, y)
89 TYPE(nevanlinna_type), INTENT(OUT) :: nev
90 COMPLEX(KIND=dp), DIMENSION(:), INTENT(IN) :: x, y
91
92 CHARACTER(len=*), PARAMETER :: routinen = 'nevanlinna_create'
93
94 COMPLEX(KIND=dp) :: s
95 COMPLEX(KIND=dp), ALLOCATABLE, DIMENSION(:) :: xx, yy
96 COMPLEX(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: pick, pick_vec
97 INTEGER :: handle, i, i_delta, k, n
98 INTEGER, ALLOCATABLE, DIMENSION(:) :: order
99 REAL(kind=dp) :: scale
100 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: pick_eig
101 TYPE(zdd_type), ALLOCATABLE, DIMENSION(:) :: lams, phis, xis
102
103 CALL timeset(routinen, handle)
104
105 CALL cite_reference(fei2021)
106
107 n = SIZE(x)
108 nev%n = n
109 ALLOCATE (nev%xis(n), nev%phis(n), xis(n), phis(n), lams(n), xx(n), yy(n), order(n))
110 nev%xis(:) = (0.0_dp, 0.0_dp)
111 nev%phis(:) = (0.0_dp, 0.0_dp)
112
113 ! occupied levels are sampled in the lower half plane: continue the mirror image
114 nev%mirrored = all(aimag(x) < 0.0_dp)
115 IF (nev%mirrored) THEN
116 xx(:) = conjg(x)
117 yy(:) = conjg(y)
118 ELSE
119 xx(:) = x
120 yy(:) = y
121 END IF
122
123 IF (n == 0 .OR. .NOT. (all(abs(xx) < huge(1.0_dp)) .AND. all(abs(yy) < huge(1.0_dp)))) THEN
124 DEALLOCATE (xis, phis, lams, xx, yy, order)
125 CALL timestop(handle)
126 RETURN
127 END IF
128
129 CALL sort_by_imag(xx, order)
130
131 scale = maxval(abs(yy))
132 IF (scale == 0.0_dp) scale = 1.0_dp
133
134 DO i = 1, n
135 xis(i) = moebius(zdd(xx(order(i))))
136 END DO
137
138 DO i_delta = 1, SIZE(nevanlinna_deltas)
139 DO i = 1, n
140 s = yy(order(i)) - cmplx(0.0_dp, nevanlinna_deltas(i_delta)*scale, kind=dp)
141 ! -Sigma is the function that maps the upper half plane into itself
142 lams(i) = moebius(zdd(-s))
143 END DO
144
145 IF (i_delta == 1) THEN
146 ! smallest eigenvalue of the Pick matrix of the unshifted samples, relative to the
147 ! largest one; negative values quantify how far the data are from causal
148 ALLOCATE (pick(n, n), pick_vec(n, n), pick_eig(n))
149 DO k = 1, n
150 DO i = 1, n
151 pick(i, k) = zdd_to_dp(zdd_div(zdd_sub(zdd_one, zdd_mul(lams(i), zdd_conjg(lams(k)))), &
152 zdd_sub(zdd_one, zdd_mul(xis(i), zdd_conjg(xis(k))))))
153 END DO
154 END DO
155 pick(:, :) = 0.5_dp*(pick + conjg(transpose(pick)))
156 CALL diag_complex(pick, pick_vec, pick_eig)
157 nev%pick_min = minval(pick_eig)/max(maxval(abs(pick_eig)), tiny(1.0_dp))
158 DEALLOCATE (pick, pick_vec, pick_eig)
159 END IF
160
161 IF (schur_parameters(xis, lams, phis)) THEN
162 nev%solvable = .true.
163 nev%delta = nevanlinna_deltas(i_delta)
164 EXIT
165 END IF
166 END DO
167
168 DO i = 1, n
169 nev%xis(i) = zdd_to_dp(xis(i))
170 IF (nev%solvable) nev%phis(i) = zdd_to_dp(phis(i))
171 END DO
172
173 DEALLOCATE (xis, phis, lams, xx, yy, order)
174
175 CALL timestop(handle)
176
177 END SUBROUTINE nevanlinna_create
178
179! **************************************************************************************************
180!> \brief Evaluates the interpolant on the real axis
181!> \param nev the interpolant
182!> \param x_val real frequency
183!> \param func_val continued correlation self-energy at x_val
184! **************************************************************************************************
185 SUBROUTINE nevanlinna_evaluate(nev, x_val, func_val)
186 TYPE(nevanlinna_type), INTENT(IN) :: nev
187 REAL(kind=dp), INTENT(IN) :: x_val
188 COMPLEX(KIND=dp), INTENT(OUT) :: func_val
189
190 COMPLEX(KIND=dp), PARAMETER :: ii = (0.0_dp, 1.0_dp), &
191 one = (1.0_dp, 0.0_dp), &
192 zero = (0.0_dp, 0.0_dp)
193
194 COMPLEX(KIND=dp) :: aa, bb, bj, cc, cphi, dd, na, nb, nc, &
195 nd, phi, th, xi, xz
196 INTEGER :: j
197 REAL(kind=dp) :: sc
198
199 ! product of the Moebius transformations of the Schur recursion, applied to theta = 0
200 xz = (cmplx(x_val, 0.0_dp, kind=dp) - ii)/(cmplx(x_val, 0.0_dp, kind=dp) + ii)
201 aa = one
202 bb = zero
203 cc = zero
204 dd = one
205 DO j = 1, nev%n
206 xi = nev%xis(j)
207 phi = nev%phis(j)
208 bj = (xz - xi)/(one - conjg(xi)*xz)
209 cphi = conjg(phi)
210 na = aa*bj + bb*cphi*bj
211 nb = aa*phi + bb
212 nc = cc*bj + dd*cphi*bj
213 nd = cc*phi + dd
214 ! rescale to avoid overflow; only the ratio bb/dd is used
215 sc = max(abs(na), abs(nb), abs(nc), abs(nd))
216 IF (sc == 0.0_dp) sc = 1.0_dp
217 aa = na/sc
218 bb = nb/sc
219 cc = nc/sc
220 dd = nd/sc
221 END DO
222 th = bb/dd
223 ! inverse Moebius map, and Sigma = -(Nevanlinna function)
224 func_val = -ii*(one + th)/(one - th)
225 IF (nev%mirrored) func_val = conjg(func_val)
226
227 END SUBROUTINE nevanlinna_evaluate
228
229! **************************************************************************************************
230!> \brief Releases the interpolant
231!> \param nev the interpolant
232! **************************************************************************************************
233 SUBROUTINE nevanlinna_release(nev)
234 TYPE(nevanlinna_type), INTENT(INOUT) :: nev
235
236 IF (ALLOCATED(nev%xis)) DEALLOCATE (nev%xis)
237 IF (ALLOCATED(nev%phis)) DEALLOCATE (nev%phis)
238 nev%solvable = .false.
239 nev%n = 0
240
241 END SUBROUTINE nevanlinna_release
242
243! **************************************************************************************************
244!> \brief Moebius map of the upper half plane onto the unit disk
245!> \param w point in the upper half plane
246!> \return (w - i)/(w + i)
247! **************************************************************************************************
248 ELEMENTAL FUNCTION moebius(w) RESULT(h)
249 TYPE(zdd_type), INTENT(IN) :: w
250 TYPE(zdd_type) :: h
251
252 h = zdd_div(zdd_sub(w, zdd_i), zdd_add(w, zdd_i))
253
254 END FUNCTION moebius
255
256! **************************************************************************************************
257!> \brief Schur recursion; fails if an intermediate value leaves the unit disk, i.e. if no
258!> contractive interpolant of the samples exists
259!> \param xis Moebius images of the sample points, sorted by imaginary part
260!> \param lams Moebius images of the function values
261!> \param phis Schur parameters
262!> \return .TRUE. if the recursion stayed inside the unit disk
263! **************************************************************************************************
264 FUNCTION schur_parameters(xis, lams, phis) RESULT(ok)
265 TYPE(zdd_type), DIMENSION(:), INTENT(IN) :: xis, lams
266 TYPE(zdd_type), DIMENSION(:), INTENT(OUT) :: phis
267 LOGICAL :: ok
268
269 INTEGER :: j, k
270 TYPE(zdd_type) :: bfac, den, phi
271 TYPE(zdd_type), DIMENSION(SIZE(xis)) :: vals
272
273 vals(:) = lams
274 phis(:) = zdd_zero
275 ok = .true.
276 DO j = 1, SIZE(xis)
277 phi = vals(j)
278 IF (zdd_abs2(phi) >= 1.0_dp) THEN
279 ok = .false.
280 RETURN
281 END IF
282 phis(j) = phi
283 DO k = j + 1, SIZE(xis)
284 bfac = zdd_div(zdd_sub(xis(k), xis(j)), zdd_sub(zdd_one, zdd_mul(zdd_conjg(xis(j)), xis(k))))
285 den = zdd_sub(zdd_one, zdd_mul(zdd_conjg(phi), vals(k)))
286 IF (zdd_abs2(den) < tiny_schur**2 .OR. zdd_abs2(bfac) < tiny_schur**2) THEN
287 vals(k) = zdd_zero
288 cycle
289 END IF
290 vals(k) = zdd_div(zdd_div(zdd_sub(vals(k), phi), den), bfac)
291 END DO
292 END DO
293
294 END FUNCTION schur_parameters
295
296! **************************************************************************************************
297!> \brief Insertion sort of sample points by increasing imaginary part
298!> \param z sample points
299!> \param order permutation that sorts z
300! **************************************************************************************************
301 SUBROUTINE sort_by_imag(z, order)
302 COMPLEX(KIND=dp), DIMENSION(:), INTENT(IN) :: z
303 INTEGER, DIMENSION(:), INTENT(OUT) :: order
304
305 INTEGER :: i, j, tmp
306
307 DO i = 1, SIZE(z)
308 order(i) = i
309 END DO
310 DO i = 2, SIZE(z)
311 tmp = order(i)
312 j = i - 1
313 DO WHILE (j >= 1)
314 IF (aimag(z(order(j))) <= aimag(z(tmp))) EXIT
315 order(j + 1) = order(j)
316 j = j - 1
317 END DO
318 order(j + 1) = tmp
319 END DO
320
321 END SUBROUTINE sort_by_imag
322
323END MODULE gw_nevanlinna
collects all references to literature in CP2K as new algorithms / method are included from literature...
integer, save, public fei2021
Double-double arithmetic: real and complex numbers stored as unevaluated sums hi + lo of two double-p...
elemental type(zdd_type) function, public zdd_mul(a, b)
Product of two complex double-double numbers.
type(zdd_type), parameter, public zdd_zero
elemental type(zdd_type) function, public zdd(z)
Complex double-double number from a double-precision one.
type(zdd_type), parameter, public zdd_i
type(zdd_type), parameter, public zdd_one
elemental type(zdd_type) function, public zdd_conjg(a)
Complex conjugate of a complex double-double number.
elemental type(zdd_type) function, public zdd_add(a, b)
Sum of two complex double-double numbers.
elemental type(zdd_type) function, public zdd_div(a, b)
Quotient of two complex double-double numbers.
elemental real(kind=dp) function, public zdd_abs2(a)
Squared modulus of a complex double-double number, rounded to double precision.
elemental type(zdd_type) function, public zdd_sub(a, b)
Difference of two complex double-double numbers.
elemental complex(kind=dp) function, public zdd_to_dp(a)
Rounds a complex double-double number to double precision.
Nevanlinna analytic continuation of the GW correlation self-energy from the imaginary to the real fre...
subroutine, public nevanlinna_release(nev)
Releases the interpolant.
subroutine, public nevanlinna_create(nev, x, y)
Builds the Nevanlinna interpolant of y(x). If the samples are not causal within the accuracy of the d...
subroutine, public nevanlinna_evaluate(nev, x_val, func_val)
Evaluates the interpolant on the real axis.
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Collection of simple mathematical functions and subroutines.
Definition mathlib.F:15
subroutine, public diag_complex(matrix, eigenvectors, eigenvalues)
Diagonalizes a local complex Hermitian matrix using LAPACK. Based on cp_cfm_heevd.
Definition mathlib.F:1909
Complex double-double number.
Parameters of the quasiparticle solution with the Nevanlinna continuation; they are set in set_heuris...
Schur parameters of one Nevanlinna interpolant.