42#ifndef BELOS_STATUS_TEST_GEN_RESNORM_H
43#define BELOS_STATUS_TEST_GEN_RESNORM_H
78template <
class ScalarType,
class MV,
class OP>
84 typedef Teuchos::ScalarTraits<ScalarType>
SCT;
203 void print(std::ostream& os,
int indent = 0)
const;
263 std::ostringstream oss;
264 oss <<
"Belos::StatusTestGenResNorm<>: " <<
resFormStr();
279 std::ostringstream oss;
293 oss <<
" (User Scale)";
385template <
class ScalarType,
class MV,
class OP>
409template <
class ScalarType,
class MV,
class OP>
413template <
class ScalarType,
class MV,
class OP>
426template <
class ScalarType,
class MV,
class OP>
430 "StatusTestGenResNorm::defineResForm(): The residual form has already been defined.");
439template <
class ScalarType,
class MV,
class OP>
444 "StatusTestGenResNorm::defineScaleForm(): The scaling type has already been defined.");
454template <
class ScalarType,
class MV,
class OP>
457 MagnitudeType zero = Teuchos::ScalarTraits<MagnitudeType>::zero();
497 std::vector<MagnitudeType> tmp_resvector(
curBlksz_ );
499 if ( residMV != Teuchos::null ) {
502 typename std::vector<int>::iterator p =
curLSIdx_.begin();
503 for (
int i=0; p<
curLSIdx_.end(); ++p, ++i) {
509 typename std::vector<int>::iterator p =
curLSIdx_.begin();
510 for (
int i=0; p<
curLSIdx_.end(); ++p, ++i) {
527 typename std::vector<int>::iterator p =
curLSIdx_.begin();
528 for (
int i=0; p<
curLSIdx_.end(); ++p, ++i) {
539 typename std::vector<int>::iterator p =
curLSIdx_.begin();
550 typename std::vector<int>::iterator p =
curLSIdx_.begin();
561 typename std::vector<int>::iterator p =
curLSIdx_.begin();
574 TEUCHOS_TEST_FOR_EXCEPTION(
true,
StatusTestError,
"StatusTestGenResNorm::checkStatus(): NaN has been detected.");
586template <
class ScalarType,
class MV,
class OP>
589 for (
int j = 0; j < indent; j ++)
601 for (
int j = 0; j < indent + 13; j ++)
607 for (
int i=0; i<
numrhs_; i++ ) {
608 for (
int j = 0; j < indent + 13; j ++)
610 os <<
"residual [ " << i <<
" ] = " <<
testvector_[ i ];
618template <
class ScalarType,
class MV,
class OP>
621 os << std::left << std::setw(13) << std::setfill(
'.');
634 os << std::left << std::setfill(
' ');
638template <
class ScalarType,
class MV,
class OP>
642 MagnitudeType zero = Teuchos::ScalarTraits<MagnitudeType>::zero();
643 MagnitudeType one = Teuchos::ScalarTraits<MagnitudeType>::one();
653 Teuchos::RCP<const MV> rhs = lp.
getRHS();
Class which describes the linear problem to be solved by the iterative solver.
Declaration of basic traits for the multivector type.
Belos::StatusTest abstract class for specifying a residual norm stopping criteria.
virtual Teuchos::RCP< const MV > getNativeResiduals(std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > *norms) const =0
Get the residuals native to the solver.
virtual Teuchos::RCP< MV > getCurrentUpdate() const =0
Get the current update to the linear system.
virtual const LinearProblem< ScalarType, MV, OP > & getProblem() const =0
Get a constant reference to the linear problem.
int getLSNumber() const
The number of linear systems that have been set.
Teuchos::RCP< const MV > getInitPrecResVec() const
A pointer to the preconditioned initial residual vector.
const std::vector< int > & getLSIndex() const
(Zero-based) indices of the linear system(s) currently being solved.
Teuchos::RCP< const MV > getRHS() const
A pointer to the right-hand side B.
Teuchos::RCP< const MV > getInitResVec() const
A pointer to the initial unpreconditioned residual vector.
virtual void computeCurrResVec(MV *R, const MV *X=0, const MV *B=0) const
Compute a residual R for this operator given a solution X, and right-hand side B.
virtual Teuchos::RCP< MV > updateSolution(const Teuchos::RCP< MV > &update=Teuchos::null, bool updateLP=false, ScalarType scale=Teuchos::ScalarTraits< ScalarType >::one())
Compute the new solution to the linear system using the given update vector.
Traits class which defines basic operations on multivectors.
static void MvNorm(const MV &mv, std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &normvec, NormType type=TwoNorm)
Compute the norm of each individual vector of mv. Upon return, normvec[i] holds the value of ,...
static Teuchos::RCP< MV > Clone(const MV &mv, const int numvecs)
Creates a new empty MV containing numvecs columns.
static int GetNumberVecs(const MV &mv)
Obtain the number of vectors in mv.
Exception thrown to signal error in a status test during Belos::StatusTest::checkStatus().
NormType scalenormtype_
Type of norm to use on the scaling (OneNorm, TwoNorm, or InfNorm)
Teuchos::RCP< MV > curSoln_
Most recent solution vector used by this status test.
NormType getResNormType()
std::string description() const
Method to return description of the maximum iteration status test.
MagnitudeType scalevalue_
Scaling value.
std::vector< int > convIndices()
Returns the std::vector containing the indices of the residuals that passed the test.
int setQuorum(int quorum)
Sets the number of residuals that must pass the convergence test before Passed is returned.
int setShowMaxResNormOnly(bool showMaxResNormOnly)
Set whether the only maximum residual norm is displayed when the print() method is called.
const std::vector< MagnitudeType > * getTestValue() const
Returns the test value, , computed in most recent call to CheckStatus.
int defineScaleForm(ScaleType TypeOfScaling, NormType TypeOfNorm, MagnitudeType ScaleValue=Teuchos::ScalarTraits< MagnitudeType >::one())
Define form of the scaling, its norm, its optional weighting std::vector, or, alternatively,...
StatusType firstCallCheckStatusSetup(Iteration< ScalarType, MV, OP > *iSolver)
Call to setup initial scaling std::vector.
std::vector< MagnitudeType > resvector_
Residual norm std::vector.
std::string resFormStr() const
Description of current residual form.
StatusType status_
Status.
MagnitudeType tolerance_
Tolerance used to determine convergence.
std::vector< MagnitudeType > testvector_
Test std::vector = resvector_ / scalevector_.
void reset()
Resets the internal configuration to the initial state.
virtual ~StatusTestGenResNorm()
Destructor.
int curNumRHS_
The current number of right-hand sides being solved for.
int getQuorum() const
Returns the number of residuals that must pass the convergence test before Passed is returned.
Teuchos::ScalarTraits< ScalarType > SCT
int setTolerance(MagnitudeType tolerance)
Set the value of the tolerance.
bool getShowMaxResNormOnly()
Returns whether the only maximum residual norm is displayed when the print() method is called.
std::vector< int > ind_
Vector containing the indices for the vectors that passed the test.
MagnitudeType getTolerance() const
Returns the value of the tolerance, , set in the constructor.
int defineResForm(ResType TypeOfResidual, NormType TypeOfNorm)
Define form of the residual, its norm and optional weighting std::vector.
StatusType checkStatus(Iteration< ScalarType, MV, OP > *iSolver)
Check convergence status: Passed, Failed, or Undefined.
std::vector< int > curLSIdx_
The indices of the current number of right-hand sides being solved for.
StatusTestGenResNorm(MagnitudeType Tolerance, int quorum=-1, bool showMaxResNormOnly=false)
Constructor.
Teuchos::RCP< MV > getSolution()
Returns the current solution estimate that was computed for the most recent residual test.
bool showMaxResNormOnly_
Determines if the entries for all of the residuals are shown or just the max.
ResType restype_
Type of residual to use (explicit or implicit)
ScaleType scaletype_
Type of scaling to use (Norm of RHS, Norm of Initial Residual, None or User provided)
int numrhs_
The total number of right-hand sides being solved for.
NormType resnormtype_
Type of norm to use on residual (OneNorm, TwoNorm, or InfNorm).
int quorum_
Number of residuals that must pass the convergence test before Passed is returned.
bool firstcallDefineScaleForm_
Is this the first time DefineScaleForm is called?
StatusType getStatus() const
Return the result of the most recent CheckStatus call.
MultiVecTraits< ScalarType, MV > MVT
const std::vector< MagnitudeType > * getResNormValue() const
Returns the residual norm value, , computed in most recent call to CheckStatus.
bool firstcallDefineResForm_
Is this the first time DefineResForm is called?
ResType
Select how the residual std::vector is produced.
int curBlksz_
The current blocksize of the linear system being solved.
const std::vector< MagnitudeType > * getScaledNormValue() const
Returns the scaled norm value, .
bool firstcallCheckStatus_
Is this the first time CheckStatus is called?
void printStatus(std::ostream &os, StatusType type) const
Print message for each status specific to this stopping test.
int curLSNum_
The current number of linear systems that have been loaded into the linear problem.
bool getLOADetected() const
Returns a boolean indicating a loss of accuracy has been detected in computing the residual.
std::vector< MagnitudeType > scalevector_
Scaling std::vector.
void print(std::ostream &os, int indent=0) const
Output formatted description of stopping test to output stream.
SCT::magnitudeType MagnitudeType
An abstract class of StatusTest for stopping criteria using residual norms.
NormType
The type of vector norm to compute.
StatusType
Whether the StatusTest wants iteration to stop.
ScaleType
The type of scaling to use on the residual norm value.
@ NormOfFullScaledPrecInitRes
@ NormOfFullScaledInitRes