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"
55 #include <type_traits>
56 
57 namespace Ifpack2 {
58 namespace Details {
59 
72 template<class MatrixType,
73  const bool stub = ! LapackSupportsScalar<typename MatrixType::scalar_type>::value>
74 class TriDiSolver :
75  public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
76  typename MatrixType::local_ordinal_type,
77  typename MatrixType::global_ordinal_type,
78  typename MatrixType::node_type>,
79  virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
80  typename MatrixType::local_ordinal_type,
81  typename MatrixType::global_ordinal_type,
82  typename MatrixType::node_type> >
83 {};
84 
86 template<class MatrixType>
87 class TriDiSolver<MatrixType, false> :
88  public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
89  typename MatrixType::local_ordinal_type,
90  typename MatrixType::global_ordinal_type,
91  typename MatrixType::node_type>,
92  virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
93  typename MatrixType::local_ordinal_type,
94  typename MatrixType::global_ordinal_type,
95  typename MatrixType::node_type> >
96 {
97 public:
99 
100 
104  typedef MatrixType matrix_type;
105 
107  typedef typename MatrixType::scalar_type scalar_type;
108 
110  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
111 
113  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
114 
116  typedef typename MatrixType::node_type node_type;
117 
120 
122  typedef Tpetra::RowMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type> row_matrix_type;
123 
124  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.");
125 
127  typedef Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> map_type;
128 
130 
132 
137 
139  virtual ~TriDiSolver ();
140 
142 
144 
145 
151 
157 
163  void
164  apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
165  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
169 
171 
173  void setParameters (const Teuchos::ParameterList& params);
174 
184  void initialize ();
185 
187  bool isInitialized () const;
188 
198  void compute ();
199 
201  bool isComputed () const;
202 
205 
208 
210  int getNumInitialize () const;
211 
213  int getNumCompute () const;
214 
216  int getNumApply() const;
217 
219  double getInitializeTime() const;
220 
222  double getComputeTime() const;
223 
225  double getApplyTime() const;
226 
228 
230 
232  std::string description () const;
233 
235  void
236  describe (Teuchos::FancyOStream &out,
237  const Teuchos::EVerbosityLevel verbLevel =
240 private:
241 
243  void
244  describeLocal (Teuchos::FancyOStream& out,
245  const Teuchos::EVerbosityLevel verbLevel) const;
246 
248  void reset ();
249 
257  static void
258  extract (Teuchos::SerialTriDiMatrix<int, scalar_type>& A_local_tridi,
259  const row_matrix_type& A_local);
260 
270  static void
272  const Teuchos::ArrayView<int>& ipiv);
273 
275  typedef Tpetra::MultiVector<scalar_type, local_ordinal_type,
277 
279  typedef Tpetra::Import<local_ordinal_type,
280  global_ordinal_type, node_type> import_type;
281 
283  typedef Tpetra::Export<local_ordinal_type,
284  global_ordinal_type, node_type> export_type;
285 
288 
297  void
298  applyImpl (const MV& X,
299  MV& Y,
300  const Teuchos::ETransp mode,
301  const scalar_type alpha,
302  const scalar_type beta) const;
303 
306 
309 
312 
314  Teuchos::Array<int> ipiv_;
315 
317  double initializeTime_;
318 
320  double computeTime_;
321 
323  mutable double applyTime_;
324 
326  int numInitialize_;
327 
329  int numCompute_;
330 
332  mutable int numApply_;
333 
335  bool isInitialized_;
336 
338  bool isComputed_;
339 };
340 
341 
343 template<class MatrixType>
344 class TriDiSolver<MatrixType, true> :
345  public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
346  typename MatrixType::local_ordinal_type,
347  typename MatrixType::global_ordinal_type,
348  typename MatrixType::node_type>,
349  virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
350  typename MatrixType::local_ordinal_type,
351  typename MatrixType::global_ordinal_type,
352  typename MatrixType::node_type> >
353 {
354 public:
356 
357 
361  typedef MatrixType matrix_type;
362 
364  typedef typename MatrixType::scalar_type scalar_type;
365 
367  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
368 
370  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
371 
373  typedef typename MatrixType::node_type node_type;
374 
377 
379  typedef Tpetra::RowMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type> row_matrix_type;
380 
381  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.");
382 
384  typedef Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> map_type;
385 
387 
389 
394 
396  virtual ~TriDiSolver ();
397 
399 
401 
407 
413 
419  void
420  apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
421  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
423  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
424  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
425 
427 
429  void setParameters (const Teuchos::ParameterList& params);
430 
440  void initialize ();
441 
443  bool isInitialized () const;
444 
454  void compute ();
455 
457  bool isComputed () const;
458 
461 
464 
466  int getNumInitialize () const;
467 
469  int getNumCompute () const;
470 
472  int getNumApply() const;
473 
475  double getInitializeTime() const;
476 
478  double getComputeTime() const;
479 
481  double getApplyTime() const;
482 
484 
486 
488  std::string description () const;
489 
491  void
492  describe (Teuchos::FancyOStream &out,
493  const Teuchos::EVerbosityLevel verbLevel =
495 
496  void
497  describeLocal (Teuchos::FancyOStream& out,
498  const Teuchos::EVerbosityLevel verbLevel) const;
499 
501 private:
503  typedef Tpetra::MultiVector<scalar_type, local_ordinal_type,
504  global_ordinal_type, node_type> MV;
505 };
506 
507 } // namespace Details
508 } // namespace Ifpack2
509 
510 #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:119
&quot;Preconditioner&quot; that uses LAPACK&#39;s tridi LU.
Definition: Ifpack2_Details_TriDiSolver_decl.hpp:74
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input (global) matrix.
Definition: Ifpack2_Details_TriDiSolver_decl.hpp:113
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:122
MatrixType::scalar_type scalar_type
The type of entries in the input (global) matrix.
Definition: Ifpack2_Details_TriDiSolver_decl.hpp:107
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:104
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:124
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:116
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input (global) matrix.
Definition: Ifpack2_Details_TriDiSolver_decl.hpp:110
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.