Ifpack2 Templated Preconditioning Package Version 1.0
Ifpack2_Diagonal_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_DIAGONAL_DECL_HPP
00031 #define IFPACK2_DIAGONAL_DECL_HPP
00032 
00033 #include "Ifpack2_Preconditioner.hpp"
00034 
00035 namespace Ifpack2 {
00036 
00038 
00054 template<class MatrixType>
00055 class Diagonal : virtual public Ifpack2::Preconditioner<typename MatrixType::scalar_type,typename MatrixType::local_ordinal_type,typename MatrixType::global_ordinal_type,typename MatrixType::node_type> {
00056 
00057 public:
00058   typedef typename MatrixType::scalar_type Scalar;
00059   typedef typename MatrixType::local_ordinal_type LocalOrdinal;
00060   typedef typename MatrixType::global_ordinal_type GlobalOrdinal;
00061   typedef typename MatrixType::node_type Node;
00062   typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType magnitudeType;
00063 
00065   Diagonal(const Teuchos::RCP<const MatrixType>& A);
00066 
00068 
00076   Diagonal(const Teuchos::RCP<const Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >& diag);
00077 
00078 public:
00080   virtual ~Diagonal();
00081 
00083 
00086   void setParameters(const Teuchos::ParameterList& params);
00087 
00089   void initialize();
00090 
00092   inline bool isInitialized() const {
00093     return(isInitialized_);
00094   }
00095 
00097   void compute();
00098 
00100   inline bool isComputed() const {
00101     return(isComputed_);
00102   }
00103 
00105 
00106 
00108 
00118   void apply(const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& X,
00119              Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Y,
00120              Teuchos::ETransp mode = Teuchos::NO_TRANS,
00121                  Scalar alpha = Teuchos::ScalarTraits<Scalar>::one(),
00122                  Scalar beta = Teuchos::ScalarTraits<Scalar>::zero()) const;
00123 
00125   const Teuchos::RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >& getDomainMap() const
00126   { return domainMap_; }
00127 
00129   const Teuchos::RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >& getRangeMap() const
00130   { return rangeMap_; }
00131 
00133 
00139   void applyMat(const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& X,
00140                 Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Y,
00141                 Teuchos::ETransp mode = Teuchos::NO_TRANS) const;
00142 
00144 
00145 
00147 
00148 
00150   magnitudeType computeCondEst(CondestType CT = Cheap,
00151                                LocalOrdinal MaxIters = 1550,
00152                                magnitudeType Tol = 1e-9,
00153                                const Teuchos::Ptr<const Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &matrix = Teuchos::null);
00154 
00156 
00158 
00159 
00161   magnitudeType getCondEst() const
00162   { return condEst_; }
00163 
00165   const Teuchos::RCP<const Teuchos::Comm<int> > & getComm() const;
00166 
00168   Teuchos::RCP<const Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > getMatrix() const
00169   { return matrix_; }
00170 
00172   double getComputeFlops() const;
00173 
00175   double getApplyFlops() const;
00176 
00178   int getNumInitialize() const;
00179 
00181   int getNumCompute() const;
00182 
00184   int getNumApply() const;
00185 
00187   double getInitializeTime() const;
00188 
00190   double getComputeTime() const;
00191 
00193   double getApplyTime() const;
00194 
00196 
00198 
00199 
00201   std::string description() const;
00202 
00204   void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const;
00205 
00207 
00208   private:
00209     bool isInitialized_;
00210     bool isComputed_;
00211     Teuchos::RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > domainMap_;
00212     Teuchos::RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > rangeMap_;
00213     Teuchos::RCP<const MatrixType> matrix_;
00214     Teuchos::RCP<const Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > inversediag_;
00215 
00216     mutable int numInitialize_;
00217     mutable int numCompute_;
00218     mutable int numApply_;
00219 
00220     double initializeTime_;
00221     double computeTime_;
00222     double applyTime_;
00223 
00224     magnitudeType condEst_;
00225 };
00226 
00241 template<class MatrixType,class VectorType>
00242 Teuchos::RCP<Ifpack2::Diagonal<MatrixType> >
00243 createDiagonalPreconditioner(const Teuchos::RCP<const VectorType>& invdiag)
00244 {
00245   return Teuchos::rcp(new Ifpack2::Diagonal<MatrixType>(invdiag));
00246 }
00247 
00248 }//namespace Ifpack2
00249 
00250 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends