1#ifndef STRAWBERRY_DMRG_HEFF_STUFF_2SITE_WITH_Q
2#define STRAWBERRY_DMRG_HEFF_STUFF_2SITE_WITH_Q
15template<
typename Symmetry,
typename Scalar,
typename MpoScalar=
double>
20 vector<vector<vector<Biped<Symmetry,Eigen::SparseMatrix<MpoScalar,Eigen::ColMajor,EIGEN_DEFAULT_SPARSE_INDEX_TYPE>> > > >
W12;
21 vector<vector<vector<Biped<Symmetry,Eigen::SparseMatrix<MpoScalar,Eigen::ColMajor,EIGEN_DEFAULT_SPARSE_INDEX_TYPE>> > > >
W34;
23 vector<qarray<Symmetry::Nq> >
qloc12;
24 vector<qarray<Symmetry::Nq> >
qloc34;
25 vector<qarray<Symmetry::Nq> >
qOp12;
26 vector<qarray<Symmetry::Nq> >
qOp34;
29template<
typename Symmetry,
typename Scalar,
typename MpoScalar=
double>
35 const Tripod<Symmetry,Matrix<Scalar,Dynamic,Dynamic> > &R_input,
36 const vector<vector<vector<
Biped<Symmetry,Eigen::SparseMatrix<MpoScalar,Eigen::ColMajor,EIGEN_DEFAULT_SPARSE_INDEX_TYPE>> > > >& W12_input,
37 const vector<vector<vector<
Biped<Symmetry,Eigen::SparseMatrix<MpoScalar,Eigen::ColMajor,EIGEN_DEFAULT_SPARSE_INDEX_TYPE>> > > >& W34_input,
46 Terms[0].W12 = W12_input;
47 Terms[0].W34 = W34_input;
48 Terms[0].qloc12 = qloc12_input;
49 Terms[0].qloc34 = qloc34_input;
50 Terms[0].qOp12 = qOp12_input;
51 Terms[0].qOp34 = qOp34_input;
64 vector<PivotMatrix2Terms<Symmetry,Scalar,MpoScalar> >
Terms;
67 vector<std::array<size_t,2> >
qlhs;
68 vector<vector<std::array<size_t,12> > >
qrhs;
73 vector<vector<Biped<Symmetry,Matrix<Scalar,Dynamic,Dynamic> > > >
A0proj;
78template<
typename Symmetry,
typename Scalar,
typename MpoScalar>
85template<
typename Symmetry,
typename Scalar,
typename MpoScalar>
88 for (
size_t i=0; i<Vout.
data.size(); ++i) {Vout.
data[i].setZero();}
89 vector<PivotVector<Symmetry,Scalar> > Vt(H.
Terms.size());
90 for (
size_t t=0; t<H.
Terms.size(); ++t) Vt[t] = Vout;
158 #ifdef DMRG_PARALLELIZE_TERMS
159 #pragma omp parallel for schedule(dynamic)
161 for (
size_t t=0; t<H.
Terms.size(); ++t)
163 vector<std::array<size_t,2> > qlhs;
164 vector<vector<std::array<size_t,12> > > qrhs;
165 vector<vector<Scalar> > factor_cgcs;
167 if (H.
Terms.size() == 1)
175 precalc_blockStructure<Symmetry,Scalar,Eigen::SparseMatrix<MpoScalar,Eigen::ColMajor,EIGEN_DEFAULT_SPARSE_INDEX_TYPE> >
176 (H.
Terms[t].L, Vin.
data, H.
Terms[t].W12, H.
Terms[t].W34, Vin.
data, H.
Terms[t].R, H.
Terms[t].qloc12, H.
Terms[t].qloc34, H.
Terms[t].qOp12, H.
Terms[t].qOp34, qlhs, qrhs, factor_cgcs);
179 #ifdef DMRG_PIVOT2_PARALLELIZE
180 #pragma omp parallel for schedule(dynamic)
182 for (
size_t q=0; q<qlhs.size(); ++q)
184 size_t s1s3 = qlhs[q][0];
185 size_t q13 = qlhs[q][1];
187 for (
size_t p=0; p<qrhs[q].size(); ++p)
189 size_t s2s4 = qrhs[q][p][0];
190 size_t q24 = qrhs[q][p][1];
191 size_t qL = qrhs[q][p][2];
192 size_t qR = qrhs[q][p][3];
193 size_t s1 = qrhs[q][p][4];
194 size_t s2 = qrhs[q][p][5];
195 size_t k12 = qrhs[q][p][6];
196 size_t qW12 = qrhs[q][p][7];
197 size_t s3 = qrhs[q][p][8];
198 size_t s4 = qrhs[q][p][9];
199 size_t k34 = qrhs[q][p][10];
200 size_t qW34 = qrhs[q][p][11];
202 for (
int r12=0; r12<H.
Terms[t].W12[s1][s2][k12].block[qW12].outerSize(); ++r12)
203 for (
typename SparseMatrix<MpoScalar>::InnerIterator iW12(H.
Terms[t].W12[s1][s2][k12].block[qW12],r12); iW12; ++iW12)
204 for (
int r34=0; r34<H.
Terms[t].W34[s3][s4][k34].block[qW34].outerSize(); ++r34)
205 for (
typename SparseMatrix<MpoScalar>::InnerIterator iW34(H.
Terms[t].W34[s3][s4][k34].block[qW34],r34); iW34; ++iW34)
207 if (H.
Terms[t].L.block[qL][iW12.row()][0].size() != 0 and
208 H.
Terms[t].R.block[qR][iW34.col()][0].size() != 0 and
209 Vin.
data[s2s4].block[q24].size() != 0 and
210 iW12.col() == iW34.row())
212 if (Vt[t].data[s1s3].block[q13].rows() != H.
Terms[t].L.block[qL][iW12.row()][0].rows() or
213 Vt[t].data[s1s3].block[q13].cols() != H.
Terms[t].R.block[qR][iW34.col()][0].cols())
215 Vt[t].data[s1s3].block[q13].noalias() = factor_cgcs[q][p] * iW12.value() * iW34.value() *
216 (H.
Terms[t].L.block[qL][iW12.row()][0] *
217 Vin.
data[s2s4].block[q24] *
218 H.
Terms[t].R.block[qR][iW34.col()][0]);
222 Vt[t].data[s1s3].block[q13].noalias() += factor_cgcs[q][p] * iW12.value() * iW34.value() *
223 (H.
Terms[t].L.block[qL][iW12.row()][0] *
224 Vin.
data[s2s4].block[q24] *
225 H.
Terms[t].R.block[qR][iW34.col()][0]);
233 for (
size_t s=0; s<Vout.
size(); ++s)
238 #ifdef DMRG_PARALLELIZE_TERMS
239 #pragma omp parallel for
241 for (
size_t s=0; s<Vout.
size(); ++s)
242 for (
size_t t=1; t<H.
Terms.size(); ++t)
244 Vout[s].addScale(1.,Vt[t][s]);
247 if (H.
Terms.size() > 0)
for (
size_t s=0; s<Vout.
size(); ++s) Vout[s] = Vout[s].cleaned();
250 for (
size_t n=0; n<H.
A0proj.size(); ++n)
253 for (
size_t s=0; s<H.
A0proj[n].size(); ++s)
256 overlap += H.
A0proj[n][s].adjoint().contract(Vin.
data[s]).trace();
260 for (
size_t s=0; s<H.
A0proj[n].size(); ++s)
261 for (
size_t q=0; q<H.
A0proj[n][s].dim; ++q)
264 auto qA = Vout.
data[s].dict.find(cmp);
267 if (qA != Vout.
data[s].dict.end() and H.
A0proj[n][s].block[q].size() != 0)
419template<
typename Symmetry,
typename Scalar,
typename MpoScalar>
427template<
typename Symmetry,
typename Scalar,
typename MpoScalar>
434template<
typename Symmetry,
typename Scalar,
typename MpoScalar>
size_t dim(const PivotMatrix2< Symmetry, Scalar, MpoScalar > &H)
double norm(const PivotMatrix2< Symmetry, Scalar, MpoScalar > &H)
void OxV(const PivotMatrix2< Symmetry, Scalar, MpoScalar > &H, const PivotVector< Symmetry, Scalar > &Vin, PivotVector< Symmetry, Scalar > &Vout)
void HxV(const PivotMatrix2< Symmetry, Scalar, MpoScalar > &H, const PivotVector< Symmetry, Scalar > &Vin, PivotVector< Symmetry, Scalar > &Vout)
std::array< qarray< Nq >, 2 > qarray2
vector< vector< vector< Biped< Symmetry, Eigen::SparseMatrix< MpoScalar, Eigen::ColMajor, EIGEN_DEFAULT_SPARSE_INDEX_TYPE > > > > > W12
Tripod< Symmetry, Matrix< Scalar, Dynamic, Dynamic > > R
Tripod< Symmetry, Matrix< Scalar, Dynamic, Dynamic > > L
vector< vector< vector< Biped< Symmetry, Eigen::SparseMatrix< MpoScalar, Eigen::ColMajor, EIGEN_DEFAULT_SPARSE_INDEX_TYPE > > > > > W34
vector< qarray< Symmetry::Nq > > qloc12
vector< qarray< Symmetry::Nq > > qOp34
vector< qarray< Symmetry::Nq > > qloc34
vector< qarray< Symmetry::Nq > > qOp12
vector< vector< Biped< Symmetry, Matrix< Scalar, Dynamic, Dynamic > > > > A0proj
vector< vector< std::array< size_t, 12 > > > qrhs
vector< std::array< size_t, 2 > > qlhs
vector< vector< Scalar > > factor_cgcs
PivotMatrix2(const Tripod< Symmetry, Matrix< Scalar, Dynamic, Dynamic > > &L_input, const Tripod< Symmetry, Matrix< Scalar, Dynamic, Dynamic > > &R_input, const vector< vector< vector< Biped< Symmetry, Eigen::SparseMatrix< MpoScalar, Eigen::ColMajor, EIGEN_DEFAULT_SPARSE_INDEX_TYPE > > > > > &W12_input, const vector< vector< vector< Biped< Symmetry, Eigen::SparseMatrix< MpoScalar, Eigen::ColMajor, EIGEN_DEFAULT_SPARSE_INDEX_TYPE > > > > > &W34_input, const vector< qarray< Symmetry::Nq > > &qloc12_input, const vector< qarray< Symmetry::Nq > > &qloc34_input, const vector< qarray< Symmetry::Nq > > &qOp12_input, const vector< qarray< Symmetry::Nq > > &qOp34_input)
vector< PivotMatrix2Terms< Symmetry, Scalar, MpoScalar > > Terms
vector< Biped< Symmetry, Matrix< Scalar_, Dynamic, Dynamic > > > data