42 #ifndef BELOS_BLOCK_CG_ITER_HPP
43 #define BELOS_BLOCK_CG_ITER_HPP
82 template<
class ScalarType,
class MV,
class OP>
245 bool stateStorageInitialized_;
269 template<
class ScalarType,
class MV,
class OP>
281 stateStorageInitialized_(false),
285 int bs = params.
get(
"Block Size", 1);
291 template <
class ScalarType,
class MV,
class OP>
294 if (!stateStorageInitialized_) {
299 if (lhsMV == Teuchos::null && rhsMV == Teuchos::null) {
300 stateStorageInitialized_ =
false;
307 if (R_ == Teuchos::null || MVT::GetNumberVecs(*R_)!=blockSize_) {
311 "Belos::BlockCGIter::setStateSize(): linear problem does not specify multivectors to clone from.");
312 R_ = MVT::Clone( *tmp, blockSize_ );
313 Z_ = MVT::Clone( *tmp, blockSize_ );
314 P_ = MVT::Clone( *tmp, blockSize_ );
315 AP_ = MVT::Clone( *tmp, blockSize_ );
319 stateStorageInitialized_ =
true;
326 template <
class ScalarType,
class MV,
class OP>
332 TEUCHOS_TEST_FOR_EXCEPTION(blockSize <= 0, std::invalid_argument,
"Belos::BlockGmresIter::setBlockSize was passed a non-positive argument.");
333 if (blockSize == blockSize_) {
338 if (blockSize!=blockSize_)
339 stateStorageInitialized_ =
false;
341 blockSize_ = blockSize;
343 initialized_ =
false;
352 template <
class ScalarType,
class MV,
class OP>
356 if (!stateStorageInitialized_)
360 "Belos::BlockCGIter::initialize(): Cannot initialize state storage!");
364 std::string errstr(
"Belos::BlockCGIter::initialize(): Specified multivectors must have a consistent length and width.");
370 if (newstate.
R != Teuchos::null) {
373 std::invalid_argument, errstr );
375 std::invalid_argument, errstr );
378 if (newstate.
R != R_) {
380 MVT::MvAddMv( one, *newstate.
R, zero, *newstate.
R, *R_ );
385 if ( lp_->getLeftPrec() != Teuchos::null ) {
386 lp_->applyLeftPrec( *R_, *Z_ );
387 if ( lp_->getRightPrec() != Teuchos::null ) {
389 lp_->applyRightPrec( *Z_, *tmp );
393 else if ( lp_->getRightPrec() != Teuchos::null ) {
394 lp_->applyRightPrec( *R_, *Z_ );
399 MVT::MvAddMv( one, *Z_, zero, *Z_, *P_ );
404 "Belos::BlockCGIter::initialize(): BlockCGStateIterState does not have initial residual.");
414 template <
class ScalarType,
class MV,
class OP>
420 if (initialized_ ==
false) {
434 rHz_old( blockSize_, blockSize_ ), pAp( blockSize_, blockSize_ );
448 "Belos::BlockCGIter::iterate(): current linear system does not have the right number of vectors!" );
449 int rank = ortho_->normalize( *P_, Teuchos::null );
451 "Belos::BlockCGIter::iterate(): Failed to compute initial block of orthonormal direction vectors.");
457 while (stest_->checkStatus(
this) !=
Passed) {
463 lp_->applyOp( *P_, *AP_ );
470 MVT::MvTransMv( one, *P_, *R_, alpha );
471 MVT::MvTransMv( one, *P_, *AP_, pAp );
475 lltSolver.factorWithEquilibration(
true );
476 info = lltSolver.factor();
478 "Belos::BlockCGIter::iterate(): Failed to compute Cholesky factorization using LAPACK routine POTRF.");
482 info = lltSolver.solve();
484 "Belos::BlockCGIter::iterate(): Failed to compute alpha using Cholesky factorization (POTRS).");
489 MVT::MvTimesMatAddMv( one, *P_, alpha, one, *cur_soln_vec );
490 lp_->updateSolution();
494 MVT::MvTimesMatAddMv( -one, *AP_, alpha, one, *R_ );
497 if ( lp_->getLeftPrec() != Teuchos::null ) {
498 lp_->applyLeftPrec( *R_, *Z_ );
499 if ( lp_->getRightPrec() != Teuchos::null ) {
501 lp_->applyRightPrec( *Z_, *tmp );
505 else if ( lp_->getRightPrec() != Teuchos::null ) {
506 lp_->applyRightPrec( *R_, *Z_ );
518 MVT::MvTransMv( -one, *AP_, *Z_, beta );
521 info = lltSolver.solve();
523 "Belos::BlockCGIter::iterate(): Failed to compute beta using Cholesky factorization (POTRS).");
528 MVT::MvTimesMatAddMv(one, *P_, beta, one, *Pnew);
532 rank = ortho_->normalize( *P_, Teuchos::null );
534 "Belos::BlockCGIter::iterate(): Failed to compute block of orthonormal direction vectors.");
ScalarType * values() const
Teuchos::RCP< const MV > R
The current residual.
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...
void resetNumIters(int iter=0)
Reset the iteration count.
Class which manages the output and verbosity of the Belos solvers.
OperatorTraits< ScalarType, MV, OP > OPT
Structure to contain pointers to CGIteration state variables.
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)
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.
Teuchos::RCP< MV > getCurrentUpdate() const
Get the current update to the linear system.
An extension of the MultiVecTraits class that adds a new vector length method.
MultiVecTraitsExt< ScalarType, MV > MVText
BlockCGIter(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)
BlockCGIter constructor with linear problem, solver utilities, and parameter list of solver options...
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...
Teuchos::RCP< const MV > AP
The matrix A applied to current decent direction vector.
bool isInitialized()
States whether the solver has been initialized or not.
Traits class which defines basic operations on multivectors.
const LinearProblem< ScalarType, MV, OP > & getProblem() const
Get a constant reference to the linear problem.
MultiVecTraits< ScalarType, MV > MVT
CGIterationLAPACKFailure is thrown when a nonzero return value is passed back from an LAPACK routine...
Teuchos::ScalarTraits< ScalarType > SCT
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
SCT::magnitudeType MagnitudeType
A linear system to solve, and its associated information.
Class which describes the linear problem to be solved by the iterative solver.
void iterate()
This method performs BlockCG iterations until the status test indicates the need to stop or an error ...
virtual ~BlockCGIter()
Destructor.
Teuchos::RCP< const MV > Z
The current preconditioned residual.
Teuchos::RCP< const MV > getNativeResiduals(std::vector< MagnitudeType > *norms) const
Get the norms of the residuals native to the solver.
void setBlockSize(int blockSize)
Set the block size to be used by the iterative solver in solving this linear problem.
CGIterationOrthoFailure is thrown when the CGIteration object is unable to compute independent direct...
int getNumIters() const
Get the current iteration count.
CGIterationState< ScalarType, MV > getState() const
Get the current state of the linear solver.
Class which defines basic traits for the operator type.
void initializeCG(CGIterationState< ScalarType, MV > newstate)
Initialize the solver to an iterate, providing a complete state.
Belos's templated virtual class for providing routines for orthogonalization and orthonormzalition of...
int getBlockSize() const
Get the block size to be used by the iterative solver in solving this linear problem.
Belos header file which uses auto-configuration information to include necessary C++ headers...
Teuchos::RCP< const MV > P
The current decent direction vector.
Templated virtual class for providing orthogonalization/orthonormalization methods with matrix-based ...
void initialize()
Initialize the solver with the initial vectors from the linear problem or random data.
This class implements the block, preconditioned Conjugate Gradient (CG) iteration.