14#ifndef TRACEMIN_RITZ_OP_HPP 
   15#define TRACEMIN_RITZ_OP_HPP 
   22#ifdef HAVE_ANASAZI_BELOS 
   23  #include "BelosMultiVecTraits.hpp" 
   24  #include "BelosLinearProblem.hpp" 
   25  #include "BelosPseudoBlockGmresSolMgr.hpp" 
   26  #include "BelosOperator.hpp" 
   27  #ifdef HAVE_ANASAZI_TPETRA 
   28    #include "BelosTpetraAdapter.hpp" 
   30  #ifdef HAVE_ANASAZI_EPETRA 
   31    #include "BelosEpetraAdapter.hpp" 
   35#include "Teuchos_RCP.hpp" 
   36#include "Teuchos_SerialDenseSolver.hpp" 
   37#include "Teuchos_ScalarTraitsDecl.hpp" 
   52template <
class Scalar, 
class MV, 
class OP>
 
   56  virtual ~TraceMinOp() { };
 
   57  virtual void Apply(
const MV& X, MV& Y) 
const =0;
 
   58  virtual void removeIndices(
const std::vector<int>& indicesToRemove) =0;
 
   69template <
class Scalar, 
class MV, 
class OP>
 
   78  TraceMinProjOp(
const Teuchos::RCP<const MV> X, 
const Teuchos::RCP<const OP> B, Teuchos::RCP<
Anasazi::MatOrthoManager<Scalar,MV,OP> >  orthman, Teuchos::Array<Teuchos::RCP<const MV> > auxVecs);
 
   84  void Apply(
const MV& X, MV& Y) 
const;
 
   87  void removeIndices(
const std::vector<int>& indicesToRemove);
 
   90  Teuchos::Array< Teuchos::RCP<const MV> > projVecs_;
 
   91  Teuchos::RCP<Anasazi::MatOrthoManager<Scalar,MV,OP> > orthman_;
 
   92  Teuchos::RCP<const OP> B_;
 
   94#ifdef ANASAZI_TEUCHOS_TIME_MONITOR 
   95  RCP<Teuchos::Time> ProjTime_;
 
  106template <
class Scalar, 
class MV, 
class OP>
 
  107class TraceMinRitzOp : 
public TraceMinOp<Scalar,MV,OP>
 
  109  template <
class Scalar_, 
class MV_, 
class OP_> 
friend class TraceMinProjRitzOp;
 
  110  template <
class Scalar_, 
class MV_, 
class OP_> 
friend class TraceMinProjRitzOpWithPrec;
 
  111  template <
class Scalar_, 
class MV_, 
class OP_> 
friend class TraceMinProjectedPrecOp;
 
  120  TraceMinRitzOp(
const Teuchos::RCP<const OP>& A, 
const Teuchos::RCP<const OP>& B = Teuchos::null, 
const Teuchos::RCP<const OP>& Prec = Teuchos::null);
 
  123  ~TraceMinRitzOp() { };
 
  126  void setRitzShifts(std::vector<Scalar> shifts) {ritzShifts_ = shifts;};
 
  128  Scalar getRitzShift(
const int subscript) { 
return ritzShifts_[subscript]; };
 
  130  Teuchos::RCP<TraceMinRitzOp<Scalar,MV,OP> > getPrec() { 
return Prec_; };
 
  133  void setInnerTol(
const std::vector<Scalar>& tolerances) { tolerances_ = tolerances; };
 
  135  void getInnerTol(std::vector<Scalar>& tolerances)
 const { tolerances = tolerances_; };
 
  137  void setMaxIts(
const int maxits) { maxits_ = maxits; };
 
  139  int getMaxIts()
 const { 
return maxits_; };
 
  142  void Apply(
const MV& X, MV& Y) 
const;
 
  145  void ApplyInverse(
const MV& X, MV& Y);
 
  147  void removeIndices(
const std::vector<int>& indicesToRemove);
 
  150  Teuchos::RCP<const OP> A_, B_;
 
  151  Teuchos::RCP<TraceMinRitzOp<Scalar,MV,OP> > Prec_;
 
  154  std::vector<Scalar> ritzShifts_;
 
  155  std::vector<Scalar> tolerances_;
 
  157  Teuchos::RCP< PseudoBlockMinres< Scalar,MV,TraceMinRitzOp<Scalar,MV,OP> > > solver_;
 
  159#ifdef ANASAZI_TEUCHOS_TIME_MONITOR 
  160  RCP<Teuchos::Time> PetraMultTime_, AopMultTime_;
 
  172template <
class Scalar, 
class MV, 
class OP>
 
  173class TraceMinProjRitzOp : 
