22#include "./G2_tau.hpp"
24namespace triqs_cthyb {
26 using namespace triqs::gfs;
27 using namespace triqs::mesh;
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) {
32 double beta = data.config.beta();
34 order = G2_measures.params.measure_G2_block_order;
35 int n_tau = G2_measures.params.measure_G2_n_tau;
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};
40 G2_tau_opt = make_block2_gf(G2_tau_mesh, G2_measures.gf_struct, order);
42 G2_tau.rebind(*G2_tau_opt);
46 void measure_G2_tau::accumulate(mc_weight_t sign) {
48 sign *= data.atomic_reweighting;
52 for (
auto &m : G2_measures()) {
54 auto G2_tau_block = G2_tau(m.b1.idx, m.b2.idx);
55 bool diag_block = (m.b1.idx == m.b2.idx);
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) {
61 auto compute_M2_product = [&](auto const &i, auto const &j, auto const &k, auto const &l, mc_weight_t sign) {
63 double t1 = double(i.first - l.first);
64 double t2 = double(j.first - l.first);
65 double t3 = double(k.first - l.first);
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);
71 G2_tau_block[closest_mesh_pt(t1, t2, t3)](i.second, j.second, k.second, l.second) += pre_factor * M_ij * M_kl;
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);
84 void measure_G2_tau::collect_results(mpi::communicator
const &comm) {
86 average_sign = mpi::all_reduce(average_sign, comm);
87 G2_tau = mpi::all_reduce(G2_tau, comm);
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));
99 for (
auto &G2_tau_block : G2_tau) {
101 int n = std::get<0>(G2_tau_block.mesh().components()).size() - 1;
103 G2_tau_block[0, _, _] *= 2.0;
104 G2_tau_block[_, 0, _] *= 2.0;
105 G2_tau_block[_, _, 0] *= 2.0;
107 G2_tau_block[n, _, _] *= 2.0;
108 G2_tau_block[_, n, _] *= 2.0;
109 G2_tau_block[_, _, n] *= 2.0;