Ifpack2 Templated Preconditioning Package Version 1.0
Loading...
Searching...
No Matches
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"
56#include "Teuchos_SerialTriDiMatrix.hpp"
57#include <type_traits>
58
59namespace Ifpack2 {
60namespace Details {
61
74template<class MatrixType,
75 const bool stub = ! LapackSupportsScalar<typename MatrixType::scalar_type>::value>
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
88template<class MatrixType>
89class 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{
99public:
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
121 typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
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
128 typedef typename row_matrix_type::nonconst_global_inds_host_view_type nonconst_global_inds_host_view_type;
129 typedef typename row_matrix_type::nonconst_local_inds_host_view_type nonconst_local_inds_host_view_type;
130 typedef typename row_matrix_type::nonconst_values_host_view_type nonconst_values_host_view_type;
131
133 typedef Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> map_type;
134
136
138
142 TriDiSolver (const Teuchos::RCP<const row_matrix_type>& matrix);
143
145 virtual ~TriDiSolver ();
146
148
150
151
156 Teuchos::RCP<const map_type> getDomainMap () const;
157
162 Teuchos::RCP<const map_type> getRangeMap () const;
163
169 void
170 apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
171 Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
172 Teuchos::ETransp mode = Teuchos::NO_TRANS,
173 scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
174 scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
175
177
179 void setParameters (const Teuchos::ParameterList& params);
180
190 void initialize ();
191
193 bool isInitialized () const;
194
204 void compute ();
205
207 bool isComputed () const;
208
210 Teuchos::RCP<const row_matrix_type> getMatrix () const;
211
213 void setMatrix (const Teuchos::RCP<const row_matrix_type>& A);
214
216 int getNumInitialize () const;
217
219 int getNumCompute () const;
220
222 int getNumApply() const;
223
225 double getInitializeTime() const;
226
228 double getComputeTime() const;
229
231 double getApplyTime() const;
232
234
236
238 std::string description () const;
239
241 void
242 describe (Teuchos::FancyOStream &out,
243 const Teuchos::EVerbosityLevel verbLevel =
244 Teuchos::Describable::verbLevel_default) const;
246private:
247
249 void
250 describeLocal (Teuchos::FancyOStream& out,
251 const Teuchos::EVerbosityLevel verbLevel) const;
252
254 void reset ();
255
263 static void
264 extract (Teuchos::SerialTriDiMatrix<int, scalar_type>& A_local_tridi,
265 const row_matrix_type& A_local);
266
276 static void
277 factor (Teuchos::SerialTriDiMatrix<int, scalar_type>& A,
278 const Teuchos::ArrayView<int>& ipiv);
279
281 typedef Tpetra::MultiVector<scalar_type, local_ordinal_type,
283
285 typedef Tpetra::Import<local_ordinal_type,
286 global_ordinal_type, node_type> import_type;
287
289 typedef Tpetra::Export<local_ordinal_type,
290 global_ordinal_type, node_type> export_type;
291
293 typedef Teuchos::ScalarTraits<scalar_type> STS;
294
303 void
304 applyImpl (const MV& X,
305 MV& Y,
306 const Teuchos::ETransp mode,
307 const scalar_type alpha,
308 const scalar_type beta) const;
309
311 Teuchos::RCP<const row_matrix_type> A_;
312
314 Teuchos::RCP<const row_matrix_type> A_local_;
315
317 Teuchos::SerialTriDiMatrix<int, scalar_type> A_local_tridi_;
318
320 Teuchos::Array<int> ipiv_;
321
323 double initializeTime_;
324
326 double computeTime_;
327
329 mutable double applyTime_;
330
332 int numInitialize_;
333
335 int numCompute_;
336
338 mutable int numApply_;
339
341 bool isInitialized_;
342
344 bool isComputed_;
345};
346
347
349template<class MatrixType>
350class TriDiSolver<MatrixType, true> :
351 public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
352 typename MatrixType::local_ordinal_type,
353 typename MatrixType::global_ordinal_type,
354 typename MatrixType::node_type>,
355 virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
356 typename MatrixType::local_ordinal_type,
357 typename MatrixType::global_ordinal_type,
358 typename MatrixType::node_type> >
359{
360public:
362
363
367 typedef MatrixType matrix_type;
368
370 typedef typename MatrixType::scalar_type scalar_type;
371
373 typedef typename MatrixType::local_ordinal_type local_ordinal_type;
374
376 typedef typename MatrixType::global_ordinal_type global_ordinal_type;
377
379 typedef typename MatrixType::node_type node_type;
380
382 typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
383
385 typedef Tpetra::RowMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type> row_matrix_type;
386
387 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.");
388
390 typedef Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> map_type;
391
393
395
399 TriDiSolver (const Teuchos::RCP<const row_matrix_type>& matrix);
400
402 virtual ~TriDiSolver ();
403
405
407
412 Teuchos::RCP<const map_type> getDomainMap () const;
413
418 Teuchos::RCP<const map_type> getRangeMap () const;
419
425 void
426 apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
427 Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
428 Teuchos::ETransp mode = Teuchos::NO_TRANS,
429 scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
430 scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
431
433
435 void setParameters (const Teuchos::ParameterList& params);
436
446 void initialize ();
447
449 bool isInitialized () const;
450
460 void compute ();
461
463 bool isComputed () const;
464
466 Teuchos::RCP<const row_matrix_type> getMatrix () const;
467
469 void setMatrix (const Teuchos::RCP<const row_matrix_type>& A);
470
472 int getNumInitialize () const;
473
475 int getNumCompute () const;
476
478 int getNumApply() const;
479
481 double getInitializeTime() const;
482
484 double getComputeTime() const;
485
487 double getApplyTime() const;
488
490
492
494 std::string description () const;
495
497 void
498 describe (Teuchos::FancyOStream &out,
499 const Teuchos::EVerbosityLevel verbLevel =
500 Teuchos::Describable::verbLevel_default) const;
501
502 void
503 describeLocal (Teuchos::FancyOStream& out,
504 const Teuchos::EVerbosityLevel verbLevel) const;
505
507private:
509 typedef Tpetra::MultiVector<scalar_type, local_ordinal_type,
510 global_ordinal_type, node_type> MV;
511};
512
513} // namespace Details
514} // namespace Ifpack2
515
516#endif // IFPACK2_DETAILS_TRIDISOLVER_DECL_HPP
Declaration of interface for preconditioners that can change their matrix after construction.
Mix-in interface for preconditioners that can change their matrix after construction.
Definition Ifpack2_Details_CanChangeMatrix.hpp:93
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.
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::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< scalar_type >::magnitudeType magnitude_type
The type of the absolute value (magnitude) of a scalar_type.
Definition Ifpack2_Details_TriDiSolver_decl.hpp:121
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
MatrixType matrix_type
The first template parameter of this class.
Definition Ifpack2_Details_TriDiSolver_decl.hpp:106
MatrixType::scalar_type scalar_type
The type of entries in the input (global) matrix.
Definition Ifpack2_Details_TriDiSolver_decl.hpp:109
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:133
"Preconditioner" that uses LAPACK's tridi LU.
Definition Ifpack2_Details_TriDiSolver_decl.hpp:85
Interface for all Ifpack2 preconditioners.
Definition Ifpack2_Preconditioner.hpp:108
virtual bool isInitialized() const=0
True if the preconditioner has been successfully initialized, else false.
Teuchos::ScalarTraits< MatrixType::scalar_type >::magnitudeType magnitude_type
The type of the magnitude (absolute value) of a matrix entry.
Definition Ifpack2_Preconditioner.hpp:111
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.
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_type alpha=Teuchos::ScalarTraits< MatrixType::scalar_type >::one(), MatrixType::scalar_type beta=Teuchos::ScalarTraits< MatrixType::scalar_type >::zero()) const=0
Apply the preconditioner to X, putting the result in Y.
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.
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.
virtual bool isComputed() const=0
True if the preconditioner has been successfully computed, else false.
Ifpack2 implementation details.
Preconditioners and smoothers for Tpetra sparse matrices.
Definition Ifpack2_AdditiveSchwarz_decl.hpp:74