public TraceMinOp<Scalar,MV,OP>
 
  180  TraceMinProjRitzOp(
const Teuchos::RCP<TraceMinRitzOp<Scalar,MV,OP> >& Op, 
const Teuchos::RCP<const MV> projVecs, 
const Teuchos::RCP<
Anasazi::MatOrthoManager<Scalar,MV,OP> > orthman = Teuchos::null);
 
  181  TraceMinProjRitzOp(
const Teuchos::RCP<TraceMinRitzOp<Scalar,MV,OP> >& Op, 
const Teuchos::RCP<const MV> projVecs, 
const Teuchos::RCP<
Anasazi::MatOrthoManager<Scalar,MV,OP> > orthman, Teuchos::Array<Teuchos::RCP<const MV> > auxVecs);
 
  184  void Apply(
const MV& X, MV& Y) 
const;
 
  188  void ApplyInverse(
const MV& X, MV& Y);
 
  190  void removeIndices(
const std::vector<int>& indicesToRemove);
 
  193  Teuchos::RCP< TraceMinRitzOp<Scalar,MV,OP> > Op_;
 
  194  Teuchos::RCP< TraceMinProjOp<Scalar,MV,OP> > projector_;
 
  196  Teuchos::RCP< PseudoBlockMinres< Scalar,MV,TraceMinProjRitzOp<Scalar,MV,OP> > > solver_;
 
  208template <
class Scalar, 
class MV, 
class OP>
 
  209class TraceMinProjectedPrecOp : 
public TraceMinOp<Scalar,MV,OP>
 
  218  TraceMinProjectedPrecOp(
const Teuchos::RCP<const OP> Op, 
const Teuchos::RCP<const MV> projVecs, Teuchos::RCP< 
Anasazi::MatOrthoManager<Scalar,MV,OP> > orthman, Teuchos::Array< Teuchos::RCP<const MV> > auxVecs);
 
  220  ~TraceMinProjectedPrecOp();
 
  222  void Apply(
const MV& X, MV& Y) 
const;
 
  224  void removeIndices(
const std::vector<int>& indicesToRemove);
 
  227  Teuchos::RCP<const OP> Op_;
 
  228  Teuchos::Array< Teuchos::RCP<const MV> > projVecs_;
 
  230  Teuchos::RCP< Anasazi::MatOrthoManager<Scalar,MV,OP> > orthman_;
 
  231  Teuchos::RCP<const OP> B_;
 
  242#ifdef HAVE_ANASAZI_BELOS 
  243template <
class Scalar, 
class MV, 
class OP>
 
  244class TraceMinProjRitzOpWithPrec : 
public TraceMinOp<Scalar,MV,OP>
 
  252  TraceMinProjRitzOpWithPrec(
const Teuchos::RCP<TraceMinRitzOp<Scalar,MV,OP> >& Op, 
const Teuchos::RCP<const MV> projVecs, Teuchos::RCP< 
Anasazi::MatOrthoManager<Scalar,MV,OP> > orthman = Teuchos::null);
 
  253  TraceMinProjRitzOpWithPrec(
const Teuchos::RCP<TraceMinRitzOp<Scalar,MV,OP> >& Op, 
const Teuchos::RCP<const MV> projVecs, Teuchos::RCP< 
Anasazi::MatOrthoManager<Scalar,MV,OP> > orthman, Teuchos::Array< Teuchos::RCP<const MV> > auxVecs);
 
  255  void Apply(
const MV& X, MV& Y) 
const;
 
  259  void ApplyInverse(
const MV& X, MV& Y);
 
  261  void removeIndices(
const std::vector<int>& indicesToRemove);
 
  264  Teuchos::RCP<TraceMinRitzOp<Scalar,MV,OP> > Op_;
 
  265  Teuchos::RCP<TraceMinProjectedPrecOp<Scalar,MV,OP> > Prec_;
 
  267  Teuchos::RCP< Belos::PseudoBlockGmresSolMgr< Scalar,MV,TraceMinOp<Scalar,MV,OP> > > solver_;
 
  268  Teuchos::RCP< Belos::LinearProblem<Scalar,MV,TraceMinOp<Scalar,MV,OP> > > problem_;
 
  284template <
class Scalar, 
class MV, 
class OP>
 
  285class OperatorTraits <Scalar, MV, 
Experimental::TraceMinOp<Scalar,MV,OP> >
 
  289    Apply (
const Experimental::TraceMinOp<Scalar,MV,OP>& Op,
 
  291           MV& y) {Op.Apply(x,y);};
 
  295    HasApplyTranspose (
const Experimental::TraceMinOp<Scalar,MV,OP>& Op) {
return true;};
 
  300#ifdef HAVE_ANASAZI_BELOS 
  303template <
class Scalar, 
class MV, 
class OP>
 
  304class OperatorTraits <Scalar, MV, 
Anasazi::Experimental::TraceMinOp<Scalar,MV,OP> >
 
  308    Apply (
const Anasazi::Experimental::TraceMinOp<Scalar,MV,OP>& Op,
 
  310           MV& y,  Belos::ETrans trans = NOTRANS) {Op.Apply(x,y);};
 
  314    HasApplyTranspose (
const Anasazi::Experimental::TraceMinOp<Scalar,MV,OP>& Op) {
return true;};
 
  323template <
class Scalar, 
class MV, 
class OP>
 
  324class OperatorTraits <Scalar, MV, 
Experimental::TraceMinRitzOp<Scalar,MV,OP> >
 
  328    Apply (
const Experimental::TraceMinRitzOp<Scalar,MV,OP>& Op,
 
  330           MV& y) {Op.Apply(x,y);};
 
  334    HasApplyTranspose (
const Experimental::TraceMinRitzOp<Scalar,MV,OP>& Op) {
return true;};
 
  342template <
class Scalar, 
class MV, 
class OP>
 
  343class OperatorTraits <Scalar, MV, 
Experimental::TraceMinProjRitzOp<Scalar,MV,OP> >
 
  347    Apply (
const Experimental::TraceMinProjRitzOp<Scalar,MV,OP>& Op,
 
  349           MV& y) {Op.Apply(x,y);};
 
  353    HasApplyTranspose (
const Experimental::TraceMinProjRitzOp<Scalar,MV,OP>& Op) {
return true;};
 
  361template <
class Scalar, 
class MV, 
class OP>
 
  362class OperatorTraits <Scalar, MV, 
Experimental::TraceMinProjectedPrecOp<Scalar,MV,OP> >
 
  366    Apply (
const Experimental::TraceMinProjectedPrecOp<Scalar,MV,OP>& Op,
 
  368           MV& y) {Op.Apply(x,y);};
 
  372    HasApplyTranspose (
const Experimental::TraceMinProjectedPrecOp<Scalar,MV,OP>& Op) {
return true;};
 
  385template <
class Scalar, 
class MV, 
class OP>
 
  387ONE(Teuchos::ScalarTraits<Scalar>::one())
 
  389#ifdef ANASAZI_TEUCHOS_TIME_MONITOR 
  390  ProjTime_ = Teuchos::TimeMonitor::getNewTimer(
"Anasazi: TraceMinProjOp::Apply()");
 
  395  if(orthman_ != Teuchos::null && B_ != Teuchos::null)
 
  396    orthman_->setOp(Teuchos::null);
 
  400  if(B_ != Teuchos::null)
 
  402    int nvec = MVT::GetNumberVecs(*X);
 
  404    if(orthman_ != Teuchos::null)
 
  407      Teuchos::RCP<MV> helperMV = MVT::CloneCopy(*X);
 
  408      orthman_->normalizeMat(*helperMV);
 
  409      projVecs_.push_back(helperMV);
 
  413      std::vector<Scalar> normvec(nvec);
 
  414      MVT::MvNorm(*X,normvec);
 
  415      for(
int i=0; i<nvec; i++)
 
  416        normvec[i] = ONE/normvec[i];
 
  417      Teuchos::RCP<MV> helperMV = MVT::CloneCopy(*X);
 
  418      MVT::MvScale(*helperMV,normvec);
 
  419      projVecs_.push_back(helperMV);
 
  423    projVecs_.push_back(MVT::CloneCopy(*X));
 
  427template <
class Scalar, 
class MV, 
class OP>
 
  428TraceMinProjOp<Scalar,MV,OP>::TraceMinProjOp(
const Teuchos::RCP<const MV> X, 
const Teuchos::RCP<const OP> B, Teuchos::RCP<
Anasazi::MatOrthoManager<Scalar,MV,OP> >  orthman, Teuchos::Array<Teuchos::RCP<const MV> > auxVecs) :
 
  429ONE(Teuchos::ScalarTraits<Scalar>::one())
 
  431#ifdef ANASAZI_TEUCHOS_TIME_MONITOR 
  432  ProjTime_ = Teuchos::TimeMonitor::getNewTimer(
"Anasazi: TraceMinProjOp::Apply()");
 
  437  if(B_ != Teuchos::null)
 
  438    orthman_->setOp(Teuchos::null);
 
  444  if(B_ != Teuchos::null)
 
  447    Teuchos::RCP<MV> helperMV = MVT::CloneCopy(*X);
 
  448    orthman_->normalizeMat(*helperMV);
 
  449    projVecs_.push_back(helperMV);
 
  453    projVecs_.push_back(MVT::CloneCopy(*X));
 
  458template <
