43 #ifndef IFPACK2_DROPFILTER_DEF_HPP 44 #define IFPACK2_DROPFILTER_DEF_HPP 45 #include "Ifpack2_DropFilter_decl.hpp" 48 #include "Tpetra_ConfigDefs.hpp" 49 #include "Tpetra_RowMatrix.hpp" 50 #include "Tpetra_Map.hpp" 51 #include "Tpetra_MultiVector.hpp" 52 #include "Tpetra_Vector.hpp" 57 template<
class MatrixType>
59 magnitudeType DropTol):
69 if (A_->getComm()->getSize() != 1 || A_->getNodeNumRows() != A_->getGlobalNumRows()) {
70 throw std::runtime_error(
"Ifpack2::DropFilter can be used with Comm().getSize() == 1 only. This class is a tool for Ifpack2_AdditiveSchwarz, and it is not meant to be used otherwise.");
75 NumRows_ = A_->getNodeNumRows();
80 NumEntries_.resize(NumRows_);
84 MaxNumEntries_ = A_->getNodeMaxNumRowEntries();
85 MaxNumEntriesA_ = A_->getNodeMaxNumRowEntries();
88 Indices_.
resize(MaxNumEntries_);
89 Values_.
resize(MaxNumEntries_);
91 size_t ActualMaxNumEntries = 0;
92 for (
size_t i = 0 ; i < NumRows_ ; ++i) {
93 NumEntries_[i] = MaxNumEntriesA_;
95 A_->getLocalRowCopy(i,Indices_,Values_,Nnz);
96 for (
size_t j = 0 ; j < Nnz ; ++j) {
101 NumNonzeros_ += NewNnz;
102 NumEntries_[i] = NewNnz;
103 if (NewNnz > ActualMaxNumEntries)
104 ActualMaxNumEntries = NewNnz;
107 MaxNumEntries_ = ActualMaxNumEntries;
111 template<
class MatrixType>
115 template<
class MatrixType>
119 return A_->getComm ();
123 template<
class MatrixType>
127 return A_->getNode ();
131 template<
class MatrixType>
132 Teuchos::RCP<
const Tpetra::Map<
typename MatrixType::local_ordinal_type,
133 typename MatrixType::global_ordinal_type,
134 typename MatrixType::node_type> >
137 return A_->getRowMap();
141 template<
class MatrixType>
142 Teuchos::RCP<
const Tpetra::Map<
typename MatrixType::local_ordinal_type,
143 typename MatrixType::global_ordinal_type,
144 typename MatrixType::node_type> >
147 return A_->getColMap();
151 template<
class MatrixType>
152 Teuchos::RCP<
const Tpetra::Map<
typename MatrixType::local_ordinal_type,
153 typename MatrixType::global_ordinal_type,
154 typename MatrixType::node_type> >
157 return A_->getDomainMap();
161 template<
class MatrixType>
162 Teuchos::RCP<
const Tpetra::Map<
typename MatrixType::local_ordinal_type,
163 typename MatrixType::global_ordinal_type,
164 typename MatrixType::node_type> >
167 return A_->getRangeMap();
171 template<
class MatrixType>
172 Teuchos::RCP<
const Tpetra::RowGraph<
typename MatrixType::local_ordinal_type,
173 typename MatrixType::global_ordinal_type,
174 typename MatrixType::node_type> >
177 throw std::runtime_error(
"Ifpack2::DropFilter: does not support getGraph.");
181 template<
class MatrixType>
188 template<
class MatrixType>
195 template<
class MatrixType>
203 template<
class MatrixType>
210 template<
class MatrixType>
213 return A_->getIndexBase();
217 template<
class MatrixType>
224 template<
class MatrixType>
231 template<
class MatrixType>
234 throw std::runtime_error(
"Ifpack2::DropFilter does not implement getNumEntriesInGlobalRow.");
238 template<
class MatrixType>
241 return NumEntries_[localRow];
245 template<
class MatrixType>
248 return MaxNumEntries_;
252 template<
class MatrixType>
255 return MaxNumEntries_;
259 template<
class MatrixType>
266 template<
class MatrixType>
269 return A_->isLocallyIndexed();
273 template<
class MatrixType>
276 return A_->isGloballyIndexed();
280 template<
class MatrixType>
283 return A_->isFillComplete();
287 template<
class MatrixType>
293 throw std::runtime_error(
"Ifpack2::DropFilter does not implement getGlobalRowCopy.");
297 template<
class MatrixType>
301 size_t &NumEntries)
const 303 TEUCHOS_TEST_FOR_EXCEPTION((LocalRow < 0 || (
size_t) LocalRow >= NumRows_ || (
size_t) Indices.
size() < NumEntries_[LocalRow]), std::runtime_error,
"Ifpack2::DropFilter::getLocalRowCopy invalid row or array size.");
311 size_t A_NumEntries=0;
312 A_->getLocalRowCopy(LocalRow,Indices_(),Values_(),A_NumEntries);
318 for (
size_t i = 0 ; i < A_NumEntries ; ++i) {
323 Values[NumEntries] = Values_[i];
324 Indices[NumEntries] = Indices_[i];
331 template<
class MatrixType>
336 throw std::runtime_error(
"Ifpack2::DropFilter: does not support getGlobalRowView.");
340 template<
class MatrixType>
345 throw std::runtime_error(
"Ifpack2::DropFilter: does not support getLocalRowView.");
349 template<
class MatrixType>
353 return A_->getLocalDiagCopy(diag);
357 template<
class MatrixType>
360 throw std::runtime_error(
"Ifpack2::DropFilter does not support leftScale.");
364 template<
class MatrixType>
367 throw std::runtime_error(
"Ifpack2::DropFilter does not support rightScale.");
371 template<
class MatrixType>
373 Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &Y,
381 "Ifpack2::DropFilter::apply ERROR: X.getNumVectors() != Y.getNumVectors().");
388 size_t NumVectors = Y.getNumVectors();
390 for (
size_t i = 0 ; i < NumRows_ ; ++i) {
393 getLocalRowCopy(i,Indices_(),Values_(),Nnz);
394 if (mode==Teuchos::NO_TRANS){
395 for (
size_t j = 0 ; j < Nnz ; ++j)
396 for (
size_t k = 0 ; k < NumVectors ; ++k)
397 y_ptr[k][i] += Values_[j] * x_ptr[k][Indices_[j]];
399 else if (mode==Teuchos::TRANS){
400 for (
size_t j = 0 ; j < Nnz ; ++j)
401 for (
size_t k = 0 ; k < NumVectors ; ++k)
402 y_ptr[k][Indices_[j]] += Values_[j] * x_ptr[k][i];
405 for (
size_t j = 0 ; j < Nnz ; ++j)
406 for (
size_t k = 0 ; k < NumVectors ; ++k)
414 template<
class MatrixType>
421 template<
class MatrixType>
428 template<
class MatrixType>
431 throw std::runtime_error(
"Ifpack2::DropFilter does not implement getFrobeniusNorm.");
435 #define IFPACK2_DROPFILTER_INSTANT(S,LO,GO,N) \ 436 template class Ifpack2::DropFilter< Tpetra::RowMatrix<S, LO, GO, N> >; virtual Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const
Returns the Map that describes the range distribution in this matrix.
Definition: Ifpack2_DropFilter_def.hpp:165
virtual void getLocalRowCopy(LocalOrdinal DropRow, const Teuchos::ArrayView< LocalOrdinal > &Indices, const Teuchos::ArrayView< Scalar > &Values, size_t &NumEntries) const
Extract a list of entries in a specified local row of the graph. Put into storage allocated by callin...
Definition: Ifpack2_DropFilter_def.hpp:298
virtual size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const
Returns the current number of entries on this node in the specified local row.
Definition: Ifpack2_DropFilter_def.hpp:239
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
virtual bool hasTransposeApply() const
Indicates whether this operator supports applying the adjoint operator.
Definition: Ifpack2_DropFilter_def.hpp:415
virtual void getGlobalRowView(GlobalOrdinal GlobalRow, Teuchos::ArrayView< const GlobalOrdinal > &indices, Teuchos::ArrayView< const Scalar > &values) const
Extract a const, non-persisting view of global indices in a specified row of the matrix.
Definition: Ifpack2_DropFilter_def.hpp:332
virtual size_t getNodeNumCols() const
Returns the number of columns needed to apply the forward operator on this node, i.e., the number of elements listed in the column map.
Definition: Ifpack2_DropFilter_def.hpp:204
DropFilter(const Teuchos::RCP< const Tpetra::RowMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &Matrix, magnitudeType DropTol)
Constructor.
Definition: Ifpack2_DropFilter_def.hpp:58
virtual size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const
Returns the current number of entries on this node in the specified global row.
Definition: Ifpack2_DropFilter_def.hpp:232
virtual Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const
Returns the Map that describes the domain distribution in this matrix.
Definition: Ifpack2_DropFilter_def.hpp:155
virtual void getGlobalRowCopy(GlobalOrdinal GlobalRow, const Teuchos::ArrayView< GlobalOrdinal > &Indices, const Teuchos::ArrayView< Scalar > &Values, size_t &NumEntries) const
Extract a list of entries in a specified global row of this matrix. Put into pre-allocated storage...
Definition: Ifpack2_DropFilter_def.hpp:288
virtual void leftScale(const Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
Scales the RowMatrix on the left with the Vector x.
Definition: Ifpack2_DropFilter_def.hpp:358
virtual bool isLocallyIndexed() const
If matrix indices are in the local range, this function returns true. Otherwise, this function return...
Definition: Ifpack2_DropFilter_def.hpp:267
virtual bool isFillComplete() const
Returns true if fillComplete() has been called.
Definition: Ifpack2_DropFilter_def.hpp:281
virtual global_size_t getGlobalNumRows() const
Returns the number of global rows in this matrix.
Definition: Ifpack2_DropFilter_def.hpp:182
virtual void rightScale(const Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
Scales the RowMatrix on the right with the Vector x.
Definition: Ifpack2_DropFilter_def.hpp:365
virtual size_t getNodeNumEntries() const
Returns the local number of entries in this matrix.
Definition: Ifpack2_DropFilter_def.hpp:225
LinearOp zero(const VectorSpace &vs)
virtual size_t getNodeNumRows() const
Returns the number of rows owned on the calling node.
Definition: Ifpack2_DropFilter_def.hpp:196
void resize(size_type new_size, const value_type &x=value_type())
virtual global_size_t getGlobalNumEntries() const
Returns the global number of entries in this matrix.
Definition: Ifpack2_DropFilter_def.hpp:218
virtual void apply(const Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=Teuchos::ScalarTraits< Scalar >::one(), Scalar beta=Teuchos::ScalarTraits< Scalar >::zero()) const
Computes the operator-multivector application.
Definition: Ifpack2_DropFilter_def.hpp:372
virtual Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Returns the communicator.
Definition: Ifpack2_DropFilter_def.hpp:117
virtual bool hasColMap() const
Indicates whether this matrix has a well-defined column map.
Definition: Ifpack2_DropFilter_def.hpp:260
virtual bool supportsRowViews() const
Returns true if RowViews are supported.
Definition: Ifpack2_DropFilter_def.hpp:422
virtual global_size_t getGlobalNumCols() const
Returns the number of global columns in this matrix.
Definition: Ifpack2_DropFilter_def.hpp:189
virtual size_t getGlobalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on all nodes.
Definition: Ifpack2_DropFilter_def.hpp:246
virtual Teuchos::RCP< Node > getNode() const
Returns the underlying node.
Definition: Ifpack2_DropFilter_def.hpp:125
virtual size_t getNodeMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on this node.
Definition: Ifpack2_DropFilter_def.hpp:253
virtual bool isGloballyIndexed() const
If matrix indices are in the global range, this function returns true. Otherwise, this function retur...
Definition: Ifpack2_DropFilter_def.hpp:274
virtual Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getColMap() const
Returns the Map that describes the column distribution in this matrix.
Definition: Ifpack2_DropFilter_def.hpp:145
virtual void getLocalDiagCopy(Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const
Get a copy of the diagonal entries owned by this node, with local row indices.
Definition: Ifpack2_DropFilter_def.hpp:350
virtual mag_type getFrobeniusNorm() const
Returns the Frobenius norm of the matrix.
Definition: Ifpack2_DropFilter_def.hpp:429
virtual Teuchos::RCP< const Tpetra::RowGraph< LocalOrdinal, GlobalOrdinal, Node > > getGraph() const
Returns the RowGraph associated with this matrix.
Definition: Ifpack2_DropFilter_def.hpp:175
virtual void getLocalRowView(LocalOrdinal DropRow, Teuchos::ArrayView< const LocalOrdinal > &indices, Teuchos::ArrayView< const Scalar > &values) const
Extract a const, non-persisting view of local indices in a specified row of the matrix.
Definition: Ifpack2_DropFilter_def.hpp:341
virtual Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getRowMap() const
Returns the Map that describes the row distribution in this matrix.
Definition: Ifpack2_DropFilter_def.hpp:135
virtual GlobalOrdinal getIndexBase() const
Returns the index base for global indices for this matrix.
Definition: Ifpack2_DropFilter_def.hpp:211
Preconditioners and smoothers for Tpetra sparse matrices.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:72
virtual ~DropFilter()
Destructor.
Definition: Ifpack2_DropFilter_def.hpp:112