42#ifndef BELOS_STATUS_TEST_IMPRESNORM_H
43#define BELOS_STATUS_TEST_IMPRESNORM_H
53#include "Teuchos_as.hpp"
103template <
class ScalarType,
class MV,
class OP>
107 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
MagnitudeType;
112 typedef Teuchos::ScalarTraits<ScalarType>
STS;
113 typedef Teuchos::ScalarTraits<MagnitudeType>
STM;
134 bool showMaxResNormOnly =
false);
226 void print(std::ostream& os,
int indent = 0)
const;
301 std::ostringstream oss;
302 oss <<
"Belos::StatusTestImpResNorm<>: " <<
resFormStr();
317 std::ostringstream oss;
330 oss <<
" (User Scale)";
419template <
class ScalarType,
class MV,
class OP>
444template <
class ScalarType,
class MV,
class OP>
448template <
class ScalarType,
class MV,
class OP>
463template <
class ScalarType,
class MV,
class OP>
467 "StatusTestResNorm::defineResForm(): The residual form has already been defined.");
475template <
class ScalarType,
class MV,
class OP>
480 "StatusTestResNorm::defineScaleForm(): The scaling type has already been defined.");
490template <
class ScalarType,
class MV,
class OP>
554 std::vector<MagnitudeType> tmp_resvector(
curBlksz_ );
556 if (! residMV.is_null ()) {
560 typename std::vector<int>::iterator p =
curLSIdx_.begin();
561 for (
int i=0; p<
curLSIdx_.end(); ++p, ++i) {
568 typename std::vector<int>::iterator p =
curLSIdx_.begin();
569 for (
int i=0; p<
curLSIdx_.end(); ++p, ++i) {
581 typename std::vector<int>::iterator p =
curLSIdx_.begin();
596 typename std::vector<int>::iterator p =
curLSIdx_.begin();
614 std::vector<int> lclInd(
curLSIdx_.size() );
615 typename std::vector<int>::iterator p =
curLSIdx_.begin();
616 for (
int i=0; p<
curLSIdx_.end(); ++p, ++i) {
634 "StatusTestImpResNorm::checkStatus(): One or more of the current "
635 "implicit residual norms is NaN.");
653 std::vector<MagnitudeType> tmp_testvector (have);
658 for (
int i=0; i<have; ++i) {
664 tmp_testvector[ i ] = tmp_resvector[ lclInd[i] ] /
scalevalue_;
669 for (
int i=0; i<have; ++i) {
670 tmp_testvector[ i ] = tmp_resvector[ lclInd[i] ] /
scalevalue_;
681 for (
int i = 0; i < have; ++i) {
728 const MagnitudeType onePointFive = as<MagnitudeType>(3) / as<MagnitudeType> (2);
729 const MagnitudeType oneTenth = STM::one () / as<MagnitudeType> (10);
751template <
class ScalarType,
class MV,
class OP>
754 for (
int j = 0; j < indent; j ++)
766 for (
int j = 0; j < indent + 13; j ++)
772 for (
int i=0; i<
numrhs_; i++ ) {
773 for (
int j = 0; j < indent + 13; j ++)
775 os <<
"residual [ " << i <<
" ] = " <<
testvector_[ i ];
783template <
class ScalarType,
class MV,
class OP>
786 os << std::left << std::setw(13) << std::setfill(
'.');
793 os <<
"Unconverged (LoA)";
802 os << std::left << std::setfill(
' ');
806template <
class ScalarType,
class MV,
class OP>
822 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
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().
StatusTestImpResNorm(MagnitudeType Tolerance, int quorum=-1, bool showMaxResNormOnly=false)
Constructor.
Teuchos::ScalarTraits< ScalarType > STS
std::vector< MagnitudeType > scalevector_
Scaling vector.
std::vector< MagnitudeType > resvector_
Residual norm vector.
StatusType status_
Status.
const std::vector< MagnitudeType > * getScaledNormValue() const
Returns the scaled norm value, .
bool firstcallCheckStatus_
Is this the first time CheckStatus is called?
bool lossDetected_
Has a loss in accuracy been detected?
virtual ~StatusTestImpResNorm()
Destructor (virtual for memory safety).
Teuchos::ScalarTraits< ScalarType >::magnitudeType MagnitudeType
The type of the magnitude (absolute value) of a ScalarType.
ScaleType scaletype_
Type of scaling to use (Norm of RHS, Norm of Initial Residual, None or User provided).
MagnitudeType getTolerance() const
"Original" convergence tolerance as set by user.
int numrhs_
The total number of right-hand sides being solved for.
MagnitudeType currTolerance_
MagnitudeType getCurrTolerance() const
Current convergence tolerance; may be changed to prevent loss of accuracy.
bool showMaxResNormOnly_
Determines if the entries for all of the residuals are shown or just the max.
Teuchos::ScalarTraits< MagnitudeType > STM
std::string description() const
Method to return description of the maximum iteration status test.
std::vector< int > convIndices()
Returns the vector containing the indices of the residuals that passed the test.
void printStatus(std::ostream &os, StatusType type) const
Print message for each status specific to this stopping test.
bool firstcallDefineScaleForm_
Is this the first time DefineScaleForm is called?
int defineScaleForm(ScaleType TypeOfScaling, NormType TypeOfNorm, MagnitudeType ScaleValue=Teuchos::ScalarTraits< MagnitudeType >::one())
Define form of the scaling, its norm, its optional weighting vector, or, alternatively,...
std::vector< MagnitudeType > testvector_
Test vector = resvector_ / scalevector_.
std::string resFormStr() const
Description of current residual form.
const std::vector< MagnitudeType > * getResNormValue() const
Returns the residual norm value, , computed in most recent call to CheckStatus.
Teuchos::RCP< MV > getSolution()
Returns the current solution estimate that was computed for the most recent residual test.
void print(std::ostream &os, int indent=0) const
Output formatted description of stopping test to output stream.
void reset()
Resets the internal configuration to the initial state.
MagnitudeType scalevalue_
Scaling value.
bool getShowMaxResNormOnly()
Returns whether the only maximum residual norm is displayed when the print() method is called.
NormType scalenormtype_
Type of norm to use on the scaling (OneNorm, TwoNorm, or InfNorm).
bool getLOADetected() const
Returns a boolean indicating a loss of accuracy has been detected in computing the residual.
MagnitudeType tolerance_
Current tolerance used to determine convergence and the default tolerance set by user.
StatusType getStatus() const
Return the result of the most recent CheckStatus call.
std::vector< int > ind_
Vector containing the indices for the vectors that passed the test.
MultiVecTraits< ScalarType, MV > MVT
StatusType checkStatus(Iteration< ScalarType, MV, OP > *iSolver)
Check convergence status: Passed, Failed, or Undefined.
int setTolerance(MagnitudeType tolerance)
Set the value of the tolerance.
int quorum_
Number of residuals that must pass the convergence test before Passed is returned.
std::vector< int > curLSIdx_
The indices of the current number of right-hand sides being solved for.
bool firstcallDefineResForm_
Is this the first time DefineResForm is called?
int curNumRHS_
The current number of right-hand sides being solved for.
int curBlksz_
The current blocksize of the linear system being solved.
const std::vector< MagnitudeType > * getTestValue() const
Returns the test value, , computed in most recent call to CheckStatus.
NormType resnormtype_
Type of norm to use on residual (OneNorm, TwoNorm, or InfNorm).
Teuchos::RCP< MV > curSoln_
Current solution vector.
int defineResForm(NormType TypeOfNorm)
Define form of the residual, its norm and optional weighting vector.
int setShowMaxResNormOnly(bool showMaxResNormOnly)
Set whether the only maximum residual norm is displayed when the print() method is called.
StatusType firstCallCheckStatusSetup(Iteration< ScalarType, MV, OP > *iSolver)
Call to setup initial scaling vector.
int curLSNum_
The current number of linear systems that have been loaded into the linear problem.
int setQuorum(int quorum)
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.