Ifpack2 Templated Preconditioning Package Version 1.0
Ifpack2_Chebyshev_decl.hpp
Go to the documentation of this file.
00001 /*
00002 @HEADER
00003 // ***********************************************************************
00004 //
00005 //       Ifpack2: Tempated Object-Oriented Algebraic Preconditioner Package
00006 //                 Copyright (2009) Sandia Corporation
00007 //
00008 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00009 // license for use of this work by or on behalf of the U.S. Government.
00010 //
00011 // Redistribution and use in source and binary forms, with or without
00012 // modification, are permitted provided that the following conditions are
00013 // met:
00014 //
00015 // 1. Redistributions of source code must retain the above copyright
00016 // notice, this list of conditions and the following disclaimer.
00017 //
00018 // 2. Redistributions in binary form must reproduce the above copyright
00019 // notice, this list of conditions and the following disclaimer in the
00020 // documentation and/or other materials provided with the distribution.
00021 //
00022 // 3. Neither the name of the Corporation nor the names of the
00023 // contributors may be used to endorse or promote products derived from
00024 // this software without specific prior written permission.
00025 //
00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037 //
00038 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00039 //
00040 // ***********************************************************************
00041 //@HEADER
00042 */
00043 
00050 
00051 #ifndef IFPACK2_CHEBYSHEV_DECL_HPP
00052 #define IFPACK2_CHEBYSHEV_DECL_HPP
00053 
00054 #include <Ifpack2_ConfigDefs.hpp>
00055 #include <Ifpack2_Preconditioner.hpp>
00056 #include <Ifpack2_Details_CanChangeMatrix.hpp>
00057 
00058 // FIXME (mfh 20 Nov 2013) We really shouldn't have to include both of
00059 // these, if we were to handle the implementation by pointer instead
00060 // of by value.
00061 #include <Ifpack2_Details_Chebyshev_decl.hpp>
00062 #include <Ifpack2_Details_Chebyshev_def.hpp>
00063 
00064 #include <Tpetra_CrsMatrix.hpp>
00065 
00066 #include <iostream>
00067 #include <string>
00068 #include <sstream>
00069 
00070 
00071 namespace Ifpack2 {
00072 
00199 template<class MatrixType>
00200 class Chebyshev :
00201     virtual public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
00202                                            typename MatrixType::local_ordinal_type,
00203                                            typename MatrixType::global_ordinal_type,
00204                                            typename MatrixType::node_type>,
00205     virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
00206                                                                        typename MatrixType::local_ordinal_type,
00207                                                                        typename MatrixType::global_ordinal_type,
00208                                                                        typename MatrixType::node_type> >
00209 {
00210 public:
00212 
00213 
00215   typedef MatrixType matrix_type;
00216 
00218   typedef typename MatrixType::scalar_type scalar_type;
00219 
00221   TEUCHOS_DEPRECATED typedef typename MatrixType::scalar_type Scalar;
00222 
00223 
00225   typedef typename MatrixType::local_ordinal_type local_ordinal_type;
00226 
00228   TEUCHOS_DEPRECATED typedef typename MatrixType::local_ordinal_type LocalOrdinal;
00229 
00230 
00232   typedef typename MatrixType::global_ordinal_type global_ordinal_type;
00233 
00235   TEUCHOS_DEPRECATED typedef typename MatrixType::global_ordinal_type GlobalOrdinal;
00236 
00237 
00239   typedef typename MatrixType::node_type node_type;
00240 
00242   TEUCHOS_DEPRECATED typedef typename MatrixType::node_type Node;
00243 
00244 
00246   typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
00247 
00249   TEUCHOS_DEPRECATED typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitudeType;
00250 
00251 
00258   typedef Tpetra::RowMatrix<scalar_type,local_ordinal_type,global_ordinal_type,node_type> row_matrix_type;
00259 
00261   typedef Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> map_type;
00262 
00268   typedef Tpetra::Vector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> vector_type;
00269 
00271   // \name Constructors and destructors
00273 
00295   explicit Chebyshev (const Teuchos::RCP<const row_matrix_type>& A);
00296 
00298   virtual ~Chebyshev ();
00299 
00301 
00302 
00303 
00440   void setParameters (const Teuchos::ParameterList& params);
00441 
00448   void initialize();
00449 
00452   inline bool isInitialized() const {
00453     return IsInitialized_;
00454   }
00455 
00488   void compute ();
00489 
00499   inline bool isComputed() const {
00500     return IsComputed_;
00501   }
00502 
00504 
00505 
00506 
00529   virtual void
00530   setMatrix (const Teuchos::RCP<const row_matrix_type>& A);
00531 
00533 
00534 
00535 
00564   void
00565   apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
00566          Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
00567          Teuchos::ETransp mode = Teuchos::NO_TRANS,
00568          scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
00569          scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
00570 
00572   Teuchos::RCP<const map_type> getDomainMap() const;
00573 
00575   Teuchos::RCP<const map_type> getRangeMap() const;
00576 
00578   bool hasTransposeApply() const;
00579 
00600   void
00601   applyMat (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
00602             Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
00603             Teuchos::ETransp mode = Teuchos::NO_TRANS) const;
00604 
00606 
00607 
00608 
00618   virtual magnitude_type TEUCHOS_DEPRECATED
00619   computeCondEst (CondestType CT = Cheap,
00620                   local_ordinal_type MaxIters = 1550,
00621                   magnitude_type Tol = 1e-9,
00622                   const Teuchos::Ptr<const row_matrix_type>& matrix = Teuchos::null);
00623 
00625 
00626 
00627 
00631   virtual magnitude_type TEUCHOS_DEPRECATED getCondEst() const;
00632 
00634   Teuchos::RCP<const Teuchos::Comm<int> > getComm() const;
00635 
00637   Teuchos::RCP<const row_matrix_type> getMatrix() const;
00638 
00640   Teuchos::RCP<const MatrixType > getCrsMatrix() const;
00641 
00643   double getComputeFlops() const;
00644 
00646   double getApplyFlops() const;
00647 
00649   int getNumInitialize() const;
00650 
00652   int getNumCompute() const;
00653 
00655   int getNumApply() const;
00656 
00658   double getInitializeTime() const;
00659 
00661   double getComputeTime() const;
00662 
00664   double getApplyTime() const;
00665 
00667   typename MatrixType::scalar_type getLambdaMaxForApply() const;
00668 
00670 
00671 
00672 
00674   std::string description() const;
00675 
00677   void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const;
00678 
00680 
00681 
00682 
00689   static void TEUCHOS_DEPRECATED
00690   PowerMethod (const Tpetra::Operator<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Operator,
00691                const vector_type& InvPointDiagonal,
00692                const int MaximumIterations,
00693                scalar_type& LambdaMax);
00694 
00696   static void TEUCHOS_DEPRECATED
00697   CG (const Tpetra::Operator<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Operator,
00698       const vector_type& InvPointDiagonal,
00699       const int MaximumIterations,
00700       scalar_type& lambda_min, scalar_type& lambda_max);
00701 
00702   // This "template friend" declaration lets any Chebyshev
00703   // specialization be a friend of any of its other specializations.
00704   // That makes clone() easier to implement.
00705   template <class NewMatrixType> friend class Chebyshev;
00706 
00730   template <typename NewMatrixType>
00731   Teuchos::RCP<Chebyshev<NewMatrixType> >
00732   clone (const Teuchos::RCP<const NewMatrixType>& A_newnode,
00733          const Teuchos::ParameterList& params) const;
00734 
00736 
00737 private:
00738 
00740   typedef Teuchos::ScalarTraits<typename MatrixType::scalar_type> STS;
00741 
00743   typedef Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type> MV;
00744 
00746   Chebyshev (const Chebyshev<MatrixType>&);
00747 
00749   Chebyshev<MatrixType>& operator= (const Chebyshev<MatrixType>&);
00750 
00758   void
00759   applyImpl (const MV& X,
00760              MV& Y,
00761              Teuchos::ETransp mode,
00762              scalar_type alpha,
00763              scalar_type beta) const;
00764 
00766 
00767 
00775   mutable Details::Chebyshev<scalar_type, MV> impl_;
00776 
00778   magnitude_type Condest_;
00780   bool IsInitialized_;
00782   bool IsComputed_;
00784   int NumInitialize_;
00786   int NumCompute_;
00791   mutable int NumApply_;
00793   double InitializeTime_;
00795   double ComputeTime_;
00800   mutable double ApplyTime_;
00802   double ComputeFlops_;
00807   mutable double ApplyFlops_;
00808 
00810 }; // class Chebyshev
00811 
00812 
00813 template <typename MatrixType>
00814 template <typename NewMatrixType>
00815 Teuchos::RCP<Chebyshev<NewMatrixType> >
00816 Chebyshev<MatrixType>::
00817 clone (const Teuchos::RCP<const NewMatrixType>& A_newnode,
00818        const Teuchos::ParameterList& params) const
00819 {
00820   using Teuchos::RCP;
00821   typedef Ifpack2::Chebyshev<NewMatrixType> new_prec_type;
00822 
00823   RCP<new_prec_type> prec (new new_prec_type (A_newnode));
00824   prec->setParameters (params);
00825   prec->initialize ();
00826   prec->compute ();
00827   return prec;
00828 }
00829 
00830 } // namespace Ifpack2
00831 
00832 #endif // IFPACK2_CHEBYSHEV_DECL_HPP
00833 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends