TRIQS/triqs_cthyb 4.0.0
A TRIQS application
Loading...
Searching...
No Matches
G_l.cpp
1/*******************************************************************************
2 *
3 * TRIQS: a Toolbox for Research in Interacting Quantum Systems
4 *
5 * Copyright (C) 2014, H. U.R. Strand, P. Seth, I. Krivenko, 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 "G_l.hpp"
23
24namespace triqs_cthyb {
25
26 using namespace triqs::gfs;
27 using namespace triqs::mesh;
28
29 measure_G_l::measure_G_l(std::optional<G_l_t> &G_l_opt, qmc_data const &data, int n_l, gf_struct_t const &gf_struct) : data(data), average_sign(0) {
30 G_l_opt = block_gf<legendre>{{data.config.beta(), Fermion, n_l}, gf_struct};
31 G_l.rebind(*G_l_opt);
32 G_l() = 0.0;
33 }
34
35 void measure_G_l::accumulate(mc_weight_t s) {
36 s *= data.atomic_reweighting;
37 average_sign += s;
38
39 double beta = data.config.beta();
40 auto Tn = triqs::utility::legendre_generator();
41
42 for (auto block_idx : range(G_l.size())) {
43
44 foreach (data.dets[block_idx], [this, s, block_idx, beta, &Tn](op_t const &x, op_t const &y, det_scalar_t M) {
45
46 double poly_arg = 2 * double(y.first - x.first) / beta - 1.0;
47 Tn.reset(poly_arg);
48
49 auto val = (y.first >= x.first ? s : -s) * M;
50
51 for (auto l : G_l[block_idx].mesh()) {
52 // Evaluate all polynomial orders
53 this->G_l[block_idx][l](y.second, x.second) += val * Tn.next();
54 }
55 })
56 ;
57 } // for block_idx
58 }
59
60 void measure_G_l::collect_results(mpi::communicator const &c) {
61
62 average_sign = mpi::all_reduce(average_sign, c);
63 G_l = mpi::all_reduce(G_l, c);
64
65 double beta = data.config.beta();
66
67 for (auto &G_l_block : G_l) {
68 for (auto l : G_l_block.mesh()) {
70 G_l_block[l] *= -(sqrt(2.0 * l.index() + 1.0) / (real(average_sign) * beta));
71 }
72 matrix<double> id(G_l_block.target_shape());
73 id() = 1.0; // this creates an unit matrix
74 enforce_discontinuity(G_l_block, id);
75 }
76 }
77
78} // namespace triqs_cthyb