TRIQS/triqs_modest 3.3.0
Brillouin zone summation
Loading...
Searching...
No Matches
postprocess.cpp
Go to the documentation of this file.
1// Copyright (c) 2025--present, The Simons Foundation
2// This file is part of TRIQS/modest and is licensed under the terms of GPLv3 or later.
3// SPDX-License-Identifier: GPL-3.0-or-later
4// See LICENSE in the root of this distribution for details.
5
6#include "./postprocess.hpp"
7
8namespace triqs::modest {
9
10 constexpr auto lattice_gf(auto const &mesh, auto const &obe, auto const &Proj, auto const &mu, auto const &embedding_decomp, auto const &Sigma_w,
11 auto const &broadening) {
12
13 return [&](auto &k_idx, auto &sigma) {
14 auto PSP = [&](auto &w) {
15 auto N_nu = obe.H.N_nu(sigma, k_idx);
16 auto out = nda::zeros<dcomplex>(N_nu, N_nu);
17 for (auto &&[alpha, R] : enumerated_sub_slices(embedding_decomp)) {
18 auto P = Proj.P(sigma, k_idx)(R, r_all);
19 out(r_all, r_all) += dagger(P) * nda::matrix<dcomplex>{Sigma_w(alpha, sigma).data()(w, r_all, r_all)} * P;
20 }
21 return out;
22 };
23
24 auto out = gf{mesh};
25 for (auto &&[n, w] : enumerate(mesh)) { out.data()(n) = trace(inverse(w + dcomplex(0.0, broadening) + mu - obe.H.H(sigma, k_idx) - PSP(n))); }
26 return out;
27 };
28 }
29
31 block2_gf<mesh::refreq, matrix_valued> const &Sigma_w, double broadening) {
32
33 auto const &mesh = Sigma_w(0, 0).mesh();
34
35 auto n_sigma = obe_theta.C_space.n_sigma();
36 auto n_M = obe_theta.C_space.dim();
37 auto n_w = mesh.size();
38 auto n_k = obe_theta.H.n_k();
39
40 auto embedding_decomp = get_struct(Sigma_w).dims(r_all, 0) | tl::to<std::vector>();
41
42 auto PSP = [&](auto &w, auto &k_idx, auto &sigma) {
43 auto N_nu = obe_theta.H.N_nu(sigma, k_idx);
44 auto out = nda::zeros<dcomplex>(N_nu, N_nu);
45 for (auto &&[alpha, R] : enumerated_sub_slices(embedding_decomp)) {
46 auto P = Proj.P(sigma, k_idx)(R, r_all);
47 out(r_all, r_all) += dagger(P) * nda::matrix<dcomplex>{Sigma_w(alpha, sigma).data()(w, r_all, r_all)} * P;
48 }
49 return out;
50 };
51
52 auto Gloc = [&](auto &k_idx, auto &sigma) {
53 auto out = gf{mesh, {n_M, n_M}};
54 auto P = obe_theta.P.P(sigma, k_idx);
55 for (auto &&[n, w] : enumerate(mesh)) {
56 out.data()(n, r_all, r_all) =
57 P * inverse(w + dcomplex(0.0, broadening) + mu - obe_theta.H.H(sigma, k_idx) - PSP(n, k_idx, sigma)) * dagger(P);
58 }
59 return out;
60 };
61
62 auto gloc_result = make_block2_gf(mesh, obe_theta.C_space.Gc_block_shape());
63
64 for (auto k_idx : range(n_k)) {
65 for (auto sigma : range(n_sigma)) {
66 gloc_result(0, sigma).data()(r_all, r_all, r_all) += obe_theta.H.k_weights(k_idx) * Gloc(k_idx, sigma).data();
67 }
68 }
69
70 gloc_result = mpi::all_reduce(gloc_result);
71
72 if (auto const &S = obe_theta.ibz_symm_ops; S) { gloc_result = S->symmetrize(gloc_result, obe_theta.C_space.atomic_decomposition()); }
73
74 auto total = nda::array<double, 2>(n_sigma, n_w);
75 auto per_theta = nda::array<double, 4>(n_sigma, n_w, n_M, n_M);
76
77 for (auto sigma : nda::range(n_sigma)) {
78 auto g = gloc_result(0, sigma).data();
79 auto gC = conj(gloc_result(0, sigma)).data();
80 for (auto [n, w] : enumerate(mesh)) {
81 // auto g = gloc_result(0, sigma).data()(n, r_all, r_all);
82 //FIXME: can trace ignore the mesh dimension (or in general the first axis dimension and broadcast over all the w-mesh points)
83 total(sigma, n) = (-1.0 / M_PI) * imag(trace(g(n, r_all, r_all)));
84 // missing sign?
85 per_theta(sigma, n, r_all, r_all) = real(dcomplex(0, 1.0) * (g(n, r_all, r_all) - transpose(gC(n, r_all, r_all))) / (2.0 * M_PI));
86 }
87 }
88 return {.total = total, .per_theta = per_theta};
89 }
90
92 block2_gf<mesh::refreq, matrix_valued> const &Sigma_w, double broadening) {
93 auto const &mesh = Sigma_w(0, 0).mesh();
94 auto n_sigma = obe.C_space.n_sigma();
95 auto n_w = mesh.size();
96 auto n_k = obe.H.n_k();
97
98 auto data = nda::array<double, 3>(n_sigma, n_k, n_w);
99
100 auto embedding_decomp = get_struct(Sigma_w).dims(r_all, 0) | tl::to<std::vector>();
101
102 auto Glatt = lattice_gf(mesh, obe, obe.P, mu, embedding_decomp, Sigma_w, broadening);
103
104 for (auto k_idx : range(n_k)) {
105 for (auto sigma : range(n_sigma)) { data(sigma, k_idx, r_all) = (-1.0 / M_PI) * imag(Glatt(k_idx, sigma).data()); }
106 }
107
108 return {data};
109 }
110
111} // namespace triqs::modest
long n_sigma() const
Dimension of the σ index.
auto atomic_decomposition() const
Generates [dimension of the atomic shell].
long dim() const
Dimension of the correlated space.
C2PY_IGNORE gf_struct2_t Gc_block_shape() const
Shape of the Green function in the correlated space, without block decomposition.
spectral_function_w projected_spectral_function(one_body_elements_on_grid const &obe_theta, downfolding_projector const &Proj, double mu, block2_gf< mesh::refreq, matrix_valued > const &Sigma_w, double broadening)
Compute the atom- and orbital-resolved spectral function (interacting density of states).
spectral_function_kw spectral_function_on_high_symmetry_path(one_body_elements_on_grid const &obe, double mu, block2_gf< mesh::refreq, matrix_valued > const &Sigma_w, double broadening)
Compute momentum-resolved spectral function A(k, ω) along high-symmetry path.
block2_gf< Mesh, matrix_valued > make_block2_gf(Mesh const &mesh, gf_struct2_t const &gf_s)
Definition gf_supp.hpp:41
gf_struct_t get_struct(block_gf< Mesh > const &g)
Definition gf_supp.hpp:51
constexpr auto lattice_gf(auto const &mesh, auto const &obe, auto const &Proj, auto const &mu, auto const &embedding_decomp, auto const &Sigma_w, auto const &broadening)
static constexpr auto r_all
Definition defs.hpp:40
generator< std::pair< long, nda::range > > enumerated_sub_slices(auto sub_div)
std::complex< double > dcomplex
Definition nda_supp.hpp:8
nda::array< double, 1 > k_weights
k_weights[k_idx]
long n_k() const
Number of k points in the grid.
long N_nu(long sigma, long k_idx) const
Number of bands #ν
nda::matrix_const_view< dcomplex > H(long sigma, long k_idx) const
H^σ(k)_ν, returned as a MATRIX in (ν, ν)
The projector that downfolds the one-body dispersion (ν) onto local orbitals (m).
nda::matrix_const_view< dcomplex > P(long sigma, long k_idx) const
P^σ(k)_mν, returned as a matrix in (m ν)
A one-body elements struct where all of the underlying data exists on a fixed momentum grid.
C2PY_IGNORE std::optional< ibz_symmetry_ops > ibz_symm_ops
IBZ symmetrizer after a k-sum.
Returns Tr (A) [σ,k,ω] for all k points in obe grid and all omega in Sigma mesh.