43#ifndef IFPACK2_CHEBYSHEV_DEF_HPP
44#define IFPACK2_CHEBYSHEV_DEF_HPP
46#include "Ifpack2_Parameters.hpp"
47#include "Teuchos_TimeMonitor.hpp"
48#include "Tpetra_CrsMatrix.hpp"
49#include "Teuchos_TypeNameTraits.hpp"
56template<
class MatrixType>
58Chebyshev (
const Teuchos::RCP<const row_matrix_type>& A)
60 IsInitialized_ (false),
66 InitializeTime_ (0.0),
72 this->setObjectLabel (
"Ifpack2::Chebyshev");
76template<
class MatrixType>
81template<
class MatrixType>
84 if (A.getRawPtr () != impl_.getMatrix ().getRawPtr ()) {
85 IsInitialized_ =
false;
92template<
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");
103template<
class MatrixType>
107 impl_.setZeroStartingSolution(zeroStartingSolution);
110template<
class MatrixType>
111Teuchos::RCP<const Teuchos::Comm<int> >
114 Teuchos::RCP<const row_matrix_type> A = impl_.getMatrix ();
115 TEUCHOS_TEST_FOR_EXCEPTION(
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 ();
123template<
class MatrixType>
124Teuchos::RCP<const typename Chebyshev<MatrixType>::row_matrix_type>
127 return impl_.getMatrix ();
131template<
class MatrixType>
132Teuchos::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 ());
144template<
class MatrixType>
145Teuchos::RCP<const typename Chebyshev<MatrixType>::map_type>
149 Teuchos::RCP<const row_matrix_type> A = impl_.getMatrix ();
150 TEUCHOS_TEST_FOR_EXCEPTION(
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 ();
158template<
class MatrixType>
159Teuchos::RCP<const typename Chebyshev<MatrixType>::map_type>
163 Teuchos::RCP<const row_matrix_type> A = impl_.getMatrix ();
164 TEUCHOS_TEST_FOR_EXCEPTION(
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 ();
172template<
class MatrixType>
174 return impl_.hasTransposeApply ();
178template<
class MatrixType>
180 return NumInitialize_;
184template<
class MatrixType>
190template<
class MatrixType>
196template<
class MatrixType>
198 return InitializeTime_;
202template<
class MatrixType>
208template<
class MatrixType>
214template<
class MatrixType>
216 return ComputeFlops_;
220template<
class MatrixType>
225template<
class MatrixType>
227 Teuchos::RCP<const row_matrix_type> A = impl_.getMatrix();
228 TEUCHOS_TEST_FOR_EXCEPTION(
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();
238template<
class MatrixType>
241apply (
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,
243 Teuchos::ETransp mode,
247 Teuchos::RCP<Teuchos::Time> timer;
248 const std::string timerName (
"Ifpack2::Chebyshev::apply");
249 if (TimerForApply_) {
250 timer = Teuchos::TimeMonitor::lookupCounter (timerName);
251 if (timer.is_null ()) {
252 timer = Teuchos::TimeMonitor::getNewCounter (timerName);
256 Teuchos::Time time = Teuchos::Time(timerName);
257 double startTime = time.wallTime();
261 Teuchos::RCP<Teuchos::TimeMonitor> timeMon;
263 timeMon = Teuchos::rcp(
new Teuchos::TimeMonitor(*timer));
267 TEUCHOS_TEST_FOR_EXCEPTION(
269 "Ifpack2::Chebyshev::apply(): You must call the compute() method before "
270 "you may call apply().");
271 TEUCHOS_TEST_FOR_EXCEPTION(
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);
283template<
class MatrixType>
286applyMat (
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,
288 Teuchos::ETransp mode)
const
290 TEUCHOS_TEST_FOR_EXCEPTION(
291 X.getNumVectors () != Y.getNumVectors (), std::invalid_argument,
292 "Ifpack2::Chebyshev::applyMat: X.getNumVectors() != Y.getNumVectors().");
294 Teuchos::RCP<const row_matrix_type> A = impl_.getMatrix ();
295 TEUCHOS_TEST_FOR_EXCEPTION(
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);
304template<
class MatrixType>
309 const std::string timerName (
"Ifpack2::Chebyshev::initialize");
310 Teuchos::RCP<Teuchos::Time> timer = Teuchos::TimeMonitor::lookupCounter (timerName);
311 if (timer.is_null ()) {
312 timer = Teuchos::TimeMonitor::getNewCounter (timerName);
314 IsInitialized_ =
true;
319template<
class MatrixType>
322 const std::string timerName (
"Ifpack2::Chebyshev::compute");
323 Teuchos::RCP<Teuchos::Time> timer = Teuchos::TimeMonitor::lookupCounter (timerName);
324 if (timer.is_null ()) {
325 timer = Teuchos::TimeMonitor::getNewCounter (timerName);
328 double startTime = timer->wallTime();
332 Teuchos::TimeMonitor timeMon (*timer);
342 ComputeTime_ += (timer->wallTime() - startTime);
346template <
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();
374template <
class MatrixType>
376describe (Teuchos::FancyOStream& out,
377 const Teuchos::EVerbosityLevel verbLevel)
const
379 using Teuchos::TypeNameTraits;
383 const Teuchos::EVerbosityLevel vl =
384 (verbLevel == Teuchos::VERB_DEFAULT) ? Teuchos::VERB_LOW : verbLevel;
386 if (vl == Teuchos::VERB_NONE) {
396 Teuchos::OSTab tab0 (out);
397 const int myRank = this->
getComm ()->getRank ();
401 out <<
"\"Ifpack2::Chebyshev\":" << endl;
404 Teuchos::OSTab tab1 (out);
405 if (vl >= Teuchos::VERB_LOW && myRank == 0) {
406 out <<
"Template parameters:" << endl;
408 Teuchos::OSTab tab2 (out);
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;
430template<
class MatrixType>
437 scalar_type beta)
const
439 using Teuchos::ArrayRCP;
443 using Teuchos::rcp_const_cast;
444 using Teuchos::rcpFromRef;
446 const scalar_type zero = STS::zero();
447 const scalar_type one = STS::one();
468 Y_orig = rcp (
new MV (Y, Teuchos::Copy));
477 RCP<const MV> X_copy;
478 bool copiedInput =
false;
480 X_copy = rcp (
new MV (X, Teuchos::Copy));
483 X_copy = rcpFromRef (X);
492 RCP<MV> X_copy_nonConst = rcp_const_cast<MV> (X_copy);
494 X_copy_nonConst = rcp (
new MV (X, Teuchos::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);
509template<
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> >;
Diagonally scaled Chebyshev iteration for Tpetra sparse matrices.
Definition Ifpack2_Chebyshev_decl.hpp:208
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition Ifpack2_Chebyshev_decl.hpp:223
double getInitializeTime() const
The total time spent in all calls to initialize().
Definition Ifpack2_Chebyshev_def.hpp:197
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
std::string description() const
A simple one-line description of this object.
Definition Ifpack2_Chebyshev_def.hpp:347
Chebyshev(const Teuchos::RCP< const row_matrix_type > &A)
Constructor.
Definition Ifpack2_Chebyshev_def.hpp:58
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 map_type > getRangeMap() const
The Tpetra::Map representing the range of this operator.
Definition Ifpack2_Chebyshev_def.hpp:161
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 initialize()
Initialize the preconditioner.
Definition Ifpack2_Chebyshev_def.hpp:305
Teuchos::RCP< const row_matrix_type > getMatrix() const
The matrix for which this is a preconditioner.
Definition Ifpack2_Chebyshev_def.hpp:126
int getNumApply() const
The total number of successful calls to apply().
Definition Ifpack2_Chebyshev_def.hpp:191
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition Ifpack2_Chebyshev_decl.hpp:220
bool isInitialized() const
Definition Ifpack2_Chebyshev_decl.hpp:442
MatrixType::node_type node_type
The Node type used by the input MatrixType.
Definition Ifpack2_Chebyshev_decl.hpp:229
size_t getNodeSmootherComplexity() const
Get a rough estimate of cost per iteration.
Definition Ifpack2_Chebyshev_def.hpp:226
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition Ifpack2_Chebyshev_decl.hpp:217
virtual void setMatrix(const Teuchos::RCP< const row_matrix_type > &A)
Change the matrix to be preconditioned.
Definition Ifpack2_Chebyshev_def.hpp:82
bool isComputed() const
Definition Ifpack2_Chebyshev_decl.hpp:489
int getNumCompute() const
The total number of successful calls to compute().
Definition Ifpack2_Chebyshev_def.hpp:185
void setParameters(const Teuchos::ParameterList ¶ms)
Set (or reset) parameters.
Definition Ifpack2_Chebyshev_def.hpp:94
double getComputeFlops() const
The total number of floating-point operations taken by all calls to compute().
Definition Ifpack2_Chebyshev_def.hpp:215
double getComputeTime() const
The total time spent in all calls to compute().
Definition Ifpack2_Chebyshev_def.hpp:203
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
void setZeroStartingSolution(bool zeroStartingSolution)
Set this preconditioner's parameters.
Definition Ifpack2_Chebyshev_def.hpp:105
Teuchos::RCP< const map_type > getDomainMap() const
The Tpetra::Map representing the domain of this operator.
Definition Ifpack2_Chebyshev_def.hpp:147
int getNumInitialize() const
The total number of successful calls to initialize().
Definition Ifpack2_Chebyshev_def.hpp:179
virtual ~Chebyshev()
Destructor.
Definition Ifpack2_Chebyshev_def.hpp:77
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
The communicator over which the matrix is distributed.
Definition Ifpack2_Chebyshev_def.hpp:112
double getApplyFlops() const
The total number of floating-point operations taken by all calls to apply().
Definition Ifpack2_Chebyshev_def.hpp:221
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
MatrixType::scalar_type getLambdaMaxForApply() const
The estimate of the maximum eigenvalue used in the apply().
Definition Ifpack2_Chebyshev_def.hpp:510
bool hasTransposeApply() const
Whether it's possible to apply the transpose of this operator.
Definition Ifpack2_Chebyshev_def.hpp:173
double getApplyTime() const
The total time spent in all calls to apply().
Definition Ifpack2_Chebyshev_def.hpp:209
Preconditioners and smoothers for Tpetra sparse matrices.
Definition Ifpack2_AdditiveSchwarz_decl.hpp:74