42#ifndef BELOS_BLOCK_GCRODR_ITER_HPP
43#define BELOS_BLOCK_GCRODR_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"
94 template <
class ScalarType,
class MV>
107 Teuchos::RCP<MV>
U,
C;
114 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> >
H;
118 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> >
B;
121 U(Teuchos::null),
C(Teuchos::null),
122 H(Teuchos::null),
B(Teuchos::null)
166 template<
class ScalarType,
class MV,
class OP>
175 typedef Teuchos::ScalarTraits<ScalarType>
SCT;
177 typedef Teuchos::SerialDenseMatrix<int,ScalarType>
SDM;
178 typedef Teuchos::SerialDenseVector<int,ScalarType>
SDV;
195 Teuchos::ParameterList ¶ms );
349 void setSize(
int recycledBlocks,
int numBlocks ) {
372 const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> >
lp_;
373 const Teuchos::RCP<OutputManager<ScalarType> >
om_;
374 const Teuchos::RCP<StatusTest<ScalarType,MV,OP> >
stest_;
375 const Teuchos::RCP<OrthoManager<ScalarType,MV> >
ortho_;
395 Teuchos::SerialDenseVector<int,MagnitudeType>
cs_;
434 Teuchos::RCP<SDM >
H_;
439 Teuchos::RCP<SDM >
B_;
447 Teuchos::RCP<SDM>
R_;
462 template<
class ScalarType,
class MV,
class OP>
467 Teuchos::ParameterList ¶ms ):
lp_(problem),
483 TEUCHOS_TEST_FOR_EXCEPTION(!params.isParameter(
"Num Blocks"), std::invalid_argument,
"Belos::BlockGCRODRIter::constructor: mandatory parameter \"Num Blocks\" is not specified.");
484 int nb = Teuchos::getParameter<int>(params,
"Num Blocks");
486 TEUCHOS_TEST_FOR_EXCEPTION(!params.isParameter(
"Recycled Blocks"), std::invalid_argument,
"Belos::BlockGCRODRIter::constructor: mandatory parameter \"Recycled Blocks\" is not specified.");
487 int rb = Teuchos::getParameter<int>(params,
"Recycled Blocks");
489 TEUCHOS_TEST_FOR_EXCEPTION(nb <= 0, std::invalid_argument,
"Belos::BlockGCRODRIter() was passed a non-positive argument for \"Num Blocks\".");
490 TEUCHOS_TEST_FOR_EXCEPTION(rb >= nb, std::invalid_argument,
"Belos::BlockGCRODRIter() the number of recycled blocks is larger than the allowable subspace.");
493 int bs = Teuchos::getParameter<int>(params,
"Block Size");
495 TEUCHOS_TEST_FOR_EXCEPTION(bs <= 0, std::invalid_argument,
"Belos::BlockGCRODRIter() the block size was passed a non-postitive argument.");
525 template <
class ScalarType,
class MV,
class OP>
535 Teuchos::RCP<MV> Vnext;
536 Teuchos::RCP<const MV> Vprev;
543 for(
int i = 0; i<
blockSize_; i++){curind[i] = i;};
551 Teuchos::RCP<SDM > Z0 =
553 int rank =
ortho_->normalize(*Vnext,Z0);
561 Z_block->assign(*Z0);
578 int HLastOrthRow = HLastCol;
579 int HFirstNormRow = HLastOrthRow + 1;
596 lp_->apply(*Vprev,*Vnext);
597 Vprev = Teuchos::null;
603 Teuchos::Array<Teuchos::RCP<const MV> > C(1,
C_);
608 Teuchos::Array<Teuchos::RCP<SDM > > AsubB;
609 AsubB.append( subB );
611 ortho_->project( *Vnext, AsubB, C );
616 for (
int i=0; i<
curDim_; i++) { prevind[i] = i; }
618 Teuchos::Array<Teuchos::RCP<const MV> > AVprev(1, Vprev);
622 Teuchos::Array<Teuchos::RCP<SDM > > AsubH;
623 AsubH.append( subH );
627 int rank =
ortho_->projectAndNormalize(*Vnext,AsubH,subR,AVprev);
650 template <
class ScalarType,
class MV,
class OP>
652 if (newstate.
V != Teuchos::null && newstate.
H != Teuchos::null) {
660 R_ = Teuchos::rcp(
new SDM(
H_->numRows(),
H_->numCols() ));
669 House_[i].assign(Identity);
673 TEUCHOS_TEST_FOR_EXCEPTION(newstate.
V == Teuchos::null,std::invalid_argument,
"Belos::GCRODRIter::initialize(): BlockGCRODRIterState does not have V initialized.");
674 TEUCHOS_TEST_FOR_EXCEPTION(newstate.
H == Teuchos::null,std::invalid_argument,
"Belos::GCRODRIter::initialize(): BlockGCRODRIterState does not have H initialized.");
686 template <
class ScalarType,
class MV,
class OP>
687 Teuchos::RCP<const MV>
694 if (
static_cast<int> (norms->size()) <
blockSize_) {
697 Teuchos::BLAS<int,ScalarType> blas;
706 return Teuchos::null;
709 return Teuchos::null;
715 template <
class ScalarType,
class MV,
class OP>
721 Teuchos::RCP<MV> currentUpdate = Teuchos::null;
724 return currentUpdate;
727 const ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
728 const ScalarType zero = Teuchos::ScalarTraits<ScalarType>::zero();
729 Teuchos::BLAS<int,ScalarType> blas;
752 blas.TRSM( Teuchos::LEFT_SIDE, Teuchos::UPPER_TRI, Teuchos::NO_TRANS,
754 Rtmp->values(), Rtmp->stride(), Y.values(), Y.stride() );
771 if (
U_ != Teuchos::null) {
774 z.multiply( Teuchos::NO_TRANS, Teuchos::NO_TRANS, one, subB, Y, zero );
783 return currentUpdate;
786 template<
class ScalarType,
class MV,
class OP>
790 const ScalarType zero = Teuchos::ScalarTraits<ScalarType>::zero();
791 const ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
803 Teuchos::BLAS<int, ScalarType> blas;
812 for (i=0; i<curDim-1; i++) {
816 blas.ROT( 1, &(*
R_)(i,curDim-1), 1, &(*
R_)(i+1, curDim-1), 1, &
cs_[i], &
sn_[i] );
821 blas.ROTG( &(*
R_)(curDim-1,curDim-1), &(*
R_)(curDim,curDim-1), &
cs_[curDim-1], &
sn_[curDim-1] );
822 (*R_)(curDim,curDim-1) = zero;
826 blas.ROT( 1, &
Z_(curDim-1,0), 1, &
Z_(curDim,0), 1, &
cs_[curDim-1], &
sn_[curDim-1] );
841 Teuchos::RCP< SDM > workmatrix = Teuchos::null;
842 Teuchos::RCP< SDV > workvec = Teuchos::null;
843 Teuchos::RCP<SDV> v_refl = Teuchos::null;
845 Teuchos::RCP< SDM >Rblock = Teuchos::null;
855 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());
871 ScalarType signDiag = (*R_)(curcol,curcol) / Teuchos::ScalarTraits<ScalarType>::magnitude((*
R_)(curcol,curcol));
875 ScalarType nvs = blas.NRM2(
blockSize_+1,&((*
R_)[curcol][curcol]),1);
876 ScalarType alpha = -signDiag*nvs;
894 v_refl = rcp(
new SDV(Teuchos::Copy, &((*
R_)(curcol,curcol)),
blockSize_ + 1 ));
895 (*v_refl)[0] -= alpha;
896 nvs = blas.NRM2(
blockSize_+1,v_refl -> values(),1);
915 workmatrix = Teuchos::rcp(
new SDM (Teuchos::View, *Rblock,
blockSize_+1,
blockSize_ - i -1, lclCurcol, lclCurcol +1 ) );
916 blas.GEMV(Teuchos::TRANS, workmatrix->numRows(), workmatrix->numCols(), one, workmatrix->values(), workmatrix->stride(), v_refl->values(), 1, zero, workvec->values(), 1);
917 blas.GER(workmatrix->numRows(),workmatrix->numCols(), -2.0*one/nvs, v_refl->values(),1,workvec->values(),1,workmatrix->values(),workmatrix->stride());
926 blas.GEMV(Teuchos::TRANS,workmatrix->numRows(),workmatrix->numCols(),one,workmatrix->values(),workmatrix->stride(), v_refl->values(), 1,zero,workvec->values(),1);
927 blas.GER(workmatrix->numRows(),workmatrix->numCols(), -2.0*one/nvs, v_refl -> values(),1,workvec->values(),1,workmatrix->values(),(*workmatrix).stride());
934 blas.GEMV(Teuchos::TRANS, workmatrix->numRows(), workmatrix->numCols(), one, workmatrix-> values(), workmatrix->stride(), v_refl -> values(), 1, zero, workvec->values(), 1);
935 blas.GER((*workmatrix).numRows(),(*workmatrix).numCols(), -2.0*one/nvs,v_refl -> values(), 1,&((*workvec)[0]),1,(*workmatrix)[0],(*workmatrix).stride());
940 (*R_)[curcol][curcol] = alpha;
942 (*R_)[curcol][curcol+ii] = 0;
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.
BelosError(const std::string &what_arg)
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)
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.
std::vector< SDM > House_
const Teuchos::RCP< OrthoManager< ScalarType, MV > > ortho_
Teuchos::RCP< MV > V_
The Krylov basis vectors.
Teuchos::RCP< SDM > B_
Projected matrix from the recycled subspace.
const Teuchos::RCP< OutputManager< ScalarType > > om_
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.
Teuchos::SerialDenseVector< int, MagnitudeType > cs_
int getNumBlocks() const
Get the maximum number of blocks used by the iterative solver in solving this linear problem.
SDM Z_
Q applied to right-hand side of the least squares system.
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
const Teuchos::RCP< StatusTest< ScalarType, MV, OP > > stest_
MultiVecTraits< ScalarType, MV > MVT
BlockGCRODRIterState< ScalarType, MV > getState() const
Get the current state of the linear solver.
const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > lp_
void setNumBlocks(int numBlocks)
Set the maximum number of blocks used by the iterative solver.
SCT::magnitudeType MagnitudeType
Teuchos::RCP< SDM > R_
Upper triangular reduction of H_ (see above).
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.
Teuchos::RCP< SDM > H_
Projected matrix from the Krylov factorization.
std::vector< bool > trueRHSIndices_
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.
Teuchos::RCP< MV > U_
Recycled subspace vectors.
Iteration()
Default Constructor.
Belos's templated virtual class for providing routines for orthogonalization and orthonormzalition of...
Traits class which defines basic operations on multivectors.
static void MvTimesMatAddMv(const ScalarType alpha, const MV &A, const Teuchos::SerialDenseMatrix< int, ScalarType > &B, const ScalarType beta, MV &mv)
Update mv with .
static Teuchos::RCP< MV > Clone(const MV &mv, const int numvecs)
Creates a new empty MV containing numvecs columns.
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).
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...
A pure virtual class for defining the status tests for the Belos iterative solvers.
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.