libMesh
trilinos_preconditioner.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2025 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"
30 #include "libmesh/reference_counted_object.h"
31 #include "libmesh/libmesh.h"
32 
33 // Trilinos includes. Ignore many unused parameter warnings coming
34 // from these headers.
35 #include "libmesh/ignore_warnings.h"
36 #include "Epetra_Operator.h"
37 #include "Epetra_FECrsMatrix.h"
38 #include "Teuchos_ParameterList.hpp"
39 #include "libmesh/restore_warnings.h"
40 
41 // C++ includes
42 #include <cstddef>
43 
44 namespace libMesh
45 {
46 
47 // forward declarations
48 template <typename T> class SparseMatrix;
49 template <typename T> class NumericVector;
50 template <typename T> class ShellMatrix;
51 enum PreconditionerType : int;
52 
61 template <typename T>
63  public Preconditioner<T>,
64  public Epetra_Operator
65 {
66 public:
67 
72 
76  virtual ~TrilinosPreconditioner ();
77 
78  virtual void apply(const NumericVector<T> & x, NumericVector<T> & y) override;
79 
80  virtual void clear () override {}
81 
82  virtual void init () override;
83 
87  void set_params(Teuchos::ParameterList & list);
88 
92  Epetra_FECrsMatrix * mat() { return _mat; }
93 
99  void set_preconditioner_type (const PreconditionerType & preconditioner_type);
100 
104  void compute();
105 
106 protected:
107 
111  Epetra_Operator * _prec;
112 
116  Epetra_FECrsMatrix * _mat;
117 
121  Teuchos::ParameterList _param_list;
122 
123  // Epetra_Operator interface
124  virtual int SetUseTranspose(bool UseTranspose) override;
125  virtual int Apply(const Epetra_MultiVector & X, Epetra_MultiVector & Y) const override;
126  virtual int ApplyInverse(const Epetra_MultiVector & r, Epetra_MultiVector & z) const override;
127  virtual double NormInf() const override;
128  virtual const char * Label() const override;
129  virtual bool UseTranspose() const override;
130  virtual bool HasNormInf() const override;
131  virtual const Epetra_Comm & Comm() const override;
132  virtual const Epetra_Map & OperatorDomainMap() const override;
133  virtual const Epetra_Map & OperatorRangeMap() const override;
134 };
135 
136 
137 
138 
139 /*----------------------- inline functions ----------------------------------*/
140 template <typename T>
141 inline
143  Preconditioner<T>(comm),
144  _prec(nullptr),
145  _mat(nullptr)
146 {
147 }
148 
149 
150 
151 template <typename T>
152 inline
154 {
155  this->clear ();
156 }
157 
158 } // namespace libMesh
159 
160 #endif // LIBMESH_TRILINOS_HAVE_EPETRA
161 #endif // LIBMESH_TRILINOS_PRECONDITIONER_H
void set_params(Teuchos::ParameterList &list)
Stores a copy of the ParameterList list internally.
virtual void init() override
Initialize data structures if not done so already.
virtual ~TrilinosPreconditioner()
Destructor.
TrilinosPreconditioner(const libMesh::Parallel::Communicator &comm)
Constructor.
Teuchos::ParameterList _param_list
Parameter list to be used for building the preconditioner.
virtual bool HasNormInf() const override
virtual void apply(const NumericVector< T > &x, NumericVector< T > &y) override
Computes the preconditioned vector y based on input vector x.
Provides a uniform interface to vector storage schemes for different linear algebra libraries...
Definition: vector_fe_ex5.C:44
const Parallel::Communicator & comm() const
The libMesh namespace provides an interface to certain functionality in the library.
void set_preconditioner_type(const PreconditionerType &preconditioner_type)
Sets the Trilinos preconditioner to use based on the libMesh PreconditionerType.
virtual void clear() override
Release all memory and clear data structures.
This class provides an interface to the suite of preconditioners available from Trilinos.
This class provides a uniform interface for preconditioners.
Epetra_FECrsMatrix * _mat
Trilinos matrix that&#39;s been pulled out of the _matrix object.
void compute()
Compute the preconditioner.
virtual const Epetra_Map & OperatorDomainMap() const override
virtual bool UseTranspose() const override
virtual double NormInf() const override
PreconditionerType
Defines an enum for preconditioner types.
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
Epetra_Operator * _prec
Trilinos preconditioner.
virtual const Epetra_Comm & Comm() const override
virtual int ApplyInverse(const Epetra_MultiVector &r, Epetra_MultiVector &z) const override
void ErrorVector unsigned int
Definition: adjoints_ex3.C:360