42 #ifndef BELOS_PSEUDO_BLOCK_GMRES_ITER_HPP
43 #define BELOS_PSEUDO_BLOCK_GMRES_ITER_HPP
89 template <
class ScalarType,
class MV>
101 std::vector<Teuchos::RCP<const MV> >
V;
107 std::vector<Teuchos::RCP<const Teuchos::SerialDenseMatrix<int,ScalarType> > >
H;
109 std::vector<Teuchos::RCP<const Teuchos::SerialDenseMatrix<int,ScalarType> > >
R;
111 std::vector<Teuchos::RCP<const Teuchos::SerialDenseVector<int,ScalarType> > >
Z;
113 std::vector<Teuchos::RCP<const Teuchos::SerialDenseVector<int,ScalarType> > >
sn;
114 std::vector<Teuchos::RCP<const Teuchos::SerialDenseVector<int,MagnitudeType> > >
cs;
154 template<
class ScalarType,
class MV,
class OP>
258 state.
V.resize(numRHS_);
259 state.
H.resize(numRHS_);
260 state.
Z.resize(numRHS_);
261 state.
sn.resize(numRHS_);
262 state.
cs.resize(numRHS_);
263 for (
int i=0; i<numRHS_; ++i) {
267 state.
sn[i] = sn_[i];
268 state.
cs[i] = cs_[i];
320 if (!initialized_)
return 0;
342 "Belos::PseudoBlockGmresIter::setBlockSize(): Cannot use a block size that is not one.");
375 std::vector<Teuchos::RCP<Teuchos::SerialDenseVector<int,ScalarType> > > sn_;
376 std::vector<Teuchos::RCP<Teuchos::SerialDenseVector<int,MagnitudeType> > > cs_;
398 std::vector<Teuchos::RCP<MV> > V_;
403 std::vector<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > H_;
408 std::vector<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > R_;
409 std::vector<Teuchos::RCP<Teuchos::SerialDenseVector<int,ScalarType> > > Z_;
414 template<
class ScalarType,
class MV,
class OP>
432 "Belos::PseudoBlockGmresIter::constructor: mandatory parameter 'Num Blocks' is not specified.");
433 int nb = Teuchos::getParameter<int>(params,
"Num Blocks");
440 template <
class ScalarType,
class MV,
class OP>
446 TEUCHOS_TEST_FOR_EXCEPTION(numBlocks <= 0, std::invalid_argument,
"Belos::PseudoBlockGmresIter::setNumBlocks was passed a non-positive argument.");
448 numBlocks_ = numBlocks;
451 initialized_ =
false;
456 template <
class ScalarType,
class MV,
class OP>
465 return currentUpdate;
467 currentUpdate = MVT::Clone(*(V_[0]), numRHS_);
468 std::vector<int> index(1), index2(curDim_);
469 for (
int i=0; i<curDim_; ++i) {
476 for (
int i=0; i<numRHS_; ++i) {
478 Teuchos::RCP<MV> cur_block_copy_vec = MVT::CloneViewNonConst( *currentUpdate, index );
488 H_[i]->values(), H_[i]->stride(), y.
values(), y.
stride() );
491 MVT::MvTimesMatAddMv( one, *Vjp1, y, zero, *cur_block_copy_vec );
494 return currentUpdate;
501 template <
class ScalarType,
class MV,
class OP>
512 if (static_cast<int> (norms->size()) < numRHS_)
513 norms->resize (numRHS_);
516 for (
int j = 0; j < numRHS_; ++j)
518 const ScalarType curNativeResid = (*Z_[j])(curDim_);
519 (*norms)[j] = STS::magnitude (curNativeResid);
522 return Teuchos::null;
526 template <
class ScalarType,
class MV,
class OP>
535 this->numRHS_ = MVT::GetNumberVecs (*(lp_->getCurrLHSVec()));
541 std::string errstr (
"Belos::PseudoBlockGmresIter::initialize(): "
542 "Specified multivectors must have a consistent "
543 "length and width.");
547 std::invalid_argument,
548 "Belos::PseudoBlockGmresIter::initialize(): "
549 "V and/or Z was not specified in the input state; "
550 "the V and/or Z arrays have length zero.");
561 RCP<const MV> lhsMV = lp_->getLHS();
562 RCP<const MV> rhsMV = lp_->getRHS();
566 RCP<const MV> vectorInBasisSpace = rhsMV.is_null() ? lhsMV : rhsMV;
570 std::invalid_argument,
571 "Belos::PseudoBlockGmresIter::initialize(): "
572 "The linear problem to solve does not specify multi"
573 "vectors from which we can clone basis vectors. The "
574 "right-hand side(s), left-hand side(s), or both should "
580 std::invalid_argument,
582 curDim_ = newstate.
curDim;
588 for (
int i=0; i<numRHS_; ++i) {
592 if (V_[i].
is_null() || MVT::GetNumberVecs(*V_[i]) < numBlocks_ + 1) {
593 V_[i] = MVT::Clone (*vectorInBasisSpace, numBlocks_ + 1);
597 TEUCHOS_TEST_FOR_EXCEPTION( MVText::GetGlobalLength(*newstate.
V[i]) != MVText::GetGlobalLength(*V_[i]),
598 std::invalid_argument, errstr );
599 TEUCHOS_TEST_FOR_EXCEPTION( MVT::GetNumberVecs(*newstate.
V[i]) < newstate.
curDim,
600 std::invalid_argument, errstr );
605 int lclDim = MVT::GetNumberVecs(*newstate.
V[i]);
606 if (newstate.
V[i] != V_[i]) {
608 if (curDim_ == 0 && lclDim > 1) {
610 <<
"Belos::PseudoBlockGmresIter::initialize(): the solver was "
611 <<
"initialized with a kernel of " << lclDim
613 <<
"The block size however is only " << 1
615 <<
"The last " << lclDim - 1 <<
" vectors will be discarded."
618 std::vector<int> nevind (curDim_ + 1);
619 for (
int j = 0; j < curDim_ + 1; ++j)
622 RCP<const MV> newV = MVT::CloneView (*newstate.
V[i], nevind);
623 RCP<MV> lclV = MVT::CloneViewNonConst( *V_[i], nevind );
626 MVT::MvAddMv (one, *newV, zero, *newV, *lclV);
629 lclV = Teuchos::null;
636 for (
int i=0; i<numRHS_; ++i) {
638 if (Z_[i] == Teuchos::null) {
641 if (Z_[i]->length() < numBlocks_+1) {
642 Z_[i]->shapeUninitialized(numBlocks_+1, 1);
646 TEUCHOS_TEST_FOR_EXCEPTION(newstate.
Z[i]->numRows() < curDim_, std::invalid_argument, errstr);
649 if (newstate.
Z[i] != Z_[i]) {
659 lclZ = Teuchos::null;
666 for (
int i=0; i<numRHS_; ++i) {
668 if (H_[i] == Teuchos::null) {
671 if (H_[i]->numRows() < numBlocks_+1 || H_[i]->numCols() < numBlocks_) {
672 H_[i]->shapeUninitialized(numBlocks_+1, numBlocks_);
676 if ((
int)newstate.
H.size() == numRHS_) {
679 TEUCHOS_TEST_FOR_EXCEPTION((newstate.
H[i]->numRows() < curDim_ || newstate.
H[i]->numCols() < curDim_), std::invalid_argument,
680 "Belos::PseudoBlockGmresIter::initialize(): Specified Hessenberg matrices must have a consistent size to the current subspace dimension");
682 if (newstate.
H[i] != H_[i]) {
691 lclH = Teuchos::null;
703 if ((
int)newstate.
cs.size() == numRHS_ && (int)newstate.
sn.size() == numRHS_) {
704 for (
int i=0; i<numRHS_; ++i) {
705 if (cs_[i] != newstate.
cs[i])
707 if (sn_[i] != newstate.
sn[i])
713 for (
int i=0; i<numRHS_; ++i) {
714 if (cs_[i] == Teuchos::null)
717 cs_[i]->resize(numBlocks_+1);
718 if (sn_[i] == Teuchos::null)
721 sn_[i]->resize(numBlocks_+1);
743 template <
class ScalarType,
class MV,
class OP>
749 if (initialized_ ==
false) {
757 int searchDim = numBlocks_;
762 std::vector<int> index(1);
763 std::vector<int> index2(1);
770 for (
int i=0; i<numRHS_; ++i) {
774 MVT::MvAddMv( one, *tmp_vec, zero, *tmp_vec, *U_vec_view );
782 while (stest_->checkStatus(
this) !=
Passed && curDim_ < searchDim) {
788 lp_->apply( *U_vec, *AU_vec );
793 int num_prev = curDim_+1;
794 index.resize( num_prev );
795 for (
int i=0; i<num_prev; ++i) {
801 for (
int i=0; i<numRHS_; ++i) {
827 ortho_->projectAndNormalize( *V_new, h_array, r_new, V_array );
832 index2[0] = curDim_+1;
834 MVT::MvAddMv( one, *V_new, zero, *V_new, *tmp_vec );
876 template<
class ScalarType,
class MV,
class OP>
882 int curDim = curDim_;
883 if (dim >= curDim_ && dim < getMaxSubspaceDim()) {
892 for (i=0; i<numRHS_; ++i) {
898 for (j=0; j<curDim; j++) {
902 blas.
ROT( 1, &(*H_[i])(j,curDim), 1, &(*H_[i])(j+1, curDim), 1, &(*cs_[i])[j], &(*sn_[i])[j] );
907 blas.
ROTG( &(*H_[i])(curDim,curDim), &(*H_[i])(curDim+1,curDim), &(*cs_[i])[curDim], &(*sn_[i])[curDim] );
908 (*H_[i])(curDim+1,curDim) = zero;
912 blas.
ROT( 1, &(*Z_[i])(curDim), 1, &(*Z_[i])(curDim+1), 1, &(*cs_[i])[curDim], &(*sn_[i])[curDim] );
ScalarType * values() const
std::vector< Teuchos::RCP< const Teuchos::SerialDenseMatrix< int, ScalarType > > > H
The current Hessenberg matrix.
int getCurSubspaceDim() const
Get the dimension of the search subspace used to generate the current solution to the linear problem...
Collection of types and exceptions used within the Belos solvers.
Belos's basic output manager for sending information of select verbosity levels to the appropriate ou...
Class which manages the output and verbosity of the Belos solvers.
bool is_null(const boost::shared_ptr< T > &p)
PseudoBlockGmresIterState< ScalarType, MV > getState() const
Get the current state of the linear solver.
std::vector< Teuchos::RCP< const Teuchos::SerialDenseMatrix< int, ScalarType > > > R
The current upper-triangular matrix from the QR reduction of H.
Teuchos::ScalarTraits< ScalarType > SCT
Pure virtual base class for defining the status testing capabilities of Belos.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Declaration of basic traits for the multivector type.
int getNumBlocks() const
Get the maximum number of blocks used by the iterative solver in solving this linear problem...
virtual ~PseudoBlockGmresIter()
Destructor.
std::vector< Teuchos::RCP< const MV > > V
The current Krylov basis.
int resize(OrdinalType length_in)
Teuchos::RCP< const MV > getNativeResiduals(std::vector< MagnitudeType > *norms) const
Get the norms of the "native" residual vectors.
An extension of the MultiVecTraits class that adds a new vector length method.
Pure virtual base class which describes the basic interface to the linear solver iteration.
A pure virtual class for defining the status tests for the Belos iterative solvers.
Class which defines basic traits for the operator type.
int getNumIters() const
Get the current iteration count.
Structure to contain pointers to PseudoBlockGmresIter state variables.
const LinearProblem< ScalarType, MV, OP > & getProblem() const
Get a constant reference to the linear problem.
void initialize()
Initialize the solver with the initial vectors from the linear problem or random data.
bool isInitialized()
States whether the solver has been initialized or not.
int getBlockSize() const
Get the blocksize to be used by the iterative solver in solving this linear problem.
Traits class which defines basic operations on multivectors.
Teuchos::RCP< MV > getCurrentUpdate() const
Get the current update to the linear system.
bool isParameter(const std::string &name) const
void ROTG(ScalarType *da, ScalarType *db, MagnitudeType *c, ScalarType *s) const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void updateLSQR(int dim=-1)
Method for updating QR factorization of upper Hessenberg matrix.
PseudoBlockGmresIter(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)
PseudoBlockGmresIter constructor with linear problem, solver utilities, and parameter list of solver ...
PseudoBlockGmresIterState()
PseudoBlockGmresIterOrthoFailure(const std::string &what_arg)
std::vector< Teuchos::RCP< const Teuchos::SerialDenseVector< int, MagnitudeType > > > cs
MultiVecTraitsExt< ScalarType, MV > MVText
A linear system to solve, and its associated information.
Class which describes the linear problem to be solved by the iterative solver.
void setNumBlocks(int numBlocks)
Set the maximum number of blocks used by the iterative solver.
void ROT(const OrdinalType n, ScalarType *dx, const OrdinalType incx, ScalarType *dy, const OrdinalType incy, MagnitudeType *c, ScalarType *s) const
PseudoBlockGmresIterInitFailure(const std::string &what_arg)
SCT::magnitudeType MagnitudeType
Teuchos::ScalarTraits< ScalarType > SCT
int getMaxSubspaceDim() const
Get the maximum dimension allocated for the search subspace.
void resetNumIters(int iter=0)
Reset the iteration count.
MultiVecTraits< ScalarType, MV > MVT
std::vector< Teuchos::RCP< const Teuchos::SerialDenseVector< int, ScalarType > > > Z
The current right-hand side of the least squares system RY = Z.
OperatorTraits< ScalarType, MV, OP > OPT
void iterate()
This method performs block Gmres iterations until the status test indicates the need to stop or an er...
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
Class which defines basic traits for the operator type.
SCT::magnitudeType MagnitudeType
int curDim
The current dimension of the reduction.
Parent class to all Belos exceptions.
std::vector< Teuchos::RCP< const Teuchos::SerialDenseVector< int, ScalarType > > > sn
The current Given's rotation coefficients.
Belos's templated virtual class for providing routines for orthogonalization and orthonormzalition of...
Belos header file which uses auto-configuration information to include necessary C++ headers...
This class implements the pseudo-block GMRES iteration, where a block Krylov subspace is constructed ...
SerialDenseMatrix< OrdinalType, ScalarType > & assign(const SerialDenseMatrix< OrdinalType, ScalarType > &Source)
void setBlockSize(int blockSize)
Set the blocksize.
PseudoBlockGmresIterOrthoFailure is thrown when the orthogonalization manager is unable to generate o...
OrdinalType stride() const
Templated virtual class for providing orthogonalization/orthonormalization methods with matrix-based ...
PseudoBlockGmresIterInitFailure is thrown when the PseudoBlockGmresIter object is unable to generate ...