Ifpack2 Templated Preconditioning Package Version 1.0
Loading...
Searching...
No Matches
Ifpack2_Details_DenseSolver_decl.hpp
1// @HEADER
2// *****************************************************************************
3// Ifpack2: Templated Object-Oriented Algebraic Preconditioner Package
4//
5// Copyright 2009 NTESS and the Ifpack2 contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef IFPACK2_DETAILS_DENSESOLVER_DECL_HPP
11#define IFPACK2_DETAILS_DENSESOLVER_DECL_HPP
12
15
16#include "Ifpack2_ConfigDefs.hpp"
19#include "Ifpack2_Details_LapackSupportsScalar.hpp"
20#include "Tpetra_Import_fwd.hpp"
21#include "Tpetra_Export_fwd.hpp"
22#include "Teuchos_SerialDenseMatrix.hpp"
23#include <type_traits>
24
25namespace Ifpack2 {
26namespace Details {
27
40template <class MatrixType,
41 const bool stub = !LapackSupportsScalar<typename MatrixType::scalar_type>::value>
42class DenseSolver : public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
43 typename MatrixType::local_ordinal_type,
44 typename MatrixType::global_ordinal_type,
45 typename MatrixType::node_type>,
46 virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
47 typename MatrixType::local_ordinal_type,
48 typename MatrixType::global_ordinal_type,
49 typename MatrixType::node_type> > {};
50
52template <class MatrixType>
53class DenseSolver<MatrixType, false> : public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
54 typename MatrixType::local_ordinal_type,
55 typename MatrixType::global_ordinal_type,
56 typename MatrixType::node_type>,
57 virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
58 typename MatrixType::local_ordinal_type,
59 typename MatrixType::global_ordinal_type,
60 typename MatrixType::node_type> > {
61 public:
63
64
69
71 typedef typename MatrixType::scalar_type scalar_type;
72
74 typedef typename MatrixType::local_ordinal_type local_ordinal_type;
75
77 typedef typename MatrixType::global_ordinal_type global_ordinal_type;
78
80 typedef typename MatrixType::node_type node_type;
81
83 typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
84
86 typedef Tpetra::RowMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type> row_matrix_type;
87
88 static_assert(std::is_same<MatrixType, row_matrix_type>::value,
89 "Ifpack2::Details::DenseSolver: Please use MatrixType = Tpetra::RowMatrix.");
90
91 typedef typename row_matrix_type::nonconst_global_inds_host_view_type nonconst_global_inds_host_view_type;
92 typedef typename row_matrix_type::nonconst_local_inds_host_view_type nonconst_local_inds_host_view_type;
93 typedef typename row_matrix_type::nonconst_values_host_view_type nonconst_values_host_view_type;
94
96 typedef Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> map_type;
97
99
101
105 DenseSolver(const Teuchos::RCP<const row_matrix_type>& matrix);
106
108 virtual ~DenseSolver();
109
111
113
118 Teuchos::RCP<const map_type> getDomainMap() const;
119
124 Teuchos::RCP<const map_type> getRangeMap() const;
125
131 void
132 apply(const Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& X,
133 Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& Y,
134 Teuchos::ETransp mode = Teuchos::NO_TRANS,
135 scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
136 scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
137
139
141 void setParameters(const Teuchos::ParameterList& params);
142
152 void initialize();
153
155 bool isInitialized() const;
156
166 void compute();
167
169 bool isComputed() const;
170
172 Teuchos::RCP<const row_matrix_type> getMatrix() const;
173
175 void setMatrix(const Teuchos::RCP<const row_matrix_type>& A);
176
178 int getNumInitialize() const;
179
181 int getNumCompute() const;
182
184 int getNumApply() const;
185
187 double getInitializeTime() const;
188
190 double getComputeTime() const;
191
193 double getApplyTime() const;
194
196
198
200 std::string description() const;
201
203 void
204 describe(Teuchos::FancyOStream& out,
205 const Teuchos::EVerbosityLevel verbLevel =
206 Teuchos::Describable::verbLevel_default) const;
208 private:
210 void
211 describeLocal(Teuchos::FancyOStream& out,
212 const Teuchos::EVerbosityLevel verbLevel) const;
213
215 void reset();
216
224 static void
225 extract(Teuchos::SerialDenseMatrix<int, scalar_type>& A_local_dense,
226 const row_matrix_type& A_local);
227
237 static void
238 factor(Teuchos::SerialDenseMatrix<int, scalar_type>& A,
239 const Teuchos::ArrayView<int>& ipiv);
240
242 typedef Tpetra::MultiVector<scalar_type, local_ordinal_type,
244 MV;
245
247 typedef Tpetra::Import<local_ordinal_type,
249 import_type;
250
252 typedef Tpetra::Export<local_ordinal_type,
254 export_type;
255
257 typedef Teuchos::ScalarTraits<scalar_type> STS;
258
267 void
268 applyImpl(const MV& X,
269 MV& Y,
270 const Teuchos::ETransp mode,
271 const scalar_type alpha,
272 const scalar_type beta) const;
273
275 Teuchos::RCP<const row_matrix_type> A_;
276
278 Teuchos::RCP<const row_matrix_type> A_local_;
279
281 Teuchos::SerialDenseMatrix<int, scalar_type> A_local_dense_;
282
284 Teuchos::Array<int> ipiv_;
285
287 double initializeTime_;
288
290 double computeTime_;
291
293 mutable double applyTime_;
294
296 int numInitialize_;
297
299 int numCompute_;
300
302 mutable int numApply_;
303
305 bool isInitialized_;
306
308 bool isComputed_;
309};
310
312template <class MatrixType>
313class DenseSolver<MatrixType, true> : public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
314 typename MatrixType::local_ordinal_type,
315 typename MatrixType::global_ordinal_type,
316 typename MatrixType::node_type>,
317 virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
318 typename MatrixType::local_ordinal_type,
319 typename MatrixType::global_ordinal_type,
320 typename MatrixType::node_type> > {
321 public:
323
324
330
332 typedef typename MatrixType::scalar_type scalar_type;
333
335 typedef typename MatrixType::local_ordinal_type local_ordinal_type;
336
338 typedef typename MatrixType::global_ordinal_type global_ordinal_type;
339
341 typedef typename MatrixType::node_type node_type;
342
344 typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
345
347 typedef Tpetra::RowMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type> row_matrix_type;
348
350 typedef Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> map_type;
351
353
355
359 DenseSolver(const Teuchos::RCP<const row_matrix_type>& matrix);
360
362 virtual ~DenseSolver();
363
365
367
372 Teuchos::RCP<const map_type> getDomainMap() const;
373
378 Teuchos::RCP<const map_type> getRangeMap() const;
379
385 void
386 apply(const Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& X,
387 Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& Y,
388 Teuchos::ETransp mode = Teuchos::NO_TRANS,
389 scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
390 scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
391
393
395 void setParameters(const Teuchos::ParameterList& params);
396
406 void initialize();
407
409 bool isInitialized() const;
410
420 void compute();
421
423 bool isComputed() const;
424
426 Teuchos::RCP<const row_matrix_type> getMatrix() const;
427
429 void setMatrix(const Teuchos::RCP<const row_matrix_type>& A);
430
432 int getNumInitialize() const;
433
435 int getNumCompute() const;
436
438 int getNumApply() const;
439
441 double getInitializeTime() const;
442
444 double getComputeTime() const;
445
447 double getApplyTime() const;
448
450
452
454 std::string description() const;
455
457 void
458 describe(Teuchos::FancyOStream& out,
459 const Teuchos::EVerbosityLevel verbLevel =
460 Teuchos::Describable::verbLevel_default) const;
462 private:
464 typedef Tpetra::MultiVector<scalar_type, local_ordinal_type,
466 MV;
467};
468
469} // namespace Details
470} // namespace Ifpack2
471
472#endif // IFPACK2_DETAILS_DENSESOLVER_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:60
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.
MatrixType::node_type node_type
The Node type of the input (global) matrix.
Definition Ifpack2_Details_DenseSolver_decl.hpp:80
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input (global) matrix.
Definition Ifpack2_Details_DenseSolver_decl.hpp:74
MatrixType matrix_type
The first template parameter of this class.
Definition Ifpack2_Details_DenseSolver_decl.hpp:68
MatrixType::scalar_type scalar_type
The type of entries in the input (global) matrix.
Definition Ifpack2_Details_DenseSolver_decl.hpp:71
Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type > map_type
Specialization of Tpetra::Map used by this class.
Definition Ifpack2_Details_DenseSolver_decl.hpp:96
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input (global) matrix.
Definition Ifpack2_Details_DenseSolver_decl.hpp:77
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_DenseSolver_decl.hpp:86
Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitude_type
The type of the absolute value (magnitude) of a scalar_type.
Definition Ifpack2_Details_DenseSolver_decl.hpp:83
MatrixType::node_type node_type
The Node type of the input (global) matrix.
Definition Ifpack2_Details_DenseSolver_decl.hpp:341
MatrixType matrix_type
The first template parameter of this class.
Definition Ifpack2_Details_DenseSolver_decl.hpp:329
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_DenseSolver_decl.hpp:347
Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type > map_type
Specialization of Tpetra::Map used by this class.
Definition Ifpack2_Details_DenseSolver_decl.hpp:350
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input (global) matrix.
Definition Ifpack2_Details_DenseSolver_decl.hpp:335
Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitude_type
The type of the absolute value (magnitude) of a scalar_type.
Definition Ifpack2_Details_DenseSolver_decl.hpp:344
MatrixType::scalar_type scalar_type
The type of entries in the input (global) matrix.
Definition Ifpack2_Details_DenseSolver_decl.hpp:332
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input (global) matrix.
Definition Ifpack2_Details_DenseSolver_decl.hpp:338
"Preconditioner" that uses LAPACK's dense LU.
Definition Ifpack2_Details_DenseSolver_decl.hpp:49
Ifpack2's implementation of Trilinos::Details::LinearSolver interface.
Definition Ifpack2_Details_LinearSolver_decl.hpp:75
Interface for all Ifpack2 preconditioners.
Definition Ifpack2_Preconditioner.hpp:74
virtual bool isInitialized() const=0
True if the preconditioner has been successfully initialized, else false.
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:40