44#ifndef BELOS_LSQR_STATUS_TEST_HPP
45#define BELOS_LSQR_STATUS_TEST_HPP
64template <
class ScalarType,
class MV,
class OP>
70 typedef Teuchos::ScalarTraits<ScalarType>
SCT;
84 int term_iter_max = 1,
114 rcondMin_ = (condMax > 0) ? (Teuchos::ScalarTraits< MagnitudeType >::one() / condMax) : Teuchos::ScalarTraits< MagnitudeType >::eps();
118 term_iter_max_ = term_iter_max;
119 if (term_iter_max_ < 1)
124 rel_rhs_err_ = rel_rhs_err;
128 rel_mat_err_ = rel_mat_err;
169 void print(std::ostream& os,
int indent = 0)
const;
190 std::ostringstream oss;
191 oss <<
"LSQRStatusTest<>: [ limit of condition number = " << condMax_ <<
" ]";
239template <
class ScalarType,
class MV,
class OP>
246 term_iter_max_ (term_iter_max),
247 rel_rhs_err_ (rel_rhs_err),
248 rel_mat_err_ (rel_mat_err),
258template <
class ScalarType,
class MV,
class OP>
262template <
class ScalarType,
class MV,
class OP>
268template <
class ScalarType,
class MV,
class OP>
271 const MagnitudeType MTzero = Teuchos::ScalarTraits<MagnitudeType>::zero();
272 const MagnitudeType MTone = Teuchos::ScalarTraits<MagnitudeType>::one();
273 if (condMax_ > MTzero )
275 rcondMin_ = MTone / condMax_;
279 rcondMin_ = Teuchos::ScalarTraits< MagnitudeType >::eps();
282 bool termIterFlag =
false;
284 TEUCHOS_ASSERT(solver != NULL);
305 std::cout <<
" X " << state.
sol_norm
314 const MagnitudeType zero = Teuchos::ScalarTraits<MagnitudeType>::zero();
315 const ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
316 ScalarType stop_crit_1 = zero;
317 if( state.
bnorm > zero )
321 ScalarType stop_crit_2 = zero;
339 ScalarType resid_tol_mach = Teuchos::ScalarTraits< MagnitudeType >::eps() + Teuchos::ScalarTraits< MagnitudeType >::eps() * state.
frob_mat_norm * state.
sol_norm / state.
bnorm;
356 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()) {
359 if (stop_crit_1 <= resid_tol )
360 std::cout <<
"Conv: stop_crit_1 " << stop_crit_1 <<
" resid_tol " << resid_tol << std::endl;
362 if (stop_crit_1 <= resid_tol_mach )
363 std::cout <<
"Conv: stop_crit_1 " << stop_crit_1 <<
" resid_tol_mach " << resid_tol_mach << std::endl;
365 if (stop_crit_2 <= rel_mat_err_ )
366 std::cout <<
"Conv: stop_crit_2 " << stop_crit_2 <<
" rel_mat_err " << rel_mat_err_ << std::endl;
368 if (stop_crit_2 <= Teuchos::ScalarTraits< MagnitudeType >::eps() )
369 std::cout <<
"Conv: stop_crit_2 " << stop_crit_2 <<
" eps " << Teuchos::ScalarTraits< MagnitudeType >::eps() << std::endl;
371 if (stop_crit_3 <= rcondMin_ )
372 std::cout <<
"Conv: stop_crit_3 " << stop_crit_3 <<
" rcondMin_ " << rcondMin_ << std::endl;
374 if (stop_crit_3 <= Teuchos::ScalarTraits< MagnitudeType >::eps() )
375 std::cout <<
"Conv: stop_crit_3 " << stop_crit_3 <<
" eps " << Teuchos::ScalarTraits< MagnitudeType >::eps() << std::endl;
394template <
class ScalarType,
class MV,
class OP>
397 for (
int j = 0; j < indent; j++)
399 printStatus(os, status_);
400 os <<
"limit of condition number = " << condMax_ << std::endl;
401 os <<
"limit of condition number = " << condMax_ << std::endl;
404template <
class ScalarType,
class MV,
class OP>
407 os << std::left << std::setw(13) << std::setfill(
'.');
420 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 print(std::ostream &os, int indent=0) const
Output formatted description of stopping test to output stream.
Belos::MultiVecTraits< ScalarType, MV > MVT
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.
LSQRStatusTest(MagnitudeType condMax=0.0, int term_iter_max=1, MagnitudeType rel_rhs_err=0.0, MagnitudeType rel_mat_err=0.0)
Constructor.
int setCondLim(MagnitudeType condMax)
Set the tolerances.
void printStatus(std::ostream &os, Belos::StatusType type) const
Print message for each status specific to this stopping test.
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.
void reset()
Resets the status test to the initial internal state.
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...
MagnitudeType getLSResidNorm() const
Returns the value of the observed norm of the Least Squares residual A^T r.
int setTermIterMax(int term_iter_max)
Belos::StatusType checkStatus(Belos::Iteration< ScalarType, MV, OP > *iSolver)
Check convergence status of the iterative solver: Unconverged, Converged, Failed.
std::string description() const
Method to return description of the maximum iteration status test
virtual ~LSQRStatusTest()
Destructor.
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.