TRIQS/triqs_modest 3.3.0
Modular Electronic Structure Toolkit
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 namespace detail {
11
12 constexpr auto upfold_self_energy_at_freq(one_body_elements_on_grid const &obe, downfolding_projector const &Proj, auto const &Sigma_w,
13 long w_idx, long k_idx, long sigma_idx) {
14 auto N_nu = obe.H.N_nu(sigma_idx, k_idx);
15 auto out = nda::zeros<dcomplex>(N_nu, N_nu);
16 for (auto &&[alpha, R] : enumerated_sub_slices(get_struct(Sigma_w).dims(r_all, 0) | tl::to<std::vector>())) {
17 auto P = Proj.P(sigma_idx, k_idx)(R, r_all);
18 out(r_all, r_all) += dagger(P) * nda::matrix<dcomplex>{Sigma_w(alpha, sigma_idx).data()(w_idx, r_all, r_all)} * P;
19 }
20 return out;
21 }
22
23 template <bool Trace>
24 constexpr auto lattice_gf_at_k(auto const &mesh, one_body_elements_on_grid const &obe, downfolding_projector const &Proj, double mu,
25 auto const &Sigma_w, dcomplex broadening) {
26 return [&, mu, broadening](auto &k_idx, auto &sigma) {
27 if constexpr (Trace) {
28 auto out = gf{mesh};
29 for (auto &&[n, w] : enumerate(mesh)) {
30 auto PSP = upfold_self_energy_at_freq(obe, Proj, Sigma_w, n, k_idx, sigma);
31 out.data()(n) = trace(inverse(w + broadening + mu - obe.H.H(sigma, k_idx) - PSP));
32 }
33 return out;
34 } else {
35 auto N_nu = obe.H.N_nu(sigma, k_idx);
36 auto out = gf{mesh, {N_nu, N_nu}};
37 for (auto &&[n, w] : enumerate(mesh)) {
38 auto PSP = upfold_self_energy_at_freq(obe, Proj, Sigma_w, n, k_idx, sigma);
39 out.data()(n, r_all, r_all) = inverse(w + broadening + mu - obe.H.H(sigma, k_idx) - PSP);
40 }
41 return out;
42 }
43 };
44 }
45
46 constexpr auto local_gf_at_k(auto const &mesh, one_body_elements_on_grid const &obe, downfolding_projector const &Proj, double mu,
47 auto const &Sigma_w, dcomplex broadening) {
48 return [&, mu, broadening](auto &k_idx, auto &sigma) {
49 auto n_M = obe.C_space.dim();
50 auto out = gf{mesh, {n_M, n_M}};
51 auto P = obe.P.P(sigma, k_idx);
52 for (auto &&[n, w] : enumerate(mesh)) {
53 auto PSP = upfold_self_energy_at_freq(obe, Proj, Sigma_w, n, k_idx, sigma);
54 out.data()(n, r_all, r_all) = P * inverse(w + broadening + mu - obe.H.H(sigma, k_idx) - PSP) * dagger(P);
55 }
56 return out;
57 };
58 }
59
60 } // namespace detail
61
63 block2_gf<mesh::refreq, matrix_valued> const &Sigma_w, double broadening) {
64
65 auto const &mesh = Sigma_w(0, 0).mesh();
66
67 auto n_sigma = obe_theta.C_space.n_sigma();
68 auto n_k = obe_theta.H.n_k();
69
70 auto gloc_at_k = detail::local_gf_at_k(mesh, obe_theta, Proj, mu, Sigma_w, dcomplex(0, broadening));
71
72 auto gloc_result = make_block2_gf(mesh, obe_theta.C_space.Gc_block_shape());
73
74 for (auto const &k_idx : range(n_k)) {
75 for (auto const &sigma : range(n_sigma)) {
76 gloc_result(0, sigma).data()(r_all, r_all, r_all) += obe_theta.H.k_weights(k_idx) * gloc_at_k(k_idx, sigma).data();
77 }
78 }
79
80 gloc_result = mpi::all_reduce(gloc_result);
81
82 if (auto const &S = obe_theta.ibz_symm_ops; S) { gloc_result = S->symmetrize(gloc_result, obe_theta.C_space.atomic_decomposition()); }
83
84 auto n_M = obe_theta.C_space.dim();
85 auto n_w = mesh.size();
86
87 auto total = nda::array<double, 2>(n_sigma, n_w);
88 auto per_theta = nda::array<double, 4>(n_sigma, n_w, n_M, n_M);
89
90 for (auto const &sigma : nda::range(n_sigma)) {
91 auto g = gloc_result(0, sigma).data();
92 auto gC = conj(gloc_result(0, sigma)).data();
93 for (auto [n, w] : enumerate(mesh)) {
94 // auto g = gloc_result(0, sigma).data()(n, r_all, r_all);
95 //FIXME: can trace ignore the mesh dimension (or in general the first axis dimension and broadcast over all the w-mesh points)
96 total(sigma, n) = (-1.0 / M_PI) * imag(trace(g(n, r_all, r_all)));
97 // missing sign?
98 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));
99 }
100 }
101 return {.total = total, .per_theta = per_theta};
102 }
103
105 block2_gf<mesh::refreq, matrix_valued> const &Sigma_w, double broadening) {
106 auto const &mesh = Sigma_w(0, 0).mesh();
107 auto n_sigma = obe.C_space.n_sigma();
108 auto n_w = mesh.size();
109 auto n_k = obe.H.n_k();
110 auto n_M = obe.C_space.dim();
111
112 auto data = nda::array<double, 3>(n_sigma, n_k, n_w);
113 auto proj_data = nda::array<double, 5>(n_sigma, n_k, n_w, n_M, n_M);
114
115 auto trglatt_at_k = detail::lattice_gf_at_k<true>(mesh, obe, obe.P, mu, Sigma_w, broadening);
116 auto glatt_at_k = detail::lattice_gf_at_k<false>(mesh, obe, obe.P, mu, Sigma_w, broadening);
117
118 for (auto k_idx : range(n_k)) {
119 for (auto sigma : range(n_sigma)) {
120 data(sigma, k_idx, r_all) = (-1.0 / M_PI) * imag(trglatt_at_k(k_idx, sigma).data());
121 auto P = obe.P.P(sigma, k_idx);
122
123 for (auto n : range(n_w)) {
124 auto PGP = P * nda::matrix<dcomplex>{glatt_at_k(k_idx, sigma).data()(n, r_all, r_all)} * dagger(P);
125 proj_data(sigma, k_idx, n, r_all, r_all) = (-1.0 / M_PI) * imag(PGP);
126 }
127 }
128 }
129 return {.data = data, .proj_data = proj_data};
130 }
131
132} // namespace triqs::modest
long n_sigma() const
Dimension of the index.
auto atomic_decomposition() const
Transformed view containing the dimension of each 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 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
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
Weight in the BZ for each k-point.
long n_k() const
Number of k-points in the grid.
The projector that downfolds the energy bands onto a set of localized atomic-like orbitals.
nda::matrix_const_view< dcomplex > P(long sigma, long k_idx) const
Get for a given and .
A one-body elements struct where all of the underlying data exists on a fixed momentum grid.
band_dispersion H
Band dispersion.
downfolding_projector P
Downfolding projector .
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.
Store data of spectral functions.