TRIQS/triqs_cthyb 4.0.0
A TRIQS application
Loading...
Searching...
No Matches
util.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
22#pragma once
23
24#include "../types.hpp"
25
26namespace triqs_cthyb {
27
28 // --------------------------------------------------------------------------
32 class G2_measure_t {
33 public:
34 using target_shape_t = std::array<int, 4>;
35 struct block_t {
36 int idx;
37 std::string name;
38 };
39 block_t b1, b2;
40 target_shape_t target_shape;
41 G2_measure_t(block_t b1, block_t b2, target_shape_t target_shape) : b1(b1), b2(b2), target_shape(target_shape) {}
42 };
43
44 // --------------------------------------------------------------------------
48
49 private:
50 std::vector<G2_measure_t> measures;
51
52 public:
53 const gf_struct_t gf_struct;
54 const solve_parameters_t params;
55
56 const std::vector<G2_measure_t> &operator()() { return measures; }
57
60 G2_measures_t(const G_tau_t &_Delta_tau, const gf_struct_t &gf_struct, const solve_parameters_t &params) : gf_struct(gf_struct), params(params) {
61
62 auto G2_blocks_to_measure = params.measure_G2_blocks;
63
64 // Measure all blocks
65 if (G2_blocks_to_measure.empty()) {
66 for (auto const &bn1 : gf_struct) {
67 for (auto const &bn2 : gf_struct) { G2_blocks_to_measure.emplace(bn1.first, bn2.first); }
68 }
69 } else { // Check the blocks we've been asked to measure
70 for (auto const &bn : G2_blocks_to_measure) {
71 auto count_bl = [&gf_struct](auto bl_name){ return std::count_if(gf_struct.cbegin(), gf_struct.cend(), [&bl_name](auto & bl){ return bl.first == bl_name; }); };
72 if (count_bl(bn.first) != 1) TRIQS_RUNTIME_ERROR << "Invalid left block name " << bn.first << " for G^2 measurement";
73 if (count_bl(bn.second) != 1) TRIQS_RUNTIME_ERROR << "Invalid right block name " << bn.second << " for G^2 measurement";
74 }
75 }
76
77 std::map<std::string, int> block_name_to_index;
78 auto block_names = _Delta_tau.block_names();
79 for (auto block_idx : range(block_names.size())) {
80 std::string block_name = block_names[block_idx];
81 block_name_to_index[block_name] = block_idx;
82 }
83
84 for (auto const &block_pair : G2_blocks_to_measure) {
85
86 auto const &bn1 = std::get<0>(block_pair);
87 auto const &bn2 = std::get<1>(block_pair);
88
89 auto b1 = block_name_to_index[bn1];
90 auto b2 = block_name_to_index[bn2];
91
92 int s1 = _Delta_tau[b1].target_shape()[0];
93 int s3 = _Delta_tau[b2].target_shape()[0];
94 int s2 = params.measure_G2_block_order == block_order::AABB ? s1 : s3;
95 int s4 = params.measure_G2_block_order == block_order::AABB ? s3 : s1;
96
97 std::array<int, 4> target_shape{s1, s2, s3, s4};
98
99 G2_measure_t measure{{b1, bn1}, {b2, bn2}, target_shape};
100
101 measures.push_back(measure);
102 }
103 }
104 };
105
106 // --------------------------------------------------------------------------
107} // namespace triqs_cthyb
G2_measures_t(const G_tau_t &_Delta_tau, const gf_struct_t &gf_struct, const solve_parameters_t &params)
Definition util.hpp:60
Parameters passed to the solve method of the solver class.