11#ifndef BELOS_LINEAR_PROBLEM_HPP
12#define BELOS_LINEAR_PROBLEM_HPP
19#include "Teuchos_ParameterList.hpp"
20#include "Teuchos_TimeMonitor.hpp"
49 template <
class ScalarType,
class MV,
class OP>
71 const Teuchos::RCP<MV> &X,
72 const Teuchos::RCP<const MV> &B);
101 void setLHS (
const Teuchos::RCP<MV> &X) {
110 void setRHS (
const Teuchos::RCP<const MV> &B) {
164 virtual void setLSIndex (
const std::vector<int>& index);
184 void setLabel (
const std::string& label);
225 bool updateLP =
false,
226 ScalarType scale = Teuchos::ScalarTraits<ScalarType>::one());
248 ScalarType scale = Teuchos::ScalarTraits<ScalarType>::one() )
const
283 setProblem (
const Teuchos::RCP<MV> &newX = Teuchos::null,
284 const Teuchos::RCP<const MV> &newB = Teuchos::null);
298 Teuchos::RCP<const MV>
getRHS()
const {
return(
B_); }
384 Teuchos::Array<Teuchos::RCP<Teuchos::Time> >
getTimers()
const {
432 virtual void apply(
const MV& x, MV& y )
const;
441 virtual void applyOp(
const MV& x, MV& y )
const;
464 virtual void computeCurrResVec( MV* R ,
const MV* X = 0,
const MV* B = 0 )
const;
478 Teuchos::RCP<const OP>
A_;
487 Teuchos::RCP<const MV>
B_;
505 Teuchos::RCP<const OP>
LP_;
508 Teuchos::RCP<const OP>
RP_;
556 template <
class ScalarType,
class MV,
class OP>
569 template <
class ScalarType,
class MV,
class OP>
571 const Teuchos::RCP<MV> &X,
572 const Teuchos::RCP<const MV> &B
588 template <
class ScalarType,
class MV,
class OP>
614 template <
class ScalarType,
class MV,
class OP>
622 curB_ = Teuchos::null;
623 curX_ = Teuchos::null;
626 int validIdx = 0, ivalidIdx = 0;
634 newIndex[validIdx] = i;
638 iIndex[ivalidIdx] = i;
642 vldIndex.resize(validIdx);
643 newIndex.resize(validIdx);
644 iIndex.resize(ivalidIdx);
681 template <
class ScalarType,
class MV,
class OP>
698 newIndex[validIdx] = i;
709 curX_ = Teuchos::null;
710 curB_ = Teuchos::null;
715 template <
class ScalarType,
class MV,
class OP>
726 if (update.is_null())
744 RCP<MV> rightPrecUpdate =
766 RCP<MV> rightPrecUpdate =
777 template <
class ScalarType,
class MV,
class OP>
784 std::string opLabel =
label_ +
": Operation Op*x";
785#ifdef BELOS_TEUCHOS_TIME_MONITOR
786 timerOp_ = Teuchos::TimeMonitor::getNewCounter( opLabel );
790 std::string precLabel =
label_ +
": Operation Prec*x";
791#ifdef BELOS_TEUCHOS_TIME_MONITOR
792 timerPrec_ = Teuchos::TimeMonitor::getNewCounter( precLabel );
798 template <
class ScalarType,
class MV,
class OP>
802 const Teuchos::RCP<const MV> &newB)
806 std::string opLabel =
label_ +
": Operation Op*x";
807#ifdef BELOS_TEUCHOS_TIME_MONITOR
808 timerOp_ = Teuchos::TimeMonitor::getNewCounter( opLabel );
812 std::string precLabel =
label_ +
": Operation Prec*x";
813#ifdef BELOS_TEUCHOS_TIME_MONITOR
814 timerPrec_ = Teuchos::TimeMonitor::getNewCounter( precLabel );
821 if (newX != Teuchos::null)
823 if (newB != Teuchos::null)
828 curX_ = Teuchos::null;
829 curB_ = Teuchos::null;
833 if (
A_ == Teuchos::null ||
X_ == Teuchos::null ||
B_ == Teuchos::null) {
850 if (
LP_!=Teuchos::null) {
869 if (
LP_!=Teuchos::null) {
904 template <
class ScalarType,
class MV,
class OP>
913 template <
class ScalarType,
class MV,
class OP>
922 template <
class ScalarType,
class MV,
class OP>
929 return Teuchos::null;
933 template <
class ScalarType,
class MV,
class OP>
940 return Teuchos::null;
944 template <
class ScalarType,
class MV,
class OP>
950 const bool leftPrec =
LP_ != null;
951 const bool rightPrec =
RP_ != null;
953 if(leftPrec || rightPrec) {
963 if (!leftPrec && !rightPrec) {
969 else if( leftPrec && rightPrec )
993 template <
class ScalarType,
class MV,
class OP>
996#ifdef BELOS_TEUCHOS_TIME_MONITOR
997 Teuchos::TimeMonitor OpTimer(*
timerOp_);
1002 MVT::MvAddMv( Teuchos::ScalarTraits<ScalarType>::one(), x,
1003 Teuchos::ScalarTraits<ScalarType>::zero(), x, y );
1007 template <
class ScalarType,
class MV,
class OP>
1009 if (
LP_!=Teuchos::null) {
1010#ifdef BELOS_TEUCHOS_TIME_MONITOR
1016 MVT::MvAddMv( Teuchos::ScalarTraits<ScalarType>::one(), x,
1017 Teuchos::ScalarTraits<ScalarType>::zero(), x, y );
1021 template <
class ScalarType,
class MV,
class OP>
1023 if (
RP_!=Teuchos::null) {
1024#ifdef BELOS_TEUCHOS_TIME_MONITOR
1030 MVT::MvAddMv( Teuchos::ScalarTraits<ScalarType>::one(), x,
1031 Teuchos::ScalarTraits<ScalarType>::zero(), x, y );
1035 template <
class ScalarType,
class MV,
class OP>
1041 if (
LP_!=Teuchos::null)
1056 Teuchos::RCP<const MV> localB, localX;
1058 localB = Teuchos::rcp( B,
false );
1063 localX = Teuchos::rcp( X,
false );
1067 if (
LP_!=Teuchos::null)
1084 template <
class ScalarType,
class MV,
class OP>
1095 Teuchos::RCP<const MV> localB, localX;
1097 localB = Teuchos::rcp( B,
false );
1102 localX = Teuchos::rcp( X,
false );
Declaration of basic traits for the multivector type.
Class which defines basic traits for the operator type.
BelosError(const std::string &what_arg)
LinearProblemError(const std::string &what_arg)
Teuchos::RCP< const MV > PR0_user_
User-defined preconditioned initial residual of the linear system.
std::vector< int > rhsIndex_
Indices of current linear systems being solver for.
bool isSet_
Has the linear problem to solve been set?
void setLabel(const std::string &label)
Set the label prefix used by the timers in this object.
bool isRightPrec() const
Whether the linear system is being preconditioned on the right.
void setInitPrecResVec(const Teuchos::RCP< const MV > &PR0)
Set the user-defined preconditioned residual of linear problem .
int blocksize_
Current block size of linear system.
virtual void applyLeftPrec(const MV &x, MV &y) const
Apply ONLY the left preconditioner to x, returning y.
bool isSolutionUpdated() const
Has the current approximate solution been updated?
std::string label_
Linear problem label that prefixes the timer labels.
Teuchos::RCP< const MV > curB_
Current right-hand side of the linear system.
void setLeftPrec(const Teuchos::RCP< const OP > &LP)
Set left preconditioner (LP) of linear problem .
Teuchos::RCP< const MV > B_
Right-hand side of linear system.
virtual void computeCurrPrecResVec(MV *R, const MV *X=0, const MV *B=0) const
Compute a residual R for this operator given a solution X, and right-hand side B.
virtual ~LinearProblem(void)
Destructor (declared virtual for memory safety of derived classes).
virtual void apply(const MV &x, MV &y) const
Apply the composite operator of this linear problem to x, returning y.
void setLHS(const Teuchos::RCP< MV > &X)
Set left-hand-side X of linear problem .
virtual void setLSIndex(const std::vector< int > &index)
Tell the linear problem which linear system(s) need to be solved next.
bool solutionUpdated_
Has the current approximate solution been updated?
Teuchos::RCP< MV > PR0_
Preconditioned initial residual of the linear system.
virtual void applyRightPrec(const MV &x, MV &y) const
Apply ONLY the right preconditioner to x, returning y.
Teuchos::RCP< const OP > LP_
Left preconditioning operator of linear system.
Teuchos::RCP< const OP > getLeftPrec() const
Get a pointer to the left preconditioner.
Teuchos::RCP< const MV > R0_user_
User-defined initial residual of the linear system.
Teuchos::RCP< MV > curX_
Current solution vector of the linear system.
Teuchos::RCP< MV > R0_
Initial residual of the linear system.
void setRightPrec(const Teuchos::RCP< const OP > &RP)
Set right preconditioner (RP) of linear problem .
virtual void setCurrLS()
Tell the linear problem that the solver is finished with the current linear system.
int getLSNumber() const
The number of linear systems that have been set.
void setHermitian(bool isSym=true)
Tell the linear problem that the (preconditioned) operator is Hermitian.
void setOperator(const Teuchos::RCP< const OP > &A)
Set the operator A of the linear problem .
bool isProblemSet() const
Whether the problem has been set.
int num2Solve_
Number of linear systems that are currently being solver for ( <= blocksize_ ).
Teuchos::RCP< Teuchos::Time > timerPrec_
Teuchos::RCP< const MV > getInitPrecResVec() const
A pointer to the preconditioned initial residual vector.
Teuchos::RCP< const OP > getRightPrec() const
Get a pointer to the right preconditioner.
Teuchos::RCP< const OP > getOperator() const
A pointer to the (unpreconditioned) operator A.
Teuchos::RCP< Teuchos::Time > timerOp_
Timers.
const std::vector< int > & getLSIndex() const
(Zero-based) indices of the linear system(s) currently being solved.
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
The timers for this object.
bool isHermitian_
Whether the operator A is symmetric (in real arithmetic, or Hermitian in complex arithmetic).
LinearProblem(void)
Default constructor.
void setRHS(const Teuchos::RCP< const MV > &B)
Set right-hand-side B of linear problem .
Teuchos::RCP< const MV > getRHS() const
A pointer to the right-hand side B.
bool isHermitian() const
Whether the (preconditioned) operator is Hermitian.
Teuchos::RCP< MV > getLHS() const
A pointer to the left-hand side X.
virtual void applyOp(const MV &x, MV &y) const
Apply ONLY the operator to x, returning y.
Teuchos::RCP< const MV > getInitResVec() const
A pointer to the initial unpreconditioned residual vector.
Teuchos::RCP< MV > getCurrLHSVec()
Get a pointer to the current left-hand side (solution) of the linear system.
bool isLeftPrec() const
Whether the linear system is being preconditioned on the left.
Teuchos::RCP< const MV > getCurrRHSVec()
Get a pointer to the current right-hand side of the linear system.
virtual void computeCurrResVec(MV *R, const MV *X=0, const MV *B=0) const
Compute a residual R for this operator given a solution X, and right-hand side B.
int lsNum_
Number of linear systems that have been loaded in this linear problem object.
Teuchos::RCP< MV > Y_temp_
Scratch vector for use in apply().
Teuchos::RCP< MV > X_
Solution vector of linear system.
Teuchos::RCP< const OP > A_
Operator of linear system.
virtual Teuchos::RCP< MV > updateSolution(const Teuchos::RCP< MV > &update=Teuchos::null, bool updateLP=false, ScalarType scale=Teuchos::ScalarTraits< ScalarType >::one())
Compute the new solution to the linear system using the given update vector.
void setInitResVec(const Teuchos::RCP< const MV > &R0)
Set the user-defined residual of linear problem .
virtual Teuchos::RCP< MV > updateSolution(const Teuchos::RCP< MV > &update=Teuchos::null, ScalarType scale=Teuchos::ScalarTraits< ScalarType >::one()) const
Compute the new solution to the linear system using the given update vector.
virtual bool setProblem(const Teuchos::RCP< MV > &newX=Teuchos::null, const Teuchos::RCP< const MV > &newB=Teuchos::null)
Set up the linear problem manager.
Teuchos::RCP< const OP > RP_
Right preconditioning operator of linear system.
Traits class which defines basic operations on multivectors.
static void MvRandom(MV &mv)
Replace the vectors in mv with random vectors.
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).
static void MvAddMv(const ScalarType alpha, const MV &A, const ScalarType beta, const MV &B, MV &mv)
Replace mv with .
static void MvInit(MV &mv, const ScalarType alpha=Teuchos::ScalarTraits< ScalarType >::zero())
Replace each element of the vectors in mv with alpha.
static void SetBlock(const MV &A, const std::vector< int > &index, MV &mv)
Copy the vectors in A to a set of vectors in mv indicated by the indices given in index.
static int GetNumberVecs(const MV &mv)
Obtain the number of vectors in mv.
Class which defines basic traits for the operator type.
static void Apply(const OP &Op, const MV &x, MV &y, ETrans trans=NOTRANS)
Apply Op to x, putting the result into y.