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>
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;
322 cs_.sizeUninitialized( numBlocks_ );
323 sn_.sizeUninitialized( numBlocks_ );
324 Z_.shapeUninitialized( numBlocks_*blockSize_, blockSize_ );
340 const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > lp_;
341 const Teuchos::RCP<OutputManager<ScalarType> > om_;
342 const Teuchos::RCP<StatusTest<ScalarType,MV,OP> > stest_;
343 const Teuchos::RCP<OrthoManager<ScalarType,MV> > ortho_;
351 int numBlocks_, blockSize_;
356 std::vector<bool> trueRHSIndices_;
363 Teuchos::SerialDenseVector<int,MagnitudeType> cs_;
370 std::vector< SDM >House_;
382 int curDim_, iter_, lclIter_;
393 Teuchos::RCP<MV> U_, C_;
402 Teuchos::RCP<SDM > H_;
407 Teuchos::RCP<SDM > B_;
415 Teuchos::RCP<SDM> R_;
430 template<
class ScalarType,
class MV,
class OP>
440 initialized_ =
false;
451 TEUCHOS_TEST_FOR_EXCEPTION(!
params.isParameter(
"Num Blocks"), std::invalid_argument,
"Belos::BlockGCRODRIter::constructor: mandatory parameter \"Num Blocks\" is not specified.");
452 int nb = Teuchos::getParameter<int>(
params,
"Num Blocks");
454 TEUCHOS_TEST_FOR_EXCEPTION(!
params.isParameter(
"Recycled Blocks"), std::invalid_argument,
"Belos::BlockGCRODRIter::constructor: mandatory parameter \"Recycled Blocks\" is not specified.");
455 int rb = Teuchos::getParameter<int>(
params,
"Recycled Blocks");
457 TEUCHOS_TEST_FOR_EXCEPTION(
nb <= 0, std::invalid_argument,
"Belos::BlockGCRODRIter() was passed a non-positive argument for \"Num Blocks\".");
458 TEUCHOS_TEST_FOR_EXCEPTION(
rb >=
nb, std::invalid_argument,
"Belos::BlockGCRODRIter() the number of recycled blocks is larger than the allowable subspace.");
461 int bs = Teuchos::getParameter<int>(
params,
"Block Size");
463 TEUCHOS_TEST_FOR_EXCEPTION(
bs <= 0, std::invalid_argument,
"Belos::BlockGCRODRIter() the block size was passed a non-postitive argument.");
467 recycledBlocks_ =
rb;
472 trueRHSIndices_.resize(blockSize_);
474 for(
i=0;
i<blockSize_;
i++){
475 trueRHSIndices_[
i] =
true;
480 cs_.sizeUninitialized( numBlocks_+1 );
481 sn_.sizeUninitialized( numBlocks_+1 );
482 Z_.shapeUninitialized( (numBlocks_+1)*blockSize_,blockSize_ );
484 House_.resize(numBlocks_);
486 for(
i=0;
i<numBlocks_;
i++){
487 House_[
i].shapeUninitialized(2*blockSize_, 2*blockSize_);
493 template <
class ScalarType,
class MV,
class OP>
501 setSize( recycledBlocks_, numBlocks_ );
503 Teuchos::RCP<MV>
Vnext;
504 Teuchos::RCP<const MV>
Vprev;
505 std::vector<int>
curind(blockSize_);
519 Teuchos::RCP<SDM >
Z0 =
520 Teuchos::rcp(
new SDM(blockSize_,blockSize_) );
528 Teuchos::RCP<SDM >
Z_block = Teuchos::rcp(
new SDM(Teuchos::View, Z_, blockSize_,blockSize_) );
531 std::vector<int>
prevind(blockSize_*(numBlocks_ + 1));
538 while( (stest_->checkStatus(
this) !=
Passed) && (curDim_+blockSize_-1) < (numBlocks_*blockSize_)) {
551 for(
int i = 0;
i< blockSize_;
i++){
559 for(
int i = 0;
i< blockSize_;
i++){
560 curind[blockSize_ - 1 -
i] = curDim_ -
i - 1;
565 Vprev = Teuchos::null;
571 Teuchos::Array<Teuchos::RCP<const MV> > C(1, C_);
574 subB = Teuchos::rcp(
new SDM ( Teuchos::View,*B_,recycledBlocks_,blockSize_,0,
HFirstCol ) );
576 Teuchos::Array<Teuchos::RCP<SDM > >
AsubB;
586 Teuchos::Array<Teuchos::RCP<const MV> >
AVprev(1,
Vprev);
589 Teuchos::RCP<SDM>
subH = Teuchos::rcp(
new SDM ( Teuchos::View,*H_,curDim_,blockSize_,0,
HFirstCol ) );
590 Teuchos::Array<Teuchos::RCP<SDM > >
AsubH;
608 curDim_ = curDim_ + blockSize_;
618 template <
class ScalarType,
class MV,
class OP>
628 R_ = Teuchos::rcp(
new SDM(H_->numRows(), H_->numCols() ));
633 for(
int i=0;
i<2*blockSize_;
i++){
636 for(
int i=0;
i<numBlocks_;
i++){
654 template <
class ScalarType,
class MV,
class OP>
655 Teuchos::RCP<const MV>
662 if (
static_cast<int> (
norms->size()) < blockSize_) {
663 norms->resize( blockSize_ );
665 Teuchos::BLAS<int,ScalarType>
blas;
666 for (
int j=0;
j<blockSize_;
j++) {
667 if(trueRHSIndices_[
j]){
668 (*norms)[
j] =
blas.NRM2( blockSize_, &Z_(curDim_-blockSize_+
j,
j), 1);
674 return Teuchos::null;
677 return Teuchos::null;
683 template <
class ScalarType,
class MV,
class OP>
691 if(curDim_<=blockSize_) {
695 const ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
696 const ScalarType zero = Teuchos::ScalarTraits<ScalarType>::zero();
697 Teuchos::BLAS<int,ScalarType>
blas;
702 SDM Y( Teuchos::Copy, Z_, curDim_-blockSize_, blockSize_ );
703 Teuchos::RCP<SDM>
Rtmp = Teuchos::rcp(
new SDM(Teuchos::View, *R_, curDim_, curDim_-blockSize_));
720 blas.TRSM( Teuchos::LEFT_SIDE, Teuchos::UPPER_TRI, Teuchos::NO_TRANS,
721 Teuchos::NON_UNIT_DIAG, curDim_-blockSize_, blockSize_,
one,
722 Rtmp->values(),
Rtmp->stride(), Y.values(), Y.stride() );
729 std::vector<int> index(curDim_-blockSize_);
730 for (
int i=0;
i<curDim_-blockSize_;
i++ ) index[
i] =
i;
731 Teuchos::RCP<const MV>
Vjp1 = MVT::CloneView( *V_, index );
739 if (U_ != Teuchos::null) {
740 SDM z(recycledBlocks_,blockSize_);
741 SDM subB( Teuchos::View, *B_, recycledBlocks_, curDim_-blockSize_ );
742 z.multiply( Teuchos::NO_TRANS, Teuchos::NO_TRANS,
one,
subB, Y,
zero );
754 template<
class ScalarType,
class MV,
class OP>
758 const ScalarType zero = Teuchos::ScalarTraits<ScalarType>::zero();
759 const ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
766 int curDim = curDim_;
767 if ( (
dim >= curDim_) && (
dim < getMaxSubspaceDim()) ){
771 Teuchos::BLAS<int, ScalarType>
blas;
780 for (
i=0;
i<curDim-1;
i++) {
784 blas.ROT( 1, &(*R_)(
i,curDim-1), 1, &(*R_)(
i+1, curDim-1), 1, &cs_[
i], &sn_[
i] );
789 blas.ROTG( &(*R_)(curDim-1,curDim-1), &(*R_)(curDim,curDim-1), &cs_[curDim-1], &sn_[curDim-1] );
790 (*R_)(curDim,curDim-1) =
zero;
794 blas.ROT( 1, &Z_(curDim-1,0), 1, &Z_(curDim,0), 1, &cs_[curDim-1], &sn_[curDim-1] );
809 Teuchos::RCP< SDM >
workmatrix = Teuchos::null;
810 Teuchos::RCP< SDV >
workvec = Teuchos::null;
811 Teuchos::RCP<SDV>
v_refl = Teuchos::null;
813 Teuchos::RCP< SDM >
Rblock = Teuchos::null;
818 for(
i=0;
i<lclIter_-1;
i++){
823 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());
830 Rblock =
rcp(
new SDM (Teuchos::View, *R_, 2*blockSize_,blockSize_, curDim_-blockSize_, curDim_-blockSize_));
833 for(
i=0;
i<blockSize_;
i++){
837 int curcol = (lclIter_ - 1)*blockSize_ +
i;
863 (*v_refl)[0] -= alpha;
880 if(
i < blockSize_ - 1){
881 workvec = Teuchos::rcp(
new SDV(blockSize_ -
i -1));
884 blas.GEMV(Teuchos::TRANS,
workmatrix->numRows(),
workmatrix->numCols(),
one,
workmatrix->values(),
workmatrix->stride(),
v_refl->values(), 1,
zero,
workvec->values(), 1);
892 workvec = Teuchos::rcp(
new SDV(2*blockSize_));
893 workmatrix = Teuchos::rcp(
new SDM (Teuchos::View, House_[lclIter_ -1], blockSize_+1, 2*blockSize_,
i, 0 ) );
894 blas.GEMV(Teuchos::TRANS,
workmatrix->numRows(),
workmatrix->numCols(),
one,
workmatrix->values(),
workmatrix->stride(),
v_refl->values(), 1,
zero,
workvec->values(),1);
901 workmatrix = Teuchos::rcp(
new SDM (Teuchos::View, Z_, blockSize_+1, blockSize_,
curcol, 0 ) );
902 blas.GEMV(Teuchos::TRANS,
workmatrix->numRows(),
workmatrix->numCols(),
one,
workmatrix->
values(),
workmatrix->stride(),
v_refl ->
values(), 1,
zero,
workvec->values(), 1);
909 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.
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)
Implementation of the Block GCRO-DR (Block Recycling GMRES) iteration.
BlockGCRODRIter(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)
BlockGCRODRIter constructor with linear problem, solver utilities, and parameter list of solver optio...
int getBlockSize() const
Get the blocksize to be 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.
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.
void initialize()
Initialize the solver to an iterate, providing a complete state.
Teuchos::SerialDenseVector< int, ScalarType > SDV
void setRecycledBlocks(int recycledBlocks)
Set the maximum number of recycled blocks used by the iterative solver.
int getRecycledBlocks() const
Set the maximum number of recycled blocks used by the iterative solver.
void setBlockSize(int blockSize)
Set the blocksize.
Teuchos::SerialDenseMatrix< int, ScalarType > SDM
MultiVecTraits< ScalarType, MV > MVT
BlockGCRODRIterState< ScalarType, MV > getState() const
Get the current state of the linear solver.
void setNumBlocks(int numBlocks)
Set the maximum number of blocks used by the iterative solver.
SCT::magnitudeType MagnitudeType
Teuchos::ScalarTraits< ScalarType > SCT
Teuchos::RCP< const MV > getNativeResiduals(std::vector< MagnitudeType > *norms) const
Get the norms of the residuals native to the solver.
virtual ~BlockGCRODRIter()
Destructor.
const LinearProblem< ScalarType, MV, OP > & getProblem() const
Get a constant reference to the linear problem.
int getCurSubspaceDim() const
Get the dimension of the search subspace used to generate the current solution to the linear problem.
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.
void updateLSQR(int dim=-1)
OperatorTraits< ScalarType, MV, OP > OPT
int getMaxSubspaceDim() const
Get the maximum dimension allocated for the search subspace.
int getNumIters() const
Get the current iteration count.
Teuchos::RCP< MV > getCurrentUpdate() const
Get the current update to the linear system.
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.