Ifpack2 Templated Preconditioning Package Version 1.0
Ifpack2_Krylov_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 //-----------------------------------------------------
00031 // Ifpack2::KRYLOV is based on the Krylov iterative
00032 // solvers in Belos.
00033 // written by Paul Tsuji.
00034 //-----------------------------------------------------
00035 
00036 #ifndef IFPACK2_KRYLOV_DECL_HPP
00037 #define IFPACK2_KRYLOV_DECL_HPP
00038 
00039 #include "Ifpack2_ConfigDefs.hpp"
00040 #include "Ifpack2_Preconditioner.hpp"
00041 #include "Ifpack2_Condest.hpp"
00042 #include "Ifpack2_Heap.hpp"
00043 #include "Ifpack2_Parameters.hpp"
00044 
00045 #include <Tpetra_CrsMatrix.hpp>
00046 #include <Tpetra_Vector.hpp>
00047 
00048 #include <BelosConfigDefs.hpp>
00049 #include <BelosSolverFactory.hpp>
00050 #include <BelosSolverManager.hpp>
00051 #include <BelosLinearProblem.hpp>
00052 #include <BelosTpetraAdapter.hpp>
00053 #include <BelosBlockGmresSolMgr.hpp>
00054 #include <BelosBlockCGSolMgr.hpp>
00055 
00056 #include <Teuchos_Assert.hpp>
00057 #include <Teuchos_RCP.hpp>
00058 #include <Teuchos_Time.hpp>
00059 #include <Teuchos_TypeNameTraits.hpp>
00060 #include <Teuchos_ScalarTraits.hpp>
00061 
00062 #include <iostream>
00063 #include <string>
00064 #include <sstream>
00065 
00066 
00067 #include <string>
00068 #include <sstream>
00069 #include <iostream>
00070 #include <cmath>
00071 
00072 namespace Teuchos {
00073   // forward declaration
00074   class ParameterList;
00075 }
00076 
00077 namespace Ifpack2 {
00078 
00080   /*
00081    * This exists to allow a ScalarType to override what scalar type is used
00082    * for Belos, if those are not equal, by specializing this class.
00083    */
00084   template <typename ScalarType>
00085   struct BelosScalarType {
00086     typedef ScalarType type;
00087   };
00088   
00090   // for a given Tpetra::RowMatrix.
00091   
00097   template<class MatrixType,class PrecType>
00098   class Krylov: virtual public Ifpack2::Preconditioner<typename MatrixType::scalar_type,typename MatrixType::local_ordinal_type,typename MatrixType::global_ordinal_type,typename MatrixType::node_type> {
00099     
00100   public:
00101     // \name Typedefs
00103     
00105     typedef typename MatrixType::scalar_type scalar_type;
00106 
00108     typedef typename BelosScalarType<scalar_type>::type belos_scalar_type;
00109     
00111     TEUCHOS_DEPRECATED typedef typename MatrixType::scalar_type Scalar;
00112     
00113     
00115     typedef typename MatrixType::local_ordinal_type local_ordinal_type;
00116     
00118     TEUCHOS_DEPRECATED typedef typename MatrixType::local_ordinal_type LocalOrdinal;
00119     
00120 
00122     typedef typename MatrixType::global_ordinal_type global_ordinal_type;
00123     
00125     TEUCHOS_DEPRECATED typedef typename MatrixType::global_ordinal_type GlobalOrdinal;
00126     
00127     
00129     typedef typename MatrixType::node_type node_type;
00130     
00132     TEUCHOS_DEPRECATED typedef typename MatrixType::node_type Node;
00133 
00134 
00136     typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
00137     
00139     TEUCHOS_DEPRECATED typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitudeType;
00140 
00142     // \name Constructors and Destructors
00144     
00146     explicit Krylov(const Teuchos::RCP<const Tpetra::RowMatrix<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > &A);
00147     
00149     virtual ~Krylov();
00150     
00152 
00153 
00154 
00163     void setParameters(const Teuchos::ParameterList& params);
00164     
00166 
00168     void initialize();
00169     
00171     inline bool isInitialized() const {
00172       return(IsInitialized_);
00173     }
00174     
00176 
00183     void compute();
00184     
00186     inline bool isComputed() const {
00187       return(IsComputed_);
00188     }
00189 
00191 
00193 
00194     
00196 
00202     void apply(
00203          const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
00204          Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
00205          Teuchos::ETransp mode = Teuchos::NO_TRANS,
00206          scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
00207          scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
00208     
00210     const Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> >& getDomainMap() const;
00211     
00213     const Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> >& getRangeMap() const;
00214     
00216     bool hasTransposeApply() const;
00217     
00219     magnitude_type getCondEst() const { return Condest_; }
00220 
00222 
00224 
00225     
00227     const Teuchos::RCP<const Teuchos::Comm<int> > & getComm() const;
00228 
00230     Teuchos::RCP<const Tpetra::RowMatrix<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > getMatrix() const;
00231     
00233     int getNumInitialize() const;
00234     
00236     int getNumCompute() const;
00237 
00239     int getNumApply() const;
00240     
00242     double getInitializeTime() const;
00243 
00245     double getComputeTime() const;
00246     
00248     double getApplyTime() const;
00249 
00251     magnitude_type computeCondEst(CondestType CT = Cheap,
00252           local_ordinal_type MaxIters = 1550,
00253           magnitude_type Tol = 1e-9,
00254           const Teuchos::Ptr<const Tpetra::RowMatrix<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > &Matrix_in = Teuchos::null);
00255     
00257 
00258     
00260     std::string description() const;
00261     
00263     void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const;
00264     
00266     
00267   private:
00268     
00269     // @{ Internal methods
00270     
00272     Krylov(const Krylov<MatrixType,PrecType>& RHS);
00273     
00275     Krylov<MatrixType,PrecType>& operator=(const Krylov<MatrixType,PrecType>& RHS);
00276     
00278     
00279     // @{ Internal data and parameters
00280     
00282     const Teuchos::RCP<const Tpetra::RowMatrix<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > A_;
00284     const Teuchos::RCP<const Teuchos::Comm<int> > Comm_;
00285 
00288     // 1 for GMRES (default)
00289     // 2 for CG
00290     int IterationType_;
00292     int Iterations_;
00294     magnitude_type ResidualTolerance_;
00296     int BlockSize_;
00298     bool ZeroStartingSolution_;
00300     // 1 for relaxation (default)
00301     // 2 for ILUT
00302     // 3 for Chebyshev
00303     int PreconditionerType_;
00305     Teuchos::ParameterList params_;
00306 
00308     magnitude_type Condest_;
00310     bool IsInitialized_;
00312     bool IsComputed_;
00314     int NumInitialize_;
00316     int NumCompute_;
00318     mutable int NumApply_;
00320     double InitializeTime_;
00322     double ComputeTime_;
00324     mutable double ApplyTime_;
00326     mutable Teuchos::Time Time_;
00328     local_ordinal_type NumMyRows_;
00330     global_size_t NumGlobalNonzeros_;
00331     
00333     Teuchos::RCP< Belos::LinearProblem<belos_scalar_type,
00334                Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>,
00335                Tpetra::Operator<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > > belosProblem_;
00336     Teuchos::RCP< Belos::SolverManager<belos_scalar_type,
00337                Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>,
00338                Tpetra::Operator<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > > belosSolver_;
00339     Teuchos::RCP<Teuchos::ParameterList> belosList_;
00340     Teuchos::RCP<PrecType> ifpack2_prec_;
00341 
00343 
00344 }; // class Krylov
00345 
00346 }//namespace Ifpack2
00347 
00348 #endif /* IFPACK2_KRYLOV_HPP */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends