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 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00038 //
00039 // ***********************************************************************
00040 //@HEADER
00041 */
00042 
00043 #ifndef IFPACK2_DIAGONAL_DECL_HPP
00044 #define IFPACK2_DIAGONAL_DECL_HPP
00045 
00046 #include <Ifpack2_Preconditioner.hpp>
00047 #include <Ifpack2_Details_CanChangeMatrix.hpp>
00048 #include <Tpetra_CrsMatrix_decl.hpp>
00049 
00050 namespace Ifpack2 {
00051 
00053 
00069 template<class MatrixType>
00070 class Diagonal :
00071     virtual public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
00072                                            typename MatrixType::local_ordinal_type,
00073                                            typename MatrixType::global_ordinal_type,
00074                                            typename MatrixType::node_type>,
00075     virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
00076                                                                        typename MatrixType::local_ordinal_type,
00077                                                                        typename MatrixType::global_ordinal_type,
00078                                                                        typename MatrixType::node_type> >
00079 {
00080 public:
00081   typedef TEUCHOS_DEPRECATED typename MatrixType::scalar_type Scalar;
00082   typedef TEUCHOS_DEPRECATED typename MatrixType::local_ordinal_type LocalOrdinal;
00083   typedef TEUCHOS_DEPRECATED typename MatrixType::global_ordinal_type GlobalOrdinal;
00084   typedef TEUCHOS_DEPRECATED typename MatrixType::node_type Node;
00085   typedef TEUCHOS_DEPRECATED typename Teuchos::ScalarTraits<typename MatrixType::scalar_type>::magnitudeType magnitudeType;
00086 
00087   typedef typename MatrixType::scalar_type scalar_type;
00088   typedef typename MatrixType::local_ordinal_type local_ordinal_type;
00089   typedef typename MatrixType::global_ordinal_type global_ordinal_type;
00090   typedef typename MatrixType::node_type node_type;
00091   typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
00092 
00094   typedef Tpetra::RowMatrix<scalar_type,
00095                             local_ordinal_type,
00096                             global_ordinal_type,
00097                             node_type> row_matrix_type;
00099   typedef Tpetra::CrsMatrix<scalar_type,
00100                             local_ordinal_type,
00101                             global_ordinal_type,
00102                             node_type> crs_matrix_type;
00104   typedef Tpetra::Vector<scalar_type,
00105                          local_ordinal_type,
00106                          global_ordinal_type,
00107                          node_type> vector_type;
00109   typedef Tpetra::Map<local_ordinal_type,
00110                       global_ordinal_type,
00111                       node_type> map_type;
00112 
00116   Diagonal (const Teuchos::RCP<const row_matrix_type>& A);
00117 
00125   Diagonal (const Teuchos::RCP<const crs_matrix_type>& A_in);
00126 
00138   Diagonal (const Teuchos::RCP<const vector_type>& diag);
00139 
00141   virtual ~Diagonal();
00142 
00144 
00147   void setParameters (const Teuchos::ParameterList& params);
00148 
00150   void initialize();
00151 
00153   inline bool isInitialized() const {
00154     return isInitialized_;
00155   }
00156 
00158   void compute();
00159 
00161   inline bool isComputed() const {
00162     return(isComputed_);
00163   }
00164 
00166 
00167 
00168 
00191   virtual void
00192   setMatrix (const Teuchos::RCP<const row_matrix_type>& A);
00193 
00195 
00196 
00197 
00203   void
00204   apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
00205          Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
00206          Teuchos::ETransp mode = Teuchos::NO_TRANS,
00207          scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
00208          scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
00209 
00211   Teuchos::RCP<const map_type> getDomainMap () const;
00212 
00214   Teuchos::RCP<const map_type> getRangeMap () const;
00215 
00217 
00218 
00219 
00229   magnitude_type TEUCHOS_DEPRECATED
00230   computeCondEst (CondestType CT = Cheap,
00231                   local_ordinal_type MaxIters = 1550,
00232                   magnitude_type Tol = 1e-9,
00233                   const Teuchos::Ptr<const Tpetra::RowMatrix<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > &matrix = Teuchos::null);
00234 
00236 
00237 
00238 
00242   magnitude_type TEUCHOS_DEPRECATED getCondEst() const {
00243     return condEst_;
00244   }
00245 
00247   //Teuchos::RCP<const Teuchos::Comm<int> > getComm () const;
00248 
00254   Teuchos::RCP<const row_matrix_type> getMatrix () const {
00255     return matrix_;
00256   }
00257 
00259   double getComputeFlops() const;
00260 
00262   double getApplyFlops() const;
00263 
00265   int getNumInitialize() const;
00266 
00268   int getNumCompute() const;
00269 
00271   int getNumApply() const;
00272 
00274   double getInitializeTime() const;
00275 
00277   double getComputeTime() const;
00278 
00280   double getApplyTime() const;
00281 
00283 
00284 
00285 
00287   std::string description() const;
00288 
00290   void
00291   describe (Teuchos::FancyOStream& out,
00292             const Teuchos::EVerbosityLevel verbLevel =
00293             Teuchos::Describable::verbLevel_default) const;
00295 
00296 private:
00298   void reset ();
00299 
00301   Teuchos::RCP<const row_matrix_type> matrix_;
00302 
00307   Teuchos::RCP<const vector_type> userInverseDiag_;
00308 
00310   Teuchos::RCP<const vector_type> inverseDiag_;
00311   Teuchos::ArrayRCP<size_t> offsets_;
00312 
00313   double initializeTime_;
00314   double computeTime_;
00315   mutable double applyTime_;
00316 
00317   int numInitialize_;
00318   int numCompute_;
00319   mutable int numApply_;
00320 
00321   magnitude_type condEst_;
00322   bool isInitialized_;
00323   bool isComputed_;
00324 };
00325 
00340 template<class MatrixType,class VectorType>
00341 Teuchos::RCP<Ifpack2::Diagonal<MatrixType> >
00342 createDiagonalPreconditioner(const Teuchos::RCP<const VectorType>& invdiag)
00343 {
00344   return Teuchos::rcp(new Ifpack2::Diagonal<MatrixType>(invdiag));
00345 }
00346 
00347 }//namespace Ifpack2
00348 
00349 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends