Ifpack2 Templated Preconditioning Package  Version 1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Ifpack2_Details_AdditiveSchwarzFilter_decl.hpp
1 
2 /*@HEADER
3 // ***********************************************************************
4 //
5 // Ifpack2: Templated Object-Oriented Algebraic Preconditioner Package
6 // Copyright (2009) Sandia Corporation
7 //
8 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
9 // license for use of this work by or on behalf of the U.S. Government.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
39 //
40 // ***********************************************************************
41 //@HEADER
42 */
43 
44 #ifndef IFPACK2_ADDITIVE_SCHWARZ_FILTER_DECL_HPP
45 #define IFPACK2_ADDITIVE_SCHWARZ_FILTER_DECL_HPP
46 
54 #include "Ifpack2_ConfigDefs.hpp"
55 #include "Ifpack2_Details_RowMatrix.hpp"
56 #include "Ifpack2_OverlappingRowMatrix.hpp"
57 
58 namespace Ifpack2
59 {
60 namespace Details
61 {
62  template<typename MatrixType>
63  class AdditiveSchwarzFilter :
64  public Ifpack2::Details::RowMatrix<MatrixType> {
65 public:
66  typedef typename MatrixType::scalar_type scalar_type;
67  typedef typename Kokkos::ArithTraits<scalar_type>::val_type impl_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 MatrixType::global_inds_host_view_type global_inds_host_view_type;
72  typedef typename MatrixType::local_inds_host_view_type local_inds_host_view_type;
73  typedef typename MatrixType::values_host_view_type values_host_view_type;
74 
75  typedef typename MatrixType::nonconst_global_inds_host_view_type nonconst_global_inds_host_view_type;
76  typedef typename MatrixType::nonconst_local_inds_host_view_type nonconst_local_inds_host_view_type;
77  typedef typename MatrixType::nonconst_values_host_view_type nonconst_values_host_view_type;
78 
79  typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
80  typedef Tpetra::RowMatrix<scalar_type,
81  local_ordinal_type,
82  global_ordinal_type,
83  node_type> row_matrix_type;
84  typedef Tpetra::CrsMatrix<scalar_type,
85  local_ordinal_type,
86  global_ordinal_type,
87  node_type> crs_matrix_type;
88  typedef Tpetra::MultiVector<scalar_type,
89  local_ordinal_type,
90  global_ordinal_type,
91  node_type> mv_type;
92  typedef typename crs_matrix_type::device_type device_type;
93  typedef typename crs_matrix_type::execution_space execution_space;
94  typedef Kokkos::RangePolicy<execution_space> policy_type;
95  typedef Kokkos::MDRangePolicy<execution_space, Kokkos::Rank<2>> policy_2d_type;
96  typedef Ifpack2::OverlappingRowMatrix<row_matrix_type> overlapping_matrix_type;
97  typedef typename crs_matrix_type::local_matrix_device_type local_matrix_type;
98  typedef typename local_matrix_type::size_type size_type;
99  typedef typename local_matrix_type::row_map_type::non_const_type row_map_type;
100  typedef typename local_matrix_type::index_type entries_type;
101  typedef typename local_matrix_type::values_type values_type;
102  typedef typename row_map_type::HostMirror host_row_map_type;
103  typedef typename entries_type::HostMirror host_entries_type;
104  typedef typename values_type::HostMirror host_values_type;
105  typedef typename local_matrix_type::HostMirror host_local_matrix_type;
106 
107  static_assert(std::is_same<MatrixType, row_matrix_type>::value, "Ifpack2::AdditiveSchwarzFilter: 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.");
108 
109  typedef Tpetra::Map<local_ordinal_type,
110  global_ordinal_type,
111  node_type> map_type;
112 
113  typedef typename row_matrix_type::mag_type mag_type;
114 
116 
117 
121  // Must be a Tpetra::CrsMatrix or an Ifpack2::OverlappingRowMatrix that wraps a Tpetra::CrsMatrix.
137  const Teuchos::ArrayRCP<local_ordinal_type>& reverseperm,
138  bool filterSingletons);
139 
141  void updateMatrixValues();
142 
143  Teuchos::RCP<const crs_matrix_type> getFilteredMatrix() const;
144 
146  virtual ~AdditiveSchwarzFilter ();
147 
149 
151 
153  virtual Teuchos::RCP<const Teuchos::Comm<int> > getComm() const;
154 
156  virtual Teuchos::RCP<const map_type> getRowMap() const;
157 
159  virtual Teuchos::RCP<const map_type> getColMap() const;
160 
162  virtual Teuchos::RCP<const map_type> getDomainMap() const;
163 
165  virtual Teuchos::RCP<const map_type> getRangeMap() const;
166 
169 
171  virtual local_ordinal_type getBlockSize() const;
172 
174  virtual global_size_t getGlobalNumRows() const;
175 
177  virtual global_size_t getGlobalNumCols() const;
178 
180  virtual size_t getLocalNumRows() const;
181 
183  virtual size_t getLocalNumCols() const;
184 
186  virtual global_ordinal_type getIndexBase() const;
187 
189  virtual global_size_t getGlobalNumEntries() const;
190 
192  virtual size_t getLocalNumEntries() const;
193 
200  virtual size_t getNumEntriesInGlobalRow (global_ordinal_type globalRow) const;
201 
208  virtual size_t getNumEntriesInLocalRow (local_ordinal_type localRow) const;
209 
211  virtual size_t getGlobalMaxNumRowEntries() const;
212 
214  virtual size_t getLocalMaxNumRowEntries() const;
215 
217  virtual bool hasColMap() const;
218 
220  virtual bool isLocallyIndexed() const;
221 
223  virtual bool isGloballyIndexed() const;
224 
226  virtual bool isFillComplete() const;
227 
229  virtual bool supportsRowViews() const;
230 
232 
234 
235 
237 
247  virtual void
248  getGlobalRowCopy (global_ordinal_type GlobalRow,
249  nonconst_global_inds_host_view_type &Indices,
250  nonconst_values_host_view_type &Values,
251  size_t& NumEntries) const;
253 
263  virtual void
264  getLocalRowCopy (local_ordinal_type LocalRow,
265  nonconst_local_inds_host_view_type &Indices,
266  nonconst_values_host_view_type &Values,
267  size_t& NumEntries) const;
268 
270 
278  virtual void
279  getGlobalRowView (global_ordinal_type GlobalRow,
280  global_inds_host_view_type &indices,
281  values_host_view_type &values) const;
283 
292  virtual void
293  getLocalRowView (local_ordinal_type LocalRow,
294  local_inds_host_view_type & indices,
295  values_host_view_type & values) const;
297 
299  virtual void getLocalDiagCopy(Tpetra::Vector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> &diag) const;
300 
302 
304 
305 
315  virtual void leftScale(const Tpetra::Vector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& x);
316 
326  virtual void rightScale(const Tpetra::Vector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& x);
327 
329 
332  virtual mag_type getFrobeniusNorm() const;
333 
355  virtual void
356  apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> &X,
357  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> &Y,
359  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
360  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
361 
363  virtual bool hasTransposeApply() const;
364 
366  void CreateReducedProblem(
367  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& OverlappingB,
368  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& OverlappingY,
369  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& ReducedReorderedB) const;
370 
372  void UpdateLHS(
373  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& ReducedReorderedY,
374  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& OverlappingY) const;
375 
376  void setup(const Teuchos::RCP<const row_matrix_type>& A_unfiltered,
378  const Teuchos::ArrayRCP<local_ordinal_type>& reverseperm,
379  bool filterSingletons);
380 
385  void fillLocalMatrix(local_matrix_type localMatrix);
386 
388 
389 private:
390 
403  static bool
404  mapPairIsFitted (const map_type& map1, const map_type& map2);
405 
409  // If both pairs of Maps of the original matrix A are fitted on this
410  // process, then this process can use a fast "view" implementation.
411  static bool
412  mapPairsAreFitted (const row_matrix_type& A);
413 
419  Kokkos::DualView<local_ordinal_type*, device_type> perm_;
421  Kokkos::DualView<local_ordinal_type*, device_type> reverseperm_;
422  local_ordinal_type numSingletons_;
424  Kokkos::DualView<local_ordinal_type*, device_type> singletons_;
426  Kokkos::DualView<impl_scalar_type*, device_type> singletonDiagonals_;
427 
429  // (apply and solve still process those rows separately)
430  bool FilterSingletons_;
431 
434 };
435 
436 }} //namespace Ifpack2::Details
437 
438 #endif
439 
All Ifpack2 implementations of Tpetra::RowMatrix must inherit from this class.
Definition: Ifpack2_Details_RowMatrix.hpp:63
Sparse matrix (Tpetra::RowMatrix subclass) with ghost rows.
Definition: Ifpack2_OverlappingRowMatrix_decl.hpp:58
Wraps a Tpetra::CrsMatrix or Ifpack2::OverlappingRowMatrix in a filter that removes off-process edges...