Ifpack2 Templated Preconditioning Package  Version 1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Ifpack2_LocalFilter_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_LOCALFILTER_DECL_HPP
44 #define IFPACK2_LOCALFILTER_DECL_HPP
45 
46 #include "Ifpack2_ConfigDefs.hpp"
47 #include "Ifpack2_Details_RowMatrix.hpp"
48 #include "Tpetra_CrsGraph.hpp"
49 #include <type_traits>
50 #include <vector>
51 
52 
53 namespace Ifpack2 {
54 
160 template<class MatrixType>
161 class LocalFilter :
162  virtual public Ifpack2::Details::RowMatrix<MatrixType>,
163  virtual public Teuchos::Describable
164 {
165 private:
166  // Tpetra needs C++11 now because Kokkos needs C++11 now.
167  // Thus, Ifpack2 needs C++11.
168  static_assert (std::is_same<
169  MatrixType,
170  Tpetra::RowMatrix<
171  typename MatrixType::scalar_type,
172  typename MatrixType::local_ordinal_type,
173  typename MatrixType::global_ordinal_type,
174  typename MatrixType::node_type> >::value,
175  "Ifpack2::LocalFilter: MatrixType must be a Tpetra::RowMatrix specialization.");
176 
177 public:
179 
180 
182  typedef typename MatrixType::scalar_type scalar_type;
183 
185  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
186 
188  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
189 
191  typedef typename MatrixType::node_type node_type;
192 
193 
194  typedef typename MatrixType::global_inds_host_view_type global_inds_host_view_type;
195  typedef typename MatrixType::local_inds_host_view_type local_inds_host_view_type;
196  typedef typename MatrixType::values_host_view_type values_host_view_type;
197 
198  typedef typename MatrixType::nonconst_global_inds_host_view_type nonconst_global_inds_host_view_type;
199  typedef typename MatrixType::nonconst_local_inds_host_view_type nonconst_local_inds_host_view_type;
200  typedef typename MatrixType::nonconst_values_host_view_type nonconst_values_host_view_type;
201 
202 
205 
206 
207 
209  typedef Tpetra::RowMatrix<scalar_type,
212  node_type> row_matrix_type;
213 
215  typedef Tpetra::RowGraph<local_ordinal_type,
217  node_type> row_graph_type;
218 
220  typedef Tpetra::Map<local_ordinal_type,
222  node_type> map_type;
223 
224  typedef typename row_matrix_type::mag_type mag_type;
225 
227 
229 
231  virtual std::string description () const;
232 
234  virtual void
236  const Teuchos::EVerbosityLevel verbLevel =
238 
240 
242 
249 
251  virtual ~LocalFilter();
252 
254 
256 
259 
260 
262  virtual Teuchos::RCP<const map_type> getRowMap() const;
263 
265  virtual Teuchos::RCP<const map_type> getColMap() const;
266 
269 
272 
275  getGraph () const;
276 
278  virtual global_size_t getGlobalNumRows() const;
279 
281  virtual global_size_t getGlobalNumCols() const;
282 
284  virtual size_t getLocalNumRows() const;
285 
287  virtual size_t getLocalNumCols() const;
288 
290  virtual global_ordinal_type getIndexBase() const;
291 
293  virtual global_size_t getGlobalNumEntries() const;
294 
296  virtual size_t getLocalNumEntries() const;
297 
299  virtual local_ordinal_type getBlockSize () const;
300 
306  virtual size_t getNumEntriesInGlobalRow (global_ordinal_type globalRow) const;
307 
313  virtual size_t getNumEntriesInLocalRow (local_ordinal_type localRow) const;
314 
316  virtual size_t getGlobalMaxNumRowEntries() const;
317 
319  virtual size_t getLocalMaxNumRowEntries() const;
320 
322  virtual bool hasColMap() const;
323 
325  virtual bool isLocallyIndexed() const;
326 
328  virtual bool isGloballyIndexed() const;
329 
331  virtual bool isFillComplete() const;
332 
334  virtual bool supportsRowViews() const;
335 
337 
339 
353  virtual void
354  getGlobalRowCopy (global_ordinal_type GlobalRow,
355  nonconst_global_inds_host_view_type &Indices,
356  nonconst_values_host_view_type &Values,
357  size_t& NumEntries) const;
358 
372  virtual void
373  getLocalRowCopy (local_ordinal_type LocalRow,
374  nonconst_local_inds_host_view_type &Indices,
375  nonconst_values_host_view_type &Values,
376  size_t& NumEntries) const;
377 
379 
389  virtual void
390  getGlobalRowView (global_ordinal_type GlobalRow,
391  global_inds_host_view_type &indices,
392  values_host_view_type &values) const;
393 
395 
405  virtual void
406  getLocalRowView (local_ordinal_type LocalRow,
407  local_inds_host_view_type & indices,
408  values_host_view_type & values) const;
409 
416  virtual void
417  getLocalDiagCopy (Tpetra::Vector<scalar_type, local_ordinal_type, global_ordinal_type, node_type> &diag) const;
418 
420 
422 
432  virtual void leftScale(const Tpetra::Vector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& x);
433 
443  virtual void rightScale(const Tpetra::Vector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& x);
444 
453  virtual mag_type getFrobeniusNorm() const;
454 
461  virtual void
462  apply (const Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type> &X,
463  Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type> &Y,
465  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
466  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
467 
469  virtual bool hasTransposeApply() const;
470 
473 
475 private:
477  typedef Tpetra::CrsGraph<local_ordinal_type,
479  node_type> crs_graph_type;
480 
482  void
483  applyNonAliased (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> &X,
484  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> &Y,
485  Teuchos::ETransp mode,
486  scalar_type alpha,
487  scalar_type beta) const;
488 
501  static bool
502  mapPairIsFitted (const map_type& map1, const map_type& map2);
503 
507  // If both pairs of Maps of the original matrix A are fitted on this
508  // process, then this process can use a fast "view" implementation.
509  static bool
510  mapPairsAreFitted (const row_matrix_type& A);
511 
514 
516  Teuchos::RCP<const map_type> localRowMap_;
517 
519  Teuchos::RCP<const map_type> localDomainMap_;
520 
522  Teuchos::RCP<const map_type> localRangeMap_;
523 
525  mutable Teuchos::RCP<const row_graph_type> local_graph_;
526 
528  size_t NumNonzeros_;
530  size_t MaxNumEntries_;
532  size_t MaxNumEntriesA_;
534  std::vector<size_t> NumEntries_;
535 
537  mutable nonconst_local_inds_host_view_type localIndices_;
538  mutable nonconst_local_inds_host_view_type localIndicesForGlobalCopy_;
540  mutable nonconst_values_host_view_type Values_;
541 
542 };// class LocalFilter
543 
544 }// namespace Ifpack2
545 
546 #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:664
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:212
virtual Teuchos::RCP< const map_type > getRowMap() const
Returns the Map that describes the row distribution in this matrix.
Definition: Ifpack2_LocalFilter_def.hpp:252
All Ifpack2 implementations of Tpetra::RowMatrix must inherit from this class.
Definition: Ifpack2_Details_RowMatrix.hpp:63
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:919
virtual Teuchos::RCP< const map_type > getDomainMap() const
Returns the Map that describes the domain distribution in this matrix.
Definition: Ifpack2_LocalFilter_def.hpp:272
virtual size_t getLocalMaxNumRowEntries() const
The maximum number of entries across all rows/columns on this process.
Definition: Ifpack2_LocalFilter_def.hpp:424
virtual void getGlobalRowCopy(global_ordinal_type GlobalRow, nonconst_global_inds_host_view_type &Indices, nonconst_values_host_view_type &Values, size_t &NumEntries) const
Get the entries in the given row, using global indices.
Definition: Ifpack2_LocalFilter_def.hpp:461
virtual bool isFillComplete() const
Returns true if fillComplete() has been called.
Definition: Ifpack2_LocalFilter_def.hpp:452
virtual void getLocalRowCopy(local_ordinal_type LocalRow, nonconst_local_inds_host_view_type &Indices, nonconst_values_host_view_type &Values, size_t &NumEntries) const
Get the entries in the given row, using local indices.
Definition: Ifpack2_LocalFilter_def.hpp:506
virtual Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Returns the communicator.
Definition: Ifpack2_LocalFilter_def.hpp:240
virtual void getGlobalRowView(global_ordinal_type GlobalRow, global_inds_host_view_type &indices, values_host_view_type &values) const
Extract a const, non-persisting view of global indices in a specified row of the matrix.
Definition: Ifpack2_LocalFilter_def.hpp:615
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:674
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition: Ifpack2_LocalFilter_decl.hpp:188
virtual bool hasTransposeApply() const
Whether this operator supports applying the transpose or conjugate transpose.
Definition: Ifpack2_LocalFilter_def.hpp:856
virtual bool isLocallyIndexed() const
Whether the underlying sparse matrix is locally (opposite of globally) indexed.
Definition: Ifpack2_LocalFilter_def.hpp:438
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:639
virtual size_t getLocalNumEntries() const
Returns the local number of entries in this matrix.
Definition: Ifpack2_LocalFilter_def.hpp:363
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:222
virtual mag_type getFrobeniusNorm() const
The Frobenius norm of the (locally filtered) matrix.
Definition: Ifpack2_LocalFilter_def.hpp:872
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:292
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition: Ifpack2_LocalFilter_decl.hpp:185
virtual bool supportsRowViews() const
Returns true if RowViews are supported.
Definition: Ifpack2_LocalFilter_def.hpp:863
virtual size_t getLocalNumCols() const
The number of columns in the (locally filtered) matrix.
Definition: Ifpack2_LocalFilter_def.hpp:341
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:377
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:654
virtual global_ordinal_type getIndexBase() const
Returns the index base for global indices for this matrix.
Definition: Ifpack2_LocalFilter_def.hpp:349
virtual bool isGloballyIndexed() const
Whether the underlying sparse matrix is globally (opposite of locally) indexed.
Definition: Ifpack2_LocalFilter_def.hpp:445
virtual size_t getGlobalMaxNumRowEntries() const
The maximum number of entries across all rows/columns on all processes.
Definition: Ifpack2_LocalFilter_def.hpp:417
static const EVerbosityLevel verbLevel_default
LocalFilter(const Teuchos::RCP< const row_matrix_type > &A)
Constructor.
Definition: Ifpack2_LocalFilter_def.hpp:98
virtual ~LocalFilter()
Destructor.
Definition: Ifpack2_LocalFilter_def.hpp:234
virtual global_size_t getGlobalNumRows() const
The number of global rows in this matrix.
Definition: Ifpack2_LocalFilter_def.hpp:320
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition: Ifpack2_LocalFilter_decl.hpp:182
virtual std::string description() const
A one-line description of this object.
Definition: Ifpack2_LocalFilter_def.hpp:899
virtual size_t getLocalNumRows() const
The number of rows owned on the calling process.
Definition: Ifpack2_LocalFilter_def.hpp:334
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:396
virtual Teuchos::RCP< const map_type > getRangeMap() const
Returns the Map that describes the range distribution in this matrix.
Definition: Ifpack2_LocalFilter_def.hpp:282
Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitude_type
The type of the magnitude (absolute value) of a matrix entry.
Definition: Ifpack2_LocalFilter_decl.hpp:204
virtual global_size_t getGlobalNumEntries() const
Returns the global number of entries in this matrix.
Definition: Ifpack2_LocalFilter_def.hpp:356
virtual Teuchos::RCP< const row_matrix_type > getUnderlyingMatrix() const
Return matrix that LocalFilter was built on.
Definition: Ifpack2_LocalFilter_def.hpp:959
Access only local rows and columns of a sparse matrix.
Definition: Ifpack2_LocalFilter_decl.hpp:161
virtual global_size_t getGlobalNumCols() const
The number of global columns in this matrix.
Definition: Ifpack2_LocalFilter_def.hpp:327
virtual Teuchos::RCP< const map_type > getColMap() const
Returns the Map that describes the column distribution in this matrix.
Definition: Ifpack2_LocalFilter_def.hpp:262
virtual void getLocalRowView(local_ordinal_type LocalRow, local_inds_host_view_type &indices, values_host_view_type &values) const
Extract a const, non-persisting view of local indices in a specified row of the matrix.
Definition: Ifpack2_LocalFilter_def.hpp:627
virtual bool hasColMap() const
Whether this matrix has a well-defined column Map.
Definition: Ifpack2_LocalFilter_def.hpp:431
Tpetra::RowGraph< local_ordinal_type, global_ordinal_type, node_type > row_graph_type
Type of the Tpetra::RowGraph specialization that this class uses.
Definition: Ifpack2_LocalFilter_decl.hpp:217
MatrixType::node_type node_type
The Node type used by the input MatrixType.
Definition: Ifpack2_LocalFilter_decl.hpp:191
virtual local_ordinal_type getBlockSize() const
The number of degrees of freedom per mesh point.
Definition: Ifpack2_LocalFilter_def.hpp:369