TRIQS/triqs_ctseg 4.0.0
A TRIQS application
Loading...
Searching...
No Matches
remove_spin_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_spin_segment.hpp"
8#include "../logs.hpp"
9#include <cmath>
10
11namespace triqs_ctseg::moves {
12
13 double remove_spin_segment::attempt() {
14
15 LOG("\n =================== ATTEMPT REMOVE SPIN ================ \n");
16
17 // ------------ Choose a Jperp line --------------
18
19 auto &jl = config.Jperp_list;
20
21 if (jl.empty()) {
22 LOG("No bosonic lines!");
23 return 0;
24 }
25
26 line_idx = rng(jl.size());
27
28 // ------------- Find the hanging segment -------------
29
30 // Find the two segments whose c is connected to the spin line
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);
33
34 // The hanging segment if it is in spin up
35 auto spin_seg_up = segment_t{jl[line_idx].tau_Sminus, jl[line_idx].tau_Splus};
36
37 // The hanging segment if it is in spin down
38 auto spin_seg_down = segment_t{jl[line_idx].tau_Splus, jl[line_idx].tau_Sminus};
39
40 making_full_line = *it_up == spin_seg_up and *it_down == spin_seg_down;
41
42 if (making_full_line) {
43 LOG("Making full line.");
44 // Randomly choose one of the ways of making a full line
45 if (rng(2) == 0) {
46 spin_seg = spin_seg_up;
47 orig_color = 0;
48 dest_color = 1;
49 orig_it = it_up;
50 dest_it = it_down;
51 LOG("Removing segment at spin up (color 0)");
52 } else {
53 spin_seg = spin_seg_down;
54 orig_color = 1;
55 dest_color = 0;
56 orig_it = it_down;
57 dest_it = it_up;
58 LOG("Removing segment at spin down (color 1)");
59 }
60 } else if (*it_up == spin_seg_up) {
61 spin_seg = spin_seg_up;
62 orig_color = 0;
63 dest_color = 1;
64 orig_it = it_up;
65 dest_it = it_down;
66 LOG("Removing segment at spin up (color 0)");
67 } else if (*it_down == spin_seg_down) {
68 spin_seg = spin_seg_down;
69 orig_color = 1;
70 dest_color = 0;
71 orig_it = it_down;
72 dest_it = it_up;
73 LOG("Removing segment at spin down (color 1)");
74 } else {
75 LOG("Bosonic line does not correspond to a segment.");
76 return 0;
77 }
78
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());
82
83 // ------------- Check if space is free -------------
84
85 if (dsl[dest_left_idx].tau_cdag != spin_seg.tau_c) {
86 LOG("Space in opposite line is occupied.");
87 return 0;
88 }
89 LOG("Regrouping between positions {} and {} in opposite spin.", dest_left_idx, dest_right_idx);
90
91 // ------------ Trace ratio -------------
92
93 double ln_trace_ratio = (wdata.mu(dest_color) - wdata.mu(orig_color)) * spin_seg.length();
94 if (wdata.has_Dt) {
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);
97 // "antisegment" - careful with order
98 ln_trace_ratio -= K_overlap(config.seglists[c], spin_seg.tau_cdag, spin_seg.tau_c, wdata.K, dest_color, c);
99 }
100 // Correct for the interactions of the removed operators with themselves
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));
104 }
105 double trace_ratio = std::exp(ln_trace_ratio);
106 trace_ratio /= -(real(wdata.Jperp(double(spin_seg.length()))(0, 0)) / 2);
107
108 // ------------ Det ratio ---------------
109
110 double det_ratio = 1.0;
111
112 // ------------ Proposition ratio ------------
113
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;
116
117 // T direct = 1 / #Jperp * (full_line ? 1/2 : 1) /// because if full_line, rng(2) above !
118 // T inverse = 1/ (# color * #seg in future * new_seg_len^2) * (future_full_line ? 1 : 2)
119 // the (splitting_full_line ...) simplify to a ratio of 2
120 double prop_ratio = double(config.Jperp_list.size())
121 / (double(config.n_color()) * future_number_seg * new_seg_length * new_seg_length / 2);
122
123 LOG("trace_ratio = {}, prop_ratio = {}, det_ratio = {}", trace_ratio, prop_ratio, det_ratio);
124
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);
128 }
129
130 //--------------------------------------------------
131
132 double remove_spin_segment::accept() {
133
134 LOG("\n - - - - - ====> ACCEPT - - - - - - - - - - -\n");
135
136 auto &sl = config.seglists[orig_color];
137 auto &dsl = config.seglists[dest_color];
138
139 // Remove segment at origin
140 sl.erase(orig_it);
141
142 // Regroup segment at destination
143 if (making_full_line) {
144 dsl[0] = segment_t{tau_t::beta(), tau_t::zero()};
145 } else {
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);
150 }
151
152 // Remove Jperp line
153 auto &jl = config.Jperp_list;
154 jl.erase(jl.begin() + line_idx);
155
156 // Check invariant
157 if constexpr (print_logs or ctseg_debug) check_invariant(config, wdata);
158 LOG("Configuration is {}", config);
159
160 return 1.0;
161 }
162
163 //--------------------------------------------------
164 void remove_spin_segment::reject() { LOG("\n - - - - - ====> REJECT - - - - - - - - - - -\n"); }
165
166} // 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