Ifpack2 Templated Preconditioning Package  Version 1.0
Ifpack2_Krylov_decl.hpp
Go to the documentation of this file.
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 
49 
50 #ifndef IFPACK2_KRYLOV_DECL_HPP
51 #define IFPACK2_KRYLOV_DECL_HPP
52 
55 
56 #include "BelosSolverManager.hpp"
57 #include "BelosTpetraAdapter.hpp"
58 #include "Teuchos_ScalarTraits.hpp"
59 #include <type_traits>
60 
61 namespace Teuchos {
62  class ParameterList; // forward declaration
63 }
64 
65 namespace Ifpack2 {
66 
77  template <typename ScalarType>
78  struct BelosScalarType {
79  typedef ScalarType type;
80  };
81 
94  template<class MatrixType>
95  class IFPACK2_DEPRECATED Krylov :
96  virtual public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
97  typename MatrixType::local_ordinal_type,
98  typename MatrixType::global_ordinal_type,
99  typename MatrixType::node_type>,
100  virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
101  typename MatrixType::local_ordinal_type,
102  typename MatrixType::global_ordinal_type,
103  typename MatrixType::node_type> >
104  {
105  public:
106  // \name Public typedefs
108 
110  typedef typename MatrixType::scalar_type scalar_type;
111 
113  typedef typename BelosScalarType<scalar_type>::type belos_scalar_type;
114 
116  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
117 
119  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
120 
122  typedef typename MatrixType::node_type node_type;
123 
125  typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
126 
128  typedef Tpetra::RowMatrix<scalar_type,
129  local_ordinal_type,
130  global_ordinal_type,
131  node_type> row_matrix_type;
132 
133  static_assert(std::is_same<MatrixType, row_matrix_type>::value, "Ifpack2::Krylov: 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.");
134 
136  typedef Ifpack2::Preconditioner<scalar_type,
137  local_ordinal_type,
138  global_ordinal_type,
139  node_type> prec_type;
140 
142  // \name Constructors and Destructors
144 
146  explicit Krylov (const Teuchos::RCP<const row_matrix_type>& A);
147 
149  virtual ~Krylov ();
150 
152 
154 
169  void setParameters (const Teuchos::ParameterList& params);
170 
172  void initialize ();
173 
175  inline bool isInitialized () const {
176  return IsInitialized_;
177  }
178 
180  void compute ();
181 
183  inline bool isComputed() const {
184  return IsComputed_;
185  }
186 
188 
190 
213  virtual void setMatrix (const Teuchos::RCP<const row_matrix_type>& A);
214 
216 
218 
220  void
221  apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
222  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
223  Teuchos::ETransp mode = Teuchos::NO_TRANS,
224  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
225  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
226 
228  Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> > getDomainMap() const;
229 
231  Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> > getRangeMap() const;
232 
234  bool hasTransposeApply() const;
235 
237 
239 
241  Teuchos::RCP<const Teuchos::Comm<int> > getComm() const;
242 
244  Teuchos::RCP<const Tpetra::RowMatrix<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > getMatrix() const;
245 
247  int getNumInitialize() const;
248 
250  int getNumCompute() const;
251 
253  int getNumApply() const;
254 
256  double getInitializeTime() const;
257 
259  double getComputeTime() const;
260 
262  double getApplyTime() const;
263 
265 
266 
268  std::string description() const;
269 
271  void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const;
272 
274 
275  private:
276  typedef Teuchos::ScalarTraits<scalar_type> STS;
277  typedef Teuchos::ScalarTraits<magnitude_type> STM;
278 
280  Krylov (const Krylov<MatrixType>& RHS);
281 
283  Krylov<MatrixType>& operator= (const Krylov<MatrixType>& RHS);
284 
289  Teuchos::RCP<const row_matrix_type> A_;
290 
292 
296  std::string iterationType_;
297 
299  int numIters_;
300 
302  magnitude_type resTol_;
303 
305  int BlockSize_;
306 
308  bool ZeroStartingSolution_;
309 
311  // 1 for relaxation
312  // 2 for ILUT
313  // 3 for RILUK
314  // 4 for Chebyshev
315  int PreconditionerType_;
316 
321  Teuchos::ParameterList precParams_;
322 
324  bool IsInitialized_;
326  bool IsComputed_;
328  int NumInitialize_;
330  int NumCompute_;
332  mutable int NumApply_;
334  double InitializeTime_;
336  double ComputeTime_;
338  mutable double ApplyTime_;
339 
341  Teuchos::RCP<Belos::LinearProblem<belos_scalar_type,
342  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>,
343  Tpetra::Operator<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > > belosProblem_;
344 
346  Teuchos::RCP<Belos::SolverManager<belos_scalar_type,
347  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>,
348  Tpetra::Operator<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > > belosSolver_;
349 
351  Teuchos::RCP<prec_type> ifpack2_prec_;
352  };
353 
354 } // namespace Ifpack2
355 
356 #endif // IFPACK2_KRYLOV_DECL_HPP
Mix-in interface for preconditioners that can change their matrix after construction.
Definition: Ifpack2_Details_CanChangeMatrix.hpp:93
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition: Ifpack2_Krylov_decl.hpp:110
Traits class for determining the scalar type to use for Belos.
Definition: Ifpack2_Krylov_decl.hpp:78
Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitude_type
The type of the magnitude (absolute value) of a matrix entry.
Definition: Ifpack2_Krylov_decl.hpp:125
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition: Ifpack2_Krylov_decl.hpp:119
MatrixType::node_type node_type
The Node type used by the input MatrixType.
Definition: Ifpack2_Krylov_decl.hpp:122
Ifpack2::Preconditioner< scalar_type, local_ordinal_type, global_ordinal_type, node_type > prec_type
Type of the Ifpack2::Preconditioner specialization from which this class inherits.
Definition: Ifpack2_Krylov_decl.hpp:133
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition: Ifpack2_Krylov_decl.hpp:116
Interface for all Ifpack2 preconditioners.
Definition: Ifpack2_Preconditioner.hpp:107
Declaration of interface for preconditioners that can change their matrix after construction.
Wrapper for iterative linear solvers (e.g., CG or GMRES).
Definition: Ifpack2_Krylov_decl.hpp:95
bool isComputed() const
Return true if compute() completed successfully, else false.
Definition: Ifpack2_Krylov_decl.hpp:183
Definition: Ifpack2_Details_Amesos2Wrapper_decl.hpp:63
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_Krylov_decl.hpp:131
BelosScalarType< scalar_type >::type belos_scalar_type
The scalar type used by Belos (which may not be scalar_type)
Definition: Ifpack2_Krylov_decl.hpp:113
Preconditioners and smoothers for Tpetra sparse matrices.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:72
bool isInitialized() const
Return true if initialize() completed successfully, else false.
Definition: Ifpack2_Krylov_decl.hpp:175