10#ifndef IFPACK2_DROPFILTER_DEF_HPP
11#define IFPACK2_DROPFILTER_DEF_HPP
12#include "Ifpack2_DropFilter_decl.hpp"
15#include "Tpetra_ConfigDefs.hpp"
16#include "Tpetra_RowMatrix.hpp"
17#include "Tpetra_Map.hpp"
18#include "Tpetra_MultiVector.hpp"
19#include "Tpetra_Vector.hpp"
24template <
class MatrixType>
26 magnitudeType DropTol)
32 , MaxNumEntriesA_(0) {
34 if (A_->getComm()->getSize() != 1 || A_->getLocalNumRows() != A_->getGlobalNumRows()) {
35 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.");
39 NumRows_ = A_->getLocalNumRows();
44 NumEntries_.resize(NumRows_);
48 MaxNumEntries_ = A_->getLocalMaxNumRowEntries();
49 MaxNumEntriesA_ = A_->getLocalMaxNumRowEntries();
52 Kokkos::resize(Indices_, MaxNumEntries_);
53 Kokkos::resize(Values_, MaxNumEntries_);
55 size_t ActualMaxNumEntries = 0;
56 for (
size_t i = 0; i < NumRows_; ++i) {
57 NumEntries_[i] = MaxNumEntriesA_;
58 size_t Nnz, NewNnz = 0;
59 A_->getLocalRowCopy(i, Indices_, Values_, Nnz);
60 for (
size_t j = 0; j < Nnz; ++j) {
61 if (((
size_t)Indices_[j] == i) || (Teuchos::ScalarTraits<Scalar>::magnitude(Values_[j]) >= DropTol_))
65 NumNonzeros_ += NewNnz;
66 NumEntries_[i] = NewNnz;
67 if (NewNnz > ActualMaxNumEntries)
68 ActualMaxNumEntries = NewNnz;
71 MaxNumEntries_ = ActualMaxNumEntries;
75template <
class MatrixType>
79template <
class MatrixType>
80Teuchos::RCP<const Teuchos::Comm<int> >
86template <
class MatrixType>
87Teuchos::RCP<
const Tpetra::Map<
typename MatrixType::local_ordinal_type,
88 typename MatrixType::global_ordinal_type,
89 typename MatrixType::node_type> >
91 return A_->getRowMap();
95template <
class MatrixType>
96Teuchos::RCP<
const Tpetra::Map<
typename MatrixType::local_ordinal_type,
97 typename MatrixType::global_ordinal_type,
98 typename MatrixType::node_type> >
100 return A_->getColMap();
104template <
class MatrixType>
105Teuchos::RCP<
const Tpetra::Map<
typename MatrixType::local_ordinal_type,
106 typename MatrixType::global_ordinal_type,
107 typename MatrixType::node_type> >
109 return A_->getDomainMap();
113template <
class MatrixType>
114Teuchos::RCP<
const Tpetra::Map<
typename MatrixType::local_ordinal_type,
115 typename MatrixType::global_ordinal_type,
116 typename MatrixType::node_type> >
118 return A_->getRangeMap();
122template <
class MatrixType>
123Teuchos::RCP<
const Tpetra::RowGraph<
typename MatrixType::local_ordinal_type,
124 typename MatrixType::global_ordinal_type,
125 typename MatrixType::node_type> >
127 throw std::runtime_error(
"Ifpack2::DropFilter: does not support getGraph.");
131template <
class MatrixType>
137template <
class MatrixType>
143template <
class MatrixType>
150template <
class MatrixType>
156template <
class MatrixType>
158 return A_->getIndexBase();
162template <
class MatrixType>
168template <
class MatrixType>
174template <
class MatrixType>
176 throw std::runtime_error(
"Ifpack2::DropFilter does not implement getNumEntriesInGlobalRow.");
180template <
class MatrixType>
182 return NumEntries_[localRow];
186template <
class MatrixType>
188 return MaxNumEntries_;
192template <
class MatrixType>
194 return MaxNumEntries_;
198template <
class MatrixType>
200 return A_->getBlockSize();
204template <
class MatrixType>
210template <
class MatrixType>
212 return A_->isLocallyIndexed();
216template <
class MatrixType>
218 return A_->isGloballyIndexed();
222template <
class MatrixType>
224 return A_->isFillComplete();
228template <
class MatrixType>
231 nonconst_global_inds_host_view_type & ,
232 nonconst_values_host_view_type & ,
234 throw std::runtime_error(
"Ifpack2::DropFilter does not implement getGlobalRowCopy.");
238template <
class MatrixType>
241 nonconst_local_inds_host_view_type &Indices,
242 nonconst_values_host_view_type &Values,
243 size_t &NumEntries)
const {
244 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.");
252 size_t A_NumEntries = 0;
253 A_->getLocalRowCopy(LocalRow, Indices_, Values_, A_NumEntries);
259 for (
size_t i = 0; i < A_NumEntries; ++i) {
263 if ((Indices_[i] == LocalRow) || (Teuchos::ScalarTraits<Scalar>::magnitude(Values_[i]) >= DropTol_)) {
264 Values[NumEntries] = Values_[i];
265 Indices[NumEntries] = Indices_[i];
272template <
class MatrixType>
274 global_inds_host_view_type & ,
275 values_host_view_type & )
const {
276 throw std::runtime_error(
"Ifpack2::DropFilter: does not support getGlobalRowView.");
280template <
class MatrixType>
282 local_inds_host_view_type & ,
283 values_host_view_type & )
const {
284 throw std::runtime_error(
"Ifpack2::DropFilter: does not support getLocalRowView.");
288template <
class MatrixType>
291 return A_->getLocalDiagCopy(diag);
295template <
class MatrixType>
297 throw std::runtime_error(
"Ifpack2::DropFilter does not support leftScale.");
301template <
class MatrixType>
303 throw std::runtime_error(
"Ifpack2::DropFilter does not support rightScale.");
307template <
class MatrixType>
309 Tpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> &Y,
310 Teuchos::ETransp mode,
315 TEUCHOS_TEST_FOR_EXCEPTION(X.getNumVectors() != Y.getNumVectors(), std::runtime_error,
316 "Ifpack2::DropFilter::apply ERROR: X.getNumVectors() != Y.getNumVectors().");
318 Scalar zero = Teuchos::ScalarTraits<Scalar>::zero();
319 Teuchos::ArrayRCP<Teuchos::ArrayRCP<const Scalar> > x_ptr = X.get2dView();
320 Teuchos::ArrayRCP<Teuchos::ArrayRCP<Scalar> > y_ptr = Y.get2dViewNonConst();
323 size_t NumVectors = Y.getNumVectors();
325 for (
size_t i = 0; i < NumRows_; ++i) {
328 getLocalRowCopy(i, Indices_, Values_, Nnz);
329 Scalar *Values =
reinterpret_cast<Scalar *
>(Values_.data());
330 if (mode == Teuchos::NO_TRANS) {
331 for (
size_t j = 0; j < Nnz; ++j)
332 for (
size_t k = 0; k < NumVectors; ++k)
333 y_ptr[k][i] += Values[j] * x_ptr[k][Indices_[j]];
334 }
else if (mode == Teuchos::TRANS) {
335 for (
size_t j = 0; j < Nnz; ++j)
336 for (
size_t k = 0; k < NumVectors; ++k)
337 y_ptr[k][Indices_[j]] += Values[j] * x_ptr[k][i];
339 for (
size_t j = 0; j < Nnz; ++j)
340 for (
size_t k = 0; k < NumVectors; ++k)
341 y_ptr[k][Indices_[j]] += Teuchos::ScalarTraits<Scalar>::conjugate(Values[j]) * x_ptr[k][i];
347template <
class MatrixType>
353template <
class MatrixType>
359template <
class MatrixType>
361 throw std::runtime_error(
"Ifpack2::DropFilter does not implement getFrobeniusNorm.");
364#define IFPACK2_DROPFILTER_INSTANT(S, LO, GO, N) \
365 template class Ifpack2::DropFilter<Tpetra::RowMatrix<S, LO, GO, N> >;
virtual size_t getLocalNumRows() const
Returns the number of rows owned on the calling node.
Definition Ifpack2_DropFilter_def.hpp:144
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:99
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:302
virtual bool hasColMap() const
Indicates whether this matrix has a well-defined column map.
Definition Ifpack2_DropFilter_def.hpp:205
virtual void getLocalRowView(LocalOrdinal LocalRow, local_inds_host_view_type &indices, values_host_view_type &values) const
Extract a const, non-persisting view of local indices in a specified row of the matrix.
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:132
virtual bool hasTransposeApply() const
Indicates whether this operator supports applying the adjoint operator.
Definition Ifpack2_DropFilter_def.hpp:348
virtual bool supportsRowViews() const
Returns true if RowViews are supported.
Definition Ifpack2_DropFilter_def.hpp:354
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:296
virtual GlobalOrdinal getIndexBase() const
Returns the index base for global indices for this matrix.
Definition Ifpack2_DropFilter_def.hpp:157
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:181
virtual Teuchos::RCP< const Tpetra::RowGraph< LocalOrdinal, GlobalOrdinal, Node > > getGraph() const
Returns the RowGraph associated with this matrix.
Definition Ifpack2_DropFilter_def.hpp:126
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:90
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:217
virtual size_t getLocalNumEntries() const
Returns the local number of entries in this matrix.
Definition Ifpack2_DropFilter_def.hpp:169
virtual void getGlobalRowCopy(GlobalOrdinal GlobalRow, nonconst_global_inds_host_view_type &Indices, nonconst_values_host_view_type &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:230
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:117
DropFilter(const Teuchos::RCP< const Tpetra::RowMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &Matrix, magnitudeType DropTol)
Constructor.
Definition Ifpack2_DropFilter_def.hpp:25
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:211
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:108
virtual mag_type getFrobeniusNorm() const
Returns the Frobenius norm of the matrix.
Definition Ifpack2_DropFilter_def.hpp:360
virtual bool isFillComplete() const
Returns true if fillComplete() has been called.
Definition Ifpack2_DropFilter_def.hpp:223
virtual size_t getLocalNumCols() const
Returns the number of columns needed to apply the forward operator on this node, i....
Definition Ifpack2_DropFilter_def.hpp:151
virtual void getGlobalRowView(GlobalOrdinal GlobalRow, global_inds_host_view_type &indices, values_host_view_type &values) const
Extract a const, non-persisting view of global indices in a specified row of the matrix.
Definition Ifpack2_DropFilter_def.hpp:273
virtual size_t getLocalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on this node.
Definition Ifpack2_DropFilter_def.hpp:193
virtual void getLocalRowCopy(LocalOrdinal DropRow, nonconst_local_inds_host_view_type &Indices, nonconst_values_host_view_type &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:240
virtual ~DropFilter()
Destructor.
Definition Ifpack2_DropFilter_def.hpp:76
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:175
virtual global_size_t getGlobalNumEntries() const
Returns the global number of entries in this matrix.
Definition Ifpack2_DropFilter_def.hpp:163
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:308
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:289
virtual Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Returns the communicator.
Definition Ifpack2_DropFilter_def.hpp:81
virtual global_size_t getGlobalNumCols() const
Returns the number of global columns in this matrix.
Definition Ifpack2_DropFilter_def.hpp:138
virtual LocalOrdinal getBlockSize() const
The number of degrees of freedom per mesh point.
Definition Ifpack2_DropFilter_def.hpp:199
virtual size_t getGlobalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on all nodes.
Definition Ifpack2_DropFilter_def.hpp:187
Preconditioners and smoothers for Tpetra sparse matrices.
Definition Ifpack2_AdditiveSchwarz_decl.hpp:40