TRIQS/TRIQS 4.0.0
Researching Interacting Quantum Systems
Loading...
Searching...
No Matches
evaluator.hpp
Go to the documentation of this file.
1// Copyright (c) 2016-2018 Commissariat à l'énergie atomique et aux énergies alternatives (CEA)
2// Copyright (c) 2016-2018 Centre national de la recherche scientifique (CNRS)
3// Copyright (c) 2018-2023 Simons Foundation
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You may obtain a copy of the License at
16// https://www.gnu.org/licenses/gpl-3.0.txt
17//
18// Authors: Michel Ferrero, Olivier Parcollet, Nils Wentzell
19
24
25#pragma once
26
28#include "./gf/defs.hpp"
29#include "./gf/gf.hpp"
30
31#include "../mesh/imfreq.hpp"
32
33namespace triqs::gfs {
34
35 // evaluator by default forwards everything to evaluate
36 // specialize e.g. for tail where gf data is used
37
42
52 template <Mesh M> struct gf_evaluator {
53
67 template <typename G, typename... XS>
68 requires(is_gf_v<G>)
69 auto operator()(G const &g, XS &&...xs) const {
70 auto l = [&g](auto &&...ys) -> decltype(auto) { return g.operator[](ys...); };
71 using r_t = std::decay_t<decltype(make_regular(evaluate(g.mesh(), l, std::forward<XS>(xs)...)))>;
72 if constexpr (nda::Array<r_t> or nda::is_scalar_v<r_t>) {
73 // Return zero if any mesh evaluates to zero
74 if (detail::eval_to_zero(g.mesh(), xs...)) { return r_t{nda::zeros<typename G::target_t::scalar_t>(g.target_shape())}; }
75 }
76 return make_regular(evaluate(g.mesh(), l, std::forward<XS>(xs)...));
77 }
78 };
79
80 // Evaluator specialization for Matsubara-frequency Green's functions (internal; the primary gf_evaluator is the
81 // documented API). Off the stored grid it uses the analytic structure: on a positive-only mesh negative
82 // frequencies are reconstructed by conjugation, and outside the grid the high-frequency tail is fitted and summed.
83 template <> struct gf_evaluator<mesh::imfreq> {
84
85 // Evaluate at a Matsubara frequency: stored value on the grid, conjugate on a positive-only mesh, else tail sum.
86 template <typename G> auto operator()(G const &g, matsubara_freq const &f) const {
87
88 using r_t = std::decay_t<decltype(make_regular(g[0]))>;
89
90 if (g.mesh().is_index_valid(f.n)) return r_t{g[f.n]};
91 if (g.mesh().positive_only()) {
92 int sh = (g.mesh().statistic() == Fermion ? 1 : 0);
93 if (g.mesh().is_index_valid(-f.n - sh)) return r_t{conj(g[-f.n - sh])};
94 TRIQS_RUNTIME_ERROR << " ERROR: Cannot evaluate Green function with positive only mesh outside grid ";
95 }
96
97 auto [tail, err] = fit_tail_no_normalize(g);
98 dcomplex x = std::abs(g.mesh().w_max()) / f;
99 auto res = r_t{nda::zeros<dcomplex>(g.target_shape())}; // a new array
100
101 dcomplex z = 1.0;
102 for (int n : range(tail.extent(0))) {
103 res += tail(n, ellipsis()) * z;
104 z = z * x;
105 }
106
107 return res;
108 }
109
110 // Integer overload: convert n to a matsubara_freq and delegate to the matsubara_freq overload.
111 template <typename G> decltype(auto) operator()(G const &g, int n) const { return g(matsubara_freq(n, g.mesh().beta(), g.mesh().statistic())); }
112 };
113
115
116} // namespace triqs::gfs
const_view_type operator()() const
Make a const view of *this.
Provides common type aliases, forward declarations and internal helpers for the Green's function cont...
Provides tail fitting, slicing, inversion, reality and matrix-multiplication functions for Green's fu...
Provides the Green's function class.
G::regular_type conj(G const &g)
Complex-conjugate a Green's function, returning a new Green's function.
constexpr bool is_gf_v
Trait to check whether a type models the Green's function concept.
Definition gf.hpp:101
nda::vector< double > r_t
Real space vector type.
many_body_operator_generic< T > n(IndexTypes... indices)
Create a number operator .
#define TRIQS_RUNTIME_ERROR
Throw a triqs::runtime_error with the current source location.
std::complex< double > dcomplex
Convenience alias for std::complex<double>.
Provides a mesh type on the imaginary frequency axis.
Default evaluator of a Green's function at arbitrary points of its mesh.
Definition evaluator.hpp:52