12#ifndef BELOS_LSQR_STATUS_TEST_HPP
13#define BELOS_LSQR_STATUS_TEST_HPP
33template <
class ScalarType,
class MV,
class OP,
class DM = Belos::DefaultDenseMatrix<
int, ScalarType>>
39 typedef Teuchos::ScalarTraits<ScalarType>
SCT;
53 int term_iter_max = 1,
83 rcondMin_ = (condMax > 0) ? (Teuchos::ScalarTraits< MagnitudeType >::one() / condMax) : Teuchos::ScalarTraits< MagnitudeType >::eps();
87 term_iter_max_ = term_iter_max;
88 if (term_iter_max_ < 1)
93 rel_rhs_err_ = rel_rhs_err;
97 rel_mat_err_ = rel_mat_err;
138 void print(std::ostream& os,
int indent = 0)
const;
159 std::ostringstream oss;
160 oss <<
"LSQRStatusTest<>: [ limit of condition number = " << condMax_ <<
" ]";
208template <
class ScalarType,
class MV,
class OP,
class DM>
215 term_iter_max_ (term_iter_max),
216 rel_rhs_err_ (rel_rhs_err),
217 rel_mat_err_ (rel_mat_err),
227template <
class ScalarType,
class MV,
class OP,
class DM>
231template <
class ScalarType,
class MV,
class OP,
class DM>
237template <
class ScalarType,
class MV,
class OP,
class DM>
240 const MagnitudeType MTzero = Teuchos::ScalarTraits<MagnitudeType>::zero();
241 const MagnitudeType MTone = Teuchos::ScalarTraits<MagnitudeType>::one();
242 if (condMax_ > MTzero )
244 rcondMin_ = MTone / condMax_;
248 rcondMin_ = Teuchos::ScalarTraits< MagnitudeType >::eps();
251 bool termIterFlag =
false;
253 TEUCHOS_ASSERT(solver != NULL);
274 std::cout <<
" X " << state.
sol_norm
283 const MagnitudeType zero = Teuchos::ScalarTraits<MagnitudeType>::zero();
284 const ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
285 ScalarType stop_crit_1 = zero;
286 if( state.
bnorm > zero )
290 ScalarType stop_crit_2 = zero;
308 ScalarType resid_tol_mach = Teuchos::ScalarTraits< MagnitudeType >::eps() + Teuchos::ScalarTraits< MagnitudeType >::eps() * state.
frob_mat_norm * state.
sol_norm / state.
bnorm;
325 if (stop_crit_1 <= resid_tol || stop_crit_2 <= rel_mat_err_ || stop_crit_3 <= rcondMin_ || stop_crit_1 <= resid_tol_mach || stop_crit_2 <= Teuchos::ScalarTraits< MagnitudeType >::eps() || stop_crit_3 <= Teuchos::ScalarTraits< MagnitudeType >::eps()) {
328 if (stop_crit_1 <= resid_tol )
329 std::cout <<
"Conv: stop_crit_1 " << stop_crit_1 <<
" resid_tol " << resid_tol << std::endl;
331 if (stop_crit_1 <= resid_tol_mach )
332 std::cout <<
"Conv: stop_crit_1 " << stop_crit_1 <<
" resid_tol_mach " << resid_tol_mach << std::endl;
334 if (stop_crit_2 <= rel_mat_err_ )
335 std::cout <<
"Conv: stop_crit_2 " << stop_crit_2 <<
" rel_mat_err " << rel_mat_err_ << std::endl;
337 if (stop_crit_2 <= Teuchos::ScalarTraits< MagnitudeType >::eps() )
338 std::cout <<
"Conv: stop_crit_2 " << stop_crit_2 <<
" eps " << Teuchos::ScalarTraits< MagnitudeType >::eps() << std::endl;
340 if (stop_crit_3 <= rcondMin_ )
341 std::cout <<
"Conv: stop_crit_3 " << stop_crit_3 <<
" rcondMin_ " << rcondMin_ << std::endl;
343 if (stop_crit_3 <= Teuchos::ScalarTraits< MagnitudeType >::eps() )
344 std::cout <<
"Conv: stop_crit_3 " << stop_crit_3 <<
" eps " << Teuchos::ScalarTraits< MagnitudeType >::eps() << std::endl;
363template <
class ScalarType,
class MV,
class OP,
class DM>
366 for (
int j = 0; j < indent; j++)
369 os <<
"limit of condition number = " << condMax_ << std::endl;
370 os <<
"limit of condition number = " << condMax_ << std::endl;
373template <
class ScalarType,
class MV,
class OP,
class DM>
376 os << std::left << std::setw(13) << std::setfill(
'.');
389 os << std::left << std::setfill(
' ');
Belos concrete class that iterates LSQR.
Pure virtual base class for defining the status testing capabilities of Belos.
Collection of types and exceptions used within the Belos solvers.
Implementation of the LSQR iteration.
LSQRIterationState< ScalarType, MV > getState() const
Get the current state of the linear solver.
MagnitudeType getResidNorm() const
Returns the value of the observed norm of the residual r = b-Ax.
Teuchos::ScalarTraits< ScalarType > SCT
Belos::MultiVecTraits< ScalarType, MV, DM > MVT
virtual ~LSQRStatusTest()
Destructor.
MagnitudeType getLSResidNorm() const
Returns the value of the observed norm of the Least Squares residual A^T r.
SCT::magnitudeType MagnitudeType
int setRelRhsErr(MagnitudeType rel_rhs_err)
Belos::StatusType firstCallCheckStatusSetup(Belos::Iteration< ScalarType, MV, OP, DM > *iSolver)
Called in checkStatus exactly once, on the first call to checkStatus.
void printStatus(std::ostream &os, Belos::StatusType type) const
Print message for each status specific to this stopping test.
std::string description() const
Method to return description of the maximum iteration status test.
void reset()
Resets the status test to the initial internal state.
int getTermIterMax() const
Returns the number of successful convergent iterations required set in the constructor.
int getTermIter() const
!Returns the current number of successful iterations from the most recent StatusTest call.
Belos::StatusType getStatus() const
Return the result of the most recent CheckStatus call.
MagnitudeType getRelRhsErr() const
Returns the value of the estimate of the relative error in the data defining b set in the constructor...
MagnitudeType getMatNorm() const
Returns the value of the observed (Frobenius) norm of A.
int setRelMatErr(MagnitudeType rel_mat_err)
LSQRStatusTest(MagnitudeType condMax=0.0, int term_iter_max=1, MagnitudeType rel_rhs_err=0.0, MagnitudeType rel_mat_err=0.0)
Constructor.
Belos::StatusType checkStatus(Belos::Iteration< ScalarType, MV, OP, DM > *iSolver)
Check convergence status of the iterative solver: Unconverged, Converged, Failed.
MagnitudeType getMatCondNum() const
Returns the value of the observed condition number of Abar.
MagnitudeType getMatErr() const
Returns the value of the estimate of the relative error in the data defining A set in the constructor...
int setTermIterMax(int term_iter_max)
MagnitudeType getCondMaxLim() const
Returns the value of the upper limit of the condition number of Abar set in the constructor.
void print(std::ostream &os, int indent=0) const
Output formatted description of stopping test to output stream.
int setCondLim(MagnitudeType condMax)
Set the tolerances.
Traits class which defines basic operations on multivectors.
A pure virtual class for defining the status tests for the Belos iterative solvers.
StatusType
Whether the StatusTest wants iteration to stop.
Structure to contain pointers to LSQRIteration state variables, ...
ScalarType sol_norm
An estimate of the norm of the solution.
ScalarType frob_mat_norm
An approximation to the Frobenius norm of A.
ScalarType mat_resid_norm
An estimate of the norm of A^T*resid.
ScalarType bnorm
The norm of the RHS vector b.
ScalarType resid_norm
The current residual norm.
ScalarType mat_cond_num
An approximation to the condition number of A.