42 #ifndef BELOS_GMRESPOLYOP_HPP
43 #define BELOS_GMRESPOLYOP_HPP
94 template <
class ScalarType,
class MV>
104 mv_ = Teuchos::rcp_const_cast<MV>( mv_in );
192 template <
class ScalarType,
class MV,
class OP>
203 : problem_(problem_in),
205 LP_(problem_in->getLeftPrec()),
206 RP_(problem_in->getRightPrec()),
207 outputStream_ (Teuchos::
rcp(outputStream_default_,false)),
209 maxDegree_ (maxDegree_default_),
210 verbosity_ (verbosity_default_),
211 randomRHS_ (randomRHS_default_),
212 label_ (label_default_),
213 polyType_ (polyType_default_),
214 orthoType_ (orthoType_default_),
219 if (polyType_ ==
"Arnoldi")
221 else if (polyType_ ==
"Gmres")
225 "Belos::GmresPolyOp(): Invalid polynomial type.");
230 : problem_(problem_in)
270 void ApplyPoly (
const MV& x, MV& y )
const;
292 typedef MultiVecTraits<ScalarType,MV> MVT;
297 static constexpr
int maxDegree_default_ = 25;
299 static constexpr
bool randomRHS_default_ =
true;
300 static constexpr
const char * label_default_ =
"Belos";
301 static constexpr
const char * polyType_default_ =
"Arnoldi";
302 static constexpr
const char * orthoType_default_ =
"DGKS";
303 static constexpr std::ostream * outputStream_default_ = &std::cout;
318 MagnitudeType polyTol_;
323 std::string polyType_;
324 std::string orthoType_;
333 bool autoDeg =
false;
338 template <
class ScalarType,
class MV,
class OP>
343 polyType_ = params_in->
get(
"Polynomial Type", polyType_default_);
347 if (params_in->
isParameter(
"Polynomial Tolerance")) {
348 if (params_in->
isType<MagnitudeType> (
"Polynomial Tolerance")) {
349 polyTol_ = params_in->
get (
"Polynomial Tolerance",
359 maxDegree_ = params_in->
get(
"Maximum Degree", maxDegree_default_);
364 randomRHS_ = params_in->
get(
"Random RHS", randomRHS_default_);
369 if (Teuchos::isParameterType<int>(*params_in,
"Verbosity")) {
370 verbosity_ = params_in->
get(
"Verbosity", verbosity_default_);
373 verbosity_ = (int)Teuchos::getParameter<Belos::MsgType>(*params_in,
"Verbosity");
378 orthoType_ = params_in->
get(
"Orthogonalization",orthoType_default_);
380 std::invalid_argument,
381 "Belos::GmresPolyOp: \"Orthogonalization\" must be either \"DGKS\", \"ICGS\", or \"IMGS\".");
386 label_ = params_in->
get(
"Timer Label", label_default_);
391 outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params_in,
"Output Stream");
395 template <
class ScalarType,
class MV,
class OP>
401 std::vector<int> index(1,0);
404 MVT::MvRandom( *V0 );
406 MVT::Assign( *problem_->getRHS(), *V0 );
408 if ( !LP_.is_null() )
411 problem_->applyLeftPrec( *Vtemp, *V0);
414 for(
int i=0; i< maxDegree_+1; i++)
420 problem_->apply( *Vi, *Vip1);
429 MVT::MvTransMv( SCT::one(), *AV, *AV, AVtransAV);
438 while( status && dim_ >= 1)
448 std::cout <<
"BelosGmresPolyOp.hpp: LAPACK POTRF was not successful!!" << std::endl;
449 std::cout <<
"Error code: " << infoInt << std::endl;
470 pCoeff_.
shape( 1, 1);
471 pCoeff_(0,0) = SCT::one();
472 std::cout <<
"Poly Degree is zero. No preconditioner created." << std::endl;
476 pCoeff_.shape( dim_+1, 1);
482 MVT::MvTransMv( SCT::one(), *AVsub, *V0, pCoeff_);
483 lapack.
POTRS(
'U', dim_+1, 1, lhs.
values(), lhs.
stride(), pCoeff_.values(), pCoeff_.stride(), &infoInt);
486 std::cout <<
"BelosGmresPolyOp.hpp: LAPACK POTRS was not successful!!" << std::endl;
487 std::cout <<
"Error code: " << infoInt << std::endl;
492 template <
class ScalarType,
class MV,
class OP>
495 std::string polyLabel = label_ +
": GmresPolyOp creation";
498 std::vector<int> idx(1,0);
501 MVT::MvInit( *newX, SCT::zero() );
503 MVT::MvRandom( *newB );
506 MVT::Assign( *(MVT::CloneView(*(problem_->getRHS()), idx)), *newB );
510 newProblem->setInitResVec( newB );
511 newProblem->setLeftPrec( problem_->getLeftPrec() );
512 newProblem->setRightPrec( problem_->getRightPrec() );
513 newProblem->setLabel(polyLabel);
514 newProblem->setProblem();
515 newProblem->setLSIndex( idx );
521 polyList.
set(
"Num Blocks",maxDegree_);
522 polyList.
set(
"Block Size",1);
523 polyList.
set(
"Keep Hessenberg",
true);
526 if (ortho_.is_null()) {
527 params_->
set(
"Orthogonalization", orthoType_);
528 if (orthoType_==
"DGKS") {
531 else if (orthoType_==
"ICGS") {
534 else if (orthoType_==
"IMGS") {
539 "Belos::GmresPolyOp(): Invalid orthogonalization type.");
565 if ( !LP_.is_null() )
566 problem_->applyLeftPrec( *newB, *V_0 );
572 int rank = ortho_->normalize( *V_0,
Teuchos::rcp( &r0_,
false ) );
574 "Belos::GmresPolyOp::generateArnoldiPoly(): Failed to compute initial block of orthonormal vectors for polynomial generation.");
581 gmres_iter->initializeGmres(newstate);
585 gmres_iter->iterate();
589 gmres_iter->updateLSQR( gmres_iter->getCurSubspaceDim() );
591 catch (std::exception e) {
593 printer_->stream(
Errors) <<
"Error! Caught exception in BlockGmresIter::iterate() at iteration "
594 << gmres_iter->getNumIters() << endl << e.what () << endl;
622 y_.values(), y_.stride() );
626 template <
class ScalarType,
class MV,
class OP>
630 if (polyType_ ==
"Arnoldi")
631 ApplyArnoldiPoly(x, y);
632 else if (polyType_ ==
"Gmres")
633 ApplyGmresPoly(x, y);
637 problem_->applyOp( x, y );
641 template <
class ScalarType,
class MV,
class OP>
648 if (!LP_.is_null()) {
650 problem_->applyLeftPrec( *AX, *Xtmp );
654 MVT::MvAddMv(pCoeff_(0,0), *AX, SCT::zero(), y, y);
655 for(
int i=1; i < dim_+1; i++)
668 problem_->apply(*X, *Y);
669 MVT::MvAddMv(pCoeff_(i,0), *Y, SCT::one(), y, y);
673 if (!RP_.is_null()) {
675 problem_->applyRightPrec( *Ytmp, y );
679 template <
class ScalarType,
class MV,
class OP>
684 V_ = MVT::Clone( x, dim_ );
685 if (!LP_.is_null()) {
686 wL_ = MVT::Clone( y, 1 );
688 if (!RP_.is_null()) {
689 wR_ = MVT::Clone( y, 1 );
695 int n = MVT::GetNumberVecs( x );
696 std::vector<int> idxi(1), idxi2, idxj(1);
699 for (
int j=0; j<n; ++j) {
705 if (!LP_.is_null()) {
707 problem_->applyLeftPrec( *x_view, *v_curr );
709 MVT::SetBlock( *x_view, idxi, *V_ );
712 for (
int i=0; i<dim_-1; ++i) {
716 for (
int ii=0; ii<i+1; ++ii) { idxi2[ii] = ii; }
728 if (!RP_.is_null()) {
729 problem_->applyRightPrec( *v_curr, *wR_ );
738 problem_->applyOp( *wR_, *wL_ );
740 if (!LP_.is_null()) {
741 problem_->applyLeftPrec( *wL_, *v_next );
746 MVT::MvTimesMatAddMv( -SCT::one(), *v_prev, h, SCT::one(), *v_next );
749 MVT::MvScale( *v_next, SCT::one()/H_(i+1,i) );
753 if (!RP_.is_null()) {
754 MVT::MvTimesMatAddMv( SCT::one()/r0_(0), *V_, y_, SCT::zero(), *wR_ );
755 problem_->applyRightPrec( *wR_, *y_view );
758 MVT::MvTimesMatAddMv( SCT::one()/r0_(0), *V_, y_, SCT::zero(), *y_view );
ScaleType convertStringToScaleType(const std::string &scaleType)
Convert the given string to its ScaleType enum value.
ScalarType * values() const
GmresPolyMv(const Teuchos::RCP< const MV > &mv_in)
Collection of types and exceptions used within the Belos solvers.
const GmresPolyMv * CloneView(const std::vector< int > &index) const
Creates a new Belos::MultiVec that shares the selected contents of *this. The index of the numvecs ve...
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
Belos's basic output manager for sending information of select verbosity levels to the appropriate ou...
void MvScale(const std::vector< ScalarType > &alpha)
Scale each element of the i-th vector in *this with alpha[i].
Class which manages the output and verbosity of the Belos solvers.
static void MvDot(const MV &mv, const MV &A, std::vector< ScalarType > &b)
Compute a vector b where the components are the individual dot-products of the i-th columns of A and ...
void MvAddMv(const ScalarType alpha, const MultiVec< ScalarType > &A, const ScalarType beta, const MultiVec< ScalarType > &B)
Replace *this with alpha * A + beta * B.
GmresPolyMv * CloneCopy() const
Create a new MultiVec and copy contents of *this into it (deep copy).
void MvScale(const ScalarType alpha)
Scale each element of the vectors in *this with alpha.
ptrdiff_t GetGlobalLength() const
The number of rows in the multivector.
static void MvRandom(MV &mv)
Replace the vectors in mv with random vectors.
This class implements the block GMRES iteration, where a block Krylov subspace is constructed...
Teuchos::RCP< const MV > V
The current Krylov basis.
Teuchos::RCP< MV > getMV()
T & get(const std::string &name, T def_value)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
void ApplyGmresPoly(const MV &x, MV &y) const
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
static Teuchos::RCP< const MV > CloneView(const MV &mv, const std::vector< int > &index)
Creates a new const MV that shares the selected contents of mv (shallow copy).
void generateGmresPoly()
This routine takes the matrix, preconditioner, and vectors from the linear problem as well as the par...
Declaration of basic traits for the multivector type.
void POTRS(const char &UPLO, const OrdinalType &n, const OrdinalType &nrhs, const ScalarType *A, const OrdinalType &lda, ScalarType *B, const OrdinalType &ldb, OrdinalType *info) const
Teuchos::RCP< const Teuchos::SerialDenseMatrix< int, ScalarType > > z
The current right-hand side of the least squares system RY = Z.
An implementation of StatusTestResNorm using a family of residual norms.
GmresPolyMv * CloneViewNonConst(const std::vector< int > &index)
Creates a new Belos::MultiVec that shares the selected contents of *this. The index of the numvecs ve...
GmresPolyMv * CloneCopy(const std::vector< int > &index) const
Creates a new Belos::MultiVec and copies the selected contents of *this into the new multivector (dee...
void MvRandom()
Fill all the vectors in *this with random numbers.
Structure to contain pointers to GmresIteration state variables.
GmresPolyOp(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem_in, const Teuchos::RCP< Teuchos::ParameterList > ¶ms_in)
Basic contstructor.
Belos::StatusTest class for specifying a maximum number of iterations.
static void MvInit(MV &mv, const ScalarType alpha=Teuchos::ScalarTraits< ScalarType >::zero())
Replace each element of the vectors in mv with alpha.
static const double polyTol
Relative residual tolerance for matrix polynomial construction.
static void MvTransMv(const ScalarType alpha, const MV &A, const MV &mv, Teuchos::SerialDenseMatrix< int, ScalarType > &B)
Compute a dense matrix B through the matrix-matrix multiply .
Class which defines basic traits for the operator type.
int GetNumberVecs() const
The number of vectors (i.e., columns) in the multivector.
static int GetNumberVecs(const MV &mv)
Obtain the number of vectors in mv.
A factory class for generating StatusTestOutput objects.
Iterated Modified Gram-Schmidt (IMGS) implementation of the Belos::OrthoManager class.
static void MvAddMv(const ScalarType alpha, const MV &A, const ScalarType beta, const MV &B, MV &mv)
Replace mv with .
ETrans
Whether to apply the (conjugate) transpose of an operator.
Traits class which defines basic operations on multivectors.
Belos::StatusTest for logically combining several status tests.
bool isParameter(const std::string &name) const
static void SetBlock(const MV &A, const std::vector< int > &index, MV &mv)
Copy the vectors in A to a set of vectors in mv indicated by the indices given in index...
Classical Gram-Schmidt (with DGKS correction) implementation of the Belos::OrthoManager class...
A Belos::StatusTest class for specifying a maximum number of iterations.
static Teuchos::RCP< MV > CloneViewNonConst(MV &mv, const std::vector< int > &index)
Creates a new MV that shares the selected contents of mv (shallow copy).
void MvTimesMatAddMv(const ScalarType alpha, const MultiVec< ScalarType > &A, const Teuchos::SerialDenseMatrix< int, ScalarType > &B, const ScalarType beta)
Update *this with alpha * A * B + beta * (*this).
static Teuchos::RCP< MV > Clone(const MV &mv, const int numvecs)
Creates a new empty MV containing numvecs columns.
Alternative run-time polymorphic interface for operators.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
int curDim
The current dimension of the reduction.
void ApplyPoly(const MV &x, MV &y) const
This routine takes the MV x and applies the polynomial operator phi(OP) to it resulting in the MV y...
void POTRF(const char &UPLO, const OrdinalType &n, ScalarType *A, const OrdinalType &lda, OrdinalType *info) const
Teuchos::RCP< const Teuchos::SerialDenseMatrix< int, ScalarType > > R
The current upper-triangular matrix from the QR reduction of H.
void ApplyArnoldiPoly(const MV &x, MV &y) const
void MvNorm(std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &normvec, NormType type=TwoNorm) const
Compute the norm of each vector in *this.
A linear system to solve, and its associated information.
Class which describes the linear problem to be solved by the iterative solver.
GmresPolyOpOrthoFailure(const std::string &what_arg)
void SetBlock(const MultiVec< ScalarType > &A, const std::vector< int > &index)
Copy the vectors in A to a set of vectors in *this.
static Teuchos::RCP< MV > CloneCopy(const MV &mv)
Creates a new MV and copies contents of mv into the new vector (deep copy).
Teuchos::RCP< const MV > getConstMV() const
static void MvTimesMatAddMv(const ScalarType alpha, const MV &A, const Teuchos::SerialDenseMatrix< int, ScalarType > &B, const ScalarType beta, MV &mv)
Update mv with .
Belos's class for applying the GMRES polynomial operator that is used by the hybrid-GMRES linear solv...
Belos concrete class for performing the block GMRES iteration.
Iterated Classical Gram-Schmidt (ICGS) implementation of the Belos::OrthoManager class.
An implementation of the Belos::MatOrthoManager that performs orthogonalization using multiple steps ...
An implementation of the Belos::MatOrthoManager that performs orthogonalization using multiple steps ...
static ptrdiff_t GetGlobalLength(const MV &mv)
Return the number of rows in the given multivector mv.
NormType
The type of vector norm to compute.
void MvInit(const ScalarType alpha)
Replace each element of the vectors in *this with alpha.
void MvDot(const MultiVec< ScalarType > &A, std::vector< ScalarType > &b) const
Compute the dot product of each column of *this with the corresponding column of A.
void MvTransMv(const ScalarType alpha, const MultiVec< ScalarType > &A, Teuchos::SerialDenseMatrix< int, ScalarType > &B) const
Compute a dense matrix B through the matrix-matrix multiply alpha * A^T * (*this).
Alternative run-time polymorphic interface for operators.
virtual ~GmresPolyOp()
Destructor.
GmresPolyMv * Clone(const int numvecs) const
Create a new MultiVec with numvecs columns.
Belos::StatusTestResNorm for specifying general residual norm stopping criteria.
Belos::StatusTest for specifying an implicit residual norm stopping criteria that checks for loss of ...
bool isType(const std::string &name) const
An implementation of the Belos::MatOrthoManager that performs orthogonalization using (potentially) m...
A class for extending the status testing capabilities of Belos via logical combinations.
Interface for multivectors used by Belos' linear solvers.
GmresPolyOp(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem_in)
Create a simple polynomial of dimension 1.
static void MvNorm(const MV &mv, std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &normvec, NormType type=TwoNorm)
Compute the norm of each individual vector of mv. Upon return, normvec[i] holds the value of ...
void generateArnoldiPoly()
This routine takes the matrix, preconditioner, and vectors from the linear problem as well as the par...
static void MvScale(MV &mv, const ScalarType alpha)
Scale each element of the vectors in mv with alpha.
Parent class to all Belos exceptions.
int shape(OrdinalType numRows, OrdinalType numCols)
Default parameters common to most Belos solvers.
Pure virtual base class which augments the basic interface for a Gmres linear solver iteration...
GmresIterationOrthoFailure is thrown when the GmresIteration object is unable to compute independent ...
Belos header file which uses auto-configuration information to include necessary C++ headers...
static void MvPrint(const MV &mv, std::ostream &os)
Print the mv multi-vector to the os output stream.
GmresPolyOpOrthoFailure is thrown when the orthogonalization manager is unable to generate orthonorma...
void MvPrint(std::ostream &os) const
Print *this multivector to the os output stream.
OrdinalType stride() const
void Apply(const MultiVec< ScalarType > &x, MultiVec< ScalarType > &y, ETrans=NOTRANS) const
This routine casts the MultiVec to GmresPolyMv to retrieve the MV. Then the above apply method is cal...
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > ¶ms_in)
Process the passed in parameters.
Interface for multivectors used by Belos' linear solvers.
GmresPolyMv(const Teuchos::RCP< MV > &mv_in)
Teuchos::RCP< const Teuchos::SerialDenseMatrix< int, ScalarType > > H
The current Hessenberg matrix.