10 #ifndef BELOS_BLOCK_CG_ITER_HPP
11 #define BELOS_BLOCK_CG_ITER_HPP
46 template <
class ScalarType,
class MV>
60 this->
R = MVT::Clone( *tmp, _numVectors );
61 this->
Z = MVT::Clone( *tmp, _numVectors );
62 this->
P = MVT::Clone( *tmp, _numVectors );
63 this->
AP = MVT::Clone(*tmp, _numVectors );
82 template<
class ScalarType,
class MV,
class OP,
83 const bool lapackSupportsScalarType =
166 template<
class ScalarType,
class MV,
class OP>
346 bool stateStorageInitialized_;
368 template<
class ScalarType,
class MV,
class OP>
381 stateStorageInitialized_(false),
385 int bs = params.
get(
"Block Size", 1);
389 template <
class ScalarType,
class MV,
class OP>
395 (blockSize <= 0, std::invalid_argument,
"Belos::BlockGmresIter::"
396 "setBlockSize: blockSize = " << blockSize <<
" <= 0.");
397 if (blockSize == blockSize_) {
400 if (blockSize!=blockSize_) {
401 stateStorageInitialized_ =
false;
403 blockSize_ = blockSize;
404 initialized_ =
false;
407 template <
class ScalarType,
class MV,
class OP>
411 const char prefix[] =
"Belos::BlockCGIter::initialize: ";
419 newstate->initialize(tmp, blockSize_);
423 const char errstr[] =
"Specified multivectors must have a consistent "
430 std::invalid_argument, prefix << errstr );
433 std::invalid_argument, prefix << errstr );
443 if ( lp_->getLeftPrec() != Teuchos::null ) {
444 lp_->applyLeftPrec( *R_, *Z_ );
445 if ( lp_->getRightPrec() != Teuchos::null ) {
447 lp_->applyRightPrec( *Z_, *tmp2 );
451 else if ( lp_->getRightPrec() != Teuchos::null ) {
452 lp_->applyRightPrec( *R_, *Z_ );
464 template <
class ScalarType,
class MV,
class OP>
467 const char prefix[] =
"Belos::BlockCGIter::iterate: ";
472 if (initialized_ ==
false) {
486 rHz_old( blockSize_, blockSize_ ), pAp( blockSize_, blockSize_ );
501 prefix <<
"Current linear system does not have the right number of vectors!" );
502 int rank = ortho_->normalize( *P_, Teuchos::null );
505 prefix <<
"Failed to compute initial block of orthonormal direction vectors.");
510 while (stest_->checkStatus(
this) !=
Passed) {
515 lp_->applyOp( *P_, *AP_ );
527 lltSolver.factorWithEquilibration(
true );
528 info = lltSolver.factor();
531 prefix <<
"Failed to compute Cholesky factorization using LAPACK routine POTRF.");
535 lltSolver.setVectors (Teuchos::rcpFromRef (alpha), Teuchos::rcpFromRef (alpha));
536 info = lltSolver.solve();
539 prefix <<
"Failed to compute alpha using Cholesky factorization (POTRS).");
543 lp_->updateSolution();
549 if ( lp_->getLeftPrec() != Teuchos::null ) {
550 lp_->applyLeftPrec( *R_, *Z_ );
551 if ( lp_->getRightPrec() != Teuchos::null ) {
553 lp_->applyRightPrec( *Z_, *tmp );
557 else if ( lp_->getRightPrec() != Teuchos::null ) {
558 lp_->applyRightPrec( *R_, *Z_ );
573 info = lltSolver.solve();
576 prefix <<
"Failed to compute beta using Cholesky factorization (POTRS).");
584 rank = ortho_->normalize( *P_, Teuchos::null );
587 prefix <<
"Failed to compute block of orthonormal direction vectors.");
Structure to contain pointers to BlockCGIteration state variables.
ScalarType * values() const
Collection of types and exceptions used within the Belos solvers.
Teuchos::RCP< CGIterationStateBase< ScalarType, MV > > getState() const
Get the current state of the linear solver.
Belos's basic output manager for sending information of select verbosity levels to the appropriate ou...
void setDoCondEst(bool val)
Sets whether or not to store the diagonal for condition estimation.
Teuchos::ArrayView< MagnitudeType > getOffDiag()
Gets the off-diagonal for condition estimation (NOT_IMPLEMENTED)
void setState(Teuchos::RCP< CGIterationStateBase< ScalarType, MV > > state)
int getBlockSize() const
Get the blocksize to be used by the iterative solver in solving this linear problem.
Class which manages the output and verbosity of the Belos solvers.
void initialize()
Initialize the solver with the initial vectors from the linear problem or random data.
int getNumIters() const
Get the current iteration count.
Teuchos::RCP< CGIterationStateBase< ScalarType, MV > > getState() const
Get the current state of the linear solver.
BlockCGIterationState()=default
BlockCGIter(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &, const Teuchos::RCP< OutputManager< ScalarType > > &, const Teuchos::RCP< StatusTest< ScalarType, MV, OP > > &, const Teuchos::RCP< MatOrthoManager< ScalarType, MV, OP > > &, Teuchos::ParameterList &)
const LinearProblem< ScalarType, MV, OP > & getProblem() const
Get a constant reference to the linear problem.
Pure virtual base class which augments the basic interface for a conjugate gradient linear solver ite...
T & get(const std::string &name, T def_value)
void resetNumIters(int iter=0)
Reset the iteration count.
void setState(Teuchos::RCP< CGIterationStateBase< ScalarType, MV > > state)
Pure virtual base class for defining the status testing capabilities of Belos.
void setDoCondEst(bool)
Sets whether or not to store the diagonal for condition estimation.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
MultiVecTraits< ScalarType, MV > MVT
Declaration of basic traits for the multivector type.
bool matches(Teuchos::RCP< const MV > tmp, int _numVectors=1) const
Teuchos::ScalarTraits< ScalarType > SCT
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 .
A pure virtual class for defining the status tests for the Belos iterative solvers.
Class which defines basic traits for the operator type.
CGIterateFailure is thrown when the CGIteration object is unable to compute the next iterate in the C...
const LinearProblem< ScalarType, MV, OP > & getProblem() const
Get a constant reference to the linear problem.
Teuchos::RCP< MV > P
The current decent direction vector.
static int GetNumberVecs(const MV &mv)
Obtain the number of vectors in mv.
static void Assign(const MV &A, MV &mv)
mv := A
Teuchos::RCP< MV > getCurrentUpdate() const
Get the current update to the linear system.
Traits class which defines basic operations on multivectors.
void initializeCG(Teuchos::RCP< BlockCGIterationState< ScalarType, MV > >, Teuchos::RCP< MV >)
CGIterationLAPACKFailure is thrown when a nonzero return value is passed back from an LAPACK routine...
static Teuchos::RCP< MV > Clone(const MV &mv, const int numvecs)
Creates a new empty MV containing numvecs columns.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
virtual void initialize(Teuchos::RCP< const MV > tmp, int _numVectors)
Teuchos::RCP< const MV > getNativeResiduals(std::vector< MagnitudeType > *) const
Get the norms of the residuals native to the solver.
void iterate()
This method performs linear solver iterations until the status test indicates the need to stop or an ...
A linear system to solve, and its associated information.
int getNumIters() const
Get the current iteration count.
Class which describes the linear problem to be solved by the iterative solver.
SCT::magnitudeType MagnitudeType
Type traits class that says whether Teuchos::LAPACK has a valid implementation for the given ScalarTy...
static Teuchos::RCP< MV > CloneCopy(const MV &mv)
Creates a new MV and copies contents of mv into the new vector (deep copy).
static void MvTimesMatAddMv(const ScalarType alpha, const MV &A, const Teuchos::SerialDenseMatrix< int, ScalarType > &B, const ScalarType beta, MV &mv)
Update mv with .
Teuchos::RCP< MV > getCurrentUpdate() const
Get the current update to the linear system.
bool isInitialized()
States whether the solver has been initialized or not.
void initialize(Teuchos::RCP< const MV > tmp, int _numVectors)
bool isInitialized()
States whether the solver has been initialized or not.
BlockCGIterationState(Teuchos::RCP< const MV > tmp)
void resetNumIters(int iter=0)
Reset the iteration count to iter.
Structure to contain pointers to CGIteration state variables.
Teuchos::ArrayView< MagnitudeType > getDiag()
Gets the diagonal for condition estimation (NOT_IMPLEMENTED)
Teuchos::RCP< MV > Z
The current preconditioned residual.
OperatorTraits< ScalarType, MV, OP > OPT
static ptrdiff_t GetGlobalLength(const MV &mv)
Return the number of rows in the given multivector mv.
Teuchos::RCP< MV > AP
The matrix A applied to current decent direction vector.
typename SCT::magnitudeType MagnitudeType
CGIterationOrthoFailure is thrown when the CGIteration object is unable to compute independent direct...
void setBlockSize(int blockSize)
Set the blocksize to be used by the iterative solver in solving this linear problem.
Teuchos::RCP< const MV > getNativeResiduals(std::vector< MagnitudeType > *) const
int getBlockSize() const
Get the block size to be used by the iterative solver in solving this linear problem.
void initialize()
Initialize the solver with the initial vectors from the linear problem or random data.
Class which defines basic traits for the operator type.
Belos's templated virtual class for providing routines for orthogonalization and orthonormzalition of...
#define TEUCHOS_ASSERT(assertion_test)
Teuchos::RCP< MV > R
The current residual.
Belos header file which uses auto-configuration information to include necessary C++ headers...
virtual ~BlockCGIterationState()=default
virtual bool matches(Teuchos::RCP< const MV > tmp, int _numVectors=1) const
Templated virtual class for providing orthogonalization/orthonormalization methods with matrix-based ...
Stub implementation of BlockCGIter, for ScalarType types for which Teuchos::LAPACK does NOT have a va...