LifeV
LinearOperator.hpp
Go to the documentation of this file.
1 //@HEADER
2 /*
3 *******************************************************************************
4 
5  Copyright (C) 2004, 2005, 2007 EPFL, Politecnico di Milano, INRIA
6  Copyright (C) 2010 EPFL, Politecnico di Milano, Emory University
7 
8  This file is part of LifeV.
9 
10  LifeV is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  LifeV is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with LifeV. If not, see <http://www.gnu.org/licenses/>.
22 
23 *******************************************************************************
24 */
25 //@HEADER
26 
27 /*!
28  @file
29  @brief Linear Operator
30 
31  @author Umberto Villa <umberto.villa@gmail.com>
32 
33  @date 03-09-2010
34  */
35 
36 #ifndef LINEAROPERATOR_HPP_
37 #define LINEAROPERATOR_HPP_
38 
39 
40 #include <lifev/core/LifeV.hpp>
41 
42 #include <Epetra_Comm.h>
43 #include <Epetra_Map.h>
44 #include <Epetra_Operator.h>
45 #include <Epetra_MultiVector.h>
46 
47 #include <lifev/core/array/VectorEpetra.hpp>
48 
49 namespace LifeV
50 {
51 namespace Operators
52 {
53 //! @class LinearOperator
54 /*! @brief Abstract class which defines the interface of a Linear Operator.
55  *
56  * LinearOperator is an abstract which inherits from Epetra_Operator.
57  * LinearOperator should be the base class for all the LifeV class which implements a linear operator.
58  *
59  * LinearOperator ensures perfect compatibility with all the Trilinos solvers,
60  * plus it supports directly the LifeV::VectorEpetra data.
61  *
62  * Two concrete methods are implemented in LinearOperator
63  * int apply(const VectorEpetra &X, VectorEpetra & Y) const ;
64  * int applyInverse(const VectorEpetra &X, VectorEpetra &Y) const.
65  *
66  *
67  * Such methods extract a raw Epetra_MultiVector from the VectorEpetra and then call the virtual methods
68  * Int Apply(const Epetra_MultiVector & X, Epetra_MultiVector & Y) const
69  * or
70  * Int ApplyInverse(const Epetra_MultiVector & X, Epetra_MultiVector & Y) const
71  * respectively.
72  *
73  *
74  */
76 {
77 public:
78 
79  //! @name Public Types
80  //@{
90  //@}
91 
92  //! @name Destructor
93  //@{
94  //! Destructor
95  virtual ~LinearOperator() {}
96  //@}
97 
98  //! @name Attribute set methods
99  //@{
100 
101  //! If set true, transpose of this operator will be applied.
102  /*! This flag allows the transpose of the given operator to be used implicitly. Setting this flag
103  affects only the Apply() and ApplyInverse() methods. If the implementation of this interface
104  does not support transpose use, this method should return a value of -1.
105 
106  \param In
107  UseTranspose -If true, multiply by the transpose of operator, otherwise just use operator.
108 
109  \return Integer error code, set to 0 if successful. Set to -1 if this implementation does not support transpose.
110  */
111  virtual int SetUseTranspose (bool UseTranspose) = 0;
112  //@}
113 
114  //! @name Mathematical functions
115  //@{
116 
117  //! Returns the result of a raw_operator applied to a raw_vector X in Y.
118  /*!
119  \param In
120  X - A raw_vector of dimension NumVectors to multiply with matrix.
121  \param Out
122  Y -A raw_vector of dimension NumVectors containing result.
123 
124  \return Integer error code, set to 0 if successful.
125  */
126  virtual int Apply (const vector_Type& X, vector_Type& Y) const = 0;
127 
128  //! Returns the result of a LinearOperator applied to a VectorEpetra X in Y.
129  /*!
130  \param In
131  X - A VectorEpetra to multiply with matrix.
132  \param Out
133  Y -A VectorEpetra containing result.
134 
135  \return Integer error code, set to 0 if successful.
136  */
137  inline int apply (const VectorEpetra& X, VectorEpetra& Y) const
138  {
140  }
141 
142  //! Returns the result of a raw_operator inverse applied to an raw_vector X in Y.
143  /*!
144  \param In
145  X - A raw_vector of dimension NumVectors to solve for.
146  \param Out
147  Y -A raw_vector of dimension NumVectors containing result.
148 
149  \return Integer error code, set to 0 if successful.
150 
151  \warning In order to work with AztecOO, any implementation of this method must
152  support the case where X and Y are the same object.
153  */
154  virtual int ApplyInverse (const vector_Type& X, vector_Type& Y) const = 0;
155 
156  //! Returns the result of a LinearOperator inverse applied to an VectorEpetra X in Y.
157  /*!
158  \param In
159  X - A VectorEpetra to solve for.
160  \param Out
161  Y -A VectorEpetra containing result.
162 
163  \return Integer error code, set to 0 if successful.
164 
165  \warning In order to work with AztecOO, any implementation of this method must
166  support the case where X and Y are the same object.
167  */
168 
169  inline int applyInverse (const VectorEpetra& X, VectorEpetra& Y)
170  {
172  }
173 
174  //! Returns the infinity norm of the global matrix.
175  /* Returns the quantity \f$ \| A \|_\infty\f$ such that
176  \f[\| A \|_\infty = \max_{1\lei\lem} \sum_{j=1}^n |a_{ij}| \f].
177 
178  \warning This method must not be called unless HasNormInf() returns true.
179  */
180  virtual double NormInf() const = 0;
181  //@}
182 
183  //! @name Attribute access functions
184  //@{
185 
186  //! Returns a character string describing the operator
187  virtual const char* Label() const = 0;
188 
189  //! Returns the current UseTranspose setting.
190  virtual bool UseTranspose() const = 0;
191 
192  //! Returns true if the \e this object can provide an approximate Inf-norm, false otherwise.
193  virtual bool HasNormInf() const = 0;
194 
195  //! Returns a pointer to the Epetra_Comm communicator associated with this operator.
196  virtual const comm_Type& Comm() const = 0;
197 
198  //! Returns the raw_map object associated with the domain of this operator.
199  virtual const map_Type& OperatorDomainMap() const = 0;
200 
201  //! Returns the raw_map object associated with the range of this operator.
202  virtual const map_Type& OperatorRangeMap() const = 0;
203  //@}
204 
205 };
206 
207 } /*end namespace Operators*/
208 } /*end namespace */
209 #endif /* LINEAROPERATOR_HPP_ */
VectorEpetra - The Epetra Vector format Wrapper.
virtual const char * Label() const =0
Returns a character string describing the operator.
Abstract class which defines the interface of a Linear Operator.
std::shared_ptr< map_Type > mapPtr_Type
int applyInverse(const VectorEpetra &X, VectorEpetra &Y)
Returns the result of a LinearOperator inverse applied to an VectorEpetra X in Y. ...
std::shared_ptr< comm_Type > commPtr_Type
virtual ~LinearOperator()
Destructor.
virtual const comm_Type & Comm() const =0
Returns a pointer to the Epetra_Comm communicator associated with this operator.
virtual bool HasNormInf() const =0
Returns true if the this object can provide an approximate Inf-norm, false otherwise.
virtual int ApplyInverse(const vector_Type &X, vector_Type &Y) const =0
Returns the result of a raw_operator inverse applied to an raw_vector X in Y.
virtual double NormInf() const =0
Returns the infinity norm of the global matrix.
void updateInverseJacobian(const UInt &iQuadPt)
std::shared_ptr< vector_Type > vectorPtr_Type
virtual const map_Type & OperatorRangeMap() const =0
Returns the raw_map object associated with the range of this operator.
virtual int Apply(const vector_Type &X, vector_Type &Y) const =0
Returns the result of a raw_operator applied to a raw_vector X in Y.
vector_type & epetraVector()
Return the VectorEpetra in the wrapper.
int apply(const VectorEpetra &X, VectorEpetra &Y) const
Returns the result of a LinearOperator applied to a VectorEpetra X in Y.
virtual const map_Type & OperatorDomainMap() const =0
Returns the raw_map object associated with the domain of this operator.
std::shared_ptr< operator_Type > operatorPtr_Type
const vector_type & epetraVector() const
Return the VectorEpetra in the wrapper.
virtual int SetUseTranspose(bool UseTranspose)=0
If set true, transpose of this operator will be applied.
std::shared_ptr< const map_Type > constMapPtr_Type
virtual bool UseTranspose() const =0
Returns the current UseTranspose setting.