Ifpack2 Templated Preconditioning Package  Version 1.0
Ifpack2_ILUT_decl.hpp
Go to the documentation of this file.
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 
45 
46 #ifndef IFPACK2_ILUT_DECL_HPP
47 #define IFPACK2_ILUT_DECL_HPP
48 
51 #include "Tpetra_CrsMatrix_decl.hpp"
52 #include "Ifpack2_LocalSparseTriangularSolver_decl.hpp"
53 
54 #include <string>
55 #include <sstream>
56 #include <iostream>
57 #include <cmath>
58 #include <type_traits>
59 
60 namespace Teuchos {
61  class ParameterList; // forward declaration
62 }
63 
64 namespace Ifpack2 {
65 
90 template<class MatrixType>
91 class ILUT :
92  virtual public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
93  typename MatrixType::local_ordinal_type,
94  typename MatrixType::global_ordinal_type,
95  typename MatrixType::node_type>,
96  virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
97  typename MatrixType::local_ordinal_type,
98  typename MatrixType::global_ordinal_type,
99  typename MatrixType::node_type> >
100 {
101 public:
103 
104 
106  typedef typename MatrixType::scalar_type scalar_type;
107 
109  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
110 
112  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
113 
115  typedef typename MatrixType::node_type node_type;
116 
118  typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
119 
121  typedef Tpetra::RowMatrix<scalar_type,
125 
126  typedef typename row_matrix_type::global_inds_host_view_type global_inds_host_view_type;
127  typedef typename row_matrix_type::local_inds_host_view_type local_inds_host_view_type;
128  typedef typename row_matrix_type::values_host_view_type values_host_view_type;
129 
130  typedef typename row_matrix_type::nonconst_global_inds_host_view_type nonconst_global_inds_host_view_type;
131  typedef typename row_matrix_type::nonconst_local_inds_host_view_type nonconst_local_inds_host_view_type;
132  typedef typename row_matrix_type::nonconst_values_host_view_type nonconst_values_host_view_type;
133 
134  static_assert(std::is_same<MatrixType, row_matrix_type>::value, "Ifpack2::ILUT: 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.");
135 
137  typedef Tpetra::CrsMatrix<scalar_type,
141 
143  typedef Tpetra::Map<local_ordinal_type,
147 
149 
159  explicit ILUT (const Teuchos::RCP<const row_matrix_type>& A);
160 
162  virtual ~ILUT () = default;
163 
165 
167 
199  void setParameters (const Teuchos::ParameterList& params);
200 
208  void initialize ();
209 
211  inline bool isInitialized() const {
212  return IsInitialized_;
213  }
214 
216 
223  void compute();
224 
226  inline bool isComputed() const {
227  return IsComputed_;
228  }
229 
231 
233 
256  virtual void
257  setMatrix (const Teuchos::RCP<const row_matrix_type>& A);
258 
260 
262 
267  void
268  apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
269  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
270  Teuchos::ETransp mode = Teuchos::NO_TRANS,
271  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
272  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
273 
275  Teuchos::RCP<const map_type> getDomainMap() const;
276 
278  Teuchos::RCP<const map_type> getRangeMap() const;
279 
281  bool hasTransposeApply() const;
282 
284 
286 
288  Teuchos::RCP<const Teuchos::Comm<int> > getComm() const;
289 
291  Teuchos::RCP<const row_matrix_type> getMatrix () const;
292 
294  Teuchos::RCP<const crs_matrix_type> getL () const { return L_; }
295 
297  Teuchos::RCP<const crs_matrix_type> getU () const { return U_; }
298 
300  int getNumInitialize() const;
301 
303  int getNumCompute() const;
304 
306  int getNumApply() const;
307 
309  double getInitializeTime() const;
310 
312  double getComputeTime() const;
313 
315  double getApplyTime() const;
316 
318  size_t getNodeSmootherComplexity() const;
319 
320 
328  inline double getLevelOfFill() const {
329  return LevelOfFill_;
330  }
331 
334  return(Athresh_);
335  }
336 
339  return(Rthresh_);
340  }
341 
343  inline magnitude_type getRelaxValue() const {
344  return(RelaxValue_);
345  }
346 
349  return(DropTolerance_);
350  }
351 
353  global_size_t getGlobalNumEntries() const;
354 
356  size_t getNodeNumEntries() const;
357 
359 
361 
363  std::string description() const;
364 
366  void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const;
367 
369 
370 private:
371  typedef Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> MV;
372  typedef Teuchos::ScalarTraits<scalar_type> STS;
373  typedef Teuchos::ScalarTraits<magnitude_type> STM;
374  typedef typename Teuchos::Array<local_ordinal_type>::size_type size_type;
375 
377  ILUT (const ILUT<MatrixType>& RHS);
378 
379  void allocateSolvers ();
380 
382  ILUT<MatrixType>& operator= (const ILUT<MatrixType>& RHS);
383 
394  static Teuchos::RCP<const row_matrix_type>
395  makeLocalFilter (const Teuchos::RCP<const row_matrix_type>& A);
396 
397  // \name The matrix and its incomplete LU factors
399 
401  Teuchos::RCP<const row_matrix_type> A_;
403  Teuchos::RCP<const row_matrix_type> A_local_;
405  Teuchos::RCP<crs_matrix_type> L_;
407  Teuchos::RCP<LocalSparseTriangularSolver<row_matrix_type> > L_solver_;
409  Teuchos::RCP<crs_matrix_type> U_;
411  Teuchos::RCP<LocalSparseTriangularSolver<row_matrix_type> > U_solver_;
412 
414  // \name Parameters (set by setParameters())
416 
417  magnitude_type Athresh_;
418  magnitude_type Rthresh_;
419  magnitude_type RelaxValue_;
420  double LevelOfFill_;
421  magnitude_type DropTolerance_;
423 
425  // \name Other internal data
427 
429  double InitializeTime_;
431  double ComputeTime_;
433  mutable double ApplyTime_;
435  int NumInitialize_;
437  int NumCompute_;
439  mutable int NumApply_;
441  bool IsInitialized_;
443  bool IsComputed_;
445 }; // class ILUT
446 
447 } // namespace Ifpack2
448 
449 #endif /* IFPACK2_ILUT_HPP */
magnitude_type getRelaxValue() const
Get the relax value.
Definition: Ifpack2_ILUT_decl.hpp:343
int getNumCompute() const
Returns the number of calls to Compute().
Definition: Ifpack2_ILUT_def.hpp:267
Mix-in interface for preconditioners that can change their matrix after construction.
Definition: Ifpack2_Details_CanChangeMatrix.hpp:93
Teuchos::RCP< const crs_matrix_type > getL() const
Returns a reference to the L factor.
Definition: Ifpack2_ILUT_decl.hpp:294
ILUT(const Teuchos::RCP< const row_matrix_type > &A)
Constructor.
Definition: Ifpack2_ILUT_def.hpp:117
global_size_t getGlobalNumEntries() const
Returns the number of nonzero entries in the global graph.
Definition: Ifpack2_ILUT_def.hpp:308
bool hasTransposeApply() const
Whether this object&#39;s apply() method can apply the transpose (or conjugate transpose, if applicable).
Definition: Ifpack2_ILUT_def.hpp:255
size_t getNodeNumEntries() const
Returns the number of nonzero entries in the local graph.
Definition: Ifpack2_ILUT_def.hpp:314
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition: Ifpack2_ILUT_decl.hpp:112
Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitude_type
The type of the magnitude (absolute value) of a matrix entry.
Definition: Ifpack2_ILUT_decl.hpp:118
void initialize()
Clear any previously computed factors.
Definition: Ifpack2_ILUT_def.hpp:360
magnitude_type getDropTolerance() const
Gets the dropping tolerance.
Definition: Ifpack2_ILUT_decl.hpp:348
magnitude_type getAbsoluteThreshold() const
Get absolute threshold value.
Definition: Ifpack2_ILUT_decl.hpp:333
bool isComputed() const
If compute() is completed, this query returns true, otherwise it returns false.
Definition: Ifpack2_ILUT_decl.hpp:226
int getNumApply() const
Returns the number of calls to apply().
Definition: Ifpack2_ILUT_def.hpp:273
int getNumInitialize() const
Returns the number of calls to Initialize().
Definition: Ifpack2_ILUT_def.hpp:261
ILUT (incomplete LU factorization with threshold) of a Tpetra sparse matrix.
Definition: Ifpack2_ILUT_decl.hpp:91
double getLevelOfFill() const
The level of fill.
Definition: Ifpack2_ILUT_decl.hpp:328
Teuchos::RCP< const map_type > getRangeMap() const
Tpetra::Map representing the range of this operator.
Definition: Ifpack2_ILUT_def.hpp:244
virtual ~ILUT()=default
Destructor.
double getInitializeTime() const
Returns the time spent in Initialize().
Definition: Ifpack2_ILUT_def.hpp:279
bool isInitialized() const
Returns true if the preconditioner has been successfully initialized.
Definition: Ifpack2_ILUT_decl.hpp:211
Teuchos::RCP< const map_type > getDomainMap() const
Tpetra::Map representing the domain of this operator.
Definition: Ifpack2_ILUT_def.hpp:232
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition: Ifpack2_ILUT_decl.hpp:106
Interface for all Ifpack2 preconditioners.
Definition: Ifpack2_Preconditioner.hpp:107
Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type > map_type
Type of the Tpetra::Map specialization that this class uses.
Definition: Ifpack2_ILUT_decl.hpp:145
Declaration of interface for preconditioners that can change their matrix after construction.
void compute()
Compute factors L and U using the specified diagonal perturbation thresholds and relaxation parameter...
Definition: Ifpack2_ILUT_def.hpp:398
virtual void setMatrix(const Teuchos::RCP< const row_matrix_type > &A)
Change the matrix to be preconditioned.
Definition: Ifpack2_ILUT_def.hpp:320
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_ILUT_decl.hpp:124
magnitude_type getRelativeThreshold() const
Get relative threshold value.
Definition: Ifpack2_ILUT_decl.hpp:338
Teuchos::RCP< const row_matrix_type > getMatrix() const
Returns a reference to the matrix to be preconditioned.
Definition: Ifpack2_ILUT_def.hpp:225
std::string description() const
Return a simple one-line description of this object.
Definition: Ifpack2_ILUT_def.hpp:827
Definition: Ifpack2_Container_decl.hpp:576
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_ILUT_def.hpp:860
double getComputeTime() const
Returns the time spent in Compute().
Definition: Ifpack2_ILUT_def.hpp:285
Tpetra::CrsMatrix< scalar_type, local_ordinal_type, global_ordinal_type, node_type > crs_matrix_type
Type of the Tpetra::CrsMatrix specialization that this class uses for the L and U factors...
Definition: Ifpack2_ILUT_decl.hpp:134
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Returns the input matrix&#39;s communicator.
Definition: Ifpack2_ILUT_def.hpp:214
Teuchos::RCP< const crs_matrix_type > getU() const
Returns a reference to the U factor.
Definition: Ifpack2_ILUT_decl.hpp:297
size_t getNodeSmootherComplexity() const
Get a rough estimate of cost per iteration.
Definition: Ifpack2_ILUT_def.hpp:297
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
Apply the ILUT preconditioner to X, resulting in Y.
Definition: Ifpack2_ILUT_def.hpp:756
Preconditioners and smoothers for Tpetra sparse matrices.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:73
double getApplyTime() const
Returns the time spent in apply().
Definition: Ifpack2_ILUT_def.hpp:291
void setParameters(const Teuchos::ParameterList &params)
Set preconditioner parameters.
Definition: Ifpack2_ILUT_def.hpp:144
MatrixType::node_type node_type
The Node type used by the input MatrixType.
Definition: Ifpack2_ILUT_decl.hpp:115
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition: Ifpack2_ILUT_decl.hpp:109