Belos Package Browser (Single Doxygen Collection)  Development
BelosMinresSolMgr.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_MINRES_SOLMGR_HPP
43 #define BELOS_MINRES_SOLMGR_HPP
44 
47 
48 #include "BelosConfigDefs.hpp"
49 #include "BelosTypes.hpp"
50 
51 #include "BelosLinearProblem.hpp"
52 #include "BelosSolverManager.hpp"
53 
54 #include "BelosMinresIter.hpp"
57 #include "BelosStatusTestCombo.hpp"
59 #include "BelosOutputManager.hpp"
60 #ifdef BELOS_TEUCHOS_TIME_MONITOR
61 #include "Teuchos_TimeMonitor.hpp"
62 #endif
63 
64 #include "Teuchos_StandardParameterEntryValidators.hpp"
65 // Teuchos::ScalarTraits<int> doesn't define rmax(), alas, so we get
66 // INT_MAX from here.
67 #include <climits>
68 
69 namespace Belos {
70 
72 
73 
83  //
88  public:
89  MinresSolMgrLinearProblemFailure (const std::string& what_arg) :
90  BelosError(what_arg)
91  {}
92  };
93 
112  template<class ScalarType, class MV, class OP>
113  class MinresSolMgr : public SolverManager<ScalarType,MV,OP> {
114 
115  private:
118  typedef Teuchos::ScalarTraits<ScalarType> SCT;
119  typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
120  typedef Teuchos::ScalarTraits< MagnitudeType > MT;
121 
122  public:
123 
135  static Teuchos::RCP<const Teuchos::ParameterList> defaultParameters();
136 
138 
139 
148  MinresSolMgr();
149 
181  MinresSolMgr (const Teuchos::RCP<LinearProblem< ScalarType, MV, OP> > &problem,
182  const Teuchos::RCP<Teuchos::ParameterList> &params);
183 
185  virtual ~MinresSolMgr() {};
186 
188  Teuchos::RCP<SolverManager<ScalarType, MV, OP> > clone () const override {
189  return Teuchos::rcp(new MinresSolMgr<ScalarType,MV,OP>);
190  }
192 
194 
195 
197  const LinearProblem<ScalarType,MV,OP>& getProblem() const override {
198  return *problem_;
199  }
200 
202  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const override {
203  if (defaultParams_.is_null()) {
205  }
206  return defaultParams_;
207  }
208 
210  Teuchos::RCP<const Teuchos::ParameterList> getCurrentParameters() const override {
211  return params_;
212  }
213 
223  Teuchos::Array<Teuchos::RCP<Teuchos::Time> > getTimers() const {
224  return Teuchos::tuple (timerSolve_);
225  }
226 
232  MagnitudeType achievedTol() const override {
233  return achievedTol_;
234  }
235 
237  int getNumIters() const override {
238  return numIters_;
239  }
240 
246  bool isLOADetected() const override { return false; }
247 
249 
251 
252 
253  void
254  setProblem (const Teuchos::RCP<LinearProblem<ScalarType, MV, OP> > &problem) override
255  {
256  problem_ = problem;
257  }
258 
259  void
260  setParameters (const Teuchos::RCP<Teuchos::ParameterList>& params) override;
261 
263 
265 
266 
267  void
268  reset (const ResetType type) override
269  {
270  if ((type & Belos::Problem) && ! problem_.is_null()) {
271  problem_->setProblem ();
272  }
273  }
275 
277 
278 
296  ReturnType solve() override;
297 
299 
302 
303  std::string description() const override;
304 
306 
307  private:
309  Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > problem_;
310 
312  Teuchos::RCP<OutputManager<ScalarType> > printer_;
313  Teuchos::RCP<std::ostream> outputStream_;
314 
321  Teuchos::RCP<StatusTest<ScalarType,MV,OP> > sTest_;
322 
326  Teuchos::RCP<StatusTestMaxIters<ScalarType,MV,OP> > maxIterTest_;
327 
331  Teuchos::RCP<StatusTest<ScalarType,MV,OP> > convTest_;
332 
336  Teuchos::RCP<StatusTestGenResNorm<ScalarType,MV,OP> > impConvTest_;
337 
341  Teuchos::RCP<StatusTestGenResNorm<ScalarType,MV,OP> > expConvTest_;
342 
347  Teuchos::RCP<StatusTestOutput<ScalarType,MV,OP> > outputTest_;
348 
352  mutable Teuchos::RCP<const Teuchos::ParameterList> defaultParams_;
353 
355  Teuchos::RCP<Teuchos::ParameterList> params_;
356 
359 
362 
365 
368 
371 
374 
377 
380 
382  std::string label_;
383 
385  Teuchos::RCP<Teuchos::Time> timerSolve_;
386 
389 
395  static void
396  validateProblem (const Teuchos::RCP<LinearProblem<ScalarType, MV, OP> >& problem);
397  };
398 
399 
400  template<class ScalarType, class MV, class OP>
401  Teuchos::RCP<const Teuchos::ParameterList>
403  {
404  using Teuchos::ParameterList;
405  using Teuchos::parameterList;
406  using Teuchos::RCP;
407  using Teuchos::rcp;
408  using Teuchos::rcpFromRef;
409  using Teuchos::EnhancedNumberValidator;
410  typedef MagnitudeType MT;
411  typedef Teuchos::ScalarTraits<MT> MST;
412 
413  // List of parameters accepted by MINRES, and their default values.
414  RCP<ParameterList> pl = parameterList ("MINRES");
415 
416  pl->set ("Convergence Tolerance", MST::squareroot (MST::eps()),
417  "Relative residual tolerance that needs to be achieved by "
418  "the iterative solver, in order for the linear system to be "
419  "declared converged.",
420  rcp (new EnhancedNumberValidator<MT> (MST::zero(), MST::rmax())));
421  pl->set ("Maximum Iterations", static_cast<int>(1000),
422  "Maximum number of iterations allowed for each right-hand "
423  "side solved.",
424  rcp (new EnhancedNumberValidator<int> (0, INT_MAX)));
425  pl->set ("Num Blocks", static_cast<int> (-1),
426  "Ignored, but permitted, for compatibility with other Belos "
427  "solvers.");
428  pl->set ("Block Size", static_cast<int> (1),
429  "Number of vectors in each block. WARNING: The current "
430  "implementation of MINRES only accepts a block size of 1, "
431  "since it can only solve for 1 right-hand side at a time.",
432  rcp (new EnhancedNumberValidator<int> (1, 1)));
433  pl->set ("Verbosity", (int) Belos::Errors,
434  "The type(s) of solver information that should "
435  "be written to the output stream.");
436  pl->set ("Output Style", (int) Belos::General,
437  "What style is used for the solver information written "
438  "to the output stream.");
439  pl->set ("Output Frequency", static_cast<int>(-1),
440  "How often (in terms of number of iterations) intermediate "
441  "convergence information should be written to the output stream."
442  " -1 means never.");
443  pl->set ("Output Stream", rcpFromRef(std::cout),
444  "A reference-counted pointer to the output stream where all "
445  "solver output is sent. The output stream defaults to stdout.");
446  pl->set ("Timer Label", std::string("Belos"),
447  "The string to use as a prefix for the timer labels.");
448  return pl;
449  }
450 
451  //
452  // Empty Constructor
453  //
454  template<class ScalarType, class MV, class OP>
456  convtol_(0.0),
457  achievedTol_(0.0),
458  maxIters_(0),
459  numIters_ (0),
460  blockSize_(0),
461  verbosity_(0),
462  outputStyle_(0),
463  outputFreq_(0),
464  parametersSet_ (false)
465  {}
466 
467  //
468  // Primary constructor (use this one)
469  //
470  template<class ScalarType, class MV, class OP>
472  MinresSolMgr (const Teuchos::RCP<LinearProblem<ScalarType, MV, OP> > &problem,
473  const Teuchos::RCP<Teuchos::ParameterList>& params) :
474  problem_ (problem),
475  numIters_ (0),
476  parametersSet_ (false)
477  {
478  TEUCHOS_TEST_FOR_EXCEPTION(problem_.is_null(), std::invalid_argument,
479  "MinresSolMgr: The version of the constructor "
480  "that takes a LinearProblem to solve was given a "
481  "null LinearProblem.");
482  setParameters (params);
483  }
484 
485  template<class ScalarType, class MV, class OP>
486  void
489  {
490  TEUCHOS_TEST_FOR_EXCEPTION(problem.is_null(),
492  "MINRES requires that you have provided a nonnull LinearProblem to the "
493  "solver manager, before you call the solve() method.");
494  TEUCHOS_TEST_FOR_EXCEPTION(problem->getOperator().is_null(),
496  "MINRES requires a LinearProblem object with a non-null operator (the "
497  "matrix A).");
498  TEUCHOS_TEST_FOR_EXCEPTION(problem->getRHS().is_null(),
500  "MINRES requires a LinearProblem object with a non-null right-hand side.");
501  TEUCHOS_TEST_FOR_EXCEPTION( ! problem->isProblemSet(),
503  "MINRES requires that before you give it a LinearProblem to solve, you "
504  "must first call the linear problem's setProblem() method.");
505  }
506 
507  template<class ScalarType, class MV, class OP>
508  void
510  setParameters (const Teuchos::RCP<Teuchos::ParameterList>& params)
511  {
512  using Teuchos::ParameterList;
513  using Teuchos::parameterList;
514  using Teuchos::RCP;
515  using Teuchos::rcp;
516  using Teuchos::rcpFromRef;
517  using Teuchos::null;
518  using Teuchos::is_null;
519  using std::string;
520  using std::ostream;
521  using std::endl;
522 
523  if (params_.is_null()) {
524  params_ = parameterList (*getValidParameters());
525  }
526  RCP<ParameterList> pl = params;
527  pl->validateParametersAndSetDefaults (*params_);
528 
529  //
530  // Read parameters from the parameter list. We have already
531  // populated it with defaults.
532  //
533  blockSize_ = pl->get<int> ("Block Size");
534  verbosity_ = pl->get<int> ("Verbosity");
535  outputStyle_ = pl->get<int> ("Output Style");
536  outputFreq_ = pl->get<int>("Output Frequency");
537  outputStream_ = pl->get<RCP<std::ostream> > ("Output Stream");
538  convtol_ = pl->get<MagnitudeType> ("Convergence Tolerance");
539  maxIters_ = pl->get<int> ("Maximum Iterations");
540  //
541  // All done reading parameters from the parameter list.
542  // Now we know it's valid and we can store it.
543  //
544  params_ = pl;
545 
546  // Change the timer label, and create the timer if necessary.
547  const string newLabel = pl->get<string> ("Timer Label");
548  {
549  if (newLabel != label_ || timerSolve_.is_null()) {
550  label_ = newLabel;
551 #ifdef BELOS_TEUCHOS_TIME_MONITOR
552  const string solveLabel = label_ + ": MinresSolMgr total solve time";
553  // Unregister the old timer before creating a new one.
554  if (! timerSolve_.is_null()) {
555  Teuchos::TimeMonitor::clearCounter (label_);
556  timerSolve_ = Teuchos::null;
557  }
558  timerSolve_ = Teuchos::TimeMonitor::getNewCounter (solveLabel);
559 #endif // BELOS_TEUCHOS_TIME_MONITOR
560  }
561  }
562 
563  // Create output manager, if necessary; otherwise, set its parameters.
564  bool recreatedPrinter = false;
565  if (printer_.is_null()) {
566  printer_ = rcp (new OutputManager<ScalarType> (verbosity_, outputStream_));
567  recreatedPrinter = true;
568  } else {
569  // Set the output stream's verbosity level.
570  printer_->setVerbosity (verbosity_);
571  // Tell the output manager about the new output stream.
572  printer_->setOStream (outputStream_);
573  }
574 
575  //
576  // Set up the convergence tests
577  //
578  typedef StatusTestGenResNorm<ScalarType, MV, OP> res_norm_type;
579  typedef StatusTestCombo<ScalarType, MV, OP> combo_type;
580 
581  // Do we need to allocate at least one of the implicit or explicit
582  // residual norm convergence tests?
583  const bool allocatedConvergenceTests =
584  impConvTest_.is_null() || expConvTest_.is_null();
585 
586  // Allocate or set the tolerance of the implicit residual norm
587  // convergence test.
588  if (impConvTest_.is_null()) {
589  impConvTest_ = rcp (new res_norm_type (convtol_));
590  impConvTest_->defineResForm (res_norm_type::Implicit, TwoNorm);
591  // TODO (mfh 03 Nov 2011) Allow users to define the type of
592  // scaling (or a custom scaling factor).
593  impConvTest_->defineScaleForm (NormOfInitRes, TwoNorm);
594  } else {
595  impConvTest_->setTolerance (convtol_);
596  }
597 
598  // Allocate or set the tolerance of the explicit residual norm
599  // convergence test.
600  if (expConvTest_.is_null()) {
601  expConvTest_ = rcp (new res_norm_type (convtol_));
602  expConvTest_->defineResForm (res_norm_type::Explicit, TwoNorm);
603  // TODO (mfh 03 Nov 2011) Allow users to define the type of
604  // scaling (or a custom scaling factor).
605  expConvTest_->defineScaleForm (NormOfInitRes, TwoNorm);
606  } else {
607  expConvTest_->setTolerance (convtol_);
608  }
609 
610  // Whether we need to recreate the full status test. We only need
611  // to do that if at least one of convTest_ or maxIterTest_ had to
612  // be reallocated.
613  bool needToRecreateFullStatusTest = sTest_.is_null();
614 
615  // Residual status test is a combo of the implicit and explicit
616  // convergence tests.
617  if (convTest_.is_null() || allocatedConvergenceTests) {
618  convTest_ = rcp (new combo_type (combo_type::SEQ, impConvTest_, expConvTest_));
619  needToRecreateFullStatusTest = true;
620  }
621 
622  // Maximum number of iterations status test. It tells the solver to
623  // stop iteration, if the maximum number of iterations has been
624  // exceeded. Initialize it if we haven't yet done so, otherwise
625  // tell it the new maximum number of iterations.
626  if (maxIterTest_.is_null()) {
627  maxIterTest_ = rcp (new StatusTestMaxIters<ScalarType,MV,OP> (maxIters_));
628  needToRecreateFullStatusTest = true;
629  } else {
630  maxIterTest_->setMaxIters (maxIters_);
631  }
632 
633  // Create the full status test if we need to.
634  //
635  // The full status test: the maximum number of iterations have
636  // been reached, OR the residual has converged.
637  //
638  // "If we need to" means either that the status test was never
639  // created before, or that its two component tests had to be
640  // reallocated.
641  if (needToRecreateFullStatusTest) {
642  sTest_ = rcp (new combo_type (combo_type::OR, maxIterTest_, convTest_));
643  }
644 
645  // If necessary, create the status test output class. This class
646  // manages and formats the output from the status test. We have
647  // to recreate the output test if we had to (re)allocate either
648  // printer_ or sTest_.
649  if (outputTest_.is_null() || needToRecreateFullStatusTest || recreatedPrinter) {
650  StatusTestOutputFactory<ScalarType,MV,OP> stoFactory (outputStyle_);
651  outputTest_ = stoFactory.create (printer_, sTest_, outputFreq_,
653  } else {
654  outputTest_->setOutputFrequency (outputFreq_);
655  }
656  // Set the solver string for the output test.
657  // StatusTestOutputFactory has no constructor argument for this.
658  outputTest_->setSolverDesc (std::string (" MINRES "));
659 
660  // Inform the solver manager that the current parameters were set.
661  parametersSet_ = true;
662 
663  if (verbosity_ & Debug) {
664  using std::endl;
665 
666  std::ostream& dbg = printer_->stream (Debug);
667  dbg << "MINRES parameters:" << endl << params_ << endl;
668  }
669  }
670 
671 
672  template<class ScalarType, class MV, class OP>
674  {
675  using Teuchos::RCP;
676  using Teuchos::rcp;
677  using Teuchos::rcp_const_cast;
678  using std::endl;
679 
680  if (! parametersSet_) {
681  setParameters (params_);
682  }
683  std::ostream& dbg = printer_->stream (Debug);
684 
685 #ifdef BELOS_TEUCHOS_TIME_MONITOR
686  Teuchos::TimeMonitor solveTimerMonitor (*timerSolve_);
687 #endif // BELOS_TEUCHOS_TIME_MONITOR
688 
689  // We need a problem to solve, else we can't solve it.
690  validateProblem (problem_);
691 
692  // Reset the status test for this solve.
693  outputTest_->reset();
694 
695  // The linear problem has this many right-hand sides to solve.
696  // MINRES can solve only one at a time, so we solve for each
697  // right-hand side in succession.
698  const int numRHS2Solve = MVT::GetNumberVecs (*(problem_->getRHS()));
699 
700  // Create MINRES iteration object. Pass along the solver
701  // manager's parameters, which have already been validated.
702  typedef MinresIter<ScalarType, MV, OP> iter_type;
703  RCP<iter_type> minres_iter =
704  rcp (new iter_type (problem_, printer_, outputTest_, *params_));
705 
706  // The index/indices of the right-hand sides for which MINRES did
707  // _not_ converge. Hopefully this is empty after the for loop
708  // below! If it is not empty, at least one right-hand side did
709  // not converge.
710  std::vector<int> notConverged;
711  std::vector<int> currentIndices(1);
712 
713  numIters_ = 0;
714 
715  // Solve for each right-hand side in turn.
716  for (int currentRHS = 0; currentRHS < numRHS2Solve; ++currentRHS) {
717  // Inform the linear problem of the right-hand side(s) currently
718  // being solved. MINRES only knows how to solve linear problems
719  // with one right-hand side, so we only include one index, which
720  // is the index of the current right-hand side.
721  currentIndices[0] = currentRHS;
722  problem_->setLSIndex (currentIndices);
723 
724  dbg << "-- Current right-hand side index being solved: "
725  << currentRHS << endl;
726 
727  // Reset the number of iterations.
728  minres_iter->resetNumIters();
729  // Reset the number of calls that the status test output knows about.
730  outputTest_->resetNumCalls();
731  // Set the new state and initialize the solver.
733 
734  // Get the residual vector for the current linear system
735  // (that is, for the current right-hand side).
736  newstate.Y = MVT::CloneViewNonConst (*(rcp_const_cast<MV> (problem_->getInitResVec())), currentIndices);
737  minres_iter->initializeMinres (newstate);
738 
739  // Attempt to solve for the solution corresponding to the
740  // current right-hand side.
741  while (true) {
742  try {
743  minres_iter->iterate();
744 
745  // First check for convergence
746  if (convTest_->getStatus() == Passed) {
747  dbg << "---- Converged after " << maxIterTest_->getNumIters()
748  << " iterations" << endl;
749  break;
750  }
751  // Now check for max # of iterations
752  else if (maxIterTest_->getStatus() == Passed) {
753  dbg << "---- Did not converge after " << maxIterTest_->getNumIters()
754  << " iterations" << endl;
755  // This right-hand side didn't converge!
756  notConverged.push_back (currentRHS);
757  break;
758  } else {
759  // If we get here, we returned from iterate(), but none of
760  // our status tests Passed. Something is wrong, and it is
761  // probably our fault.
762  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
763  "Belos::MinresSolMgr::solve(): iterations neither converged, "
764  "nor reached the maximum number of iterations " << maxIters_
765  << ". That means something went wrong.");
766  }
767  } catch (const std::exception &e) {
768  printer_->stream (Errors)
769  << "Error! Caught std::exception in MinresIter::iterate() at "
770  << "iteration " << minres_iter->getNumIters() << endl
771  << e.what() << endl;
772  throw e;
773  }
774  }
775 
776  // Inform the linear problem that we are finished with the
777  // current right-hand side. It may or may not have converged,
778  // but we don't try again if the first time didn't work.
779  problem_->setCurrLS();
780 
781  // Get iteration information for this solve: total number of
782  // iterations for all right-hand sides.
783  numIters_ += maxIterTest_->getNumIters();
784  }
785 
786  // Print final summary of the solution process
787  sTest_->print (printer_->stream (FinalSummary));
788 
789  // Print timing information, if the corresponding compile-time and
790  // run-time options are enabled.
791 #ifdef BELOS_TEUCHOS_TIME_MONITOR
792  // Calling summarize() can be expensive, so don't call unless the
793  // user wants to print out timing details. summarize() will do all
794  // the work even if it's passed a "black hole" output stream.
795  if (verbosity_ & TimingDetails) {
796  Teuchos::TimeMonitor::summarize (printer_->stream (TimingDetails));
797  }
798 #endif // BELOS_TEUCHOS_TIME_MONITOR
799 
800  // Save the convergence test value ("achieved tolerance") for this
801  // solve. This solver always has two residual norm status tests:
802  // an explicit and an implicit test. The master convergence test
803  // convTest_ is a SEQ combo of the implicit resp. explicit tests.
804  // If the implicit test never passes, then the explicit test won't
805  // ever be executed. This manifests as
806  // expConvTest_->getTestValue()->size() < 1. We deal with this
807  // case by using the values returned by
808  // impConvTest_->getTestValue().
809  {
810  const std::vector<MagnitudeType>* pTestValues = expConvTest_->getTestValue();
811  if (pTestValues == NULL || pTestValues->size() < 1) {
812  pTestValues = impConvTest_->getTestValue();
813  }
814  TEUCHOS_TEST_FOR_EXCEPTION(pTestValues == NULL, std::logic_error,
815  "Belos::MinresSolMgr::solve(): The implicit convergence test's getTestValue() "
816  "method returned NULL. Please report this bug to the Belos developers.");
817  TEUCHOS_TEST_FOR_EXCEPTION(pTestValues->size() < 1, std::logic_error,
818  "Belos::MinresSolMgr::solve(): The implicit convergence test's getTestValue() "
819  "method returned a vector of length zero. Please report this bug to the "
820  "Belos developers.");
821 
822  // FIXME (mfh 12 Dec 2011) Does pTestValues really contain the
823  // achieved tolerances for all vectors in the current solve(), or
824  // just for the vectors from the last deflation?
825  achievedTol_ = *std::max_element (pTestValues->begin(), pTestValues->end());
826  }
827 
828  if (notConverged.size() > 0) {
829  return Unconverged;
830  } else {
831  return Converged;
832  }
833  }
834 
835  // This method requires the solver manager to return a std::string that describes itself.
836  template<class ScalarType, class MV, class OP>
838  {
839  std::ostringstream oss;
840  oss << "Belos::MinresSolMgr< "
841  << Teuchos::ScalarTraits<ScalarType>::name()
842  <<", MV, OP >";
843  // oss << "{";
844  // oss << "Block Size=" << blockSize_;
845  // oss << "}";
846  return oss.str();
847  }
848 
849 } // end Belos namespace
850 
851 #endif /* BELOS_MINRES_SOLMGR_HPP */
int blockSize_
Current block size (i.e., number of right-hand sides): always 1 (one).
Collection of types and exceptions used within the Belos solvers.
Teuchos::RCP< StatusTestGenResNorm< ScalarType, MV, OP > > impConvTest_
The implicit (a.k.a.
Belos&#39;s basic output manager for sending information of select verbosity levels to the appropriate ou...
std::string label_
Timer label.
Teuchos::RCP< StatusTestMaxIters< ScalarType, MV, OP > > maxIterTest_
The status test for maximum iteration count.
Class which manages the output and verbosity of the Belos solvers.
Teuchos::RCP< Teuchos::ParameterList > params_
List of current parameters.
Teuchos::RCP< StatusTestGenResNorm< ScalarType, MV, OP > > expConvTest_
The explicit residual norm test.
OperatorTraits< ScalarType, MV, OP > OPT
virtual ~MinresSolMgr()
Destructor.
MINRES implementation.
int outputFreq_
Current frequency of output.
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return all timers for this object.
Teuchos::RCP< OutputManager< ScalarType > > printer_
Output manager.
Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > problem_
Linear problem to solve.
int getNumIters() const override
Get the iteration count for the most recent call to solve().
A factory class for generating StatusTestOutput objects.
static Teuchos::RCP< const Teuchos::ParameterList > defaultParameters()
List of valid MINRES parameters and their default values.
static void validateProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem)
Validate the given linear problem.
An implementation of StatusTestResNorm using a family of residual norms.
Belos::StatusTest class for specifying a maximum number of iterations.
A factory class for generating StatusTestOutput objects.
Teuchos::RCP< SolverManager< ScalarType, MV, OP > > clone() const override
clone for Inverted Injection (DII)
Traits class which defines basic operations on multivectors.
Belos::StatusTest for logically combining several status tests.
const LinearProblem< ScalarType, MV, OP > & getProblem() const override
Return the linear problem to be solved.
MinresSolMgrLinearProblemFailure(const std::string &what_arg)
A Belos::StatusTest class for specifying a maximum number of iterations.
ResetType
How to reset the solver.
Definition: BelosTypes.hpp:206
MagnitudeType achievedTol() const override
Tolerance achieved by the last solve() invocation.
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > &params) override
Set the parameters to use when solving the linear problem.
This subclass of std::exception may be thrown from the MinresSolMgr::solve() method.
Pure virtual base class which describes the basic interface for a solver manager. ...
MagnitudeType achievedTol_
Tolerance achieved by the last solve() invocation.
bool parametersSet_
Whether the solver manager&#39;s parameters have been set.
Teuchos::RCP< StatusTestOutput< ScalarType, MV, OP > > outputTest_
The "status test" that handles output.
Teuchos::RCP< const Teuchos::ParameterList > defaultParams_
List of default parameters.
MINRES linear solver solution manager.
Teuchos::RCP< Teuchos::Time > timerSolve_
Total time to solution.
int maxIters_
Maximum number of iterations before stopping.
MINRES iteration implementation.
std::string description() const override
A linear system to solve, and its associated information.
Teuchos::ScalarTraits< ScalarType > SCT
Class which describes the linear problem to be solved by the iterative solver.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const override
Return the list of default parameters for this object.
Teuchos::ScalarTraits< ScalarType >::magnitudeType MagnitudeType
Structure to contain pointers to MinresIteration state variables.
ReturnType
Whether the Belos solve converged for all linear systems.
Definition: BelosTypes.hpp:155
int numIters_
Current number of iterations.
The Belos::SolverManager is a templated virtual base class that defines the basic interface that any ...
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const override
Return the list of current parameters for this object.
Teuchos::RCP< StatusTest< ScalarType, MV, OP > > convTest_
The combined status test for convergence.
Teuchos::RCP< std::ostream > outputStream_
void reset(const ResetType type) override
Reset the solver manager.
void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem) override
Set the linear problem that needs to be solved.
Teuchos::RCP< const MV > Y
The current residual.
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.
Teuchos::ScalarTraits< MagnitudeType > MT
Belos::StatusTestResNorm for specifying general residual norm stopping criteria.
A class for extending the status testing capabilities of Belos via logical combinations.
MinresSolMgr()
Default constructor.
MagnitudeType convtol_
Current relative residual 2-norm convergence tolerance.
Class which defines basic traits for the operator type.
Parent class to all Belos exceptions.
Definition: BelosTypes.hpp:60
Belos header file which uses auto-configuration information to include necessary C++ headers...
Teuchos::RCP< StatusTest< ScalarType, MV, OP > > sTest_
The full status test.
ReturnType solve() override
Iterate until the status test tells us to stop.
int verbosity_
Current output verbosity.
MultiVecTraits< ScalarType, MV > MVT
bool isLOADetected() const override
Whether a loss of accuracy was detected in the solver.
int outputStyle_
Current output style.