42 #ifndef BELOS_CG_ITER_HPP
43 #define BELOS_CG_ITER_HPP
77 template<
class ScalarType,
class MV,
class OP>
201 "Belos::CGIter::setBlockSize(): Cannot use a block size that is not one.");
235 bool stateStorageInitialized_;
259 template<
class ScalarType,
class MV,
class OP>
268 stateStorageInitialized_(false),
275 template <
class ScalarType,
class MV,
class OP>
278 if (!stateStorageInitialized_) {
283 if (lhsMV == Teuchos::null && rhsMV == Teuchos::null) {
284 stateStorageInitialized_ =
false;
291 if (R_ == Teuchos::null) {
295 "Belos::CGIter::setStateSize(): linear problem does not specify multivectors to clone from.");
296 R_ = MVT::Clone( *tmp, 1 );
297 Z_ = MVT::Clone( *tmp, 1 );
298 P_ = MVT::Clone( *tmp, 1 );
299 AP_ = MVT::Clone( *tmp, 1 );
303 stateStorageInitialized_ =
true;
311 template <
class ScalarType,
class MV,
class OP>
315 if (!stateStorageInitialized_)
319 "Belos::CGIter::initialize(): Cannot initialize state storage!");
323 std::string errstr(
"Belos::CGIter::initialize(): Specified multivectors must have a consistent length and width.");
329 if (newstate.
R != Teuchos::null) {
332 std::invalid_argument, errstr );
334 std::invalid_argument, errstr );
337 if (newstate.
R != R_) {
339 MVT::MvAddMv( one, *newstate.
R, zero, *newstate.
R, *R_ );
345 if ( lp_->getLeftPrec() != Teuchos::null ) {
346 lp_->applyLeftPrec( *R_, *Z_ );
347 if ( lp_->getRightPrec() != Teuchos::null ) {
349 lp_->applyRightPrec( *Z_, *tmp );
353 else if ( lp_->getRightPrec() != Teuchos::null ) {
354 lp_->applyRightPrec( *R_, *Z_ );
359 MVT::MvAddMv( one, *Z_, zero, *Z_, *P_ );
364 "Belos::CGIter::initialize(): CGIterationState does not have initial residual.");
374 template <
class ScalarType,
class MV,
class OP>
380 if (initialized_ ==
false) {
398 "Belos::CGIter::iterate(): current linear system has more than one vector!" );
401 MVT::MvTransMv( one, *R_, *Z_, rHz );
406 while (stest_->checkStatus(
this) !=
Passed) {
412 lp_->applyOp( *P_, *AP_ );
415 MVT::MvTransMv( one, *P_, *AP_, pAp );
416 alpha(0,0) = rHz(0,0) / pAp(0,0);
420 "Belos::CGIter::iterate(): non-positive value for p^H*A*p encountered!" );
424 MVT::MvAddMv( one, *cur_soln_vec, alpha(0,0), *P_, *cur_soln_vec );
425 lp_->updateSolution();
429 rHz_old(0,0) = rHz(0,0);
433 MVT::MvAddMv( one, *R_, -alpha(0,0), *AP_, *R_ );
438 if ( lp_->getLeftPrec() != Teuchos::null ) {
439 lp_->applyLeftPrec( *R_, *Z_ );
440 if ( lp_->getRightPrec() != Teuchos::null ) {
442 lp_->applyRightPrec( *Z_, *tmp );
446 else if ( lp_->getRightPrec() != Teuchos::null ) {
447 lp_->applyRightPrec( *R_, *Z_ );
453 MVT::MvTransMv( one, *R_, *Z_, rHz );
455 beta(0,0) = rHz(0,0) / rHz_old(0,0);
457 MVT::MvAddMv( one, *Z_, beta(0,0), *P_, *P_ );
Teuchos::RCP< const MV > R
The current residual.
Collection of types and exceptions used within the Belos solvers.
Teuchos::ScalarTraits< ScalarType > SCT
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.
This class implements the preconditioned Conjugate Gradient (CG) iteration.
Structure to contain pointers to CGIteration state variables.
Pure virtual base class which augments the basic interface for a conjugate gradient linear solver ite...
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.
void setBlockSize(int blockSize)
Set the blocksize to be used by the iterative solver in solving this linear problem.
MultiVecTraitsExt< ScalarType, MV > MVText
void initializeCG(CGIterationState< ScalarType, MV > newstate)
Initialize the solver to an iterate, providing a complete state.
MultiVecTraits< ScalarType, MV > MVT
An extension of the MultiVecTraits class that adds a new vector length method.
A pure virtual class for defining the status tests for the Belos iterative solvers.
Class which defines basic traits for the operator type.
CGIter(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem, const Teuchos::RCP< OutputManager< ScalarType > > &printer, const Teuchos::RCP< StatusTest< ScalarType, MV, OP > > &tester, Teuchos::ParameterList ¶ms)
CGIter constructor with linear problem, solver utilities, and parameter list of solver options...
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.
Teuchos::RCP< const MV > getNativeResiduals(std::vector< MagnitudeType > *norms) const
Get the norms of the residuals native to the solver.
CGIterationState< ScalarType, MV > getState() const
Get the current state of the linear solver.
bool isInitialized()
States whether the solver has been initialized or not.
OperatorTraits< ScalarType, MV, OP > OPT
int getNumIters() const
Get the current iteration count.
Traits class which defines basic operations on multivectors.
int getBlockSize() const
Get the blocksize to be used by the iterative solver in solving this linear problem.
void iterate()
This method performs CG iterations until the status test indicates the need to stop or an error occur...
A linear system to solve, and its associated information.
Class which describes the linear problem to be solved by the iterative solver.
Teuchos::RCP< const MV > Z
The current preconditioned residual.
virtual ~CGIter()
Destructor.
void initialize()
Initialize the solver with the initial vectors from the linear problem or random data.
Teuchos::RCP< MV > getCurrentUpdate() const
Get the current update to the linear system.
SCT::magnitudeType MagnitudeType
void resetNumIters(int iter=0)
Reset the iteration count.
const LinearProblem< ScalarType, MV, OP > & getProblem() const
Get a constant reference to the linear problem.
Class which defines basic traits for the operator type.
Belos header file which uses auto-configuration information to include necessary C++ headers...
Teuchos::RCP< const MV > P
The current decent direction vector.