5#include "termcolor.hpp"
8template<
typename Symmetry,
typename Scalar_>
13 static constexpr std::size_t
Nq = Symmetry::Nq;
35 const vector<
Biped<Symmetry,Matrix<Scalar_,Dynamic,Dynamic> > > &A34,
46 auto loc = loc12.
combine(loc34);
55 for (
size_t i=0; i<
data.size(); ++i)
60 data[i].block.resize(Vrhs.
data[i].block.size());
67 for (
size_t i=0; i<
data.size(); ++i)
68 for (
size_t q=0; q<
data[i].dim; ++q)
70 data[i].block[q].setZero();
74 inline size_t size()
const {
return data.size();}
78 map<qarray<Symmetry::Nq>,set<int> > indim;
79 map<qarray<Symmetry::Nq>,set<int> > outdim;
80 for (
size_t s1s3=0; s1s3<
data.size(); ++s1s3)
81 for (
size_t q=0; q<
data[s1s3].dim; ++q)
83 indim[
data[s1s3].in[q]].insert(
data[s1s3].block[q].rows());
84 outdim[
data[s1s3].out[q]].insert(
data[s1s3].block[q].cols());
86 for (
auto it=indim.begin(); it!=indim.end(); ++it)
88 cout <<
"in=" << it->first <<
":";
89 for (
auto ip=it->second.begin(); ip!=it->second.end(); ++ip)
95 for (
auto it=outdim.begin(); it!=outdim.end(); ++it)
97 cout <<
"out=" << it->first <<
":";
98 for (
auto ip=it->second.begin(); ip!=it->second.end(); ++ip)
116 vector<Biped<Symmetry,Matrix<Scalar_,Dynamic,Dynamic> > >
data;
121template<
typename Symmetry,
typename Scalar_>
138 #ifdef DMRG_PIVOTVECTOR_PARALLELIZE
139 #pragma omp parallel for schedule(dynamic)
141 for (
size_t s=0; s<data.size(); s++)
142 for (
size_t q=0; q<data[s].dim; ++q)
154 if (data[s].block[q].size() == 0)
156 data[s].block[q] = Vrhs.
data[s].block[q];
158 else if (data[s].block[q].size() != 0 and Vrhs.
data[s].block[q].size() != 0)
164 data[s].block[q] += Vrhs.
data[s].block[q];
171template<
typename Symmetry,
typename Scalar_>
189 #ifdef DMRG_PIVOTVECTOR_PARALLELIZE
190 #pragma omp parallel for schedule(dynamic)
192 for (
size_t s=0; s<data.size(); s++)
193 for (
size_t q=0; q<data[s].dim; ++q)
210 if (data[s].block[q].size() == 0)
212 data[s].block[q] = -Vrhs.
data[s].block[q];
214 else if (data[s].block[q].size() != 0 and Vrhs.
data[s].block[q].size() != 0)
216 data[s].block[q] -= Vrhs.
data[s].block[q];
223template<
typename Symmetry,
typename Scalar_>
224template<
typename OtherScalar>
228 #ifdef DMRG_PIVOTVECTOR_PARALLELIZE
229 #pragma omp parallel for schedule(dynamic)
231 for (
size_t s=0; s<data.size(); ++s)
232 for (
size_t q=0; q<data[s].dim; ++q)
234 data[s].block[q] *= alpha;
239template<
typename Symmetry,
typename Scalar_>
240template<
typename OtherScalar>
244 #ifdef DMRG_PIVOTVECTOR_PARALLELIZE
245 #pragma omp parallel for schedule(dynamic)
247 for (
size_t s=0; s<data.size(); ++s)
248 for (
size_t q=0; q<data[s].dim; ++q)
250 data[s].block[q] /= alpha;
255template<
typename Symmetry,
typename Scalar_,
typename OtherScalar>
261template<
typename Symmetry,
typename Scalar_,
typename OtherScalar>
267template<
typename Symmetry,
typename Scalar_,
typename OtherScalar>
273template<
typename Symmetry,
typename Scalar_>
281template<
typename Symmetry,
typename Scalar_>
289template<
typename Symmetry,
typename Scalar_,
typename OtherScalar>
296template<
typename Symmetry,
typename Scalar_>
301 #ifdef DMRG_PIVOTVECTOR_PARALLELIZE
302 #pragma omp parallel for schedule(dynamic) reduction(+:res)
304 for (
size_t s=0; s<V2.
data.size(); ++s)
305 for (
size_t q=0; q<V2.
data[s].dim; ++q)
307 if (V1.
data[s].in[q] != V2.
data[s].in[q] or V1.
data[s].out[q] != V2.
data[s].out[q])
309 cout <<
"s=" << s <<
", q=" << q << endl;
310 cout <<
"V1 inout=" << V1.
data[s].in[q] <<
", " << V1.
data[s].out[q] << endl;
311 cout <<
"V2 inout=" << V2.
data[s].in[q] <<
", " << V2.
data[s].out[q] << endl;
315 cout << termcolor::red <<
"Mismatched blocks in dot(PivotVector)" << termcolor::reset << endl;
316 cout << V1.
data[s].print() << endl;
317 cout << V2.
data[s].print() << endl;
320 if (V1.
data[s].block[q].size() > 0 and
321 V2.
data[s].block[q].size() > 0)
323 res += (V1.
data[s].block[q].adjoint() * V2.
data[s].block[q]).trace() * Symmetry::coeff_dot(V1.
data[s].out[q]);
341template<
typename Symmetry,
typename Scalar_>
348template<
typename Symmetry,
typename Scalar_>
354template<
typename Symmetry,
typename Scalar_>
360template<
typename Symmetry,
typename Scalar_>
364 for (
size_t s=0; s<V.
data.size(); ++s)
365 for (
size_t q=0; q<V.
data[s].dim; ++q)
367 out += V.
data[s].block[q].size();
372template<
typename Symmetry,
typename Scalar_>
376 for (
size_t s=0; s<V1.
data.size(); ++s)
378 auto Mtmp = V1.
data[s] - V2.
data[s];
379 for (
size_t q=0; q<Mtmp.dim; ++q)
381 double tmp = Mtmp.block[q].template lpNorm<Eigen::Infinity>();
382 if (tmp>res) {res = tmp;}
388template<
typename Symmetry,
typename Scalar_>
398template<
typename Symmetry,
typename Scalar_>
401 for (
size_t s=0; s<V.
data.size(); ++s)
402 for (
size_t q=0; q<V.
data[s].dim; ++q)
404 V.
data[s].block[q].setZero();
408#include "RandomVector.h"
410template<
typename Symmetry,
typename Scalar_>
415 for (
size_t s=0; s<Vout.
data.size(); ++s)
416 for (
size_t q=0; q<Vout.
data[s].dim; ++q)
417 for (
size_t a1=0; a1<Vout.
data[s].block[q].rows(); ++a1)
418 for (
size_t a2=0; a2<Vout.
data[s].block[q].cols(); ++a2)
420 Vout.
data[s].block[q](a1,a2) = threadSafeRandUniform<Scalar_>(-1.,1.);
void contract_AA2(const vector< Biped< Symmetry, Matrix< Scalar, Dynamic, Dynamic > > > &A1, const vector< qarray< Symmetry::Nq > > &qloc1, const vector< Biped< Symmetry, Matrix< Scalar, Dynamic, Dynamic > > > &A2, const vector< qarray< Symmetry::Nq > > &qloc2, vector< Biped< Symmetry, Matrix< Scalar, Dynamic, Dynamic > > > &Apair, bool DRY=false)
vector< Biped< Symmetry, Matrix< Scalar, Dynamic, Dynamic > > > extend_A(const vector< Biped< Symmetry, Matrix< Scalar, Dynamic, Dynamic > > > &A, const vector< qarray< Symmetry::Nq > > &qloc)
void print_size(const MatrixType &M, string label)
size_t dim(const PivotVector< Symmetry, Scalar_ > &V)
PivotVector< Symmetry, Scalar_ > operator-(const PivotVector< Symmetry, Scalar_ > &V1, const PivotVector< Symmetry, Scalar_ > &V2)
double infNorm(const PivotVector< Symmetry, Scalar_ > &V1, const PivotVector< Symmetry, Scalar_ > &V2)
double squaredNorm(const PivotVector< Symmetry, Scalar_ > &V)
double norm(const PivotVector< Symmetry, Scalar_ > &V)
void swap(PivotVector< Symmetry, Scalar_ > &V1, PivotVector< Symmetry, Scalar_ > &V2)
PivotVector< Symmetry, Scalar_ > operator+(const PivotVector< Symmetry, Scalar_ > &V1, const PivotVector< Symmetry, Scalar_ > &V2)
void normalize(PivotVector< Symmetry, Scalar_ > &V)
void addScale(const OtherScalar alpha, const PivotVector< Symmetry, Scalar_ > &Vin, PivotVector< Symmetry, Scalar_ > &Vout)
PivotVector< Symmetry, Scalar_ > operator*(const OtherScalar &alpha, PivotVector< Symmetry, Scalar_ > V)
PivotVector< Symmetry, Scalar_ > operator/(PivotVector< Symmetry, Scalar_ > V, const OtherScalar &alpha)
void setZero(PivotVector< Symmetry, Scalar_ > &V)
Scalar_ dot(const PivotVector< Symmetry, Scalar_ > &V1, const PivotVector< Symmetry, Scalar_ > &V2)
Qbasis< Symmetry > combine(const Qbasis< Symmetry > &other, bool FLIP=false) const
void pullData(const vector< Biped< Symmetry, MatrixType > > &A, const Eigen::Index &leg)
static void fill(size_t N, PivotVector< Symmetry, Scalar_ > &Vout)
PivotVector< Symmetry, Scalar_ > & operator+=(const PivotVector< Symmetry, Scalar_ > &Vrhs)
PivotVector< Symmetry, Scalar_ > & operator-=(const PivotVector< Symmetry, Scalar_ > &Vrhs)
PivotVector(const vector< Biped< Symmetry, Matrix< Scalar_, Dynamic, Dynamic > > > &A12)
static constexpr std::size_t Nq
Biped< Symmetry, Matrix< Scalar_, Dynamic, Dynamic > > & operator[](size_t i)
PivotVector< Symmetry, Scalar_ > & operator*=(const OtherScalar &alpha)
Biped< Symmetry, Matrix< Scalar_, Dynamic, Dynamic > > & operator()(size_t i)
PivotVector(const Biped< Symmetry, Matrix< Scalar_, Dynamic, Dynamic > > &C)
void outerResize(const PivotVector &Vrhs)
PivotVector< Symmetry, Scalar_ > & operator/=(const OtherScalar &alpha)
vector< Biped< Symmetry, Matrix< Scalar_, Dynamic, Dynamic > > > data
PivotVector(const vector< Biped< Symmetry, Matrix< Scalar_, Dynamic, Dynamic > > > &A12, const vector< qarray< Symmetry::Nq > > &qloc12, const vector< Biped< Symmetry, Matrix< Scalar_, Dynamic, Dynamic > > > &A34, const vector< qarray< Symmetry::Nq > > &qloc34, const qarray< Symmetry::Nq > &Qtop, const qarray< Symmetry::Nq > &Qbot, bool DRY=false)