class Scalar, 
class MV, 
class OP>
 
  459TraceMinProjOp<Scalar,MV,OP>::~TraceMinProjOp()
 
  461  if(orthman_ != Teuchos::null)
 
  467template <
class Scalar, 
class MV, 
class OP>
 
  468void TraceMinProjOp<Scalar,MV,OP>::Apply(
const MV& X, MV& Y)
 const 
  470#ifdef ANASAZI_TEUCHOS_TIME_MONITOR 
  471    Teuchos::TimeMonitor lcltimer( *ProjTime_ );
 
  474  if(orthman_ != Teuchos::null)
 
  477    orthman_->projectMat(Y,projVecs_);
 
  481    int nvec = MVT::GetNumberVecs(X);
 
  482    std::vector<Scalar> dotProducts(nvec);
 
  483    MVT::MvDot(*projVecs_[0],X,dotProducts);
 
  484    Teuchos::RCP<MV> helper = MVT::CloneCopy(*projVecs_[0]);
 
  485    MVT::MvScale(*helper,dotProducts);
 
  486    MVT::MvAddMv(ONE,X,-ONE,*helper,Y);
 
  492template <
class Scalar, 
class MV, 
class OP>
 
  493void TraceMinProjOp<Scalar,MV,OP>::removeIndices(
const std::vector<int>& indicesToRemove)
 
  495  if (orthman_ == Teuchos::null) {
 
  496    const int nprojvecs = projVecs_.size();
 
  497    const int nvecs = MVT::GetNumberVecs(*projVecs_[nprojvecs-1]);
 
  498    const int numRemoving = indicesToRemove.size();
 
  499    std::vector<int> helper(nvecs), indicesToLeave(nvecs-numRemoving);
 
  501    for (
int i=0; i<nvecs; i++) {
 
  505    std::set_difference(helper.begin(), helper.end(), indicesToRemove.begin(), indicesToRemove.end(), indicesToLeave.begin());
 
  507    Teuchos::RCP<MV> helperMV = MVT::CloneCopy(*projVecs_[nprojvecs-1],indicesToLeave);
 
  508    projVecs_[nprojvecs-1] = helperMV;
 
  518template <
class Scalar, 
class MV, 
class OP>
 
  519TraceMinRitzOp<Scalar,MV,OP>::TraceMinRitzOp(
const Teuchos::RCP<const OP>& A, 
const Teuchos::RCP<const OP>& B, 
const Teuchos::RCP<const OP>& Prec) :
 
  520ONE(Teuchos::ScalarTraits<Scalar>::one()),
 
  521ZERO(Teuchos::ScalarTraits<Scalar>::zero())
 
  528#ifdef ANASAZI_TEUCHOS_TIME_MONITOR 
  529  PetraMultTime_ = Teuchos::TimeMonitor::getNewTimer(
"Anasazi: TraceMinRitzOp: *Petra::Apply()");
 
  530  AopMultTime_ = Teuchos::TimeMonitor::getNewTimer(
"Anasazi: TraceMinRitzOp::Apply()");
 
  534  Teuchos::RCP<TraceMinRitzOp<Scalar,MV,OP> > linSolOp = Teuchos::rcp(
this);
 
  538  if(Prec != Teuchos::null)    
 
  539    Prec_ = Teuchos::rcp( 
new TraceMinRitzOp<Scalar,MV,OP>(Prec) );
 
  542  solver_ = Teuchos::rcp( 
new PseudoBlockMinres< Scalar,MV,TraceMinRitzOp<Scalar,MV,OP> >(linSolOp,Prec_) );
 
  547template <
class Scalar, 
class MV, 
class OP>
 
  548void TraceMinRitzOp<Scalar,MV,OP>::Apply(
const MV& X, MV& Y)
 const 
  550  int nvecs = MVT::GetNumberVecs(X);
 
  552#ifdef ANASAZI_TEUCHOS_TIME_MONITOR 
  553  Teuchos::TimeMonitor outertimer( *AopMultTime_ );
 
  558#ifdef ANASAZI_TEUCHOS_TIME_MONITOR 
  559    Teuchos::TimeMonitor lcltimer( *PetraMultTime_ );
 
  566  if(ritzShifts_.size() > 0)
 
  569    std::vector<int> nonzeroRitzIndices;
 
  570    nonzeroRitzIndices.reserve(nvecs);
 
  571    for(
int i=0; i<nvecs; i++)
 
  573      if(ritzShifts_[i] != ZERO)
 
  574        nonzeroRitzIndices.push_back(i);
 
  578    int numRitzShifts = nonzeroRitzIndices.size();
 
  579    if(numRitzShifts > 0)
 
  582      Teuchos::RCP<const MV> ritzX = MVT::CloneView(X,nonzeroRitzIndices);
 
  583      Teuchos::RCP<MV> ritzY = MVT::CloneViewNonConst(Y,nonzeroRitzIndices);
 
  586      std::vector<Scalar> nonzeroRitzShifts(numRitzShifts);
 
  587      for(
int i=0; i<numRitzShifts; i++)
 
  588        nonzeroRitzShifts[i] = ritzShifts_[nonzeroRitzIndices[i]];
 
  591      if(B_ != Teuchos::null)
 
  593        Teuchos::RCP<MV> BX = MVT::Clone(*ritzX,numRitzShifts);
 
  594        OPT::Apply(*B_,*ritzX,*BX);
 
  595        MVT::MvScale(*BX,nonzeroRitzShifts);
 
  596        MVT::MvAddMv(ONE,*ritzY,-ONE,*BX,*ritzY);
 
  601        Teuchos::RCP<MV> scaledX = MVT::CloneCopy(*ritzX);
 
  602        MVT::MvScale(*scaledX,nonzeroRitzShifts);
 
  603        MVT::MvAddMv(ONE,*ritzY,-ONE,*scaledX,*ritzY);
 
  611template <
class Scalar, 
class MV, 
class OP>
 
  612void TraceMinRitzOp<Scalar,MV,OP>::ApplyInverse(
const MV& X, MV& Y)
 
  614  int nvecs = MVT::GetNumberVecs(X);
 
  615  std::vector<int> indices(nvecs);
 
  616  for(
int i=0; i<nvecs; i++)
 
  619  Teuchos::RCP<const MV> rcpX = MVT::CloneView(X,indices);
 
  620  Teuchos::RCP<MV> rcpY = MVT::CloneViewNonConst(Y,indices);
 
  623  solver_->setTol(tolerances_);
 
  624  solver_->setMaxIter(maxits_);
 
  627  solver_->setSol(rcpY);
 
  628  solver_->setRHS(rcpX);
 
  636template <
class Scalar, 
class MV, 
class OP>
 
  637void TraceMinRitzOp<Scalar,MV,OP>::removeIndices(
const std::vector<int>& indicesToRemove)
 
  639  int nvecs = tolerances_.size();
 
  640  int numRemoving = indicesToRemove.size();
 
  641  std::vector<int> helper(nvecs), indicesToLeave(nvecs-numRemoving);
 
  642  std::vector<Scalar> helperS(nvecs-numRemoving);
 
  644  for(
int i=0; i<nvecs; i++)
 
  647  std::set_difference(helper.begin(), helper.end(), indicesToRemove.begin(), indicesToRemove.end(), indicesToLeave.begin());
 
  649  for(
int i=0; i<nvecs-numRemoving; i++)
 
  650    helperS[i] = ritzShifts_[indicesToLeave[i]];
 
  651  ritzShifts_ = helperS;
 
  653  for(
int i=0; i<nvecs-numRemoving; i++)
 
  654    helperS[i] = tolerances_[indicesToLeave[i]];
 
  655  tolerances_ = helperS;
 
  665template <
class Scalar, 
class MV, 
class OP>
 
  666TraceMinProjRitzOp<Scalar,MV,OP>::TraceMinProjRitzOp(
const Teuchos::RCP<TraceMinRitzOp<Scalar,MV,OP> >& Op, 
const Teuchos::RCP<const MV> projVecs, 
const Teuchos::RCP<
Anasazi::MatOrthoManager<Scalar,MV,OP> > orthman) 
 
  671  projector_ = Teuchos::rcp( 
new TraceMinProjOp<Scalar,MV,OP>(projVecs, Op_->B_, orthman) );
 
  674  Teuchos::RCP<TraceMinProjRitzOp<Scalar,MV,OP> > linSolOp = Teuchos::rcp(
this);
 
  678  solver_ = Teuchos::rcp( 
new PseudoBlockMinres< Scalar,MV,TraceMinProjRitzOp<Scalar,MV,OP> >(linSolOp) );
 
  682template <
class Scalar, 
class MV, 
class OP>
 
  683TraceMinProjRitzOp<Scalar,MV,OP>::TraceMinProjRitzOp(
const Teuchos::RCP<TraceMinRitzOp<Scalar,MV,OP> >& Op, 
const Teuchos::RCP<const MV> projVecs, 
const Teuchos::RCP<
Anasazi::MatOrthoManager<Scalar,MV,OP> > orthman, Teuchos::Array<Teuchos::RCP<const MV> > auxVecs)
 
  688  projector_ = Teuchos::rcp( 
new TraceMinProjOp<Scalar,MV,OP>(projVecs, Op_->B_, orthman, auxVecs) );
 
  691  Teuchos::RCP<TraceMinProjRitzOp<Scalar,MV,OP> > linSolOp = Teuchos::rcp(
this);
 
  695  solver_ = Teuchos::rcp( 
new PseudoBlockMinres< Scalar,MV,TraceMinProjRitzOp<Scalar,MV,OP> >(linSolOp) );
 
  701template <
class Scalar, 
class MV, 
class OP>
 
  702void TraceMinProjRitzOp<Scalar,MV,OP>::Apply(
const MV& X, MV& Y)
 const 
  704  int nvecs = MVT::GetNumberVecs(X);
 
  711  Teuchos::RCP<MV> APX = MVT::Clone(X,nvecs);
 
  712  OPT::Apply(*Op_,X,*APX);
 
  715  projector_->Apply(*APX,Y);
 
  720template <
class Scalar, 
class MV, 
class OP>
 
  721void TraceMinProjRitzOp<Scalar,MV,OP>::ApplyInverse(
const MV& X, MV& Y)
 
  723  int nvecs = MVT::GetNumberVecs(X);
 
  724  std::vector<int> indices(nvecs);
 
  725  for(
int i=0; i<nvecs; i++)
 
  728  Teuchos::RCP<MV> rcpY = MVT::CloneViewNonConst(Y,indices);
 
  729  Teuchos::RCP<MV> PX = MVT::Clone(X,nvecs);
 
  730  projector_->Apply(X,*PX);
 
  733  solver_->setTol(Op_->tolerances_);
 
  734  solver_->setMaxIter(Op_->maxits_);
 
  737  solver_->setSol(rcpY);
 
  746template <
class Scalar, 
class MV, 
class OP>
 
  747void TraceMinProjRitzOp<Scalar,MV,OP>::removeIndices(
const std::vector<int>& indicesToRemove)
 
  749  Op_->removeIndices(indicesToRemove);
 
  751  projector_->removeIndices(indicesToRemove);
 
  757#ifdef HAVE_ANASAZI_BELOS 
  763template <
class Scalar, 
class MV, 
class OP>
 
  764TraceMinProjRitzOpWithPrec<Scalar,MV,OP>::TraceMinProjRitzOpWithPrec(
const Teuchos::RCP<TraceMinRitzOp<Scalar,MV,OP> >& Op, 
const Teuchos::RCP<const MV> projVecs, Teuchos::RCP< 
Anasazi::MatOrthoManager<Scalar,MV,OP> > orthman) :
 
  765ONE(Teuchos::ScalarTraits<Scalar>::one())
 
  770  Teuchos::RCP<TraceMinProjRitzOpWithPrec<Scalar,MV,OP> > linSolOp = Teuchos::rcp(
this);
 
  774  problem_ = Teuchos::rcp(
new Belos::LinearProblem< Scalar,MV,TraceMinOp<Scalar,MV,OP> >());
 
  777  problem_->setOperator(linSolOp);
 
  781  Prec_ = Teuchos::rcp( 
new TraceMinProjectedPrecOp<Scalar,MV,OP>(Op_->Prec_->A_, projVecs, orthman) );
 
  786  solver_ = Teuchos::rcp( 
new Belos::PseudoBlockGmresSolMgr< Scalar,MV,TraceMinOp<Scalar,MV,OP> >());
 
  790template <
class Scalar, 
class MV, 
class OP>
 
  791TraceMinProjRitzOpWithPrec<Scalar,MV,OP>::TraceMinProjRitzOpWithPrec(
const Teuchos::RCP<TraceMinRitzOp<Scalar,MV,OP> >& Op, 
const Teuchos::RCP<const MV> projVecs, Teuchos::RCP< 
Anasazi::MatOrthoManager<Scalar,MV,OP> > orthman, Teuchos::Array< Teuchos::RCP<const MV> > auxVecs) :
 
  792ONE(Teuchos::ScalarTraits<Scalar>::one())
 
  797  Teuchos::RCP<const TraceMinProjRitzOpWithPrec<Scalar,MV,OP> > linSolOp = Teuchos::rcp(
this);
 
  801  problem_ = Teuchos::rcp(
new Belos::LinearProblem< Scalar,MV,TraceMinOp<Scalar,MV,OP> >());
 
  804  problem_->setOperator(linSolOp);
 
  808  Prec_ = Teuchos::rcp( 
new TraceMinProjectedPrecOp<Scalar,MV,OP>(Op_->Prec_->A_, projVecs, orthman, auxVecs) );
 
  813  solver_ = Teuchos::rcp( 
new Belos::PseudoBlockGmresSolMgr< Scalar,MV,TraceMinOp<Scalar,MV,OP> >());
 
  817template <
class Scalar, 
class MV, 
class OP>
 
  818void TraceMinProjRitzOpWithPrec<Scalar,MV,OP>::Apply(
const MV& X, MV& Y)
 const 
  820  int nvecs = MVT::GetNumberVecs(X);
 
  821  RCP<MV> Ydot = MVT::Clone(Y,nvecs);
 
  822  OPT::Apply(*Op_,X,*Ydot);
 
  823  Prec_->Apply(*Ydot,Y);
 
  827template <
class Scalar, 
class MV, 
class OP>
 
  828void TraceMinProjRitzOpWithPrec<Scalar,MV,OP>::ApplyInverse(
const MV& X, MV& Y)
 
  830  int nvecs = MVT::GetNumberVecs(X);
 
  831  std::vector<int> indices(nvecs);
 
  832  for(
int i=0; i<nvecs; i++)
 
  835  Teuchos::RCP<MV> rcpY = MVT::CloneViewNonConst(Y,indices);
 
  836  Teuchos::RCP<MV> rcpX = MVT::Clone(X,nvecs);
 
  838  Prec_->Apply(X,*rcpX);
 
  841  problem_->setProblem(rcpY,rcpX);
 
  844  solver_->setProblem(problem_);
 
  850  Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::rcp(
new Teuchos::ParameterList());
 
  851  pl->set(
"Convergence Tolerance", Op_->tolerances_[0]);
 
  852  pl->set(
"Block Size", nvecs);
 
  855  pl->set(
"Maximum Iterations", Op_->getMaxIts());
 
  856  pl->set(
"Num Blocks", Op_->getMaxIts());
 
  857  solver_->setParameters(pl);
 
  864template <
class Scalar, 
class MV, 
class OP>
 
  865void TraceMinProjRitzOpWithPrec<Scalar,MV,OP>::removeIndices(
const std::vector<int>& indicesToRemove)
 
  867  Op_->removeIndices(indicesToRemove);
 
  869  Prec_->removeIndices(indicesToRemove);
 
  879template <
class Scalar, 
class MV, 
class OP>
 
  880TraceMinProjectedPrecOp<Scalar,MV,OP>::TraceMinProjectedPrecOp(
const Teuchos::RCP<const OP> Op, 
const Teuchos::RCP<const MV> projVecs, Teuchos::RCP< 
Anasazi::MatOrthoManager<Scalar,MV,OP> > orthman) :
 
  881ONE (Teuchos::ScalarTraits<Scalar>::one())
 
  886  int nvecs = MVT::GetNumberVecs(*projVecs);
 
  887  Teuchos::RCP<MV> helperMV = MVT::Clone(*projVecs,nvecs);
 
  890  OPT::Apply(*Op_,*projVecs,*helperMV);
 
  892  if(orthman_ != Teuchos::null)
 
  895    B_ = orthman_->getOp();
 
  896    orthman_->setOp(Op_);
 
  898    Teuchos::RCP<MV> locProjVecs = MVT::CloneCopy(*projVecs);
 
  901    const int rank = orthman_->normalizeMat (*locProjVecs, Teuchos::null, helperMV);
 
  904    TEUCHOS_TEST_FOR_EXCEPTION(rank != nvecs, std::runtime_error, 
"Belos::TraceMinProjectedPrecOp: constructor: Loss of orthogonality detected.");
 
  906    orthman_->setOp(Teuchos::null);
 
  910    std::vector<Scalar> dotprods(nvecs);
 
  911    MVT::MvDot(*projVecs,*helperMV,dotprods);
 
  913    for(
int i=0; i<nvecs; i++)
 
  914      dotprods[i] = ONE/sqrt(dotprods[i]);
 
  916    MVT::MvScale(*helperMV, dotprods);
 
  919  projVecs_.push_back(helperMV);
 
  923template <
class Scalar, 
class MV, 
class OP>
 
  924TraceMinProjectedPrecOp<Scalar,MV,OP>::TraceMinProjectedPrecOp(
const Teuchos::RCP<const OP> Op, 
const Teuchos::RCP<const MV> projVecs, Teuchos::RCP< 
Anasazi::MatOrthoManager<Scalar,MV,OP> > orthman, Teuchos::Array< Teuchos::RCP<const MV> > auxVecs) :
 
  925ONE(Teuchos::ScalarTraits<Scalar>::one())
 
  931  Teuchos::RCP<MV> locProjVecs;
 
  934  if(auxVecs.size() > 0)
 
  937    nvecs = MVT::GetNumberVecs(*projVecs);
 
  938    for(
int i=0; i<auxVecs.size(); i++)
 
  939      nvecs += MVT::GetNumberVecs(*auxVecs[i]);
 
  942    locProjVecs = MVT::Clone(*projVecs, nvecs);
 
  946    std::vector<int> locind(nvecs);
 
  948    locind.resize(MVT::GetNumberVecs(*projVecs));
 
  949    for (
size_t i = 0; i<locind.size(); i++) {
 
  950      locind[i] = startIndex + i;
 
  952    startIndex += locind.size();
 
  953    MVT::SetBlock(*projVecs,locind,*locProjVecs);
 
  955    for (
size_t i=0; i < static_cast<size_t> (auxVecs.size ()); ++i)
 
  957      locind.resize(MVT::GetNumberVecs(*auxVecs[i]));
 
  958      for(
size_t j=0; j<locind.size(); j++) locind[j] = startIndex + j;
 
  959      startIndex += locind.size();
 
  960      MVT::SetBlock(*auxVecs[i],locind,*locProjVecs);
 
  966    nvecs = MVT::GetNumberVecs(*projVecs);
 
  967    locProjVecs = MVT::CloneCopy(*projVecs);
 
  970  Teuchos::RCP<MV> helperMV = MVT::Clone(*projVecs,nvecs);
 
  973  OPT::Apply(*Op_,*locProjVecs,*helperMV);
 
  976  B_ = orthman_->getOp();
 
  977  orthman_->setOp(Op_);
 
  980  const int rank = orthman_->normalizeMat(*locProjVecs,Teuchos::null,helperMV);
 
  982  projVecs_.push_back(helperMV);
 
  987  TEUCHOS_TEST_FOR_EXCEPTION(
 
  988          rank != nvecs, std::runtime_error, 
 
  989    "Belos::TraceMinProjectedPrecOp: constructor: Loss of orthogonality detected.");
 
  991  orthman_->setOp(Teuchos::null);
 
  995template <
class Scalar, 
class MV, 
class OP>
 
  996TraceMinProjectedPrecOp<Scalar,MV,OP>::~TraceMinProjectedPrecOp()
 
  998  if(orthman_ != Teuchos::null)
 
 1004template <
class Scalar, 
class MV, 
class OP>
 
 1005void TraceMinProjectedPrecOp<Scalar,MV,OP>::Apply(
const MV& X, MV& Y)
 const 
 1007  int nvecsX = MVT::GetNumberVecs(X);
 
 1009  if(orthman_ != Teuchos::null)
 
 1012    int nvecsP = MVT::GetNumberVecs(*projVecs_[0]);
 
 1013    OPT::Apply(*Op_,X,Y);
 
 1015    Teuchos::RCP< Teuchos::SerialDenseMatrix<int,Scalar> > projX = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,Scalar>(nvecsP,nvecsX));
 
 1017    MVT::MvTransMv(ONE, *projVecs_[0], X, *projX);
 
 1019    MVT::MvTimesMatAddMv(-ONE, *projVecs_[0], *projX, ONE, Y);
 
 1023    Teuchos::RCP<MV> MX = MVT::Clone(X,nvecsX);
 
 1024    OPT::Apply(*Op_,X,*MX);
 
 1026    std::vector<Scalar> dotprods(nvecsX);
 
 1027    MVT::MvDot(*projVecs_[0], X, dotprods);
 
 1029    Teuchos::RCP<MV> helper = MVT::CloneCopy(*projVecs_[0]);
 
 1030    MVT::MvScale(*helper, dotprods);
 
 1031    MVT::MvAddMv(ONE, *MX, -ONE, *helper, Y);
 
 1036template <
class Scalar, 
class MV, 
class OP>
 
 1037void TraceMinProjectedPrecOp<Scalar,MV,OP>::removeIndices(
const std::vector<int>& indicesToRemove)
 
 1039  if(orthman_ == Teuchos::null)
 
 1041    int nvecs = MVT::GetNumberVecs(*projVecs_[0]);
 
 1042    int numRemoving = indicesToRemove.size();
 
 1043    std::vector<int> helper(nvecs), indicesToLeave(nvecs-numRemoving);
 
 1045    for(
int i=0; i<nvecs; i++)
 
 1048    std::set_difference(helper.begin(), helper.end(), indicesToRemove.begin(), indicesToRemove.end(), indicesToLeave.begin());
 
 1050    Teuchos::RCP<const MV> helperMV = MVT::CloneCopy(*projVecs_[0],indicesToLeave);
 
 1051    projVecs_[0] = helperMV;
 
Anasazi header file which uses auto-configuration information to include necessary C++ headers.
 
Templated virtual class for providing orthogonalization/orthonormalization methods with matrix-based ...
 
Abstract base class for trace minimization eigensolvers.
 
Anasazi's templated virtual class for providing routines for orthogonalization and orthonormalization...
 
Traits class which defines basic operations on multivectors.
 
Virtual base class which defines basic traits for the operator type.
 
static void Apply(const OP &Op, const MV &x, MV &y)
Application method which performs operation y = Op*x. An OperatorError exception is thrown if there i...
 
Namespace Anasazi contains the classes, structs, enums and utilities used by the Anasazi package.