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 // 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_RELAXATION_DECL_HPP
00044 #define IFPACK2_RELAXATION_DECL_HPP
00045 
00046 #include <Ifpack2_ConfigDefs.hpp>
00047 #include <Ifpack2_Preconditioner.hpp>
00048 #include <Ifpack2_Details_CanChangeMatrix.hpp>
00049 #include <Ifpack2_Condest.hpp>
00050 #include <Ifpack2_Parameters.hpp>
00051 #include <Tpetra_Vector.hpp>
00052 #include <Teuchos_ScalarTraits.hpp>
00053 #include <Tpetra_CrsMatrix_decl.hpp> // Don't need the definition here
00054 
00055 namespace Teuchos {
00056   // forward declarations
00057   class ParameterList;
00058   class Time;
00059 } // namespace Teuchos
00060 
00061 namespace Ifpack2 {
00062 
00226 template<class MatrixType>
00227 class Relaxation :
00228   virtual public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
00229                                          typename MatrixType::local_ordinal_type,
00230                                          typename MatrixType::global_ordinal_type,
00231                                          typename MatrixType::node_type>,
00232   virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
00233                                                                      typename MatrixType::local_ordinal_type,
00234                                                                      typename MatrixType::global_ordinal_type,
00235                                                                      typename MatrixType::node_type> >
00236 {
00237 public:
00239 
00240 
00242   typedef typename MatrixType::scalar_type scalar_type;
00243 
00245   TEUCHOS_DEPRECATED typedef typename MatrixType::scalar_type Scalar;
00246 
00247 
00249   typedef typename MatrixType::local_ordinal_type local_ordinal_type;
00250 
00252   TEUCHOS_DEPRECATED typedef typename MatrixType::local_ordinal_type LocalOrdinal;
00253 
00254 
00256   typedef typename MatrixType::global_ordinal_type global_ordinal_type;
00257 
00259   TEUCHOS_DEPRECATED typedef typename MatrixType::global_ordinal_type GlobalOrdinal;
00260 
00261 
00263   typedef typename MatrixType::node_type node_type;
00264 
00266   TEUCHOS_DEPRECATED typedef typename MatrixType::node_type Node;
00267 
00268 
00270   typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
00271 
00273   TEUCHOS_DEPRECATED typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitudeType;
00274 
00276   typedef Tpetra::RowMatrix<scalar_type, local_ordinal_type,
00277                             global_ordinal_type, node_type> row_matrix_type;
00279 
00280 
00281 
00315   explicit Relaxation (const Teuchos::RCP<const row_matrix_type>& A);
00316 
00318   virtual ~Relaxation();
00319 
00321 
00322 
00323 
00401   void setParameters (const Teuchos::ParameterList& params);
00402 
00404   Teuchos::RCP<const Teuchos::ParameterList>
00405   getValidParameters () const;
00406 
00415   void initialize ();
00416 
00418   inline bool isInitialized() const {
00419     return isInitialized_;
00420   }
00421 
00429   void compute ();
00430 
00432   inline bool isComputed() const {
00433     return(IsComputed_);
00434   }
00435 
00437 
00438 
00439 
00462   virtual void
00463   setMatrix (const Teuchos::RCP<const row_matrix_type>& A);
00464 
00466 
00467 
00468 
00484   void
00485   apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
00486          Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
00487          Teuchos::ETransp mode = Teuchos::NO_TRANS,
00488          scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
00489          scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
00490 
00492   Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> >
00493   getDomainMap () const;
00494 
00496   Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> >
00497   getRangeMap () const;
00498 
00500   bool hasTransposeApply () const;
00501 
00514   void
00515   applyMat (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
00516             Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
00517             Teuchos::ETransp mode = Teuchos::NO_TRANS) const;
00518 
00520 
00521 
00522 
00532   virtual magnitude_type TEUCHOS_DEPRECATED
00533   computeCondEst (CondestType CT = Cheap,
00534                   local_ordinal_type MaxIters = 1550,
00535                   magnitude_type Tol = 1e-9,
00536                   const Teuchos::Ptr<const row_matrix_type>& matrix = Teuchos::null);
00537 
00539 
00540 
00541 
00545   virtual magnitude_type TEUCHOS_DEPRECATED getCondEst() const;
00546 
00548   Teuchos::RCP<const Teuchos::Comm<int> > getComm() const;
00549 
00551   Teuchos::RCP<const row_matrix_type> getMatrix () const;
00552 
00554   double getComputeFlops() const;
00555 
00557   double getApplyFlops() const;
00558 
00560   int getNumInitialize() const;
00561 
00563   int getNumCompute() const;
00564 
00566   int getNumApply() const;
00567 
00569   double getInitializeTime() const;
00570 
00572   double getComputeTime() const;
00573 
00575   double getApplyTime() const;
00576 
00578 
00579 
00580 
00587   std::string description () const;
00588 
00611   void
00612   describe (Teuchos::FancyOStream &out,
00613             const Teuchos::EVerbosityLevel verbLevel =
00614             Teuchos::Describable::verbLevel_default) const;
00616 
00617 private:
00619 
00620 
00621   typedef Teuchos::ScalarTraits<scalar_type> STS;
00622   typedef Teuchos::ScalarTraits<magnitude_type> STM;
00623 
00641   typedef Tpetra::CrsMatrix<scalar_type, local_ordinal_type,
00642                             global_ordinal_type, node_type> crs_matrix_type;
00644 
00645 
00646 
00648   Relaxation (const Relaxation<MatrixType>& RHS);
00649 
00651   Relaxation<MatrixType>& operator= (const Relaxation<MatrixType>& RHS);
00652 
00654 
00655 
00656 
00661   void setParametersImpl (Teuchos::ParameterList& params);
00662 
00664   void ApplyInverseJacobi(
00665         const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
00666               Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
00667 
00669   void ApplyInverseGS(
00670         const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
00671               Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
00672 
00674   void ApplyInverseGS_RowMatrix(
00675         const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
00676               Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
00677 
00679   void
00680   ApplyInverseGS_CrsMatrix (const crs_matrix_type& A,
00681                             const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
00682                             Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
00683 
00685   void ApplyInverseSGS(
00686         const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
00687               Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
00688 
00690   void ApplyInverseSGS_RowMatrix(
00691         const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
00692               Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
00693 
00695   void
00696   ApplyInverseSGS_CrsMatrix (const crs_matrix_type& A,
00697                              const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
00698                              Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
00699 
00701 
00702 
00703 
00710   mutable Teuchos::RCP<const Teuchos::ParameterList> validParams_;
00711 
00713   Teuchos::RCP<const row_matrix_type> A_;
00715   Teuchos::RCP<Teuchos::Time> Time_;
00717   Teuchos::RCP<const Tpetra::Import<local_ordinal_type,global_ordinal_type,node_type> > Importer_;
00719   mutable Teuchos::RCP<Tpetra::Vector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > Diagonal_;
00720 
00722   int NumSweeps_;
00724   Details::RelaxationType PrecType_;
00726   scalar_type DampingFactor_;
00728   bool IsParallel_;
00730   bool ZeroStartingSolution_;
00732   bool DoBackwardGS_;
00734   bool DoL1Method_;
00736   magnitude_type L1Eta_;
00738   scalar_type MinDiagonalValue_;
00740   bool fixTinyDiagEntries_;
00742   bool checkDiagEntries_;
00743 
00745   magnitude_type Condest_;
00747   bool isInitialized_;
00749   bool IsComputed_;
00751   int NumInitialize_;
00753   int NumCompute_;
00755   mutable int NumApply_;
00757   double InitializeTime_;
00759   double ComputeTime_;
00761   mutable double ApplyTime_;
00763   double ComputeFlops_;
00765   mutable double ApplyFlops_;
00766 
00768   magnitude_type globalMinMagDiagEntryMag_;
00770   magnitude_type globalMaxMagDiagEntryMag_;
00772   size_t globalNumSmallDiagEntries_;
00774   size_t globalNumZeroDiagEntries_;
00776   size_t globalNumNegDiagEntries_;
00781   magnitude_type globalDiagNormDiff_;
00782 
00788   Teuchos::ArrayRCP<size_t> diagOffsets_;
00794   bool savedDiagOffsets_;
00795 
00797   Teuchos::ArrayRCP<local_ordinal_type> localSmoothingIndices_;
00798 
00800 }; //class Relaxation
00801 
00802 }//namespace Ifpack2
00803 
00804 #endif // IFPACK2_RELAXATION_DECL_HPP
00805 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends