Ifpack2 Templated Preconditioning Package  Version 1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Ifpack2_Diagonal_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_DIAGONAL_DECL_HPP
44 #define IFPACK2_DIAGONAL_DECL_HPP
45 
48 #include "Tpetra_CrsMatrix_decl.hpp"
49 #include <type_traits>
50 
51 namespace Ifpack2 {
52 
70 template<class MatrixType>
71 class Diagonal :
72  virtual public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
73  typename MatrixType::local_ordinal_type,
74  typename MatrixType::global_ordinal_type,
75  typename MatrixType::node_type>,
76  virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
77  typename MatrixType::local_ordinal_type,
78  typename MatrixType::global_ordinal_type,
79  typename MatrixType::node_type> >
80 {
81 public:
82  typedef typename MatrixType::scalar_type scalar_type;
83  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
84  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
85  typedef typename MatrixType::node_type node_type;
86  typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
87 
89  typedef Tpetra::RowMatrix<scalar_type,
90  local_ordinal_type,
91  global_ordinal_type,
92  node_type> row_matrix_type;
93 
94  static_assert(std::is_same<MatrixType, row_matrix_type>::value, "Ifpack2::Diagonal: 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.");
95 
97  typedef Tpetra::CrsMatrix<scalar_type,
98  local_ordinal_type,
99  global_ordinal_type,
100  node_type> crs_matrix_type;
102  typedef Tpetra::Vector<scalar_type,
103  local_ordinal_type,
104  global_ordinal_type,
105  node_type> vector_type;
107  typedef Tpetra::Map<local_ordinal_type,
108  global_ordinal_type,
109  node_type> map_type;
110 
114  Diagonal (const Teuchos::RCP<const row_matrix_type>& A);
115 
123  Diagonal (const Teuchos::RCP<const crs_matrix_type>& A_in);
124 
136  Diagonal (const Teuchos::RCP<const vector_type>& diag);
137 
139  virtual ~Diagonal ();
140 
142 
145  void setParameters (const Teuchos::ParameterList& params);
146 
148  void initialize ();
149 
151  bool isInitialized () const {
152  return isInitialized_;
153  }
154 
156  void compute ();
157 
159  bool isComputed () const {
160  return isComputed_;
161  }
162 
164 
166 
189  virtual void
190  setMatrix (const Teuchos::RCP<const row_matrix_type>& A);
191 
193 
195 
201  void
202  apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
203  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
205  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
206  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
207 
209  Teuchos::RCP<const map_type> getDomainMap () const;
210 
212  Teuchos::RCP<const map_type> getRangeMap () const;
213 
215 
217 
219  //Teuchos::RCP<const Teuchos::Comm<int> > getComm () const;
220 
226  Teuchos::RCP<const row_matrix_type> getMatrix () const {
227  return matrix_;
228  }
229 
231  double getComputeFlops() const;
232 
234  double getApplyFlops() const;
235 
237  int getNumInitialize() const;
238 
240  int getNumCompute() const;
241 
243  int getNumApply() const;
244 
246  double getInitializeTime() const;
247 
249  double getComputeTime() const;
250 
252  double getApplyTime() const;
253 
255 
257 
259  std::string description() const;
260 
262  void
263  describe (Teuchos::FancyOStream& out,
264  const Teuchos::EVerbosityLevel verbLevel =
267 
268 private:
270  void reset ();
271 
274 
279  Teuchos::RCP<const vector_type> userInverseDiag_;
280 
282  Teuchos::RCP<const vector_type> inverseDiag_;
283 
284  typedef Kokkos::View<size_t*, typename node_type::device_type> offsets_type;
285  offsets_type offsets_;
286 
287  double initializeTime_;
288  double computeTime_;
289  mutable double applyTime_;
290 
291  int numInitialize_;
292  int numCompute_;
293  mutable int numApply_;
294 
295  bool isInitialized_;
296  bool isComputed_;
297 };
298 
315 template<class MatrixType, class VectorType>
316 Teuchos::RCP<Ifpack2::Diagonal<Tpetra::RowMatrix<typename MatrixType::scalar_type,
317  typename MatrixType::local_ordinal_type,
318  typename MatrixType::global_ordinal_type,
319  typename MatrixType::node_type> > >
320 createDiagonalPreconditioner (const Teuchos::RCP<const VectorType>& invdiag)
321 {
322  typedef Tpetra::RowMatrix<typename MatrixType::scalar_type,
323  typename MatrixType::local_ordinal_type,
324  typename MatrixType::global_ordinal_type,
325  typename MatrixType::node_type> row_matrix_type;
326 
327  return Teuchos::rcp (new Ifpack2::Diagonal<row_matrix_type> (invdiag));
328 }
329 
330 }//namespace Ifpack2
331 
332 #endif
Mix-in interface for preconditioners that can change their matrix after construction.
Definition: Ifpack2_Details_CanChangeMatrix.hpp:93
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Interface for all Ifpack2 preconditioners.
Definition: Ifpack2_Preconditioner.hpp:107
Declaration of interface for preconditioners that can change their matrix after construction.
static const EVerbosityLevel verbLevel_default