Ifpack2 Templated Preconditioning Package  Version 1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Ifpack2_RILUK_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_CRSRILUK_DECL_HPP
47 #define IFPACK2_CRSRILUK_DECL_HPP
48 
51 #include "Tpetra_CrsMatrix_decl.hpp"
52 #include "Ifpack2_ScalingType.hpp"
53 #include "Ifpack2_IlukGraph.hpp"
54 #include "Ifpack2_LocalSparseTriangularSolver_decl.hpp"
55 
56 #include <type_traits>
57 
58 namespace Teuchos {
59  class ParameterList; // forward declaration
60 }
61 
62 namespace Ifpack2 {
63 
242 template<class MatrixType>
243 class RILUK:
244  virtual public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
245  typename MatrixType::local_ordinal_type,
246  typename MatrixType::global_ordinal_type,
247  typename MatrixType::node_type>,
248  virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
249  typename MatrixType::local_ordinal_type,
250  typename MatrixType::global_ordinal_type,
251  typename MatrixType::node_type> >
252 {
253  public:
255  typedef typename MatrixType::scalar_type scalar_type;
256 
258  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
259 
261  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
262 
264  typedef typename MatrixType::node_type node_type;
265 
268 
270  typedef Tpetra::RowMatrix<scalar_type,
274 
275 
276  static_assert(std::is_same<MatrixType, row_matrix_type>::value, "Ifpack2::RILUK: The template parameter MatrixType must be a Tpetra::RowMatrix specialization. Please don't use Tpetra::CrsMatrix (a subclass of Tpetra::RowMatrix) here anymore.");
277 
279  typedef Tpetra::CrsMatrix<scalar_type,
283 
284  template <class NewMatrixType> friend class RILUK;
285 
290 
299 
300  private:
303  RILUK (const RILUK<MatrixType> & src);
304 
305  public:
311  template <typename NewMatrixType>
313  clone (const Teuchos::RCP<const NewMatrixType>& A_newnode) const;
314 
316  virtual ~RILUK ();
317 
325  void setParameters (const Teuchos::ParameterList& params);
326 
328  void initialize ();
329 
338  void compute ();
339 
341  bool isInitialized () const {
342  return isInitialized_;
343  }
345  bool isComputed () const {
346  return isComputed_;
347  }
348 
350  int getNumInitialize () const {
351  return numInitialize_;
352  }
354  int getNumCompute () const {
355  return numCompute_;
356  }
358  int getNumApply () const {
359  return numApply_;
360  }
361 
363  double getInitializeTime () const {
364  return initializeTime_;
365  }
367  double getComputeTime () const {
368  return computeTime_;
369  }
371  double getApplyTime () const {
372  return applyTime_;
373  }
374 
376  size_t getNodeSmootherComplexity() const;
377 
378 
379 
381 
382 
405  virtual void
407 
409 
411 
413  std::string description () const;
414 
416 
418 
421  getDomainMap () const;
422 
425  getRangeMap () const;
426 
456  void
457  apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
458  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
463 
464 private:
486  void
487  multiply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
488  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
489  const Teuchos::ETransp mode = Teuchos::NO_TRANS) const;
490 public:
491 
494 
495  // Attribute access functions
496 
498  magnitude_type getRelaxValue () const { return RelaxValue_; }
499 
501  magnitude_type getAbsoluteThreshold () const { return Athresh_; }
502 
504  magnitude_type getRelativeThreshold () const {return Rthresh_;}
505 
507  int getLevelOfFill () const { return LevelOfFill_; }
508 
510  Tpetra::CombineMode getOverlapMode () {
512  true, std::logic_error, "Ifpack2::RILUK::SetOverlapMode: "
513  "RILUK no longer implements overlap on its own. "
514  "Use RILUK with AdditiveSchwarz if you want overlap.");
515  }
516 
518  Tpetra::global_size_t getGlobalNumEntries () const {
519  return getL ().getGlobalNumEntries () + getU ().getGlobalNumEntries ();
520  }
521 
524  return Graph_;
525  }
526 
528  const crs_matrix_type& getL () const;
529 
531  const Tpetra::Vector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>&
532  getD () const;
533 
535  const crs_matrix_type& getU () const;
536 
539 
540 private:
541  typedef Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> MV;
544 
545  void allocateSolvers ();
546  void allocate_L_and_U ();
547  static void checkOrderingConsistency (const row_matrix_type& A);
548  void initAllValues (const row_matrix_type& A);
549 
556  makeLocalFilter (const Teuchos::RCP<const row_matrix_type>& A);
557 
558 protected:
559  typedef Tpetra::Vector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> vec_type;
560 
563 
572 
583 
584  int LevelOfFill_;
585 
586  bool isAllocated_;
587  bool isInitialized_;
588  bool isComputed_;
589 
590  int numInitialize_;
591  int numCompute_;
592  mutable int numApply_;
593 
594  double initializeTime_;
595  double computeTime_;
596  mutable double applyTime_;
597 
598  magnitude_type RelaxValue_;
599  magnitude_type Athresh_;
600  magnitude_type Rthresh_;
601 
602 };
603 
604 // NOTE (mfh 11 Feb 2015) This used to exist in order to deal with
605 // different behavior of Tpetra::Crs{Graph,Matrix} for
606 // KokkosClassic::ThrustGPUNode. In particular, fillComplete on a
607 // CrsMatrix used to make the graph go away by default, so we had to
608 // pass in a parameter to keep a host copy of the graph. With the new
609 // (Kokkos refactor) version of Tpetra, this problem has gone away.
610 namespace detail {
611  template<class MatrixType, class NodeType>
612  struct setLocalSolveParams{
614  setParams (const Teuchos::RCP<Teuchos::ParameterList>& param) {
615  return param;
616  }
617  };
618 } // namespace detail
619 
620 template <class MatrixType>
621 template <typename NewMatrixType>
624 clone (const Teuchos::RCP<const NewMatrixType>& A_newnode) const
625 {
627  using Teuchos::RCP;
628  using Teuchos::rcp;
629 
630  typedef typename NewMatrixType::scalar_type new_scalar_type;
631  typedef typename NewMatrixType::local_ordinal_type new_local_ordinal_type;
632  typedef typename NewMatrixType::global_ordinal_type new_global_ordinal_type;
633  typedef typename NewMatrixType::node_type new_node_type;
634  typedef Tpetra::RowMatrix<new_scalar_type, new_local_ordinal_type,
635  new_global_ordinal_type, new_node_type> new_row_matrix_type;
636  typedef RILUK<new_row_matrix_type> new_riluk_type;
637 
638  RCP<new_riluk_type> new_riluk = rcp (new new_riluk_type (A_newnode));
639 
640  RCP<ParameterList> plClone = Teuchos::parameterList ();
641  plClone = detail::setLocalSolveParams<NewMatrixType, new_node_type>::setParams (plClone);
642 
643  new_riluk->L_ = rcp(new crs_matrix_type(L_, Teuchos::Copy));
644  new_riluk->U_ = rcp(new crs_matrix_type(U_, Teuchos::Copy));
645  new_riluk->D_ = rcp(new crs_matrix_type(D_, Teuchos::Copy));
646 
647  new_riluk->LevelOfFill_ = LevelOfFill_;
648 
649  new_riluk->isAllocated_ = isAllocated_;
650  new_riluk->isInitialized_ = isInitialized_;
651  new_riluk->isComputed_ = isComputed_;
652 
653  new_riluk->numInitialize_ = numInitialize_;
654  new_riluk->numCompute_ = numCompute_;
655  new_riluk->numApply_ = numApply_;
656 
657  new_riluk->RelaxValue_ = RelaxValue_;
658  new_riluk->Athresh_ = Athresh_;
659  new_riluk->Rthresh_ = Rthresh_;
660 
661 
662  return new_riluk;
663 }
664 
665 } // namespace Ifpack2
666 
667 #endif /* IFPACK2_CRSRILUK_DECL_HPP */
Mix-in interface for preconditioners that can change their matrix after construction.
Definition: Ifpack2_Details_CanChangeMatrix.hpp:93
Declaration and definition of IlukGraph.
magnitude_type getRelaxValue() const
Get RILU(k) relaxation parameter.
Definition: Ifpack2_RILUK_decl.hpp:498
magnitude_type getAbsoluteThreshold() const
Get absolute threshold value.
Definition: Ifpack2_RILUK_decl.hpp:501
Ifpack2::ScalingType enumerable type.
Teuchos::RCP< const Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type > > getRangeMap() const
Returns the Tpetra::Map object associated with the range of this operator.
Definition: Ifpack2_RILUK_def.hpp:223
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition: Ifpack2_RILUK_decl.hpp:261
Teuchos::RCP< crs_matrix_type > L_
The L (lower triangular) factor of ILU(k).
Definition: Ifpack2_RILUK_decl.hpp:574
const Tpetra::Vector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > & getD() const
Return the diagonal entries of the ILU factorization.
Definition: Ifpack2_RILUK_def.hpp:159
void initialize()
Initialize by computing the symbolic incomplete factorization.
Definition: Ifpack2_RILUK_def.hpp:471
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Tpetra::RowMatrix< scalar_type, local_ordinal_type, global_ordinal_type, node_type > row_matrix_type
Tpetra::RowMatrix specialization used by this class.
Definition: Ifpack2_RILUK_decl.hpp:273
double getApplyTime() const
Total time in seconds taken by all successful apply() calls for this object.
Definition: Ifpack2_RILUK_decl.hpp:371
virtual void setMatrix(const Teuchos::RCP< const row_matrix_type > &A)
Change the matrix to be preconditioned.
Definition: Ifpack2_RILUK_def.hpp:106
std::string description() const
A one-line description of this object.
Definition: Ifpack2_RILUK_def.hpp:1052
void setParameters(const Teuchos::ParameterList &params)
Definition: Ifpack2_RILUK_def.hpp:270
ILU(k) factorization of a given Tpetra::RowMatrix.
Definition: Ifpack2_RILUK_decl.hpp:243
size_t getNodeSmootherComplexity() const
Get a rough estimate of cost per iteration.
Definition: Ifpack2_RILUK_def.hpp:186
Tpetra::CombineMode getOverlapMode()
Get overlap mode type.
Definition: Ifpack2_RILUK_decl.hpp:510
Teuchos::RCP< Ifpack2::IlukGraph< Tpetra::CrsGraph< local_ordinal_type, global_ordinal_type, node_type > > > getGraph() const
Return the Ifpack2::IlukGraph associated with this factored matrix.
Definition: Ifpack2_RILUK_decl.hpp:523
Teuchos::RCP< const crs_matrix_type > getCrsMatrix() const
Return the input matrix A as a Tpetra::CrsMatrix, if possible; else throws.
Definition: Ifpack2_RILUK_def.hpp:431
bool isComputed() const
Whether compute() has been called on this object.
Definition: Ifpack2_RILUK_decl.hpp:345
Tpetra::CrsMatrix< scalar_type, local_ordinal_type, global_ordinal_type, node_type > crs_matrix_type
Tpetra::CrsMatrix specialization used by this class for representing L and U.
Definition: Ifpack2_RILUK_decl.hpp:276
const crs_matrix_type & getU() const
Return the U factor of the ILU factorization.
Definition: Ifpack2_RILUK_def.hpp:173
MatrixType::node_type node_type
The Node type used by the input MatrixType.
Definition: Ifpack2_RILUK_decl.hpp:264
Teuchos::RCP< const Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type > > getDomainMap() const
Returns the Tpetra::Map object associated with the domain of this operator.
Definition: Ifpack2_RILUK_def.hpp:204
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition: Ifpack2_RILUK_decl.hpp:258
virtual ~RILUK()
Destructor (declared virtual for memory safety).
Definition: Ifpack2_RILUK_def.hpp:95
Teuchos::RCP< LocalSparseTriangularSolver< row_matrix_type > > U_solver_
Sparse triangular solver for U.
Definition: Ifpack2_RILUK_decl.hpp:580
int getLevelOfFill() const
Get level of fill (the &quot;k&quot; in ILU(k)).
Definition: Ifpack2_RILUK_decl.hpp:507
Teuchos::RCP< RILUK< NewMatrixType > > clone(const Teuchos::RCP< const NewMatrixType > &A_newnode) const
Clone preconditioner to a new node type.
Definition: Ifpack2_RILUK_decl.hpp:624
Teuchos::RCP< Ifpack2::IlukGraph< Tpetra::CrsGraph< local_ordinal_type, global_ordinal_type, node_type > > > Graph_
The ILU(k) graph.
Definition: Ifpack2_RILUK_decl.hpp:567
Interface for all Ifpack2 preconditioners.
Definition: Ifpack2_Preconditioner.hpp:107
void compute()
Compute the (numeric) incomplete factorization.
Definition: Ifpack2_RILUK_def.hpp:722
magnitude_type getRelativeThreshold() const
Get relative threshold value.
Definition: Ifpack2_RILUK_decl.hpp:504
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 (inverse of the) incomplete factorization to X, resulting in Y.
Definition: Ifpack2_RILUK_def.hpp:904
Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitude_type
The type of the magnitude (absolute value) of a matrix entry.
Definition: Ifpack2_RILUK_decl.hpp:267
Construct a level filled graph for use in computing an ILU(k) incomplete factorization.
Definition: Ifpack2_IlukGraph.hpp:97
Declaration of interface for preconditioners that can change their matrix after construction.
bool isInitialized() const
Whether initialize() has been called on this object.
Definition: Ifpack2_RILUK_decl.hpp:341
Teuchos::RCP< LocalSparseTriangularSolver< row_matrix_type > > L_solver_
Sparse triangular solver for L.
Definition: Ifpack2_RILUK_decl.hpp:576
Teuchos::RCP< const row_matrix_type > A_
The (original) input matrix for which to compute ILU(k).
Definition: Ifpack2_RILUK_decl.hpp:562
Teuchos::RCP< const row_matrix_type > getMatrix() const
Get the input matrix.
Definition: Ifpack2_RILUK_def.hpp:424
double getComputeTime() const
Total time in seconds taken by all successful compute() calls for this object.
Definition: Ifpack2_RILUK_decl.hpp:367
Teuchos::RCP< vec_type > D_
The diagonal entries of the ILU(k) factorization.
Definition: Ifpack2_RILUK_decl.hpp:582
int getNumCompute() const
Number of successful compute() calls for this object.
Definition: Ifpack2_RILUK_decl.hpp:354
int getNumApply() const
Number of successful apply() calls for this object.
Definition: Ifpack2_RILUK_decl.hpp:358
Tpetra::global_size_t getGlobalNumEntries() const
Returns the number of nonzero entries in the global graph.
Definition: Ifpack2_RILUK_decl.hpp:518
double getInitializeTime() const
Total time in seconds taken by all successful initialize() calls for this object. ...
Definition: Ifpack2_RILUK_decl.hpp:363
const crs_matrix_type & getL() const
Return the L factor of the ILU factorization.
Definition: Ifpack2_RILUK_def.hpp:142
Teuchos::RCP< const row_matrix_type > A_local_
The matrix whos numbers are used to to compute ILU(k). The graph may be computed using a crs_matrix_t...
Definition: Ifpack2_RILUK_decl.hpp:571
Teuchos::RCP< crs_matrix_type > U_
The U (upper triangular) factor of ILU(k).
Definition: Ifpack2_RILUK_decl.hpp:578
int getNumInitialize() const
Number of successful initialize() calls for this object.
Definition: Ifpack2_RILUK_decl.hpp:350
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition: Ifpack2_RILUK_decl.hpp:255