1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662
|
/*
Copyright (c) 2009, UT-Battelle, LLC
All rights reserved
[DMRG++, Version 2.0.0]
[by G.A., Oak Ridge National Laboratory]
UT Battelle Open Source Software License 11242008
OPEN SOURCE LICENSE
Subject to the conditions of this License, each
contributor to this software hereby grants, free of
charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), a
perpetual, worldwide, non-exclusive, no-charge,
royalty-free, irrevocable copyright license to use, copy,
modify, merge, publish, distribute, and/or sublicense
copies of the Software.
1. Redistributions of Software must retain the above
copyright and license notices, this list of conditions,
and the following disclaimer. Changes or modifications
to, or derivative works of, the Software should be noted
with comments and the contributor and organization's
name.
2. Neither the names of UT-Battelle, LLC or the
Department of Energy nor the names of the Software
contributors may be used to endorse or promote products
derived from this software without specific prior written
permission of UT-Battelle.
3. The software and the end-user documentation included
with the redistribution, with or without modification,
must include the following acknowledgment:
"This product includes software produced by UT-Battelle,
LLC under Contract No. DE-AC05-00OR22725 with the
Department of Energy."
*********************************************************
DISCLAIMER
THE SOFTWARE IS SUPPLIED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER, CONTRIBUTORS, UNITED STATES GOVERNMENT,
OR THE UNITED STATES DEPARTMENT OF ENERGY BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
NEITHER THE UNITED STATES GOVERNMENT, NOR THE UNITED
STATES DEPARTMENT OF ENERGY, NOR THE COPYRIGHT OWNER, NOR
ANY OF THEIR EMPLOYEES, REPRESENTS THAT THE USE OF ANY
INFORMATION, DATA, APPARATUS, PRODUCT, OR PROCESS
DISCLOSED WOULD NOT INFRINGE PRIVATELY OWNED RIGHTS.
*********************************************************
*/
/** \ingroup DMRG */
/*@{*/
/*! \file ReflectionOperator
*
* Critical problems:
*
* - support for fermionic reflections
*
* Low priority work that needs to be done:
*
* - support for bases that change from site to site
*
*/
#ifndef REFLECTION_OPERATOR_H
#define REFLECTION_OPERATOR_H
#include "LAPACK.h"
#include "Matrix.h"
#include "PackIndices.h" // in PsimagLite
#include "ProgressIndicator.h"
#include "ReflectionTransform.h"
#include "Sort.h"
namespace Dmrg
{
template <typename LeftRightSuperType, typename ConcurrencyType>
class ReflectionOperator
{
typedef PsimagLite::PackIndices PackIndicesType;
typedef typename LeftRightSuperType::SparseMatrixType
SparseMatrixType;
typedef typename LeftRightSuperType::RealType RealType;
typedef typename SparseMatrixType::value_type ComplexOrRealType;
typedef typename PsimagLite::Vector<ComplexOrRealType>::Type VectorType;
typedef SparseVector<typename VectorType::value_type> SparseVectorType;
typedef ReflectionTransform<RealType, SparseMatrixType> ReflectionTransformType;
enum { AVAILABLE,
NOT_AVAILABLE,
COLOR };
public:
ReflectionOperator(LeftRightSuperType& lrs,
ConcurrencyType& concurrency,
SizeType n0,
bool isEnabled,
SizeType expandSys)
: lrs_(lrs)
, concurrency_(concurrency)
, n0_(n0)
, progress_("ReflectionOperator", 0)
, isEnabled_(isEnabled)
, expandSys_(expandSys)
, reflectedLeft_(n0_, n0_)
, reflectedRight_(n0_, n0_)
, reflectionTransform_(false)
{
SizeType counter = 0;
for (SizeType i = 0; i < reflectedLeft_.rank(); i++) {
reflectedLeft_.setRow(i, counter);
reflectedLeft_.pushCol(i);
reflectedLeft_.pushValue(1);
counter++;
}
reflectedLeft_.setRow(reflectedLeft_.rank(), counter);
reflectedRight_ = reflectedLeft_;
}
void update(const typename PsimagLite::Vector<SizeType>::Type& sectors)
{
if (!isEnabled_)
return;
// SparseMatrixType sSuper;
// setS(sSuper);
SparseMatrixType sSector;
setSsector(sSector, sectors);
updateReflected();
// extractCurrentSector(sSector,sSuper,sectors);
reflectionTransform_.update(sSector);
}
template <typename SomeStructType>
void updateKeptStates(SizeType& keptStates,
const SomeStructType& cacheLeft,
const SomeStructType& cacheRight)
{
const PsimagLite::Matrix<ComplexOrRealType>& transform1 = cacheLeft.transform;
const PsimagLite::Matrix<ComplexOrRealType>& transform2 = cacheRight.transform;
if (!isEnabled_)
return;
if (keptStates >= transform1.n_col())
return;
PsimagLite::OstringStream msg;
msg << "updateKeptStates";
progress_.printline(msg, std::cout);
check(cacheLeft.removedIndices, reflectedLeft_, transform1, transform2);
check(cacheRight.removedIndices, reflectedRight_, transform2, transform1);
}
void transform(SparseMatrixType& matrixA,
SparseMatrixType& matrixB,
const SparseMatrixType& matrix) const
{
assert(isEnabled_);
reflectionTransform_.transform(matrixA, matrixB, matrix);
}
template <typename SomeVectorType>
void setInitState(const SomeVectorType& initVector,
SomeVectorType& initVector1,
SomeVectorType& initVector2) const
{
assert(isEnabled_);
return reflectionTransform_.setInitState(initVector, initVector1, initVector2);
}
RealType setGroundState(VectorType& gs,
const RealType& gsEnergy1,
const VectorType& gsVector1,
const RealType& gsEnergy2,
const VectorType& gsVector2) const
{
assert(isEnabled_);
if (gsEnergy1 <= gsEnergy2) {
reflectionTransform_.setGs(gs, gsVector1, 1.0);
return gsEnergy1;
}
reflectionTransform_.setGs(gs, gsVector2, -1.0);
return gsEnergy2;
}
const LeftRightSuperType& leftRightSuper() const { return lrs_; }
bool isEnabled() const { return isEnabled_; }
void changeBasis(const PsimagLite::Matrix<ComplexOrRealType>& transform1,
const PsimagLite::Matrix<ComplexOrRealType>& transform2)
{
if (!isEnabled_)
return;
SparseMatrixType newreflected;
changeBasis(newreflected, reflectedLeft_, transform1, transform2);
// if (newreflected.rank()!=reflectedLeft_.rank()) {
// printFullMatrix(newreflected,"newreflectedLeft",0,1e-6);
// transform1.print(std::cerr,1e-6);
// transform2.print(std::cerr,1e-6);
// }
reflectedLeft_ = newreflected;
// normalize(reflectedLeft_);
changeBasis(newreflected, reflectedRight_, transform2, transform1);
reflectedRight_ = newreflected;
// normalize(reflectedRight_);
// diagBasis();
}
void diagBasis()
{
// SparseMatrixType sSector;
// setSsector(sSector);
// reflectionTransform_.update(sSector);
// const SparseMatrixType& Q1 = reflectionTransform_.getTransform(0);
// const SparseMatrixType& Qm = reflectionTransform_.getTransform(1);
// SparseMatrixType transf;
// transformPartialLeft(transf,Q1,Qm);
// PsimagLite::Matrix<ComplexOrRealType> fullm;
// crsMatrixToFullMatrix(fullm,transf);
// lrs_.leftNonConst().changeBasisDirect(fullm,concurrency_);
// transformPartialRight(transf,Q1,Qm);
// crsMatrixToFullMatrix(fullm,transf);
// lrs_.rightNonConst().changeBasisDirect(fullm,concurrency_);
}
private:
// void transformPartialLeft(SparseMatrixType& tr,const SparseMatrixType& Q1,const SparseMatrix& Qm) const
// {
// SizeType ns = lrs_.left().size();
// PackIndicesType pack2(ns/n0_);
// PackIndicesType pack3(n0_);
// PackIndicesType pack1(ns);
// assert(reflectedLeft_.rank()==ns/n0_);
// assert(reflectedRight_.rank()==ns/n0_);
// typename PsimagLite::Vector<int>::Type ptr(total,-1);
// typename PsimagLite::Vector<SizeType>::Type index(total,0);
// typename PsimagLite::Vector<ComplexOrRealType>::Type temp(total,0);
// SizeType counter = 0;
// for (SizeType i=0;i<total;i++) {
// SizeType x = 0, y = 0;
// pack1.unpack(x,y,lrs_.super().permutation(i));
// tr.setRow(x,counter);
// for (int k=Q1.getRowPtr(i);k<Q1.getRowPtr(i+1);k++) {
// SizeType col = Q1.getCol(k);
// pack1.unpack(xprime,yprime,lrs_.super().permutation(i));
// }
// void transformPartial(SparseMatrixType& s1,const PsimagLite::Matrix<ComplexOrRealType>& fullm)
// {
// SparseMatrixType m1(fullm);
// SparseMatrixType m1Conj;
// transposeConjugate(m1Conj,m1);
// SparseMatrixType tmp = s1*m1Conj;
// s1 = m1*tmp;
// s1.checkValidity();
// }
// void transformPartial(SparseMatrixType& s1,const typename PsimagLite::Vector<RealType>::Type& eigs)
// {
// SizeType n = s1.rank();
// s1.resize(n);
// SizeType counter = 0;
// for (SizeType i=0;i<n;i++) {
// s1.setRow(i,counter);
// s1.pushCol(i);
// s1.pushValue(eigs[i]);
// counter++;
// }
// s1.setRow(n,counter);
// s1.checkValidity();
// }
void check(const typename PsimagLite::Vector<SizeType>::Type& removedIndices,
const SparseMatrixType& reflected,
const PsimagLite::Matrix<ComplexOrRealType>& transform1,
const PsimagLite::Matrix<ComplexOrRealType>& transform2)
{
SparseMatrixType newreflected;
changeBasis(newreflected, reflected, transform1, transform2);
// RealType eps = 1e-6;
// printFullMatrix(newreflected,"newreflected",0,eps);
typename PsimagLite::Vector<SizeType>::Type x;
for (SizeType ii = 0; ii < removedIndices.size(); ii++) {
SizeType i = removedIndices[ii];
for (int k = newreflected.getRowPtr(i); k < newreflected.getRowPtr(i + 1); k++) {
ComplexOrRealType val = newreflected.getValue(k);
if (isAlmostZero(val, 1e-8))
continue;
SizeType col = newreflected.getCol(k);
x.push_back(col);
}
}
Sort<typename PsimagLite::Vector<SizeType>::Type> sort;
typename PsimagLite::Vector<SizeType>::Type iperm(x.size());
sort.sort(x, iperm);
typename PsimagLite::Vector<SizeType>::Type diffs;
getDifferences(diffs, x, removedIndices);
for (SizeType i = 0; i < diffs.size(); i++)
std::cerr << "diffs[" << i << "]=" << diffs[i] << "\n";
for (SizeType i = 0; i < x.size(); i++)
std::cerr << "x[" << i << "]=" << x[i] << "\n";
for (SizeType i = 0; i < removedIndices.size(); i++)
std::cerr << "removed[" << i << "]=" << removedIndices[i] << "\n";
}
void getDifferences(typename PsimagLite::Vector<SizeType>::Type& diffs,
const typename PsimagLite::Vector<SizeType>::Type& x1,
const typename PsimagLite::Vector<SizeType>::Type& x2) const
{
typename PsimagLite::Vector<SizeType>::const_iterator::Type it2 = x2.begin();
for (SizeType i = 0; i < x1.size(); i++) {
typename PsimagLite::Vector<SizeType>::const_iterator::Type it = find(it2, x2.end(), x1[i]);
if (it == x2.end()) {
diffs.push_back(x1[i]);
continue;
}
it2 = it + 1;
}
}
void normalize(SparseMatrixType& A) const
{
SizeType n = A.rank();
typename PsimagLite::Vector<ComplexOrRealType>::Type sum(n, 0.0);
for (SizeType i = 0; i < n; i++) {
for (int k = A.getRowPtr(i); k < A.getRowPtr(i + 1); k++) {
ComplexOrRealType val = A.getValue(k);
sum[i] += PsimagLite::conj(val) * val;
}
}
for (SizeType i = 0; i < n; i++) {
// assert(isAlmostZero(sum[i]-1.0,1e-6));
assert(!isAlmostZero(sum[i], 1e-6));
ComplexOrRealType x = 1.0 / sqrt(sum[i]);
for (int k = A.getRowPtr(i); k < A.getRowPtr(i + 1); k++)
A.setValues(k, A.getValue(k) * x);
}
}
void changeBasis(SparseMatrixType& newreflected,
const SparseMatrixType& reflected,
const PsimagLite::Matrix<ComplexOrRealType>& transform1,
const PsimagLite::Matrix<ComplexOrRealType>& transform2)
{
assert(reflected.rank() == transform1.n_row());
assert(reflected.rank() == transform2.n_row());
SizeType total = transform1.n_col();
newreflected.resize(total);
typename PsimagLite::Vector<int>::Type ptr(total, -1);
typename PsimagLite::Vector<SizeType>::Type index(total, 0);
typename PsimagLite::Vector<ComplexOrRealType>::Type temp(total, 0);
std::cerr << "transform1=" << transform1.n_row() << "x" << transform1.n_col() << "\n";
std::cerr << "transform2=" << transform2.n_row() << "x" << transform2.n_col() << "\n";
SizeType counter = 0;
for (SizeType x = 0; x < total; x++) {
newreflected.setRow(x, counter);
SizeType itemp = 0;
for (SizeType xprime = 0; xprime < transform1.n_row(); xprime++) {
ComplexOrRealType wl1 = transform1(xprime, x);
// ComplexOrRealType wl1 = transform(x,xprime);
for (int k = reflected.getRowPtr(xprime); k < reflected.getRowPtr(xprime + 1); k++) {
SizeType xsecond = reflected.getCol(k);
ComplexOrRealType r = reflected.getValue(k);
for (SizeType xthird = 0; xthird < transform2.n_col(); xthird++) {
// ComplexOrRealType val = wl1 * r * transform(xthird,xsecond);
ComplexOrRealType val = wl1 * r * transform2(xsecond, xthird);
// if (isAlmostZero(val)) continue;
if (ptr[xthird] < 0) {
ptr[xthird] = itemp;
temp[ptr[xthird]] = val;
index[ptr[xthird]] = xthird;
itemp++;
} else {
temp[ptr[xthird]] += val;
}
}
}
}
for (SizeType s = 0; s < itemp; s++) {
newreflected.pushCol(index[s]);
newreflected.pushValue(temp[s]);
ptr[index[s]] = -1;
}
counter += itemp;
}
newreflected.setRow(newreflected.rank(), counter);
newreflected.checkValidity();
}
void setSsector(SparseMatrixType& sSector, const typename PsimagLite::Vector<SizeType>::Type& sectors) const
{
assert(sectors.size() == 1);
SizeType m = sectors[0];
SizeType offset = lrs_.super().partition(m);
SizeType total = lrs_.super().partition(m + 1) - offset;
setSsector(sSector, total, offset);
}
void setSsector(SparseMatrixType& sSector, SizeType total = 0, SizeType offset = 0) const
{
if (total == 0)
total = lrs_.super().size();
sSector.resize(total);
SizeType counter = 0;
SizeType ns = lrs_.left().size();
PackIndicesType pack2(ns / n0_);
PackIndicesType pack3(n0_);
PackIndicesType pack1(ns);
assert(reflectedLeft_.rank() == ns / n0_);
assert(reflectedRight_.rank() == ns / n0_);
typename PsimagLite::Vector<int>::Type ptr(total, -1);
typename PsimagLite::Vector<SizeType>::Type index(total, 0);
typename PsimagLite::Vector<ComplexOrRealType>::Type temp(total, 0);
for (SizeType i = 0; i < total; i++) {
sSector.setRow(i, counter);
SizeType x = 0, y = 0;
pack1.unpack(x, y, lrs_.super().permutation(i + offset));
SizeType x0 = 0, x1 = 0;
pack2.unpack(x0, x1, lrs_.left().permutation(x));
SizeType y0 = 0, y1 = 0;
pack3.unpack(y0, y1, lrs_.right().permutation(y));
SizeType itemp = 0;
for (int k = reflectedLeft_.getRowPtr(x0); k < reflectedLeft_.getRowPtr(x0 + 1); k++) {
ComplexOrRealType val1 = reflectedLeft_.getValue(k);
for (int k2 = reflectedRight_.getRowPtr(y1); k2 < reflectedRight_.getRowPtr(y1 + 1); k2++) {
ComplexOrRealType val2 = val1 * reflectedRight_.getValue(k2);
if (isAlmostZero(val2))
continue;
SizeType x0prime = reflectedLeft_.getCol(k);
SizeType xprime = pack3.pack(x1, x0prime, lrs_.right().permutationInverse());
SizeType y1prime = reflectedRight_.getCol(k2);
SizeType yprime = pack2.pack(y1prime, y0, lrs_.left().permutationInverse());
SizeType iprime = pack1.pack(yprime, xprime, lrs_.super().permutationInverse());
assert(iprime >= offset && iprime < offset + total);
SizeType col = iprime - offset;
if (ptr[col] < 0) {
ptr[col] = itemp;
temp[ptr[col]] = val2;
index[ptr[col]] = col;
itemp++;
} else {
temp[ptr[col]] += val2;
}
}
}
ComplexOrRealType val = 0.0;
for (SizeType s = 0; s < itemp; s++) {
sSector.pushCol(index[s]);
sSector.pushValue(temp[s]);
val += PsimagLite::conj(temp[s]) * temp[s];
ptr[index[s]] = -1;
counter++;
}
if (isAlmostZero(val, 1e-8)) {
std::cerr << "i=" << i << " x0=" << x0 << " x1=" << x1 << " y0=" << y0 << " y1=" << y1 << "\n";
}
}
sSector.setRow(total, counter);
sSector.checkValidity();
// printSparseMatrix(sSector,"sSector",1e-3);
#ifndef NDEBUG
SparseMatrixType tmp;
multiply(tmp, sSector, sSector);
bool b = isTheIdentity(tmp, 1e-5);
if (b)
return;
hasZeroRows(sSector, true);
printFullMatrix(sSector, "sSector");
printFullMatrix(tmp, "sSector*sSector");
assert(false);
#endif
}
bool hasZeroRows(const SparseMatrixType& sSector, bool verbose) const
{
bool flag = false;
SizeType n = sSector.rank();
for (SizeType i = 0; i < n; i++) {
ComplexOrRealType sum = 0.0;
for (int k = sSector.getRowPtr(i); k < sSector.getRowPtr(i + 1); k++) {
ComplexOrRealType val = sSector.getValue(k);
sum += PsimagLite::conj(val) * val;
}
if (isAlmostZero(sum, 1e-4)) {
flag = true;
if (verbose)
std::cerr << "zero row=" << i << "\n";
}
}
return flag;
}
void printSparseMatrix(SparseMatrixType& s1, const PsimagLite::String& label, const RealType& eps) const
{
std::cout << label << "\n";
for (SizeType i = 0; i < s1.rank(); i++) {
for (int k = s1.getRowPtr(i); k < s1.getRowPtr(i + 1); k++) {
ComplexOrRealType val = s1.getValue(k);
if (isAlmostZero(val, eps))
continue;
std::cout << (i + 1) << " " << (1 + s1.getCol(k)) << " " << val << "\n";
}
}
}
void truncate(SparseMatrixType& reflectedFinal,
const SparseMatrixType& reflected,
SizeType keptstates)
{
// SizeType n = reflected.rank();
// if (keptstates >= n) {
reflectedFinal = reflected;
return;
// }
// reflectedFinal.resize(keptstates);
// SizeType counterl = 0;
// typename PsimagLite::Vector<ComplexOrRealType>::Type sum(keptstates,0.0);
// for (SizeType i=0;i<keptstates;i++) {
// reflectedFinal.setRow(i,counterl);
// for (int k = reflected.getRowPtr(i); k < reflected.getRowPtr(i+1);k++) {
// SizeType col = reflected.getCol(k);
// if (col>=keptstates) continue;
// ComplexOrRealType val = reflected.getValue(k);
// reflectedFinal.pushCol(col);
// reflectedFinal.pushValue(val);
// counterl++;
// sum[i] += PsimagLite::conj(val) * val;
// }
// }
// reflectedFinal.setRow(reflectedFinal.rank(),counterl);
// reflectedFinal.checkValidity();
// // normalize
// for (SizeType i=0;i<reflectedFinal.rank();i++) {
// assert(!isAlmostZero(sum[i],1e-8));
// ComplexOrRealType x = 1.0/sqrt(sum[i]);
// for (int k = reflectedFinal.getRowPtr(i); k < reflectedFinal.getRowPtr(i+1);k++)
// reflectedFinal.setValues(k,reflectedFinal.getValue(k)*x);
// }
// reflectedFinal.checkValidity();
}
void updateReflected()
{
SizeType ns = lrs_.left().size();
PackIndicesType pack2(ns / n0_);
PackIndicesType pack3(n0_);
SparseMatrixType reflectedLeft(ns, ns);
SizeType counter = 0;
for (SizeType x = 0; x < ns; x++) {
reflectedLeft.setRow(x, counter);
SizeType x0 = 0, x1 = 0;
pack2.unpack(x0, x1, lrs_.left().permutation(x));
for (int k = reflectedLeft_.getRowPtr(x0); k < reflectedLeft_.getRowPtr(x0 + 1); k++) {
SizeType x0r = reflectedLeft_.getCol(k);
SizeType col = pack3.pack(x1, x0r, lrs_.right().permutationInverse());
ComplexOrRealType val = reflectedLeft_.getValue(k);
// if (isAlmostZero(val)) continue;
reflectedLeft.pushCol(col);
reflectedLeft.pushValue(val);
counter++;
}
}
reflectedLeft.setRow(ns, counter);
reflectedLeft.checkValidity();
reflectedLeft_ = reflectedLeft;
SparseMatrixType reflectedRight(ns, ns);
counter = 0;
for (SizeType x = 0; x < ns; x++) {
SizeType x0 = 0, x1 = 0;
reflectedRight.setRow(x, counter);
pack3.unpack(x0, x1, lrs_.right().permutation(x));
for (int k = reflectedRight_.getRowPtr(x1); k < reflectedRight_.getRowPtr(x1 + 1); k++) {
SizeType x1r = reflectedRight_.getCol(k);
ComplexOrRealType val = reflectedRight_.getValue(k);
// if (isAlmostZero(val)) continue;
SizeType col = pack2.pack(x1r, x0, lrs_.left().permutationInverse());
reflectedRight.pushCol(col);
reflectedRight.pushValue(val);
counter++;
}
}
reflectedRight.setRow(ns, counter);
reflectedRight.checkValidity();
reflectedRight_ = reflectedRight;
}
LeftRightSuperType& lrs_;
ConcurrencyType& concurrency_;
SizeType n0_; // hilbert size of one site
PsimagLite::ProgressIndicator progress_;
bool isEnabled_;
SizeType expandSys_;
SparseMatrixType reflectedLeft_, reflectedRight_;
ReflectionTransformType reflectionTransform_;
}; // class ReflectionOperator
} // namespace Dmrg
/*@}*/
#endif // REFLECTION_OPERATOR_H
|