Ifpack2 Templated Preconditioning Package  Version 1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
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 
00071 template<class MatrixType>
00072 class Diagonal :
00073     virtual public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
00074                                            typename MatrixType::local_ordinal_type,
00075                                            typename MatrixType::global_ordinal_type,
00076                                            typename MatrixType::node_type>,
00077     virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
00078                                                                        typename MatrixType::local_ordinal_type,
00079                                                                        typename MatrixType::global_ordinal_type,
00080                                                                        typename MatrixType::node_type> >
00081 {
00082 public:
00083   typedef typename MatrixType::scalar_type scalar_type;
00084   typedef typename MatrixType::local_ordinal_type local_ordinal_type;
00085   typedef typename MatrixType::global_ordinal_type global_ordinal_type;
00086   typedef typename MatrixType::node_type node_type;
00087   typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
00088 
00089   typedef TEUCHOS_DEPRECATED typename MatrixType::scalar_type Scalar;
00090   typedef TEUCHOS_DEPRECATED typename MatrixType::local_ordinal_type LocalOrdinal;
00091   typedef TEUCHOS_DEPRECATED typename MatrixType::global_ordinal_type GlobalOrdinal;
00092   typedef TEUCHOS_DEPRECATED typename MatrixType::node_type Node;
00093   typedef TEUCHOS_DEPRECATED typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitudeType;
00094 
00096   typedef Tpetra::RowMatrix<scalar_type,
00097                             local_ordinal_type,
00098                             global_ordinal_type,
00099                             node_type> row_matrix_type;
00101   typedef Tpetra::CrsMatrix<scalar_type,
00102                             local_ordinal_type,
00103                             global_ordinal_type,
00104                             node_type> crs_matrix_type;
00106   typedef Tpetra::Vector<scalar_type,
00107                          local_ordinal_type,
00108                          global_ordinal_type,
00109                          node_type> vector_type;
00111   typedef Tpetra::Map<local_ordinal_type,
00112                       global_ordinal_type,
00113                       node_type> map_type;
00114 
00118   Diagonal (const Teuchos::RCP<const row_matrix_type>& A);
00119 
00127   Diagonal (const Teuchos::RCP<const crs_matrix_type>& A_in);
00128 
00140   Diagonal (const Teuchos::RCP<const vector_type>& diag);
00141 
00143   virtual ~Diagonal ();
00144 
00146 
00149   void setParameters (const Teuchos::ParameterList& params);
00150 
00152   void initialize ();
00153 
00155   bool isInitialized () const {
00156     return isInitialized_;
00157   }
00158 
00160   void compute ();
00161 
00163   bool isComputed () const {
00164     return isComputed_;
00165   }
00166 
00168 
00169 
00170 
00193   virtual void
00194   setMatrix (const Teuchos::RCP<const row_matrix_type>& A);
00195 
00197 
00198 
00199 
00205   void
00206   apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
00207          Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
00208          Teuchos::ETransp mode = Teuchos::NO_TRANS,
00209          scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
00210          scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
00211 
00213   Teuchos::RCP<const map_type> getDomainMap () const;
00214 
00216   Teuchos::RCP<const map_type> getRangeMap () const;
00217 
00219 
00220 
00221 
00231   magnitude_type TEUCHOS_DEPRECATED
00232   computeCondEst (CondestType CT = Cheap,
00233                   local_ordinal_type MaxIters = 1550,
00234                   magnitude_type Tol = 1e-9,
00235                   const Teuchos::Ptr<const row_matrix_type>& matrix = Teuchos::null);
00236 
00238 
00239 
00240 
00244   magnitude_type TEUCHOS_DEPRECATED getCondEst() const {
00245     return condEst_;
00246   }
00247 
00249   //Teuchos::RCP<const Teuchos::Comm<int> > getComm () const;
00250 
00256   Teuchos::RCP<const row_matrix_type> getMatrix () const {
00257     return matrix_;
00258   }
00259 
00261   double getComputeFlops() const;
00262 
00264   double getApplyFlops() const;
00265 
00267   int getNumInitialize() const;
00268 
00270   int getNumCompute() const;
00271 
00273   int getNumApply() const;
00274 
00276   double getInitializeTime() const;
00277 
00279   double getComputeTime() const;
00280 
00282   double getApplyTime() const;
00283 
00285 
00286 
00287 
00289   std::string description() const;
00290 
00292   void
00293   describe (Teuchos::FancyOStream& out,
00294             const Teuchos::EVerbosityLevel verbLevel =
00295             Teuchos::Describable::verbLevel_default) const;
00297 
00298 private:
00300   void reset ();
00301 
00303   Teuchos::RCP<const row_matrix_type> matrix_;
00304 
00309   Teuchos::RCP<const vector_type> userInverseDiag_;
00310 
00312   Teuchos::RCP<const vector_type> inverseDiag_;
00313   Teuchos::ArrayRCP<size_t> offsets_;
00314 
00315   double initializeTime_;
00316   double computeTime_;
00317   mutable double applyTime_;
00318 
00319   int numInitialize_;
00320   int numCompute_;
00321   mutable int numApply_;
00322 
00323   magnitude_type condEst_;
00324   bool isInitialized_;
00325   bool isComputed_;
00326 };
00327 
00344 template<class MatrixType, class VectorType>
00345 Teuchos::RCP<Ifpack2::Diagonal<MatrixType> >
00346 createDiagonalPreconditioner (const Teuchos::RCP<const VectorType>& invdiag)
00347 {
00348   return Teuchos::rcp (new Ifpack2::Diagonal<MatrixType> (invdiag));
00349 }
00350 
00351 }//namespace Ifpack2
00352 
00353 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends