TRIQS/triqs_ctint 4.0.0
A TRIQS application
Loading...
Searching...
No Matches
insert.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 "./insert.hpp"
7
8namespace triqs_ctint::moves {
9
10 mc_weight_t insert::attempt() {
11 TRIQS_ASSERT(n_insertions > 0);
12
13 auto single_insert = [&]() {
14 // Pick up one factory at random
15 int n_fact = vertex_factories.size();
16 auto const &fact = vertex_factories[rng(n_fact)];
17
18 // Generate a vertex from the factory
19 vertex_t v = fact();
20
21 // Lazy add the vertex to the det
22 lazy_op << v;
23
24 // Calculate Monte-Carlo weight
25 double insert_proposition_proba = v.proposition_proba / n_fact;
26 U_scalar_t weight = v.amplitude / insert_proposition_proba;
27
28 // Move new vertex to its storage
29 qmc_config->vertex_lst.push_back(std::move(v));
30
31 return weight;
32 };
33
34 // Lazy insert and capture the weight for the vertices
35 U_scalar_t ratio = 1;
36 for (int i = 0; i < n_insertions; ++i) { ratio *= single_insert(); }
37
38 // Execute the insertion move
39 g_tau_scalar_t const det_ratio = lazy_op.execute_try_insert();
40
41 // Calculate the removal proposition probability
42 double remove_proposition_proba = 0.0;
43 if (max_order == -1 || qmc_config->perturbation_order() < max_order) {
44 remove_proposition_proba = 1.0 / std::pow(qmc_config->perturbation_order(), n_insertions);
45 }
46
47 // Return the overall weight
48 return mc_weight_t{det_ratio} * remove_proposition_proba * ratio;
49 }
50
51 mc_weight_t insert::accept() {
52 for (auto &d : qmc_config->dets) d.complete_operation(); // maybe doing nothing if not try_insert but it is quick
53 return 1.0; // no need for a correction of the sign
54 }
55
57 for (int i = 0; i < n_insertions; ++i) qmc_config->vertex_lst.pop_back(); // remove the last insertions.
58 for (auto &d : qmc_config->dets) d.reject_last_try(); // reject the last try in all determinants
59 }
60
61} // namespace triqs_ctint::moves
mc_weight_t attempt()
Attempt vertex insertion.
Definition insert.cpp:10
triqs::mc_tools::random_generator & rng
The random number generator.
Definition insert.hpp:24
void reject()
Reject vertex insertion.
Definition insert.cpp:56
int n_insertions
Switch for double vertex insertions.
Definition insert.hpp:27
mc_weight_t accept()
Accept vertex insertion.
Definition insert.cpp:51
std::vector< vertex_factory_t > const & vertex_factories
Factory that randomly generates vertices.
Definition insert.hpp:21
lazy_det_operation_t lazy_op
Object that allows to delay determinant operations, necessary for multi-inserts/removes.
Definition insert.hpp:33
qmc_config_t * qmc_config
The Monte-Carlo configuration.
Definition insert.hpp:18
int max_order
Maximum perturbation order (<0 : unlimited).
Definition insert.hpp:30
U_scalar_t amplitude
Amplitude of the vertex, i.e. U, U(tau1-tau2), etc...
Definition vertex.hpp:109
double proposition_proba
Probability of proposition for this vertex.
Definition vertex.hpp:112