43 #ifndef IFPACK2_SINGLETONFILTER_DEF_HPP
44 #define IFPACK2_SINGLETONFILTER_DEF_HPP
45 #include "Ifpack2_SingletonFilter_decl.hpp"
47 #include "Tpetra_ConfigDefs.hpp"
48 #include "Tpetra_RowMatrix.hpp"
49 #include "Tpetra_Map.hpp"
50 #include "Tpetra_MultiVector.hpp"
51 #include "Tpetra_Vector.hpp"
56 template<
class MatrixType>
67 if (A_->getComm()->getSize() != 1 || A_->getNodeNumRows() != A_->getGlobalNumRows()) {
68 throw std::runtime_error(
"Ifpack2::SingeltonFilter 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.");
72 size_t NumRowsA_ = A_->getNodeNumRows();
76 MaxNumEntriesA_ = A_->getNodeMaxNumRowEntries();
79 Indices_.
resize(MaxNumEntriesA_);
80 Values_.
resize(MaxNumEntriesA_);
83 Reorder_.resize(NumRowsA_);
84 Reorder_.assign(Reorder_.size(),-1);
88 for (
size_t i = 0 ; i < NumRowsA_ ; ++i) {
90 A_->getLocalRowCopy(i,Indices_,Values_,Nnz);
92 Reorder_[i] = NumRows_++;
100 InvReorder_.resize(NumRows_);
101 for (
size_t i = 0 ; i < NumRowsA_ ; ++i) {
104 InvReorder_[Reorder_[i]] = i;
106 NumEntries_.resize(NumRows_);
107 SingletonIndex_.resize(NumSingletons_);
112 for (
size_t i = 0 ; i < NumRowsA_ ; ++i) {
114 A_->getLocalRowCopy(i,Indices_,Values_,Nnz);
115 LocalOrdinal ii = Reorder_[i];
117 NumEntries_[ii] = Nnz;
119 if (Nnz > MaxNumEntries_)
120 MaxNumEntries_ = Nnz;
123 SingletonIndex_[count] = i;
129 ReducedMap_ =
Teuchos::rcp(
new Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node>(NumRows_,0,A_->getComm()) );
132 Diagonal_ =
Teuchos::rcp(
new Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(ReducedMap_) );
134 Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> DiagonalA(A_->getRowMap());
135 A_->getLocalDiagCopy(DiagonalA);
137 for (
size_t i = 0 ; i < NumRows_ ; ++i) {
138 LocalOrdinal ii = InvReorder_[i];
139 Diagonal_->replaceLocalValue((LocalOrdinal)i,DiagonalAview[ii]);
144 template<
class MatrixType>
148 template<
class MatrixType>
151 return A_->getComm();
155 template<
class MatrixType>
158 return A_->getNode();
162 template<
class MatrixType>
163 const Teuchos::RCP<
const Tpetra::Map<
typename MatrixType::local_ordinal_type,
164 typename MatrixType::global_ordinal_type,
165 typename MatrixType::node_type> >&
172 template<
class MatrixType>
173 const Teuchos::RCP<
const Tpetra::Map<
typename MatrixType::local_ordinal_type,
174 typename MatrixType::global_ordinal_type,
175 typename MatrixType::node_type> >&
182 template<
class MatrixType>
183 const Teuchos::RCP<
const Tpetra::Map<
typename MatrixType::local_ordinal_type,
184 typename MatrixType::global_ordinal_type,
185 typename MatrixType::node_type> >&
192 template<
class MatrixType>
193 const Teuchos::RCP<
const Tpetra::Map<
typename MatrixType::local_ordinal_type,
194 typename MatrixType::global_ordinal_type,
195 typename MatrixType::node_type> >&
202 template<
class MatrixType>
203 Teuchos::RCP<
const Tpetra::RowGraph<
typename MatrixType::local_ordinal_type,
204 typename MatrixType::global_ordinal_type,
205 typename MatrixType::node_type> >
208 throw std::runtime_error(
"Ifpack2::SingletonFilter: does not support getGraph.");
212 template<
class MatrixType>
219 template<
class MatrixType>
226 template<
class MatrixType>
234 template<
class MatrixType>
241 template<
class MatrixType>
244 return A_->getIndexBase();
248 template<
class MatrixType>
255 template<
class MatrixType>
262 template<
class MatrixType>
265 throw std::runtime_error(
"Ifpack2::SingletonFilter does not implement getNumEntriesInGlobalRow.");
269 template<
class MatrixType>
272 return NumEntries_[localRow];
276 template<
class MatrixType>
279 return A_->getGlobalNumDiags();
283 template<
class MatrixType>
286 return A_->getNodeNumDiags();
290 template<
class MatrixType>
293 return MaxNumEntries_;
297 template<
class MatrixType>
300 return MaxNumEntries_;
304 template<
class MatrixType>
311 template<
class MatrixType>
314 return A_->isLowerTriangular();
318 template<
class MatrixType>
321 return A_->isUpperTriangular();
325 template<
class MatrixType>
328 return A_->isLocallyIndexed();
332 template<
class MatrixType>
335 return A_->isGloballyIndexed();
339 template<
class MatrixType>
342 return A_->isFillComplete();
346 template<
class MatrixType>
350 size_t &NumEntries)
const
352 throw std::runtime_error(
"Ifpack2::SingletonFilter does not implement getGlobalRowCopy.");
356 template<
class MatrixType>
360 size_t &NumEntries)
const
362 TEUCHOS_TEST_FOR_EXCEPTION((LocalRow < 0 || (
size_t) LocalRow >= NumRows_ || (
size_t) Indices.
size() < NumEntries_[LocalRow]), std::runtime_error,
"Ifpack2::SingletonFilter::getLocalRowCopy invalid row or array size.");
365 LocalOrdinal ARow = InvReorder_[LocalRow];
366 A_->getLocalRowCopy(ARow,Indices_(),Values_(),Nnz);
370 for (
size_t i = 0 ; i < Nnz ; ++i) {
371 LocalOrdinal ii = Reorder_[Indices_[i]];
373 Indices[NumEntries] = ii;
374 Values[NumEntries] = Values_[i];
382 template<
class MatrixType>
387 throw std::runtime_error(
"Ifpack2::SingletonFilter: does not support getGlobalRowView.");
391 template<
class MatrixType>
396 throw std::runtime_error(
"Ifpack2::SingletonFilter: does not support getLocalRowView.");
400 template<
class MatrixType>
404 return A_->getLocalDiagCopy(diag);
408 template<
class MatrixType>
411 throw std::runtime_error(
"Ifpack2::SingletonFilter does not support leftScale.");
415 template<
class MatrixType>
418 throw std::runtime_error(
"Ifpack2::SingletonFilter does not support rightScale.");
422 template<
class MatrixType>
424 Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &Y,
429 this->
template applyTempl<Scalar,Scalar>(X, Y, mode, alpha, beta);
434 template<
class MatrixType>
435 template<
class DomainScalar,
class RangeScalar>
437 Tpetra::MultiVector<RangeScalar,LocalOrdinal,GlobalOrdinal,Node> &Y,
440 RangeScalar beta)
const
445 "Ifpack2::SingletonFilter::apply ERROR: X.getNumVectors() != Y.getNumVectors().");
452 size_t NumVectors = Y.getNumVectors();
455 for (
size_t i = 0 ; i < NumRows_ ; ++i) {
458 getLocalRowCopy(i,Indices_(),Values_(),Nnz);
460 for (
size_t j = 0 ; j < Nnz ; ++j)
461 for (
size_t k = 0 ; k < NumVectors ; ++k)
462 y_ptr[k][i] += (RangeScalar)Values_[j] * (RangeScalar)x_ptr[k][Indices_[j]];
465 for (
size_t j = 0 ; j < Nnz ; ++j)
466 for (
size_t k = 0 ; k < NumVectors ; ++k)
467 y_ptr[k][Indices_[j]] += (RangeScalar)Values_[j] * (RangeScalar)x_ptr[k][i];
470 for (
size_t j = 0 ; j < Nnz ; ++j)
471 for (
size_t k = 0 ; k < NumVectors ; ++k)
479 template<
class MatrixType>
486 template<
class MatrixType>
493 template<
class MatrixType>
495 Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& LHS)
497 this->
template SolveSingletonsTempl<Scalar,Scalar>(RHS, LHS);
501 template<
class MatrixType>
502 template<
class DomainScalar,
class RangeScalar>
504 Tpetra::MultiVector<RangeScalar,LocalOrdinal,GlobalOrdinal,Node>& LHS)
509 for (
size_t i = 0 ; i < NumSingletons_ ; ++i) {
510 LocalOrdinal ii = SingletonIndex_[i];
513 A_->getLocalRowCopy(ii,Indices_(),Values_(),Nnz);
514 for (
size_t j = 0 ; j < Nnz ; ++j) {
515 if (Indices_[j] == ii) {
516 for (
size_t k = 0 ; k < LHS.getNumVectors() ; ++k)
517 LHS_ptr[k][ii] = (RangeScalar)RHS_ptr[k][ii] / (RangeScalar)Values_[j];
524 template<
class MatrixType>
526 const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& RHS,
527 Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& ReducedRHS)
529 this->
template CreateReducedRHSTempl<Scalar,Scalar>(LHS, RHS, ReducedRHS);
533 template<
class MatrixType>
534 template<
class DomainScalar,
class RangeScalar>
536 const Tpetra::MultiVector<RangeScalar,LocalOrdinal,GlobalOrdinal,Node>& RHS,
537 Tpetra::MultiVector<RangeScalar,LocalOrdinal,GlobalOrdinal,Node>& ReducedRHS)
543 size_t NumVectors = LHS.getNumVectors();
545 for (
size_t i = 0 ; i < NumRows_ ; ++i)
546 for (
size_t k = 0 ; k < NumVectors ; ++k)
547 ReducedRHS_ptr[k][i] = RHS_ptr[k][InvReorder_[i]];
549 for (
size_t i = 0 ; i < NumRows_ ; ++i) {
550 LocalOrdinal ii = InvReorder_[i];
552 A_->getLocalRowCopy(ii,Indices_(),Values_(),Nnz);
554 for (
size_t j = 0 ; j < Nnz ; ++j) {
555 if (Reorder_[Indices_[j]] == -1) {
556 for (
size_t k = 0 ; k < NumVectors ; ++k)
557 ReducedRHS_ptr[k][i] -= (RangeScalar)Values_[j] * (RangeScalar)LHS_ptr[k][Indices_[j]];
564 template<
class MatrixType>
566 Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& LHS)
568 this->
template UpdateLHSTempl<Scalar,Scalar>(ReducedLHS, LHS);
572 template<
class MatrixType>
573 template<
class DomainScalar,
class RangeScalar>
575 Tpetra::MultiVector<RangeScalar,LocalOrdinal,GlobalOrdinal,Node>& LHS)
581 for (
size_t i = 0 ; i < NumRows_ ; ++i)
582 for (
size_t k = 0 ; k < LHS.getNumVectors() ; ++k)
583 LHS_ptr[k][InvReorder_[i]] = (RangeScalar)ReducedLHS_ptr[k][i];
587 template<
class MatrixType>
590 throw std::runtime_error(
"Ifpack2::SingletonFilter does not implement getFrobeniusNorm.");
594 template<
class MatrixType>
599 throw std::runtime_error(
"Ifpack2::SingletonFilter does not implement getGlobalRowView.");
603 template<
class MatrixType>
608 throw std::runtime_error(
"Ifpack2::SingletonFilter does not implement getLocalRowView.");
virtual const Teuchos::RCP< const Teuchos::Comm< int > > & getComm() const
Returns the communicator.
Definition: Ifpack2_SingletonFilter_def.hpp:149
virtual bool hasTransposeApply() const
Indicates whether this operator supports applying the adjoint operator.
Definition: Ifpack2_SingletonFilter_def.hpp:480
virtual void rightScale(const Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
Scales the RowMatrix on the right with the Vector x.
Definition: Ifpack2_SingletonFilter_def.hpp:416
virtual ~SingletonFilter()
Destructor.
Definition: Ifpack2_SingletonFilter_def.hpp:145
virtual Teuchos::RCP< const Tpetra::RowGraph< LocalOrdinal, GlobalOrdinal, Node > > getGraph() const
Returns the RowGraph associated with this matrix.
Definition: Ifpack2_SingletonFilter_def.hpp:206
virtual void UpdateLHS(const Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &ReducedLHS, Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &LHS)
Updates a full LHS from a reduces LHS.
Definition: Ifpack2_SingletonFilter_def.hpp:565
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_SingletonFilter_def.hpp:383
void applyTempl(const Tpetra::MultiVector< DomainScalar, LocalOrdinal, GlobalOrdinal, Node > &X, Tpetra::MultiVector< RangeScalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, RangeScalar alpha=Teuchos::ScalarTraits< Scalar >::one(), RangeScalar beta=Teuchos::ScalarTraits< Scalar >::zero()) const
Computes the operator-multivector application.
Definition: Ifpack2_SingletonFilter_def.hpp:436
virtual void CreateReducedRHS(const Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &LHS, const Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &RHS, Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &ReducedRHS)
Creates a RHS for the reduced singleton-free system.
Definition: Ifpack2_SingletonFilter_def.hpp:525
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
virtual global_size_t getGlobalNumDiags() const
Returns the number of global diagonal entries, based on global row/column index comparisons.
Definition: Ifpack2_SingletonFilter_def.hpp:277
virtual bool supportsRowViews() const
Returns true if RowViews are supported.
Definition: Ifpack2_SingletonFilter_def.hpp:487
virtual global_size_t getGlobalNumRows() const
Returns the number of global rows in this matrix.
Definition: Ifpack2_SingletonFilter_def.hpp:213
virtual Teuchos::ScalarTraits< Scalar >::magnitudeType getFrobeniusNorm() const
Returns the Frobenius norm of the matrix.
Definition: Ifpack2_SingletonFilter_def.hpp:588
virtual GlobalOrdinal getIndexBase() const
Returns the index base for global indices for this matrix.
Definition: Ifpack2_SingletonFilter_def.hpp:242
virtual size_t getNodeNumEntries() const
Returns the local number of entries in this matrix.
Definition: Ifpack2_SingletonFilter_def.hpp:256
virtual size_t getNodeNumDiags() const
Returns the number of local diagonal entries, based on global row/column index comparisons.
Definition: Ifpack2_SingletonFilter_def.hpp:284
virtual const Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > & getColMap() const
Returns the Map that describes the column distribution in this matrix.
Definition: Ifpack2_SingletonFilter_def.hpp:176
virtual bool isFillComplete() const
Returns true if fillComplete() has been called.
Definition: Ifpack2_SingletonFilter_def.hpp:340
virtual global_size_t getGlobalNumCols() const
Returns the number of global columns in this matrix.
Definition: Ifpack2_SingletonFilter_def.hpp:220
virtual void getLocalRowView(LocalOrdinal LocalRow, 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_SingletonFilter_def.hpp:392
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
virtual bool isGloballyIndexed() const
If matrix indices are in the global range, this function returns true. Otherwise, this function retur...
Definition: Ifpack2_SingletonFilter_def.hpp:333
virtual global_size_t getGlobalNumEntries() const
Returns the global number of entries in this matrix.
Definition: Ifpack2_SingletonFilter_def.hpp:249
virtual bool hasColMap() const
Indicates whether this matrix has a well-defined column map.
Definition: Ifpack2_SingletonFilter_def.hpp:305
virtual bool isLocallyIndexed() const
If matrix indices are in the local range, this function returns true. Otherwise, this function return...
Definition: Ifpack2_SingletonFilter_def.hpp:326
virtual Teuchos::RCP< Node > getNode() const
Returns the underlying node.
Definition: Ifpack2_SingletonFilter_def.hpp:156
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_SingletonFilter_def.hpp:235
void resize(size_type new_size, const value_type &x=value_type())
virtual size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const
Returns the current number of entries on this node in the specified local row.
Definition: Ifpack2_SingletonFilter_def.hpp:270
virtual size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const
Returns the current number of entries on this node in the specified global row.
Definition: Ifpack2_SingletonFilter_def.hpp:263
virtual const Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > & getRangeMap() const
Returns the Map that describes the range distribution in this matrix.
Definition: Ifpack2_SingletonFilter_def.hpp:196
virtual const Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > & getDomainMap() const
Returns the Map that describes the domain distribution in this matrix.
Definition: Ifpack2_SingletonFilter_def.hpp:186
virtual size_t getGlobalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on all nodes.
Definition: Ifpack2_SingletonFilter_def.hpp:291
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_SingletonFilter_def.hpp:401
SingletonFilter(const Teuchos::RCP< const Tpetra::RowMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &Matrix)
Constructor.
Definition: Ifpack2_SingletonFilter_def.hpp:57
virtual size_t getNodeNumRows() const
Returns the number of rows owned on the calling node.
Definition: Ifpack2_SingletonFilter_def.hpp:227
virtual const Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > & getRowMap() const
Returns the Map that describes the row distribution in this matrix.
Definition: Ifpack2_SingletonFilter_def.hpp:166
virtual bool isLowerTriangular() const
Indicates whether this matrix is lower triangular.
Definition: Ifpack2_SingletonFilter_def.hpp:312
virtual size_t getNodeMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on this node.
Definition: Ifpack2_SingletonFilter_def.hpp:298
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_SingletonFilter_def.hpp:423
virtual void SolveSingletons(const Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &RHS, Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &LHS)
Solve the singleton components of the linear system.
Definition: Ifpack2_SingletonFilter_def.hpp:494
virtual bool isUpperTriangular() const
Indicates whether this matrix is upper triangular.
Definition: Ifpack2_SingletonFilter_def.hpp:319
Ifpack2_SingletonFilter: Filter based on matrix entries.
Definition: Ifpack2_SingletonFilter_decl.hpp:58
virtual void leftScale(const Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
Scales the RowMatrix on the left with the Vector x.
Definition: Ifpack2_SingletonFilter_def.hpp:409
virtual void getLocalRowCopy(LocalOrdinal LocalRow, 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_SingletonFilter_def.hpp:357
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_SingletonFilter_def.hpp:347