libMesh
Loading...
Searching...
No Matches
trilinos_preconditioner.h
Go to the documentation of this file.
1// The libMesh Finite Element Library.
2// Copyright (C) 2002-2026 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
44namespace libMesh
45{
46
47// forward declarations
48template <typename T> class SparseMatrix;
49template <typename T> class NumericVector;
50template <typename T> class ShellMatrix;
52
61template <typename T>
63 public Preconditioner<T>,
64 public Epetra_Operator
65{
66public:
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
106protected:
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 ----------------------------------*/
140template <typename T>
141inline
143 Preconditioner<T>(comm),
144 _prec(nullptr),
145 _mat(nullptr)
146{
147}
148
149
150
151template <typename T>
152inline
157
158} // namespace libMesh
159
160#endif // LIBMESH_TRILINOS_HAVE_EPETRA
161#endif // LIBMESH_TRILINOS_PRECONDITIONER_H
void ErrorVector unsigned int
Provides a uniform interface to vector storage schemes for different linear algebra libraries.
const Parallel::Communicator & comm() const
This class provides a uniform interface for preconditioners.
This class provides an interface to the suite of preconditioners available from Trilinos.
void compute()
Compute the preconditioner.
Epetra_FECrsMatrix * _mat
Trilinos matrix that's been pulled out of the _matrix object.
virtual int ApplyInverse(const Epetra_MultiVector &r, Epetra_MultiVector &z) const override
TrilinosPreconditioner(const libMesh::Parallel::Communicator &comm)
Constructor.
virtual bool HasNormInf() const override
virtual double NormInf() const override
virtual const Epetra_Map & OperatorDomainMap() const override
virtual const Epetra_Comm & Comm() const override
Epetra_Operator * _prec
Trilinos preconditioner.
void set_params(Teuchos::ParameterList &list)
Stores a copy of the ParameterList list internally.
Teuchos::ParameterList _param_list
Parameter list to be used for building the preconditioner.
virtual const char * Label() const override
virtual void clear() override
Release all memory and clear data structures.
virtual bool UseTranspose() const override
void set_preconditioner_type(const PreconditionerType &preconditioner_type)
Sets the Trilinos preconditioner to use based on the libMesh PreconditionerType.
virtual void init() override
Initialize data structures if not done so already.
virtual const Epetra_Map & OperatorRangeMap() const override
virtual void apply(const NumericVector< T > &x, NumericVector< T > &y) override
Computes the preconditioned vector y based on input vector x.
virtual int Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const override
virtual int SetUseTranspose(bool UseTranspose) override
The libMesh namespace provides an interface to certain functionality in the library.
PreconditionerType
Defines an enum for preconditioner types.