7#include "remove_spin_segment.hpp"
11namespace triqs_ctseg::moves {
13 double remove_spin_segment::attempt() {
15 LOG(
"\n =================== ATTEMPT REMOVE SPIN ================ \n");
19 auto &jl = config.Jperp_list;
22 LOG(
"No bosonic lines!");
26 line_idx = rng(jl.size());
31 auto it_up = lower_bound(config.seglists[0], config.Jperp_list[line_idx].tau_Sminus);
32 auto it_down = lower_bound(config.seglists[1], config.Jperp_list[line_idx].tau_Splus);
35 auto spin_seg_up = segment_t{jl[line_idx].tau_Sminus, jl[line_idx].tau_Splus};
38 auto spin_seg_down = segment_t{jl[line_idx].tau_Splus, jl[line_idx].tau_Sminus};
40 making_full_line = *it_up == spin_seg_up and *it_down == spin_seg_down;
42 if (making_full_line) {
43 LOG(
"Making full line.");
46 spin_seg = spin_seg_up;
51 LOG(
"Removing segment at spin up (color 0)");
53 spin_seg = spin_seg_down;
58 LOG(
"Removing segment at spin down (color 1)");
60 }
else if (*it_up == spin_seg_up) {
61 spin_seg = spin_seg_up;
66 LOG(
"Removing segment at spin up (color 0)");
67 }
else if (*it_down == spin_seg_down) {
68 spin_seg = spin_seg_down;
73 LOG(
"Removing segment at spin down (color 1)");
75 LOG(
"Bosonic line does not correspond to a segment.");
79 auto &dsl = config.seglists[dest_color];
80 dest_right_idx = dest_it - dsl.cbegin();
81 dest_left_idx = modulo(dest_right_idx - 1, dsl.size());
85 if (dsl[dest_left_idx].tau_cdag != spin_seg.tau_c) {
86 LOG(
"Space in opposite line is occupied.");
89 LOG(
"Regrouping between positions {} and {} in opposite spin.", dest_left_idx, dest_right_idx);
93 double ln_trace_ratio = (wdata.mu(dest_color) - wdata.mu(orig_color)) * spin_seg.length();
95 for (
auto c : range(config.n_color())) {
96 ln_trace_ratio -= K_overlap(config.seglists[c], spin_seg.tau_c, spin_seg.tau_cdag, wdata.K, orig_color, c);
98 ln_trace_ratio -= K_overlap(config.seglists[c], spin_seg.tau_cdag, spin_seg.tau_c, wdata.K, dest_color, c);
101 ln_trace_ratio -= real(wdata.K(
double(spin_seg.length()))(orig_color, orig_color));
102 ln_trace_ratio -= real(wdata.K(
double(spin_seg.length()))(dest_color, dest_color));
103 ln_trace_ratio += 2 * real(wdata.K(
double(spin_seg.length()))(orig_color, dest_color));
105 double trace_ratio = std::exp(ln_trace_ratio);
106 trace_ratio /= -(real(wdata.Jperp(
double(spin_seg.length()))(0, 0)) / 2);
110 double det_ratio = 1.0;
114 tau_t new_seg_length = making_full_line ?
tau_t::beta() : dsl[dest_left_idx].tau_c - dsl[dest_right_idx].tau_cdag;
115 double future_number_seg = making_full_line ? 1 : double(dsl.size()) - 1;
120 double prop_ratio = double(config.Jperp_list.size())
121 / (double(config.n_color()) * future_number_seg * new_seg_length * new_seg_length / 2);
123 LOG(
"trace_ratio = {}, prop_ratio = {}, det_ratio = {}", trace_ratio, prop_ratio, det_ratio);
125 double prod = trace_ratio * det_ratio * prop_ratio;
126 det_sign = (det_ratio > 0) ? 1.0 : -1.0;
127 return (std::isfinite(prod) ? prod : det_sign);
132 double remove_spin_segment::accept() {
134 LOG(
"\n - - - - - ====> ACCEPT - - - - - - - - - - -\n");
136 auto &sl = config.seglists[orig_color];
137 auto &dsl = config.seglists[dest_color];
143 if (making_full_line) {
146 auto new_seg = segment_t{dsl[dest_left_idx].tau_c, dsl[dest_right_idx].tau_cdag, dsl[dest_left_idx].J_c,
147 dsl[dest_right_idx].J_cdag};
148 dsl[dest_left_idx] = new_seg;
149 dsl.erase(dsl.begin() + dest_right_idx);
153 auto &jl = config.Jperp_list;
154 jl.erase(jl.begin() + line_idx);
157 if constexpr (print_logs or ctseg_debug) check_invariant(config, wdata);
158 LOG(
"Configuration is {}", config);
164 void remove_spin_segment::reject() { LOG(
"\n - - - - - ====> REJECT - - - - - - - - - - -\n"); }
static tau_t beta()
tau_t at tau = beta
static tau_t zero()
$\tau = 0$