52 #ifndef ANASAZI_LOBPCG_HPP 53 #define ANASAZI_LOBPCG_HPP 100 template <
class ScalarType,
class MultiVector>
208 template <
class ScalarType,
class MV,
class OP>
317 bool isInitialized()
const;
337 int getNumIters()
const;
340 void resetNumIters();
356 std::vector<Value<ScalarType> > getRitzValues();
365 std::vector<int> getRitzIndex();
373 std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> getResNorms();
381 std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> getRes2Norms();
391 std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> getRitzRes2Norms();
402 int getCurSubspaceDim()
const;
407 int getMaxSubspaceDim()
const;
432 void setBlockSize(
int blockSize);
436 int getBlockSize()
const;
465 void setFullOrtho(
bool fullOrtho);
468 bool getFullOrtho()
const;
479 void currentStatus(std::ostream &os);
497 const MagnitudeType ONE;
498 const MagnitudeType ZERO;
499 const MagnitudeType NANVAL;
504 bool checkX, checkMX, checkKX;
505 bool checkH, checkMH;
506 bool checkP, checkMP, checkKP;
508 CheckList() : checkX(
false),checkMX(
false),checkKX(
false),
509 checkH(
false),checkMH(
false),
510 checkP(
false),checkMP(
false),checkKP(
false),
511 checkR(
false),checkQ(
false) {};
516 std::string accuracyCheck(
const CheckList &chk,
const std::string &where)
const;
537 timerLocalProj_, timerDS_,
538 timerLocalUpdate_, timerCompRes_,
539 timerOrtho_, timerInit_;
544 int count_ApplyOp_, count_ApplyM_, count_ApplyPrec_;
599 std::vector<MagnitudeType> theta_, Rnorms_, R2norms_;
602 bool Rnorms_current_, R2norms_current_;
611 template <
class ScalarType,
class MV,
class OP>
620 ONE(
Teuchos::ScalarTraits<MagnitudeType>::one()),
621 ZERO(
Teuchos::ScalarTraits<MagnitudeType>::zero()),
622 NANVAL(
Teuchos::ScalarTraits<MagnitudeType>::nan()),
630 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
631 timerOp_(
Teuchos::TimeMonitor::getNewTimer(
"Anasazi: LOBPCG::Operation Op*x")),
632 timerMOp_(
Teuchos::TimeMonitor::getNewTimer(
"Anasazi: LOBPCG::Operation M*x")),
633 timerPrec_(
Teuchos::TimeMonitor::getNewTimer(
"Anasazi: LOBPCG::Operation Prec*x")),
634 timerSort_(
Teuchos::TimeMonitor::getNewTimer(
"Anasazi: LOBPCG::Sorting eigenvalues")),
635 timerLocalProj_(
Teuchos::TimeMonitor::getNewTimer(
"Anasazi: LOBPCG::Local projection")),
636 timerDS_(
Teuchos::TimeMonitor::getNewTimer(
"Anasazi: LOBPCG::Direct solve")),
637 timerLocalUpdate_(
Teuchos::TimeMonitor::getNewTimer(
"Anasazi: LOBPCG::Local update")),
638 timerCompRes_(
Teuchos::TimeMonitor::getNewTimer(
"Anasazi: LOBPCG::Computing residuals")),
639 timerOrtho_(
Teuchos::TimeMonitor::getNewTimer(
"Anasazi: LOBPCG::Orthogonalization")),
640 timerInit_(
Teuchos::TimeMonitor::getNewTimer(
"Anasazi: LOBPCG::Initialization")),
647 fullOrtho_(params.get(
"Full Ortho", true)),
654 Rnorms_current_(false),
655 R2norms_current_(false)
658 "Anasazi::LOBPCG::constructor: user passed null problem pointer.");
660 "Anasazi::LOBPCG::constructor: user passed null sort manager pointer.");
662 "Anasazi::LOBPCG::constructor: user passed null output manager pointer.");
664 "Anasazi::LOBPCG::constructor: user passed null status test pointer.");
666 "Anasazi::LOBPCG::constructor: user passed null orthogonalization manager pointer.");
668 "Anasazi::LOBPCG::constructor: problem is not set.");
670 "Anasazi::LOBPCG::constructor: problem is not Hermitian; LOBPCG requires Hermitian problem.");
673 Op_ = problem_->getOperator();
675 "Anasazi::LOBPCG::constructor: problem provides no operator.");
676 MOp_ = problem_->getM();
677 Prec_ = problem_->getPrec();
678 hasM_ = (MOp_ != Teuchos::null);
681 int bs = params.
get(
"Block Size", problem_->getNEV());
688 template <
class ScalarType,
class MV,
class OP>
692 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 706 if (blockSize_ > 0) {
710 tmp = problem_->getInitVec();
712 "Anasazi::LOBPCG::setBlockSize(): eigenproblem did not specify initial vectors to clone from.");
716 std::invalid_argument,
"Anasazi::LOBPCG::setBlockSize(): block size must be strictly positive.");
717 if (newBS == blockSize_) {
721 else if (newBS < blockSize_ && initialized_) {
737 std::vector<int> newind(newBS), oldind(newBS);
738 for (
int i=0; i<newBS; i++) {
770 theta_.resize(3*newBS);
771 Rnorms_.resize(newBS);
772 R2norms_.resize(newBS);
791 for (
int i=0; i<newBS; i++) {
792 newind[i] += 2*newBS;
793 oldind[i] += 2*blockSize_;
820 initialized_ =
false;
839 theta_.resize(3*newBS,NANVAL);
840 Rnorms_.resize(newBS,NANVAL);
841 R2norms_.resize(newBS,NANVAL);
856 tmpmvec_ = Teuchos::null;
871 template <
class ScalarType,
class MV,
class OP>
874 std::vector<int> ind(blockSize_);
876 for (
int i=0; i<blockSize_; i++) {
888 for (
int i=0; i<blockSize_; i++) {
889 ind[i] += blockSize_;
900 for (
int i=0; i<blockSize_; i++) {
901 ind[i] += blockSize_;
916 template <
class ScalarType,
class MV,
class OP>
924 for (tarcpmv i=auxVecs_.
begin(); i != auxVecs_.
end(); i++) {
929 if (numAuxVecs_ > 0 && initialized_) {
930 initialized_ =
false;
934 if (om_->isVerbosity(
Debug ) ) {
938 om_->print(
Debug, accuracyCheck(chk,
": in setAuxVecs()") );
961 template <
class ScalarType,
class MV,
class OP>
967 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 971 std::vector<int> bsind(blockSize_);
972 for (
int i=0; i<blockSize_; i++) bsind[i] = i;
996 if (newstate.
X != Teuchos::null) {
998 std::invalid_argument,
"Anasazi::LOBPCG::initialize(newstate): vector length of newstate.X not correct." );
1001 std::invalid_argument,
"Anasazi::LOBPCG::initialize(newstate): newstate.X must have at least block size vectors.");
1008 if (newstate.
MX != Teuchos::null) {
1010 std::invalid_argument,
"Anasazi::LOBPCG::initialize(newstate): vector length of newstate.MX not correct." );
1013 std::invalid_argument,
"Anasazi::LOBPCG::initialize(newstate): newstate.MX must have at least block size vectors.");
1019 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 1023 count_ApplyM_ += blockSize_;
1026 newstate.
R = Teuchos::null;
1031 if (newstate.
KX != Teuchos::null) {
1033 std::invalid_argument,
"Anasazi::LOBPCG::initialize(newstate): vector length of newstate.KX not correct." );
1036 std::invalid_argument,
"Anasazi::LOBPCG::initialize(newstate): newstate.KX must have at least block size vectors.");
1042 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 1046 count_ApplyOp_ += blockSize_;
1049 newstate.
R = Teuchos::null;
1057 newstate.
P = Teuchos::null;
1058 newstate.
KP = Teuchos::null;
1059 newstate.
MP = Teuchos::null;
1060 newstate.
R = Teuchos::null;
1061 newstate.
T = Teuchos::null;
1066 "Anasazi::LOBPCG::initialize(): Eigenproblem did not specify initial vectors to clone from.");
1069 if (initSize > blockSize_) {
1071 initSize = blockSize_;
1072 std::vector<int> ind(blockSize_);
1073 for (
int i=0; i<blockSize_; i++) ind[i] = i;
1079 std::vector<int> ind(initSize);
1080 for (
int i=0; i<initSize; i++) ind[i] = i;
1084 if (blockSize_ > initSize) {
1085 std::vector<int> ind(blockSize_ - initSize);
1086 for (
int i=0; i<blockSize_ - initSize; i++) ind[i] = initSize + i;
1094 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 1098 count_ApplyM_ += blockSize_;
1102 if (numAuxVecs_ > 0) {
1103 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 1107 int rank = orthman_->projectAndNormalizeMat(*X_,auxVecs_,dummy,Teuchos::null,MX_);
1109 "Anasazi::LOBPCG::initialize(): Couldn't generate initial basis of full rank.");
1112 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 1115 int rank = orthman_->normalizeMat(*X_,Teuchos::null,MX_);
1117 "Anasazi::LOBPCG::initialize(): Couldn't generate initial basis of full rank.");
1122 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 1126 count_ApplyOp_ += blockSize_;
1134 theta_.resize(3*blockSize_,NANVAL);
1135 if (newstate.
T != Teuchos::null) {
1137 std::invalid_argument,
"Anasazi::LOBPCG::initialize(newstate): newstate.T must contain at least block size Ritz values.");
1138 for (
int i=0; i<blockSize_; i++) {
1139 theta_[i] = (*newstate.
T)[i];
1141 nevLocal_ = blockSize_;
1146 MM(blockSize_,blockSize_),
1147 S(blockSize_,blockSize_);
1149 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 1156 nevLocal_ = blockSize_;
1161 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 1166 "Anasazi::LOBPCG::initialize(): Initial Ritz analysis did not produce enough Ritz pairs to initialize algorithm.");
1172 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 1176 std::vector<int> order(blockSize_);
1179 sm_->sort(theta_, Teuchos::rcpFromRef(order), blockSize_);
1187 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 1207 if (newstate.
R != Teuchos::null) {
1209 std::invalid_argument,
"Anasazi::LOBPCG::initialize(newstate): vector length of newstate.R not correct." );
1211 std::invalid_argument,
"Anasazi::LOBPCG::initialize(newstate): newstate.R must have blockSize number of vectors." );
1215 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 1221 for (
int i=0; i<blockSize_; i++) T(i,i) = theta_[i];
1226 Rnorms_current_ =
false;
1227 R2norms_current_ =
false;
1230 if (newstate.
P != Teuchos::null) {
1232 std::invalid_argument,
"Anasazi::LOBPCG::initialize(newstate): newstate.P must have blockSize number of vectors." );
1234 std::invalid_argument,
"Anasazi::LOBPCG::initialize(newstate): vector length of newstate.P not correct." );
1241 if (newstate.
KP != Teuchos::null) {
1243 std::invalid_argument,
"Anasazi::LOBPCG::initialize(newstate): newstate.KP must have blockSize number of vectors." );
1245 std::invalid_argument,
"Anasazi::LOBPCG::initialize(newstate): vector length of newstate.KP not correct." );
1249 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 1253 count_ApplyOp_ += blockSize_;
1258 if (newstate.
MP != Teuchos::null) {
1260 std::invalid_argument,
"Anasazi::LOBPCG::initialize(newstate): newstate.MP must have blockSize number of vectors." );
1262 std::invalid_argument,
"Anasazi::LOBPCG::initialize(newstate): vector length of newstate.MP not correct." );
1266 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 1270 count_ApplyM_ += blockSize_;
1279 initialized_ =
true;
1281 if (om_->isVerbosity(
Debug ) ) {
1292 om_->print(
Debug, accuracyCheck(chk,
": after initialize()") );
1297 template <
class ScalarType,
class MV,
class OP>
1307 template <
class ScalarType,
class MV,
class OP>
1310 if ( fullOrtho_ ==
true || initialized_ ==
false || fullOrtho == fullOrtho_ ) {
1312 fullOrtho_ = fullOrtho;
1324 if (fullOrtho_ && tmpmvec_ == Teuchos::null) {
1328 else if (fullOrtho_==
false) {
1330 tmpmvec_ = Teuchos::null;
1337 template <
class ScalarType,
class MV,
class OP>
1343 if (initialized_ ==
false) {
1349 const int oneBlock = blockSize_;
1350 const int twoBlocks = 2*blockSize_;
1351 const int threeBlocks = 3*blockSize_;
1353 std::vector<int> indblock1(blockSize_), indblock2(blockSize_), indblock3(blockSize_);
1354 for (
int i=0; i<blockSize_; i++) {
1356 indblock2[i] = i + blockSize_;
1357 indblock3[i] = i + 2*blockSize_;
1366 MM( threeBlocks, threeBlocks ),
1367 S( threeBlocks, threeBlocks );
1369 while (tester_->checkStatus(
this) !=
Passed) {
1372 if (om_->isVerbosity(
Debug)) {
1383 if (Prec_ != Teuchos::null) {
1384 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 1388 count_ApplyPrec_ += blockSize_;
1396 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 1400 count_ApplyM_ += blockSize_;
1416 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 1420 Teuchos::tuple<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > >(Teuchos::null);
1421 int rank = orthman_->projectAndNormalizeMat(*H_,Q,dummyC,Teuchos::null,MH_);
1424 "Anasazi::LOBPCG::iterate(): unable to compute orthonormal basis for H.");
1427 if (om_->isVerbosity(
Debug ) ) {
1431 om_->print(
Debug, accuracyCheck(chk,
": after ortho H") );
1437 om_->print(
OrthoDetails, accuracyCheck(chk,
": after ortho H") );
1442 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 1446 count_ApplyOp_ += blockSize_;
1450 nevLocal_ = threeBlocks;
1453 nevLocal_ = twoBlocks;
1475 KX_ = Teuchos::null;
1476 MX_ = Teuchos::null;
1478 KH_ = Teuchos::null;
1479 MH_ = Teuchos::null;
1481 KP_ = Teuchos::null;
1482 MP_ = Teuchos::null;
1483 Teuchos::RCP<const MV> cX, cH, cXHP, cHP, cK_XHP, cK_HP, cM_XHP, cM_HP, cP, cK_P, cM_P;
1485 cX =
MVT::CloneView(*Teuchos::rcp_implicit_cast<const MV>(V_),indblock1);
1486 cH =
MVT::CloneView(*Teuchos::rcp_implicit_cast<const MV>(V_),indblock2);
1488 std::vector<int> indXHP(nevLocal_);
1489 for (
int i=0; i<nevLocal_; i++) {
1492 cXHP =
MVT::CloneView(*Teuchos::rcp_implicit_cast<const MV>(V_),indXHP);
1493 cK_XHP =
MVT::CloneView(*Teuchos::rcp_implicit_cast<const MV>(KV_),indXHP);
1495 cM_XHP =
MVT::CloneView(*Teuchos::rcp_implicit_cast<const MV>(MV_),indXHP);
1501 std::vector<int> indHP(nevLocal_-blockSize_);
1502 for (
int i=blockSize_; i<nevLocal_; i++) {
1503 indHP[i-blockSize_] = i;
1505 cHP =
MVT::CloneView(*Teuchos::rcp_implicit_cast<const MV>(V_),indHP);
1506 cK_HP =
MVT::CloneView(*Teuchos::rcp_implicit_cast<const MV>(KV_),indHP);
1508 cM_HP =
MVT::CloneView(*Teuchos::rcp_implicit_cast<const MV>(MV_),indHP);
1514 if (nevLocal_ == threeBlocks) {
1515 cP =
MVT::CloneView(*Teuchos::rcp_implicit_cast<const MV>(V_),indblock3);
1516 cK_P =
MVT::CloneView(*Teuchos::rcp_implicit_cast<const MV>(KV_),indblock3);
1518 cM_P =
MVT::CloneView(*Teuchos::rcp_implicit_cast<const MV>(MV_),indblock3);
1541 K1(
Teuchos::View,KK,blockSize_,nevLocal_ ,0*blockSize_,0*blockSize_),
1542 K2(
Teuchos::View,KK,blockSize_,nevLocal_-1*blockSize_,1*blockSize_,1*blockSize_),
1543 K3(
Teuchos::View,KK,blockSize_,nevLocal_-2*blockSize_,2*blockSize_,2*blockSize_),
1544 M1(
Teuchos::View,MM,blockSize_,nevLocal_ ,0*blockSize_,0*blockSize_),
1545 M2(
Teuchos::View,MM,blockSize_,nevLocal_-1*blockSize_,1*blockSize_,1*blockSize_),
1546 M3(
Teuchos::View,MM,blockSize_,nevLocal_-2*blockSize_,2*blockSize_,2*blockSize_);
1548 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 1555 if (nevLocal_ == threeBlocks) {
1567 cK_P = Teuchos::null;
1568 cM_P = Teuchos::null;
1569 if (fullOrtho_ ==
true) {
1570 cHP = Teuchos::null;
1571 cK_HP = Teuchos::null;
1572 cM_HP = Teuchos::null;
1585 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 1588 int localSize = nevLocal_;
1589 Utils::directSolver(localSize, lclKK, Teuchos::rcpFromRef(lclMM), lclS, theta_, nevLocal_, 0);
1598 if (nevLocal_ != localSize) {
1601 cXHP = Teuchos::null;
1602 cK_XHP = Teuchos::null;
1603 cM_XHP = Teuchos::null;
1604 cHP = Teuchos::null;
1605 cK_HP = Teuchos::null;
1606 cM_HP = Teuchos::null;
1610 "Anasazi::LOBPCG::iterate(): indefiniteness detected in projected mass matrix." );
1620 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 1624 std::vector<int> order(nevLocal_);
1627 sm_->sort(theta_, Teuchos::rcpFromRef(order), nevLocal_);
1654 MMC(nevLocal_,twoBlocks),
1655 CMMC(twoBlocks ,twoBlocks);
1658 for (
int j=0; j<oneBlock; j++) {
1659 for (
int i=0; i<oneBlock; i++) {
1663 C(i,j+oneBlock) = ZERO;
1667 for (
int j=0; j<oneBlock; j++) {
1668 for (
int i=oneBlock; i<twoBlocks; i++) {
1672 C(i,j+oneBlock) = lclS(i,j);
1676 if (nevLocal_ == threeBlocks) {
1677 for (
int j=0; j<oneBlock; j++) {
1678 for (
int i=twoBlocks; i<threeBlocks; i++) {
1682 C(i,j+oneBlock) = lclS(i,j);
1692 "Anasazi::LOBPCG::iterate(): Logic error calling SerialDenseMatrix::multiply");
1696 "Anasazi::LOBPCG::iterate(): Logic error calling SerialDenseMatrix::multiply");
1709 MagnitudeType symNorm = K22_trans.
normOne();
1712 cXHP = Teuchos::null;
1713 cHP = Teuchos::null;
1714 cK_XHP = Teuchos::null;
1715 cK_HP = Teuchos::null;
1716 cM_XHP = Teuchos::null;
1717 cM_HP = Teuchos::null;
1720 std::string errMsg =
"Anasazi::LOBPCG::iterate(): Cholesky factorization failed during full orthogonalization.";
1721 if ( symNorm < tol )
1727 errMsg +=
" Check the operator A (or K), it may not be Hermitian!";
1734 nevLocal_,twoBlocks,ONE,CMMC.
values(),CMMC.
stride(),C.values(),C.stride());
1741 if (om_->isVerbosity(
Debug ) ) {
1743 tmp2(oneBlock,oneBlock);
1746 std::stringstream os;
1748 os.setf(std::ios::scientific, std::ios::floatfield);
1750 os <<
" Checking Full Ortho: iteration " << iter_ << std::endl;
1756 "Anasazi::LOBPCG::iterate(): Logic error calling SerialDenseMatrix::multiply");
1760 "Anasazi::LOBPCG::iterate(): Logic error calling SerialDenseMatrix::multiply");
1762 for (
int i=0; i<oneBlock; i++) tmp2(i,i) -= ONE;
1764 os <<
" >> Error in CX^H MM CX == I : " << tmp << std::endl;
1770 "Anasazi::LOBPCG::iterate(): Logic error calling SerialDenseMatrix::multiply");
1774 "Anasazi::LOBPCG::iterate(): Logic error calling SerialDenseMatrix::multiply");
1776 for (
int i=0; i<oneBlock; i++) tmp2(i,i) -= ONE;
1778 os <<
" >> Error in CP^H MM CP == I : " << tmp << std::endl;
1783 TEUCHOS_TEST_FOR_EXCEPTION(teuchosret != 0,std::logic_error,
"Anasazi::LOBPCG::iterate(): Logic error calling SerialDenseMatrix::multiply");
1786 TEUCHOS_TEST_FOR_EXCEPTION(teuchosret != 0,std::logic_error,
"Anasazi::LOBPCG::iterate(): Logic error calling SerialDenseMatrix::multiply");
1789 os <<
" >> Error in CX^H MM CP == 0 : " << tmp << std::endl;
1792 om_->print(
Debug,os.str());
1817 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 1848 cXHP = Teuchos::null;
1854 cK_XHP = Teuchos::null;
1861 cM_XHP = Teuchos::null;
1866 cM_XHP = Teuchos::null;
1872 cXHP = Teuchos::null;
1875 cHP = Teuchos::null;
1879 cK_XHP = Teuchos::null;
1882 cK_HP = Teuchos::null;
1887 cM_XHP = Teuchos::null;
1890 cM_HP = Teuchos::null;
1894 cM_XHP = Teuchos::null;
1895 cM_HP = Teuchos::null;
1910 || cHP != Teuchos::null || cK_HP != Teuchos::null || cM_HP != Teuchos::null
1911 || cP != Teuchos::null || cK_P != Teuchos::null || cM_P != Teuchos::null,
1913 "Anasazi::BlockKrylovSchur::iterate(): const views were not all cleared! Something went wrong!" );
1922 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 1927 for (
int i = 0; i < blockSize_; i++) {
1934 Rnorms_current_ =
false;
1935 R2norms_current_ =
false;
1938 if (om_->isVerbosity(
Debug ) ) {
1948 om_->print(
Debug, accuracyCheck(chk,
": after local update") );
1955 om_->print(
OrthoDetails, accuracyCheck(chk,
": after local update") );
1963 template <
class ScalarType,
class MV,
class OP>
1964 std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>
1966 if (Rnorms_current_ ==
false) {
1968 orthman_->norm(*R_,Rnorms_);
1969 Rnorms_current_ =
true;
1977 template <
class ScalarType,
class MV,
class OP>
1978 std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>
1980 if (R2norms_current_ ==
false) {
1983 R2norms_current_ =
true;
2018 template <
class ScalarType,
class MV,
class OP>
2023 std::stringstream os;
2025 os.setf(std::ios::scientific, std::ios::floatfield);
2028 os <<
" Debugging checks: iteration " << iter_ << where << endl;
2031 if (chk.checkX && initialized_) {
2032 tmp = orthman_->orthonormError(*X_);
2033 os <<
" >> Error in X^H M X == I : " << tmp << endl;
2034 for (Array_size_type i=0; i<auxVecs_.
size(); i++) {
2035 tmp = orthman_->orthogError(*X_,*auxVecs_[i]);
2036 os <<
" >> Error in X^H M Q[" << i <<
"] == 0 : " << tmp << endl;
2039 if (chk.checkMX && hasM_ && initialized_) {
2041 os <<
" >> Error in MX == M*X : " << tmp << endl;
2043 if (chk.checkKX && initialized_) {
2045 os <<
" >> Error in KX == K*X : " << tmp << endl;
2049 if (chk.checkP && hasP_ && initialized_) {
2051 tmp = orthman_->orthonormError(*P_);
2052 os <<
" >> Error in P^H M P == I : " << tmp << endl;
2053 tmp = orthman_->orthogError(*P_,*X_);
2054 os <<
" >> Error in P^H M X == 0 : " << tmp << endl;
2056 for (Array_size_type i=0; i<auxVecs_.
size(); i++) {
2057 tmp = orthman_->orthogError(*P_,*auxVecs_[i]);
2058 os <<
" >> Error in P^H M Q[" << i <<
"] == 0 : " << tmp << endl;
2061 if (chk.checkMP && hasM_ && hasP_ && initialized_) {
2063 os <<
" >> Error in MP == M*P : " << tmp << endl;
2065 if (chk.checkKP && hasP_ && initialized_) {
2067 os <<
" >> Error in KP == K*P : " << tmp << endl;
2071 if (chk.checkH && initialized_) {
2073 tmp = orthman_->orthonormError(*H_);
2074 os <<
" >> Error in H^H M H == I : " << tmp << endl;
2075 tmp = orthman_->orthogError(*H_,*X_);
2076 os <<
" >> Error in H^H M X == 0 : " << tmp << endl;
2078 tmp = orthman_->orthogError(*H_,*P_);
2079 os <<
" >> Error in H^H M P == 0 : " << tmp << endl;
2082 for (Array_size_type i=0; i<auxVecs_.
size(); i++) {
2083 tmp = orthman_->orthogError(*H_,*auxVecs_[i]);
2084 os <<
" >> Error in H^H M Q[" << i <<
"] == 0 : " << tmp << endl;
2087 if (chk.checkMH && hasM_ && initialized_) {
2089 os <<
" >> Error in MH == M*H : " << tmp << endl;
2093 if (chk.checkR && initialized_) {
2099 os <<
" >> RelError in X^H R == 0: " << tmp/normR << endl;
2104 for (Array_size_type i=0; i<auxVecs_.
size(); i++) {
2105 tmp = orthman_->orthonormError(*auxVecs_[i]);
2106 os <<
" >> Error in Q[" << i <<
"]^H M Q[" << i <<
"] == I : " << tmp << endl;
2107 for (Array_size_type j=i+1; j<auxVecs_.
size(); j++) {
2108 tmp = orthman_->orthogError(*auxVecs_[i],*auxVecs_[j]);
2109 os <<
" >> Error in Q[" << i <<
"]^H M Q[" << j <<
"] == 0 : " << tmp << endl;
2122 template <
class ScalarType,
class MV,
class OP>
2128 os.setf(std::ios::scientific, std::ios::floatfield);
2131 os <<
"================================================================================" << endl;
2133 os <<
" LOBPCG Solver Status" << endl;
2135 os <<
"The solver is "<<(initialized_ ?
"initialized." :
"not initialized.") << endl;
2136 os <<
"The number of iterations performed is " << iter_ << endl;
2137 os <<
"The current block size is " << blockSize_ << endl;
2138 os <<
"The number of auxiliary vectors is " << numAuxVecs_ << endl;
2139 os <<
"The number of operations Op*x is " << count_ApplyOp_ << endl;
2140 os <<
"The number of operations M*x is " << count_ApplyM_ << endl;
2141 os <<
"The number of operations Prec*x is " << count_ApplyPrec_ << endl;
2143 os.setf(std::ios_base::right, std::ios_base::adjustfield);
2147 os <<
"CURRENT EIGENVALUE ESTIMATES "<<endl;
2148 os << std::setw(20) <<
"Eigenvalue" 2149 << std::setw(20) <<
"Residual(M)" 2150 << std::setw(20) <<
"Residual(2)" 2152 os <<
"--------------------------------------------------------------------------------"<<endl;
2153 for (
int i=0; i<blockSize_; i++) {
2154 os << std::setw(20) << theta_[i];
2155 if (Rnorms_current_) os << std::setw(20) << Rnorms_[i];
2156 else os << std::setw(20) <<
"not current";
2157 if (R2norms_current_) os << std::setw(20) << R2norms_[i];
2158 else os << std::setw(20) <<
"not current";
2162 os <<
"================================================================================" << endl;
2168 template <
class ScalarType,
class MV,
class OP>
2170 return initialized_;
2176 template <
class ScalarType,
class MV,
class OP>
2183 template <
class ScalarType,
class MV,
class OP>
2191 template <
class ScalarType,
class MV,
class OP>
2198 template <
class ScalarType,
class MV,
class OP>
2205 template <
class ScalarType,
class MV,
class OP>
2213 template <
class ScalarType,
class MV,
class OP>
2215 return 3*blockSize_;
2220 template <
class ScalarType,
class MV,
class OP>
2222 if (!initialized_)
return 0;
2229 template <
class ScalarType,
class MV,
class OP>
2230 std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>
2239 template <
class ScalarType,
class MV,
class OP>
2241 std::vector<int> ret(nevLocal_,0);
2248 template <
class ScalarType,
class MV,
class OP>
2250 std::vector<Value<ScalarType> > ret(nevLocal_);
2251 for (
int i=0; i<nevLocal_; i++) {
2252 ret[i].realpart = theta_[i];
2253 ret[i].imagpart = ZERO;
2260 template <
class ScalarType,
class MV,
class OP>
2263 "Anasazi::LOBPCG::setStatusTest() was passed a null StatusTest.");
2269 template <
class ScalarType,
class MV,
class OP>
2276 template <
class ScalarType,
class MV,
class OP>
2284 template <
class ScalarType,
class MV,
class OP>
2292 template <
class ScalarType,
class MV,
class OP>
2300 template <
class ScalarType,
class MV,
class OP>
2312 state.
T =
Teuchos::rcp(
new std::vector<MagnitudeType>(theta_));
2320 state.
MX = Teuchos::null;
2321 state.
MP = Teuchos::null;
2322 state.
MH = Teuchos::null;
2329 #endif // ANASAZI_LOBPCG_HPP ScalarTraits< ScalarType >::magnitudeType normOne() const
ScalarType * values() const
static void MvRandom(MV &mv)
Replace the vectors in mv with random vectors.
static void MvTimesMatAddMv(const ScalarType alpha, const MV &A, const Teuchos::SerialDenseMatrix< int, ScalarType > &B, const ScalarType beta, MV &mv)
Update mv with .
An extension of the MultiVecTraits class that adds a new vector length method.This traits class provi...
Templated virtual class for providing orthogonalization/orthonormalization methods with matrix-based ...
Teuchos::Array< Teuchos::RCP< const MV > > getAuxVecs() const
Get the current auxiliary vectors.
LOBPCG(const Teuchos::RCP< Eigenproblem< ScalarType, MV, OP > > &problem, const Teuchos::RCP< SortManager< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > > &sorter, const Teuchos::RCP< OutputManager< ScalarType > > &printer, const Teuchos::RCP< StatusTest< ScalarType, MV, OP > > &tester, const Teuchos::RCP< MatOrthoManager< ScalarType, MV, OP > > &ortho, Teuchos::ParameterList ¶ms)
LOBPCG constructor with eigenproblem, solver utilities, and parameter list of solver options...
This class defines the interface required by an eigensolver and status test class to compute solution...
static ptrdiff_t GetGlobalLength(const MV &mv)
static magnitudeType eps()
int getBlockSize() const
Get the blocksize to be used by the iterative solver in solving this eigenproblem.
void setStatusTest(Teuchos::RCP< StatusTest< ScalarType, MV, OP > > test)
Set a new StatusTest for the solver.
Declaration of basic traits for the multivector type.
T & get(const std::string &name, T def_value)
int multiply(ETransp transa, ETransp transb, ScalarType alpha, const SerialDenseMatrix< OrdinalType, ScalarType > &A, const SerialDenseMatrix< OrdinalType, ScalarType > &B, ScalarType beta)
static ScalarType squareroot(ScalarType x)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
This class provides the Locally Optimal Block Preconditioned Conjugate Gradient (LOBPCG) iteration...
Teuchos::RCP< const MultiVector > V
The current test basis.
virtual ~LOBPCG()
LOBPCG destructor
Virtual base class which defines basic traits for the operator type.
Teuchos::RCP< const MultiVector > H
The current preconditioned residual vectors.
Teuchos::RCP< const MultiVector > P
The current search direction.
static Teuchos::ScalarTraits< ScalarType >::magnitudeType errorEquality(const MV &X, const MV &MX, Teuchos::RCP< const OP > M=Teuchos::null)
Return the maximum coefficient of the matrix scaled by the maximum coefficient of MX...
static void Apply(const OP &Op, const MV &x, MV &y)
Application method which performs operation y = Op*x. An OperatorError exception is thrown if there i...
An exception class parent to all Anasazi exceptions.
Teuchos::RCP< const MultiVector > MV
The image of the current test basis under M, or Teuchos::null if M was not specified.
ScalarTraits< ScalarType >::magnitudeType normFrobenius() const
Pure virtual base class which describes the basic interface to the iterative eigensolver.
Namespace Anasazi contains the classes, structs, enums and utilities used by the Anasazi package...
Teuchos::RCP< const MultiVector > R
The current residual vectors.
void initialize()
Initialize the solver with the initial vectors from the eigenproblem or random data.
Teuchos::RCP< const std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > > T
The current Ritz values.
bool isInitialized() const
Indicates whether the solver has been initialized or not.
Anasazi's templated, static class providing utilities for the solvers.
const Eigenproblem< ScalarType, MV, OP > & getProblem() const
Get a constant reference to the eigenvalue problem.
static void MvTransMv(const ScalarType alpha, const MV &A, const MV &mv, Teuchos::SerialDenseMatrix< int, ScalarType > &B)
Compute a dense matrix B through the matrix-matrix multiply .
void POTRF(const char UPLO, const OrdinalType n, ScalarType *A, const OrdinalType lda, OrdinalType *info) const
Anasazi's templated virtual class for providing routines for orthogonalization and orthonormalization...
void setBlockSize(int blockSize)
Set the blocksize to be used by the iterative solver in solving this eigenproblem.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Output managers remove the need for the eigensolver to know any information about the required output...
static int directSolver(int size, const Teuchos::SerialDenseMatrix< int, ScalarType > &KK, Teuchos::RCP< const Teuchos::SerialDenseMatrix< int, ScalarType > > MM, Teuchos::SerialDenseMatrix< int, ScalarType > &EV, std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &theta, int &nev, int esType=0)
Routine for computing the first NEV generalized eigenpairs of the Hermitian pencil (KK...
Traits class which defines basic operations on multivectors.
int getNumIters() const
Get the current iteration count.
Virtual base class which defines basic traits for the operator type.
std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > getRes2Norms()
Get the current residual 2-norms.
Teuchos::RCP< const MultiVector > MX
The image of the current eigenvectors under M, or Teuchos::null if M was not specified.
Teuchos::RCP< const MultiVector > KX
The image of the current eigenvectors under K.
bool getFullOrtho() const
Determine if the LOBPCG iteration is using full orthogonality.
Teuchos::RCP< const MultiVector > KH
The image of the current preconditioned residual vectors under K.
static Teuchos::RCP< MV > CloneViewNonConst(MV &mv, const std::vector< int > &index)
Creates a new MV that shares the selected contents of mv (shallow copy).
std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > getResNorms()
Get the current residual norms.
std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > getRitzRes2Norms()
Get the 2-norms of the residuals.
std::vector< int > getRitzIndex()
Get the index used for extracting Ritz vectors from getRitzVectors().
static void MvNorm(const MV &mv, std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &normvec)
Compute the 2-norm of each individual vector of mv. Upon return, normvec[i] holds the value of ...
static Teuchos::RCP< const MV > CloneView(const MV &mv, const std::vector< int > &index)
Creates a new const MV that shares the selected contents of mv (shallow copy).
static void SetBlock(const MV &A, const std::vector< int > &index, MV &mv)
Copy the vectors in A to a set of vectors in mv indicated by the indices given in index...
int getMaxSubspaceDim() const
Get the maximum dimension allocated for the search subspace. For LOBPCG, this always returns 3*getBlo...
Teuchos::RCP< const MultiVector > MH
The image of the current preconditioned residual vectors under M, or Teuchos::null if M was not speci...
Teuchos::RCP< const MultiVector > KP
The image of the current search direction under K.
static magnitudeType magnitude(ScalarType a)
static int GetNumberVecs(const MV &mv)
Obtain the number of vectors in mv.
static void MvAddMv(const ScalarType alpha, const MV &A, const ScalarType beta, const MV &B, MV &mv)
Replace mv with .
Teuchos::RCP< StatusTest< ScalarType, MV, OP > > getStatusTest() const
Get the current StatusTest used by the solver.
void push_back(const value_type &x)
void currentStatus(std::ostream &os)
This method requests that the solver print out its current status to screen.
void iterate()
This method performs LOBPCG iterations until the status test indicates the need to stop or an error o...
static void permuteVectors(const int n, const std::vector< int > &perm, MV &Q, std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > *resids=0)
Permute the vectors in a multivector according to the permutation vector perm, and optionally the res...
LOBPCGRitzFailure is thrown when the LOBPCG solver is unable to continue a call to LOBPCG::iterate() ...
std::vector< Value< ScalarType > > getRitzValues()
Get the Ritz values from the previous iteration.
Teuchos::RCP< const MultiVector > KV
The image of the current test basis under K.
void setAuxVecs(const Teuchos::Array< Teuchos::RCP< const MV > > &auxvecs)
Set the auxiliary vectors for the solver.
Types and exceptions used within Anasazi solvers and interfaces.
void resetNumIters()
Reset the iteration count.
void TRSM(ESide side, EUplo uplo, ETransp transa, EDiag diag, const OrdinalType m, const OrdinalType n, const alpha_type alpha, const A_type *A, const OrdinalType lda, ScalarType *B, const OrdinalType ldb) const
Teuchos::RCP< const MultiVector > MP
The image of the current search direction under M, or Teuchos::null if M was not specified.
Anasazi's templated pure virtual class for managing the sorting of approximate eigenvalues computed b...
A pure virtual class for defining the status tests for the Anasazi iterative solvers.
LOBPCGOrthoFailure is thrown when an orthogonalization attempt fails.
LOBPCGInitFailure is thrown when the LOBPCG solver is unable to generate an initial iterate in the LO...
LOBPCGState< ScalarType, MV > getState() const
Get the current state of the eigensolver.
The Eigensolver is a templated virtual base class that defines the basic interface that any eigensolv...
void setFullOrtho(bool fullOrtho)
Instruct the LOBPCG iteration to use full orthogonality.
Structure to contain pointers to Anasazi state variables.
Teuchos::RCP< const MultiVector > X
The current eigenvectors.
OrdinalType stride() const
Teuchos::RCP< const MV > getRitzVectors()
Get the Ritz vectors from the previous iteration.
static Teuchos::RCP< MV > Clone(const MV &mv, const int numvecs)
Creates a new empty MV containing numvecs columns.
bool hasP()
Indicates whether the search direction given by getState() is valid.
int getCurSubspaceDim() const
Get the dimension of the search subspace used to generate the current eigenvectors and eigenvalues...
Class which provides internal utilities for the Anasazi solvers.