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"
22template <
class MatrixType>
24 Chebyshev(
const Teuchos::RCP<const row_matrix_type>& A)
26 , IsInitialized_(false)
30 , TimerForApply_(true)
32 , InitializeTime_(0.0)
37 this->setObjectLabel(
"Ifpack2::Chebyshev");
40template <
class MatrixType>
44template <
class MatrixType>
46 if (A.getRawPtr() != impl_.getMatrix().getRawPtr()) {
47 IsInitialized_ =
false;
53template <
class MatrixType>
56 impl_.setParameters(
const_cast<Teuchos::ParameterList&
>(List));
57 if (List.isType<
bool>(
"timer for apply"))
58 TimerForApply_ = List.get<
bool>(
"timer for apply");
61template <
class MatrixType>
63 impl_.setZeroStartingSolution(zeroStartingSolution);
66template <
class MatrixType>
67Teuchos::RCP<const Teuchos::Comm<int> >
69 Teuchos::RCP<const row_matrix_type> A = impl_.getMatrix();
70 TEUCHOS_TEST_FOR_EXCEPTION(
71 A.is_null(), std::runtime_error,
72 "Ifpack2::Chebyshev::getComm: The input "
73 "matrix A is null. Please call setMatrix() with a nonnull input matrix "
74 "before calling this method.");
75 return A->getRowMap()->getComm();
78template <
class MatrixType>
79Teuchos::RCP<const typename Chebyshev<MatrixType>::row_matrix_type>
82 return impl_.getMatrix();
85template <
class MatrixType>
86Teuchos::RCP<
const Tpetra::CrsMatrix<
typename MatrixType::scalar_type,
87 typename MatrixType::local_ordinal_type,
88 typename MatrixType::global_ordinal_type,
89 typename MatrixType::node_type> >
95 return Teuchos::rcp_dynamic_cast<const crs_matrix_type>(impl_.getMatrix());
98template <
class MatrixType>
99Teuchos::RCP<const typename Chebyshev<MatrixType>::map_type>
102 Teuchos::RCP<const row_matrix_type> A = impl_.getMatrix();
103 TEUCHOS_TEST_FOR_EXCEPTION(
104 A.is_null(), std::runtime_error,
105 "Ifpack2::Chebyshev::getDomainMap: The "
106 "input matrix A is null. Please call setMatrix() with a nonnull input "
107 "matrix before calling this method.");
108 return A->getDomainMap();
111template <
class MatrixType>
112Teuchos::RCP<const typename Chebyshev<MatrixType>::map_type>
115 Teuchos::RCP<const row_matrix_type> A = impl_.getMatrix();
116 TEUCHOS_TEST_FOR_EXCEPTION(
117 A.is_null(), std::runtime_error,
118 "Ifpack2::Chebyshev::getRangeMap: The "
119 "input matrix A is null. Please call setMatrix() with a nonnull input "
120 "matrix before calling this method.");
121 return A->getRangeMap();
124template <
class MatrixType>
126 return impl_.hasTransposeApply();
129template <
class MatrixType>
131 return NumInitialize_;
134template <
class MatrixType>
139template <
class MatrixType>
144template <
class MatrixType>
146 return InitializeTime_;
149template <
class MatrixType>
154template <
class MatrixType>
159template <
class MatrixType>
161 return ComputeFlops_;
164template <
class MatrixType>
169template <
class MatrixType>
171 Teuchos::RCP<const row_matrix_type> A = impl_.getMatrix();
172 TEUCHOS_TEST_FOR_EXCEPTION(
173 A.is_null(), std::runtime_error,
174 "Ifpack2::Chevyshev::getNodeSmootherComplexity: "
175 "The input matrix A is null. Please call setMatrix() with a nonnull "
176 "input matrix, then call compute(), before calling this method.");
178 return A->getLocalNumRows() + A->getLocalNumEntries();
181template <
class MatrixType>
183 apply(
const Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& X,
184 Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& Y,
185 Teuchos::ETransp mode,
188 Teuchos::RCP<Teuchos::Time> timer;
189 const std::string timerName(
"Ifpack2::Chebyshev::apply");
190 if (TimerForApply_) {
191 timer = Teuchos::TimeMonitor::lookupCounter(timerName);
192 if (timer.is_null()) {
193 timer = Teuchos::TimeMonitor::getNewCounter(timerName);
197 Teuchos::Time time = Teuchos::Time(timerName);
198 double startTime = time.wallTime();
202 Teuchos::RCP<Teuchos::TimeMonitor> timeMon;
204 timeMon = Teuchos::rcp(
new Teuchos::TimeMonitor(*timer));
208 TEUCHOS_TEST_FOR_EXCEPTION(
209 !isComputed(), std::runtime_error,
210 "Ifpack2::Chebyshev::apply(): You must call the compute() method before "
211 "you may call apply().");
212 TEUCHOS_TEST_FOR_EXCEPTION(
213 X.getNumVectors() != Y.getNumVectors(), std::runtime_error,
214 "Ifpack2::Chebyshev::apply(): X and Y must have the same number of "
215 "columns. X.getNumVectors() = "
216 << X.getNumVectors() <<
" != "
217 <<
"Y.getNumVectors() = " << Y.getNumVectors() <<
".");
218 applyImpl(X, Y, mode, alpha, beta);
221 ApplyTime_ += (time.wallTime() - startTime);
224template <
class MatrixType>
226 applyMat(
const Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& X,
227 Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& Y,
228 Teuchos::ETransp mode)
const {
229 TEUCHOS_TEST_FOR_EXCEPTION(
230 X.getNumVectors() != Y.getNumVectors(), std::invalid_argument,
231 "Ifpack2::Chebyshev::applyMat: X.getNumVectors() != Y.getNumVectors().");
233 Teuchos::RCP<const row_matrix_type> A = impl_.getMatrix();
234 TEUCHOS_TEST_FOR_EXCEPTION(
235 A.is_null(), std::runtime_error,
236 "Ifpack2::Chebyshev::applyMat: The input "
237 "matrix A is null. Please call setMatrix() with a nonnull input matrix "
238 "before calling this method.");
240 A->apply(X, Y, mode);
243template <
class MatrixType>
248 const std::string timerName(
"Ifpack2::Chebyshev::initialize");
249 Teuchos::RCP<Teuchos::Time> timer = Teuchos::TimeMonitor::lookupCounter(timerName);
250 if (timer.is_null()) {
251 timer = Teuchos::TimeMonitor::getNewCounter(timerName);
253 IsInitialized_ =
true;
257template <
class MatrixType>
259 const std::string timerName(
"Ifpack2::Chebyshev::compute");
260 Teuchos::RCP<Teuchos::Time> timer = Teuchos::TimeMonitor::lookupCounter(timerName);
261 if (timer.is_null()) {
262 timer = Teuchos::TimeMonitor::getNewCounter(timerName);
265 double startTime = timer->wallTime();
269 Teuchos::TimeMonitor timeMon(*timer);
270 if (!isInitialized()) {
279 ComputeTime_ += (timer->wallTime() - startTime);
282template <
class MatrixType>
284 std::ostringstream out;
289 out <<
"\"Ifpack2::Chebyshev\": {";
290 out <<
"Initialized: " << (isInitialized() ?
"true" :
"false") <<
", "
291 <<
"Computed: " << (isComputed() ?
"true" :
"false") <<
", ";
293 out << impl_.description() <<
", ";
295 if (impl_.getMatrix().is_null()) {
296 out <<
"Matrix: null";
298 out <<
"Global matrix dimensions: ["
299 << impl_.getMatrix()->getGlobalNumRows() <<
", "
300 << impl_.getMatrix()->getGlobalNumCols() <<
"]"
301 <<
", Global nnz: " << impl_.getMatrix()->getGlobalNumEntries();
308template <
class MatrixType>
310 describe(Teuchos::FancyOStream& out,
311 const Teuchos::EVerbosityLevel verbLevel)
const {
313 using Teuchos::TypeNameTraits;
316 const Teuchos::EVerbosityLevel vl =
317 (verbLevel == Teuchos::VERB_DEFAULT) ? Teuchos::VERB_LOW : verbLevel;
319 if (vl == Teuchos::VERB_NONE) {
329 Teuchos::OSTab tab0(out);
330 const int myRank = this->getComm()->getRank();
334 out <<
"\"Ifpack2::Chebyshev\":" << endl;
337 Teuchos::OSTab tab1(out);
338 if (vl >= Teuchos::VERB_LOW && myRank == 0) {
339 out <<
"Template parameters:" << endl;
341 Teuchos::OSTab tab2(out);
342 out <<
"Scalar: " << TypeNameTraits<scalar_type>::name() << endl
343 <<
"LocalOrdinal: " << TypeNameTraits<local_ordinal_type>::name() << endl
344 <<
"GlobalOrdinal: " << TypeNameTraits<global_ordinal_type>::name() << endl
345 <<
"Device: " << TypeNameTraits<device_type>::name() << endl;
347 out <<
"Initialized: " << (isInitialized() ?
"true" :
"false") << endl
348 <<
"Computed: " << (isComputed() ?
"true" :
"false") << endl;
349 impl_.describe(out, vl);
351 if (impl_.getMatrix().is_null()) {
352 out <<
"Matrix: null" << endl;
354 out <<
"Global matrix dimensions: ["
355 << impl_.getMatrix()->getGlobalNumRows() <<
", "
356 << impl_.getMatrix()->getGlobalNumCols() <<
"]" << endl
357 <<
"Global nnz: " << impl_.getMatrix()->getGlobalNumEntries() << endl;
362template <
class MatrixType>
368 scalar_type beta)
const {
369 using Teuchos::ArrayRCP;
373 using Teuchos::rcp_const_cast;
374 using Teuchos::rcpFromRef;
376 const scalar_type zero = STS::zero();
377 const scalar_type one = STS::one();
397 Y_orig = rcp(
new MV(Y, Teuchos::Copy));
406 RCP<const MV> X_copy;
407 bool copiedInput =
false;
409 X_copy = rcp(
new MV(X, Teuchos::Copy));
412 X_copy = rcpFromRef(X);
421 RCP<MV> X_copy_nonConst = rcp_const_cast<MV>(X_copy);
423 X_copy_nonConst = rcp(
new MV(X, Teuchos::Copy));
426 X_copy_nonConst->scale(alpha);
427 X_copy = rcp_const_cast<const MV>(X_copy_nonConst);
430 impl_.apply(*X_copy, Y);
433 Y.update(beta, *Y_orig, one);
437template <
class MatrixType>
439 return impl_.getLambdaMaxForApply();
444#define IFPACK2_CHEBYSHEV_INSTANT(S, LO, GO, N) \
445 template class Ifpack2::Chebyshev<Tpetra::RowMatrix<S, LO, GO, N> >;
Diagonally scaled Chebyshev iteration for Tpetra sparse matrices.
Definition Ifpack2_Chebyshev_decl.hpp:172
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition Ifpack2_Chebyshev_decl.hpp:187
double getInitializeTime() const
The total time spent in all calls to initialize().
Definition Ifpack2_Chebyshev_def.hpp:145
void compute()
(Re)compute the left scaling, and (if applicable) estimate max and min eigenvalues of D_inv * A.
Definition Ifpack2_Chebyshev_def.hpp:258
std::string description() const
A simple one-line description of this object.
Definition Ifpack2_Chebyshev_def.hpp:283
Chebyshev(const Teuchos::RCP< const row_matrix_type > &A)
Constructor.
Definition Ifpack2_Chebyshev_def.hpp:24
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:310
Teuchos::RCP< const map_type > getRangeMap() const
The Tpetra::Map representing the range of this operator.
Definition Ifpack2_Chebyshev_def.hpp:114
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:226
void initialize()
Initialize the preconditioner.
Definition Ifpack2_Chebyshev_def.hpp:244
Teuchos::RCP< const row_matrix_type > getMatrix() const
The matrix for which this is a preconditioner.
Definition Ifpack2_Chebyshev_def.hpp:81
int getNumApply() const
The total number of successful calls to apply().
Definition Ifpack2_Chebyshev_def.hpp:140
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition Ifpack2_Chebyshev_decl.hpp:184
MatrixType::node_type node_type
The Node type used by the input MatrixType.
Definition Ifpack2_Chebyshev_decl.hpp:193
size_t getNodeSmootherComplexity() const
Get a rough estimate of cost per iteration.
Definition Ifpack2_Chebyshev_def.hpp:170
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition Ifpack2_Chebyshev_decl.hpp:181
virtual void setMatrix(const Teuchos::RCP< const row_matrix_type > &A)
Change the matrix to be preconditioned.
Definition Ifpack2_Chebyshev_def.hpp:45
int getNumCompute() const
The total number of successful calls to compute().
Definition Ifpack2_Chebyshev_def.hpp:135
void setParameters(const Teuchos::ParameterList ¶ms)
Set (or reset) parameters.
Definition Ifpack2_Chebyshev_def.hpp:54
double getComputeFlops() const
The total number of floating-point operations taken by all calls to compute().
Definition Ifpack2_Chebyshev_def.hpp:160
double getComputeTime() const
The total time spent in all calls to compute().
Definition Ifpack2_Chebyshev_def.hpp:150
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:91
void setZeroStartingSolution(bool zeroStartingSolution)
Set this preconditioner's parameters.
Definition Ifpack2_Chebyshev_def.hpp:62
Teuchos::RCP< const map_type > getDomainMap() const
The Tpetra::Map representing the domain of this operator.
Definition Ifpack2_Chebyshev_def.hpp:101
int getNumInitialize() const
The total number of successful calls to initialize().
Definition Ifpack2_Chebyshev_def.hpp:130
virtual ~Chebyshev()
Destructor.
Definition Ifpack2_Chebyshev_def.hpp:41
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
The communicator over which the matrix is distributed.
Definition Ifpack2_Chebyshev_def.hpp:68
double getApplyFlops() const
The total number of floating-point operations taken by all calls to apply().
Definition Ifpack2_Chebyshev_def.hpp:165
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:183
MatrixType::scalar_type getLambdaMaxForApply() const
The estimate of the maximum eigenvalue used in the apply().
Definition Ifpack2_Chebyshev_def.hpp:438
bool hasTransposeApply() const
Whether it's possible to apply the transpose of this operator.
Definition Ifpack2_Chebyshev_def.hpp:125
double getApplyTime() const
The total time spent in all calls to apply().
Definition Ifpack2_Chebyshev_def.hpp:155
Preconditioners and smoothers for Tpetra sparse matrices.
Definition Ifpack2_AdditiveSchwarz_decl.hpp:40