TRIQS/triqs_ctint 4.0.0
A TRIQS application
Loading...
Searching...
No Matches
density.cpp
1// Copyright (c) 2018--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 "./density.hpp"
7
8using namespace triqs::utility;
9
10namespace triqs_ctint::measures {
11
12 density::density(params_t const &params_, qmc_config_t &qmc_config_, container_set *results) : params(params_), qmc_config(qmc_config_) {
13
14 results->density = block_matrix_t{};
15
16 // Init measurement container and capture view
17 for (auto &[bl, bl_size] : params.gf_struct) {
18 results->density->push_back(zeros<M_tau_scalar_t>(make_shape(bl_size, bl_size)));
19 density_.push_back(results->density->back());
20 }
21 }
22
23 void density::accumulate(mc_weight_t sign) {
24 // Accumulate sign
25 Z += sign;
26
27 // Calculate density matrix
28 for (int bl : range(params.n_blocks())) {
29
30 auto &det = qmc_config.dets[bl];
31 auto &density = density_[bl];
32 int bl_size = density.shape()[0];
33
34 for (int a : range(bl_size))
35 for (int b : range(bl_size)) {
36
37 cdag_t cdag_a{tau_t::get_zero_plus(), a};
38 c_t c_b{tau_t::get_zero(), b};
39
40 density(a, b) += sign * det.try_insert(0, 0, c_b, cdag_a);
41 det.reject_last_try();
42 }
43 }
44 }
45
46 void density::collect_results(mpi::communicator const &comm) {
47 // Collect results and normalize
48 Z = mpi::all_reduce(Z, comm);
49 for (auto &dens_mat : density_) {
50 dens_mat = mpi::all_reduce(dens_mat, comm);
51 dens_mat = dens_mat / Z;
52 }
53 }
54
55} // namespace triqs_ctint::measures
void collect_results(mpi::communicator const &comm)
Collect results and normalize.
Definition density.cpp:46
void accumulate(mc_weight_t sign)
Accumulate M_tau using binning.
Definition density.cpp:23
static constexpr tau_t get_zero()
Return \tau = 0.
Definition vertex.hpp:48
static constexpr tau_t get_zero_plus()
Return \tau = 0^{+} = 0 + \delta.
Definition vertex.hpp:51