Ifpack2 Templated Preconditioning Package  Version 1.0
Ifpack2_OverlappingRowMatrix_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_OVERLAPPINGROWMATRIX_DECL_HPP
44 #define IFPACK2_OVERLAPPINGROWMATRIX_DECL_HPP
45 
46 #include "Ifpack2_ConfigDefs.hpp"
47 #include "Tpetra_RowMatrix.hpp"
48 #include "Tpetra_CrsMatrix_decl.hpp" // only need the declaration here
49 #include "Tpetra_Import.hpp"
50 #include "Tpetra_Map.hpp"
51 #include <type_traits>
52 
53 namespace Ifpack2 {
54 
58 template<class MatrixType>
60  virtual public Tpetra::RowMatrix<typename MatrixType::scalar_type,
61  typename MatrixType::local_ordinal_type,
62  typename MatrixType::global_ordinal_type,
63  typename MatrixType::node_type> {
64 public:
66 
67  typedef typename MatrixType::scalar_type scalar_type;
68  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
69  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
70  typedef typename MatrixType::node_type node_type;
71  typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
72  typedef Tpetra::RowMatrix<scalar_type, local_ordinal_type,
73  global_ordinal_type, node_type> row_matrix_type;
74 
75  static_assert(std::is_same<MatrixType, row_matrix_type>::value, "Ifpack2::OverlappingRowMatrix: The template parameter MatrixType must be a Tpetra::RowMatrix specialization. Please don't use Tpetra::CrsMatrix (a subclass of Tpetra::RowMatrix) here anymore. The constructor can take either a RowMatrix or a CrsMatrix just fine.");
76 
77  typedef typename row_matrix_type::mag_type mag_type;
78 
80 
82 
93  OverlappingRowMatrix (const Teuchos::RCP<const row_matrix_type>& A,
94  const int overlapLevel);
95 
98 
100 
102 
104  virtual Teuchos::RCP<const Teuchos::Comm<int> > getComm() const;
105 
107  virtual Teuchos::RCP<node_type> getNode() const;
108 
110  virtual Teuchos::RCP<const Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> >
111  getRowMap () const;
112 
114  virtual Teuchos::RCP<const Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> >
115  getColMap () const;
116 
120  virtual Teuchos::RCP<const Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> >
121  getDomainMap () const;
122 
126  virtual Teuchos::RCP<const Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> >
127  getRangeMap () const;
128 
130  virtual Teuchos::RCP<const Tpetra::RowGraph<local_ordinal_type, global_ordinal_type, node_type> >
131  getGraph () const;
132 
134  virtual global_size_t getGlobalNumRows () const;
135 
137  virtual global_size_t getGlobalNumCols () const;
138 
140  virtual size_t getNodeNumRows () const;
141 
147  virtual size_t getNodeNumCols () const;
148 
150  virtual global_ordinal_type getIndexBase () const;
151 
153  virtual global_size_t getGlobalNumEntries () const;
154 
156  virtual size_t getNodeNumEntries () const;
157 
167  virtual size_t getNumEntriesInGlobalRow (global_ordinal_type globalRow) const;
168 
178  virtual size_t getNumEntriesInLocalRow (local_ordinal_type localRow) const;
179 
181  virtual global_size_t getGlobalNumDiags () const;
182 
184  virtual size_t getNodeNumDiags () const;
185 
187  virtual size_t getGlobalMaxNumRowEntries () const;
188 
190  virtual size_t getNodeMaxNumRowEntries() const;
191 
193  virtual bool hasColMap() const;
194 
196  virtual bool isLowerTriangular() const;
197 
199  virtual bool isUpperTriangular() const;
200 
202  virtual bool isLocallyIndexed () const;
203 
205  virtual bool isGloballyIndexed () const;
206 
208  virtual bool isFillComplete() const;
209 
211  virtual bool supportsRowViews() const;
212 
214 
216 
218 
228  virtual void
229  getGlobalRowCopy (global_ordinal_type GlobalRow,
230  const Teuchos::ArrayView<global_ordinal_type> &Indices,
231  const Teuchos::ArrayView<scalar_type> &Values,
232  size_t &NumEntries) const;
233 
235 
245  virtual void
246  getLocalRowCopy (local_ordinal_type LocalRow,
247  const Teuchos::ArrayView<local_ordinal_type> &Indices,
248  const Teuchos::ArrayView<scalar_type> &Values,
249  size_t &NumEntries) const;
250 
252 
261  virtual void
262  getGlobalRowView (global_ordinal_type GlobalRow,
263  Teuchos::ArrayView<const global_ordinal_type> &indices,
264  Teuchos::ArrayView<const scalar_type> &values) const;
265 
267 
276  virtual void
277  getLocalRowView (local_ordinal_type LocalRow,
278  Teuchos::ArrayView<const local_ordinal_type> &indices,
279  Teuchos::ArrayView<const scalar_type> &values) const;
280 
282 
284  virtual
285  void getLocalDiagCopy (Tpetra::Vector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> &diag) const;
286 
288 
290 
300  virtual void
301  leftScale (const Tpetra::Vector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& x);
302 
312  virtual void
313  rightScale (const Tpetra::Vector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& x);
314 
316 
319  virtual mag_type
320  getFrobeniusNorm () const;
321 
323 
330  virtual void
331  apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> &X,
332  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> &Y,
333  Teuchos::ETransp mode = Teuchos::NO_TRANS,
334  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
335  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
336 
338  virtual bool hasTransposeApply() const;
339 
340  virtual void
341  importMultiVector (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> &X,
342  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> &OvX,
343  Tpetra::CombineMode CM = Tpetra::INSERT);
344 
345  virtual void
346  exportMultiVector (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> &OvX,
347  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> &X,
348  Tpetra::CombineMode CM = Tpetra::ADD);
350 
351  std::string description() const;
352 
353  void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const;
354 
355  virtual Teuchos::RCP<const row_matrix_type> getUnderlyingMatrix() const;
356 
357 private:
358  typedef Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> map_type;
359  typedef Tpetra::Import<local_ordinal_type, global_ordinal_type, node_type> import_type;
360  typedef Tpetra::Export<local_ordinal_type, global_ordinal_type, node_type> export_type;
361  typedef Tpetra::RowGraph<local_ordinal_type, global_ordinal_type, node_type> row_graph_type;
362  typedef Tpetra::CrsMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type> crs_matrix_type;
363 
365  Teuchos::RCP<const row_matrix_type> A_;
366 
367  Tpetra::global_size_t NumGlobalRows_;
368  Tpetra::global_size_t NumGlobalNonzeros_;
369  size_t MaxNumEntries_;
370  int OverlapLevel_;
371 
372  // Wrapper matrix objects
373  Teuchos::RCP<const map_type> RowMap_;
374  Teuchos::RCP<const map_type> ColMap_;
375  Teuchos::RCP<const import_type> Importer_;
376 
378  Teuchos::RCP<row_matrix_type> ExtMatrix_;
379  Teuchos::RCP<map_type> ExtMap_;
380  Teuchos::RCP<import_type> ExtImporter_;
381 
383  Teuchos::RCP<const row_graph_type> graph_;
384 
386  mutable Teuchos::Array<local_ordinal_type> Indices_;
388  mutable Teuchos::Array<scalar_type> Values_;
389 
390 }; // class OverlappingRowMatrix
391 
392 } // namespace Ifpack2
393 
394 #endif // IFPACK2_OVERLAPPINGROWMATRIX_DECL_HPP
virtual bool isGloballyIndexed() const
Whether this matrix is globally indexed.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:425
virtual mag_type getFrobeniusNorm() const
Returns the Frobenius norm of the matrix.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:546
virtual size_t getNodeNumRows() const
The number of rows owned by the calling process.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:304
virtual bool isFillComplete() const
true if fillComplete() has been called, else false.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:432
virtual bool isUpperTriangular() const
Whether this matrix is upper triangular.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:411
virtual Teuchos::RCP< node_type > getNode() const
The matrix&#39;s Node instance.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:241
virtual size_t getNodeNumDiags() const
The number of diagonal entries owned by the calling process.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:376
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_OverlappingRowMatrix_def.hpp:529
virtual Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
The communicator over which the matrix is distributed.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:233
virtual Teuchos::RCP< const Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type > > getRowMap() const
The Map that describes the distribution of rows over processes.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:249
virtual bool isLowerTriangular() const
Whether this matrix is lower triangular.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:404
virtual global_size_t getGlobalNumRows() const
The global number of rows in this matrix.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:290
virtual global_size_t getGlobalNumCols() const
The global number of columns in this matrix.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:297
virtual bool isLocallyIndexed() const
Whether this matrix is locally indexed.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:418
virtual global_size_t getGlobalNumDiags() const
The global number of diagonal entries.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:369
virtual Teuchos::RCP< const Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type > > getRangeMap() const
The Map that describes the range of this matrix.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:275
virtual Teuchos::RCP< const Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type > > getDomainMap() const
The Map that describes the domain of this matrix.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:267
virtual size_t getNumEntriesInGlobalRow(global_ordinal_type globalRow) const
The number of entries in the given global row that are owned by the calling process.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:342
virtual size_t getNodeNumEntries() const
The number of entries in this matrix owned by the calling process.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:333
virtual global_size_t getGlobalNumEntries() const
The global number of entries in this matrix.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:326
~OverlappingRowMatrix()
Destructor.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:228
virtual bool hasTransposeApply() const
Whether this operator&#39;s apply() method can apply the adjoint (transpose).
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:667
virtual global_ordinal_type getIndexBase() const
The index base for global indices for this matrix.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:319
virtual bool hasColMap() const
Whether this matrix has a column Map.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:397
virtual size_t getNumEntriesInLocalRow(local_ordinal_type localRow) const
The number of entries in the given local row that are owned by the calling process.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:356
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_OverlappingRowMatrix_def.hpp:538
virtual Teuchos::RCP< const Tpetra::RowGraph< local_ordinal_type, global_ordinal_type, node_type > > getGraph() const
This matrix&#39;s graph.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:283
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_OverlappingRowMatrix_def.hpp:481
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_OverlappingRowMatrix_def.hpp:520
Sparse matrix (Tpetra::RowMatrix subclass) with ghost rows.
Definition: Ifpack2_OverlappingRowMatrix_decl.hpp:59
OverlappingRowMatrix(const Teuchos::RCP< const row_matrix_type > &A, const int overlapLevel)
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:55
virtual size_t getNodeMaxNumRowEntries() const
The maximum number of entries in any row on the calling process.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:390
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
Computes the operator-multivector application.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:555
virtual void getLocalRowCopy(local_ordinal_type LocalRow, 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_OverlappingRowMatrix_def.hpp:462
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_OverlappingRowMatrix_def.hpp:441
Preconditioners and smoothers for Tpetra sparse matrices.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:72
virtual Teuchos::RCP< const Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type > > getColMap() const
The Map that describes the distribution of columns over processes.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:258
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_OverlappingRowMatrix_def.hpp:502
virtual bool supportsRowViews() const
true if row views are supported, else false.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:674
virtual size_t getGlobalMaxNumRowEntries() const
The maximum number of entries in any row on any process.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:383
virtual size_t getNodeNumCols() const
The number of columns owned by the calling process.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:311