TRIQS/triqs_ctseg 4.0.0
A TRIQS application
Loading...
Searching...
No Matches
state_hist.cpp
1// Copyright (c) 2024--present, The Simons Foundation
2// Copyright (c) 2024--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 "./state_hist.hpp"
8#include "../logs.hpp"
9
10namespace triqs_ctseg::measures {
11
12 state_hist::state_hist(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 H = nda::zeros<double>(ipow(2, config.n_color()));
17 }
18
19 // -------------------------------------
20
21 void state_hist::accumulate(double s) {
22
23 LOG("\n =================== MEASURE STATE HISTOGRAM ================ \n");
24
26
35
36 Z += s;
37
38 double tau_prev = beta; // time of prevous operator; start with beta
39 nda::vector<bool> state = nda::zeros<bool>(config.n_color());
40 for (auto const &op : colored_ordered_ops(config.seglists)) {
41 int state_idx = 0;
42 for (auto c : range(config.n_color()))
43 if (state(c)) state_idx += ipow(2, c); // get the index of the impurity state
44 H(state_idx) += (tau_prev - op.tau);
45 tau_prev = (double)op.tau;
46 ALWAYS_EXPECTS((state(op.color) == op.is_cdag), "Operator error at color {}", op.color);
47 state(op.color) = !op.is_cdag;
48 }
49
50 // get edge state contribution; tau_prev has time of last operator
51 ALWAYS_EXPECTS((state == nda::zeros<bool>(config.n_color())), "Operator error");
52 H(0) += tau_prev;
53 }
54 // -------------------------------------
55
56 void state_hist::collect_results(mpi::communicator const &c) {
57
58 Z = mpi::all_reduce(Z, c);
59 H = mpi::all_reduce(H, c);
60 H = H / (Z * beta);
61
62 // store the result (not reused later, hence we can move it).
63 results.state_hist = std::move(H);
64 }
65
66} // namespace triqs_ctseg::measures