Ifpack2 Templated Preconditioning Package  Version 1.0
Ifpack2_OverlappingRowMatrix_decl.hpp
1 /*@HEADER
2 // ***********************************************************************
3 //
4 // Ifpack2: Templated 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_Details_RowMatrix.hpp"
47 #include "Tpetra_CrsMatrix_decl.hpp" // only need the declaration here
48 #include "Tpetra_Import.hpp"
49 #include "Tpetra_Map.hpp"
50 #include <type_traits>
51 
52 namespace Ifpack2 {
53 
57 template<class MatrixType>
59  virtual public Ifpack2::Details::RowMatrix<MatrixType> {
60 public:
62 
63  typedef typename MatrixType::scalar_type scalar_type;
64  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
65  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
66  typedef typename MatrixType::node_type node_type;
67  typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
68  typedef Tpetra::RowMatrix<scalar_type, local_ordinal_type,
69  global_ordinal_type, node_type> row_matrix_type;
70 
71  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.");
72 
73  typedef typename row_matrix_type::mag_type mag_type;
74 
76 
78 
89  OverlappingRowMatrix (const Teuchos::RCP<const row_matrix_type>& A,
90  const int overlapLevel);
91 
94 
96 
98 
100  virtual Teuchos::RCP<const Teuchos::Comm<int> > getComm() const;
101 
103  virtual Teuchos::RCP<node_type> getNode() const;
104 
106  virtual Teuchos::RCP<const Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> >
107  getRowMap () const;
108 
110  virtual Teuchos::RCP<const Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> >
111  getColMap () const;
112 
116  virtual Teuchos::RCP<const Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> >
117  getDomainMap () const;
118 
122  virtual Teuchos::RCP<const Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> >
123  getRangeMap () const;
124 
126  virtual Teuchos::RCP<const Tpetra::RowGraph<local_ordinal_type, global_ordinal_type, node_type> >
127  getGraph () const;
128 
130  virtual global_size_t getGlobalNumRows () const;
131 
133  virtual global_size_t getGlobalNumCols () const;
134 
136  virtual size_t getNodeNumRows () const;
137 
143  virtual size_t getNodeNumCols () const;
144 
146  virtual global_ordinal_type getIndexBase () const;
147 
149  virtual global_size_t getGlobalNumEntries () const;
150 
152  virtual size_t getNodeNumEntries () const;
153 
163  virtual size_t getNumEntriesInGlobalRow (global_ordinal_type globalRow) const;
164 
174  virtual size_t getNumEntriesInLocalRow (local_ordinal_type localRow) const;
175 
177  virtual size_t getGlobalMaxNumRowEntries () const;
178 
180  virtual size_t getNodeMaxNumRowEntries() const;
181 
183  virtual bool hasColMap() const;
184 
186  virtual bool isLocallyIndexed () const;
187 
189  virtual bool isGloballyIndexed () const;
190 
192  virtual bool isFillComplete() const;
193 
195  virtual bool supportsRowViews() const;
196 
198 
200 
202 
212  virtual void
213  getGlobalRowCopy (global_ordinal_type GlobalRow,
214  const Teuchos::ArrayView<global_ordinal_type> &Indices,
215  const Teuchos::ArrayView<scalar_type> &Values,
216  size_t &NumEntries) const;
217 
219 
229  virtual void
230  getLocalRowCopy (local_ordinal_type LocalRow,
231  const Teuchos::ArrayView<local_ordinal_type> &Indices,
232  const Teuchos::ArrayView<scalar_type> &Values,
233  size_t &NumEntries) const;
234 
236 
245  virtual void
246  getGlobalRowView (global_ordinal_type GlobalRow,
247  Teuchos::ArrayView<const global_ordinal_type> &indices,
248  Teuchos::ArrayView<const scalar_type> &values) const;
249 
251 
260  virtual void
261  getLocalRowView (local_ordinal_type LocalRow,
262  Teuchos::ArrayView<const local_ordinal_type> &indices,
263  Teuchos::ArrayView<const scalar_type> &values) const;
264 
266 
268  virtual
269  void getLocalDiagCopy (Tpetra::Vector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> &diag) const;
270 
272 
274 
284  virtual void
285  leftScale (const Tpetra::Vector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& x);
286 
296  virtual void
297  rightScale (const Tpetra::Vector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& x);
298 
300 
303  virtual mag_type
304  getFrobeniusNorm () const;
305 
307 
314  virtual void
315  apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> &X,
316  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> &Y,
317  Teuchos::ETransp mode = Teuchos::NO_TRANS,
318  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
319  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
320 
322  virtual bool hasTransposeApply() const;
323 
324  virtual void
325  importMultiVector (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> &X,
326  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> &OvX,
327  Tpetra::CombineMode CM = Tpetra::INSERT);
328 
329  virtual void
330  exportMultiVector (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> &OvX,
331  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> &X,
332  Tpetra::CombineMode CM = Tpetra::ADD);
334 
335  std::string description() const;
336 
337  void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const;
338 
339  virtual Teuchos::RCP<const row_matrix_type> getUnderlyingMatrix() const;
340 
341 private:
342  typedef Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> map_type;
343  typedef Tpetra::Import<local_ordinal_type, global_ordinal_type, node_type> import_type;
344  typedef Tpetra::Export<local_ordinal_type, global_ordinal_type, node_type> export_type;
345  typedef Tpetra::RowGraph<local_ordinal_type, global_ordinal_type, node_type> row_graph_type;
346  typedef Tpetra::CrsMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type> crs_matrix_type;
347  typedef Tpetra::Vector<scalar_type, local_ordinal_type, global_ordinal_type, node_type> vector_type;
348 
350  Teuchos::RCP<const row_matrix_type> A_;
351 
352  Tpetra::global_size_t NumGlobalRows_;
353  Tpetra::global_size_t NumGlobalNonzeros_;
354  size_t MaxNumEntries_;
355  int OverlapLevel_;
356 
357  // Wrapper matrix objects
358  Teuchos::RCP<const map_type> RowMap_;
359  Teuchos::RCP<const map_type> ColMap_;
360  Teuchos::RCP<const import_type> Importer_;
361 
363  Teuchos::RCP<row_matrix_type> ExtMatrix_;
364  Teuchos::RCP<map_type> ExtMap_;
365  Teuchos::RCP<import_type> ExtImporter_;
366 
368  Teuchos::RCP<const row_graph_type> graph_;
369 
371  mutable Teuchos::Array<local_ordinal_type> Indices_;
373  mutable Teuchos::Array<scalar_type> Values_;
374 
375 }; // class OverlappingRowMatrix
376 
377 } // namespace Ifpack2
378 
379 #endif // IFPACK2_OVERLAPPINGROWMATRIX_DECL_HPP
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:269
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:285
All Ifpack2 implementations of Tpetra::RowMatrix must inherit from this class.
Definition: Ifpack2_Details_RowMatrix.hpp:64
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:293
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:463
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:260
virtual bool hasTransposeApply() const
Whether this operator&#39;s apply() method can apply the adjoint (transpose).
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:673
virtual mag_type getFrobeniusNorm() const
Returns the Frobenius norm of the matrix.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:552
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:352
virtual Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
The communicator over which the matrix is distributed.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:235
virtual bool isLocallyIndexed() const
Whether this matrix is locally indexed.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:400
virtual global_size_t getGlobalNumCols() const
The global number of columns in this matrix.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:307
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:535
virtual bool isFillComplete() const
true if fillComplete() has been called, else false.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:414
virtual bool isGloballyIndexed() const
Whether this matrix is globally indexed.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:407
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:251
virtual bool hasColMap() const
Whether this matrix has a column Map.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:393
virtual Teuchos::RCP< node_type > getNode() const
The matrix&#39;s Node instance.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:243
virtual size_t getNodeNumEntries() const
The number of entries in this matrix owned by the calling process.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:343
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:484
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:444
virtual bool supportsRowViews() const
true if row views are supported, else false.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:680
virtual size_t getNodeNumCols() const
The number of columns owned by the calling process.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:321
virtual size_t getGlobalMaxNumRowEntries() const
The maximum number of entries in any row on any process.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:379
~OverlappingRowMatrix()
Destructor.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:230
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:544
Sparse matrix (Tpetra::RowMatrix subclass) with ghost rows.
Definition: Ifpack2_OverlappingRowMatrix_decl.hpp:58
virtual size_t getNodeMaxNumRowEntries() const
The maximum number of entries in any row on the calling process.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:386
OverlappingRowMatrix(const Teuchos::RCP< const row_matrix_type > &A, const int overlapLevel)
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:57
virtual size_t getNodeNumRows() const
The number of rows owned by the calling process.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:314
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:561
Preconditioners and smoothers for Tpetra sparse matrices.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:72
virtual global_size_t getGlobalNumEntries() const
The global number of entries in this matrix.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:336
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:423
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:366
virtual global_ordinal_type getIndexBase() const
The index base for global indices for this matrix.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:329
virtual global_size_t getGlobalNumRows() const
The global number of rows in this matrix.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:300
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:502