Belos  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BelosGmresPolySolMgr.hpp
Go to the documentation of this file.
1 //@HEADER
2 // ************************************************************************
3 //
4 // Belos: Block Linear Solvers Package
5 // Copyright 2004 Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ************************************************************************
40 //@HEADER
41 
42 #ifndef BELOS_GMRES_POLY_SOLMGR_HPP
43 #define BELOS_GMRES_POLY_SOLMGR_HPP
44 
49 #include "BelosConfigDefs.hpp"
50 #include "BelosTypes.hpp"
51 
52 #include "BelosLinearProblem.hpp"
53 #include "BelosSolverManager.hpp"
54 
55 #include "BelosGmresPolyOp.hpp"
56 #include "BelosGmresIteration.hpp"
57 #include "BelosBlockGmresIter.hpp"
64 #include "BelosStatusTestCombo.hpp"
66 #include "BelosOutputManager.hpp"
67 #include "Teuchos_BLAS.hpp"
68 #include "Teuchos_LAPACK.hpp"
69 #include "Teuchos_as.hpp"
70 #ifdef BELOS_TEUCHOS_TIME_MONITOR
71 #include "Teuchos_TimeMonitor.hpp"
72 #endif
73 
87 namespace Belos {
88 
90 
91 
99  GmresPolySolMgrLinearProblemFailure(const std::string& what_arg) : BelosError(what_arg)
100  {}};
101 
109  GmresPolySolMgrPolynomialFailure(const std::string& what_arg) : BelosError(what_arg)
110  {}};
111 
119  GmresPolySolMgrOrthoFailure(const std::string& what_arg) : BelosError(what_arg)
120  {}};
121 
122 template<class ScalarType, class MV, class OP>
123 class GmresPolySolMgr : public SolverManager<ScalarType,MV,OP> {
124 
125 private:
130  typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
132 
133 public:
134 
136 
137 
143  GmresPolySolMgr();
144 
160 
162  virtual ~GmresPolySolMgr() {};
164 
166 
167 
171  return *problem_;
172  }
173 
177 
181 
188  return Teuchos::tuple(timerSolve_, timerPoly_);
189  }
190 
192  int getNumIters() const {
193  return numIters_;
194  }
195 
199  bool isLOADetected() const { return loaDetected_; }
200 
202 
204 
205 
207  void setProblem( const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > &problem ) { problem_ = problem; isSTSet_ = false; }
208 
211 
213 
215 
216 
220  void reset( const ResetType type ) {
221  if ((type & Belos::Problem) && !Teuchos::is_null(problem_)) {
222  problem_->setProblem();
223  isPolyBuilt_ = false; // Rebuild the GMRES polynomial
224  }
225  }
227 
229 
230 
248  ReturnType solve();
249 
251 
254 
256  std::string description() const;
257 
259 
260 private:
261 
262  // Method for checking current status test against defined linear problem.
263  bool checkStatusTest();
264 
265  // Method for generating GMRES polynomial.
266  bool generatePoly();
267 
268  // Linear problem.
270 
271  // Output manager.
273  Teuchos::RCP<std::ostream> outputStream_;
274 
275  // Status test.
279  Teuchos::RCP<StatusTestResNorm<ScalarType,MV,OP> > expConvTest_, impConvTest_;
281 
282  // Orthogonalization manager.
284 
285  // Current parameter list.
287 
288  // Default solver values.
289  static const MagnitudeType polytol_default_;
290  static const MagnitudeType convtol_default_;
291  static const MagnitudeType orthoKappa_default_;
292  static const int maxDegree_default_;
293  static const int maxRestarts_default_;
294  static const int maxIters_default_;
295  static const bool strictConvTol_default_;
296  static const bool showMaxResNormOnly_default_;
297  static const int blockSize_default_;
298  static const int numBlocks_default_;
299  static const int verbosity_default_;
300  static const int outputStyle_default_;
301  static const int outputFreq_default_;
302  static const std::string impResScale_default_;
303  static const std::string expResScale_default_;
304  static const std::string label_default_;
305  static const std::string orthoType_default_;
306  static const Teuchos::RCP<std::ostream> outputStream_default_;
307 
308  // Current solver values.
309  MagnitudeType polytol_, convtol_, orthoKappa_;
310  int maxDegree_, maxRestarts_, maxIters_, numIters_;
311  int blockSize_, numBlocks_, verbosity_, outputStyle_, outputFreq_;
312  bool strictConvTol_, showMaxResNormOnly_;
313  std::string orthoType_;
314  std::string impResScale_, expResScale_;
315 
316  // Polynomial storage
317  int poly_dim_;
321 
322  // Timers.
323  std::string label_;
324  Teuchos::RCP<Teuchos::Time> timerSolve_, timerPoly_;
325 
326  // Internal state variables.
327  bool isPolyBuilt_;
328  bool isSet_, isSTSet_, expResTest_;
329  bool loaDetected_;
330 };
331 
332 
333 // Default solver values.
334 template<class ScalarType, class MV, class OP>
335 const typename GmresPolySolMgr<ScalarType,MV,OP>::MagnitudeType GmresPolySolMgr<ScalarType,MV,OP>::polytol_default_ = 1e-12;
336 
337 template<class ScalarType, class MV, class OP>
338 const typename GmresPolySolMgr<ScalarType,MV,OP>::MagnitudeType GmresPolySolMgr<ScalarType,MV,OP>::convtol_default_ = 1e-8;
339 
340 template<class ScalarType, class MV, class OP>
341 const typename GmresPolySolMgr<ScalarType,MV,OP>::MagnitudeType GmresPolySolMgr<ScalarType,MV,OP>::orthoKappa_default_ = -1.0;
342 
343 template<class ScalarType, class MV, class OP>
344 const int GmresPolySolMgr<ScalarType,MV,OP>::maxDegree_default_ = 25;
345 
346 template<class ScalarType, class MV, class OP>
347 const int GmresPolySolMgr<ScalarType,MV,OP>::maxRestarts_default_ = 20;
348 
349 template<class ScalarType, class MV, class OP>
350 const int GmresPolySolMgr<ScalarType,MV,OP>::maxIters_default_ = 1000;
351 
352 template<class ScalarType, class MV, class OP>
353 const bool GmresPolySolMgr<ScalarType,MV,OP>::strictConvTol_default_ = false;
354 
355 template<class ScalarType, class MV, class OP>
356 const bool GmresPolySolMgr<ScalarType,MV,OP>::showMaxResNormOnly_default_ = false;
357 
358 template<class ScalarType, class MV, class OP>
359 const int GmresPolySolMgr<ScalarType,MV,OP>::blockSize_default_ = 1;
360 
361 template<class ScalarType, class MV, class OP>
362 const int GmresPolySolMgr<ScalarType,MV,OP>::numBlocks_default_ = 300;
363 
364 template<class ScalarType, class MV, class OP>
365 const int GmresPolySolMgr<ScalarType,MV,OP>::verbosity_default_ = Belos::Errors;
366 
367 template<class ScalarType, class MV, class OP>
368 const int GmresPolySolMgr<ScalarType,MV,OP>::outputStyle_default_ = Belos::General;
369 
370 template<class ScalarType, class MV, class OP>
371 const int GmresPolySolMgr<ScalarType,MV,OP>::outputFreq_default_ = -1;
372 
373 template<class ScalarType, class MV, class OP>
374 const std::string GmresPolySolMgr<ScalarType,MV,OP>::impResScale_default_ = "Norm of RHS";
375 
376 template<class ScalarType, class MV, class OP>
377 const std::string GmresPolySolMgr<ScalarType,MV,OP>::expResScale_default_ = "Norm of RHS";
378 
379 template<class ScalarType, class MV, class OP>
380 const std::string GmresPolySolMgr<ScalarType,MV,OP>::label_default_ = "Belos";
381 
382 template<class ScalarType, class MV, class OP>
383 const std::string GmresPolySolMgr<ScalarType,MV,OP>::orthoType_default_ = "DGKS";
384 
385 template<class ScalarType, class MV, class OP>
386 const Teuchos::RCP<std::ostream> GmresPolySolMgr<ScalarType,MV,OP>::outputStream_default_ = Teuchos::rcp(&std::cout,false);
387 
388 
389 // Empty Constructor
390 template<class ScalarType, class MV, class OP>
392  outputStream_(outputStream_default_),
393  polytol_(polytol_default_),
394  convtol_(convtol_default_),
395  orthoKappa_(orthoKappa_default_),
396  maxDegree_(maxDegree_default_),
397  maxRestarts_(maxRestarts_default_),
398  maxIters_(maxIters_default_),
399  blockSize_(blockSize_default_),
400  numBlocks_(numBlocks_default_),
401  verbosity_(verbosity_default_),
402  outputStyle_(outputStyle_default_),
403  outputFreq_(outputFreq_default_),
404  strictConvTol_(strictConvTol_default_),
405  showMaxResNormOnly_(showMaxResNormOnly_default_),
406  orthoType_(orthoType_default_),
407  impResScale_(impResScale_default_),
408  expResScale_(expResScale_default_),
409  label_(label_default_),
410  isPolyBuilt_(false),
411  isSet_(false),
412  isSTSet_(false),
413  expResTest_(false),
414  loaDetected_(false)
415 {}
416 
417 
418 // Basic Constructor
419 template<class ScalarType, class MV, class OP>
423  problem_(problem),
424  outputStream_(outputStream_default_),
425  polytol_(polytol_default_),
426  convtol_(convtol_default_),
427  orthoKappa_(orthoKappa_default_),
428  maxDegree_(maxDegree_default_),
429  maxRestarts_(maxRestarts_default_),
430  maxIters_(maxIters_default_),
431  blockSize_(blockSize_default_),
432  numBlocks_(numBlocks_default_),
433  verbosity_(verbosity_default_),
434  outputStyle_(outputStyle_default_),
435  outputFreq_(outputFreq_default_),
436  strictConvTol_(strictConvTol_default_),
437  showMaxResNormOnly_(showMaxResNormOnly_default_),
438  orthoType_(orthoType_default_),
439  impResScale_(impResScale_default_),
440  expResScale_(expResScale_default_),
441  label_(label_default_),
442  isPolyBuilt_(false),
443  isSet_(false),
444  isSTSet_(false),
445  expResTest_(false),
446  loaDetected_(false)
447 {
448 
449  TEUCHOS_TEST_FOR_EXCEPTION(problem_ == Teuchos::null, std::invalid_argument, "Problem not given to solver manager.");
450 
451  // If the parameter list pointer is null, then set the current parameters to the default parameter list.
452  if ( !is_null(pl) ) {
453  setParameters( pl );
454  }
455 
456 }
457 
458 
459 template<class ScalarType, class MV, class OP>
462 {
464  if (is_null(validPL)) {
465  Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
466  pl->set("Polynomial Tolerance", polytol_default_,
467  "The relative residual tolerance that used to construct the GMRES polynomial.");
468  pl->set("Maximum Degree", maxDegree_default_,
469  "The maximum degree allowed for any GMRES polynomial.");
470  pl->set("Convergence Tolerance", convtol_default_,
471  "The relative residual tolerance that needs to be achieved by the\n"
472  "iterative solver in order for the linear system to be declared converged." );
473  pl->set("Maximum Restarts", maxRestarts_default_,
474  "The maximum number of restarts allowed for each\n"
475  "set of RHS solved.");
476  pl->set("Maximum Iterations", maxIters_default_,
477  "The maximum number of block iterations allowed for each\n"
478  "set of RHS solved.");
479  pl->set("Num Blocks", numBlocks_default_,
480  "The maximum number of blocks allowed in the Krylov subspace\n"
481  "for each set of RHS solved.");
482  pl->set("Block Size", blockSize_default_,
483  "The number of vectors in each block. This number times the\n"
484  "number of blocks is the total Krylov subspace dimension.");
485  pl->set("Verbosity", verbosity_default_,
486  "What type(s) of solver information should be outputted\n"
487  "to the output stream.");
488  pl->set("Output Style", outputStyle_default_,
489  "What style is used for the solver information outputted\n"
490  "to the output stream.");
491  pl->set("Output Frequency", outputFreq_default_,
492  "How often convergence information should be outputted\n"
493  "to the output stream.");
494  pl->set("Output Stream", outputStream_default_,
495  "A reference-counted pointer to the output stream where all\n"
496  "solver output is sent.");
497  pl->set("Strict Convergence", strictConvTol_default_,
498  "After polynomial is applied, whether solver should try to achieve\n"
499  "the relative residual tolerance.");
500  pl->set("Show Maximum Residual Norm Only", showMaxResNormOnly_default_,
501  "When convergence information is printed, only show the maximum\n"
502  "relative residual norm when the block size is greater than one.");
503  pl->set("Implicit Residual Scaling", impResScale_default_,
504  "The type of scaling used in the implicit residual convergence test.");
505  pl->set("Explicit Residual Scaling", expResScale_default_,
506  "The type of scaling used in the explicit residual convergence test.");
507  pl->set("Timer Label", label_default_,
508  "The string to use as a prefix for the timer labels.");
509  // pl->set("Restart Timers", restartTimers_);
510  pl->set("Orthogonalization", orthoType_default_,
511  "The type of orthogonalization to use: DGKS, ICGS, or IMGS.");
512  pl->set("Orthogonalization Constant",orthoKappa_default_,
513  "The constant used by DGKS orthogonalization to determine\n"
514  "whether another step of classical Gram-Schmidt is necessary.");
515  validPL = pl;
516  }
517  return validPL;
518 }
519 
520 
521 template<class ScalarType, class MV, class OP>
523 {
524 
525  // Create the internal parameter list if ones doesn't already exist.
526  if (params_ == Teuchos::null) {
527  params_ = Teuchos::rcp( new Teuchos::ParameterList(*getValidParameters()) );
528  }
529  else {
530  params->validateParameters(*getValidParameters());
531  }
532 
533  // Check for maximum polynomial degree
534  if (params->isParameter("Maximum Degree")) {
535  maxDegree_ = params->get("Maximum Degree",maxDegree_default_);
536 
537  // Update parameter in our list.
538  params_->set("Maximum Degree", maxDegree_);
539  }
540 
541  // Check for maximum number of restarts
542  if (params->isParameter("Maximum Restarts")) {
543  maxRestarts_ = params->get("Maximum Restarts",maxRestarts_default_);
544 
545  // Update parameter in our list.
546  params_->set("Maximum Restarts", maxRestarts_);
547  }
548 
549  // Check for maximum number of iterations
550  if (params->isParameter("Maximum Iterations")) {
551  maxIters_ = params->get("Maximum Iterations",maxIters_default_);
552 
553  // Update parameter in our list and in status test.
554  params_->set("Maximum Iterations", maxIters_);
555  if (maxIterTest_!=Teuchos::null)
556  maxIterTest_->setMaxIters( maxIters_ );
557  }
558 
559  // Check for blocksize
560  if (params->isParameter("Block Size")) {
561  blockSize_ = params->get("Block Size",blockSize_default_);
562  TEUCHOS_TEST_FOR_EXCEPTION(blockSize_ <= 0, std::invalid_argument,
563  "Belos::GmresPolySolMgr: \"Block Size\" must be strictly positive.");
564 
565  // Update parameter in our list.
566  params_->set("Block Size", blockSize_);
567  }
568 
569  // Check for the maximum number of blocks.
570  if (params->isParameter("Num Blocks")) {
571  numBlocks_ = params->get("Num Blocks",numBlocks_default_);
572  TEUCHOS_TEST_FOR_EXCEPTION(numBlocks_ <= 0, std::invalid_argument,
573  "Belos::GmresPolySolMgr: \"Num Blocks\" must be strictly positive.");
574 
575  // Update parameter in our list.
576  params_->set("Num Blocks", numBlocks_);
577  }
578 
579  // Check to see if the timer label changed.
580  if (params->isParameter("Timer Label")) {
581  std::string tempLabel = params->get("Timer Label", label_default_);
582 
583  // Update parameter in our list and solver timer
584  if (tempLabel != label_) {
585  label_ = tempLabel;
586  params_->set("Timer Label", label_);
587  std::string solveLabel = label_ + ": GmresPolySolMgr total solve time";
588 #ifdef BELOS_TEUCHOS_TIME_MONITOR
589  timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
590 #endif
591  std::string polyLabel = label_ + ": GmresPolySolMgr polynomial creation time";
592 #ifdef BELOS_TEUCHOS_TIME_MONITOR
593  timerPoly_ = Teuchos::TimeMonitor::getNewCounter(polyLabel);
594 #endif
595  if (ortho_ != Teuchos::null) {
596  ortho_->setLabel( label_ );
597  }
598  }
599  }
600 
601  // Check if the orthogonalization changed.
602  if (params->isParameter("Orthogonalization")) {
603  std::string tempOrthoType = params->get("Orthogonalization",orthoType_default_);
604  TEUCHOS_TEST_FOR_EXCEPTION( tempOrthoType != "DGKS" && tempOrthoType != "ICGS" && tempOrthoType != "IMGS",
605  std::invalid_argument,
606  "Belos::GmresPolySolMgr: \"Orthogonalization\" must be either \"DGKS\", \"ICGS\", or \"IMGS\".");
607  if (tempOrthoType != orthoType_) {
608  orthoType_ = tempOrthoType;
609  // Create orthogonalization manager
610  if (orthoType_=="DGKS") {
611  if (orthoKappa_ <= 0) {
612  ortho_ = Teuchos::rcp( new DGKSOrthoManager<ScalarType,MV,OP>( label_ ) );
613  }
614  else {
615  ortho_ = Teuchos::rcp( new DGKSOrthoManager<ScalarType,MV,OP>( label_ ) );
616  Teuchos::rcp_dynamic_cast<DGKSOrthoManager<ScalarType,MV,OP> >(ortho_)->setDepTol( orthoKappa_ );
617  }
618  }
619  else if (orthoType_=="ICGS") {
620  ortho_ = Teuchos::rcp( new ICGSOrthoManager<ScalarType,MV,OP>( label_ ) );
621  }
622  else if (orthoType_=="IMGS") {
623  ortho_ = Teuchos::rcp( new IMGSOrthoManager<ScalarType,MV,OP>( label_ ) );
624  }
625  }
626  }
627 
628  // Check which orthogonalization constant to use.
629  if (params->isParameter("Orthogonalization Constant")) {
630  orthoKappa_ = params->get("Orthogonalization Constant",orthoKappa_default_);
631 
632  // Update parameter in our list.
633  params_->set("Orthogonalization Constant",orthoKappa_);
634  if (orthoType_=="DGKS") {
635  if (orthoKappa_ > 0 && ortho_ != Teuchos::null) {
636  Teuchos::rcp_dynamic_cast<DGKSOrthoManager<ScalarType,MV,OP> >(ortho_)->setDepTol( orthoKappa_ );
637  }
638  }
639  }
640 
641  // Check for a change in verbosity level
642  if (params->isParameter("Verbosity")) {
643  if (Teuchos::isParameterType<int>(*params,"Verbosity")) {
644  verbosity_ = params->get("Verbosity", verbosity_default_);
645  } else {
646  verbosity_ = (int)Teuchos::getParameter<Belos::MsgType>(*params,"Verbosity");
647  }
648 
649  // Update parameter in our list.
650  params_->set("Verbosity", verbosity_);
651  if (printer_ != Teuchos::null)
652  printer_->setVerbosity(verbosity_);
653  }
654 
655  // Check for a change in output style
656  if (params->isParameter("Output Style")) {
657  if (Teuchos::isParameterType<int>(*params,"Output Style")) {
658  outputStyle_ = params->get("Output Style", outputStyle_default_);
659  } else {
660  outputStyle_ = (int)Teuchos::getParameter<Belos::OutputType>(*params,"Output Style");
661  }
662 
663  // Reconstruct the convergence test if the explicit residual test is not being used.
664  params_->set("Output Style", outputStyle_);
665  if (outputTest_ != Teuchos::null) {
666  isSTSet_ = false;
667  }
668  }
669 
670  // output stream
671  if (params->isParameter("Output Stream")) {
672  outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params,"Output Stream");
673 
674  // Update parameter in our list.
675  params_->set("Output Stream", outputStream_);
676  if (printer_ != Teuchos::null)
677  printer_->setOStream( outputStream_ );
678  }
679 
680  // frequency level
681  if (verbosity_ & Belos::StatusTestDetails) {
682  if (params->isParameter("Output Frequency")) {
683  outputFreq_ = params->get("Output Frequency", outputFreq_default_);
684  }
685 
686  // Update parameter in out list and output status test.
687  params_->set("Output Frequency", outputFreq_);
688  if (outputTest_ != Teuchos::null)
689  outputTest_->setOutputFrequency( outputFreq_ );
690  }
691 
692  // Create output manager if we need to.
693  if (printer_ == Teuchos::null) {
694  printer_ = Teuchos::rcp( new OutputManager<ScalarType>(verbosity_, outputStream_) );
695  }
696 
697  // Convergence
698  typedef Belos::StatusTestCombo<ScalarType,MV,OP> StatusTestCombo_t;
699  typedef Belos::StatusTestGenResNorm<ScalarType,MV,OP> StatusTestResNorm_t;
700 
701  // Check for polynomial convergence tolerance
702  if (params->isParameter("Polynomial Tolerance")) {
703  polytol_ = params->get("Polynomial Tolerance",polytol_default_);
704 
705  // Update parameter in our list and residual tests.
706  params_->set("Polynomial Tolerance", polytol_);
707  }
708 
709  // Check for convergence tolerance
710  if (params->isParameter("Convergence Tolerance")) {
711  convtol_ = params->get("Convergence Tolerance",convtol_default_);
712 
713  // Update parameter in our list and residual tests.
714  params_->set("Convergence Tolerance", convtol_);
715  if (impConvTest_ != Teuchos::null)
716  impConvTest_->setTolerance( convtol_ );
717  if (expConvTest_ != Teuchos::null)
718  expConvTest_->setTolerance( convtol_ );
719  }
720 
721  // Check if user requires solver to reach convergence tolerance
722  if (params->isParameter("Strict Convergence")) {
723  strictConvTol_ = params->get("Strict Convergence",strictConvTol_default_);
724 
725  // Update parameter in our list and residual tests
726  params_->set("Strict Convergence", strictConvTol_);
727  }
728 
729  // Check for a change in scaling, if so we need to build new residual tests.
730  if (params->isParameter("Implicit Residual Scaling")) {
731  std::string tempImpResScale = Teuchos::getParameter<std::string>( *params, "Implicit Residual Scaling" );
732 
733  // Only update the scaling if it's different.
734  if (impResScale_ != tempImpResScale) {
735  Belos::ScaleType impResScaleType = convertStringToScaleType( tempImpResScale );
736  impResScale_ = tempImpResScale;
737 
738  // Update parameter in our list and residual tests
739  params_->set("Implicit Residual Scaling", impResScale_);
740  if (impConvTest_ != Teuchos::null) {
741  try {
742  impConvTest_->defineScaleForm( impResScaleType, Belos::TwoNorm );
743  }
744  catch (std::exception& e) {
745  // Make sure the convergence test gets constructed again.
746  isSTSet_ = false;
747  }
748  }
749  }
750  }
751 
752  if (params->isParameter("Explicit Residual Scaling")) {
753  std::string tempExpResScale = Teuchos::getParameter<std::string>( *params, "Explicit Residual Scaling" );
754 
755  // Only update the scaling if it's different.
756  if (expResScale_ != tempExpResScale) {
757  Belos::ScaleType expResScaleType = convertStringToScaleType( tempExpResScale );
758  expResScale_ = tempExpResScale;
759 
760  // Update parameter in our list and residual tests
761  params_->set("Explicit Residual Scaling", expResScale_);
762  if (expConvTest_ != Teuchos::null) {
763  try {
764  expConvTest_->defineScaleForm( expResScaleType, Belos::TwoNorm );
765  }
766  catch (std::exception& e) {
767  // Make sure the convergence test gets constructed again.
768  isSTSet_ = false;
769  }
770  }
771  }
772  }
773 
774 
775  if (params->isParameter("Show Maximum Residual Norm Only")) {
776  showMaxResNormOnly_ = Teuchos::getParameter<bool>(*params,"Show Maximum Residual Norm Only");
777 
778  // Update parameter in our list and residual tests
779  params_->set("Show Maximum Residual Norm Only", showMaxResNormOnly_);
780  if (impConvTest_ != Teuchos::null)
781  impConvTest_->setShowMaxResNormOnly( showMaxResNormOnly_ );
782  if (expConvTest_ != Teuchos::null)
783  expConvTest_->setShowMaxResNormOnly( showMaxResNormOnly_ );
784  }
785 
786  // Create orthogonalization manager if we need to.
787  if (ortho_ == Teuchos::null) {
788  if (orthoType_=="DGKS") {
789  if (orthoKappa_ <= 0) {
790  ortho_ = Teuchos::rcp( new DGKSOrthoManager<ScalarType,MV,OP>( label_ ) );
791  }
792  else {
793  ortho_ = Teuchos::rcp( new DGKSOrthoManager<ScalarType,MV,OP>( label_ ) );
794  Teuchos::rcp_dynamic_cast<DGKSOrthoManager<ScalarType,MV,OP> >(ortho_)->setDepTol( orthoKappa_ );
795  }
796  }
797  else if (orthoType_=="ICGS") {
798  ortho_ = Teuchos::rcp( new ICGSOrthoManager<ScalarType,MV,OP>( label_ ) );
799  }
800  else if (orthoType_=="IMGS") {
801  ortho_ = Teuchos::rcp( new IMGSOrthoManager<ScalarType,MV,OP>( label_ ) );
802  }
803  else {
804  TEUCHOS_TEST_FOR_EXCEPTION(orthoType_!="ICGS"&&orthoType_!="DGKS"&&orthoType_!="IMGS",std::logic_error,
805  "Belos::GmresPolySolMgr(): Invalid orthogonalization type.");
806  }
807  }
808 
809  // Create the timers if we need to.
810  if (timerSolve_ == Teuchos::null) {
811  std::string solveLabel = label_ + ": GmresPolySolMgr total solve time";
812 #ifdef BELOS_TEUCHOS_TIME_MONITOR
813  timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
814 #endif
815  }
816 
817  if (timerPoly_ == Teuchos::null) {
818  std::string polyLabel = label_ + ": GmresPolySolMgr polynomial creation time";
819 #ifdef BELOS_TEUCHOS_TIME_MONITOR
820  timerPoly_ = Teuchos::TimeMonitor::getNewCounter(polyLabel);
821 #endif
822  }
823 
824  // Inform the solver manager that the current parameters were set.
825  isSet_ = true;
826 }
827 
828 // Check the status test versus the defined linear problem
829 template<class ScalarType, class MV, class OP>
831 
832  typedef Belos::StatusTestCombo<ScalarType,MV,OP> StatusTestCombo_t;
833  typedef Belos::StatusTestGenResNorm<ScalarType,MV,OP> StatusTestGenResNorm_t;
834  typedef Belos::StatusTestImpResNorm<ScalarType,MV,OP> StatusTestImpResNorm_t;
835 
836  // Basic test checks maximum iterations and native residual.
837  maxIterTest_ = Teuchos::rcp( new StatusTestMaxIters<ScalarType,MV,OP>( maxIters_ ) );
838 
839  // If there is a left preconditioner, we create a combined status test that checks the implicit
840  // and then explicit residual norm to see if we have convergence.
841  if (!Teuchos::is_null(problem_->getLeftPrec())) {
842  expResTest_ = true;
843  }
844 
845  if (expResTest_) {
846 
847  // Implicit residual test, using the native residual to determine if convergence was achieved.
848  Teuchos::RCP<StatusTestGenResNorm_t> tmpImpConvTest =
849  Teuchos::rcp( new StatusTestGenResNorm_t( convtol_ ) );
850  tmpImpConvTest->defineScaleForm( convertStringToScaleType(impResScale_), Belos::TwoNorm );
851  tmpImpConvTest->setShowMaxResNormOnly( showMaxResNormOnly_ );
852  impConvTest_ = tmpImpConvTest;
853 
854  // Explicit residual test once the native residual is below the tolerance
855  Teuchos::RCP<StatusTestGenResNorm_t> tmpExpConvTest =
856  Teuchos::rcp( new StatusTestGenResNorm_t( convtol_ ) );
857  tmpExpConvTest->defineResForm( StatusTestGenResNorm_t::Explicit, Belos::TwoNorm );
858  tmpExpConvTest->defineScaleForm( convertStringToScaleType(expResScale_), Belos::TwoNorm );
859  tmpExpConvTest->setShowMaxResNormOnly( showMaxResNormOnly_ );
860  expConvTest_ = tmpExpConvTest;
861 
862  // The convergence test is a combination of the "cheap" implicit test and explicit test.
863  convTest_ = Teuchos::rcp( new StatusTestCombo_t( StatusTestCombo_t::SEQ, impConvTest_, expConvTest_ ) );
864  }
865  else {
866 
867  // Implicit residual test, using the native residual to determine if convergence was achieved.
868  // Use test that checks for loss of accuracy.
869  Teuchos::RCP<StatusTestImpResNorm_t> tmpImpConvTest =
870  Teuchos::rcp( new StatusTestImpResNorm_t( convtol_ ) );
871  tmpImpConvTest->defineScaleForm( convertStringToScaleType(impResScale_), Belos::TwoNorm );
872  tmpImpConvTest->setShowMaxResNormOnly( showMaxResNormOnly_ );
873  impConvTest_ = tmpImpConvTest;
874 
875  // Set the explicit and total convergence test to this implicit test that checks for accuracy loss.
876  expConvTest_ = impConvTest_;
877  convTest_ = impConvTest_;
878  }
879 
880  sTest_ = Teuchos::rcp( new StatusTestCombo_t( StatusTestCombo_t::OR, maxIterTest_, convTest_ ) );
881 
882  // Create the status test output class.
883  // This class manages and formats the output from the status test.
884  StatusTestOutputFactory<ScalarType,MV,OP> stoFactory( outputStyle_ );
885  outputTest_ = stoFactory.create( printer_, sTest_, outputFreq_, Passed+Failed+Undefined );
886 
887  // Set the solver string for the output test
888  std::string solverDesc = " Gmres Polynomial ";
889  outputTest_->setSolverDesc( solverDesc );
890 
891 
892  // The status test is now set.
893  isSTSet_ = true;
894 
895  return false;
896 }
897 
898 template<class ScalarType, class MV, class OP>
899 bool GmresPolySolMgr<ScalarType,MV,OP>::generatePoly()
900 {
901  // Create a copy of the linear problem that has a zero initial guess and random RHS.
902  Teuchos::RCP<MV> newX = MVT::Clone( *(problem_->getLHS()), 1 );
903  Teuchos::RCP<MV> newB = MVT::Clone( *(problem_->getRHS()), 1 );
904  MVT::MvInit( *newX, SCT::zero() );
905  MVT::MvRandom( *newB );
907  Teuchos::rcp( new LinearProblem<ScalarType,MV,OP>( problem_->getOperator(), newX, newB ) );
908  newProblem->setLeftPrec( problem_->getLeftPrec() );
909  newProblem->setRightPrec( problem_->getRightPrec() );
910  newProblem->setLabel("Belos GMRES Poly Generation");
911  newProblem->setProblem();
912  std::vector<int> idx(1,0); // Must set the index to be the first vector (0)!
913  newProblem->setLSIndex( idx );
914 
915  // Create a parameter list for the GMRES iteration.
916  Teuchos::ParameterList polyList;
917 
918  // Tell the block solver that the block size is one.
919  polyList.set("Num Blocks",maxDegree_);
920  polyList.set("Block Size",1);
921  polyList.set("Keep Hessenberg", true);
922 
923  // Create a simple status test that either reaches the relative residual tolerance or maximum polynomial size.
925  Teuchos::rcp( new StatusTestMaxIters<ScalarType,MV,OP>( maxDegree_ ) );
926 
927  // Implicit residual test, using the native residual to determine if convergence was achieved.
929  Teuchos::rcp( new StatusTestGenResNorm<ScalarType,MV,OP>( polytol_ ) );
930  convTst->defineScaleForm( convertStringToScaleType(impResScale_), Belos::TwoNorm );
931 
932  // Convergence test that stops the iteration when either are satisfied.
934  Teuchos::rcp( new StatusTestCombo<ScalarType,MV,OP>( StatusTestCombo<ScalarType,MV,OP>::OR, maxItrTst, convTst ) );
935 
936  // Create Gmres iteration object to perform one cycle of Gmres.
938  gmres_iter = Teuchos::rcp( new BlockGmresIter<ScalarType,MV,OP>(newProblem,printer_,polyTest,ortho_,polyList) );
939 
940  // Create the first block in the current Krylov basis (residual).
941  Teuchos::RCP<MV> V_0 = MVT::Clone( *(newProblem->getRHS()), 1 );
942  newProblem->computeCurrPrecResVec( &*V_0 );
943 
944  // Get a matrix to hold the orthonormalization coefficients.
946 
947  // Orthonormalize the new V_0
948  int rank = ortho_->normalize( *V_0, poly_r0_ );
949  TEUCHOS_TEST_FOR_EXCEPTION(rank != 1,GmresPolySolMgrOrthoFailure,
950  "Belos::GmresPolySolMgr::generatePoly(): Failed to compute initial block of orthonormal vectors for polynomial generation.");
951 
952  // Set the new state and initialize the solver.
953  GmresIterationState<ScalarType,MV> newstate;
954  newstate.V = V_0;
955  newstate.z = poly_r0_;
956  newstate.curDim = 0;
957  gmres_iter->initializeGmres(newstate);
958 
959  // Perform Gmres iteration
960  bool polyConverged = false;
961  try {
962  gmres_iter->iterate();
963 
964  // Check convergence first
965  if ( convTst->getStatus() == Passed ) {
966  // we have convergence
967  polyConverged = true;
968  }
969  }
970  catch (GmresIterationOrthoFailure e) {
971  // Try to recover the most recent least-squares solution
972  gmres_iter->updateLSQR( gmres_iter->getCurSubspaceDim() );
973 
974  // Check to see if the most recent least-squares solution yielded convergence.
975  polyTest->checkStatus( &*gmres_iter );
976  if (convTst->getStatus() == Passed)
977  polyConverged = true;
978  }
979  catch (std::exception e) {
980  printer_->stream(Errors) << "Error! Caught exception in BlockGmresIter::iterate() at iteration "
981  << gmres_iter->getNumIters() << std::endl
982  << e.what() << std::endl;
983  throw;
984  }
985 
986  // FIXME (mfh 27 Apr 2013) Why aren't we using polyConverged after
987  // setting it? I'm tired of the compile warning so I'll silence it
988  // here, but I'm curious why we aren't using the variable.
989  (void) polyConverged;
990 
991  // Get the solution for this polynomial, use in comparison below
992  Teuchos::RCP<MV> currX = gmres_iter->getCurrentUpdate();
993 
994  // Record polynomial info, get current GMRES state
995  GmresIterationState<ScalarType,MV> gmresState = gmres_iter->getState();
996 
997  // If the polynomial has no dimension, the tolerance is too low, return false
998  poly_dim_ = gmresState.curDim;
999  if (poly_dim_ == 0) {
1000  return false;
1001  }
1002  //
1003  // Make a view and then copy the RHS of the least squares problem.
1004  //
1005  poly_y_ = Teuchos::rcp( new Teuchos::SerialDenseMatrix<int,ScalarType>( Teuchos::Copy, *gmresState.z, poly_dim_, 1 ) );
1006  poly_H_ = Teuchos::rcp( new Teuchos::SerialDenseMatrix<int,ScalarType>( *gmresState.H ) );
1007  //
1008  // Solve the least squares problem.
1009  //
1010  const ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
1013  Teuchos::NON_UNIT_DIAG, poly_dim_, 1, one,
1014  gmresState.R->values(), gmresState.R->stride(),
1015  poly_y_->values(), poly_y_->stride() );
1016  //
1017  // Generate the polynomial operator
1018  //
1019  poly_Op_ = Teuchos::rcp(
1020  new Belos::GmresPolyOp<ScalarType,MV,OP>( problem_, poly_H_, poly_y_, poly_r0_ ) );
1021 
1022  return true;
1023 }
1024 
1025 // solve()
1026 template<class ScalarType, class MV, class OP>
1028 
1029  // Set the current parameters if they were not set before.
1030  // NOTE: This may occur if the user generated the solver manager with the default constructor and
1031  // then didn't set any parameters using setParameters().
1032  if (!isSet_) {
1033  setParameters(Teuchos::parameterList(*getValidParameters()));
1034  }
1035 
1038 
1040  "Belos::GmresPolySolMgr::solve(): Linear problem is not a valid object.");
1041 
1043  "Belos::GmresPolySolMgr::solve(): Linear problem is not ready, setProblem() has not been called.");
1044 
1045  if (!isSTSet_ || (!expResTest_ && !Teuchos::is_null(problem_->getLeftPrec())) ) {
1047  "Belos::GmresPolySolMgr::solve(): Linear problem and requested status tests are incompatible.");
1048  }
1049 
1050  // If the GMRES polynomial has not been constructed for this matrix, preconditioner pair, generate it
1051  if (!isPolyBuilt_) {
1052 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1053  Teuchos::TimeMonitor slvtimer(*timerPoly_);
1054 #endif
1055  isPolyBuilt_ = generatePoly();
1056  TEUCHOS_TEST_FOR_EXCEPTION( !isPolyBuilt_ && poly_dim_==0, GmresPolySolMgrPolynomialFailure,
1057  "Belos::GmresPolySolMgr::generatePoly(): Failed to generate a non-trivial polynomial, reduce polynomial tolerance.");
1059  "Belos::GmresPolySolMgr::generatePoly(): Failed to generate polynomial that satisfied requirements.");
1060  }
1061 
1062  // Assume convergence is achieved if user does not require strict convergence.
1063  bool isConverged = true;
1064 
1065  // Solve the linear system using the polynomial
1066  {
1067 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1068  Teuchos::TimeMonitor slvtimer(*timerSolve_);
1069 #endif
1070 
1071  // Apply the polynomial to the current linear system
1072  poly_Op_->Apply( *problem_->getRHS(), *problem_->getLHS() );
1073 
1074  // Reset the problem to acknowledge the updated solution
1075  problem_->setProblem();
1076 
1077  // If we have to strictly adhere to the requested convergence tolerance, set up a standard GMRES solver.
1078  if (strictConvTol_) {
1079 
1080  // Create indices for the linear systems to be solved.
1081  int startPtr = 0;
1082  int numRHS2Solve = MVT::GetNumberVecs( *(problem_->getRHS()) );
1083  int numCurrRHS = ( numRHS2Solve < blockSize_) ? numRHS2Solve : blockSize_;
1084 
1085  std::vector<int> currIdx;
1086  // If an adaptive block size is allowed then only the linear systems that need to be solved are solved.
1087  // Otherwise, the index set is generated that informs the linear problem that some linear systems are augmented.
1088  currIdx.resize( blockSize_ );
1089  for (int i=0; i<numCurrRHS; ++i)
1090  { currIdx[i] = startPtr+i; }
1091  for (int i=numCurrRHS; i<blockSize_; ++i)
1092  { currIdx[i] = -1; }
1093 
1094  // Inform the linear problem of the current linear system to solve.
1095  problem_->setLSIndex( currIdx );
1096 
1098  // Parameter list
1099  Teuchos::ParameterList plist;
1100  plist.set("Block Size",blockSize_);
1101 
1102  ptrdiff_t dim = MVText::GetGlobalLength( *(problem_->getRHS()) );
1103  if (blockSize_*static_cast<ptrdiff_t>(numBlocks_) > dim) {
1104  ptrdiff_t tmpNumBlocks = 0;
1105  if (blockSize_ == 1)
1106  tmpNumBlocks = dim / blockSize_; // Allow for a good breakdown.
1107  else
1108  tmpNumBlocks = ( dim - blockSize_) / blockSize_; // Allow for restarting.
1109  printer_->stream(Warnings) <<
1110  "Warning! Requested Krylov subspace dimension is larger than operator dimension!" << std::endl <<
1111  " The maximum number of blocks allowed for the Krylov subspace will be adjusted to " << tmpNumBlocks << std::endl;
1112  plist.set("Num Blocks",Teuchos::asSafe<int>(tmpNumBlocks));
1113  }
1114  else
1115  plist.set("Num Blocks",numBlocks_);
1116 
1117  // Reset the status test.
1118  outputTest_->reset();
1119  loaDetected_ = false;
1120 
1121  // Assume convergence is achieved, then let any failed convergence set this to false.
1122  isConverged = true;
1123 
1125  // BlockGmres solver
1126 
1128 
1129  block_gmres_iter = Teuchos::rcp( new BlockGmresIter<ScalarType,MV,OP>(problem_,printer_,outputTest_,ortho_,plist) );
1130 
1131  // Enter solve() iterations
1132  while ( numRHS2Solve > 0 ) {
1133 
1134  // Set the current number of blocks and blocksize with the Gmres iteration.
1135  if (blockSize_*numBlocks_ > dim) {
1136  int tmpNumBlocks = 0;
1137  if (blockSize_ == 1)
1138  tmpNumBlocks = dim / blockSize_; // Allow for a good breakdown.
1139  else
1140  tmpNumBlocks = ( dim - blockSize_) / blockSize_; // Allow for restarting.
1141  block_gmres_iter->setSize( blockSize_, tmpNumBlocks );
1142  }
1143  else
1144  block_gmres_iter->setSize( blockSize_, numBlocks_ );
1145 
1146  // Reset the number of iterations.
1147  block_gmres_iter->resetNumIters();
1148 
1149  // Reset the number of calls that the status test output knows about.
1150  outputTest_->resetNumCalls();
1151 
1152  // Create the first block in the current Krylov basis.
1153  Teuchos::RCP<MV> V_0;
1154  V_0 = MVT::CloneCopy( *(problem_->getInitPrecResVec()), currIdx );
1155 
1156 
1157  // Get a matrix to hold the orthonormalization coefficients.
1159  Teuchos::rcp( new Teuchos::SerialDenseMatrix<int,ScalarType>( blockSize_, blockSize_ ) );
1160 
1161  // Orthonormalize the new V_0
1162  int rank = ortho_->normalize( *V_0, z_0 );
1164  "Belos::GmresPolySolMgr::solve(): Failed to compute initial block of orthonormal vectors.");
1165 
1166  // Set the new state and initialize the solver.
1168  newstate.V = V_0;
1169  newstate.z = z_0;
1170  newstate.curDim = 0;
1171  block_gmres_iter->initializeGmres(newstate);
1172  int numRestarts = 0;
1173 
1174  while(1) {
1175  // tell block_gmres_iter to iterate
1176  try {
1177  block_gmres_iter->iterate();
1178 
1180  //
1181  // check convergence first
1182  //
1184  if ( convTest_->getStatus() == Passed ) {
1185  if ( expConvTest_->getLOADetected() ) {
1186  // we don't have convergence
1187  loaDetected_ = true;
1188  isConverged = false;
1189  }
1190  break; // break from while(1){block_gmres_iter->iterate()}
1191  }
1193  //
1194  // check for maximum iterations
1195  //
1197  else if ( maxIterTest_->getStatus() == Passed ) {
1198  // we don't have convergence
1199  isConverged = false;
1200  break; // break from while(1){block_gmres_iter->iterate()}
1201  }
1203  //
1204  // check for restarting, i.e. the subspace is full
1205  //
1207  else if ( block_gmres_iter->getCurSubspaceDim() == block_gmres_iter->getMaxSubspaceDim() ) {
1208 
1209  if ( numRestarts >= maxRestarts_ ) {
1210  isConverged = false;
1211  break; // break from while(1){block_gmres_iter->iterate()}
1212  }
1213  numRestarts++;
1214 
1215  printer_->stream(Debug) << " Performing restart number " << numRestarts << " of " << maxRestarts_ << std::endl << std::endl;
1216 
1217  // Update the linear problem.
1218  Teuchos::RCP<MV> update = block_gmres_iter->getCurrentUpdate();
1219  problem_->updateSolution( update, true );
1220 
1221  // Get the state.
1222  GmresIterationState<ScalarType,MV> oldState = block_gmres_iter->getState();
1223 
1224  // Compute the restart std::vector.
1225  // Get a view of the current Krylov basis.
1226  Teuchos::RCP<MV> V_0 = MVT::Clone( *(oldState.V), blockSize_ );
1227  problem_->computeCurrPrecResVec( &*V_0 );
1228 
1229  // Get a view of the first block of the Krylov basis.
1231  Teuchos::rcp( new Teuchos::SerialDenseMatrix<int,ScalarType>( blockSize_, blockSize_ ) );
1232 
1233  // Orthonormalize the new V_0
1234  int rank = ortho_->normalize( *V_0, z_0 );
1236  "Belos::GmresPolySolMgr::solve(): Failed to compute initial block of orthonormal vectors after restart.");
1237 
1238  // Set the new state and initialize the solver.
1240  newstate.V = V_0;
1241  newstate.z = z_0;
1242  newstate.curDim = 0;
1243  block_gmres_iter->initializeGmres(newstate);
1244 
1245  } // end of restarting
1246 
1248  //
1249  // we returned from iterate(), but none of our status tests Passed.
1250  // something is wrong, and it is probably our fault.
1251  //
1253 
1254  else {
1255  TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
1256  "Belos::GmresPolySolMgr::solve(): Invalid return from BlockGmresIter::iterate().");
1257  }
1258  }
1259  catch (const GmresIterationOrthoFailure &e) {
1260  // If the block size is not one, it's not considered a lucky breakdown.
1261  if (blockSize_ != 1) {
1262  printer_->stream(Errors) << "Error! Caught std::exception in BlockGmresIter::iterate() at iteration "
1263  << block_gmres_iter->getNumIters() << std::endl
1264  << e.what() << std::endl;
1265  if (convTest_->getStatus() != Passed)
1266  isConverged = false;
1267  break;
1268  }
1269  else {
1270  // If the block size is one, try to recover the most recent least-squares solution
1271  block_gmres_iter->updateLSQR( block_gmres_iter->getCurSubspaceDim() );
1272 
1273  // Check to see if the most recent least-squares solution yielded convergence.
1274  sTest_->checkStatus( &*block_gmres_iter );
1275  if (convTest_->getStatus() != Passed)
1276  isConverged = false;
1277  break;
1278  }
1279  }
1280  catch (const std::exception &e) {
1281  printer_->stream(Errors) << "Error! Caught std::exception in BlockGmresIter::iterate() at iteration "
1282  << block_gmres_iter->getNumIters() << std::endl
1283  << e.what() << std::endl;
1284  throw;
1285  }
1286  }
1287 
1288  // Compute the current solution.
1289  // Update the linear problem.
1290  // Attempt to get the current solution from the residual status test, if it has one.
1291  if ( !Teuchos::is_null(expConvTest_->getSolution()) ) {
1292  Teuchos::RCP<MV> newX = expConvTest_->getSolution();
1293  Teuchos::RCP<MV> curX = problem_->getCurrLHSVec();
1294  MVT::MvAddMv( 0.0, *newX, 1.0, *newX, *curX );
1295  }
1296  else {
1297  Teuchos::RCP<MV> update = block_gmres_iter->getCurrentUpdate();
1298  problem_->updateSolution( update, true );
1299  }
1300 
1301  // Inform the linear problem that we are finished with this block linear system.
1302  problem_->setCurrLS();
1303 
1304  // Update indices for the linear systems to be solved.
1305  startPtr += numCurrRHS;
1306  numRHS2Solve -= numCurrRHS;
1307  if ( numRHS2Solve > 0 ) {
1308  numCurrRHS = ( numRHS2Solve < blockSize_) ? numRHS2Solve : blockSize_;
1309 
1310  currIdx.resize( blockSize_ );
1311  for (int i=0; i<numCurrRHS; ++i)
1312  { currIdx[i] = startPtr+i; }
1313  for (int i=numCurrRHS; i<blockSize_; ++i)
1314  { currIdx[i] = -1; }
1315 
1316  // Set the next indices.
1317  problem_->setLSIndex( currIdx );
1318  }
1319  else {
1320  currIdx.resize( numRHS2Solve );
1321  }
1322 
1323  }// while ( numRHS2Solve > 0 )
1324 
1325  // print final summary
1326  sTest_->print( printer_->stream(FinalSummary) );
1327 
1328  } // if (strictConvTol_)
1329  } // timing block
1330 
1331  // print timing information
1332 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1333  // Calling summarize() can be expensive, so don't call unless the
1334  // user wants to print out timing details. summarize() will do all
1335  // the work even if it's passed a "black hole" output stream.
1336  if (verbosity_ & TimingDetails)
1337  Teuchos::TimeMonitor::summarize( printer_->stream(TimingDetails) );
1338 #endif
1339 
1340  if (!isConverged || loaDetected_) {
1341  return Unconverged; // return from GmresPolySolMgr::solve()
1342  }
1343  return Converged; // return from GmresPolySolMgr::solve()
1344 }
1345 
1346 // This method requires the solver manager to return a std::string that describes itself.
1347 template<class ScalarType, class MV, class OP>
1349  {
1350  std::ostringstream oss;
1351  oss << "Belos::GmresPolySolMgr<...,"<<Teuchos::ScalarTraits<ScalarType>::name()<<">";
1352  oss << "{";
1353  oss << "Ortho Type='"<<orthoType_<<"\', Block Size=" <<blockSize_;
1354  oss << ", Num Blocks=" <<numBlocks_<< ", Max Restarts=" << maxRestarts_;
1355  oss << "}";
1356  return oss.str();
1357 }
1358 
1359 } // end Belos namespace
1360 
1361 #endif /* BELOS_GMRES_POLY_SOLMGR_HPP */
ScaleType convertStringToScaleType(const std::string &scaleType)
Convert the given string to its ScaleType enum value.
Definition: BelosTypes.cpp:93
std::string description() const
Method to return description of the hybrid block GMRES solver manager.
Collection of types and exceptions used within the Belos solvers.
Belos's basic output manager for sending information of select verbosity levels to the appropriate ou...
bool isLOADetected() const
Return whether a loss of accuracy was detected by this solver during the most current solve...
Class which manages the output and verbosity of the Belos solvers.
bool is_null(const boost::shared_ptr< T > &p)
virtual ~GmresPolySolMgr()
Destructor.
Defines the GMRES polynomial operator hybrid-GMRES iterative linear solver.
ScaleType
The type of scaling to use on the residual norm value.
Definition: BelosTypes.hpp:119
This class implements the block GMRES iteration, where a block Krylov subspace is constructed...
Convergence test using the implicit residual norm(s), with an explicit residual norm(s) check for los...
Teuchos::RCP< const MV > V
The current Krylov basis.
T & get(const std::string &name, T def_value)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers for this object.
static RCP< Time > getNewCounter(const std::string &name)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem)
Set the linear problem that needs to be solved.
Teuchos::RCP< const Teuchos::SerialDenseMatrix< int, ScalarType > > z
The current right-hand side of the least squares system RY = Z.
An implementation of StatusTestResNorm using a family of residual norms.
Structure to contain pointers to GmresIteration state variables.
An extension of the MultiVecTraits class that adds a new vector length method.
Belos::StatusTest class for specifying a maximum number of iterations.
static std::string name()
A factory class for generating StatusTestOutput objects.
Iterated Modified Gram-Schmidt (IMGS) implementation of the Belos::OrthoManager class.
void reset(const ResetType type)
Performs a reset of the solver manager specified by the ResetType. This informs the solver manager th...
static void summarize(Ptr< const Comm< int > > comm, std::ostream &out=std::cout, const bool alwaysWriteLocal=false, const bool writeGlobalStats=true, const bool writeZeroTimers=true, const ECounterSetOp setOp=Intersection, const std::string &filter="")
Traits class which defines basic operations on multivectors.
Belos::StatusTest for logically combining several status tests.
bool isParameter(const std::string &name) const
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.
Definition: BelosTypes.hpp:200
GmresPolySolMgrLinearProblemFailure is thrown when the linear problem is not setup (i...
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Pure virtual base class which describes the basic interface for a solver manager. ...
int curDim
The current dimension of the reduction.
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const
Get a parameter list containing the current parameters for this object.
A linear system to solve, and its associated information.
Class which describes the linear problem to be solved by the iterative solver.
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > &params)
Set the parameters the solver manager should use to solve the linear problem.
The Belos::GmresPolySolMgr provides a powerful and fully-featured solver manager over the hybrid bloc...
ReturnType
Whether the Belos solve converged for all linear systems.
Definition: BelosTypes.hpp:149
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Get a parameter list containing the valid parameters for this object.
The Belos::SolverManager is a templated virtual base class that defines the basic interface that any ...
ReturnType solve()
This method performs possibly repeated calls to the underlying linear solver's iterate() routine unti...
Belos's class for applying the GMRES polynomial operator that is used by the hybrid-GMRES linear solv...
Belos concrete class for performing the block GMRES iteration.
Iterated Classical Gram-Schmidt (ICGS) implementation of the Belos::OrthoManager class.
void validateParameters(ParameterList const &validParamList, int const depth=1000, EValidateUsed const validateUsed=VALIDATE_USED_ENABLED, EValidateDefaults const validateDefaults=VALIDATE_DEFAULTS_ENABLED) const
An implementation of the Belos::MatOrthoManager that performs orthogonalization using multiple steps ...
An implementation of the Belos::MatOrthoManager that performs orthogonalization using multiple steps ...
GmresPolySolMgrPolynomialFailure is thrown when their is a problem generating the GMRES polynomial fo...
GmresPolySolMgrPolynomialFailure(const std::string &what_arg)
Belos::StatusTestResNorm for specifying general residual norm stopping criteria.
Belos::StatusTest for specifying an implicit residual norm stopping criteria that checks for loss of ...
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.
void TRSM(ESide side, EUplo uplo, ETransp transa, EDiag diag, const OrdinalType m, const OrdinalType n, const alpha_type alpha, const A_type *A, const OrdinalType lda, ScalarType *B, const OrdinalType ldb) const
Class which defines basic traits for the operator type.
const LinearProblem< ScalarType, MV, OP > & getProblem() const
Get current linear problem being solved for in this object.
Parent class to all Belos exceptions.
Definition: BelosTypes.hpp:60
GmresPolySolMgr()
Empty constructor for GmresPolySolMgr. This constructor takes no arguments and sets the default value...
Pure virtual base class which augments the basic interface for a Gmres linear solver iteration...
GmresIterationOrthoFailure is thrown when the GmresIteration object is unable to compute independent ...
Belos header file which uses auto-configuration information to include necessary C++ headers...
int getNumIters() const
Get the iteration count for the most recent call to solve().
GmresPolySolMgrOrthoFailure is thrown when the orthogonalization manager is unable to generate orthon...
GmresPolySolMgrOrthoFailure(const std::string &what_arg)
GmresPolySolMgrLinearProblemFailure(const std::string &what_arg)