TRIQS/triqs_ctseg 4.0.0
A TRIQS application
Loading...
Searching...
No Matches
remove_segment.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 "remove_segment.hpp"
8#include "../logs.hpp"
9
10namespace triqs_ctseg::moves {
11
12 double remove_segment::attempt() {
13
14 LOG("\n =================== ATTEMPT REMOVE ================ \n");
15
16 // ------------ Choice of segment --------------
17 // Select removal color
18 color = rng(config.n_color());
19 auto &sl = config.seglists[color];
20 LOG("Removing at color {}", color);
21
22 // If color is empty, nothing to remove
23 if (sl.empty()) {
24 LOG("remove_segment: reject : color is empty.");
25 return 0;
26 }
27
28 // Select segment to remove
29 prop_seg_idx = rng(sl.size());
30 prop_seg = sl[prop_seg_idx];
31 if (is_full_line(prop_seg)) {
32 LOG("Cannot remove full line.");
33 return 0;
34 }
35 if (prop_seg.J_c or prop_seg.J_cdag) {
36 LOG("Segment has spin line attached, cannot remove.");
37 return 0;
38 }
39
40 LOG("Removing segment at position {} : c at {}, cdag at {}", prop_seg_idx, prop_seg.tau_c, prop_seg.tau_cdag);
41
42 // ------------ Trace ratio -------------
43 // Same as insert, up to the sign
44 double ln_trace_ratio = -wdata.mu(color) * prop_seg.length();
45 for (auto c : range(config.n_color())) {
46 if (c != color) { ln_trace_ratio -= -wdata.U(color, c) * overlap(config.seglists[c], prop_seg); }
47 if (wdata.has_Dt)
48 ln_trace_ratio -= K_overlap(config.seglists[c], prop_seg.tau_c, prop_seg.tau_cdag, wdata.K, color, c);
49 }
50 if (wdata.has_Dt) ln_trace_ratio -= real(wdata.K(double(prop_seg.length()))(color, color));
51
52 double trace_ratio = std::exp(ln_trace_ratio);
53
54 // ------------ Det ratio ---------------
55 // same code as in insert. In Insert, it is a true bound, does not insert at same time
56 auto bl = wdata.block_number[color];
57 auto &D = wdata.dets[bl];
58 auto det_ratio = D.try_remove(det_lower_bound_x(D, prop_seg.tau_cdag), //
59 det_lower_bound_y(D, prop_seg.tau_c));
60
61 // ------------ Proposition ratio ------------
62
63 double current_number_segments = sl.size();
64 double future_number_intervals = std::max(1, int(sl.size()) - 1);
65 // Insertion window for the reverse move insert_segment
66 // initialise at (beta,0)
67 auto tau_left = tau_t::beta(), tau_right = tau_t::zero();
68 if (current_number_segments != 1) {
69 // Find left, right, with cyclicity
70 tau_right = sl[modulo(prop_seg_idx + 1, sl.size())].tau_c;
71 tau_left = sl[modulo(prop_seg_idx - 1, sl.size())].tau_cdag;
72 }
73 auto window_length = double(tau_left - tau_right);
74
75 double prop_ratio = current_number_segments
76 / (future_number_intervals * window_length * window_length / (current_number_segments == 1 ? 1 : 2));
77 LOG("trace_ratio = {}, prop_ratio = {}, det_ratio = {}", trace_ratio, prop_ratio, det_ratio);
78
79 det_sign = (det_ratio > 0) ? 1.0 : -1.0;
80 double prod = trace_ratio * det_ratio * prop_ratio;
81
82 return (std::isfinite(prod)) ? prod : det_sign;
83 }
84
85 //--------------------------------------------------
86
87 double remove_segment::accept() {
88
89 LOG("\n - - - - - ====> ACCEPT - - - - - - - - - - -\n");
90
91 double initial_sign = trace_sign(wdata);
92 LOG("Initial sign is {}. Initial configuration: {}", initial_sign, config);
93
94 // Update the dets
95 wdata.dets[wdata.block_number[color]].complete_operation();
96
97 auto &sl = config.seglists[color];
98 // Remove the segment
99 sl.erase(sl.begin() + prop_seg_idx);
100
101 double final_sign = trace_sign(wdata);
102 double sign_ratio = initial_sign / final_sign;
103 LOG("Final sign is {}", final_sign);
104
105 // Check invariant
106 if constexpr (print_logs or ctseg_debug) check_invariant(config, wdata);
107
108 if (sign_ratio * det_sign == -1.0) wdata.minus_sign = true;
109
110 LOG("Configuration is {}", config);
111
112 return sign_ratio;
113 }
114
115 //--------------------------------------------------
116 void remove_segment::reject() {
117 LOG("\n - - - - - ====> REJECT - - - - - - - - - - -\n");
118 wdata.dets[wdata.block_number[color]].reject_last_try();
119 }
120
121} // namespace triqs_ctseg::moves
static tau_t beta()
tau_t at tau = beta
Definition tau_t.hpp:67
static tau_t zero()
$\tau = 0$
Definition tau_t.hpp:70