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_->getLocalNumRows() != 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_->getLocalNumRows();
80 NumEntries_.resize(NumRows_);
84 MaxNumEntries_ = A_->getLocalMaxNumRowEntries();
85 MaxNumEntriesA_ = A_->getLocalMaxNumRowEntries();
88 Kokkos::resize(Indices_,MaxNumEntries_);
89 Kokkos::resize(Values_,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 ();
124 template<
class MatrixType>
125 Teuchos::RCP<
const Tpetra::Map<
typename MatrixType::local_ordinal_type,
126 typename MatrixType::global_ordinal_type,
127 typename MatrixType::node_type> >
130 return A_->getRowMap();
134 template<
class MatrixType>
135 Teuchos::RCP<
const Tpetra::Map<
typename MatrixType::local_ordinal_type,
136 typename MatrixType::global_ordinal_type,
137 typename MatrixType::node_type> >
140 return A_->getColMap();
144 template<
class MatrixType>
145 Teuchos::RCP<
const Tpetra::Map<
typename MatrixType::local_ordinal_type,
146 typename MatrixType::global_ordinal_type,
147 typename MatrixType::node_type> >
150 return A_->getDomainMap();
154 template<
class MatrixType>
155 Teuchos::RCP<
const Tpetra::Map<
typename MatrixType::local_ordinal_type,
156 typename MatrixType::global_ordinal_type,
157 typename MatrixType::node_type> >
160 return A_->getRangeMap();
164 template<
class MatrixType>
165 Teuchos::RCP<
const Tpetra::RowGraph<
typename MatrixType::local_ordinal_type,
166 typename MatrixType::global_ordinal_type,
167 typename MatrixType::node_type> >
170 throw std::runtime_error(
"Ifpack2::DropFilter: does not support getGraph.");
174 template<
class MatrixType>
181 template<
class MatrixType>
188 template<
class MatrixType>
196 template<
class MatrixType>
203 template<
class MatrixType>
206 return A_->getIndexBase();
210 template<
class MatrixType>
217 template<
class MatrixType>
224 template<
class MatrixType>
227 throw std::runtime_error(
"Ifpack2::DropFilter does not implement getNumEntriesInGlobalRow.");
231 template<
class MatrixType>
234 return NumEntries_[localRow];
238 template<
class MatrixType>
241 return MaxNumEntries_;
245 template<
class MatrixType>
248 return MaxNumEntries_;
252 template<
class MatrixType>
255 return A_->getBlockSize();
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>
290 nonconst_global_inds_host_view_type &,
291 nonconst_values_host_view_type &,
294 throw std::runtime_error(
"Ifpack2::DropFilter does not implement getGlobalRowCopy.");
298 template<
class MatrixType>
301 nonconst_local_inds_host_view_type &Indices,
302 nonconst_values_host_view_type &Values,
303 size_t& NumEntries)
const
305 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.");
313 size_t A_NumEntries=0;
314 A_->getLocalRowCopy(LocalRow,Indices_,Values_,A_NumEntries);
320 for (
size_t i = 0 ; i < A_NumEntries ; ++i) {
325 Values[NumEntries] = Values_[i];
326 Indices[NumEntries] = Indices_[i];
333 template<
class MatrixType>
335 global_inds_host_view_type &,
336 values_host_view_type &)
const
338 throw std::runtime_error(
"Ifpack2::DropFilter: does not support getGlobalRowView.");
342 template<
class MatrixType>
344 local_inds_host_view_type & ,
345 values_host_view_type & )
const
347 throw std::runtime_error(
"Ifpack2::DropFilter: does not support getLocalRowView.");
351 template<
class MatrixType>
355 return A_->getLocalDiagCopy(diag);
359 template<
class MatrixType>
362 throw std::runtime_error(
"Ifpack2::DropFilter does not support leftScale.");
366 template<
class MatrixType>
369 throw std::runtime_error(
"Ifpack2::DropFilter does not support rightScale.");
373 template<
class MatrixType>
375 Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &Y,
383 "Ifpack2::DropFilter::apply ERROR: X.getNumVectors() != Y.getNumVectors().");
390 size_t NumVectors = Y.getNumVectors();
392 for (
size_t i = 0 ; i < NumRows_ ; ++i) {
395 getLocalRowCopy(i,Indices_,Values_,Nnz);
396 Scalar* Values =
reinterpret_cast<Scalar*
>(Values_.data());
398 for (
size_t j = 0 ; j < Nnz ; ++j)
399 for (
size_t k = 0 ; k < NumVectors ; ++k)
400 y_ptr[k][i] += Values[j] * x_ptr[k][Indices_[j]];
403 for (
size_t j = 0 ; j < Nnz ; ++j)
404 for (
size_t k = 0 ; k < NumVectors ; ++k)
405 y_ptr[k][Indices_[j]] += Values[j] * x_ptr[k][i];
408 for (
size_t j = 0 ; j < Nnz ; ++j)
409 for (
size_t k = 0 ; k < NumVectors ; ++k)
417 template<
class MatrixType>
424 template<
class MatrixType>
431 template<
class MatrixType>
434 throw std::runtime_error(
"Ifpack2::DropFilter does not implement getFrobeniusNorm.");
438 #define IFPACK2_DROPFILTER_INSTANT(S,LO,GO,N) \
439 template class Ifpack2::DropFilter< Tpetra::RowMatrix<S, LO, GO, N> >;
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:374
virtual global_size_t getGlobalNumRows() const
Returns the number of global rows in this matrix.
Definition: Ifpack2_DropFilter_def.hpp:175
virtual bool supportsRowViews() const
Returns true if RowViews are supported.
Definition: Ifpack2_DropFilter_def.hpp:425
virtual size_t getLocalNumCols() 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:197
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
virtual mag_type getFrobeniusNorm() const
Returns the Frobenius norm of the matrix.
Definition: Ifpack2_DropFilter_def.hpp:432
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:128
DropFilter(const Teuchos::RCP< const Tpetra::RowMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &Matrix, magnitudeType DropTol)
Constructor.
Definition: Ifpack2_DropFilter_def.hpp:58
virtual LocalOrdinal getBlockSize() const
The number of degrees of freedom per mesh point.
Definition: Ifpack2_DropFilter_def.hpp:253
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:352
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:232
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:360
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:367
virtual bool hasTransposeApply() const
Indicates whether this operator supports applying the adjoint operator.
Definition: Ifpack2_DropFilter_def.hpp:418
virtual size_t getLocalNumEntries() const
Returns the local number of entries in this matrix.
Definition: Ifpack2_DropFilter_def.hpp:218
virtual global_size_t getGlobalNumEntries() const
Returns the global number of entries in this matrix.
Definition: Ifpack2_DropFilter_def.hpp:211
virtual size_t getLocalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on this node.
Definition: Ifpack2_DropFilter_def.hpp:246
virtual size_t getGlobalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on all nodes.
Definition: Ifpack2_DropFilter_def.hpp:239
virtual Teuchos::RCP< const Tpetra::RowGraph< LocalOrdinal, GlobalOrdinal, Node > > getGraph() const
Returns the RowGraph associated with this matrix.
Definition: Ifpack2_DropFilter_def.hpp:168
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:225
virtual GlobalOrdinal getIndexBase() const
Returns the index base for global indices for this matrix.
Definition: Ifpack2_DropFilter_def.hpp:204
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:158
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:148
virtual global_size_t getGlobalNumCols() const
Returns the number of global columns in this matrix.
Definition: Ifpack2_DropFilter_def.hpp:182
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:289
virtual Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Returns the communicator.
Definition: Ifpack2_DropFilter_def.hpp:117
virtual size_t getLocalNumRows() const
Returns the number of rows owned on the calling node.
Definition: Ifpack2_DropFilter_def.hpp:189
virtual bool hasColMap() const
Indicates whether this matrix has a well-defined column map.
Definition: Ifpack2_DropFilter_def.hpp:260
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:334
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 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 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:300
virtual ~DropFilter()
Destructor.
Definition: Ifpack2_DropFilter_def.hpp:112
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:138
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:343
virtual bool isFillComplete() const
Returns true if fillComplete() has been called.
Definition: Ifpack2_DropFilter_def.hpp:281