LifeV
LinearOperatorAlgebra.hpp
Go to the documentation of this file.
1 /*
2  * LinearOperator.hpp
3  *
4  * Created on: Sep 3, 2010
5  * Author: uvilla
6  */
7 
8 #ifndef LINEAR_OPERATOR_ALGEBRA_HPP_
9 #define LINEAR_OPERATOR_ALGEBRA_HPP_
10 
11 #include <Epetra_Comm.h>
12 #include <Epetra_Map.h>
13 #include <Epetra_Operator.h>
14 #include <Epetra_MultiVector.h>
15 
16 #include <lifev/core/LifeV.hpp>
17 
18 namespace LifeV
19 {
20 
21 //Forward declaration (save a lot of re-compiling time when VectorEpetra or MatrixEpetra are modified)
22 class VectorEpetra;
23 
24 namespace Operators
25 {
26 //! @class LinearOperator
27 /*! @brief Abstract class which defines the interface of a Linear Operator.
28  *
29  * LinearOperator is an abstract which inherits from Epetra_Operator.
30  * LinearOperator should be the base class for all the LifeV class which implements a linear operator.
31  *
32  * LinearOperator ensures perfect compatibility with all the Trilinos solvers,
33  * plus it supports directly the LifeV::VectorEpetra data.
34  *
35  * Two concrete methods are implemented in LinearOperator
36  * int apply(const VectorEpetra &X, VectorEpetra & Y) const ;
37  * int applyInverse(const VectorEpetra &X, VectorEpetra &Y) const.
38  *
39  *
40  * Such methods extract a raw Epetra_MultiVector from the VectorEpetra and then call the virtual methods
41  * Int Apply(const Epetra_MultiVector & X, Epetra_MultiVector & Y) const
42  * or
43  * Int ApplyInverse(const Epetra_MultiVector & X, Epetra_MultiVector & Y) const
44  * respectively.
45  *
46  *
47  */
49 {
50 public:
51 
52  //! @name Public Types
53  //@{
63  //@}
64 
65  //! @name Destructor
66  //@{
67  //! Destructor
68  virtual ~LinearOperatorAlgebra() {};
69  //@}
70 
71  //! @name Attribute set methods
72  //@{
73 
74  //! If set true, transpose of this operator will be applied.
75  /*! This flag allows the transpose of the given operator to be used implicitly. Setting this flag
76  affects only the Apply() and ApplyInverse() methods. If the implementation of this interface
77  does not support transpose use, this method should return a value of -1.
78 
79  \param In
80  UseTranspose -If true, multiply by the transpose of operator, otherwise just use operator.
81 
82  \return Integer error code, set to 0 if successful. Set to -1 if this implementation does not support transpose.
83  */
84  virtual int SetUseTranspose(bool UseTranspose) = 0;
85  //@}
86 
87  //! @name Mathematical functions
88  //@{
89 
90  //! Returns the result of a raw_operator applied to a raw_vector X in Y.
91  /*!
92  \param In
93  X - A raw_vector of dimension NumVectors to multiply with matrix.
94  \param Out
95  Y -A raw_vector of dimension NumVectors containing result.
96 
97  \return Integer error code, set to 0 if successful.
98  */
99  virtual int Apply(const vector_Type& X, vector_Type& Y) const = 0;
100 
101  //! Returns the result of a LinearOperator applied to a VectorEpetra X in Y.
102  /*!
103  \param In
104  X - A VectorEpetra to multiply with matrix.
105  \param Out
106  Y -A VectorEpetra containing result.
107 
108  \return Integer error code, set to 0 if successful.
109  */
110  int apply(const VectorEpetra & X, VectorEpetra & Y) const;
111 
112  //! Returns the result of a raw_operator inverse applied to an raw_vector X in Y.
113  /*!
114  \param In
115  X - A raw_vector of dimension NumVectors to solve for.
116  \param Out
117  Y -A raw_vector of dimension NumVectors containing result.
118 
119  \return Integer error code, set to 0 if successful.
120 
121  \warning In order to work with AztecOO, any implementation of this method must
122  support the case where X and Y are the same object.
123  */
124  virtual int ApplyInverse(const vector_Type& X, vector_Type& Y) const = 0;
125 
126  //! Returns the result of a LinearOperator inverse applied to an VectorEpetra X in Y.
127  /*!
128  \param In
129  X - A VectorEpetra to solve for.
130  \param Out
131  Y -A VectorEpetra containing result.
132 
133  \return Integer error code, set to 0 if successful.
134 
135  \warning In order to work with AztecOO, any implementation of this method must
136  support the case where X and Y are the same object.
137  */
138 
139  int applyInverse(const VectorEpetra & X, VectorEpetra & Y);
140 
141  //! Returns the infinity norm of the global matrix.
142  /* Returns the quantity \f$ \| A \|_\infty\f$ such that
143  \f[\| A \|_\infty = \max_{1\lei\lem} \sum_{j=1}^n |a_{ij}| \f].
144 
145  \warning This method must not be called unless HasNormInf() returns true.
146  */
147  virtual double NormInf() const = 0;
148  //@}
149 
150  //! @name Attribute access functions
151  //@{
152 
153  //! Returns a character string describing the operator
154  virtual const char * Label() const = 0;
155 
156  //! Returns the current UseTranspose setting.
157  virtual bool UseTranspose() const = 0;
158 
159  //! Returns true if the \e this object can provide an approximate Inf-norm, false otherwise.
160  virtual bool HasNormInf() const = 0;
161 
162  //! Returns a pointer to the Epetra_Comm communicator associated with this operator.
163  virtual const comm_Type & Comm() const = 0;
164 
165  //! Returns the raw_map object associated with the domain of this operator.
166  virtual const map_Type & OperatorDomainMap() const = 0;
167 
168  //! Returns the raw_map object associated with the range of this operator.
169  virtual const map_Type & OperatorRangeMap() const = 0;
170  //@}
171 
172 };
173 
174 //! @class IdentityOperator
175 /*! @brief Identity operator x = I*x. */
177 {
178 public:
179 
181  typedef super::map_Type map_Type;
182  typedef super::mapPtr_Type mapPtr_Type;
183  typedef super::vector_Type vector_Type;
184 
185  IdentityOperator():M_name("identity"), M_useTranspose(false) {};
186  void setUp(const mapPtr_Type & map)
187  {
188  M_map = map;
189  }
190  int SetUseTranspose(bool useTranspose)
191  {
192  M_useTranspose = useTranspose;
193  return 0;
194  }
195  int Apply(const vector_Type & X, vector_Type & Y) const
196  {
197  Y = X;
198  return 0;
199  }
200  int ApplyInverse(const vector_Type & X, vector_Type & Y) const
201  {
202  Y = X;
203  return 0;
204  }
205  double NormInf() const
206  {
207  return 1.0;
208  }
209  const char * Label() const
210  {
211  return M_name.c_str();
212  }
213  bool UseTranspose() const
214  {
215  return M_useTranspose;
216  }
217  bool HasNormInf() const
218  {
219  return true;
220  }
221  const comm_Type & Comm() const
222  {
223  return M_map->Comm();
224  }
225  const map_Type & OperatorDomainMap() const
226  {
227  return *M_map;
228  }
229  const map_Type & OperatorRangeMap() const
230  {
231  return *M_map;
232  }
233 private:
234  std::string M_name;
235  mapPtr_Type M_map;
237 };
238 
239 //! @class NullOperator
240 /*! @brief Null operator 0 = Z*x. */
242 {
243 public:
244 
246  typedef super::map_Type map_Type;
247  typedef super::mapPtr_Type mapPtr_Type;
248  typedef super::vector_Type vector_Type;
249 
250  NullOperator():M_name("Null Operator"), M_useTranspose(false) {};
251  void setUp(const mapPtr_Type & domainMap,
252  const mapPtr_Type & rangeMap)
253  {
254  M_domainMap = domainMap;
255  M_rangeMap = rangeMap;
256  }
257  int SetUseTranspose(bool useTranspose)
258  {
259  M_useTranspose = useTranspose;
260  return 0;
261  }
262  int Apply(const vector_Type & /*X*/, vector_Type & Y) const
263  {
264  Y.PutScalar(0.0);
265  return 0;
266  }
267  int ApplyInverse(const vector_Type & /*X*/, vector_Type & Y) const
268  {
269  Y.PutScalar(1.0/0.0);
270  return -1;
271  }
272  double NormInf() const
273  {
274  return 0.0;
275  }
276  const char * Label() const
277  {
278  return M_name.c_str();
279  }
280  bool UseTranspose() const
281  {
282  return M_useTranspose;
283  }
284  bool HasNormInf() const
285  {
286  return true;
287  }
288  const comm_Type & Comm() const
289  {
290  return M_rangeMap->Comm();
291  }
292  const map_Type & OperatorDomainMap() const
293  {
294  return *M_domainMap;
295  }
296  const map_Type & OperatorRangeMap() const
297  {
298  return *M_rangeMap;
299  }
300 private:
301  std::string M_name;
302  mapPtr_Type M_domainMap;
303  mapPtr_Type M_rangeMap;
305 };
306 
307 } /*end namespace Operators*/
308 } /*end namespace */
309 #endif /* LINEAR_OPERATOR_ALGEBRA_HPP_ */
VectorEpetra - The Epetra Vector format Wrapper.
bool UseTranspose() const
Returns the current UseTranspose setting.
virtual const map_Type & OperatorRangeMap() const =0
Returns the raw_map object associated with the range of this operator.
int Apply(const vector_Type &, vector_Type &Y) const
Returns the result of a raw_operator applied to a raw_vector X in Y.
virtual int SetUseTranspose(bool UseTranspose)=0
If set true, transpose of this operator will be applied.
int ApplyInverse(const vector_Type &X, vector_Type &Y) const
Returns the result of a raw_operator inverse applied to an raw_vector X in Y.
double NormInf() const
Returns the infinity norm of the global matrix.
void setUp(const mapPtr_Type &domainMap, const mapPtr_Type &rangeMap)
const char * Label() const
Returns a character string describing the operator.
std::shared_ptr< const map_Type > constMapPtr_Type
int apply(const VectorEpetra &X, VectorEpetra &Y) const
Returns the result of a LinearOperator applied to a VectorEpetra X in Y.
const comm_Type & Comm() const
Returns a pointer to the Epetra_Comm communicator associated with this operator.
Abstract class which defines the interface of a Linear Operator.
int ApplyInverse(const vector_Type &, vector_Type &Y) const
Returns the result of a raw_operator inverse applied to an raw_vector X in Y.
void updateInverseJacobian(const UInt &iQuadPt)
int SetUseTranspose(bool useTranspose)
If set true, transpose of this operator will be applied.
bool HasNormInf() const
Returns true if the this object can provide an approximate Inf-norm, false otherwise.
virtual double NormInf() const =0
Returns the infinity norm of the global matrix.
virtual const char * Label() const =0
Returns a character string describing the operator.
virtual const comm_Type & Comm() const =0
Returns a pointer to the Epetra_Comm communicator associated with this operator.
virtual bool UseTranspose() const =0
Returns the current UseTranspose setting.
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.
virtual const map_Type & OperatorDomainMap() const =0
Returns the raw_map object associated with the domain of this operator.
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.
int SetUseTranspose(bool useTranspose)
If set true, transpose of this operator will be applied.
const char * Label() const
Returns a character string describing the operator.
bool UseTranspose() const
Returns the current UseTranspose setting.
const comm_Type & Comm() const
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.
int Apply(const vector_Type &X, vector_Type &Y) const
Returns the result of a raw_operator applied to a raw_vector X in Y.
int applyInverse(const VectorEpetra &X, VectorEpetra &Y)
Returns the result of a LinearOperator inverse applied to an VectorEpetra X in Y. ...
const map_Type & OperatorDomainMap() const
Returns the raw_map object associated with the domain of this operator.
const map_Type & OperatorDomainMap() const
Returns the raw_map object associated with the domain of this operator.
std::shared_ptr< vector_Type > vectorPtr_Type
double NormInf() const
Returns the infinity norm of the global matrix.
bool HasNormInf() const
Returns true if the this object can provide an approximate Inf-norm, false otherwise.
const map_Type & OperatorRangeMap() const
Returns the raw_map object associated with the range of this operator.
std::shared_ptr< operator_Type > operatorPtr_Type
const map_Type & OperatorRangeMap() const
Returns the raw_map object associated with the range of this operator.