waves
Basic FE playground
Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP > Class Template Reference

An implementation of StatusTestResNorm using a family of weighted residual norms. More...

#include <BelosStatusTestWeightedGenResNorm_MP_Vector.hpp>

Inheritance diagram for Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >:
Collaboration diagram for Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >:

Public Types

typedef Teuchos::ScalarTraits< ScalarType > SCT
 
typedef SCT::magnitudeType MagnitudeType
 
typedef MultiVecTraits< ScalarType, MV > MVT
 
Enums.
enum  ResType { Implicit, Explicit }
 Select how the residual std::vector is produced. More...
 

Public Member Functions

Constructors/destructors.
 StatusTestWeightedGenResNorm (MagnitudeType Tolerance, Teuchos::RCP< MV > weights, int quorum=-1, bool showMaxResNormOnly=false)
 Constructor. More...
 
virtual ~StatusTestWeightedGenResNorm ()
 Destructor. More...
 
Form and parameter definition methods.
int defineResForm (ResType TypeOfResidual, NormType TypeOfNorm)
 Define form of the residual, its norm and optional weighting std::vector. More...
 
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, define an explicit value. More...
 
NormType getResNormType ()
 
int setTolerance (MagnitudeType tolerance)
 Set the value of the tolerance. More...
 
int setQuorum (int quorum)
 
int setShowMaxResNormOnly (bool showMaxResNormOnly)
 Set whether the only maximum residual norm is displayed when the print() method is called. More...
 
Status methods
StatusType checkStatus (Iteration< ScalarType, MV, OP > *iSolver)
 Check convergence status: Passed, Failed, or Undefined. More...
 
StatusType getStatus () const
 Return the result of the most recent CheckStatus call. More...
 
Reset methods
void reset ()
 Resets the internal configuration to the initial state. More...
 
Print methods
void print (std::ostream &os, int indent=0) const
 Output formatted description of stopping test to output stream. More...
 
void printStatus (std::ostream &os, StatusType type) const
 Print message for each status specific to this stopping test. More...
 
Methods to access data members.
Teuchos::RCP< MV > getSolution ()
 
int getQuorum () const
 
bool getShowMaxResNormOnly ()
 Returns whether the only maximum residual norm is displayed when the print() method is called. More...
 
std::vector< int > convIndices ()
 Returns the std::vector containing the indices of the residuals that passed the test. More...
 
MagnitudeType getTolerance () const
 Returns the value of the tolerance, \( \tau \), set in the constructor. More...
 
const std::vector< MagnitudeType > * getTestValue () const
 Returns the test value, \( \frac{\|r\|}{\sigma} \), computed in most recent call to CheckStatus. More...
 
const std::vector< MagnitudeType > * getResNormValue () const
 Returns the residual norm value, \( \|r\| \), computed in most recent call to CheckStatus. More...
 
const std::vector< MagnitudeType > * getScaledNormValue () const
 Returns the scaled norm value, \( \sigma \). More...
 
bool getLOADetected () const
 
const std::vector< int > getEnsembleIterations () const
 Returns number of ensemble iterations. More...
 
Misc.
StatusType firstCallCheckStatusSetup (Iteration< ScalarType, MV, OP > *iSolver)
 Call to setup initial scaling std::vector. More...
 
Overridden from Teuchos::Describable
std::string description () const
 Method to return description of the maximum iteration status test
More...
 

Private Member Functions

Private methods.
std::string resFormStr () const
 Description of current residual form. More...
 
Private helper functions
void MvWNorm (const MV &mv, const MV &w, std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &normVec, NormType type=TwoNorm)
 

Private Attributes

Private data members.
MagnitudeType tolerance_
 Tolerance used to determine convergence. More...
 
int quorum_
 Number of residuals that must pass the convergence test before Passed is returned. More...
 
bool showMaxResNormOnly_
 Determines if the entries for all of the residuals are shown or just the max. More...
 
NormType resnormtype_
 Type of norm to use on residual (OneNorm, TwoNorm, or InfNorm). More...
 
ScaleType scaletype_
 Type of scaling to use (Norm of RHS, Norm of Initial Residual, None or User provided) More...
 
NormType scalenormtype_
 Type of norm to use on the scaling (OneNorm, TwoNorm, or InfNorm) More...
 
MagnitudeType scalevalue_
 Scaling value. More...
 
std::vector< MagnitudeTypescalevector_
 Scaling std::vector. More...
 
std::vector< MagnitudeTyperesvector_
 Residual norm std::vector. More...
 
std::vector< MagnitudeTypetestvector_
 Test std::vector = resvector_ / scalevector_. More...
 
std::vector< int > ind_
 Vector containing the indices for the vectors that passed the test. More...
 
