TRIQS/triqs_cthyb 4.0.0
A TRIQS application
Loading...
Searching...
No Matches
G2_tau.cpp
1/*******************************************************************************
2 *
3 * TRIQS: a Toolbox for Research in Interacting Quantum Systems
4 *
5 * Copyright (C) 2017, H. U.R. Strand, M. Ferrero and O. Parcollet
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#include "./G2_tau.hpp"
23
24namespace triqs_cthyb {
25
26 using namespace triqs::gfs;
27 using namespace triqs::mesh;
28
29 measure_G2_tau::measure_G2_tau(std::optional<G2_tau_t> &G2_tau_opt, qmc_data const &data, G2_measures_t const &G2_measures)
30 : data(data), average_sign(0), G2_measures(G2_measures) {
31
32 double beta = data.config.beta();
33
34 order = G2_measures.params.measure_G2_block_order;
35 int n_tau = G2_measures.params.measure_G2_n_tau;
36
37 mesh::imtime fermi_tau_mesh{beta, Fermion, n_tau};
38 mesh::prod<imtime, imtime, imtime> G2_tau_mesh{fermi_tau_mesh, fermi_tau_mesh, fermi_tau_mesh};
39
40 G2_tau_opt = make_block2_gf(G2_tau_mesh, G2_measures.gf_struct, order);
41
42 G2_tau.rebind(*G2_tau_opt);
43 G2_tau() = 0.0;
44 }
45
46 void measure_G2_tau::accumulate(mc_weight_t sign) {
47
48 sign *= data.atomic_reweighting;
49 average_sign += sign;
50
51 // loop only over block-combinations that should be measured
52 for (auto &m : G2_measures()) {
53
54 auto G2_tau_block = G2_tau(m.b1.idx, m.b2.idx);
55 bool diag_block = (m.b1.idx == m.b2.idx);
56
57 foreach (data.dets[m.b1.idx], [&](auto const &i, auto const &j, auto const M_ij) {
58 foreach (data.dets[m.b2.idx], [&](auto const &k, auto const &l, auto const M_kl) {
59
60 // lambda for computing a single product term of M_ij and M_kl
61 auto compute_M2_product = [&](auto const &i, auto const &j, auto const &k, auto const &l, mc_weight_t sign) {
62
63 double t1 = double(i.first - l.first);
64 double t2 = double(j.first - l.first);
65 double t3 = double(k.first - l.first);
66
67 // implicit beta-periodicity, but fix the sign properly
68 int sign_flips = int(i.first < l.first) + int(j.first < l.first) + int(k.first < l.first);
69 mc_weight_t pre_factor = (sign_flips % 2 ? -sign : sign);
70
71 G2_tau_block[closest_mesh_pt(t1, t2, t3)](i.second, j.second, k.second, l.second) += pre_factor * M_ij * M_kl;
72 };
73
74 if (order == block_order::AABB || diag_block) compute_M2_product(i, j, k, l, +sign);
75 if (order == block_order::ABBA || diag_block) compute_M2_product(i, l, k, j, -sign);
76
77 })
78 ;
79 })
80 ;
81 }
82 }
83
84 void measure_G2_tau::collect_results(mpi::communicator const &comm) {
85
86 average_sign = mpi::all_reduce(average_sign, comm);
87 G2_tau = mpi::all_reduce(G2_tau, comm);
88
89 // Rescale sampled Green's function
90 double beta = data.config.beta();
91 double dtau = std::get<0>(G2_tau(0,0).mesh()).delta();
92 G2_tau = G2_tau / (real(average_sign) * beta * std::pow(dtau, 3));
93
94 // Account for
95 // the 1/2 smaller volume of the side bins,
96 // the 1/4 smaller volume of the edge bins, and
97 // the 1/8 smaller volume of the corner bins.
98
99 for (auto &G2_tau_block : G2_tau) {
100 auto _ = all_t{};
101 int n = std::get<0>(G2_tau_block.mesh().components()).size() - 1;
102
103 G2_tau_block[0, _, _] *= 2.0;
104 G2_tau_block[_, 0, _] *= 2.0;
105 G2_tau_block[_, _, 0] *= 2.0;
106
107 G2_tau_block[n, _, _] *= 2.0;
108 G2_tau_block[_, n, _] *= 2.0;
109 G2_tau_block[_, _, n] *= 2.0;
110 }
111 }
112
113} // namespace triqs_cthyb