Ifpack2 Templated Preconditioning Package  Version 1.0
Ifpack2_Hiptmair_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 
46 
47 #ifndef IFPACK2_HIPTMAIR_DECL_HPP
48 #define IFPACK2_HIPTMAIR_DECL_HPP
49 
51 #include "Tpetra_Map_fwd.hpp"
52 #include <type_traits>
53 
54 namespace Teuchos {
55  class ParameterList; // forward declaration
56 }
57 
58 namespace Ifpack2 {
59 
70  template<class MatrixType>
71  class Hiptmair :
72  virtual public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
73  typename MatrixType::local_ordinal_type,
74  typename MatrixType::global_ordinal_type,
75  typename MatrixType::node_type>
76  {
77  public:
78  // \name Public typedefs
80 
82  typedef typename MatrixType::scalar_type scalar_type;
83 
85  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
86 
88  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
89 
91  typedef typename MatrixType::node_type node_type;
92 
94  typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
95 
97  typedef Tpetra::RowMatrix<scalar_type,
101 
102  static_assert(std::is_same<MatrixType, row_matrix_type>::value, "Ifpack2::Hiptmair: The template parameter MatrixType must be a Tpetra::RowMatrix specialization. Please don't use Tpetra::CrsMatrix (a subclass of Tpetra::RowMatrix) here anymore. The constructor can take either a RowMatrix or a CrsMatrix just fine.");
103 
109 
111  // \name Constructors and Destructors
113 
115  explicit Hiptmair (const Teuchos::RCP<const row_matrix_type>& A);
116 
117 
119  explicit Hiptmair (const Teuchos::RCP<const row_matrix_type>& A,
120  const Teuchos::RCP<const row_matrix_type>& PtAP,
121  const Teuchos::RCP<const row_matrix_type>& P,
122  const Teuchos::RCP<const row_matrix_type>& Pt=Teuchos::null);
123 
125  virtual ~Hiptmair ();
126 
128 
130 
140  void setParameters (const Teuchos::ParameterList& params);
141 
142  bool supportsZeroStartingSolution() { return true; }
143 
144  void setZeroStartingSolution (bool zeroStartingSolution) { ZeroStartingSolution_ = zeroStartingSolution; };
145 
147  void initialize ();
148 
150  inline bool isInitialized () const {
151  return IsInitialized_;
152  }
153 
155  void compute ();
156 
158  inline bool isComputed() const {
159  return IsComputed_;
160  }
161 
163 
165 
167  void
168  apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
169  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
170  Teuchos::ETransp mode = Teuchos::NO_TRANS,
171  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
172  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
173 
174  void
175  applyHiptmairSmoother(const Tpetra::MultiVector<typename MatrixType::scalar_type,
176  typename MatrixType::local_ordinal_type,
177  typename MatrixType::global_ordinal_type,
178  typename MatrixType::node_type>& X,
179  Tpetra::MultiVector<typename MatrixType::scalar_type,
180  typename MatrixType::local_ordinal_type,
181  typename MatrixType::global_ordinal_type,
182  typename MatrixType::node_type>& Y) const;
183 
185  void updateCachedMultiVectors(const Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> >& map1,
186  const Teuchos::RCP<const Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type>>& map2,
187  size_t numVecs) const;
188 
190  Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> > getDomainMap() const;
191 
193  Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> > getRangeMap() const;
194 
196  bool hasTransposeApply() const;
197 
199 
201 
203  Teuchos::RCP<const Teuchos::Comm<int> > getComm() const;
204 
206  Teuchos::RCP<const Tpetra::RowMatrix<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > getMatrix() const;
207 
209  int getNumInitialize() const;
210 
212  int getNumCompute() const;
213 
215  int getNumApply() const;
216 
218  double getInitializeTime() const;
219 
221  double getComputeTime() const;
222 
224  double getApplyTime() const;
225 
227 
228 
230  std::string description() const;
231 
233  void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const;
234 
236 
237  private:
238  typedef Teuchos::ScalarTraits<scalar_type> STS;
239  typedef Teuchos::ScalarTraits<magnitude_type> STM;
240 
242  Hiptmair (const Hiptmair<MatrixType>& RHS);
243 
245  Hiptmair<MatrixType>& operator= (const Hiptmair<MatrixType>& RHS);
246 
248  // A - matrix in primary space
249  // PtAP - matrix in auxiliary space
250  // P - prolongator matrix
251  Teuchos::RCP<const row_matrix_type> A_, PtAP_, P_, Pt_;
252 
254  std::string precType1_, precType2_, preOrPost_;
255 
257  bool ZeroStartingSolution_;
258 
260  bool ImplicitTranspose_;
261 
263  Teuchos::ParameterList precList1_, precList2_;
264 
266  bool IsInitialized_;
268  bool IsComputed_;
270  int NumInitialize_;
272  int NumCompute_;
274  mutable int NumApply_;
276  double InitializeTime_;
278  double ComputeTime_;
280  mutable double ApplyTime_;
282  Teuchos::RCP<prec_type> ifpack2_prec1_, ifpack2_prec2_;
284  mutable Teuchos::RCP<Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > cachedResidual1_;
285  mutable Teuchos::RCP<Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > cachedSolution1_;
286  mutable Teuchos::RCP<Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > cachedResidual2_;
287  mutable Teuchos::RCP<Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > cachedSolution2_;
288  };
289 
290 } // namespace Ifpack2
291 
292 #endif // IFPACK2_HIPTMAIR_DECL_HPP
void initialize()
Do any initialization that depends on the input matrix&#39;s structure.
Definition: Ifpack2_Hiptmair_def.hpp:257
int getNumInitialize() const
Returns the number of calls to Initialize().
Definition: Ifpack2_Hiptmair_def.hpp:221
void setZeroStartingSolution(bool zeroStartingSolution)
Set this preconditioner&#39;s parameters.
Definition: Ifpack2_Hiptmair_decl.hpp:144
double getComputeTime() const
Returns the time spent in Compute().
Definition: Ifpack2_Hiptmair_def.hpp:245
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition: Ifpack2_Hiptmair_decl.hpp:85
Hiptmair(const Teuchos::RCP< const row_matrix_type > &A)
Constructor that takes 1 Tpetra matrix (assumes we&#39;ll get the rest off the parameter list) ...
Definition: Ifpack2_Hiptmair_def.hpp:90
double getApplyTime() const
Returns the time spent in apply().
Definition: Ifpack2_Hiptmair_def.hpp:251
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition: Ifpack2_Hiptmair_decl.hpp:82
bool isComputed() const
Return true if compute() completed successfully, else false.
Definition: Ifpack2_Hiptmair_decl.hpp:158
Teuchos::RCP< const Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type > > getRangeMap() const
Tpetra::Map representing the range of this operator.
Definition: Ifpack2_Hiptmair_def.hpp:202
int getNumCompute() const
Returns the number of calls to Compute().
Definition: Ifpack2_Hiptmair_def.hpp:227
void setParameters(const Teuchos::ParameterList &params)
Set the preconditioner&#39;s parameters.
Definition: Ifpack2_Hiptmair_def.hpp:117
Tpetra::RowMatrix< scalar_type, local_ordinal_type, global_ordinal_type, node_type > row_matrix_type
Type of the Tpetra::RowMatrix specialization that this class uses.
Definition: Ifpack2_Hiptmair_decl.hpp:100
Teuchos::RCP< const Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type > > getDomainMap() const
Tpetra::Map representing the domain of this operator.
Definition: Ifpack2_Hiptmair_def.hpp:190
void updateCachedMultiVectors(const Teuchos::RCP< const Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type > > &map1, const Teuchos::RCP< const Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type >> &map2, size_t numVecs) const
A service routine for updating the cached MultiVectors.
Definition: Ifpack2_Hiptmair_def.hpp:417
Teuchos::RCP< const Tpetra::RowMatrix< scalar_type, local_ordinal_type, global_ordinal_type, node_type > > getMatrix() const
Returns a reference to the matrix to be preconditioned.
Definition: Ifpack2_Hiptmair_def.hpp:183
Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitude_type
The type of the magnitude (absolute value) of a matrix entry.
Definition: Ifpack2_Hiptmair_decl.hpp:94
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition: Ifpack2_Hiptmair_decl.hpp:88
Wrapper for Hiptmair smoothers.
Definition: Ifpack2_Hiptmair_decl.hpp:71
bool isInitialized() const
Return true if initialize() completed successfully, else false.
Definition: Ifpack2_Hiptmair_decl.hpp:150
MatrixType::node_type node_type
The Node type used by the input MatrixType.
Definition: Ifpack2_Hiptmair_decl.hpp:91
Interface for all Ifpack2 preconditioners.
Definition: Ifpack2_Preconditioner.hpp:107
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_Hiptmair_def.hpp:618
void compute()
Do any initialization that depends on the input matrix&#39;s values.
Definition: Ifpack2_Hiptmair_def.hpp:300
virtual ~Hiptmair()
Destructor.
Definition: Ifpack2_Hiptmair_def.hpp:114
double getInitializeTime() const
Returns the time spent in Initialize().
Definition: Ifpack2_Hiptmair_def.hpp:239
Definition: Ifpack2_Container_decl.hpp:576
std::string description() const
Return a simple one-line description of this object.
Definition: Ifpack2_Hiptmair_def.hpp:583
bool hasTransposeApply() const
Whether this object&#39;s apply() method can apply the transpose (or conjugate transpose, if applicable).
Definition: Ifpack2_Hiptmair_def.hpp:213
int getNumApply() const
Returns the number of calls to apply().
Definition: Ifpack2_Hiptmair_def.hpp:233
Ifpack2::Preconditioner< scalar_type, local_ordinal_type, global_ordinal_type, node_type > prec_type
Type of the Ifpack2::Preconditioner specialization from which this class inherits.
Definition: Ifpack2_Hiptmair_decl.hpp:102
Preconditioners and smoothers for Tpetra sparse matrices.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:74
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Returns the operator&#39;s communicator.
Definition: Ifpack2_Hiptmair_def.hpp:172
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
Apply the preconditioner to X, putting the result in Y.
Definition: Ifpack2_Hiptmair_def.hpp:343