Teuchos::RCP< MV > curSoln_
 Most recent solution vector used by this status test. More...
 
StatusType status_
 Status. More...
 
int curBlksz_
 The current blocksize of the linear system being solved. More...
 
int curNumRHS_
 The current number of right-hand sides being solved for. More...
 
std::vector< int > curLSIdx_
 The indices of the current number of right-hand sides being solved for. More...
 
int curLSNum_
 The current number of linear systems that have been loaded into the linear problem. More...
 
int numrhs_
 The total number of right-hand sides being solved for. More...
 
bool firstcallCheckStatus_
 Is this the first time CheckStatus is called? More...
 
bool firstcallDefineResForm_
 Is this the first time DefineResForm is called? More...
 
bool firstcallDefineScaleForm_
 Is this the first time DefineScaleForm is called? More...
 
Teuchos::RCP< MV > weights_
 Weights of the used norm: More...
 
std::vector< int > ensemble_iterations
 The number of iterations at which point each ensemble component converges. More...
 

Detailed Description

template<class ScalarType, class MV, class OP>
class Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >

An implementation of StatusTestResNorm using a family of weighted residual norms.

StatusTestWeightedGenResNorm is an implementation of StatusTestResNorm that allows a user to construct one of a family of residual tests for use as a status/convergence test for Belos. The form of the test is

\[ \frac{\|w\odot r_i\|}{\sigma_i} \le \tau \]

where

  • \(w\) is a vector of weights,
  • \(\odot\) is the Hadamard product,
  • \(r_i\) is the i-th residual std::vector, implicitly or explicitly computed (determined by enum ResType),
  • \(\|r_i\|\) is the i-th residual norm determined by the enum NormType (1-norm, 2-norm or inf-norm),
  • \(\sigma_i\) is the i-th scale factor that can be passed in as a precomputed number of the templated type, or can be selected from by the enum ScaleType (norm of RHS, norm of initial residual).
  • \(\tau\) is the tolerance that is passed in as a number of the templated type to the constructor. The value of \(\tau\) can be reset using the setTolerance() method.

Member Typedef Documentation

◆ MagnitudeType

template<class ScalarType , class MV , class OP >
typedef SCT::magnitudeType Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::MagnitudeType

◆ MVT

template<class ScalarType , class MV , class OP >
typedef MultiVecTraits<ScalarType, MV> Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::MVT

◆ SCT

template<class ScalarType , class MV , class OP >
typedef Teuchos::ScalarTraits<ScalarType> Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::SCT

Member Enumeration Documentation

◆ ResType

template<class ScalarType , class MV , class OP >
enum Belos::StatusTestWeightedGenResNorm::ResType

Select how the residual std::vector is produced.

Enumerator
Implicit 

Use the residual std::vector produced by the iterative solver.

Explicit 

Explicitly compute the residual std::vector r = b - A*x using the linear problem.

Constructor & Destructor Documentation

◆ StatusTestWeightedGenResNorm()

template<class ScalarType , class MV , class OP >
Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::StatusTestWeightedGenResNorm ( MagnitudeType  Tolerance,
Teuchos::RCP< MV >  weights,
int  quorum = -1,
bool  showMaxResNormOnly = false 
)

Constructor.

The constructor takes a single argument specifying the tolerance ( \(\tau\)). If none of the form definition methods are called, we use \(\|r\|_2/\|r^{(0)}\|_2 \le \tau\) as the stopping criterion, where \(\|r\|_2\) uses the least costly form of the 2-norm of residual available from the iterative method and \(\|r^{(0)}\|_2\) is the corresponding norm of the initial residual. The least costly form of the 2-norm depends on the chosen iterative method. Most Krylov methods produce the preconditioned residual std::vector in a form that would be exact in infinite precision arithmetic. This std::vector may be different from the true residual either because left preconditioning was used, or because round-off error has introduced significant error, or both.

You can also state the number of vectors that must pass the convergence criteria before the status test passes by using the quorum argument.

◆ ~StatusTestWeightedGenResNorm()

template<class ScalarType , class MV , class OP >
Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::~StatusTestWeightedGenResNorm
virtual

Destructor.

Member Function Documentation

◆ checkStatus()

template<class ScalarType , class MV , class OP >
StatusType Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::checkStatus ( Iteration< ScalarType, MV, OP > *  iSolver)

Check convergence status: Passed, Failed, or Undefined.

This method checks to see if the convergence criteria are met. Depending on how the residual test is constructed this method will return the appropriate status type.

Returns
StatusType: Passed, Failed, or Undefined.

◆ convIndices()

template<class ScalarType , class MV , class OP >
std::vector<int> Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::convIndices ( )
inline

Returns the std::vector containing the indices of the residuals that passed the test.

◆ defineResForm()

