10#ifndef BELOS_RCG_ITER_HPP
11#define BELOS_RCG_ITER_HPP
28#include "Teuchos_LAPACK.hpp"
29#include "Teuchos_SerialDenseMatrix.hpp"
30#include "Teuchos_SerialDenseVector.hpp"
31#include "Teuchos_ScalarTraits.hpp"
32#include "Teuchos_ParameterList.hpp"
33#include "Teuchos_TimeMonitor.hpp"
59 template <
class ScalarType,
class MV>
83 Teuchos::RCP<MV>
U,
AU;
87 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> >
Alpha;
88 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> >
Beta;
89 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> >
D;
90 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> >
rTz_old;
93 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> >
Delta;
96 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> >
LUUTAU;
98 Teuchos::RCP<std::vector<int> >
ipiv;
104 U(Teuchos::null),
AU(Teuchos::null),
105 Alpha(Teuchos::null),
Beta(Teuchos::null),
D(Teuchos::null),
rTz_old(Teuchos::null),
112 template<
class ScalarType,
class MV,
class OP>
122 typedef Teuchos::ScalarTraits<ScalarType>
SCT;
138 Teuchos::ParameterList ¶ms );
212 if (!initialized_)
return 0;
245 TEUCHOS_TEST_FOR_EXCEPTION(blockSize!=1,std::invalid_argument,
246 "Belos::RCGIter::setBlockSize(): Cannot use a block size that is not one.");
250 void setSize(
int recycleBlocks,
int numBlocks );
266 const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > lp_;
267 const Teuchos::RCP<OutputManager<ScalarType> > om_;
268 const Teuchos::RCP<StatusTest<ScalarType,MV,OP> > stest_;
297 Teuchos::RCP<MV> Ap_;
308 Teuchos::RCP<MV> U_, AU_;
311 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > Alpha_,Beta_,D_;
314 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > Delta_;
317 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > LUUTAU_;
320 Teuchos::RCP<std::vector<int> > ipiv_;
323 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > rTz_old_;
328 template<
class ScalarType,
class MV,
class OP>
332 Teuchos::ParameterList ¶ms ):
344 TEUCHOS_TEST_FOR_EXCEPTION(!params.isParameter(
"Num Blocks"), std::invalid_argument,
345 "Belos::RCGIter::constructor: mandatory parameter \"Num Blocks\" is not specified.");
346 int nb = Teuchos::getParameter<int>(params,
"Num Blocks");
348 TEUCHOS_TEST_FOR_EXCEPTION(!params.isParameter(
"Recycled Blocks"), std::invalid_argument,
349 "Belos::RCGIter::constructor: mandatory parameter \"Recycled Blocks\" is not specified.");
350 int rb = Teuchos::getParameter<int>(params,
"Recycled Blocks");
358 template <
class ScalarType,
class MV,
class OP>
362 TEUCHOS_TEST_FOR_EXCEPTION(numBlocks <= 0, std::invalid_argument,
"Belos::RCGIter::setSize() was passed a non-positive argument for \"Num Blocks\".");
363 TEUCHOS_TEST_FOR_EXCEPTION(recycleBlocks <= 0, std::invalid_argument,
"Belos::RCGIter::setSize() was passed a non-positive argument for \"Recycled Blocks\".");
364 TEUCHOS_TEST_FOR_EXCEPTION(recycleBlocks >= numBlocks, std::invalid_argument,
"Belos::RCGIter::setSize() the number of recycled blocks is larger than the allowable subspace.");
366 numBlocks_ = numBlocks;
367 recycleBlocks_ = recycleBlocks;
373 template <
class ScalarType,
class MV,
class OP>
377 if (newstate.
P != Teuchos::null &&
378 newstate.
Ap != Teuchos::null &&
379 newstate.
r != Teuchos::null &&
380 newstate.
z != Teuchos::null &&
381 newstate.
U != Teuchos::null &&
382 newstate.
AU != Teuchos::null &&
383 newstate.
Alpha != Teuchos::null &&
384 newstate.
Beta != Teuchos::null &&
385 newstate.
D != Teuchos::null &&
386 newstate.
Delta != Teuchos::null &&
387 newstate.
LUUTAU != Teuchos::null &&
388 newstate.
ipiv != Teuchos::null &&
389 newstate.
rTz_old != Teuchos::null) {
391 curDim_ = newstate.
curDim;
396 existU_ = newstate.
existU;
399 Alpha_ = newstate.
Alpha;
400 Beta_ = newstate.
Beta;
402 Delta_ = newstate.
Delta;
403 LUUTAU_ = newstate.
LUUTAU;
404 ipiv_ = newstate.
ipiv;
409 TEUCHOS_TEST_FOR_EXCEPTION(newstate.
P == Teuchos::null,std::invalid_argument,
410 "Belos::RCGIter::initialize(): RCGIterState does not have P initialized.");
412 TEUCHOS_TEST_FOR_EXCEPTION(newstate.
Ap == Teuchos::null,std::invalid_argument,
413 "Belos::RCGIter::initialize(): RCGIterState does not have Ap initialized.");
415 TEUCHOS_TEST_FOR_EXCEPTION(newstate.
r == Teuchos::null,std::invalid_argument,
416 "Belos::RCGIter::initialize(): RCGIterState does not have r initialized.");
418 TEUCHOS_TEST_FOR_EXCEPTION(newstate.
z == Teuchos::null,std::invalid_argument,
419 "Belos::RCGIter::initialize(): RCGIterState does not have z initialized.");
421 TEUCHOS_TEST_FOR_EXCEPTION(newstate.
U == Teuchos::null,std::invalid_argument,
422 "Belos::RCGIter::initialize(): RCGIterState does not have U initialized.");
424 TEUCHOS_TEST_FOR_EXCEPTION(newstate.
AU == Teuchos::null,std::invalid_argument,
425 "Belos::RCGIter::initialize(): RCGIterState does not have AU initialized.");
427 TEUCHOS_TEST_FOR_EXCEPTION(newstate.
Alpha == Teuchos::null,std::invalid_argument,
428 "Belos::RCGIter::initialize(): RCGIterState does not have Alpha initialized.");
430 TEUCHOS_TEST_FOR_EXCEPTION(newstate.
Beta == Teuchos::null,std::invalid_argument,
431 "Belos::RCGIter::initialize(): RCGIterState does not have Beta initialized.");
433 TEUCHOS_TEST_FOR_EXCEPTION(newstate.
D == Teuchos::null,std::invalid_argument,
434 "Belos::RCGIter::initialize(): RCGIterState does not have D initialized.");
436 TEUCHOS_TEST_FOR_EXCEPTION(newstate.
Delta == Teuchos::null,std::invalid_argument,
437 "Belos::RCGIter::initialize(): RCGIterState does not have Delta initialized.");
439 TEUCHOS_TEST_FOR_EXCEPTION(newstate.
LUUTAU == Teuchos::null,std::invalid_argument,
440 "Belos::RCGIter::initialize(): RCGIterState does not have LUUTAU initialized.");
442 TEUCHOS_TEST_FOR_EXCEPTION(newstate.
ipiv == Teuchos::null,std::invalid_argument,
443 "Belos::RCGIter::initialize(): RCGIterState does not have ipiv initialized.");
445 TEUCHOS_TEST_FOR_EXCEPTION(newstate.
rTz_old == Teuchos::null,std::invalid_argument,
446 "Belos::RCGIter::initialize(): RCGIterState does not have rTz_old initialized.");
457 template <
class ScalarType,
class MV,
class OP>
461 "Belos::RCGIter::iterate(): RCGIter class not initialized." );
464 Teuchos::LAPACK<int,ScalarType> lapack;
467 ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
468 ScalarType zero = Teuchos::ScalarTraits<ScalarType>::zero();
471 std::vector<int> index(1);
472 Teuchos::SerialDenseMatrix<int,ScalarType> pAp(1,1), rTz(1,1);
475 Teuchos::RCP<MV> cur_soln_vec = lp_->getCurrLHSVec();
479 "Belos::RCGIter::iterate(): current linear system has more than one std::vector!" );
482 int searchDim = numBlocks_+1;
492 Teuchos::RCP<const MV> p_ = Teuchos::null;
493 Teuchos::RCP<MV> pnext_ = Teuchos::null;
494 while (stest_->checkStatus(
this) !=
Passed && curDim_+1 <= searchDim) {
500 lp_->applyOp( *p_, *Ap_ );
504 (*D_)(i_,0) = pAp(0,0);
507 (*Alpha_)(i_,0) = (*rTz_old_)(0,0) / pAp(0,0);
511 "Belos::RCGIter::iterate(): non-positive value for p^H*A*p encountered!" );
514 MVT::MvAddMv( one, *cur_soln_vec, (*Alpha_)(i_,0), *p_, *cur_soln_vec );
515 lp_->updateSolution();
520 std::vector<MagnitudeType> norm(1);
525 if ( lp_->getLeftPrec() != Teuchos::null ) {
526 lp_->applyLeftPrec( *r_, *z_ );
528 else if ( lp_->getRightPrec() != Teuchos::null ) {
529 lp_->applyRightPrec( *r_, *z_ );
539 (*Beta_)(i_,0) = rTz(0,0) / (*rTz_old_)(0,0);
542 (*rTz_old_)(0,0) = rTz(0,0);
551 Teuchos::SerialDenseMatrix<int,ScalarType> mu( Teuchos::View, *Delta_, recycleBlocks_, 1, 0, i_ );
555 lapack.GETRS(
TRANS, recycleBlocks_, 1, LUUTAU_->values(), LUUTAU_->stride(), &(*ipiv_)[0], mu.values(), mu.stride(), &info );
557 "Belos::RCGIter::solve(): LAPACK GETRS failed to compute a solution.");
571 pnext_ = Teuchos::null;
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.
CGIterateFailure is thrown when the CGIteration object is unable to compute the next iterate in the C...
CGIterationLAPACKFailure is thrown when a nonzero return value is passed back from an LAPACK routine.
CGPositiveDefiniteFailure is thrown when the the CG 'alpha = p^H*A*P' value is less than zero,...
Iteration()
Default Constructor.
Traits class which defines basic operations on multivectors.
static void MvTransMv(const ScalarType alpha, const MV &A, const MV &mv, Teuchos::SerialDenseMatrix< int, ScalarType > &B)
Compute a dense matrix B through the matrix-matrix multiply .
static void MvTimesMatAddMv(const ScalarType alpha, const MV &A, const Teuchos::SerialDenseMatrix< int, ScalarType > &B, const ScalarType beta, MV &mv)
Update mv with .
static void MvNorm(const MV &mv, std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &normvec, NormType type=TwoNorm)
Compute the norm of each individual vector of mv. Upon return, normvec[i] holds the value of ,...
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...
Teuchos::ScalarTraits< ScalarType > SCT
OperatorTraits< ScalarType, MV, OP > OPT
Teuchos::RCP< MV > getCurrentUpdate() const
Get the current update to the linear system.
MultiVecTraits< ScalarType, MV > MVT
int getMaxSubspaceDim() const
Get the maximum dimension allocated for the search subspace.
virtual ~RCGIter()
Destructor.
void resetNumIters(int iter=0)
Reset the iteration count.
void setSize(int recycleBlocks, int numBlocks)
Set the maximum number of blocks used by the iterative solver and the number of recycled vectors.
bool isInitialized()
States whether the solver has been initialized or not.
int getNumBlocks() const
Get the maximum number of blocks used by the iterative solver in solving this linear problem.
int getNumIters() const
Get the current iteration count.
void setBlockSize(int blockSize)
Set the blocksize.
void setRecycledBlocks(int recycleBlocks)
Set the maximum number of recycled blocks used by the iterative solver.
void setNumBlocks(int numBlocks)
Set the maximum number of blocks used by the iterative solver.
int getCurSubspaceDim() const
Get the dimension of the search subspace used to generate the current solution to the linear problem.
SCT::magnitudeType MagnitudeType
void initialize()
Initialize the solver with the initial vectors from the linear problem or random data.
int getRecycledBlocks() const
Get the maximum number of recycled blocks used by the iterative solver in solving this linear problem...
void iterate()
This method performs RCG iterations until the status test indicates the need to stop or an error occu...
RCGIter(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)
RCGIter constructor with linear problem, solver utilities, and parameter list of solver options.
const LinearProblem< ScalarType, MV, OP > & getProblem() const
Get a constant reference to the linear problem.
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.
A pure virtual class for defining the status tests for the Belos iterative solvers.
Structure to contain pointers to RCGIter state variables.
bool existU
Flag to indicate the recycle space should be used.
Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > Beta
Teuchos::RCP< MV > U
The recycled subspace and its image.
Teuchos::RCP< MV > Ap
A times current search vector.
Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > Delta
Solutions to local least-squares problems.
Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > D
int curDim
The current dimension of the reduction.
Teuchos::RCP< MV > r
The current residual.
Teuchos::RCP< std::vector< int > > ipiv
Data from LU factorization of U^T A U.
Teuchos::RCP< MV > z
The current preconditioned residual.
Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > LUUTAU
The LU factorization of the matrix U^T A U.
Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > rTz_old
Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > Alpha
Coefficients arising in RCG iteration.
Teuchos::RCP< MV > P
The current Krylov basis.