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 "Tpetra_BlockCrsMatrix.hpp"
54 #include <type_traits>
55 
56 namespace Ifpack2 {
57 
81 template<class MatrixType, class ContainerType = Container<MatrixType> >
83  virtual public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
84  typename MatrixType::local_ordinal_type,
85  typename MatrixType::global_ordinal_type,
86  typename MatrixType::node_type>,
87  virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
88  typename MatrixType::local_ordinal_type,
89  typename MatrixType::global_ordinal_type,
90  typename MatrixType::node_type> >
91 {
92 public:
94 
95 
97  typedef typename MatrixType::scalar_type scalar_type;
98 
100  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
101 
103  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
105  typedef typename MatrixType::node_type node_type;
106 
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 
116  static_assert (std::is_same<ContainerType, Container<row_matrix_type> >::value,
117  "Ifpack2::BlockRelaxation: Do NOT specify the (second) "
118  "ContainerType template parameter explicitly. The default "
119  "value is fine. Please instead specify the container type to "
120  "use by setting the \"relaxation: container\" parameter.");
121 
123  typedef Tpetra::Import<local_ordinal_type, global_ordinal_type, node_type> import_type;
124 
125 private:
126 
131  void setParametersImpl(Teuchos::ParameterList& params);
132 
133  void computeImporter() const;
134 
136 
137  typedef Tpetra::MultiVector<scalar_type, local_ordinal_type,
139  typedef Tpetra::Vector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> vector_type;
142  typedef Tpetra::BlockCrsMatrix<scalar_type, local_ordinal_type,
143  global_ordinal_type, node_type> block_crs_matrix_type;
144  typedef Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> map_type;
145 public:
147 
148  // \name Constructors and Destructors
150 
180  explicit BlockRelaxation (const Teuchos::RCP<const row_matrix_type>& Matrix);
181 
183  virtual ~BlockRelaxation ();
184 
186 
188 
190 
217  void setParameters(const Teuchos::ParameterList& params);
218 
219  bool supportsZeroStartingSolution() { return true; }
220 
221  void setZeroStartingSolution (bool zeroStartingSolution) { ZeroStartingSolution_ = zeroStartingSolution; };
222 
225  getValidParameters () const;
226 
228  void initialize();
229 
231  inline bool isInitialized() const {
232  return(IsInitialized_);
233  }
234 
236  void compute();
237 
239  inline bool isComputed() const {
240  return(IsComputed_);
241  }
242 
244 
246 
269  virtual void
271 
273 
275 
277 
287  void apply(const MV& X,
288  MV& Y,
292 
295 
298 
299  bool hasTransposeApply() const;
300 
302 
308  void applyMat(const MV& X,
309  MV& Y,
310  Teuchos::ETransp mode = Teuchos::NO_TRANS) const;
311 
313 
315 
318 
321 
323  int getNumInitialize() const;
324 
326  int getNumCompute() const;
327 
329  int getNumApply() const;
330 
332  double getInitializeTime() const;
333 
335  double getComputeTime() const;
336 
338  double getApplyTime() const;
339 
341  size_t getNodeSmootherComplexity() const;
342 
344 
346 
348  std::string description() const;
349 
351  void
353  const Teuchos::EVerbosityLevel verbLevel =
355 
357 
360 
361 private:
362 
365 
368  operator= (const BlockRelaxation<MatrixType, ContainerType>& RHS);
369 
370  virtual void ApplyInverseJacobi (const MV& X, MV& Y) const;
371 
372  virtual void ApplyInverseGS (const MV& X, MV& Y) const;
373 
374  virtual void ApplyInverseSGS (const MV& X, MV& Y) const;
375 
378  void ExtractSubmatricesStructure();
379 
381 
383 
386 
388  mutable Teuchos::RCP<Container<row_matrix_type> > Container_;
389 
390  // FIXME (mfh 06 Oct 2014) This doesn't comply with the naming
391  // convention for instance members of a class. Furthermore, the
392  // class should keep the Vector, not the ArrayRCP to the data _in_
393  // the Vector.
394  // FIXED! (amk 10 Nov 2015)
395  mutable Teuchos::RCP<vector_type> DiagRCP_;
396 
399 
402  std::string PartitionerType_;
403 
406 
408  int NumSweeps_;
409 
411  local_ordinal_type NumLocalBlocks_;
412 
414  std::string containerType_;
415 
417  Details::RelaxationType PrecType_;
418 
420  bool IsParallel_;
421 
423  bool ZeroStartingSolution_;
424 
427  bool hasBlockCrsMatrix_;
428 
430  bool DoBackwardGS_;
431 
433  int OverlapLevel_;
434 
436  //only valid with block Jacobi relaxation and overlapping blocks (e.g., defined by "partitioner: type" "user" and "parts: " or "global ID parts:"). Average solutions in overlapped regions (i.e., after summing different solutions divide by number of blocks contain this dof). When false (the default) symmetric averaging performed (i.e., average residuals and solutions).
437  bool nonsymCombine_;
438 
440  std::string schwarzCombineMode_;
441 
443  scalar_type DampingFactor_;
444 
446  bool decouple_;
447 
449  bool IsInitialized_;
450 
452  bool IsComputed_;
453 
455  int NumInitialize_;
456 
458  int NumCompute_;
459 
461  bool TimerForApply_;
462 
464  mutable int NumApply_;
465 
467  double InitializeTime_;
468 
470  double ComputeTime_;
471 
473  mutable double ApplyTime_;
474 
476  local_ordinal_type NumLocalRows_;
477 
479  global_ordinal_type NumGlobalRows_;
480 
482  global_ordinal_type NumGlobalNonzeros_;
483 
487 
489 
491 }; //class BlockRelaxation
492 
493 }//namespace Ifpack2
494 
495 #endif // IFPACK2_BLOCKRELAXATION_DECL_HPP
496 
void setZeroStartingSolution(bool zeroStartingSolution)
Set this preconditioner&#39;s parameters.
Definition: Ifpack2_BlockRelaxation_decl.hpp:221
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:371
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition: Ifpack2_BlockRelaxation_decl.hpp:103
std::string description() const
A one-line description of this object.
Definition: Ifpack2_BlockRelaxation_def.hpp:1076
double getApplyTime() const
Returns the time spent in apply().
Definition: Ifpack2_BlockRelaxation_def.hpp:466
int getNumApply() const
Returns the number of calls to apply().
Definition: Ifpack2_BlockRelaxation_def.hpp:442
Teuchos::RCP< const map_type > getRangeMap() const
Returns the Tpetra::Map object associated with the range of this operator.
Definition: Ifpack2_BlockRelaxation_def.hpp:408
int getNumCompute() const
Returns the number of calls to compute().
Definition: Ifpack2_BlockRelaxation_def.hpp:434
void setParameters(const Teuchos::ParameterList &params)
Sets all the parameters for the preconditioner.
Definition: Ifpack2_BlockRelaxation_def.hpp:186
void compute()
compute the preconditioner for the specified matrix, diagonal perturbation thresholds and relaxation ...
Definition: Ifpack2_BlockRelaxation_def.hpp:761
Block relaxation preconditioners (or smoothers) for Tpetra::RowMatrix and Tpetra::CrsMatrix sparse ma...
Definition: Ifpack2_BlockRelaxation_decl.hpp:82
double getInitializeTime() const
Returns the time spent in initialize().
Definition: Ifpack2_BlockRelaxation_def.hpp:450
double getComputeTime() const
Returns the time spent in compute().
Definition: Ifpack2_BlockRelaxation_def.hpp:458
bool isComputed() const
Return true if compute() has been called.
Definition: Ifpack2_BlockRelaxation_decl.hpp:239
size_t getNodeSmootherComplexity() const
Get a rough estimate of cost per iteration.
Definition: Ifpack2_BlockRelaxation_def.hpp:473
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
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:114
virtual void setMatrix(const Teuchos::RCP< const row_matrix_type > &A)
Change the matrix to be preconditioned.
Definition: Ifpack2_BlockRelaxation_def.hpp:61
virtual ~BlockRelaxation()
Destructor.
Definition: Ifpack2_BlockRelaxation_def.hpp:124
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:394
bool isInitialized() const
Returns true if the preconditioner has been successfully initialized.
Definition: Ifpack2_BlockRelaxation_decl.hpp:231
int getNumInitialize() const
Returns the number of calls to initialize().
Definition: Ifpack2_BlockRelaxation_def.hpp:427
Declaration of interface for preconditioners that can change their matrix after construction.
void initialize()
Initialize.
Definition: Ifpack2_BlockRelaxation_def.hpp:609
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:1140
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:100
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:593
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition: Ifpack2_BlockRelaxation_decl.hpp:97
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:385
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Return a list of all the parameters that this class accepts.
Definition: Ifpack2_BlockRelaxation_def.hpp:130
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:490
Teuchos::RCP< Ifpack2::Partitioner< Tpetra::RowGraph< local_ordinal_type, global_ordinal_type, node_type > > > getPartitioner()
For diagnostic purposes.
Definition: Ifpack2_BlockRelaxation_decl.hpp:359
BlockRelaxation(const Teuchos::RCP< const row_matrix_type > &Matrix)
Constructor.
Definition: Ifpack2_BlockRelaxation_def.hpp:89