libMesh
trilinos_preconditioner.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 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/enum_solver_package.h"
31 #include "libmesh/enum_preconditioner_type.h"
32 #include "libmesh/reference_counted_object.h"
33 #include "libmesh/libmesh.h"
34 #include "libmesh/auto_ptr.h"
35 
36 // Trilinos includes. Ignore many unused parameter warnings coming
37 // from these headers.
38 #include "libmesh/ignore_warnings.h"
39 #include "Epetra_Operator.h"
40 #include "Epetra_FECrsMatrix.h"
41 #include "Teuchos_ParameterList.hpp"
42 #include "libmesh/restore_warnings.h"
43 
44 // C++ includes
45 #include <cstddef>
46 
47 namespace libMesh
48 {
49 
50 // forward declarations
51 template <typename T> class SparseMatrix;
52 template <typename T> class NumericVector;
53 template <typename T> class ShellMatrix;
54 
63 template <typename T>
65  public Preconditioner<T>,
66  public Epetra_Operator
67 {
68 public:
69 
74  LIBMESH_CAN_DEFAULT_TO_COMMWORLD);
75 
79  virtual ~TrilinosPreconditioner ();
80 
81  virtual void apply(const NumericVector<T> & x, NumericVector<T> & y) libmesh_override;
82 
83  virtual void clear () libmesh_override {}
84 
85  virtual void init () libmesh_override;
86 
90  void set_params(Teuchos::ParameterList & list);
91 
95  Epetra_FECrsMatrix * mat() { return _mat; }
96 
102  void set_preconditioner_type (const PreconditionerType & preconditioner_type);
103 
107  void compute();
108 
109 protected:
110 
114  Epetra_Operator * _prec;
115 
119  Epetra_FECrsMatrix * _mat;
120 
124  Teuchos::ParameterList _param_list;
125 
126  // Epetra_Operator interface
127  virtual int SetUseTranspose(bool UseTranspose) libmesh_override;
128  virtual int Apply(const Epetra_MultiVector & X, Epetra_MultiVector & Y) const libmesh_override;
129  virtual int ApplyInverse(const Epetra_MultiVector & r, Epetra_MultiVector & z) const libmesh_override;
130  virtual double NormInf() const libmesh_override;
131  virtual const char * Label() const libmesh_override;
132  virtual bool UseTranspose() const libmesh_override;
133  virtual bool HasNormInf() const libmesh_override;
134  virtual const Epetra_Comm & Comm() const libmesh_override;
135  virtual const Epetra_Map & OperatorDomainMap() const libmesh_override;
136  virtual const Epetra_Map & OperatorRangeMap() const libmesh_override;
137 };
138 
139 
140 
141 
142 /*----------------------- inline functions ----------------------------------*/
143 template <typename T>
144 inline
145 TrilinosPreconditioner<T>::TrilinosPreconditioner (const libMesh::Parallel::Communicator & comm) :
146  Preconditioner<T>(comm),
147  _prec(libmesh_nullptr),
148  _mat(libmesh_nullptr)
149 {
150 }
151 
152 
153 
154 template <typename T>
155 inline
157 {
158  this->clear ();
159 }
160 
161 } // namespace libMesh
162 
163 #endif // LIBMESH_TRILINOS_HAVE_EPETRA
164 #endif // LIBMESH_TRILINOS_PRECONDITIONER_H
virtual const char * Label() const libmesh_override
void set_params(Teuchos::ParameterList &list)
Stores a copy of the ParameterList list internally.
virtual ~TrilinosPreconditioner()
Destructor.
Encapsulates the MPI_Comm object.
Definition: parallel.h:657
Teuchos::ParameterList _param_list
Parameter list to be used for building the preconditioner.
virtual int SetUseTranspose(bool UseTranspose) libmesh_override
const class libmesh_nullptr_t libmesh_nullptr
Numeric vector.
Definition: dof_map.h:66
virtual const Epetra_Map & OperatorRangeMap() const libmesh_override
virtual void clear() libmesh_override
Release all memory and clear data structures.
virtual int Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const libmesh_override
The libMesh namespace provides an interface to certain functionality in the library.
virtual const Epetra_Comm & Comm() const libmesh_override
TrilinosPreconditioner(const libMesh::Parallel::Communicator &comm LIBMESH_CAN_DEFAULT_TO_COMMWORLD)
Constructor.
void set_preconditioner_type(const PreconditionerType &preconditioner_type)
Sets the Trilinos preconditioner to use based on the libMesh PreconditionerType.
This class provides an interface to the suite of preconditioners available from Trilinos.
virtual double NormInf() const libmesh_override
PreconditionerType
Defines an enum for preconditioner types.
This class provides a uniform interface for preconditioners.
Epetra_FECrsMatrix * _mat
Trilinos matrix that&#39;s been pulled out of the _matrix object.
PetscErrorCode Vec x
void compute()
Compute the preconditioner.
virtual bool HasNormInf() const libmesh_override
virtual bool UseTranspose() const libmesh_override
virtual void init() libmesh_override
Initialize data structures if not done so already.
const Parallel::Communicator & comm() const
Epetra_Operator * _prec
Trilinos preconditioner.
virtual void apply(const NumericVector< T > &x, NumericVector< T > &y) libmesh_override
Computes the preconditioned vector y based on input vector x.
virtual int ApplyInverse(const Epetra_MultiVector &r, Epetra_MultiVector &z) const libmesh_override
virtual const Epetra_Map & OperatorDomainMap() const libmesh_override