Ifpack2 Templated Preconditioning Package  Version 1.0
Ifpack2_Diagonal_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_DIAGONAL_DECL_HPP
44 #define IFPACK2_DIAGONAL_DECL_HPP
45 
46 #include "Ifpack2_Preconditioner.hpp"
47 
48 namespace Ifpack2 {
49 
51 
67 template<class MatrixType>
68 class Diagonal : virtual public Ifpack2::Preconditioner<typename MatrixType::scalar_type,typename MatrixType::local_ordinal_type,typename MatrixType::global_ordinal_type,typename MatrixType::node_type> {
69 
70 public:
71  typedef typename MatrixType::scalar_type Scalar;
72  typedef typename MatrixType::local_ordinal_type LocalOrdinal;
73  typedef typename MatrixType::global_ordinal_type GlobalOrdinal;
74  typedef typename MatrixType::node_type Node;
75  typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType magnitudeType;
76 
78  Diagonal(const Teuchos::RCP<const MatrixType>& A);
79 
81 
89  Diagonal(const Teuchos::RCP<const Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >& diag);
90 
91 public:
93  virtual ~Diagonal();
94 
96 
99  void setParameters(const Teuchos::ParameterList& params);
100 
102  void initialize();
103 
105  inline bool isInitialized() const {
106  return(isInitialized_);
107  }
108 
110  void compute();
111 
113  inline bool isComputed() const {
114  return(isComputed_);
115  }
116 
118 
119 
121 
131  void apply(const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& X,
132  Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Y,
133  Teuchos::ETransp mode = Teuchos::NO_TRANS,
134  Scalar alpha = Teuchos::ScalarTraits<Scalar>::one(),
135  Scalar beta = Teuchos::ScalarTraits<Scalar>::zero()) const;
136 
138  const Teuchos::RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >& getDomainMap() const
139  { return domainMap_; }
140 
142  const Teuchos::RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >& getRangeMap() const
143  { return rangeMap_; }
144 
146 
152  void applyMat(const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& X,
153  Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Y,
154  Teuchos::ETransp mode = Teuchos::NO_TRANS) const;
155 
157 
158 
160 
163 
173  template <class DomainScalar, class RangeScalar>
174  void applyTempl(const Tpetra::MultiVector<DomainScalar,LocalOrdinal,GlobalOrdinal,Node>& X,
175  Tpetra::MultiVector<RangeScalar,LocalOrdinal,GlobalOrdinal,Node>& Y,
176  Teuchos::ETransp mode = Teuchos::NO_TRANS,
177  RangeScalar alpha = Teuchos::ScalarTraits<Scalar>::one(),
178  RangeScalar beta = Teuchos::ScalarTraits<Scalar>::zero()) const;
179 
181  magnitudeType computeCondEst(CondestType CT = Cheap,
182  LocalOrdinal MaxIters = 1550,
183  magnitudeType Tol = 1e-9,
184  const Teuchos::Ptr<const Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &matrix = Teuchos::null);
185 
187 
189 
192  magnitudeType getCondEst() const
193  { return condEst_; }
194 
196  const Teuchos::RCP<const Teuchos::Comm<int> > & getComm() const;
197 
199  Teuchos::RCP<const Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > getMatrix() const
200  { return matrix_; }
201 
203  double getComputeFlops() const;
204 
206  double getApplyFlops() 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 
229 
230 
232  std::string description() const;
233 
235  void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const;
236 
238 
239  private:
240  bool isInitialized_;
241  bool isComputed_;
242  Teuchos::RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > domainMap_;
243  Teuchos::RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > rangeMap_;
244  Teuchos::RCP<const MatrixType> matrix_;
245  Teuchos::RCP<const Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > inversediag_;
246  Teuchos::ArrayRCP<size_t> offsets_;
247 
248  mutable int numInitialize_;
249  mutable int numCompute_;
250  mutable int numApply_;
251 
252  double initializeTime_;
253  double computeTime_;
254  double applyTime_;
255 
256  magnitudeType condEst_;
257 };
258 
273 template<class MatrixType,class VectorType>
274 Teuchos::RCP<Ifpack2::Diagonal<MatrixType> >
275 createDiagonalPreconditioner(const Teuchos::RCP<const VectorType>& invdiag)
276 {
277  return Teuchos::rcp(new Ifpack2::Diagonal<MatrixType>(invdiag));
278 }
279 
280 }//namespace Ifpack2
281 
282 #endif
std::string description() const
Return a simple one-line description of this object.
Definition: Ifpack2_Diagonal_def.hpp:234
void applyMat(const Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS) const
Applies the matrix to a Tpetra::MultiVector.
CondestType
Ifpack2::CondestType: enum to define the type of condition number estimate.
Definition: Ifpack2_CondestType.hpp:50
const Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > & getDomainMap() const
Returns the Tpetra::Map object associated with the domain of this operator.
Definition: Ifpack2_Diagonal_decl.hpp:138
const Teuchos::RCP< const Teuchos::Comm< int > > & getComm() const
Returns the Tpetra::BlockMap object associated with the range of this matrix operator.
Teuchos::RCP< Ifpack2::Diagonal< MatrixType > > createDiagonalPreconditioner(const Teuchos::RCP< const VectorType > &invdiag)
Definition: Ifpack2_Diagonal_decl.hpp:275
A class for diagonal preconditioning.
Definition: Ifpack2_Diagonal_decl.hpp:68
bool isInitialized() const
Returns true if the preconditioner has been successfully initialized.
Definition: Ifpack2_Diagonal_decl.hpp:105
magnitudeType computeCondEst(CondestType CT=Cheap, LocalOrdinal MaxIters=1550, magnitudeType Tol=1e-9, const Teuchos::Ptr< const Tpetra::RowMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &matrix=Teuchos::null)
Computes the estimated condition number and returns the value.
Definition: Ifpack2_Diagonal_def.hpp:185
double getApplyFlops() const
Returns the number of flops for the application of the preconditioner.
void apply(const Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=Teuchos::ScalarTraits< Scalar >::one(), Scalar beta=Teuchos::ScalarTraits< Scalar >::zero()) const
Applies the preconditioner to X, returns the result in Y.
Definition: Ifpack2_Diagonal_def.hpp:129
const Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > & getRangeMap() const
Returns the Tpetra::Map object associated with the range of this operator.
Definition: Ifpack2_Diagonal_decl.hpp:142
double getComputeFlops() const
Returns the number of flops in the computation phase.
void compute()
compute the preconditioner
Definition: Ifpack2_Diagonal_def.hpp:106
Base class for all Ifpack2 preconditioners.
Definition: Ifpack2_Preconditioner.hpp:130
void applyTempl(const Tpetra::MultiVector< DomainScalar, LocalOrdinal, GlobalOrdinal, Node > &X, Tpetra::MultiVector< RangeScalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, RangeScalar alpha=Teuchos::ScalarTraits< Scalar >::one(), RangeScalar beta=Teuchos::ScalarTraits< Scalar >::zero()) const
Applies the preconditioner to X, returns the result in Y.
Definition: Ifpack2_Diagonal_def.hpp:147
virtual ~Diagonal()
Destructor.
Definition: Ifpack2_Diagonal_def.hpp:82
double getComputeTime() const
Returns the time spent in compute().
Definition: Ifpack2_Diagonal_def.hpp:224
int getNumCompute() const
Returns the number of calls to compute().
Definition: Ifpack2_Diagonal_def.hpp:209
magnitudeType getCondEst() const
Returns the computed estimated condition number, or -1.0 if no computed.
Definition: Ifpack2_Diagonal_decl.hpp:192
double getInitializeTime() const
Returns the time spent in initialize().
Definition: Ifpack2_Diagonal_def.hpp:219
void setParameters(const Teuchos::ParameterList &params)
Sets parameters on this object.
Definition: Ifpack2_Diagonal_def.hpp:87
Diagonal(const Teuchos::RCP< const MatrixType > &A)
Constructor to create a Diagonal preconditioner using a Tpetra::CrsMatrix.
Definition: Ifpack2_Diagonal_def.hpp:52
int getNumInitialize() const
Returns the number of calls to initialize().
Definition: Ifpack2_Diagonal_def.hpp:204
double getApplyTime() const
Returns the time spent in apply().
Definition: Ifpack2_Diagonal_def.hpp:229
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_Diagonal_def.hpp:240
Teuchos::RCP< const Tpetra::RowMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getMatrix() const
Returns a reference to the matrix to be preconditioned.
Definition: Ifpack2_Diagonal_decl.hpp:199
Ifpack2::Container: a pure virtual class for creating and solving local linear problems.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:67
void initialize()
Initialize.
Definition: Ifpack2_Diagonal_def.hpp:92
cheap estimate
Definition: Ifpack2_CondestType.hpp:51
int getNumApply() const
Returns the number of calls to apply().
Definition: Ifpack2_Diagonal_def.hpp:214
bool isComputed() const
Return true if compute() has been called.
Definition: Ifpack2_Diagonal_decl.hpp:113