TRIQS/triqs_ctint 4.0.0
A TRIQS application
Loading...
Searching...
No Matches
spinflip.cpp
1#include "../types.hpp"
2#include "./spinflip.hpp"
3
4namespace triqs_ctint::moves {
5
6 mc_weight_t spinflip::attempt() {
7 TRIQS_ASSERT(n_spinflips == 1); // only single spinflip supported right now
8 vpos.reserve(n_spinflips);
9 vpos.clear();
10
11 // Don't spinflip if there are not enough vertices
12 if (qmc_config->vertex_lst.size() < n_spinflips) return 0.0;
13
14 // Choose one of the vertices for spinflip
15 for (int i = 0; i < n_spinflips; ++i) {
16 int this_vpos = rng(qmc_config->vertex_lst.size());
17 // In case of double spinflip we pick up another vertex
18 if (std::find(vpos.begin(), vpos.end(), this_vpos) == vpos.end()) {
19 vpos.emplace_back(this_vpos);
20 // Lazy insert and capture the weight for the vertex
21 auto &v = qmc_config->vertex_lst[this_vpos];
22 lazy_op << v;
23 } else {
24 lazy_op.reset();
25 return 0;
26 }
27 }
28
29 // Execute the spinflip move
30 g_tau_scalar_t det_ratio = lazy_op.execute_try_change_col_row();
31
32 // Return the overall weight
33 return mc_weight_t{det_ratio};
34 }
35
36 mc_weight_t spinflip::accept() {
37 for (auto &d : qmc_config->dets) d.complete_operation();
38
39 // Flip spin in the vertex list
40 for (auto const &this_vpos : vpos) {
41 auto &v = qmc_config->vertex_lst[this_vpos];
42 v.s = 1 - v.s;
43 }
44
45 return 1.0; // no need for a correction of the sign
46 }
47
49 for (auto &d : qmc_config->dets) d.reject_last_try(); // reject the last try in all determinants
50 }
51
52} // namespace triqs_ctint::moves
mc_weight_t accept()
Accept vertex removal.
Definition spinflip.cpp:36
triqs::mc_tools::random_generator & rng
The random number generator.
Definition spinflip.hpp:19
void reject()
Reject vertex removal.
Definition spinflip.cpp:48
std::vector< int > vpos
Positions at which to flip the spins.
Definition spinflip.hpp:28
lazy_det_operation_t lazy_op
Object that allows to delay determinant operations, necessary for multi-spinflips.
Definition spinflip.hpp:31
mc_weight_t attempt()
Attempt vertex removal.
Definition spinflip.cpp:6
qmc_config_t * qmc_config
The Monte-Carlo configuration.
Definition spinflip.hpp:13
int n_spinflips
Switch for multi vertex spinflips.
Definition spinflip.hpp:22