Ifpack2 Templated Preconditioning Package  Version 1.0
Ifpack2_LocalFilter_decl.hpp
1 /*@HEADER
2 // ***********************************************************************
3 //
4 // Ifpack2: Tempated Object-Oriented Algebraic Preconditioner Package
5 // Copyright (2009) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 //@HEADER
41 */
42 
43 #ifndef IFPACK2_LOCALFILTER_DECL_HPP
44 #define IFPACK2_LOCALFILTER_DECL_HPP
45 
46 #include "Ifpack2_ConfigDefs.hpp"
47 #include "Tpetra_RowMatrix.hpp"
48 #include <type_traits>
49 #include <vector>
50 
51 
52 namespace Ifpack2 {
53 
159 template<class MatrixType>
160 class LocalFilter :
161  virtual public Tpetra::RowMatrix<typename MatrixType::scalar_type,
162  typename MatrixType::local_ordinal_type,
163  typename MatrixType::global_ordinal_type,
164  typename MatrixType::node_type>,
165  virtual public Teuchos::Describable
166 {
167 private:
168  // Tpetra needs C++11 now because Kokkos needs C++11 now.
169  // Thus, Ifpack2 needs C++11.
170  static_assert (std::is_same<
171  MatrixType,
172  Tpetra::RowMatrix<
173  typename MatrixType::scalar_type,
174  typename MatrixType::local_ordinal_type,
175  typename MatrixType::global_ordinal_type,
176  typename MatrixType::node_type> >::value,
177  "Ifpack2::LocalFilter: MatrixType must be a Tpetra::RowMatrix specialization.");
178 
179 public:
181 
182 
184  typedef typename MatrixType::scalar_type scalar_type;
185 
187  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
188 
190  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
191 
193  typedef typename MatrixType::node_type node_type;
194 
196  typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
197 
199  typedef Tpetra::RowMatrix<scalar_type,
202  node_type> row_matrix_type;
203 
205  typedef Tpetra::Map<local_ordinal_type,
207  node_type> map_type;
208 
209  typedef typename row_matrix_type::mag_type mag_type;
210 
212 
214 
216  virtual std::string description () const;
217 
219  virtual void
220  describe (Teuchos::FancyOStream &out,
221  const Teuchos::EVerbosityLevel verbLevel =
222  Teuchos::Describable::verbLevel_default) const;
223 
225 
227 
233  explicit LocalFilter (const Teuchos::RCP<const row_matrix_type>& A);
234 
236  virtual ~LocalFilter();
237 
239 
241 
243  virtual Teuchos::RCP<const Teuchos::Comm<int> > getComm() const;
244 
246  virtual Teuchos::RCP<node_type> getNode() const;
247 
249  virtual Teuchos::RCP<const map_type> getRowMap() const;
250 
252  virtual Teuchos::RCP<const map_type> getColMap() const;
253 
255  virtual Teuchos::RCP<const map_type> getDomainMap() const;
256 
258  virtual Teuchos::RCP<const map_type> getRangeMap() const;
259 
261  virtual Teuchos::RCP<const Tpetra::RowGraph<local_ordinal_type,global_ordinal_type,node_type> >
262  getGraph () const;
263 
265  virtual global_size_t getGlobalNumRows() const;
266 
268  virtual global_size_t getGlobalNumCols() const;
269 
271  virtual size_t getNodeNumRows() const;
272 
274  virtual size_t getNodeNumCols() const;
275 
277  virtual global_ordinal_type getIndexBase() const;
278 
280  virtual global_size_t getGlobalNumEntries() const;
281 
283  virtual size_t getNodeNumEntries() const;
284 
290  virtual size_t getNumEntriesInGlobalRow (global_ordinal_type globalRow) const;
291 
297  virtual size_t getNumEntriesInLocalRow (local_ordinal_type localRow) const;
298 
300  virtual global_size_t getGlobalNumDiags() const;
301 
303  virtual size_t getNodeNumDiags() const;
304 
306  virtual size_t getGlobalMaxNumRowEntries() const;
307 
309  virtual size_t getNodeMaxNumRowEntries() const;
310 
312  virtual bool hasColMap() const;
313 
315  virtual bool isLowerTriangular() const;
316 
318  virtual bool isUpperTriangular() const;
319 
321  virtual bool isLocallyIndexed() const;
322 
324  virtual bool isGloballyIndexed() const;
325 
327  virtual bool isFillComplete() const;
328 
330  virtual bool supportsRowViews() const;
331 
333 
335 
349  virtual void
350  getGlobalRowCopy (global_ordinal_type GlobalRow,
351  const Teuchos::ArrayView<global_ordinal_type> &Indices,
352  const Teuchos::ArrayView<scalar_type> &Values,
353  size_t &NumEntries) const;
354 
368  virtual void
369  getLocalRowCopy (local_ordinal_type LocalRow,
370  const Teuchos::ArrayView<local_ordinal_type> &Indices,
371  const Teuchos::ArrayView<scalar_type> &Values,
372  size_t &NumEntries) const ;
373 
375 
385  virtual void
386  getGlobalRowView (global_ordinal_type GlobalRow,
387  Teuchos::ArrayView<const global_ordinal_type> &indices,
388  Teuchos::ArrayView<const scalar_type> &values) const;
389 
391 
401  virtual void
402  getLocalRowView (local_ordinal_type LocalRow,
403  Teuchos::ArrayView<const local_ordinal_type> &indices,
404  Teuchos::ArrayView<const scalar_type> &values) const;
405 
412  virtual void
413  getLocalDiagCopy (Tpetra::Vector<scalar_type, local_ordinal_type, global_ordinal_type, node_type> &diag) const;
414 
416 
418 
428  virtual void leftScale(const Tpetra::Vector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& x);
429 
439  virtual void rightScale(const Tpetra::Vector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& x);
440 
449  virtual mag_type getFrobeniusNorm() const;
450 
457  virtual void
458  apply (const Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type> &X,
459  Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type> &Y,
460  Teuchos::ETransp mode = Teuchos::NO_TRANS,
461  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
462  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
463 
465  virtual bool hasTransposeApply() const;
466 
468  virtual Teuchos::RCP<const row_matrix_type> getUnderlyingMatrix() const;
469 
471 private:
473  typedef Tpetra::RowGraph<local_ordinal_type,
475  node_type> row_graph_type;
477  void
478  applyNonAliased (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> &X,
479  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> &Y,
480  Teuchos::ETransp mode,
481  scalar_type alpha,
482  scalar_type beta) const;
483 
496  static bool
497  mapPairIsFitted (const map_type& map1, const map_type& map2);
498 
502  // If both pairs of Maps of the original matrix A are fitted on this
503  // process, then this process can use a fast "view" implementation.
504  static bool
505  mapPairsAreFitted (const row_matrix_type& A);
506 
508  Teuchos::RCP<const row_matrix_type> A_;
509 
511  Teuchos::RCP<const map_type> localRowMap_;
512 
514  Teuchos::RCP<const map_type> localDomainMap_;
515 
517  Teuchos::RCP<const map_type> localRangeMap_;
518 
520  size_t NumNonzeros_;
522  size_t MaxNumEntries_;
524  size_t MaxNumEntriesA_;
526  std::vector<size_t> NumEntries_;
527 
529  mutable Teuchos::Array<local_ordinal_type> localIndices_;
530 
532  mutable Teuchos::Array<scalar_type> Values_;
533 };// class LocalFilter
534 
535 }// namespace Ifpack2
536 
537 #endif /* IFPACK2_LOCALFILTER_DECL_HPP */
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_LocalFilter_def.hpp:723
virtual size_t getNodeNumDiags() const
The number of local diagonal entries, based on global row/column index comparisons.
Definition: Ifpack2_LocalFilter_def.hpp:465
Tpetra::RowMatrix< scalar_type, local_ordinal_type, global_ordinal_type, node_type > row_matrix_type
Type of the Tpetra::RowMatrix specialization that this class uses.
Definition: Ifpack2_LocalFilter_decl.hpp:202
virtual Teuchos::RCP< const map_type > getRowMap() const
Returns the Map that describes the row distribution in this matrix.
Definition: Ifpack2_LocalFilter_def.hpp:316
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object to the given output stream.
Definition: Ifpack2_LocalFilter_def.hpp:975
virtual Teuchos::RCP< node_type > getNode() const
Returns the underlying Node object.
Definition: Ifpack2_LocalFilter_def.hpp:306
virtual size_t getNodeNumRows() const
The number of rows owned on the calling process.
Definition: Ifpack2_LocalFilter_def.hpp:380
virtual Teuchos::RCP< const map_type > getDomainMap() const
Returns the Map that describes the domain distribution in this matrix.
Definition: Ifpack2_LocalFilter_def.hpp:336
virtual bool isFillComplete() const
Returns true if fillComplete() has been called.
Definition: Ifpack2_LocalFilter_def.hpp:521
virtual Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Returns the communicator.
Definition: Ifpack2_LocalFilter_def.hpp:298
virtual size_t getNodeMaxNumRowEntries() const
The maximum number of entries across all rows/columns on this process.
Definition: Ifpack2_LocalFilter_def.hpp:479
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
Compute Y = beta*Y + alpha*A_local*X.
Definition: Ifpack2_LocalFilter_def.hpp:733
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition: Ifpack2_LocalFilter_decl.hpp:190
virtual bool hasTransposeApply() const
Whether this operator supports applying the transpose or conjugate transpose.
Definition: Ifpack2_LocalFilter_def.hpp:908
virtual bool isLocallyIndexed() const
Whether the underlying sparse matrix is locally (opposite of globally) indexed.
Definition: Ifpack2_LocalFilter_def.hpp:507
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_LocalFilter_def.hpp:674
virtual void getLocalDiagCopy(Tpetra::Vector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > &diag) const
Get the diagonal entries of the (locally filtered) matrix.
Definition: Ifpack2_LocalFilter_def.hpp:698
Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type > map_type
Type of the Tpetra::Map specialization that this class uses.
Definition: Ifpack2_LocalFilter_decl.hpp:207
virtual mag_type getFrobeniusNorm() const
The Frobenius norm of the (locally filtered) matrix.
Definition: Ifpack2_LocalFilter_def.hpp:924
virtual Teuchos::RCP< const Tpetra::RowGraph< local_ordinal_type, global_ordinal_type, node_type > > getGraph() const
The (locally filtered) matrix&#39;s graph.
Definition: Ifpack2_LocalFilter_def.hpp:356
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition: Ifpack2_LocalFilter_decl.hpp:187
virtual bool supportsRowViews() const
Returns true if RowViews are supported.
Definition: Ifpack2_LocalFilter_def.hpp:915
virtual global_size_t getGlobalNumDiags() const
The number of global diagonal entries, based on global row/column index comparisons.
Definition: Ifpack2_LocalFilter_def.hpp:458
virtual size_t getNumEntriesInGlobalRow(global_ordinal_type globalRow) const
The current number of entries on this node in the specified global row.
Definition: Ifpack2_LocalFilter_def.hpp:418
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_LocalFilter_def.hpp:713
virtual global_ordinal_type getIndexBase() const
Returns the index base for global indices for this matrix.
Definition: Ifpack2_LocalFilter_def.hpp:395
virtual bool isGloballyIndexed() const
Whether the underlying sparse matrix is globally (opposite of locally) indexed.
Definition: Ifpack2_LocalFilter_def.hpp:514
virtual bool isUpperTriangular() const
Whether this matrix is upper triangular.
Definition: Ifpack2_LocalFilter_def.hpp:500
virtual size_t getGlobalMaxNumRowEntries() const
The maximum number of entries across all rows/columns on all processes.
Definition: Ifpack2_LocalFilter_def.hpp:472
virtual void getLocalRowCopy(local_ordinal_type LocalRow, const Teuchos::ArrayView< local_ordinal_type > &Indices, const Teuchos::ArrayView< scalar_type > &Values, size_t &NumEntries) const
Get the entries in the given row, using local indices.
Definition: Ifpack2_LocalFilter_def.hpp:574
virtual size_t getNodeNumCols() const
The number of columns in the (locally filtered) matrix.
Definition: Ifpack2_LocalFilter_def.hpp:387
LocalFilter(const Teuchos::RCP< const row_matrix_type > &A)
Constructor.
Definition: Ifpack2_LocalFilter_def.hpp:149
virtual ~LocalFilter()
Destructor.
Definition: Ifpack2_LocalFilter_def.hpp:292
virtual global_size_t getGlobalNumRows() const
The number of global rows in this matrix.
Definition: Ifpack2_LocalFilter_def.hpp:366
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition: Ifpack2_LocalFilter_decl.hpp:184
virtual std::string description() const
A one-line description of this object.
Definition: Ifpack2_LocalFilter_def.hpp:955
virtual size_t getNodeNumEntries() const
Returns the local number of entries in this matrix.
Definition: Ifpack2_LocalFilter_def.hpp:409
virtual size_t getNumEntriesInLocalRow(local_ordinal_type localRow) const
The current number of entries on this node in the specified local row.
Definition: Ifpack2_LocalFilter_def.hpp:437
virtual Teuchos::RCP< const map_type > getRangeMap() const
Returns the Map that describes the range distribution in this matrix.
Definition: Ifpack2_LocalFilter_def.hpp:346
Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitude_type
The type of the magnitude (absolute value) of a matrix entry.
Definition: Ifpack2_LocalFilter_decl.hpp:196
virtual global_size_t getGlobalNumEntries() const
Returns the global number of entries in this matrix.
Definition: Ifpack2_LocalFilter_def.hpp:402
virtual Teuchos::RCP< const row_matrix_type > getUnderlyingMatrix() const
Return matrix that LocalFilter was built on.
Definition: Ifpack2_LocalFilter_def.hpp:1015
virtual void getGlobalRowCopy(global_ordinal_type GlobalRow, const Teuchos::ArrayView< global_ordinal_type > &Indices, const Teuchos::ArrayView< scalar_type > &Values, size_t &NumEntries) const
Get the entries in the given row, using global indices.
Definition: Ifpack2_LocalFilter_def.hpp:530
Access only local rows and columns of a sparse matrix.
Definition: Ifpack2_LocalFilter_decl.hpp:160
virtual global_size_t getGlobalNumCols() const
The number of global columns in this matrix.
Definition: Ifpack2_LocalFilter_def.hpp:373
Preconditioners and smoothers for Tpetra sparse matrices.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:72
virtual bool isLowerTriangular() const
Whether this matrix is lower triangular.
Definition: Ifpack2_LocalFilter_def.hpp:493
virtual Teuchos::RCP< const map_type > getColMap() const
Returns the Map that describes the column distribution in this matrix.
Definition: Ifpack2_LocalFilter_def.hpp:326
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_LocalFilter_def.hpp:686
virtual bool hasColMap() const
Whether this matrix has a well-defined column Map.
Definition: Ifpack2_LocalFilter_def.hpp:486
MatrixType::node_type node_type
The Node type used by the input MatrixType.
Definition: Ifpack2_LocalFilter_decl.hpp:193