TRIQS/triqs_ctseg 4.0.0
A TRIQS application
Loading...
Searching...
No Matches
swap_spin_lines.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 "swap_spin_lines.hpp"
8#include "../logs.hpp"
9#include <cmath>
10
11namespace triqs_ctseg::moves {
12
13 double swap_spin_lines::attempt() {
14
15 LOG("\n =================== ATTEMPT SWAP SPIN LINES ================ \n");
16
17 // ------------ Choose two spin lines --------------
18
19 auto &jl = config.Jperp_list;
20
21 if (jl.empty() or jl.size() == 1) {
22 LOG("Nothing to swap!");
23 return 0;
24 }
25
26 first_line_idx = rng(jl.size());
27 second_line_idx = rng(jl.size() - 1);
28 if (second_line_idx >= first_line_idx) ++second_line_idx; // trick to select second_line_idx ! = first_line_idx
29
30 auto &l1 = jl[first_line_idx];
31 auto &l2 = jl[second_line_idx];
32
33 // ------------ Trace ratio -------------
34
35 double J_current = //
36 real(wdata.Jperp(double(l1.tau_Sminus - l1.tau_Splus))(0, 0)) * //
37 real(wdata.Jperp(double(l2.tau_Sminus - l2.tau_Splus))(0, 0));
38
39 double J_future = //
40 real(wdata.Jperp(double(l1.tau_Sminus - l2.tau_Splus))(0, 0)) * //
41 real(wdata.Jperp(double(l2.tau_Sminus - l1.tau_Splus))(0, 0));
42
43 double trace_ratio = J_future / J_current;
44
45 // ------------ Det ratio ---------------
46
47 double det_ratio = 1.0;
48
49 // ------------ Proposition ratio ------------
50
51 double prop_ratio = 1.0;
52
53 LOG("trace_ratio = {}, prop_ratio = {}, det_ratio = {}", trace_ratio, prop_ratio, det_ratio);
54
55 double prod = trace_ratio * det_ratio * prop_ratio;
56 return (std::isfinite(prod) ? prod : 1);
57 }
58
59 // --------------------------------------------
60
61 double swap_spin_lines::accept() {
62
63 LOG("\n - - - - - ====> ACCEPT - - - - - - - - - - -\n");
64
65 auto &jl = config.Jperp_list;
66 auto &l1 = jl[first_line_idx];
67 auto &l2 = jl[second_line_idx];
68
69 // Swap lines
70 std::swap(l1.tau_Splus, l2.tau_Splus);
71
72 // Check invariant
73 if constexpr (print_logs or ctseg_debug) check_invariant(config, wdata);
74 LOG("Configuration is {}", config);
75
76 return 1.0;
77 }
78
79 //--------------------------------------------------
80 void swap_spin_lines::reject() { LOG("\n - - - - - ====> REJECT - - - - - - - - - - -\n"); }
81
82} // namespace triqs_ctseg::moves