Ifpack2 Templated Preconditioning Package Version 1.0
Ifpack2_BlockRelaxation_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_BLOCKRELAXATION_DECL_HPP
00031 #define IFPACK2_BLOCKRELAXATION_DECL_HPP
00032 
00033 #include "Ifpack2_ConfigDefs.hpp"
00034 #include "Ifpack2_Preconditioner.hpp"
00035 #include "Ifpack2_Condest.hpp"
00036 #include "Ifpack2_Parameters.hpp"
00037 #include "Ifpack2_Partitioner.hpp"
00038 
00039 #include <Tpetra_Vector.hpp>
00040 
00041 #include <Teuchos_Assert.hpp>
00042 #include <Teuchos_RCP.hpp>
00043 #include <Teuchos_Time.hpp>
00044 #include <Teuchos_TypeNameTraits.hpp>
00045 #include <Teuchos_ScalarTraits.hpp>
00046 
00047 #include <string>
00048 #include <iostream>
00049 #include <sstream>
00050 
00051 namespace Teuchos {
00052   // forward declaration
00053   class ParameterList;
00054 }
00055 
00056 namespace Ifpack2 {
00057 enum RelaxationType {
00058   JACOBI,
00059   GS,
00060   SGS
00061 };
00062 
00064 
00123 template<class MatrixType,class ContainerType>
00124 class BlockRelaxation : virtual public Ifpack2::Preconditioner<typename MatrixType::scalar_type,typename MatrixType::local_ordinal_type,typename MatrixType::global_ordinal_type,typename MatrixType::node_type> {
00125 
00126 public:
00127   typedef typename MatrixType::scalar_type         Scalar;
00128   typedef typename MatrixType::local_ordinal_type  LocalOrdinal;
00129   typedef typename MatrixType::global_ordinal_type GlobalOrdinal;
00130   typedef typename MatrixType::node_type           Node;
00131   typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType magnitudeType;
00132 
00133   // \name Constructors and Destructors
00135 
00137   explicit BlockRelaxation(const Teuchos::RCP<const Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >& Matrix);
00138 
00140   virtual ~BlockRelaxation();
00141 
00143 
00145 
00147 
00164   void setParameters(const Teuchos::ParameterList& params);
00165 
00167   void initialize();
00168 
00170   inline bool isInitialized() const {
00171     return(IsInitialized_);
00172   }
00173 
00175   void compute();
00176 
00178   inline bool isComputed() const {
00179     return(IsComputed_);
00180   }
00181 
00183 
00185 
00186 
00188 
00198   void apply(const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& X,
00199              Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Y,
00200              Teuchos::ETransp mode = Teuchos::NO_TRANS,
00201        Scalar alpha = Teuchos::ScalarTraits<Scalar>::one(),
00202        Scalar beta = Teuchos::ScalarTraits<Scalar>::zero()) const;
00203 
00205   const Teuchos::RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >& getDomainMap() const;
00206 
00208   const Teuchos::RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >& getRangeMap() const;
00209 
00210   bool hasTransposeApply() const;
00211 
00213 
00219   void applyMat(const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& X,
00220                 Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Y,
00221                 Teuchos::ETransp mode = Teuchos::NO_TRANS) const;
00222 
00224 
00226 
00227 
00229   magnitudeType computeCondEst(CondestType CT = Cheap, 
00230                                LocalOrdinal MaxIters = 1550,
00231                                magnitudeType Tol = 1e-9,
00232                                const Teuchos::Ptr<const Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &matrix = Teuchos::null);
00233 
00235 
00237 
00238 
00240   magnitudeType getCondEst() const;
00241 
00243   const Teuchos::RCP<const Teuchos::Comm<int> > & getComm() const;
00244 
00246   Teuchos::RCP<const Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > getMatrix() const;
00247 
00249   double getComputeFlops() const;
00250 
00252   double getApplyFlops() const;
00253 
00255   int getNumInitialize() const;
00256 
00258   int getNumCompute() const;
00259 
00261   int getNumApply() const;
00262 
00264   double getInitializeTime() const;
00265 
00267   double getComputeTime() const;
00268 
00270   double getApplyTime() const;
00271 
00273 
00275 
00276 
00278   std::string description() const;
00279 
00281   void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const;
00282 
00284 
00285 private:
00286 
00287   // @{ Internal methods
00288 
00290   BlockRelaxation(const BlockRelaxation<MatrixType,ContainerType> & RHS);
00291 
00293   BlockRelaxation<MatrixType,ContainerType>& operator=(const BlockRelaxation<MatrixType,ContainerType>& RHS);
00294 
00295   virtual void ApplyInverseJacobi(const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& X, 
00296           Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Y) const;
00297 
00298   virtual void DoJacobi(const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& X, 
00299       Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Y) const;
00300 
00301   virtual void ApplyInverseGS(const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& X, 
00302             Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Y) const;
00303 
00304   virtual void DoGaussSeidel(Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& X, 
00305            Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Y) const;
00306 
00307   virtual void ApplyInverseSGS(const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& X, 
00308              Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Y) const;
00309 
00310   virtual void DoSGS(const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& X,
00311          Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Xtmp,
00312          Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Y) const;
00313  
00314   void ExtractSubmatrices();
00315 
00317 
00318   // @{ Internal data and parameters
00319 
00321   const Teuchos::RCP<const Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > A_;
00323   Teuchos::RCP<Teuchos::Time> Time_;
00325   Teuchos::RCP<const Tpetra::Import<LocalOrdinal,GlobalOrdinal,Node> > Importer_;
00326 
00328   Teuchos::RCP<Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > W_;
00329   // Level of overlap among blocks (for overlapped Jacobi only).
00330   int OverlapLevel_;
00332   mutable std::vector<Teuchos::RCP<ContainerType> > Containers_;
00334   Teuchos::RCP<Ifpack2::Partitioner<Tpetra::RowGraph<LocalOrdinal,GlobalOrdinal,Node> > > Partitioner_;
00335   std::string PartitionerType_;
00336 
00338   Teuchos::ParameterList List_;
00339 
00341   int NumSweeps_;
00343   LocalOrdinal NumLocalBlocks_;
00345   int PrecType_;
00347   Scalar MinDiagonalValue_;
00349   Scalar DampingFactor_;
00351   bool IsParallel_;
00353   bool ZeroStartingSolution_;
00355   bool DoBackwardGS_;
00357   magnitudeType Condest_;
00359   bool IsInitialized_;
00361   bool IsComputed_;
00363   int NumInitialize_;
00365   int NumCompute_;
00367   mutable int NumApply_;
00369   double InitializeTime_;
00371   double ComputeTime_;
00373   mutable double ApplyTime_;
00375   double ComputeFlops_;
00377   mutable double ApplyFlops_;
00379   size_t NumMyRows_;
00381   global_size_t NumGlobalRows_;
00383   global_size_t NumGlobalNonzeros_;
00384 
00386 
00387 }; //class BlockRelaxation
00388 
00389 }//namespace Ifpack2
00390 
00391 #endif // IFPACK2_BLOCKRELAXATION_DECL_HPP
00392 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends