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"
56 template<
class MatrixType>
63 reverseperm_ (reverseperm)
66 A_.
is_null (), std::invalid_argument,
67 "Ifpack2::ReorderFilter: The input matrix is null.");
71 A_->getComm()->getSize() != 1, std::invalid_argument,
72 "Ifpack2::ReorderFilter: This class may only be used if the input matrix's "
73 "communicator has one process. This class is an implementation detail of "
74 "Ifpack2::AdditiveSchwarz, and it is not meant to be used otherwise.");
77 A_->getNodeNumRows () != A_->getGlobalNumRows (),
78 std::invalid_argument,
79 "Ifpack2::ReorderFilter: The input matrix is not square.");
82 Indices_.
resize (A_->getNodeMaxNumRowEntries ());
83 Values_.
resize (A_->getNodeMaxNumRowEntries ());
87 template<
class MatrixType>
91 template<
class MatrixType>
100 template<
class MatrixType>
105 A_.is_null (), std::runtime_error,
"Ifpack2::ReorderFilter::"
106 "getRowMap: The matrix A is null, so there is no row Map.");
108 return A_->getRowMap ();
112 template<
class MatrixType>
117 A_.is_null (), std::runtime_error,
"Ifpack2::ReorderFilter::"
118 "getColMap: The matrix A is null, so there is no column Map.");
120 return A_->getColMap();
124 template<
class MatrixType>
129 A_.is_null (), std::runtime_error,
"Ifpack2::ReorderFilter::"
130 "getDomainMap: The matrix A is null, so there is no domain Map.");
132 return A_->getDomainMap();
136 template<
class MatrixType>
141 A_.is_null (), std::runtime_error,
"Ifpack2::ReorderFilter::"
142 "getRangeMap: The matrix A is null, so there is no range Map.");
144 return A_->getRangeMap();
148 template<
class MatrixType>
149 Teuchos::RCP<
const Tpetra::RowGraph<
typename MatrixType::local_ordinal_type,
150 typename MatrixType::global_ordinal_type,
151 typename MatrixType::node_type> >
154 throw std::runtime_error(
"Ifpack2::ReorderFilter: does not support getGraph.");
158 template<
class MatrixType>
161 return A_->getGlobalNumRows();
165 template<
class MatrixType>
168 return A_->getGlobalNumCols();
172 template<
class MatrixType>
175 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>
211 if (A_.is_null () || A_->getRowMap ().is_null ()) {
215 const local_ordinal_type lclRow =
216 A_->getRowMap ()->getLocalElement (globalRow);
219 return static_cast<size_t> (0);
221 const local_ordinal_type origLclRow = reverseperm_[lclRow];
222 return A_->getNumEntriesInLocalRow (origLclRow);
228 template<
class MatrixType>
234 if (A_->getRowMap ()->isNodeLocalElement (localRow)) {
236 const local_ordinal_type localReorderedRow = reverseperm_[localRow];
237 return A_->getNumEntriesInLocalRow (localReorderedRow);
240 return static_cast<size_t> (0);
245 template<
class MatrixType>
248 return A_->getGlobalMaxNumRowEntries();
252 template<
class MatrixType>
255 return A_->getNodeMaxNumRowEntries();
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>
292 size_t& numEntries)
const
296 using Teuchos::av_reinterpret_cast;
297 typedef local_ordinal_type LO;
298 typedef global_ordinal_type GO;
301 const map_type& rowMap = * (A_->getRowMap ());
302 const local_ordinal_type localRow = rowMap.getLocalElement (globalRow);
304 localRow == OTLO::invalid (), std::invalid_argument,
"Ifpack2::Reorder"
305 "Filter::getGlobalRowCopy: The given global row index " << globalRow
306 <<
" is not owned by the calling process with rank "
307 << rowMap.getComm ()->getRank () <<
".");
309 if (
sizeof (GO) ==
sizeof (LO)) {
311 ArrayView<LO> localInd = av_reinterpret_cast<LO> (globalInd);
312 this->getLocalRowCopy (localRow, localInd, val, numEntries);
315 for (
size_t k = 0; k < numEntries; ++k) {
316 globalInd[k] = rowMap.getGlobalElement (localInd[k]);
322 numEntries = this->getNumEntriesInLocalRow (localRow);
323 Array<LO> localInd (numEntries);
324 this->getLocalRowCopy (localRow, localInd, val, numEntries);
327 for (
size_t k = 0; k < numEntries; ++k) {
328 globalInd[k] = rowMap.getGlobalElement (localInd[k]);
334 template<
class MatrixType>
339 size_t &NumEntries)
const
342 ! A_->getRowMap ()->isNodeLocalElement (LocalRow),
343 std::invalid_argument,
344 "Ifpack2::ReorderFilter::getLocalRowCopy: The given local row index "
345 << LocalRow <<
" is not a valid local row index on the calling process "
346 "with rank " << A_->getRowMap ()->getComm ()->getRank () <<
".");
350 const local_ordinal_type origLclRow = reverseperm_[LocalRow];
351 const size_t numEntries = A_->getNumEntriesInLocalRow (origLclRow);
354 static_cast<size_t> (Indices.
size ()) < numEntries ||
355 static_cast<size_t> (Values.
size ()) < numEntries,
356 std::invalid_argument,
357 "Ifpack2::ReorderFilter::getLocalRowCopy: The given array views are not "
358 "long enough to store all the data in the given row " << LocalRow
359 <<
". Indices.size() = " << Indices.
size () <<
", Values.size() = "
360 << Values.
size () <<
", but the (original) row has " << numEntries
363 A_->getLocalRowCopy (origLclRow, Indices, Values, NumEntries);
368 for (
size_t i = 0; i < NumEntries; ++i) {
369 Indices[i] = perm_[Indices[i]];
374 template<
class MatrixType>
380 throw std::runtime_error(
"Ifpack2::ReorderFilter: does not support getGlobalRowView.");
384 template<
class MatrixType>
390 throw std::runtime_error(
"Ifpack2::ReorderFilter: does not support getLocalRowView.");
394 template<
class MatrixType>
396 getLocalDiagCopy (Tpetra::Vector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> &diag)
const
399 return A_->getLocalDiagCopy(diag);
403 template<
class MatrixType>
406 throw std::runtime_error(
"Ifpack2::ReorderFilter does not support leftScale.");
410 template<
class MatrixType>
413 throw std::runtime_error(
"Ifpack2::ReorderFilter does not support rightScale.");
417 template<
class MatrixType>
419 apply (
const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> &X,
420 Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> &Y,
423 scalar_type beta)
const
428 alpha != STS::one () || beta != STS::zero (), std::logic_error,
429 "Ifpack2::ReorderFilter::apply is only implemented for alpha = 1 and "
430 "beta = 0. You set alpha = " << alpha <<
" and beta = " << beta <<
".");
435 X.getNumVectors() != Y.getNumVectors(), std::runtime_error,
436 "Ifpack2::ReorderFilter::apply: X.getNumVectors() != Y.getNumVectors().");
438 const scalar_type zero = STS::zero ();
443 const size_t NumVectors = Y.getNumVectors ();
445 for (
size_t i = 0; i < A_->getNodeNumRows (); ++i) {
448 getLocalRowCopy (i, Indices_ (), Values_ (), Nnz);
450 for (
size_t j = 0; j < Nnz; ++j) {
451 for (
size_t k = 0; k < NumVectors; ++k) {
452 y_ptr[k][i] += Values_[j] * x_ptr[k][Indices_[j]];
457 for (
size_t j = 0; j < Nnz; ++j) {
458 for (
size_t k = 0; k < NumVectors; ++k) {
459 y_ptr[k][Indices_[j]] += Values_[j] * x_ptr[k][i];
464 for (
size_t j = 0; j < Nnz; ++j) {
465 for (
size_t k = 0; k < NumVectors; ++k) {
466 y_ptr[k][Indices_[j]] += STS::conjugate(Values_[j]) * x_ptr[k][i];
474 template<
class MatrixType>
481 template<
class MatrixType>
488 template<
class MatrixType>
492 return A_->getFrobeniusNorm ();
496 template<
class MatrixType>
499 Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> &reorderedY)
const
501 this->
template permuteOriginalToReorderedTempl<scalar_type,scalar_type>(originalX, reorderedY);
505 template<
class MatrixType>
506 template<
class DomainScalar,
class RangeScalar>
508 Tpetra::MultiVector<RangeScalar,local_ordinal_type,global_ordinal_type,node_type> &reorderedY)
const
511 "Ifpack2::ReorderFilter::permuteOriginalToReordered ERROR: X.getNumVectors() != Y.getNumVectors().");
516 for(
size_t k=0; k < originalX.getNumVectors(); k++)
517 for(local_ordinal_type i=0; (size_t)i< originalX.getLocalLength(); i++)
518 y_ptr[k][perm_[i]] = (RangeScalar)x_ptr[k][i];
522 template<
class MatrixType>
524 Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> &originalY)
const
526 this->
template permuteReorderedToOriginalTempl<scalar_type,scalar_type>(reorderedX, originalY);
530 template<
class MatrixType>
531 template<
class DomainScalar,
class RangeScalar>
534 Tpetra::MultiVector<RangeScalar,local_ordinal_type,global_ordinal_type,node_type> &originalY)
const
537 reorderedX.getNumVectors() != originalY.getNumVectors(),
539 "Ifpack2::ReorderFilter::permuteReorderedToOriginal: "
540 "X.getNumVectors() != Y.getNumVectors().");
542 #ifdef HAVE_IFPACK2_DEBUG
545 typedef typename STS::magnitudeType magnitude_type;
548 reorderedX.norm2 (norms ());
551 j < reorderedX.getNumVectors (); ++j) {
552 if (STM::isnaninf (norms[j])) {
558 ! good, std::runtime_error,
"Ifpack2::ReorderFilter::"
559 "permuteReorderedToOriginalTempl: The 2-norm of the input reorderedX is "
562 #endif // HAVE_IFPACK2_DEBUG
567 for (
size_t k = 0; k < reorderedX.getNumVectors (); ++k) {
568 for (local_ordinal_type i = 0; (size_t)i < reorderedX.getLocalLength (); ++i) {
569 y_ptr[k][reverseperm_[i]] = (RangeScalar) x_ptr[k][i];
573 #ifdef HAVE_IFPACK2_DEBUG
576 typedef typename STS::magnitudeType magnitude_type;
579 originalY.norm2 (norms ());
582 j < originalY.getNumVectors (); ++j) {
583 if (STM::isnaninf (norms[j])) {
589 ! good, std::runtime_error,
"Ifpack2::ReorderFilter::"
590 "permuteReorderedToOriginalTempl: The 2-norm of the output originalY is "
593 #endif // HAVE_IFPACK2_DEBUG
598 #define IFPACK2_REORDERFILTER_INSTANT(S,LO,GO,N) \
599 template class Ifpack2::ReorderFilter< Tpetra::RowMatrix<S, LO, GO, N> >;
virtual void getGlobalRowView(global_ordinal_type GlobalRow, Teuchos::ArrayView< const global_ordinal_type > &indices, Teuchos::ArrayView< const scalar_type > &values) const
Extract a const, non-persisting view of global indices in a specified row of the matrix.
Definition: Ifpack2_ReorderFilter_def.hpp:376
Wraps a Tpetra::RowMatrix in a filter that reorders local rows and columns.
Definition: Ifpack2_ReorderFilter_decl.hpp:69
virtual mag_type getFrobeniusNorm() const
Returns the Frobenius norm of the matrix.
Definition: Ifpack2_ReorderFilter_def.hpp:489
virtual Teuchos::RCP< const map_type > getRowMap() const
Returns the Map that describes the row distribution in this matrix.
Definition: Ifpack2_ReorderFilter_def.hpp:102
virtual bool supportsRowViews() const
Returns true if RowViews are supported.
Definition: Ifpack2_ReorderFilter_def.hpp:482
virtual void getGlobalRowCopy(global_ordinal_type GlobalRow, const Teuchos::ArrayView< global_ordinal_type > &Indices, const Teuchos::ArrayView< scalar_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_ReorderFilter_def.hpp:289
virtual size_t getGlobalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on all nodes.
Definition: Ifpack2_ReorderFilter_def.hpp:246
virtual Teuchos::RCP< const map_type > getDomainMap() const
Returns the Map that describes the domain distribution in this matrix.
Definition: Ifpack2_ReorderFilter_def.hpp:126
virtual size_t getNodeMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on this node.
Definition: Ifpack2_ReorderFilter_def.hpp:253
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
virtual global_size_t getGlobalNumRows() const
Returns the number of global rows in this matrix.
Definition: Ifpack2_ReorderFilter_def.hpp:159
virtual Teuchos::RCP< const map_type > getColMap() const
Returns the Map that describes the column distribution in this matrix.
Definition: Ifpack2_ReorderFilter_def.hpp:114
ReorderFilter(const Teuchos::RCP< const row_matrix_type > &A, const Teuchos::ArrayRCP< local_ordinal_type > &perm, const Teuchos::ArrayRCP< local_ordinal_type > &reverseperm)
Constructor.
Definition: Ifpack2_ReorderFilter_def.hpp:58
virtual Teuchos::RCP< const map_type > getRangeMap() const
Returns the Map that describes the range distribution in this matrix.
Definition: Ifpack2_ReorderFilter_def.hpp:138
virtual size_t getNodeNumEntries() const
Returns the local number of entries in this matrix.
Definition: Ifpack2_ReorderFilter_def.hpp:201
virtual void apply(const Tpetra::MultiVector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > &X, Tpetra::MultiVector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, scalar_type alpha=Teuchos::ScalarTraits< scalar_type >::one(), scalar_type beta=Teuchos::ScalarTraits< scalar_type >::zero()) const
, where Op(A) is either A, , or .
Definition: Ifpack2_ReorderFilter_def.hpp:419
virtual size_t getNodeNumRows() const
Returns the number of rows owned on the calling node.
Definition: Ifpack2_ReorderFilter_def.hpp:173
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:274
virtual Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
The matrix's communicator.
Definition: Ifpack2_ReorderFilter_def.hpp:92
virtual void getLocalDiagCopy(Tpetra::Vector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > &diag) const
Get a copy of the diagonal entries owned by this node, with local row indices.
Definition: Ifpack2_ReorderFilter_def.hpp:396
void resize(size_type new_size, const value_type &x=value_type())
virtual size_t getNumEntriesInLocalRow(local_ordinal_type localRow) const
The current number of entries in this matrix, stored on the calling process, in the row whose local i...
Definition: Ifpack2_ReorderFilter_def.hpp:230
virtual bool hasColMap() const
Indicates whether this matrix has a well-defined column map.
Definition: Ifpack2_ReorderFilter_def.hpp:260
virtual size_t getNumEntriesInGlobalRow(global_ordinal_type globalRow) const
The current number of entries in this matrix, stored on the calling process, in the row whose global ...
Definition: Ifpack2_ReorderFilter_def.hpp:209
virtual void getLocalRowCopy(local_ordinal_type DropRow, const Teuchos::ArrayView< local_ordinal_type > &Indices, const Teuchos::ArrayView< scalar_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_ReorderFilter_def.hpp:336
virtual global_size_t getGlobalNumCols() const
Returns the number of global columns in this matrix.
Definition: Ifpack2_ReorderFilter_def.hpp:166
virtual bool hasTransposeApply() const
Whether apply() can apply the transpose or conjugate transpose.
Definition: Ifpack2_ReorderFilter_def.hpp:475
virtual global_ordinal_type getIndexBase() const
Returns the index base for global indices for this matrix.
Definition: Ifpack2_ReorderFilter_def.hpp:187
virtual void getLocalRowView(local_ordinal_type LocalRow, Teuchos::ArrayView< const local_ordinal_type > &indices, Teuchos::ArrayView< const scalar_type > &values) const
Extract a const, non-persisting view of local indices in a specified row of the matrix.
Definition: Ifpack2_ReorderFilter_def.hpp:386
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:281
virtual void permuteReorderedToOriginal(const Tpetra::MultiVector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > &reorderedX, Tpetra::MultiVector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > &originalY) const
Permute multivector: reordered-to-original.
Definition: Ifpack2_ReorderFilter_def.hpp:523
virtual Teuchos::RCP< const Tpetra::RowGraph< local_ordinal_type, global_ordinal_type, node_type > > getGraph() const
Returns the RowGraph associated with this matrix.
Definition: Ifpack2_ReorderFilter_def.hpp:152
virtual void leftScale(const Tpetra::Vector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > &x)
Scales the RowMatrix on the left with the Vector x.
Definition: Ifpack2_ReorderFilter_def.hpp:404
virtual void rightScale(const Tpetra::Vector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > &x)
Scales the RowMatrix on the right with the Vector x.
Definition: Ifpack2_ReorderFilter_def.hpp:411
virtual void permuteOriginalToReordered(const Tpetra::MultiVector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > &originalX, Tpetra::MultiVector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > &reorderedY) const
Permute multivector: original-to-reordered.
Definition: Ifpack2_ReorderFilter_def.hpp:498
virtual ~ReorderFilter()
Destructor.
Definition: Ifpack2_ReorderFilter_def.hpp:88
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:267