10 #ifndef BELOS_CG_SINGLE_RED_ITER_HPP
11 #define BELOS_CG_SINGLE_RED_ITER_HPP
46 template<
class ScalarType,
class MV,
class OP>
170 "Belos::CGSingleRedIter::setBlockSize(): Cannot use a block size that is not one.");
262 template<
class ScalarType,
class MV,
class OP>
271 convTest_(convTester),
273 stateStorageInitialized_(false),
281 template <
class ScalarType,
class MV,
class OP>
284 if (!stateStorageInitialized_) {
290 stateStorageInitialized_ =
false;
301 "Belos::CGSingleRedIter::setStateSize(): linear problem does not specify multivectors to clone from.");
304 W_ = MVT::Clone( *tmp, 3 );
305 std::vector<int> index2(2,0);
306 std::vector<int> index(1,0);
311 S_ = MVT::CloneViewNonConst( *W_, index2 );
316 U_ = MVT::CloneViewNonConst( *W_, index2 );
319 R_ = MVT::CloneViewNonConst( *W_, index );
321 AZ_ = MVT::CloneViewNonConst( *W_, index );
323 Z_ = MVT::CloneViewNonConst( *W_, index );
328 T_ = MVT::CloneViewNonConst( *W_, index2 );
331 V_ = MVT::Clone( *tmp, 2 );
333 AP_ = MVT::CloneViewNonConst( *V_, index );
335 P_ = MVT::CloneViewNonConst( *V_, index );
340 stateStorageInitialized_ =
true;
348 template <
class ScalarType,
class MV,
class OP>
352 if (!stateStorageInitialized_)
356 "Belos::CGSingleRedIter::initialize(): Cannot initialize state storage!");
360 std::string errstr(
"Belos::CGSingleRedIter::initialize(): Specified multivectors must have a consistent length and width.");
365 std::invalid_argument, errstr );
367 std::invalid_argument, errstr );
370 if (newstate.
R != R_) {
372 MVT::Assign( *newstate.
R, *R_ );
379 lp_->applyLeftPrec( *R_, *Z_ );
382 lp_->applyRightPrec( *Z_, *tmp );
383 MVT::Assign( *tmp, *Z_ );
387 lp_->applyRightPrec( *R_, *Z_ );
390 MVT::Assign( *R_, *Z_ );
394 lp_->applyOp( *Z_, *AZ_ );
398 MVT::Assign( *U_, *V_);
403 "Belos::CGSingleRedIter::initialize(): CGIterationState does not have initial residual.");
413 template <
class ScalarType,
class MV,
class OP>
419 }
else if (foldConvergenceDetectionIntoAllreduce_ && convTest_->getResNormType() ==
Belos::TwoNorm) {
429 template <
class ScalarType,
class MV,
class OP>
435 if (initialized_ ==
false) {
442 ScalarType rHz_old, alpha, beta, delta;
453 "Belos::CGSingleRedIter::iterate(): current linear system has more than one vector!" );
455 if (foldConvergenceDetectionIntoAllreduce_ && convTest_->getResNormType() ==
Belos::TwoNorm) {
457 MVT::MvTransMv( one, *S_, *T_, sHt );
463 MVT::MvTransMv( one, *S_, *Z_, sHz );
468 (stest_->checkStatus(
this) ==
Passed))
470 alpha = rHz_ / delta;
474 "Belos::CGSingleRedIter::iterate(): non-positive value for p^H*A*p encountered!" );
479 if (foldConvergenceDetectionIntoAllreduce_ && convTest_->getResNormType() ==
Belos::TwoNorm) {
487 MVT::MvAddMv( one, *cur_soln_vec, alpha, *P_, *cur_soln_vec );
491 MVT::MvAddMv( one, *R_, -alpha, *AP_, *R_ );
496 lp_->applyLeftPrec( *R_, *Z_ );
499 lp_->applyRightPrec( *tmp, *Z_ );
503 lp_->applyRightPrec( *R_, *Z_ );
506 MVT::Assign( *R_, *Z_ );
510 lp_->applyOp( *Z_, *AZ_ );
513 MVT::MvTransMv( one, *S_, *T_, sHt );
526 if (stest_->checkStatus(
this) ==
Passed) {
530 beta = rHz_ / rHz_old;
531 alpha = rHz_ / (delta - (beta*rHz_ / alpha));
535 "Belos::CGSingleRedIter::iterate(): non-positive value for p^H*A*p encountered!" );
542 MVT::MvAddMv( one, *U_, beta, *V_, *V_ );
553 MVT::MvAddMv( one, *cur_soln_vec, alpha, *P_, *cur_soln_vec );
557 MVT::MvAddMv( one, *R_, -alpha, *AP_, *R_ );
564 if (stest_->checkStatus(
this) ==
Passed) {
571 lp_->applyLeftPrec( *R_, *Z_ );
574 lp_->applyRightPrec( *tmp, *Z_ );
578 lp_->applyRightPrec( *R_, *Z_ );
581 MVT::Assign( *R_, *Z_ );
585 lp_->applyOp( *Z_, *AZ_ );
588 MVT::MvTransMv( one, *S_, *Z_, sHz );
595 beta = rHz_ / rHz_old;
596 alpha = rHz_ / (delta - (beta*rHz_ / alpha));
600 "Belos::CGSingleRedIter::iterate(): non-positive value for p^H*A*p encountered!" );
607 MVT::MvAddMv( one, *U_, beta, *V_, *V_ );
Teuchos::RCP< const MV > R
The current residual.
Collection of types and exceptions used within the Belos solvers.
int getBlockSize() const
Get the blocksize to be used by the iterative solver in solving this linear problem.
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.
Teuchos::RCP< MV > getCurrentUpdate() const
Get the current update to the linear system.
bool foldConvergenceDetectionIntoAllreduce_
void setStateSize()
Method for initalizing the state storage needed by CG.
int getNumIters() const
Get the current iteration count.
const LinearProblem< ScalarType, MV, OP > & getProblem() const
Get a constant reference to the linear problem.
T & get(ParameterList &l, const std::string &name)
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.
An implementation of StatusTestResNorm using a family of residual norms.
const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > lp_
void iterate()
This method performs CG iterations until the status test indicates the need to stop or an error occur...
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.
Teuchos::RCP< const MV > getNativeResiduals(std::vector< MagnitudeType > *norms) const
Get the norms of the residuals native to the solver.
MultiVecTraits< ScalarType, MV > MVT
Traits class which defines basic operations on multivectors.
void initialize()
Initialize the solver with the initial vectors from the linear problem or random data.
CGPositiveDefiniteFailure is thrown when the the CG 'alpha = p^H*A*P' value is less than zero...
Teuchos::ArrayView< MagnitudeType > getOffDiag()
Gets the off-diagonal for condition estimation (NOT_IMPLEMENTED)
void setBlockSize(int blockSize)
Set the blocksize to be used by the iterative solver in solving this linear problem.
A linear system to solve, and its associated information.
Class which describes the linear problem to be solved by the iterative solver.
bool isInitialized()
States whether the solver has been initialized or not.
virtual ~CGSingleRedIter()
Destructor.
SCT::magnitudeType MagnitudeType
const Teuchos::RCP< StatusTestGenResNorm< ScalarType, MV, OP > > convTest_
void initializeCG(CGIterationState< ScalarType, MV > &newstate)
Initialize the solver to an iterate, providing a complete state.
Teuchos::RCP< const MV > Z
The current preconditioned residual.
CGSingleRedIter(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< StatusTestGenResNorm< ScalarType, MV, OP > > &convTester, Teuchos::ParameterList ¶ms)
CGSingleRedIter constructor with linear problem, solver utilities, and parameter list of solver optio...
const Teuchos::RCP< OutputManager< ScalarType > > om_
Belos::StatusTestResNorm for specifying general residual norm stopping criteria.
bool stateStorageInitialized_
Class which defines basic traits for the operator type.
const Teuchos::RCP< StatusTest< ScalarType, MV, OP > > stest_
This class implements the preconditioned single-reduction Conjugate Gradient (CG) iteration...
Teuchos::ScalarTraits< ScalarType > SCT
Belos header file which uses auto-configuration information to include necessary C++ headers...
void resetNumIters(int iter=0)
Reset the iteration count.
OperatorTraits< ScalarType, MV, OP > OPT
Teuchos::RCP< const MV > P
The current decent direction vector.
CGIterationState< ScalarType, MV > getState() const
Get the current state of the linear solver.
void setDoCondEst(bool)
Sets whether or not to store the diagonal for condition estimation.
Teuchos::ArrayView< MagnitudeType > getDiag()
Gets the diagonal for condition estimation (NOT_IMPLEMENTED)