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;
78 template<
class ScalarType,
class MV,
class OP,
class DM>
88 typedef Teuchos::ScalarTraits<ScalarType>
SCT;
90 typedef Teuchos::ScalarTraits<MagnitudeType>
MT;
103 Teuchos::ParameterList &
params );
172 state.rho_old = rho_old_;
173 state.alpha = alpha_;
174 state.omega = omega_;
218 "Belos::BiCGStabIter::setBlockSize(): Cannot use a block size that is not one.");
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();
303 "Belos::BiCGStabIter::initialize(): Cannot initialize state storage!");
314 if (Teuchos::is_null(R_) || MVT::GetNumberVecs(*R_)!=numRHS_) {
315 R_ = MVT::Clone( *
tmp, numRHS_ );
316 Rhat_ = MVT::Clone( *
tmp, numRHS_ );
317 P_ = MVT::Clone( *
tmp, numRHS_ );
318 V_ = MVT::Clone( *
tmp, numRHS_ );
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.");
335 if (!Teuchos::is_null(
newstate.R)) {
338 std::invalid_argument,
errstr );
340 std::invalid_argument,
errstr );
349 lp_->computeCurrResVec(R_.get());
355 MVT::Assign(*
newstate.Rhat, *Rhat_);
359 MVT::Assign(*R_, *Rhat_);
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_)) {
399 alpha_.assign(numRHS_,
one);
403 if (
newstate.omega.size() ==
static_cast<size_t> (numRHS_)) {
409 omega_.assign(numRHS_,
one);
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_ );
450 S = MVT::Clone( *R_, numRHS_ );
451 T = MVT::Clone( *R_, numRHS_ );
452 if (lp_->isLeftPrec() || lp_->isRightPrec()) {
453 Y = MVT::Clone( *R_, numRHS_ );
454 Z = MVT::Clone( *R_, numRHS_ );
462 Teuchos::RCP<MV>
X = lp_->getCurrLHSVec();
467 while (stest_->checkStatus(
this) !=
Passed && !breakdown_) {
473 MVT::MvDot(*R_,*Rhat_,
rho_new);
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()) {
503 lp_->applyLeftPrec(*P_,*Y);
506 else if(lp_->isRightPrec()) {
507 lp_->applyRightPrec(*P_,*Y);
511 lp_->applyOp(*Y,*V_);
514 MVT::MvDot(*V_,*Rhat_,
rhatV);
515 for(
i=0;
i<numRHS_;
i++) {
516 if (SCT::magnitude(
rhatV[
i]) < MT::sfmin())
526 axpy(
one, *R_, alpha_, *V_, *S,
true);
529 if(lp_->isLeftPrec()) {
530 if(lp_->isRightPrec()) {
538 lp_->applyLeftPrec(*S,*Z);
541 else if(lp_->isRightPrec()) {
542 lp_->applyRightPrec(*S,*Z);
549 if(lp_->isLeftPrec()) {
561 MVT::MvDot(*T,*T,
tT);
562 MVT::MvDot(*S,*T,
tS);
564 for(
i=0;
i<numRHS_;
i++) {
565 if (SCT::magnitude(
tT[
i]) < MT::sfmin())
567 omega_[
i] = SCT::zero();
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>
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.
This class implements the pseudo-block BiCGStab iteration, where the basic BiCGStab algorithm is perf...
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
Get the norms of the residuals native to the solver.
SCT::magnitudeType MagnitudeType
Alternative run-time polymorphic interface for operators.
Operator()
Default constructor (does nothing).
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.