trilinos_preconditioner.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_TRILINOS_PRECONDITIONER_H
21 #define LIBMESH_TRILINOS_PRECONDITIONER_H
22 
23 #include "libmesh/libmesh_config.h"
24 
25 #ifdef LIBMESH_TRILINOS_HAVE_EPETRA
26 
27 // Local includes
28 #include "libmesh/preconditioner.h"
29 #include "libmesh/libmesh_common.h"
31 #include "libmesh/libmesh.h"
32 #include "libmesh/auto_ptr.h" // deprecated
33 
34 // Trilinos includes. Ignore many unused parameter warnings coming
35 // from these headers.
37 #include "Epetra_Operator.h"
38 #include "Epetra_FECrsMatrix.h"
39 #include "Teuchos_ParameterList.hpp"
41 
42 #ifdef LIBMESH_FORWARD_DECLARE_ENUMS
43 namespace libMesh
44 {
45 enum PreconditionerType : int;
46 }
47 #else
49 #endif
50 
51 // C++ includes
52 #include <cstddef>
53 
54 namespace libMesh
55 {
56 
57 // forward declarations
58 template <typename T> class SparseMatrix;
59 template <typename T> class NumericVector;
60 template <typename T> class ShellMatrix;
61 
70 template <typename T>
72  public Preconditioner<T>,
73  public Epetra_Operator
74 {
75 public:
76 
81 
85  virtual ~TrilinosPreconditioner ();
86 
87  virtual void apply(const NumericVector<T> & x, NumericVector<T> & y) override;
88 
89  virtual void clear () override {}
90 
91  virtual void init () override;
92 
96  void set_params(Teuchos::ParameterList & list);
97 
101  Epetra_FECrsMatrix * mat() { return _mat; }
102 
108  void set_preconditioner_type (const PreconditionerType & preconditioner_type);
109 
113  void compute();
114 
115 protected:
116 
120  Epetra_Operator * _prec;
121 
125  Epetra_FECrsMatrix * _mat;
126 
130  Teuchos::ParameterList _param_list;
131 
132  // Epetra_Operator interface
133  virtual int SetUseTranspose(bool UseTranspose) override;
134  virtual int Apply(const Epetra_MultiVector & X, Epetra_MultiVector & Y) const override;
135  virtual int ApplyInverse(const Epetra_MultiVector & r, Epetra_MultiVector & z) const override;
136  virtual double NormInf() const override;
137  virtual const char * Label() const override;
138  virtual bool UseTranspose() const override;
139  virtual bool HasNormInf() const override;
140  virtual const Epetra_Comm & Comm() const override;
141  virtual const Epetra_Map & OperatorDomainMap() const override;
142  virtual const Epetra_Map & OperatorRangeMap() const override;
143 };
144 
145 
146 
147 
148 /*----------------------- inline functions ----------------------------------*/
149 template <typename T>
150 inline
152  Preconditioner<T>(comm),
153  _prec(nullptr),
154  _mat(nullptr)
155 {
156 }
157 
158 
159 
160 template <typename T>
161 inline
163 {
164  this->clear ();
165 }
166 
167 } // namespace libMesh
168 
169 #endif // LIBMESH_TRILINOS_HAVE_EPETRA
170 #endif // LIBMESH_TRILINOS_PRECONDITIONER_H
void set_params(Teuchos::ParameterList &list)
TrilinosPreconditioner(const libMesh::Parallel::Communicator &comm)
virtual bool HasNormInf() const override
virtual void apply(const NumericVector< T > &x, NumericVector< T > &y) override
Provides a uniform interface to vector storage schemes for different linear algebra libraries...
Definition: diff_context.h:40
const Parallel::Communicator & comm() const
void set_preconditioner_type(const PreconditionerType &preconditioner_type)
virtual const Epetra_Map & OperatorDomainMap() const override
virtual bool UseTranspose() const override
virtual double NormInf() const override
virtual int SetUseTranspose(bool UseTranspose) override
virtual const char * Label() const override
virtual const Epetra_Map & OperatorRangeMap() const override
virtual int Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const override
virtual const Epetra_Comm & Comm() const override
virtual int ApplyInverse(const Epetra_MultiVector &r, Epetra_MultiVector &z) const override