12#ifndef BELOS_LSQR_STATUS_TEST_HPP
13#define BELOS_LSQR_STATUS_TEST_HPP
32template <
class ScalarType,
class MV,
class OP>
38 typedef Teuchos::ScalarTraits<ScalarType>
SCT;
52 int term_iter_max = 1,
82 rcondMin_ = (condMax > 0) ? (Teuchos::ScalarTraits< MagnitudeType >::one() / condMax) : Teuchos::ScalarTraits< MagnitudeType >::eps();
86 term_iter_max_ = term_iter_max;
87 if (term_iter_max_ < 1)
92 rel_rhs_err_ = rel_rhs_err;
96 rel_mat_err_ = rel_mat_err;
137 void print(std::ostream& os,
int indent = 0)
const;
158 std::ostringstream oss;
159 oss <<
"LSQRStatusTest<>: [ limit of condition number = " << condMax_ <<
" ]";
207template <
class ScalarType,
class MV,
class OP>
214 term_iter_max_ (term_iter_max),
215 rel_rhs_err_ (rel_rhs_err),
216 rel_mat_err_ (rel_mat_err),
226template <
class ScalarType,
class MV,
class OP>
230template <
class ScalarType,
class MV,
class OP>
236template <
class ScalarType,
class MV,
class OP>
239 const MagnitudeType MTzero = Teuchos::ScalarTraits<MagnitudeType>::zero();
240 const MagnitudeType MTone = Teuchos::ScalarTraits<MagnitudeType>::one();
241 if (condMax_ > MTzero )
243 rcondMin_ = MTone / condMax_;
247 rcondMin_ = Teuchos::ScalarTraits< MagnitudeType >::eps();
250 bool termIterFlag =
false;
252 TEUCHOS_ASSERT(solver != NULL);
273 std::cout <<
" X " << state.
sol_norm
282 const MagnitudeType zero = Teuchos::ScalarTraits<MagnitudeType>::zero();
283 const ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
284 ScalarType stop_crit_1 = zero;
285 if( state.
bnorm > zero )
289 ScalarType stop_crit_2 = zero;
307 ScalarType resid_tol_mach = Teuchos::ScalarTraits< MagnitudeType >::eps() + Teuchos::ScalarTraits< MagnitudeType >::eps() * state.
frob_mat_norm * state.
sol_norm / state.
bnorm;
324 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()) {
327 if (stop_crit_1 <= resid_tol )
328 std::cout <<
"Conv: stop_crit_1 " << stop_crit_1 <<
" resid_tol " << resid_tol << std::endl;
330 if (stop_crit_1 <= resid_tol_mach )
331 std::cout <<
"Conv: stop_crit_1 " << stop_crit_1 <<
" resid_tol_mach " << resid_tol_mach << std::endl;
333 if (stop_crit_2 <= rel_mat_err_ )
334 std::cout <<
"Conv: stop_crit_2 " << stop_crit_2 <<
" rel_mat_err " << rel_mat_err_ << std::endl;
336 if (stop_crit_2 <= Teuchos::ScalarTraits< MagnitudeType >::eps() )
337 std::cout <<
"Conv: stop_crit_2 " << stop_crit_2 <<
" eps " << Teuchos::ScalarTraits< MagnitudeType >::eps() << std::endl;
339 if (stop_crit_3 <= rcondMin_ )
340 std::cout <<
"Conv: stop_crit_3 " << stop_crit_3 <<
" rcondMin_ " << rcondMin_ << std::endl;
342 if (stop_crit_3 <= Teuchos::ScalarTraits< MagnitudeType >::eps() )
343 std::cout <<
"Conv: stop_crit_3 " << stop_crit_3 <<
" eps " << Teuchos::ScalarTraits< MagnitudeType >::eps() << std::endl;
362template <
class ScalarType,
class MV,
class OP>
365 for (
int j = 0; j < indent; j++)
368 os <<
"limit of condition number = " << condMax_ << std::endl;
369 os <<
"limit of condition number = " << condMax_ << std::endl;
372template <
class ScalarType,
class MV,
class OP>
375 os << std::left << std::setw(13) << std::setfill(
'.');
388 os << std::left << std::setfill(
' ');
Belos concrete class that iterates LSQR.
Pure virtual base class for defining the status testing capabilities of Belos.
Implementation of the LSQR iteration.
LSQRIterationState< ScalarType, MV > getState() const
Get the current state of the linear solver.
int setRelMatErr(MagnitudeType rel_mat_err)
int setRelRhsErr(MagnitudeType rel_rhs_err)
void printStatus(std::ostream &os, Belos::StatusType type) const
Print message for each status specific to this stopping test.
Belos::MultiVecTraits< ScalarType, MV > MVT
virtual ~LSQRStatusTest()
Destructor.
void reset()
Resets the status test to the initial internal state.
Teuchos::ScalarTraits< ScalarType > SCT
int getTermIter() const
!Returns the current number of successful iterations from the most recent StatusTest call.
MagnitudeType getMatNorm() const
Returns the value of the observed (Frobenius) norm of A.
int setCondLim(MagnitudeType condMax)
Set the tolerances.
void print(std::ostream &os, int indent=0) const
Output formatted description of stopping test to output stream.
Belos::StatusType firstCallCheckStatusSetup(Belos::Iteration< ScalarType, MV, OP > *iSolver)
Called in checkStatus exactly once, on the first call to checkStatus.
int getTermIterMax() const
Returns the number of successful convergent iterations required set in the constructor.
MagnitudeType getMatErr() const
Returns the value of the estimate of the relative error in the data defining A set in the constructor...
SCT::magnitudeType MagnitudeType
MagnitudeType getResidNorm() const
Returns the value of the observed norm of the residual r = b-Ax.
MagnitudeType getCondMaxLim() const
Returns the value of the upper limit of the condition number of Abar set in the constructor.
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...
Belos::StatusType checkStatus(Belos::Iteration< ScalarType, MV, OP > *iSolver)
Check convergence status of the iterative solver: Unconverged, Converged, Failed.
MagnitudeType getLSResidNorm() const
Returns the value of the observed norm of the Least Squares residual A^T r.
int setTermIterMax(int term_iter_max)
std::string description() const
Method to return description of the maximum iteration status test.
LSQRStatusTest(MagnitudeType condMax=0.0, int term_iter_max=1, MagnitudeType rel_rhs_err=0.0, MagnitudeType rel_mat_err=0.0)
Constructor.
MagnitudeType getMatCondNum() const
Returns the value of the observed condition number of Abar.
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.