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,
class DM = DefaultDenseMatrix<
int,ScalarType>>
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) {
225 bool updateLP =
false,
226 ScalarType scale = Teuchos::ScalarTraits<ScalarType>::one());
248 ScalarType scale = Teuchos::ScalarTraits<ScalarType>::one() )
const
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;
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,
class DM>
569 template <
class ScalarType,
class MV,
class OP,
class DM>
571 const Teuchos::RCP<MV> &X,
572 const Teuchos::RCP<const MV> &B
588 template <
class ScalarType,
class MV,
class OP,
class DM>
614 template <
class ScalarType,
class MV,
class OP,
class DM>
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,
class DM>
698 newIndex[validIdx] = i;
709 curX_ = Teuchos::null;
710 curB_ = Teuchos::null;
715 template <
class ScalarType,
class MV,
class OP,
class DM>
726 if (update.is_null())
744 RCP<MV> rightPrecUpdate =
766 RCP<MV> rightPrecUpdate =
777 template <
class ScalarType,
class MV,
class OP,
class DM>
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,
class DM>
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,
class DM>
913 template <
class ScalarType,
class MV,
class OP,
class DM>
922 template <
class ScalarType,
class MV,
class OP,
class DM>
929 return Teuchos::null;
933 template <
class ScalarType,
class MV,
class OP,
class DM>
940 return Teuchos::null;
944 template <
class ScalarType,
class MV,
class OP,
class DM>
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,
class DM>
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,
class DM>
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,
class DM>
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,
class DM>
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,
class DM>
1095 Teuchos::RCP<const MV> localB, localX;
1097 localB = Teuchos::rcp( B,
false );
1102 localX = Teuchos::rcp( X,
false );
1114#ifdef HAVE_BELOS_TPETRA
1117#define BELOS_TPETRA_LINEARPROBLEM_NOEXTERN_CALL(SC, LO, GO, NT) \
1118 BELOS_TPETRA_CALL(Belos::LinearProblem, SC, LO, GO, NT)
1120#define BELOS_TPETRA_LINEARPROBLEM_EXTERN_CALL(SC, LO, GO, NT) \
1121 BELOS_TPETRA_EXTERN_CALL(Belos::LinearProblem, SC, LO, GO, NT)
1123TPETRA_INSTANTIATE_SLGN_NO_ORDINAL_SCALAR(BELOS_TPETRA_LINEARPROBLEM_EXTERN_CALL)
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< MV > Y_temp_
Teuchos::RCP< const MV > getInitPrecResVec() const
A pointer to the preconditioned initial residual vector.
Teuchos::RCP< const MV > getRHS() const
A pointer to the right-hand side B.
Teuchos::RCP< const OP > LP_
void setHermitian(bool isSym=true)
Tell the linear problem that the (preconditioned) operator is Hermitian.
LinearProblem(void)
Default constructor.
virtual void apply(const MV &x, MV &y) const
Apply the composite operator of this linear problem to x, returning y.
Teuchos::RCP< const MV > PR0_user_
void setLabel(const std::string &label)
Set the label prefix used by the timers in this object.
virtual ~LinearProblem(void)
Destructor (declared virtual for memory safety of derived classes).
Teuchos::RCP< Teuchos::Time > timerPrec_
virtual void applyOp(const MV &x, MV &y) const
Apply ONLY the operator to x, returning y.
void setRightPrec(const Teuchos::RCP< const OP > &RP)
Set right preconditioner (RP) of linear problem .
bool isProblemSet() const
Whether the problem has been set.
virtual bool setProblem(const Teuchos::RCP< MV > &newX=Teuchos::null, const Teuchos::RCP< const MV > &newB=Teuchos::null)
Set up the linear problem manager.
virtual void setLSIndex(const std::vector< int > &index)
Tell the linear problem which linear system(s) need to be solved next.
bool isSolutionUpdated() const
Has the current approximate solution been updated?
LinearProblem(const Teuchos::RCP< const OP > &A, const Teuchos::RCP< MV > &X, const Teuchos::RCP< const MV > &B)
Unpreconditioned linear system constructor.
void setRHS(const Teuchos::RCP< const MV > &B)
Set right-hand-side B of linear problem .
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.
virtual void setCurrLS()
Tell the linear problem that the solver is finished with the current 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 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.
const std::vector< int > & getLSIndex() const
(Zero-based) indices of the linear system(s) currently being solved.
bool isHermitian() const
Whether the (preconditioned) operator is Hermitian.
Teuchos::RCP< const OP > A_
Teuchos::RCP< MV > getLHS() const
A pointer to the left-hand side X.
Teuchos::RCP< const MV > B_
int getLSNumber() const
The number of linear systems that have been set.
void setLeftPrec(const Teuchos::RCP< const OP > &LP)
Set left preconditioner (LP) of linear problem .
Teuchos::RCP< const OP > getOperator() const
A pointer to the (unpreconditioned) operator A.
Teuchos::RCP< const MV > curB_
void setInitPrecResVec(const Teuchos::RCP< const MV > &PR0)
Set the user-defined preconditioned residual of linear problem .
std::vector< int > rhsIndex_
bool isLeftPrec() const
Whether the linear system is being preconditioned on the left.
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.
Teuchos::RCP< const OP > RP_
Teuchos::RCP< const OP > getLeftPrec() const
Get a pointer to the left preconditioner.
Teuchos::RCP< const OP > getRightPrec() const
Get a pointer to the right preconditioner.
bool isRightPrec() const
Whether the linear system is being preconditioned on the right.
Teuchos::RCP< const MV > R0_user_
Teuchos::RCP< const MV > getCurrRHSVec()
Get a pointer to the current right-hand side of the linear system.
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
The timers for this object.
Teuchos::RCP< const MV > getInitResVec() const
A pointer to the initial unpreconditioned residual vector.
virtual void applyRightPrec(const MV &x, MV &y) const
Apply ONLY the right preconditioner to x, returning y.
void setInitResVec(const Teuchos::RCP< const MV > &R0)
Set the user-defined residual of linear problem .
void setOperator(const Teuchos::RCP< const OP > &A)
Set the operator A of the linear problem .
virtual void applyLeftPrec(const MV &x, MV &y) const
Apply ONLY the left preconditioner to x, returning y.
void setLHS(const Teuchos::RCP< MV > &X)
Set left-hand-side X of linear problem .
Teuchos::RCP< MV > getCurrLHSVec()
Get a pointer to the current left-hand side (solution) of the linear system.
Teuchos::RCP< Teuchos::Time > timerOp_
LinearProblem(const LinearProblem< ScalarType, MV, OP, DM > &Problem)
Copy constructor.
Traits class which defines basic operations on multivectors.
static void MvInit(MV &mv, const ScalarType alpha=Teuchos::ScalarTraits< ScalarType >::zero())
static Teuchos::RCP< MV > Clone(const MV &mv, const int numvecs)
static void MvRandom(MV &mv)
static void MvAddMv(const ScalarType alpha, const MV &A, const ScalarType beta, const MV &B, MV &mv)
static Teuchos::RCP< const MV > CloneView(const MV &mv, const std::vector< int > &index)
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 int GetNumberVecs(const MV &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.