10#ifndef BELOS_BLOCK_GCRODR_ITER_HPP
11#define BELOS_BLOCK_GCRODR_ITER_HPP
28#include "Teuchos_BLAS.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"
62 template <
class ScalarType,
class MV>
75 Teuchos::RCP<MV>
U,
C;
82 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> >
H;
86 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> >
B;
134 template<
class ScalarType,
class MV,
class OP,
class DM = DefaultDenseMatrix<
int,ScalarType> >
143 typedef Teuchos::ScalarTraits<ScalarType>
SCT;
145 typedef Teuchos::SerialDenseMatrix<int,ScalarType>
SDM;
146 typedef Teuchos::SerialDenseVector<int,ScalarType>
SDV;
163 Teuchos::ParameterList &
params );
236 state.curDim = curDim_;
289 if (!initialized_)
return 0;
316 cs_.resize( numBlocks_ );
317 sn_.resize( numBlocks_ );
318 Z_.shapeUninitialized( numBlocks_*blockSize_, blockSize_ );
334 const Teuchos::RCP<LinearProblem<ScalarType,MV,OP,DM> > lp_;
335 const Teuchos::RCP<OutputManager<ScalarType> > om_;
336 const Teuchos::RCP<StatusTest<ScalarType,MV,OP> > stest_;
337 const Teuchos::RCP<OrthoManager<ScalarType,MV> > ortho_;
345 int numBlocks_, blockSize_;
350 std::vector<bool> trueRHSIndices_;
356 std::vector<ScalarType> sn_;
357 std::vector<MagnitudeType> cs_;
364 std::vector< SDM >House_;
375 int curDim_, iter_, lclIter_;
386 Teuchos::RCP<MV> U_, C_;
395 Teuchos::RCP<SDM > H_;
400 Teuchos::RCP<SDM > B_;
408 Teuchos::RCP<SDM> R_;
423 template<
class ScalarType,
class MV,
class OP,
class DM>
433 initialized_ =
false;
444 TEUCHOS_TEST_FOR_EXCEPTION(!
params.isParameter(
"Num Blocks"), std::invalid_argument,
"Belos::BlockGCRODRIter::constructor: mandatory parameter \"Num Blocks\" is not specified.");
445 int nb = Teuchos::getParameter<int>(
params,
"Num Blocks");
447 TEUCHOS_TEST_FOR_EXCEPTION(!
params.isParameter(
"Recycled Blocks"), std::invalid_argument,
"Belos::BlockGCRODRIter::constructor: mandatory parameter \"Recycled Blocks\" is not specified.");
448 int rb = Teuchos::getParameter<int>(
params,
"Recycled Blocks");
450 TEUCHOS_TEST_FOR_EXCEPTION(
nb <= 0, std::invalid_argument,
"Belos::BlockGCRODRIter() was passed a non-positive argument for \"Num Blocks\".");
451 TEUCHOS_TEST_FOR_EXCEPTION(
rb >=
nb, std::invalid_argument,
"Belos::BlockGCRODRIter() the number of recycled blocks is larger than the allowable subspace.");
454 int bs = Teuchos::getParameter<int>(
params,
"Block Size");
456 TEUCHOS_TEST_FOR_EXCEPTION(
bs <= 0, std::invalid_argument,
"Belos::BlockGCRODRIter() the block size was passed a non-postitive argument.");
460 recycledBlocks_ =
rb;
465 trueRHSIndices_.resize(blockSize_);
467 for(
i=0;
i<blockSize_;
i++){
468 trueRHSIndices_[
i] =
true;
473 cs_.resize( numBlocks_+1 );
474 sn_.resize( numBlocks_+1 );
475 Z_.shapeUninitialized( (numBlocks_+1)*blockSize_,blockSize_ );
477 House_.resize(numBlocks_);
479 for(
i=0;
i<numBlocks_;
i++){
480 House_[
i].shapeUninitialized(2*blockSize_, 2*blockSize_);
486 template <
class ScalarType,
class MV,
class OP,
class DM>
494 setSize( recycledBlocks_, numBlocks_ );
496 Teuchos::RCP<MV>
Vnext;
497 Teuchos::RCP<const MV>
Vprev;
498 std::vector<int>
curind(blockSize_);
512 Teuchos::RCP<SDM >
Z0 =
513 Teuchos::rcp(
new SDM(blockSize_,blockSize_) );
521 Teuchos::RCP<SDM >
Z_block = Teuchos::rcp(
new SDM(Teuchos::View, Z_, blockSize_,blockSize_) );
524 std::vector<int>
prevind(blockSize_*(numBlocks_ + 1));
531 while( (stest_->checkStatus(
this) !=
Passed) && (curDim_+blockSize_-1) < (numBlocks_*blockSize_)) {
544 for(
int i = 0;
i< blockSize_;
i++){
552 for(
int i = 0;
i< blockSize_;
i++){
553 curind[blockSize_ - 1 -
i] = curDim_ -
i - 1;
558 Vprev = Teuchos::null;
564 Teuchos::Array<Teuchos::RCP<const MV> > C(1, C_);
567 subB = Teuchos::rcp(
new SDM ( Teuchos::View,*B_,recycledBlocks_,blockSize_,0,
HFirstCol ) );
569 Teuchos::Array<Teuchos::RCP<SDM > >
AsubB;
579 Teuchos::Array<Teuchos::RCP<const MV> >
AVprev(1,
Vprev);
582 Teuchos::RCP<SDM>
subH = Teuchos::rcp(
new SDM ( Teuchos::View,*H_,curDim_,blockSize_,0,
HFirstCol ) );
583 Teuchos::Array<Teuchos::RCP<SDM > >
AsubH;
601 curDim_ = curDim_ + blockSize_;
611 template <
class ScalarType,
class MV,
class OP,
class DM>
621 R_ = Teuchos::rcp(
new SDM(H_->numRows(), H_->numCols() ));
626 for(
int i=0;
i<2*blockSize_;
i++){
629 for(
int i=0;
i<numBlocks_;
i++){
647 template <
class ScalarType,
class MV,
class OP,
class DM>
648 Teuchos::RCP<const MV>
655 if (
static_cast<int> (
norms->size()) < blockSize_) {
656 norms->resize( blockSize_ );
658 Teuchos::BLAS<int,ScalarType>
blas;
659 for (
int j=0;
j<blockSize_;
j++) {
660 if(trueRHSIndices_[
j]){
661 (*norms)[
j] =
blas.NRM2( blockSize_, &Z_(curDim_-blockSize_+
j,
j), 1);
667 return Teuchos::null;
670 return Teuchos::null;
676 template <
class ScalarType,
class MV,
class OP,
class DM>
684 if(curDim_<=blockSize_) {
688 const ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
689 const ScalarType zero = Teuchos::ScalarTraits<ScalarType>::zero();
690 Teuchos::BLAS<int,ScalarType>
blas;
695 SDM Y( Teuchos::Copy, Z_, curDim_-blockSize_, blockSize_ );
696 Teuchos::RCP<SDM>
Rtmp = Teuchos::rcp(
new SDM(Teuchos::View, *R_, curDim_, curDim_-blockSize_));
713 blas.TRSM( Teuchos::LEFT_SIDE, Teuchos::UPPER_TRI, Teuchos::NO_TRANS,
714 Teuchos::NON_UNIT_DIAG, curDim_-blockSize_, blockSize_,
one,
715 Rtmp->values(),
Rtmp->stride(), Y.values(), Y.stride() );
722 std::vector<int> index(curDim_-blockSize_);
723 for (
int i=0;
i<curDim_-blockSize_;
i++ ) index[
i] =
i;
724 Teuchos::RCP<const MV>
Vjp1 = MVT::CloneView( *V_, index );
732 if (U_ != Teuchos::null) {
733 SDM z(recycledBlocks_,blockSize_);
734 SDM subB( Teuchos::View, *B_, recycledBlocks_, curDim_-blockSize_ );
735 z.multiply( Teuchos::NO_TRANS, Teuchos::NO_TRANS,
one,
subB, Y,
zero );
747 template<
class ScalarType,
class MV,
class OP,
class DM>
751 const ScalarType zero = Teuchos::ScalarTraits<ScalarType>::zero();
752 const ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
759 int curDim = curDim_;
760 if ( (
dim >= curDim_) && (
dim < getMaxSubspaceDim()) ){
764 Teuchos::BLAS<int, ScalarType>
blas;
773 for (
i=0;
i<curDim-1;
i++) {
777 blas.ROT( 1, &(*R_)(
i,curDim-1), 1, &(*R_)(
i+1, curDim-1), 1, &cs_[
i], &sn_[
i] );
782 blas.ROTG( &(*R_)(curDim-1,curDim-1), &(*R_)(curDim,curDim-1), &cs_[curDim-1], &sn_[curDim-1] );
783 (*R_)(curDim,curDim-1) =
zero;
787 blas.ROT( 1, &Z_(curDim-1,0), 1, &Z_(curDim,0), 1, &cs_[curDim-1], &sn_[curDim-1] );
802 Teuchos::RCP< SDM >
workmatrix = Teuchos::null;
803 Teuchos::RCP< SDV >
workvec = Teuchos::null;
804 Teuchos::RCP<SDV>
v_refl = Teuchos::null;
806 Teuchos::RCP< SDM >
Rblock = Teuchos::null;
811 for(
i=0;
i<lclIter_-1;
i++){
816 blas.GEMM(Teuchos::NO_TRANS,Teuchos::NO_TRANS, 2*blockSize_,blockSize_,2*blockSize_,
one,House_[
i].
values(),House_[
i].
stride(),
RblockCopy->values(),
RblockCopy ->
stride(),
zero,
RblockView->values(),
RblockView ->
stride());
823 Rblock =
rcp(
new SDM (Teuchos::View, *R_, 2*blockSize_,blockSize_, curDim_-blockSize_, curDim_-blockSize_));
826 for(
i=0;
i<blockSize_;
i++){
830 int curcol = (lclIter_ - 1)*blockSize_ +
i;
856 (*v_refl)[0] -= alpha;
873 if(
i < blockSize_ - 1){
874 workvec = Teuchos::rcp(
new SDV(blockSize_ -
i -1));
877 blas.GEMV(Teuchos::TRANS,
workmatrix->numRows(),
workmatrix->numCols(),
one,
workmatrix->values(),
workmatrix->stride(),
v_refl->values(), 1,
zero,
workvec->values(), 1);
885 workvec = Teuchos::rcp(
new SDV(2*blockSize_));
886 workmatrix = Teuchos::rcp(
new SDM (Teuchos::View, House_[lclIter_ -1], blockSize_+1, 2*blockSize_,
i, 0 ) );
887 blas.GEMV(Teuchos::TRANS,
workmatrix->numRows(),
workmatrix->numCols(),
one,
workmatrix->values(),
workmatrix->stride(),
v_refl->values(), 1,
zero,
workvec->values(),1);
894 workmatrix = Teuchos::rcp(
new SDM (Teuchos::View, Z_, blockSize_+1, blockSize_,
curcol, 0 ) );
895 blas.GEMV(Teuchos::TRANS,
workmatrix->numRows(),
workmatrix->numCols(),
one,
workmatrix->
values(),
workmatrix->stride(),
v_refl ->
values(), 1,
zero,
workvec->values(), 1);
902 for(
int ii=1;
ii<= blockSize_;
ii++){
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.
Implementation of the Block GCRO-DR (Block Recycling GMRES) iteration.
void setBlockSize(int blockSize)
Set the blocksize.
int getNumIters() const
Get the current iteration count.
int getCurSubspaceDim() const
Get the dimension of the search subspace used to generate the current solution to the linear problem.
BlockGCRODRIterState< ScalarType, MV > getState() const
Get the current state of the linear solver.
int getBlockSize() const
Get the blocksize to be used by the iterative solver in solving this linear problem.
void initialize()
Initialize the solver to an iterate, providing a complete state.
MultiVecTraits< ScalarType, MV, DM > MVT
BlockGCRODRIter(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP, DM > > &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)
BlockGCRODRIter constructor with linear problem, solver utilities, and parameter list of solver optio...
Teuchos::RCP< MV > getCurrentUpdate() const
Get the current update to the linear system.
bool isInitialized()
States whether the solver has been initialized or not.
SCT::magnitudeType MagnitudeType
int getNumBlocks() const
Get the maximum number of blocks used by the iterative solver in solving this linear problem.
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.
Teuchos::SerialDenseMatrix< int, ScalarType > SDM
OperatorTraits< ScalarType, MV, OP > OPT
virtual ~BlockGCRODRIter()
Destructor.
Teuchos::SerialDenseVector< int, ScalarType > SDV
void updateLSQR(int dim=-1)
void setNumBlocks(int numBlocks)
Set the maximum number of blocks used by the iterative solver.
Teuchos::ScalarTraits< ScalarType > SCT
int getMaxSubspaceDim() const
Get the maximum dimension allocated for the search subspace.
void iterate()
This method performs block GCRODR iterations until the status test indicates the need to stop or an e...
void resetNumIters(int iter=0)
Reset the iteration count.
const LinearProblem< ScalarType, MV, OP, DM > & getProblem() const
Get a constant reference to the linear problem.
BlockGCRODRIterInitFailure is thrown when the BlockGCRODRIter object is unable to generate an initial...
BlockGCRODRIterInitFailure(const std::string &what_arg)
BlockGCRODRIterOrthoFailure is thrown when the BlockGCRODRIter object is unable to compute independen...
BlockGCRODRIterOrthoFailure(const std::string &what_arg)
Alternative run-time polymorphic interface for operators.
Operator()
Default constructor (does nothing).
Structure to contain pointers to BlockGCRODRIter state variables.
Teuchos::RCP< MV > V
The current Krylov basis.
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.
int curDim
The current dimension of the reduction.