10#ifndef IFPACK2_IDENTITY_SOLVER_DEF_HPP
11#define IFPACK2_IDENTITY_SOLVER_DEF_HPP
13#include "Ifpack2_IdentitySolver_decl.hpp"
14#include "Tpetra_Map.hpp"
15#include "Tpetra_MultiVector.hpp"
16#include "Tpetra_Export.hpp"
20template<
class MatrixType>
24 isInitialized_ (false),
35template<
class MatrixType>
40template<
class MatrixType>
45template<
class MatrixType>
48 TEUCHOS_TEST_FOR_EXCEPTION(
49 matrix_.is_null (), std::runtime_error,
"Ifpack2::IdentitySolver: "
50 "You must call setMatrix() with a nonnull input matrix "
51 "before you may call initialize() or compute().");
53 TEUCHOS_TEST_FOR_EXCEPTION(
54 ! matrix_->getDomainMap ()->isCompatible (* (matrix_->getRangeMap ())),
55 std::invalid_argument,
56 "Ifpack2::IdentitySolver: The domain and range Maps "
57 "of the input matrix must be compatible.");
62 if (! matrix_->getDomainMap ()->isSameAs (* (matrix_->getRangeMap ()))) {
63 export_ = Teuchos::rcp (
new export_type (matrix_->getDomainMap (),
64 matrix_->getRangeMap ()));
69 export_ = Teuchos::null;
72 isInitialized_ =
true;
76template<
class MatrixType>
79 TEUCHOS_TEST_FOR_EXCEPTION(
80 matrix_.is_null (), std::runtime_error,
"Ifpack2::IdentitySolver: "
81 "You must call setMatrix() with a nonnull input matrix "
82 "before you may call initialize() or compute().");
84 if (! isInitialized_) {
92template<
class MatrixType>
94apply (
const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
95 Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
101 typedef Teuchos::ScalarTraits<scalar_type> STS;
105 TEUCHOS_TEST_FOR_EXCEPTION(
107 "Ifpack2::IdentitySolver::apply: If compute() has not yet been called, "
108 "or if you have changed the matrix via setMatrix(), "
109 "you must call compute() before you may call this method.");
114 if (export_.is_null ()) {
115 Y.update (alpha, X, beta);
118 if (alpha == STS::one () && beta == STS::zero ()) {
119 Y.doExport (X, *export_, Tpetra::REPLACE);
125 MV X_tmp (Y.getMap (), Y.getNumVectors ());
126 X_tmp.doExport (X, *export_, Tpetra::REPLACE);
127 Y.update (alpha, X_tmp, beta);
133template <
class MatrixType>
135 return(numInitialize_);
138template <
class MatrixType>
143template <
class MatrixType>
148template <
class MatrixType>
150 return(initializeTime_);
153template<
class MatrixType>
155 return(computeTime_);
158template<
class MatrixType>
163template <
class MatrixType>
166 std::ostringstream os;
171 os <<
"\"Ifpack2::IdentitySolver\": {";
172 if (this->getObjectLabel () !=
"") {
173 os <<
"Label: \"" << this->getObjectLabel () <<
"\", ";
175 os <<
"Initialized: " << (
isInitialized () ?
"true" :
"false") <<
", "
176 <<
"Computed: " << (
isComputed () ?
"true" :
"false") <<
", ";
178 if (matrix_.is_null ()) {
179 os <<
"Matrix: null";
182 os <<
"Matrix: not null"
183 <<
", Global matrix dimensions: ["
184 << matrix_->getGlobalNumRows () <<
", "
185 << matrix_->getGlobalNumCols () <<
"]";
192template <
class MatrixType>
194describe (Teuchos::FancyOStream& out,
195 const Teuchos::EVerbosityLevel verbLevel)
const
198 const Teuchos::EVerbosityLevel vl
199 = (verbLevel == Teuchos::VERB_DEFAULT) ? Teuchos::VERB_LOW : verbLevel;
201 if (vl != Teuchos::VERB_NONE) {
203 Teuchos::OSTab tab0 (out);
204 out <<
"\"Ifpack2::IdentitySolver\":" << endl;
205 Teuchos::OSTab tab1 (out);
206 out <<
"MatrixType: " << Teuchos::TypeNameTraits<MatrixType>::name () << endl;
207 out <<
"numInitialize: " << numInitialize_ << endl;
208 out <<
"numCompute: " << numCompute_ << endl;
209 out <<
"numApply: " << numApply_ << endl;
213template <
class MatrixType>
216 TEUCHOS_TEST_FOR_EXCEPTION(
217 matrix_.is_null (), std::runtime_error,
"Ifpack2::IdentitySolver::getDomainMap: "
218 "The matrix is null. Please call setMatrix() with a nonnull input "
219 "before calling this method.");
220 return matrix_->getDomainMap ();
223template <
class MatrixType>
226 TEUCHOS_TEST_FOR_EXCEPTION(
227 matrix_.is_null (), std::runtime_error,
"Ifpack2::IdentitySolver::getRangeMap: "
228 "The matrix is null. Please call setMatrix() with a nonnull input "
229 "before calling this method.");
230 return matrix_->getRangeMap ();
233template<
class MatrixType>
235setMatrix (
const Teuchos::RCP<const row_matrix_type>& A)
238 TEUCHOS_TEST_FOR_EXCEPTION(
239 ! A.is_null () && A->getComm ()->getSize () == 1 &&
240 A->getLocalNumRows () != A->getLocalNumCols (),
241 std::runtime_error,
"Ifpack2::IdentitySolver::setMatrix: If A's communicator only "
242 "contains one process, then A must be square. Instead, you provided a "
243 "matrix A with " << A->getLocalNumRows () <<
" rows and "
244 << A->getLocalNumCols () <<
" columns.");
249 isInitialized_ =
false;
251 export_ = Teuchos::null;
258#define IFPACK2_IDENTITYSOLVER_INSTANT(S,LO,GO,N) \
259 template class Ifpack2::IdentitySolver< Tpetra::RowMatrix<S, LO, GO, N> >;
void initialize()
Initialize.
Definition Ifpack2_IdentitySolver_def.hpp:46
int getNumInitialize() const
Return the number of calls to initialize().
Definition Ifpack2_IdentitySolver_def.hpp:134
Teuchos::RCP< const map_type > getDomainMap() const
Return the Tpetra::Map object associated with the domain of this operator.
Definition Ifpack2_IdentitySolver_def.hpp:214
MatrixType::node_type node_type
Node type of the input matrix.
Definition Ifpack2_IdentitySolver_decl.hpp:45
void setParameters(const Teuchos::ParameterList ¶ms)
Set this object's parameters.
Definition Ifpack2_IdentitySolver_def.hpp:41
double getInitializeTime() const
Return the time spent in initialize().
Definition Ifpack2_IdentitySolver_def.hpp:149
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, and put the result in Y.
Definition Ifpack2_IdentitySolver_def.hpp:94
int getNumCompute() const
Return the number of calls to compute().
Definition Ifpack2_IdentitySolver_def.hpp:139
MatrixType::local_ordinal_type local_ordinal_type
Type of the local indices of the input matrix.
Definition Ifpack2_IdentitySolver_decl.hpp:41
IdentitySolver(const Teuchos::RCP< const row_matrix_type > &A)
Constructor: Takes the matrix to precondition.
Definition Ifpack2_IdentitySolver_def.hpp:22
bool isInitialized() const
Return true if the preconditioner has been successfully initialized.
Definition Ifpack2_IdentitySolver_decl.hpp:72
double getApplyTime() const
Return the time spent in apply().
Definition Ifpack2_IdentitySolver_def.hpp:159
std::string description() const
Return a simple one-line description of this object.
Definition Ifpack2_IdentitySolver_def.hpp:164
virtual void setMatrix(const Teuchos::RCP< const row_matrix_type > &A)
Set this preconditioner's matrix.
Definition Ifpack2_IdentitySolver_def.hpp:235
Teuchos::RCP< const map_type > getRangeMap() const
Return the Tpetra::Map object associated with the range of this operator.
Definition Ifpack2_IdentitySolver_def.hpp:224
double getComputeTime() const
Return the time spent in compute().
Definition Ifpack2_IdentitySolver_def.hpp:154
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to an FancyOStream object.
Definition Ifpack2_IdentitySolver_def.hpp:194
MatrixType::global_ordinal_type global_ordinal_type
Type of the global indices of the input matrix.
Definition Ifpack2_IdentitySolver_decl.hpp:43
MatrixType::scalar_type scalar_type
Type of the entries of the input matrix.
Definition Ifpack2_IdentitySolver_decl.hpp:39
int getNumApply() const
Return the number of calls to apply().
Definition Ifpack2_IdentitySolver_def.hpp:144
virtual ~IdentitySolver()
Destructor.
Definition Ifpack2_IdentitySolver_def.hpp:36
void compute()
Compute the preconditioner.
Definition Ifpack2_IdentitySolver_def.hpp:77
bool isComputed() const
Return true if compute() has been called.
Definition Ifpack2_IdentitySolver_decl.hpp:80
Preconditioners and smoothers for Tpetra sparse matrices.
Definition Ifpack2_AdditiveSchwarz_decl.hpp:41