10#ifndef BELOS_GCRODR_ITER_HPP
11#define BELOS_GCRODR_ITER_HPP
27#include "Teuchos_BLAS.hpp"
28#include "Teuchos_SerialDenseMatrix.hpp"
29#include "Teuchos_SerialDenseVector.hpp"
30#include "Teuchos_ScalarTraits.hpp"
31#include "Teuchos_ParameterList.hpp"
32#include "Teuchos_TimeMonitor.hpp"
55 template <
class ScalarType,
class MV>
67 Teuchos::RCP<MV>
U,
C;
74 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> >
H;
78 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> >
B;
121 template<
class ScalarType,
class MV,
class OP>
131 typedef Teuchos::ScalarTraits<ScalarType>
SCT;
149 Teuchos::ParameterList &
params );
222 state.curDim = curDim_;
263 if (!initialized_)
return 0;
305 cs_.sizeUninitialized( numBlocks_+1 );
306 sn_.sizeUninitialized( numBlocks_+1 );
307 z_.sizeUninitialized( numBlocks_+1 );
308 R_.shapeUninitialized( numBlocks_+1,
numBlocks );
326 const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > lp_;
327 const Teuchos::RCP<OutputManager<ScalarType> > om_;
328 const Teuchos::RCP<StatusTest<ScalarType,MV,OP> > stest_;
329 const Teuchos::RCP<OrthoManager<ScalarType,MV> > ortho_;
341 Teuchos::SerialDenseVector<int,ScalarType> sn_;
342 Teuchos::SerialDenseVector<int,MagnitudeType> cs_;
362 Teuchos::RCP<MV> U_, C_;
366 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > H_;
369 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B_;
374 Teuchos::SerialDenseMatrix<int,ScalarType> R_;
375 Teuchos::SerialDenseVector<int,ScalarType> z_;
380 template<
class ScalarType,
class MV,
class OP>
385 Teuchos::ParameterList &
params ):
389 initialized_ =
false;
399 TEUCHOS_TEST_FOR_EXCEPTION(!
params.isParameter(
"Num Blocks"), std::invalid_argument,
"Belos::GCRODRIter::constructor: mandatory parameter \"Num Blocks\" is not specified.");
400 int nb = Teuchos::getParameter<int>(
params,
"Num Blocks");
402 TEUCHOS_TEST_FOR_EXCEPTION(!
params.isParameter(
"Recycled Blocks"), std::invalid_argument,
"Belos::GCRODRIter::constructor: mandatory parameter \"Recycled Blocks\" is not specified.");
403 int rb = Teuchos::getParameter<int>(
params,
"Recycled Blocks");
405 TEUCHOS_TEST_FOR_EXCEPTION(
nb <= 0, std::invalid_argument,
"Belos::GCRODRIter() was passed a non-positive argument for \"Num Blocks\".");
406 TEUCHOS_TEST_FOR_EXCEPTION(
rb >=
nb, std::invalid_argument,
"Belos::GCRODRIter() the number of recycled blocks is larger than the allowable subspace.");
409 recycledBlocks_ =
rb;
411 cs_.sizeUninitialized( numBlocks_+1 );
412 sn_.sizeUninitialized( numBlocks_+1 );
413 z_.sizeUninitialized( numBlocks_+1 );
414 R_.shapeUninitialized( numBlocks_+1,numBlocks_ );
420 template <
class ScalarType,
class MV,
class OP>
430 const ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
431 const ScalarType zero = Teuchos::ScalarTraits<ScalarType>::zero();
432 Teuchos::BLAS<int,ScalarType>
blas;
437 Teuchos::SerialDenseMatrix<int,ScalarType> y( Teuchos::Copy, z_, curDim_, 1 );
441 blas.TRSM( Teuchos::LEFT_SIDE, Teuchos::UPPER_TRI, Teuchos::NO_TRANS,
442 Teuchos::NON_UNIT_DIAG, curDim_, 1,
one,
443 R_.values(), R_.stride(), y.values(), y.stride() );
447 std::vector<int> index(curDim_);
448 for (
int i=0;
i<curDim_;
i++ ) index[
i] =
i;
449 Teuchos::RCP<const MV>
Vjp1 = MVT::CloneView( *V_, index );
454 if (U_ != Teuchos::null) {
455 Teuchos::SerialDenseMatrix<int,ScalarType> z(recycledBlocks_,1);
456 Teuchos::SerialDenseMatrix<int,ScalarType>
subB( Teuchos::View, *B_, recycledBlocks_, curDim_ );
457 z.multiply( Teuchos::NO_TRANS, Teuchos::NO_TRANS,
one,
subB, y,
zero );
468 template <
class ScalarType,
class MV,
class OP>
477 Teuchos::BLAS<int,ScalarType>
blas;
478 (*norms)[0] =
blas.NRM2( 1, &z_(curDim_), 1);
480 return Teuchos::null;
487 template <
class ScalarType,
class MV,
class OP>
511 template <
class ScalarType,
class MV,
class OP>
517 setSize( recycledBlocks_, numBlocks_ );
519 Teuchos::RCP<MV>
Vnext;
520 Teuchos::RCP<const MV>
Vprev;
521 std::vector<int>
curind(1);
531 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> >
z0 =
532 Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>(1,1) );
538 std::vector<int>
prevind(numBlocks_+1);
545 if (U_ == Teuchos::null) {
546 while (stest_->checkStatus(
this) !=
Passed && curDim_+1 <= numBlocks_) {
567 Teuchos::Array<Teuchos::RCP<const MV> >
AVprev(1,
Vprev);
570 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> >
571 subH = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType> ( Teuchos::View,*H_,
lclDim,1,0,curDim_ ) );
572 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > >
AsubH;
576 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> >
577 subR = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType> ( Teuchos::View,*H_,1,1,
lclDim,curDim_ ) );
583 Teuchos::SerialDenseMatrix<int,ScalarType>
subR2( Teuchos::View,R_,
lclDim+1,1,0,curDim_ );
584 Teuchos::SerialDenseMatrix<int,ScalarType>
subH2( Teuchos::View,*H_,
lclDim+1,1,0,curDim_ );
597 while (stest_->checkStatus(
this) !=
Passed && curDim_+1 <= numBlocks_) {
612 Vprev = Teuchos::null;
615 Teuchos::Array<Teuchos::RCP<const MV> > C(1, C_);
616 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> >
617 subB = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType> ( Teuchos::View,*B_,recycledBlocks_,1,0,curDim_ ) );
618 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > >
AsubB;
629 Teuchos::Array<Teuchos::RCP<const MV> >
AVprev(1,
Vprev);
632 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> >
subH = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType> ( Teuchos::View,*H_,
lclDim,1,0,curDim_ ) );
633 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > >
AsubH;
637 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> >
subR = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType> ( Teuchos::View,*H_,1,1,
lclDim,curDim_ ) );
643 Teuchos::SerialDenseMatrix<int,ScalarType>
subR2( Teuchos::View,R_,
lclDim+1,1,0,curDim_ );
644 Teuchos::SerialDenseMatrix<int,ScalarType>
subH2( Teuchos::View,*H_,
lclDim+1,1,0,curDim_ );
661 template<
class ScalarType,
class MV,
class OP>
665 const ScalarType zero = Teuchos::ScalarTraits<ScalarType>::zero();
670 int curDim = curDim_;
671 if ( (
dim >= curDim_) && (
dim < getMaxSubspaceDim()) )
674 Teuchos::BLAS<int, ScalarType>
blas;
681 for (
i=0;
i<curDim;
i++) {
685 blas.ROT( 1, &R_(
i,curDim), 1, &R_(
i+1, curDim), 1, &cs_[
i], &sn_[
i] );
690 blas.ROTG( &R_(curDim,curDim), &R_(curDim+1,curDim), &cs_[curDim], &sn_[curDim] );
691 R_(curDim+1,curDim) =
zero;
695 blas.ROT( 1, &z_(curDim), 1, &z_(curDim+1), 1, &cs_[curDim], &sn_[curDim] );
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.
Parent class to all Belos exceptions.
GCRODRIterInitFailure is thrown when the GCRODRIter object is unable to generate an initial iterate i...
GCRODRIterInitFailure(const std::string &what_arg)
GCRODRIterOrthoFailure is thrown when the GCRODRIter object is unable to compute independent directio...
GCRODRIterOrthoFailure(const std::string &what_arg)
This class implements the GCRODR iteration, where a single-std::vector Krylov subspace is constructed...
int getNumBlocks() const
Get the maximum number of blocks used by the iterative solver in solving this linear problem.
virtual ~GCRODRIter()
Destructor.
void setRecycledBlocks(int recycledBlocks)
Set the maximum number of recycled blocks used by the iterative solver.
Teuchos::RCP< MV > getCurrentUpdate() const
Get the current update to the linear system.
const LinearProblem< ScalarType, MV, OP > & getProblem() const
Get a constant reference to the linear problem.
void setBlockSize(int blockSize)
Set the blocksize.
int getCurSubspaceDim() const
Get the dimension of the search subspace used to generate the current solution to the linear problem.
void setNumBlocks(int numBlocks)
Set the maximum number of blocks used by the iterative solver.
OperatorTraits< ScalarType, MV, OP > OPT
void resetNumIters(int iter=0)
Reset the iteration count.
GCRODRIterState< ScalarType, MV > getState() const
Get the current state of the linear solver.
int getRecycledBlocks() const
Get the maximum number of recycled blocks used by the iterative solver in solving this linear problem...
Teuchos::ScalarTraits< ScalarType > SCT
int getBlockSize() const
Get the blocksize to be used by the iterative solver in solving this linear problem.
int getMaxSubspaceDim() const
Get the maximum dimension allocated for the search subspace.
bool isInitialized()
States whether the solver has been initialized or not.
MultiVecTraits< ScalarType, MV > MVT
int getNumIters() const
Get the current iteration count.
GCRODRIter(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem, const Teuchos::RCP< OutputManager< ScalarType > > &printer, const Teuchos::RCP< StatusTest< ScalarType, MV, OP > > &tester, const Teuchos::RCP< MatOrthoManager< ScalarType, MV, OP > > &ortho, Teuchos::ParameterList ¶ms)
GCRODRIter constructor with linear problem, solver utilities, and parameter list of solver options.
void initialize()
Initialize the solver with empty data. Calling this method will result in error, as GCRODRIter must b...
void iterate()
This method performs block Gmres iterations until the status test indicates the need to stop or an er...
void setSize(int recycledBlocks, int numBlocks)
Set the maximum number of blocks used by the iterative solver and the number of recycled vectors.
Teuchos::RCP< const MV > getNativeResiduals(std::vector< MagnitudeType > *norms) const
Get the norms of the residuals native to the solver.
void updateLSQR(int dim=-1)
Method for updating QR factorization of upper Hessenberg matrix.
SCT::magnitudeType MagnitudeType
Alternative run-time polymorphic interface for operators.
Operator()
Default constructor (does nothing).
Structure to contain pointers to GCRODRIter state variables.
Teuchos::RCP< MV > U
The recycled subspace and its projection.
Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > B
The projection of the Krylov subspace against the recycled subspace.
Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > H
The current Hessenberg matrix.
Teuchos::RCP< MV > V
The current Krylov basis.
int curDim
The current dimension of the reduction.