Stokhos Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
Belos_StatusTest_ImpResNorm_MP_Vector.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_IMPRESNORM_MP_VECTOR_HPP
43#define BELOS_STATUS_TEST_GEN_IMPRESNORM_MP_VECTOR_HPP
44
54#include "BelosStatusTestImpResNorm.hpp"
55
107namespace Belos {
108
109template <class Storage, class MV, class OP>
110class StatusTestImpResNorm<Sacado::MP::Vector<Storage>, MV, OP> :
111 public StatusTestResNorm<Sacado::MP::Vector<Storage>,MV,OP> {
112
113public:
116 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
117
118private:
120
121 typedef Teuchos::ScalarTraits<ScalarType> STS;
122 typedef Teuchos::ScalarTraits<MagnitudeType> STM;
123 typedef MultiVecTraits<ScalarType,MV> MVT;
125
126public:
128
129
142 int quorum = -1,
143 bool showMaxResNormOnly = false);
144
147
149
151
153
159 int defineResForm( NormType TypeOfNorm);
160
162
182 int defineScaleForm( ScaleType TypeOfScaling, NormType TypeOfNorm, MagnitudeType ScaleValue = Teuchos::ScalarTraits<MagnitudeType>::one());
183
185
188 int setTolerance (MagnitudeType tolerance) {
189 tolerance_ = tolerance;
190 return 0;
191 }
192
195 int setQuorum (int quorum) {
196 quorum_ = quorum;
197 return 0;
198 }
199
201 int setShowMaxResNormOnly (bool showMaxResNormOnly) {
202 showMaxResNormOnly_ = showMaxResNormOnly;
203 return 0;
204 }
205
207
209
210
217 StatusType checkStatus(Iteration<ScalarType,MV,OP>* iSolver);
218
220 StatusType getStatus() const {return(status_);}
222
224
225
227 void reset();
228
230
232
233
235 void print(std::ostream& os, int indent = 0) const;
236
238 void printStatus(std::ostream& os, StatusType type) const;
240
242
243
245 Teuchos::RCP<MV> getSolution() { return curSoln_; }
246
249 int getQuorum() const { return quorum_; }
250
252 bool getShowMaxResNormOnly() { return showMaxResNormOnly_; }
253
255 std::vector<int> convIndices() { return ind_; }
256
265 return tolerance_;
266 }
267
276 return currTolerance_;
277 }
278
280 const std::vector<MagnitudeType>* getTestValue() const {return(&testvector_);}
281
283 const std::vector<MagnitudeType>* getResNormValue() const {return(&resvector_);}
284
286 const std::vector<MagnitudeType>* getScaledNormValue() const {return(&scalevector_);}
287
289 bool getLOADetected() const { return lossDetected_; }
290
292 const std::vector<int> getEnsembleIterations() const { return ensemble_iterations; }
294
295
298
304 StatusType firstCallCheckStatusSetup(Iteration<ScalarType,MV,OP>* iSolver);
306
309
311 std::string description() const
312 {
313 std::ostringstream oss;
314 oss << "Belos::StatusTestImpResNorm<>: " << resFormStr();
315 oss << ", tol = " << tolerance_;
316 return oss.str();
317 }
319
320 protected:
321
322 private:
323
325
326
327 std::string resFormStr() const
328 {
329 std::ostringstream oss;
330 oss << "(";
331 oss << ((resnormtype_==OneNorm) ? "1-Norm" : (resnormtype_==TwoNorm) ? "2-Norm" : "Inf-Norm");
332 oss << " Res Vec) ";
333
334 // If there is no residual scaling, return current string.
335 if (scaletype_!=None)
336 {
337 // Insert division sign.
338 oss << "/ ";
339
340 // Determine output string for scaling, if there is any.
341 if (scaletype_==UserProvided)
342 oss << " (User Scale)";
343 else {
344 oss << "(";
345 oss << ((scalenormtype_==OneNorm) ? "1-Norm" : (resnormtype_==TwoNorm) ? "2-Norm" : "Inf-Norm");
346 if (scaletype_==NormOfInitRes)
347 oss << " Res0";
348 else if (scaletype_==NormOfPrecInitRes)
349 oss << " Prec Res0";
350 else
351 oss << " RHS ";
352 oss << ")";
353 }
354 }
355
356 return oss.str();
357 }
358
360
361
364
367
370
372 NormType resnormtype_;
373
375 ScaleType scaletype_;
376
379
382
384 std::vector<MagnitudeType> scalevector_;
385
387 std::vector<MagnitudeType> resvector_;
388
390 std::vector<MagnitudeType> testvector_;
391
393 Teuchos::RCP<MV> curSoln_;
394
396 std::vector<int> ind_;
397
399 StatusType status_;
400
403
406
408 std::vector<int> curLSIdx_;
409
412
415
418
421
424
427
429 std::vector<int> ensemble_iterations;
430
432
433};
434
435template <class StorageType, class MV, class OP>
436StatusTestImpResNorm<Sacado::MP::Vector<StorageType>,MV,OP>::
437StatusTestImpResNorm (MagnitudeType Tolerance, int quorum, bool showMaxResNormOnly)
438 : tolerance_(Tolerance),
439 currTolerance_(Tolerance),
440 quorum_(quorum),
441 showMaxResNormOnly_(showMaxResNormOnly),
442 resnormtype_(TwoNorm),
443 scaletype_(NormOfInitRes),
444 scalenormtype_(TwoNorm),
445 scalevalue_(Teuchos::ScalarTraits<MagnitudeType>::one ()),
446 status_(Undefined),
447 curBlksz_(0),
448 curNumRHS_(0),
449 curLSNum_(0),
450 numrhs_(0),
451 firstcallCheckStatus_(true),
452 firstcallDefineResForm_(true),
453 firstcallDefineScaleForm_(true),
454 lossDetected_(false),
455 ensemble_iterations(StorageType::static_size, 0)
456{
457 // This constructor will compute the residual ||r_i||/||r0_i|| <= tolerance using the 2-norm of
458 // the implicit residual vector.
459}
460
461template <class StorageType, class MV, class OP>
462StatusTestImpResNorm<Sacado::MP::Vector<StorageType>,MV,OP>::~StatusTestImpResNorm()
463{}
464
465template <class StorageType, class MV, class OP>
466void StatusTestImpResNorm<Sacado::MP::Vector<StorageType>,MV,OP>::reset()
467{
468 status_ = Undefined;
469 curBlksz_ = 0;
470 curLSNum_ = 0;
471 curLSIdx_.resize(0);
472 numrhs_ = 0;
473 ind_.resize(0);
474 currTolerance_ = tolerance_;
475 firstcallCheckStatus_ = true;
476 lossDetected_ = false;
477 curSoln_ = Teuchos::null;
478 ensemble_iterations = std::vector<int>(StorageType::static_size, 0);
479}
480
481template <class StorageType, class MV, class OP>
482int StatusTestImpResNorm<Sacado::MP::Vector<StorageType>,MV,OP>::defineResForm( NormType TypeOfNorm )
483{
484 TEUCHOS_TEST_FOR_EXCEPTION(firstcallDefineResForm_==false,StatusTestError,
485 "StatusTestResNorm::defineResForm(): The residual form has already been defined.");
486 firstcallDefineResForm_ = false;
487
488 resnormtype_ = TypeOfNorm;
489
490 return(0);
491}
492
493template <class StorageType, class MV, class OP>
494int StatusTestImpResNorm<Sacado::MP::Vector<StorageType>,MV,OP>::defineScaleForm(ScaleType TypeOfScaling, NormType TypeOfNorm,
495 MagnitudeType ScaleValue )
496{
497 TEUCHOS_TEST_FOR_EXCEPTION(firstcallDefineScaleForm_==false,StatusTestError,
498 "StatusTestResNorm::defineScaleForm(): The scaling type has already been defined.");
499 firstcallDefineScaleForm_ = false;
500
501 scaletype_ = TypeOfScaling;
502 scalenormtype_ = TypeOfNorm;
503 scalevalue_ = ScaleValue;
504
505 return(0);
506}
507
508template <class StorageType, class MV, class OP>
509StatusType StatusTestImpResNorm<Sacado::MP::Vector<StorageType>,MV,OP>::
510checkStatus (Iteration<ScalarType,MV,OP>* iSolver)
511{
512 //std::cout << "check status start" << std::endl;
513 using Teuchos::as;
514 using Teuchos::RCP;
515
516 const MagnitudeType zero = STM::zero ();
517 const MagnitudeType one = STM::one ();
518 const LinearProblem<ScalarType,MV,OP>& lp = iSolver->getProblem ();
519
520 // Compute scaling term (done once for each block that's being solved)
521 if (firstcallCheckStatus_) {
522 StatusType status = firstCallCheckStatusSetup (iSolver);
523 if (status == Failed) {
524 status_ = Failed;
525 return status_;
526 }
527 }
528
529 // mfh 23 Apr 2012: I don't know exactly what this code does. It
530 // has something to do with picking the block of right-hand sides
531 // which we're currently checking.
532 if (curLSNum_ != lp.getLSNumber ()) {
533 //
534 // We have moved on to the next rhs block
535 //
536 curLSNum_ = lp.getLSNumber();
537 curLSIdx_ = lp.getLSIndex();
538 curBlksz_ = (int)curLSIdx_.size();
539 int validLS = 0;
540 for (int i=0; i<curBlksz_; ++i) {
541 if (curLSIdx_[i] > -1 && curLSIdx_[i] < numrhs_)
542 validLS++;
543 }
544 curNumRHS_ = validLS;
545 curSoln_ = Teuchos::null;
546 } else {
547 //
548 // We are in the same rhs block, return if we are converged
549 //
550 if (status_ == Passed) {
551 //std::cout << "check status end 2" << std::endl;
552 return status_;
553 }
554 }
555
556 //
557 // Get the "native" residual norms from the solver for this block of
558 // right-hand sides. If the solver's getNativeResiduals() method
559 // actually returns a multivector, compute the norms of the columns
560 // of the multivector explicitly. Otherwise, we assume that
561 // resvector_ contains the norms.
562 //
563 // Note that "compute the norms explicitly" doesn't necessarily mean
564 // the "explicit" residual norms (in the sense discussed in this
565 // class' documentation). These are just some vectors returned by
566 // the solver. Some Krylov methods, like CG, compute a residual
567 // vector "recursively." This is an "implicit residual" in the
568 // sense of this class' documentation. It equals the explicit
569 // residual in exact arithmetic, but due to rounding error, it is
570 // usually different than the explicit residual.
571 //
572 // FIXME (mfh 23 Apr 2012) This method does _not_ respect the
573 // OrthoManager used by the solver.
574 //
575 std::vector<MagnitudeType> tmp_resvector( curBlksz_ );
576 RCP<const MV> residMV = iSolver->getNativeResiduals (&tmp_resvector);
577 if (! residMV.is_null ()) {
578 // We got a multivector back. Compute the norms explicitly.
579 tmp_resvector.resize (MVT::GetNumberVecs (*residMV));
580 MVT::MvNorm (*residMV, tmp_resvector, resnormtype_);
581 typename std::vector<int>::iterator p = curLSIdx_.begin();
582 for (int i=0; p<curLSIdx_.end(); ++p, ++i) {
583 // Check if this index is valid
584 if (*p != -1) {
585 resvector_[*p] = tmp_resvector[i];
586 }
587 }
588 } else {
589 typename std::vector<int>::iterator p = curLSIdx_.begin();
590 for (int i=0; p<curLSIdx_.end(); ++p, ++i) {
591 // Check if this index is valid
592 if (*p != -1) {
593 resvector_[*p] = tmp_resvector[i];
594 }
595 }
596 }
597 //
598 // Scale the unscaled residual norms we computed or obtained above.
599 //
600 if (scalevector_.size () > 0) {
601 // There are per-vector scaling factors to apply.
602 typename std::vector<int>::iterator p = curLSIdx_.begin();
603 for (; p<curLSIdx_.end(); ++p) {
604 // Check if this index is valid
605 if (*p != -1) {
606 // Scale the vector accordingly
607 testvector_[ *p ] = resvector_[ *p ] / scalevalue_;
608 mask_assign(scalevector_[ *p ]!= zero, testvector_[ *p ]) /= scalevector_[ *p ];
609 }
610 }
611 }
612 else { // There are no per-vector scaling factors.
613 typename std::vector<int>::iterator p = curLSIdx_.begin();
614 for (; p<curLSIdx_.end(); ++p) {
615 // Check if this index is valid
616 if (*p != -1) {
617 testvector_[ *p ] = resvector_[ *p ] / scalevalue_;
618 }
619 }
620 }
621
622 // Count how many scaled residual norms (in testvector_) pass, using
623 // the current tolerance (currTolerance_) rather than the original
624 // tolerance (tolerance_). If at least quorum_ of them pass, we
625 // have a quorum for the whole test to pass.
626 //
627 // We also check here whether any of the scaled residual norms is
628 // NaN, and throw an exception in that case.
629 int have = 0;
630 ind_.resize( curLSIdx_.size() );
631 std::vector<int> lclInd( curLSIdx_.size() );
632 typename std::vector<int>::iterator p = curLSIdx_.begin();
633 for (int i=0; p<curLSIdx_.end(); ++p, ++i) {
634 // Check if this index is valid
635 if (*p != -1) {
636 // Check if any of the residuals are larger than the tolerance.
637 const int ensemble_size = StorageType::static_size;
638 bool all_converged = true;
639 for (int ii=0; ii<ensemble_size; ++ii) {
640 if (testvector_[ *p ].coeff(ii) > currTolerance_.coeff(ii)) {
641 ++ensemble_iterations[ii];
642 all_converged = false;
643 }
644 else if (!(testvector_[ *p ].coeff(ii) <= currTolerance_.coeff(ii))) {
645 // Throw an std::exception if the current residual norm is
646 // NaN. We know that it's NaN because it is not less than,
647 // equal to, or greater than the current tolerance. This is
648 // only possible if either the residual norm or the current
649 // tolerance is NaN; we assume the former. We also mark the
650 // test as failed, in case you want to catch the exception.
651 status_ = Failed;
652 TEUCHOS_TEST_FOR_EXCEPTION(true, StatusTestError, "Belos::"
653 "StatusTestImpResNorm::checkStatus(): One or more of the current "
654 "implicit residual norms is NaN.");
655 }
656 }
657 if (all_converged) {
658 ind_[have] = *p;
659 have++;
660 }
661 }
662 }
663 // "have" is the number of residual norms that passed.
664 ind_.resize(have);
665 lclInd.resize(have);
666
667 // Now check the exact residuals
668 if (have) { // At least one residual norm has converged.
669 //
670 // Compute the explicit residual norm(s) from the current solution update.
671 //
672 RCP<MV> cur_update = iSolver->getCurrentUpdate ();
673 curSoln_ = lp.updateSolution (cur_update);
674 RCP<MV> cur_res = MVT::Clone (*curSoln_, MVT::GetNumberVecs (*curSoln_));
675 lp.computeCurrResVec (&*cur_res, &*curSoln_);
676 tmp_resvector.resize (MVT::GetNumberVecs (*cur_res));
677 std::vector<MagnitudeType> tmp_testvector (have);
678
679 MVT::MvNorm (*cur_res, tmp_resvector, resnormtype_);
680
681 // Scale the explicit residual norm(s), just like the implicit norm(s).
682 if ( scalevector_.size() > 0 ) {
683 for (int i=0; i<have; ++i) {
684 // Scale the vector accordingly
685 tmp_testvector[ i ] = tmp_resvector[ lclInd[i] ] / scalevalue_;
686 mask_assign(scalevector_[ ind_[i] ]!=zero,tmp_testvector[ i ]) /= scalevector_[ ind_[i] ];
687 }
688 }
689 else {
690 for (int i=0; i<have; ++i) {
691 tmp_testvector[ i ] = tmp_resvector[ lclInd[i] ] / scalevalue_;
692 }
693 }
694
695 //
696 // Check whether the explicit residual norms also pass the
697 // convergence test. If not, check whether we want to try
698 // iterating a little more to force both implicit and explicit
699 // residual norms to pass.
700 //
701 int have2 = 0;
702 for (int i = 0; i < have; ++i) {
703 // testvector_ contains the implicit (i.e., recursive, computed
704 // by the algorithm) (possibly scaled) residuals. All of these
705 // pass the convergence test.
706 //
707 // tmp_testvector contains the explicit (i.e., ||B-AX||)
708 // (possibly scaled) residuals. We're checking whether these
709 // pass as well. The explicit residual norms only have to meet
710 // the _original_ tolerance (tolerance_), not the current
711 // tolerance (currTolerance_).
712
713
714 // Absolute difference between the current explicit and
715 // implicit residual norm.
716 const MagnitudeType diff = STM::magnitude (testvector_[ind_[i]] - tmp_testvector[i]);
717
718 // Check if any of the residuals are larger than the tolerance.
719 const int ensemble_size = StorageType::static_size;
720 typedef typename StorageType::value_type value_type;
721 bool all_converged = true;
722 {
723 for (int ii=0; ii<ensemble_size; ++ii) {
724 if (!(tmp_testvector[i].coeff(ii) <= tolerance_.coeff(ii))) {
725 if (diff.coeff(ii) > currTolerance_.coeff(ii)) {
726 lossDetected_ = true;
727 }
728 else {
729 const value_type onePointFive = as<value_type>(3) / as<value_type> (2);
730 const value_type oneTenth = as<value_type>(1) / as<value_type> (10);
731
732 currTolerance_.fastAccessCoeff(ii) = currTolerance_.coeff(ii) - onePointFive * diff.coeff(ii);
733 while (currTolerance_.coeff(ii) < as<value_type>(0)) {
734 currTolerance_.fastAccessCoeff(ii) += oneTenth * diff.coeff(ii);
735 }
736 all_converged = false;
737 }
738 }
739 }
740 }
741 if (all_converged) {
742 ind_[have2] = ind_[i];
743 have2++; // This right-hand side has converged.
744 }
745 }
746 have = have2;
747 ind_.resize(have);
748 }
749
750 // Check whether we've met the quorum of vectors necessary for the
751 // whole test to pass.
752 int need = (quorum_ == -1) ? curNumRHS_: quorum_;
753 status_ = (have >= need) ? Passed : Failed;
754
755
756 //std::cout << "check status end default" << std::endl;
757 // Return the current status
758 return status_;
759}
760
761template <class StorageType, class MV, class OP>
762void StatusTestImpResNorm<Sacado::MP::Vector<StorageType>,MV,OP>::print(std::ostream& os, int indent) const
763{
764 for (int j = 0; j < indent; j ++)
765 os << ' ';
766 printStatus(os, status_);
767 os << resFormStr();
768 if (status_==Undefined)
769 os << ", tol = " << tolerance_ << std::endl;
770 else {
771 os << std::endl;
772 if(showMaxResNormOnly_ && curBlksz_ > 1) {
773 const MagnitudeType maxRelRes = *std::max_element(
774 testvector_.begin()+curLSIdx_[0],testvector_.begin()+curLSIdx_[curBlksz_-1]
775 );
776 for (int j = 0; j < indent + 13; j ++)
777 os << ' ';
778 os << "max{residual["<<curLSIdx_[0]<<"..."<<curLSIdx_[curBlksz_-1]<<"]} = " << maxRelRes
779 << ( maxRelRes <= tolerance_ ? " <= " : " > " ) << tolerance_ << std::endl;
780 }
781 else {
782 for ( int i=0; i<numrhs_; i++ ) {
783 for (int j = 0; j < indent + 13; j ++)
784 os << ' ';
785 os << "residual [ " << i << " ] = " << testvector_[ i ];
786 os << ((testvector_[i]<tolerance_) ? " < " : (testvector_[i]==tolerance_) ? " == " : (testvector_[i]>tolerance_) ? " > " : " " ) << tolerance_ << std::endl;
787 }
788 }
789 }
790 os << std::endl;
791}
792
793template <class StorageType, class MV, class OP>
794void StatusTestImpResNorm<Sacado::MP::Vector<StorageType>,MV,OP>::printStatus(std::ostream& os, StatusType type) const
795{
796 os << std::left << std::setw(13) << std::setfill('.');
797 switch (type) {
798 case Passed:
799 os << "Converged";
800 break;
801 case Failed:
802 if (lossDetected_)
803 os << "Unconverged (LoA)";
804 else
805 os << "Unconverged";
806 break;
807 case Undefined:
808 default:
809 os << "**";
810 break;
811 }
812 os << std::left << std::setfill(' ');
813 return;
814}
815
816template <class StorageType, class MV, class OP>
817StatusType StatusTestImpResNorm<Sacado::MP::Vector<StorageType>,MV,OP>::
818firstCallCheckStatusSetup (Iteration<ScalarType,MV,OP>* iSolver)
819{
820 int i;
821 const MagnitudeType zero = STM::zero ();
822 const MagnitudeType one = STM::one ();
823 const LinearProblem<ScalarType,MV,OP>& lp = iSolver->getProblem();
824 // Compute scaling term (done once for each block that's being solved)
825 if (firstcallCheckStatus_) {
826 //
827 // Get some current solver information.
828 //
829 firstcallCheckStatus_ = false;
830
831 if (scaletype_== NormOfRHS) {
832 Teuchos::RCP<const MV> rhs = lp.getRHS();
833 numrhs_ = MVT::GetNumberVecs( *rhs );
834 scalevector_.resize( numrhs_ );
835 MVT::MvNorm( *rhs, scalevector_, scalenormtype_ );
836 }
837 else if (scaletype_==NormOfInitRes) {
838 Teuchos::RCP<const MV> init_res = lp.getInitResVec();
839 numrhs_ = MVT::GetNumberVecs( *init_res );
840 scalevector_.resize( numrhs_ );
841 MVT::MvNorm( *init_res, scalevector_, scalenormtype_ );
842 }
843 else if (scaletype_==NormOfPrecInitRes) {
844 Teuchos::RCP<const MV> init_res = lp.getInitPrecResVec();
845 numrhs_ = MVT::GetNumberVecs( *init_res );
846 scalevector_.resize( numrhs_ );
847 MVT::MvNorm( *init_res, scalevector_, scalenormtype_ );
848 }
849 else {
850 numrhs_ = MVT::GetNumberVecs( *(lp.getRHS()) );
851 }
852
853 resvector_.resize( numrhs_ );
854 testvector_.resize( numrhs_ );
855
856 curLSNum_ = lp.getLSNumber();
857 curLSIdx_ = lp.getLSIndex();
858 curBlksz_ = (int)curLSIdx_.size();
859 int validLS = 0;
860 for (i=0; i<curBlksz_; ++i) {
861 if (curLSIdx_[i] > -1 && curLSIdx_[i] < numrhs_)
862 validLS++;
863 }
864 curNumRHS_ = validLS;
865 //
866 // Initialize the testvector.
867 for (i=0; i<numrhs_; i++) { testvector_[i] = one; }
868
869 // Return an error if the scaling is zero.
870 if (scalevalue_ == zero) {
871 return Failed;
872 }
873 }
874 return Undefined;
875}
876
877} // end namespace Belos
878
879#endif /* BELOS_STATUS_TEST_GEN_IMPRESNORM_MP_VECTOR_HPP */
KOKKOS_INLINE_FUNCTION MaskedAssign< scalar > mask_assign(bool b, scalar *s)
const std::vector< MagnitudeType > * getResNormValue() const
Returns the residual norm value, , computed in most recent call to CheckStatus.
NormType scalenormtype_
Type of norm to use on the scaling (OneNorm, TwoNorm, or InfNorm)
void reset()
Resets the internal configuration to the initial state.
Teuchos::RCP< MV > getSolution()
Returns the current solution estimate that was computed for the most recent residual test.
int setShowMaxResNormOnly(bool showMaxResNormOnly)
Set whether the only maximum residual norm is displayed when the print() method is called.
Teuchos::ScalarTraits< ScalarType >::magnitudeType MagnitudeType
The type of the magnitude (absolute value) of a ScalarType.
NormType resnormtype_
Type of norm to use on residual (OneNorm, TwoNorm, or InfNorm).
bool getShowMaxResNormOnly()
Returns whether the only maximum residual norm is displayed when the print() method is called.
std::vector< int > ind_
Vector containing the indices for the vectors that passed the test.
MagnitudeType getTolerance() const
"Original" convergence tolerance as set by user.
int quorum_
Number of residuals that must pass the convergence test before Passed is returned.
std::vector< int > ensemble_iterations
The number of iterations at which point each ensemble component converges.
int defineResForm(NormType TypeOfNorm)
Define form of the residual, its norm and optional weighting vector.
void printStatus(std::ostream &os, StatusType type) const
Print message for each status specific to this stopping test.
StatusType firstCallCheckStatusSetup(Iteration< ScalarType, MV, OP > *iSolver)
Call to setup initial scaling vector.
StatusType checkStatus(Iteration< ScalarType, MV, OP > *iSolver)
Check convergence status: Passed, Failed, or Undefined.
std::string description() const
Method to return description of the maximum iteration status test
std::vector< MagnitudeType > testvector_
Test vector = resvector_ / scalevector_.
const std::vector< MagnitudeType > * getTestValue() const
Returns the test value, , computed in most recent call to CheckStatus.
ScaleType scaletype_
Type of scaling to use (Norm of RHS, Norm of Initial Residual, None or User provided)
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.
StatusType getStatus() const
Return the result of the most recent CheckStatus call.
const std::vector< int > getEnsembleIterations() const
Returns number of ensemble iterations.
virtual ~StatusTestImpResNorm()
Destructor (virtual for memory safety).
bool showMaxResNormOnly_
Determines if the entries for all of the residuals are shown or just the max.
StatusTestImpResNorm(MagnitudeType Tolerance, int quorum=-1, bool showMaxResNormOnly=false)
Constructor.
std::vector< int > convIndices()
Returns the vector containing the indices of the residuals that passed the test.
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,...
MagnitudeType getCurrTolerance() const
Current convergence tolerance; may be changed to prevent loss of accuracy.
std::vector< int > curLSIdx_
The indices of the current number of right-hand sides being solved for.
const std::vector< MagnitudeType > * getScaledNormValue() const
Returns the scaled norm value, .
int curLSNum_
The current number of linear systems that have been loaded into the linear problem.
Convergence test using the implicit residual norm(s), with an explicit residual norm(s) check for los...