42 #ifndef BELOS_CG_ITER_HPP
43 #define BELOS_CG_ITER_HPP
77 template<
class ScalarType,
class MV,
class OP>
200 "Belos::CGIter::setBlockSize(): Cannot use a block size that is not one.");
300 template<
class ScalarType,
class MV,
class OP>
309 stateStorageInitialized_(false),
311 assertPositiveDefiniteness_( params.get(
"Assert Positive Definiteness", true) ),
312 numEntriesForCondEst_(params.get(
"Max Size For Condest",0) )
318 template <
class ScalarType,
class MV,
class OP>
321 if (!stateStorageInitialized_) {
326 if (lhsMV == Teuchos::null && rhsMV == Teuchos::null) {
327 stateStorageInitialized_ =
false;
334 if (R_ == Teuchos::null) {
338 "Belos::CGIter::setStateSize(): linear problem does not specify multivectors to clone from.");
339 R_ = MVT::Clone( *tmp, 1 );
340 Z_ = MVT::Clone( *tmp, 1 );
341 P_ = MVT::Clone( *tmp, 1 );
342 AP_ = MVT::Clone( *tmp, 1 );
346 if(numEntriesForCondEst_ > 0) {
347 diag_.resize(numEntriesForCondEst_);
348 offdiag_.resize(numEntriesForCondEst_-1);
352 stateStorageInitialized_ =
true;
360 template <
class ScalarType,
class MV,
class OP>
364 if (!stateStorageInitialized_)
368 "Belos::CGIter::initialize(): Cannot initialize state storage!");
372 std::string errstr(
"Belos::CGIter::initialize(): Specified multivectors must have a consistent length and width.");
378 if (newstate.
R != Teuchos::null) {
381 std::invalid_argument, errstr );
383 std::invalid_argument, errstr );
386 if (newstate.
R != R_) {
388 MVT::MvAddMv( one, *newstate.
R, zero, *newstate.
R, *R_ );
394 if ( lp_->getLeftPrec() != Teuchos::null ) {
395 lp_->applyLeftPrec( *R_, *Z_ );
396 if ( lp_->getRightPrec() != Teuchos::null ) {
398 lp_->applyRightPrec( *Z_, *tmp );
402 else if ( lp_->getRightPrec() != Teuchos::null ) {
403 lp_->applyRightPrec( *R_, *Z_ );
408 MVT::MvAddMv( one, *Z_, zero, *Z_, *P_ );
413 "Belos::CGIter::initialize(): CGIterationState does not have initial residual.");
423 template <
class ScalarType,
class MV,
class OP>
429 if (initialized_ ==
false) {
447 "Belos::CGIter::iterate(): current linear system has more than one vector!" );
450 MVT::MvTransMv( one, *R_, *Z_, rHz );
455 while (stest_->checkStatus(
this) !=
Passed) {
461 lp_->applyOp( *P_, *AP_ );
464 MVT::MvTransMv( one, *P_, *AP_, pAp );
465 alpha(0,0) = rHz(0,0) / pAp(0,0);
468 if(assertPositiveDefiniteness_)
470 "Belos::CGIter::iterate(): non-positive value for p^H*A*p encountered!" );
474 MVT::MvAddMv( one, *cur_soln_vec, alpha(0,0), *P_, *cur_soln_vec );
475 lp_->updateSolution();
479 rHz_old(0,0) = rHz(0,0);
483 MVT::MvAddMv( one, *R_, -alpha(0,0), *AP_, *R_ );
488 if ( lp_->getLeftPrec() != Teuchos::null ) {
489 lp_->applyLeftPrec( *R_, *Z_ );
490 if ( lp_->getRightPrec() != Teuchos::null ) {
492 lp_->applyRightPrec( *Z_, *tmp );
496 else if ( lp_->getRightPrec() != Teuchos::null ) {
497 lp_->applyRightPrec( *R_, *Z_ );
503 MVT::MvTransMv( one, *R_, *Z_, rHz );
505 beta(0,0) = rHz(0,0) / rHz_old(0,0);
507 MVT::MvAddMv( one, *Z_, beta(0,0), *P_, *P_ );