42 #ifndef BELOS_GCRODR_ITER_HPP
43 #define BELOS_GCRODR_ITER_HPP
87 template <
class ScalarType,
class MV>
113 U(Teuchos::null),
C(Teuchos::null),
114 H(Teuchos::null),
B(Teuchos::null)
153 template<
class ScalarType,
class MV,
class OP>
295 if (!initialized_)
return 0;
328 TEUCHOS_TEST_FOR_EXCEPTION(blockSize!=1,std::invalid_argument,
"Belos::GCRODRIter::setBlockSize(): Cannot use a block size that is not one.");
332 void setSize(
int recycledBlocks,
int numBlocks ) {
334 if ( (recycledBlocks_ != recycledBlocks) || (numBlocks_ != numBlocks) ) {
335 recycledBlocks_ = recycledBlocks;
336 numBlocks_ = numBlocks;
412 template<
class ScalarType,
class MV,
class OP>
418 lp_(problem), om_(printer), stest_(tester), ortho_(ortho) {
421 initialized_ =
false;
432 int nb = Teuchos::getParameter<int>(params,
"Num Blocks");
434 TEUCHOS_TEST_FOR_EXCEPTION(!params.
isParameter(
"Recycled Blocks"), std::invalid_argument,
"Belos::GCRODRIter::constructor: mandatory parameter \"Recycled Blocks\" is not specified.");
435 int rb = Teuchos::getParameter<int>(params,
"Recycled Blocks");
437 TEUCHOS_TEST_FOR_EXCEPTION(nb <= 0, std::invalid_argument,
"Belos::GCRODRIter() was passed a non-positive argument for \"Num Blocks\".");
438 TEUCHOS_TEST_FOR_EXCEPTION(rb >= nb, std::invalid_argument,
"Belos::GCRODRIter() the number of recycled blocks is larger than the allowable subspace.");
441 recycledBlocks_ = rb;
452 template <
class ScalarType,
class MV,
class OP>
460 return currentUpdate;
465 currentUpdate = MVT::Clone( *V_, 1 );
479 std::vector<int> index(curDim_);
480 for (
int i=0; i<curDim_; i++ ) index[i] = i;
482 MVT::MvTimesMatAddMv( one, *Vjp1, y, zero, *currentUpdate );
486 if (U_ != Teuchos::null) {
490 MVT::MvTimesMatAddMv( -one, *U_, z, one, *currentUpdate );
493 return currentUpdate;
500 template <
class ScalarType,
class MV,
class OP>
505 if ( norms && (
int)norms->size()==0 )
510 (*norms)[0] = blas.
NRM2( 1, &z_(curDim_), 1);
512 return Teuchos::null;
519 template <
class ScalarType,
class MV,
class OP>
522 if (newstate.
V != Teuchos::null && newstate.
H != Teuchos::null) {
523 curDim_ = newstate.
curDim;
531 TEUCHOS_TEST_FOR_EXCEPTION(newstate.
V == Teuchos::null,std::invalid_argument,
"Belos::GCRODRIter::initialize(): GCRODRIterState does not have V initialized.");
532 TEUCHOS_TEST_FOR_EXCEPTION(newstate.
H == Teuchos::null,std::invalid_argument,
"Belos::GCRODRIter::initialize(): GCRODRIterState does not have H initialized.");
543 template <
class ScalarType,
class MV,
class OP>
549 setSize( recycledBlocks_, numBlocks_ );
553 std::vector<int> curind(1);
560 Vnext = MVT::CloneViewNonConst(*V_,curind);
565 int rank = ortho_->normalize( *Vnext, z0 );
570 std::vector<int> prevind(numBlocks_+1);
577 if (U_ == Teuchos::null) {
578 while (stest_->checkStatus(
this) !=
Passed && curDim_+1 <= numBlocks_) {
580 int lclDim = curDim_ + 1;
584 Vnext = MVT::CloneViewNonConst(*V_,curind);
588 Vprev = MVT::CloneView(*V_,curind);
591 lp_->apply(*Vprev,*Vnext);
596 prevind.resize(lclDim);
597 for (
int i=0; i<lclDim; i++) { prevind[i] = i; }
598 Vprev = MVT::CloneView(*V_,prevind);
612 rank = ortho_->projectAndNormalize(*Vnext,AsubH,subR,AVprev);
629 while (stest_->checkStatus(
this) !=
Passed && curDim_+1 <= numBlocks_) {
631 int lclDim = curDim_ + 1;
635 Vnext = MVT::CloneViewNonConst(*V_,curind);
640 Vprev = MVT::CloneView(*V_,curind);
643 lp_->apply(*Vprev,*Vnext);
644 Vprev = Teuchos::null;
654 ortho_->project( *Vnext, AsubB, C );
658 prevind.resize(lclDim);
659 for (
int i=0; i<lclDim; i++) { prevind[i] = i; }
660 Vprev = MVT::CloneView(*V_,prevind);
672 rank = ortho_->projectAndNormalize(*Vnext,AsubH,subR,AVprev);
693 template<
class ScalarType,
class MV,
class OP>
702 int curDim = curDim_;
703 if ( (dim >= curDim_) && (dim < getMaxSubspaceDim()) )
713 for (i=0; i<curDim; i++) {
717 blas.
ROT( 1, &R_(i,curDim), 1, &R_(i+1, curDim), 1, &cs_[i], &sn_[i] );
722 blas.
ROTG( &R_(curDim,curDim), &R_(curDim+1,curDim), &cs_[curDim], &sn_[curDim] );
723 R_(curDim+1,curDim) = zero;
727 blas.
ROT( 1, &z_(curDim), 1, &z_(curDim+1), 1, &cs_[curDim], &sn_[curDim] );