Ifpack2 Templated Preconditioning Package  Version 1.0
Ifpack2_Chebyshev_decl.hpp
Go to the documentation of this file.
1 /*
2 @HEADER
3 // ***********************************************************************
4 //
5 // Ifpack2: Tempated Object-Oriented Algebraic Preconditioner Package
6 // Copyright (2009) Sandia Corporation
7 //
8 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
9 // license for use of this work by or on behalf of the U.S. Government.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
39 //
40 // ***********************************************************************
41 //@HEADER
42 */
43 
50 
51 #ifndef IFPACK2_CHEBYSHEV_DECL_HPP
52 #define IFPACK2_CHEBYSHEV_DECL_HPP
53 
56 
57 // FIXME (mfh 20 Nov 2013) We really shouldn't have to include this.
58 // We should handle the implementation by pointer instead of by value.
59 #include "Ifpack2_Details_Chebyshev.hpp"
60 
61 // We only need the declaration here, and only for the method
62 // getCrsMatrix. I would very much prefer that this method not exist.
63 // Furthermore, it is both unsafe (MatrixType need not be CrsMatrix)
64 // and completely redundant (just call getMatrix() and do the
65 // dynamic_cast yourself).
66 #include "Tpetra_CrsMatrix_decl.hpp"
67 
68 #include <type_traits>
69 
70 namespace Ifpack2 {
71 
198 template<class MatrixType>
199 class Chebyshev :
200  virtual public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
201  typename MatrixType::local_ordinal_type,
202  typename MatrixType::global_ordinal_type,
203  typename MatrixType::node_type>,
204  virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
205  typename MatrixType::local_ordinal_type,
206  typename MatrixType::global_ordinal_type,
207  typename MatrixType::node_type> >
208 {
209 public:
211 
212 
214  typedef MatrixType matrix_type;
215 
217  typedef typename MatrixType::scalar_type scalar_type;
218 
220  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
221 
223  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
224 
226  typedef typename MatrixType::node_type node_type;
227 
229  typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
230 
235  typedef Tpetra::RowMatrix<scalar_type,local_ordinal_type,global_ordinal_type,node_type> row_matrix_type;
236 
237  static_assert(std::is_same<MatrixType, row_matrix_type>::value,
238  "Ifpack2::Chebyshev: Please use MatrixType = Tpetra::RowMatrix.");
239 
241  typedef Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> map_type;
242 
248  typedef Tpetra::Vector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> vector_type;
249 
251  // \name Constructors and destructors
253 
275  explicit Chebyshev (const Teuchos::RCP<const row_matrix_type>& A);
276 
278  virtual ~Chebyshev ();
279 
281 
283 
420  void setParameters (const Teuchos::ParameterList& params);
421 
428  void initialize();
429 
432  inline bool isInitialized() const {
433  return IsInitialized_;
434  }
435 
468  void compute ();
469 
479  inline bool isComputed() const {
480  return IsComputed_;
481  }
482 
484 
486 
509  virtual void
510  setMatrix (const Teuchos::RCP<const row_matrix_type>& A);
511 
513 
515 
544  void
545  apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
546  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
547  Teuchos::ETransp mode = Teuchos::NO_TRANS,
548  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
549  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
550 
552  Teuchos::RCP<const map_type> getDomainMap() const;
553 
555  Teuchos::RCP<const map_type> getRangeMap() const;
556 
558  bool hasTransposeApply() const;
559 
580  void
581  applyMat (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
582  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
583  Teuchos::ETransp mode = Teuchos::NO_TRANS) const;
584 
586 
588 
590  Teuchos::RCP<const Teuchos::Comm<int> > getComm() const;
591 
593  Teuchos::RCP<const row_matrix_type> getMatrix() const;
594 
599  Teuchos::RCP<const Tpetra::CrsMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type> >
600  getCrsMatrix() const;
601 
603  double getComputeFlops() const;
604 
606  double getApplyFlops() const;
607 
609  int getNumInitialize() const;
610 
612  int getNumCompute() const;
613 
615  int getNumApply() const;
616 
618  double getInitializeTime() const;
619 
621  double getComputeTime() const;
622 
624  double getApplyTime() const;
625 
627  typename MatrixType::scalar_type getLambdaMaxForApply() const;
628 
630 
632 
634  std::string description() const;
635 
637  void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const;
638 
640 
642 
643  // This "template friend" declaration lets any Chebyshev
644  // specialization be a friend of any of its other specializations.
645  // That makes clone() easier to implement.
646  template <class NewMatrixType> friend class Chebyshev;
647 
667  template <typename NewMatrixType>
668  Teuchos::RCP<Chebyshev<Tpetra::RowMatrix<typename NewMatrixType::scalar_type, typename NewMatrixType::local_ordinal_type, typename NewMatrixType::global_ordinal_type, typename NewMatrixType::node_type> > >
669  clone (const Teuchos::RCP<const NewMatrixType>& A_newnode,
670  const Teuchos::ParameterList& params) const;
671 
673 
674 private:
675 
677  typedef Teuchos::ScalarTraits<typename MatrixType::scalar_type> STS;
678 
680  typedef Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type> MV;
681 
684 
686  Chebyshev<MatrixType>& operator= (const Chebyshev<MatrixType>&);
687 
695  void
696  applyImpl (const MV& X,
697  MV& Y,
698  Teuchos::ETransp mode,
699  scalar_type alpha,
700  scalar_type beta) const;
701 
703 
704 
713 
715  bool IsInitialized_;
717  bool IsComputed_;
719  int NumInitialize_;
721  int NumCompute_;
726  mutable int NumApply_;
728  double InitializeTime_;
730  double ComputeTime_;
735  mutable double ApplyTime_;
737  double ComputeFlops_;
742  mutable double ApplyFlops_;
743 
745 }; // class Chebyshev
746 
747 
748 template <typename MatrixType>
749 template <typename NewMatrixType>
750 Teuchos::RCP<Chebyshev<Tpetra::RowMatrix<typename NewMatrixType::scalar_type, typename NewMatrixType::local_ordinal_type, typename NewMatrixType::global_ordinal_type, typename NewMatrixType::node_type> > >
752 clone (const Teuchos::RCP<const NewMatrixType>& A_newnode,
753  const Teuchos::ParameterList& params) const
754 {
755  using Teuchos::RCP;
756  typedef Tpetra::RowMatrix<typename NewMatrixType::scalar_type,
757  typename NewMatrixType::local_ordinal_type,
758  typename NewMatrixType::global_ordinal_type,
759  typename NewMatrixType::node_type> new_row_matrix_type;
760  typedef Ifpack2::Chebyshev<new_row_matrix_type> new_prec_type;
761 
762  RCP<new_prec_type> prec (new new_prec_type (A_newnode));
763  prec->setParameters (params);
764  prec->initialize ();
765  prec->compute ();
766  return prec;
767 }
768 
769 } // namespace Ifpack2
770 
771 #endif // IFPACK2_CHEBYSHEV_DECL_HPP
772 
Mix-in interface for preconditioners that can change their matrix after construction.
Definition: Ifpack2_Details_CanChangeMatrix.hpp:93
double getApplyFlops() const
The total number of floating-point operations taken by all calls to apply().
Definition: Ifpack2_Chebyshev_def.hpp:210
Teuchos::RCP< const Tpetra::CrsMatrix< scalar_type, local_ordinal_type, global_ordinal_type, node_type > > getCrsMatrix() const
Attempt to return the matrix A as a Tpetra::CrsMatrix.
Definition: Ifpack2_Chebyshev_def.hpp:126
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition: Ifpack2_Chebyshev_decl.hpp:223
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition: Ifpack2_Chebyshev_decl.hpp:217
double getApplyTime() const
The total time spent in all calls to apply().
Definition: Ifpack2_Chebyshev_def.hpp:198
virtual void setMatrix(const Teuchos::RCP< const row_matrix_type > &A)
Change the matrix to be preconditioned.
Definition: Ifpack2_Chebyshev_def.hpp:80
void setParameters(const Teuchos::ParameterList &params)
Set (or reset) parameters.
Definition: Ifpack2_Chebyshev_def.hpp:92
double getComputeTime() const
The total time spent in all calls to compute().
Definition: Ifpack2_Chebyshev_def.hpp:192
int getNumApply() const
The total number of successful calls to apply().
Definition: Ifpack2_Chebyshev_def.hpp:180
MatrixType::node_type node_type
The Node type used by the input MatrixType.
Definition: Ifpack2_Chebyshev_decl.hpp:226
Tpetra::Vector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > vector_type
The Tpetra::Vector specialization matching MatrixType.
Definition: Ifpack2_Chebyshev_decl.hpp:248
bool isInitialized() const
Definition: Ifpack2_Chebyshev_decl.hpp:432
void compute()
(Re)compute the left scaling, and (if applicable) estimate max and min eigenvalues of D_inv * A...
Definition: Ifpack2_Chebyshev_def.hpp:292
bool hasTransposeApply() const
Whether it&#39;s possible to apply the transpose of this operator.
Definition: Ifpack2_Chebyshev_def.hpp:162
Teuchos::RCP< Chebyshev< Tpetra::RowMatrix< typename NewMatrixType::scalar_type, typename NewMatrixType::local_ordinal_type, typename NewMatrixType::global_ordinal_type, typename NewMatrixType::node_type > > > clone(const Teuchos::RCP< const NewMatrixType > &A_newnode, const Teuchos::ParameterList &params) const
Clone this object to one with a different Node type.
Definition: Ifpack2_Chebyshev_decl.hpp:752
double getComputeFlops() const
The total number of floating-point operations taken by all calls to compute().
Definition: Ifpack2_Chebyshev_def.hpp:204
Diagonally scaled Chebyshev iteration for Tpetra sparse matrices.
Definition: Ifpack2_Chebyshev_decl.hpp:199
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 preconditioner to X, returning the result in Y.
Definition: Ifpack2_Chebyshev_def.hpp:218
Interface for all Ifpack2 preconditioners.
Definition: Ifpack2_Preconditioner.hpp:107
bool isComputed() const
Definition: Ifpack2_Chebyshev_decl.hpp:479
std::string description() const
A simple one-line description of this object.
Definition: Ifpack2_Chebyshev_def.hpp:319
void initialize()
Initialize the preconditioner.
Definition: Ifpack2_Chebyshev_def.hpp:277
Declaration of interface for preconditioners that can change their matrix after construction.
Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type > map_type
The Tpetra::Map specialization matching MatrixType.
Definition: Ifpack2_Chebyshev_decl.hpp:238
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
The communicator over which the matrix is distributed.
Definition: Ifpack2_Chebyshev_def.hpp:101
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition: Ifpack2_Chebyshev_decl.hpp:220
int getNumInitialize() const
The total number of successful calls to initialize().
Definition: Ifpack2_Chebyshev_def.hpp:168
Tpetra::RowMatrix< scalar_type, local_ordinal_type, global_ordinal_type, node_type > row_matrix_type
The Tpetra::RowMatrix specialization matching MatrixType.
Definition: Ifpack2_Chebyshev_decl.hpp:235
double getInitializeTime() const
The total time spent in all calls to initialize().
Definition: Ifpack2_Chebyshev_def.hpp:186
MatrixType::scalar_type getLambdaMaxForApply() const
The estimate of the maximum eigenvalue used in the apply().
Definition: Ifpack2_Chebyshev_def.hpp:511
Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitude_type
The type of the magnitude (absolute value) of a matrix entry.
Definition: Ifpack2_Chebyshev_decl.hpp:229
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to a Teuchos::FancyOStream.
Definition: Ifpack2_Chebyshev_def.hpp:348
Teuchos::RCP< const row_matrix_type > getMatrix() const
The matrix for which this is a preconditioner.
Definition: Ifpack2_Chebyshev_def.hpp:115
Teuchos::RCP< const map_type > getDomainMap() const
The Tpetra::Map representing the domain of this operator.
Definition: Ifpack2_Chebyshev_def.hpp:136
MatrixType matrix_type
The template parameter of this class.
Definition: Ifpack2_Chebyshev_decl.hpp:214
virtual ~Chebyshev()
Destructor.
Definition: Ifpack2_Chebyshev_def.hpp:75
Preconditioners and smoothers for Tpetra sparse matrices.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:72
Teuchos::RCP< const map_type > getRangeMap() const
The Tpetra::Map representing the range of this operator.
Definition: Ifpack2_Chebyshev_def.hpp:150
int getNumCompute() const
The total number of successful calls to compute().
Definition: Ifpack2_Chebyshev_def.hpp:174
void applyMat(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) const
Compute Y = Op(A)*X, where Op(A) is either A, , or .
Definition: Ifpack2_Chebyshev_def.hpp:258