Xped
Loading...
Searching...
No Matches
functions.hpp
Go to the documentation of this file.
1#ifndef XPED_FUNCTIONS_H_
2#define XPED_FUNCTIONS_H_
3
7
8#include <boost/rational.hpp>
9
10namespace Xped {
11
12namespace util {
13
15inline std::string print_frac_nice(boost::rational<int> r)
16{
17 std::stringstream ss;
18 if(r.denominator() == 1) {
19 ss << r.numerator();
20 } else {
21 ss << r;
22 }
23 return ss.str();
24}
25
26} // namespace util
27
28namespace Sym {
29#ifndef KIND_ENUM
30# define KIND_ENUM
31enum KIND
32{
42 Z2
43};
44#endif
45
52template <typename Symmetry>
54{
55 std::stringstream ss;
56 for(int q = 0; q < Symmetry::Nq; ++q) {
57 if(Symmetry::kind()[q] == KIND::S or Symmetry::kind()[q] == KIND::Salt or Symmetry::kind()[q] == KIND::T) {
58 ss << util::print_frac_nice(boost::rational<int>(qnum[q] - 1, 2));
59 } else if(Symmetry::kind()[q] == KIND::M) {
60 if(Symmetry::IS_MODULAR[q]) {
61 int q_nice = qnum[q];
62 if(std::abs(qnum[q]) > std::abs(qnum[q] - Symmetry::MOD_N[q])) { q_nice = q_nice - Symmetry::MOD_N[q]; }
63 ss << util::print_frac_nice(boost::rational<int>(q_nice, 2));
64 } else {
65 ss << util::print_frac_nice(boost::rational<int>(qnum[q], 2));
66 }
67 } else if(Symmetry::kind()[q] == KIND::Z2) {
68 std::string parity = util::constFct::posmod<2>(qnum[q] == 0) ? "evn" : "odd";
69 ss << parity;
70 } else {
71 ss << qnum[q];
72 }
73 if(q != Symmetry::Nq - 1) { ss << ","; }
74 }
75 if(Symmetry::Nq == 0) { ss << "()"; }
76 return ss.str();
77}
78
79template <typename Scalar>
80Scalar phase(int q)
81{
82 if(q % 2) { return Scalar(-1.); }
83 return Scalar(1.);
84}
85
91template <typename Symmetry>
92std::vector<std::pair<typename Symmetry::qType, typename Symmetry::qType>>
93split(const typename Symmetry::qType Q, const std::vector<typename Symmetry::qType>& ql, const std::vector<typename Symmetry::qType> qr)
94{
95 std::vector<std::pair<typename Symmetry::qType, typename Symmetry::qType>> vout;
96 for(std::size_t q1 = 0; q1 < ql.size(); q1++)
97 for(std::size_t q2 = 0; q2 < qr.size(); q2++) {
98 auto Qs = Symmetry::reduceSilent(ql[q1], qr[q2]);
99 if(auto it = std::find(Qs.begin(), Qs.end(), Q) != Qs.end()) { vout.push_back({ql[q1], qr[q2]}); }
100 }
101 return vout;
102}
103
104template <typename Symmetry>
105std::vector<std::pair<std::size_t, std::size_t>>
106split(const typename Symmetry::qType Q, const std::vector<typename Symmetry::qType>& ql, const std::vector<typename Symmetry::qType> qr)
107{
108 std::vector<std::pair<std::size_t, std::size_t>> vout;
109 for(std::size_t q1 = 0; q1 < ql.size(); q1++)
110 for(std::size_t q2 = 0; q2 < qr.size(); q2++) {
111 auto Qs = Symmetry::reduceSilent(ql[q1], qr[q2]);
112 if(auto it = std::find(Qs.begin(), Qs.end(), Q) != Qs.end()) { vout.push_back({q1, q2}); }
113 }
114 return vout;
115}
116
132inline void initialize(int maxJ = 1, std::string f_3j = "", std::string f_6j = "", std::string f_9j = "")
133{
134 std::ignore = maxJ;
135 std::ignore = f_3j;
136 std::ignore = f_6j;
137 std::ignore = f_9j;
138#ifdef USE_WIG_SU2_COEFFS
139 wig_table_init(2 * maxJ, 9);
140 wig_temp_init(2 * maxJ);
141#endif
142
143#ifdef USE_FAST_WIG_SU2_COEFFS
144 fastwigxj_load(f_3j.c_str(), 3, NULL);
145 fastwigxj_load(f_6j.c_str(), 6, NULL);
146 fastwigxj_load(f_9j.c_str(), 9, NULL);
147
148 wig_table_init(2 * maxJ, 9);
149 wig_temp_init(2 * maxJ);
150#endif
151}
152
153inline void finalize(bool PRINT_STATS = false)
154{
155 std::ignore = PRINT_STATS;
156#ifdef USE_WIG_SU2_COEFFS
157 wig_temp_free();
158 wig_table_free();
159#endif
160
161#ifdef USE_FAST_WIG_SU2_COEFFS
162 if(PRINT_STATS) {
163 std::cout << std::endl;
164 fastwigxj_print_stats();
165 }
166
167 fastwigxj_unload(3);
168 fastwigxj_unload(6);
169 fastwigxj_unload(9);
170
171 wig_temp_free();
172 wig_table_free();
173#endif
174}
175
176} // namespace Sym
177
178template <typename Symmetry>
179qarray<Symmetry::Nq> adjustQN(const qarray<Symmetry::Nq>& qin, const size_t number_cells, bool BACK = false)
180{
182 for(size_t q = 0; q < Symmetry::Nq; ++q) {
183 if(Symmetry::kind()[q] != Sym::KIND::S and Symmetry::kind()[q] != Sym::KIND::Salt and
184 Symmetry::kind()[q] != Sym::KIND::T) // Do not transform the base for non-Abelian symmetries
185 {
186 if(BACK) {
187 out[q] = qin[q] / number_cells;
188 } else {
189 out[q] = qin[q] * number_cells;
190 }
191 } else {
192 out[q] = qin[q];
193 }
194 }
195 return out;
196};
197
198} // namespace Xped
199#endif
KIND
Definition: functions.hpp:32
@ FN
Definition: functions.hpp:38
@ Ndn
Definition: functions.hpp:41
@ M
Definition: functions.hpp:39
@ T
Definition: functions.hpp:35
@ FT
Definition: functions.hpp:36
@ N
Definition: functions.hpp:37
@ S
Definition: functions.hpp:33
@ Z2
Definition: functions.hpp:42
@ Nup
Definition: functions.hpp:40
@ Salt
Definition: functions.hpp:34
void initialize(int maxJ=1, std::string f_3j="", std::string f_6j="", std::string f_9j="")
Definition: functions.hpp:132
Scalar phase(int q)
Definition: functions.hpp:80
std::vector< std::pair< typename Symmetry::qType, typename Symmetry::qType > > split(const typename Symmetry::qType Q, const std::vector< typename Symmetry::qType > &ql, const std::vector< typename Symmetry::qType > qr)
Definition: functions.hpp:93
std::string format(qarray< Symmetry::Nq > qnum)
Definition: functions.hpp:53
void finalize(bool PRINT_STATS=false)
Definition: functions.hpp:153
std::string print_frac_nice(boost::rational< int > r)
Definition: functions.hpp:15
Definition: bench.cpp:62
qarray< Symmetry::Nq > adjustQN(const qarray< Symmetry::Nq > &qin, const size_t number_cells, bool BACK=false)
Definition: functions.hpp:179
Definition: qarray.hpp:30