42 #ifndef BELOS_STATUS_TEST_GEN_RESNORM_H
43 #define BELOS_STATUS_TEST_GEN_RESNORM_H
78 template <
class ScalarType,
class MV,
class OP>
84 typedef Teuchos::ScalarTraits<ScalarType>
SCT;
169 int setQuorum(
int quorum) {quorum_ = quorum;
return(0);}
203 void print(std::ostream& os,
int indent = 0)
const;
215 Teuchos::RCP<MV>
getSolution() {
if (restype_==
Implicit) {
return Teuchos::null; }
else {
return curSoln_; } }
231 const std::vector<MagnitudeType>*
getTestValue()
const {
return(&testvector_);};
263 std::ostringstream oss;
264 oss <<
"Belos::StatusTestGenResNorm<>: " << resFormStr();
265 oss <<
", tol = " << tolerance_;
277 std::string resFormStr()
const
279 std::ostringstream oss;
281 oss << ((resnormtype_==
OneNorm) ?
"1-Norm" : (resnormtype_==
TwoNorm) ?
"2-Norm" :
"Inf-Norm");
282 oss << ((restype_==
Explicit) ?
" Exp" :
" Imp");
286 if (scaletype_!=
None)
293 oss <<
" (User Scale)";
296 oss << ((scalenormtype_==
OneNorm) ?
"1-Norm" : (resnormtype_==
TwoNorm) ?
"2-Norm" :
"Inf-Norm");
322 bool showMaxResNormOnly_;
340 std::vector<MagnitudeType> scalevector_;
343 std::vector<MagnitudeType> resvector_;
346 std::vector<MagnitudeType> testvector_;
349 std::vector<int> ind_;
352 Teuchos::RCP<MV> curSoln_;
364 std::vector<int> curLSIdx_;
373 bool firstcallCheckStatus_;
376 bool firstcallDefineResForm_;
379 bool firstcallDefineScaleForm_;
385 template <
class ScalarType,
class MV,
class OP>
388 : tolerance_(Tolerance),
390 showMaxResNormOnly_(showMaxResNormOnly),
401 firstcallCheckStatus_(true),
402 firstcallDefineResForm_(true),
403 firstcallDefineScaleForm_(true)
409 template <
class ScalarType,
class MV,
class OP>
413 template <
class ScalarType,
class MV,
class OP>
422 firstcallCheckStatus_ =
true;
423 curSoln_ = Teuchos::null;
426 template <
class ScalarType,
class MV,
class OP>
429 TEUCHOS_TEST_FOR_EXCEPTION(firstcallDefineResForm_==
false,
StatusTestError,
430 "StatusTestGenResNorm::defineResForm(): The residual form has already been defined.");
431 firstcallDefineResForm_ =
false;
433 restype_ = TypeOfResidual;
434 resnormtype_ = TypeOfNorm;
439 template <
class ScalarType,
class MV,
class OP>
443 TEUCHOS_TEST_FOR_EXCEPTION(firstcallDefineScaleForm_==
false,
StatusTestError,
444 "StatusTestGenResNorm::defineScaleForm(): The scaling type has already been defined.");
445 firstcallDefineScaleForm_ =
false;
447 scaletype_ = TypeOfScaling;
448 scalenormtype_ = TypeOfNorm;
449 scalevalue_ = ScaleValue;
454 template <
class ScalarType,
class MV,
class OP>
457 MagnitudeType zero = Teuchos::ScalarTraits<MagnitudeType>::zero();
460 if (firstcallCheckStatus_) {
461 StatusType status = firstCallCheckStatusSetup(iSolver);
476 curBlksz_ = (int)curLSIdx_.size();
478 for (
int i=0; i<curBlksz_; ++i) {
479 if (curLSIdx_[i] > -1 && curLSIdx_[i] < numrhs_)
482 curNumRHS_ = validLS;
483 curSoln_ = Teuchos::null;
489 if (status_==
Passed) {
return status_; }
491 if (restype_==Implicit) {
497 std::vector<MagnitudeType> tmp_resvector( curBlksz_ );
499 if ( residMV != Teuchos::null ) {
500 tmp_resvector.resize( MVT::GetNumberVecs( *residMV ) );
501 MVT::MvNorm( *residMV, tmp_resvector, resnormtype_ );
502 typename std::vector<int>::iterator p = curLSIdx_.begin();
503 for (
int i=0; p<curLSIdx_.end(); ++p, ++i) {
506 resvector_[*p] = tmp_resvector[i];
509 typename std::vector<int>::iterator p = curLSIdx_.begin();
510 for (
int i=0; p<curLSIdx_.end(); ++p, ++i) {
513 resvector_[*p] = tmp_resvector[i];
517 else if (restype_==Explicit) {
523 Teuchos::RCP<MV> cur_res = MVT::Clone( *curSoln_, MVT::GetNumberVecs( *curSoln_ ) );
525 std::vector<MagnitudeType> tmp_resvector( MVT::GetNumberVecs( *cur_res ) );
526 MVT::MvNorm( *cur_res, tmp_resvector, resnormtype_ );
527 typename std::vector<int>::iterator p = curLSIdx_.begin();
528 for (
int i=0; p<curLSIdx_.end(); ++p, ++i) {
531 resvector_[*p] = tmp_resvector[i];
538 if ( scalevector_.size() > 0 ) {
539 typename std::vector<int>::iterator p = curLSIdx_.begin();
540 for (; p<curLSIdx_.end(); ++p) {
544 if ( scalevector_[ *p ] != zero ) {
546 testvector_[ *p ] = resvector_[ *p ] / scalevector_[ *p ] / scalevalue_;
548 testvector_[ *p ] = resvector_[ *p ] / scalevalue_;
554 typename std::vector<int>::iterator p = curLSIdx_.begin();
555 for (; p<curLSIdx_.end(); ++p) {
558 testvector_[ *p ] = resvector_[ *p ] / scalevalue_;
564 ind_.resize( curLSIdx_.size() );
565 typename std::vector<int>::iterator p = curLSIdx_.begin();
566 for (; p<curLSIdx_.end(); ++p) {
570 if (testvector_[ *p ] > tolerance_) {
572 }
else if (testvector_[ *p ] <= tolerance_) {
578 TEUCHOS_TEST_FOR_EXCEPTION(
true,
StatusTestError,
"StatusTestGenResNorm::checkStatus(): NaN has been detected.");
583 int need = (quorum_ == -1) ? curNumRHS_: quorum_;
590 template <
class ScalarType,
class MV,
class OP>
593 for (
int j = 0; j < indent; j ++)
595 printStatus(os, status_);
598 os <<
", tol = " << tolerance_ << std::endl;
601 if(showMaxResNormOnly_ && curBlksz_ > 1) {
603 testvector_.begin()+curLSIdx_[0],testvector_.begin()+curLSIdx_[curBlksz_-1]
605 for (
int j = 0; j < indent + 13; j ++)
607 os <<
"max{residual["<<curLSIdx_[0]<<
"..."<<curLSIdx_[curBlksz_-1]<<
"]} = " << maxRelRes
608 << ( maxRelRes <= tolerance_ ?
" <= " :
" > " ) << tolerance_ << std::endl;
611 for (
int i=0; i<numrhs_; i++ ) {
612 for (
int j = 0; j < indent + 13; j ++)
614 os <<
"residual [ " << i <<
" ] = " << testvector_[ i ];
615 os << ((testvector_[i]<tolerance_) ?
" < " : (testvector_[i]==tolerance_) ?
" == " : (testvector_[i]>tolerance_) ?
" > " :
" " ) << tolerance_ << std::endl;
622 template <
class ScalarType,
class MV,
class OP>
625 os << std::left << std::setw(13) << std::setfill(
'.');
638 os << std::left << std::setfill(
' ');
642 template <
class ScalarType,
class MV,
class OP>
646 MagnitudeType zero = Teuchos::ScalarTraits<MagnitudeType>::zero();
647 MagnitudeType one = Teuchos::ScalarTraits<MagnitudeType>::one();
650 if (firstcallCheckStatus_) {
654 firstcallCheckStatus_ =
false;
657 Teuchos::RCP<const MV> rhs = lp.
getRHS();
658 numrhs_ = MVT::GetNumberVecs( *rhs );
659 scalevector_.resize( numrhs_ );
660 MVT::MvNorm( *rhs, scalevector_, scalenormtype_ );
664 numrhs_ = MVT::GetNumberVecs( *init_res );
665 scalevector_.resize( numrhs_ );
666 MVT::MvNorm( *init_res, scalevector_, scalenormtype_ );
670 numrhs_ = MVT::GetNumberVecs( *init_res );
671 scalevector_.resize( numrhs_ );
672 MVT::MvNorm( *init_res, scalevector_, scalenormtype_ );
675 numrhs_ = MVT::GetNumberVecs( *(lp.
getRHS()) );
678 resvector_.resize( numrhs_ );
679 testvector_.resize( numrhs_ );
683 curBlksz_ = (int)curLSIdx_.size();
685 for (i=0; i<curBlksz_; ++i) {
686 if (curLSIdx_[i] > -1 && curLSIdx_[i] < numrhs_)
689 curNumRHS_ = validLS;
692 for (i=0; i<numrhs_; i++) { testvector_[i] = one; }
695 if (scalevalue_ == zero) {