LifeV
FEFunction.hpp
Go to the documentation of this file.
1 #ifndef _FEFUNCTION_
2 #define _FEFUNCTION_ 1
3 
4 /*
5 *******************************************************************************
6 
7  Copyright (C) 2004, 2005, 2007 EPFL, Politecnico di Milano, INRIA
8  Copyright (C) 2010 EPFL, Politecnico di Milano, Emory University
9 
10  This file is part of LifeV.
11 
12  LifeV is free software; you can redistribute it and/or modify
13  it under the terms of the GNU Lesser General Public License as published by
14  the Free Software Foundation, either version 3 of the License, or
15  (at your option) any later version.
16 
17  LifeV is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  Lesser General Public License for more details.
21 
22  You should have received a copy of the GNU Lesser General Public License
23  along with LifeV. If not, see <http://www.gnu.org/licenses/>.
24 
25 *******************************************************************************
26 */
27 //@HEADER
28 
29 /*!
30  @file
31  @brief File containing the FEFunction class
32 
33  @author A. Fumagalli <alessio.fumagalli@mail.polimi.it>
34  @author M. Kern <michel.kern@inria.fr>
35  @date 29-03-2011
36 
37 */
38 
39 #include <lifev/core/fem/FEField.hpp>
40 
41 namespace LifeV
42 {
43 
44 //! FEFunction - This class gives an abstract implementation of a finite element function on finite elements fields.
45 /*!
46  @author A. Fumagalli <alessio.fumagalli@mail.polimi.it>
47  @author M. Kern <michel.kern@inria.fr>
48 
49  This class represents the concept of a function associated to a set of finite element fields.
50  <br>
51  This class is implemented as a simple container which stores pointers to finite element fields, both
52  scalar and vector.
53  <br>
54  <br>
55  The method eval, which is abstract and virtual, is the manipulator of the fields.
56  <br>
57  For example the scalar function \f$ f \f$ is a function of the scalar field \f$ S \f$ and the vector
58  field \f$ u \f$, that is \f$ f = f(S, u)\f$. And, for example, the function \f$ f \f$ is
59  \f[
60  f(S, u) = S^2 + \sin( u_0 )
61  \f]
62  then create a new class MyFun which inherit from FEFunction<MeshType, MapType, Real> where the eval method,
63  using the methods scalarField and vectorField, can be written as
64  @code
65  const Real S = scalarField(0).eval( iElem, point, time );
66  const Vector u = vectorField(0).eval( iElem, point, time );
67  return std::pow(S, 2) + std::sin( u[0] );
68  @endcode
69  Partial specialization of the type returned by the access operator is scalar, vector and matrix, implemented
70  in the derived classes. The implementation of user defined classes can be derived from one of the specialized
71  classes.
72  <br>
73  The evaluation of the field in a given point is given in the access operator (). The implementation
74  of this method requires also the id of the geometrical element in the mesh, which is less general but
75  more efficient compared to the case where the id of the geometrical element is not given.
76 
77  @todo Add a method without the element id, less efficient but more flexible.
78 */
79 template < typename MeshType, typename MapType, typename ReturnType >
80 class FEFunction
81 {
82 public:
83 
84  //! @name Public Types
85  //@{
86 
87  typedef MeshType mesh_Type;
88  typedef MapType map_Type;
89  typedef ReturnType return_Type;
90 
94 
95  typedef typename std::shared_ptr < FEField_Type > FEFieldPtr_Type;
98 
101 
102  typedef typename FEField_Type::point_Type point_Type;
103 
104  //@}
105 
106  //! @name Constructors and destructor
107  //@{
108 
109  //! Empty constructor for the class.
111  {}
112 
113  //! Virtual destructor.
114  virtual ~FEFunction ()
115  {}
116 
117  //! @name Methods
118  //@{
119 
120  //! Abstract virtual eval function.
121  /*!
122  In the case of derived and specialized classes it evaluates the function on a given point
123  in a given element
124  @param iElem Element id in the mesh.
125  @param point Point where the field is evaluated, vector format.
126  @param time Time in the evaluation.
127  @return The type template of value of the function.
128  */
129  virtual return_Type eval ( const UInt& iElem,
130  const point_Type& P,
131  const Real& time = 0. ) const = 0;
132 
133  //! Interpolate to a field
134  /*!
135  Fill the input field with the value of the function. Useful for exporting pourpose.
136  @param interpolatedFct Field where the function is interpolated.
137  @param time Time in the evaluation.
138  @note The method does not work for matrix value functions.
139  */
140  void interpolate ( FEField_Type& interpolatedFct,
141  const Real& time = 0. ) const
142  {
143  interpolatedFct.getFESpace().interpolate ( this, interpolatedFct.getVector(), time );
144  }
145 
146  //! Add an external scalar field to the function.
147  /*!
148  @param fieldPtr Pointer of a scalar field which as to be added.
149  */
150  void addScalarField ( const FEScalarFieldPtr_Type& fieldPtr )
151  {
152  M_scalarFields.push_back ( fieldPtr );
153  }
154 
155  //! Add an external vector field to the function.
156  /*!
157  @param fieldPtr Pointer of a vector field which as to be added.
158  */
159  void addVectorField ( const FEVectorFieldPtr_Type& fieldPtr )
160  {
161  M_vectorFields.push_back ( fieldPtr );
162  }
163 
164  //@}
165 
166  //! @name Get Methods
167  //@{
168 
169  //! Return the i-th scalar field.
170  /*!
171  @param i Index of the scalar field.
172  @return Constant FEScalarFieldPtr_Type reference stored of index i.
173  */
174  const FEScalarFieldPtr_Type& scalarFieldPtr ( const UInt& i ) const
175  {
176  ASSERT ( i < M_scalarFields.size() , "Index out of range.");
177  return M_scalarFields[ i ];
178  }
179 
180  //! Return the i-th scalar field.
181  /*!
182  @param i Index of the scalar field.
183  @return Constant FEScalarField_Type reference stored of index i.
184  */
185  const FEScalarField_Type& scalarField ( const UInt& i ) const
186  {
187  ASSERT ( i < M_scalarFields.size() , "Index out of range.");
188  return * ( M_scalarFields[ i ] );
189  }
190 
191  //! Return the i-th vector field.
192  /*!
193  @param i Index of the vector field.
194  @return Constant FEVectorFieldPtr_Type reference stored of index i.
195  */
196  const FEVectorFieldPtr_Type& vectorFieldPtr ( const UInt& i ) const
197  {
198  ASSERT ( i < M_vectorFields.size() , "Index out of range.");
199  return M_vectorFields[ i ];
200  }
201 
202  //! Return the i-th vector field.
203  /*!
204  @param i Index of the vector field.
205  @return Constant FEVectorField_Type reference stored of index i.
206  */
207  const FEVectorField_Type& vectorField ( const UInt& i ) const
208  {
209  ASSERT ( i < M_vectorFields.size() , "Index out of range.");
210  return * ( M_vectorFields[ i ] );
211  }
212 
213  //@}
214 
215 private:
216 
217  //! Vector of pointers of scalar fields.
219 
220  //! Vector of pointers of vector fields.
222 
223 };
224 
225 } // namespace LifeV
226 
227 #endif
FEField - This class gives an abstract implementation of a finite element field.
Definition: FEField.hpp:75
FEScalarFieldPtrContainer_Type M_scalarFields
Vector of pointers of scalar fields.
Definition: FEFunction.hpp:218
const FEScalarFieldPtr_Type & scalarFieldPtr(const UInt &i) const
Return the i-th scalar field.
Definition: FEFunction.hpp:174
MeshType mesh_Type
Definition: FEFunction.hpp:87
const FEScalarField_Type & scalarField(const UInt &i) const
Return the i-th scalar field.
Definition: FEFunction.hpp:185
FEScalarField - This class gives an abstract implementation of a finite element scalar field...
Definition: FEField.hpp:307
const FEVectorFieldPtr_Type & vectorFieldPtr(const UInt &i) const
Return the i-th vector field.
Definition: FEFunction.hpp:196
FEScalarField< mesh_Type, map_Type > FEScalarField_Type
Definition: FEFunction.hpp:92
virtual ~FEFunction()
Virtual destructor.
Definition: FEFunction.hpp:114
#define ASSERT(X, A)
Definition: LifeAssert.hpp:90
const FEVectorField_Type & vectorField(const UInt &i) const
Return the i-th vector field.
Definition: FEFunction.hpp:207
ReturnType return_Type
Definition: FEFunction.hpp:89
void addVectorField(const FEVectorFieldPtr_Type &fieldPtr)
Add an external vector field to the function.
Definition: FEFunction.hpp:159
std::vector< FEVectorFieldPtr_Type > FEVectorFieldPtrContainer_Type
Definition: FEFunction.hpp:100
double Real
Generic real data.
Definition: LifeV.hpp:175
FEVectorField< mesh_Type, map_Type > FEVectorField_Type
Definition: FEFunction.hpp:93
FEVectorField - This class gives an abstract implementation of a finite element vector field...
Definition: FEField.hpp:405
FEVectorFieldPtrContainer_Type M_vectorFields
Vector of pointers of vector fields.
Definition: FEFunction.hpp:221
void interpolate(FEField_Type &interpolatedFct, const Real &time=0.) const
Interpolate to a field.
Definition: FEFunction.hpp:140
void addScalarField(const FEScalarFieldPtr_Type &fieldPtr)
Add an external scalar field to the function.
Definition: FEFunction.hpp:150
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191
virtual return_Type eval(const UInt &iElem, const point_Type &P, const Real &time=0.) const =0
Abstract virtual eval function.
FEField< mesh_Type, map_Type, return_Type > FEField_Type
Definition: FEFunction.hpp:91
FEFunction()
Empty constructor for the class.
Definition: FEFunction.hpp:110
FEField_Type::point_Type point_Type
Definition: FEFunction.hpp:102