10#ifndef IFPACK2_CHEBYSHEV_DEF_HPP
11#define IFPACK2_CHEBYSHEV_DEF_HPP
13#include "Ifpack2_Parameters.hpp"
14#include "Teuchos_TimeMonitor.hpp"
15#include "Tpetra_CrsMatrix.hpp"
16#include "Teuchos_TypeNameTraits.hpp"
23template<
class MatrixType>
25Chebyshev (
const Teuchos::RCP<const row_matrix_type>& A)
27 IsInitialized_ (false),
33 InitializeTime_ (0.0),
39 this->setObjectLabel (
"Ifpack2::Chebyshev");
43template<
class MatrixType>
48template<
class MatrixType>
51 if (A.getRawPtr () != impl_.getMatrix ().getRawPtr ()) {
52 IsInitialized_ =
false;
59template<
class MatrixType>
64 impl_.setParameters (
const_cast<Teuchos::ParameterList&
> (List));
65 if (List.isType<
bool>(
"timer for apply"))
66 TimerForApply_ = List.get<
bool>(
"timer for apply");
70template<
class MatrixType>
74 impl_.setZeroStartingSolution(zeroStartingSolution);
77template<
class MatrixType>
78Teuchos::RCP<const Teuchos::Comm<int> >
81 Teuchos::RCP<const row_matrix_type> A = impl_.getMatrix ();
82 TEUCHOS_TEST_FOR_EXCEPTION(
83 A.is_null (), std::runtime_error,
"Ifpack2::Chebyshev::getComm: The input "
84 "matrix A is null. Please call setMatrix() with a nonnull input matrix "
85 "before calling this method.");
86 return A->getRowMap ()->getComm ();
90template<
class MatrixType>
91Teuchos::RCP<const typename Chebyshev<MatrixType>::row_matrix_type>
94 return impl_.getMatrix ();
98template<
class MatrixType>
99Teuchos::RCP<
const Tpetra::CrsMatrix<
typename MatrixType::scalar_type,
100 typename MatrixType::local_ordinal_type,
101 typename MatrixType::global_ordinal_type,
102 typename MatrixType::node_type> >
107 return Teuchos::rcp_dynamic_cast<const crs_matrix_type> (impl_.getMatrix ());
111template<
class MatrixType>
112Teuchos::RCP<const typename Chebyshev<MatrixType>::map_type>
116 Teuchos::RCP<const row_matrix_type> A = impl_.getMatrix ();
117 TEUCHOS_TEST_FOR_EXCEPTION(
118 A.is_null (), std::runtime_error,
"Ifpack2::Chebyshev::getDomainMap: The "
119 "input matrix A is null. Please call setMatrix() with a nonnull input "
120 "matrix before calling this method.");
121 return A->getDomainMap ();
125template<
class MatrixType>
126Teuchos::RCP<const typename Chebyshev<MatrixType>::map_type>
130 Teuchos::RCP<const row_matrix_type> A = impl_.getMatrix ();
131 TEUCHOS_TEST_FOR_EXCEPTION(
132 A.is_null (), std::runtime_error,
"Ifpack2::Chebyshev::getRangeMap: The "
133 "input matrix A is null. Please call setMatrix() with a nonnull input "
134 "matrix before calling this method.");
135 return A->getRangeMap ();
139template<
class MatrixType>
141 return impl_.hasTransposeApply ();
145template<
class MatrixType>
147 return NumInitialize_;
151template<
class MatrixType>
157template<
class MatrixType>
163template<
class MatrixType>
165 return InitializeTime_;
169template<
class MatrixType>
175template<
class MatrixType>
181template<
class MatrixType>
183 return ComputeFlops_;
187template<
class MatrixType>
192template<
class MatrixType>
194 Teuchos::RCP<const row_matrix_type> A = impl_.getMatrix();
195 TEUCHOS_TEST_FOR_EXCEPTION(
196 A.is_null (), std::runtime_error,
"Ifpack2::Chevyshev::getNodeSmootherComplexity: "
197 "The input matrix A is null. Please call setMatrix() with a nonnull "
198 "input matrix, then call compute(), before calling this method.");
200 return A->getLocalNumRows() + A->getLocalNumEntries();
205template<
class MatrixType>
208apply (
const Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& X,
209 Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& Y,
210 Teuchos::ETransp mode,
214 Teuchos::RCP<Teuchos::Time> timer;
215 const std::string timerName (
"Ifpack2::Chebyshev::apply");
216 if (TimerForApply_) {
217 timer = Teuchos::TimeMonitor::lookupCounter (timerName);
218 if (timer.is_null ()) {
219 timer = Teuchos::TimeMonitor::getNewCounter (timerName);
223 Teuchos::Time time = Teuchos::Time(timerName);
224 double startTime = time.wallTime();
228 Teuchos::RCP<Teuchos::TimeMonitor> timeMon;
230 timeMon = Teuchos::rcp(
new Teuchos::TimeMonitor(*timer));
234 TEUCHOS_TEST_FOR_EXCEPTION(
236 "Ifpack2::Chebyshev::apply(): You must call the compute() method before "
237 "you may call apply().");
238 TEUCHOS_TEST_FOR_EXCEPTION(
239 X.getNumVectors () != Y.getNumVectors (), std::runtime_error,
240 "Ifpack2::Chebyshev::apply(): X and Y must have the same number of "
241 "columns. X.getNumVectors() = " << X.getNumVectors() <<
" != "
242 <<
"Y.getNumVectors() = " << Y.getNumVectors() <<
".");
243 applyImpl (X, Y, mode, alpha, beta);
246 ApplyTime_ += (time.wallTime() - startTime);
250template<
class MatrixType>
253applyMat (
const Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& X,
254 Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& Y,
255 Teuchos::ETransp mode)
const
257 TEUCHOS_TEST_FOR_EXCEPTION(
258 X.getNumVectors () != Y.getNumVectors (), std::invalid_argument,
259 "Ifpack2::Chebyshev::applyMat: X.getNumVectors() != Y.getNumVectors().");
261 Teuchos::RCP<const row_matrix_type> A = impl_.getMatrix ();
262 TEUCHOS_TEST_FOR_EXCEPTION(
263 A.is_null (), std::runtime_error,
"Ifpack2::Chebyshev::applyMat: The input "
264 "matrix A is null. Please call setMatrix() with a nonnull input matrix "
265 "before calling this method.");
267 A->apply (X, Y, mode);
271template<
class MatrixType>
276 const std::string timerName (
"Ifpack2::Chebyshev::initialize");
277 Teuchos::RCP<Teuchos::Time> timer = Teuchos::TimeMonitor::lookupCounter (timerName);
278 if (timer.is_null ()) {
279 timer = Teuchos::TimeMonitor::getNewCounter (timerName);
281 IsInitialized_ =
true;
286template<
class MatrixType>
289 const std::string timerName (
"Ifpack2::Chebyshev::compute");
290 Teuchos::RCP<Teuchos::Time> timer = Teuchos::TimeMonitor::lookupCounter (timerName);
291 if (timer.is_null ()) {
292 timer = Teuchos::TimeMonitor::getNewCounter (timerName);
295 double startTime = timer->wallTime();
299 Teuchos::TimeMonitor timeMon (*timer);
309 ComputeTime_ += (timer->wallTime() - startTime);
313template <
class MatrixType>
315 std::ostringstream out;
320 out <<
"\"Ifpack2::Chebyshev\": {";
321 out <<
"Initialized: " << (
isInitialized () ?
"true" :
"false") <<
", "
322 <<
"Computed: " << (
isComputed () ?
"true" :
"false") <<
", ";
324 out << impl_.description() <<
", ";
326 if (impl_.getMatrix ().is_null ()) {
327 out <<
"Matrix: null";
330 out <<
"Global matrix dimensions: ["
331 << impl_.getMatrix ()->getGlobalNumRows () <<
", "
332 << impl_.getMatrix ()->getGlobalNumCols () <<
"]"
333 <<
", Global nnz: " << impl_.getMatrix ()->getGlobalNumEntries();
341template <
class MatrixType>
343describe (Teuchos::FancyOStream& out,
344 const Teuchos::EVerbosityLevel verbLevel)
const
346 using Teuchos::TypeNameTraits;
350 const Teuchos::EVerbosityLevel vl =
351 (verbLevel == Teuchos::VERB_DEFAULT) ? Teuchos::VERB_LOW : verbLevel;
353 if (vl == Teuchos::VERB_NONE) {
363 Teuchos::OSTab tab0 (out);
364 const int myRank = this->
getComm ()->getRank ();
368 out <<
"\"Ifpack2::Chebyshev\":" << endl;
371 Teuchos::OSTab tab1 (out);
372 if (vl >= Teuchos::VERB_LOW && myRank == 0) {
373 out <<
"Template parameters:" << endl;
375 Teuchos::OSTab tab2 (out);
376 out <<
"Scalar: " << TypeNameTraits<scalar_type>::name () << endl
377 <<
"LocalOrdinal: " << TypeNameTraits<local_ordinal_type>::name () << endl
378 <<
"GlobalOrdinal: " << TypeNameTraits<global_ordinal_type>::name () << endl
379 <<
"Device: " << TypeNameTraits<device_type>::name () << endl;
381 out <<
"Initialized: " << (
isInitialized () ?
"true" :
"false") << endl
382 <<
"Computed: " << (
isComputed () ?
"true" :
"false") << endl;
383 impl_.describe (out, vl);
385 if (impl_.getMatrix ().is_null ()) {
386 out <<
"Matrix: null" << endl;
389 out <<
"Global matrix dimensions: ["
390 << impl_.getMatrix ()->getGlobalNumRows () <<
", "
391 << impl_.getMatrix ()->getGlobalNumCols () <<
"]" << endl
392 <<
"Global nnz: " << impl_.getMatrix ()->getGlobalNumEntries() << endl;
397template<
class MatrixType>
404 scalar_type beta)
const
406 using Teuchos::ArrayRCP;
410 using Teuchos::rcp_const_cast;
411 using Teuchos::rcpFromRef;
413 const scalar_type zero = STS::zero();
414 const scalar_type one = STS::one();
435 Y_orig = rcp (
new MV (Y, Teuchos::Copy));
444 RCP<const MV> X_copy;
445 bool copiedInput =
false;
447 X_copy = rcp (
new MV (X, Teuchos::Copy));
450 X_copy = rcpFromRef (X);
459 RCP<MV> X_copy_nonConst = rcp_const_cast<MV> (X_copy);
461 X_copy_nonConst = rcp (
new MV (X, Teuchos::Copy));
464 X_copy_nonConst->scale (alpha);
465 X_copy = rcp_const_cast<const MV> (X_copy_nonConst);
468 impl_.apply (*X_copy, Y);
471 Y.update (beta, *Y_orig, one);
476template<
class MatrixType>
478 return impl_.getLambdaMaxForApply ();
485#define IFPACK2_CHEBYSHEV_INSTANT(S,LO,GO,N) \
486 template class Ifpack2::Chebyshev< Tpetra::RowMatrix<S, LO, GO, N> >;
Diagonally scaled Chebyshev iteration for Tpetra sparse matrices.
Definition Ifpack2_Chebyshev_decl.hpp:174
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition Ifpack2_Chebyshev_decl.hpp:189
double getInitializeTime() const
The total time spent in all calls to initialize().
Definition Ifpack2_Chebyshev_def.hpp:164
void compute()
(Re)compute the left scaling, and (if applicable) estimate max and min eigenvalues of D_inv * A.
Definition Ifpack2_Chebyshev_def.hpp:287
std::string description() const
A simple one-line description of this object.
Definition Ifpack2_Chebyshev_def.hpp:314
Chebyshev(const Teuchos::RCP< const row_matrix_type > &A)
Constructor.
Definition Ifpack2_Chebyshev_def.hpp:25
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:343
Teuchos::RCP< const map_type > getRangeMap() const
The Tpetra::Map representing the range of this operator.
Definition Ifpack2_Chebyshev_def.hpp:128
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:253
void initialize()
Initialize the preconditioner.
Definition Ifpack2_Chebyshev_def.hpp:272
Teuchos::RCP< const row_matrix_type > getMatrix() const
The matrix for which this is a preconditioner.
Definition Ifpack2_Chebyshev_def.hpp:93
int getNumApply() const
The total number of successful calls to apply().
Definition Ifpack2_Chebyshev_def.hpp:158
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition Ifpack2_Chebyshev_decl.hpp:186
bool isInitialized() const
Definition Ifpack2_Chebyshev_decl.hpp:408
MatrixType::node_type node_type
The Node type used by the input MatrixType.
Definition Ifpack2_Chebyshev_decl.hpp:195
size_t getNodeSmootherComplexity() const
Get a rough estimate of cost per iteration.
Definition Ifpack2_Chebyshev_def.hpp:193
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition Ifpack2_Chebyshev_decl.hpp:183
virtual void setMatrix(const Teuchos::RCP< const row_matrix_type > &A)
Change the matrix to be preconditioned.
Definition Ifpack2_Chebyshev_def.hpp:49
bool isComputed() const
Definition Ifpack2_Chebyshev_decl.hpp:455
int getNumCompute() const
The total number of successful calls to compute().
Definition Ifpack2_Chebyshev_def.hpp:152
void setParameters(const Teuchos::ParameterList ¶ms)
Set (or reset) parameters.
Definition Ifpack2_Chebyshev_def.hpp:61
double getComputeFlops() const
The total number of floating-point operations taken by all calls to compute().
Definition Ifpack2_Chebyshev_def.hpp:182
double getComputeTime() const
The total time spent in all calls to compute().
Definition Ifpack2_Chebyshev_def.hpp:170
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:104
void setZeroStartingSolution(bool zeroStartingSolution)
Set this preconditioner's parameters.
Definition Ifpack2_Chebyshev_def.hpp:72
Teuchos::RCP< const map_type > getDomainMap() const
The Tpetra::Map representing the domain of this operator.
Definition Ifpack2_Chebyshev_def.hpp:114
int getNumInitialize() const
The total number of successful calls to initialize().
Definition Ifpack2_Chebyshev_def.hpp:146
virtual ~Chebyshev()
Destructor.
Definition Ifpack2_Chebyshev_def.hpp:44
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
The communicator over which the matrix is distributed.
Definition Ifpack2_Chebyshev_def.hpp:79
double getApplyFlops() const
The total number of floating-point operations taken by all calls to apply().
Definition Ifpack2_Chebyshev_def.hpp:188
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:208
MatrixType::scalar_type getLambdaMaxForApply() const
The estimate of the maximum eigenvalue used in the apply().
Definition Ifpack2_Chebyshev_def.hpp:477
bool hasTransposeApply() const
Whether it's possible to apply the transpose of this operator.
Definition Ifpack2_Chebyshev_def.hpp:140
double getApplyTime() const
The total time spent in all calls to apply().
Definition Ifpack2_Chebyshev_def.hpp:176
Preconditioners and smoothers for Tpetra sparse matrices.
Definition Ifpack2_AdditiveSchwarz_decl.hpp:41