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)
29 , initializeTime_(0.0)
34 template <
class MatrixType>
38 template <
class MatrixType>
42 template <
class MatrixType>
45 matrix_.is_null(), std::runtime_error,
46 "Ifpack2::IdentitySolver: "
47 "You must call setMatrix() with a nonnull input matrix "
48 "before you may call initialize() or compute().");
51 !matrix_->getDomainMap()->isCompatible(*(matrix_->getRangeMap())),
52 std::invalid_argument,
53 "Ifpack2::IdentitySolver: The domain and range Maps "
54 "of the input matrix must be compatible.");
59 if (!matrix_->getDomainMap()->isSameAs(*(matrix_->getRangeMap()))) {
60 export_ =
Teuchos::rcp(
new export_type(matrix_->getDomainMap(),
61 matrix_->getRangeMap()));
65 export_ = Teuchos::null;
68 isInitialized_ =
true;
72 template <
class MatrixType>
75 matrix_.is_null(), std::runtime_error,
76 "Ifpack2::IdentitySolver: "
77 "You must call setMatrix() with a nonnull input matrix "
78 "before you may call initialize() or compute().");
80 if (!isInitialized_) {
88 template <
class MatrixType>
90 apply(
const Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& X,
91 Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& Y,
102 !isComputed(), std::runtime_error,
103 "Ifpack2::IdentitySolver::apply: If compute() has not yet been called, "
104 "or if you have changed the matrix via setMatrix(), "
105 "you must call compute() before you may call this method.");
110 if (export_.is_null()) {
111 Y.update(alpha, X, beta);
113 if (alpha == STS::one() && beta == STS::zero()) {
114 Y.doExport(X, *export_, Tpetra::REPLACE);
119 MV X_tmp(Y.getMap(), Y.getNumVectors());
120 X_tmp.doExport(X, *export_, Tpetra::REPLACE);
121 Y.update(alpha, X_tmp, beta);
127 template <
class MatrixType>
129 return (numInitialize_);
132 template <
class MatrixType>
134 return (numCompute_);
137 template <
class MatrixType>
142 template <
class MatrixType>
144 return (initializeTime_);
147 template <
class MatrixType>
149 return (computeTime_);
152 template <
class MatrixType>
157 template <
class MatrixType>
159 std::ostringstream os;
164 os <<
"\"Ifpack2::IdentitySolver\": {";
165 if (this->getObjectLabel() !=
"") {
166 os <<
"Label: \"" << this->getObjectLabel() <<
"\", ";
168 os <<
"Initialized: " << (isInitialized() ?
"true" :
"false") <<
", "
169 <<
"Computed: " << (isComputed() ?
"true" :
"false") <<
", ";
171 if (matrix_.is_null()) {
172 os <<
"Matrix: null";
174 os <<
"Matrix: not null"
175 <<
", Global matrix dimensions: ["
176 << matrix_->getGlobalNumRows() <<
", "
177 << matrix_->getGlobalNumCols() <<
"]";
184 template <
class MatrixType>
194 out <<
"\"Ifpack2::IdentitySolver\":" << endl;
197 out <<
"numInitialize: " << numInitialize_ << endl;
198 out <<
"numCompute: " << numCompute_ << endl;
199 out <<
"numApply: " << numApply_ << endl;
203 template <
class MatrixType>
206 matrix_.is_null(), std::runtime_error,
207 "Ifpack2::IdentitySolver::getDomainMap: "
208 "The matrix is null. Please call setMatrix() with a nonnull input "
209 "before calling this method.");
210 return matrix_->getDomainMap();
213 template <
class MatrixType>
216 matrix_.is_null(), std::runtime_error,
217 "Ifpack2::IdentitySolver::getRangeMap: "
218 "The matrix is null. Please call setMatrix() with a nonnull input "
219 "before calling this method.");
220 return matrix_->getRangeMap();
223 template <
class MatrixType>
228 !A.
is_null() && A->getComm()->getSize() == 1 &&
229 A->getLocalNumRows() != A->getLocalNumCols(),
231 "Ifpack2::IdentitySolver::setMatrix: If A's communicator only "
232 "contains one process, then A must be square. Instead, you provided a "
234 << A->getLocalNumRows() <<
" rows and "
235 << A->getLocalNumCols() <<
" columns.");
240 isInitialized_ =
false;
242 export_ = Teuchos::null;
249 #define IFPACK2_IDENTITYSOLVER_INSTANT(S, LO, GO, N) \
250 template class Ifpack2::IdentitySolver<Tpetra::RowMatrix<S, LO, GO, N> >;
252 #endif // IFPACK2_IDENTITY_SOLVER_DEF_HPP
int getNumApply() const
Return the number of calls to apply().
Definition: Ifpack2_IdentitySolver_def.hpp:138
MatrixType::node_type node_type
Node type of the input matrix.
Definition: Ifpack2_IdentitySolver_decl.hpp:43
double getComputeTime() const
Return the time spent in compute().
Definition: Ifpack2_IdentitySolver_def.hpp:148
int getNumCompute() const
Return the number of calls to compute().
Definition: Ifpack2_IdentitySolver_def.hpp:133
virtual ~IdentitySolver()
Destructor.
Definition: Ifpack2_IdentitySolver_def.hpp:35
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:90
Teuchos::RCP< const map_type > getRangeMap() const
Return the Tpetra::Map object associated with the range of this operator.
Definition: Ifpack2_IdentitySolver_def.hpp:214
#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:39
void initialize()
Initialize.
Definition: Ifpack2_IdentitySolver_def.hpp:43
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:204
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:39
virtual void setMatrix(const Teuchos::RCP< const row_matrix_type > &A)
Set this preconditioner's matrix.
Definition: Ifpack2_IdentitySolver_def.hpp:225
std::string description() const
Return a simple one-line description of this object.
Definition: Ifpack2_IdentitySolver_def.hpp:158
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:186
void compute()
Compute the preconditioner.
Definition: Ifpack2_IdentitySolver_def.hpp:73
int getNumInitialize() const
Return the number of calls to initialize().
Definition: Ifpack2_IdentitySolver_def.hpp:128
MatrixType::global_ordinal_type global_ordinal_type
Type of the global indices of the input matrix.
Definition: Ifpack2_IdentitySolver_decl.hpp:41
double getInitializeTime() const
Return the time spent in initialize().
Definition: Ifpack2_IdentitySolver_def.hpp:143
MatrixType::scalar_type scalar_type
Type of the entries of the input matrix.
Definition: Ifpack2_IdentitySolver_decl.hpp:37
double getApplyTime() const
Return the time spent in apply().
Definition: Ifpack2_IdentitySolver_def.hpp:153
static std::string name()