|
Belos Package Browser (Single Doxygen Collection)
Development
|
Go to the documentation of this file.
42 #ifndef BELOS_BLOCK_CG_ITER_HPP
43 #define BELOS_BLOCK_CG_ITER_HPP
80 template<
class ScalarType,
class MV,
class OP,
81 const bool lapackSupportsScalarType =
165 template<
class ScalarType,
class MV,
class OP>
363 template<
class ScalarType,
class MV,
class OP>
376 stateStorageInitialized_(false),
380 int bs = params.
get(
"Block Size", 1);
384 template <
class ScalarType,
class MV,
class OP>
387 if (! stateStorageInitialized_) {
391 if (lhsMV == Teuchos::null && rhsMV == Teuchos::null) {
392 stateStorageInitialized_ =
false;
403 (tmp == Teuchos::null,std:: invalid_argument,
404 "Belos::BlockCGIter::setStateSize: LinearProblem lacks "
405 "multivectors from which to clone.");
413 stateStorageInitialized_ =
true;
418 template <
class ScalarType,
class MV,
class OP>
424 (blockSize <= 0, std::invalid_argument,
"Belos::BlockGmresIter::"
425 "setBlockSize: blockSize = " << blockSize <<
" <= 0.");
426 if (blockSize == blockSize_) {
429 if (blockSize!=blockSize_) {
430 stateStorageInitialized_ =
false;
432 blockSize_ = blockSize;
433 initialized_ =
false;
438 template <
class ScalarType,
class MV,
class OP>
442 const char prefix[] =
"Belos::BlockCGIter::initialize: ";
445 if (! stateStorageInitialized_) {
450 (! stateStorageInitialized_, std::invalid_argument,
451 prefix <<
"Cannot initialize state storage!");
454 const char errstr[] =
"Specified multivectors must have a consistent "
460 if (newstate.
R != Teuchos::null) {
464 std::invalid_argument, prefix << errstr );
467 std::invalid_argument, prefix << errstr );
470 if (newstate.
R != R_) {
477 if ( lp_->getLeftPrec() != Teuchos::null ) {
478 lp_->applyLeftPrec( *R_, *Z_ );
479 if ( lp_->getRightPrec() != Teuchos::null ) {
481 lp_->applyRightPrec( *Z_, *tmp );
485 else if ( lp_->getRightPrec() != Teuchos::null ) {
486 lp_->applyRightPrec( *R_, *Z_ );
495 (newstate.
R == Teuchos::null, std::invalid_argument,
496 prefix <<
"BlockCGStateIterState does not have initial residual.");
503 template <
class ScalarType,
class MV,
class OP>
506 const char prefix[] =
"Belos::BlockCGIter::iterate: ";
511 if (initialized_ ==
false) {
525 rHz_old( blockSize_, blockSize_ ), pAp( blockSize_, blockSize_ );
540 prefix <<
"Current linear system does not have the right number of vectors!" );
541 int rank = ortho_->normalize( *P_, Teuchos::null );
544 prefix <<
"Failed to compute initial block of orthonormal direction vectors.");
549 while (stest_->checkStatus(
this) !=
Passed) {
554 lp_->applyOp( *P_, *AP_ );
566 lltSolver.factorWithEquilibration(
true );
567 info = lltSolver.factor();
570 prefix <<
"Failed to compute Cholesky factorization using LAPACK routine POTRF.");
574 lltSolver.setVectors (Teuchos::rcpFromRef (alpha), Teuchos::rcpFromRef (alpha));
575 info = lltSolver.solve();
578 prefix <<
"Failed to compute alpha using Cholesky factorization (POTRS).");
582 lp_->updateSolution();
588 if ( lp_->getLeftPrec() != Teuchos::null ) {
589 lp_->applyLeftPrec( *R_, *Z_ );
590 if ( lp_->getRightPrec() != Teuchos::null ) {
592 lp_->applyRightPrec( *Z_, *tmp );
596 else if ( lp_->getRightPrec() != Teuchos::null ) {
597 lp_->applyRightPrec( *R_, *Z_ );
612 info = lltSolver.solve();
615 prefix <<
"Failed to compute beta using Cholesky factorization (POTRS).");
623 rank = ortho_->normalize( *P_, Teuchos::null );
626 prefix <<
"Failed to compute block of orthonormal direction vectors.");
Teuchos::RCP< MV > getCurrentUpdate() const
Get the current update to the linear system.
CGIterateFailure is thrown when the CGIteration object is unable to compute the next iterate in the C...
void setDoCondEst(bool val)
Sets whether or not to store the diagonal for condition estimation.
void initializeCG(CGIterationState< ScalarType, MV > &)
Initialize the solver to an iterate, providing a complete state.
Belos header file which uses auto-configuration information to include necessary C++ headers.
bool isInitialized()
States whether the solver has been initialized or not.
CGIterationState< ScalarType, MV > getState() const
Get the current state of the linear solver.
Teuchos::RCP< const MV > AP
The matrix A applied to current decent direction vector.
int getNumIters() const
Get the current iteration count.
Class which defines basic traits for the operator type.
Belos's basic output manager for sending information of select verbosity levels to the appropriate ou...
Class which describes the linear problem to be solved by the iterative solver.
Pure virtual base class for defining the status testing capabilities of Belos.
Teuchos::RCP< const MV > getNativeResiduals(std::vector< MagnitudeType > *norms) const
Get the norms of the residuals native to the solver.
SCT::magnitudeType MagnitudeType
const LinearProblem< ScalarType, MV, OP > & getProblem() const
Get a constant reference to the linear problem.
static void Assign(const MV &A, MV &mv)
mv := A
const Teuchos::RCP< StatusTest< ScalarType, MV, OP > > stest_
Teuchos::RCP< const MV > Z
The current preconditioned residual.
void resetNumIters(int iter=0)
Reset the iteration count.
ScalarType * values() const
Teuchos::RCP< const MV > P
The current decent direction vector.
CGIterationOrthoFailure is thrown when the CGIteration object is unable to compute independent direct...
Teuchos::RCP< const MV > getNativeResiduals(std::vector< MagnitudeType > *) const
CGIterationLAPACKFailure is thrown when a nonzero return value is passed back from an LAPACK routine.
CGIterationState< ScalarType, MV > getState() const
Get the current state of the linear solver.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
static int GetNumberVecs(const MV &mv)
Obtain the number of vectors in mv.
A linear system to solve, and its associated information.
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 manages the output and verbosity of the Belos solvers.
T & get(ParameterList &l, const std::string &name)
int getBlockSize() const
Get the block size to be used by the iterative solver in solving this linear problem.
Structure to contain pointers to CGIteration state variables.
Type traits class that says whether Teuchos::LAPACK has a valid implementation for the given ScalarTy...
void setBlockSize(int blockSize)
Set the blocksize to be used by the iterative solver in solving this linear problem.
static Teuchos::RCP< MV > Clone(const MV &mv, const int numvecs)
Creates a new empty MV containing numvecs columns.
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 > R
The current residual.
Teuchos::ArrayView< MagnitudeType > getOffDiag()
Gets the off-diagonal for condition estimation (NOT_IMPLEMENTED)
Class which defines basic traits for the operator type.
Templated virtual class for providing orthogonalization/orthonormalization methods with matrix-based ...
const Teuchos::RCP< OutputManager< ScalarType > > om_
Stub implementation of BlockCGIter, for ScalarType types for which Teuchos::LAPACK does NOT have a va...
Teuchos::ScalarTraits< ScalarType > SCT
Belos's templated virtual class for providing routines for orthogonalization and orthonormzalition of...
static void MvTimesMatAddMv(const ScalarType alpha, const MV &A, const Teuchos::SerialDenseMatrix< int, ScalarType > &B, const ScalarType beta, MV &mv)
Update mv with .
void initialize()
Initialize the solver with the initial vectors from the linear problem or random data.
const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > lp_
A pure virtual class for defining the status tests for the Belos iterative solvers.
SCT::magnitudeType MagnitudeType
void initialize()
Initialize the solver with the initial vectors from the linear problem or random data.
MultiVecTraits< ScalarType, MV > MVT
OperatorTraits< ScalarType, MV, OP > OPT
virtual ~BlockCGIter()
Destructor.
Declaration of basic traits for the multivector type.
Teuchos::ArrayView< MagnitudeType > getDiag()
Gets the diagonal for condition estimation (NOT_IMPLEMENTED)
Teuchos::RCP< MV > getCurrentUpdate() const
Get the current update to the linear system.
static ptrdiff_t GetGlobalLength(const MV &mv)
Return the number of rows in the given multivector mv.
const Teuchos::RCP< OrthoManager< ScalarType, MV > > ortho_
Collection of types and exceptions used within the Belos solvers.
int getNumIters() const
Get the current iteration count.
bool isInitialized()
States whether the solver has been initialized or not.
OperatorTraits< ScalarType, MV, OP > OPT
const LinearProblem< ScalarType, MV, OP > & getProblem() const
Get a constant reference to the linear problem.
int getBlockSize() const
Get the blocksize to be used by the iterative solver in solving this linear problem.
void iterate()
This method performs linear solver iterations until the status test indicates the need to stop or an ...
void setDoCondEst(bool val)
Sets whether or not to store the diagonal for condition estimation.
bool stateStorageInitialized_
Traits class which defines basic operations on multivectors.
MultiVecTraits< ScalarType, MV > MVT
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
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 &)
Teuchos::ScalarTraits< ScalarType > SCT
Pure virtual base class which augments the basic interface for a conjugate gradient linear solver ite...
void resetNumIters(int iter=0)
Reset the iteration count to iter.