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 
00431 
00433   inline bool isComputed() const {
00434     return(IsComputed_);
00435   }
00436 
00438 
00439 
00440 
00463   virtual void
00464   setMatrix (const Teuchos::RCP<const row_matrix_type>& A);
00465 
00467 
00468 
00469 
00485   void
00486   apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
00487          Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
00488          Teuchos::ETransp mode = Teuchos::NO_TRANS,
00489          scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
00490          scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
00491 
00493   Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> >
00494   getDomainMap () const;
00495 
00497   Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> >
00498   getRangeMap () const;
00499 
00501   bool hasTransposeApply () const;
00502 
00515   void
00516   applyMat (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
00517             Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
00518             Teuchos::ETransp mode = Teuchos::NO_TRANS) const;
00519 
00521 
00522 
00523 
00533   virtual magnitude_type TEUCHOS_DEPRECATED
00534   computeCondEst (CondestType CT = Cheap,
00535                   local_ordinal_type MaxIters = 1550,
00536                   magnitude_type Tol = 1e-9,
00537                   const Teuchos::Ptr<const row_matrix_type>& matrix = Teuchos::null);
00538 
00540 
00541 
00542 
00546   virtual magnitude_type TEUCHOS_DEPRECATED getCondEst() const;
00547 
00549   Teuchos::RCP<const Teuchos::Comm<int> > getComm() const;
00550 
00552   Teuchos::RCP<const row_matrix_type> getMatrix () const;
00553 
00555   double getComputeFlops() const;
00556 
00558   double getApplyFlops() const;
00559 
00561   int getNumInitialize() const;
00562 
00564   int getNumCompute() const;
00565 
00567   int getNumApply() const;
00568 
00570   double getInitializeTime() const;
00571 
00573   double getComputeTime() const;
00574 
00576   double getApplyTime() const;
00577 
00579 
00580 
00581 
00588   std::string description () const;
00589 
00612   void
00613   describe (Teuchos::FancyOStream &out,
00614             const Teuchos::EVerbosityLevel verbLevel =
00615             Teuchos::Describable::verbLevel_default) const;
00617 
00618 private:
00620 
00621 
00622   typedef Teuchos::ScalarTraits<scalar_type> STS;
00623   typedef Teuchos::ScalarTraits<magnitude_type> STM;
00624 
00642   typedef Tpetra::CrsMatrix<scalar_type, local_ordinal_type,
00643                             global_ordinal_type, node_type> crs_matrix_type;
00644   typedef Tpetra::Experimental::BlockCrsMatrix<scalar_type, local_ordinal_type,
00645                             global_ordinal_type, node_type> block_crs_matrix_type;
00647 
00648 
00649 
00651   Relaxation (const Relaxation<MatrixType>& RHS);
00652 
00654   Relaxation<MatrixType>& operator= (const Relaxation<MatrixType>& RHS);
00655 
00657 
00658 
00659 
00664   void setParametersImpl (Teuchos::ParameterList& params);
00665 
00667   void ApplyInverseJacobi(
00668         const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
00669               Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
00670 
00672   void ApplyInverseJacobi_BlockCrsMatrix(
00673         const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
00674               Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
00675 
00677   void ApplyInverseGS(
00678         const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
00679               Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
00680 
00682   void ApplyInverseGS_RowMatrix(
00683         const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
00684               Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
00685 
00687   void
00688   ApplyInverseGS_CrsMatrix (const crs_matrix_type& A,
00689                             const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
00690                             Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
00691 
00693   void
00694   ApplyInverseGS_BlockCrsMatrix (const block_crs_matrix_type& A,
00695                             const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
00696                             Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
00697 
00699   void ApplyInverseSGS(
00700         const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
00701               Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
00702 
00704   void ApplyInverseSGS_RowMatrix(
00705         const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
00706               Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
00707 
00709   void
00710   ApplyInverseSGS_CrsMatrix (const crs_matrix_type& A,
00711                              const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
00712                              Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
00713 
00715   void
00716   ApplyInverseSGS_BlockCrsMatrix (const block_crs_matrix_type& A,
00717                              const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
00718                              Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
00719 
00720   void computeBlockCrs ();
00721 
00722 
00724 
00725 
00726 
00733   mutable Teuchos::RCP<const Teuchos::ParameterList> validParams_;
00734 
00736   Teuchos::RCP<const row_matrix_type> A_;
00738   Teuchos::RCP<Teuchos::Time> Time_;
00740   Teuchos::RCP<const Tpetra::Import<local_ordinal_type,global_ordinal_type,node_type> > Importer_;
00742   mutable Teuchos::RCP<Tpetra::Vector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > Diagonal_;
00743 
00744   Teuchos::RCP<block_crs_matrix_type> BlockDiagonal_;
00745   Teuchos::Array<int> blockDiagonalFactorizationPivots;
00746 
00747 
00749   int NumSweeps_;
00751   Details::RelaxationType PrecType_;
00753   scalar_type DampingFactor_;
00755   bool IsParallel_;
00757   bool ZeroStartingSolution_;
00759   bool DoBackwardGS_;
00761   bool DoL1Method_;
00763   magnitude_type L1Eta_;
00765   scalar_type MinDiagonalValue_;
00767   bool fixTinyDiagEntries_;
00769   bool checkDiagEntries_;
00770 
00772   magnitude_type Condest_;
00774   bool isInitialized_;
00776   bool IsComputed_;
00778   int NumInitialize_;
00780   int NumCompute_;
00782   mutable int NumApply_;
00784   double InitializeTime_;
00786   double ComputeTime_;
00788   mutable double ApplyTime_;
00790   double ComputeFlops_;
00792   mutable double ApplyFlops_;
00793 
00795   magnitude_type globalMinMagDiagEntryMag_;
00797   magnitude_type globalMaxMagDiagEntryMag_;
00799   size_t globalNumSmallDiagEntries_;
00801   size_t globalNumZeroDiagEntries_;
00803   size_t globalNumNegDiagEntries_;
00808   magnitude_type globalDiagNormDiff_;
00809 
00815   Teuchos::ArrayRCP<size_t> diagOffsets_;
00821   bool savedDiagOffsets_;
00822 
00823   bool hasBlockCrsMatrix_;
00824 
00826   Teuchos::ArrayRCP<local_ordinal_type> localSmoothingIndices_;
00827 
00829 }; //class Relaxation
00830 
00831 }//namespace Ifpack2
00832 
00833 #endif // IFPACK2_RELAXATION_DECL_HPP
00834 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends