43 #ifndef IFPACK2_REORDERFILTER_DEF_HPP 44 #define IFPACK2_REORDERFILTER_DEF_HPP 45 #include "Ifpack2_ReorderFilter_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" 58 #ifdef HAVE_IFPACK2_ZOLTAN2 59 template<
class MatrixType>
60 ReorderFilter<MatrixType>::ReorderFilter(
const Teuchos::RCP<
const Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > & Matrix,
61 const Teuchos::RCP<
const Zoltan2::OrderingSolution<GlobalOrdinal,LocalOrdinal> > & Reordering):
66 if (A_->getComm()->getSize() != 1 || A_->getNodeNumRows() != A_->getGlobalNumRows()) {
67 throw std::runtime_error(
"Ifpack2::ReorderFilter 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 perm_=Reordering->getPermutationRCPConst();
75 size_t N=A_->getNodeNumRows();
76 reverseperm_.resize(N);
78 for(
size_t i=0; i<N; i++) {
79 reverseperm_[perm_[i]] = i;
83 Indices_.resize(A_->getNodeMaxNumRowEntries());
84 Values_.resize(A_->getNodeMaxNumRowEntries());
89 template<
class MatrixType>
93 template<
class MatrixType>
100 template<
class MatrixType>
103 return A_->getNode();
107 template<
class MatrixType>
108 const Teuchos::RCP<
const Tpetra::Map<
typename MatrixType::local_ordinal_type,
109 typename MatrixType::global_ordinal_type,
110 typename MatrixType::node_type> >&
113 return A_->getRowMap();
117 template<
class MatrixType>
118 const Teuchos::RCP<
const Tpetra::Map<
typename MatrixType::local_ordinal_type,
119 typename MatrixType::global_ordinal_type,
120 typename MatrixType::node_type> >&
123 return A_->getColMap();
127 template<
class MatrixType>
128 const Teuchos::RCP<
const Tpetra::Map<
typename MatrixType::local_ordinal_type,
129 typename MatrixType::global_ordinal_type,
130 typename MatrixType::node_type> >&
133 return A_->getDomainMap();
137 template<
class MatrixType>
138 const Teuchos::RCP<
const Tpetra::Map<
typename MatrixType::local_ordinal_type,
139 typename MatrixType::global_ordinal_type,
140 typename MatrixType::node_type> >&
143 return A_->getRangeMap();
147 template<
class MatrixType>
148 Teuchos::RCP<
const Tpetra::RowGraph<
typename MatrixType::local_ordinal_type,
149 typename MatrixType::global_ordinal_type,
150 typename MatrixType::node_type> >
153 throw std::runtime_error(
"Ifpack2::ReorderFilter: does not support getGraph.");
157 template<
class MatrixType>
160 return A_->getGlobalNumRows();
164 template<
class MatrixType>
167 return A_->getGlobalNumCols();
171 template<
class MatrixType>
174 return A_->getNodeNumRows();
179 template<
class MatrixType>
182 return A_->getNodeNumCols();
186 template<
class MatrixType>
189 return A_->getIndexBase();
193 template<
class MatrixType>
196 return A_->getGlobalNumEntries();
200 template<
class MatrixType>
203 return A_->getNodeNumEntries();
207 template<
class MatrixType>
210 throw std::runtime_error(
"Ifpack2::ReorderFilter does not implement getNumEntriesInGlobalRow");
214 template<
class MatrixType>
217 LocalOrdinal MyReorderedRow = reverseperm_[localRow];
218 return A_->getNumEntriesInLocalRow(MyReorderedRow);
222 template<
class MatrixType>
225 return A_->getGlobalNumDiags();
229 template<
class MatrixType>
232 return A_->getNodeNumDiags();
236 template<
class MatrixType>
239 return A_->getGlobalMaxNumRowEntries();
243 template<
class MatrixType>
246 return A_->getNodeMaxNumRowEntries();
250 template<
class MatrixType>
257 template<
class MatrixType>
260 return A_->isLowerTriangular();
264 template<
class MatrixType>
267 return A_->isUpperTriangular();
271 template<
class MatrixType>
274 return A_->isLocallyIndexed();
278 template<
class MatrixType>
281 return A_->isGloballyIndexed();
285 template<
class MatrixType>
288 return A_->isFillComplete();
292 template<
class MatrixType>
294 const Teuchos::ArrayView<GlobalOrdinal> &Indices,
295 const Teuchos::ArrayView<Scalar> &Values,
296 size_t &NumEntries)
const 298 throw std::runtime_error(
"Ifpack2::ReorderFilter does not implement getGlobalRowCopy.");
302 template<
class MatrixType>
304 const Teuchos::ArrayView<LocalOrdinal> &Indices,
305 const Teuchos::ArrayView<Scalar> &Values,
306 size_t &NumEntries)
const 308 TEUCHOS_TEST_FOR_EXCEPTION((LocalRow < 0 || (
size_t) LocalRow >= A_->getNodeNumRows() || (size_t) Indices.size() < A_->getNumEntriesInLocalRow(LocalRow)), std::runtime_error,
"Ifpack2::ReorderFilter::getLocalRowCopy invalid row or array size.");
311 LocalOrdinal MyOriginalRow = reverseperm_[LocalRow];
312 A_->getLocalRowCopy(MyOriginalRow,Indices,Values,NumEntries);
314 for (
size_t i = 0 ; i < NumEntries ; ++i) {
315 Indices[i] = perm_[Indices[i]];
320 template<
class MatrixType>
322 Teuchos::ArrayView<const GlobalOrdinal> &indices,
323 Teuchos::ArrayView<const Scalar> &values)
const 325 throw std::runtime_error(
"Ifpack2::ReorderFilter: does not support getGlobalRowView.");
329 template<
class MatrixType>
331 Teuchos::ArrayView<const LocalOrdinal> &indices,
332 Teuchos::ArrayView<const Scalar> &values)
const 334 throw std::runtime_error(
"Ifpack2::ReorderFilter: does not support getLocalRowView.");
338 template<
class MatrixType>
342 return A_->getLocalDiagCopy(diag);
346 template<
class MatrixType>
349 throw std::runtime_error(
"Ifpack2::ReorderFilter does not support leftScale.");
353 template<
class MatrixType>
356 throw std::runtime_error(
"Ifpack2::ReorderFilter does not support rightScale.");
360 template<
class MatrixType>
362 Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &Y,
363 Teuchos::ETransp mode,
367 this->
template applyTempl<Scalar,Scalar>(X, Y, mode, alpha, beta);
372 template<
class MatrixType>
373 template<
class DomainScalar,
class RangeScalar>
375 Tpetra::MultiVector<RangeScalar,LocalOrdinal,GlobalOrdinal,Node> &Y,
376 Teuchos::ETransp mode,
378 RangeScalar beta)
const 382 TEUCHOS_TEST_FOR_EXCEPTION(X.getNumVectors() != Y.getNumVectors(), std::runtime_error,
383 "Ifpack2::ReorderFilter::apply ERROR: X.getNumVectors() != Y.getNumVectors().");
385 RangeScalar zero = Teuchos::ScalarTraits<RangeScalar>::zero();
386 Teuchos::ArrayRCP<Teuchos::ArrayRCP<const DomainScalar> > x_ptr = X.get2dView();
387 Teuchos::ArrayRCP<Teuchos::ArrayRCP<RangeScalar> > y_ptr = Y.get2dViewNonConst();
390 size_t NumVectors = Y.getNumVectors();
392 for (
size_t i = 0 ; i < A_->getNodeNumRows() ; ++i) {
396 if (mode==Teuchos::NO_TRANS){
397 for (
size_t j = 0 ; j < Nnz ; ++j)
398 for (
size_t k = 0 ; k < NumVectors ; ++k)
399 y_ptr[k][i] += (RangeScalar)Values_[j] * (RangeScalar)x_ptr[k][Indices_[j]];
401 else if (mode==Teuchos::TRANS){
402 for (
size_t j = 0 ; j < Nnz ; ++j)
403 for (
size_t k = 0 ; k < NumVectors ; ++k)
404 y_ptr[k][Indices_[j]] += (RangeScalar)Values_[j] * (RangeScalar)x_ptr[k][i];
407 for (
size_t j = 0 ; j < Nnz ; ++j)
408 for (
size_t k = 0 ; k < NumVectors ; ++k)
409 y_ptr[k][Indices_[j]] += Teuchos::ScalarTraits<RangeScalar>::conjugate((RangeScalar)Values_[j]) * (RangeScalar)x_ptr[k][i];
416 template<
class MatrixType>
423 template<
class MatrixType>
430 template<
class MatrixType>
433 throw std::runtime_error(
"Ifpack2::ReorderFilter does not implement getFrobeniusNorm.");
438 template<
class MatrixType>
440 Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &reorderedY)
const 442 this->
template permuteOriginalToReorderedTempl<Scalar,Scalar>(originalX, reorderedY);
447 template<
class MatrixType>
448 template<
class DomainScalar,
class RangeScalar>
450 Tpetra::MultiVector<RangeScalar,LocalOrdinal,GlobalOrdinal,Node> &reorderedY)
const 452 TEUCHOS_TEST_FOR_EXCEPTION(originalX.getNumVectors() != reorderedY.getNumVectors(), std::runtime_error,
453 "Ifpack2::ReorderFilter::permuteOriginalToReordered ERROR: X.getNumVectors() != Y.getNumVectors().");
455 Teuchos::ArrayRCP<Teuchos::ArrayRCP<const DomainScalar> > x_ptr = originalX.get2dView();
456 Teuchos::ArrayRCP<Teuchos::ArrayRCP<RangeScalar> > y_ptr = reorderedY.get2dViewNonConst();
458 for(
size_t k=0; k < originalX.getNumVectors(); k++)
459 for(LocalOrdinal i=0; (size_t)i< originalX.getLocalLength(); i++)
460 y_ptr[k][perm_[i]] = (RangeScalar)x_ptr[k][i];
465 template<
class MatrixType>
467 Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &originalY)
const 469 this->
template permuteReorderedToOriginalTempl<Scalar,Scalar>(reorderedX, originalY);
474 template<
class MatrixType>
475 template<
class DomainScalar,
class RangeScalar>
477 Tpetra::MultiVector<RangeScalar,LocalOrdinal,GlobalOrdinal,Node> &originalY)
const 479 TEUCHOS_TEST_FOR_EXCEPTION(reorderedX.getNumVectors() != originalY.getNumVectors(), std::runtime_error,
480 "Ifpack2::ReorderFilter::permuteReorderedToOriginal ERROR: X.getNumVectors() != Y.getNumVectors().");
482 Teuchos::ArrayRCP<Teuchos::ArrayRCP<const DomainScalar> > x_ptr = reorderedX.get2dView();
483 Teuchos::ArrayRCP<Teuchos::ArrayRCP<RangeScalar> > y_ptr = originalY.get2dViewNonConst();
485 for(
size_t k=0; k < reorderedX.getNumVectors(); k++)
486 for(LocalOrdinal i=0; (size_t)i< reorderedX.getLocalLength(); i++)
487 y_ptr[k][reverseperm_[i]] = (RangeScalar)x_ptr[k][i];
491 template<
class MatrixType>
493 Teuchos::ArrayRCP<const GlobalOrdinal> &indices,
494 Teuchos::ArrayRCP<const Scalar> &values)
const 496 throw std::runtime_error(
"Ifpack2::ReorderFilter does not implement getGlobalRowView.");
500 template<
class MatrixType>
502 Teuchos::ArrayRCP<const LocalOrdinal> &indices,
503 Teuchos::ArrayRCP<const Scalar> &values)
const 505 throw std::runtime_error(
"Ifpack2::ReorderFilter does not implement getLocalRowView.");
virtual bool isLowerTriangular() const
Indicates whether this matrix is lower triangular.
Definition: Ifpack2_ReorderFilter_def.hpp:258
virtual bool isUpperTriangular() const
Indicates whether this matrix is upper triangular.
Definition: Ifpack2_ReorderFilter_def.hpp:265
virtual global_size_t getGlobalNumDiags() const
Returns the number of global diagonal entries, based on global row/column index comparisons.
Definition: Ifpack2_ReorderFilter_def.hpp:223
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_ReorderFilter_def.hpp:339
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_ReorderFilter_def.hpp:141
virtual void permuteReorderedToOriginal(const Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &reorderedX, Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &originalY) const
Permute multivector: reordered-to-original.
Definition: Ifpack2_ReorderFilter_def.hpp:466
virtual bool supportsRowViews() const
Returns true if RowViews are supported.
Definition: Ifpack2_ReorderFilter_def.hpp:424
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_ReorderFilter_def.hpp:303
virtual size_t getGlobalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on all nodes.
Definition: Ifpack2_ReorderFilter_def.hpp:237
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_ReorderFilter_def.hpp:361
virtual void rightScale(const Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
Scales the RowMatrix on the right with the Vector x.
Definition: Ifpack2_ReorderFilter_def.hpp:354
virtual size_t getNodeMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on this node.
Definition: Ifpack2_ReorderFilter_def.hpp:244
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_ReorderFilter_def.hpp:293
virtual global_size_t getGlobalNumRows() const
Returns the number of global rows in this matrix.
Definition: Ifpack2_ReorderFilter_def.hpp:158
virtual Teuchos::RCP< Node > getNode() const
Returns the underlying node.
Definition: Ifpack2_ReorderFilter_def.hpp:101
virtual Teuchos::ScalarTraits< Scalar >::magnitudeType getFrobeniusNorm() const
Returns the Frobenius norm of the matrix.
Definition: Ifpack2_ReorderFilter_def.hpp:431
virtual size_t getNodeNumEntries() const
Returns the local number of entries in this matrix.
Definition: Ifpack2_ReorderFilter_def.hpp:201
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_ReorderFilter_def.hpp:111
void permuteReorderedToOriginalTempl(const Tpetra::MultiVector< DomainScalar, LocalOrdinal, GlobalOrdinal, Node > &reorderedX, Tpetra::MultiVector< RangeScalar, LocalOrdinal, GlobalOrdinal, Node > &originalY) const
Permute multivector: reordered-to-original.
Definition: Ifpack2_ReorderFilter_def.hpp:476
virtual size_t getNodeNumRows() const
Returns the number of rows owned on the calling node.
Definition: Ifpack2_ReorderFilter_def.hpp:172
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_ReorderFilter_def.hpp:180
virtual bool isGloballyIndexed() const
If matrix indices are in the global range, this function returns true. Otherwise, this function retur...
Definition: Ifpack2_ReorderFilter_def.hpp:279
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_ReorderFilter_def.hpp:121
virtual size_t getNodeNumDiags() const
Returns the number of local diagonal entries, based on global row/column index comparisons.
Definition: Ifpack2_ReorderFilter_def.hpp:230
void permuteOriginalToReorderedTempl(const Tpetra::MultiVector< DomainScalar, LocalOrdinal, GlobalOrdinal, Node > &originalX, Tpetra::MultiVector< RangeScalar, LocalOrdinal, GlobalOrdinal, Node > &reorderedY) const
Permute multivector: original-to-reordered.
Definition: Ifpack2_ReorderFilter_def.hpp:449
virtual size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const
Returns the current number of entries on this node in the specified global row.
Definition: Ifpack2_ReorderFilter_def.hpp:208
virtual bool hasColMap() const
Indicates whether this matrix has a well-defined column map.
Definition: Ifpack2_ReorderFilter_def.hpp:251
virtual void leftScale(const Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
Scales the RowMatrix on the left with the Vector x.
Definition: Ifpack2_ReorderFilter_def.hpp:347
virtual global_size_t getGlobalNumCols() const
Returns the number of global columns in this matrix.
Definition: Ifpack2_ReorderFilter_def.hpp:165
virtual const Teuchos::RCP< const Teuchos::Comm< int > > & getComm() const
Returns the communicator.
Definition: Ifpack2_ReorderFilter_def.hpp:94
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_ReorderFilter_def.hpp:330
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_ReorderFilter_def.hpp:321
virtual bool hasTransposeApply() const
Indicates whether this operator supports applying the adjoint operator.
Definition: Ifpack2_ReorderFilter_def.hpp:417
virtual size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const
Returns the current number of entries on this node in the specified local row.
Definition: Ifpack2_ReorderFilter_def.hpp:215
virtual GlobalOrdinal getIndexBase() const
Returns the index base for global indices for this matrix.
Definition: Ifpack2_ReorderFilter_def.hpp:187
virtual global_size_t getGlobalNumEntries() const
Returns the global number of entries in this matrix.
Definition: Ifpack2_ReorderFilter_def.hpp:194
virtual bool isFillComplete() const
Returns true if fillComplete() has been called.
Definition: Ifpack2_ReorderFilter_def.hpp:286
virtual Teuchos::RCP< const Tpetra::RowGraph< LocalOrdinal, GlobalOrdinal, Node > > getGraph() const
Returns the RowGraph associated with this matrix.
Definition: Ifpack2_ReorderFilter_def.hpp:151
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_ReorderFilter_def.hpp:374
Ifpack2::Container: a pure virtual class for creating and solving local linear problems.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:67
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_ReorderFilter_def.hpp:131
virtual ~ReorderFilter()
Constructor.
Definition: Ifpack2_ReorderFilter_def.hpp:90
virtual bool isLocallyIndexed() const
If matrix indices are in the local range, this function returns true. Otherwise, this function return...
Definition: Ifpack2_ReorderFilter_def.hpp:272
virtual void permuteOriginalToReordered(const Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &originalX, Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &reorderedY) const
Permute multivector: original-to-reordered.
Definition: Ifpack2_ReorderFilter_def.hpp:439