TRIQS/triqs_modest 3.3.0
Modular Electronic Structure Toolkit
Loading...
Searching...
No Matches
degenerate_blocks.hpp
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#pragma once
7#include "utils/defs.hpp"
8
9using namespace triqs::gfs;
10
11namespace triqs::modest {
12
27 template <typename Mesh>
28 std::vector<std::vector<long>> analyze_degenerate_blocks(block_gf<Mesh, matrix_valued> const &Gimp, double threshold = 1.e-5) {
29
30 auto n_mesh = Gimp[0].mesh().size();
31 auto n_blocks = Gimp.size();
32
33 std::vector<std::vector<long>> groups;
34 std::vector<bool> used(n_blocks, false);
35
36 auto are_matrices_equal = [threshold, n_mesh](auto const &A, auto const &B) {
37 if (A.target_shape() != B.target_shape()) return false;
38 long n0 = A.target_shape()[0];
39 for (auto mesh_idx : range(n_mesh)) {
40 auto const &Am = A(mesh_idx);
41 auto const &Bm = B(mesh_idx);
42 for (size_t i = 0; i < n0; ++i) {
43 for (size_t j = i + 1; j < n0; ++j) {
44 if (std::abs(Am(i, j) - Bm(i, j)) > threshold) return false;
45 }
46 }
47 }
48 return true;
49 };
50
51 for (auto i = 0; i < n_blocks; ++i) {
52 if (!used[i]) {
53 std::vector<long> current_group = {i};
54 used[i] = true;
55 for (auto j = i + 1; j < n_blocks; ++j) {
56 if (!used[j] && are_matrices_equal(Gimp[i], Gimp[j])) {
57 current_group.push_back(j);
58 used[j] = true;
59 }
60 }
61 groups.push_back(std::move(current_group));
62 }
63 }
64 return groups;
65 }
66
78 template <typename Mesh>
79 block_gf<Mesh, matrix_valued> symmetrize_gf(block_gf<Mesh, matrix_valued> const &g, std::vector<std::vector<long>> deg_bls) {
80 auto gsymm = g;
81 auto const &mesh = gsymm[0].mesh();
82
83 for (auto const &deg_bl : deg_bls) {
84 auto n_deg = deg_bl.size();
85 auto dim = g[deg_bl[0]].target_shape()[0];
86
87 auto gtmp = gf{mesh, {dim, dim}};
88 for (auto bl : deg_bl) { gtmp += g[bl]; }
89
90 gtmp /= n_deg;
91
92 for (auto bl : deg_bl) { gsymm[bl] = gtmp; }
93 }
94
95 return gsymm;
96 }
97
98 template std::vector<std::vector<long>> analyze_degenerate_blocks(block_gf<dlr_imfreq, matrix_valued> const &G, double threshold);
99 template std::vector<std::vector<long>> analyze_degenerate_blocks(block_gf<dlr_imtime, matrix_valued> const &G, double threshold);
100 template std::vector<std::vector<long>> analyze_degenerate_blocks(block_gf<imfreq, matrix_valued> const &G, double threshold);
101 template std::vector<std::vector<long>> analyze_degenerate_blocks(block_gf<imtime, matrix_valued> const &G, double threshold);
102
103 template block_gf<imfreq, matrix_valued> symmetrize_gf(block_gf<imfreq, matrix_valued> const &g, std::vector<std::vector<long>> deg_bls);
104 template block_gf<imtime, matrix_valued> symmetrize_gf(block_gf<imtime, matrix_valued> const &g, std::vector<std::vector<long>> deg_bls);
105 template block_gf<dlr_imfreq, matrix_valued> symmetrize_gf(block_gf<dlr_imfreq, matrix_valued> const &g, std::vector<std::vector<long>> deg_bls);
106 template block_gf<dlr_imtime, matrix_valued> symmetrize_gf(block_gf<dlr_imtime, matrix_valued> const &g, std::vector<std::vector<long>> deg_bls);
107} // namespace triqs::modest
block_gf< Mesh, matrix_valued > symmetrize_gf(block_gf< Mesh, matrix_valued > const &g, std::vector< std::vector< long > > deg_bls)
Symmetrize the blocks of a Green's function given a list of it's degenerate blocks.
std::vector< std::vector< long > > analyze_degenerate_blocks(block_gf< Mesh, matrix_valued > const &Gimp, double threshold=1.e-5)
Find the generate blocks of a block GF by analyzing or using the union-find algorithm.