Ifpack2 Templated Preconditioning Package  Version 1.0
Ifpack2_Krylov_decl.hpp
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 
43 //-----------------------------------------------------
44 // Ifpack2::KRYLOV is based on the Krylov iterative
45 // solvers in Belos.
46 // written by Paul Tsuji.
47 //-----------------------------------------------------
48 
49 #ifndef IFPACK2_KRYLOV_DECL_HPP
50 #define IFPACK2_KRYLOV_DECL_HPP
51 
52 #include "Ifpack2_ConfigDefs.hpp"
53 #include "Ifpack2_Preconditioner.hpp"
54 #include "Ifpack2_Condest.hpp"
55 #include "Ifpack2_Heap.hpp"
56 #include "Ifpack2_Parameters.hpp"
57 #include "Ifpack2_Relaxation.hpp"
58 #include "Ifpack2_Chebyshev.hpp"
59 #include "Ifpack2_ILUT.hpp"
60 #include "Ifpack2_AdditiveSchwarz.hpp"
61 
62 #include <BelosConfigDefs.hpp>
63 #include <BelosSolverManager.hpp>
64 #include <BelosTpetraAdapter.hpp>
66 #include <BelosBlockCGSolMgr.hpp>
67 
68 #include <Teuchos_Assert.hpp>
69 #include <Teuchos_RCP.hpp>
70 #include <Teuchos_Time.hpp>
71 #include <Teuchos_TypeNameTraits.hpp>
72 #include <Teuchos_ScalarTraits.hpp>
73 
74 #include <iostream>
75 #include <string>
76 #include <sstream>
77 
78 
79 #include <string>
80 #include <sstream>
81 #include <iostream>
82 #include <cmath>
83 
84 namespace Teuchos {
85  // forward declaration
86  class ParameterList;
87 }
88 
89 namespace Ifpack2 {
90 
92  /*
93  * This exists to allow a ScalarType to override what scalar type is used
94  * for Belos, if those are not equal, by specializing this class.
95  */
96  template <typename ScalarType>
97  struct BelosScalarType {
98  typedef ScalarType type;
99  };
100 
102  // for a given Tpetra::RowMatrix.
103 
109  template<class MatrixType,class PrecType>
110  class Krylov: virtual public Ifpack2::Preconditioner<typename MatrixType::scalar_type,typename MatrixType::local_ordinal_type,typename MatrixType::global_ordinal_type,typename MatrixType::node_type> {
111 
112  public:
113  // \name Typedefs
115 
117  typedef typename MatrixType::scalar_type scalar_type;
118 
120  typedef typename BelosScalarType<scalar_type>::type belos_scalar_type;
121 
123  TEUCHOS_DEPRECATED typedef typename MatrixType::scalar_type Scalar;
124 
125 
127  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
128 
130  TEUCHOS_DEPRECATED typedef typename MatrixType::local_ordinal_type LocalOrdinal;
131 
132 
134  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
135 
137  TEUCHOS_DEPRECATED typedef typename MatrixType::global_ordinal_type GlobalOrdinal;
138 
139 
141  typedef typename MatrixType::node_type node_type;
142 
144  TEUCHOS_DEPRECATED typedef typename MatrixType::node_type Node;
145 
146 
148  typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
149 
151  TEUCHOS_DEPRECATED typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitudeType;
152 
154  typedef typename Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> TMV;
155  typedef typename Tpetra::Operator<scalar_type,local_ordinal_type,global_ordinal_type,node_type> TOP;
156 
158  // \name Constructors and Destructors
160 
162  explicit Krylov(const Teuchos::RCP<const Tpetra::RowMatrix<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > &A);
163 
165  virtual ~Krylov();
166 
168 
169 
179  void setParameters(const Teuchos::ParameterList& params);
180 
182 
184  void initialize();
185 
187  inline bool isInitialized() const {
188  return(IsInitialized_);
189  }
190 
192 
199  void compute();
200 
202  inline bool isComputed() const {
203  return(IsComputed_);
204  }
205 
207 
209 
210 
212 
218  void apply(
219  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
220  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
221  Teuchos::ETransp mode = Teuchos::NO_TRANS,
222  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
223  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
224 
226  const Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> >& getDomainMap() const;
227 
229  const Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> >& getRangeMap() const;
230 
232  bool hasTransposeApply() const;
233 
235  magnitude_type getCondEst() const { return Condest_; }
236 
238 
240 
243  const Teuchos::RCP<const Teuchos::Comm<int> > & getComm() const;
244 
246  Teuchos::RCP<const Tpetra::RowMatrix<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > getMatrix() const;
247 
249  int getNumInitialize() const;
250 
252  int getNumCompute() const;
253 
255  int getNumApply() const;
256 
258  double getInitializeTime() const;
259 
261  double getComputeTime() const;
262 
264  double getApplyTime() const;
265 
267  magnitude_type computeCondEst(CondestType CT = Cheap,
268  local_ordinal_type MaxIters = 1550,
269  magnitude_type Tol = 1e-9,
270  const Teuchos::Ptr<const Tpetra::RowMatrix<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > &Matrix_in = Teuchos::null);
271 
273 
274 
276  std::string description() const;
277 
279  void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const;
280 
282 
283  private:
284 
285  // @{ Internal methods
286 
289 
292 
294 
295  // @{ Internal data and parameters
296 
298  const Teuchos::RCP<const Tpetra::RowMatrix<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > A_;
300  const Teuchos::RCP<const Teuchos::Comm<int> > Comm_;
301 
304  // 1 for GMRES (default)
305  // 2 for CG
306  int IterationType_;
308  int Iterations_;
310  magnitude_type ResidualTolerance_;
312  int BlockSize_;
314  bool ZeroStartingSolution_;
316  // 1 for relaxation (default)
317  // 2 for ILUT
318  // 3 for Chebyshev
319  int PreconditionerType_;
321  Teuchos::ParameterList params_;
322 
324  magnitude_type Condest_;
326  bool IsInitialized_;
328  bool IsComputed_;
330  int NumInitialize_;
332  int NumCompute_;
334  mutable int NumApply_;
336  double InitializeTime_;
338  double ComputeTime_;
340  mutable double ApplyTime_;
342  mutable Teuchos::Time Time_;
344  local_ordinal_type NumMyRows_;
346  global_size_t NumGlobalNonzeros_;
347 
349  Teuchos::RCP< Belos::LinearProblem<scalar_type,
350  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>,
351  Tpetra::Operator<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > > belosProblem_;
352  Teuchos::RCP< Belos::SolverManager<scalar_type,
353  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>,
354  Tpetra::Operator<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > > belosSolver_;
355  Teuchos::RCP<Teuchos::ParameterList> belosList_;
356  Teuchos::RCP<PrecType> ifpack2_prec_;
357 
359 
360 }; // class Krylov
361 
362 }//namespace Ifpack2
363 
364 #endif /* IFPACK2_KRYLOV_HPP */
CondestType
Ifpack2::CondestType: enum to define the type of condition number estimate.
Definition: Ifpack2_CondestType.hpp:50
TEUCHOS_DEPRECATED typedef MatrixType::node_type Node
Preserved only for backwards compatibility. Please use "node_type".
Definition: Ifpack2_Krylov_decl.hpp:144
MatrixType::node_type node_type
The type of the Kokkos Node used by the input MatrixType.
Definition: Ifpack2_Krylov_decl.hpp:141
A traits class for determining the scalar type to use for Belos.
Definition: Ifpack2_Krylov_decl.hpp:97
bool isInitialized() const
Returns true if the preconditioner has been successfully initialized.
Definition: Ifpack2_Krylov_decl.hpp:187
TEUCHOS_DEPRECATED typedef MatrixType::local_ordinal_type LocalOrdinal
Preserved only for backwards compatibility. Please use "local_ordinal_type".
Definition: Ifpack2_Krylov_decl.hpp:130
TEUCHOS_DEPRECATED typedef Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitudeType
Preserved only for backwards compatibility. Please use "magnitude_type".
Definition: Ifpack2_Krylov_decl.hpp:151
BelosScalarType< scalar_type >::type belos_scalar_type
The scalar type used by Belos (which may not be scalar_type)
Definition: Ifpack2_Krylov_decl.hpp:120
Tpetra::MultiVector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > TMV
Tpetra MultiVector/Operator.
Definition: Ifpack2_Krylov_decl.hpp:154
magnitude_type getCondEst() const
Returns the computed estimated condition number, or -1.0 if no computed.
Definition: Ifpack2_Krylov_decl.hpp:235
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition: Ifpack2_Krylov_decl.hpp:127
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition: Ifpack2_Krylov_decl.hpp:117
Base class for all Ifpack2 preconditioners.
Definition: Ifpack2_Preconditioner.hpp:130
A class for constructing and using a CG/GMRES smoother.
Definition: Ifpack2_Krylov_decl.hpp:110
TEUCHOS_DEPRECATED typedef MatrixType::global_ordinal_type GlobalOrdinal
Preserved only for backwards compatibility. Please use "global_ordinal_type".
Definition: Ifpack2_Krylov_decl.hpp:137
bool isComputed() const
If compute() is completed, this query returns true, otherwise it returns false.
Definition: Ifpack2_Krylov_decl.hpp:202
Definition: Ifpack2_BlockRelaxation_decl.hpp:64
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition: Ifpack2_Krylov_decl.hpp:134
Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitude_type
The type of the magnitude (absolute value) of a matrix entry.
Definition: Ifpack2_Krylov_decl.hpp:148
TEUCHOS_DEPRECATED typedef MatrixType::scalar_type Scalar
Preserved only for backwards compatibility. Please use "scalar_type".
Definition: Ifpack2_Krylov_decl.hpp:123
Ifpack2::Container: a pure virtual class for creating and solving local linear problems.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:67
cheap estimate
Definition: Ifpack2_CondestType.hpp:51