|
Belos Package Browser (Single Doxygen Collection)
Development
|
Go to the documentation of this file.
42 #ifndef BELOS_LSQR_SOLMGR_HPP
43 #define BELOS_LSQR_SOLMGR_HPP
65 #ifdef BELOS_TEUCHOS_TIME_MONITOR
234 template<
class ScalarType,
class MV,
class OP,
238 Teuchos::ScalarTraits<ScalarType>::isComplex>
263 template<
class ScalarType,
class MV,
class OP>
349 return Teuchos::tuple (timerSolve_);
423 problem_->setProblem ();
456 std::string description ()
const override;
509 template<
class ScalarType,
class MV,
class OP>
511 lambda_ (
STM::zero ()),
514 condMax_ (
STM::one () /
STM::eps ()),
521 matCondNum_ (
STM::zero ()),
522 matNorm_ (
STM::zero ()),
523 resNorm_ (
STM::zero ()),
524 matResNorm_ (
STM::zero ()),
529 template<
class ScalarType,
class MV,
class OP>
534 lambda_ (
STM::zero ()),
537 condMax_ (
STM::one () /
STM::eps ()),
544 matCondNum_ (
STM::zero ()),
545 matNorm_ (
STM::zero ()),
546 resNorm_ (
STM::zero ()),
547 matResNorm_ (
STM::zero ()),
564 template<
class ScalarType,
class MV,
class OP>
569 using Teuchos::parameterList;
572 using Teuchos::rcpFromRef;
575 if (validParams_.is_null ()) {
583 RCP<std::ostream> outputStream = rcpFromRef (std::cout);
587 const int maxIters = 1000;
588 const int termIterMax = 1;
591 const int outputFreq = -1;
592 const std::string label (
"Belos");
595 pl->
set (
"Output Stream", outputStream,
"Teuchos::RCP<std::ostream> "
596 "(reference-counted pointer to the output stream) receiving "
597 "all solver output");
598 pl->
set (
"Lambda", lambda,
"Damping parameter");
599 pl->
set (
"Rel RHS Err", relRhsErr,
"Estimates the error in the data "
600 "defining the right-hand side");
601 pl->
set (
"Rel Mat Err", relMatErr,
"Estimates the error in the data "
602 "defining the matrix.");
603 pl->
set (
"Condition Limit", condMax,
"Bounds the estimated condition "
605 pl->
set (
"Maximum Iterations", maxIters,
"Maximum number of iterations");
606 pl->
set (
"Term Iter Max", termIterMax,
"The number of consecutive "
607 "iterations must that satisfy all convergence criteria in order "
608 "for LSQR to stop iterating");
609 pl->
set (
"Verbosity", verbosity,
"Type(s) of solver information written to "
610 "the output stream");
611 pl->
set (
"Output Style", outputStyle,
"Style of solver output");
612 pl->
set (
"Output Frequency", outputFreq,
"Frequency at which information "
613 "is written to the output stream (-1 means \"not at all\")");
614 pl->
set (
"Timer Label", label,
"String to use as a prefix for the timer "
616 pl->
set (
"Block Size", 1,
"Block size parameter (currently, LSQR requires "
617 "this must always be 1)");
624 template<
class ScalarType,
class MV,
class OP>
629 using Teuchos::isParameterType;
630 using Teuchos::getParameter;
633 using Teuchos::parameterList;
636 using Teuchos::rcp_dynamic_cast;
637 using Teuchos::rcpFromRef;
645 (params.
is_null (), std::invalid_argument,
646 "Belos::LSQRSolMgr::setParameters: The input ParameterList is null.");
647 RCP<const ParameterList> defaultParams = getValidParameters ();
676 maxIters_ = params->
get<
int> (
"Maximum Iterations");
679 (maxIters_ < 0, std::invalid_argument,
"Belos::LSQRSolMgr::setParameters: "
680 "\"Maximum Iterations\" = " << maxIters_ <<
" < 0.");
684 const std::string newLabel =
686 params->
get<std::string> (
"Timer Label") :
690 if (newLabel != label_) {
694 #ifdef BELOS_TEUCHOS_TIME_MONITOR
695 const std::string newSolveLabel = (newLabel !=
"") ?
696 (newLabel +
": Belos::LSQRSolMgr total solve time") :
697 std::string (
"Belos::LSQRSolMgr total solve time");
698 if (timerSolve_.is_null ()) {
700 timerSolve_ = TimeMonitor::getNewCounter (newSolveLabel);
709 const std::string oldSolveLabel = timerSolve_->name ();
711 if (oldSolveLabel != newSolveLabel) {
714 TimeMonitor::clearCounter (oldSolveLabel);
715 timerSolve_ = TimeMonitor::getNewCounter (newSolveLabel);
718 #endif // BELOS_TEUCHOS_TIME_MONITOR
723 int newVerbosity = 0;
732 newVerbosity = params->
get<
int> (
"Verbosity");
734 if (newVerbosity != verbosity_) {
735 verbosity_ = newVerbosity;
741 outputStyle_ = params->
get<
int> (
"Output Style");
749 outputStream_ = params->
get<RCP<std::ostream> > (
"Output Stream");
756 if (outputStream_.is_null ()) {
763 outputFreq_ = params->
get<
int> (
"Output Frequency");
769 if (printer_.is_null ()) {
772 printer_->setVerbosity (verbosity_);
773 printer_->setOStream (outputStream_);
784 termIterMax_ = params->
get<
int> (
"Term Iter Max");
789 else if (params->
isParameter (
"Convergence Tolerance")) {
801 if (convTest_.is_null ()) {
804 relRhsErr_, relMatErr_));
806 convTest_->setCondLim (condMax_);
807 convTest_->setTermIterMax (termIterMax_);
808 convTest_->setRelRhsErr (relRhsErr_);
809 convTest_->setRelMatErr (relMatErr_);
816 if (maxIterTest_.is_null()) {
819 maxIterTest_->setMaxIters (maxIters_);
831 if (sTest_.is_null()) {
832 sTest_ =
rcp (
new combo_type (combo_type::OR, maxIterTest_, convTest_));
835 if (outputTest_.is_null ()) {
839 outputTest_ = stoFactory.
create (printer_, sTest_, outputFreq_,
842 const std::string solverDesc =
" LSQR ";
843 outputTest_->setSolverDesc (solverDesc);
847 outputTest_->setOutputManager (printer_);
848 outputTest_->setChild (sTest_);
849 outputTest_->setOutputFrequency (outputFreq_);
865 template<
class ScalarType,
class MV,
class OP>
877 this->setParameters (Teuchos::parameterList (* (getValidParameters ())));
882 "Belos::LSQRSolMgr::solve: The linear problem to solve is null.");
885 "Belos::LSQRSolMgr::solve: The linear problem is not ready, "
886 "as its setProblem() method has not been called.");
888 (MVT::GetNumberVecs (*(problem_->getRHS ())) != 1,
890 "The current implementation of LSQR only knows how to solve problems "
891 "with one right-hand side, but the linear problem to solve has "
892 << MVT::GetNumberVecs (* (problem_->getRHS ()))
893 <<
" right-hand sides.");
909 std::vector<int> currRHSIdx (1, 0);
910 problem_->setLSIndex (currRHSIdx);
913 outputTest_->reset ();
917 bool isConverged =
false;
941 plist.
set (
"Lambda", lambda_);
944 RCP<iter_type> lsqr_iter =
945 rcp (
new iter_type (problem_, printer_, outputTest_, plist));
946 #ifdef BELOS_TEUCHOS_TIME_MONITOR
951 lsqr_iter->resetNumIters ();
953 outputTest_->resetNumCalls ();
956 lsqr_iter->initializeLSQR (newstate);
959 lsqr_iter->iterate ();
970 (
true, std::logic_error,
"Belos::LSQRSolMgr::solve: "
971 "LSQRIteration::iterate returned without either the convergence test "
972 "or the maximum iteration count test passing. "
973 "Please report this bug to the Belos developers.");
975 }
catch (
const std::exception& e) {
977 <<
"Error! Caught std::exception in LSQRIter::iterate at iteration "
978 << lsqr_iter->getNumIters () << std::endl << e.what () << std::endl;
983 problem_->setCurrLS();
989 #ifdef BELOS_TEUCHOS_TIME_MONITOR
995 #endif // BELOS_TEUCHOS_TIME_MONITOR
998 numIters_ = maxIterTest_->getNumIters();
999 matCondNum_ = convTest_->getMatCondNum();
1000 matNorm_ = convTest_->getMatNorm();
1001 resNorm_ = convTest_->getResidNorm();
1002 matResNorm_ = convTest_->getLSResidNorm();
1004 if (! isConverged) {
1012 template<
class ScalarType,
class MV,
class OP>
1015 std::ostringstream oss;
1016 oss <<
"LSQRSolMgr<...," << STS::name () <<
">";
1018 oss <<
"Lambda: " << lambda_;
1019 oss <<
", condition number limit: " << condMax_;
1020 oss <<
", relative RHS Error: " << relRhsErr_;
1021 oss <<
", relative Matrix Error: " << relMatErr_;
1022 oss <<
", maximum number of iterations: " << maxIters_;
1023 oss <<
", termIterMax: " << termIterMax_;
static void summarize(Ptr< const Comm< int > > comm, std::ostream &out=std::cout, const bool alwaysWriteLocal=false, const bool writeGlobalStats=true, const bool writeZeroTimers=true, const ECounterSetOp setOp=Intersection, const std::string &filter="", const bool ignoreZeroTimers=false)
Belos header file which uses auto-configuration information to include necessary C++ headers.
Teuchos::RCP< SolverManager< ScalarType, MV, OP > > clone() const override
clone for Inverted Injection (DII)
static const bool isComplex
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...
Class which describes the linear problem to be solved by the iterative solver.
Base class for Belos::SolverManager subclasses which normally can only compile for real ScalarType.
void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem) override
Set the linear problem that needs to be solved.
Details::RealSolverManager< ScalarType, MV, OP, isComplex > base_type
LSQRSolMgrBlockSizeFailure is thrown when the linear problem has more than one RHS.
Belos::LSQRSolMgrLinearProblemFailure is thrown when the linear problem is not setup (i....
Teuchos::RCP< StatusTestMaxIters< ScalarType, MV, OP > > maxIterTest_
A Belos::StatusTest class for specifying a maximum number of iterations.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Belos concrete class that iterates LSQR.
Teuchos::ScalarTraits< ScalarType > STS
Pure virtual base class which describes the basic interface for a solver manager.
Teuchos::RCP< StatusTest< ScalarType, MV, OP > > sTest_
The "master" status test (that includes all status tests).
Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > problem_
The linear problem to solve.
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.
A linear system to solve, and its associated information.
Teuchos::RCP< LSQRStatusTest< ScalarType, MV, OP > > convTest_
MagnitudeType getMatCondNum() const
Estimated matrix condition number from the last solve.
const LinearProblem< ScalarType, MV, OP > & getProblem() const override
Get current linear problem being solved for in this object.
LSQRSolMgrOrthoFailure(const std::string &what_arg)
Class which manages the output and verbosity of the Belos solvers.
virtual ~LSQRSolMgr()
Destructor (declared virtual for memory safety of base classes).
T & get(ParameterList &l, const std::string &name)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Belos::StatusTest class for specifying a maximum number of iterations.
OperatorTraits< ScalarType, MV, OP > OPT
Teuchos::RCP< const Teuchos::ParameterList > validParams_
Default parameter list.
LSQR method (for linear systems and linear least-squares problems).
LSQRSolMgrOrthoFailure is thrown when the orthogonalization manager is unable to generate orthonormal...
Teuchos::ScalarTraits< MagnitudeType > STM
bool isParameter(const std::string &name) const
int getNumIters() const override
Iteration count from the last solve.
MagnitudeType getMatNorm() const
Estimated matrix Frobenius norm from the last solve.
ReturnType
Whether the Belos solve converged for all linear systems.
Teuchos::RCP< Teuchos::ParameterList > params_
Current parameter list.
LSQRSolMgrLinearProblemFailure(const std::string &what_arg)
Teuchos::RCP< StatusTestOutput< ScalarType, MV, OP > > outputTest_
Teuchos::ScalarTraits< ScalarType >::magnitudeType MagnitudeType
ResetType
How to reset the solver.
Structure to contain pointers to LSQRIteration state variables, ...
Teuchos::RCP< SolverManager< ScalarType, MV, OP > > clone() const override
clone for Inverted Injection (DII)
MsgType
Available message types recognized by the linear solvers.
TypeTo as(const TypeFrom &t)
LSQRSolMgr(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem, const Teuchos::RCP< Teuchos::ParameterList > &pl)
IterationState contains the data that defines the state of the LSQR solver at any given time.
MultiVecTraits< ScalarType, MV > MVT
Parent class to all Belos exceptions.
A class for extending the status testing capabilities of Belos via logical combinations.
A factory class for generating StatusTestOutput objects.
Teuchos::RCP< std::ostream > outputStream_
Output stream to which to write status output.
bool isLOADetected() const override
Whether a loss of accuracy was detected during the last solve.
MagnitudeType matResNorm_
Collection of types and exceptions used within the Belos solvers.
Belos::StatusTest class defining LSQR convergence.
A factory class for generating StatusTestOutput objects.
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers for this object.
MagnitudeType getResNorm() const
Estimated residual norm from the last solve.
Teuchos::RCP< OutputManager< ScalarType > > printer_
The output manager.
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const override
Get a parameter list containing the current parameters for this object.
bool is_null(const RCP< T > &p)
Traits class which defines basic operations on multivectors.
MagnitudeType getMatResNorm() const
Estimate of (residual vector ) from the last solve.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
LSQRSolMgrBlockSizeFailure(const std::string &what_arg)
Teuchos::RCP< Teuchos::Time > timerSolve_
Belos::StatusTest for logically combining several status tests.
Implementation of the LSQR iteration.
MagnitudeType matCondNum_
void reset(const ResetType type) override
reset the solver manager as specified by the ResetType, informs the solver manager that the solver sh...