10#ifndef BELOS_STATUS_TEST_GEN_RESNORM_H
11#define BELOS_STATUS_TEST_GEN_RESNORM_H
46template <
class ScalarType,
class MV,
class OP>
52 typedef Teuchos::ScalarTraits<ScalarType>
SCT;
183 Teuchos::RCP<MV>
getSolution() {
if (restype_==
Implicit) {
return Teuchos::null; }
else {
return curSoln_; } }
199 const std::vector<MagnitudeType>*
getTestValue()
const {
return(&testvector_);};
231 std::ostringstream
oss;
232 oss <<
"Belos::StatusTestGenResNorm<>: " << resFormStr();
233 oss <<
", tol = " << tolerance_;
245 std::string resFormStr()
const
247 std::ostringstream
oss;
249 oss << ((resnormtype_==
OneNorm) ?
"1-Norm" : (resnormtype_==
TwoNorm) ?
"2-Norm" :
"Inf-Norm");
254 if (scaletype_!=
None)
261 oss <<
" (User Scale)";
264 oss << ((scalenormtype_==
OneNorm) ?
"1-Norm" : (resnormtype_==
TwoNorm) ?
"2-Norm" :
"Inf-Norm");
290 bool showMaxResNormOnly_;
308 std::vector<MagnitudeType> scalevector_;
311 std::vector<MagnitudeType> resvector_;
314 std::vector<MagnitudeType> testvector_;
317 std::vector<int> ind_;
320 Teuchos::RCP<MV> curSoln_;
332 std::vector<int> curLSIdx_;
341 bool firstcallCheckStatus_;
344 bool firstcallDefineResForm_;
347 bool firstcallDefineScaleForm_;
353template <
class ScalarType,
class MV,
class OP>
369 firstcallCheckStatus_(
true),
370 firstcallDefineResForm_(
true),
371 firstcallDefineScaleForm_(
true)
377template <
class ScalarType,
class MV,
class OP>
381template <
class ScalarType,
class MV,
class OP>
390 firstcallCheckStatus_ =
true;
391 curSoln_ = Teuchos::null;
394template <
class ScalarType,
class MV,
class OP>
398 "StatusTestGenResNorm::defineResForm(): The residual form has already been defined.");
399 firstcallDefineResForm_ =
false;
407template <
class ScalarType,
class MV,
class OP>
412 "StatusTestGenResNorm::defineScaleForm(): The scaling type has already been defined.");
413 firstcallDefineScaleForm_ =
false;
422template <
class ScalarType,
class MV,
class OP>
428 if (firstcallCheckStatus_) {
438 if ( curLSNum_ !=
lp.getLSNumber() ) {
442 curLSNum_ =
lp.getLSNumber();
443 curLSIdx_ =
lp.getLSIndex();
444 curBlksz_ = (
int)curLSIdx_.size();
446 for (
int i=0;
i<curBlksz_; ++
i) {
447 if (curLSIdx_[
i] > -1 && curLSIdx_[
i] < numrhs_)
451 curSoln_ = Teuchos::null;
457 if (status_==
Passed) {
return status_; }
459 if (restype_==Implicit) {
467 if (
residMV != Teuchos::null ) {
470 typename std::vector<int>::iterator
p = curLSIdx_.begin();
471 for (
int i=0;
p<curLSIdx_.end(); ++
p, ++
i) {
477 typename std::vector<int>::iterator
p = curLSIdx_.begin();
478 for (
int i=0;
p<curLSIdx_.end(); ++
p, ++
i) {
485 else if (restype_==Explicit) {
491 Teuchos::RCP<MV>
cur_res = MVT::Clone( *curSoln_, MVT::GetNumberVecs( *curSoln_ ) );
492 lp.computeCurrResVec( &*
cur_res, &*curSoln_ );
495 typename std::vector<int>::iterator
p = curLSIdx_.begin();
496 for (
int i=0;
p<curLSIdx_.end(); ++
p, ++
i) {
506 if ( scalevector_.size() > 0 ) {
507 typename std::vector<int>::iterator
p = curLSIdx_.begin();
508 for (;
p<curLSIdx_.end(); ++
p) {
513 scalevector_[ *
p ] !=
zero? resvector_[ *
p ] / (scalevector_[ *
p ] * scalevalue_) : resvector_[ *
p ] / scalevalue_;
518 typename std::vector<int>::iterator
p = curLSIdx_.begin();
519 for (;
p<curLSIdx_.end(); ++
p) {
522 testvector_[ *
p ] = resvector_[ *
p ] / scalevalue_;
528 ind_.resize( curLSIdx_.size() );
529 typename std::vector<int>::iterator
p = curLSIdx_.begin();
530 for (;
p<curLSIdx_.end(); ++
p) {
534 if (testvector_[ *
p ] > tolerance_) {
536 }
else if (testvector_[ *
p ] <= tolerance_) {
547 int need = (quorum_ == -1) ? curNumRHS_: quorum_;
554template <
class ScalarType,
class MV,
class OP>
559 printStatus(
os, status_);
562 os <<
", tol = " << tolerance_ << std::endl;
565 if(showMaxResNormOnly_ && curBlksz_ > 1) {
567 testvector_.begin()+curLSIdx_[0],testvector_.begin()+curLSIdx_[curBlksz_-1]
571 os <<
"max{residual["<<curLSIdx_[0]<<
"..."<<curLSIdx_[curBlksz_-1]<<
"]} = " <<
maxRelRes
572 << (
maxRelRes <= tolerance_ ?
" <= " :
" > " ) << tolerance_ << std::endl;
575 for (
int i=0;
i<numrhs_;
i++ ) {
578 os <<
"residual [ " <<
i <<
" ] = " << testvector_[
i ];
579 os << ((testvector_[
i]<tolerance_) ?
" < " : (testvector_[
i]==tolerance_) ?
" == " : (testvector_[
i]>tolerance_) ?
" > " :
" " ) << tolerance_ << std::endl;
586template <
class ScalarType,
class MV,
class OP>
589 os << std::left << std::setw(13) << std::setfill(
'.');
602 os << std::left << std::setfill(
' ');
606template <
class ScalarType,
class MV,
class OP>
614 if (firstcallCheckStatus_) {
618 firstcallCheckStatus_ =
false;
621 Teuchos::RCP<const MV>
rhs =
lp.getRHS();
622 numrhs_ = MVT::GetNumberVecs( *
rhs );
623 scalevector_.resize( numrhs_ );
624 MVT::MvNorm( *
rhs, scalevector_, scalenormtype_ );
627 Teuchos::RCP<const MV>
init_res =
lp.getInitResVec();
628 numrhs_ = MVT::GetNumberVecs( *
init_res );
629 scalevector_.resize( numrhs_ );
630 MVT::MvNorm( *
init_res, scalevector_, scalenormtype_ );
633 Teuchos::RCP<const MV>
init_res =
lp.getInitPrecResVec();
634 numrhs_ = MVT::GetNumberVecs( *
init_res );
635 scalevector_.resize( numrhs_ );
636 MVT::MvNorm( *
init_res, scalevector_, scalenormtype_ );
639 numrhs_ = MVT::GetNumberVecs( *(
lp.getRHS()) );
642 resvector_.resize( numrhs_ );
643 testvector_.resize( numrhs_ );
645 curLSNum_ =
lp.getLSNumber();
646 curLSIdx_ =
lp.getLSIndex();
647 curBlksz_ = (
int)curLSIdx_.size();
649 for (
i=0;
i<curBlksz_; ++
i) {
650 if (curLSIdx_[
i] > -1 && curLSIdx_[
i] < numrhs_)
656 for (
i=0;
i<numrhs_;
i++) { testvector_[
i] =
one; }
659 if (scalevalue_ ==
zero) {
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.
Alternative run-time polymorphic interface for operators.
Operator()
Default constructor (does nothing).
Exception thrown to signal error in a status test during Belos::StatusTest::checkStatus().
An implementation of StatusTestResNorm using a family of residual norms.
NormType getResNormType()
std::string description() const
Method to return description of the maximum iteration status test
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.
void reset()
Resets the internal configuration to the initial state.
virtual ~StatusTestGenResNorm()
Destructor.
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.
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.
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.
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.
ResType
Select how the residual std::vector is produced.
const std::vector< MagnitudeType > * getScaledNormValue() const
Returns the scaled norm value, .
void printStatus(std::ostream &os, StatusType type) const
Print message for each status specific to this stopping test.
bool getLOADetected() const
Returns a boolean indicating a loss of accuracy has been detected in computing the residual.
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