VMPS++
Loading...
Searching...
No Matches
SiteOperator.h
Go to the documentation of this file.
1#ifndef SITEOPERATOR_H_
2#define SITEOPERATOR_H_
3
5#include <Eigen/Sparse>
7
8#include "numeric_limits.h"
9
10//forward declarations
11template<typename Symmetry, typename MatrixType_> class SiteOperatorQ;
12template<typename Symmetry> class Qbasis;
13template<typename Symmetry, typename MatrixType_> struct Biped;
14
15//include "tensors/Qbasis.h"
16//include "tensors/Biped.h"
17//include "tensors/SiteOperatorQ.h"
18
30template<typename Symmetry, typename Scalar_>
32{
33 typedef Scalar_ Scalar;
34
36 SiteOperator (const Eigen::SparseMatrix<Scalar_> &data_input, const typename Symmetry::qType& Q_input, std::string label_input="")
37 :data(data_input), Q(Q_input), label(label_input)
38 {};
39
40 typename Symmetry::qType Q = Symmetry::qvacuum();
41 Eigen::SparseMatrix<Scalar_> data;
42
43 void setZero()
44 {
45 data.setZero();
46 Q = Symmetry::qvacuum();
47 }
48
49 template<typename OtherScalar>
51 {
53 Oout.Q = Q;
54 Oout.data = data.template cast<OtherScalar>();
55 #ifdef OPLABELS
56 Oout.label = label;
57 #endif
58 return Oout;
59 }
60
63
68
70
71 std::string label = "";
72};
73
74template<typename Symmetry,typename Scalar_>
77{
78 Qbasis<Symmetry> basis; basis.push_back(Symmetry::qvacuum(),this->data.rows());
79 Biped<Symmetry,Eigen::Matrix<Scalar_,Eigen::Dynamic,Eigen::Dynamic> > mat; mat.push_back(Symmetry::qvacuum(),Symmetry::qvacuum(),this->data);
81 return out;
82}
83
84template<typename Symmetry,typename Scalar_>
86{
87 *this = *this + Op;
88 return *this;
89}
90
91template<typename Symmetry,typename Scalar_>
93{
94 *this = *this - Op;
95 return *this;
96}
97
98template<typename Symmetry, typename Scalar_>
100{
102 Oout.data = O1.data * O2.data;
103 Oout.Q = O1.Q+O2.Q;
104 #ifdef OPLABELS
105 std::stringstream labelstream;
106 labelstream << "(" << O1.label << "*" << O2.label << ")";
107 Oout.label = labelstream.str();
108 #endif
109 return Oout;
110}
111
112template<typename Symmetry, typename Scalar_>
114{
115 assert(O1.Q == O2.Q and "For addition of SiteOperators the operator quantum number needs to be the same.");
117 Oout.data = O1.data + O2.data;
118 Oout.Q = O1.Q;
119 #ifdef OPLABELS
120 std::stringstream labelstream;
121 labelstream << "(" << O1.label << "+" << O2.label << ")";
122 Oout.label = labelstream.str();
123 #endif
124 return Oout;
125}
126
127template<typename Symmetry, typename Scalar_>
129{
130 assert(O1.Q == O2.Q and "For addition of SiteOperators the operator quantum number needs to be the same.");
132 Oout.data = O1.data - O2.data;
133 Oout.Q = O1.Q;
134 #ifdef OPLABELS
135 std::stringstream labelstream;
136 labelstream << "(" << O1.label << "-" << O2.label << ")";
137 Oout.label = labelstream.str();
138 #endif
139 return Oout;
140}
141
142template<typename Symmetry, typename Scalar_, typename OtherScalar>
144{
146 Oout.data = x * O.data;
147 Oout.Q = O.Q;
148 #ifdef OPLABELS
149 std::stringstream labelstream;
150 if(std::abs(x-1.) > ::mynumeric_limits<double>::epsilon())
151 {
152 labelstream << "(" << x << "*" << O.label << ")";
153 }
154 else
155 {
156 labelstream << O.label;
157 }
158 Oout.label = labelstream.str();
159 #endif
160 return Oout;
161}
162
163template<typename Symmetry, typename Scalar_>
165{
167 Oout.data = kroneckerProduct(O1.data,O2.data);
168 Oout.Q = O1.Q+O2.Q;
169 return Oout;
170}
171
172template<typename Symmetry, typename Scalar_>
174{
175 if(O1.Q == O2.Q)
176 {
177 return ((O1.data - O2.data).norm() < ::mynumeric_limits<double>::epsilon());
178 }
179 return false;
180}
181
182template<typename Symmetry, typename Scalar_>
184{
185 return lambda*op;
186}
187
188template<typename Symmetry, typename Scalar_>
191{
192 Q = Symmetry::qvacuum();
193 data.setIdentity();
194}
195
196/*template<typename Symmetry, typename Scalar_>
197std::vector<SiteOperator<Symmetry,Scalar_>> operator*(const std::vector<SiteOperator<Symmetry,Scalar_>> &ops, const Eigen::Matrix<Scalar_, Eigen::Dynamic, Eigen::Dynamic> &mat)
198{
199 assert(ops.size() == mat.rows() and "Dimensions of vector and matrix do not match!");
200 std::vector<SiteOperator<Symmetry, Scalar_>> out;
201 for(std::size_t j=0; j<mat.cols(); ++j)
202 {
203 SiteOperator<Symmetry, Scalar_> temp;
204 std::size_t i=0;
205 for(; std::abs(mat(i,j)) < ::mynumeric_limits<double>::epsilon() and i<mat.rows()-1; ++i){}
206 if(i == mat.rows()-1 and mat.row(i).norm() < ::mynumeric_limits<double>::epsilon())
207 {
208 temp = 0*ops[j];
209 }
210 else
211 {
212 temp = ops[i]*mat(i,j);
213 ++i;
214 }
215 for(; i<mat.rows(); ++i)
216 {
217 if(std::abs(mat(i,j)) > ::mynumeric_limits<double>::epsilon())
218 {
219 temp += ops[i]*mat(i,j);
220 }
221 }
222 out.push_back(temp);
223 }
224 return out;
225}
226
227template<typename Symmetry, typename Scalar_>
228std::vector<SiteOperator<Symmetry,Scalar_>> operator*(const Eigen::Matrix<Scalar_, Eigen::Dynamic, Eigen::Dynamic> &mat, const std::vector<SiteOperator<Symmetry,Scalar_>> &ops)
229{
230 assert(ops.size() == mat.cols() and "Dimensions of matrix and vector do not match!");
231 std::vector<SiteOperator<Symmetry, Scalar_>> out;
232 for(std::size_t i=0; i<mat.rows(); ++i)
233 {
234 SiteOperator<Symmetry, Scalar_> temp;
235 std::size_t j=0;
236 for(; std::abs(mat(i,j)) < ::mynumeric_limits<double>::epsilon() and j<mat.cols()-1; ++j){}
237 if(j == mat.cols()-1 and mat.row(i).norm() < ::mynumeric_limits<double>::epsilon())
238 {
239 temp = 0*ops[i];
240 }
241 else
242 {
243 temp = mat(i,j)*ops[j];
244 ++j;
245 }
246
247 for(; j<mat.cols(); ++j)
248 {
249 if(std::abs(mat(i,j)) > ::mynumeric_limits<double>::epsilon())
250 {
251 temp += mat(i,j)*ops[j];
252 }
253 }
254 out.push_back(temp);
255 }
256 return out;
257}*/
258
259#endif
SiteOperator< Symmetry, Scalar_ > operator-(const SiteOperator< Symmetry, Scalar_ > &O1, const SiteOperator< Symmetry, Scalar_ > &O2)
Definition: SiteOperator.h:128
SiteOperator< Symmetry, Scalar_ > operator+(const SiteOperator< Symmetry, Scalar_ > &O1, const SiteOperator< Symmetry, Scalar_ > &O2)
Definition: SiteOperator.h:113
bool operator==(const SiteOperator< Symmetry, Scalar_ > &O1, const SiteOperator< Symmetry, Scalar_ > &O2)
Definition: SiteOperator.h:173
SiteOperator< Symmetry, Scalar_ > operator*(const SiteOperator< Symmetry, Scalar_ > &O1, const SiteOperator< Symmetry, Scalar_ > &O2)
Definition: SiteOperator.h:99
SiteOperator< Symmetry, Scalar_ > kroneckerProduct(const SiteOperator< Symmetry, Scalar_ > &O1, const SiteOperator< Symmetry, Scalar_ > &O2)
Definition: SiteOperator.h:164
Definition: Qbasis.h:39
void push_back(const std::tuple< qType, Eigen::Index, std::vector< std::string > > &state)
Definition: Qbasis.h:214
Definition: Biped.h:64
void push_back(qType qin, qType qout, const MatrixType_ &M)
Definition: Biped.h:529
SiteOperator< Symmetry, Scalar_ > & operator-=(const SiteOperator< Symmetry, Scalar_ > &Op)
Definition: SiteOperator.h:92
SiteOperator(const Eigen::SparseMatrix< Scalar_ > &data_input, const typename Symmetry::qType &Q_input, std::string label_input="")
Definition: SiteOperator.h:36
SiteOperatorQ< Symmetry, Eigen::Matrix< Scalar_, Eigen::Dynamic, Eigen::Dynamic > > structured()
Definition: SiteOperator.h:76
void setZero()
Definition: SiteOperator.h:43
std::string label
Definition: SiteOperator.h:71
Eigen::SparseMatrix< Scalar_ > data
Definition: SiteOperator.h:41
Symmetry::qType Q
Definition: SiteOperator.h:40
Scalar_ Scalar
Definition: SiteOperator.h:33
SiteOperator< Symmetry, OtherScalar > cast() const
Definition: SiteOperator.h:50
SiteOperator< Symmetry, Scalar_ > & operator+=(const SiteOperator< Symmetry, Scalar_ > &Op)
Definition: SiteOperator.h:85
void setIdentity()
Definition: SiteOperator.h:190