Ifpack2 Templated Preconditioning Package  Version 1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Ifpack2_BlockRelaxation_decl.hpp
Go to the documentation of this file.
1 /*@HEADER
2 // ***********************************************************************
3 //
4 // Ifpack2: Templated 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 "Ifpack2_ContainerFactory.hpp"
53 #include "Teuchos_Time.hpp"
54 #include "Tpetra_BlockCrsMatrix.hpp"
55 #include <type_traits>
56 
57 namespace Ifpack2 {
58 
82 template<class MatrixType, class ContainerType = Container<MatrixType> >
84  virtual public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
85  typename MatrixType::local_ordinal_type,
86  typename MatrixType::global_ordinal_type,
87  typename MatrixType::node_type>,
88  virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
89  typename MatrixType::local_ordinal_type,
90  typename MatrixType::global_ordinal_type,
91  typename MatrixType::node_type> >
92 {
93 public:
95 
96 
98  typedef typename MatrixType::scalar_type scalar_type;
99 
101  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
102 
104  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
106  typedef typename MatrixType::node_type node_type;
107 
110 
112  typedef Tpetra::RowMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type> row_matrix_type;
113 
114  static_assert (std::is_same<MatrixType, row_matrix_type>::value,
115  "Ifpack2::BlockRelaxation: Please use MatrixType = Tpetra::RowMatrix.");
116 
117  static_assert (std::is_same<ContainerType, Container<row_matrix_type> >::value,
118  "Ifpack2::BlockRelaxation: Do NOT specify the (second) "
119  "ContainerType template parameter explicitly. The default "
120  "value is fine. Please instead specify the container type to "
121  "use by setting the \"relaxation: container\" parameter.");
122 
124  typedef Tpetra::Import<local_ordinal_type, global_ordinal_type, node_type> import_type;
125 
126 private:
127  void computeImporter() const;
128 
130 
131  typedef Tpetra::MultiVector<scalar_type, local_ordinal_type,
133  typedef Tpetra::Vector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> vector_type;
136  typedef Tpetra::BlockCrsMatrix<scalar_type, local_ordinal_type,
137  global_ordinal_type, node_type> block_crs_matrix_type;
138  typedef Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> map_type;
139 public:
141 
142  // \name Constructors and Destructors
144 
174  explicit BlockRelaxation (const Teuchos::RCP<const row_matrix_type>& Matrix);
175 
177  virtual ~BlockRelaxation ();
178 
180 
182 
184 
211  void setParameters(const Teuchos::ParameterList& params);
212 
215  getValidParameters () const;
216 
218  void initialize();
219 
221  inline bool isInitialized() const {
222  return(IsInitialized_);
223  }
224 
226  void compute();
227 
229  inline bool isComputed() const {
230  return(IsComputed_);
231  }
232 
234 
236 
259  virtual void
261 
263 
265 
267 
277  void apply(const MV& X,
278  MV& Y,
282 
285 
288 
289  bool hasTransposeApply() const;
290 
292 
298  void applyMat(const MV& X,
299  MV& Y,
300  Teuchos::ETransp mode = Teuchos::NO_TRANS) const;
301 
303 
305 
308 
311 
313  int getNumInitialize() const;
314 
316  int getNumCompute() const;
317 
319  int getNumApply() const;
320 
322  double getInitializeTime() const;
323 
325  double getComputeTime() const;
326 
328  double getApplyTime() const;
329 
331  size_t getNodeSmootherComplexity() const;
332 
334 
336 
338  std::string description() const;
339 
341  void
343  const Teuchos::EVerbosityLevel verbLevel =
345 
347 
350 
351 private:
352 
355 
358  operator= (const BlockRelaxation<MatrixType, ContainerType>& RHS);
359 
360  virtual void ApplyInverseJacobi (const MV& X, MV& Y) const;
361 
362  virtual void ApplyInverseGS (const MV& X, MV& Y) const;
363 
364  virtual void ApplyInverseSGS (const MV& X, MV& Y) const;
365 
368  void ExtractSubmatricesStructure();
369 
371 
373 
376 
379 
381  mutable Teuchos::RCP<Container<row_matrix_type> > Container_;
382 
383  // FIXME (mfh 06 Oct 2014) This doesn't comply with the naming
384  // convention for instance members of a class. Furthermore, the
385  // class should keep the Vector, not the ArrayRCP to the data _in_
386  // the Vector.
387  // FIXED! (amk 10 Nov 2015)
388  mutable Teuchos::RCP<vector_type> DiagRCP_;
389 
392 
395  std::string PartitionerType_;
396 
399 
401  int NumSweeps_;
402 
404  local_ordinal_type NumLocalBlocks_;
405 
407  std::string containerType_;
408 
410  Details::RelaxationType PrecType_;
411 
413  bool IsParallel_;
414 
416  bool ZeroStartingSolution_;
417 
420  bool hasBlockCrsMatrix_;
421 
423  bool DoBackwardGS_;
424 
426  int OverlapLevel_;
427 
429  scalar_type DampingFactor_;
430 
432  bool decouple_;
433 
435  bool IsInitialized_;
436 
438  bool IsComputed_;
439 
441  int NumInitialize_;
442 
444  int NumCompute_;
445 
447  mutable int NumApply_;
448 
450  double InitializeTime_;
451 
453  double ComputeTime_;
454 
456  mutable double ApplyTime_;
457 
459  local_ordinal_type NumLocalRows_;
460 
462  global_ordinal_type NumGlobalRows_;
463 
465  global_ordinal_type NumGlobalNonzeros_;
466 
470 
472 
474 }; //class BlockRelaxation
475 
476 }//namespace Ifpack2
477 
478 #endif // IFPACK2_BLOCKRELAXATION_DECL_HPP
479 
Mix-in interface for preconditioners that can change their matrix after construction.
Definition: Ifpack2_Details_CanChangeMatrix.hpp:93
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
The communicator over which the input matrix is distributed.
Definition: Ifpack2_BlockRelaxation_def.hpp:327
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition: Ifpack2_BlockRelaxation_decl.hpp:104
std::string description() const
A one-line description of this object.
Definition: Ifpack2_BlockRelaxation_def.hpp:963
double getApplyTime() const
Returns the time spent in apply().
Definition: Ifpack2_BlockRelaxation_def.hpp:422
int getNumApply() const
Returns the number of calls to apply().
Definition: Ifpack2_BlockRelaxation_def.hpp:398
Teuchos::RCP< const map_type > getRangeMap() const
Returns the Tpetra::Map object associated with the range of this operator.
Definition: Ifpack2_BlockRelaxation_def.hpp:364
int getNumCompute() const
Returns the number of calls to compute().
Definition: Ifpack2_BlockRelaxation_def.hpp:390
void setParameters(const Teuchos::ParameterList &params)
Sets all the parameters for the preconditioner.
Definition: Ifpack2_BlockRelaxation_def.hpp:173
void compute()
compute the preconditioner for the specified matrix, diagonal perturbation thresholds and relaxation ...
Definition: Ifpack2_BlockRelaxation_def.hpp:662
Block relaxation preconditioners (or smoothers) for Tpetra::RowMatrix and Tpetra::CrsMatrix sparse ma...
Definition: Ifpack2_BlockRelaxation_decl.hpp:83
double getInitializeTime() const
Returns the time spent in initialize().
Definition: Ifpack2_BlockRelaxation_def.hpp:406
double getComputeTime() const
Returns the time spent in compute().
Definition: Ifpack2_BlockRelaxation_def.hpp:414
bool isComputed() const
Return true if compute() has been called.
Definition: Ifpack2_BlockRelaxation_decl.hpp:229
size_t getNodeSmootherComplexity() const
Get a rough estimate of cost per iteration.
Definition: Ifpack2_BlockRelaxation_def.hpp:429
Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitude_type
The type of the magnitude (absolute value) of a matrix entry.
Definition: Ifpack2_BlockRelaxation_decl.hpp:109
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:112
Tpetra::Import< local_ordinal_type, global_ordinal_type, node_type > import_type
Tpetra::Importer specialization for use with MatrixType and compatible MultiVectors.
Definition: Ifpack2_BlockRelaxation_decl.hpp:115
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:118
Interface for all Ifpack2 preconditioners.
Definition: Ifpack2_Preconditioner.hpp:107
Teuchos::RCP< const map_type > getDomainMap() const
Returns the Tpetra::Map object associated with the domain of this operator.
Definition: Ifpack2_BlockRelaxation_def.hpp:350
bool isInitialized() const
Returns true if the preconditioner has been successfully initialized.
Definition: Ifpack2_BlockRelaxation_decl.hpp:221
int getNumInitialize() const
Returns the number of calls to initialize().
Definition: Ifpack2_BlockRelaxation_def.hpp:383
Declaration of interface for preconditioners that can change their matrix after construction.
void initialize()
Initialize.
Definition: Ifpack2_BlockRelaxation_def.hpp:553
static const EVerbosityLevel verbLevel_default
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:1020
MatrixType::node_type node_type
Node type of the input MatrixType.
Definition: Ifpack2_BlockRelaxation_decl.hpp:106
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition: Ifpack2_BlockRelaxation_decl.hpp:101
void applyMat(const MV &X, MV &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS) const
Applies the matrix to a Tpetra::MultiVector.
Definition: Ifpack2_BlockRelaxation_def.hpp:537
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition: Ifpack2_BlockRelaxation_decl.hpp:98
Interface for creating and solving a set of local linear problems.
Definition: Ifpack2_Container_decl.hpp:112
Teuchos::RCP< const row_matrix_type > getMatrix() const
The input matrix of this preconditioner&#39;s constructor.
Definition: Ifpack2_BlockRelaxation_def.hpp:341
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Return a list of all the parameters that this class accepts.
Definition: Ifpack2_BlockRelaxation_def.hpp:124
void apply(const MV &X, MV &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:446
Teuchos::RCP< Ifpack2::Partitioner< Tpetra::RowGraph< local_ordinal_type, global_ordinal_type, node_type > > > getPartitioner()
For diagnostic purposes.
Definition: Ifpack2_BlockRelaxation_decl.hpp:349
BlockRelaxation(const Teuchos::RCP< const row_matrix_type > &Matrix)
Constructor.
Definition: Ifpack2_BlockRelaxation_def.hpp:85