42 #ifndef BELOS_RCG_SOLMGR_HPP 43 #define BELOS_RCG_SOLMGR_HPP 64 #include "Teuchos_BLAS.hpp" 65 #include "Teuchos_LAPACK.hpp" 66 #include "Teuchos_as.hpp" 67 #ifdef BELOS_TEUCHOS_TIME_MONITOR 68 #include "Teuchos_TimeMonitor.hpp" 117 template<
class ScalarType,
class MV,
class OP>
124 typedef Teuchos::ScalarTraits<ScalarType> SCT;
125 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
126 typedef Teuchos::ScalarTraits<MagnitudeType> MT;
162 const Teuchos::RCP<Teuchos::ParameterList> &pl );
176 Teuchos::RCP<const Teuchos::ParameterList> getValidParameters()
const;
186 Teuchos::Array<Teuchos::RCP<Teuchos::Time> >
getTimers()
const {
187 return Teuchos::tuple(timerSolve_);
215 void setParameters(
const Teuchos::RCP<Teuchos::ParameterList> ¶ms );
228 if ((type &
Belos::Problem) && !Teuchos::is_null(problem_)) problem_->setProblem();
261 std::string description()
const;
272 void getHarmonicVecs(
const Teuchos::SerialDenseMatrix<int,ScalarType> &F,
273 const Teuchos::SerialDenseMatrix<int,ScalarType> &G,
274 Teuchos::SerialDenseMatrix<int,ScalarType>& Y);
277 void sort(std::vector<ScalarType>& dlist,
int n, std::vector<int>& iperm);
280 void initializeStateStorage();
283 Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > problem_;
286 Teuchos::RCP<OutputManager<ScalarType> > printer_;
287 Teuchos::RCP<std::ostream> outputStream_;
290 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > sTest_;
291 Teuchos::RCP<StatusTestMaxIters<ScalarType,MV,OP> > maxIterTest_;
292 Teuchos::RCP<StatusTestGenResNorm<ScalarType,MV,OP> > convTest_;
293 Teuchos::RCP<StatusTestOutput<ScalarType,MV,OP> > outputTest_;
296 Teuchos::RCP<Teuchos::ParameterList> params_;
299 static const MagnitudeType convtol_default_;
300 static const int maxIters_default_;
301 static const int blockSize_default_;
302 static const int numBlocks_default_;
303 static const int recycleBlocks_default_;
304 static const bool showMaxResNormOnly_default_;
305 static const int verbosity_default_;
306 static const int outputStyle_default_;
307 static const int outputFreq_default_;
308 static const std::string label_default_;
309 static const Teuchos::RCP<std::ostream> outputStream_default_;
316 MagnitudeType convtol_;
322 MagnitudeType achievedTol_;
330 int numBlocks_, recycleBlocks_;
331 bool showMaxResNormOnly_;
332 int verbosity_, outputStyle_, outputFreq_;
341 Teuchos::RCP<MV> Ap_;
356 Teuchos::RCP<MV> U_, AU_;
359 Teuchos::RCP<MV> U1_;
362 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > Alpha_;
363 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > Beta_;
364 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > D_;
367 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > Delta_;
370 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > UTAU_;
373 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > LUUTAU_;
376 Teuchos::RCP<std::vector<int> > ipiv_;
379 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > AUTAU_;
382 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > rTz_old_;
385 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > F_,G_,Y_;
388 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > L2_,DeltaL2_,AU1TUDeltaL2_;
389 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > AU1TAU1_, AU1TU1_, AU1TAP_;
390 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > FY_,GY_;
391 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > APTAP_;
392 Teuchos::RCP<MV> U1Y1_, PY2_;
393 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > AUTAP_, AU1TU_;
399 Teuchos::RCP<Teuchos::Time> timerSolve_;
407 template<
class ScalarType,
class MV,
class OP>
410 template<
class ScalarType,
class MV,
class OP>
413 template<
class ScalarType,
class MV,
class OP>
416 template<
class ScalarType,
class MV,
class OP>
419 template<
class ScalarType,
class MV,
class OP>
422 template<
class ScalarType,
class MV,
class OP>
425 template<
class ScalarType,
class MV,
class OP>
428 template<
class ScalarType,
class MV,
class OP>
431 template<
class ScalarType,
class MV,
class OP>
434 template<
class ScalarType,
class MV,
class OP>
437 template<
class ScalarType,
class MV,
class OP>
441 template<
class ScalarType,
class MV,
class OP>
447 template<
class ScalarType,
class MV,
class OP>
450 const Teuchos::RCP<Teuchos::ParameterList> &pl ) :
454 TEUCHOS_TEST_FOR_EXCEPTION(problem_ == Teuchos::null, std::invalid_argument,
"Problem not given to solver manager.");
457 if ( !is_null(pl) ) {
463 template<
class ScalarType,
class MV,
class OP>
466 outputStream_ = outputStream_default_;
467 convtol_ = convtol_default_;
468 maxIters_ = maxIters_default_;
469 numBlocks_ = numBlocks_default_;
470 recycleBlocks_ = recycleBlocks_default_;
471 verbosity_ = verbosity_default_;
472 outputStyle_= outputStyle_default_;
473 outputFreq_= outputFreq_default_;
474 showMaxResNormOnly_ = showMaxResNormOnly_default_;
475 label_ = label_default_;
486 Alpha_ = Teuchos::null;
487 Beta_ = Teuchos::null;
489 Delta_ = Teuchos::null;
490 UTAU_ = Teuchos::null;
491 LUUTAU_ = Teuchos::null;
492 ipiv_ = Teuchos::null;
493 AUTAU_ = Teuchos::null;
494 rTz_old_ = Teuchos::null;
499 DeltaL2_ = Teuchos::null;
500 AU1TUDeltaL2_ = Teuchos::null;
501 AU1TAU1_ = Teuchos::null;
502 AU1TU1_ = Teuchos::null;
503 AU1TAP_ = Teuchos::null;
506 APTAP_ = Teuchos::null;
507 U1Y1_ = Teuchos::null;
508 PY2_ = Teuchos::null;
509 AUTAP_ = Teuchos::null;
510 AU1TU_ = Teuchos::null;
514 template<
class ScalarType,
class MV,
class OP>
518 if (params_ == Teuchos::null) {
526 if (params->isParameter(
"Maximum Iterations")) {
527 maxIters_ = params->get(
"Maximum Iterations",maxIters_default_);
530 params_->set(
"Maximum Iterations", maxIters_);
531 if (maxIterTest_!=Teuchos::null)
532 maxIterTest_->setMaxIters( maxIters_ );
536 if (params->isParameter(
"Num Blocks")) {
537 numBlocks_ = params->get(
"Num Blocks",numBlocks_default_);
538 TEUCHOS_TEST_FOR_EXCEPTION(numBlocks_ <= 0, std::invalid_argument,
539 "Belos::RCGSolMgr: \"Num Blocks\" must be strictly positive.");
542 params_->set(
"Num Blocks", numBlocks_);
546 if (params->isParameter(
"Num Recycled Blocks")) {
547 recycleBlocks_ = params->get(
"Num Recycled Blocks",recycleBlocks_default_);
548 TEUCHOS_TEST_FOR_EXCEPTION(recycleBlocks_ <= 0, std::invalid_argument,
549 "Belos::RCGSolMgr: \"Num Recycled Blocks\" must be strictly positive.");
551 TEUCHOS_TEST_FOR_EXCEPTION(recycleBlocks_ >= numBlocks_, std::invalid_argument,
552 "Belos::RCGSolMgr: \"Num Recycled Blocks\" must be less than \"Num Blocks\".");
555 params_->set(
"Num Recycled Blocks", recycleBlocks_);
559 if (params->isParameter(
"Timer Label")) {
560 std::string tempLabel = params->get(
"Timer Label", label_default_);
563 if (tempLabel != label_) {
565 params_->set(
"Timer Label", label_);
566 std::string solveLabel = label_ +
": RCGSolMgr total solve time";
567 #ifdef BELOS_TEUCHOS_TIME_MONITOR 568 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
574 if (params->isParameter(
"Verbosity")) {
575 if (Teuchos::isParameterType<int>(*params,
"Verbosity")) {
576 verbosity_ = params->get(
"Verbosity", verbosity_default_);
578 verbosity_ = (int)Teuchos::getParameter<Belos::MsgType>(*params,
"Verbosity");
582 params_->set(
"Verbosity", verbosity_);
583 if (printer_ != Teuchos::null)
584 printer_->setVerbosity(verbosity_);
588 if (params->isParameter(
"Output Style")) {
589 if (Teuchos::isParameterType<int>(*params,
"Output Style")) {
590 outputStyle_ = params->get(
"Output Style", outputStyle_default_);
592 outputStyle_ = (int)Teuchos::getParameter<Belos::OutputType>(*params,
"Output Style");
596 params_->set(
"Output Style", outputStyle_);
597 outputTest_ = Teuchos::null;
601 if (params->isParameter(
"Output Stream")) {
602 outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params,
"Output Stream");
605 params_->set(
"Output Stream", outputStream_);
606 if (printer_ != Teuchos::null)
607 printer_->setOStream( outputStream_ );
612 if (params->isParameter(
"Output Frequency")) {
613 outputFreq_ = params->get(
"Output Frequency", outputFreq_default_);
617 params_->set(
"Output Frequency", outputFreq_);
618 if (outputTest_ != Teuchos::null)
619 outputTest_->setOutputFrequency( outputFreq_ );
623 if (printer_ == Teuchos::null) {
632 if (params->isParameter(
"Convergence Tolerance")) {
633 convtol_ = params->get(
"Convergence Tolerance",convtol_default_);
636 params_->set(
"Convergence Tolerance", convtol_);
637 if (convTest_ != Teuchos::null)
638 convTest_->setTolerance( convtol_ );
641 if (params->isParameter(
"Show Maximum Residual Norm Only")) {
642 showMaxResNormOnly_ = Teuchos::getParameter<bool>(*params,
"Show Maximum Residual Norm Only");
645 params_->set(
"Show Maximum Residual Norm Only", showMaxResNormOnly_);
646 if (convTest_ != Teuchos::null)
647 convTest_->setShowMaxResNormOnly( showMaxResNormOnly_ );
653 if (maxIterTest_ == Teuchos::null)
657 if (convTest_ == Teuchos::null)
658 convTest_ = Teuchos::rcp(
new StatusTestResNorm_t( convtol_, 1 ) );
660 if (sTest_ == Teuchos::null)
661 sTest_ = Teuchos::rcp(
new StatusTestCombo_t( StatusTestCombo_t::OR, maxIterTest_, convTest_ ) );
663 if (outputTest_ == Teuchos::null) {
671 std::string solverDesc =
" Recycling CG ";
672 outputTest_->setSolverDesc( solverDesc );
676 if (timerSolve_ == Teuchos::null) {
677 std::string solveLabel = label_ +
": RCGSolMgr total solve time";
678 #ifdef BELOS_TEUCHOS_TIME_MONITOR 679 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
688 template<
class ScalarType,
class MV,
class OP>
689 Teuchos::RCP<const Teuchos::ParameterList>
692 static Teuchos::RCP<const Teuchos::ParameterList> validPL;
695 if(is_null(validPL)) {
696 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
697 pl->set(
"Convergence Tolerance", convtol_default_,
698 "The relative residual tolerance that needs to be achieved by the\n" 699 "iterative solver in order for the linear system to be declared converged.");
700 pl->set(
"Maximum Iterations", maxIters_default_,
701 "The maximum number of block iterations allowed for each\n" 702 "set of RHS solved.");
703 pl->set(
"Block Size", blockSize_default_,
704 "Block Size Parameter -- currently must be 1 for RCG");
705 pl->set(
"Num Blocks", numBlocks_default_,
706 "The length of a cycle (and this max number of search vectors kept)\n");
707 pl->set(
"Num Recycled Blocks", recycleBlocks_default_,
708 "The number of vectors in the recycle subspace.");
709 pl->set(
"Verbosity", verbosity_default_,
710 "What type(s) of solver information should be outputted\n" 711 "to the output stream.");
712 pl->set(
"Output Style", outputStyle_default_,
713 "What style is used for the solver information outputted\n" 714 "to the output stream.");
715 pl->set(
"Output Frequency", outputFreq_default_,
716 "How often convergence information should be outputted\n" 717 "to the output stream.");
718 pl->set(
"Output Stream", outputStream_default_,
719 "A reference-counted pointer to the output stream where all\n" 720 "solver output is sent.");
721 pl->set(
"Show Maximum Residual Norm Only", showMaxResNormOnly_default_,
722 "When convergence information is printed, only show the maximum\n" 723 "relative residual norm when the block size is greater than one.");
724 pl->set(
"Timer Label", label_default_,
725 "The string to use as a prefix for the timer labels.");
733 template<
class ScalarType,
class MV,
class OP>
737 Teuchos::RCP<const MV> rhsMV = problem_->getRHS();
738 if (rhsMV == Teuchos::null) {
745 TEUCHOS_TEST_FOR_EXCEPTION(static_cast<ptrdiff_t>(numBlocks_) >
MVText::GetGlobalLength(*rhsMV),std::invalid_argument,
746 "Belos::RCGSolMgr::initializeStateStorage(): Cannot generate a Krylov basis with dimension larger the operator!");
749 if (P_ == Teuchos::null) {
755 Teuchos::RCP<const MV> tmp = P_;
761 if (Ap_ == Teuchos::null)
765 if (r_ == Teuchos::null)
769 if (z_ == Teuchos::null)
773 if (U_ == Teuchos::null) {
779 Teuchos::RCP<const MV> tmp = U_;
785 if (AU_ == Teuchos::null) {
791 Teuchos::RCP<const MV> tmp = AU_;
797 if (U1_ == Teuchos::null) {
803 Teuchos::RCP<const MV> tmp = U1_;
809 if (Alpha_ == Teuchos::null)
810 Alpha_ = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( numBlocks_, 1 ) );
812 if ( (Alpha_->numRows() != numBlocks_) || (Alpha_->numCols() != 1) )
813 Alpha_->reshape( numBlocks_, 1 );
817 if (Beta_ == Teuchos::null)
818 Beta_ = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( numBlocks_ + 1, 1 ) );
820 if ( (Beta_->numRows() != (numBlocks_+1)) || (Beta_->numCols() != 1) )
821 Beta_->reshape( numBlocks_ + 1, 1 );
825 if (D_ == Teuchos::null)
826 D_ = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( numBlocks_ , 1 ) );
828 if ( (D_->numRows() != numBlocks_) || (D_->numCols() != 1) )
829 D_->reshape( numBlocks_, 1 );
833 if (Delta_ == Teuchos::null)
834 Delta_ = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( recycleBlocks_, numBlocks_ + 1 ) );
836 if ( (Delta_->numRows() != recycleBlocks_) || (Delta_->numCols() != (numBlocks_ + 1)) )
837 Delta_->reshape( recycleBlocks_, numBlocks_ + 1 );
841 if (UTAU_ == Teuchos::null)
842 UTAU_ = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( recycleBlocks_, recycleBlocks_ ) );
844 if ( (UTAU_->numRows() != recycleBlocks_) || (UTAU_->numCols() != recycleBlocks_) )
845 UTAU_->reshape( recycleBlocks_, recycleBlocks_ );
849 if (LUUTAU_ == Teuchos::null)
850 LUUTAU_ = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( recycleBlocks_, recycleBlocks_ ) );
852 if ( (LUUTAU_->numRows() != recycleBlocks_) || (LUUTAU_->numCols() != recycleBlocks_) )
853 LUUTAU_->reshape( recycleBlocks_, recycleBlocks_ );
857 if (ipiv_ == Teuchos::null)
858 ipiv_ = Teuchos::rcp(
new std::vector<int>(recycleBlocks_) );
860 if ( (
int)ipiv_->size() != recycleBlocks_ )
861 ipiv_->resize(recycleBlocks_);
865 if (AUTAU_ == Teuchos::null)
866 AUTAU_ = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( recycleBlocks_, recycleBlocks_ ) );
868 if ( (AUTAU_->numRows() != recycleBlocks_) || (AUTAU_->numCols() != recycleBlocks_) )
869 AUTAU_->reshape( recycleBlocks_, recycleBlocks_ );
873 if (rTz_old_ == Teuchos::null)
874 rTz_old_ = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( 1, 1 ) );
876 if ( (rTz_old_->numRows() != 1) || (rTz_old_->numCols() != 1) )
877 rTz_old_->reshape( 1, 1 );
881 if (F_ == Teuchos::null)
882 F_ = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( numBlocks_+recycleBlocks_, numBlocks_+recycleBlocks_ ) );
884 if ( (F_->numRows() != (numBlocks_+recycleBlocks_)) || (F_->numCols() != numBlocks_+recycleBlocks_) )
885 F_->reshape( numBlocks_+recycleBlocks_, numBlocks_+recycleBlocks_ );
889 if (G_ == Teuchos::null)
890 G_ = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( numBlocks_+recycleBlocks_, numBlocks_+recycleBlocks_ ) );
892 if ( (G_->numRows() != (numBlocks_+recycleBlocks_)) || (G_->numCols() != numBlocks_+recycleBlocks_) )
893 G_->reshape( numBlocks_+recycleBlocks_, numBlocks_+recycleBlocks_ );
897 if (Y_ == Teuchos::null)
898 Y_ = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( numBlocks_+recycleBlocks_, recycleBlocks_ ) );
900 if ( (Y_->numRows() != (numBlocks_+recycleBlocks_)) || (Y_->numCols() != numBlocks_+recycleBlocks_) )
901 Y_->reshape( numBlocks_+recycleBlocks_, numBlocks_+recycleBlocks_ );
905 if (L2_ == Teuchos::null)
906 L2_ = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( numBlocks_+1, numBlocks_ ) );
908 if ( (L2_->numRows() != (numBlocks_+1)) || (L2_->numCols() != numBlocks_) )
909 L2_->reshape( numBlocks_+1, numBlocks_ );
913 if (DeltaL2_ == Teuchos::null)
914 DeltaL2_ = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( recycleBlocks_, numBlocks_ ) );
916 if ( (DeltaL2_->numRows() != (recycleBlocks_)) || (DeltaL2_->numCols() != (numBlocks_) ) )
917 DeltaL2_->reshape( recycleBlocks_, numBlocks_ );
921 if (AU1TUDeltaL2_ == Teuchos::null)
922 AU1TUDeltaL2_ = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( recycleBlocks_, numBlocks_ ) );
924 if ( (AU1TUDeltaL2_->numRows() != (recycleBlocks_)) || (AU1TUDeltaL2_->numCols() != (numBlocks_) ) )
925 AU1TUDeltaL2_->reshape( recycleBlocks_, numBlocks_ );
929 if (AU1TAU1_ == Teuchos::null)
930 AU1TAU1_ = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( recycleBlocks_, recycleBlocks_ ) );
932 if ( (AU1TAU1_->numRows() != (recycleBlocks_)) || (AU1TAU1_->numCols() != (recycleBlocks_) ) )
933 AU1TAU1_->reshape( recycleBlocks_, recycleBlocks_ );
937 if (GY_ == Teuchos::null)
938 GY_ = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( numBlocks_ + recycleBlocks_, recycleBlocks_ ) );
940 if ( (GY_->numRows() != (numBlocks_ + recycleBlocks_)) || (GY_->numCols() != (recycleBlocks_) ) )
941 GY_->reshape( numBlocks_+recycleBlocks_, recycleBlocks_ );
945 if (AU1TU1_ == Teuchos::null)
946 AU1TU1_ = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( recycleBlocks_, recycleBlocks_ ) );
948 if ( (AU1TU1_->numRows() != (recycleBlocks_)) || (AU1TU1_->numCols() != (recycleBlocks_) ) )
949 AU1TU1_->reshape( recycleBlocks_, recycleBlocks_ );
953 if (FY_ == Teuchos::null)
954 FY_ = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( numBlocks_ + recycleBlocks_, recycleBlocks_ ) );
956 if ( (FY_->numRows() != (numBlocks_ + recycleBlocks_)) || (FY_->numCols() != (recycleBlocks_) ) )
957 FY_->reshape( numBlocks_+recycleBlocks_, recycleBlocks_ );
961 if (AU1TAP_ == Teuchos::null)
962 AU1TAP_ = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( recycleBlocks_, numBlocks_ ) );
964 if ( (AU1TAP_->numRows() != (recycleBlocks_)) || (AU1TAP_->numCols() != (numBlocks_) ) )
965 AU1TAP_->reshape( recycleBlocks_, numBlocks_ );
969 if (APTAP_ == Teuchos::null)
970 APTAP_ = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( numBlocks_, numBlocks_ ) );
972 if ( (APTAP_->numRows() != (numBlocks_)) || (APTAP_->numCols() != (numBlocks_) ) )
973 APTAP_->reshape( numBlocks_, numBlocks_ );
977 if (U1Y1_ == Teuchos::null) {
983 Teuchos::RCP<const MV> tmp = U1Y1_;
989 if (PY2_ == Teuchos::null) {
995 Teuchos::RCP<const MV> tmp = PY2_;
1001 if (AUTAP_ == Teuchos::null)
1002 AUTAP_ = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( recycleBlocks_, numBlocks_ ) );
1004 if ( (AUTAP_->numRows() != (recycleBlocks_)) || (AUTAP_->numCols() != (numBlocks_) ) )
1005 AUTAP_->reshape( recycleBlocks_, numBlocks_ );
1009 if (AU1TU_ == Teuchos::null)
1010 AU1TU_ = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( recycleBlocks_, recycleBlocks_ ) );
1012 if ( (AU1TU_->numRows() != (recycleBlocks_)) || (AU1TU_->numCols() != (recycleBlocks_) ) )
1013 AU1TU_->reshape( recycleBlocks_, recycleBlocks_ );
1020 template<
class ScalarType,
class MV,
class OP>
1023 Teuchos::LAPACK<int,ScalarType> lapack;
1024 std::vector<int> index(recycleBlocks_);
1025 ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
1026 ScalarType zero = Teuchos::ScalarTraits<ScalarType>::zero();
1039 "Belos::RCGSolMgr::solve(): Linear problem is not a valid object.");
1041 "Belos::RCGSolMgr::solve(): Linear problem is not ready, setProblem() has not been called.");
1042 TEUCHOS_TEST_FOR_EXCEPTION((problem_->getLeftPrec() != Teuchos::null)&&(problem_->getRightPrec() != Teuchos::null),
1044 "Belos::RCGSolMgr::solve(): RCG does not support split preconditioning, only set left or right preconditioner.");
1047 Teuchos::RCP<OP> precObj;
1048 if (problem_->getLeftPrec() != Teuchos::null) {
1049 precObj = Teuchos::rcp_const_cast<OP>(problem_->getLeftPrec());
1051 else if (problem_->getRightPrec() != Teuchos::null) {
1052 precObj = Teuchos::rcp_const_cast<OP>(problem_->getRightPrec());
1057 std::vector<int> currIdx(1);
1061 problem_->setLSIndex( currIdx );
1065 if (numBlocks_ > dim) {
1066 numBlocks_ = Teuchos::asSafe<int>(dim);
1067 params_->set(
"Num Blocks", numBlocks_);
1069 "Warning! Requested Krylov subspace dimension is larger than operator dimension!" << std::endl <<
1070 " The maximum number of blocks allowed for the Krylov subspace will be adjusted to " << numBlocks_ << std::endl;
1074 initializeStateStorage();
1077 Teuchos::ParameterList plist;
1078 plist.set(
"Num Blocks",numBlocks_);
1079 plist.set(
"Recycled Blocks",recycleBlocks_);
1082 outputTest_->reset();
1085 bool isConverged =
true;
1089 index.resize(recycleBlocks_);
1090 for (
int i=0; i<recycleBlocks_; ++i) { index[i] = i; }
1092 index.resize(recycleBlocks_);
1093 for (
int i=0; i<recycleBlocks_; ++i) { index[i] = i; }
1096 problem_->applyOp( *Utmp, *AUtmp );
1098 Teuchos::SerialDenseMatrix<int,ScalarType> UTAUtmp( Teuchos::View, *UTAU_, recycleBlocks_, recycleBlocks_ );
1101 Teuchos::SerialDenseMatrix<int,ScalarType> AUTAUtmp( Teuchos::View, *AUTAU_, recycleBlocks_, recycleBlocks_ );
1102 if ( precObj != Teuchos::null ) {
1103 index.resize(recycleBlocks_);
1104 for (
int i=0; i<recycleBlocks_; ++i) { index[i] = i; }
1105 index.resize(recycleBlocks_);
1106 for (
int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1118 Teuchos::RCP<RCGIter<ScalarType,MV,OP> > rcg_iter;
1123 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1124 Teuchos::TimeMonitor slvtimer(*timerSolve_);
1127 while ( numRHS2Solve > 0 ) {
1130 if (printer_->isVerbosity(
Debug ) ) {
1131 if (existU_) printer_->print(
Debug,
"Using recycle space generated from previous call to solve()." );
1132 else printer_->print(
Debug,
"No recycle space exists." );
1136 rcg_iter->resetNumIters();
1139 rcg_iter->setSize( recycleBlocks_, numBlocks_ );
1142 outputTest_->resetNumCalls();
1151 problem_->computeCurrResVec( &*r_ );
1156 Teuchos::SerialDenseMatrix<int,ScalarType> Utr(recycleBlocks_,1);
1157 index.resize(recycleBlocks_);
1158 for (
int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1161 Teuchos::SerialDenseMatrix<int,ScalarType> UTAUtmp( Teuchos::View, *UTAU_, recycleBlocks_, recycleBlocks_ );
1162 Teuchos::SerialDenseMatrix<int,ScalarType> LUUTAUtmp( Teuchos::View, *LUUTAU_, recycleBlocks_, recycleBlocks_ );
1163 LUUTAUtmp.assign(UTAUtmp);
1165 lapack.GESV(recycleBlocks_, 1, LUUTAUtmp.values(), LUUTAUtmp.stride(), &(*ipiv_)[0], Utr.values(), Utr.stride(), &info);
1167 "Belos::RCGSolMgr::solve(): LAPACK GESV failed to compute a solution.");
1173 index.resize(recycleBlocks_);
1174 for (
int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1179 if ( precObj != Teuchos::null ) {
1190 Teuchos::SerialDenseMatrix<int,ScalarType> mu( Teuchos::View, *Delta_, recycleBlocks_, 1);
1191 index.resize(recycleBlocks_);
1192 for (
int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1195 Teuchos::SerialDenseMatrix<int,ScalarType> LUUTAUtmp( Teuchos::View, *LUUTAU_, recycleBlocks_, recycleBlocks_ );
1198 lapack.GETRS( TRANS, recycleBlocks_, 1, LUUTAUtmp.values(), LUUTAUtmp.stride(), &(*ipiv_)[0], mu.values(), mu.stride(), &info );
1200 "Belos::RCGSolMgr::solve(): LAPACK GETRS failed to compute a solution.");
1219 index.resize( numBlocks_+1 );
1220 for (
int ii=0; ii<(numBlocks_+1); ++ii) { index[ii] = ii; }
1222 index.resize( recycleBlocks_ );
1223 for (
int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1225 index.resize( recycleBlocks_ );
1226 for (
int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1228 newstate.
Alpha = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( Teuchos::View, *Alpha_, numBlocks_, 1 ) );
1229 newstate.
Beta = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( Teuchos::View, *Beta_, numBlocks_, 1 ) );
1230 newstate.
D = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( Teuchos::View, *D_, numBlocks_, 1 ) );
1231 newstate.
Delta = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( Teuchos::View, *Delta_, recycleBlocks_, numBlocks_, 0, 1 ) );
1232 newstate.
LUUTAU = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( Teuchos::View, *LUUTAU_, recycleBlocks_, recycleBlocks_ ) );
1238 newstate.
existU = existU_;
1239 newstate.
ipiv = ipiv_;
1242 rcg_iter->initialize(newstate);
1248 rcg_iter->iterate();
1255 if ( convTest_->getStatus() ==
Passed ) {
1264 else if ( maxIterTest_->getStatus() ==
Passed ) {
1266 isConverged =
false;
1274 else if ( rcg_iter->getCurSubspaceDim() == rcg_iter->getMaxSubspaceDim() ) {
1279 if (recycleBlocks_ > 0) {
1283 Teuchos::SerialDenseMatrix<int,ScalarType> Ftmp( Teuchos::View, *F_, numBlocks_, numBlocks_ );
1284 Teuchos::SerialDenseMatrix<int,ScalarType> Gtmp( Teuchos::View, *G_, numBlocks_, numBlocks_ );
1285 Teuchos::SerialDenseMatrix<int,ScalarType> Dtmp( Teuchos::View, *D_, numBlocks_, 1 );
1286 Teuchos::SerialDenseMatrix<int,ScalarType> Alphatmp( Teuchos::View, *Alpha_, numBlocks_, 1 );
1287 Teuchos::SerialDenseMatrix<int,ScalarType> Betatmp( Teuchos::View, *Beta_, numBlocks_, 1 );
1288 Ftmp.putScalar(zero);
1289 Gtmp.putScalar(zero);
1290 for (
int ii=0;ii<numBlocks_;ii++) {
1291 Gtmp(ii,ii) = (Dtmp(ii,0) / Alphatmp(ii,0))*(1 + Betatmp(ii,0));
1293 Gtmp(ii-1,ii) = -Dtmp(ii,0)/Alphatmp(ii-1,0);
1294 Gtmp(ii,ii-1) = -Dtmp(ii,0)/Alphatmp(ii-1,0);
1296 Ftmp(ii,ii) = Dtmp(ii,0);
1300 Teuchos::SerialDenseMatrix<int,ScalarType> Ytmp( Teuchos::View, *Y_, numBlocks_, recycleBlocks_ );
1301 getHarmonicVecs(Ftmp,Gtmp,Ytmp);
1304 index.resize( numBlocks_ );
1305 for (
int ii=0; ii<numBlocks_; ++ii) { index[ii] = ii; }
1307 index.resize( recycleBlocks_ );
1308 for (
int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1315 Teuchos::SerialDenseMatrix<int,ScalarType> GYtmp( Teuchos::View, *GY_, numBlocks_, recycleBlocks_ );
1316 GYtmp.multiply(Teuchos::NO_TRANS,Teuchos::NO_TRANS,one,Gtmp,Ytmp,zero);
1317 Teuchos::SerialDenseMatrix<int,ScalarType> AU1TAU1tmp( Teuchos::View, *AU1TAU1_, recycleBlocks_, recycleBlocks_ );
1318 AU1TAU1tmp.multiply(
Teuchos::TRANS,Teuchos::NO_TRANS,one,Ytmp,GYtmp,zero);
1321 Teuchos::SerialDenseMatrix<int,ScalarType> FYtmp( Teuchos::View, *FY_, numBlocks_, recycleBlocks_ );
1322 FYtmp.multiply(Teuchos::NO_TRANS,Teuchos::NO_TRANS,one,Ftmp,Ytmp,zero);
1323 Teuchos::SerialDenseMatrix<int,ScalarType> AU1TU1tmp( Teuchos::View, *AU1TU1_, recycleBlocks_, recycleBlocks_ );
1324 AU1TU1tmp.multiply(
Teuchos::TRANS,Teuchos::NO_TRANS,one,Ytmp,FYtmp,zero);
1326 Teuchos::SerialDenseMatrix<int,ScalarType> AU1TAPtmp( Teuchos::View, *AU1TAP_, recycleBlocks_, 1 );
1328 AU1TAPtmp.putScalar(zero);
1330 ScalarType alphatmp = -1.0 / Alphatmp(numBlocks_-1,0);
1331 for (
int ii=0; ii<recycleBlocks_; ++ii) {
1332 AU1TAPtmp(ii,0) = Ytmp(numBlocks_-1,ii) * alphatmp;
1340 lastBeta = numBlocks_-1;
1347 Teuchos::SerialDenseMatrix<int,ScalarType> Dtmp( Teuchos::View, *D_, numBlocks_, 1 );
1348 Teuchos::SerialDenseMatrix<int,ScalarType> AU1TAPtmp( Teuchos::View, *AU1TAP_, recycleBlocks_, numBlocks_ );
1349 AU1TAPtmp.scale(Dtmp(0,0));
1351 Teuchos::SerialDenseMatrix<int,ScalarType> Alphatmp( Teuchos::View, *Alpha_, numBlocks_, 1 );
1352 Teuchos::SerialDenseMatrix<int,ScalarType> Betatmp( Teuchos::View, *Beta_, numBlocks_+1, 1 );
1353 Teuchos::SerialDenseMatrix<int,ScalarType> APTAPtmp( Teuchos::View, *APTAP_, numBlocks_, numBlocks_ );
1354 APTAPtmp.putScalar(zero);
1355 for (
int ii=0; ii<numBlocks_; ii++) {
1356 APTAPtmp(ii,ii) = (Dtmp(ii,0) / Alphatmp(ii,0))*(1 + Betatmp(ii+1,0));
1358 APTAPtmp(ii-1,ii) = -Dtmp(ii,0)/Alphatmp(ii-1,0);
1359 APTAPtmp(ii,ii-1) = -Dtmp(ii,0)/Alphatmp(ii-1,0);
1364 Teuchos::SerialDenseMatrix<int,ScalarType> Ftmp( Teuchos::View, *F_, (numBlocks_+recycleBlocks_), (numBlocks_+recycleBlocks_) );
1365 Teuchos::SerialDenseMatrix<int,ScalarType> F11( Teuchos::View, *F_, recycleBlocks_, recycleBlocks_ );
1366 Teuchos::SerialDenseMatrix<int,ScalarType> F12( Teuchos::View, *F_, recycleBlocks_, numBlocks_, 0, recycleBlocks_ );
1367 Teuchos::SerialDenseMatrix<int,ScalarType> F21( Teuchos::View, *F_, numBlocks_, recycleBlocks_, recycleBlocks_, 0 );
1368 Teuchos::SerialDenseMatrix<int,ScalarType> F22( Teuchos::View, *F_, numBlocks_, numBlocks_, recycleBlocks_, recycleBlocks_ );
1369 Teuchos::SerialDenseMatrix<int,ScalarType> AU1TU1tmp( Teuchos::View, *AU1TU1_, recycleBlocks_, recycleBlocks_ );
1370 F11.assign(AU1TU1tmp);
1371 F12.putScalar(zero);
1372 F21.putScalar(zero);
1373 F22.putScalar(zero);
1374 for(
int ii=0;ii<numBlocks_;ii++) {
1375 F22(ii,ii) = Dtmp(ii,0);
1379 Teuchos::SerialDenseMatrix<int,ScalarType> Gtmp( Teuchos::View, *G_, (numBlocks_+recycleBlocks_), (numBlocks_+recycleBlocks_) );
1380 Teuchos::SerialDenseMatrix<int,ScalarType> AU1TAU1tmp( Teuchos::View, *AU1TAU1_, recycleBlocks_, recycleBlocks_ );
1381 Teuchos::SerialDenseMatrix<int,ScalarType> G11( Teuchos::View, *G_, recycleBlocks_, recycleBlocks_ );
1382 Teuchos::SerialDenseMatrix<int,ScalarType> G12( Teuchos::View, *G_, recycleBlocks_, numBlocks_, 0, recycleBlocks_ );
1383 Teuchos::SerialDenseMatrix<int,ScalarType> G21( Teuchos::View, *G_, numBlocks_, recycleBlocks_, recycleBlocks_, 0 );
1384 Teuchos::SerialDenseMatrix<int,ScalarType> G22( Teuchos::View, *G_, numBlocks_, numBlocks_, recycleBlocks_, recycleBlocks_ );
1385 G11.assign(AU1TAU1tmp);
1386 G12.assign(AU1TAPtmp);
1388 for (
int ii=0;ii<recycleBlocks_;++ii)
1389 for (
int jj=0;jj<numBlocks_;++jj)
1390 G21(jj,ii) = G12(ii,jj);
1391 G22.assign(APTAPtmp);
1394 Teuchos::SerialDenseMatrix<int,ScalarType> Ytmp( Teuchos::View, *Y_, (recycleBlocks_+numBlocks_), recycleBlocks_ );
1395 getHarmonicVecs(Ftmp,Gtmp,Ytmp);
1398 index.resize( numBlocks_ );
1399 for (
int ii=0; ii<numBlocks_; ++ii) { index[ii] = ii+1; }
1401 index.resize( recycleBlocks_ );
1402 for (
int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1404 Teuchos::SerialDenseMatrix<int,ScalarType> Y2( Teuchos::View, *Y_, numBlocks_, recycleBlocks_, recycleBlocks_, 0 );
1405 index.resize( recycleBlocks_ );
1406 for (
int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1408 index.resize( recycleBlocks_ );
1409 for (
int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1411 Teuchos::SerialDenseMatrix<int,ScalarType> Y1( Teuchos::View, *Y_, recycleBlocks_, recycleBlocks_ );
1419 Teuchos::SerialDenseMatrix<int,ScalarType> GYtmp( Teuchos::View, *GY_, (numBlocks_+recycleBlocks_), recycleBlocks_ );
1420 GYtmp.multiply(Teuchos::NO_TRANS,Teuchos::NO_TRANS,one,Gtmp,Ytmp,zero);
1421 AU1TAU1tmp.multiply(
Teuchos::TRANS,Teuchos::NO_TRANS,one,Ytmp,GYtmp,zero);
1425 AU1TAPtmp.putScalar(zero);
1426 ScalarType alphatmp = -1.0 / Alphatmp(numBlocks_-1,0);
1427 for (
int ii=0; ii<recycleBlocks_; ++ii) {
1428 AU1TAPtmp(ii,0) = Ytmp(numBlocks_+recycleBlocks_-1,ii) * alphatmp;
1432 Teuchos::SerialDenseMatrix<int,ScalarType> FYtmp( Teuchos::View, *FY_, (numBlocks_+recycleBlocks_), recycleBlocks_ );
1433 FYtmp.multiply(Teuchos::NO_TRANS,Teuchos::NO_TRANS,one,Ftmp,Ytmp,zero);
1435 AU1TU1tmp.multiply(
Teuchos::TRANS,Teuchos::NO_TRANS,one,Ytmp,FYtmp,zero);
1438 lastp = numBlocks_+1;
1439 lastBeta = numBlocks_;
1445 Teuchos::SerialDenseMatrix<int,ScalarType> Alphatmp( Teuchos::View, *Alpha_, numBlocks_, 1 );
1446 Teuchos::SerialDenseMatrix<int,ScalarType> Betatmp( Teuchos::View, *Beta_, numBlocks_, 1 );
1447 Teuchos::SerialDenseMatrix<int,ScalarType> Dtmp( Teuchos::View, *D_, numBlocks_, 1 );
1448 Teuchos::SerialDenseMatrix<int,ScalarType> APTAPtmp( Teuchos::View, *APTAP_, numBlocks_, numBlocks_ );
1449 APTAPtmp.putScalar(zero);
1450 for (
int ii=0; ii<numBlocks_; ii++) {
1451 APTAPtmp(ii,ii) = (Dtmp(ii,0) / Alphatmp(ii,0))*(1 + Betatmp(ii,0));
1453 APTAPtmp(ii-1,ii) = -Dtmp(ii,0)/Alphatmp(ii-1,0);
1454 APTAPtmp(ii,ii-1) = -Dtmp(ii,0)/Alphatmp(ii-1,0);
1458 Teuchos::SerialDenseMatrix<int,ScalarType> L2tmp( Teuchos::View, *L2_, numBlocks_+1, numBlocks_ );
1459 L2tmp.putScalar(zero);
1460 for(
int ii=0;ii<numBlocks_;ii++) {
1461 L2tmp(ii,ii) = 1./Alphatmp(ii,0);
1462 L2tmp(ii+1,ii) = -1./Alphatmp(ii,0);
1466 Teuchos::SerialDenseMatrix<int,ScalarType> AUTAPtmp( Teuchos::View, *AUTAP_, recycleBlocks_, numBlocks_ );
1467 Teuchos::SerialDenseMatrix<int,ScalarType> UTAUtmp( Teuchos::View, *UTAU_, recycleBlocks_, recycleBlocks_ );
1468 Teuchos::SerialDenseMatrix<int,ScalarType> Deltatmp( Teuchos::View, *Delta_, recycleBlocks_, numBlocks_+1 );
1469 Teuchos::SerialDenseMatrix<int,ScalarType> DeltaL2tmp( Teuchos::View, *DeltaL2_, recycleBlocks_, numBlocks_ );
1470 DeltaL2tmp.multiply(Teuchos::NO_TRANS,Teuchos::NO_TRANS,one,Deltatmp,L2tmp,zero);
1471 AUTAPtmp.multiply(Teuchos::NO_TRANS,Teuchos::NO_TRANS,one,UTAUtmp,DeltaL2tmp,zero);
1474 Teuchos::SerialDenseMatrix<int,ScalarType> Ftmp( Teuchos::View, *F_, (numBlocks_+recycleBlocks_), (numBlocks_+recycleBlocks_) );
1475 Teuchos::SerialDenseMatrix<int,ScalarType> F11( Teuchos::View, *F_, recycleBlocks_, recycleBlocks_ );
1476 Teuchos::SerialDenseMatrix<int,ScalarType> F12( Teuchos::View, *F_, recycleBlocks_, numBlocks_, 0, recycleBlocks_ );
1477 Teuchos::SerialDenseMatrix<int,ScalarType> F21( Teuchos::View, *F_, numBlocks_, recycleBlocks_, recycleBlocks_, 0 );
1478 Teuchos::SerialDenseMatrix<int,ScalarType> F22( Teuchos::View, *F_, numBlocks_, numBlocks_, recycleBlocks_, recycleBlocks_ );
1479 F11.assign(UTAUtmp);
1480 F12.putScalar(zero);
1481 F21.putScalar(zero);
1482 F22.putScalar(zero);
1483 for(
int ii=0;ii<numBlocks_;ii++) {
1484 F22(ii,ii) = Dtmp(ii,0);
1488 Teuchos::SerialDenseMatrix<int,ScalarType> Gtmp( Teuchos::View, *G_, (numBlocks_+recycleBlocks_), (numBlocks_+recycleBlocks_) );
1489 Teuchos::SerialDenseMatrix<int,ScalarType> G11( Teuchos::View, *G_, recycleBlocks_, recycleBlocks_ );
1490 Teuchos::SerialDenseMatrix<int,ScalarType> G12( Teuchos::View, *G_, recycleBlocks_, numBlocks_, 0, recycleBlocks_ );
1491 Teuchos::SerialDenseMatrix<int,ScalarType> G21( Teuchos::View, *G_, numBlocks_, recycleBlocks_, recycleBlocks_, 0 );
1492 Teuchos::SerialDenseMatrix<int,ScalarType> G22( Teuchos::View, *G_, numBlocks_, numBlocks_, recycleBlocks_, recycleBlocks_ );
1493 Teuchos::SerialDenseMatrix<int,ScalarType> AUTAUtmp( Teuchos::View, *AUTAU_, recycleBlocks_, recycleBlocks_ );
1494 G11.assign(AUTAUtmp);
1495 G12.assign(AUTAPtmp);
1497 for (
int ii=0;ii<recycleBlocks_;++ii)
1498 for (
int jj=0;jj<numBlocks_;++jj)
1499 G21(jj,ii) = G12(ii,jj);
1500 G22.assign(APTAPtmp);
1503 Teuchos::SerialDenseMatrix<int,ScalarType> Ytmp( Teuchos::View, *Y_, (recycleBlocks_+numBlocks_), recycleBlocks_ );
1504 getHarmonicVecs(Ftmp,Gtmp,Ytmp);
1507 index.resize( recycleBlocks_ );
1508 for (
int ii=0; ii<(recycleBlocks_); ++ii) { index[ii] = ii; }
1510 index.resize( numBlocks_ );
1511 for (
int ii=0; ii<numBlocks_; ++ii) { index[ii] = ii; }
1513 index.resize( recycleBlocks_ );
1514 for (
int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1516 Teuchos::SerialDenseMatrix<int,ScalarType> Y2( Teuchos::View, *Y_, numBlocks_, recycleBlocks_, recycleBlocks_, 0 );
1517 index.resize( recycleBlocks_ );
1518 for (
int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1520 Teuchos::SerialDenseMatrix<int,ScalarType> Y1( Teuchos::View, *Y_, recycleBlocks_, recycleBlocks_ );
1521 index.resize( recycleBlocks_ );
1522 for (
int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1531 Teuchos::SerialDenseMatrix<int,ScalarType> GYtmp( Teuchos::View, *GY_, (numBlocks_+recycleBlocks_), recycleBlocks_ );
1532 GYtmp.multiply(Teuchos::NO_TRANS,Teuchos::NO_TRANS,one,Gtmp,Ytmp,zero);
1533 Teuchos::SerialDenseMatrix<int,ScalarType> AU1TAU1tmp( Teuchos::View, *AU1TAU1_, recycleBlocks_, recycleBlocks_ );
1534 AU1TAU1tmp.multiply(
Teuchos::TRANS,Teuchos::NO_TRANS,one,Ytmp,GYtmp,zero);
1537 Teuchos::SerialDenseMatrix<int,ScalarType> FYtmp( Teuchos::View, *FY_, (numBlocks_+recycleBlocks_), recycleBlocks_ );
1538 FYtmp.multiply(Teuchos::NO_TRANS,Teuchos::NO_TRANS,one,Ftmp,Ytmp,zero);
1539 Teuchos::SerialDenseMatrix<int,ScalarType> AU1TU1tmp( Teuchos::View, *AU1TU1_, recycleBlocks_, recycleBlocks_ );
1540 AU1TU1tmp.multiply(
Teuchos::TRANS,Teuchos::NO_TRANS,one,Ytmp,FYtmp,zero);
1543 Teuchos::SerialDenseMatrix<int,ScalarType> AU1TUtmp( Teuchos::View, *AU1TU_, recycleBlocks_, recycleBlocks_ );
1544 AU1TUtmp.assign(UTAUtmp);
1547 dold = Dtmp(numBlocks_-1,0);
1554 lastBeta = numBlocks_-1;
1557 Teuchos::SerialDenseMatrix<int,ScalarType> Alphatmp( Teuchos::View, *Alpha_, numBlocks_, 1 );
1558 Teuchos::SerialDenseMatrix<int,ScalarType> Betatmp( Teuchos::View, *Beta_, numBlocks_+1, 1 );
1559 Teuchos::SerialDenseMatrix<int,ScalarType> Dtmp( Teuchos::View, *D_, numBlocks_, 1 );
1560 Teuchos::SerialDenseMatrix<int,ScalarType> APTAPtmp( Teuchos::View, *APTAP_, numBlocks_, numBlocks_ );
1561 for (
int ii=0; ii<numBlocks_; ii++) {
1562 APTAPtmp(ii,ii) = (Dtmp(ii,0) / Alphatmp(ii,0))*(1 + Betatmp(ii+1,0));
1564 APTAPtmp(ii-1,ii) = -Dtmp(ii,0)/Alphatmp(ii-1,0);
1565 APTAPtmp(ii,ii-1) = -Dtmp(ii,0)/Alphatmp(ii-1,0);
1569 Teuchos::SerialDenseMatrix<int,ScalarType> L2tmp( Teuchos::View, *L2_, numBlocks_+1, numBlocks_ );
1570 for(
int ii=0;ii<numBlocks_;ii++) {
1571 L2tmp(ii,ii) = 1./Alphatmp(ii,0);
1572 L2tmp(ii+1,ii) = -1./Alphatmp(ii,0);
1577 Teuchos::SerialDenseMatrix<int,ScalarType> DeltaL2( Teuchos::View, *DeltaL2_, recycleBlocks_, numBlocks_ );
1578 Teuchos::SerialDenseMatrix<int,ScalarType> Deltatmp( Teuchos::View, *Delta_, recycleBlocks_, numBlocks_+1 );
1579 DeltaL2.multiply(Teuchos::NO_TRANS,Teuchos::NO_TRANS,one,Deltatmp,L2tmp,zero);
1580 Teuchos::SerialDenseMatrix<int,ScalarType> AU1TUDeltaL2( Teuchos::View, *AU1TUDeltaL2_, recycleBlocks_, numBlocks_ );
1581 Teuchos::SerialDenseMatrix<int,ScalarType> AU1TUtmp( Teuchos::View, *AU1TU_, recycleBlocks_, recycleBlocks_ );
1582 AU1TUDeltaL2.multiply(Teuchos::NO_TRANS,Teuchos::NO_TRANS,one,AU1TUtmp,DeltaL2,zero);
1583 Teuchos::SerialDenseMatrix<int,ScalarType> Y1( Teuchos::View, *Y_, recycleBlocks_, recycleBlocks_ );
1584 Teuchos::SerialDenseMatrix<int,ScalarType> AU1TAPtmp( Teuchos::View, *AU1TAP_, recycleBlocks_, numBlocks_ );
1585 AU1TAPtmp.putScalar(zero);
1586 AU1TAPtmp.multiply(
Teuchos::TRANS,Teuchos::NO_TRANS,one,Y1,AU1TUDeltaL2,zero);
1587 Teuchos::SerialDenseMatrix<int,ScalarType> Y2( Teuchos::View, *Y_, numBlocks_, recycleBlocks_, recycleBlocks_, 0 );
1588 ScalarType val = dold * (-Betatmp(0,0)/Alphatmp(0,0));
1589 for(
int ii=0;ii<recycleBlocks_;ii++) {
1590 AU1TAPtmp(ii,0) += Y2(numBlocks_-1,ii)*val;
1594 Teuchos::SerialDenseMatrix<int,ScalarType> Y1TAU1TU( Teuchos::View, *GY_, recycleBlocks_, recycleBlocks_ );
1595 Y1TAU1TU.multiply(
Teuchos::TRANS,Teuchos::NO_TRANS,one,Y1,AU1TUtmp,zero);
1596 AU1TUtmp.assign(Y1TAU1TU);
1599 Teuchos::SerialDenseMatrix<int,ScalarType> Ftmp( Teuchos::View, *F_, (numBlocks_+recycleBlocks_), (numBlocks_+recycleBlocks_) );
1600 Teuchos::SerialDenseMatrix<int,ScalarType> F11( Teuchos::View, *F_, recycleBlocks_, recycleBlocks_ );
1601 Teuchos::SerialDenseMatrix<int,ScalarType> F12( Teuchos::View, *F_, recycleBlocks_, numBlocks_, 0, recycleBlocks_ );
1602 Teuchos::SerialDenseMatrix<int,ScalarType> F21( Teuchos::View, *F_, numBlocks_, recycleBlocks_, recycleBlocks_, 0 );
1603 Teuchos::SerialDenseMatrix<int,ScalarType> F22( Teuchos::View, *F_, numBlocks_, numBlocks_, recycleBlocks_, recycleBlocks_ );
1604 Teuchos::SerialDenseMatrix<int,ScalarType> AU1TU1tmp( Teuchos::View, *AU1TU1_, recycleBlocks_, recycleBlocks_ );
1605 F11.assign(AU1TU1tmp);
1606 for(
int ii=0;ii<numBlocks_;ii++) {
1607 F22(ii,ii) = Dtmp(ii,0);
1611 Teuchos::SerialDenseMatrix<int,ScalarType> Gtmp( Teuchos::View, *G_, (numBlocks_+recycleBlocks_), (numBlocks_+recycleBlocks_) );
1612 Teuchos::SerialDenseMatrix<int,ScalarType> G11( Teuchos::View, *G_, recycleBlocks_, recycleBlocks_ );
1613 Teuchos::SerialDenseMatrix<int,ScalarType> G12( Teuchos::View, *G_, recycleBlocks_, numBlocks_, 0, recycleBlocks_ );
1614 Teuchos::SerialDenseMatrix<int,ScalarType> G21( Teuchos::View, *G_, numBlocks_, recycleBlocks_, recycleBlocks_, 0 );
1615 Teuchos::SerialDenseMatrix<int,ScalarType> G22( Teuchos::View, *G_, numBlocks_, numBlocks_, recycleBlocks_, recycleBlocks_ );
1616 Teuchos::SerialDenseMatrix<int,ScalarType> AU1TAU1tmp( Teuchos::View, *AU1TAU1_, recycleBlocks_, recycleBlocks_ );
1617 G11.assign(AU1TAU1tmp);
1618 G12.assign(AU1TAPtmp);
1620 for (
int ii=0;ii<recycleBlocks_;++ii)
1621 for (
int jj=0;jj<numBlocks_;++jj)
1622 G21(jj,ii) = G12(ii,jj);
1623 G22.assign(APTAPtmp);
1626 Teuchos::SerialDenseMatrix<int,ScalarType> Ytmp( Teuchos::View, *Y_, (recycleBlocks_+numBlocks_), recycleBlocks_ );
1627 getHarmonicVecs(Ftmp,Gtmp,Ytmp);
1630 index.resize( numBlocks_ );
1631 for (
int ii=0; ii<numBlocks_; ++ii) { index[ii] = ii+1; }
1633 index.resize( recycleBlocks_ );
1634 for (
int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1636 index.resize( recycleBlocks_ );
1637 for (
int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1639 index.resize( recycleBlocks_ );
1640 for (
int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1649 Teuchos::SerialDenseMatrix<int,ScalarType> GYtmp( Teuchos::View, *GY_, (numBlocks_+recycleBlocks_), recycleBlocks_ );
1650 GYtmp.multiply(Teuchos::NO_TRANS,Teuchos::NO_TRANS,one,Gtmp,Ytmp,zero);
1651 AU1TAU1tmp.multiply(
Teuchos::TRANS,Teuchos::NO_TRANS,one,Ytmp,GYtmp,zero);
1654 Teuchos::SerialDenseMatrix<int,ScalarType> FYtmp( Teuchos::View, *FY_, (numBlocks_+recycleBlocks_), recycleBlocks_ );
1655 FYtmp.multiply(Teuchos::NO_TRANS,Teuchos::NO_TRANS,one,Ftmp,Ytmp,zero);
1656 AU1TU1tmp.multiply(
Teuchos::TRANS,Teuchos::NO_TRANS,one,Ytmp,FYtmp,zero);
1659 dold = Dtmp(numBlocks_-1,0);
1662 lastp = numBlocks_+1;
1663 lastBeta = numBlocks_;
1673 index[0] = lastp-1; index[1] = lastp;
1675 index[0] = 0; index[1] = 1;
1679 (*Beta_)(0,0) = (*Beta_)(lastBeta,0);
1683 Teuchos::SerialDenseMatrix<int,ScalarType> mu1( Teuchos::View, *Delta_, recycleBlocks_, 1, 0, 0 );
1684 Teuchos::SerialDenseMatrix<int,ScalarType> mu2( Teuchos::View, *Delta_, recycleBlocks_, 1, 0, numBlocks_ );
1689 newstate.
P = Teuchos::null;
1690 index.resize( numBlocks_+1 );
1691 for (
int ii=0; ii<(numBlocks_+1); ++ii) { index[ii] = ii+1; }
1694 newstate.
Beta = Teuchos::null;
1695 newstate.
Beta = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( Teuchos::View, *Beta_, numBlocks_, 1, 1, 0 ) );
1697 newstate.
Delta = Teuchos::null;
1698 newstate.
Delta = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( Teuchos::View, *Delta_, recycleBlocks_, numBlocks_, 0, 1 ) );
1703 rcg_iter->initialize(newstate);
1716 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
1717 "Belos::RCGSolMgr::solve(): Invalid return from RCGIter::iterate().");
1720 catch (
const std::exception &e) {
1721 printer_->stream(
Errors) <<
"Error! Caught std::exception in RCGIter::iterate() at iteration " 1722 << rcg_iter->getNumIters() << std::endl
1723 << e.what() << std::endl;
1729 problem_->setCurrLS();
1733 if ( numRHS2Solve > 0 ) {
1736 problem_->setLSIndex( currIdx );
1739 currIdx.resize( numRHS2Solve );
1745 index.resize(recycleBlocks_);
1746 for (
int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1750 if (numRHS2Solve > 0) {
1752 newstate.
P = Teuchos::null;
1753 newstate.
Ap = Teuchos::null;
1754 newstate.
r = Teuchos::null;
1755 newstate.
z = Teuchos::null;
1756 newstate.
U = Teuchos::null;
1757 newstate.
AU = Teuchos::null;
1758 newstate.
Alpha = Teuchos::null;
1759 newstate.
Beta = Teuchos::null;
1760 newstate.
D = Teuchos::null;
1761 newstate.
Delta = Teuchos::null;
1762 newstate.
LUUTAU = Teuchos::null;
1763 newstate.
ipiv = Teuchos::null;
1764 newstate.
rTz_old = Teuchos::null;
1767 index.resize(recycleBlocks_);
1768 for (
int i=0; i<recycleBlocks_; ++i) { index[i] = i; }
1770 index.resize(recycleBlocks_);
1771 for (
int i=0; i<recycleBlocks_; ++i) { index[i] = i; }
1774 problem_->applyOp( *Utmp, *AUtmp );
1776 Teuchos::SerialDenseMatrix<int,ScalarType> UTAUtmp( Teuchos::View, *UTAU_, recycleBlocks_, recycleBlocks_ );
1779 Teuchos::SerialDenseMatrix<int,ScalarType> AUTAUtmp( Teuchos::View, *AUTAU_, recycleBlocks_, recycleBlocks_ );
1780 if ( precObj != Teuchos::null ) {
1781 index.resize(recycleBlocks_);
1782 for (
int i=0; i<recycleBlocks_; ++i) { index[i] = i; }
1783 index.resize(recycleBlocks_);
1784 for (
int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1802 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1807 Teuchos::TimeMonitor::summarize( printer_->stream(TimingDetails) );
1811 numIters_ = maxIterTest_->getNumIters();
1815 using Teuchos::rcp_dynamic_cast;
1818 const std::vector<MagnitudeType>* pTestValues =
1819 rcp_dynamic_cast<conv_test_type>(convTest_)->getTestValue();
1821 TEUCHOS_TEST_FOR_EXCEPTION(pTestValues == NULL, std::logic_error,
1822 "Belos::RCGSolMgr::solve(): The convergence test's getTestValue() " 1823 "method returned NULL. Please report this bug to the Belos developers.");
1825 TEUCHOS_TEST_FOR_EXCEPTION(pTestValues->size() < 1, std::logic_error,
1826 "Belos::RCGSolMgr::solve(): The convergence test's getTestValue() " 1827 "method returned a vector of length zero. Please report this bug to the " 1828 "Belos developers.");
1833 achievedTol_ = *std::max_element (pTestValues->begin(), pTestValues->end());
1843 template<
class ScalarType,
class MV,
class OP>
1845 const Teuchos::SerialDenseMatrix<int,ScalarType>& G,
1846 Teuchos::SerialDenseMatrix<int,ScalarType>& Y) {
1848 int n = F.numCols();
1851 Teuchos::LAPACK<int,ScalarType> lapack;
1854 std::vector<MagnitudeType> w(n);
1857 std::vector<int> iperm(n);
1864 std::vector<ScalarType> work(1);
1868 Teuchos::SerialDenseMatrix<int,ScalarType> F2( Teuchos::Copy, *F_, F_->numRows(), F_->numCols() );
1869 Teuchos::SerialDenseMatrix<int,ScalarType> G2( Teuchos::Copy, *G_, G_->numRows(), G_->numCols() );
1872 lapack.SYGV(itype, jobz, uplo, n, G2.values(), G2.stride(), F2.values(), F2.stride(), &w[0], &work[0], lwork, &info);
1874 "Belos::RCGSolMgr::solve(): LAPACK SYGV failed to query optimal work size.");
1875 lwork = (int)work[0];
1877 lapack.SYGV(itype, jobz, uplo, n, G2.values(), G2.stride(), F2.values(), F2.stride(), &w[0], &work[0], lwork, &info);
1879 "Belos::RCGSolMgr::solve(): LAPACK SYGV failed to compute eigensolutions.");
1883 this->sort(w,n,iperm);
1886 for(
int i=0; i<recycleBlocks_; i++ ) {
1887 for(
int j=0; j<n; j++ ) {
1888 Y(j,i) = G2(j,iperm[i]);
1895 template<
class ScalarType,
class MV,
class OP>
1898 int l, r, j, i, flag;
1927 if (dlist[j] > dlist[j - 1]) j = j + 1;
1929 if (dlist[j - 1] > dK) {
1930 dlist[i - 1] = dlist[j - 1];
1931 iperm[i - 1] = iperm[j - 1];
1944 dlist[r] = dlist[0];
1945 iperm[r] = iperm[0];
1960 template<
class ScalarType,
class MV,
class OP>
1963 std::ostringstream oss;
1964 oss <<
"Belos::RCGSolMgr<...,"<<Teuchos::ScalarTraits<ScalarType>::name()<<
">";
Teuchos::RCP< MV > r
The current residual.
Collection of types and exceptions used within the Belos solvers.
Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > rTz_old
Belos's basic output manager for sending information of select verbosity levels to the appropriate ou...
Teuchos::RCP< MV > P
The current Krylov basis.
Teuchos::RCP< std::vector< int > > ipiv
Data from LU factorization of U^T A U.
Class which manages the output and verbosity of the Belos solvers.
RCGSolMgrRecyclingFailure is thrown when any problem occurs in using/creating the recycling subspace...
ReturnType solve()
This method performs possibly repeated calls to the underlying linear solver's iterate() routine unti...
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const
Get a parameter list containing the current parameters for this object.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Get a parameter list containing the valid parameters for this object.
void reset(const ResetType type)
Performs a reset of the solver manager specified by the ResetType. This informs the solver manager th...
Teuchos::RCP< MV > U
The recycled subspace and its image.
Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > LUUTAU
The LU factorization of the matrix U^T A U.
A factory class for generating StatusTestOutput objects.
The Belos::RCGSolMgr provides a powerful and fully-featured solver manager over the RCG (Recycling Co...
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).
Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > Beta
This class implements the RCG iteration, where a single-std::vector Krylov subspace is constructed...
An implementation of StatusTestResNorm using a family of residual norms.
An extension of the MultiVecTraits class that adds a new vector length method.
Belos::StatusTest class for specifying a maximum number of iterations.
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 .
std::string description() const
Method to return description of the RCG solver manager.
int getNumIters() const
Get the iteration count for the most recent call to solve().
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > ¶ms)
Set the parameters the solver manager should use to solve the linear problem.
static int GetNumberVecs(const MV &mv)
Obtain the number of vectors in mv.
A factory class for generating StatusTestOutput objects.
Iterated Modified Gram-Schmidt (IMGS) implementation of the Belos::OrthoManager class.
static void MvAddMv(const ScalarType alpha, const MV &A, const ScalarType beta, const MV &B, MV &mv)
Replace mv with .
RCGSolMgrLinearProblemFailure(const std::string &what_arg)
RCGSolMgrLinearProblemFailure is thrown when the linear problem is not setup (i.e.
MagnitudeType achievedTol() const
Tolerance achieved by the last solve() invocation.
Traits class which defines basic operations on multivectors.
Belos::StatusTest for logically combining several status tests.
Structure to contain pointers to RCGIter state variables.
Belos concrete class for performing the RCG iteration.
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...
Classical Gram-Schmidt (with DGKS correction) implementation of the Belos::OrthoManager class...
A Belos::StatusTest class for specifying a maximum number of iterations.
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).
static Teuchos::RCP< MV > Clone(const MV &mv, const int numvecs)
Creates a new empty MV containing numvecs columns.
ResetType
How to reset the solver.
bool existU
Flag to indicate the recycle space should be used.
Pure virtual base class which describes the basic interface for a solver manager. ...
Teuchos::RCP< MV > z
The current preconditioned residual.
static void Apply(const OP &Op, const MV &x, MV &y, ETrans trans=NOTRANS)
Apply Op to x, putting the result into y.
Teuchos::RCP< MV > Ap
A times current search vector.
A linear system to solve, and its associated information.
Class which describes the linear problem to be solved by the iterative solver.
bool isLOADetected() const
Return whether a loss of accuracy was detected by this solver during the most current solve...
RCGSolMgr()
Empty constructor for RCGSolMgr. This constructor takes no arguments and sets the default values for ...
ReturnType
Whether the Belos solve converged for all linear systems.
static void MvTimesMatAddMv(const ScalarType alpha, const MV &A, const Teuchos::SerialDenseMatrix< int, ScalarType > &B, const ScalarType beta, MV &mv)
Update mv with .
The Belos::SolverManager is a templated virtual base class that defines the basic interface that any ...
Iterated Classical Gram-Schmidt (ICGS) implementation of the Belos::OrthoManager class.
const LinearProblem< ScalarType, MV, OP > & getProblem() const
Return a reference to the linear problem being solved by this solver manager.
Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > Alpha
Coefficients arising in RCG iteration.
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers for this object.
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.
virtual ~RCGSolMgr()
Destructor.
void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem)
Set the linear problem that needs to be solved.
Belos::StatusTestResNorm for specifying general residual norm stopping criteria.
int curDim
The current dimension of the reduction.
RCGSolMgrLAPACKFailure(const std::string &what_arg)
static ptrdiff_t GetGlobalLength(const MV &mv)
Obtain the vector length of mv.
A class for extending the status testing capabilities of Belos via logical combinations.
Class which defines basic traits for the operator type.
Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > D
Parent class to all Belos exceptions.
RCGSolMgrRecyclingFailure(const std::string &what_arg)
Belos header file which uses auto-configuration information to include necessary C++ headers...
RCGSolMgrLAPACKFailure is thrown when a nonzero value is retuned from an LAPACK call.
Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > Delta
Solutions to local least-squares problems.