10#ifndef BELOS_BICGSTAB_ITER_HPP
11#define BELOS_BICGSTAB_ITER_HPP
28#include "Teuchos_ScalarTraits.hpp"
29#include "Teuchos_ParameterList.hpp"
30#include "Teuchos_TimeMonitor.hpp"
52 template <
class ScalarType,
class MV>
56 Teuchos::RCP<const MV>
R;
59 Teuchos::RCP<const MV>
Rhat;
62 Teuchos::RCP<const MV>
P;
65 Teuchos::RCP<const MV>
V;
70 P(Teuchos::null),
V(Teuchos::null)
78 template<
class ScalarType,
class MV,
class OP,
class DM = DefaultDenseMatrix<
int,ScalarType>>
88 typedef Teuchos::ScalarTraits<ScalarType>
SCT;
90 typedef Teuchos::ScalarTraits<MagnitudeType>
MT;
103 Teuchos::ParameterList ¶ms );
173 state.
alpha = alpha_;
174 state.
omega = omega_;
217 TEUCHOS_TEST_FOR_EXCEPTION(blockSize!=1,std::invalid_argument,
218 "Belos::BiCGStabIter::setBlockSize(): Cannot use a block size that is not one.");
228 void axpy(
const ScalarType alpha,
const MV & A,
229 const std::vector<ScalarType> beta,
const MV& B, MV& mv,
bool minus=
false);
234 const Teuchos::RCP<LinearProblem<ScalarType,MV,OP,DM> > lp_;
235 const Teuchos::RCP<OutputManager<ScalarType> > om_;
236 const Teuchos::RCP<StatusTest<ScalarType,MV,OP,DM> > stest_;
262 Teuchos::RCP<MV> Rhat_;
273 std::vector<ScalarType> rho_old_, alpha_, omega_;
278 template<
class ScalarType,
class MV,
class OP,
class DM>
282 Teuchos::ParameterList & ):
296 template<
class ScalarType,
class MV,
class OP,
class DM>
300 Teuchos::RCP<const MV> lhsMV = lp_->getCurrLHSVec();
301 Teuchos::RCP<const MV> rhsMV = lp_->getCurrRHSVec();
302 TEUCHOS_TEST_FOR_EXCEPTION((lhsMV==Teuchos::null && rhsMV==Teuchos::null),std::invalid_argument,
303 "Belos::BiCGStabIter::initialize(): Cannot initialize state storage!");
306 Teuchos::RCP<const MV> tmp = ( (rhsMV!=Teuchos::null)? rhsMV: lhsMV );
320 rho_old_.resize(numRHS_);
321 alpha_.resize(numRHS_);
322 omega_.resize(numRHS_);
330 std::string errstr(
"Belos::BlockPseudoCGIter::initialize(): Specified multivectors must have a consistent length and width.");
333 const ScalarType one = SCT::one();
335 if (!Teuchos::is_null(newstate.
R)) {
338 std::invalid_argument, errstr );
340 std::invalid_argument, errstr );
343 if (newstate.
R != R_) {
349 lp_->computeCurrResVec(R_.get());
353 if (!Teuchos::is_null(newstate.
Rhat) && newstate.
Rhat != Rhat_) {
363 if (!Teuchos::is_null(newstate.
V) && newstate.
V != V_) {
373 if (!Teuchos::is_null(newstate.
P) && newstate.
P != P_) {
383 if (newstate.
rho_old.size () ==
static_cast<size_t> (numRHS_)) {
389 rho_old_.assign(numRHS_,one);
393 if (newstate.
alpha.size() ==
static_cast<size_t> (numRHS_)) {
395 alpha_ = newstate.
alpha;
399 alpha_.assign(numRHS_,one);
403 if (newstate.
omega.size() ==
static_cast<size_t> (numRHS_)) {
405 omega_ = newstate.
omega;
409 omega_.assign(numRHS_,one);
415 TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::is_null(newstate.
R),std::invalid_argument,
416 "Belos::BiCGStabIter::initialize(): BiCGStabStateIterState does not have initial residual.");
426 template<
class ScalarType,
class MV,
class OP,
class DM>
434 if (initialized_ ==
false) {
440 std::vector<ScalarType> rho_new( numRHS_ ), beta( numRHS_ );
441 std::vector<ScalarType> rhatV( numRHS_ ), tT( numRHS_ ), tS( numRHS_ );
444 const ScalarType one = SCT::one();
447 RCP<MV> leftPrecVec, leftPrecVec2;
452 if (lp_->isLeftPrec() || lp_->isRightPrec()) {
462 Teuchos::RCP<MV> X = lp_->getCurrLHSVec();
467 while (stest_->checkStatus(
this) !=
Passed && !breakdown_) {
477 for(i=0; i<numRHS_; i++) {
480 if (SCT::magnitude(rho_new[i]) < MT::sfmin())
483 beta[i] = (rho_new[i] / rho_old_[i]) * (alpha_[i] / omega_[i]);
489 axpy(one, *P_, omega_, *V_, *P_,
true);
490 axpy(one, *R_, beta, *P_, *P_);
494 if(lp_->isLeftPrec()) {
495 if(lp_->isRightPrec()) {
496 if(leftPrecVec == Teuchos::null) {
499 lp_->applyLeftPrec(*P_,*leftPrecVec);
500 lp_->applyRightPrec(*leftPrecVec,*Y);
503 lp_->applyLeftPrec(*P_,*Y);
506 else if(lp_->isRightPrec()) {
507 lp_->applyRightPrec(*P_,*Y);
511 lp_->applyOp(*Y,*V_);
515 for(i=0; i<numRHS_; i++) {
516 if (SCT::magnitude(rhatV[i]) < MT::sfmin())
522 alpha_[i] = rho_new[i] / rhatV[i];
526 axpy(one, *R_, alpha_, *V_, *S,
true);
529 if(lp_->isLeftPrec()) {
530 if(lp_->isRightPrec()) {
531 if(leftPrecVec == Teuchos::null) {
534 lp_->applyLeftPrec(*S,*leftPrecVec);
535 lp_->applyRightPrec(*leftPrecVec,*Z);
538 lp_->applyLeftPrec(*S,*Z);
541 else if(lp_->isRightPrec()) {
542 lp_->applyRightPrec(*S,*Z);
549 if(lp_->isLeftPrec()) {
550 if(leftPrecVec == Teuchos::null) {
553 if(leftPrecVec2 == Teuchos::null) {
556 lp_->applyLeftPrec(*T,*leftPrecVec2);
564 for(i=0; i<numRHS_; i++) {
565 if (SCT::magnitude(tT[i]) < MT::sfmin())
567 omega_[i] = SCT::zero();
571 omega_[i] = tS[i] / tT[i];
575 axpy(one, *X, alpha_, *Y, *X);
576 axpy(one, *X, omega_, *Z, *X);
579 axpy(one, *S, omega_, *T, *R_,
true);
589 template<
class ScalarType,
class MV,
class OP,
class DM>
590 void BiCGStabIter<ScalarType,MV,OP,DM>::axpy(
const ScalarType alpha,
const MV & A,
591 const std::vector<ScalarType> beta,
const MV& B, MV& mv,
bool minus)
593 Teuchos::RCP<const MV> A1, B1;
594 Teuchos::RCP<MV> mv1;
595 std::vector<int> index(1);
597 for(
int i=0; i<numRHS_; i++) {
599 A1 = MVT::CloneView(A,index);
600 B1 = MVT::CloneView(B,index);
601 mv1 = MVT::CloneViewNonConst(mv,index);
603 MVT::MvAddMv(alpha,*A1,-beta[i],*B1,*mv1);
606 MVT::MvAddMv(alpha,*A1,beta[i],*B1,*mv1);
Pure virtual base class which augments the basic interface for a conjugate gradient linear solver ite...
Belos header file which uses auto-configuration information to include necessary C++ headers.
Class which describes the linear problem to be solved by the iterative solver.
Templated virtual class for providing orthogonalization/orthonormalization methods with matrix-based ...
Declaration of basic traits for the multivector type.
Class which defines basic traits for the operator type.
Class which manages the output and verbosity of the Belos solvers.
Pure virtual base class for defining the status testing capabilities of Belos.
Collection of types and exceptions used within the Belos solvers.
void iterate()
This method performs BiCGStab iterations on each linear system until the status test indicates the ne...
BiCGStabIterationState< ScalarType, MV > getState() const
Get the current state of the linear solver.
bool isInitialized()
States whether the solver has been initialized or not.
MultiVecTraits< ScalarType, MV, DM > MVT
BiCGStabIter(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP, DM > > &problem, const Teuchos::RCP< OutputManager< ScalarType > > &printer, const Teuchos::RCP< StatusTest< ScalarType, MV, OP, DM > > &tester, Teuchos::ParameterList ¶ms)
BiCGStabIter constructor with linear problem, solver utilities, and parameter list of solver options.
int getNumIters() const
Get the current iteration count.
virtual ~BiCGStabIter()
Destructor.
Teuchos::RCP< MV > getCurrentUpdate() const
Get the current update to the linear system.
Teuchos::ScalarTraits< MagnitudeType > MT
const LinearProblem< ScalarType, MV, OP, DM > & getProblem() const
Get a constant reference to the linear problem.
void resetNumIters(int iter=0)
Reset the iteration count.
bool breakdownDetected()
Has breakdown been detected in any linear system.
Teuchos::ScalarTraits< ScalarType > SCT
void setBlockSize(int blockSize)
Set the blocksize.
int getBlockSize() const
Get the blocksize to be used by the iterative solver in solving this linear problem.
void initialize()
Initialize the solver with the initial vectors from the linear problem or random data.
OperatorTraits< ScalarType, MV, OP > OPT
void initializeBiCGStab(BiCGStabIterationState< ScalarType, MV > &newstate)
Initialize the solver to an iterate, providing a complete state.
Teuchos::RCP< const MV > getNativeResiduals(std::vector< MagnitudeType > *) const
SCT::magnitudeType MagnitudeType
Iteration()
Default Constructor.
Traits class which defines basic operations on multivectors.
static void MvInit(MV &mv, const ScalarType alpha=Teuchos::ScalarTraits< ScalarType >::zero())
static Teuchos::RCP< MV > Clone(const MV &mv, const int numvecs)
static void Assign(const MV &A, MV &mv)
static ptrdiff_t GetGlobalLength(const MV &mv)
static void MvDot(const MV &mv, const MV &A, std::vector< ScalarType > &b)
static int GetNumberVecs(const MV &mv)
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...
A pure virtual class for defining the status tests for the Belos iterative solvers.
Structure to contain pointers to BiCGStabIteration state variables.
std::vector< ScalarType > omega
Teuchos::RCP< const MV > R
The current residual.
Teuchos::RCP< const MV > Rhat
The initial residual.
std::vector< ScalarType > rho_old
Teuchos::RCP< const MV > P
The first decent direction vector.
std::vector< ScalarType > alpha
Teuchos::RCP< const MV > V
A * M * the first decent direction vector.