Ifpack2 Templated Preconditioning Package Version 1.0
Ifpack2_Chebyshev_decl.hpp
00001 /*@HEADER
00002 // ***********************************************************************
00003 //
00004 //       Ifpack2: Tempated Object-Oriented Algebraic Preconditioner Package
00005 //                 Copyright (2009) Sandia Corporation
00006 //
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 //
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00025 //
00026 // ***********************************************************************
00027 //@HEADER
00028 */
00029 
00030 #ifndef IFPACK2_CHEBYSHEV_DECL_HPP
00031 #define IFPACK2_CHEBYSHEV_DECL_HPP
00032 
00033 
00034 #include "Ifpack2_ConfigDefs.hpp"
00035 #include "Ifpack2_Preconditioner.hpp"
00036 #include "Ifpack2_Condest.hpp"
00037 #include "Ifpack2_Parameters.hpp"
00038 
00039 #include <Tpetra_CrsMatrix.hpp>
00040 #include <Tpetra_Vector.hpp>
00041 
00042 #include <Teuchos_Assert.hpp>
00043 #include <Teuchos_RCP.hpp>
00044 #include <Teuchos_Time.hpp>
00045 #include <Teuchos_TypeNameTraits.hpp>
00046 #include <Teuchos_ScalarTraits.hpp>
00047 
00048 #include <iostream>
00049 #include <string>
00050 #include <sstream>
00051 
00052 namespace Teuchos {
00053   // forward declaration
00054   class ParameterList;
00055 }
00056 
00057 namespace Ifpack2 {
00058 
00060 
00079 template<class MatrixType>
00080 class Chebyshev : virtual public Ifpack2::Preconditioner<typename MatrixType::scalar_type,typename MatrixType::local_ordinal_type,typename MatrixType::global_ordinal_type,typename MatrixType::node_type> {
00081 
00082 public:
00083   typedef typename MatrixType::scalar_type Scalar;
00084   typedef typename MatrixType::local_ordinal_type LocalOrdinal;
00085   typedef typename MatrixType::global_ordinal_type GlobalOrdinal;
00086   typedef typename MatrixType::node_type Node;
00087   typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType magnitudeType;
00088 
00089   // \name Constructors and Destructors
00091 
00093   explicit Chebyshev(const Teuchos::RCP<const Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >& A);
00094 
00096   virtual ~Chebyshev();
00097 
00099 
00101 
00103 
00123   void setParameters(const Teuchos::ParameterList& params);
00124 
00126   void initialize();
00127 
00129   inline bool isInitialized() const {
00130     return(IsInitialized_);
00131   }
00132 
00134   void compute();
00135 
00137   inline bool isComputed() const {
00138     return(IsComputed_);
00139   }
00140 
00142 
00144 
00145 
00147 
00153   void apply(const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& X,
00154                    Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Y,
00155                    Teuchos::ETransp mode = Teuchos::NO_TRANS,
00156                  Scalar alpha = Teuchos::ScalarTraits<Scalar>::one(),
00157                  Scalar beta = Teuchos::ScalarTraits<Scalar>::zero()) const;
00158 
00160   const Teuchos::RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >& getDomainMap() const;
00161 
00163   const Teuchos::RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >& getRangeMap() const;
00164 
00165   bool hasTransposeApply() const;
00166 
00168 
00174   void applyMat(const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& X,
00175                       Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Y,
00176                       Teuchos::ETransp mode = Teuchos::NO_TRANS) const;
00177 
00179 
00181 
00182 
00184   magnitudeType computeCondEst(CondestType CT = Cheap, 
00185                                LocalOrdinal MaxIters = 1550,
00186                                magnitudeType Tol = 1e-9,
00187                                const Teuchos::Ptr<const Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &matrix = Teuchos::null);
00188 
00190 
00192 
00193 
00195   magnitudeType getCondEst() const;
00196 
00198   const Teuchos::RCP<const Teuchos::Comm<int> > & getComm() const;
00199 
00201   Teuchos::RCP<const Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > getMatrix() const;
00202 
00204   double getComputeFlops() const;
00205 
00207   double getApplyFlops() const;
00208 
00210   int getNumInitialize() const;
00211 
00213   int getNumCompute() const;
00214 
00216   int getNumApply() const;
00217 
00219   double getInitializeTime() const;
00220 
00222   double getComputeTime() const;
00223 
00225   double getApplyTime() const;
00226 
00228 
00230 
00231 
00233   std::string description() const;
00234 
00236   void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const;
00237 
00239 
00240   // @{ \name Utility methods
00241 
00243   static void PowerMethod(const Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Operator,
00244                          const Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& InvPointDiagonal,
00245                          const int MaximumIterations, 
00246                          Scalar& LambdaMax);
00247 
00249   static void CG(const Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Operator, 
00250                 const Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& InvPointDiagonal, 
00251                 const int MaximumIterations, 
00252                 Scalar& lambda_min, Scalar& lambda_max);
00253 
00255 
00256 private:
00257   
00259   Chebyshev(const Chebyshev<MatrixType>& src);
00260 
00262   Chebyshev<MatrixType>& operator=(const Chebyshev<MatrixType>& src);
00263 
00264   // @{ Internal data and parameters
00265 
00267   const Teuchos::RCP<const Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > A_;
00269   const Teuchos::RCP<const Teuchos::Comm<int> > Comm_;
00271   mutable Teuchos::RCP<Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > InvDiagonal_;
00273   Teuchos::RCP<Teuchos::Time> Time_;
00275   int PolyDegree_;
00277   magnitudeType EigRatio_;
00279   Scalar LambdaMin_;
00281   Scalar LambdaMax_;
00283   Scalar MinDiagonalValue_;
00286   bool ZeroStartingSolution_;
00287   magnitudeType Condest_;
00289   bool IsInitialized_;
00291   bool IsComputed_;
00293   int NumInitialize_;
00295   int NumCompute_;
00297   mutable int NumApply_;
00299   double InitializeTime_;
00301   double ComputeTime_;
00303   mutable double ApplyTime_;
00305   double ComputeFlops_;
00307   mutable double ApplyFlops_;
00309   size_t NumMyRows_;
00311   global_size_t NumGlobalRows_;
00313   global_size_t NumGlobalNonzeros_;
00314 
00316 
00317 }; // class Chebyshev
00318 
00319 }//namespace Ifpack2
00320 
00321 #endif // IFPACK2_CHEBYSHEV_DECL_HPP
00322 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends