Ifpack2 Templated Preconditioning Package  Version 1.0
Ifpack2_BlockRelaxation_decl.hpp
Go to the documentation of this file.
1 /*@HEADER
2 // ***********************************************************************
3 //
4 // Ifpack2: Tempated Object-Oriented Algebraic Preconditioner Package
5 // Copyright (2009) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 //@HEADER
41 */
42 
43 #ifndef IFPACK2_BLOCKRELAXATION_DECL_HPP
44 #define IFPACK2_BLOCKRELAXATION_DECL_HPP
45 
48 
50 #include "Ifpack2_Partitioner.hpp"
52 #include "Teuchos_Time.hpp"
53 #include <type_traits>
54 
55 namespace Ifpack2 {
56 
79 template<class MatrixType, class ContainerType>
81  virtual public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
82  typename MatrixType::local_ordinal_type,
83  typename MatrixType::global_ordinal_type,
84  typename MatrixType::node_type>,
85  virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
86  typename MatrixType::local_ordinal_type,
87  typename MatrixType::global_ordinal_type,
88  typename MatrixType::node_type> >
89 {
90 public:
92 
93 
95  typedef typename MatrixType::scalar_type scalar_type;
96 
98  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
99 
101  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
102 
104  typedef typename MatrixType::node_type node_type;
105 
107  typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
108 
110  typedef Tpetra::RowMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type> row_matrix_type;
111 
112  static_assert(std::is_same<MatrixType, row_matrix_type>::value,
113  "Ifpack2::BlockRelaxation: Please use MatrixType = Tpetra::RowMatrix.");
114 
116  // \name Constructors and Destructors
118 
148  explicit BlockRelaxation (const Teuchos::RCP<const row_matrix_type>& Matrix);
149 
151  virtual ~BlockRelaxation ();
152 
154 
156 
158 
175  void setParameters(const Teuchos::ParameterList& params);
176 
178  void initialize();
179 
181  inline bool isInitialized() const {
182  return(IsInitialized_);
183  }
184 
186  void compute();
187 
189  inline bool isComputed() const {
190  return(IsComputed_);
191  }
192 
194 
196 
219  virtual void
220  setMatrix (const Teuchos::RCP<const row_matrix_type>& A);
221 
223 
225 
227 
237  void apply(const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
238  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
239  Teuchos::ETransp mode = Teuchos::NO_TRANS,
240  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
241  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
242 
244  Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> > getDomainMap() const;
245 
247  Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> > getRangeMap() const;
248 
249  bool hasTransposeApply() const;
250 
252 
258  void applyMat(const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
259  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
260  Teuchos::ETransp mode = Teuchos::NO_TRANS) const;
261 
263 
265 
267  Teuchos::RCP<const Teuchos::Comm<int> > getComm() const;
268 
270  Teuchos::RCP<const Tpetra::RowMatrix<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > getMatrix() const;
271 
273  double getComputeFlops() const;
274 
276  double getApplyFlops() const;
277 
279  int getNumInitialize() const;
280 
282  int getNumCompute() const;
283 
285  int getNumApply() const;
286 
288  double getInitializeTime() const;
289 
291  double getComputeTime() const;
292 
294  double getApplyTime() const;
295 
297 
299 
301  std::string description() const;
302 
304  void
305  describe (Teuchos::FancyOStream& out,
306  const Teuchos::EVerbosityLevel verbLevel =
307  Teuchos::Describable::verbLevel_default) const;
308 
310 
312  Teuchos::RCP<Ifpack2::Partitioner<Tpetra::RowGraph<local_ordinal_type,global_ordinal_type,node_type> > > getPartitioner(){return Partitioner_;}
313 
314 private:
316 
317  typedef Tpetra::MultiVector<scalar_type, local_ordinal_type,
318  global_ordinal_type, node_type> MV;
319  typedef Teuchos::ScalarTraits<scalar_type> STS;
320  typedef Teuchos::ScalarTraits<magnitude_type> STM;
322 
325 
328  operator= (const BlockRelaxation<MatrixType, ContainerType>& RHS);
329 
330  virtual void ApplyInverseJacobi (const MV& X, MV& Y) const;
331 
332  virtual void DoJacobi (const MV& X, MV& Y) const;
333 
334  virtual void ApplyInverseGS (const MV& X, MV& Y) const;
335 
336  virtual void DoGaussSeidel (MV& X, MV& Y) const;
337 
338  virtual void ApplyInverseSGS (const MV& X, MV& Y) const;
339 
340  virtual void DoSGS (MV& X, MV& Y) const;
341 
342  void ExtractSubmatrices ();
343 
345 
347 
349  Teuchos::RCP<const row_matrix_type> A_;
350 
352  Teuchos::RCP<Teuchos::Time> Time_;
353 
355  Teuchos::RCP<const Tpetra::Import<local_ordinal_type,global_ordinal_type,node_type> > Importer_;
356 
358  Teuchos::RCP<Tpetra::Vector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > W_;
359 
360  // Level of overlap among blocks (for overlapped Jacobi only).
361  int OverlapLevel_;
362 
364  mutable std::vector<Teuchos::RCP<ContainerType> > Containers_;
365 
366  // mutable Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node>* Diagonal_;
367 
368  // FIXME (mfh 06 Oct 2014) This doesn't comply with the naming
369  // convention for instance members of a class. Furthermore, the
370  // class should keep the Vector, not the ArrayRCP to the data _in_
371  // the Vector.
372  Teuchos::ArrayRCP< const scalar_type > DiagRCP;
373 
375  Teuchos::RCP<Ifpack2::Partitioner<Tpetra::RowGraph<local_ordinal_type,global_ordinal_type,node_type> > > Partitioner_;
376 
377  std::string PartitionerType_;
378 
380  Teuchos::ParameterList List_;
381 
383  int NumSweeps_;
384 
386  local_ordinal_type NumLocalBlocks_;
387 
389  Details::RelaxationType PrecType_;
390 
392  scalar_type DampingFactor_;
393 
395  bool IsParallel_;
396 
398  bool ZeroStartingSolution_;
399 
401  bool DoBackwardGS_;
402 
404  bool IsInitialized_;
405 
407  bool IsComputed_;
408 
410  int NumInitialize_;
411 
413  int NumCompute_;
414 
416  mutable int NumApply_;
417 
419  double InitializeTime_;
420 
422  double ComputeTime_;
423 
425  mutable double ApplyTime_;
426 
428  double ComputeFlops_;
429 
431  mutable double ApplyFlops_;
432 
434  size_t NumMyRows_;
435 
437  global_size_t NumGlobalRows_;
438 
440  global_size_t NumGlobalNonzeros_;
442 }; //class BlockRelaxation
443 
444 }//namespace Ifpack2
445 
446 #endif // IFPACK2_BLOCKRELAXATION_DECL_HPP
447 
double getApplyFlops() const
Returns the number of flops for the application of the preconditioner.
Definition: Ifpack2_BlockRelaxation_def.hpp:264
Mix-in interface for preconditioners that can change their matrix after construction.
Definition: Ifpack2_Details_CanChangeMatrix.hpp:93
void applyMat(const Tpetra::MultiVector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > &X, Tpetra::MultiVector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS) const
Applies the matrix to a Tpetra::MultiVector.
Definition: Ifpack2_BlockRelaxation_def.hpp:346
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
The communicator over which the input matrix is distributed.
Definition: Ifpack2_BlockRelaxation_def.hpp:182
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition: Ifpack2_BlockRelaxation_decl.hpp:101
std::string description() const
A one-line description of this object.
Definition: Ifpack2_BlockRelaxation_def.hpp:904
double getApplyTime() const
Returns the time spent in apply().
Definition: Ifpack2_BlockRelaxation_def.hpp:252
int getNumApply() const
Returns the number of calls to apply().
Definition: Ifpack2_BlockRelaxation_def.hpp:234
Teuchos::RCP< const Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type > > getRangeMap() const
Returns the Tpetra::Map object associated with the range of this operator.
Definition: Ifpack2_BlockRelaxation_def.hpp:210
int getNumCompute() const
Returns the number of calls to compute().
Definition: Ifpack2_BlockRelaxation_def.hpp:228
void setParameters(const Teuchos::ParameterList &params)
Sets all the parameters for the preconditioner.
Definition: Ifpack2_BlockRelaxation_def.hpp:119
void compute()
compute the preconditioner for the specified matrix, diagonal perturbation thresholds and relaxation ...
Definition: Ifpack2_BlockRelaxation_def.hpp:422
Block relaxation preconditioners (or smoothers) for Tpetra::RowMatrix and Tpetra::CrsMatrix sparse ma...
Definition: Ifpack2_BlockRelaxation_decl.hpp:80
double getInitializeTime() const
Returns the time spent in initialize().
Definition: Ifpack2_BlockRelaxation_def.hpp:240
double getComputeFlops() const
Returns the number of flops in the computation phase.
Definition: Ifpack2_BlockRelaxation_def.hpp:258
double getComputeTime() const
Returns the time spent in compute().
Definition: Ifpack2_BlockRelaxation_def.hpp:246
bool isComputed() const
Return true if compute() has been called.
Definition: Ifpack2_BlockRelaxation_decl.hpp:189
Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitude_type
The type of the magnitude (absolute value) of a matrix entry.
Definition: Ifpack2_BlockRelaxation_decl.hpp:107
Tpetra::RowMatrix< scalar_type, local_ordinal_type, global_ordinal_type, node_type > row_matrix_type
Tpetra::RowMatrix specialization corresponding to MatrixType.
Definition: Ifpack2_BlockRelaxation_decl.hpp:110
virtual void setMatrix(const Teuchos::RCP< const row_matrix_type > &A)
Change the matrix to be preconditioned.
Definition: Ifpack2_BlockRelaxation_def.hpp:57
virtual ~BlockRelaxation()
Destructor.
Definition: Ifpack2_BlockRelaxation_def.hpp:113
Interface for all Ifpack2 preconditioners.
Definition: Ifpack2_Preconditioner.hpp:107
Teuchos::RCP< const Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type > > getDomainMap() const
Returns the Tpetra::Map object associated with the domain of this operator.
Definition: Ifpack2_BlockRelaxation_def.hpp:201
bool isInitialized() const
Returns true if the preconditioner has been successfully initialized.
Definition: Ifpack2_BlockRelaxation_decl.hpp:181
int getNumInitialize() const
Returns the number of calls to initialize().
Definition: Ifpack2_BlockRelaxation_def.hpp:222
Declaration of interface for preconditioners that can change their matrix after construction.
void initialize()
Initialize.
Definition: Ifpack2_BlockRelaxation_def.hpp:366
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to an FancyOStream object.
Definition: Ifpack2_BlockRelaxation_def.hpp:950
MatrixType::node_type node_type
Node type of the input MatrixType.
Definition: Ifpack2_BlockRelaxation_decl.hpp:104
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition: Ifpack2_BlockRelaxation_decl.hpp:98
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition: Ifpack2_BlockRelaxation_decl.hpp:95
Preconditioners and smoothers for Tpetra sparse matrices.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:72
Teuchos::RCP< const Tpetra::RowMatrix< scalar_type, local_ordinal_type, global_ordinal_type, node_type > > getMatrix() const
The input matrix of this preconditioner&#39;s constructor.
Definition: Ifpack2_BlockRelaxation_def.hpp:192
void apply(const Tpetra::MultiVector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > &X, Tpetra::MultiVector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, scalar_type alpha=Teuchos::ScalarTraits< scalar_type >::one(), scalar_type beta=Teuchos::ScalarTraits< scalar_type >::zero()) const
Applies the preconditioner to X, returns the result in Y.
Definition: Ifpack2_BlockRelaxation_def.hpp:272
Teuchos::RCP< Ifpack2::Partitioner< Tpetra::RowGraph< local_ordinal_type, global_ordinal_type, node_type > > > getPartitioner()
For diagnostic purposes.
Definition: Ifpack2_BlockRelaxation_decl.hpp:312
BlockRelaxation(const Teuchos::RCP< const row_matrix_type > &Matrix)
Constructor.
Definition: Ifpack2_BlockRelaxation_def.hpp:80