10 #ifndef BELOS_GCRODR_ITER_HPP
11 #define BELOS_GCRODR_ITER_HPP
55 template <
class ScalarType,
class MV>
81 U(Teuchos::null),
C(Teuchos::null),
82 H(Teuchos::null),
B(Teuchos::null)
121 template<
class ScalarType,
class MV,
class OP>
263 if (!initialized_)
return 0;
296 TEUCHOS_TEST_FOR_EXCEPTION(blockSize!=1,std::invalid_argument,
"Belos::GCRODRIter::setBlockSize(): Cannot use a block size that is not one.");
300 void setSize(
int recycledBlocks,
int numBlocks ) {
302 if ( (recycledBlocks_ != recycledBlocks) || (numBlocks_ != numBlocks) ) {
303 recycledBlocks_ = recycledBlocks;
304 numBlocks_ = numBlocks;
380 template<
class ScalarType,
class MV,
class OP>
386 lp_(problem), om_(printer), stest_(tester), ortho_(ortho) {
389 initialized_ =
false;
400 int nb = Teuchos::getParameter<int>(params,
"Num Blocks");
402 TEUCHOS_TEST_FOR_EXCEPTION(!params.isParameter(
"Recycled Blocks"), std::invalid_argument,
"Belos::GCRODRIter::constructor: mandatory parameter \"Recycled Blocks\" is not specified.");
403 int rb = Teuchos::getParameter<int>(params,
"Recycled Blocks");
405 TEUCHOS_TEST_FOR_EXCEPTION(nb <= 0, std::invalid_argument,
"Belos::GCRODRIter() was passed a non-positive argument for \"Num Blocks\".");
406 TEUCHOS_TEST_FOR_EXCEPTION(rb >= nb, std::invalid_argument,
"Belos::GCRODRIter() the number of recycled blocks is larger than the allowable subspace.");
409 recycledBlocks_ = rb;
420 template <
class ScalarType,
class MV,
class OP>
428 return currentUpdate;
433 currentUpdate = MVT::Clone( *V_, 1 );
447 std::vector<int> index(curDim_);
448 for (
int i=0; i<curDim_; i++ ) index[i] = i;
450 MVT::MvTimesMatAddMv( one, *Vjp1, y, zero, *currentUpdate );
454 if (U_ != Teuchos::null) {
458 MVT::MvTimesMatAddMv( -one, *U_, z, one, *currentUpdate );
461 return currentUpdate;
468 template <
class ScalarType,
class MV,
class OP>
473 if ( norms && (
int)norms->size()==0 )
478 (*norms)[0] = blas.
NRM2( 1, &z_(curDim_), 1);
480 return Teuchos::null;
487 template <
class ScalarType,
class MV,
class OP>
490 if (newstate.
V != Teuchos::null && newstate.
H != Teuchos::null) {
491 curDim_ = newstate.
curDim;
499 TEUCHOS_TEST_FOR_EXCEPTION(newstate.
V == Teuchos::null,std::invalid_argument,
"Belos::GCRODRIter::initialize(): GCRODRIterState does not have V initialized.");
500 TEUCHOS_TEST_FOR_EXCEPTION(newstate.
H == Teuchos::null,std::invalid_argument,
"Belos::GCRODRIter::initialize(): GCRODRIterState does not have H initialized.");
511 template <
class ScalarType,
class MV,
class OP>
517 setSize( recycledBlocks_, numBlocks_ );
521 std::vector<int> curind(1);
528 Vnext = MVT::CloneViewNonConst(*V_,curind);
533 int rank = ortho_->normalize( *Vnext, z0 );
538 std::vector<int> prevind(numBlocks_+1);
545 if (U_ == Teuchos::null) {
546 while (stest_->checkStatus(
this) !=
Passed && curDim_+1 <= numBlocks_) {
548 int lclDim = curDim_ + 1;
552 Vnext = MVT::CloneViewNonConst(*V_,curind);
556 Vprev = MVT::CloneView(*V_,curind);
559 lp_->apply(*Vprev,*Vnext);
564 prevind.resize(lclDim);
565 for (
int i=0; i<lclDim; i++) { prevind[i] = i; }
566 Vprev = MVT::CloneView(*V_,prevind);
580 rank = ortho_->projectAndNormalize(*Vnext,AsubH,subR,AVprev);
597 while (stest_->checkStatus(
this) !=
Passed && curDim_+1 <= numBlocks_) {
599 int lclDim = curDim_ + 1;
603 Vnext = MVT::CloneViewNonConst(*V_,curind);
608 Vprev = MVT::CloneView(*V_,curind);
611 lp_->apply(*Vprev,*Vnext);
612 Vprev = Teuchos::null;
622 ortho_->project( *Vnext, AsubB, C );
626 prevind.resize(lclDim);
627 for (
int i=0; i<lclDim; i++) { prevind[i] = i; }
628 Vprev = MVT::CloneView(*V_,prevind);
640 rank = ortho_->projectAndNormalize(*Vnext,AsubH,subR,AVprev);
661 template<
class ScalarType,
class MV,
class OP>
670 int curDim = curDim_;
671 if ( (dim >= curDim_) && (dim < getMaxSubspaceDim()) )
681 for (i=0; i<curDim; i++) {
685 blas.
ROT( 1, &R_(i,curDim), 1, &R_(i+1, curDim), 1, &cs_[i], &sn_[i] );
690 blas.
ROTG( &R_(curDim,curDim), &R_(curDim+1,curDim), &cs_[curDim], &sn_[curDim] );
691 R_(curDim+1,curDim) = zero;
695 blas.
ROT( 1, &z_(curDim), 1, &z_(curDim+1), 1, &cs_[curDim], &sn_[curDim] );
ScalarType * values() const
Collection of types and exceptions used within the Belos solvers.
void TRSM(ESide side, EUplo uplo, ETransp transa, EDiag diag, const OrdinalType &m, const OrdinalType &n, const alpha_type alpha, const A_type *A, const OrdinalType &lda, ScalarType *B, const OrdinalType &ldb) const
Teuchos::RCP< const MV > getNativeResiduals(std::vector< MagnitudeType > *norms) const
Get the norms of the residuals native to the solver.
Belos's basic output manager for sending information of select verbosity levels to the appropriate ou...
int getBlockSize() const
Get the blocksize to be used by the iterative solver in solving this linear problem.
const LinearProblem< ScalarType, MV, OP > & getProblem() const
Get a constant reference to the linear problem.
Array< T > & append(const T &x)
Class which manages the output and verbosity of the Belos solvers.
int shapeUninitialized(OrdinalType numRows, OrdinalType numCols)
void setSize(int recycledBlocks, int numBlocks)
Set the maximum number of blocks used by the iterative solver and the number of recycled vectors...
void updateLSQR(int dim=-1)
Method for updating QR factorization of upper Hessenberg matrix.
void ROT(const OrdinalType &n, ScalarType *dx, const OrdinalType &incx, ScalarType *dy, const OrdinalType &incy, MagnitudeType *c, ScalarType *s) const
int getRecycledBlocks() const
Get the maximum number of recycled blocks used by the iterative solver in solving this linear problem...
Pure virtual base class for defining the status testing capabilities of Belos.
int multiply(ETransp transa, ETransp transb, ScalarType alpha, const SerialDenseMatrix< OrdinalType, ScalarType > &A, const SerialDenseMatrix< OrdinalType, ScalarType > &B, ScalarType beta)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Declaration of basic traits for the multivector type.
ScalarTraits< ScalarType >::magnitudeType NRM2(const OrdinalType &n, const ScalarType *x, const OrdinalType &incx) const
This class implements the GCRODR iteration, where a single-std::vector Krylov subspace is constructed...
int curDim
The current dimension of the reduction.
A pure virtual class for defining the status tests for the Belos iterative solvers.
Class which defines basic traits for the operator type.
GCRODRIterOrthoFailure(const std::string &what_arg)
void iterate()
This method performs block Gmres iterations until the status test indicates the need to stop or an er...
Traits class which defines basic operations on multivectors.
virtual ~GCRODRIter()
Destructor.
bool isParameter(const std::string &name) const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::RCP< MV > V
The current Krylov basis.
void setRecycledBlocks(int recycledBlocks)
Set the maximum number of recycled blocks used by the iterative solver.
Teuchos::RCP< MV > U
The recycled subspace and its projection.
GCRODRIterInitFailure(const std::string &what_arg)
int getCurSubspaceDim() const
Get the dimension of the search subspace used to generate the current solution to the linear problem...
void resetNumIters(int iter=0)
Reset the iteration count.
GCRODRIterInitFailure is thrown when the GCRODRIter object is unable to generate an initial iterate i...
A linear system to solve, and its associated information.
Class which describes the linear problem to be solved by the iterative solver.
GCRODRIterOrthoFailure is thrown when the GCRODRIter object is unable to compute independent directio...
void initialize()
Initialize the solver with empty data. Calling this method will result in error, as GCRODRIter must b...
Structure to contain pointers to GCRODRIter state variables.
OperatorTraits< ScalarType, MV, OP > OPT
int getNumIters() const
Get the current iteration count.
void ROTG(ScalarType *da, ScalarType *db, rotg_c_type *c, ScalarType *s) const
Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > B
The projection of the Krylov subspace against the recycled subspace.
Teuchos::ScalarTraits< ScalarType > SCT
Teuchos::RCP< MV > getCurrentUpdate() const
Get the current update to the linear system.
GCRODRIterState< ScalarType, MV > getState() const
Get the current state of the linear solver.
void setNumBlocks(int numBlocks)
Set the maximum number of blocks used by the iterative solver.
int getMaxSubspaceDim() const
Get the maximum dimension allocated for the search subspace.
void setBlockSize(int blockSize)
Set the blocksize.
Class which defines basic traits for the operator type.
SCT::magnitudeType MagnitudeType
Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > H
The current Hessenberg matrix.
Parent class to all Belos exceptions.
Belos's templated virtual class for providing routines for orthogonalization and orthonormzalition of...
GCRODRIter(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem, const Teuchos::RCP< OutputManager< ScalarType > > &printer, const Teuchos::RCP< StatusTest< ScalarType, MV, OP > > &tester, const Teuchos::RCP< MatOrthoManager< ScalarType, MV, OP > > &ortho, Teuchos::ParameterList ¶ms)
GCRODRIter constructor with linear problem, solver utilities, and parameter list of solver options...
Belos header file which uses auto-configuration information to include necessary C++ headers...
SerialDenseMatrix< OrdinalType, ScalarType > & assign(const SerialDenseMatrix< OrdinalType, ScalarType > &Source)
int getNumBlocks() const
Get the maximum number of blocks used by the iterative solver in solving this linear problem...
MultiVecTraits< ScalarType, MV > MVT
OrdinalType stride() const
bool isInitialized()
States whether the solver has been initialized or not.
int sizeUninitialized(OrdinalType length_in)
Templated virtual class for providing orthogonalization/orthonormalization methods with matrix-based ...