Belos Package Browser (Single Doxygen Collection)  Development
BelosStatusTestGenResSubNorm.hpp
Go to the documentation of this file.
1 //@HEADER
2 // ************************************************************************
3 //
4 // Belos: Block Linear Solvers Package
5 // Copyright 2004 Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ************************************************************************
40 //@HEADER
41 
42 #ifndef BELOS_STATUS_TEST_GEN_RESSUBNORM_H
43 #define BELOS_STATUS_TEST_GEN_RESSUBNORM_H
44 
51 #include "BelosLinearProblem.hpp"
52 #include "BelosMultiVecTraits.hpp"
53 #include "BelosOperatorTraits.hpp"
54 
55 #ifdef HAVE_BELOS_THYRA
56 #include <Thyra_MultiVectorBase.hpp>
57 #include <Thyra_MultiVectorStdOps.hpp>
58 #include <Thyra_ProductMultiVectorBase.hpp>
59 #endif
60 
69 namespace Belos {
70 
71 template <class ScalarType, class MV, class OP>
72 class StatusTestGenResSubNorm: public StatusTestResNorm<ScalarType,MV,OP> {
73 
74  public:
75  // Convenience typedefs
76  typedef Teuchos::ScalarTraits<ScalarType> SCT;
77  typedef typename SCT::magnitudeType MagnitudeType;
79 
81 
82 
96  StatusTestGenResSubNorm( MagnitudeType Tolerance, size_t subIdx, int quorum = -1, bool showMaxResNormOnly = false ) {
97  TEUCHOS_TEST_FOR_EXCEPTION(true,StatusTestError,
98  "StatusTestGenResSubNorm::StatusTestGenResSubNorm(): StatusTestGenResSubNorm only available for blocked operators (e.g., Thyra).");
99  }
100 
102  virtual ~StatusTestGenResSubNorm() { };
104 
106 
107 
109 
115  int defineResForm( NormType TypeOfNorm) {
116  TEUCHOS_TEST_FOR_EXCEPTION(true,StatusTestError,
117  "StatusTestGenResSubNorm::defineResForm(): StatusTestGenResSubNorm only available for blocked operators (e.g., Thyra).");
118  return(0);
119  }
120 
122 
142  int defineScaleForm( ScaleType TypeOfScaling, NormType TypeOfNorm, MagnitudeType ScaleValue = Teuchos::ScalarTraits<MagnitudeType>::one()) {
143  TEUCHOS_TEST_FOR_EXCEPTION(true,StatusTestError,
144  "StatusTestGenResSubNorm::defineScaleForm(): StatusTestGenResSubNorm only available for blocked operators (e.g., Thyra).");
145  return(0);
146  }
147 
149 
152  int setTolerance(MagnitudeType tolerance) { return 0; }
153 
155 
157  int setSubIdx ( size_t subIdx ) { return 0;}
158 
161  int setQuorum(int quorum) { return 0; }
162 
164  int setShowMaxResNormOnly(bool showMaxResNormOnly) { return 0; }
165 
167 
169 
170 
177  StatusType checkStatus(Iteration<ScalarType,MV,OP>* iSolver) { return Undefined; }
178 
180  StatusType getStatus() const {return Undefined;}
182 
184 
185 
187  void reset() { }
188 
190 
192 
193 
195  void print(std::ostream& os, int indent = 0) const { }
196 
198  void printStatus(std::ostream& os, StatusType type) const { }
200 
202 
203 
207  Teuchos::RCP<MV> getSolution() { return Teuchos::null; }
208 
211  int getQuorum() const { return -1; }
212 
214  size_t getSubIdx() const { return 0; }
215 
217  bool getShowMaxResNormOnly() { return false; }
218 
220  std::vector<int> convIndices() { return std::vector<int>(0); }
221 
223  MagnitudeType getTolerance() const {return SCT::magnitude(SCT::zero());};
224 
226  const std::vector<MagnitudeType>* getTestValue() const {return NULL;};
227 
229  const std::vector<MagnitudeType>* getResNormValue() const {return NULL;};
230 
232  const std::vector<MagnitudeType>* getScaledNormValue() const {return NULL;};
233 
236  bool getLOADetected() const { return false; }
237 
239 
240 
243 
249  StatusType firstCallCheckStatusSetup(Iteration<ScalarType,MV,OP>* iSolver) {
250  return Undefined;
251  }
253 
256 
258  std::string description() const
259  { return std::string(""); }
261 };
262 
263 #ifdef HAVE_BELOS_THYRA
264 
265 // specialization for Thyra
266 template <class ScalarType>
267 class StatusTestGenResSubNorm<ScalarType,Thyra::MultiVectorBase<ScalarType>,Thyra::LinearOpBase<ScalarType> >
268  : public StatusTestResNorm<ScalarType,Thyra::MultiVectorBase<ScalarType>,Thyra::LinearOpBase<ScalarType> > {
269 
270  public:
271  // Convenience typedefs
272  typedef Thyra::MultiVectorBase<ScalarType> MV;
273  typedef Thyra::LinearOpBase<ScalarType> OP;
274 
275  typedef Teuchos::ScalarTraits<ScalarType> SCT;
276  typedef typename SCT::magnitudeType MagnitudeType;
277  typedef MultiVecTraits<ScalarType,MV> MVT;
278  typedef OperatorTraits<ScalarType,MV,OP> OT;
279 
281 
282 
295  StatusTestGenResSubNorm( MagnitudeType Tolerance, size_t subIdx, int quorum = -1, bool showMaxResNormOnly = false )
296  : tolerance_(Tolerance),
297  subIdx_(subIdx),
298  quorum_(quorum),
299  showMaxResNormOnly_(showMaxResNormOnly),
300  resnormtype_(TwoNorm),
301  scaletype_(NormOfInitRes),
302  scalenormtype_(TwoNorm),
303  scalevalue_(Teuchos::ScalarTraits<MagnitudeType>::one ()),
304  status_(Undefined),
305  curBlksz_(0),
306  curNumRHS_(0),
307  curLSNum_(0),
308  numrhs_(0),
309  firstcallCheckStatus_(true),
310  firstcallDefineResForm_(true),
311  firstcallDefineScaleForm_(true) { }
312 
314  virtual ~StatusTestGenResSubNorm() { };
316 
318 
319 
321 
327  int defineResForm(NormType TypeOfNorm) {
328  TEUCHOS_TEST_FOR_EXCEPTION(firstcallDefineResForm_==false,StatusTestError,
329  "StatusTestGenResSubNorm::defineResForm(): The residual form has already been defined.");
330  firstcallDefineResForm_ = false;
331 
332  resnormtype_ = TypeOfNorm;
333 
334  return(0);
335  }
336 
338 
358  int defineScaleForm( ScaleType TypeOfScaling, NormType TypeOfNorm, MagnitudeType ScaleValue = Teuchos::ScalarTraits<MagnitudeType>::one()) {
359  TEUCHOS_TEST_FOR_EXCEPTION(firstcallDefineScaleForm_==false,StatusTestError,
360  "StatusTestGenResSubNorm::defineScaleForm(): The scaling type has already been defined.");
361  firstcallDefineScaleForm_ = false;
362 
363  scaletype_ = TypeOfScaling;
364  scalenormtype_ = TypeOfNorm;
365  scalevalue_ = ScaleValue;
366 
367  return(0);
368  }
369 
371 
374  int setTolerance(MagnitudeType tolerance) {tolerance_ = tolerance; return(0);}
375 
377 
379  int setSubIdx ( size_t subIdx ) { subIdx_ = subIdx; return(0);}
380 
383  int setQuorum(int quorum) {quorum_ = quorum; return(0);}
384 
386  int setShowMaxResNormOnly(bool showMaxResNormOnly) {showMaxResNormOnly_ = showMaxResNormOnly; return(0);}
387 
389 
391 
392 
399  StatusType checkStatus(Iteration<ScalarType,MV,OP>* iSolver) {
400  MagnitudeType zero = Teuchos::ScalarTraits<MagnitudeType>::zero();
401  const LinearProblem<ScalarType,MV,OP>& lp = iSolver->getProblem();
402  // Compute scaling term (done once for each block that's being solved)
403  if (firstcallCheckStatus_) {
404  StatusType status = firstCallCheckStatusSetup(iSolver);
405  if(status==Failed) {
406  status_ = Failed;
407  return(status_);
408  }
409  }
410 
411  //
412  // This section computes the norm of the residual std::vector
413  //
414  if ( curLSNum_ != lp.getLSNumber() ) {
415  //
416  // We have moved on to the next rhs block
417  //
418  curLSNum_ = lp.getLSNumber();
419  curLSIdx_ = lp.getLSIndex();
420  curBlksz_ = (int)curLSIdx_.size();
421  int validLS = 0;
422  for (int i=0; i<curBlksz_; ++i) {
423  if (curLSIdx_[i] > -1 && curLSIdx_[i] < numrhs_)
424  validLS++;
425  }
426  curNumRHS_ = validLS;
427  curSoln_ = Teuchos::null;
428  //
429  } else {
430  //
431  // We are in the same rhs block, return if we are converged
432  //
433  if (status_==Passed) { return status_; }
434  }
435 
436  //
437  // Request the true residual for this block of right-hand sides.
438  //
439  Teuchos::RCP<MV> cur_update = iSolver->getCurrentUpdate();
440  curSoln_ = lp.updateSolution( cur_update );
441  Teuchos::RCP<MV> cur_res = MVT::Clone( *curSoln_, MVT::GetNumberVecs( *curSoln_ ) );
442  lp.computeCurrResVec( &*cur_res, &*curSoln_ );
443  std::vector<MagnitudeType> tmp_resvector( MVT::GetNumberVecs( *cur_res ) );
444  MvSubNorm( *cur_res, subIdx_, tmp_resvector, resnormtype_ );
445 
446  typename std::vector<int>::iterator pp = curLSIdx_.begin();
447  for (int i=0; pp<curLSIdx_.end(); ++pp, ++i) {
448  // Check if this index is valid
449  if (*pp != -1)
450  resvector_[*pp] = tmp_resvector[i];
451  }
452 
453  //
454  // Compute the new linear system residuals for testing.
455  // (if any of them don't meet the tolerance or are NaN, then we exit with that status)
456  //
457  if ( scalevector_.size() > 0 ) {
458  typename std::vector<int>::iterator p = curLSIdx_.begin();
459  for (; p<curLSIdx_.end(); ++p) {
460  // Check if this index is valid
461  if (*p != -1) {
462  // Scale the std::vector accordingly
463  if ( scalevector_[ *p ] != zero ) {
464  // Don't intentionally divide by zero.
465  testvector_[ *p ] = resvector_[ *p ] / scalevector_[ *p ] / scalevalue_;
466  } else {
467  testvector_[ *p ] = resvector_[ *p ] / scalevalue_;
468  }
469  }
470  }
471  }
472  else {
473  typename std::vector<int>::iterator ppp = curLSIdx_.begin();
474  for (; ppp<curLSIdx_.end(); ++ppp) {
475  // Check if this index is valid
476  if (*ppp != -1)
477  testvector_[ *ppp ] = resvector_[ *ppp ] / scalevalue_;
478  }
479  }
480  // Check status of new linear system residuals and see if we have the quorum.
481  int have = 0;
482  ind_.resize( curLSIdx_.size() );
483  typename std::vector<int>::iterator p2 = curLSIdx_.begin();
484  for (; p2<curLSIdx_.end(); ++p2) {
485  // Check if this index is valid
486  if (*p2 != -1) {
487  // Check if any of the residuals are larger than the tolerance.
488  if (testvector_[ *p2 ] > tolerance_) {
489  // do nothing.
490  } else if (testvector_[ *p2 ] <= tolerance_) {
491  ind_[have] = *p2;
492  have++;
493  } else {
494  // Throw an std::exception if a NaN is found.
495  status_ = Failed;
496  TEUCHOS_TEST_FOR_EXCEPTION(true,StatusTestError,"StatusTestGenResSubNorm::checkStatus(): NaN has been detected.");
497  }
498  }
499  }
500  ind_.resize(have);
501  int need = (quorum_ == -1) ? curNumRHS_: quorum_;
502  status_ = (have >= need) ? Passed : Failed;
503  // Return the current status
504  return status_;
505  }
506 
508  StatusType getStatus() const {return(status_);};
510 
512 
513 
515  void reset() {
516  status_ = Undefined;
517  curBlksz_ = 0;
518  curLSNum_ = 0;
519  curLSIdx_.resize(0);
520  numrhs_ = 0;
521  ind_.resize(0);
522  firstcallCheckStatus_ = true;
523  curSoln_ = Teuchos::null;
524  }
525 
527 
529 
530 
532  void print(std::ostream& os, int indent = 0) const {
533  os.setf(std::ios_base::scientific);
534  for (int j = 0; j < indent; j ++)
535  os << ' ';
536  printStatus(os, status_);
537  os << resFormStr();
538  if (status_==Undefined)
539  os << ", tol = " << tolerance_ << std::endl;
540  else {
541  os << std::endl;
542  if(showMaxResNormOnly_ && curBlksz_ > 1) {
543  const MagnitudeType maxRelRes = *std::max_element(
544  testvector_.begin()+curLSIdx_[0],testvector_.begin()+curLSIdx_[curBlksz_-1]
545  );
546  for (int j = 0; j < indent + 13; j ++)
547  os << ' ';
548  os << "max{residual["<<curLSIdx_[0]<<"..."<<curLSIdx_[curBlksz_-1]<<"]} = " << maxRelRes
549  << ( maxRelRes <= tolerance_ ? " <= " : " > " ) << tolerance_ << std::endl;
550  }
551  else {
552  for ( int i=0; i<numrhs_; i++ ) {
553  for (int j = 0; j < indent + 13; j ++)
554  os << ' ';
555  os << "residual [ " << i << " ] = " << testvector_[ i ];
556  os << ((testvector_[i]<tolerance_) ? " < " : (testvector_[i]==tolerance_) ? " == " : (testvector_[i]>tolerance_) ? " > " : " " ) << tolerance_ << std::endl;
557  }
558  }
559  }
560  os << std::endl;
561  }
562 
564  void printStatus(std::ostream& os, StatusType type) const {
565  os << std::left << std::setw(13) << std::setfill('.');
566  switch (type) {
567  case Passed:
568  os << "Converged";
569  break;
570  case Failed:
571  os << "Unconverged";
572  break;
573  case Undefined:
574  default:
575  os << "**";
576  break;
577  }
578  os << std::left << std::setfill(' ');
579  return;
580  }
582 
584 
585 
587  Teuchos::RCP<MV> getSolution() { return curSoln_; }
588 
591  int getQuorum() const { return quorum_; }
592 
594  size_t getSubIdx() const { return subIdx_; }
595 
597  bool getShowMaxResNormOnly() { return showMaxResNormOnly_; }
598 
600  std::vector<int> convIndices() { return ind_; }
601 
603  MagnitudeType getTolerance() const {return(tolerance_);};
604 
606  const std::vector<MagnitudeType>* getTestValue() const {return(&testvector_);};
607 
609  const std::vector<MagnitudeType>* getResNormValue() const {return(&resvector_);};
610 
612  const std::vector<MagnitudeType>* getScaledNormValue() const {return(&scalevector_);};
613 
616  bool getLOADetected() const { return false; }
617 
619 
620 
623 
629  StatusType firstCallCheckStatusSetup(Iteration<ScalarType,MV,OP>* iSolver) {
630  int i;
631  MagnitudeType zero = Teuchos::ScalarTraits<MagnitudeType>::zero();
632  MagnitudeType one = Teuchos::ScalarTraits<MagnitudeType>::one();
633  const LinearProblem<ScalarType,MV,OP>& lp = iSolver->getProblem();
634  // Compute scaling term (done once for each block that's being solved)
635  if (firstcallCheckStatus_) {
636  //
637  // Get some current solver information.
638  //
639  firstcallCheckStatus_ = false;
640 
641  if (scaletype_== NormOfRHS) {
642  Teuchos::RCP<const MV> rhs = lp.getRHS();
643  numrhs_ = MVT::GetNumberVecs( *rhs );
644  scalevector_.resize( numrhs_ );
645  MvSubNorm( *rhs, subIdx_, scalevector_, scalenormtype_ );
646  }
647  else if (scaletype_==NormOfInitRes) {
648  Teuchos::RCP<const MV> init_res = lp.getInitResVec();
649  numrhs_ = MVT::GetNumberVecs( *init_res );
650  scalevector_.resize( numrhs_ );
651  MvSubNorm( *init_res, subIdx_, scalevector_, scalenormtype_ );
652  }
653  else if (scaletype_==NormOfPrecInitRes) {
654  Teuchos::RCP<const MV> init_res = lp.getInitPrecResVec();
655  numrhs_ = MVT::GetNumberVecs( *init_res );
656  scalevector_.resize( numrhs_ );
657  MvSubNorm( *init_res, subIdx_, scalevector_, scalenormtype_ );
658  }
659  else if (scaletype_==NormOfFullInitRes) {
660  Teuchos::RCP<const MV> init_res = lp.getInitResVec();
661  numrhs_ = MVT::GetNumberVecs( *init_res );
662  scalevector_.resize( numrhs_ );
663  MVT::MvNorm( *init_res, scalevector_, scalenormtype_ );
664  scalevalue_ = Teuchos::ScalarTraits<ScalarType>::one();
665  }
666  else if (scaletype_==NormOfFullPrecInitRes) {
667  Teuchos::RCP<const MV> init_res = lp.getInitPrecResVec();
668  numrhs_ = MVT::GetNumberVecs( *init_res );
669  scalevector_.resize( numrhs_ );
670  MVT::MvNorm( *init_res, scalevector_, scalenormtype_ );
671  scalevalue_ = Teuchos::ScalarTraits<ScalarType>::one();
672  }
673  else if (scaletype_==NormOfFullScaledInitRes) {
674  Teuchos::RCP<const MV> init_res = lp.getInitResVec();
675  numrhs_ = MVT::GetNumberVecs( *init_res );
676  scalevector_.resize( numrhs_ );
677  MVT::MvNorm( *init_res, scalevector_, scalenormtype_ );
678  MvScalingRatio( *init_res, subIdx_, scalevalue_ );
679  }
680  else if (scaletype_==NormOfFullScaledPrecInitRes) {
681  Teuchos::RCP<const MV> init_res = lp.getInitPrecResVec();
682  numrhs_ = MVT::GetNumberVecs( *init_res );
683  scalevector_.resize( numrhs_ );
684  MVT::MvNorm( *init_res, scalevector_, scalenormtype_ );
685  MvScalingRatio( *init_res, subIdx_, scalevalue_ );
686  }
687  else {
688  numrhs_ = MVT::GetNumberVecs( *(lp.getRHS()) );
689  }
690 
691  resvector_.resize( numrhs_ );
692  testvector_.resize( numrhs_ );
693 
694  curLSNum_ = lp.getLSNumber();
695  curLSIdx_ = lp.getLSIndex();
696  curBlksz_ = (int)curLSIdx_.size();
697  int validLS = 0;
698  for (i=0; i<curBlksz_; ++i) {
699  if (curLSIdx_[i] > -1 && curLSIdx_[i] < numrhs_)
700  validLS++;
701  }
702  curNumRHS_ = validLS;
703  //
704  // Initialize the testvector.
705  for (i=0; i<numrhs_; i++) { testvector_[i] = one; }
706 
707  // Return an error if the scaling is zero.
708  if (scalevalue_ == zero) {
709  return Failed;
710  }
711  }
712  return Undefined;
713  }
715 
718 
720  std::string description() const
721  {
722  std::ostringstream oss;
723  oss << "Belos::StatusTestGenResSubNorm<>: " << resFormStr();
724  oss << ", tol = " << tolerance_;
725  return oss.str();
726  }
728 
729  protected:
730 
731  private:
732 
734 
735 
736  std::string resFormStr() const
737  {
738  std::ostringstream oss;
739  oss << "(";
740  oss << ((resnormtype_==OneNorm) ? "1-Norm" : (resnormtype_==TwoNorm) ? "2-Norm" : "Inf-Norm");
741  oss << " Exp";
742  oss << " Res Vec [" << subIdx_ << "]) ";
743 
744  // If there is no residual scaling, return current string.
745  if (scaletype_!=None)
746  {
747  // Insert division sign.
748  oss << "/ ";
749 
750  // Determine output string for scaling, if there is any.
751  if (scaletype_==UserProvided)
752  oss << " (User Scale)";
753  else {
754  oss << "(";
755  oss << ((scalenormtype_==OneNorm) ? "1-Norm" : (resnormtype_==TwoNorm) ? "2-Norm" : "Inf-Norm");
756  if (scaletype_==NormOfInitRes)
757  oss << " Res0 [" << subIdx_ << "]";
758  else if (scaletype_==NormOfPrecInitRes)
759  oss << " Prec Res0 [" << subIdx_ << "]";
760  else if (scaletype_==NormOfFullInitRes)
761  oss << " Full Res0 [" << subIdx_ << "]";
762  else if (scaletype_==NormOfFullPrecInitRes)
763  oss << " Full Prec Res0 [" << subIdx_ << "]";
764  else if (scaletype_==NormOfFullScaledInitRes)
765  oss << " scaled Full Res0 [" << subIdx_ << "]";
766  else if (scaletype_==NormOfFullScaledPrecInitRes)
767  oss << " scaled Full Prec Res0 [" << subIdx_ << "]";
768  else
769  oss << " RHS [" << subIdx_ << "]";
770  oss << ")";
771  }
772  }
773 
774  // TODO add a tagging name
775 
776  return oss.str();
777  }
778 
780 
782 
783 
784  // calculate norm of partial multivector
785  void MvSubNorm( const MV& mv, size_t block, std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>& normVec, NormType type = TwoNorm) {
786  Teuchos::RCP<const MV> input = Teuchos::rcpFromRef(mv);
787 
788  typedef typename Thyra::ProductMultiVectorBase<ScalarType> TPMVB;
789  Teuchos::RCP<const TPMVB> thyProdVec = Teuchos::rcp_dynamic_cast<const TPMVB>(input);
790 
791  TEUCHOS_TEST_FOR_EXCEPTION(thyProdVec == Teuchos::null, std::invalid_argument,
792  "Belos::StatusTestGenResSubNorm::MvSubNorm (Thyra specialization): "
793  "mv must be a Thyra::ProductMultiVector, but is of type " << thyProdVec);
794 
795  Teuchos::RCP<const MV> thySubVec = thyProdVec->getMultiVectorBlock(block);
796 
797  typedef MultiVecTraits<ScalarType, MV> MVT;
798  MVT::MvNorm(*thySubVec,normVec,type);
799  }
800 
801  // calculate ration of sub-vector length to full vector length (for scalevalue_)
802  void MvScalingRatio( const MV& mv, size_t block, MagnitudeType& lengthRatio) {
803  Teuchos::RCP<const MV> input = Teuchos::rcpFromRef(mv);
804 
805  typedef typename Thyra::ProductMultiVectorBase<ScalarType> TPMVB;
806  Teuchos::RCP<const TPMVB> thyProdVec = Teuchos::rcp_dynamic_cast<const TPMVB>(input);
807 
808  TEUCHOS_TEST_FOR_EXCEPTION(thyProdVec == Teuchos::null, std::invalid_argument,
809  "Belos::StatusTestGenResSubNorm::MvScalingRatio (Thyra specialization): "
810  "mv must be a Thyra::ProductMultiVector, but is of type " << thyProdVec);
811 
812  Teuchos::RCP<const MV> thySubVec = thyProdVec->getMultiVectorBlock(block);
813 
814  lengthRatio = Teuchos::as<MagnitudeType>(thySubVec->range()->dim()) / Teuchos::as<MagnitudeType>(thyProdVec->range()->dim());
815  }
816 
818 
820 
821 
823  MagnitudeType tolerance_;
824 
826  size_t subIdx_;
827 
829  int quorum_;
830 
832  bool showMaxResNormOnly_;
833 
835  NormType resnormtype_;
836 
838  ScaleType scaletype_;
839 
841  NormType scalenormtype_;
842 
844  MagnitudeType scalevalue_;
845 
847  std::vector<MagnitudeType> scalevector_;
848 
850  std::vector<MagnitudeType> resvector_;
851 
853  std::vector<MagnitudeType> testvector_;
854 
856  std::vector<int> ind_;
857 
859  Teuchos::RCP<MV> curSoln_;
860 
862  StatusType status_;
863 
865  int curBlksz_;
866 
868  int curNumRHS_;
869 
871  std::vector<int> curLSIdx_;
872 
874  int curLSNum_;
875 
877  int numrhs_;
878 
880  bool firstcallCheckStatus_;
881 
883  bool firstcallDefineResForm_;
884 
886  bool firstcallDefineScaleForm_;
887 
889 
890 };
891 
892 #endif // HAVE_BELOS_THYRA
893 
894 } // end namespace Belos
895 
896 #endif /* BELOS_STATUS_TEST_RESSUBNORM_H */
virtual std::vector< int > convIndices()=0
Returns the std::vector containing the indices of the residuals that passed the test.
ScaleType
The type of scaling to use on the residual norm value.
Definition: BelosTypes.hpp:119
Exception thrown to signal error in a status test during Belos::StatusTest::checkStatus().
virtual int setQuorum(int quorum)=0
Sets the number of residuals that must pass the convergence test before Passed is returned...
virtual int getQuorum() const =0
Returns the number of residuals that must pass the convergence test before Passed is returned...
An implementation of StatusTestResNorm using a family of norms of subvectors of the residual vectors...
Declaration of basic traits for the multivector type.
An abstract class of StatusTest for stopping criteria using residual norms.
virtual MagnitudeType getTolerance() const =0
Returns the value of the tolerance, , set in the constructor.
virtual StatusType checkStatus(Iteration< ScalarType, MV, OP > *iSolver)=0
Check convergence status: Unconverged, Converged, Failed.
Class which defines basic traits for the operator type.
StatusType
Whether the StatusTest wants iteration to stop.
Definition: BelosTypes.hpp:188
static int GetNumberVecs(const MV &mv)
Obtain the number of vectors in mv.
virtual void print(std::ostream &os, int indent=0) const =0
Output formatted description of stopping test to output stream.
virtual int defineScaleForm(ScaleType TypeOfScaling, NormType TypeOfNorm, MagnitudeType ScaleValue=Teuchos::ScalarTraits< MagnitudeType >::one())=0
Define the form of the scaling for the residual.
MultiVecTraits< ScalarType, MV > MVT
Traits class which defines basic operations on multivectors.
static Teuchos::RCP< MV > Clone(const MV &mv, const int numvecs)
Creates a new empty MV containing numvecs columns.
virtual void printStatus(std::ostream &os, StatusType type) const
Output the result of the most recent CheckStatus call.
virtual Teuchos::RCP< MV > getSolution()=0
Returns the current solution estimate that was computed for the most recent residual test...
virtual int setShowMaxResNormOnly(bool showMaxResNormOnly)=0
Set whether the only maximum residual norm is displayed when the print() method is called...
virtual bool getShowMaxResNormOnly()=0
Returns whether the only maximum residual norm is displayed when the print() method is called...
Class which describes the linear problem to be solved by the iterative solver.
virtual const std::vector< MagnitudeType > * getTestValue() const =0
Returns the test value, , computed in most recent call to CheckStatus.
Belos::StatusTest abstract class for specifying a residual norm stopping criteria.
Teuchos::ScalarTraits< ScalarType > SCT
NormType
The type of vector norm to compute.
Definition: BelosTypes.hpp:97
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 ...
virtual void reset()=0
Informs the convergence test that it should reset its internal configuration to the initialized state...
virtual bool getLOADetected() const =0
Returns a boolean indicating a loss of accuracy has been detected in computing the residual...
virtual StatusType getStatus() const =0
Return the result of the most recent CheckStatus call.
virtual int setTolerance(MagnitudeType tolerance)=0
Set the value of the tolerance.