Belos  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BelosStatusTestImpResNorm.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_IMPRESNORM_H
43 #define BELOS_STATUS_TEST_IMPRESNORM_H
44 
51 #include "BelosLinearProblem.hpp"
52 #include "BelosMultiVecTraits.hpp"
53 #include "Teuchos_as.hpp"
54 
101 namespace Belos {
102 
103 template <class ScalarType, class MV, class OP>
104 class StatusTestImpResNorm: public StatusTestResNorm<ScalarType,MV,OP> {
105 public:
108 
109 private:
111 
116 
117 public:
119 
120 
133  int quorum = -1,
134  bool showMaxResNormOnly = false);
135 
137  virtual ~StatusTestImpResNorm();
138 
140 
142 
144 
150  int defineResForm( NormType TypeOfNorm);
151 
153 
173  int defineScaleForm( ScaleType TypeOfScaling, NormType TypeOfNorm, MagnitudeType ScaleValue = Teuchos::ScalarTraits<MagnitudeType>::one());
174 
176 
179  int setTolerance (MagnitudeType tolerance) {
180  tolerance_ = tolerance;
181  return 0;
182  }
183 
186  int setQuorum (int quorum) {
187  quorum_ = quorum;
188  return 0;
189  }
190 
192  int setShowMaxResNormOnly (bool showMaxResNormOnly) {
193  showMaxResNormOnly_ = showMaxResNormOnly;
194  return 0;
195  }
196 
198 
200 
201 
209 
211  StatusType getStatus() const {return(status_);};
213 
215 
216 
218  void reset();
219 
221 
223 
224 
226  void print(std::ostream& os, int indent = 0) const;
227 
229  void printStatus(std::ostream& os, StatusType type) const;
231 
233 
234 
236  Teuchos::RCP<MV> getSolution() { return curSoln_; }
237 
240  int getQuorum() const { return quorum_; }
241 
243  bool getShowMaxResNormOnly() { return showMaxResNormOnly_; }
244 
246  std::vector<int> convIndices() { return ind_; }
247 
256  return tolerance_;
257  }
258 
267  return currTolerance_;
268  }
269 
271  const std::vector<MagnitudeType>* getTestValue() const {return(&testvector_);};
272 
274  const std::vector<MagnitudeType>* getResNormValue() const {return(&resvector_);};
275 
277  const std::vector<MagnitudeType>* getScaledNormValue() const {return(&scalevector_);};
278 
280  bool getLOADetected() const { return lossDetected_; }
282 
283 
286 
294 
297 
299  std::string description() const
300  {
301  std::ostringstream oss;
302  oss << "Belos::StatusTestImpResNorm<>: " << resFormStr();
303  oss << ", tol = " << tolerance_;
304  return oss.str();
305  }
307 
308  protected:
309 
310  private:
311 
313 
314 
315  std::string resFormStr() const
316  {
317  std::ostringstream oss;
318  oss << "(";
319  oss << ((resnormtype_==OneNorm) ? "1-Norm" : (resnormtype_==TwoNorm) ? "2-Norm" : "Inf-Norm");
320  oss << " Res Vec) ";
321 
322  // If there is no residual scaling, return current string.
323  if (scaletype_!=None)
324  {
325  // Insert division sign.
326  oss << "/ ";
327 
328  // Determine output string for scaling, if there is any.
329  if (scaletype_==UserProvided)
330  oss << " (User Scale)";
331  else {
332  oss << "(";
333  oss << ((scalenormtype_==OneNorm) ? "1-Norm" : (resnormtype_==TwoNorm) ? "2-Norm" : "Inf-Norm");
334  if (scaletype_==NormOfInitRes)
335  oss << " Res0";
336  else if (scaletype_==NormOfPrecInitRes)
337  oss << " Prec Res0";
338  else
339  oss << " RHS ";
340  oss << ")";
341  }
342  }
343 
344  return oss.str();
345  }
346 
348 
349 
351  MagnitudeType tolerance_, currTolerance_;
352 
354  int quorum_;
355 
357  bool showMaxResNormOnly_;
358 
360  NormType resnormtype_;
361 
363  ScaleType scaletype_;
364 
366  NormType scalenormtype_;
367 
369  MagnitudeType scalevalue_;
370 
372  std::vector<MagnitudeType> scalevector_;
373 
375  std::vector<MagnitudeType> resvector_;
376 
378  std::vector<MagnitudeType> testvector_;
379 
381  Teuchos::RCP<MV> curSoln_;
382 
384  std::vector<int> ind_;
385 
387  StatusType status_;
388 
390  int curBlksz_;
391 
393  int curNumRHS_;
394 
396  std::vector<int> curLSIdx_;
397 
399  int curLSNum_;
400 
402  int numrhs_;
403 
405  bool firstcallCheckStatus_;
406 
408  bool firstcallDefineResForm_;
409 
411  bool firstcallDefineScaleForm_;
412 
414  bool lossDetected_;
416 
417 };
418 
419 template <class ScalarType, class MV, class OP>
421 StatusTestImpResNorm (MagnitudeType Tolerance, int quorum, bool showMaxResNormOnly)
422  : tolerance_(Tolerance),
423  currTolerance_(Tolerance),
424  quorum_(quorum),
425  showMaxResNormOnly_(showMaxResNormOnly),
426  resnormtype_(TwoNorm),
427  scaletype_(NormOfInitRes),
428  scalenormtype_(TwoNorm),
429  scalevalue_(1.0),
430  status_(Undefined),
431  curBlksz_(0),
432  curLSNum_(0),
433  numrhs_(0),
434  firstcallCheckStatus_(true),
435  firstcallDefineResForm_(true),
436  firstcallDefineScaleForm_(true),
437  lossDetected_(false)
438 {
439  // This constructor will compute the residual ||r_i||/||r0_i|| <= tolerance using the 2-norm of
440  // the implicit residual vector.
441 }
442 
443 template <class ScalarType, class MV, class OP>
445 {}
446 
447 template <class ScalarType, class MV, class OP>
449 {
450  status_ = Undefined;
451  curBlksz_ = 0;
452  curLSNum_ = 0;
453  curLSIdx_.resize(0);
454  numrhs_ = 0;
455  ind_.resize(0);
456  currTolerance_ = tolerance_;
457  firstcallCheckStatus_ = true;
458  lossDetected_ = false;
459  curSoln_ = Teuchos::null;
460 }
461 
462 template <class ScalarType, class MV, class OP>
464 {
465  TEUCHOS_TEST_FOR_EXCEPTION(firstcallDefineResForm_==false,StatusTestError,
466  "StatusTestResNorm::defineResForm(): The residual form has already been defined.");
467  firstcallDefineResForm_ = false;
468 
469  resnormtype_ = TypeOfNorm;
470 
471  return(0);
472 }
473 
474 template <class ScalarType, class MV, class OP>
476  MagnitudeType ScaleValue )
477 {
478  TEUCHOS_TEST_FOR_EXCEPTION(firstcallDefineScaleForm_==false,StatusTestError,
479  "StatusTestResNorm::defineScaleForm(): The scaling type has already been defined.");
480  firstcallDefineScaleForm_ = false;
481 
482  scaletype_ = TypeOfScaling;
483  scalenormtype_ = TypeOfNorm;
484  scalevalue_ = ScaleValue;
485 
486  return(0);
487 }
488 
489 template <class ScalarType, class MV, class OP>
492 {
493  using Teuchos::as;
494  using Teuchos::RCP;
495 
496  const MagnitudeType zero = STM::zero ();
497  const LinearProblem<ScalarType,MV,OP>& lp = iSolver->getProblem ();
498 
499  // Compute scaling term (done once for each block that's being solved)
500  if (firstcallCheckStatus_) {
501  StatusType status = firstCallCheckStatusSetup (iSolver);
502  if (status == Failed) {
503  status_ = Failed;
504  return status_;
505  }
506  }
507 
508  // mfh 23 Apr 2012: I don't know exactly what this code does. It
509  // has something to do with picking the block of right-hand sides
510  // which we're currently checking.
511  if (curLSNum_ != lp.getLSNumber ()) {
512  //
513  // We have moved on to the next rhs block
514  //
515  curLSNum_ = lp.getLSNumber();
516  curLSIdx_ = lp.getLSIndex();
517  curBlksz_ = (int)curLSIdx_.size();
518  int validLS = 0;
519  for (int i=0; i<curBlksz_; ++i) {
520  if (curLSIdx_[i] > -1 && curLSIdx_[i] < numrhs_)
521  validLS++;
522  }
523  curNumRHS_ = validLS;
524  curSoln_ = Teuchos::null;
525  } else {
526  //
527  // We are in the same rhs block, return if we are converged
528  //
529  if (status_ == Passed) {
530  return status_;
531  }
532  }
533 
534  //
535  // Get the "native" residual norms from the solver for this block of
536  // right-hand sides. If the solver's getNativeResiduals() method
537  // actually returns a multivector, compute the norms of the columns
538  // of the multivector explicitly. Otherwise, we assume that
539  // resvector_ contains the norms.
540  //
541  // Note that "compute the norms explicitly" doesn't necessarily mean
542  // the "explicit" residual norms (in the sense discussed in this
543  // class' documentation). These are just some vectors returned by
544  // the solver. Some Krylov methods, like CG, compute a residual
545  // vector "recursively." This is an "implicit residual" in the
546  // sense of this class' documentation. It equals the explicit
547  // residual in exact arithmetic, but due to rounding error, it is
548  // usually different than the explicit residual.
549  //
550  // FIXME (mfh 23 Apr 2012) This method does _not_ respect the
551  // OrthoManager used by the solver.
552  //
553  std::vector<MagnitudeType> tmp_resvector( curBlksz_ );
554  RCP<const MV> residMV = iSolver->getNativeResiduals (&tmp_resvector);
555  if (! residMV.is_null ()) {
556  // We got a multivector back. Compute the norms explicitly.
557  tmp_resvector.resize (MVT::GetNumberVecs (*residMV));
558  MVT::MvNorm (*residMV, tmp_resvector, resnormtype_);
559  typename std::vector<int>::iterator p = curLSIdx_.begin();
560  for (int i=0; p<curLSIdx_.end(); ++p, ++i) {
561  // Check if this index is valid
562  if (*p != -1) {
563  resvector_[*p] = tmp_resvector[i];
564  }
565  }
566  } else {
567  typename std::vector<int>::iterator p = curLSIdx_.begin();
568  for (int i=0; p<curLSIdx_.end(); ++p, ++i) {
569  // Check if this index is valid
570  if (*p != -1) {
571  resvector_[*p] = tmp_resvector[i];
572  }
573  }
574  }
575  //
576  // Scale the unscaled residual norms we computed or obtained above.
577  //
578  if (scalevector_.size () > 0) {
579  // There are per-vector scaling factors to apply.
580  typename std::vector<int>::iterator p = curLSIdx_.begin();
581  for (; p<curLSIdx_.end(); ++p) {
582  // Check if this index is valid
583  if (*p != -1) {
584  // Scale the vector accordingly
585  if ( scalevector_[ *p ] != zero ) {
586  // Don't intentionally divide by zero.
587  testvector_[ *p ] = resvector_[ *p ] / scalevector_[ *p ] / scalevalue_;
588  } else {
589  testvector_[ *p ] = resvector_[ *p ] / scalevalue_;
590  }
591  }
592  }
593  }
594  else { // There are no per-vector scaling factors.
595  typename std::vector<int>::iterator p = curLSIdx_.begin();
596  for (; p<curLSIdx_.end(); ++p) {
597  // Check if this index is valid
598  if (*p != -1) {
599  testvector_[ *p ] = resvector_[ *p ] / scalevalue_;
600  }
601  }
602  }
603 
604  // Count how many scaled residual norms (in testvector_) pass, using
605  // the current tolerance (currTolerance_) rather than the original
606  // tolerance (tolerance_). If at least quorum_ of them pass, we
607  // have a quorum for the whole test to pass.
608  //
609  // We also check here whether any of the scaled residual norms is
610  // NaN, and throw an exception in that case.
611  int have = 0;
612  ind_.resize( curLSIdx_.size() );
613  std::vector<int> lclInd( curLSIdx_.size() );
614  typename std::vector<int>::iterator p = curLSIdx_.begin();
615  for (int i=0; p<curLSIdx_.end(); ++p, ++i) {
616  // Check if this index is valid
617  if (*p != -1) {
618  if (testvector_[ *p ] > currTolerance_) {
619  // The current residual norm doesn't pass. Do nothing.
620  } else if (testvector_[ *p ] <= currTolerance_) {
621  ind_[have] = *p;
622  lclInd[have] = i;
623  have++; // Yay, the current residual norm passes!
624  } else {
625  // Throw an std::exception if the current residual norm is
626  // NaN. We know that it's NaN because it is not less than,
627  // equal to, or greater than the current tolerance. This is
628  // only possible if either the residual norm or the current
629  // tolerance is NaN; we assume the former. We also mark the
630  // test as failed, in case you want to catch the exception.
631  status_ = Failed;
633  "StatusTestImpResNorm::checkStatus(): One or more of the current "
634  "implicit residual norms is NaN.");
635  }
636  }
637  }
638  // "have" is the number of residual norms that passed.
639  ind_.resize(have);
640  lclInd.resize(have);
641 
642  // Now check the exact residuals
643  if (have) { // At least one residual norm has converged.
644  //
645  // Compute the explicit residual norm(s) from the current solution update.
646  //
647  RCP<MV> cur_update = iSolver->getCurrentUpdate ();
648  curSoln_ = lp.updateSolution (cur_update);
649  RCP<MV> cur_res = MVT::Clone (*curSoln_, MVT::GetNumberVecs (*curSoln_));
650  lp.computeCurrResVec (&*cur_res, &*curSoln_);
651  tmp_resvector.resize (MVT::GetNumberVecs (*cur_res));
652  std::vector<MagnitudeType> tmp_testvector (have);
653  MVT::MvNorm (*cur_res, tmp_resvector, resnormtype_);
654 
655  // Scale the explicit residual norm(s), just like the implicit norm(s).
656  if ( scalevector_.size() > 0 ) {
657  for (int i=0; i<have; ++i) {
658  // Scale the vector accordingly
659  if ( scalevector_[ ind_[i] ] != zero ) {
660  // Don't intentionally divide by zero.
661  tmp_testvector[ i ] = tmp_resvector[ lclInd[i] ] / scalevector_[ ind_[i] ] / scalevalue_;
662  } else {
663  tmp_testvector[ i ] = tmp_resvector[ lclInd[i] ] / scalevalue_;
664  }
665  }
666  }
667  else {
668  for (int i=0; i<have; ++i) {
669  tmp_testvector[ i ] = tmp_resvector[ lclInd[i] ] / scalevalue_;
670  }
671  }
672 
673  //
674  // Check whether the explicit residual norms also pass the
675  // convergence test. If not, check whether we want to try
676  // iterating a little more to force both implicit and explicit
677  // residual norms to pass.
678  //
679  int have2 = 0;
680  for (int i = 0; i < have; ++i) {
681  // testvector_ contains the implicit (i.e., recursive, computed
682  // by the algorithm) (possibly scaled) residuals. All of these
683  // pass the convergence test.
684  //
685  // tmp_testvector contains the explicit (i.e., ||B-AX||)
686  // (possibly scaled) residuals. We're checking whether these
687  // pass as well. The explicit residual norms only have to meet
688  // the _original_ tolerance (tolerance_), not the current
689  // tolerance (currTolerance_).
690  if (tmp_testvector[i] <= tolerance_) {
691  ind_[have2] = ind_[i];
692  have2++; // This right-hand side has converged.
693  }
694  else {
695  // Absolute difference between the current explicit and
696  // implicit residual norm.
697  const MagnitudeType diff = STM::magnitude (testvector_[ind_[i]] - tmp_testvector[i]);
698  if (diff > currTolerance_) {
699  // If the above difference is bigger than the current
700  // convergence tolerance, report a loss of accuracy, but
701  // mark this right-hand side converged. (The latter tells
702  // users not to iterate further on this right-hand side,
703  // since it probably won't do much good.) Note that the
704  // current tolerance may have been changed by the branch
705  // below in a previous call to this method.
706  lossDetected_ = true;
707  ind_[have2] = ind_[i];
708  have2++; // Count this right-hand side as converged.
709  }
710  else {
711  // Otherwise, the explicit and implicit residuals are pretty
712  // close together, and the implicit residual has converged,
713  // but the explicit residual hasn't converged. Reduce the
714  // convergence tolerance by some formula related to the
715  // difference, and keep iterating.
716  //
717  // mfh 23 Apr 2012: I have no idea why the currTolerance_
718  // update formula is done the way it's done below. It
719  // doesn't make sense to me. It definitely makes the
720  // current tolerance smaller, though, which is what we want.
721 
722  // We define these constants in this way, rather than simply
723  // writing 1.5 resp. 0.1, to ensure no rounding error from
724  // translating from float to MagnitudeType. Remember that
725  // 0.1 doesn't have an exact representation in binary finite
726  // floating-point arithmetic.
727  const MagnitudeType onePointFive = as<MagnitudeType>(3) / as<MagnitudeType> (2);
728  const MagnitudeType oneTenth = STM::one () / as<MagnitudeType> (10);
729 
730  currTolerance_ = currTolerance_ - onePointFive * diff;
731  while (currTolerance_ < STM::zero ()) {
732  currTolerance_ += oneTenth * diff;
733  }
734  }
735  }
736  }
737  have = have2;
738  ind_.resize(have);
739  }
740 
741  // Check whether we've met the quorum of vectors necessary for the
742  // whole test to pass.
743  int need = (quorum_ == -1) ? curNumRHS_: quorum_;
744  status_ = (have >= need) ? Passed : Failed;
745 
746  // Return the current status
747  return status_;
748 }
749 
750 template <class ScalarType, class MV, class OP>
751 void StatusTestImpResNorm<ScalarType,MV,OP>::print(std::ostream& os, int indent) const
752 {
753  for (int j = 0; j < indent; j ++)
754  os << ' ';
755  printStatus(os, status_);
756  os << resFormStr();
757  if (status_==Undefined)
758  os << ", tol = " << tolerance_ << std::endl;
759  else {
760  os << std::endl;
761  if(showMaxResNormOnly_ && curBlksz_ > 1) {
762  const MagnitudeType maxRelRes = *std::max_element(
763  testvector_.begin()+curLSIdx_[0],testvector_.begin()+curLSIdx_[curBlksz_-1]
764  );
765  for (int j = 0; j < indent + 13; j ++)
766  os << ' ';
767  os << "max{residual["<<curLSIdx_[0]<<"..."<<curLSIdx_[curBlksz_-1]<<"]} = " << maxRelRes
768  << ( maxRelRes <= tolerance_ ? " <= " : " > " ) << tolerance_ << std::endl;
769  }
770  else {
771  for ( int i=0; i<numrhs_; i++ ) {
772  for (int j = 0; j < indent + 13; j ++)
773  os << ' ';
774  os << "residual [ " << i << " ] = " << testvector_[ i ];
775  os << ((testvector_[i]<tolerance_) ? " < " : (testvector_[i]==tolerance_) ? " == " : (testvector_[i]>tolerance_) ? " > " : " " ) << tolerance_ << std::endl;
776  }
777  }
778  }
779  os << std::endl;
780 }
781 
782 template <class ScalarType, class MV, class OP>
784 {
785  os << std::left << std::setw(13) << std::setfill('.');
786  switch (type) {
787  case Passed:
788  os << "Converged";
789  break;
790  case Failed:
791  if (lossDetected_)
792  os << "Unconverged (LoA)";
793  else
794  os << "Unconverged";
795  break;
796  case Undefined:
797  default:
798  os << "**";
799  break;
800  }
801  os << std::left << std::setfill(' ');
802  return;
803 }
804 
805 template <class ScalarType, class MV, class OP>
808 {
809  int i;
810  const MagnitudeType zero = STM::zero ();
811  const MagnitudeType one = STM::one ();
812  const LinearProblem<ScalarType,MV,OP>& lp = iSolver->getProblem();
813  // Compute scaling term (done once for each block that's being solved)
814  if (firstcallCheckStatus_) {
815  //
816  // Get some current solver information.
817  //
818  firstcallCheckStatus_ = false;
819 
820  if (scaletype_== NormOfRHS) {
821  Teuchos::RCP<const MV> rhs = lp.getRHS();
822  numrhs_ = MVT::GetNumberVecs( *rhs );
823  scalevector_.resize( numrhs_ );
824  MVT::MvNorm( *rhs, scalevector_, scalenormtype_ );
825  }
826  else if (scaletype_==NormOfInitRes) {
827  Teuchos::RCP<const MV> init_res = lp.getInitResVec();
828  numrhs_ = MVT::GetNumberVecs( *init_res );
829  scalevector_.resize( numrhs_ );
830  MVT::MvNorm( *init_res, scalevector_, scalenormtype_ );
831  }
832  else if (scaletype_==NormOfPrecInitRes) {
834  numrhs_ = MVT::GetNumberVecs( *init_res );
835  scalevector_.resize( numrhs_ );
836  MVT::MvNorm( *init_res, scalevector_, scalenormtype_ );
837  }
838  else {
839  numrhs_ = MVT::GetNumberVecs( *(lp.getRHS()) );
840  }
841 
842  resvector_.resize( numrhs_ );
843  testvector_.resize( numrhs_ );
844 
845  curLSNum_ = lp.getLSNumber();
846  curLSIdx_ = lp.getLSIndex();
847  curBlksz_ = (int)curLSIdx_.size();
848  int validLS = 0;
849  for (i=0; i<curBlksz_; ++i) {
850  if (curLSIdx_[i] > -1 && curLSIdx_[i] < numrhs_)
851  validLS++;
852  }
853  curNumRHS_ = validLS;
854  //
855  // Initialize the testvector.
856  for (i=0; i<numrhs_; i++) { testvector_[i] = one; }
857 
858  // Return an error if the scaling is zero.
859  if (scalevalue_ == zero) {
860  return Failed;
861  }
862  }
863  return Undefined;
864 }
865 
866 } // end namespace Belos
867 
868 #endif /* BELOS_STATUS_TEST_IMPRESNORM_H */
virtual Teuchos::RCP< const MV > getNativeResiduals(std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > *norms) const =0
Get the residuals native to the solver.
Teuchos::RCP< MV > getSolution()
Returns the current solution estimate that was computed for the most recent residual test...
virtual ~StatusTestImpResNorm()
Destructor (virtual for memory safety).
const std::vector< MagnitudeType > * getTestValue() const
Returns the test value, , computed in most recent call to CheckStatus.
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().
Convergence test using the implicit residual norm(s), with an explicit residual norm(s) check for los...
StatusType checkStatus(Iteration< ScalarType, MV, OP > *iSolver)
Check convergence status: Passed, Failed, or Undefined.
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.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
virtual Teuchos::RCP< MV > getCurrentUpdate() const =0
Get the current update to the linear system.
Declaration of basic traits for the multivector type.
An abstract class of StatusTest for stopping criteria using residual norms.
Teuchos::RCP< const MV > getRHS() const
A pointer to the right-hand side B.
StatusType
Whether the StatusTest wants iteration to stop.
Definition: BelosTypes.hpp:183
const std::vector< MagnitudeType > * getResNormValue() const
Returns the residual norm value, , computed in most recent call to CheckStatus.
Traits class which defines basic operations on multivectors.
int getQuorum() const
Returns the number of residuals that must pass the convergence test before Passed is returned...
Teuchos::ScalarTraits< ScalarType >::magnitudeType MagnitudeType
The type of the magnitude (absolute value) of a ScalarType.
Teuchos::RCP< const MV > getInitResVec() const
A pointer to the initial unpreconditioned residual vector.
int setShowMaxResNormOnly(bool showMaxResNormOnly)
Set whether the only maximum residual norm is displayed when the print() method is called...
const std::vector< MagnitudeType > * getScaledNormValue() const
Returns the scaled norm value, .
A linear system to solve, and its associated information.
Class which describes the linear problem to be solved by the iterative solver.
int getLSNumber() const
The number of linear systems that have been set.
int setQuorum(int quorum)
Sets the number of residuals that must pass the convergence test before Passed is returned...
StatusType firstCallCheckStatusSetup(Iteration< ScalarType, MV, OP > *iSolver)
Call to setup initial scaling vector.
MagnitudeType getCurrTolerance() const
Current convergence tolerance; may be changed to prevent loss of accuracy.
int defineResForm(NormType TypeOfNorm)
Define form of the residual, its norm and optional weighting vector.
virtual const LinearProblem< ScalarType, MV, OP > & getProblem() const =0
Get a constant reference to the linear problem.
Belos::StatusTest abstract class for specifying a residual norm stopping criteria.
bool getLOADetected() const
Returns a boolean indicating a loss of accuracy has been detected in computing the residual...
Teuchos::RCP< const MV > getInitPrecResVec() const
A pointer to the preconditioned initial residual vector.
NormType
The type of vector norm to compute.
Definition: BelosTypes.hpp:97
const std::vector< int > getLSIndex() const
(Zero-based) indices of the linear system(s) currently being solved.
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. ...
StatusType getStatus() const
Return the result of the most recent CheckStatus call.
MagnitudeType getTolerance() const
&quot;Original&quot; convergence tolerance as set by user.
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, define an explicit value.
TypeTo as(const TypeFrom &t)
StatusTestImpResNorm(MagnitudeType Tolerance, int quorum=-1, bool showMaxResNormOnly=false)
Constructor.
int setTolerance(MagnitudeType tolerance)
Set the value of the tolerance.
std::string description() const
Method to return description of the maximum iteration status test.
void printStatus(std::ostream &os, StatusType type) const
Print message for each status specific to this stopping test.
void reset()
Resets the internal configuration to the initial state.
void print(std::ostream &os, int indent=0) const
Output formatted description of stopping test to output stream.
std::vector< int > convIndices()
Returns the vector containing the indices of the residuals that passed the test.
bool getShowMaxResNormOnly()
Returns whether the only maximum residual norm is displayed when the print() method is called...