1#ifndef DMRGPIVOTMATRIX1
2#define DMRGPIVOTMATRIX1
11template<
typename Symmetry,
typename Scalar,
typename MpoScalar=
double>
16 vector<vector<vector<Biped<Symmetry,Eigen::SparseMatrix<MpoScalar,Eigen::ColMajor,EIGEN_DEFAULT_SPARSE_INDEX_TYPE> > > > >
W;
18 vector<qarray<Symmetry::Nq> >
qloc;
19 vector<qarray<Symmetry::Nq> >
qOp;
46template<
typename Symmetry,
typename Scalar,
typename MpoScalar=
double>
56 vector<PivotMatrix1Terms<Symmetry,Scalar,MpoScalar> >
Terms;
59 vector<std::array<size_t,2> >
qlhs;
60 vector<vector<std::array<size_t,6> > >
qrhs;
65 vector<Biped<Symmetry,Matrix<Scalar,Dynamic,Dynamic> > >
PL;
66 vector<Biped<Symmetry,Matrix<Scalar,Dynamic,Dynamic> > >
PR;
67 vector<vector<Biped<Symmetry,Matrix<Scalar,Dynamic,Dynamic> > > >
A0proj;
71 template<
typename OtherScalar>
78 for (
size_t t=0; t<
Terms.size(); ++t)
80 Pout.
Terms[t].L =
Terms[t].L.template cast<Matrix<OtherScalar,Dynamic,Dynamic> >();
81 Pout.
Terms[t].R =
Terms[t].R.template cast<Matrix<OtherScalar,Dynamic,Dynamic> >();
108 for (
size_t t=0; t<
Terms.size(); ++t)
110 res +=
Terms[t].L.memory(memunit);
111 res +=
Terms[t].R.memory(memunit);
112 for (
size_t s1=0; s1<
Terms[t].W.size(); ++s1)
113 for (
size_t s2=0; s2<
Terms[t].W[s1].size(); ++s2)
114 for (
size_t k=0; k<
Terms[t].W[s1][s2].size(); ++k)
116 res +=
Terms[t].W[s1][s2][k].memory(memunit);
123template<
typename Symmetry,
typename Scalar,
typename MpoScalar>
131template<
typename Symmetry,
typename Scalar,
typename MpoScalar>
134 for (
size_t s=0; s<Vout.
data.size(); ++s) {Vout.
data[s].setZero();}
135 vector<PivotVector<Symmetry,Scalar> > Vt(H.
Terms.size());
136 for (
size_t t=0; t<H.
Terms.size(); ++t) Vt[t] = Vout;
138 vector<std::array<size_t,2> > qlhs;
139 vector<vector<std::array<size_t,6> > > qrhs;
140 vector<vector<Scalar> > factor_cgcs;
197 #ifdef DMRG_PARALLELIZE_TERMS
198 #pragma omp parallel for schedule(dynamic)
200 for (
size_t t=0; t<H.
Terms.size(); ++t)
202 vector<std::array<size_t,2> > qlhs;
203 vector<vector<std::array<size_t,6> > > qrhs;
204 vector<vector<Scalar> > factor_cgcs;
206 if (H.
Terms.size() == 1)
214 precalc_blockStructure<Symmetry,Scalar,Eigen::SparseMatrix<MpoScalar,Eigen::ColMajor,EIGEN_DEFAULT_SPARSE_INDEX_TYPE> >
219 #ifdef DMRG_PIVOT1_PARALLELIZE
220 #pragma omp parallel for schedule(dynamic)
222 for (
size_t q=0; q<qlhs.size(); ++q)
224 size_t s1 = qlhs[q][0];
225 size_t q1 = qlhs[q][1];
227 for (
size_t p=0; p<qrhs[q].size(); ++p)
229 size_t s2 = qrhs[q][p][0];
230 size_t q2 = qrhs[q][p][1];
231 size_t qL = qrhs[q][p][2];
232 size_t qR = qrhs[q][p][3];
233 size_t k = qrhs[q][p][4];
234 size_t qW = qrhs[q][p][5];
236 for (
int r=0; r<H.
Terms[t].W[s1][s2][k].block[qW].outerSize(); ++r)
237 for (
typename Eigen::SparseMatrix<MpoScalar,Eigen::ColMajor,EIGEN_DEFAULT_SPARSE_INDEX_TYPE>::InnerIterator iW(H.
Terms[t].W[s1][s2][k].block[qW],r); iW; ++iW)
244 if (H.
Terms[t].L.block[qL][iW.row()][0].size() != 0 and
245 H.
Terms[t].R.block[qR][iW.col()][0].size() != 0 and
246 Vin.
data[s2].block[q2].size() !=0)
248 if (Vt[t].data[s1].block[q1].rows() != H.
Terms[t].L.block[qL][iW.row()][0].rows() or
249 Vt[t].data[s1].block[q1].cols() != H.
Terms[t].R.block[qR][iW.col()][0].cols())
251 Vt[t].data[s1].block[q1].noalias() = factor_cgcs[q][p] * iW.value() *
252 (H.
Terms[t].L.block[qL][iW.row()][0] *
253 Vin.
data[s2].block[q2] *
254 H.
Terms[t].R.block[qR][iW.col()][0]);
258 Vt[t].data[s1].block[q1].noalias() += factor_cgcs[q][p] * iW.value() *
259 (H.
Terms[t].L.block[qL][iW.row()][0] *
260 Vin.
data[s2].block[q2] *
261 H.
Terms[t].R.block[qR][iW.col()][0]);
273 for (
size_t s=0; s<Vout.
size(); ++s)
278 #ifdef DMRG_PARALLELIZE_TERMS
279 #pragma omp parallel for
281 for (
size_t s=0; s<Vout.
size(); ++s)
282 for (
size_t t=1; t<H.
Terms.size(); ++t)
284 Vout[s].addScale(1.,Vt[t][s]);
287 if (H.
Terms.size() > 0)
for (
size_t s=0; s<Vout.
size(); ++s) Vout[s] = Vout[s].cleaned();
304 for (
size_t n=0; n<H.
A0proj.size(); ++n)
307 for (
size_t s=0; s<H.
A0proj[n].size(); ++s)
310 overlap += H.
A0proj[n][s].adjoint().contract(Vin.
data[s]).trace();
315 for (
size_t s=0; s<H.
A0proj[n].size(); ++s)
316 for (
size_t q=0; q<H.
A0proj[n][s].dim; ++q)
319 auto qA = Vout.
data[s].dict.find(cmp);
321 if (qA != Vout.
data[s].dict.end() and H.
A0proj[n][s].block[q].size() != 0)
418template<
typename Symmetry,
typename Scalar,
typename MpoScalar>
426template<
typename Symmetry,
typename Scalar,
typename MpoScalar>
433template<
typename Symmetry,
typename Scalar,
typename MpoScalar>
size_t dim(const PivotMatrix1< Symmetry, Scalar, MpoScalar > &H)
double norm(const PivotMatrix1< Symmetry, Scalar, MpoScalar > &H)
void HxV(const PivotMatrix1< Symmetry, Scalar, MpoScalar > &H, const PivotVector< Symmetry, Scalar > &Vin, PivotVector< Symmetry, Scalar > &Vout)
void OxV(const PivotMatrix1< 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 > > > > > W
vector< qarray< Symmetry::Nq > > qloc
Tripod< Symmetry, Matrix< Scalar, Dynamic, Dynamic > > L
vector< qarray< Symmetry::Nq > > qOp
Tripod< Symmetry, Matrix< Scalar, Dynamic, Dynamic > > R
vector< vector< std::array< size_t, 6 > > > qrhs
vector< std::array< size_t, 2 > > qlhs
vector< Biped< Symmetry, Matrix< Scalar, Dynamic, Dynamic > > > PL
double memory(MEMUNIT memunit) const
vector< Biped< Symmetry, Matrix< Scalar, Dynamic, Dynamic > > > PR
vector< vector< Biped< Symmetry, Matrix< Scalar, Dynamic, Dynamic > > > > A0proj
PivotMatrix1< Symmetry, OtherScalar, OtherScalar > cast() const
vector< PivotMatrix1Terms< Symmetry, Scalar, MpoScalar > > Terms
vector< vector< Scalar > > factor_cgcs
vector< Biped< Symmetry, Matrix< Scalar_, Dynamic, Dynamic > > > data