VMPS++
Loading...
Searching...
No Matches
functions.h
Go to the documentation of this file.
1#ifndef FUNCTIONS_H_
2#define FUNCTIONS_H_
3
4// #include "DmrgTypedefs.h"
5#include "SU2Wrappers.h"
6#include "DmrgExternal.h"
7
8namespace Sym
9{
10 // Crazy that this enum needs to be here, because it is also in DmrgTypedefs.h. But without this, it doesn't compile...
11 #ifndef KIND_ENUM
12 #define KIND_ENUM
14 #endif
15
22 template<typename Symmetry>
23 std::string format (qarray<Symmetry::Nq> qnum)
24 {
25 std::stringstream ss;
26 for (int q=0; q<Symmetry::Nq; ++q)
27 {
28 if (Symmetry::kind()[q] == KIND::S or Symmetry::kind()[q] == KIND::Salt or Symmetry::kind()[q] == KIND::T)
29 {
30 ss << print_frac_nice(boost::rational<int>(qnum[q]-1,2));
31 }
32 else if (Symmetry::kind()[q] == KIND::M)
33 {
34 ss << print_frac_nice(boost::rational<int>(qnum[q],2));
35 }
36 else if (Symmetry::kind()[q] == KIND::Nparity)
37 {
38 string parity = (posmod<2>(qnum[q])==0)? "evn":"odd";
39 ss << parity;
40 }
41 else
42 {
43 ss << qnum[q];
44 }
45 if (q!=Symmetry::Nq-1) {ss << ",";}
46 }
47 return ss.str();
48 }
49
50 template<typename Scalar>
51 Scalar phase(int q)
52 {
53 if (q % 2) {return Scalar(-1.);}
54 return Scalar(1.);
55 }
56
62 template<typename Symmetry>
63 std::vector<std::pair<typename Symmetry::qType,typename Symmetry::qType> >
64 split(const typename Symmetry::qType Q,
65 const std::vector<typename Symmetry::qType>& ql,
66 const std::vector<typename Symmetry::qType> qr)
67 {
68 std::vector<std::pair<typename Symmetry::qType,typename Symmetry::qType> > vout;
69 for (std::size_t q1=0; q1<ql.size(); q1++)
70 for (std::size_t q2=0; q2<qr.size(); q2++)
71 {
72 auto Qs = Symmetry::reduceSilent(ql[q1],qr[q2]);
73 if(auto it = std::find(Qs.begin(),Qs.end(),Q) != Qs.end()) {vout.push_back({ql[q1],qr[q2]});}
74 }
75 return vout;
76 }
77
78 template<typename Symmetry>
79 std::vector<std::pair<std::size_t,std::size_t> >
80 split(const typename Symmetry::qType Q,
81 const std::vector<typename Symmetry::qType>& ql,
82 const std::vector<typename Symmetry::qType> qr,
83 bool INDEX)
84 {
85 std::vector<std::pair<std::size_t,std::size_t> > vout;
86 for (std::size_t q1=0; q1<ql.size(); q1++)
87 for (std::size_t q2=0; q2<qr.size(); q2++)
88 {
89 auto Qs = Symmetry::reduceSilent(ql[q1],qr[q2]);
90 if(auto it = std::find(Qs.begin(),Qs.end(),Q) != Qs.end()) {vout.push_back({q1,q2});}
91 }
92 return vout;
93 }
94
110 void initialize(int maxJ=1, std::string f_3j="", std::string f_6j="", std::string f_9j="")
111 {
112#ifdef USE_WIG_SU2_COEFFS
113 wig_table_init(2*maxJ,9);
114 wig_temp_init(2*maxJ);
115#endif
116
117#ifdef USE_FAST_WIG_SU2_COEFFS
118 fastwigxj_load(f_3j.c_str(), 3, NULL);
119 fastwigxj_load(f_6j.c_str(), 6, NULL);
120 fastwigxj_load(f_9j.c_str(), 9, NULL);
121
122 wig_table_init(2*maxJ,9);
123 wig_temp_init(2*maxJ);
124#endif
125 }
126
127 void finalize(bool PRINT_STATS=false)
128 {
129#ifdef USE_WIG_SU2_COEFFS
130 wig_temp_free();
131 wig_table_free();
132#endif
133
134#ifdef USE_FAST_WIG_SU2_COEFFS
135 if (PRINT_STATS) {std::cout << std::endl; fastwigxj_print_stats();}
136
137 fastwigxj_unload(3);
138 fastwigxj_unload(6);
139 fastwigxj_unload(9);
140
141 wig_temp_free();
142 wig_table_free();
143#endif
144 }
145
146} //end namespace Sym
147
148template<typename Symmetry>
149void transform_base (vector<vector<qarray<Symmetry::Nq> > > &qloc, qarray<Symmetry::Nq> Qtot, bool PRINT=false, bool BACK=false, int L=-1)
150{
151 int length = (L==-1)? static_cast<int>(qloc.size()):L;
152
153 if (Qtot != Symmetry::qvacuum())
154 {
155 if (PRINT) lout << "•old base:" << endl;
156 for (size_t l=0; l<qloc.size(); ++l)
157 {
158 if (PRINT) lout << "l=" << l << endl;
159 for (size_t i=0; i<qloc[l].size(); ++i)
160 {
161 if (PRINT) lout << "qloc: " << qloc[l][i] << endl;
162 for (size_t q=0; q<Symmetry::Nq; ++q)
163 {
164 if (Symmetry::kind()[q] != Sym::KIND::S and Symmetry::kind()[q] != Sym::KIND::Salt and Symmetry::kind()[q] != Sym::KIND::T) //Do not transform the base for non Abelian symmetries
165 {
166 if (BACK) // back transform
167 {
168 qloc[l][i][q] = (qloc[l][i][q] + Qtot[q]) / length;
169 }
170 else // forward transform
171 {
172 qloc[l][i][q] = qloc[l][i][q] * length - Qtot[q];
173 }
174 }
175 }
176 }
177 }
178
179 if (PRINT)
180 {
181 lout << "•transformed base:" << endl;
182 for (size_t l=0; l<qloc.size(); ++l)
183 {
184 lout << "l=" << l << endl;
185 for (size_t i=0; i<qloc[l].size(); ++i)
186 {
187 lout << "qloc: " << qloc[l][i] << endl;
188 }
189 }
190 }
191 }
192};
193
194template<typename Symmetry>
195qarray<Symmetry::Nq> adjustQN (const qarray<Symmetry::Nq> &qin, const size_t number_cells, bool BACK=false)
196{
198 for (size_t q=0; q<Symmetry::Nq; ++q)
199 {
200 if (Symmetry::kind()[q] != Sym::KIND::S and Symmetry::kind()[q] != Sym::KIND::Salt and Symmetry::kind()[q] != Sym::KIND::T) //Do not transform the base for non-Abelian symmetries
201 {
202 if (BACK)
203 {
204 out[q] = qin[q] / number_cells;
205 }
206 else
207 {
208 out[q] = qin[q] * number_cells;
209 }
210 }
211 else
212 {
213 out[q] = qin[q];
214 }
215 }
216 return out;
217};
218#endif
void transform_base(vector< vector< qarray< Symmetry::Nq > > > &qloc, qarray< Symmetry::Nq > Qtot, bool PRINT=false, bool BACK=false, int L=-1)
Definition: functions.h:149
qarray< Symmetry::Nq > adjustQN(const qarray< Symmetry::Nq > &qin, const size_t number_cells, bool BACK=false)
Definition: functions.h:195
@ Nparity
Definition: DmrgTypedefs.h:110
@ Salt
Definition: DmrgTypedefs.h:110
void finalize(bool PRINT_STATS=false)
Definition: functions.h:127
std::string format(qarray< Symmetry::Nq > qnum)
Definition: functions.h:23
Scalar phase(int q)
Definition: functions.h:51
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.h:64
void initialize(int maxJ=1, std::string f_3j="", std::string f_6j="", std::string f_9j="")
Definition: functions.h:110
Definition: qarray.h:26