42#ifndef BELOS_PSEUDO_BLOCK_CG_ITER_HPP
43#define BELOS_PSEUDO_BLOCK_CG_ITER_HPP
60#include "Teuchos_SerialDenseMatrix.hpp"
61#include "Teuchos_SerialDenseVector.hpp"
62#include "Teuchos_ScalarTraits.hpp"
63#include "Teuchos_ParameterList.hpp"
64#include "Teuchos_TimeMonitor.hpp"
79 template<
class ScalarType,
class MV,
class OP>
89 typedef Teuchos::ScalarTraits<ScalarType>
SCT;
103 Teuchos::ParameterList ¶ms );
209 TEUCHOS_TEST_FOR_EXCEPTION(blockSize!=1,std::invalid_argument,
210 "Belos::PseudoBlockCGIter::setBlockSize(): Cannot use a block size that is not one.");
228 typedef typename Teuchos::ArrayView<MagnitudeType>::size_type size_type;
229 if (
static_cast<size_type
> (
iter_) >=
diag_.size ()) {
243 typedef typename Teuchos::ArrayView<MagnitudeType>::size_type size_type;
256 const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> >
lp_;
257 const Teuchos::RCP<OutputManager<ScalarType> >
om_;
258 const Teuchos::RCP<StatusTest<ScalarType,MV,OP> >
stest_;
305 template<
class ScalarType,
class MV,
class OP>
309 Teuchos::ParameterList ¶ms ):
325 template <
class ScalarType,
class MV,
class OP>
329 Teuchos::RCP<const MV> lhsMV =
lp_->getCurrLHSVec();
330 Teuchos::RCP<const MV> rhsMV =
lp_->getCurrRHSVec();
331 TEUCHOS_TEST_FOR_EXCEPTION((lhsMV==Teuchos::null && rhsMV==Teuchos::null),std::invalid_argument,
332 "Belos::PseudoBlockCGIter::initialize(): Cannot initialize state storage!");
335 Teuchos::RCP<const MV> tmp = ( (rhsMV!=Teuchos::null)? rhsMV: lhsMV );
358 std::string errstr(
"Belos::BlockPseudoCGIter::initialize(): Specified multivectors must have a consistent length and width.");
361 const ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
362 const MagnitudeType zero = Teuchos::ScalarTraits<MagnitudeType>::zero();
364 if (!Teuchos::is_null(newstate.
R)) {
367 std::invalid_argument, errstr );
369 std::invalid_argument, errstr );
372 if (newstate.
R !=
R_) {
380 if (
lp_->getLeftPrec() != Teuchos::null ) {
381 lp_->applyLeftPrec( *
R_, *
Z_ );
382 if (
lp_->getRightPrec() != Teuchos::null ) {
384 lp_->applyRightPrec( *
Z_, *tmp1 );
388 else if (
lp_->getRightPrec() != Teuchos::null ) {
389 lp_->applyRightPrec( *
R_, *
Z_ );
398 TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::is_null(newstate.
R),std::invalid_argument,
399 "Belos::CGIter::initialize(): CGStateIterState does not have initial residual.");
409 template <
class ScalarType,
class MV,
class OP>
421 std::vector<int> index(1);
423 Teuchos::SerialDenseMatrix<int, ScalarType> alpha(
numRHS_,
numRHS_ );
426 const ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
427 const MagnitudeType zero = Teuchos::ScalarTraits<MagnitudeType>::zero();
430 Teuchos::RCP<MV> cur_soln_vec =
lp_->getCurrLHSVec();
437 TEUCHOS_TEST_FOR_EXCEPTION( SCT::real(rHz[i]) < zero,
439 "Belos::PseudoBlockCGIter::iterate(): negative value for r^H*M*r encountered!" );
458 TEUCHOS_TEST_FOR_EXCEPTION( SCT::real(pAp[i]) <= zero,
460 "Belos::PseudoBlockCGIter::iterate(): non-positive value for p^H*A*p encountered!" );
462 alpha(i,i) = rHz[i] / pAp[i];
469 lp_->updateSolution();
484 if (
lp_->getLeftPrec() != Teuchos::null ) {
485 lp_->applyLeftPrec( *
R_, *
Z_ );
486 if (
lp_->getRightPrec() != Teuchos::null ) {
488 lp_->applyRightPrec( *
Z_, *tmp );
492 else if (
lp_->getRightPrec() != Teuchos::null ) {
493 lp_->applyRightPrec( *
R_, *
Z_ );
502 TEUCHOS_TEST_FOR_EXCEPTION( SCT::real(rHz[i]) < zero,
504 "Belos::PseudoBlockCGIter::iterate(): negative value for r^H*M*r encountered!" );
508 beta[i] = rHz[i] / rHz_old[i];
522 diag_[
iter_-1] = Teuchos::ScalarTraits<ScalarType>::real(pAp[0] / rHz_old[0]);
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.
CGPositiveDefiniteFailure is thrown when the the CG 'alpha = p^H*A*P' value is less than zero,...
Traits class which defines basic operations on multivectors.
static void MvTimesMatAddMv(const ScalarType alpha, const MV &A, const Teuchos::SerialDenseMatrix< int, ScalarType > &B, const ScalarType beta, MV &mv)
Update mv with .
static ptrdiff_t GetGlobalLength(const MV &mv)
Return the number of rows in the given multivector mv.
static void MvDot(const MV &mv, const MV &A, std::vector< ScalarType > &b)
Compute a vector b where the components are the individual dot-products of the i-th columns of A and ...
static Teuchos::RCP< MV > Clone(const MV &mv, const int numvecs)
Creates a new empty MV containing numvecs columns.
static Teuchos::RCP< const MV > CloneView(const MV &mv, const std::vector< int > &index)
Creates a new const MV that shares the selected contents of mv (shallow copy).
static Teuchos::RCP< MV > CloneViewNonConst(MV &mv, const std::vector< int > &index)
Creates a new MV that shares the selected contents of mv (shallow copy).
static void MvAddMv(const ScalarType alpha, const MV &A, const ScalarType beta, const MV &B, MV &mv)
Replace mv with .
static int GetNumberVecs(const MV &mv)
Obtain the number of vectors in 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...
int numEntriesForCondEst_
void resetNumIters(int iter=0)
Reset the iteration count.
int getNumIters() const
Get the current iteration count.
const Teuchos::RCP< StatusTest< ScalarType, MV, OP > > stest_
bool isInitialized()
States whether the solver has been initialized or not.
CGIterationState< ScalarType, MV > getState() const
Get the current state of the linear solver.
PseudoBlockCGIter(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)
PseudoBlockCGIter constructor with linear problem, solver utilities, and parameter list of solver opt...
Teuchos::ArrayView< MagnitudeType > getOffDiag()
Gets the off-diagonal for condition estimation.
Teuchos::ScalarTraits< ScalarType > SCT
Teuchos::ArrayView< MagnitudeType > getDiag()
Gets the diagonal for condition estimation.
void initializeCG(CGIterationState< ScalarType, MV > &newstate)
Initialize the solver to an iterate, providing a complete state.
const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > lp_
SCT::magnitudeType MagnitudeType
void iterate()
This method performs CG iterations on each linear system until the status test indicates the need to ...
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.
const Teuchos::RCP< OutputManager< ScalarType > > om_
Teuchos::ArrayRCP< MagnitudeType > offdiag_
virtual ~PseudoBlockCGIter()
Destructor.
void setDoCondEst(bool val)
Sets whether or not to store the diagonal for condition estimation.
Teuchos::RCP< const MV > getNativeResiduals(std::vector< MagnitudeType > *) const
int getBlockSize() const
Get the blocksize to be used by the iterative solver in solving this linear problem.
const LinearProblem< ScalarType, MV, OP > & getProblem() const
Get a constant reference to the linear problem.
Teuchos::ArrayRCP< MagnitudeType > diag_
MultiVecTraits< ScalarType, MV > MVT
void setBlockSize(int blockSize)
Set the blocksize.
OperatorTraits< ScalarType, MV, OP > OPT
bool assertPositiveDefiniteness_
A pure virtual class for defining the status tests for the Belos iterative solvers.
Structure to contain pointers to CGIteration state variables.
Teuchos::RCP< const MV > P
The current decent direction vector.
Teuchos::RCP< const MV > R
The current residual.
Teuchos::RCP< const MV > Z
The current preconditioned residual.
Teuchos::RCP< const MV > AP
The matrix A applied to current decent direction vector.