10 #ifndef IFPACK2_CHEBYSHEV_DEF_HPP
11 #define IFPACK2_CHEBYSHEV_DEF_HPP
13 #include "Ifpack2_Parameters.hpp"
15 #include "Tpetra_CrsMatrix.hpp"
22 template <
class MatrixType>
26 , IsInitialized_(false)
30 , TimerForApply_(true)
32 , InitializeTime_(0.0)
37 this->setObjectLabel(
"Ifpack2::Chebyshev");
40 template <
class MatrixType>
44 template <
class MatrixType>
46 if (A.
getRawPtr() != impl_.getMatrix().getRawPtr()) {
47 IsInitialized_ =
false;
53 template <
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");
61 template <
class MatrixType>
63 impl_.setZeroStartingSolution(zeroStartingSolution);
66 template <
class MatrixType>
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();
78 template <
class MatrixType>
82 return impl_.getMatrix();
85 template <
class MatrixType>
86 Teuchos::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());
98 template <
class MatrixType>
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();
111 template <
class MatrixType>
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();
124 template <
class MatrixType>
126 return impl_.hasTransposeApply();
129 template <
class MatrixType>
131 return NumInitialize_;
134 template <
class MatrixType>
139 template <
class MatrixType>
144 template <
class MatrixType>
146 return InitializeTime_;
149 template <
class MatrixType>
154 template <
class MatrixType>
159 template <
class MatrixType>
161 return ComputeFlops_;
164 template <
class MatrixType>
169 template <
class MatrixType>
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();
181 template <
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,
189 const std::string timerName(
"Ifpack2::Chebyshev::apply");
190 if (TimerForApply_) {
209 !isComputed(), std::runtime_error,
210 "Ifpack2::Chebyshev::apply(): You must call the compute() method before "
211 "you may call apply().");
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);
224 template <
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,
230 X.getNumVectors() != Y.getNumVectors(), std::invalid_argument,
231 "Ifpack2::Chebyshev::applyMat: X.getNumVectors() != Y.getNumVectors().");
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);
243 template <
class MatrixType>
248 const std::string timerName(
"Ifpack2::Chebyshev::initialize");
253 IsInitialized_ =
true;
257 template <
class MatrixType>
259 const std::string timerName(
"Ifpack2::Chebyshev::compute");
265 double startTime = timer->
wallTime();
270 if (!isInitialized()) {
279 ComputeTime_ += (timer->
wallTime() - startTime);
282 template <
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();
308 template <
class MatrixType>
330 const int myRank = this->getComm()->getRank();
334 out <<
"\"Ifpack2::Chebyshev\":" << endl;
339 out <<
"Template parameters:" << endl;
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;
362 template <
class MatrixType>
368 scalar_type beta)
const {
373 using Teuchos::rcp_const_cast;
374 using Teuchos::rcpFromRef;
376 const scalar_type zero = STS::zero();
377 const scalar_type one = STS::one();
406 RCP<const MV> X_copy;
407 bool copiedInput =
false;
412 X_copy = rcpFromRef(X);
421 RCP<MV> X_copy_nonConst = rcp_const_cast<MV>(X_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);
437 template <
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> >;
447 #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:165
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
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition: Ifpack2_Chebyshev_decl.hpp:187
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition: Ifpack2_Chebyshev_decl.hpp:181
double getApplyTime() const
The total time spent in all calls to apply().
Definition: Ifpack2_Chebyshev_def.hpp:155
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:45
#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:54
double getComputeTime() const
The total time spent in all calls to compute().
Definition: Ifpack2_Chebyshev_def.hpp:150
int getNumApply() const
The total number of successful calls to apply().
Definition: Ifpack2_Chebyshev_def.hpp:140
MatrixType::node_type node_type
The Node type used by the input MatrixType.
Definition: Ifpack2_Chebyshev_decl.hpp:193
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
bool hasTransposeApply() const
Whether it's possible to apply the transpose of this operator.
Definition: Ifpack2_Chebyshev_def.hpp:125
double getComputeFlops() const
The total number of floating-point operations taken by all calls to compute().
Definition: Ifpack2_Chebyshev_def.hpp:160
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:183
Chebyshev(const Teuchos::RCP< const row_matrix_type > &A)
Constructor.
Definition: Ifpack2_Chebyshev_def.hpp:24
std::string description() const
A simple one-line description of this object.
Definition: Ifpack2_Chebyshev_def.hpp:283
void initialize()
Initialize the preconditioner.
Definition: Ifpack2_Chebyshev_def.hpp:244
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
The communicator over which the matrix is distributed.
Definition: Ifpack2_Chebyshev_def.hpp:68
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition: Ifpack2_Chebyshev_decl.hpp:184
int getNumInitialize() const
The total number of successful calls to initialize().
Definition: Ifpack2_Chebyshev_def.hpp:130
double getInitializeTime() const
The total time spent in all calls to initialize().
Definition: Ifpack2_Chebyshev_def.hpp:145
MatrixType::scalar_type getLambdaMaxForApply() const
The estimate of the maximum eigenvalue used in the apply().
Definition: Ifpack2_Chebyshev_def.hpp:438
size_t getNodeSmootherComplexity() const
Get a rough estimate of cost per iteration.
Definition: Ifpack2_Chebyshev_def.hpp:170
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 row_matrix_type > getMatrix() const
The matrix for which this is a preconditioner.
Definition: Ifpack2_Chebyshev_def.hpp:81
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:101
virtual ~Chebyshev()
Destructor.
Definition: Ifpack2_Chebyshev_def.hpp:41
Teuchos::RCP< const map_type > getRangeMap() const
The Tpetra::Map representing the range of this operator.
Definition: Ifpack2_Chebyshev_def.hpp:114
int getNumCompute() const
The total number of successful calls to compute().
Definition: Ifpack2_Chebyshev_def.hpp:135
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 setZeroStartingSolution(bool zeroStartingSolution)
Set this preconditioner's parameters.
Definition: Ifpack2_Chebyshev_def.hpp:62