TRIQS/triqs_ctseg 4.0.0
A TRIQS application
Loading...
Searching...
No Matches
nn_static.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_static.hpp"
8#include "../logs.hpp"
9
10namespace triqs_ctseg::measures {
11
12 nn_static::nn_static(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 n_color = config.n_color();
17 nn = nda::zeros<double>(n_color, n_color);
18 }
19
20 // -------------------------------------
21
22 void nn_static::accumulate(double s) {
23
24 LOG("\n =================== MEASURE <nn> ================ \n");
25
26 Z += s;
27
28 for (int a = 0; a < n_color; ++a)
29 for (int b = 0; b < n_color; ++b) {
30 for (auto const &sa : config.seglists[a]) {
31 for (auto const &sb : config.seglists[b]) //
32 nn(a, b) += s * overlap(sa, sb);
33 }
34 }
35 }
36 // -------------------------------------
37
38 void nn_static::collect_results(mpi::communicator const &c) {
39
40 Z = mpi::all_reduce(Z, c);
41 nn = mpi::all_reduce(nn, c);
42 nn = nn / Z / beta;
43
44 std::map<std::pair<std::string, std::string>, nda::matrix<double>> nn_block;
45 for (long x1 = 0; auto &[bl1, bl1_size] : wdata.gf_struct) {
46 for (long x2 = 0; auto &[bl2, bl2_size] : wdata.gf_struct) {
47 nn_block[{bl1, bl2}] = nn(range(x1, x1 + bl1_size), range(x2, x2 + bl2_size));
48 x2 += bl2_size;
49 }
50 x1 += bl1_size;
51 }
52
53 // store the result (not reused later, hence we can move it).
54 results.nn_static = std::move(nn_block);
55 }
56
57} // namespace triqs_ctseg::measures