Ifpack2 Templated Preconditioning Package Version 1.0
Ifpack2_BlockRelaxation_decl.hpp
Go to the documentation of this file.
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_BLOCKRELAXATION_DECL_HPP
00044 #define IFPACK2_BLOCKRELAXATION_DECL_HPP
00045 
00048 
00049 #include <Ifpack2_ConfigDefs.hpp>
00050 #include <Ifpack2_Preconditioner.hpp>
00051 #include <Ifpack2_Partitioner.hpp>
00052 #include <Ifpack2_Details_CanChangeMatrix.hpp>
00053 #include <Teuchos_Time.hpp>
00054 #include <string>
00055 #include <iostream>
00056 #include <sstream>
00057 
00058 
00059 namespace Ifpack2 {
00060 
00084 template<class MatrixType, class ContainerType>
00085 class BlockRelaxation :
00086     virtual public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
00087                                            typename MatrixType::local_ordinal_type,
00088                                            typename MatrixType::global_ordinal_type,
00089                                            typename MatrixType::node_type>,
00090     virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
00091                                                                        typename MatrixType::local_ordinal_type,
00092                                                                        typename MatrixType::global_ordinal_type,
00093                                                                        typename MatrixType::node_type> >
00094 {
00095 public:
00097 
00098 
00100   typedef typename MatrixType::scalar_type scalar_type;
00101 
00103   TEUCHOS_DEPRECATED typedef typename MatrixType::scalar_type Scalar;
00104 
00105 
00107   typedef typename MatrixType::local_ordinal_type local_ordinal_type;
00108 
00110   TEUCHOS_DEPRECATED typedef typename MatrixType::local_ordinal_type LocalOrdinal;
00111 
00112 
00114   typedef typename MatrixType::global_ordinal_type global_ordinal_type;
00115 
00117   TEUCHOS_DEPRECATED typedef typename MatrixType::global_ordinal_type GlobalOrdinal;
00118 
00119 
00121   typedef typename MatrixType::node_type node_type;
00122 
00124   TEUCHOS_DEPRECATED typedef typename MatrixType::node_type Node;
00125 
00126 
00128   typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
00129 
00131   TEUCHOS_DEPRECATED typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitudeType;
00132 
00134   typedef Tpetra::RowMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type> row_matrix_type;
00135 
00137   // \name Constructors and Destructors
00139 
00169   explicit BlockRelaxation (const Teuchos::RCP<const row_matrix_type>& Matrix);
00170 
00172   virtual ~BlockRelaxation ();
00173 
00175 
00176 
00177 
00179 
00196   void setParameters(const Teuchos::ParameterList& params);
00197 
00199   void initialize();
00200 
00202   inline bool isInitialized() const {
00203     return(IsInitialized_);
00204   }
00205 
00207   void compute();
00208 
00210   inline bool isComputed() const {
00211     return(IsComputed_);
00212   }
00213 
00215 
00216 
00217 
00240   virtual void
00241   setMatrix (const Teuchos::RCP<const row_matrix_type>& A);
00242   
00244 
00245 
00246 
00248 
00258   void apply(const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
00259              Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
00260              Teuchos::ETransp mode = Teuchos::NO_TRANS,
00261              scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
00262              scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
00263 
00265   Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> > getDomainMap() const;
00266 
00268   Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> > getRangeMap() const;
00269 
00270   bool hasTransposeApply() const;
00271 
00273 
00279   void applyMat(const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
00280                 Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
00281                 Teuchos::ETransp mode = Teuchos::NO_TRANS) const;
00282 
00284 
00285 
00286 
00296   virtual magnitude_type TEUCHOS_DEPRECATED
00297   computeCondEst (CondestType CT = Cheap,
00298                   local_ordinal_type MaxIters = 1550,
00299                   magnitude_type Tol = 1e-9,
00300                   const Teuchos::Ptr<const row_matrix_type>& matrix =
00301                   Teuchos::null);
00303 
00304 
00305 
00309   virtual magnitude_type TEUCHOS_DEPRECATED getCondEst() const;
00310 
00312   Teuchos::RCP<const Teuchos::Comm<int> > getComm() const;
00313 
00315   Teuchos::RCP<const Tpetra::RowMatrix<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > getMatrix() const;
00316 
00318   double getComputeFlops() const;
00319 
00321   double getApplyFlops() const;
00322 
00324   int getNumInitialize() const;
00325 
00327   int getNumCompute() const;
00328 
00330   int getNumApply() const;
00331 
00333   double getInitializeTime() const;
00334 
00336   double getComputeTime() const;
00337 
00339   double getApplyTime() const;
00340 
00342 
00343 
00344 
00346   std::string description() const;
00347 
00349   void
00350   describe (Teuchos::FancyOStream& out,
00351             const Teuchos::EVerbosityLevel verbLevel =
00352             Teuchos::Describable::verbLevel_default) const;
00353 
00355 
00356 private:
00358 
00359   typedef Tpetra::MultiVector<scalar_type, local_ordinal_type,
00360                               global_ordinal_type, node_type> MV;
00361   typedef Teuchos::ScalarTraits<scalar_type> STS;
00362   typedef Teuchos::ScalarTraits<magnitude_type> STM;
00364 
00366   BlockRelaxation (const BlockRelaxation<MatrixType, ContainerType> & RHS);
00367 
00369   BlockRelaxation<MatrixType,ContainerType>&
00370   operator= (const BlockRelaxation<MatrixType, ContainerType>& RHS);
00371 
00372   virtual void ApplyInverseJacobi (const MV& X, MV& Y) const;
00373 
00374   virtual void DoJacobi (const MV& X, MV& Y) const;
00375 
00376   virtual void ApplyInverseGS (const MV& X, MV& Y) const;
00377 
00378   virtual void DoGaussSeidel (MV& X, MV& Y) const;
00379 
00380   virtual void ApplyInverseSGS (const MV& X, MV& Y) const;
00381 
00382   virtual void DoSGS (MV& X, MV& Y) const;
00383 
00384   void ExtractSubmatrices ();
00385 
00387 
00388 
00389 
00391   Teuchos::RCP<const row_matrix_type> A_;
00392 
00394   Teuchos::RCP<Teuchos::Time> Time_;
00395 
00397   Teuchos::RCP<const Tpetra::Import<local_ordinal_type,global_ordinal_type,node_type> > Importer_;
00398 
00400   Teuchos::RCP<Tpetra::Vector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > W_;
00401 
00402   // Level of overlap among blocks (for overlapped Jacobi only).
00403   int OverlapLevel_;
00404 
00406   mutable std::vector<Teuchos::RCP<ContainerType> > Containers_;
00407 
00409   Teuchos::RCP<Ifpack2::Partitioner<Tpetra::RowGraph<local_ordinal_type,global_ordinal_type,node_type> > > Partitioner_;
00410 
00411   std::string PartitionerType_;
00412 
00414   Teuchos::ParameterList List_;
00415 
00417   int NumSweeps_;
00418 
00420   local_ordinal_type NumLocalBlocks_;
00421 
00423   Details::RelaxationType PrecType_;
00424 
00426   scalar_type MinDiagonalValue_;
00427 
00429   scalar_type DampingFactor_;
00430 
00432   bool IsParallel_;
00433 
00435   bool ZeroStartingSolution_;
00436 
00438   bool DoBackwardGS_;
00439 
00441   magnitude_type Condest_;
00442 
00444   bool IsInitialized_;
00445 
00447   bool IsComputed_;
00448 
00450   int NumInitialize_;
00451 
00453   int NumCompute_;
00454 
00456   mutable int NumApply_;
00457 
00459   double InitializeTime_;
00460 
00462   double ComputeTime_;
00463 
00465   mutable double ApplyTime_;
00466 
00468   double ComputeFlops_;
00469 
00471   mutable double ApplyFlops_;
00472 
00474   size_t NumMyRows_;
00475 
00477   global_size_t NumGlobalRows_;
00478 
00480   global_size_t NumGlobalNonzeros_;
00482 }; //class BlockRelaxation
00483 
00484 }//namespace Ifpack2
00485 
00486 #endif // IFPACK2_BLOCKRELAXATION_DECL_HPP
00487 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends