10 #ifndef IFPACK2_CHEBYSHEV_DEF_HPP
11 #define IFPACK2_CHEBYSHEV_DEF_HPP
13 #include "Ifpack2_Parameters.hpp"
15 #include "Tpetra_CrsMatrix.hpp"
23 template<
class MatrixType>
27 IsInitialized_ (false),
33 InitializeTime_ (0.0),
39 this->setObjectLabel (
"Ifpack2::Chebyshev");
43 template<
class MatrixType>
48 template<
class MatrixType>
51 if (A.
getRawPtr () != impl_.getMatrix ().getRawPtr ()) {
52 IsInitialized_ =
false;
59 template<
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");
70 template<
class MatrixType>
74 impl_.setZeroStartingSolution(zeroStartingSolution);
77 template<
class MatrixType>
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 ();
90 template<
class MatrixType>
94 return impl_.getMatrix ();
98 template<
class MatrixType>
99 Teuchos::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 ());
111 template<
class MatrixType>
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 ();
125 template<
class MatrixType>
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 ();
139 template<
class MatrixType>
141 return impl_.hasTransposeApply ();
145 template<
class MatrixType>
147 return NumInitialize_;
151 template<
class MatrixType>
157 template<
class MatrixType>
163 template<
class MatrixType>
165 return InitializeTime_;
169 template<
class MatrixType>
175 template<
class MatrixType>
181 template<
class MatrixType>
183 return ComputeFlops_;
187 template<
class MatrixType>
192 template<
class MatrixType>
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();
205 template<
class MatrixType>
208 apply (
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,
215 const std::string timerName (
"Ifpack2::Chebyshev::apply");
216 if (TimerForApply_) {
235 ! isComputed (), std::runtime_error,
236 "Ifpack2::Chebyshev::apply(): You must call the compute() method before "
237 "you may call apply().");
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);
250 template<
class MatrixType>
253 applyMat (
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,
258 X.getNumVectors () != Y.getNumVectors (), std::invalid_argument,
259 "Ifpack2::Chebyshev::applyMat: X.getNumVectors() != Y.getNumVectors().");
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);
271 template<
class MatrixType>
276 const std::string timerName (
"Ifpack2::Chebyshev::initialize");
281 IsInitialized_ =
true;
286 template<
class MatrixType>
289 const std::string timerName (
"Ifpack2::Chebyshev::compute");
295 double startTime = timer->
wallTime();
300 if (! isInitialized ()) {
309 ComputeTime_ += (timer->
wallTime() - startTime);
313 template <
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();
341 template <
class MatrixType>
364 const int myRank = this->getComm ()->getRank ();
368 out <<
"\"Ifpack2::Chebyshev\":" << endl;
373 out <<
"Template parameters:" << endl;
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;
397 template<
class MatrixType>
404 scalar_type beta)
const
410 using Teuchos::rcp_const_cast;
411 using Teuchos::rcpFromRef;
413 const scalar_type zero = STS::zero();
414 const scalar_type one = STS::one();
444 RCP<const MV> X_copy;
445 bool copiedInput =
false;
450 X_copy = rcpFromRef (X);
459 RCP<MV> X_copy_nonConst = rcp_const_cast<MV> (X_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);
476 template<
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> >;
488 #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:188
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
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition: Ifpack2_Chebyshev_decl.hpp:189
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition: Ifpack2_Chebyshev_decl.hpp:183
double getApplyTime() const
The total time spent in all calls to apply().
Definition: Ifpack2_Chebyshev_def.hpp:176
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:49
#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:61
double getComputeTime() const
The total time spent in all calls to compute().
Definition: Ifpack2_Chebyshev_def.hpp:170
int getNumApply() const
The total number of successful calls to apply().
Definition: Ifpack2_Chebyshev_def.hpp:158
MatrixType::node_type node_type
The Node type used by the input MatrixType.
Definition: Ifpack2_Chebyshev_decl.hpp:195
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
bool hasTransposeApply() const
Whether it's possible to apply the transpose of this operator.
Definition: Ifpack2_Chebyshev_def.hpp:140
double getComputeFlops() const
The total number of floating-point operations taken by all calls to compute().
Definition: Ifpack2_Chebyshev_def.hpp:182
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: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:208
Chebyshev(const Teuchos::RCP< const row_matrix_type > &A)
Constructor.
Definition: Ifpack2_Chebyshev_def.hpp:25
std::string description() const
A simple one-line description of this object.
Definition: Ifpack2_Chebyshev_def.hpp:314
void initialize()
Initialize the preconditioner.
Definition: Ifpack2_Chebyshev_def.hpp:272
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
The communicator over which the matrix is distributed.
Definition: Ifpack2_Chebyshev_def.hpp:79
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition: Ifpack2_Chebyshev_decl.hpp:186
int getNumInitialize() const
The total number of successful calls to initialize().
Definition: Ifpack2_Chebyshev_def.hpp:146
double getInitializeTime() const
The total time spent in all calls to initialize().
Definition: Ifpack2_Chebyshev_def.hpp:164
MatrixType::scalar_type getLambdaMaxForApply() const
The estimate of the maximum eigenvalue used in the apply().
Definition: Ifpack2_Chebyshev_def.hpp:477
size_t getNodeSmootherComplexity() const
Get a rough estimate of cost per iteration.
Definition: Ifpack2_Chebyshev_def.hpp:193
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 row_matrix_type > getMatrix() const
The matrix for which this is a preconditioner.
Definition: Ifpack2_Chebyshev_def.hpp:93
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:114
virtual ~Chebyshev()
Destructor.
Definition: Ifpack2_Chebyshev_def.hpp:44
Teuchos::RCP< const map_type > getRangeMap() const
The Tpetra::Map representing the range of this operator.
Definition: Ifpack2_Chebyshev_def.hpp:128
int getNumCompute() const
The total number of successful calls to compute().
Definition: Ifpack2_Chebyshev_def.hpp:152
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 setZeroStartingSolution(bool zeroStartingSolution)
Set this preconditioner's parameters.
Definition: Ifpack2_Chebyshev_def.hpp:72