TRIQS/triqs_ctseg 4.0.0
A TRIQS application
Loading...
Searching...
No Matches
nn_tau.cpp
1// Copyright (c) 2022--present, The Simons Foundation
2// Copyright (c) 2022--present, Max Planck Institute for Polymer Research, Mainz, Germany
3// This file is part of TRIQS/ctseg and is licensed under the terms of GPLv3 or later.
4// SPDX-License-Identifier: GPL-3.0-or-later
5// See LICENSE in the root of this distribution for details.
6
7#include "./nn_tau.hpp"
8#include "../logs.hpp"
9
10namespace triqs_ctseg::measures {
11
12 nn_tau::nn_tau(params_t const &p, work_data_t const &wdata, configuration_t const &config, results_t &results)
13 : wdata{wdata}, config{config}, results{results} {
14
15 beta = p.beta;
16 ntau = p.n_tau_chi2;
17 dtau = p.beta / (ntau - 1);
18 n_color = config.n_color();
19 block_number = wdata.block_number;
20 index_in_block = wdata.index_in_block;
21
22 q_tau = gf<imtime>({beta, Boson, ntau}, {n_color, n_color});
23 q_tau() = 0;
24 q_tau_block = make_block2_gf<imtime>({beta, Boson, ntau}, p.gf_struct);
25 }
26
27 // -------------------------------------
28
29 // FIXME mv to nda
30 inline static range::all_t nda_all = range::all_t{};
31
32 void nn_tau::accumulate(double s) {
33
34 LOG("\n =================== MEASURE nn(tau) ================ \n");
35
36 Z += s;
37
38 // <n_a(tau) n_b(0) >
39 for (int b = 0; b < n_color; ++b) {
40 if (n_at_boundary(config.seglists[b]) == 0) continue; // nb = 0, nothing to accumulate
41 for (int a = 0; a < n_color; ++a)
42 for (auto const &seg : config.seglists[a]) {
43
44 // find closest mesh point to the right of c
45 int u_idx_c = (seg.tau_c == tau_t::beta()) ? ntau - 1 : int(std::floor(seg.tau_c / dtau));
46 // find closest mesh point to the left of cdag
47 int u_idx_cdag = int(std::ceil(seg.tau_cdag / dtau));
48
49 auto d = q_tau.data()(nda_all, a, b); // a view of the data for fixed a,b
50 // add + s to the data. NB : id1 > id2
51 auto fill = [s, &d](long u_idx1, long u_idx2) {
52 ALWAYS_EXPECTS((u_idx1 >= u_idx2), "error", 1);
53 for (auto u = u_idx1; u >= u_idx2; --u) d(u) += s;
54 };
55
56 // Execute with 2 cases : cyclic segment or not
57 if (not is_cyclic(seg)) {
58 if (u_idx_c >= u_idx_cdag) fill(u_idx_c, u_idx_cdag);
59 } else { // cyclic segment
60 ALWAYS_EXPECTS((u_idx_cdag >= u_idx_c), "eee", 1);
61 fill(u_idx_c, 0);
62 fill(ntau - 1, u_idx_cdag);
63 }
64 }
65 }
66 }
67
68 // -------------------------------------
69
70 void nn_tau::collect_results(mpi::communicator const &c) {
71
72 Z = mpi::all_reduce(Z, c);
73
74 q_tau = mpi::all_reduce(q_tau, c);
75 q_tau = q_tau / Z; //(beta * Z * q_tau.mesh().delta());
76
77 // store the result
78 for (int c1 : range(n_color)) {
79 for (int c2 : range(n_color)) {
80 q_tau_block(block_number[c1], block_number[c2]).data()(range::all, index_in_block[c1], index_in_block[c2]) =
81 q_tau.data()(range::all, c1, c2);
82 }
83 }
84 results.nn_tau = std::move(q_tau_block);
85 }
86
87} // namespace triqs_ctseg::measures