43 #ifndef IFPACK2_DIAGONAL_DEF_HPP
44 #define IFPACK2_DIAGONAL_DEF_HPP
46 #include "Ifpack2_Diagonal_decl.hpp"
47 #include "Ifpack2_Condest.hpp"
51 template<
class MatrixType>
53 : isInitialized_(false),
55 domainMap_(A->getDomainMap()),
56 rangeMap_(A->getRangeMap()),
62 condEst_ (-Teuchos::ScalarTraits<magnitudeType>::one ())
66 template<
class MatrixType>
68 : isInitialized_(false),
77 condEst_ (-Teuchos::ScalarTraits<magnitudeType>::one ())
81 template<
class MatrixType>
86 template<
class MatrixType>
91 template<
class MatrixType>
94 if (isInitialized_)
return;
97 if (matrix_ != Teuchos::null) {
98 matrix_->getLocalDiagOffsets(offsets_);
101 isInitialized_ =
true;
105 template<
class MatrixType>
108 if (!isInitialized_) initialize();
112 if (matrix_ == Teuchos::null) {
119 matrix_->getLocalDiagCopy(*tmp_vec, offsets_());
120 tmp_vec->reciprocal(*tmp_vec);
122 inversediag_ = tmp_vec;
128 template<
class MatrixType>
130 Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Y,
139 "Ifpack2::Diagonal::apply() ERROR, compute() hasn't been called yet.");
142 Y.elementWiseMultiply(alpha, *inversediag_, X, beta);
145 template<
class MatrixType>
146 template<
class DomainScalar,
class RangeScalar>
148 Tpetra::MultiVector<RangeScalar,LocalOrdinal,GlobalOrdinal,Node>& Y,
151 RangeScalar beta)
const
153 typedef typename Tpetra::MultiVector<RangeScalar,LocalOrdinal,GlobalOrdinal,Node> RangeMultiVectorType;
154 typedef typename Tpetra::Vector<RangeScalar,LocalOrdinal,GlobalOrdinal,Node> RangeVectorType;
157 "Ifpack2::Diagonal::apply() ERROR, compute() hasn't been called yet.");
160 "Ifpack2::Diagonal::apply() ERROR: X.getNumVectors() != Y.getNumVectors().");
167 for (
size_t j = 0; j < X.getNumVectors(); ++j) {
176 if( invVals.
size() ) {
180 Y.elementWiseMultiply(alpha, *invtmp, *Xtmp, beta);
183 template<
class MatrixType>
187 LocalOrdinal MaxIters,
189 const Teuchos::Ptr<
const Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &matrix)
197 if (condEst_ == minusOne) {
198 condEst_ = Ifpack2::Condest(*
this, CT, MaxIters, Tol, matrix);
203 template <
class MatrixType>
205 return(numInitialize_);
208 template <
class MatrixType>
213 template <
class MatrixType>
218 template <
class MatrixType>
220 return(initializeTime_);
223 template<
class MatrixType>
225 return(computeTime_);
228 template<
class MatrixType>
233 template <
class MatrixType>
236 return std::string(
"Ifpack2::Diagonal");
239 template <
class MatrixType>
243 out << this->description() << std::endl;
244 out <<
" numApply: " << numApply_ << std::endl;
std::string description() const
Return a simple one-line description of this object.
Definition: Ifpack2_Diagonal_def.hpp:234
CondestType
Ifpack2::CondestType: enum to define the type of condition number estimate.
Definition: Ifpack2_CondestType.hpp:50
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
magnitudeType computeCondEst(CondestType CT=Cheap, LocalOrdinal MaxIters=1550, magnitudeType Tol=1e-9, const Teuchos::Ptr< const Tpetra::RowMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &matrix=Teuchos::null)
Computes the estimated condition number and returns the value.
Definition: Ifpack2_Diagonal_def.hpp:185
void apply(const Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=Teuchos::ScalarTraits< Scalar >::one(), Scalar beta=Teuchos::ScalarTraits< Scalar >::zero()) const
Applies the preconditioner to X, returns the result in Y.
Definition: Ifpack2_Diagonal_def.hpp:129
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void compute()
compute the preconditioner
Definition: Ifpack2_Diagonal_def.hpp:106
void applyTempl(const Tpetra::MultiVector< DomainScalar, LocalOrdinal, GlobalOrdinal, Node > &X, Tpetra::MultiVector< RangeScalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, RangeScalar alpha=Teuchos::ScalarTraits< Scalar >::one(), RangeScalar beta=Teuchos::ScalarTraits< Scalar >::zero()) const
Applies the preconditioner to X, returns the result in Y.
Definition: Ifpack2_Diagonal_def.hpp:147
virtual ~Diagonal()
Destructor.
Definition: Ifpack2_Diagonal_def.hpp:82
double getComputeTime() const
Returns the time spent in compute().
Definition: Ifpack2_Diagonal_def.hpp:224
int getNumCompute() const
Returns the number of calls to compute().
Definition: Ifpack2_Diagonal_def.hpp:209
double getInitializeTime() const
Returns the time spent in initialize().
Definition: Ifpack2_Diagonal_def.hpp:219
void setParameters(const Teuchos::ParameterList ¶ms)
Sets parameters on this object.
Definition: Ifpack2_Diagonal_def.hpp:87
Diagonal(const Teuchos::RCP< const MatrixType > &A)
Constructor to create a Diagonal preconditioner using a Tpetra::CrsMatrix.
Definition: Ifpack2_Diagonal_def.hpp:52
int getNumInitialize() const
Returns the number of calls to initialize().
Definition: Ifpack2_Diagonal_def.hpp:204
double getApplyTime() const
Returns the time spent in apply().
Definition: Ifpack2_Diagonal_def.hpp:229
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to an FancyOStream object.
Definition: Ifpack2_Diagonal_def.hpp:240
void initialize()
Initialize.
Definition: Ifpack2_Diagonal_def.hpp:92
int getNumApply() const
Returns the number of calls to apply().
Definition: Ifpack2_Diagonal_def.hpp:214