TRIQS/triqs_ctseg 4.0.0
A TRIQS application
Loading...
Searching...
No Matches
configuration.hpp
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#pragma once
8#include <vector>
9#include "tau_t.hpp"
10#include "dets.hpp"
11#include "work_data.hpp"
12
13namespace triqs_ctseg {
14
15 // The MC configuration and associated functions.
16 // NB : all the time ordering are in DECREASING order,
17 // in agreement with the usual convention
18
19 // ================= Data structures =================
20
21 // The configuration is made of n_color ordered lists of segments
22 // and (if needed) a list of Jperp lines.
23
24 // --------------- Segment -------------------
25 //
26 // A segment represents a couple (c, cdag), at given tau_t times in [0, beta]
27 // Segment is cyclic if tau_c < tau_cdag, non-cyclic otherwise.
28 //
29 // Some segments are aligned between 2 colors, corresponding to a S^+, S^- operators
30 // The S operators will not be linked to Delta, the hybridization, but to Jperp lines.
31 // The segment stores two booleans (J_c, J_cdag) that indicate whether its operators are
32 // linked to Jperp lines.
33 //
34 // Special case : full lines.
35 // When a line has no operator, we need to take into account 2 states : empty or full.
36 // The full line case is encoded as a [beta, 0] segment, as it naturally yields the correct overlap.
37 // This special case will however need to be treated separately in moves
38 //
39 struct segment_t {
40
41 tau_t tau_c, tau_cdag; // time of c and cdag
42 bool J_c = false, J_cdag = false; // Whether c (resp cdag) is part of a S operator
43
45 [[nodiscard]] tau_t length() const { return tau_c - tau_cdag; };
46
48 static segment_t full_line() { return {tau_t::beta(), tau_t::zero()}; }
49 };
50
51 // simple alias
52 using vec_seg_iter_t = std::vector<segment_t>::const_iterator;
53
54 // ----------------- Jperp line -------------------
55 // Stores the times of a couple (S+, S-)
56 // Note: Jperp expansion only implemented for single orbital
57 // (two colors, spin up and spin down).
58 struct Jperp_line_t {
59 tau_t tau_Sminus, tau_Splus; // times of the S-, S+
60 };
61
62 // ----------------- Operator -------------------
63 // (used by measure state_hist)
64 struct colored_ops_t {
65 tau_t tau;
66 int color;
67 bool is_cdag;
68 };
69
70 // --------------- Configuration ----------------------
71 // The configuration is a list of of segments for each color,
72 // and a list of Jperp lines.
73 struct configuration_t {
74 // A list of segments for each color.
75 // NB: ordered in DECREASING time order of the tau_c.
76 std::vector<std::vector<segment_t>> seglists;
77
78 // List of Jperp lines, NOT ordered.
79 std::vector<Jperp_line_t> Jperp_list;
80
81 // Construct from the number of colors
82 configuration_t(int n_color) : seglists(n_color) {}
83
84 // Number of segments
85 long n_segments() const {
86 return std::accumulate(begin(seglists), end(seglists), 0l, [](long r, auto &v) { return r + v.size(); });
87 }
88
89 // Expansion order in Jperp
90 long Jperp_order() const { return Jperp_list.size(); }
91
92 // Expansion order in Delta
93 long Delta_order() const { return n_segments() - 2 * Jperp_order(); }
94
95 // Accessor number of colors
96 [[nodiscard]] int n_color() const { return seglists.size(); }
97 };
98
99 // =================== Functions to manipulate segments ===================
100
101 // Comparison of segments. s1 < s2 if s1 is left of s2
102 // we order segments by decreasing tau_c (independent of tau_cdag !).
103 inline bool operator<(segment_t const &s1, segment_t const &s2) { return s1.tau_c > s2.tau_c; };
104
105 // Equality of segments based on tau_c, tau_cdag.
106 // NB : J_c, J_cdag are not important here
107 inline bool operator==(segment_t const &s1, segment_t const &s2) {
108 return s1.tau_c == s2.tau_c and s1.tau_cdag == s2.tau_cdag;
109 };
110
111 // Whether a segment is wrapped around beta/0
112 // [c cdag] is not while [cdag c] is. NB : time in decreasing order, left to right
113 inline bool is_cyclic(segment_t const &seg) { return seg.tau_cdag > seg.tau_c; }
114
115 // Check whether segment is a full line.
116 inline bool is_full_line(segment_t const &seg) { return seg == segment_t::full_line(); }
117
118 // Overlap between two non-cyclic segments.
119 double overlap(segment_t const &s1, segment_t const &s2);
120
121 // Flip a segment. J are set to default
122 inline segment_t flip(segment_t const &s) { return {s.tau_cdag, s.tau_c}; }
123
124 // =================== Functions to manipulate std::vector<segment_t> ========
125
126 // lower_bound : find segment at tau if present or the first after tau
127 vec_seg_iter_t lower_bound(std::vector<segment_t> const &seglist, tau_t const &tau);
128
129 // Value of n (= 0 or 1) at tau = beta = 0
130 // 1 iif there is a cyclic segment or a full line
131 int n_at_boundary(std::vector<segment_t> const &seglist);
132
133 // Find density (0 or 1)in seglist to the right of time tau.
134 int n_tau(tau_t const &tau, std::vector<segment_t> const &seglist);
135
136 // Flip config
137 std::vector<segment_t> flip(std::vector<segment_t> const &sl);
138
139 // Overlap between segment and a list of segments.
140 double overlap(std::vector<segment_t> const &seglist, segment_t const &seg);
141
142 // Checks if segment seg can be inserted into the list, i.e. without
143 // overlap with other segment.
144 bool is_insertable_into(segment_t const &seg, std::vector<segment_t> const &seglist);
145
146 // Find the indices of the segments whose cdag are in ]wtau_left,wtau_right[
147 std::vector<long> cdag_in_window(tau_t const &wtau_left, tau_t const &wtau_right,
148 std::vector<segment_t> const &seglist);
149
150 // Fix the list after a change of operator c time in some move
151 // to restore the invariants
152 // 1 -if first segment is cyclic (c has move beyond beta), put it at end
153 // 2- if last segment is such that its tau is > tau of first (c has moved beyond 0), put it first
154 // Only useful when # segments > 1
155 inline void fix_ordering_first_last(std::vector<segment_t> &sl) {
156 if (sl.size() <= 1) return;
157 if (is_cyclic(sl[0])) std::rotate(begin(sl), begin(sl) + 1, end(sl));
158 if (sl.back().tau_c > sl[0].tau_c) std::rotate(begin(sl), end(sl) - 1, end(sl));
159 }
160
161 // Contribution of the dynamical interaction kernel K to the overlap between a segment and a list of segments.
162 // Computes the sum of the s_a s_b K(tau_a - tau_b) where s_a is 1 for cdag and - 1 for c
163 double K_overlap(std::vector<segment_t> const &seglist, tau_t const &tau_c, tau_t const &tau_cdag,
164 gf<imtime, matrix_valued> const &K, int c1, int c2);
165
166 // Contribution of the dynamical interaction kernel K to the overlap between an operator and a list of segments.
167 double K_overlap(std::vector<segment_t> const &seglist, tau_t const &tau, bool is_c,
168 gf<imtime, matrix_valued> const &K, int c1, int c2);
169
170 // List of operators containing all colors.
171 std::vector<colored_ops_t> colored_ordered_ops(std::vector<std::vector<segment_t>> const &seglists);
172
173 // =================== PRINTING ========================
174
175 std::ostream &operator<<(std::ostream &out, std::vector<segment_t> const &sl);
176
177 std::ostream &operator<<(std::ostream &out, configuration_t const &config);
178
179 std::ostream &operator<<(std::ostream &out, std::vector<colored_ops_t> const &col);
180
181} // namespace triqs_ctseg
182
183template <> struct fmt::formatter<triqs_ctseg::configuration_t> : ostream_formatter {};
184
185template <> struct fmt::formatter<std::vector<triqs_ctseg::colored_ops_t>> : ostream_formatter {};
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