46 #ifndef ANASAZI_RTRBASE_HPP 47 #define ANASAZI_RTRBASE_HPP 54 #include "Teuchos_ScalarTraits.hpp" 59 #include "Teuchos_LAPACK.hpp" 60 #include "Teuchos_BLAS.hpp" 61 #include "Teuchos_SerialDenseMatrix.hpp" 62 #include "Teuchos_ParameterList.hpp" 63 #include "Teuchos_TimeMonitor.hpp" 123 template <
class ScalarType,
class MV>
126 Teuchos::RCP<const MV>
X;
128 Teuchos::RCP<const MV>
AX;
130 Teuchos::RCP<const MV>
BX;
132 Teuchos::RCP<const MV>
R;
134 Teuchos::RCP<const std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> >
T;
138 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
rho;
139 RTRState() : X(Teuchos::null),AX(Teuchos::null),BX(Teuchos::null),
140 R(Teuchos::null),T(Teuchos::null),rho(0) {};
201 template <
class ScalarType,
class MV,
class OP>
214 const Teuchos::RCP<
SortManager<
typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> > &sorter,
218 Teuchos::ParameterList ¶ms,
219 const std::string &solverLabel,
bool skinnySolver
251 virtual void iterate() = 0;
296 bool isInitialized()
const;
313 int getNumIters()
const;
316 void resetNumIters();
325 Teuchos::RCP<const MV> getRitzVectors();
332 std::vector<Value<ScalarType> > getRitzValues();
341 std::vector<int> getRitzIndex();
348 std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> getResNorms();
356 std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> getRes2Norms();
363 std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> getRitzRes2Norms();
374 int getCurSubspaceDim()
const;
378 int getMaxSubspaceDim()
const;
389 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > getStatusTest()
const;
403 void setBlockSize(
int blockSize);
407 int getBlockSize()
const;
430 void setAuxVecs(
const Teuchos::Array<Teuchos::RCP<const MV> > &auxvecs);
433 Teuchos::Array<Teuchos::RCP<const MV> > getAuxVecs()
const;
441 virtual void currentStatus(std::ostream &os);
452 typedef Teuchos::ScalarTraits<ScalarType> SCT;
453 typedef typename SCT::magnitudeType MagnitudeType;
454 typedef Teuchos::ScalarTraits<MagnitudeType> MAT;
455 const MagnitudeType ONE;
456 const MagnitudeType ZERO;
457 const MagnitudeType NANVAL;
458 typedef typename std::vector<MagnitudeType>::iterator vecMTiter;
459 typedef typename std::vector<ScalarType>::iterator vecSTiter;
464 bool checkX, checkAX, checkBX;
465 bool checkEta, checkAEta, checkBEta;
466 bool checkR, checkQ, checkBR;
467 bool checkZ, checkPBX;
468 CheckList() : checkX(
false),checkAX(
false),checkBX(
false),
469 checkEta(
false),checkAEta(
false),checkBEta(
false),
470 checkR(
false),checkQ(
false),checkBR(
false),
471 checkZ(
false), checkPBX(
false) {};
476 std::string accuracyCheck(
const CheckList &chk,
const std::string &where)
const;
478 virtual void solveTRSubproblem() = 0;
480 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType ginner(
const MV &xi)
const;
481 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType ginner(
const MV &xi,
const MV &zeta)
const;
482 void ginnersep(
const MV &xi, std::vector<
typename Teuchos::ScalarTraits<ScalarType>::magnitudeType > &d)
const;
483 void ginnersep(
const MV &xi,
const MV &zeta, std::vector<
typename Teuchos::ScalarTraits<ScalarType>::magnitudeType > &d)
const;
487 const Teuchos::RCP<Eigenproblem<ScalarType,MV,OP> > problem_;
488 const Teuchos::RCP<SortManager<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> > sm_;
489 const Teuchos::RCP<OutputManager<ScalarType> > om_;
490 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > tester_;
491 const Teuchos::RCP<GenOrthoManager<ScalarType,MV,OP> > orthman_;
495 Teuchos::RCP<const OP> AOp_;
496 Teuchos::RCP<const OP> BOp_;
497 Teuchos::RCP<const OP> Prec_;
498 bool hasBOp_, hasPrec_, olsenPrec_;
502 Teuchos::RCP<Teuchos::Time> timerAOp_, timerBOp_, timerPrec_,
504 timerLocalProj_, timerDS_,
505 timerLocalUpdate_, timerCompRes_,
506 timerOrtho_, timerInit_;
511 int counterAOp_, counterBOp_, counterPrec_;
574 Teuchos::RCP<MV> V_, BV_, PBV_,
577 delta_, Adelta_, Bdelta_, Hdelta_,
579 Teuchos::RCP<const MV> X_, BX_;
582 Teuchos::Array<Teuchos::RCP<const MV> > auxVecs_;
589 std::vector<MagnitudeType> theta_, Rnorms_, R2norms_, ritz2norms_;
592 bool Rnorms_current_, R2norms_current_;
595 MagnitudeType conv_kappa_, conv_theta_;
607 template <
class ScalarType,
class MV,
class OP>
610 const Teuchos::RCP<
SortManager<
typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> > &sorter,
614 Teuchos::ParameterList ¶ms,
615 const std::string &solverLabel,
bool skinnySolver
617 ONE(Teuchos::ScalarTraits<MagnitudeType>::one()),
618 ZERO(Teuchos::ScalarTraits<MagnitudeType>::zero()),
619 NANVAL(Teuchos::ScalarTraits<MagnitudeType>::nan()),
626 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
627 timerAOp_(Teuchos::TimeMonitor::getNewTimer(
"Anasazi: "+solverLabel+
"::Operation A*x")),
628 timerBOp_(Teuchos::TimeMonitor::getNewTimer(
"Anasazi: "+solverLabel+
"::Operation B*x")),
629 timerPrec_(Teuchos::TimeMonitor::getNewTimer(
"Anasazi: "+solverLabel+
"::Operation Prec*x")),
630 timerSort_(Teuchos::TimeMonitor::getNewTimer(
"Anasazi: "+solverLabel+
"::Sorting eigenvalues")),
631 timerLocalProj_(Teuchos::TimeMonitor::getNewTimer(
"Anasazi: "+solverLabel+
"::Local projection")),
632 timerDS_(Teuchos::TimeMonitor::getNewTimer(
"Anasazi: "+solverLabel+
"::Direct solve")),
633 timerLocalUpdate_(Teuchos::TimeMonitor::getNewTimer(
"Anasazi: "+solverLabel+
"::Local update")),
634 timerCompRes_(Teuchos::TimeMonitor::getNewTimer(
"Anasazi: "+solverLabel+
"::Computing residuals")),
635 timerOrtho_(Teuchos::TimeMonitor::getNewTimer(
"Anasazi: "+solverLabel+
"::Orthogonalization")),
636 timerInit_(Teuchos::TimeMonitor::getNewTimer(
"Anasazi: "+solverLabel+
"::Initialization")),
645 isSkinny_(skinnySolver),
647 auxVecs_( Teuchos::Array<Teuchos::RCP<const MV> >(0) ),
650 Rnorms_current_(false),
651 R2norms_current_(false),
657 TEUCHOS_TEST_FOR_EXCEPTION(problem_ == Teuchos::null,std::invalid_argument,
658 "Anasazi::RTRBase::constructor: user passed null problem pointer.");
659 TEUCHOS_TEST_FOR_EXCEPTION(sm_ == Teuchos::null,std::invalid_argument,
660 "Anasazi::RTRBase::constructor: user passed null sort manager pointer.");
661 TEUCHOS_TEST_FOR_EXCEPTION(om_ == Teuchos::null,std::invalid_argument,
662 "Anasazi::RTRBase::constructor: user passed null output manager pointer.");
663 TEUCHOS_TEST_FOR_EXCEPTION(tester_ == Teuchos::null,std::invalid_argument,
664 "Anasazi::RTRBase::constructor: user passed null status test pointer.");
665 TEUCHOS_TEST_FOR_EXCEPTION(orthman_ == Teuchos::null,std::invalid_argument,
666 "Anasazi::RTRBase::constructor: user passed null orthogonalization manager pointer.");
667 TEUCHOS_TEST_FOR_EXCEPTION(problem_->isProblemSet() ==
false, std::invalid_argument,
668 "Anasazi::RTRBase::constructor: problem is not set.");
669 TEUCHOS_TEST_FOR_EXCEPTION(problem_->isHermitian() ==
false, std::invalid_argument,
670 "Anasazi::RTRBase::constructor: problem is not Hermitian.");
673 AOp_ = problem_->getOperator();
674 TEUCHOS_TEST_FOR_EXCEPTION(AOp_ == Teuchos::null, std::invalid_argument,
675 "Anasazi::RTRBase::constructor: problem provides no A matrix.");
676 BOp_ = problem_->getM();
677 Prec_ = problem_->getPrec();
678 hasBOp_ = (BOp_ != Teuchos::null);
679 hasPrec_ = (Prec_ != Teuchos::null);
680 olsenPrec_ = params.get<
bool>(
"Olsen Prec",
true);
682 TEUCHOS_TEST_FOR_EXCEPTION(orthman_->getOp() != BOp_,std::invalid_argument,
683 "Anasazi::RTRBase::constructor: orthogonalization manager must use mass matrix for inner product.");
686 int bs = params.get(
"Block Size", problem_->getNEV());
690 leftMost_ = params.get(
"Leftmost",leftMost_);
692 conv_kappa_ = params.get(
"Kappa Convergence",conv_kappa_);
693 TEUCHOS_TEST_FOR_EXCEPTION(conv_kappa_ <= 0 || conv_kappa_ >= 1,std::invalid_argument,
694 "Anasazi::RTRBase::constructor: kappa must be in (0,1).");
695 conv_theta_ = params.get(
"Theta Convergence",conv_theta_);
696 TEUCHOS_TEST_FOR_EXCEPTION(conv_theta_ <= 0,std::invalid_argument,
697 "Anasazi::RTRBase::constructor: theta must be strictly postitive.");
703 template <
class ScalarType,
class MV,
class OP>
707 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 708 Teuchos::TimeMonitor lcltimer( *timerInit_ );
715 Teuchos::RCP<const MV> tmp;
721 if (blockSize_ > 0) {
725 tmp = problem_->getInitVec();
726 TEUCHOS_TEST_FOR_EXCEPTION(tmp == Teuchos::null,std::logic_error,
727 "Anasazi::RTRBase::setBlockSize(): Eigenproblem did not specify initial vectors to clone from");
730 TEUCHOS_TEST_FOR_EXCEPTION(blockSize <= 0 || blockSize >
MVT::GetGlobalLength(*tmp), std::invalid_argument,
731 "Anasazi::RTRBase::setBlockSize was passed a non-positive block size");
734 if (blockSize == blockSize_) {
753 if (blockSize > blockSize_)
757 Teuchos::RCP<const MV> Q;
758 std::vector<int> indQ(numAuxVecs_);
759 for (
int i=0; i<numAuxVecs_; i++) indQ[i] = i;
761 TEUCHOS_TEST_FOR_EXCEPTION(numAuxVecs_ > 0 && blockSize_ == 0, std::logic_error,
762 "Anasazi::RTRBase::setSize(): logic error. Please contact Anasazi team.");
765 V_ =
MVT::Clone(*tmp,numAuxVecs_ + blockSize);
770 BV_ =
MVT::Clone(*tmp,numAuxVecs_ + blockSize);
777 if (hasPrec_ && olsenPrec_) {
779 PBV_ =
MVT::Clone(*tmp,numAuxVecs_ + blockSize);
786 std::vector<int> indV(numAuxVecs_+blockSize);
787 for (
int i=0; i<numAuxVecs_+blockSize; i++) indV[i] = i;
798 if (hasPrec_ && olsenPrec_) {
803 if (blockSize < blockSize_) {
805 blockSize_ = blockSize;
807 theta_.resize(blockSize_);
808 ritz2norms_.resize(blockSize_);
809 Rnorms_.resize(blockSize_);
810 R2norms_.resize(blockSize_);
814 std::vector<int> ind(blockSize_);
815 for (
int i=0; i<blockSize_; i++) ind[i] = i;
834 Aeta_ = Teuchos::null;
835 Adelta_ = Teuchos::null;
844 Beta_ = Teuchos::null;
845 Bdelta_ = Teuchos::null;
855 if (hasPrec_ || isSkinny_) {
868 eta_ = Teuchos::null;
869 Aeta_ = Teuchos::null;
870 delta_ = Teuchos::null;
871 Adelta_ = Teuchos::null;
872 Hdelta_ = Teuchos::null;
873 Beta_ = Teuchos::null;
874 Bdelta_ = Teuchos::null;
900 if (hasPrec_ || isSkinny_) {
910 initialized_ =
false;
913 theta_.resize(blockSize,NANVAL);
914 ritz2norms_.resize(blockSize,NANVAL);
915 Rnorms_.resize(blockSize,NANVAL);
916 R2norms_.resize(blockSize,NANVAL);
921 eta_ = Teuchos::null;
922 Aeta_ = Teuchos::null;
923 delta_ = Teuchos::null;
924 Adelta_ = Teuchos::null;
925 Hdelta_ = Teuchos::null;
926 Beta_ = Teuchos::null;
927 Bdelta_ = Teuchos::null;
951 if (hasPrec_ || isSkinny_) {
957 blockSize_ = blockSize;
963 std::vector<int> indX(blockSize_);
964 for (
int i=0; i<blockSize_; i++) indX[i] = numAuxVecs_+i;
978 template <
class ScalarType,
class MV,
class OP>
980 TEUCHOS_TEST_FOR_EXCEPTION(test == Teuchos::null,std::invalid_argument,
981 "Anasazi::RTRBase::setStatusTest() was passed a null StatusTest.");
988 template <
class ScalarType,
class MV,
class OP>
996 template <
class ScalarType,
class MV,
class OP>
998 typedef typename Teuchos::Array<Teuchos::RCP<const MV> >::const_iterator tarcpmv;
1002 auxVecs_.reserve(auxvecs.size());
1005 for (tarcpmv v=auxvecs.begin(); v != auxvecs.end(); ++v) {
1010 if (numAuxVecs_ > 0 && initialized_) {
1011 initialized_ =
false;
1016 BX_ = Teuchos::null;
1019 BV_ = Teuchos::null;
1020 PBV_ = Teuchos::null;
1023 if (numAuxVecs_ > 0) {
1024 V_ =
MVT::Clone(*R_,numAuxVecs_ + blockSize_);
1026 for (tarcpmv v=auxvecs.begin(); v != auxvecs.end(); ++v) {
1028 for (
size_t j=0; j<ind.size(); j++) ind[j] = numsofar++;
1030 auxVecs_.push_back(
MVT::CloneView(*Teuchos::rcp_static_cast<const MV>(V_),ind));
1032 TEUCHOS_TEST_FOR_EXCEPTION(numsofar != numAuxVecs_, std::logic_error,
1033 "Anasazi::RTRBase::setAuxVecs(): Logic error. Please contact Anasazi team.");
1036 BV_ =
MVT::Clone(*R_,numAuxVecs_ + blockSize_);
1042 if (hasPrec_ && olsenPrec_) {
1043 PBV_ =
MVT::Clone(*R_,numAuxVecs_ + blockSize_);
1049 if (om_->isVerbosity(
Debug ) ) {
1053 om_->print(
Debug, accuracyCheck(chk,
"in setAuxVecs()") );
1070 template <
class ScalarType,
class MV,
class OP>
1079 BX_ = Teuchos::null;
1080 Teuchos::RCP<MV> X, BX;
1082 std::vector<int> ind(blockSize_);
1083 for (
int i=0; i<blockSize_; ++i) ind[i] = numAuxVecs_+i;
1093 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 1094 Teuchos::TimeMonitor inittimer( *timerInit_ );
1097 std::vector<int> bsind(blockSize_);
1098 for (
int i=0; i<blockSize_; i++) bsind[i] = i;
1117 if (newstate.
X != Teuchos::null) {
1119 std::invalid_argument,
"Anasazi::RTRBase::initialize(newstate): vector length of newstate.X not correct." );
1122 std::invalid_argument,
"Anasazi::RTRBase::initialize(newstate): newstate.X must have at least block size vectors.");
1134 if (newstate.
AX != Teuchos::null) {
1136 std::invalid_argument,
"Anasazi::RTRBase::initialize(newstate): vector length of newstate.AX not correct." );
1139 std::invalid_argument,
"Anasazi::RTRBase::initialize(newstate): newstate.AX must have at least block size vectors.");
1144 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 1145 Teuchos::TimeMonitor lcltimer( *timerAOp_ );
1148 counterAOp_ += blockSize_;
1151 newstate.
R = Teuchos::null;
1157 if (newstate.
BX != Teuchos::null) {
1159 std::invalid_argument,
"Anasazi::RTRBase::initialize(newstate): vector length of newstate.BX not correct." );
1162 std::invalid_argument,
"Anasazi::RTRBase::initialize(newstate): newstate.BX must have at least block size vectors.");
1167 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 1168 Teuchos::TimeMonitor lcltimer( *timerBOp_ );
1171 counterBOp_ += blockSize_;
1174 newstate.
R = Teuchos::null;
1179 TEUCHOS_TEST_FOR_EXCEPTION(BX != X, std::logic_error,
"Anasazi::RTRBase::initialize(): solver invariant not satisfied (BX==X).");
1187 newstate.
R = Teuchos::null;
1188 newstate.
T = Teuchos::null;
1191 Teuchos::RCP<const MV> ivec = problem_->getInitVec();
1192 TEUCHOS_TEST_FOR_EXCEPTION(ivec == Teuchos::null,std::logic_error,
1193 "Anasazi::RTRBase::initialize(): Eigenproblem did not specify initial vectors to clone from.");
1196 if (initSize > blockSize_) {
1198 initSize = blockSize_;
1199 std::vector<int> ind(blockSize_);
1200 for (
int i=0; i<blockSize_; i++) ind[i] = i;
1206 std::vector<int> ind(initSize);
1207 for (
int i=0; i<initSize; i++) ind[i] = i;
1211 if (blockSize_ > initSize) {
1212 std::vector<int> ind(blockSize_ - initSize);
1213 for (
int i=0; i<blockSize_ - initSize; i++) ind[i] = initSize + i;
1221 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 1222 Teuchos::TimeMonitor lcltimer( *timerBOp_ );
1225 counterBOp_ += blockSize_;
1229 TEUCHOS_TEST_FOR_EXCEPTION(BX != X, std::logic_error,
"Anasazi::RTRBase::initialize(): solver invariant not satisfied (BX==X).");
1233 if (numAuxVecs_ > 0) {
1234 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 1235 Teuchos::TimeMonitor lcltimer( *timerOrtho_ );
1237 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > dummyC;
1238 int rank = orthman_->projectAndNormalizeMat(*X,auxVecs_,dummyC,Teuchos::null,BX);
1240 "Anasazi::RTRBase::initialize(): Couldn't generate initial basis of full rank.");
1243 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 1244 Teuchos::TimeMonitor lcltimer( *timerOrtho_ );
1246 int rank = orthman_->normalizeMat(*X,Teuchos::null,BX);
1248 "Anasazi::RTRBase::initialize(): Couldn't generate initial basis of full rank.");
1256 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 1257 Teuchos::TimeMonitor lcltimer( *timerAOp_ );
1260 counterAOp_ += blockSize_;
1267 if (newstate.
T != Teuchos::null) {
1268 TEUCHOS_TEST_FOR_EXCEPTION( (
signed int)(newstate.
T->size()) < blockSize_,
1269 std::invalid_argument,
"Anasazi::RTRBase::initialize(newstate): newstate.T must contain at least block size Ritz values.");
1270 for (
int i=0; i<blockSize_; i++) {
1271 theta_[i] = (*newstate.
T)[i];
1276 Teuchos::SerialDenseMatrix<int,ScalarType> AA(blockSize_,blockSize_),
1277 BB(blockSize_,blockSize_),
1278 S(blockSize_,blockSize_);
1281 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 1282 Teuchos::TimeMonitor lcltimer( *timerLocalProj_ );
1289 nevLocal_ = blockSize_;
1295 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 1296 Teuchos::TimeMonitor lcltimer( *timerDS_ );
1301 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 1302 Teuchos::TimeMonitor lcltimer( *timerDS_ );
1307 "Anasazi::RTRBase::initialize(): failure solving projected eigenproblem after retraction. LAPACK returns " << ret);
1308 TEUCHOS_TEST_FOR_EXCEPTION(nevLocal_ != blockSize_,
RTRInitFailure,
"Anasazi::RTRBase::initialize(): retracted iterate failed in Ritz analysis.");
1313 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 1314 Teuchos::TimeMonitor lcltimer( *timerSort_ );
1317 std::vector<int> order(blockSize_);
1320 sm_->sort(theta_, Teuchos::rcpFromRef(order), blockSize_);
1328 Teuchos::BLAS<int,ScalarType> blas;
1329 Teuchos::SerialDenseMatrix<int,ScalarType> RR(blockSize_,blockSize_);
1333 info = RR.multiply(Teuchos::NO_TRANS,Teuchos::NO_TRANS,ONE,BB,S,ZERO);
1334 TEUCHOS_TEST_FOR_EXCEPTION(info != 0, std::logic_error,
"Anasazi::RTRBase::initialize(): Logic error calling SerialDenseMatrix::multiply.");
1339 for (
int i=0; i<blockSize_; i++) {
1340 blas.SCAL(blockSize_,theta_[i],RR[i],1);
1342 info = RR.multiply(Teuchos::NO_TRANS,Teuchos::NO_TRANS,ONE,AA,S,-ONE);
1343 TEUCHOS_TEST_FOR_EXCEPTION(info != 0, std::logic_error,
"Anasazi::RTRBase::initialize(): Logic error calling SerialDenseMatrix::multiply.");
1344 for (
int i=0; i<blockSize_; i++) {
1345 ritz2norms_[i] = blas.NRM2(blockSize_,RR[i],1);
1353 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 1354 Teuchos::TimeMonitor lcltimer( *timerLocalUpdate_ );
1374 std::vector<int> ind(blockSize_);
1375 for (
int i=0; i<blockSize_; ++i) ind[i] = numAuxVecs_+i;
1381 this->BX_ = this->X_;
1387 fx_ = std::accumulate(theta_.begin(),theta_.end(),ZERO);
1390 if (newstate.
R != Teuchos::null) {
1392 std::invalid_argument,
"Anasazi::RTRBase::initialize(newstate): newstate.R must have blockSize number of vectors." );
1394 std::invalid_argument,
"Anasazi::RTRBase::initialize(newstate): vector length of newstate.R not correct." );
1398 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 1399 Teuchos::TimeMonitor lcltimer( *timerCompRes_ );
1403 Teuchos::SerialDenseMatrix<int,ScalarType> T(blockSize_,blockSize_);
1405 for (
int i=0; i<blockSize_; i++) T(i,i) = theta_[i];
1410 Rnorms_current_ =
false;
1411 R2norms_current_ =
false;
1416 AX_ = Teuchos::null;
1420 initialized_ =
true;
1422 if (om_->isVerbosity(
Debug ) ) {
1430 om_->print(
Debug, accuracyCheck(chk,
"after initialize()") );
1434 template <
class ScalarType,
class MV,
class OP>
1446 template <
class ScalarType,
class MV,
class OP>
1447 std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>
1449 if (Rnorms_current_ ==
false) {
1451 orthman_->norm(*R_,Rnorms_);
1452 Rnorms_current_ =
true;
1460 template <
class ScalarType,
class MV,
class OP>
1461 std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>
1463 if (R2norms_current_ ==
false) {
1466 R2norms_current_ =
true;
1498 template <
class ScalarType,
class MV,
class OP>
1501 using std::setprecision;
1502 using std::scientific;
1505 std::stringstream os;
1508 os <<
" Debugging checks: " << where << endl;
1511 if (chk.checkX && initialized_) {
1512 tmp = orthman_->orthonormError(*X_);
1513 os <<
" >> Error in X^H B X == I : " << scientific << setprecision(10) << tmp << endl;
1514 for (Array_size_type i=0; i<auxVecs_.size(); i++) {
1515 tmp = orthman_->orthogError(*X_,*auxVecs_[i]);
1516 os <<
" >> Error in X^H B Q[" << i <<
"] == 0 : " << scientific << setprecision(10) << tmp << endl;
1519 if (chk.checkAX && !isSkinny_ && initialized_) {
1521 os <<
" >> Error in AX == A*X : " << scientific << setprecision(10) << tmp << endl;
1523 if (chk.checkBX && hasBOp_ && initialized_) {
1524 Teuchos::RCP<MV> BX =
MVT::Clone(*this->X_,this->blockSize_);
1527 os <<
" >> Error in BX == B*X : " << scientific << setprecision(10) << tmp << endl;
1531 if (chk.checkEta && initialized_) {
1532 tmp = orthman_->orthogError(*X_,*eta_);
1533 os <<
" >> Error in X^H B Eta == 0 : " << scientific << setprecision(10) << tmp << endl;
1534 for (Array_size_type i=0; i<auxVecs_.size(); i++) {
1535 tmp = orthman_->orthogError(*eta_,*auxVecs_[i]);
1536 os <<
" >> Error in Eta^H B Q[" << i <<
"]==0 : " << scientific << setprecision(10) << tmp << endl;
1539 if (chk.checkAEta && !isSkinny_ && initialized_) {
1541 os <<
" >> Error in AEta == A*Eta : " << scientific << setprecision(10) << tmp << endl;
1543 if (chk.checkBEta && !isSkinny_ && hasBOp_ && initialized_) {
1545 os <<
" >> Error in BEta == B*Eta : " << scientific << setprecision(10) << tmp << endl;
1549 if (chk.checkR && initialized_) {
1550 Teuchos::SerialDenseMatrix<int,ScalarType> xTx(blockSize_,blockSize_);
1552 tmp = xTx.normFrobenius();
1553 os <<
" >> Error in X^H R == 0 : " << scientific << setprecision(10) << tmp << endl;
1558 if (chk.checkBR && hasBOp_ && initialized_) {
1559 Teuchos::SerialDenseMatrix<int,ScalarType> xTx(blockSize_,blockSize_);
1561 tmp = xTx.normFrobenius();
1562 os <<
" >> Error in X^H B R == 0 : " << scientific << setprecision(10) << tmp << endl;
1566 if (chk.checkZ && initialized_) {
1567 Teuchos::SerialDenseMatrix<int,ScalarType> xTx(blockSize_,blockSize_);
1569 tmp = xTx.normFrobenius();
1570 os <<
" >> Error in X^H B Z == 0 : " << scientific << setprecision(10) << tmp << endl;
1575 for (Array_size_type i=0; i<auxVecs_.size(); i++) {
1576 tmp = orthman_->orthonormError(*auxVecs_[i]);
1577 os <<
" >> Error in Q[" << i <<
"]^H B Q[" << i <<
"]==I: " << scientific << setprecision(10) << tmp << endl;
1578 for (Array_size_type j=i+1; j<auxVecs_.size(); j++) {
1579 tmp = orthman_->orthogError(*auxVecs_[i],*auxVecs_[j]);
1580 os <<
" >> Error in Q[" << i <<
"]^H B Q[" << j <<
"]==0: " << scientific << setprecision(10) << tmp << endl;
1591 template <
class ScalarType,
class MV,
class OP>
1595 using std::setprecision;
1596 using std::scientific;
1601 os <<
"================================================================================" << endl;
1603 os <<
" RTRBase Solver Status" << endl;
1605 os <<
"The solver is "<<(initialized_ ?
"initialized." :
"not initialized.") << endl;
1606 os <<
"The number of iterations performed is " << iter_ << endl;
1607 os <<
"The current block size is " << blockSize_ << endl;
1608 os <<
"The number of auxiliary vectors is " << numAuxVecs_ << endl;
1609 os <<
"The number of operations A*x is " << counterAOp_ << endl;
1610 os <<
"The number of operations B*x is " << counterBOp_ << endl;
1611 os <<
"The number of operations Prec*x is " << counterPrec_ << endl;
1612 os <<
"The most recent rho was " << scientific << setprecision(10) << rho_ << endl;
1613 os <<
"The current value of f(x) is " << scientific << setprecision(10) << fx_ << endl;
1617 os <<
"CURRENT EIGENVALUE ESTIMATES "<<endl;
1618 os << setw(20) <<
"Eigenvalue" 1619 << setw(20) <<
"Residual(B)" 1620 << setw(20) <<
"Residual(2)" 1622 os <<
"--------------------------------------------------------------------------------"<<endl;
1623 for (
int i=0; i<blockSize_; i++) {
1624 os << scientific << setprecision(10) << setw(20) << theta_[i];
1625 if (Rnorms_current_) os << scientific << setprecision(10) << setw(20) << Rnorms_[i];
1626 else os << scientific << setprecision(10) << setw(20) <<
"not current";
1627 if (R2norms_current_) os << scientific << setprecision(10) << setw(20) << R2norms_[i];
1628 else os << scientific << setprecision(10) << setw(20) <<
"not current";
1632 os <<
"================================================================================" << endl;
1639 template <
class ScalarType,
class MV,
class OP>
1640 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
1645 MagnitudeType ret = 0;
1646 for (vecMTiter i=d.begin(); i != d.end(); ++i) {
1655 template <
class ScalarType,
class MV,
class OP>
1656 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
1661 return SCT::real(std::accumulate(d.begin(),d.end(),SCT::zero()));
1667 template <
class ScalarType,
class MV,
class OP>
1670 std::vector<
typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> &d)
const 1673 for (vecMTiter i=d.begin(); i != d.end(); ++i) {
1681 template <
class ScalarType,
class MV,
class OP>
1683 const MV &xi,
const MV &zeta,
1684 std::vector<
typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> &d)
const 1688 vecMTiter iR=d.begin();
1689 vecSTiter iS=dC.begin();
1690 for (; iR != d.end(); iR++, iS++) {
1691 (*iR) = SCT::real(*iS);
1695 template <
class ScalarType,
class MV,
class OP>
1700 template <
class ScalarType,
class MV,
class OP>
1705 template <
class ScalarType,
class MV,
class OP>
1710 template <
class ScalarType,
class MV,
class OP>
1715 template <
class ScalarType,
class MV,
class OP>
1718 if (!initialized_)
return 0;
1722 template <
class ScalarType,
class MV,
class OP>
1723 std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>
1726 std::vector<MagnitudeType> ret = ritz2norms_;
1727 ret.resize(nevLocal_);
1731 template <
class ScalarType,
class MV,
class OP>
1732 std::vector<Value<ScalarType> >
1735 std::vector<Value<ScalarType> > ret(nevLocal_);
1736 for (
int i=0; i<nevLocal_; i++) {
1737 ret[i].realpart = theta_[i];
1738 ret[i].imagpart = ZERO;
1743 template <
class ScalarType,
class MV,
class OP>
1744 Teuchos::RCP<const MV>
1750 template <
class ScalarType,
class MV,
class OP>
1756 template <
class ScalarType,
class MV,
class OP>
1762 template <
class ScalarType,
class MV,
class OP>
1772 state.
BX = Teuchos::null;
1776 state.
T = Teuchos::rcp(
new std::vector<MagnitudeType>(theta_));
1780 template <
class ScalarType,
class MV,
class OP>
1783 return initialized_;
1786 template <
class ScalarType,
class MV,
class OP>
1789 std::vector<int> ret(nevLocal_,0);
1796 #endif // ANASAZI_RTRBASE_HPP RTROrthoFailure is thrown when an orthogonalization attempt fails.
static ptrdiff_t GetGlobalLength(const MV &mv)
Return the number of rows in the given multivector mv.
void resetNumIters()
Reset the iteration count.
static void MvRandom(MV &mv)
Replace the vectors in mv with random vectors.
std::vector< Value< ScalarType > > getRitzValues()
Get the Ritz values from the previous iteration.
static void MvTimesMatAddMv(const ScalarType alpha, const MV &A, const Teuchos::SerialDenseMatrix< int, ScalarType > &B, const ScalarType beta, MV &mv)
Update mv with .
Structure to contain pointers to RTR state variables.
virtual void currentStatus(std::ostream &os)
This method requests that the solver print out its current status to screen.
Teuchos::RCP< const MV > AX
The image of the current eigenvectors under A, or Teuchos::null is we implement a skinny solver...
This class defines the interface required by an eigensolver and status test class to compute solution...
Teuchos::RCP< const MV > BX
The image of the current eigenvectors under B, or Teuchos::null if B was not specified.
Declaration of basic traits for the multivector type.
const Eigenproblem< ScalarType, MV, OP > & getProblem() const
Get a constant reference to the eigenvalue problem.
Teuchos::RCP< const MV > getRitzVectors()
Get the Ritz vectors from the previous iteration.
std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > getRitzRes2Norms()
Get the 2-norms of the Ritz residuals.
RTRState< ScalarType, MV > getState() const
Get the current state of the eigensolver.
This class is an abstract base class for Implicit Riemannian Trust-Region based eigensolvers. The class provides the interfaces shared by the IRTR solvers (e.g., getState() and initialize()) as well as the shared implementations (e.g., inner products).
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.
Templated virtual class for providing orthogonalization/orthonormalization methods with matrix-based ...
static void MvDot(const MV &mv, const MV &A, std::vector< ScalarType > &b)
Compute a vector b where the components are the individual dot-products of the i-th columns of A and ...
int getMaxSubspaceDim() const
Get the maximum dimension allocated for the search subspace. For RTR, this always returns getBlockSiz...
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...
Teuchos::RCP< const MV > X
The current eigenvectors.
An exception class parent to all Anasazi exceptions.
void setStatusTest(Teuchos::RCP< StatusTest< ScalarType, MV, OP > > test)
Set a new StatusTest for the solver.
bool isInitialized() const
Indicates whether the solver has been initialized or not.
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...
virtual ~RTRBase()
RTRBase destructor
Anasazi's templated, static class providing utilities for the solvers.
Output managers remove the need for the eigensolver to know any information about the required output...
Teuchos::RCP< StatusTest< ScalarType, MV, OP > > getStatusTest() const
Get the current StatusTest used by the solver.
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...
void setBlockSize(int blockSize)
Set the blocksize to be used by the iterative solver in solving this eigenproblem.
std::vector< int > getRitzIndex()
Get the index used for extracting Ritz vectors from getRitzVectors().
Teuchos::Array< Teuchos::RCP< const MV > > getAuxVecs() const
Get the current auxiliary vectors.
int getBlockSize() const
Get the blocksize to be used by the iterative solver in solving this eigenproblem.
Traits class which defines basic operations on multivectors.
static Teuchos::RCP< MV > CloneCopy(const MV &mv)
Creates a new MV and copies contents of mv into the new vector (deep copy).
static void MvTransMv(const ScalarType alpha, const MV &A, const MV &B, Teuchos::SerialDenseMatrix< int, ScalarType > &C)
Compute C := alpha * A^H B.
Virtual base class which defines basic traits for the operator type.
int getNumIters() const
Get the current iteration count.
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).
RTRInitFailure is thrown when the RTR solver is unable to generate an initial iterate in the RTRBase:...
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...
Teuchos::ScalarTraits< ScalarType >::magnitudeType rho
The current rho value. This is only valid if the debugging level of verbosity is enabled.
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 .
std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > getResNorms()
Get the current residual norms.
Teuchos::RCP< const std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > > T
The current Ritz values.
Teuchos::RCP< const MV > R
The current residual vectors.
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...
void setAuxVecs(const Teuchos::Array< Teuchos::RCP< const MV > > &auxvecs)
Set the auxiliary vectors for the solver.
int getCurSubspaceDim() const
Get the dimension of the search subspace used to generate the current eigenvectors and eigenvalues...
Types and exceptions used within Anasazi solvers and interfaces.
void initialize()
Initialize the solver with the initial vectors from the eigenproblem or random data.
Anasazi's templated pure virtual class for managing the sorting of approximate eigenvalues computed b...
Common interface of stopping criteria for Anasazi's solvers.
RTRRitzFailure is thrown when the RTR solver is unable to continue a call to RTRBase::iterate() due t...
The Eigensolver is a templated virtual base class that defines the basic interface that any eigensolv...
RTRBase(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< GenOrthoManager< ScalarType, MV, OP > > &ortho, Teuchos::ParameterList ¶ms, const std::string &solverLabel, bool skinnySolver)
RTRBase constructor with eigenproblem, solver utilities, and parameter list of solver options...
static Teuchos::RCP< MV > Clone(const MV &mv, const int numvecs)
Creates a new empty MV containing numvecs columns.
Class which provides internal utilities for the Anasazi solvers.