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),
65 InitializeTime_ (0.0),
71 this->setObjectLabel (
"Ifpack2::Chebyshev");
75template<
class MatrixType>
80template<
class MatrixType>
83 if (A.getRawPtr () != impl_.getMatrix ().getRawPtr ()) {
84 IsInitialized_ =
false;
91template<
class MatrixType>
96 impl_.setParameters (
const_cast<Teuchos::ParameterList&
> (List));
100template<
class MatrixType>
104 impl_.setZeroStartingSolution(zeroStartingSolution);
107template<
class MatrixType>
108Teuchos::RCP<const Teuchos::Comm<int> >
111 Teuchos::RCP<const row_matrix_type> A = impl_.getMatrix ();
112 TEUCHOS_TEST_FOR_EXCEPTION(
113 A.is_null (), std::runtime_error,
"Ifpack2::Chebyshev::getComm: The input "
114 "matrix A is null. Please call setMatrix() with a nonnull input matrix "
115 "before calling this method.");
116 return A->getRowMap ()->getComm ();
120template<
class MatrixType>
121Teuchos::RCP<const typename Chebyshev<MatrixType>::row_matrix_type>
124 return impl_.getMatrix ();
128template<
class MatrixType>
129Teuchos::RCP<
const Tpetra::CrsMatrix<
typename MatrixType::scalar_type,
130 typename MatrixType::local_ordinal_type,
131 typename MatrixType::global_ordinal_type,
132 typename MatrixType::node_type> >
137 return Teuchos::rcp_dynamic_cast<const crs_matrix_type> (impl_.getMatrix ());
141template<
class MatrixType>
142Teuchos::RCP<const typename Chebyshev<MatrixType>::map_type>
146 Teuchos::RCP<const row_matrix_type> A = impl_.getMatrix ();
147 TEUCHOS_TEST_FOR_EXCEPTION(
148 A.is_null (), std::runtime_error,
"Ifpack2::Chebyshev::getDomainMap: The "
149 "input matrix A is null. Please call setMatrix() with a nonnull input "
150 "matrix before calling this method.");
151 return A->getDomainMap ();
155template<
class MatrixType>
156Teuchos::RCP<const typename Chebyshev<MatrixType>::map_type>
160 Teuchos::RCP<const row_matrix_type> A = impl_.getMatrix ();
161 TEUCHOS_TEST_FOR_EXCEPTION(
162 A.is_null (), std::runtime_error,
"Ifpack2::Chebyshev::getRangeMap: The "
163 "input matrix A is null. Please call setMatrix() with a nonnull input "
164 "matrix before calling this method.");
165 return A->getRangeMap ();
169template<
class MatrixType>
171 return impl_.hasTransposeApply ();
175template<
class MatrixType>
177 return NumInitialize_;
181template<
class MatrixType>
187template<
class MatrixType>
193template<
class MatrixType>
195 return InitializeTime_;
199template<
class MatrixType>
205template<
class MatrixType>
211template<
class MatrixType>
213 return ComputeFlops_;
217template<
class MatrixType>
222template<
class MatrixType>
224 Teuchos::RCP<const row_matrix_type> A = impl_.getMatrix();
225 TEUCHOS_TEST_FOR_EXCEPTION(
226 A.is_null (), std::runtime_error,
"Ifpack2::Chevyshev::getNodeSmootherComplexity: "
227 "The input matrix A is null. Please call setMatrix() with a nonnull "
228 "input matrix, then call compute(), before calling this method.");
230 return A->getLocalNumRows() + A->getLocalNumEntries();
235template<
class MatrixType>
238apply (
const Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& X,
239 Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& Y,
240 Teuchos::ETransp mode,
244 const std::string timerName (
"Ifpack2::Chebyshev::apply");
245 Teuchos::RCP<Teuchos::Time> timer = Teuchos::TimeMonitor::lookupCounter (timerName);
246 if (timer.is_null ()) {
247 timer = Teuchos::TimeMonitor::getNewCounter (timerName);
250 double startTime = timer->wallTime();
254 Teuchos::TimeMonitor timeMon (*timer);
258 TEUCHOS_TEST_FOR_EXCEPTION(
259 ! isComputed (), std::runtime_error,
260 "Ifpack2::Chebyshev::apply(): You must call the compute() method before "
261 "you may call apply().");
262 TEUCHOS_TEST_FOR_EXCEPTION(
263 X.getNumVectors () != Y.getNumVectors (), std::runtime_error,
264 "Ifpack2::Chebyshev::apply(): X and Y must have the same number of "
265 "columns. X.getNumVectors() = " << X.getNumVectors() <<
" != "
266 <<
"Y.getNumVectors() = " << Y.getNumVectors() <<
".");
267 applyImpl (X, Y, mode, alpha, beta);
270 ApplyTime_ += (timer->wallTime() - startTime);
274template<
class MatrixType>
277applyMat (
const Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& X,
278 Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& Y,
279 Teuchos::ETransp mode)
const
281 TEUCHOS_TEST_FOR_EXCEPTION(
282 X.getNumVectors () != Y.getNumVectors (), std::invalid_argument,
283 "Ifpack2::Chebyshev::applyMat: X.getNumVectors() != Y.getNumVectors().");
285 Teuchos::RCP<const row_matrix_type> A = impl_.getMatrix ();
286 TEUCHOS_TEST_FOR_EXCEPTION(
287 A.is_null (), std::runtime_error,
"Ifpack2::Chebyshev::applyMat: The input "
288 "matrix A is null. Please call setMatrix() with a nonnull input matrix "
289 "before calling this method.");
291 A->apply (X, Y, mode);
295template<
class MatrixType>
300 const std::string timerName (
"Ifpack2::Chebyshev::initialize");
301 Teuchos::RCP<Teuchos::Time> timer = Teuchos::TimeMonitor::lookupCounter (timerName);
302 if (timer.is_null ()) {
303 timer = Teuchos::TimeMonitor::getNewCounter (timerName);
305 IsInitialized_ =
true;
310template<
class MatrixType>
313 const std::string timerName (
"Ifpack2::Chebyshev::compute");
314 Teuchos::RCP<Teuchos::Time> timer = Teuchos::TimeMonitor::lookupCounter (timerName);
315 if (timer.is_null ()) {
316 timer = Teuchos::TimeMonitor::getNewCounter (timerName);
319 double startTime = timer->wallTime();
323 Teuchos::TimeMonitor timeMon (*timer);
324 if (! isInitialized ()) {
333 ComputeTime_ += (timer->wallTime() - startTime);
337template <
class MatrixType>
339 std::ostringstream out;
344 out <<
"\"Ifpack2::Chebyshev\": {";
345 out <<
"Initialized: " << (isInitialized () ?
"true" :
"false") <<
", "
346 <<
"Computed: " << (isComputed () ?
"true" :
"false") <<
", ";
348 out << impl_.description() <<
", ";
350 if (impl_.getMatrix ().is_null ()) {
351 out <<
"Matrix: null";
354 out <<
"Global matrix dimensions: ["
355 << impl_.getMatrix ()->getGlobalNumRows () <<
", "
356 << impl_.getMatrix ()->getGlobalNumCols () <<
"]"
357 <<
", Global nnz: " << impl_.getMatrix ()->getGlobalNumEntries();
365template <
class MatrixType>
367describe (Teuchos::FancyOStream& out,
368 const Teuchos::EVerbosityLevel verbLevel)
const
370 using Teuchos::TypeNameTraits;
374 const Teuchos::EVerbosityLevel vl =
375 (verbLevel == Teuchos::VERB_DEFAULT) ? Teuchos::VERB_LOW : verbLevel;
377 if (vl == Teuchos::VERB_NONE) {
387 Teuchos::OSTab tab0 (out);
388 const int myRank = this->getComm ()->getRank ();
392 out <<
"\"Ifpack2::Chebyshev\":" << endl;
395 Teuchos::OSTab tab1 (out);
396 if (vl >= Teuchos::VERB_LOW && myRank == 0) {
397 out <<
"Template parameters:" << endl;
399 Teuchos::OSTab tab2 (out);
400 out <<
"Scalar: " << TypeNameTraits<scalar_type>::name () << endl
401 <<
"LocalOrdinal: " << TypeNameTraits<local_ordinal_type>::name () << endl
402 <<
"GlobalOrdinal: " << TypeNameTraits<global_ordinal_type>::name () << endl
403 <<
"Device: " << TypeNameTraits<device_type>::name () << endl;
405 out <<
"Initialized: " << (isInitialized () ?
"true" :
"false") << endl
406 <<
"Computed: " << (isComputed () ?
"true" :
"false") << endl;
407 impl_.describe (out, vl);
409 if (impl_.getMatrix ().is_null ()) {
410 out <<
"Matrix: null" << endl;
413 out <<
"Global matrix dimensions: ["
414 << impl_.getMatrix ()->getGlobalNumRows () <<
", "
415 << impl_.getMatrix ()->getGlobalNumCols () <<
"]" << endl
416 <<
"Global nnz: " << impl_.getMatrix ()->getGlobalNumEntries() << endl;
421template<
class MatrixType>
428 scalar_type beta)
const
430 using Teuchos::ArrayRCP;
434 using Teuchos::rcp_const_cast;
435 using Teuchos::rcpFromRef;
437 const scalar_type zero = STS::zero();
438 const scalar_type one = STS::one();
459 Y_orig = rcp (
new MV (Y, Teuchos::Copy));
468 RCP<const MV> X_copy;
469 bool copiedInput =
false;
471 X_copy = rcp (
new MV (X, Teuchos::Copy));
474 X_copy = rcpFromRef (X);
483 RCP<MV> X_copy_nonConst = rcp_const_cast<MV> (X_copy);
485 X_copy_nonConst = rcp (
new MV (X, Teuchos::Copy));
488 X_copy_nonConst->scale (alpha);
489 X_copy = rcp_const_cast<const MV> (X_copy_nonConst);
492 impl_.apply (*X_copy, Y);
495 Y.update (beta, *Y_orig, one);
500template<
class MatrixType>
502 return impl_.getLambdaMaxForApply ();
509#define IFPACK2_CHEBYSHEV_INSTANT(S,LO,GO,N) \
510 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:194
void compute()
(Re)compute the left scaling, and (if applicable) estimate max and min eigenvalues of D_inv * A.
Definition: Ifpack2_Chebyshev_def.hpp:311
std::string description() const
A simple one-line description of this object.
Definition: Ifpack2_Chebyshev_def.hpp:338
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:367
Teuchos::RCP< const map_type > getRangeMap() const
The Tpetra::Map representing the range of this operator.
Definition: Ifpack2_Chebyshev_def.hpp:158
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:277
void initialize()
Initialize the preconditioner.
Definition: Ifpack2_Chebyshev_def.hpp:296
Teuchos::RCP< const row_matrix_type > getMatrix() const
The matrix for which this is a preconditioner.
Definition: Ifpack2_Chebyshev_def.hpp:123
int getNumApply() const
The total number of successful calls to apply().
Definition: Ifpack2_Chebyshev_def.hpp:188
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition: Ifpack2_Chebyshev_decl.hpp:220
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:223
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:81
int getNumCompute() const
The total number of successful calls to compute().
Definition: Ifpack2_Chebyshev_def.hpp:182
void setParameters(const Teuchos::ParameterList ¶ms)
Set (or reset) parameters.
Definition: Ifpack2_Chebyshev_def.hpp:93
double getComputeFlops() const
The total number of floating-point operations taken by all calls to compute().
Definition: Ifpack2_Chebyshev_def.hpp:212
double getComputeTime() const
The total time spent in all calls to compute().
Definition: Ifpack2_Chebyshev_def.hpp:200
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:134
void setZeroStartingSolution(bool zeroStartingSolution)
Set this preconditioner's parameters.
Definition: Ifpack2_Chebyshev_def.hpp:102
Teuchos::RCP< const map_type > getDomainMap() const
The Tpetra::Map representing the domain of this operator.
Definition: Ifpack2_Chebyshev_def.hpp:144
int getNumInitialize() const
The total number of successful calls to initialize().
Definition: Ifpack2_Chebyshev_def.hpp:176
virtual ~Chebyshev()
Destructor.
Definition: Ifpack2_Chebyshev_def.hpp:76
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
The communicator over which the matrix is distributed.
Definition: Ifpack2_Chebyshev_def.hpp:109
double getApplyFlops() const
The total number of floating-point operations taken by all calls to apply().
Definition: Ifpack2_Chebyshev_def.hpp:218
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:238
MatrixType::scalar_type getLambdaMaxForApply() const
The estimate of the maximum eigenvalue used in the apply().
Definition: Ifpack2_Chebyshev_def.hpp:501
bool hasTransposeApply() const
Whether it's possible to apply the transpose of this operator.
Definition: Ifpack2_Chebyshev_def.hpp:170
double getApplyTime() const
The total time spent in all calls to apply().
Definition: Ifpack2_Chebyshev_def.hpp:206
Preconditioners and smoothers for Tpetra sparse matrices.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:74