Ifpack2 Templated Preconditioning Package  Version 1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
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 
00408   //  mutable Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node>* Diagonal_;
00409 
00410   // FIXME (mfh 06 Oct 2014) This doesn't comply with the naming
00411   // convention for instance members of a class.  Furthermore, the
00412   // class should keep the Vector, not the ArrayRCP to the data _in_
00413   // the Vector.
00414   Teuchos::ArrayRCP< const scalar_type > DiagRCP;
00415 
00417   Teuchos::RCP<Ifpack2::Partitioner<Tpetra::RowGraph<local_ordinal_type,global_ordinal_type,node_type> > > Partitioner_;
00418 
00419   std::string PartitionerType_;
00420 
00422   Teuchos::ParameterList List_;
00423 
00425   int NumSweeps_;
00426 
00428   local_ordinal_type NumLocalBlocks_;
00429 
00431   Details::RelaxationType PrecType_;
00432 
00434   scalar_type DampingFactor_;
00435 
00437   bool IsParallel_;
00438 
00440   bool ZeroStartingSolution_;
00441 
00443   bool DoBackwardGS_;
00444 
00446   magnitude_type Condest_;
00447 
00449   bool IsInitialized_;
00450 
00452   bool IsComputed_;
00453 
00455   int NumInitialize_;
00456 
00458   int NumCompute_;
00459 
00461   mutable int NumApply_;
00462 
00464   double InitializeTime_;
00465 
00467   double ComputeTime_;
00468 
00470   mutable double ApplyTime_;
00471 
00473   double ComputeFlops_;
00474 
00476   mutable double ApplyFlops_;
00477 
00479   size_t NumMyRows_;
00480 
00482   global_size_t NumGlobalRows_;
00483 
00485   global_size_t NumGlobalNonzeros_;
00487 }; //class BlockRelaxation
00488 
00489 }//namespace Ifpack2
00490 
00491 #endif // IFPACK2_BLOCKRELAXATION_DECL_HPP
00492 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends