Ifpack2 Templated Preconditioning Package  Version 1.0
Ifpack2_LocalSparseTriangularSolver_decl.hpp
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_LOCALSPARSETRIANGULARSOLVER_DECL_HPP
44 #define IFPACK2_LOCALSPARSETRIANGULARSOLVER_DECL_HPP
45 
48 #include "Teuchos_FancyOStream.hpp"
49 #include <type_traits>
50 
51 #ifndef DOXYGEN_SHOULD_SKIP_THIS
52 namespace Tpetra {
53  // forward declaration of CrsMatrix
54  template<class S, class LO, class GO, class N, const bool classic> class CrsMatrix;
55 } // namespace Tpetra
56 #endif // DOXYGEN_SHOULD_SKIP_THIS
57 
58 namespace Ifpack2 {
59 
82 template<class 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  typedef typename MatrixType::scalar_type scalar_type;
97  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
99  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
101  typedef typename MatrixType::node_type node_type;
102 
104  typedef typename MatrixType::mag_type magnitude_type;
106  typedef Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> map_type;
108  typedef Tpetra::RowMatrix<scalar_type, local_ordinal_type,
110 
111  static_assert (std::is_same<MatrixType, row_matrix_type>::value,
112  "Ifpack2::LocalSparseTriangularSolver: The template parameter "
113  "MatrixType must be a Tpetra::RowMatrix specialization. "
114  "Please don't use Tpetra::CrsMatrix (a subclass of "
115  "Tpetra::RowMatrix) here anymore. The constructor can take "
116  "either a RowMatrix or a CrsMatrix just fine.");
117 
145  LocalSparseTriangularSolver (const Teuchos::RCP<const row_matrix_type>& A);
146 
155  LocalSparseTriangularSolver (const Teuchos::RCP<const row_matrix_type>& A,
156  const Teuchos::RCP<Teuchos::FancyOStream>& out);
157 
159  virtual ~LocalSparseTriangularSolver ();
160 
164  void setParameters (const Teuchos::ParameterList& params);
165 
171  void initialize ();
172 
174  inline bool isInitialized () const {
175  return isInitialized_;
176  }
177 
182  void compute ();
183 
185  inline bool isComputed () const {
186  return isComputed_;
187  }
188 
190 
191 
207  void
208  apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
209  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
210  Teuchos::ETransp mode = Teuchos::NO_TRANS,
211  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one (),
212  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero ()) const;
213 
215  Teuchos::RCP<const map_type> getDomainMap () const;
216 
218  Teuchos::RCP<const map_type> getRangeMap () const;
219 
228  void
229  applyMat (const Tpetra::MultiVector<scalar_type, local_ordinal_type,
231  Tpetra::MultiVector<scalar_type, local_ordinal_type,
233  Teuchos::ETransp mode = Teuchos::NO_TRANS) const;
234 
236  Teuchos::RCP<const Teuchos::Comm<int> > getComm () const;
237 
239  Teuchos::RCP<const row_matrix_type> getMatrix () const {
240  return A_;
241  }
242 
244  double getComputeFlops () const;
245 
247  double getApplyFlops () const;
248 
250  int getNumInitialize () const;
251 
253  int getNumCompute () const;
254 
256  int getNumApply () const;
257 
259  double getInitializeTime () const;
260 
262  double getComputeTime () const;
263 
265  double getApplyTime () const;
266 
268 
270 
272  std::string description() const;
273 
295  void
296  describe (Teuchos::FancyOStream& out,
297  const Teuchos::EVerbosityLevel verbLevel =
298  Teuchos::Describable::verbLevel_default) const;
299 
304  virtual void setMatrix (const Teuchos::RCP<const row_matrix_type>& A);
305 
307 
308 private:
310  Teuchos::RCP<const row_matrix_type> A_;
312  Teuchos::RCP<Teuchos::FancyOStream> out_;
314  Teuchos::RCP<const Tpetra::CrsMatrix<scalar_type,
317  node_type, false> > A_crs_;
318 
319  typedef Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type> MV;
320  mutable Teuchos::RCP<MV> X_colMap_;
321  mutable Teuchos::RCP<MV> Y_rowMap_;
322 
323  bool isInitialized_;
324  bool isComputed_;
325 
326  mutable int numInitialize_;
327  mutable int numCompute_;
328  mutable int numApply_;
329 
330  double initializeTime_;
331  double computeTime_;
332  double applyTime_;
333 
352  void
353  localApply (const MV& X,
354  MV& Y,
355  const Teuchos::ETransp mode,
356  const scalar_type& alpha,
357  const scalar_type& beta) const;
358 };
359 
360 } // namespace Ifpack2
361 
362 #endif // IFPACK2_LOCALSPARSETRIANGULARSOLVER_DECL_HPP
Mix-in interface for preconditioners that can change their matrix after construction.
Definition: Ifpack2_Details_CanChangeMatrix.hpp:93
Teuchos::RCP< const row_matrix_type > getMatrix() const
The original input matrix.
Definition: Ifpack2_LocalSparseTriangularSolver_decl.hpp:239
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, and put the result in Y.
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:196
bool isInitialized() const
Return true if the preconditioner has been successfully initialized.
Definition: Ifpack2_LocalSparseTriangularSolver_decl.hpp:174
int getNumInitialize() const
Return the number of calls to initialize().
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:337
Teuchos::RCP< const map_type > getDomainMap() const
The domain of this operator.
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:447
Teuchos::RCP< const map_type > getRangeMap() const
The range of this operator.
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:460
int getNumCompute() const
Return the number of calls to compute().
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:344
double getApplyTime() const
Return the time spent in apply().
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:372
void compute()
"Numeric" phase of setup
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:163
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print this object with given verbosity to the given output stream.
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:409
MatrixType::global_ordinal_type global_ordinal_type
Type of the global indices of the input matrix.
Definition: Ifpack2_LocalSparseTriangularSolver_decl.hpp:99
MatrixType::node_type node_type
Node type of the input matrix.
Definition: Ifpack2_LocalSparseTriangularSolver_decl.hpp:101
bool isComputed() const
Return true if compute() has been called.
Definition: Ifpack2_LocalSparseTriangularSolver_decl.hpp:185
double getComputeTime() const
Return the time spent in compute().
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:365
int getNumApply() const
Return the number of calls to apply().
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:351
double getComputeFlops() const
Return the number of flops in the computation phase.
"Preconditioner" that solves local sparse triangular systems.
Definition: Ifpack2_LocalSparseTriangularSolver_decl.hpp:83
void initialize()
"Symbolic" phase of setup
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:123
Interface for all Ifpack2 preconditioners.
Definition: Ifpack2_Preconditioner.hpp:107
Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type > map_type
Specialization of Tpetra::Map used by this class.
Definition: Ifpack2_LocalSparseTriangularSolver_decl.hpp:106
virtual void setMatrix(const Teuchos::RCP< const row_matrix_type > &A)
Set this preconditioner&#39;s matrix.
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:472
LocalSparseTriangularSolver(const Teuchos::RCP< const row_matrix_type > &A)
Constructor.
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:53
Declaration of interface for preconditioners that can change their matrix after construction.
void applyMat(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) const
Apply the original input matrix.
double getInitializeTime() const
Return the time spent in initialize().
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:358
double getApplyFlops() const
Return the number of flops for the application of the preconditioner.
MatrixType::local_ordinal_type local_ordinal_type
Type of the local indices of the input matrix.
Definition: Ifpack2_LocalSparseTriangularSolver_decl.hpp:97
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
This operator&#39;s communicator.
void setParameters(const Teuchos::ParameterList &params)
Set this object&#39;s parameters.
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:117
MatrixType::scalar_type scalar_type
Type of the entries of the input matrix.
Definition: Ifpack2_LocalSparseTriangularSolver_decl.hpp:95
std::string description() const
A one-line description of this object.
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:379
Preconditioners and smoothers for Tpetra sparse matrices.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:72
MatrixType::mag_type magnitude_type
Type of the absolute value (magnitude) of a scalar_type value.
Definition: Ifpack2_LocalSparseTriangularSolver_decl.hpp:104
virtual ~LocalSparseTriangularSolver()
Destructor (virtual for memory safety).
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:111
Tpetra::RowMatrix< scalar_type, local_ordinal_type, global_ordinal_type, node_type > row_matrix_type
Specialization of Tpetra::RowMatrix used by this class.
Definition: Ifpack2_LocalSparseTriangularSolver_decl.hpp:109