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):
36 if (A_->getComm()->getSize() != 1 || A_->getLocalNumRows() != A_->getGlobalNumRows()) {
37 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.");
42 NumRows_ = A_->getLocalNumRows();
47 NumEntries_.resize(NumRows_);
51 MaxNumEntries_ = A_->getLocalMaxNumRowEntries();
52 MaxNumEntriesA_ = A_->getLocalMaxNumRowEntries();
55 Kokkos::resize(Indices_,MaxNumEntries_);
56 Kokkos::resize(Values_,MaxNumEntries_);
58 size_t ActualMaxNumEntries = 0;
59 for (
size_t i = 0 ; i < NumRows_ ; ++i) {
60 NumEntries_[i] = MaxNumEntriesA_;
62 A_->getLocalRowCopy(i,Indices_,Values_,Nnz);
63 for (
size_t j = 0 ; j < Nnz ; ++j) {
64 if (((
size_t)Indices_[j] == i) || (Teuchos::ScalarTraits<Scalar>::magnitude(Values_[j]) >= DropTol_))
68 NumNonzeros_ += NewNnz;
69 NumEntries_[i] = NewNnz;
70 if (NewNnz > ActualMaxNumEntries)
71 ActualMaxNumEntries = NewNnz;
74 MaxNumEntries_ = ActualMaxNumEntries;
78template<
class MatrixType>
82template<
class MatrixType>
83Teuchos::RCP<const Teuchos::Comm<int> >
86 return A_->getComm ();
91template<
class MatrixType>
92Teuchos::RCP<
const Tpetra::Map<
typename MatrixType::local_ordinal_type,
93 typename MatrixType::global_ordinal_type,
94 typename MatrixType::node_type> >
97 return A_->getRowMap();
101template<
class MatrixType>
102Teuchos::RCP<
const Tpetra::Map<
typename MatrixType::local_ordinal_type,
103 typename MatrixType::global_ordinal_type,
104 typename MatrixType::node_type> >
107 return A_->getColMap();
111template<
class MatrixType>
112Teuchos::RCP<
const Tpetra::Map<
typename MatrixType::local_ordinal_type,
113 typename MatrixType::global_ordinal_type,
114 typename MatrixType::node_type> >
117 return A_->getDomainMap();
121template<
class MatrixType>
122Teuchos::RCP<
const Tpetra::Map<
typename MatrixType::local_ordinal_type,
123 typename MatrixType::global_ordinal_type,
124 typename MatrixType::node_type> >
127 return A_->getRangeMap();
131template<
class MatrixType>
132Teuchos::RCP<
const Tpetra::RowGraph<
typename MatrixType::local_ordinal_type,
133 typename MatrixType::global_ordinal_type,
134 typename MatrixType::node_type> >
137 throw std::runtime_error(
"Ifpack2::DropFilter: does not support getGraph.");
141template<
class MatrixType>
148template<
class MatrixType>
155template<
class MatrixType>
163template<
class MatrixType>
170template<
class MatrixType>
173 return A_->getIndexBase();
177template<
class MatrixType>
184template<
class MatrixType>
191template<
class MatrixType>
194 throw std::runtime_error(
"Ifpack2::DropFilter does not implement getNumEntriesInGlobalRow.");
198template<
class MatrixType>
201 return NumEntries_[localRow];
205template<
class MatrixType>
208 return MaxNumEntries_;
212template<
class MatrixType>
215 return MaxNumEntries_;
219template<
class MatrixType>
222 return A_->getBlockSize();
226template<
class MatrixType>
233template<
class MatrixType>
236 return A_->isLocallyIndexed();
240template<
class MatrixType>
243 return A_->isGloballyIndexed();
247template<
class MatrixType>
250 return A_->isFillComplete();
254template<
class MatrixType>
257 nonconst_global_inds_host_view_type &,
258 nonconst_values_host_view_type &,
261 throw std::runtime_error(
"Ifpack2::DropFilter does not implement getGlobalRowCopy.");
265template<
class MatrixType>
268 nonconst_local_inds_host_view_type &Indices,
269 nonconst_values_host_view_type &Values,
270 size_t& NumEntries)
const
272 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.");
280 size_t A_NumEntries=0;
281 A_->getLocalRowCopy(LocalRow,Indices_,Values_,A_NumEntries);
287 for (
size_t i = 0 ; i < A_NumEntries ; ++i) {
291 if ((Indices_[i] == LocalRow) || (Teuchos::ScalarTraits<Scalar>::magnitude(Values_[i]) >= DropTol_)) {
292 Values[NumEntries] = Values_[i];
293 Indices[NumEntries] = Indices_[i];
300template<
class MatrixType>
302 global_inds_host_view_type &,
303 values_host_view_type &)
const
305 throw std::runtime_error(
"Ifpack2::DropFilter: does not support getGlobalRowView.");
309template<
class MatrixType>
311 local_inds_host_view_type & ,
312 values_host_view_type & )
const
314 throw std::runtime_error(
"Ifpack2::DropFilter: does not support getLocalRowView.");
318template<
class MatrixType>
322 return A_->getLocalDiagCopy(diag);
326template<
class MatrixType>
329 throw std::runtime_error(
"Ifpack2::DropFilter does not support leftScale.");
333template<
class MatrixType>
336 throw std::runtime_error(
"Ifpack2::DropFilter does not support rightScale.");
340template<
class MatrixType>
342 Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &Y,
343 Teuchos::ETransp mode,
349 TEUCHOS_TEST_FOR_EXCEPTION(X.getNumVectors() != Y.getNumVectors(), std::runtime_error,
350 "Ifpack2::DropFilter::apply ERROR: X.getNumVectors() != Y.getNumVectors().");
352 Scalar zero = Teuchos::ScalarTraits<Scalar>::zero();
353 Teuchos::ArrayRCP<Teuchos::ArrayRCP<const Scalar> > x_ptr = X.get2dView();
354 Teuchos::ArrayRCP<Teuchos::ArrayRCP<Scalar> > y_ptr = Y.get2dViewNonConst();
357 size_t NumVectors = Y.getNumVectors();
359 for (
size_t i = 0 ; i < NumRows_ ; ++i) {
363 Scalar* Values =
reinterpret_cast<Scalar*
>(Values_.data());
364 if (mode==Teuchos::NO_TRANS){
365 for (
size_t j = 0 ; j < Nnz ; ++j)
366 for (
size_t k = 0 ; k < NumVectors ; ++k)
367 y_ptr[k][i] += Values[j] * x_ptr[k][Indices_[j]];
369 else if (mode==Teuchos::TRANS){
370 for (
size_t j = 0 ; j < Nnz ; ++j)
371 for (
size_t k = 0 ; k < NumVectors ; ++k)
372 y_ptr[k][Indices_[j]] += Values[j] * x_ptr[k][i];
375 for (
size_t j = 0 ; j < Nnz ; ++j)
376 for (
size_t k = 0 ; k < NumVectors ; ++k)
377 y_ptr[k][Indices_[j]] += Teuchos::ScalarTraits<Scalar>::conjugate(Values[j]) * x_ptr[k][i];
384template<
class MatrixType>
391template<
class MatrixType>
398template<
class MatrixType>
401 throw std::runtime_error(
"Ifpack2::DropFilter does not implement getFrobeniusNorm.");
405#define IFPACK2_DROPFILTER_INSTANT(S,LO,GO,N) \
406 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:156
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:105
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:334
virtual bool hasColMap() const
Indicates whether this matrix has a well-defined column map.
Definition Ifpack2_DropFilter_def.hpp:227
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:310
virtual global_size_t getGlobalNumRows() const
Returns the number of global rows in this matrix.
Definition Ifpack2_DropFilter_def.hpp:142
virtual bool hasTransposeApply() const
Indicates whether this operator supports applying the adjoint operator.
Definition Ifpack2_DropFilter_def.hpp:385
virtual bool supportsRowViews() const
Returns true if RowViews are supported.
Definition Ifpack2_DropFilter_def.hpp:392
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:327
virtual GlobalOrdinal getIndexBase() const
Returns the index base for global indices for this matrix.
Definition Ifpack2_DropFilter_def.hpp:171
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:199
virtual Teuchos::RCP< const Tpetra::RowGraph< LocalOrdinal, GlobalOrdinal, Node > > getGraph() const
Returns the RowGraph associated with this matrix.
Definition Ifpack2_DropFilter_def.hpp:135
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:95
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:241
virtual size_t getLocalNumEntries() const
Returns the local number of entries in this matrix.
Definition Ifpack2_DropFilter_def.hpp:185
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:256
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:125
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:234
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:115
virtual mag_type getFrobeniusNorm() const
Returns the Frobenius norm of the matrix.
Definition Ifpack2_DropFilter_def.hpp:399
virtual bool isFillComplete() const
Returns true if fillComplete() has been called.
Definition Ifpack2_DropFilter_def.hpp:248
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:164
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:301
virtual size_t getLocalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on this node.
Definition Ifpack2_DropFilter_def.hpp:213
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:267
virtual ~DropFilter()
Destructor.
Definition Ifpack2_DropFilter_def.hpp:79
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:192
virtual global_size_t getGlobalNumEntries() const
Returns the global number of entries in this matrix.
Definition Ifpack2_DropFilter_def.hpp:178
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:341
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:319
virtual Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Returns the communicator.
Definition Ifpack2_DropFilter_def.hpp:84
virtual global_size_t getGlobalNumCols() const
Returns the number of global columns in this matrix.
Definition Ifpack2_DropFilter_def.hpp:149
virtual LocalOrdinal getBlockSize() const
The number of degrees of freedom per mesh point.
Definition Ifpack2_DropFilter_def.hpp:220
virtual size_t getGlobalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on all nodes.
Definition Ifpack2_DropFilter_def.hpp:206
Preconditioners and smoothers for Tpetra sparse matrices.
Definition Ifpack2_AdditiveSchwarz_decl.hpp:41