Belos Version of the Day
Loading...
Searching...
No Matches
BelosLSQRSolMgr.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Belos: Block Linear Solvers Package
4//
5// Copyright 2004-2016 NTESS and the Belos contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef BELOS_LSQR_SOLMGR_HPP
11#define BELOS_LSQR_SOLMGR_HPP
12
15
16#include "BelosConfigDefs.hpp"
17#include "BelosTypes.hpp"
18
21
23#include "BelosLSQRIter.hpp"
29#include "Teuchos_as.hpp"
30
31#ifdef BELOS_TEUCHOS_TIME_MONITOR
32#include "Teuchos_TimeMonitor.hpp"
33#endif
34
35namespace Belos {
36
37
39
40
48public:
52};
53
61public:
64 {}
65};
66
180
181
182// Partial specialization for complex ScalarType.
183// This contains a trivial implementation.
184// See discussion in the class documentation above.
185template<class ScalarType, class MV, class OP,
186 const bool scalarTypeIsComplex = Teuchos::ScalarTraits<ScalarType>::isComplex>
188 public Details::RealSolverManager<ScalarType, MV, OP,
189 Teuchos::ScalarTraits<ScalarType>::isComplex>
190{
191 static const bool isComplex = Teuchos::ScalarTraits<ScalarType>::isComplex;
193
194public:
196 base_type ()
197 {}
199 const Teuchos::RCP<Teuchos::ParameterList> &pl) :
200 base_type ()
201 {}
202 virtual ~LSQRSolMgr () {}
203
205 Teuchos::RCP<SolverManager<ScalarType, MV, OP> > clone () const override {
207 }
208};
209
210
211// Partial specialization for real ScalarType.
212// This contains the actual working implementation of LSQR.
213// See discussion in the class documentation above.
214template<class ScalarType, class MV, class OP>
216 public Details::RealSolverManager<ScalarType, MV, OP, false> {
217private:
220 typedef Teuchos::ScalarTraits<ScalarType> STS;
221 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
222 typedef Teuchos::ScalarTraits<MagnitudeType> STM;
223
224public:
225
227
228
235 LSQRSolMgr ();
236
265 const Teuchos::RCP<Teuchos::ParameterList>& pl);
266
268 virtual ~LSQRSolMgr () {}
269
271 Teuchos::RCP<SolverManager<ScalarType, MV, OP> > clone () const override {
272 return Teuchos::rcp(new LSQRSolMgr<ScalarType,MV,OP>);
273 }
275
277
281 return *problem_;
282 }
283
286 Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const override;
287
290 Teuchos::RCP<const Teuchos::ParameterList> getCurrentParameters() const override {
291 return params_;
292 }
293
299 Teuchos::Array<Teuchos::RCP<Teuchos::Time> > getTimers () const {
300 return Teuchos::tuple (timerSolve_);
301 }
302
304 int getNumIters () const override {
305 return numIters_;
306 }
307
312 MagnitudeType getMatCondNum () const {
313 return matCondNum_;
314 }
315
320 MagnitudeType getMatNorm () const {
321 return matNorm_;
322 }
323
332 MagnitudeType getResNorm () const {
333 return resNorm_;
334 }
335
337 MagnitudeType getMatResNorm () const {
338 return matResNorm_;
339 }
340
349 bool isLOADetected () const override { return false; }
350
352
354
355
357 void setProblem (const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> >& problem) override {
358 problem_ = problem;
359 }
360
362 void setParameters (const Teuchos::RCP<Teuchos::ParameterList>& params) override;
363
365
367
368
372 void reset (const ResetType type) override {
373 if ((type & Belos::Problem) && ! problem_.is_null ()) {
374 problem_->setProblem ();
375 }
376 }
377
379
381
400 ReturnType solve() override;
401
403
405
407 std::string description () const override;
408
410
411private:
412
414 Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > problem_;
416 Teuchos::RCP<OutputManager<ScalarType> > printer_;
418 Teuchos::RCP<std::ostream> outputStream_;
419
421 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > sTest_;
422 Teuchos::RCP<StatusTestMaxIters<ScalarType,MV,OP> > maxIterTest_;
423 Teuchos::RCP<LSQRStatusTest<ScalarType,MV,OP> > convTest_;
424 Teuchos::RCP<StatusTestOutput<ScalarType,MV,OP> > outputTest_;
425
427 Teuchos::RCP<Teuchos::ParameterList> params_;
428
434 mutable Teuchos::RCP<const Teuchos::ParameterList> validParams_;
435
436 // Current solver input parameters
437 MagnitudeType lambda_;
438 MagnitudeType relRhsErr_;
439 MagnitudeType relMatErr_;
440 MagnitudeType condMax_;
441 int maxIters_, termIterMax_;
442 int verbosity_, outputStyle_, outputFreq_;
443
444 // Terminal solver state values
445 int numIters_;
446 MagnitudeType matCondNum_;
447 MagnitudeType matNorm_;
448 MagnitudeType resNorm_;
449 MagnitudeType matResNorm_;
450
451 // Timers.
452 std::string label_;
453 Teuchos::RCP<Teuchos::Time> timerSolve_;
454
455 // Internal state variables.
456 bool isSet_;
457 bool loaDetected_;
458};
459
460template<class ScalarType, class MV, class OP>
462 lambda_ (STM::zero ()),
463 relRhsErr_ (Teuchos::as<MagnitudeType> (10) * STM::squareroot (STM::eps ())),
464 relMatErr_ (Teuchos::as<MagnitudeType> (10) * STM::squareroot (STM::eps ())),
465 condMax_ (STM::one () / STM::eps ()),
466 maxIters_ (1000),
467 termIterMax_ (1),
468 verbosity_ (Belos::Errors),
469 outputStyle_ (Belos::General),
470 outputFreq_ (-1),
471 numIters_ (0),
472 matCondNum_ (STM::zero ()),
473 matNorm_ (STM::zero ()),
474 resNorm_ (STM::zero ()),
475 matResNorm_ (STM::zero ()),
476 isSet_ (false),
477 loaDetected_ (false)
478{}
479
480template<class ScalarType, class MV, class OP>
483 const Teuchos::RCP<Teuchos::ParameterList>& pl) :
484 problem_ (problem),
485 lambda_ (STM::zero ()),
486 relRhsErr_ (Teuchos::as<MagnitudeType> (10) * STM::squareroot (STM::eps ())),
487 relMatErr_ (Teuchos::as<MagnitudeType> (10) * STM::squareroot (STM::eps ())),
488 condMax_ (STM::one () / STM::eps ()),
489 maxIters_ (1000),
490 termIterMax_ (1),
491 verbosity_ (Belos::Errors),
492 outputStyle_ (Belos::General),
493 outputFreq_ (-1),
494 numIters_ (0),
495 matCondNum_ (STM::zero ()),
496 matNorm_ (STM::zero ()),
497 resNorm_ (STM::zero ()),
498 matResNorm_ (STM::zero ()),
499 isSet_ (false),
500 loaDetected_ (false)
501{
502 // The linear problem to solve is allowed to be null here. The user
503 // must then set a nonnull linear problem (by calling setProblem())
504 // before calling solve().
505 //
506 // Similarly, users are allowed to set a null parameter list here,
507 // but they must first set a nonnull parameter list (by calling
508 // setParameters()) before calling solve().
509 if (! pl.is_null ()) {
510 setParameters (pl);
511 }
512}
513
514
515template<class ScalarType, class MV, class OP>
516Teuchos::RCP<const Teuchos::ParameterList>
518{
519 using Teuchos::ParameterList;
520 using Teuchos::parameterList;
521 using Teuchos::RCP;
522 using Teuchos::rcp;
523 using Teuchos::rcpFromRef;
524
525 // Set all the valid parameters and their default values.
526 if (validParams_.is_null ()) {
527 // We use Teuchos::as just in case MagnitudeType doesn't have a
528 // constructor that takes an int. Otherwise, we could just write
529 // "MagnitudeType(10)".
530 const MagnitudeType ten = Teuchos::as<MagnitudeType> (10);
531 const MagnitudeType sqrtEps = STM::squareroot (STM::eps());
532
533 const MagnitudeType lambda = STM::zero();
535 const MagnitudeType relRhsErr = ten * sqrtEps;
536 const MagnitudeType relMatErr = ten * sqrtEps;
537 const MagnitudeType condMax = STM::one() / STM::eps();
538 const int maxIters = 1000;
539 const int termIterMax = 1;
540 const int verbosity = Belos::Errors;
541 const int outputStyle = Belos::General;
542 const int outputFreq = -1;
543 const std::string label ("Belos");
544
545 RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
546 pl->set ("Output Stream", outputStream, "Teuchos::RCP<std::ostream> "
547 "(reference-counted pointer to the output stream) receiving "
548 "all solver output");
549 pl->set ("Lambda", lambda, "Damping parameter");
550 pl->set ("Rel RHS Err", relRhsErr, "Estimates the error in the data "
551 "defining the right-hand side");
552 pl->set ("Rel Mat Err", relMatErr, "Estimates the error in the data "
553 "defining the matrix.");
554 pl->set ("Condition Limit", condMax, "Bounds the estimated condition "
555 "number of Abar.");
556 pl->set ("Maximum Iterations", maxIters, "Maximum number of iterations");
557 pl->set ("Term Iter Max", termIterMax, "The number of consecutive "
558 "iterations must that satisfy all convergence criteria in order "
559 "for LSQR to stop iterating");
560 pl->set ("Verbosity", verbosity, "Type(s) of solver information written to "
561 "the output stream");
562 pl->set ("Output Style", outputStyle, "Style of solver output");
563 pl->set ("Output Frequency", outputFreq, "Frequency at which information "
564 "is written to the output stream (-1 means \"not at all\")");
565 pl->set ("Timer Label", label, "String to use as a prefix for the timer "
566 "labels");
567 pl->set ("Block Size", 1, "Block size parameter (currently, LSQR requires "
568 "this must always be 1)");
569 validParams_ = pl;
570 }
571 return validParams_;
572}
573
574
575template<class ScalarType, class MV, class OP>
576void
578setParameters (const Teuchos::RCP<Teuchos::ParameterList>& params)
579{
580 using Teuchos::isParameterType;
581 using Teuchos::getParameter;
582 using Teuchos::null;
583 using Teuchos::ParameterList;
584 using Teuchos::parameterList;
585 using Teuchos::RCP;
586 using Teuchos::rcp;
587 using Teuchos::rcp_dynamic_cast;
588 using Teuchos::rcpFromRef;
589 using Teuchos::Time;
590 using Teuchos::TimeMonitor;
591 using Teuchos::Exceptions::InvalidParameter;
592 using Teuchos::Exceptions::InvalidParameterName;
593 using Teuchos::Exceptions::InvalidParameterType;
594
596 (params.is_null (), std::invalid_argument,
597 "Belos::LSQRSolMgr::setParameters: The input ParameterList is null.");
598 RCP<const ParameterList> defaultParams = getValidParameters ();
599
600 // FIXME (mfh 29 Apr 2015) Our users would like to supply one
601 // ParameterList that works for both GMRES and LSQR. Thus, we want
602 // LSQR (the less-used solver) to ignore parameters it doesn't
603 // recognize). For now, therefore, it should not validate, since
604 // validation cannot distinguish between misspellings and
605 // unrecognized parameters. (Perhaps Belos should have a central
606 // facility for all parameters recognized by some solver in Belos,
607 // so we could use that for spell checking.)
608 //
609 //params->validateParameters (*defaultParams);
610
611 // mfh 29 Apr 2015: The convention in Belos is that the input
612 // ParameterList is a "delta" from the current state. Thus, we
613 // don't fill in the input ParameterList with defaults, and we only
614 // change the current state if the corresponding parameter was
615 // explicitly set in the input ParameterList. We set up the solver
616 // with the default state on construction.
617
618 // Get the damping (regularization) parameter lambda.
619 if (params->isParameter ("Lambda")) {
620 lambda_ = params->get<MagnitudeType> ("Lambda");
621 } else if (params->isParameter ("lambda")) {
622 lambda_ = params->get<MagnitudeType> ("lambda");
623 }
624
625 // Get the maximum number of iterations.
626 if (params->isParameter ("Maximum Iterations")) {
627 maxIters_ = params->get<int> ("Maximum Iterations");
628 }
630 (maxIters_ < 0, std::invalid_argument, "Belos::LSQRSolMgr::setParameters: "
631 "\"Maximum Iterations\" = " << maxIters_ << " < 0.");
632
633 // (Re)set the timer label.
634 {
635 const std::string newLabel =
636 params->isParameter ("Timer Label") ?
637 params->get<std::string> ("Timer Label") :
638 label_;
639
640 // Update parameter in our list and solver timer
641 if (newLabel != label_) {
642 label_ = newLabel;
643 }
644
645#ifdef BELOS_TEUCHOS_TIME_MONITOR
646 const std::string newSolveLabel = (newLabel != "") ?
647 (newLabel + ": Belos::LSQRSolMgr total solve time") :
648 std::string ("Belos::LSQRSolMgr total solve time");
649 if (timerSolve_.is_null ()) {
650 // Ask TimeMonitor for a new timer.
651 timerSolve_ = TimeMonitor::getNewCounter (newSolveLabel);
652 } else {
653 // We've already created a timer, but we may have changed its
654 // label. If we did change its name, then we have to forget
655 // about the old timer and create a new one with a different
656 // name. This is because Teuchos::Time doesn't give you a way
657 // to change a timer's name, once you've created it. We assume
658 // that if the user changed the timer's label, then the user
659 // wants to reset the timer's results.
660 const std::string oldSolveLabel = timerSolve_->name ();
661
663 // Tell TimeMonitor to forget about the old timer.
664 // TimeMonitor lets you clear timers by name.
665 TimeMonitor::clearCounter (oldSolveLabel);
666 timerSolve_ = TimeMonitor::getNewCounter (newSolveLabel);
667 }
668 }
669#endif // BELOS_TEUCHOS_TIME_MONITOR
670 }
671
672 // Check for a change in verbosity level
673 if (params->isParameter ("Verbosity")) {
674 int newVerbosity = 0;
675 // ParameterList gets confused sometimes about enums. This
676 // ensures that no matter how "Verbosity" was stored -- either an
677 // an int, or as a Belos::MsgType enum, we will be able to extract
678 // it. If it was stored as some other type, we let the exception
679 // through.
680 try {
681 newVerbosity = params->get<Belos::MsgType> ("Verbosity");
682 } catch (Teuchos::Exceptions::InvalidParameterType&) {
683 newVerbosity = params->get<int> ("Verbosity");
684 }
685 if (newVerbosity != verbosity_) {
686 verbosity_ = newVerbosity;
687 }
688 }
689
690 // (Re)set the output style.
691 if (params->isParameter ("Output Style")) {
692 outputStyle_ = params->get<int> ("Output Style");
693 }
694
695 // Get the output stream for the output manager.
696 //
697 // In case the output stream can't be read back in, we default to
698 // stdout (std::cout), just to ensure reasonable behavior.
699 if (params->isParameter ("Output Stream")) {
700 outputStream_ = params->get<RCP<std::ostream> > ("Output Stream");
701 }
702 // We assume that a null output stream indicates that the user
703 // doesn't want to print anything, so we replace it with a "black
704 // hole" stream that prints nothing sent to it. (We can't use a
705 // null output stream, since the output manager always sends
706 // things it wants to print to the output stream.)
707 if (outputStream_.is_null ()) {
708 outputStream_ = rcp (new Teuchos::oblackholestream ());
709 }
710
711 // Get the frequency of solver output. (For example, -1 means
712 // "never," and 1 means "every iteration.")
713 if (params->isParameter ("Output Frequency")) {
714 outputFreq_ = params->get<int> ("Output Frequency");
715 }
716
717 // Create output manager if we need to, using the verbosity level
718 // and output stream that we fetched above. Status tests (i.e.,
719 // stopping criteria) need this.
720 if (printer_.is_null ()) {
721 printer_ = rcp (new OutputManager<ScalarType> (verbosity_, outputStream_));
722 } else {
723 printer_->setVerbosity (verbosity_);
724 printer_->setOStream (outputStream_);
725 }
726
727 // Check for condition number limit, number of consecutive passed
728 // iterations, relative RHS error, and relative matrix error.
729 // Create the LSQR convergence test if necessary.
730 {
731 if (params->isParameter ("Condition Limit")) {
732 condMax_ = params->get<MagnitudeType> ("Condition Limit");
733 }
734 if (params->isParameter ("Term Iter Max")) {
735 termIterMax_ = params->get<int> ("Term Iter Max");
736 }
737 if (params->isParameter ("Rel RHS Err")) {
738 relRhsErr_ = params->get<MagnitudeType> ("Rel RHS Err");
739 }
740 else if (params->isParameter ("Convergence Tolerance")) {
741 // NOTE (mfh 29 Apr 2015) We accept this parameter as an alias
742 // for "Rel RHS Err".
743 relRhsErr_ = params->get<MagnitudeType> ("Convergence Tolerance");
744 }
745
746 if (params->isParameter ("Rel Mat Err")) {
747 relMatErr_ = params->get<MagnitudeType> ("Rel Mat Err");
748 }
749
750 // Create the LSQR convergence test if it doesn't exist yet.
751 // Otherwise, update its parameters.
752 if (convTest_.is_null ()) {
753 convTest_ =
754 rcp (new LSQRStatusTest<ScalarType,MV,OP> (condMax_, termIterMax_,
755 relRhsErr_, relMatErr_));
756 } else {
757 convTest_->setCondLim (condMax_);
758 convTest_->setTermIterMax (termIterMax_);
759 convTest_->setRelRhsErr (relRhsErr_);
760 convTest_->setRelMatErr (relMatErr_);
761 }
762 }
763
764 // Create the status test for maximum number of iterations if
765 // necessary. Otherwise, update it with the new maximum iteration
766 // count.
767 if (maxIterTest_.is_null()) {
768 maxIterTest_ = rcp (new StatusTestMaxIters<ScalarType,MV,OP> (maxIters_));
769 } else {
770 maxIterTest_->setMaxIters (maxIters_);
771 }
772
773 // The stopping criterion is an OR combination of the test for
774 // maximum number of iterations, and the LSQR convergence test.
775 // ("OR combination" means that both tests will always be evaluated,
776 // as opposed to a SEQ combination.)
778 // If sTest_ is not null, then maxIterTest_ and convTest_ were
779 // already constructed on entry to this routine, and sTest_ has
780 // their pointers. Thus, maxIterTest_ and convTest_ have gotten any
781 // parameter changes, so we don't need to do anything to sTest_.
782 if (sTest_.is_null()) {
783 sTest_ = rcp (new combo_type (combo_type::OR, maxIterTest_, convTest_));
784 }
785
786 if (outputTest_.is_null ()) {
787 // Create the status test output class.
788 // This class manages and formats the output from the status test.
790 outputTest_ = stoFactory.create (printer_, sTest_, outputFreq_,
792 // Set the solver string for the output test.
793 const std::string solverDesc = " LSQR ";
794 outputTest_->setSolverDesc (solverDesc);
795 } else {
796 // FIXME (mfh 18 Sep 2011) How do we change the output style of
797 // outputTest_, without destroying and recreating it?
798 outputTest_->setOutputManager (printer_);
799 outputTest_->setChild (sTest_);
800 outputTest_->setOutputFrequency (outputFreq_);
801 // Since outputTest_ can only be created here, I'm assuming that
802 // the fourth constructor argument ("printStates") was set
803 // correctly on constrution; I don't need to reset it (and I can't
804 // set it anyway, given StatusTestOutput's interface).
805 }
806
807 // At this point, params is a valid ParameterList. Now we can
808 // "commit" it to our instance's ParameterList.
809 params_ = params;
810
811 // Inform the solver manager that the current parameters were set.
812 isSet_ = true;
813}
814
815
816template<class ScalarType, class MV, class OP>
819{
820 using Teuchos::RCP;
821 using Teuchos::rcp;
822
823 // Set the current parameters if they were not set before. NOTE:
824 // This may occur if the user generated the solver manager with the
825 // default constructor, but did not set any parameters using
826 // setParameters().
827 if (! isSet_) {
828 this->setParameters (Teuchos::parameterList (* (getValidParameters ())));
829 }
830
832 (problem_.is_null (), LSQRSolMgrLinearProblemFailure,
833 "Belos::LSQRSolMgr::solve: The linear problem to solve is null.");
835 (! problem_->isProblemSet (), LSQRSolMgrLinearProblemFailure,
836 "Belos::LSQRSolMgr::solve: The linear problem is not ready, "
837 "as its setProblem() method has not been called.");
839 (MVT::GetNumberVecs (*(problem_->getRHS ())) != 1,
840 LSQRSolMgrBlockSizeFailure, "Belos::LSQRSolMgr::solve: "
841 "The current implementation of LSQR only knows how to solve problems "
842 "with one right-hand side, but the linear problem to solve has "
843 << MVT::GetNumberVecs (* (problem_->getRHS ()))
844 << " right-hand sides.");
845
846 // We've validated the LinearProblem instance above. If any of the
847 // StatusTests needed to be initialized using information from the
848 // LinearProblem, now would be the time to do so. (This is true of
849 // GMRES, where the residual convergence test(s) to instantiate
850 // depend on knowing whether there is a left preconditioner. This
851 // is why GMRES has an "isSTSet_" Boolean member datum, which tells
852 // you whether the status tests have been instantiated and are ready
853 // for use.
854
855 // test isFlexible might go here.
856
857 // Next the right-hand sides to solve are identified. Among other things,
858 // this enables getCurrLHSVec() to get the current initial guess vector,
859 // and getCurrRHSVec() to get the current right-hand side (in Iter).
860 std::vector<int> currRHSIdx (1, 0);
861 problem_->setLSIndex (currRHSIdx);
862
863 // Reset the status test.
864 outputTest_->reset ();
865
866 // Don't assume convergence unless we've verified that the
867 // convergence test passed.
868 bool isConverged = false;
869
870 // FIXME: Currently we are setting the initial guess to zero, since
871 // the solver doesn't yet know how to handle a nonzero initial
872 // guess. This could be fixed by rewriting the solver to work with
873 // the residual and a delta.
874 //
875 // In a least squares problem with a nonzero initial guess, the
876 // minimzation problem involves the distance (in a norm depending on
877 // the preconditioner) between the solution and the the initial
878 // guess.
879
881 // Solve the linear problem using LSQR
883
884 // Parameter list for the LSQR iteration.
885 Teuchos::ParameterList plist;
886
887 // Use the solver manager's "Lambda" parameter to set the
888 // iteration's "Lambda" parameter. We know that the solver
889 // manager's parameter list (params_) does indeed contain the
890 // "Lambda" parameter, because solve() always ensures that
891 // setParameters() has been called.
892 plist.set ("Lambda", lambda_);
893
896 rcp (new iter_type (problem_, printer_, outputTest_, plist));
897#ifdef BELOS_TEUCHOS_TIME_MONITOR
898 Teuchos::TimeMonitor slvtimer (*timerSolve_);
899#endif
900
901 // Reset the number of iterations.
902 lsqr_iter->resetNumIters ();
903 // Reset the number of calls that the status test output knows about.
904 outputTest_->resetNumCalls ();
905 // Set the new state and initialize the solver.
907 lsqr_iter->initializeLSQR (newstate);
908 // tell lsqr_iter to iterate
909 try {
910 lsqr_iter->iterate ();
911
912 // First check for convergence. If we didn't converge, then check
913 // whether we reached the maximum number of iterations. If
914 // neither of those happened, there must have been a bug.
915 if (convTest_->getStatus () == Belos::Passed) {
916 isConverged = true;
917 } else if (maxIterTest_->getStatus () == Belos::Passed) {
918 isConverged = false;
919 } else {
921 (true, std::logic_error, "Belos::LSQRSolMgr::solve: "
922 "LSQRIteration::iterate returned without either the convergence test "
923 "or the maximum iteration count test passing. "
924 "Please report this bug to the Belos developers.");
925 }
926 } catch (const std::exception& e) {
927 printer_->stream(Belos::Errors)
928 << "Error! Caught std::exception in LSQRIter::iterate at iteration "
929 << lsqr_iter->getNumIters () << std::endl << e.what () << std::endl;
930 throw;
931 }
932
933 // identify current linear system as solved LinearProblem
934 problem_->setCurrLS();
935 // print final summary
936 sTest_->print (printer_->stream (Belos::FinalSummary));
937
938 // Print timing information, if the corresponding compile-time and
939 // run-time options are enabled.
940#ifdef BELOS_TEUCHOS_TIME_MONITOR
941 // Calling summarize() can be expensive, so don't call unless the
942 // user wants to print out timing details. summarize() will do all
943 // the work even if it's passed a "black hole" output stream.
944 if (verbosity_ & TimingDetails)
945 Teuchos::TimeMonitor::summarize (printer_->stream (Belos::TimingDetails));
946#endif // BELOS_TEUCHOS_TIME_MONITOR
947
948 // A posteriori solve information
949 numIters_ = maxIterTest_->getNumIters();
950 matCondNum_ = convTest_->getMatCondNum();
951 matNorm_ = convTest_->getMatNorm();
952 resNorm_ = convTest_->getResidNorm();
953 matResNorm_ = convTest_->getLSResidNorm();
954
955 if (! isConverged) {
956 return Belos::Unconverged;
957 } else {
958 return Belos::Converged;
959 }
960}
961
962// LSQRSolMgr requires the solver manager to return an eponymous std::string.
963template<class ScalarType, class MV, class OP>
965{
966 std::ostringstream oss;
967 oss << "LSQRSolMgr<...," << STS::name () << ">";
968 oss << "{";
969 oss << "Lambda: " << lambda_;
970 oss << ", condition number limit: " << condMax_;
971 oss << ", relative RHS Error: " << relRhsErr_;
972 oss << ", relative Matrix Error: " << relMatErr_;
973 oss << ", maximum number of iterations: " << maxIters_;
974 oss << ", termIterMax: " << termIterMax_;
975 oss << "}";
976 return oss.str ();
977}
978
979} // end Belos namespace
980
981#endif /* BELOS_LSQR_SOLMGR_HPP */
Belos header file which uses auto-configuration information to include necessary C++ headers.
Belos concrete class that iterates LSQR.
IterationState contains the data that defines the state of the LSQR solver at any given time.
Belos::StatusTest class defining LSQR convergence.
Class which describes the linear problem to be solved by the iterative solver.
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::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.
Base class for Belos::SolverManager subclasses which normally can only compile for real ScalarType.
LSQRSolMgrBlockSizeFailure is thrown when the linear problem has more than one RHS.
LSQRSolMgrBlockSizeFailure(const std::string &what_arg)
Belos::LSQRSolMgrLinearProblemFailure is thrown when the linear problem is not setup (i....
LSQRSolMgrLinearProblemFailure(const std::string &what_arg)
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const override
Get a parameter list containing the current parameters for this object.
void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem) override
Set the linear problem that needs to be solved.
const LinearProblem< ScalarType, MV, OP > & getProblem() const override
Get current linear problem being solved for in this object.
MagnitudeType getMatCondNum() const
Estimated matrix condition number from the last solve.
int getNumIters() const override
Iteration count from the last solve.
virtual ~LSQRSolMgr()
Destructor (declared virtual for memory safety of base classes).
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers for this object.
void reset(const ResetType type) override
reset the solver manager as specified by the ResetType, informs the solver manager that the solver sh...
bool isLOADetected() const override
Whether a loss of accuracy was detected during the last solve.
MagnitudeType getMatResNorm() const
Estimate of (residual vector ) from the last solve.
MagnitudeType getResNorm() const
Estimated residual norm from the last solve.
MagnitudeType getMatNorm() const
Estimated matrix Frobenius norm from the last solve.
Teuchos::RCP< SolverManager< ScalarType, MV, OP > > clone() const override
clone for Inverted Injection (DII)
LSQR method (for linear systems and linear least-squares problems).
Teuchos::RCP< SolverManager< ScalarType, MV, OP > > clone() const override
clone for Inverted Injection (DII)
LSQRSolMgr(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem, const Teuchos::RCP< Teuchos::ParameterList > &pl)
Alternative run-time polymorphic interface for operators.
Operator()
Default constructor (does nothing).
MsgType
Available message types recognized by the linear solvers.
@ FinalSummary
@ TimingDetails
ReturnType
Whether the Belos solve converged for all linear systems.
@ Unconverged
ResetType
How to reset the solver.

Generated for Belos by doxygen 1.9.8