Ifpack2 Templated Preconditioning Package  Version 1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Ifpack2_Details_DenseSolver_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_DENSESOLVER_DECL_HPP
44 #define IFPACK2_DETAILS_DENSESOLVER_DECL_HPP
45 
48 
49 #include "Ifpack2_ConfigDefs.hpp"
52 #include "Ifpack2_Details_LapackSupportsScalar.hpp"
54 #include <type_traits>
55 
56 namespace Ifpack2 {
57 namespace Details {
58 
71 template<class MatrixType,
72  const bool stub = ! LapackSupportsScalar<typename MatrixType::scalar_type>::value>
73 class DenseSolver :
74  public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
75  typename MatrixType::local_ordinal_type,
76  typename MatrixType::global_ordinal_type,
77  typename MatrixType::node_type>,
78  virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
79  typename MatrixType::local_ordinal_type,
80  typename MatrixType::global_ordinal_type,
81  typename MatrixType::node_type> >
82 {};
83 
85 template<class MatrixType>
86 class DenseSolver<MatrixType, false> :
87  public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
88  typename MatrixType::local_ordinal_type,
89  typename MatrixType::global_ordinal_type,
90  typename MatrixType::node_type>,
91  virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
92  typename MatrixType::local_ordinal_type,
93  typename MatrixType::global_ordinal_type,
94  typename MatrixType::node_type> >
95 {
96 public:
98 
99 
103  typedef MatrixType matrix_type;
104 
106  typedef typename MatrixType::scalar_type scalar_type;
107 
109  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
110 
112  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
113 
115  typedef typename MatrixType::node_type node_type;
116 
119 
121  typedef Tpetra::RowMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type> row_matrix_type;
122 
123  static_assert(std::is_same<MatrixType, row_matrix_type>::value,
124  "Ifpack2::Details::DenseSolver: Please use MatrixType = Tpetra::RowMatrix.");
125 
127  typedef Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> map_type;
128 
130 
132 
137 
139  virtual ~DenseSolver ();
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::SerialDenseMatrix<int, scalar_type>& A_local_dense,
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 DenseSolver<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 
362  typedef MatrixType matrix_type;
363 
365  typedef typename MatrixType::scalar_type scalar_type;
366 
368  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
369 
371  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
372 
374  typedef typename MatrixType::node_type node_type;
375 
378 
380  typedef Tpetra::RowMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type> row_matrix_type;
381 
383  typedef Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> map_type;
384 
386 
388 
393 
395  virtual ~DenseSolver ();
396 
398 
400 
406 
412 
418  void
419  apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
420  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
422  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
423  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
424 
426 
428  void setParameters (const Teuchos::ParameterList& params);
429 
439  void initialize ();
440 
442  bool isInitialized () const;
443 
453  void compute ();
454 
456  bool isComputed () const;
457 
460 
463 
465  int getNumInitialize () const;
466 
468  int getNumCompute () const;
469 
471  int getNumApply() const;
472 
474  double getInitializeTime() const;
475 
477  double getComputeTime() const;
478 
480  double getApplyTime() const;
481 
483 
485 
487  std::string description () const;
488 
490  void
491  describe (Teuchos::FancyOStream &out,
492  const Teuchos::EVerbosityLevel verbLevel =
495 private:
497  typedef Tpetra::MultiVector<scalar_type, local_ordinal_type,
498  global_ordinal_type, node_type> MV;
499 };
500 
501 } // namespace Details
502 } // namespace Ifpack2
503 
504 #endif // IFPACK2_DETAILS_DENSESOLVER_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
Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitude_type
The type of the absolute value (magnitude) of a scalar_type.
Definition: Ifpack2_Details_DenseSolver_decl.hpp:118
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< MatrixType::scalar_type >::magnitudeType magnitude_type
The type of the magnitude (absolute value) of a matrix entry.
Definition: Ifpack2_Preconditioner.hpp:111
&quot;Preconditioner&quot; that uses LAPACK&#39;s dense LU.
Definition: Ifpack2_Details_DenseSolver_decl.hpp:73
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::global_ordinal_type global_ordinal_type
The type of global indices in the input (global) matrix.
Definition: Ifpack2_Details_DenseSolver_decl.hpp:112
Interface for all Ifpack2 preconditioners.
Definition: Ifpack2_Preconditioner.hpp:107
MatrixType::node_type node_type
The Node type of the input (global) matrix.
Definition: Ifpack2_Details_DenseSolver_decl.hpp:115
MatrixType matrix_type
The first template parameter of this class.
Definition: Ifpack2_Details_DenseSolver_decl.hpp:103
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.
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input (global) matrix.
Definition: Ifpack2_Details_DenseSolver_decl.hpp:109
virtual void setParameters(const Teuchos::ParameterList &List)=0
Set this preconditioner&#39;s parameters.
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:124
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.
MatrixType::scalar_type scalar_type
The type of entries in the input (global) matrix.
Definition: Ifpack2_Details_DenseSolver_decl.hpp:106
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:121
virtual bool isInitialized() const =0
True if the preconditioner has been successfully initialized, else false.
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.