Ifpack2 Templated Preconditioning Package  Version 1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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>
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 
149 
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,
224 
227 
230 
232  bool hasTransposeApply() const;
233 
235  magnitude_type getCondEst() const { return Condest_; }
236 
238 
240 
244 
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 
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 
280 
282 
283  private:
284 
285  // @{ Internal methods
286 
289 
292 
294 
295  // @{ Internal data and parameters
296 
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 
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_;
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_;
356  Teuchos::RCP<PrecType> ifpack2_prec_;
357 
359 
360 }; // class Krylov
361 
362 }//namespace Ifpack2
363 
364 #endif /* IFPACK2_KRYLOV_HPP */
virtual ~Krylov()
Krylov Destructor.
Definition: Ifpack2_Krylov_def.hpp:87
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 &quot;node_type&quot;.
Definition: Ifpack2_Krylov_decl.hpp:144
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to an FancyOStream object.
Definition: Ifpack2_Krylov_def.hpp:342
double getComputeTime() const
Returns the time spent in Compute().
Definition: Ifpack2_Krylov_def.hpp:168
int getNumInitialize() const
Returns the number of calls to Initialize().
Definition: Ifpack2_Krylov_def.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
Krylov(const Teuchos::RCP< const Tpetra::RowMatrix< scalar_type, local_ordinal_type, global_ordinal_type, node_type > > &A)
Krylov explicit constuctor with Tpetra::RowMatrix input.
Definition: Ifpack2_Krylov_def.hpp:57
const Teuchos::RCP< const Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type > > & getRangeMap() const
Tpetra::Map representing the range of this operator.
Definition: Ifpack2_Krylov_def.hpp:131
std::string description() const
Return a simple one-line description of this object.
Definition: Ifpack2_Krylov_def.hpp:320
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 &quot;local_ordinal_type&quot;.
Definition: Ifpack2_Krylov_decl.hpp:130
magnitude_type computeCondEst(CondestType CT=Cheap, local_ordinal_type MaxIters=1550, magnitude_type Tol=1e-9, const Teuchos::Ptr< const Tpetra::RowMatrix< scalar_type, local_ordinal_type, global_ordinal_type, node_type > > &Matrix_in=Teuchos::null)
Computes the estimated condition number and returns the value.
Definition: Ifpack2_Krylov_def.hpp:182
TEUCHOS_DEPRECATED typedef Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitudeType
Preserved only for backwards compatibility. Please use &quot;magnitude_type&quot;.
Definition: Ifpack2_Krylov_decl.hpp:151
const Teuchos::RCP< const Teuchos::Comm< int > > & getComm() const
Returns the Tpetra::BlockMap object associated with the range of this matrix operator.
Definition: Ifpack2_Krylov_def.hpp:109
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
Returns the result of a few iterations of CG/GMRES on a Tpetra::MultiVector X in Y.
Definition: Ifpack2_Krylov_def.hpp:271
void setParameters(const Teuchos::ParameterList &params)
Set parameters for the preconditioner.
Definition: Ifpack2_Krylov_def.hpp:92
double getApplyTime() const
Returns the time spent in apply().
Definition: Ifpack2_Krylov_def.hpp:174
Teuchos::RCP< const Tpetra::RowMatrix< scalar_type, local_ordinal_type, global_ordinal_type, node_type > > getMatrix() const
Returns a reference to the matrix to be preconditioned.
Definition: Ifpack2_Krylov_def.hpp:116
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
const Teuchos::RCP< const Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type > > & getDomainMap() const
Tpetra::Map representing the domain of this operator.
Definition: Ifpack2_Krylov_def.hpp:123
void compute()
Setup iteration.
Definition: Ifpack2_Krylov_def.hpp:249
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
bool hasTransposeApply() const
Whether this object&#39;s apply() method can apply the transpose (or conjugate transpose, if applicable).
Definition: Ifpack2_Krylov_def.hpp:138
A class for constructing and using a CG/GMRES smoother.
Definition: Ifpack2_Krylov_decl.hpp:110
int getNumApply() const
Returns the number of calls to apply().
Definition: Ifpack2_Krylov_def.hpp:156
static const EVerbosityLevel verbLevel_default
TEUCHOS_DEPRECATED typedef MatrixType::global_ordinal_type GlobalOrdinal
Preserved only for backwards compatibility. Please use &quot;global_ordinal_type&quot;.
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
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition: Ifpack2_Krylov_decl.hpp:134
void initialize()
Initialize Krylov preconditioner object.
Definition: Ifpack2_Krylov_def.hpp:198
double getInitializeTime() const
Returns the time spent in Initialize().
Definition: Ifpack2_Krylov_def.hpp:162
Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitude_type
The type of the magnitude (absolute value) of a matrix entry.
Definition: Ifpack2_Krylov_decl.hpp:148
int getNumCompute() const
Returns the number of calls to Compute().
Definition: Ifpack2_Krylov_def.hpp:150
TEUCHOS_DEPRECATED typedef MatrixType::scalar_type Scalar
Preserved only for backwards compatibility. Please use &quot;scalar_type&quot;.
Definition: Ifpack2_Krylov_decl.hpp:123
cheap estimate
Definition: Ifpack2_CondestType.hpp:51