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 "Tpetra_Experimental_BlockCrsMatrix_decl.hpp"
54 #include <type_traits>
55 
56 namespace Ifpack2 {
57 
80 template<class MatrixType, class ContainerType>
82  virtual public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
83  typename MatrixType::local_ordinal_type,
84  typename MatrixType::global_ordinal_type,
85  typename MatrixType::node_type>,
86  virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
87  typename MatrixType::local_ordinal_type,
88  typename MatrixType::global_ordinal_type,
89  typename MatrixType::node_type> >
90 {
91 public:
93 
94 
96  typedef typename MatrixType::scalar_type scalar_type;
97 
99  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
100 
102  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
103 
105  typedef typename MatrixType::node_type node_type;
106 
108  typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
109 
111  typedef Tpetra::RowMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type> row_matrix_type;
112 
113  static_assert(std::is_same<MatrixType, row_matrix_type>::value,
114  "Ifpack2::BlockRelaxation: Please use MatrixType = Tpetra::RowMatrix.");
115 
117  // \name Constructors and Destructors
119 
149  explicit BlockRelaxation (const Teuchos::RCP<const row_matrix_type>& Matrix);
150 
152  virtual ~BlockRelaxation ();
153 
155 
157 
159 
186  void setParameters(const Teuchos::ParameterList& params);
187 
189  void initialize();
190 
192  inline bool isInitialized() const {
193  return(IsInitialized_);
194  }
195 
196  void computeBlockCrs();
197 
199  void compute();
200 
202  inline bool isComputed() const {
203  return(IsComputed_);
204  }
205 
207 
209 
232  virtual void
233  setMatrix (const Teuchos::RCP<const row_matrix_type>& A);
234 
236 
238 
240 
250  void apply(const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
251  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
252  Teuchos::ETransp mode = Teuchos::NO_TRANS,
253  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
254  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
255 
257  Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> > getDomainMap() const;
258 
260  Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> > getRangeMap() const;
261 
262  bool hasTransposeApply() const;
263 
265 
271  void applyMat(const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
272  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
273  Teuchos::ETransp mode = Teuchos::NO_TRANS) const;
274 
276 
278 
280  Teuchos::RCP<const Teuchos::Comm<int> > getComm() const;
281 
283  Teuchos::RCP<const Tpetra::RowMatrix<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > getMatrix() const;
284 
286  double getComputeFlops() const;
287 
289  double getApplyFlops() const;
290 
292  int getNumInitialize() const;
293 
295  int getNumCompute() const;
296 
298  int getNumApply() const;
299 
301  double getInitializeTime() const;
302 
304  double getComputeTime() const;
305 
307  double getApplyTime() const;
308 
310 
312 
314  std::string description() const;
315 
317  void
318  describe (Teuchos::FancyOStream& out,
319  const Teuchos::EVerbosityLevel verbLevel =
320  Teuchos::Describable::verbLevel_default) const;
321 
323 
325  Teuchos::RCP<Ifpack2::Partitioner<Tpetra::RowGraph<local_ordinal_type,global_ordinal_type,node_type> > > getPartitioner(){return Partitioner_;}
326 
327 private:
329 
330  typedef Tpetra::MultiVector<scalar_type, local_ordinal_type,
331  global_ordinal_type, node_type> MV;
332  typedef Tpetra::Vector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> vector_type;
333  typedef Teuchos::ScalarTraits<scalar_type> STS;
334  typedef Teuchos::ScalarTraits<magnitude_type> STM;
335  typedef Tpetra::Experimental::BlockCrsMatrix<scalar_type, local_ordinal_type,
336  global_ordinal_type, node_type> block_crs_matrix_type;
338 
341 
344  operator= (const BlockRelaxation<MatrixType, ContainerType>& RHS);
345 
346  virtual void ApplyInverseJacobi (const MV& X, MV& Y) const;
347 
348  virtual void DoJacobi (const MV& X, MV& Y) const;
349 
350  virtual void ApplyInverseGS (const MV& X, MV& Y) const;
351 
352  virtual void DoGaussSeidel (MV& X, MV& Y) const;
353 
354  virtual void ApplyInverseSGS (const MV& X, MV& Y) const;
355 
356  virtual void DoSGS (MV& X, MV& Y) const;
357 
358  void ExtractSubmatrices ();
359 
360  void getMatDiag() const;
361 
363 
365 
367  Teuchos::RCP<const row_matrix_type> A_;
368 
370  Teuchos::RCP<Teuchos::Time> Time_;
371 
373  Teuchos::RCP<const Tpetra::Import<local_ordinal_type,global_ordinal_type,node_type> > Importer_;
374 
376  Teuchos::RCP<vector_type> W_;
377 
378  // Level of overlap among blocks (for overlapped Jacobi only).
379  int OverlapLevel_;
380 
382  mutable std::vector<Teuchos::RCP<ContainerType> > Containers_;
383 
384  // FIXME (mfh 06 Oct 2014) This doesn't comply with the naming
385  // convention for instance members of a class. Furthermore, the
386  // class should keep the Vector, not the ArrayRCP to the data _in_
387  // the Vector.
388  // FIXED! (amk 10 Nov 2015)
389  mutable Teuchos::RCP<vector_type> DiagRCP_;
390 
392  Teuchos::RCP<Ifpack2::Partitioner<Tpetra::RowGraph<local_ordinal_type,global_ordinal_type,node_type> > > Partitioner_;
393 
394  std::string PartitionerType_;
395 
397  Teuchos::ParameterList List_;
398 
400  int NumSweeps_;
401 
403  local_ordinal_type NumLocalBlocks_;
404 
406  Details::RelaxationType PrecType_;
407 
409  scalar_type DampingFactor_;
410 
412  bool IsParallel_;
413 
415  bool ZeroStartingSolution_;
416 
418  bool DoBackwardGS_;
419 
421  bool IsInitialized_;
422 
424  bool IsComputed_;
425 
427  int NumInitialize_;
428 
430  int NumCompute_;
431 
433  mutable int NumApply_;
434 
436  double InitializeTime_;
437 
439  double ComputeTime_;
440 
442  mutable double ApplyTime_;
443 
445  double ComputeFlops_;
446 
448  mutable double ApplyFlops_;
449 
451  size_t NumMyRows_;
452 
454  global_size_t NumGlobalRows_;
455 
457  global_size_t NumGlobalNonzeros_;
458 
459  bool hasBlockCrsMatrix_;
461 }; //class BlockRelaxation
462 
463 }//namespace Ifpack2
464 
465 #endif // IFPACK2_BLOCKRELAXATION_DECL_HPP
466 
double getApplyFlops() const
Returns the number of flops for the application of the preconditioner.
Definition: Ifpack2_BlockRelaxation_def.hpp:291
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:385
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
The communicator over which the input matrix is distributed.
Definition: Ifpack2_BlockRelaxation_def.hpp:180
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition: Ifpack2_BlockRelaxation_decl.hpp:102
std::string description() const
A one-line description of this object.
Definition: Ifpack2_BlockRelaxation_def.hpp:1146
double getApplyTime() const
Returns the time spent in apply().
Definition: Ifpack2_BlockRelaxation_def.hpp:275
int getNumApply() const
Returns the number of calls to apply().
Definition: Ifpack2_BlockRelaxation_def.hpp:251
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:217
int getNumCompute() const
Returns the number of calls to compute().
Definition: Ifpack2_BlockRelaxation_def.hpp:243
void setParameters(const Teuchos::ParameterList &params)
Sets all the parameters for the preconditioner.
Definition: Ifpack2_BlockRelaxation_def.hpp:117
void compute()
compute the preconditioner for the specified matrix, diagonal perturbation thresholds and relaxation ...
Definition: Ifpack2_BlockRelaxation_def.hpp:548
Block relaxation preconditioners (or smoothers) for Tpetra::RowMatrix and Tpetra::CrsMatrix sparse ma...
Definition: Ifpack2_BlockRelaxation_decl.hpp:81
double getInitializeTime() const
Returns the time spent in initialize().
Definition: Ifpack2_BlockRelaxation_def.hpp:259
double getComputeFlops() const
Returns the number of flops in the computation phase.
Definition: Ifpack2_BlockRelaxation_def.hpp:283
double getComputeTime() const
Returns the time spent in compute().
Definition: Ifpack2_BlockRelaxation_def.hpp:267
bool isComputed() const
Return true if compute() has been called.
Definition: Ifpack2_BlockRelaxation_decl.hpp:202
Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitude_type
The type of the magnitude (absolute value) of a matrix entry.
Definition: Ifpack2_BlockRelaxation_decl.hpp:108
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:111
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:111
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:203
bool isInitialized() const
Returns true if the preconditioner has been successfully initialized.
Definition: Ifpack2_BlockRelaxation_decl.hpp:192
int getNumInitialize() const
Returns the number of calls to initialize().
Definition: Ifpack2_BlockRelaxation_def.hpp:236
Declaration of interface for preconditioners that can change their matrix after construction.
void initialize()
Initialize.
Definition: Ifpack2_BlockRelaxation_def.hpp:401
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:1192
MatrixType::node_type node_type
Node type of the input MatrixType.
Definition: Ifpack2_BlockRelaxation_decl.hpp:105
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition: Ifpack2_BlockRelaxation_decl.hpp:99
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition: Ifpack2_BlockRelaxation_decl.hpp:96
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:194
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:299
Teuchos::RCP< Ifpack2::Partitioner< Tpetra::RowGraph< local_ordinal_type, global_ordinal_type, node_type > > > getPartitioner()
For diagnostic purposes.
Definition: Ifpack2_BlockRelaxation_decl.hpp:325
BlockRelaxation(const Teuchos::RCP< const row_matrix_type > &Matrix)
Constructor.
Definition: Ifpack2_BlockRelaxation_def.hpp:81