42 #ifndef BELOS_PSEUDO_BLOCK_CG_ITER_HPP 43 #define BELOS_PSEUDO_BLOCK_CG_ITER_HPP 60 #include "Teuchos_BLAS.hpp" 61 #include "Teuchos_SerialDenseMatrix.hpp" 62 #include "Teuchos_SerialDenseVector.hpp" 63 #include "Teuchos_ScalarTraits.hpp" 64 #include "Teuchos_ParameterList.hpp" 65 #include "Teuchos_TimeMonitor.hpp" 80 template<
class ScalarType,
class MV,
class OP>
91 typedef Teuchos::ScalarTraits<ScalarType>
SCT;
105 Teuchos::ParameterList ¶ms );
211 TEUCHOS_TEST_FOR_EXCEPTION(blockSize!=1,std::invalid_argument,
212 "Belos::PseudoBlockCGIter::setBlockSize(): Cannot use a block size that is not one.");
225 const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > lp_;
226 const Teuchos::RCP<OutputManager<ScalarType> > om_;
227 const Teuchos::RCP<StatusTest<ScalarType,MV,OP> > stest_;
247 bool assertPositiveDefiniteness_;
262 Teuchos::RCP<MV> AP_;
268 template<
class ScalarType,
class MV,
class OP>
272 Teuchos::ParameterList ¶ms ):
279 assertPositiveDefiniteness_( params.get(
"Assert Positive Definiteness", true) )
286 template <
class ScalarType,
class MV,
class OP>
290 Teuchos::RCP<const MV> lhsMV = lp_->getCurrLHSVec();
291 Teuchos::RCP<const MV> rhsMV = lp_->getCurrRHSVec();
292 TEUCHOS_TEST_FOR_EXCEPTION((lhsMV==Teuchos::null && rhsMV==Teuchos::null),std::invalid_argument,
293 "Belos::PseudoBlockCGIter::initialize(): Cannot initialize state storage!");
296 Teuchos::RCP<const MV> tmp = ( (rhsMV!=Teuchos::null)? rhsMV: lhsMV );
313 std::string errstr(
"Belos::BlockPseudoCGIter::initialize(): Specified multivectors must have a consistent length and width.");
316 const ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
317 const MagnitudeType zero = Teuchos::ScalarTraits<MagnitudeType>::zero();
319 if (!Teuchos::is_null(newstate.
R)) {
322 std::invalid_argument, errstr );
324 std::invalid_argument, errstr );
327 if (newstate.
R != R_) {
335 if ( lp_->getLeftPrec() != Teuchos::null ) {
336 lp_->applyLeftPrec( *R_, *Z_ );
337 if ( lp_->getRightPrec() != Teuchos::null ) {
338 Teuchos::RCP<MV> tmp1 =
MVT::Clone( *Z_, numRHS_ );
339 lp_->applyRightPrec( *Z_, *tmp1 );
343 else if ( lp_->getRightPrec() != Teuchos::null ) {
344 lp_->applyRightPrec( *R_, *Z_ );
353 TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::is_null(newstate.
R),std::invalid_argument,
354 "Belos::CGIter::initialize(): CGStateIterState does not have initial residual.");
364 template <
class ScalarType,
class MV,
class OP>
370 if (initialized_ ==
false) {
376 std::vector<int> index(1);
377 std::vector<ScalarType> rHz( numRHS_ ), rHz_old( numRHS_ ), pAp( numRHS_ );
378 Teuchos::SerialDenseMatrix<int, ScalarType> alpha( numRHS_,numRHS_ ), beta( numRHS_,numRHS_ );
381 const ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
382 const MagnitudeType zero = Teuchos::ScalarTraits<MagnitudeType>::zero();
385 Teuchos::RCP<MV> cur_soln_vec = lp_->getCurrLHSVec();
390 if ( assertPositiveDefiniteness_ )
391 for (i=0; i<numRHS_; ++i)
392 TEUCHOS_TEST_FOR_EXCEPTION( SCT::real(rHz[i]) < zero,
394 "Belos::PseudoBlockCGIter::iterate(): negative value for r^H*M*r encountered!" );
399 while (stest_->checkStatus(
this) !=
Passed) {
405 lp_->applyOp( *P_, *AP_ );
410 for (i=0; i<numRHS_; ++i) {
411 if ( assertPositiveDefiniteness_ )
413 TEUCHOS_TEST_FOR_EXCEPTION( SCT::real(pAp[i]) <= zero,
415 "Belos::PseudoBlockCGIter::iterate(): non-positive value for p^H*A*p encountered!" );
417 alpha(i,i) = rHz[i] / pAp[i];
424 lp_->updateSolution();
428 for (i=0; i<numRHS_; ++i) {
439 if ( lp_->getLeftPrec() != Teuchos::null ) {
440 lp_->applyLeftPrec( *R_, *Z_ );
441 if ( lp_->getRightPrec() != Teuchos::null ) {
442 Teuchos::RCP<MV> tmp =
MVT::Clone( *Z_, numRHS_ );
443 lp_->applyRightPrec( *Z_, *tmp );
447 else if ( lp_->getRightPrec() != Teuchos::null ) {
448 lp_->applyRightPrec( *R_, *Z_ );
455 if ( assertPositiveDefiniteness_ )
456 for (i=0; i<numRHS_; ++i)
457 TEUCHOS_TEST_FOR_EXCEPTION( SCT::real(rHz[i]) < zero,
459 "Belos::PseudoBlockCGIter::iterate(): negative value for r^H*M*r encountered!" );
462 for (i=0; i<numRHS_; ++i) {
463 beta(i,i) = rHz[i] / rHz_old[i];
Teuchos::RCP< const MV > R
The current residual.
Collection of types and exceptions used within the Belos solvers.
void initialize()
Initialize the solver with the initial vectors from the linear problem or random data.
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.
virtual ~PseudoBlockCGIter()
Destructor.
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 ...
const LinearProblem< ScalarType, MV, OP > & getProblem() const
Get a constant reference to the linear problem.
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.
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).
Declaration of basic traits for the multivector type.
void setBlockSize(int blockSize)
Set the blocksize.
An extension of the MultiVecTraits class that adds a new vector length method.
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.
static int GetNumberVecs(const MV &mv)
Obtain the number of vectors in mv.
OperatorTraits< ScalarType, MV, OP > OPT
static void MvAddMv(const ScalarType alpha, const MV &A, const ScalarType beta, const MV &B, MV &mv)
Replace mv with .
Traits class which defines basic operations on multivectors.
Teuchos::RCP< MV > getCurrentUpdate() const
Get the current update to the linear system.
void resetNumIters(int iter=0)
Reset the iteration count.
This class implements the pseudo-block CG iteration, where the basic CG algorithm is performed on all...
SCT::magnitudeType MagnitudeType
int getBlockSize() const
Get the blocksize to be used by the iterative solver in solving this linear problem.
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 Teuchos::RCP< MV > Clone(const MV &mv, const int numvecs)
Creates a new empty MV containing numvecs columns.
MultiVecTraits< ScalarType, MV > MVT
void iterate()
This method performs CG iterations on each linear system until the status test indicates the need to ...
A linear system to solve, and its associated information.
int getNumIters() const
Get the current iteration count.
Class which describes the linear problem to be solved by the iterative solver.
MultiVecTraitsExt< ScalarType, MV > MVText
Teuchos::ScalarTraits< ScalarType > SCT
void initializeCG(CGIterationState< ScalarType, MV > newstate)
Initialize the solver to an iterate, providing a complete state.
static void MvTimesMatAddMv(const ScalarType alpha, const MV &A, const Teuchos::SerialDenseMatrix< int, ScalarType > &B, const ScalarType beta, MV &mv)
Update mv with .
CGIterationState< ScalarType, MV > getState() const
Get the current state of the linear solver.
Teuchos::RCP< const MV > Z
The current preconditioned residual.
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...
static ptrdiff_t GetGlobalLength(const MV &mv)
Obtain the vector length of mv.
bool isInitialized()
States whether the solver has been initialized or not.
Class which defines basic traits for the operator type.
Teuchos::RCP< const MV > getNativeResiduals(std::vector< MagnitudeType > *norms) const
Get the norms of the residuals native to the solver.
Belos header file which uses auto-configuration information to include necessary C++ headers...
Teuchos::RCP< const MV > P
The current decent direction vector.
Templated virtual class for providing orthogonalization/orthonormalization methods with matrix-based ...