Ifpack2 Templated Preconditioning Package Version 1.0
Ifpack2_Relaxation_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_RELAXATION_DECL_HPP
00031 #define IFPACK2_RELAXATION_DECL_HPP
00032 
00033 #include "Ifpack2_ConfigDefs.hpp"
00034 #include "Ifpack2_Preconditioner.hpp"
00035 #include "Ifpack2_Condest.hpp"
00036 #include "Ifpack2_Parameters.hpp"
00037 
00038 #include <Tpetra_Vector.hpp>
00039 
00040 #include <Teuchos_Assert.hpp>
00041 #include <Teuchos_RCP.hpp>
00042 #include <Teuchos_Time.hpp>
00043 #include <Teuchos_TypeNameTraits.hpp>
00044 #include <Teuchos_ScalarTraits.hpp>
00045 
00046 #include <string>
00047 #include <iostream>
00048 #include <sstream>
00049 
00050 namespace Teuchos {
00051   // forward declaration
00052   class ParameterList;
00053 }
00054 
00055 namespace Ifpack2 {
00056 enum RelaxationType {
00057   JACOBI,
00058   GS,
00059   SGS
00060 };
00061 
00215 template<class MatrixType>
00216 class Relaxation :
00217   virtual public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
00218                                          typename MatrixType::local_ordinal_type,
00219                                          typename MatrixType::global_ordinal_type,
00220                                          typename MatrixType::node_type>
00221 {
00222 public:
00224 
00225 
00227   typedef typename MatrixType::scalar_type scalar_type;
00228 
00230   TEUCHOS_DEPRECATED typedef typename MatrixType::scalar_type Scalar;
00231 
00232 
00234   typedef typename MatrixType::local_ordinal_type local_ordinal_type;
00235 
00237   TEUCHOS_DEPRECATED typedef typename MatrixType::local_ordinal_type LocalOrdinal;
00238 
00239 
00241   typedef typename MatrixType::global_ordinal_type global_ordinal_type;
00242 
00244   TEUCHOS_DEPRECATED typedef typename MatrixType::global_ordinal_type GlobalOrdinal;
00245 
00246 
00248   typedef typename MatrixType::node_type node_type;
00249 
00251   TEUCHOS_DEPRECATED typedef typename MatrixType::node_type Node;
00252 
00253 
00255   typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
00256 
00258   TEUCHOS_DEPRECATED typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitudeType;
00259 
00261 
00262 
00263 
00297   explicit Relaxation(const Teuchos::RCP<const Tpetra::RowMatrix<scalar_type,local_ordinal_type,global_ordinal_type,node_type> >& Matrix);
00298 
00300   virtual ~Relaxation();
00301 
00303 
00304 
00305 
00361   void setParameters(const Teuchos::ParameterList& params);
00362 
00364   void initialize();
00365 
00367   inline bool isInitialized() const {
00368     return(IsInitialized_);
00369   }
00370 
00372   void compute();
00373 
00375   inline bool isComputed() const {
00376     return(IsComputed_);
00377   }
00378 
00380 
00381 
00382 
00398   void apply(const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
00399              Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
00400              Teuchos::ETransp mode = Teuchos::NO_TRANS,
00401                  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
00402                  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
00403 
00405   const Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> >& getDomainMap() const;
00406 
00408   const Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> >& getRangeMap() const;
00409 
00411   bool hasTransposeApply() const;
00412 
00425   void applyMat(const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
00426                 Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
00427                 Teuchos::ETransp mode = Teuchos::NO_TRANS) const;
00428 
00430 
00431 
00432 
00444   magnitude_type computeCondEst(CondestType CT = Cheap,
00445                                local_ordinal_type MaxIters = 1550,
00446                                magnitude_type Tol = 1e-9,
00447                                const Teuchos::Ptr<const Tpetra::RowMatrix<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > &matrix = Teuchos::null);
00448 
00450 
00451 
00452 
00456   magnitude_type getCondEst() const;
00457 
00459   const Teuchos::RCP<const Teuchos::Comm<int> > & getComm() const;
00460 
00462   Teuchos::RCP<const Tpetra::RowMatrix<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > getMatrix() const;
00463 
00465   double getComputeFlops() const;
00466 
00468   double getApplyFlops() const;
00469 
00471   int getNumInitialize() const;
00472 
00474   int getNumCompute() const;
00475 
00477   int getNumApply() const;
00478 
00480   double getInitializeTime() const;
00481 
00483   double getComputeTime() const;
00484 
00486   double getApplyTime() const;
00487 
00489 
00490 
00491 
00493   std::string description() const;
00494 
00496   void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const;
00497 
00499 
00500 private:
00501 
00503 
00504 
00506   Relaxation (const Relaxation<MatrixType>& RHS);
00507 
00509   Relaxation<MatrixType>& operator= (const Relaxation<MatrixType>& RHS);
00510 
00512 
00513 
00514 
00516   void ApplyInverseJacobi(
00517         const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
00518               Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
00519 
00521   void ApplyInverseGS(
00522         const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
00523               Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
00524 
00526   void ApplyInverseGS_RowMatrix(
00527         const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
00528               Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
00529 
00531   void ApplyInverseGS_CrsMatrix(
00532         const MatrixType& A,
00533         const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
00534               Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
00535 
00537   void ApplyInverseSGS(
00538         const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
00539               Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
00540 
00542   void ApplyInverseSGS_RowMatrix(
00543         const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
00544               Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
00545 
00547   void ApplyInverseSGS_CrsMatrix(
00548         const MatrixType& A,
00549         const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
00550               Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
00551 
00553 
00554 
00555 
00557   const Teuchos::RCP<const Tpetra::RowMatrix<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > A_;
00559   const Teuchos::RCP<const Teuchos::Comm<int> > Comm_;
00561   Teuchos::RCP<Teuchos::Time> Time_;
00563   Teuchos::RCP<const Tpetra::Import<local_ordinal_type,global_ordinal_type,node_type> > Importer_;
00565   mutable Teuchos::RCP<Tpetra::Vector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > Diagonal_;
00567   int NumSweeps_;
00569   int PrecType_;
00571   scalar_type MinDiagonalValue_;
00573   scalar_type DampingFactor_;
00575   bool IsParallel_;
00577   bool ZeroStartingSolution_;
00579   bool DoBackwardGS_;
00581   bool DoL1Method_;
00583   magnitude_type L1Eta_;
00585   magnitude_type Condest_;
00587   bool IsInitialized_;
00589   bool IsComputed_;
00591   int NumInitialize_;
00593   int NumCompute_;
00595   mutable int NumApply_;
00597   double InitializeTime_;
00599   double ComputeTime_;
00601   mutable double ApplyTime_;
00603   double ComputeFlops_;
00605   mutable double ApplyFlops_;
00607   size_t NumMyRows_;
00609   global_size_t NumGlobalRows_;
00611   global_size_t NumGlobalNonzeros_;
00612 
00614 
00615 }; //class Relaxation
00616 
00617 }//namespace Ifpack2
00618 
00619 #endif // IFPACK2_RELAXATION_DECL_HPP
00620 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends