42 #ifndef BELOS_PCPG_SOLMGR_HPP 43 #define BELOS_PCPG_SOLMGR_HPP 64 #include "Teuchos_BLAS.hpp" 65 #include "Teuchos_LAPACK.hpp" 66 #ifdef BELOS_TEUCHOS_TIME_MONITOR 67 # include "Teuchos_TimeMonitor.hpp" 69 #if defined(HAVE_TEUCHOSCORE_CXX11) 70 # include <type_traits> 71 #endif // defined(HAVE_TEUCHOSCORE_CXX11) 72 #include "Teuchos_TypeTraits.hpp" 151 template<
class ScalarType,
class MV,
class OP,
152 const bool supportsScalarType =
154 ! Teuchos::ScalarTraits<ScalarType>::isComplex>
157 Belos::Details::LapackSupportsScalar<ScalarType>::value &&
158 ! Teuchos::ScalarTraits<ScalarType>::isComplex>
160 static const bool scalarTypeIsSupported =
162 ! Teuchos::ScalarTraits<ScalarType>::isComplex;
171 const Teuchos::RCP<Teuchos::ParameterList> &pl) :
177 template<
class ScalarType,
class MV,
class OP>
183 typedef Teuchos::ScalarTraits<ScalarType> SCT;
184 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
185 typedef Teuchos::ScalarTraits<MagnitudeType> MT;
235 const Teuchos::RCP<Teuchos::ParameterList> &pl );
252 Teuchos::RCP<const Teuchos::ParameterList> getValidParameters()
const;
263 Teuchos::Array<Teuchos::RCP<Teuchos::Time> >
getTimers()
const {
264 return Teuchos::tuple(timerSolve_);
294 void setParameters(
const Teuchos::RCP<Teuchos::ParameterList> ¶ms );
335 std::string description()
const;
343 int ARRQR(
int numVecs,
int numOrthVecs,
const Teuchos::SerialDenseMatrix<int,ScalarType>& D);
346 Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > problem_;
349 Teuchos::RCP<OutputManager<ScalarType> > printer_;
350 Teuchos::RCP<std::ostream> outputStream_;
353 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > sTest_;
354 Teuchos::RCP<StatusTestMaxIters<ScalarType,MV,OP> > maxIterTest_;
355 Teuchos::RCP<StatusTestGenResNorm<ScalarType,MV,OP> > convTest_;
356 Teuchos::RCP<StatusTestOutput<ScalarType,MV,OP> > outputTest_;
359 Teuchos::RCP<MatOrthoManager<ScalarType,MV,OP> > ortho_;
362 Teuchos::RCP<Teuchos::ParameterList> params_;
365 static const MagnitudeType convtol_default_;
366 static const MagnitudeType orthoKappa_default_;
367 static const int maxIters_default_;
368 static const int deflatedBlocks_default_;
369 static const int savedBlocks_default_;
370 static const int verbosity_default_;
371 static const int outputStyle_default_;
372 static const int outputFreq_default_;
373 static const std::string label_default_;
374 static const std::string orthoType_default_;
375 static const Teuchos::RCP<std::ostream> outputStream_default_;
382 MagnitudeType convtol_;
385 MagnitudeType orthoKappa_;
388 MagnitudeType achievedTol_;
396 int deflatedBlocks_, savedBlocks_, verbosity_, outputStyle_, outputFreq_;
397 std::string orthoType_;
400 Teuchos::RCP<MV> U_, C_, R_;
407 Teuchos::RCP<Teuchos::Time> timerSolve_;
415 template<
class ScalarType,
class MV,
class OP>
419 template<
class ScalarType,
class MV,
class OP>
423 template<
class ScalarType,
class MV,
class OP>
426 template<
class ScalarType,
class MV,
class OP>
429 template<
class ScalarType,
class MV,
class OP>
432 template<
class ScalarType,
class MV,
class OP>
435 template<
class ScalarType,
class MV,
class OP>
438 template<
class ScalarType,
class MV,
class OP>
441 template<
class ScalarType,
class MV,
class OP>
444 template<
class ScalarType,
class MV,
class OP>
447 template<
class ScalarType,
class MV,
class OP>
452 template<
class ScalarType,
class MV,
class OP>
454 outputStream_(outputStream_default_),
455 convtol_(convtol_default_),
456 orthoKappa_(orthoKappa_default_),
457 achievedTol_(Teuchos::ScalarTraits<MagnitudeType>::zero()),
459 maxIters_(maxIters_default_),
460 deflatedBlocks_(deflatedBlocks_default_),
461 savedBlocks_(savedBlocks_default_),
462 verbosity_(verbosity_default_),
463 outputStyle_(outputStyle_default_),
464 outputFreq_(outputFreq_default_),
465 orthoType_(orthoType_default_),
467 label_(label_default_),
473 template<
class ScalarType,
class MV,
class OP>
476 const Teuchos::RCP<Teuchos::ParameterList> &pl ) :
478 outputStream_(outputStream_default_),
479 convtol_(convtol_default_),
480 orthoKappa_(orthoKappa_default_),
481 achievedTol_(Teuchos::ScalarTraits<MagnitudeType>::zero()),
483 maxIters_(maxIters_default_),
484 deflatedBlocks_(deflatedBlocks_default_),
485 savedBlocks_(savedBlocks_default_),
486 verbosity_(verbosity_default_),
487 outputStyle_(outputStyle_default_),
488 outputFreq_(outputFreq_default_),
489 orthoType_(orthoType_default_),
491 label_(label_default_),
494 TEUCHOS_TEST_FOR_EXCEPTION(
495 problem_.is_null (), std::invalid_argument,
496 "Belos::PCPGSolMgr two-argument constructor: " 497 "'problem' is null. You must supply a non-null Belos::LinearProblem " 498 "instance when calling this constructor.");
500 if (! pl.is_null ()) {
507 template<
class ScalarType,
class MV,
class OP>
511 if (params_ == Teuchos::null) {
512 params_ = Teuchos::rcp(
new Teuchos::ParameterList(*getValidParameters()) );
515 params->validateParameters(*getValidParameters());
519 if (params->isParameter(
"Maximum Iterations")) {
520 maxIters_ = params->get(
"Maximum Iterations",maxIters_default_);
523 params_->set(
"Maximum Iterations", maxIters_);
524 if (maxIterTest_!=Teuchos::null)
525 maxIterTest_->setMaxIters( maxIters_ );
529 if (params->isParameter(
"Num Saved Blocks")) {
530 savedBlocks_ = params->get(
"Num Saved Blocks",savedBlocks_default_);
531 TEUCHOS_TEST_FOR_EXCEPTION(savedBlocks_ <= 0, std::invalid_argument,
532 "Belos::PCPGSolMgr: \"Num Saved Blocks\" must be strictly positive.");
539 params_->set(
"Num Saved Blocks", savedBlocks_);
541 if (params->isParameter(
"Num Deflated Blocks")) {
542 deflatedBlocks_ = params->get(
"Num Deflated Blocks",deflatedBlocks_default_);
543 TEUCHOS_TEST_FOR_EXCEPTION(deflatedBlocks_ < 0, std::invalid_argument,
544 "Belos::PCPGSolMgr: \"Num Deflated Blocks\" must be positive.");
546 TEUCHOS_TEST_FOR_EXCEPTION(deflatedBlocks_ > savedBlocks_, std::invalid_argument,
547 "Belos::PCPGSolMgr: \"Num Deflated Blocks\" must be <= \"Num Saved Blocks\".");
550 params_->set(
"Num Deflated Blocks", deflatedBlocks_);
554 if (params->isParameter(
"Timer Label")) {
555 std::string tempLabel = params->get(
"Timer Label", label_default_);
558 if (tempLabel != label_) {
560 params_->set(
"Timer Label", label_);
561 std::string solveLabel = label_ +
": PCPGSolMgr total solve time";
562 #ifdef BELOS_TEUCHOS_TIME_MONITOR 563 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
565 if (ortho_ != Teuchos::null) {
566 ortho_->setLabel( label_ );
572 if (params->isParameter(
"Orthogonalization")) {
573 std::string tempOrthoType = params->get(
"Orthogonalization",orthoType_default_);
574 TEUCHOS_TEST_FOR_EXCEPTION( tempOrthoType !=
"DGKS" && tempOrthoType !=
"ICGS" && tempOrthoType !=
"IMGS",
575 std::invalid_argument,
576 "Belos::PCPGSolMgr: \"Orthogonalization\" must be either \"DGKS\", \"ICGS\", or \"IMGS\".");
577 if (tempOrthoType != orthoType_) {
578 orthoType_ = tempOrthoType;
579 params_->set(
"Orthogonalization", orthoType_);
581 if (orthoType_==
"DGKS") {
582 if (orthoKappa_ <= 0) {
590 else if (orthoType_==
"ICGS") {
593 else if (orthoType_==
"IMGS") {
600 if (params->isParameter(
"Orthogonalization Constant")) {
601 orthoKappa_ = params->get(
"Orthogonalization Constant",orthoKappa_default_);
604 params_->set(
"Orthogonalization Constant",orthoKappa_);
605 if (orthoType_==
"DGKS") {
606 if (orthoKappa_ > 0 && ortho_ != Teuchos::null) {
613 if (params->isParameter(
"Verbosity")) {
614 if (Teuchos::isParameterType<int>(*params,
"Verbosity")) {
615 verbosity_ = params->get(
"Verbosity", verbosity_default_);
617 verbosity_ = (int)Teuchos::getParameter<Belos::MsgType>(*params,
"Verbosity");
621 params_->set(
"Verbosity", verbosity_);
622 if (printer_ != Teuchos::null)
623 printer_->setVerbosity(verbosity_);
627 if (params->isParameter(
"Output Style")) {
628 if (Teuchos::isParameterType<int>(*params,
"Output Style")) {
629 outputStyle_ = params->get(
"Output Style", outputStyle_default_);
631 outputStyle_ = (int)Teuchos::getParameter<Belos::OutputType>(*params,
"Output Style");
635 params_->set(
"Output Style", outputStyle_);
636 outputTest_ = Teuchos::null;
640 if (params->isParameter(
"Output Stream")) {
641 outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params,
"Output Stream");
644 params_->set(
"Output Stream", outputStream_);
645 if (printer_ != Teuchos::null)
646 printer_->setOStream( outputStream_ );
651 if (params->isParameter(
"Output Frequency")) {
652 outputFreq_ = params->get(
"Output Frequency", outputFreq_default_);
656 params_->set(
"Output Frequency", outputFreq_);
657 if (outputTest_ != Teuchos::null)
658 outputTest_->setOutputFrequency( outputFreq_ );
662 if (printer_ == Teuchos::null) {
671 if (params->isParameter(
"Convergence Tolerance")) {
672 convtol_ = params->get(
"Convergence Tolerance",convtol_default_);
675 params_->set(
"Convergence Tolerance", convtol_);
676 if (convTest_ != Teuchos::null)
683 if (maxIterTest_ == Teuchos::null)
686 if (convTest_ == Teuchos::null)
687 convTest_ = Teuchos::rcp(
new StatusTestResNorm_t( convtol_, 1 ) );
689 sTest_ = Teuchos::rcp(
new StatusTestCombo_t( StatusTestCombo_t::OR, maxIterTest_, convTest_ ) );
697 std::string solverDesc =
" PCPG ";
698 outputTest_->setSolverDesc( solverDesc );
702 if (ortho_ == Teuchos::null) {
703 params_->set(
"Orthogonalization", orthoType_);
704 if (orthoType_==
"DGKS") {
705 if (orthoKappa_ <= 0) {
713 else if (orthoType_==
"ICGS") {
716 else if (orthoType_==
"IMGS") {
720 TEUCHOS_TEST_FOR_EXCEPTION(orthoType_!=
"ICGS"&&orthoType_!=
"DGKS"&&orthoType_!=
"IMGS",std::logic_error,
721 "Belos::PCPGSolMgr(): Invalid orthogonalization type.");
726 if (timerSolve_ == Teuchos::null) {
727 std::string solveLabel = label_ +
": PCPGSolMgr total solve time";
728 #ifdef BELOS_TEUCHOS_TIME_MONITOR 729 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
738 template<
class ScalarType,
class MV,
class OP>
739 Teuchos::RCP<const Teuchos::ParameterList>
742 static Teuchos::RCP<const Teuchos::ParameterList> validPL;
743 if (is_null(validPL)) {
744 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
746 pl->set(
"Convergence Tolerance", convtol_default_,
747 "The relative residual tolerance that needs to be achieved by the\n" 748 "iterative solver in order for the linear system to be declared converged.");
749 pl->set(
"Maximum Iterations", maxIters_default_,
750 "The maximum number of iterations allowed for each\n" 751 "set of RHS solved.");
752 pl->set(
"Num Deflated Blocks", deflatedBlocks_default_,
753 "The maximum number of vectors in the seed subspace." );
754 pl->set(
"Num Saved Blocks", savedBlocks_default_,
755 "The maximum number of vectors saved from old Krylov subspaces." );
756 pl->set(
"Verbosity", verbosity_default_,
757 "What type(s) of solver information should be outputted\n" 758 "to the output stream.");
759 pl->set(
"Output Style", outputStyle_default_,
760 "What style is used for the solver information outputted\n" 761 "to the output stream.");
762 pl->set(
"Output Frequency", outputFreq_default_,
763 "How often convergence information should be outputted\n" 764 "to the output stream.");
765 pl->set(
"Output Stream", outputStream_default_,
766 "A reference-counted pointer to the output stream where all\n" 767 "solver output is sent.");
768 pl->set(
"Timer Label", label_default_,
769 "The string to use as a prefix for the timer labels.");
770 pl->set(
"Orthogonalization", orthoType_default_,
771 "The type of orthogonalization to use: DGKS, ICGS, IMGS");
772 pl->set(
"Orthogonalization Constant",orthoKappa_default_,
773 "The constant used by DGKS orthogonalization to determine\n" 774 "whether another step of classical Gram-Schmidt is necessary.");
782 template<
class ScalarType,
class MV,
class OP>
786 if (!isSet_) { setParameters( params_ ); }
788 Teuchos::BLAS<int,ScalarType> blas;
789 Teuchos::LAPACK<int,ScalarType> lapack;
790 ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
791 ScalarType zero = Teuchos::ScalarTraits<ScalarType>::zero();
794 "Belos::PCPGSolMgr::solve(): Linear problem is not a valid object.");
797 "Belos::PCPGSolMgr::solve(): Linear problem is not ready, setProblem() has not been called.");
800 int numRHS2Solve = MVT::GetNumberVecs( *(problem_->getRHS()) );
801 std::vector<int> currIdx(1);
807 problem_->setLSIndex( currIdx );
810 bool isConverged =
true;
814 Teuchos::ParameterList plist;
815 plist.set(
"Saved Blocks", savedBlocks_);
816 plist.set(
"Block Size", 1);
817 plist.set(
"Keep Diagonal",
true);
818 plist.set(
"Initialize Diagonal",
true);
823 Teuchos::RCP<PCPGIter<ScalarType,MV,OP> > pcpg_iter;
829 #ifdef BELOS_TEUCHOS_TIME_MONITOR 830 Teuchos::TimeMonitor slvtimer(*timerSolve_);
832 while ( numRHS2Solve > 0 ) {
835 outputTest_->reset();
838 if (R_ == Teuchos::null)
839 R_ = MVT::Clone( *(problem_->getRHS()), 1 );
841 problem_->computeCurrResVec( &*R_ );
847 if( U_ != Teuchos::null ){
852 Teuchos::RCP<MV> cur_soln_vec = problem_->getCurrLHSVec();
853 std::vector<MagnitudeType> rnorm0(1);
854 MVT::MvNorm( *R_, rnorm0 );
857 std::cout <<
"Solver Manager: dimU_ = " << dimU_ << std::endl;
858 Teuchos::SerialDenseMatrix<int,ScalarType> Z( dimU_, 1 );
860 Teuchos::RCP<const MV> Uactive, Cactive;
861 std::vector<int> active_columns( dimU_ );
862 for (
int i=0; i < dimU_; ++i) active_columns[i] = i;
863 Uactive = MVT::CloneView(*U_, active_columns);
864 Cactive = MVT::CloneView(*C_, active_columns);
867 std::cout <<
" Solver Manager : check duality of seed basis " << std::endl;
868 Teuchos::SerialDenseMatrix<int,ScalarType> H( dimU_, dimU_ );
869 MVT::MvTransMv( one, *Uactive, *Cactive, H );
870 H.print( std::cout );
873 MVT::MvTransMv( one, *Uactive, *R_, Z );
874 Teuchos::RCP<MV> tempU = MVT::Clone( *R_, 1 );
875 MVT::MvTimesMatAddMv( one, *Uactive, Z, zero, *tempU );
876 MVT::MvAddMv( one, *tempU, one, *cur_soln_vec, *cur_soln_vec );
877 MVT::MvTimesMatAddMv( one, *Cactive, Z, zero, *tempU );
878 MVT::MvAddMv( -one, *tempU, one, *R_, *R_ );
879 std::vector<MagnitudeType> rnorm(1);
880 MVT::MvNorm( *R_, rnorm );
881 if( rnorm[0] < rnorm0[0] * .001 ){
882 MVT::MvTransMv( one, *Uactive, *R_, Z );
883 MVT::MvTimesMatAddMv( one, *Uactive, Z, zero, *tempU );
884 MVT::MvAddMv( one, *tempU, one, *cur_soln_vec, *cur_soln_vec );
885 MVT::MvTimesMatAddMv( one, *Cactive, Z, zero, *tempU );
886 MVT::MvAddMv( -one, *tempU, one, *R_, *R_ );
888 Uactive = Teuchos::null;
889 Cactive = Teuchos::null;
890 tempU = Teuchos::null;
901 if( U_ != Teuchos::null ) pcpgState.
U = U_;
902 if( C_ != Teuchos::null ) pcpgState.
C = C_;
903 if( dimU_ > 0 ) pcpgState.
curDim = dimU_;
904 pcpg_iter->initialize(pcpgState);
910 if( !dimU_ ) printer_->stream(
Debug) <<
" No recycled subspace available for RHS index " << currIdx[0] << std::endl << std::endl;
911 pcpg_iter->resetNumIters();
913 if( dimU_ > savedBlocks_ )
914 std::cout <<
"Error: dimU_ = " << dimU_ <<
" > savedBlocks_ = " << savedBlocks_ << std::endl;
920 if( debug ) printf(
"********** Calling iterate...\n");
921 pcpg_iter->iterate();
928 if ( convTest_->getStatus() ==
Passed ) {
937 else if ( maxIterTest_->getStatus() ==
Passed ) {
951 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
952 "Belos::PCPGSolMgr::solve(): Invalid return from PCPGIter::iterate().");
958 sTest_->checkStatus( &*pcpg_iter );
959 if (convTest_->getStatus() !=
Passed)
963 catch (
const std::exception &e) {
964 printer_->stream(
Errors) <<
"Error! Caught exception in PCPGIter::iterate() at iteration " 965 << pcpg_iter->getNumIters() << std::endl
966 << e.what() << std::endl;
972 Teuchos::RCP<MV> update = pcpg_iter->getCurrentUpdate();
973 problem_->updateSolution( update,
true );
976 problem_->setCurrLS();
984 std::cout <<
"SolverManager: dimU_ " << dimU_ <<
" prevUdim= " << q << std::endl;
986 if( q > deflatedBlocks_ )
987 std::cout <<
"SolverManager: Error deflatedBlocks = " << deflatedBlocks_ << std::endl;
998 rank = ARRQR(dimU_,q, *oldState.
D );
1000 std::cout <<
" rank decreased in ARRQR, something to do? " << std::endl;
1006 if( dimU_ > deflatedBlocks_ ){
1008 if( !deflatedBlocks_ ){
1011 dimU_ = deflatedBlocks_;
1015 bool Harmonic =
false;
1017 Teuchos::RCP<MV> Uorth;
1019 std::vector<int> active_cols( dimU_ );
1020 for (
int i=0; i < dimU_; ++i) active_cols[i] = i;
1023 Uorth = MVT::CloneCopy(*C_, active_cols);
1026 Uorth = MVT::CloneCopy(*U_, active_cols);
1030 Teuchos::SerialDenseMatrix<int,ScalarType> R(dimU_,dimU_);
1031 rank = ortho_->normalize(*Uorth, Teuchos::rcp(&R,
false));
1032 Uorth = Teuchos::null;
1038 "Belos::PCPGSolMgr::solve(): Failed to compute orthonormal basis for initial recycled subspace.");
1042 Teuchos::SerialDenseMatrix<int,ScalarType> VT;
1043 Teuchos::SerialDenseMatrix<int,ScalarType> Ur;
1044 int lwork = 5*dimU_;
1047 if( problem_->isHermitian() ) lrwork = dimU_;
1048 std::vector<ScalarType> work(lwork);
1049 std::vector<ScalarType> Svec(dimU_);
1050 std::vector<ScalarType> rwork(lrwork);
1051 lapack.GESVD(
'N',
'O',
1052 R.numRows(),R.numCols(),R.values(), R.numRows(),
1060 "Belos::PCPGSolMgr::solve(): LAPACK _GESVD failed to compute singular values.");
1062 if( work[0] != 67. * dimU_ )
1063 std::cout <<
" SVD " << dimU_ <<
" lwork " << work[0] << std::endl;
1064 for(
int i=0; i< dimU_; i++)
1065 std::cout << i <<
" " << Svec[i] << std::endl;
1067 Teuchos::SerialDenseMatrix<int,ScalarType> wholeV( R,
Teuchos::TRANS);
1069 int startRow = 0, startCol = 0;
1071 startCol = dimU_ - deflatedBlocks_;
1073 Teuchos::SerialDenseMatrix<int,ScalarType> V(Teuchos::Copy,
1079 std::vector<int> active_columns( dimU_ );
1080 std::vector<int> def_cols( deflatedBlocks_ );
1081 for (
int i=0; i < dimU_; ++i) active_columns[i] = i;
1082 for (
int i=0; i < deflatedBlocks_; ++i) def_cols[i] = i;
1084 Teuchos::RCP<MV> Uactive = MVT::CloneViewNonConst(*U_, def_cols);
1085 Teuchos::RCP<MV> Ucopy = MVT::CloneCopy( *U_, active_columns );
1086 MVT::MvTimesMatAddMv( one, *Ucopy, V, zero, *Uactive );
1087 Ucopy = Teuchos::null;
1088 Uactive = Teuchos::null;
1089 Teuchos::RCP<MV> Cactive = MVT::CloneViewNonConst(*C_, def_cols);
1090 Teuchos::RCP<MV> Ccopy = MVT::CloneCopy( *C_, active_columns );
1091 MVT::MvTimesMatAddMv( one, *Ccopy, V, zero, *Cactive );
1092 Ccopy = Teuchos::null;
1093 Cactive = Teuchos::null;
1094 dimU_ = deflatedBlocks_;
1096 printer_->stream(
Debug) <<
" Generated recycled subspace using RHS index " << currIdx[0] <<
" of dimension " << dimU_ << std::endl << std::endl;
1099 problem_->setCurrLS();
1103 if ( numRHS2Solve > 0 ) {
1107 problem_->setLSIndex( currIdx );
1110 currIdx.resize( numRHS2Solve );
1119 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1124 Teuchos::TimeMonitor::summarize( printer_->stream(TimingDetails) );
1129 using Teuchos::rcp_dynamic_cast;
1132 const std::vector<MagnitudeType>* pTestValues =
1133 rcp_dynamic_cast<conv_test_type>(convTest_)->getTestValue();
1135 TEUCHOS_TEST_FOR_EXCEPTION(pTestValues == NULL, std::logic_error,
1136 "Belos::PCPGSolMgr::solve(): The convergence test's getTestValue() " 1137 "method returned NULL. Please report this bug to the Belos developers.");
1139 TEUCHOS_TEST_FOR_EXCEPTION(pTestValues->size() < 1, std::logic_error,
1140 "Belos::PCPGSolMgr::solve(): The convergence test's getTestValue() " 1141 "method returned a vector of length zero. Please report this bug to the " 1142 "Belos developers.");
1147 achievedTol_ = *std::max_element (pTestValues->begin(), pTestValues->end());
1151 numIters_ = maxIterTest_->getNumIters();
1162 template<
class ScalarType,
class MV,
class OP>
1166 ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
1167 ScalarType zero = Teuchos::ScalarTraits<ScalarType>::zero();
1170 Teuchos::SerialDenseMatrix<int,ScalarType> alpha( 1, 1 );
1171 Teuchos::SerialDenseMatrix<int,ScalarType> gamma( 1, 1 );
1172 Teuchos::SerialDenseMatrix<int,ScalarType> anorm( 1, 1 );
1173 std::vector<int> curind(1);
1174 std::vector<int> ipiv(p - q);
1175 std::vector<ScalarType> Pivots(p);
1177 ScalarType rteps = 1.5e-8;
1180 for( i = q ; i < p ; i++ ){
1183 RCP<MV> P = MVT::CloneViewNonConst(*U_,curind);
1184 RCP<MV> AP = MVT::CloneViewNonConst(*C_,curind);
1185 anorm(0,0) = one / Teuchos::ScalarTraits<ScalarType>::squareroot( D(i-q,i-q) ) ;
1186 MVT::MvAddMv( anorm(0,0), *P, zero, *AP, *P );
1187 MVT::MvAddMv( zero, *P, anorm(0,0), *AP, *AP );
1191 for( i = q ; i < p ; i++ ){
1192 if( q < i && i < p-1 ){
1195 for( j = i+1 ; j < p ; j++ ){
1196 const int k = ipiv[j-q];
1197 if( Pivots[k] > Pivots[l] ){
1204 ipiv[imax-q] = ipiv[i-q];
1210 if( Pivots[k] > 1.5625e-2 ){
1211 anorm(0,0) = Pivots[k];
1215 RCP<const MV> P = MVT::CloneView(*U_,curind);
1216 RCP<const MV> AP = MVT::CloneView(*C_,curind);
1217 MVT::MvTransMv( one, *P, *AP, anorm );
1218 anorm(0,0) = Teuchos::ScalarTraits<ScalarType>::squareroot( anorm(0,0) ) ;
1220 if( rteps <= anorm(0,0) && anorm(0,0) < 9.765625e-4){
1228 std::cout <<
"ARRQR: Bad case not implemented" << std::endl;
1230 if( anorm(0,0) < rteps ){
1231 std::cout <<
"ARRQR : deficient case not implemented " << std::endl;
1239 RCP<MV> P = MVT::CloneViewNonConst(*U_,curind);
1240 RCP<MV> AP = MVT::CloneViewNonConst(*C_,curind);
1241 MVT::MvAddMv( anorm(0,0), *P, zero, *AP, *P );
1242 MVT::MvAddMv( zero, *P, anorm(0,0), *AP, *AP );
1246 P = MVT::CloneViewNonConst(*U_,curind);
1247 AP = MVT::CloneViewNonConst(*C_,curind);
1248 for( j = i+1 ; j < p ; j++ ){
1251 RCP<MV> Q = MVT::CloneViewNonConst(*U_,curind);
1252 MVT::MvTransMv( one, *Q, *AP, alpha);
1253 MVT::MvAddMv( -alpha(0,0), *P, one, *Q, *Q );
1255 RCP<MV> AQ = MVT::CloneViewNonConst(*C_,curind);
1256 MVT::MvAddMv( -alpha(0,0), *AP, one, *AQ, *AQ );
1258 gamma(0,0) = ( Pivots[l] - alpha(0,0))*( Pivots[l] + alpha(0,0));
1259 if( gamma(0,0) > 0){
1260 Pivots[l] = Teuchos::ScalarTraits<ScalarType>::squareroot( gamma(0,0) );
1271 template<
class ScalarType,
class MV,
class OP>
1274 std::ostringstream oss;
1275 oss <<
"Belos::PCPGSolMgr<...,"<<Teuchos::ScalarTraits<ScalarType>::name()<<
">";
1277 oss <<
"Ortho Type='"<<orthoType_;
bool isLOADetected() const
Return whether a loss of accuracy was detected by this solver during the most current solve...
Collection of types and exceptions used within the Belos solvers.
int prevUdim
Number of block columns in matrices C and U before current iteration.
Belos's basic output manager for sending information of select verbosity levels to the appropriate ou...
PCPGSolMgr(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem, const Teuchos::RCP< Teuchos::ParameterList > &pl)
Class which manages the output and verbosity of the Belos solvers.
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers for this object.
Belos concrete class to iterate Preconditioned Conjugate Projected Gradients.
PCPGSolMgrOrthoFailure is thrown when the orthogonalization manager is unable to generate orthonormal...
Teuchos::RCP< MV > R
The current residual.
const LinearProblem< ScalarType, MV, OP > & getProblem() const
Get current linear problem being solved for in this object.
Teuchos::RCP< MV > C
C = AU, U spans recycled subspace.
Base class for Belos::SolverManager subclasses which normally can only compile with real ScalarType t...
PCPGSolMgrRecyclingFailure is thrown when any problem occurs in using/creating the recycling subspace...
A factory class for generating StatusTestOutput objects.
int curDim
The current dimension of the reduction.
An implementation of StatusTestResNorm using a family of residual norms.
PCPGSolMgrOrthoFailure(const std::string &what_arg)
Structure to contain pointers to PCPGIter state variables.
PCPGSolMgrLinearProblemFailure is thrown when the linear problem is not setup (i.e.
Belos::StatusTest class for specifying a maximum number of iterations.
A factory class for generating StatusTestOutput objects.
int getNumIters() const
Get the iteration count for the most recent call to solve().
Iterated Modified Gram-Schmidt (IMGS) implementation of the Belos::OrthoManager class.
Traits class which defines basic operations on multivectors.
Belos::StatusTest for logically combining several status tests.
Teuchos::RCP< const Teuchos::SerialDenseMatrix< int, ScalarType > > D
The current Hessenberg matrix.
Classical Gram-Schmidt (with DGKS correction) implementation of the Belos::OrthoManager class...
A Belos::StatusTest class for specifying a maximum number of iterations.
ResetType
How to reset the solver.
Pure virtual base class which describes the basic interface for a solver manager. ...
void reset(const ResetType type)
Performs a reset of the solver manager specified by the ResetType. This informs the solver manager th...
A linear system to solve, and its associated information.
void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem)
Set the linear problem that needs to be solved.
Class which describes the linear problem to be solved by the iterative solver.
PCPGSolMgrLAPACKFailure is thrown when a nonzero value is retuned from an LAPACK call.
PCPGSolMgrLAPACKFailure(const std::string &what_arg)
Type traits class that says whether Teuchos::LAPACK has a valid implementation for the given ScalarTy...
ReturnType
Whether the Belos solve converged for all linear systems.
MagnitudeType achievedTol() const
Tolerance achieved by the last solve() invocation.
Iterated Classical Gram-Schmidt (ICGS) implementation of the Belos::OrthoManager class.
An implementation of the Belos::MatOrthoManager that performs orthogonalization using multiple steps ...
Teuchos::RCP< MV > U
The recycled subspace.
An implementation of the Belos::MatOrthoManager that performs orthogonalization using multiple steps ...
int setTolerance(MagnitudeType tolerance)
Set the value of the tolerance.
Teuchos::RCP< StatusTestOutput< ScalarType, MV, OP > > create(const Teuchos::RCP< OutputManager< ScalarType > > &printer, Teuchos::RCP< StatusTest< ScalarType, MV, OP > > test, int mod, int printStates)
Create the StatusTestOutput object specified by the outputStyle.
PCPGIterOrthoFailure is thrown when the PCPGIter object is unable to compute independent direction ve...
Belos::StatusTestResNorm for specifying general residual norm stopping criteria.
PCPG iterative linear solver.
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const
Get a parameter list containing the current parameters for this object.
An implementation of the Belos::MatOrthoManager that performs orthogonalization using (potentially) m...
A class for extending the status testing capabilities of Belos via logical combinations.
virtual ~PCPGSolMgr()
Destructor.
Class which defines basic traits for the operator type.
Parent class to all Belos exceptions.
PCPGSolMgrRecyclingFailure(const std::string &what_arg)
This class implements the PCPG iteration, where a single-std::vector Krylov subspace is constructed...
Belos header file which uses auto-configuration information to include necessary C++ headers...
PCPGSolMgrLinearProblemFailure(const std::string &what_arg)