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

Generated for Belos by doxygen 1.9.8