Ifpack2 Templated Preconditioning Package  Version 1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Ifpack2_Details_TriDiSolver_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_DETAILS_TRIDISOLVER_DECL_HPP
44 #define IFPACK2_DETAILS_TRIDISOLVER_DECL_HPP
45 
48 
49 #include "Ifpack2_ConfigDefs.hpp"
52 #include "Ifpack2_Details_LapackSupportsScalar.hpp"
53 #include "Tpetra_RowMatrix.hpp"
54 #include "Tpetra_Import_fwd.hpp"
55 #include "Tpetra_Export_fwd.hpp"
57 #include <type_traits>
58 
59 namespace Ifpack2 {
60 namespace Details {
61 
74 template<class MatrixType,
75  const bool stub = ! LapackSupportsScalar<typename MatrixType::scalar_type>::value>
76 class TriDiSolver :
77  public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
78  typename MatrixType::local_ordinal_type,
79  typename MatrixType::global_ordinal_type,
80  typename MatrixType::node_type>,
81  virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
82  typename MatrixType::local_ordinal_type,
83  typename MatrixType::global_ordinal_type,
84  typename MatrixType::node_type> >
85 {};
86 
88 template<class MatrixType>
89 class TriDiSolver<MatrixType, false> :
90  public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
91  typename MatrixType::local_ordinal_type,
92  typename MatrixType::global_ordinal_type,
93  typename MatrixType::node_type>,
94  virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
95  typename MatrixType::local_ordinal_type,
96  typename MatrixType::global_ordinal_type,
97  typename MatrixType::node_type> >
98 {
99 public:
101 
102 
106  typedef MatrixType matrix_type;
107 
109  typedef typename MatrixType::scalar_type scalar_type;
110 
112  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
113 
115  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
116 
118  typedef typename MatrixType::node_type node_type;
119 
122 
124  typedef Tpetra::RowMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type> row_matrix_type;
125 
126  static_assert(std::is_same<MatrixType, row_matrix_type>::value, "Ifpack2::Details::TriDiSolver: 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.");
127 
129  typedef Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> map_type;
130 
132 
134 
139 
141  virtual ~TriDiSolver ();
142 
144 
146 
147 
153 
159 
165  void
166  apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
167  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
171 
173 
175  void setParameters (const Teuchos::ParameterList& params);
176 
186  void initialize ();
187 
189  bool isInitialized () const;
190 
200  void compute ();
201 
203  bool isComputed () const;
204 
207 
210 
212  int getNumInitialize () const;
213 
215  int getNumCompute () const;
216 
218  int getNumApply() const;
219 
221  double getInitializeTime() const;
222 
224  double getComputeTime() const;
225 
227  double getApplyTime() const;
228 
230 
232 
234  std::string description () const;
235 
237  void
238  describe (Teuchos::FancyOStream &out,
239  const Teuchos::EVerbosityLevel verbLevel =
242 private:
243 
245  void
246  describeLocal (Teuchos::FancyOStream& out,
247  const Teuchos::EVerbosityLevel verbLevel) const;
248 
250  void reset ();
251 
259  static void
260  extract (Teuchos::SerialTriDiMatrix<int, scalar_type>& A_local_tridi,
261  const row_matrix_type& A_local);
262 
272  static void
274  const Teuchos::ArrayView<int>& ipiv);
275 
277  typedef Tpetra::MultiVector<scalar_type, local_ordinal_type,
279 
281  typedef Tpetra::Import<local_ordinal_type,
282  global_ordinal_type, node_type> import_type;
283 
285  typedef Tpetra::Export<local_ordinal_type,
286  global_ordinal_type, node_type> export_type;
287 
290 
299  void
300  applyImpl (const MV& X,
301  MV& Y,
302  const Teuchos::ETransp mode,
303  const scalar_type alpha,
304  const scalar_type beta) const;
305 
308 
311 
314 
316  Teuchos::Array<int> ipiv_;
317 
319  double initializeTime_;
320 
322  double computeTime_;
323 
325  mutable double applyTime_;
326 
328  int numInitialize_;
329 
331  int numCompute_;
332 
334  mutable int numApply_;
335 
337  bool isInitialized_;
338 
340  bool isComputed_;
341 };
342 
343 
345 template<class MatrixType>
346 class TriDiSolver<MatrixType, true> :
347  public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
348  typename MatrixType::local_ordinal_type,
349  typename MatrixType::global_ordinal_type,
350  typename MatrixType::node_type>,
351  virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
352  typename MatrixType::local_ordinal_type,
353  typename MatrixType::global_ordinal_type,
354  typename MatrixType::node_type> >
355 {
356 public:
358 
359 
363  typedef MatrixType matrix_type;
364 
366  typedef typename MatrixType::scalar_type scalar_type;
367 
369  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
370 
372  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
373 
375  typedef typename MatrixType::node_type node_type;
376 
379 
381  typedef Tpetra::RowMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type> row_matrix_type;
382 
383  static_assert(std::is_same<MatrixType, row_matrix_type>::value, "Ifpack2::Details::TriDiSolver: 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.");
384 
386  typedef Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> map_type;
387 
389 
391 
396 
398  virtual ~TriDiSolver ();
399 
401 
403 
409 
415 
421  void
422  apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
423  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
425  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
426  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
427 
429 
431  void setParameters (const Teuchos::ParameterList& params);
432 
442  void initialize ();
443 
445  bool isInitialized () const;
446 
456  void compute ();
457 
459  bool isComputed () const;
460 
463 
466 
468  int getNumInitialize () const;
469 
471  int getNumCompute () const;
472 
474  int getNumApply() const;
475 
477  double getInitializeTime() const;
478 
480  double getComputeTime() const;
481 
483  double getApplyTime() const;
484 
486 
488 
490  std::string description () const;
491 
493  void
494  describe (Teuchos::FancyOStream &out,
495  const Teuchos::EVerbosityLevel verbLevel =
497 
498  void
499  describeLocal (Teuchos::FancyOStream& out,
500  const Teuchos::EVerbosityLevel verbLevel) const;
501 
503 private:
505  typedef Tpetra::MultiVector<scalar_type, local_ordinal_type,
506  global_ordinal_type, node_type> MV;
507 };
508 
509 } // namespace Details
510 } // namespace Ifpack2
511 
512 #endif // IFPACK2_DETAILS_TRIDISOLVER_DECL_HPP
virtual Teuchos::RCP< const Tpetra::Map< MatrixType::local_ordinal_type, MatrixType::global_ordinal_type, MatrixType::node_type > > getDomainMap() const =0
The domain Map of this operator.
Mix-in interface for preconditioners that can change their matrix after construction.
Definition: Ifpack2_Details_CanChangeMatrix.hpp:93
virtual Teuchos::RCP< const Tpetra::RowMatrix< MatrixType::scalar_type, MatrixType::local_ordinal_type, MatrixType::global_ordinal_type, MatrixType::node_type > > getMatrix() const =0
The input matrix given to the constructor.
Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitude_type
The type of the absolute value (magnitude) of a scalar_type.
Definition: Ifpack2_Details_TriDiSolver_decl.hpp:121
&quot;Preconditioner&quot; that uses LAPACK&#39;s tridi LU.
Definition: Ifpack2_Details_TriDiSolver_decl.hpp:76
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input (global) matrix.
Definition: Ifpack2_Details_TriDiSolver_decl.hpp:115
Teuchos::ScalarTraits< MatrixType::scalar_type >::magnitudeType magnitude_type
The type of the magnitude (absolute value) of a matrix entry.
Definition: Ifpack2_Preconditioner.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_Details_TriDiSolver_decl.hpp:124
MatrixType::scalar_type scalar_type
The type of entries in the input (global) matrix.
Definition: Ifpack2_Details_TriDiSolver_decl.hpp:109
virtual Teuchos::RCP< const Tpetra::Map< MatrixType::local_ordinal_type, MatrixType::global_ordinal_type, MatrixType::node_type > > getRangeMap() const =0
The range Map of this operator.
MatrixType matrix_type
The first template parameter of this class.
Definition: Ifpack2_Details_TriDiSolver_decl.hpp:106
Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type > map_type
Specialization of Tpetra::Map used by this class.
Definition: Ifpack2_Details_TriDiSolver_decl.hpp:126
Interface for all Ifpack2 preconditioners.
Definition: Ifpack2_Preconditioner.hpp:107
Declaration of interface for preconditioners that can change their matrix after construction.
static const EVerbosityLevel verbLevel_default
virtual bool isComputed() const =0
True if the preconditioner has been successfully computed, else false.
virtual void setParameters(const Teuchos::ParameterList &List)=0
Set this preconditioner&#39;s parameters.
virtual void apply(const Tpetra::MultiVector< MatrixType::scalar_type, MatrixType::local_ordinal_type, MatrixType::global_ordinal_type, MatrixType::node_type > &X, Tpetra::MultiVector< MatrixType::scalar_type, MatrixType::local_ordinal_type, MatrixType::global_ordinal_type, MatrixType::node_type > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, MatrixType::scalar_typealpha=Teuchos::ScalarTraits< MatrixType::scalar_type >::one(), MatrixType::scalar_typebeta=Teuchos::ScalarTraits< MatrixType::scalar_type >::zero()) const =0
Apply the preconditioner to X, putting the result in Y.
virtual bool isInitialized() const =0
True if the preconditioner has been successfully initialized, else false.
MatrixType::node_type node_type
The Node type of the input (global) matrix.
Definition: Ifpack2_Details_TriDiSolver_decl.hpp:118
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input (global) matrix.
Definition: Ifpack2_Details_TriDiSolver_decl.hpp:112
virtual void setMatrix(const Teuchos::RCP< const Tpetra::RowMatrix< MatrixType::scalar_type, MatrixType::local_ordinal_type, MatrixType::global_ordinal_type, MatrixType::node_type > > &A)=0
Set the new matrix.