TRIQS/triqs_ctint 4.0.0
A TRIQS application
Loading...
Searching...
No Matches
M3pp_iw.cpp
1// Copyright (c) 2017--present, The Simons Foundation
2// This file is part of TRIQS/ctint and is licensed under the terms of GPLv3 or later.
3// SPDX-License-Identifier: GPL-3.0-or-later
4// See LICENSE in the root of this distribution for details.
5
6#include "./M3pp_iw.hpp"
7
8namespace triqs_ctint::measures {
9
10 M3pp_iw::M3pp_iw(params_t const &params_, qmc_config_t const &qmc_config_, container_set *results, g_tau_cv_t G0_tau_)
11 : params(params_), qmc_config(qmc_config_), buf_arrarr(params_.n_blocks()), G0_tau(std::move(G0_tau_)) {
12
13 // Construct Matsubara mesh
14 mesh::imfreq iW_mesh{params.beta, Boson, params.n_iW_M3};
15 mesh::imfreq iw_mesh{params.beta, Fermion, params.n_iw_M3};
16 mesh::prod<imfreq, imfreq> M3pp_iw_mesh{iW_mesh, iw_mesh};
17
18 // Init measurement container and capture view
19 results->M3pp_iw_nfft = make_block2_gf(M3pp_iw_mesh, params.gf_struct);
20 M3pp_iw_.rebind(results->M3pp_iw_nfft.value());
21 M3pp_iw_() = 0;
22
23 // Initialize intermediate scattering matrix
24 mesh::imfreq iw_mesh_large{params.beta, Fermion, params.n_iw_M3 + params.n_iW_M3};
25 GM = block_gf{iw_mesh_large, params.gf_struct};
26
27 // Create nfft buffers
28 for (int b : range(params.n_blocks())) {
29 auto init_target_func = [&](int i, int j) {
30 return nfft_buf_t<1>{slice_target_to_scalar(GM[b], i, j).data(), params.nfft_buf_size, params.beta};
31 };
32 buf_arrarr(b) = array_adapter{GM[b].target_shape(), init_target_func};
33 }
34 }
35
36 void M3pp_iw::accumulate(mc_weight_t sign) {
37 // Accumulate sign
38 Z += sign;
39
40 // Calculate intermediate scattering matrix
41 GM() = 0;
42 for (int bl : range(params.n_blocks())) {
43 int bl_size = GM[bl].target_shape()[0];
44 for (int b_u : range(bl_size))
45 //for (auto &[c_i, cdag_j, Ginv1] : qmc_config.dets[bl1]) // FIXME c++17
46 foreach (qmc_config.dets[bl], [&](c_t const &c_i, cdag_t const &cdag_j, auto const &Ginv_ji) {
47 auto G0_bj = G0_tau[bl][closest_mesh_pt(params.beta - double(cdag_j.tau))](b_u, cdag_j.u);
48 buf_arrarr(bl)(b_u, c_i.u).push_back({params.beta - double(c_i.tau)}, G0_bj * Ginv_ji);
49 });
50 }
51 for (auto &buf_arr : buf_arrarr)
52 for (auto &buf : buf_arr) buf.flush(); // Flush remaining points from all buffers
53
54 auto [iW_mesh, iw_mesh] = M3pp_iw_(0, 0).mesh();
55
56 for (int bl1 : range(params.n_blocks()))
57 for (int bl2 : range(params.n_blocks())) {
58
59 int bl1_size = GM[bl1].target_shape()[0];
60 int bl2_size = GM[bl2].target_shape()[0];
61 auto const &GM1 = GM[bl1];
62 auto const &GM2 = GM[bl2];
63 auto &M3pp_iw = M3pp_iw_(bl1, bl2);
64
65 for (auto iW : iW_mesh)
66 for (auto iw : iw_mesh)
67 for (int i : range(bl1_size))
68 for (int j : range(bl1_size))
69 for (int k : range(bl2_size))
70 for (int l : range(bl2_size)) {
71 M3pp_iw[iW, iw](i, j, k, l) += sign * GM1[iw.value()](j, i) * GM2[iW - iw](l, k);
72 if (bl1 == bl2) { M3pp_iw[iW, iw](i, j, k, l) -= sign * GM1[iw.value()](l, i) * GM2[iW - iw](j, k); }
73 }
74 }
75 }
76
77 void M3pp_iw::collect_results(mpi::communicator const &comm) {
78 // Collect results and normalize
79 Z = mpi::all_reduce(Z, comm);
80 M3pp_iw_ = mpi::all_reduce(M3pp_iw_, comm);
81 M3pp_iw_ = M3pp_iw_ / Z;
82 }
83
84} // namespace triqs_ctint::measures
void accumulate(mc_weight_t sign)
Accumulate M_tau using binning.
Definition M3pp_iw.cpp:36
void collect_results(mpi::communicator const &comm)
Collect results and normalize.
Definition M3pp_iw.cpp:77