(git:3d5d2e5)
Loading...
Searching...
No Matches
gw_utils_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 double_double, ONLY: &
24 USE kinds, ONLY: dp,&
25 int_8
26 USE mathlib, ONLY: diag_complex
27#include "./base/base_uses.f90"
28
29 IMPLICIT NONE
30
31 PRIVATE
32
33 CHARACTER(LEN=*), PARAMETER, PRIVATE :: moduleN = 'gw_utils_nevanlinna'
34
35 ! imaginary shifts delta*max|Sigma| tried in turn until the samples admit an interpolant
36 REAL(KIND=dp), DIMENSION(9), PARAMETER :: nevanlinna_deltas = [0.0_dp, 1.0e-14_dp, 1.0e-12_dp, &
37 1.0e-10_dp, 1.0e-8_dp, 1.0e-6_dp, &
38 1.0e-4_dp, 1.0e-3_dp, 1.0e-2_dp]
39 REAL(KIND=dp), PARAMETER :: tiny_schur = 1.0e-40_dp
40
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 COMPLEX(KIND=dp), DIMENSION(:), ALLOCATABLE :: xis, phis
74 END TYPE nevanlinna_type
75
76! **************************************************************************************************
77!> \brief Frequency-dependent Schur factors shared by the bands and fit windows of a k-point.
78! **************************************************************************************************
80 PRIVATE
81 REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: omega
82 TYPE(zdd_type), ALLOCATABLE, DIMENSION(:) :: xis
83 TYPE(zdd_type), ALLOCATABLE, DIMENSION(:, :) :: factors
85
86! **************************************************************************************************
87!> \brief Nevanlinna diagnostics for one GW cycle. n_kpoints is the number of target k-points per spin.
88! **************************************************************************************************
90 INTEGER :: n_kpoints = 1
91 INTEGER(KIND=int_8) :: n_reliable = 0_int_8, n_unstable = 0_int_8, &
92 n_multi = 0_int_8, n_pade = 0_int_8
93 REAL(kind=dp) :: start_time = 0.0_dp
94 END TYPE gw_qp_summary_type
95
96CONTAINS
97
98! **************************************************************************************************
99!> \brief Builds the Nevanlinna interpolant of y(x). If the samples are not causal within the
100!> accuracy of the data, a small imaginary shift -i*delta*max|y| is added, with delta taken
101!> from a fixed ladder; nev%solvable is .FALSE. if no delta of the ladder works.
102!> \param nev the interpolant
103!> \param x sample points, all in the upper or all in the lower half plane
104!> \param y values of the correlation self-energy at x
105!> \param pick_min optional smallest relative eigenvalue of the unshifted Pick matrix
106! **************************************************************************************************
107 SUBROUTINE nevanlinna_create(nev, x, y, pick_min)
108 TYPE(nevanlinna_type), INTENT(OUT) :: nev
109 COMPLEX(KIND=dp), DIMENSION(:), INTENT(IN) :: x, y
110 REAL(kind=dp), INTENT(OUT), OPTIONAL :: pick_min
111
112 CHARACTER(LEN=*), PARAMETER :: routinen = 'nevanlinna_create'
113
114 COMPLEX(KIND=dp), ALLOCATABLE, DIMENSION(:) :: xx, yy
115 COMPLEX(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: pick, pick_vec
116 INTEGER :: handle, i, i_delta, k, n, n_valid
117 INTEGER, ALLOCATABLE, DIMENSION(:) :: order
118 REAL(kind=dp) :: scale
119 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: pick_eig
120 TYPE(zdd_type), ALLOCATABLE, DIMENSION(:) :: phis, xis
121
122 CALL timeset(routinen, handle)
123
124 IF (PRESENT(pick_min)) pick_min = 0.0_dp
125 n = SIZE(x)
126 nev%n = n
127 ALLOCATE (nev%xis(n), nev%phis(n), xis(n), phis(n), xx(n), yy(n), order(n))
128 nev%xis(:) = (0.0_dp, 0.0_dp)
129 nev%phis(:) = (0.0_dp, 0.0_dp)
130
131 ! occupied levels are sampled in the lower half plane: continue the mirror image
132 nev%mirrored = all(aimag(x) < 0.0_dp)
133 IF (nev%mirrored) THEN
134 xx(:) = conjg(x)
135 yy(:) = conjg(y)
136 ELSE
137 xx(:) = x
138 yy(:) = y
139 END IF
140
141 IF (n == 0 .OR. .NOT. (all(abs(xx) < huge(1.0_dp)) .AND. all(abs(yy) < huge(1.0_dp)))) THEN
142 DEALLOCATE (xis, phis, xx, yy, order)
143 CALL timestop(handle)
144 RETURN
145 END IF
146
147 CALL sort_by_imag(xx, order)
148
149 scale = maxval(abs(yy))
150 IF (scale == 0.0_dp) scale = 1.0_dp
151
152 DO i = 1, n
153 xis(i) = moebius(zdd(xx(order(i))))
154 END DO
155
156 DO i_delta = 1, SIZE(nevanlinna_deltas)
157 DO i = 1, n
158 phis(i) = shifted_sample(yy(order(i)), nevanlinna_deltas(i_delta)*scale)
159 END DO
160
161 IF (i_delta == 1 .AND. PRESENT(pick_min)) THEN
162 ! smallest eigenvalue of the Pick matrix of the unshifted samples, relative to the
163 ! largest one; negative values quantify how far the data are from causal
164 ALLOCATE (pick(n, n), pick_vec(n, n), pick_eig(n))
165 DO k = 1, n
166 DO i = 1, n
167 pick(i, k) = zdd_to_dp(zdd_div(zdd_sub(zdd_one, zdd_mul(phis(i), zdd_conjg(phis(k)))), &
168 zdd_sub(zdd_one, zdd_mul(xis(i), zdd_conjg(xis(k))))))
169 END DO
170 END DO
171 pick(:, :) = 0.5_dp*(pick + conjg(transpose(pick)))
172 CALL diag_complex(pick, pick_vec, pick_eig)
173 pick_min = minval(pick_eig)/max(maxval(abs(pick_eig)), tiny(1.0_dp))
174 DEALLOCATE (pick, pick_vec, pick_eig)
175 END IF
176
177 n_valid = schur_prefix(xis, phis)
178 nev%solvable = n_valid == n
179 IF (nev%solvable) EXIT
180 END DO
181
182 DO i = 1, n
183 nev%xis(i) = zdd_to_dp(xis(i))
184 IF (nev%solvable) nev%phis(i) = zdd_to_dp(phis(i))
185 END DO
186
187 DEALLOCATE (xis, phis, xx, yy, order)
188
189 CALL timestop(handle)
190
191 END SUBROUTINE nevanlinna_create
192
193! **************************************************************************************************
194!> \brief Prepare the Moebius nodes and triangular table of Blaschke factors for a prefix grid.
195!> \param grid shared frequency data
196!> \param omega imaginary frequencies in window order
197! **************************************************************************************************
198 SUBROUTINE nevanlinna_prepare_window_grid(grid, omega)
199 TYPE(nevanlinna_window_grid_type), INTENT(OUT) :: grid
200 REAL(kind=dp), DIMENSION(:), INTENT(IN) :: omega
201
202 INTEGER :: j, k, n
203
204 n = SIZE(omega)
205 ALLOCATE (grid%omega(n))
206 grid%omega(:) = abs(omega)
207 ! With a zero frequency the occupied-state mirror convention changes. An unordered
208 ! grid can also give different sorted prefixes. Use the single-window path in either case.
209 IF (.NOT. all(grid%omega > 0.0_dp .AND. grid%omega < huge(1.0_dp))) RETURN
210 IF (any(grid%omega(2:n) < grid%omega(1:n - 1))) RETURN
211 ALLOCATE (grid%xis(n))
212 grid%xis(:) = moebius(zdd(cmplx(0.0_dp, grid%omega, kind=dp)))
213 IF (any(zdd_abs2(grid%xis) >= 1.0_dp)) RETURN
214 ALLOCATE (grid%factors(n, n))
215 DO k = 1, n
216 DO j = 1, k - 1
217 grid%factors(j, k) = blaschke_factor(grid%xis(j), grid%xis(k))
218 END DO
219 END DO
220 END SUBROUTINE nevanlinna_prepare_window_grid
221
222! **************************************************************************************************
223!> \brief Fit nested windows for a single band, reusing Schur parameters at equal absolute shifts.
224!> \param fits one interpolant per window, with solvable false if all shifts failed
225!> \param grid frequency data shared across bands
226!> \param y self-energy samples in the same order as the grid
227!> \param occupied whether the samples were taken on the negative imaginary axis
228!> \param sizes positive window lengths in increasing order
229! **************************************************************************************************
230 SUBROUTINE nevanlinna_create_windows(fits, grid, y, occupied, sizes)
231 TYPE(nevanlinna_type), DIMENSION(:), INTENT(OUT) :: fits
232 TYPE(nevanlinna_window_grid_type), INTENT(IN) :: grid
233 COMPLEX(KIND=dp), DIMENSION(:), INTENT(IN) :: y
234 LOGICAL, INTENT(IN) :: occupied
235 INTEGER, DIMENSION(:), INTENT(IN) :: sizes
236
237 CHARACTER(LEN=*), PARAMETER :: routinen = 'nevanlinna_create_windows'
238 COMPLEX(KIND=dp), PARAMETER :: ii = (0.0_dp, 1.0_dp)
239
240 COMPLEX(KIND=dp), DIMENSION(SIZE(y)) :: yy
241 INTEGER :: handle, i, i_delta, n, n_valid
242 REAL(kind=dp) :: previous_shift, shift, sign_freq
243 REAL(kind=dp), DIMENSION(SIZE(sizes)) :: window_scale
244 REAL(kind=dp), DIMENSION(SIZE(y)) :: abs_y
245 TYPE(zdd_type), DIMENSION(SIZE(y)) :: phis
246
247 CALL timeset(routinen, handle)
248 abs_y(:) = abs(y)
249 IF (.NOT. ALLOCATED(grid%factors) .OR. .NOT. all(abs_y < huge(1.0_dp))) THEN
250 ! A bad sample in a longer window must not invalidate its shorter prefixes.
251 sign_freq = merge(-1.0_dp, 1.0_dp, occupied)
252 DO i = 1, SIZE(sizes)
253 n = sizes(i)
254 CALL nevanlinna_create(fits(i), ii*(sign_freq*grid%omega(1:n)), y(1:n))
255 END DO
256 CALL timestop(handle)
257 RETURN
258 END IF
259
260 yy(:) = y
261 IF (occupied) yy(:) = conjg(y)
262 DO i = 1, SIZE(sizes)
263 n = sizes(i)
264 fits(i)%n = n
265 fits(i)%mirrored = occupied
266 window_scale(i) = maxval(abs_y(1:n))
267 IF (window_scale(i) == 0.0_dp) window_scale(i) = 1.0_dp
268 END DO
269
270 DO i_delta = 1, SIZE(nevanlinna_deltas)
271 previous_shift = -1.0_dp
272 n_valid = 0
273 DO i = SIZE(sizes), 1, -1
274 IF (fits(i)%solvable) cycle
275 n = sizes(i)
276 shift = nevanlinna_deltas(i_delta)*window_scale(i)
277 ! A shorter window at this exact shift has the same parameters up to the
278 ! first failed Schur step, even if the longer window needs another shift.
279 IF (shift /= previous_shift) THEN
280 phis(1:n) = shifted_sample(yy(1:n), shift)
281 n_valid = schur_prefix(grid%xis(1:n), phis(1:n), grid%factors)
282 previous_shift = shift
283 END IF
284 IF (n > n_valid) cycle
285 fits(i)%solvable = .true.
286 ALLOCATE (fits(i)%xis(n), fits(i)%phis(n))
287 fits(i)%xis(:) = zdd_to_dp(grid%xis(1:n))
288 fits(i)%phis(:) = zdd_to_dp(phis(1:n))
289 END DO
290 IF (all(fits%solvable)) EXIT
291 END DO
292 CALL timestop(handle)
293 END SUBROUTINE nevanlinna_create_windows
294
295! **************************************************************************************************
296!> \brief Evaluates the interpolant on the real axis
297!> \param nev the interpolant
298!> \param x_val real frequency
299!> \param func_val continued correlation self-energy at x_val
300! **************************************************************************************************
301 SUBROUTINE nevanlinna_evaluate(nev, x_val, func_val)
302 TYPE(nevanlinna_type), INTENT(IN) :: nev
303 REAL(kind=dp), INTENT(IN) :: x_val
304 COMPLEX(KIND=dp), INTENT(OUT) :: func_val
305
306 COMPLEX(KIND=dp), PARAMETER :: ii = (0.0_dp, 1.0_dp), &
307 one = (1.0_dp, 0.0_dp), &
308 zero = (0.0_dp, 0.0_dp)
309
310 COMPLEX(KIND=dp) :: aa, bb, bj, cc, cphi, dd, na, nb, nc, &
311 nd, phi, th, xi, xz
312 INTEGER :: j
313 REAL(kind=dp) :: sc
314
315 ! product of the Moebius transformations of the Schur recursion, applied to theta = 0
316 xz = (cmplx(x_val, 0.0_dp, kind=dp) - ii)/(cmplx(x_val, 0.0_dp, kind=dp) + ii)
317 aa = one
318 bb = zero
319 cc = zero
320 dd = one
321 DO j = 1, nev%n
322 xi = nev%xis(j)
323 phi = nev%phis(j)
324 bj = (xz - xi)/(one - conjg(xi)*xz)
325 cphi = conjg(phi)
326 na = aa*bj + bb*cphi*bj
327 nb = aa*phi + bb
328 nc = cc*bj + dd*cphi*bj
329 nd = cc*phi + dd
330 ! rescale to avoid overflow; only the ratio bb/dd is used
331 sc = max(abs(na), abs(nb), abs(nc), abs(nd))
332 IF (sc == 0.0_dp) sc = 1.0_dp
333 aa = na/sc
334 bb = nb/sc
335 cc = nc/sc
336 dd = nd/sc
337 END DO
338 th = bb/dd
339 ! inverse Moebius map, and Sigma = -(Nevanlinna function)
340 func_val = -ii*(one + th)/(one - th)
341 IF (nev%mirrored) func_val = conjg(func_val)
342
343 END SUBROUTINE nevanlinna_evaluate
344
345! **************************************************************************************************
346!> \brief Evaluates Re Sigma on a grid of real frequencies
347!> \param nev the interpolant
348!> \param x real frequencies
349!> \param values real part of the continued correlation self-energy at x
350! **************************************************************************************************
351 SUBROUTINE nevanlinna_evaluate_real_grid(nev, x, values)
352 TYPE(nevanlinna_type), INTENT(IN) :: nev
353 REAL(kind=dp), DIMENSION(:), INTENT(IN) :: x
354 REAL(kind=dp), DIMENSION(:), INTENT(OUT) :: values
355
356 COMPLEX(KIND=dp), PARAMETER :: ii = (0.0_dp, 1.0_dp)
357 INTEGER, PARAMETER :: block_size = 64, rescale_interval = 8
358 REAL(kind=dp), PARAMETER :: scalar_tol = sqrt(epsilon(1.0_dp))
359
360 COMPLEX(KIND=dp) :: alpha, beta, c, p, phi, q, sigma
361 COMPLEX(KIND=dp), DIMENSION(block_size) :: u, v
362 INTEGER :: first, i, j, n
363 REAL(kind=dp) :: scale
364 REAL(kind=dp), DIMENSION(block_size) :: inv_scale, x_scaled
365
366 IF (nev%n == 0) THEN
367 values(:) = 0.0_dp
368 RETURN
369 END IF
370 ! Near a node on the unit circle the two forms of the Blaschke factor can lose
371 ! different digits. Use the scalar arithmetic for these ill-conditioned fits.
372 IF (any(abs(nev%xis(1:nev%n - 1)) > 1.0_dp - scalar_tol)) THEN
373 DO i = 1, SIZE(x)
374 CALL nevanlinna_evaluate(nev, x(i), sigma)
375 values(i) = real(sigma, kind=dp)
376 END DO
377 RETURN
378 END IF
379 DO first = 1, SIZE(x), block_size
380 n = min(block_size, SIZE(x) - first + 1)
381 ! Represent x by (x_scaled,inv_scale) to keep the factors bounded at large x.
382 DO i = 1, n
383 scale = max(1.0_dp, abs(x(first + i - 1)))
384 x_scaled(i) = x(first + i - 1)/scale
385 inv_scale(i) = 1.0_dp/scale
386 END DO
387 ! Apply the product to (0,1) from right to left. The last factor gives (phi_n,1).
388 u(1:n) = nev%phis(nev%n)
389 v(1:n) = 1.0_dp
390 DO j = nev%n - 1, 1, -1
391 alpha = 1.0_dp - nev%xis(j)
392 beta = -ii*(1.0_dp + nev%xis(j))
393 phi = nev%phis(j)
394 ! At real x the Blaschke factor is c/conjg(c), c = (1-xi)*x - i*(1+xi).
395 ! A common real scale cancels from u/v. Bound c before multiplying the vector.
396 !$OMP SIMD PRIVATE(c,scale,p,q)
397 DO i = 1, n
398 c = alpha*x_scaled(i) + beta*inv_scale(i)
399 scale = max(abs(real(c, kind=dp)), abs(aimag(c)), tiny(1.0_dp))
400 c = c/scale
401 p = c*u(i)
402 q = conjg(c)*v(i)
403 u(i) = p + phi*q
404 v(i) = q + conjg(phi)*p
405 END DO
406 ! The common scale drops out of the final ratio; bound its drift in long fits.
407 IF (mod(j, rescale_interval) == 0) THEN
408 !$OMP SIMD PRIVATE(scale)
409 DO i = 1, n
410 scale = max(abs(real(u(i), kind=dp)), abs(aimag(u(i))), &
411 abs(real(v(i), kind=dp)), abs(aimag(v(i))), tiny(1.0_dp))
412 u(i) = u(i)/scale
413 v(i) = v(i)/scale
414 END DO
415 END IF
416 END DO
417 DO i = 1, n
418 ! Near a pole use the scalar evaluator's order of operations for the sign test.
419 IF (abs(v(i) - u(i)) <= scalar_tol*abs(v(i))) THEN
420 CALL nevanlinna_evaluate(nev, x(first + i - 1), sigma)
421 values(first + i - 1) = real(sigma, kind=dp)
422 ELSE
423 ! Re[-i*(v+u)/(v-u)] is unchanged by the occupied-state conjugation.
424 values(first + i - 1) = aimag((v(i) + u(i))/(v(i) - u(i)))
425 END IF
426 END DO
427 END DO
428
429 END SUBROUTINE nevanlinna_evaluate_real_grid
430
431! **************************************************************************************************
432!> \brief Releases the interpolant
433!> \param nev the interpolant
434! **************************************************************************************************
435 SUBROUTINE nevanlinna_release(nev)
436 TYPE(nevanlinna_type), INTENT(INOUT) :: nev
437
438 IF (ALLOCATED(nev%xis)) DEALLOCATE (nev%xis)
439 IF (ALLOCATED(nev%phis)) DEALLOCATE (nev%phis)
440 nev%solvable = .false.
441 nev%n = 0
442
443 END SUBROUTINE nevanlinna_release
444
445! **************************************************************************************************
446!> \brief Moebius map of the upper half plane onto the unit disk
447!> \param w point in the upper half plane
448!> \return (w - i)/(w + i)
449! **************************************************************************************************
450 ELEMENTAL FUNCTION moebius(w) RESULT(h)
451 TYPE(zdd_type), INTENT(IN) :: w
452 TYPE(zdd_type) :: h
453
454 h = zdd_div(zdd_sub(w, zdd_i), zdd_add(w, zdd_i))
455
456 END FUNCTION moebius
457
458! **************************************************************************************************
459!> \brief Map the shifted -Sigma sample to the unit disk.
460!> \param y self-energy sample in the upper half plane
461!> \param shift absolute imaginary shift
462!> \return Moebius image of the shifted sample
463! **************************************************************************************************
464 ELEMENTAL FUNCTION shifted_sample(y, shift) RESULT(lam)
465 COMPLEX(KIND=dp), INTENT(IN) :: y
466 REAL(kind=dp), INTENT(IN) :: shift
467 TYPE(zdd_type) :: lam
468
469 lam = moebius(zdd(-(y - cmplx(0.0_dp, shift, kind=dp))))
470 END FUNCTION shifted_sample
471
472! **************************************************************************************************
473!> \brief Blaschke factor at a pair of Moebius nodes.
474!> \param xi Schur node
475!> \param x evaluation node
476!> \return Blaschke factor
477! **************************************************************************************************
478 PURE FUNCTION blaschke_factor(xi, x) RESULT(bfac)
479 TYPE(zdd_type), INTENT(IN) :: xi, x
480 TYPE(zdd_type) :: bfac
481
482 bfac = zdd_div(zdd_sub(x, xi), zdd_sub(zdd_one, zdd_mul(zdd_conjg(xi), x)))
483 END FUNCTION blaschke_factor
484
485! **************************************************************************************************
486!> \brief Schur recursion through the first sample outside the unit disk.
487!> \param xis Moebius images of the sample points, sorted by imaginary part
488!> \param phis Moebius images of the function values on input, Schur parameters of the valid prefix on output
489!> \param factors optional precomputed Blaschke factors
490!> \return length of the valid prefix
491! **************************************************************************************************
492 FUNCTION schur_prefix(xis, phis, factors) RESULT(n_valid)
493 TYPE(zdd_type), DIMENSION(:), INTENT(IN) :: xis
494 TYPE(zdd_type), DIMENSION(:), INTENT(INOUT) :: phis
495 TYPE(zdd_type), DIMENSION(:, :), INTENT(IN), &
496 OPTIONAL :: factors
497 INTEGER :: n_valid
498
499 INTEGER :: j, k
500 TYPE(zdd_type) :: bfac, den, phi
501
502 n_valid = 0
503 ! Finish one node before starting the next so a rejected prefix never updates the tail.
504 DO k = 1, SIZE(xis)
505 phi = phis(k)
506 DO j = 1, k - 1
507 IF (PRESENT(factors)) THEN
508 bfac = factors(j, k)
509 ELSE
510 bfac = blaschke_factor(xis(j), xis(k))
511 END IF
512 den = zdd_sub(zdd_one, zdd_mul(zdd_conjg(phis(j)), phi))
513 IF (zdd_abs2(den) < tiny_schur**2 .OR. zdd_abs2(bfac) < tiny_schur**2) THEN
514 phi = zdd_zero
515 ELSE
516 phi = zdd_div(zdd_div(zdd_sub(phi, phis(j)), den), bfac)
517 END IF
518 END DO
519 IF (zdd_abs2(phi) >= 1.0_dp) EXIT
520 phis(k) = phi
521 n_valid = k
522 END DO
523
524 END FUNCTION schur_prefix
525
526! **************************************************************************************************
527!> \brief Insertion sort of sample points by increasing imaginary part
528!> \param z sample points
529!> \param order permutation that sorts z
530! **************************************************************************************************
531 SUBROUTINE sort_by_imag(z, order)
532 COMPLEX(KIND=dp), DIMENSION(:), INTENT(IN) :: z
533 INTEGER, DIMENSION(:), INTENT(OUT) :: order
534
535 INTEGER :: i, j, tmp
536
537 DO i = 1, SIZE(z)
538 order(i) = i
539 END DO
540 DO i = 2, SIZE(z)
541 tmp = order(i)
542 j = i - 1
543 DO WHILE (j >= 1)
544 IF (aimag(z(order(j))) <= aimag(z(tmp))) EXIT
545 order(j + 1) = order(j)
546 j = j - 1
547 END DO
548 order(j + 1) = tmp
549 END DO
550
551 END SUBROUTINE sort_by_imag
552
553END MODULE gw_utils_nevanlinna
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_evaluate(nev, x_val, func_val)
Evaluates the interpolant on the real axis.
subroutine, public nevanlinna_create_windows(fits, grid, y, occupied, sizes)
Fit nested windows for a single band, reusing Schur parameters at equal absolute shifts.
subroutine, public nevanlinna_create(nev, x, y, pick_min)
Builds the Nevanlinna interpolant of y(x). If the samples are not causal within the accuracy of the d...
subroutine, public nevanlinna_evaluate_real_grid(nev, x, values)
Evaluates Re Sigma on a grid of real frequencies.
subroutine, public nevanlinna_prepare_window_grid(grid, omega)
Prepare the Moebius nodes and triangular table of Blaschke factors for a prefix grid.
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public int_8
Definition kinds.F:54
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:1910
Complex double-double number.
Parameters of the quasiparticle solution with the Nevanlinna continuation; they are set in set_heuris...
Nevanlinna diagnostics for one GW cycle. n_kpoints is the number of target k-points per spin.
Schur parameters of one Nevanlinna interpolant.
Frequency-dependent Schur factors shared by the bands and fit windows of a k-point.