VMPS++
Loading...
Searching...
No Matches
VumpsTransferMatrix.h
Go to the documentation of this file.
1#ifndef VANILLA_VUMPS_TRANSFERMATRIX_AA
2#define VANILLA_VUMPS_TRANSFERMATRIX_AA
3
5//#include "pivot/DmrgPivotVector.h"
6
11template<typename Symmetry, typename Scalar>
13{
15
17 :DIR(DIR_input)
18 {};
19
21 const vector<vector<Biped<Symmetry,Matrix<Scalar,Dynamic,Dynamic> > > > &Abra_input,
22 const vector<vector<Biped<Symmetry,Matrix<Scalar,Dynamic,Dynamic> > > > &Aket_input,
23 const vector<vector<qarray<Symmetry::Nq> > > &qloc_input,
24 bool SHIFTED_input = false,
25 qarray<Symmetry::Nq> Qtot_input = Symmetry::qvacuum())
26 :DIR(DIR_input), Abra(Abra_input), Aket(Aket_input), qloc(qloc_input), SHIFTED(SHIFTED_input), Qtot(Qtot_input)
27 {}
28
30
32 vector<vector<Biped<Symmetry,Matrix<Scalar,Dynamic,Dynamic> > > > Aket;
33 vector<vector<Biped<Symmetry,Matrix<Scalar,Dynamic,Dynamic> > > > Abra;
35
37
38 bool SHIFTED = false; // true for solve_linear with 2-site Hamiltonian, code commented out and needs review
39
40 vector<vector<qarray<Symmetry::Nq> > > qloc;
42
44 Scalar TopEigval;
46};
47
48template<typename Symmetry, typename Scalar>
49inline size_t dim (const TransferMatrix<Symmetry,Scalar> &H)
50{
51 return 0;
52}
53
54template<typename Symmetry, typename Scalar_>
56{
57 typedef Scalar_ Scalar;
58
60
61 TransferVector (const Biped<Symmetry,Matrix<Scalar_,Dynamic,Dynamic> > &data_input)
62 {
63 data = data_input;
64 };
65
70
73 template<typename OtherScalar> TransferVector<Symmetry,Scalar_>& operator*= (const OtherScalar &alpha);
74 template<typename OtherScalar> TransferVector<Symmetry,Scalar_>& operator/= (const OtherScalar &alpha);
75
77};
78
79template<typename Symmetry, typename Scalar1, typename Scalar2>
81{
82 Vout.data.clear();
83 size_t Lcell = H.qloc.size();
84
85 assert(H.SHIFTED == false);
86
87 if (H.SHIFTED == false)
88 {
89 if (H.DIR == VMPS::DIRECTION::RIGHT) // contract from right to left
90 {
93 for (int l=Lcell-1; l>=0; --l)
94 {
95 contract_R(R, H.Abra[l], H.Aket[l], H.qloc[l], Rnext); // RANDOMIZE=false, CLEAR=false
96 R.clear();
97 R = Rnext;
98 Rnext.clear();
99 }
100 Vout.data = R;
101 }
102 else if (H.DIR == VMPS::DIRECTION::LEFT) // contract from left to right
103 {
106 for (size_t l=0; l<Lcell; ++l)
107 {
108 contract_L(L, H.Abra[l], H.Aket[l], H.qloc[l], Lnext); // RANDOMIZE=false, CLEAR=false
109 L.clear();
110 L = Lnext;
111 Lnext.clear();
112 }
113 Vout.data = L;
114 }
115 }
116// else
117// {
118// Vout = Vin;
119// Vout.setZero();
120//
121// PivotVector<Symmetry,Scalar2> TxV = Vin;
122// TxV.setZero();
123//
124// if (H.gauge == GAUGE::R)
125// {
126// Biped<Symmetry,Matrix<Scalar2,Dynamic,Dynamic> > Rnext;
127// Biped<Symmetry,Matrix<Scalar2,Dynamic,Dynamic> > R = Vin.data[0];
128// for (int l=Lcell-1; l>=0; --l)
129// {
130// contract_R(R, H.Abra[l], H.Aket[l], H.qloc[l], Rnext);
131// R.clear();
132// R = Rnext;
133// Rnext.clear();
134// }
135// Vout.data[0] = R;
136// }
137// else if (H.gauge == GAUGE::L)
138// {
139// Biped<Symmetry,Matrix<Scalar2,Dynamic,Dynamic> > Lnext;
140// Biped<Symmetry,Matrix<Scalar2,Dynamic,Dynamic> > L = Vin.data[0];
141// for (size_t l=0; l<Lcell; ++l)
142// {
143// contract_L (L, H.Abra[l], H.Aket[l], H.qloc[l], Lnext);
144// L.clear();
145// L = Lnext;
146// Lnext.clear();
147// }
148// Vout.data[0] = L;
149// }
150//
151// Scalar2 LdotR;
152// if (H.gauge == GAUGE::R)
153// {
155// LdotR = (H.LReigen.template cast<Matrix<Scalar2,Dynamic,Dynamic> >().contract(Vin.data[0])).trace();
156// }
157// else if (H.gauge == GAUGE::L)
158// {
160// LdotR = (Vin.data[0].contract(H.LReigen.template cast<Matrix<Scalar2,Dynamic,Dynamic> >())).trace();
161// }
162//
163// for (size_t q=0; q<TxV.data[0].dim; ++q)
164// {
165// qarray2<Symmetry::Nq> quple = {TxV.data[0].in[q], TxV.data[0].out[q]};
166// auto it = Vin.data[0].dict.find(quple);
167//
168// Matrix<Scalar2,Dynamic,Dynamic> Mtmp;
169// if (it != Vin.data[0].dict.end())
170// {
171// Mtmp = Vin.data[0].block[it->second] - TxV.data[0].block[q] +
172// LdotR * Matrix<Scalar2,Dynamic,Dynamic>::Identity(Vin.data[0].block[it->second].rows(),
173// Vin.data[0].block[it->second].cols());
174// }
175//
176// if (Mtmp.size() != 0)
177// {
178// auto ip = Vout.data[0].dict.find(quple);
179// if (ip != Vout.data[0].dict.end())
180// {
181// if (Vout.data[0].block[ip->second].rows() != Mtmp.rows() or
182// Vout.data[0].block[ip->second].cols() != Mtmp.cols())
183// {
184// Vout.data[0].block[ip->second] = Mtmp;
185// }
186// else
187// {
188// Vout.data[0].block[ip->second] += Mtmp;
189// }
190// }
191// else
192// {
193// cout << termcolor::red << "push_back that shouldn't be: TransferMatrix" << termcolor::reset << endl;
194// Vout.data[0].push_back(quple, Mtmp);
195// }
196// }
197// }
198// }
199
201 {
202 Vout.data.addScale(-(H.TopEigval * H.TopEigvec.template cast<Matrix<Scalar2,Dynamic,Dynamic> >().adjoint().contract(Vin.data).trace()),
203 H.TopEigvec.template cast<Matrix<Scalar2,Dynamic,Dynamic> >());
204 }
205}
206
207template<typename Symmetry, typename Scalar1, typename Scalar2>
209{
211 HxV(H,Vinout,Vtmp);
212 Vinout = Vtmp;
213}
214
215template<typename Symmetry, typename Scalar>
216inline size_t dim (const TransferVector<Symmetry,Scalar> &V)
217{
218 size_t out = 0;
219 for (size_t q=0; q<V.data.dim; ++q)
220 {
221 out += V.data.block[q].size();
222 }
223 return out;
224}
225
226template<typename Symmetry, typename Scalar>
228{
229 return isReal(dot(V,V));
230}
231
232template<typename Symmetry, typename Scalar>
233inline double norm (const TransferVector<Symmetry,Scalar> &V)
234{
235 return sqrt(squaredNorm(V));
236}
237
238template<typename Symmetry, typename Scalar>
240{
241 V /= norm(V);
242}
243
244template<typename Symmetry, typename Scalar>
246{
247// cout << "begin dot" << endl;
248// cout << "dot res=" << (V1.data.adjoint() * V2.data).trace() << endl;
249// return (V1.data.adjoint() * V2.data).trace();
250 return V1.data.adjoint().contract(V2.data).trace();
251}
252
253template<typename Symmetry, typename Scalar>
256{
257 data.addScale(1.,Vrhs.data);
258 return *this;
259}
260
261template<typename Symmetry, typename Scalar>
264{
265 data.addScale(-1.,Vrhs.data);
266 return *this;
267}
268
269template<typename Symmetry, typename Scalar>
270template<typename OtherScalar>
272operator*= (const OtherScalar &alpha)
273{
274 for (size_t q=0; q<data.dim; ++q)
275 {
276 data.block[q] *= alpha;
277 }
278 return *this;
279}
280
281template<typename Symmetry, typename Scalar>
282template<typename OtherScalar>
284operator/= (const OtherScalar &alpha)
285{
286 for (size_t q=0; q<data.dim; ++q)
287 {
288 data.block[q] /= alpha;
289 }
290 return *this;
291}
292
293template<typename Symmetry, typename Scalar, typename OtherScalar>
295{
296 return V *= alpha;
297}
298
299template<typename Symmetry, typename Scalar, typename OtherScalar>
301{
302 return V /= alpha;
303}
304
305template<typename Symmetry, typename Scalar>
307{
309 Vout.data.addScale(+1.,V2.data);
310 return Vout;
311}
312
313template<typename Symmetry, typename Scalar>
315{
317 Vout.data.addScale(-1.,V2.data);
318 return Vout;
319}
320
321template<typename Symmetry, typename Scalar>
323{
324 V.data.setZero();
325}
326
327template<typename Symmetry, typename Scalar, typename OtherScalar>
328inline void addScale (const OtherScalar alpha, const TransferVector<Symmetry,Scalar> &Vin, TransferVector<Symmetry,Scalar> &Vout)
329{
330 Vout.data.addScale(alpha,Vin.data);
331}
332
333template<typename Symmetry, typename Scalar>
334struct GaussianRandomVector<TransferVector<Symmetry,Scalar>,Scalar>
335{
336 static void fill (size_t N, TransferVector<Symmetry,Scalar> &Vout)
337 {
338 for (size_t q=0; q<Vout.data.dim; ++q)
339 for (size_t i=0; i<Vout.data.block[q].rows(); ++i)
340 for (size_t j=0; j<Vout.data.block[q].cols(); ++j)
341 {
342 Vout.data.block[q](i,j) = threadSafeRandUniform<Scalar>(-1.,1.);
343 }
344 normalize(Vout);
345 }
346};
347
348#endif
void normalize(PivotVector< Symmetry, Scalar_ > &V)
double isReal(double x)
Definition: DmrgTypedefs.h:21
size_t dim(const TransferMatrix< Symmetry, Scalar > &H)
double squaredNorm(const TransferVector< Symmetry, Scalar > &V)
void HxV(const TransferMatrix< Symmetry, Scalar1 > &H, const TransferVector< Symmetry, Scalar2 > &Vin, TransferVector< Symmetry, Scalar2 > &Vout)
void addScale(const OtherScalar alpha, const TransferVector< Symmetry, Scalar > &Vin, TransferVector< Symmetry, Scalar > &Vout)
void normalize(TransferVector< Symmetry, Scalar > &V)
void setZero(TransferVector< Symmetry, Scalar > &V)
Scalar dot(const TransferVector< Symmetry, Scalar > &V1, const TransferVector< Symmetry, Scalar > &V2)
TransferVector< Symmetry, Scalar > operator*(const OtherScalar &alpha, TransferVector< Symmetry, Scalar > V)
double norm(const TransferVector< Symmetry, Scalar > &V)
TransferVector< Symmetry, Scalar > operator-(const TransferVector< Symmetry, Scalar > &V1, const TransferVector< Symmetry, Scalar > &V2)
TransferVector< Symmetry, Scalar > operator+(const TransferVector< Symmetry, Scalar > &V1, const TransferVector< Symmetry, Scalar > &V2)
TransferVector< Symmetry, Scalar > operator/(TransferVector< Symmetry, Scalar > V, const OtherScalar &alpha)
void contract_R(const Tripod< Symmetry, MatrixType2 > &Rold, const vector< Biped< Symmetry, MatrixType > > &Abra, const vector< vector< vector< Biped< Symmetry, MpoMatrixType > > > > &W, const vector< Biped< Symmetry, MatrixType > > &Aket, const vector< qarray< Symmetry::Nq > > &qloc, const vector< qarray< Symmetry::Nq > > &qOp, Tripod< Symmetry, MatrixType2 > &Rnew, bool RANDOMIZE=false, tuple< CONTRACT_LR_MODE, size_t > MODE_input=make_pair(FULL, 0), const std::unordered_map< pair< qarray< Symmetry::Nq >, size_t >, size_t > &basis_order_map={})
void contract_L(const Tripod< Symmetry, MatrixType2 > &Lold, const vector< Biped< Symmetry, MatrixType > > &Abra, const vector< vector< vector< Biped< Symmetry, MpoMatrixType > > > > &W, const vector< Biped< Symmetry, MatrixType > > &Aket, const vector< qarray< Symmetry::Nq > > &qloc, const vector< qarray< Symmetry::Nq > > &qOp, Tripod< Symmetry, MatrixType2 > &Lnew, bool RANDOMIZE=false, tuple< CONTRACT_LR_MODE, size_t > MODE_input=make_pair(FULL, 0), const std::unordered_map< pair< qarray< Symmetry::Nq >, size_t >, size_t > &basis_order_map={})
Definition: Biped.h:64
Biped< Symmetry, MatrixType_ > adjoint() const
Definition: Biped.h:630
std::vector< MatrixType_ > block
Definition: Biped.h:96
void addScale(const Scalar &factor, const Biped< Symmetry, MatrixType_ > &Mrhs, BLOCK_POSITION BP=SAME_PLACE)
Definition: Biped.h:1295
Biped< Symmetry, MatrixType_ > contract(const Biped< Symmetry, MatrixType_ > &A, const contract::MODE MODE=contract::MODE::UNITY) const
Definition: Biped.h:976
void clear()
Definition: Biped.h:325
Scalar trace() const
Definition: Biped.h:936
void setZero()
Definition: Biped.h:336
std::size_t dim
Definition: Biped.h:82
static void fill(size_t N, TransferVector< Symmetry, Scalar > &Vout)
vector< vector< Biped< Symmetry, Matrix< Scalar, Dynamic, Dynamic > > > > Abra
qarray< Symmetry::Nq > Qtot
vector< vector< Biped< Symmetry, Matrix< Scalar, Dynamic, Dynamic > > > > Aket
TransferMatrix(VMPS::DIRECTION::OPTION DIR_input)
VMPS::DIRECTION::OPTION DIR
vector< vector< qarray< Symmetry::Nq > > > qloc
TransferMatrix(VMPS::DIRECTION::OPTION DIR_input, const vector< vector< Biped< Symmetry, Matrix< Scalar, Dynamic, Dynamic > > > > &Abra_input, const vector< vector< Biped< Symmetry, Matrix< Scalar, Dynamic, Dynamic > > > > &Aket_input, const vector< vector< qarray< Symmetry::Nq > > > &qloc_input, bool SHIFTED_input=false, qarray< Symmetry::Nq > Qtot_input=Symmetry::qvacuum())
Biped< Symmetry, Matrix< Scalar, Dynamic, Dynamic > > LReigen
Biped< Symmetry, Matrix< Scalar, Dynamic, Dynamic > > TopEigvec
Biped< Symmetry, Matrix< Scalar_, Dynamic, Dynamic > > & operator()(size_t i)
TransferVector(const Biped< Symmetry, Matrix< Scalar_, Dynamic, Dynamic > > &data_input)
TransferVector< Symmetry, Scalar_ > & operator-=(const TransferVector< Symmetry, Scalar_ > &Vrhs)
TransferVector< Symmetry, Scalar_ > & operator*=(const OtherScalar &alpha)
Biped< Symmetry, Matrix< Scalar_, Dynamic, Dynamic > > data
Biped< Symmetry, Matrix< Scalar_, Dynamic, Dynamic > > & operator[](size_t i)
TransferVector< Symmetry, Scalar_ > & operator/=(const OtherScalar &alpha)
TransferVector< Symmetry, Scalar_ > & operator+=(const TransferVector< Symmetry, Scalar_ > &Vrhs)
Definition: qarray.h:26