43 #ifndef IFPACK2_CHEBYSHEV_DEF_HPP
44 #define IFPACK2_CHEBYSHEV_DEF_HPP
46 #include "Ifpack2_Parameters.hpp"
48 #include "Tpetra_CrsMatrix.hpp"
56 template<
class MatrixType>
60 IsInitialized_ (false),
66 InitializeTime_ (0.0),
72 this->setObjectLabel (
"Ifpack2::Chebyshev");
76 template<
class MatrixType>
81 template<
class MatrixType>
84 if (A.
getRawPtr () != impl_.getMatrix ().getRawPtr ()) {
85 IsInitialized_ =
false;
92 template<
class MatrixType>
97 impl_.setParameters (const_cast<Teuchos::ParameterList&> (List));
98 if (List.
isType<
bool>(
"timer for apply"))
99 TimerForApply_ = List.
get<
bool>(
"timer for apply");
103 template<
class MatrixType>
107 impl_.setZeroStartingSolution(zeroStartingSolution);
110 template<
class MatrixType>
116 A.
is_null (), std::runtime_error,
"Ifpack2::Chebyshev::getComm: The input "
117 "matrix A is null. Please call setMatrix() with a nonnull input matrix "
118 "before calling this method.");
119 return A->getRowMap ()->getComm ();
123 template<
class MatrixType>
127 return impl_.getMatrix ();
131 template<
class MatrixType>
132 Teuchos::RCP<
const Tpetra::CrsMatrix<
typename MatrixType::scalar_type,
133 typename MatrixType::local_ordinal_type,
134 typename MatrixType::global_ordinal_type,
135 typename MatrixType::node_type> >
140 return Teuchos::rcp_dynamic_cast<
const crs_matrix_type> (impl_.getMatrix ());
144 template<
class MatrixType>
151 A.
is_null (), std::runtime_error,
"Ifpack2::Chebyshev::getDomainMap: The "
152 "input matrix A is null. Please call setMatrix() with a nonnull input "
153 "matrix before calling this method.");
154 return A->getDomainMap ();
158 template<
class MatrixType>
165 A.
is_null (), std::runtime_error,
"Ifpack2::Chebyshev::getRangeMap: The "
166 "input matrix A is null. Please call setMatrix() with a nonnull input "
167 "matrix before calling this method.");
168 return A->getRangeMap ();
172 template<
class MatrixType>
174 return impl_.hasTransposeApply ();
178 template<
class MatrixType>
180 return NumInitialize_;
184 template<
class MatrixType>
190 template<
class MatrixType>
196 template<
class MatrixType>
198 return InitializeTime_;
202 template<
class MatrixType>
208 template<
class MatrixType>
214 template<
class MatrixType>
216 return ComputeFlops_;
220 template<
class MatrixType>
225 template<
class MatrixType>
229 A.
is_null (), std::runtime_error,
"Ifpack2::Chevyshev::getNodeSmootherComplexity: "
230 "The input matrix A is null. Please call setMatrix() with a nonnull "
231 "input matrix, then call compute(), before calling this method.");
233 return A->getLocalNumRows() + A->getLocalNumEntries();
238 template<
class MatrixType>
241 apply (
const Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& X,
242 Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& Y,
248 const std::string timerName (
"Ifpack2::Chebyshev::apply");
249 if (TimerForApply_) {
268 ! isComputed (), std::runtime_error,
269 "Ifpack2::Chebyshev::apply(): You must call the compute() method before "
270 "you may call apply().");
272 X.getNumVectors () != Y.getNumVectors (), std::runtime_error,
273 "Ifpack2::Chebyshev::apply(): X and Y must have the same number of "
274 "columns. X.getNumVectors() = " << X.getNumVectors() <<
" != "
275 <<
"Y.getNumVectors() = " << Y.getNumVectors() <<
".");
276 applyImpl (X, Y, mode, alpha, beta);
279 ApplyTime_ += (time.
wallTime() - startTime);
283 template<
class MatrixType>
286 applyMat (
const Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& X,
287 Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& Y,
291 X.getNumVectors () != Y.getNumVectors (), std::invalid_argument,
292 "Ifpack2::Chebyshev::applyMat: X.getNumVectors() != Y.getNumVectors().");
296 A.is_null (), std::runtime_error,
"Ifpack2::Chebyshev::applyMat: The input "
297 "matrix A is null. Please call setMatrix() with a nonnull input matrix "
298 "before calling this method.");
300 A->apply (X, Y, mode);
304 template<
class MatrixType>
309 const std::string timerName (
"Ifpack2::Chebyshev::initialize");
314 IsInitialized_ =
true;
319 template<
class MatrixType>
322 const std::string timerName (
"Ifpack2::Chebyshev::compute");
328 double startTime = timer->
wallTime();
333 if (! isInitialized ()) {
342 ComputeTime_ += (timer->
wallTime() - startTime);
346 template <
class MatrixType>
348 std::ostringstream out;
353 out <<
"\"Ifpack2::Chebyshev\": {";
354 out <<
"Initialized: " << (isInitialized () ?
"true" :
"false") <<
", "
355 <<
"Computed: " << (isComputed () ?
"true" :
"false") <<
", ";
357 out << impl_.description() <<
", ";
359 if (impl_.getMatrix ().is_null ()) {
360 out <<
"Matrix: null";
363 out <<
"Global matrix dimensions: ["
364 << impl_.getMatrix ()->getGlobalNumRows () <<
", "
365 << impl_.getMatrix ()->getGlobalNumCols () <<
"]"
366 <<
", Global nnz: " << impl_.getMatrix ()->getGlobalNumEntries();
374 template <
class MatrixType>
397 const int myRank = this->getComm ()->getRank ();
401 out <<
"\"Ifpack2::Chebyshev\":" << endl;
406 out <<
"Template parameters:" << endl;
409 out <<
"Scalar: " << TypeNameTraits<scalar_type>::name () << endl
410 <<
"LocalOrdinal: " << TypeNameTraits<local_ordinal_type>::name () << endl
411 <<
"GlobalOrdinal: " << TypeNameTraits<global_ordinal_type>::name () << endl
412 <<
"Device: " << TypeNameTraits<device_type>::name () << endl;
414 out <<
"Initialized: " << (isInitialized () ?
"true" :
"false") << endl
415 <<
"Computed: " << (isComputed () ?
"true" :
"false") << endl;
416 impl_.describe (out, vl);
418 if (impl_.getMatrix ().is_null ()) {
419 out <<
"Matrix: null" << endl;
422 out <<
"Global matrix dimensions: ["
423 << impl_.getMatrix ()->getGlobalNumRows () <<
", "
424 << impl_.getMatrix ()->getGlobalNumCols () <<
"]" << endl
425 <<
"Global nnz: " << impl_.getMatrix ()->getGlobalNumEntries() << endl;
430 template<
class MatrixType>
437 scalar_type beta)
const
443 using Teuchos::rcp_const_cast;
444 using Teuchos::rcpFromRef;
446 const scalar_type zero = STS::zero();
447 const scalar_type one = STS::one();
477 RCP<const MV> X_copy;
478 bool copiedInput =
false;
483 X_copy = rcpFromRef (X);
492 RCP<MV> X_copy_nonConst = rcp_const_cast<MV> (X_copy);
497 X_copy_nonConst->scale (alpha);
498 X_copy = rcp_const_cast<
const MV> (X_copy_nonConst);
501 impl_.apply (*X_copy, Y);
504 Y.update (beta, *Y_orig, one);
509 template<
class MatrixType>
511 return impl_.getLambdaMaxForApply ();
518 #define IFPACK2_CHEBYSHEV_INSTANT(S,LO,GO,N) \
519 template class Ifpack2::Chebyshev< Tpetra::RowMatrix<S, LO, GO, N> >;
521 #endif // IFPACK2_CHEBYSHEV_DEF_HPP
double getApplyFlops() const
The total number of floating-point operations taken by all calls to apply().
Definition: Ifpack2_Chebyshev_def.hpp:221
Teuchos::RCP< const Tpetra::CrsMatrix< scalar_type, local_ordinal_type, global_ordinal_type, node_type > > getCrsMatrix() const
Attempt to return the matrix A as a Tpetra::CrsMatrix.
Definition: Ifpack2_Chebyshev_def.hpp:137
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition: Ifpack2_Chebyshev_decl.hpp:223
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition: Ifpack2_Chebyshev_decl.hpp:217
double getApplyTime() const
The total time spent in all calls to apply().
Definition: Ifpack2_Chebyshev_def.hpp:209
T & get(const std::string &name, T def_value)
virtual void setMatrix(const Teuchos::RCP< const row_matrix_type > &A)
Change the matrix to be preconditioned.
Definition: Ifpack2_Chebyshev_def.hpp:82
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void setParameters(const Teuchos::ParameterList ¶ms)
Set (or reset) parameters.
Definition: Ifpack2_Chebyshev_def.hpp:94
double getComputeTime() const
The total time spent in all calls to compute().
Definition: Ifpack2_Chebyshev_def.hpp:203
int getNumApply() const
The total number of successful calls to apply().
Definition: Ifpack2_Chebyshev_def.hpp:191
MatrixType::node_type node_type
The Node type used by the input MatrixType.
Definition: Ifpack2_Chebyshev_decl.hpp:229
void compute()
(Re)compute the left scaling, and (if applicable) estimate max and min eigenvalues of D_inv * A...
Definition: Ifpack2_Chebyshev_def.hpp:320
bool hasTransposeApply() const
Whether it's possible to apply the transpose of this operator.
Definition: Ifpack2_Chebyshev_def.hpp:173
double getComputeFlops() const
The total number of floating-point operations taken by all calls to compute().
Definition: Ifpack2_Chebyshev_def.hpp:215
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Diagonally scaled Chebyshev iteration for Tpetra sparse matrices.
Definition: Ifpack2_Chebyshev_decl.hpp:199
void apply(const Tpetra::MultiVector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > &X, Tpetra::MultiVector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, scalar_type alpha=Teuchos::ScalarTraits< scalar_type >::one(), scalar_type beta=Teuchos::ScalarTraits< scalar_type >::zero()) const
Apply the preconditioner to X, returning the result in Y.
Definition: Ifpack2_Chebyshev_def.hpp:241
Chebyshev(const Teuchos::RCP< const row_matrix_type > &A)
Constructor.
Definition: Ifpack2_Chebyshev_def.hpp:58
std::string description() const
A simple one-line description of this object.
Definition: Ifpack2_Chebyshev_def.hpp:347
void initialize()
Initialize the preconditioner.
Definition: Ifpack2_Chebyshev_def.hpp:305
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
The communicator over which the matrix is distributed.
Definition: Ifpack2_Chebyshev_def.hpp:112
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition: Ifpack2_Chebyshev_decl.hpp:220
int getNumInitialize() const
The total number of successful calls to initialize().
Definition: Ifpack2_Chebyshev_def.hpp:179
double getInitializeTime() const
The total time spent in all calls to initialize().
Definition: Ifpack2_Chebyshev_def.hpp:197
MatrixType::scalar_type getLambdaMaxForApply() const
The estimate of the maximum eigenvalue used in the apply().
Definition: Ifpack2_Chebyshev_def.hpp:510
size_t getNodeSmootherComplexity() const
Get a rough estimate of cost per iteration.
Definition: Ifpack2_Chebyshev_def.hpp:226
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to a Teuchos::FancyOStream.
Definition: Ifpack2_Chebyshev_def.hpp:376
Teuchos::RCP< const row_matrix_type > getMatrix() const
The matrix for which this is a preconditioner.
Definition: Ifpack2_Chebyshev_def.hpp:126
TypeTo as(const TypeFrom &t)
bool isType(const std::string &name) const
Teuchos::RCP< const map_type > getDomainMap() const
The Tpetra::Map representing the domain of this operator.
Definition: Ifpack2_Chebyshev_def.hpp:147
virtual ~Chebyshev()
Destructor.
Definition: Ifpack2_Chebyshev_def.hpp:77
Teuchos::RCP< const map_type > getRangeMap() const
The Tpetra::Map representing the range of this operator.
Definition: Ifpack2_Chebyshev_def.hpp:161
int getNumCompute() const
The total number of successful calls to compute().
Definition: Ifpack2_Chebyshev_def.hpp:185
void applyMat(const Tpetra::MultiVector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > &X, Tpetra::MultiVector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS) const
Compute Y = Op(A)*X, where Op(A) is either A, , or .
Definition: Ifpack2_Chebyshev_def.hpp:286
void setZeroStartingSolution(bool zeroStartingSolution)
Set this preconditioner's parameters.
Definition: Ifpack2_Chebyshev_def.hpp:105