43 #ifndef IFPACK2_CHEBYSHEV_DEF_HPP
44 #define IFPACK2_CHEBYSHEV_DEF_HPP
46 #include "Ifpack2_Parameters.hpp"
48 #include "Tpetra_CrsMatrix.hpp"
56 template<
class MatrixType>
57 Chebyshev<MatrixType>::
60 IsInitialized_ (false),
65 InitializeTime_ (0.0),
71 this->setObjectLabel (
"Ifpack2::Chebyshev");
75 template<
class MatrixType>
80 template<
class MatrixType>
83 if (A.
getRawPtr () != impl_.getMatrix ().getRawPtr ()) {
84 IsInitialized_ =
false;
91 template<
class MatrixType>
96 impl_.setParameters (const_cast<Teuchos::ParameterList&> (List));
100 template<
class MatrixType>
106 A.
is_null (), std::runtime_error,
"Ifpack2::Chebyshev::getComm: The input "
107 "matrix A is null. Please call setMatrix() with a nonnull input matrix "
108 "before calling this method.");
109 return A->getRowMap ()->getComm ();
113 template<
class MatrixType>
117 return impl_.getMatrix ();
121 template<
class MatrixType>
122 Teuchos::RCP<
const Tpetra::CrsMatrix<
typename MatrixType::scalar_type,
123 typename MatrixType::local_ordinal_type,
124 typename MatrixType::global_ordinal_type,
125 typename MatrixType::node_type> >
130 return Teuchos::rcp_dynamic_cast<
const crs_matrix_type> (impl_.getMatrix ());
134 template<
class MatrixType>
141 A.
is_null (), std::runtime_error,
"Ifpack2::Chebyshev::getDomainMap: The "
142 "input matrix A is null. Please call setMatrix() with a nonnull input "
143 "matrix before calling this method.");
144 return A->getDomainMap ();
148 template<
class MatrixType>
155 A.
is_null (), std::runtime_error,
"Ifpack2::Chebyshev::getRangeMap: The "
156 "input matrix A is null. Please call setMatrix() with a nonnull input "
157 "matrix before calling this method.");
158 return A->getRangeMap ();
162 template<
class MatrixType>
164 return impl_.hasTransposeApply ();
168 template<
class MatrixType>
170 return NumInitialize_;
174 template<
class MatrixType>
180 template<
class MatrixType>
186 template<
class MatrixType>
188 return InitializeTime_;
192 template<
class MatrixType>
198 template<
class MatrixType>
204 template<
class MatrixType>
206 return ComputeFlops_;
210 template<
class MatrixType>
215 template<
class MatrixType>
219 A.
is_null (), std::runtime_error,
"Ifpack2::Chevyshev::getNodeSmootherComplexity: "
220 "The input matrix A is null. Please call setMatrix() with a nonnull "
221 "input matrix, then call compute(), before calling this method.");
223 return A->getNodeNumRows() + A->getNodeNumEntries();
228 template<
class MatrixType>
231 apply (
const Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& X,
232 Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& Y,
237 const std::string timerName (
"Ifpack2::Chebyshev::apply");
250 ! isComputed (), std::runtime_error,
251 "Ifpack2::Chebyshev::apply(): You must call the compute() method before "
252 "you may call apply().");
254 X.getNumVectors () != Y.getNumVectors (), std::runtime_error,
255 "Ifpack2::Chebyshev::apply(): X and Y must have the same number of "
256 "columns. X.getNumVectors() = " << X.getNumVectors() <<
" != "
257 <<
"Y.getNumVectors() = " << Y.getNumVectors() <<
".");
258 applyImpl (X, Y, mode, alpha, beta);
268 template<
class MatrixType>
271 applyMat (
const Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& X,
272 Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& Y,
276 X.getNumVectors () != Y.getNumVectors (), std::invalid_argument,
277 "Ifpack2::Chebyshev::applyMat: X.getNumVectors() != Y.getNumVectors().");
281 A.is_null (), std::runtime_error,
"Ifpack2::Chebyshev::applyMat: The input "
282 "matrix A is null. Please call setMatrix() with a nonnull input matrix "
283 "before calling this method.");
285 A->apply (X, Y, mode);
289 template<
class MatrixType>
294 const std::string timerName (
"Ifpack2::Chebyshev::initialize");
299 IsInitialized_ =
true;
304 template<
class MatrixType>
307 const std::string timerName (
"Ifpack2::Chebyshev::compute");
316 if (! isInitialized ()) {
331 template <
class MatrixType>
333 std::ostringstream out;
338 out <<
"\"Ifpack2::Chebyshev\": {";
339 out <<
"Initialized: " << (isInitialized () ?
"true" :
"false") <<
", "
340 <<
"Computed: " << (isComputed () ?
"true" :
"false") <<
", ";
342 out << impl_.description() <<
", ";
344 if (impl_.getMatrix ().is_null ()) {
345 out <<
"Matrix: null";
348 out <<
"Global matrix dimensions: ["
349 << impl_.getMatrix ()->getGlobalNumRows () <<
", "
350 << impl_.getMatrix ()->getGlobalNumCols () <<
"]"
351 <<
", Global nnz: " << impl_.getMatrix ()->getGlobalNumEntries();
359 template <
class MatrixType>
382 const int myRank = this->getComm ()->getRank ();
386 out <<
"\"Ifpack2::Chebyshev\":" << endl;
391 out <<
"Template parameters:" << endl;
394 out <<
"Scalar: " << TypeNameTraits<scalar_type>::name () << endl
395 <<
"LocalOrdinal: " << TypeNameTraits<local_ordinal_type>::name () << endl
396 <<
"GlobalOrdinal: " << TypeNameTraits<global_ordinal_type>::name () << endl
397 <<
"Device: " << TypeNameTraits<device_type>::name () << endl;
399 out <<
"Initialized: " << (isInitialized () ?
"true" :
"false") << endl
400 <<
"Computed: " << (isComputed () ?
"true" :
"false") << endl;
401 impl_.describe (out, vl);
403 if (impl_.getMatrix ().is_null ()) {
404 out <<
"Matrix: null" << endl;
407 out <<
"Global matrix dimensions: ["
408 << impl_.getMatrix ()->getGlobalNumRows () <<
", "
409 << impl_.getMatrix ()->getGlobalNumCols () <<
"]" << endl
410 <<
"Global nnz: " << impl_.getMatrix ()->getGlobalNumEntries() << endl;
415 template<
class MatrixType>
422 scalar_type beta)
const
428 using Teuchos::rcp_const_cast;
429 using Teuchos::rcpFromRef;
431 const scalar_type zero = STS::zero();
432 const scalar_type one = STS::one();
462 RCP<const MV> X_copy;
463 bool copiedInput =
false;
465 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
466 auto X_lcl_host = X.template getLocalView<Kokkos::HostSpace> ();
467 auto Y_lcl_host = Y.template getLocalView<Kokkos::HostSpace> ();
469 auto X_lcl_host = X.getLocalViewHost ();
470 auto Y_lcl_host = Y.getLocalViewHost ();
472 if (X_lcl_host.data () == Y_lcl_host.data ()) {
476 X_copy = rcpFromRef (X);
486 RCP<MV> X_copy_nonConst = rcp_const_cast<MV> (X_copy);
491 X_copy_nonConst->scale (alpha);
492 X_copy = rcp_const_cast<
const MV> (X_copy_nonConst);
495 impl_.apply (*X_copy, Y);
498 Y.update (beta, *Y_orig, one);
503 template<
class MatrixType>
505 return impl_.getLambdaMaxForApply ();
512 #define IFPACK2_CHEBYSHEV_INSTANT(S,LO,GO,N) \
513 template class Ifpack2::Chebyshev< Tpetra::RowMatrix<S, LO, GO, N> >;
515 #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:211
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:127
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition: Ifpack2_Chebyshev_decl.hpp:223
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition: Ifpack2_Chebyshev_decl.hpp:217
double getApplyTime() const
The total time spent in all calls to apply().
Definition: Ifpack2_Chebyshev_def.hpp:199
virtual void setMatrix(const Teuchos::RCP< const row_matrix_type > &A)
Change the matrix to be preconditioned.
Definition: Ifpack2_Chebyshev_def.hpp:81
#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:93
double getComputeTime() const
The total time spent in all calls to compute().
Definition: Ifpack2_Chebyshev_def.hpp:193
int getNumApply() const
The total number of successful calls to apply().
Definition: Ifpack2_Chebyshev_def.hpp:181
MatrixType::node_type node_type
The Node type used by the input MatrixType.
Definition: Ifpack2_Chebyshev_decl.hpp:229
void compute()
(Re)compute the left scaling, and (if applicable) estimate max and min eigenvalues of D_inv * A...
Definition: Ifpack2_Chebyshev_def.hpp:305
bool hasTransposeApply() const
Whether it's possible to apply the transpose of this operator.
Definition: Ifpack2_Chebyshev_def.hpp:163
double getComputeFlops() const
The total number of floating-point operations taken by all calls to compute().
Definition: Ifpack2_Chebyshev_def.hpp:205
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:199
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:231
std::string description() const
A simple one-line description of this object.
Definition: Ifpack2_Chebyshev_def.hpp:332
void initialize()
Initialize the preconditioner.
Definition: Ifpack2_Chebyshev_def.hpp:290
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
The communicator over which the matrix is distributed.
Definition: Ifpack2_Chebyshev_def.hpp:102
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition: Ifpack2_Chebyshev_decl.hpp:220
int getNumInitialize() const
The total number of successful calls to initialize().
Definition: Ifpack2_Chebyshev_def.hpp:169
double getInitializeTime() const
The total time spent in all calls to initialize().
Definition: Ifpack2_Chebyshev_def.hpp:187
MatrixType::scalar_type getLambdaMaxForApply() const
The estimate of the maximum eigenvalue used in the apply().
Definition: Ifpack2_Chebyshev_def.hpp:504
size_t getNodeSmootherComplexity() const
Get a rough estimate of cost per iteration.
Definition: Ifpack2_Chebyshev_def.hpp:216
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:361
Teuchos::RCP< const row_matrix_type > getMatrix() const
The matrix for which this is a preconditioner.
Definition: Ifpack2_Chebyshev_def.hpp:116
TypeTo as(const TypeFrom &t)
double totalElapsedTime(bool readCurrentTime=false) const
Teuchos::RCP< const map_type > getDomainMap() const
The Tpetra::Map representing the domain of this operator.
Definition: Ifpack2_Chebyshev_def.hpp:137
virtual ~Chebyshev()
Destructor.
Definition: Ifpack2_Chebyshev_def.hpp:76
Teuchos::RCP< const map_type > getRangeMap() const
The Tpetra::Map representing the range of this operator.
Definition: Ifpack2_Chebyshev_def.hpp:151
int getNumCompute() const
The total number of successful calls to compute().
Definition: Ifpack2_Chebyshev_def.hpp:175
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:271