template<class ScalarType , class MV , class OP >
int Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::defineResForm ( ResType  TypeOfResidual,
NormType  TypeOfNorm 
)

Define form of the residual, its norm and optional weighting std::vector.

This method defines the form of \(\|r\|\). We specify:

  • Whether the residual std::vector should be explicitly computed, or taken from the iterative method.
  • The norm to be used on the residual (this may be different than the norm used in DefineScaleForm()).

◆ defineScaleForm()

template<class ScalarType , class MV , class OP >
int Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::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, define an explicit value.

This method defines the form of how the residual is scaled (if at all). It operates in two modes:

  1. User-provided scaling value:

    • Set argument TypeOfScaling to UserProvided.
    • Set ScaleValue to a non-zero value that the residual norm will be divided by.
    • TypeOfNorm argument will be ignored.
    • Sample use: Define ScaleValue = \(\|A\|_{\infty}\) where \( A \) is the matrix of the linear problem.

  2. Use a supported Scaling Form:
    • Define TypeOfScaling to be the norm of the right hand side, the initial residual std::vector, or to none.
    • Define norm to be used on the scaling std::vector (this may be different than the norm used in DefineResForm()).

◆ description()

template<class ScalarType , class MV , class OP >
std::string Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::description ( ) const
inline

Method to return description of the maximum iteration status test

◆ firstCallCheckStatusSetup()

template<class ScalarType , class MV , class OP >
StatusType Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::firstCallCheckStatusSetup ( Iteration< ScalarType, MV, OP > *  iSolver)

Call to setup initial scaling std::vector.

After this function is called getScaledNormValue() can be called to get the scaling std::vector.

◆ getEnsembleIterations()

template<class ScalarType , class MV , class OP >
const std::vector<int> Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::getEnsembleIterations ( ) const
inline

Returns number of ensemble iterations.

◆ getLOADetected()

template<class ScalarType , class MV , class OP >
bool Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::getLOADetected ( ) const
inline

Returns a boolean indicating a loss of accuracy has been detected in computing the residual.

Note
This status test does not check for loss of accuracy, so this method will always return false.

◆ getQuorum()

template<class ScalarType , class MV , class OP >
int Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::getQuorum ( ) const
inline

Returns the number of residuals that must pass the convergence test before Passed is returned.

Note
If quorum=-1 then all residuals must pass the convergence test before Passed is returned.

◆ getResNormType()

template<class ScalarType , class MV , class OP >
NormType Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::getResNormType ( )
inline

◆ getResNormValue()

template<class ScalarType , class MV , class OP >
const std::vector<MagnitudeType>* Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::getResNormValue ( ) const
inline

Returns the residual norm value, \( \|r\| \), computed in most recent call to CheckStatus.

◆ getScaledNormValue()

template<class ScalarType , class MV , class OP >
const std::vector<MagnitudeType>* Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::getScaledNormValue ( ) const
inline

Returns the scaled norm value, \( \sigma \).

◆ getShowMaxResNormOnly()

template<class ScalarType , class MV , class OP >
bool Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::getShowMaxResNormOnly ( )
inline

Returns whether the only maximum residual norm is displayed when the print() method is called.

◆ getSolution()

template<class ScalarType , class MV , class OP >
Teuchos::RCP<MV> Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::getSolution ( )
inline

Returns the current solution estimate that was computed for the most recent residual test.

Note
This is useful for explicit residual tests, if this test is an implicit residual test a null pointer will be returned.

◆ getStatus()

template<class ScalarType , class MV , class OP >
StatusType Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::getStatus ( ) const
inline

Return the result of the most recent CheckStatus call.

◆ getTestValue()

template<class ScalarType , class MV , class OP >
const std::vector<MagnitudeType>* Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::getTestValue ( ) const
inline

Returns the test value, \( \frac{\|r\|}{\sigma} \), computed in most recent call to CheckStatus.

◆ getTolerance()

template<class ScalarType , class MV , class OP >
MagnitudeType Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::getTolerance ( ) const
inline

Returns the value of the tolerance, \( \tau \), set in the constructor.

◆ MvWNorm()

template<class ScalarType , class MV , class OP >
void Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::MvWNorm ( const MV &  mv,
const MV &  w,
std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &  normVec,
NormType  type = TwoNorm 
)
inlineprivate

◆ print()

template<class ScalarType , class MV , class OP >
void Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::print ( std::ostream &  os,
int  indent = 0 
) const

Output formatted description of stopping test to output stream.

◆ printStatus()

template<class ScalarType , class MV , class OP >
void Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::printStatus ( std::ostream &  os,
StatusType  type 
) const

Print message for each status specific to this stopping test.

◆ reset()

template<class ScalarType , class MV , class OP >
void Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::reset

Resets the internal configuration to the initial state.

◆ resFormStr()

