VMPS++
Loading...
Searching...
No Matches
DmrgPivotOverlap2.h
Go to the documentation of this file.
1#ifndef DMRGPIVOTOVERLAP2
2#define DMRGPIVOTOVERLAP2
3
4//#include "pivot/DmrgPivotOverlap1.h"
6
7template<typename Symmetry, typename Scalar>
9{
11 PivotOverlap2(const Biped<Symmetry,Matrix<Scalar,Dynamic,Dynamic> > &L_input,
12 const Biped<Symmetry,Matrix<Scalar,Dynamic,Dynamic> > &R_input,
13 const vector<qarray<Symmetry::Nq> > &qloc1_input,
14 const vector<qarray<Symmetry::Nq> > &qloc2_input)
15 :L(L_input), R(R_input), qloc1(qloc1_input), qloc2(qloc2_input)
16 {};
17
20
21 vector<qarray<Symmetry::Nq> > qloc1;
22 vector<qarray<Symmetry::Nq> > qloc2;
23};
24
25template<typename Symmetry, typename Scalar>
27{
28// auto tensor_basis = Symmetry::tensorProd(H.qloc1, H.qloc2);
29 Vout.outerResize(Vin);
30
31 Qbasis<Symmetry> loc1; loc1.pullData(H.qloc1);
32 Qbasis<Symmetry> loc2; loc2.pullData(H.qloc2);
33 Qbasis<Symmetry> tensor_basis = loc1.combine(loc2);
34
35 for (size_t s1=0; s1<H.qloc1.size(); ++s1)
36 for (size_t s2=0; s2<H.qloc2.size(); ++s2)
37 {
38 auto qmerges12 = Symmetry::reduceSilent(H.qloc1[s1], H.qloc2[s2]);
39
40 for (const auto &qmerge12:qmerges12)
41 {
42// auto qtensor12 = make_tuple(H.qloc1[s1], s1, H.qloc2[s2], s2, qmerge12);
43// auto s1s2 = distance(tensor_basis.begin(), find(tensor_basis.begin(), tensor_basis.end(), qtensor12));
44 size_t s1s2 = tensor_basis.outer_num(qmerge12) + tensor_basis.leftOffset(qmerge12,{H.qloc1[s1],H.qloc2[s2]},{loc1.inner_num(s1),loc2.inner_num(s2)});
45
46 for (size_t qL=0; qL<H.L.dim; ++qL)
47 {
48 vector<tuple<qarray2<Symmetry::Nq>,size_t,size_t> > ixs;
49 bool FOUND_MATCH = AAAA(H.L.in[qL], H.L.out[qL], s1s2, qmerge12, Vout.data, Vin.data, ixs);
50
51 if (FOUND_MATCH)
52 {
53 for (const auto &ix:ixs)
54 {
55 auto qR = H.R.dict.find(get<0>(ix));
56 size_t qAbra = get<1>(ix);
57 size_t qAket = get<2>(ix);
58
59 if (qR != H.R.dict.end())
60 {
61 Matrix<Scalar,Dynamic,Dynamic> Mtmp;
62
63 if (H.L.block[qL].size() != 0 and
64 H.R.block[qR->second].size() !=0 and
65 Vin.data[s1s2].block[qAket].size() != 0)
66 {
67 if (H.L.block[qL].cols() == Vin.data[s1s2].block[qAket].rows() and
68 Vin.data[s1s2].block[qAket].cols() == H.R.block[qR->second].rows())
69 {
71 H.L.block[qL],
72 Vin.data[s1s2].block[qAket],
73 H.R.block[qR->second],
74 Mtmp);
75 }
76 else
77 {
78 lout << termcolor::red << "Warning: Mismatching matrix dimensions in LRxV (PivotOverlap2)!" << termcolor::reset << endl;
79 print_size(H.L.block[qL],"H.L.block[qL]");
80 print_size(Vin.data[s1s2].block[qAket],"Vin.data[s1s2].block[qAket]");
81 print_size(H.R.block[qR->second],"H.R.block[qR->second]");
82 lout << "qnums: " << H.L.in[qL] << "-" << H.L.out[qL] << ", "
83 << Vin.data[s1s2].in[qAket] << "-" << Vin.data[s1s2].out[qAket] << ", "
84 << H.R.in[qR->second] << "-" << H.R.out[qR->second]
85 << endl;
86 lout << endl;
87//
88// lout << H.L.print() << endl;
89// lout << H.R.print() << endl;
90 }
91 }
92
93 if (Mtmp.size() != 0)
94 {
95 if (Vout.data[s1s2].block[qAbra].rows() == Mtmp.rows() and
96 Vout.data[s1s2].block[qAbra].cols() == Mtmp.cols())
97 {
98 Vout.data[s1s2].block[qAbra] += Mtmp;
99 }
100 else
101 {
102 Vout.data[s1s2].block[qAbra] = Mtmp;
103 }
104 }
105 }
106 }
107 }
108 }
109 }
110 }
111}
112
113template<typename Symmetry, typename Scalar>
115{
117 LRxV(H,Vinout,Vtmp);
118 Vinout = Vtmp;
119}
120
121#endif
void print_size(const MatrixType &M, string label)
Definition: DmrgExternal.h:184
void optimal_multiply(Scalar alpha, const MatrixTypeA &A, const MatrixTypeB &B, const MatrixTypeC &C, MatrixTypeR &result, bool DEBUG=false)
Definition: DmrgExternal.h:191
bool AAAA(qarray< Symmetry::Nq > Lin, qarray< Symmetry::Nq > Lout, size_t s1s2, const qarray< Symmetry::Nq > &qmerge12, const vector< Biped< Symmetry, MatrixType > > &AAbra, const vector< Biped< Symmetry, MatrixType > > &AAket, vector< tuple< qarray2< Symmetry::Nq >, size_t, size_t > > &result)
void LRxV(const PivotOverlap2< Symmetry, Scalar > &H, const PivotVector< Symmetry, Scalar > &Vin, PivotVector< Symmetry, Scalar > &Vout)
Definition: Qbasis.h:39
Eigen::Index inner_num(const Eigen::Index &outer_num) const
Definition: Qbasis.h:335
Qbasis< Symmetry > combine(const Qbasis< Symmetry > &other, bool FLIP=false) const
Definition: Qbasis.h:686
Eigen::Index leftOffset(const qType &qnew, const std::array< qType, 2 > &qold, const std::array< Eigen::Index, 2 > &plain_old) const
Definition: Qbasis.h:440
void pullData(const vector< Biped< Symmetry, MatrixType > > &A, const Eigen::Index &leg)
Definition: Qbasis.h:486
Eigen::Index outer_num(const qType &q) const
Definition: Qbasis.h:378
Definition: Biped.h:64
std::unordered_map< std::array< qType, 2 >, std::size_t > dict
Definition: Biped.h:104
std::vector< MatrixType_ > block
Definition: Biped.h:96
std::vector< qType > in
Definition: Biped.h:87
std::size_t dim
Definition: Biped.h:82
std::vector< qType > out
Definition: Biped.h:90
vector< qarray< Symmetry::Nq > > qloc2
Biped< Symmetry, Matrix< Scalar, Dynamic, Dynamic > > R
PivotOverlap2(const Biped< Symmetry, Matrix< Scalar, Dynamic, Dynamic > > &L_input, const Biped< Symmetry, Matrix< Scalar, Dynamic, Dynamic > > &R_input, const vector< qarray< Symmetry::Nq > > &qloc1_input, const vector< qarray< Symmetry::Nq > > &qloc2_input)
vector< qarray< Symmetry::Nq > > qloc1
Biped< Symmetry, Matrix< Scalar, Dynamic, Dynamic > > L
void outerResize(const PivotVector &Vrhs)
vector< Biped< Symmetry, Matrix< Scalar_, Dynamic, Dynamic > > > data
Definition: qarray.h:26