TRIQS/TRIQS 4.0.0
Researching Interacting Quantum Systems
Loading...
Searching...
No Matches
density.hpp
Go to the documentation of this file.
1// Copyright (c) 2014-2018 Commissariat à l'énergie atomique et aux énergies alternatives (CEA)
2// Copyright (c) 2014-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, Hugo U. R. Strand, Nils Wentzell
19
24
25#pragma once
26
27#include "../block/block_gf.hpp"
28
29#include "../../mesh/dlr.hpp"
32#include "../../mesh/imfreq.hpp"
34#include "../../mesh/refreq.hpp"
36
37#include <itertools/itertools.hpp>
38
39#include <type_traits>
40#include <vector>
41
42namespace triqs::gfs {
43
44 // Names elevated from nda for the declarations below.
45 using nda::array;
46 using nda::array_const_view;
47
52
53 //-------------------------------------------------------
54 // For Imaginary Matsubara Frequency functions
55 // ------------------------------------------------------
56
67 nda::matrix<dcomplex> density(gf_const_view<mesh::imfreq> g, array_const_view<dcomplex, 3> known_moments = {});
68
79 dcomplex density(gf_const_view<mesh::imfreq, scalar_valued> g, array_const_view<dcomplex, 1> known_moments = {});
80
89 nda::matrix<dcomplex> density(gf_const_view<mesh::legendre> g);
90
100
101 //-------------------------------------------------------
102 // DLR
103 // ------------------------------------------------------
104
111 auto density(MemoryGf<mesh::dlr> auto const &g) {
112 auto res = make_regular(-g(g.mesh().beta()));
113 // Transpose to get <cdag_i c_j> instead of <cdag_j c_i>
114 if constexpr (requires { transpose(res); }) {
115 res = transpose(res);
116 return res;
117 } else
118 return res;
119 }
120
127 auto density(MemoryGf<mesh::dlr_imtime> auto const &g) { return density(make_gf_dlr(g)); }
128
135 auto density(MemoryGf<mesh::dlr_imfreq> auto const &g) { return density(make_gf_dlr(g)); }
136
137 //-------------------------------------------------------
138 // For Real Frequency functions
139 // ------------------------------------------------------
140
151 nda::matrix<dcomplex> density(gf_const_view<mesh::refreq> g, double beta);
152
163 dcomplex density(gf_const_view<mesh::refreq, scalar_valued> g, double beta);
164
174 nda::matrix<dcomplex> density(gf_const_view<mesh::refreq> g);
175
185 dcomplex density(gf_const_view<mesh::refreq, scalar_valued> g);
186
187 //-------------------------------------------------------
188 // General Version for Block Gf
189 // ------------------------------------------------------
190
202 template <typename BGf, int R>
203 auto density(BGf const &gin, std::vector<array<dcomplex, R>> const &known_moments)
204 requires(is_block_gf_v<BGf>)
205 {
206
207 using mesh_t = typename BGf::mesh_t;
208 static_assert(std::is_same_v<mesh_t, mesh::imfreq> or std::is_same_v<mesh_t, mesh::refreq>,
209 "Density Function must be called with either an imfreq or a refreq Green Function");
210
211 using r_t = decltype(density(gin[0], known_moments[0]));
212 std::vector<r_t> dens_vec;
213
214 TRIQS_ASSERT2(gin.size() == known_moments.size(), "Density: Require equal number of blocks in block_gf and known_moments vector");
215
216 for (auto [gin_bl, km_bl] : itertools::zip(gin, known_moments)) dens_vec.push_back(density(gin_bl, km_bl));
217 return dens_vec;
218 }
219
221
222} // namespace triqs::gfs
223
224namespace nda::clef {
225 // Make density usable inside lazy CLEF expressions.
226 TRIQS_CLEF_MAKE_FNT_LAZY(density);
227} // namespace nda::clef
Provides the block Green's function container.
A read-only, non-owning view of a Green's function.
Concept checking that a type behaves like an in-memory Green's function.
Definition gf.hpp:133
Provides a mesh type for the discrete Lehmann representation in imaginary frequency space.
Provides a mesh type for the discrete Lehmann representation in imaginary time.
TRIQS exception hierarchy and related macros.
auto make_gf_dlr(G const &g)
Transform a DLR imaginary-time or DLR Matsubara Green's function to its DLR-coefficient representatio...
Definition dlr.hpp:94
nda::matrix< dcomplex > density(gf_const_view< mesh::imfreq > g, array_const_view< dcomplex, 3 > known_moments)
Compute the density from a Green's function.
Definition density.cpp:49
gf< M, matrix_valued > transpose(gf_view< M, matrix_valued > g)
Transpose the target matrix of a matrix-valued Green's function, returning a new Green's function.
constexpr bool is_block_gf_v
Trait to check whether a type is a block Green's function.
Definition block_gf.hpp:119
#define TRIQS_ASSERT2(X,...)
Like TRIQS_ASSERT but lets the caller add a custom message.
Provides a mesh type for the discrete Lehmann representation.
Provides a mesh type on the imaginary frequency axis.
Provides a mesh type for Legendre polynomials as basis functions.
Provides a mesh type on the real frequency axis.