template<class ScalarType , class MV , class OP >
std::string Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::resFormStr ( ) const
inlineprivate

Description of current residual form.

◆ setQuorum()

template<class ScalarType , class MV , class OP >
int Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::setQuorum ( int  quorum)
inline

Sets the number of residuals that must pass the convergence test before Passed is returned.

Note
If quorum=-1 then all residuals must pass the convergence test before Passed is returned.

◆ setShowMaxResNormOnly()

template<class ScalarType , class MV , class OP >
int Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::setShowMaxResNormOnly ( bool  showMaxResNormOnly)
inline

Set whether the only maximum residual norm is displayed when the print() method is called.

◆ setTolerance()

template<class ScalarType , class MV , class OP >
int Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::setTolerance ( MagnitudeType  tolerance)
inline

Set the value of the tolerance.

We allow the tolerance to be reset for cases where, in the process of testing the residual, we find that the initial tolerance was too tight or too lax.

Member Data Documentation

◆ curBlksz_

template<class ScalarType , class MV , class OP >
int Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::curBlksz_
private

The current blocksize of the linear system being solved.

◆ curLSIdx_

template<class ScalarType , class MV , class OP >
std::vector<int> Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::curLSIdx_
private

The indices of the current number of right-hand sides being solved for.

◆ curLSNum_

template<class ScalarType , class MV , class OP >
int Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::curLSNum_
private

The current number of linear systems that have been loaded into the linear problem.

◆ curNumRHS_

template<class ScalarType , class MV , class OP >
int Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::curNumRHS_
private

The current number of right-hand sides being solved for.

◆ curSoln_

template<class ScalarType , class MV , class OP >
Teuchos::RCP<MV> Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::curSoln_
private

Most recent solution vector used by this status test.

◆ ensemble_iterations

template<class ScalarType , class MV , class OP >
std::vector<int> Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::ensemble_iterations
private

The number of iterations at which point each ensemble component converges.

◆ firstcallCheckStatus_

template<class ScalarType , class MV , class OP >
bool Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::firstcallCheckStatus_
private

Is this the first time CheckStatus is called?

◆ firstcallDefineResForm_

template<class ScalarType , class MV , class OP >
bool Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::firstcallDefineResForm_
private

Is this the first time DefineResForm is called?

◆ firstcallDefineScaleForm_

template<class ScalarType , class MV , class OP >
bool Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::firstcallDefineScaleForm_
private

Is this the first time DefineScaleForm is called?

◆ ind_

template<class ScalarType , class MV , class OP >
std::vector<int> Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::ind_
private

Vector containing the indices for the vectors that passed the test.

◆ numrhs_

template<class ScalarType , class MV , class OP >
int Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::numrhs_
private

The total number of right-hand sides being solved for.

◆ quorum_

template<class ScalarType , class MV , class OP >
int Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::quorum_
private

Number of residuals that must pass the convergence test before Passed is returned.

◆ resnormtype_

template<class ScalarType , class MV , class OP >
NormType Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::resnormtype_
private

Type of norm to use on residual (OneNorm, TwoNorm, or InfNorm).

◆ resvector_

template<class ScalarType , class MV , class OP >
std::vector<MagnitudeType> Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::resvector_
private

Residual norm std::vector.

◆ scalenormtype_

template<class ScalarType , class MV , class OP >
NormType Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::scalenormtype_
private

Type of norm to use on the scaling (OneNorm, TwoNorm, or InfNorm)

◆ scaletype_

template<class ScalarType , class MV , class OP >
ScaleType Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::scaletype_
private

Type of scaling to use (Norm of RHS, Norm of Initial Residual, None or User provided)

◆ scalevalue_

template<class ScalarType , class MV , class OP >
MagnitudeType Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::scalevalue_
private

Scaling value.

◆ scalevector_

template<class ScalarType , class MV , class OP >
std::vector<MagnitudeType> Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::scalevector_
private

Scaling std::vector.

◆ showMaxResNormOnly_

template<class ScalarType , class MV , class OP >
bool Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::showMaxResNormOnly_
private

Determines if the entries for all of the residuals are shown or just the max.

◆ status_

template<class ScalarType , class MV , class OP >
StatusType Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::status_
private

Status.

◆ testvector_

template<class ScalarType , class MV , class OP >
std::vector<MagnitudeType> Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::testvector_
private

Test std::vector = resvector_ / scalevector_.

◆ tolerance_

template<class ScalarType , class MV , class OP >
MagnitudeType Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::tolerance_
private

Tolerance used to determine convergence.

◆ weights_

template<class ScalarType , class MV , class OP >
Teuchos::RCP<MV> Belos::StatusTestWeightedGenResNorm< ScalarType, MV, OP >::weights_
private

Weights of the used norm:


The documentation for this class was generated from the following file: