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>
112 if (matrix_ == Teuchos::null) {
118 Teuchos::RCP<Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > tmp_vec = Teuchos::rcp(
new Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(matrix_->getRowMap()));
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,
138 TEUCHOS_TEST_FOR_EXCEPTION(!
isComputed(), std::runtime_error,
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;
156 TEUCHOS_TEST_FOR_EXCEPTION(!
isComputed(), std::runtime_error,
157 "Ifpack2::Diagonal::apply() ERROR, compute() hasn't been called yet.");
159 TEUCHOS_TEST_FOR_EXCEPTION(X.getNumVectors() != Y.getNumVectors(), std::runtime_error,
160 "Ifpack2::Diagonal::apply() ERROR: X.getNumVectors() != Y.getNumVectors().");
164 Teuchos::RCP<RangeMultiVectorType> Xtmp = rcp(
new RangeMultiVectorType(X.getMap(), X.getNumVectors()));
165 Teuchos::RCP<RangeVectorType> invtmp = rcp(
new RangeVectorType(inversediag_->getMap()));
167 for (
size_t j = 0; j < X.getNumVectors(); ++j) {
168 Teuchos::ArrayRCP<const DomainScalar> xVals = X.getVector( j )->get1dView();
169 Teuchos::ArrayRCP<RangeScalar> xValsRange = Xtmp->getVectorNonConst( j )->get1dViewNonConst();
171 std::transform( xVals.begin(), xVals.end(), xValsRange.begin(), Teuchos::asFunc<RangeScalar>() );
174 Teuchos::ArrayRCP<const Scalar> invVals = inversediag_->get1dView();
175 Teuchos::ArrayRCP<RangeScalar> invValsRange = invtmp->get1dViewNonConst();
176 if( invVals.size() ) {
177 std::transform( invVals.begin(), invVals.end(), invValsRange.begin(), Teuchos::asFunc<RangeScalar>() );
180 Y.elementWiseMultiply(alpha, *invtmp, *Xtmp, beta);
183 template<
class MatrixType>
184 typename Teuchos::ScalarTraits<typename MatrixType::scalar_type>::magnitudeType
187 LocalOrdinal MaxIters,
189 const Teuchos::Ptr<
const Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &matrix)
191 const magnitudeType minusOne = Teuchos::ScalarTraits<magnitudeType>::one ();
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>
242 if (verbLevel != Teuchos::VERB_NONE) {
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
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
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
Definition: Ifpack2_BlockRelaxation_decl.hpp:64
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
Ifpack2::Container: a pure virtual class for creating and solving local linear problems.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:67
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
bool isComputed() const
Return true if compute() has been called.
Definition: Ifpack2_Diagonal_decl.hpp:113