10#ifndef BELOS_GMRESPOLYOP_HPP
11#define BELOS_GMRESPOLYOP_HPP
38#include "Teuchos_BLAS.hpp"
39#include "Teuchos_LAPACK.hpp"
40#include "Teuchos_as.hpp"
41#include "Teuchos_RCP.hpp"
42#include "Teuchos_SerialDenseMatrix.hpp"
43#include "Teuchos_SerialDenseVector.hpp"
44#include "Teuchos_SerialDenseSolver.hpp"
45#include "Teuchos_ParameterList.hpp"
47#ifdef BELOS_TEUCHOS_TIME_MONITOR
48 #include "Teuchos_TimeMonitor.hpp"
64 template <
class ScalarType,
class MV,
class DM = DefaultDenseMatrix<
int, ScalarType>>
74 mv_ = Teuchos::rcp_const_cast<MV>( mv_in );
76 Teuchos::RCP<MV>
getMV() {
return mv_; }
77 Teuchos::RCP<const MV>
getConstMV()
const {
return mv_; }
108 const DM& B,
const ScalarType beta)
131 void MvNorm ( std::vector<
typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>& normvec,
NormType type =
TwoNorm )
const
148 Teuchos::RCP<MV> mv_;
162 template <
class ScalarType,
class MV,
class OP,
class DM>
174 const Teuchos::RCP<Teuchos::ParameterList>& params_in
176 : problem_(problem_in),
178 LP_(problem_in->getLeftPrec()),
179 RP_(problem_in->getRightPrec())
183 polyUpdateLabel_ = label_ +
": Hybrid Gmres: Vector Update";
184#ifdef BELOS_TEUCHOS_TIME_MONITOR
185 timerPolyUpdate_ = Teuchos::TimeMonitor::getNewCounter(polyUpdateLabel_);
188 if (polyType_ ==
"Arnoldi" || polyType_==
"Roots")
190 else if (polyType_ ==
"Gmres")
193 TEUCHOS_TEST_FOR_EXCEPTION(polyType_!=
"Arnoldi"&&polyType_!=
"Gmres"&&polyType_!=
"Roots",std::invalid_argument,
194 "Belos::GmresPolyOp: \"Polynomial Type\" must be either \"Arnoldi\", \"Gmres\", or \"Roots\".");
199 : problem_(problem_in)
213 void setParameters(
const Teuchos::RCP<Teuchos::ParameterList>& params_in );
239 void ApplyPoly (
const MV& x, MV& y )
const;
258#ifdef BELOS_TEUCHOS_TIME_MONITOR
259 Teuchos::RCP<Teuchos::Time> timerPolyUpdate_;
261 std::string polyUpdateLabel_;
265 typedef Teuchos::ScalarTraits<ScalarType> SCT ;
266 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
267 typedef Teuchos::ScalarTraits<MagnitudeType> MCT ;
270 static constexpr int maxDegree_default_ = 25;
272 static constexpr bool randomRHS_default_ =
true;
273 static constexpr const char * label_default_ =
"Belos";
274 static constexpr const char * polyType_default_ =
"Roots";
275 static constexpr const char * orthoType_default_ =
"DGKS";
276 static constexpr bool damp_default_ =
false;
277 static constexpr bool addRoots_default_ =
true;
280 Teuchos::RCP<LinearProblem<ScalarType,MV,OP,DM> > problem_;
281 Teuchos::RCP<Teuchos::ParameterList> params_;
282 Teuchos::RCP<const OP> LP_, RP_;
285 Teuchos::RCP<OutputManager<ScalarType> > printer_;
286 Teuchos::RCP<std::ostream> outputStream_ = Teuchos::rcpFromRef(std::cout);
289 Teuchos::RCP<MatOrthoManager<ScalarType,MV,OP,DM> > ortho_;
293 int maxDegree_ = maxDegree_default_;
294 int verbosity_ = verbosity_default_;
295 bool randomRHS_ = randomRHS_default_;
296 std::string label_ = label_default_;
297 std::string polyType_ = polyType_default_;
298 std::string orthoType_ = orthoType_default_;
300 bool damp_ = damp_default_;
301 bool addRoots_ = addRoots_default_;
304 mutable Teuchos::RCP<MV> V_, wL_, wR_;
309 bool autoDeg =
false;
313 Teuchos::SerialDenseMatrix< OT, MagnitudeType > theta_;
317 void SortModLeja(Teuchos::SerialDenseMatrix< OT, MagnitudeType > &thetaN, std::vector<int> &index)
const ;
320 void ComputeAddedRoots();
323 template <
class ScalarType,
class MV,
class OP,
class DM>
327 if (params_in->isParameter(
"Polynomial Type")) {
328 polyType_ = params_in->get(
"Polynomial Type", polyType_default_);
332 if (params_in->isParameter(
"Polynomial Tolerance")) {
333 if (params_in->isType<MagnitudeType> (
"Polynomial Tolerance")) {
334 polyTol_ = params_in->get (
"Polynomial Tolerance",
343 if (params_in->isParameter(
"Maximum Degree")) {
344 maxDegree_ = params_in->get(
"Maximum Degree", maxDegree_default_);
348 if (params_in->isParameter(
"Random RHS")) {
349 randomRHS_ = params_in->get(
"Random RHS", randomRHS_default_);
353 if (params_in->isParameter(
"Verbosity")) {
354 if (Teuchos::isParameterType<int>(*params_in,
"Verbosity")) {
355 verbosity_ = params_in->get(
"Verbosity", verbosity_default_);
358 verbosity_ = (int)Teuchos::getParameter<Belos::MsgType>(*params_in,
"Verbosity");
362 if (params_in->isParameter(
"Orthogonalization")) {
363 orthoType_ = params_in->get(
"Orthogonalization",orthoType_default_);
367 if (params_in->isParameter(
"Timer Label")) {
368 label_ = params_in->get(
"Timer Label", label_default_);
372 if (params_in->isParameter(
"Output Stream")) {
373 outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params_in,
"Output Stream");
377 if (params_in->isParameter(
"Damped Poly")) {
378 damp_ = params_in->get(
"Damped Poly", damp_default_);
382 if (params_in->isParameter(
"Add Roots")) {
383 addRoots_ = params_in->get(
"Add Roots", addRoots_default_);
387 template <
class ScalarType,
class MV,
class OP,
class DM>
390 Teuchos::RCP< MV > V =
MVT::Clone( *problem_->getRHS(), maxDegree_+1 );
393 std::vector<int> index(1,0);
400 if ( !LP_.is_null() ) {
402 problem_->applyLeftPrec( *Vtemp, *V0);
406 problem_->apply( *Vtemp, *V0);
409 for(
int i=0; i< maxDegree_; i++)
415 problem_->apply( *Vi, *Vip1);
419 Teuchos::Range1D range( 1, maxDegree_);
423 DM AVtransAV = *
DMT::Create( maxDegree_, maxDegree_);
427 Teuchos::LAPACK< OT, ScalarType > lapack;
433 while( status && dim_ >= 1)
444 std::cout <<
"BelosGmresPolyOp.hpp: LAPACK POTRF was not successful!!" << std::endl;
445 std::cout <<
"Error code: " << infoInt << std::endl;
468 std::cout <<
"Poly Degree is zero. No preconditioner created." << std::endl;
474 Teuchos::Range1D rangeSub( 1, dim_);
483 std::cout <<
"BelosGmresPolyOp.hpp: LAPACK POTRS was not successful!!" << std::endl;
484 std::cout <<
"Error code: " << infoInt << std::endl;
489 template <
class ScalarType,
class MV,
class OP,
class DM>
492 std::string polyLabel = label_ +
": GmresPolyOp creation";
495 std::vector<int> idx(1,0);
496 Teuchos::RCP<MV> newX =
MVT::Clone( *(problem_->getLHS()), 1 );
497 Teuchos::RCP<MV> newB =
MVT::Clone( *(problem_->getRHS()), 1 );
505 Teuchos::RCP<LinearProblem<ScalarType,MV,OP,DM> > newProblem =
507 newProblem->setInitResVec( newB );
508 newProblem->setLeftPrec( problem_->getLeftPrec() );
509 newProblem->setRightPrec( problem_->getRightPrec() );
510 newProblem->setLabel(polyLabel);
511 newProblem->setProblem();
512 newProblem->setLSIndex( idx );
515 Teuchos::ParameterList polyList;
518 polyList.set(
"Num Blocks",maxDegree_);
519 polyList.set(
"Block Size",1);
520 polyList.set(
"Keep Hessenberg",
true);
526 if (ortho_.is_null()) {
527 params_->set(
"Orthogonalization", orthoType_);
529 Teuchos::RCP<Teuchos::ParameterList> paramsOrtho;
531 ortho_ = factory.
makeMatOrthoManager (orthoType_, Teuchos::null, printer_, polyLabel, paramsOrtho);
535 Teuchos::RCP<StatusTestMaxIters<ScalarType,MV,OP,DM> > maxItrTst =
539 Teuchos::RCP<StatusTestGenResNorm<ScalarType,MV,OP,DM> > convTst =
544 Teuchos::RCP<StatusTestCombo<ScalarType,MV,OP,DM> > polyTest =
548 Teuchos::RCP<BlockGmresIter<ScalarType,MV,OP,DM> > gmres_iter;
553 if ( !LP_.is_null() )
554 newProblem->applyLeftPrec( *newB, *V_0 );
558 newProblem->apply( *Vtemp, *V_0 );
565 int rank = ortho_->normalize( *V_0, Teuchos::rcpFromRef(r0_) );
567 "Belos::GmresPolyOp::generateArnoldiPoly(): Failed to compute initial block of orthonormal vectors for polynomial generation.");
573 newstate.
z = Teuchos::rcpFromRef( r0_);
575 gmres_iter->initializeGmres(newstate);
579 gmres_iter->iterate();
583 gmres_iter->updateLSQR( gmres_iter->getCurSubspaceDim() );
585 catch (std::exception& e) {
587 printer_->stream(
Errors) <<
"Error! Caught exception in BlockGmresIter::iterate() at iteration "
588 << gmres_iter->getNumIters() << endl << e.what () << endl;
593 Teuchos::RCP<MV> currX = gmres_iter->getCurrentUpdate();
603 if(polyType_ ==
"Arnoldi"){
612 Teuchos::BLAS<OT,ScalarType> blas;
613 blas.TRSM( Teuchos::LEFT_SIDE, Teuchos::UPPER_TRI, Teuchos::NO_TRANS,
614 Teuchos::NON_UNIT_DIAG, dim_, 1, SCT::one(),
626 for(
int i=0; i <= dim_-3; i++) {
627 for(
int k=i+2; k <= dim_-1; k++) {
646 HSolver->setMatrix( Teuchos::rcpFromRef(Htemp));
647 HSolver->solveWithTransposeFlag( Teuchos::CONJ_TRANS );
648 HSolver->setVectors( Teuchos::rcpFromRef(F), Teuchos::rcpFromRef(E));
649 HSolver->factorWithEquilibration(
true );
653 info = HSolver->factor();
655 std::cout <<
"Hsolver factor: info = " << info << std::endl;
657 info = HSolver->solve();
659 std::cout <<
"Hsolver solve : info = " << info << std::endl;
667 Teuchos::LAPACK< OT, ScalarType > lapack;
668 theta_.shape(dim_,2);
675 std::vector<ScalarType> work(1);
676 std::vector<MagnitudeType> rwork(2*dim_);
679 lapack.GEEV(
'N',
'N',dim_,
DMT::GetRawHostPtr(H_),
DMT::GetStride(H_),theta_[0],theta_[1],vlr, ldv, vlr, ldv, &work[0], lwork, &rwork[0], &info);
680 lwork = std::abs (
static_cast<int> (Teuchos::ScalarTraits<ScalarType>::real (work[0])));
681 work.resize( lwork );
683 lapack.GEEV(
'N',
'N',dim_,
DMT::GetRawHostPtr(H_),
DMT::GetStride(H_),theta_[0],theta_[1],vlr, ldv, vlr, ldv, &work[0], lwork, &rwork[0], &info);
686 std::cout <<
"GEEV solve : info = " << info << std::endl;
691 const MagnitudeType tol = 10.0 * Teuchos::ScalarTraits<MagnitudeType>::eps();
692 std::vector<int> index(dim_);
693 for(
int i=0; i<dim_; ++i){
696 TEUCHOS_TEST_FOR_EXCEPTION(hypot(theta_(i,0),theta_(i,1)) < tol, std::runtime_error,
"BelosGmresPolyOp Error: One of the computed polynomial roots is approximately zero. This will cause a divide by zero error! Your matrix may be close to singular. Please select a lower polynomial degree or give a shifted matrix.");
698 SortModLeja(theta_,index);
707 template <
class ScalarType,
class MV,
class OP,
class DM>
708 void GmresPolyOp<ScalarType, MV, OP, DM>::ComputeAddedRoots()
712 std::vector<std::complex<MagnitudeType>> cmplxHRitz (dim_);
713 for(
unsigned int i=0; i<cmplxHRitz.size(); ++i){
714 cmplxHRitz[i] = std::complex<MagnitudeType>( theta_(i,0), theta_(i,1) );
718 const MagnitudeType one(1.0);
719 std::vector<MagnitudeType> pof (dim_,one);
720 for(
int j=0; j<dim_; ++j) {
721 for(
int i=0; i<dim_; ++i) {
723 pof[j] = std::abs(pof[j]*(one-(cmplxHRitz[j]/cmplxHRitz[i])));
729 std::vector<int> extra (dim_);
731 for(
int i=0; i<dim_; ++i){
732 if (pof[i] > MCT::zero())
733 extra[i] = ceil((log10(pof[i])-MagnitudeType(4.0))/MagnitudeType(14.0));
737 totalExtra += extra[i];
741 printer_->stream(
Warnings) <<
"Warning: Need to add " << totalExtra <<
" extra roots." << std::endl;}
744 if(addRoots_ && totalExtra>0)
746 theta_.reshape(dim_+totalExtra,2);
748 Teuchos::SerialDenseMatrix<OT,MagnitudeType> thetaPert (Teuchos::Copy, theta_, dim_+totalExtra, 2);
752 for(
int i=0; i<dim_; ++i){
753 for(
int j=0; j< extra[i]; ++j){
754 theta_(count,0) = theta_(i,0);
755 theta_(count,1) = theta_(i,1);
756 thetaPert(count,0) = theta_(i,0)+(j+MCT::one())*MagnitudeType(5e-8);
757 thetaPert(count,1) = theta_(i,1);
765 printer_->stream(
Warnings) <<
"New poly degree is: " << dim_ << std::endl;}
768 std::vector<int> index2(dim_);
769 for(
int i=0; i<dim_; ++i){
772 SortModLeja(thetaPert,index2);
774 for(
int i=0; i<dim_; ++i)
776 thetaPert(i,0) = theta_(index2[i],0);
777 thetaPert(i,1) = theta_(index2[i],1);
786 template <
class ScalarType,
class MV,
class OP,
class DM>
787 void GmresPolyOp<ScalarType, MV, OP, DM>::SortModLeja(Teuchos::SerialDenseMatrix< OT, MagnitudeType > &thetaN, std::vector<int> &index)
const
792 int dimN = index.size();
793 std::vector<int> newIndex(dimN);
794 Teuchos::SerialDenseMatrix< OT, MagnitudeType > sorted (thetaN.numRows(), thetaN.numCols());
795 Teuchos::SerialDenseVector< OT, MagnitudeType > absVal (thetaN.numRows());
796 Teuchos::SerialDenseVector< OT, MagnitudeType > prod (thetaN.numRows());
799 for(
int i = 0; i < dimN; i++){
800 absVal(i) = hypot(thetaN(i,0), thetaN(i,1));
802 MagnitudeType * maxPointer = std::max_element(absVal.values(), (absVal.values()+dimN));
803 int maxIndex = int (maxPointer- absVal.values());
806 sorted(0,0) = thetaN(maxIndex,0);
807 sorted(0,1) = thetaN(maxIndex,1);
808 newIndex[0] = index[maxIndex];
812 if(sorted(0,1)!= SCT::zero() && !SCT::isComplex)
814 sorted(1,0) = thetaN(maxIndex,0);
815 sorted(1,1) = -thetaN(maxIndex,1);
816 newIndex[1] = index[maxIndex+1];
829 for(
int i = 0; i < dimN; i++)
831 prod(i) = MCT::one();
832 for(
int k = 0; k < j; k++)
834 a = thetaN(i,0) - sorted(k,0);
835 b = thetaN(i,1) - sorted(k,1);
836 if (a*a + b*b > MCT::zero())
837 prod(i) = prod(i) + log10(hypot(a,b));
839 prod(i) = -std::numeric_limits<MagnitudeType>::infinity();
846 maxPointer = std::max_element(prod.values(), (prod.values()+dimN));
847 maxIndex = int (maxPointer- prod.values());
848 sorted(j,0) = thetaN(maxIndex,0);
849 sorted(j,1) = thetaN(maxIndex,1);
850 newIndex[j] = index[maxIndex];
853 if(sorted(j,1)!= SCT::zero() && !SCT::isComplex)
856 sorted(j,0) = thetaN(maxIndex,0);
857 sorted(j,1) = -thetaN(maxIndex,1);
858 newIndex[j] = index[maxIndex+1];
868 template <
class ScalarType,
class MV,
class OP,
class DM>
872 if (polyType_ ==
"Arnoldi")
874 else if (polyType_ ==
"Gmres")
876 else if (polyType_ ==
"Roots")
881 problem_->applyOp( x, y );
885 template <
class ScalarType,
class MV,
class OP,
class DM>
892 if (!LP_.is_null()) {
894 problem_->applyLeftPrec( *AX, *Xtmp );
899#ifdef BELOS_TEUCHOS_TIME_MONITOR
900 Teuchos::TimeMonitor updateTimer( *timerPolyUpdate_ );
904 for(
int i=1; i < dim_; i++)
906 Teuchos::RCP<MV> X, Y;
917 problem_->apply(*X, *Y);
919#ifdef BELOS_TEUCHOS_TIME_MONITOR
920 Teuchos::TimeMonitor updateTimer( *timerPolyUpdate_ );
927 if (!RP_.is_null()) {
929 problem_->applyRightPrec( *Ytmp, y );
933 template <
class ScalarType,
class MV,
class OP,
class DM>
942 if (!LP_.is_null()) {
943 problem_->applyLeftPrec( *prod, *Xtmp );
950 if(theta_(i,1)== SCT::zero() || SCT::isComplex)
953#ifdef BELOS_TEUCHOS_TIME_MONITOR
954 Teuchos::TimeMonitor updateTimer( *timerPolyUpdate_ );
956 MVT::MvAddMv(SCT::one(), y, SCT::one()/theta_(i,0), *prod, y);
958 problem_->apply(*prod, *Xtmp);
960#ifdef BELOS_TEUCHOS_TIME_MONITOR
961 Teuchos::TimeMonitor updateTimer( *timerPolyUpdate_ );
963 MVT::MvAddMv(SCT::one(), *prod, -SCT::one()/theta_(i,0), *Xtmp, *prod);
969 MagnitudeType mod = theta_(i,0)*theta_(i,0) + theta_(i,1)*theta_(i,1);
970 problem_->apply(*prod, *Xtmp);
972#ifdef BELOS_TEUCHOS_TIME_MONITOR
973 Teuchos::TimeMonitor updateTimer( *timerPolyUpdate_ );
975 MVT::MvAddMv(2*theta_(i,0), *prod, -SCT::one(), *Xtmp, *Xtmp);
980 problem_->apply(*Xtmp, *Xtmp2);
982#ifdef BELOS_TEUCHOS_TIME_MONITOR
983 Teuchos::TimeMonitor updateTimer( *timerPolyUpdate_ );
985 MVT::MvAddMv(SCT::one(), *prod, -SCT::one()/mod, *Xtmp2, *prod);
991 if(theta_(dim_-1,1)== SCT::zero() || SCT::isComplex)
993#ifdef BELOS_TEUCHOS_TIME_MONITOR
994 Teuchos::TimeMonitor updateTimer( *timerPolyUpdate_ );
996 MVT::MvAddMv(SCT::one(), y, SCT::one()/theta_(dim_-1,0), *prod, y);
1000 if (!RP_.is_null()) {
1002 problem_->applyRightPrec( *Ytmp, y );
1006 template <
class ScalarType,
class MV,
class OP,
class DM>
1012 if (!LP_.is_null()) {
1015 if (!RP_.is_null()) {
1023 std::vector<int> idxi(1), idxi2, idxj(1);
1026 for (
int j=0; j<n; ++j) {
1032 if (!LP_.is_null()) {
1034 problem_->applyLeftPrec( *x_view, *v_curr );
1039 for (
int i=0; i<dim_-1; ++i) {
1043 for (
int ii=0; ii<i+1; ++ii) { idxi2[ii] = ii; }
1055 if (!RP_.is_null()) {
1056 problem_->applyRightPrec( *v_curr, *wR_ );
1061 if (LP_.is_null()) {
1065 problem_->applyOp( *wR_, *wL_ );
1067 if (!LP_.is_null()) {
1068 problem_->applyLeftPrec( *wL_, *v_next );
1075#ifdef BELOS_TEUCHOS_TIME_MONITOR
1076 Teuchos::TimeMonitor updateTimer( *timerPolyUpdate_ );
1086 if (!RP_.is_null()) {
1088#ifdef BELOS_TEUCHOS_TIME_MONITOR
1089 Teuchos::TimeMonitor updateTimer( *timerPolyUpdate_ );
1093 problem_->applyRightPrec( *wR_, *y_view );
1096#ifdef BELOS_TEUCHOS_TIME_MONITOR
1097 Teuchos::TimeMonitor updateTimer( *timerPolyUpdate_ );
Belos concrete class for performing the block GMRES iteration.
Belos header file which uses auto-configuration information to include necessary C++ headers.
Pure virtual base class which augments the basic interface for a Gmres linear solver iteration.
Class which describes the linear problem to be solved by the iterative solver.
Interface for multivectors used by Belos' linear solvers.
Declaration of basic traits for the multivector type.
Alternative run-time polymorphic interface for operators.
Class which defines basic traits for the operator type.
Class which manages the output and verbosity of the Belos solvers.
Belos::StatusTest for logically combining several status tests.
Belos::StatusTestResNorm for specifying general residual norm stopping criteria.
Belos::StatusTest class for specifying a maximum number of iterations.
A factory class for generating StatusTestOutput objects.
Collection of types and exceptions used within the Belos solvers.
BelosError(const std::string &what_arg)
This class implements the block GMRES iteration, where a block Krylov subspace is constructed....
Virtual base class which defines basic traits for the multi-vector type.
static Teuchos::RCP< DM > Subview(DM &source, int numRows, int numCols, int startRow=0, int startCol=0)
Marks host data modified to avoid device sync errors.
static Teuchos::RCP< DM > SubviewCopy(const DM &source, int numRows, int numCols, int startRow=0, int startCol=0)
Returns a deep copy of the requested subview.
static void SyncHostToDevice(DM &dm)
static void PutScalar(DM &dm, ScalarType value=Teuchos::ScalarTraits< ScalarType >::zero())
Fill all entries with value. Value is zero if not specified.
static void Scale(DM &dm, ScalarType value)
Multiply all entries by a scalar. DM = value.*DM.
static Teuchos::RCP< DM > CreateCopy(const DM &dm, bool transpose=false)
Create a new copy DM, possibly transposed.
static ScalarType * GetRawHostPtr(DM &dm)
Returns a raw pointer to the (non-const) data on the host.
static const ScalarType & ValueConst(const DM &dm, const int i, const int j)
Access a const reference to the (i,j) entry of dm, e_i^T dm e_j.
static void SyncDeviceToHost(DM &dm)
static Teuchos::RCP< DenseSolver< ScalarType, DM > > createDenseSolver()
Returns a dense solver object for the dense matrix.
static Teuchos::RCP< const DM > SubviewConst(const DM &source, int numRows, int numCols, int startRow=0, int startCol=0)
static void Add(DM &thisDM, const DM &sourceDM)
Adds sourceDM to thisDM and returns answer in thisDM.
static void Reshape(DM &dm, const int numrows, const int numcols, bool initZero=false)
static ScalarType const * GetConstRawHostPtr(const DM &dm)
Returns a raw pointer to const data on the host.
static ScalarType & Value(DM &dm, const int i, const int j)
Access a reference to the (i,j) entry of dm, e_i^T dm e_j.
static int GetStride(const DM &dm)
Obtain the stride between the columns of dm.
static Teuchos::RCP< DM > Create()
Creates a new empty DM with no dimension.
GmresIterationOrthoFailure is thrown when the GmresIteration object is unable to compute independent ...
void MvNorm(std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &normvec, NormType type=TwoNorm) const
Compute the norm of each vector in *this.
GmresPolyMv(const Teuchos::RCP< const MV > &mv_in)
void MvInit(const ScalarType alpha)
Replace each element of the vectors in *this with alpha.
GmresPolyMv * CloneCopy(const std::vector< int > &index) const
Creates a new Belos::MultiVec and copies the selected contents of *this into the new multivector (dee...
GmresPolyMv * CloneViewNonConst(const std::vector< int > &index)
Creates a new Belos::MultiVec that shares the selected contents of *this. The index of the numvecs ve...
int GetNumberVecs() const
The number of vectors (i.e., columns) in the multivector.
void SetBlock(const MultiVec< ScalarType, DM > &A, const std::vector< int > &index)
Copy the vectors in A to a set of vectors in *this.
Teuchos::RCP< const MV > getConstMV() const
GmresPolyMv(const Teuchos::RCP< MV > &mv_in)
GmresPolyMv * Clone(const int numvecs) const
Create a new MultiVec with numvecs columns.
void MvScale(const std::vector< ScalarType > &alpha)
Scale each element of the i-th vector in *this with alpha[i].
const GmresPolyMv * CloneView(const std::vector< int > &index) const
Creates a new Belos::MultiVec that shares the selected contents of *this. The index of the numvecs ve...
Teuchos::RCP< MV > getMV()
void MvRandom()
Fill all the vectors in *this with random numbers.
void MvAddMv(const ScalarType alpha, const MultiVec< ScalarType, DM > &A, const ScalarType beta, const MultiVec< ScalarType, DM > &B)
Replace *this with alpha * A + beta * B.
ptrdiff_t GetGlobalLength() const
The number of rows in the multivector.
void MvTransMv(const ScalarType alpha, const MultiVec< ScalarType, DM > &A, DM &B) const
Compute a dense matrix B through the matrix-matrix multiply alpha * A^T * (*this).
void MvScale(const ScalarType alpha)
Scale each element of the vectors in *this with alpha.
GmresPolyMv * CloneCopy() const
Create a new MultiVec and copy contents of *this into it (deep copy).
void MvDot(const MultiVec< ScalarType, DM > &A, std::vector< ScalarType > &b) const
Compute the dot product of each column of *this with the corresponding column of A.
void MvPrint(std::ostream &os) const
Print *this multivector to the os output stream.
void MvTimesMatAddMv(const ScalarType alpha, const MultiVec< ScalarType, DM > &A, const DM &B, const ScalarType beta)
Update *this with alpha * A * B + beta * (*this).
void Apply(const MultiVec< ScalarType, DM > &x, MultiVec< ScalarType, DM > &y, ETrans=NOTRANS) const
This routine casts the MultiVec to GmresPolyMv to retrieve the MV. Then the above apply method is cal...
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > ¶ms_in)
Process the passed in parameters.
void generateArnoldiPoly()
This routine takes the matrix, preconditioner, and vectors from the linear problem as well as the par...
void ApplyPoly(const MV &x, MV &y) const
This routine takes the MV x and applies the polynomial operator phi(OP) to it resulting in the MV y,...
GmresPolyOp(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP, DM > > &problem_in, const Teuchos::RCP< Teuchos::ParameterList > ¶ms_in)
Basic contstructor.
void ApplyRootsPoly(const MV &x, MV &y) const
virtual ~GmresPolyOp()
Destructor.
GmresPolyOp(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP, DM > > &problem_in)
Given no ParameterList, constructor creates no polynomial and only applies the given operator.
void ApplyGmresPoly(const MV &x, MV &y) const
void ApplyArnoldiPoly(const MV &x, MV &y) const
void generateGmresPoly()
This routine takes the matrix, preconditioner, and vectors from the linear problem as well as the par...
GmresPolyOpOrthoFailure is thrown when the orthogonalization manager is unable to generate orthonorma...
GmresPolyOpOrthoFailure(const std::string &what_arg)
Interface for multivectors used by Belos' linear solvers.
MultiVec()
Default constructor.
Traits class which defines basic operations on multivectors.
static void MvInit(MV &mv, const ScalarType alpha=Teuchos::ScalarTraits< ScalarType >::zero())
static void MvNorm(const MV &mv, std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &normvec, NormType type=TwoNorm)
static Teuchos::RCP< MV > CloneCopy(const MV &mv)
static Teuchos::RCP< MV > Clone(const MV &mv, const int numvecs)
static void MvPrint(const MV &mv, std::ostream &os)
static void MvRandom(MV &mv)
static void MvAddMv(const ScalarType alpha, const MV &A, const ScalarType beta, const MV &B, MV &mv)
static void MvTimesMatAddMv(const ScalarType alpha, const MV &A, const DM &B, const ScalarType beta, MV &mv)
static void Assign(const MV &A, MV &mv)
static Teuchos::RCP< const MV > CloneView(const MV &mv, const std::vector< int > &index)
static void MvTransMv(const ScalarType alpha, const MV &A, const MV &mv, DM &B)
static ptrdiff_t GetGlobalLength(const MV &mv)
static void MvDot(const MV &mv, const MV &A, std::vector< ScalarType > &b)
static void SetBlock(const MV &A, const std::vector< int > &index, MV &mv)
static Teuchos::RCP< MV > CloneViewNonConst(MV &mv, const std::vector< int > &index)
static void MvScale(MV &mv, const ScalarType alpha)
static int GetNumberVecs(const MV &mv)
Enumeration of all valid Belos (Mat)OrthoManager classes.
Teuchos::RCP< Belos::MatOrthoManager< Scalar, MV, OP, DM > > makeMatOrthoManager(const std::string &ortho, const Teuchos::RCP< const OP > &M, const Teuchos::RCP< OutputManager< Scalar > > &, const std::string &label, const Teuchos::RCP< Teuchos::ParameterList > ¶ms)
Return an instance of the specified MatOrthoManager subclass.
Belos's basic output manager for sending information of select verbosity levels to the appropriate ou...
A class for extending the status testing capabilities of Belos via logical combinations.
An implementation of StatusTestResNorm using a family of residual norms.
A Belos::StatusTest class for specifying a maximum number of iterations.
ScaleType convertStringToScaleType(const std::string &scaleType)
Convert the given string to its ScaleType enum value.
NormType
The type of vector norm to compute.
ETrans
Whether to apply the (conjugate) transpose of an operator.
static const double polyTol
Relative residual tolerance for matrix polynomial construction.
Structure to contain pointers to GmresIteration state variables.
Teuchos::RCP< const DM > z
The current right-hand side of the least squares system RY = Z.
Teuchos::RCP< const DM > R
The current upper-triangular matrix from the QR reduction of H.
Teuchos::RCP< const DM > H
The current Hessenberg matrix.
int curDim
The current dimension of the reduction.
Teuchos::RCP< const MV > V
The current Krylov basis.