TRIQS/triqs_tprf 4.0.0
A TRIQS application
Loading...
Searching...
No Matches
channel_grouping.hpp
1/*******************************************************************************
2 *
3 * TRIQS: a Toolbox for Research in Interacting Quantum Systems
4 *
5 * Copyright (C) 2017, H. U.R. Strand
6 *
7 * TRIQS is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later
10 * version.
11 *
12 * TRIQS is distributed in the hope that it will be useful, but WITHOUT ANY
13 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 * details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * TRIQS. If not, see <http://www.gnu.org/licenses/>.
19 *
20 ******************************************************************************/
21#pragma once
22
23#include <nda/nda.hpp>
24#include <triqs/gfs.hpp>
25#include <triqs/mesh.hpp>
26
27using namespace triqs::gfs;
28using namespace triqs::mesh;
29using namespace nda;
30
31#include "types.hpp"
32
33namespace triqs_tprf {
34
35 // Forward declaration
36 template <Channel_t C> std::array<int, 6> channel_stride_order;
37
38 // ----------------------------------------------------
39 // Index grouping definitions
40 // ----------------------------------------------------
41
42 // The standard layout is:
43 //
44 // {nu_1, nu_2, a, b, c, d} <=> {0, 1, 2, 3, 4, 5}
45 //
46 // where nu_1 and nu_2 (nu_1=0, nu_2=1) are fermionic Matsubara frequencies
47 // and a, b, c, d (a=2, b=3, c=4, d=5) are target-space indices
48
49 // ----------------------------------------------------
50 // Channel_t::PH
51
52 // in the particle-hole channel (Channel_t::PH) the indices are grouped as
53 // {nu_1, a, b}, {nu_2, d, c} <=> {0, 2, 3}, {1, 5, 4}
54
55 template <> inline constexpr std::array<int, 6> channel_stride_order<Channel_t::PH> = {0, 2, 3, 1, 5, 4};
56
57 // ----------------------------------------------------
58 // Channel_t::PH_bar
59
60 // in the particle-hole-bar channel (Channel_t::PH_bar) the indices are grouped
61 // as
62 // {nu_1, a, d}, {nu_2, c, b} <=> {0, 2, 5}, {1, 4, 3}
63
64 template <> inline constexpr std::array<int, 6> channel_stride_order<Channel_t::PH_bar> = {0, 2, 5, 1, 4, 3};
65
66 // ----------------------------------------------------
67 // Channel_t::PP
68
69 // in the particle-particle channel (Channel_t::PP) the indices are grouped as
70 // {nu_1, a, c}, {nu_2, b, d} <=> {0, 2, 4}, {1, 3, 5}
71
72 template <> inline constexpr std::array<int, 6> channel_stride_order<Channel_t::PP> = {0, 2, 4, 1, 3, 5};
73
74 // ----------------------------------------------------
75 // channel_matrix_view
76 //
77 // Takes a contiguous 6-dimensional array_view with the layout
78 // of a given channel and returns the associated matrix_view
79
80 template <Channel_t C> using channel_memory_layout = contiguous_layout_with_stride_order<encode(channel_stride_order<C>)>;
81
82 template <Channel_t C>
83 inline nda::matrix_view<g2_iw_t::scalar_t> channel_matrix_view(array_contiguous_view<g2_iw_t::scalar_t, 6, channel_memory_layout<C>> arr) {
84 constexpr std::array<int, 6> str_ord = channel_stride_order<C>;
85 return group_indices_view(arr, idx_group<str_ord[0], str_ord[1], str_ord[2]>, idx_group<str_ord[3], str_ord[4], str_ord[5]>);
86 }
87} // namespace triqs_tprf