Ifpack2 Templated Preconditioning Package  Version 1.0
Ifpack2_BlockRelaxation_decl.hpp
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 
46 #include "Ifpack2_ConfigDefs.hpp"
47 #include "Ifpack2_Preconditioner.hpp"
48 #include "Ifpack2_Condest.hpp"
49 #include "Ifpack2_Parameters.hpp"
50 #include "Ifpack2_Partitioner.hpp"
51 
52 #include <Tpetra_Vector.hpp>
53 
54 #include <Teuchos_Assert.hpp>
55 #include <Teuchos_RCP.hpp>
56 #include <Teuchos_Time.hpp>
57 #include <Teuchos_TypeNameTraits.hpp>
58 #include <Teuchos_ScalarTraits.hpp>
59 
60 #include <string>
61 #include <iostream>
62 #include <sstream>
63 
64 namespace Teuchos {
65  // forward declaration
66  class ParameterList;
67 }
68 
69 namespace Ifpack2 {
70 enum RelaxationType {
71  JACOBI,
72  GS,
73  SGS
74 };
75 
77 
136 template<class MatrixType,class ContainerType>
137 class BlockRelaxation : virtual public Ifpack2::Preconditioner<typename MatrixType::scalar_type,typename MatrixType::local_ordinal_type,typename MatrixType::global_ordinal_type,typename MatrixType::node_type> {
138 
139 public:
140  typedef typename MatrixType::scalar_type Scalar;
141  typedef typename MatrixType::local_ordinal_type LocalOrdinal;
142  typedef typename MatrixType::global_ordinal_type GlobalOrdinal;
143  typedef typename MatrixType::node_type Node;
144  typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType magnitudeType;
145 
146  // \name Constructors and Destructors
148 
150  explicit BlockRelaxation(const Teuchos::RCP<const Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >& Matrix);
151 
153  virtual ~BlockRelaxation();
154 
156 
158 
160 
177  void setParameters(const Teuchos::ParameterList& params);
178 
180  void initialize();
181 
183  inline bool isInitialized() const {
184  return(IsInitialized_);
185  }
186 
188  void compute();
189 
191  inline bool isComputed() const {
192  return(IsComputed_);
193  }
194 
196 
198 
199 
201 
211  void apply(const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& X,
212  Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Y,
213  Teuchos::ETransp mode = Teuchos::NO_TRANS,
214  Scalar alpha = Teuchos::ScalarTraits<Scalar>::one(),
215  Scalar beta = Teuchos::ScalarTraits<Scalar>::zero()) const;
216 
218  const Teuchos::RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >& getDomainMap() const;
219 
221  const Teuchos::RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >& getRangeMap() const;
222 
223  bool hasTransposeApply() const;
224 
226 
232  void applyMat(const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& X,
233  Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Y,
234  Teuchos::ETransp mode = Teuchos::NO_TRANS) const;
235 
237 
239 
242  magnitudeType computeCondEst(CondestType CT = Cheap,
243  LocalOrdinal MaxIters = 1550,
244  magnitudeType Tol = 1e-9,
245  const Teuchos::Ptr<const Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &matrix = Teuchos::null);
246 
248 
250 
253  magnitudeType getCondEst() const;
254 
256  const Teuchos::RCP<const Teuchos::Comm<int> > & getComm() const;
257 
259  Teuchos::RCP<const Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > getMatrix() const;
260 
262  double getComputeFlops() const;
263 
265  double getApplyFlops() const;
266 
268  int getNumInitialize() const;
269 
271  int getNumCompute() const;
272 
274  int getNumApply() const;
275 
277  double getInitializeTime() const;
278 
280  double getComputeTime() const;
281 
283  double getApplyTime() const;
284 
286 
288 
289 
291  std::string description() const;
292 
294  void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const;
295 
297 
298 private:
299 
300  // @{ Internal methods
301 
304 
307 
308  virtual void ApplyInverseJacobi(const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& X,
309  Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Y) const;
310 
311  virtual void DoJacobi(const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& X,
312  Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Y) const;
313 
314  virtual void ApplyInverseGS(const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& X,
315  Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Y) const;
316 
317  virtual void DoGaussSeidel(Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& X,
318  Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Y) const;
319 
320  virtual void ApplyInverseSGS(const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& X,
321  Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Y) const;
322 
323  virtual void DoSGS(const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& X,
324  Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Xtmp,
325  Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Y) const;
326 
327  void ExtractSubmatrices();
328 
330 
331  // @{ Internal data and parameters
332 
334  const Teuchos::RCP<const Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > A_;
336  Teuchos::RCP<Teuchos::Time> Time_;
338  Teuchos::RCP<const Tpetra::Import<LocalOrdinal,GlobalOrdinal,Node> > Importer_;
339 
341  Teuchos::RCP<Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > W_;
342  // Level of overlap among blocks (for overlapped Jacobi only).
343  int OverlapLevel_;
345  mutable std::vector<Teuchos::RCP<ContainerType> > Containers_;
347  Teuchos::RCP<Ifpack2::Partitioner<Tpetra::RowGraph<LocalOrdinal,GlobalOrdinal,Node> > > Partitioner_;
348  std::string PartitionerType_;
349 
351  Teuchos::ParameterList List_;
352 
354  int NumSweeps_;
356  LocalOrdinal NumLocalBlocks_;
358  int PrecType_;
360  Scalar MinDiagonalValue_;
362  Scalar DampingFactor_;
364  bool IsParallel_;
366  bool ZeroStartingSolution_;
368  bool DoBackwardGS_;
370  magnitudeType Condest_;
372  bool IsInitialized_;
374  bool IsComputed_;
376  int NumInitialize_;
378  int NumCompute_;
380  mutable int NumApply_;
382  double InitializeTime_;
384  double ComputeTime_;
386  mutable double ApplyTime_;
388  double ComputeFlops_;
390  mutable double ApplyFlops_;
392  size_t NumMyRows_;
394  global_size_t NumGlobalRows_;
396  global_size_t NumGlobalNonzeros_;
397 
399 
400 }; //class BlockRelaxation
401 
402 }//namespace Ifpack2
403 
404 #endif // IFPACK2_BLOCKRELAXATION_DECL_HPP
405 
CondestType
Ifpack2::CondestType: enum to define the type of condition number estimate.
Definition: Ifpack2_CondestType.hpp:50
Ifpack2::BlockRelaxation: defines relaxation preconditioners for Tpetra::RowMatrix objects...
Definition: Ifpack2_BlockRelaxation_decl.hpp:137
bool isComputed() const
Return true if compute() has been called.
Definition: Ifpack2_BlockRelaxation_decl.hpp:191
Base class for all Ifpack2 preconditioners.
Definition: Ifpack2_Preconditioner.hpp:130
bool isInitialized() const
Returns true if the preconditioner has been successfully initialized.
Definition: Ifpack2_BlockRelaxation_decl.hpp:183
Definition: Ifpack2_BlockRelaxation_decl.hpp:64
Ifpack2::Container: a pure virtual class for creating and solving local linear problems.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:67
cheap estimate
Definition: Ifpack2_CondestType.hpp:51