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