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"
20 template<
class MatrixType>
24 isInitialized_ (false),
35 template<
class MatrixType>
40 template<
class MatrixType>
45 template<
class MatrixType>
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().");
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;
76 template<
class MatrixType>
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_) {
92 template<
class MatrixType>
94 apply (
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,
106 ! isComputed (), std::runtime_error,
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);
133 template <
class MatrixType>
135 return(numInitialize_);
138 template <
class MatrixType>
143 template <
class MatrixType>
148 template <
class MatrixType>
150 return(initializeTime_);
153 template<
class MatrixType>
155 return(computeTime_);
158 template<
class MatrixType>
163 template <
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 () <<
"]";
192 template <
class MatrixType>
204 out <<
"\"Ifpack2::IdentitySolver\":" << endl;
207 out <<
"numInitialize: " << numInitialize_ << endl;
208 out <<
"numCompute: " << numCompute_ << endl;
209 out <<
"numApply: " << numApply_ << endl;
213 template <
class MatrixType>
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 ();
223 template <
class MatrixType>
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 ();
233 template<
class MatrixType>
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> >;
261 #endif // IFPACK2_IDENTITY_SOLVER_DEF_HPP
int getNumApply() const
Return the number of calls to apply().
Definition: Ifpack2_IdentitySolver_def.hpp:144
MatrixType::node_type node_type
Node type of the input matrix.
Definition: Ifpack2_IdentitySolver_decl.hpp:45
double getComputeTime() const
Return the time spent in compute().
Definition: Ifpack2_IdentitySolver_def.hpp:154
int getNumCompute() const
Return the number of calls to compute().
Definition: Ifpack2_IdentitySolver_def.hpp:139
virtual ~IdentitySolver()
Destructor.
Definition: Ifpack2_IdentitySolver_def.hpp:36
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
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
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void setParameters(const Teuchos::ParameterList ¶ms)
Set this object's parameters.
Definition: Ifpack2_IdentitySolver_def.hpp:41
void initialize()
Initialize.
Definition: Ifpack2_IdentitySolver_def.hpp:46
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
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
IdentitySolver(const Teuchos::RCP< const row_matrix_type > &A)
Constructor: Takes the matrix to precondition.
Definition: Ifpack2_IdentitySolver_def.hpp:22
MatrixType::local_ordinal_type local_ordinal_type
Type of the local indices of the input matrix.
Definition: Ifpack2_IdentitySolver_decl.hpp:41
virtual void setMatrix(const Teuchos::RCP< const row_matrix_type > &A)
Set this preconditioner's matrix.
Definition: Ifpack2_IdentitySolver_def.hpp:235
std::string description() const
Return a simple one-line description of this object.
Definition: Ifpack2_IdentitySolver_def.hpp:164
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
void compute()
Compute the preconditioner.
Definition: Ifpack2_IdentitySolver_def.hpp:77
int getNumInitialize() const
Return the number of calls to initialize().
Definition: Ifpack2_IdentitySolver_def.hpp:134
MatrixType::global_ordinal_type global_ordinal_type
Type of the global indices of the input matrix.
Definition: Ifpack2_IdentitySolver_decl.hpp:43
double getInitializeTime() const
Return the time spent in initialize().
Definition: Ifpack2_IdentitySolver_def.hpp:149
MatrixType::scalar_type scalar_type
Type of the entries of the input matrix.
Definition: Ifpack2_IdentitySolver_decl.hpp:39
double getApplyTime() const
Return the time spent in apply().
Definition: Ifpack2_IdentitySolver_def.hpp:159
static std::string name()