LifeV
FEField.hpp
Go to the documentation of this file.
1 #ifndef _FEFIELD_
2 #define _FEFIELD_ 1
3 /*
4 *******************************************************************************
5 
6  Copyright (C) 2004, 2005, 2007 EPFL, Politecnico di Milano, INRIA
7  Copyright (C) 2010 EPFL, Politecnico di Milano, Emory University
8 
9  This file is part of LifeV.
10 
11  LifeV is free software; you can redistribute it and/or modify
12  it under the terms of the GNU Lesser General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  LifeV is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  Lesser General Public License for more details.
20 
21  You should have received a copy of the GNU Lesser General Public License
22  along with LifeV. If not, see <http://www.gnu.org/licenses/>.
23 
24 *******************************************************************************
25 */
26 //@HEADER
27 
28 /*!
29  @file
30  @brief File containing the FEField, FEScalarField and FEVectorField classes
31 
32  @author A. Fumagalli <alessio.fumagalli@mail.polimi.it>
33  @author M. Kern <michel.kern@inria.fr>
34  @date 29-03-2011
35 
36 */
37 
38 
39 #include <boost/numeric/ublas/matrix.hpp>
40 
41 
42 #include <lifev/core/LifeV.hpp>
43 #include <lifev/core/fem/FESpace.hpp>
44 #include <lifev/core/array/VectorEpetra.hpp>
45 #include <lifev/core/array/VectorSmall.hpp>
46 
47 namespace LifeV
48 {
49 
50 typedef boost::numeric::ublas::vector<Real> Vector;
51 typedef boost::numeric::ublas::matrix<Real> Matrix;
52 
53 //! FEField - This class gives an abstract implementation of a finite element field.
54 /*!
55  @author A. Fumagalli <alessio.fumagalli@mail.polimi.it>
56  @author M. Kern <michel.kern@inria.fr>
57 
58  This class represents the concept of a field associated to a finite element space.
59  <br>
60  This class is implemented as a simple container which stores a reference to a finite element space
61  and a pointer to a vector. The vector represents the value of the field at each degree of freedom.
62  The type of the value, e.g. scalar, is a template parameter which is specialized in the derived classes
63  for the case of scalar fields and vector fields.
64  <br>
65  The evaluation of the field in a given point is given in the access operator (). The implementation
66  of this method requires also the id of the geometrical element in the mesh, which is less general but
67  more efficient compared to the case where the id of the geometrical element is not given.
68 
69  @todo Add a method without the element id, less efficient but more flexible.
70  @note The attribute which represent a point is an array of three elements. Change in future with a standard container.
71  @note If you need an Raviart-Thomas field you need to create a scalar field and not a vector field, since the field
72  contains the value of a Raviart-Thomas times the outward unit normal of the face element.
73 */
74 template < typename MeshType, typename MapType, typename ReturnType >
75 class FEField
76 {
77 
78 public:
79 
80  //! @name Public Types
81  //@{
82 
83  typedef MeshType mesh_Type;
84  typedef MapType map_Type;
85  typedef ReturnType return_Type;
86 
89 
90  typedef VectorEpetra vector_Type;
92 
94 
95  //@}
96 
97  //! @name Constructors and destructor
98  //@{
99 
100  //! Empty constructor for the class.
102  {}
103 
104  //! Full constructor for the class.
105  /*!
106  @param fESpace Finite element space where the field is defined.
107  @param vector vector witch represent the solution.
108  */
109  FEField ( const FESpacePtr_Type& fESpace, const vectorPtr_Type& vector ) :
110  M_FESpace ( fESpace ),
111  M_vector ( vector )
112  {}
113 
114  //! Constructor for the class without the vector.
115  /*!
116  Create the field with the input finite element space and a new vector.
117  The type of the map of the vector is Repeated (default value) or Unique.
118  @param fESpace Finite element space where the field is defined.
119  @param mapType Specify wether the map is Unique or Repeated. Default value: Repeated.
120  */
121  FEField ( const FESpacePtr_Type& fESpace, const MapEpetraType& mapType = Repeated ) :
122  M_FESpace ( fESpace ),
123  M_vector ( new vector_Type ( M_FESpace->map(), mapType ) )
124  {}
125 
126  //! Copy constructor.
127  /*!
128  @param field Finite element field to be copied.
129  */
130  FEField ( const FEField& field ) :
131  M_FESpace ( field.M_FESpace ),
132  M_vector ( field.M_vector )
133  {}
134 
135  //! Virtual destructor.
136  virtual ~FEField () {};
137 
138  //@}
139 
140  //! @name Operators
141  //@{
142 
143  FEField& operator = ( const FEField& field )
144  {
145  if ( this != & field )
146  {
147  M_FESpace = field.M_FESpace;
148  M_vector = field.M_vector;
149  }
150  return *this;
151  }
152 
153  //@}
154 
155  //! @name Methods
156  //@{
157 
158  //! Abstract virtual eval function.
159  /*!
160  Evaluate the field on a given point in a given element.
161  @param iElem Element id in the mesh.
162  @param point Point where the field is evaluated, vector format.
163  @return The template type of the value of the field.
164  */
165  virtual return_Type eval ( const UInt& iElem,
166  const point_Type& point,
167  const Real& time = 0.) const = 0;
168 
169  //@}
170 
171  //! @name Set Methods
172  //@{
173 
174  //! Set the FESpace
175  /*!
176  @param fESpace Pointer of a FESpace.
177  @param createVector True if the vector is created, false otherwise. Default value: false.
178  @param mapType Specify wether the map is Unique or Repeated. Default value: Repeated.
179  */
180  void setFESpacePtr ( const FESpacePtr_Type& fESpace,
181  const bool createVector = false,
182  const MapEpetraType& mapType = Repeated )
183  {
184  M_FESpace = fESpace;
185 
186  if ( createVector )
187  {
188  M_vector.reset ( new vector_Type ( M_FESpace->map(), mapType ) );
189  }
190  }
191 
192  //! Set the epetra vector
193  /*!
194  @param vector Pointer of an epetra vector.
195  */
196  void setVectorPtr ( const vectorPtr_Type& vector )
197  {
198  M_vector = vector;
199  }
200 
201  //! Set the epetra vector
202  /*!
203  @param vector The epetra vector.
204  */
205  void setVector ( const vector_Type& vector )
206  {
207  M_vector.reset ( new vector_Type ( vector ) );
208  }
209 
210  //! Set both FESpace and vector
211  /*!
212  @param fESpace Pointer of a FESpace.
213  @param vector Pointer of a vector.
214  */
215  void setUp ( const FESpacePtr_Type& fESpace, const vectorPtr_Type& vector )
216  {
217  this->setFESpacePtr ( fESpace, false );
218  this->setVectorPtr ( vector );
219  }
220 
221  //! Clean the field.
222  void cleanField ()
223  {
224  this->getVector().zero();
225  }
226 
227  //@}
228 
229  //! @name Get Methods
230  //@{
231 
232  //! Return the finite element space.
233  /*!
234  @return Constant FESpace_Type reference of the finite element space.
235  */
236  const FESpace_Type& getFESpace () const
237  {
238  return *M_FESpace;
239  }
240 
241  //! Return the pointer to the finite element space.
242  /*!
243  @return Constant FESpacePtr_Type reference of the finite element space.
244  */
246  {
247  return M_FESpace;
248  }
249 
250  //! Return the finite element space.
251  /*!
252  @return FESpace_Type reference of the finite element space.
253  */
255  {
256  return *M_FESpace;
257  }
258 
259  //! Return the vector where the value are stored.
260  /*!
261  @return Constant vectorPtr_Type reference of the vector.
262  */
263  const vectorPtr_Type& getVectorPtr () const
264  {
265  return M_vector;
266  }
267 
268  //! Return the vector where the value are stored.
269  /*!
270  @return vector_Type reference of the vector.
271  */
273  {
274  return *M_vector;
275  }
276 
277  //! Return the vector where the value are stored.
278  /*!
279  @return Constant vector_Type reference of the vector.
280  */
281  const vector_Type& getVector () const
282  {
283  return *M_vector;
284  }
285 
286  //@}
287 
288 protected:
289 
290  //! Reference of the finite element space.
292 
293  //! Pointer of a vector where the value are stored.
295 
296 };
297 
298 //! FEScalarField - This class gives an abstract implementation of a finite element scalar field.
299 /*!
300  @author A. Fumagalli <alessio.fumagalli@mail.polimi.it>
301  @author M. Kern <michel.kern@inria.fr>
302 
303  This class, derived from FEField, implements the concept of a scalar field associated to a
304  finite element space.
305 */
306 template < typename MeshType, typename MapType >
308  public FEField < MeshType, MapType, Real >
309 {
310 public:
311 
312  //! @name Public Types
313  //@{
314 
315  typedef MeshType mesh_Type;
316  typedef MapType map_Type;
317  typedef Real return_Type;
318 
320 
323 
324  typedef typename FEField_Type::point_Type point_Type;
325 
326  //@}
327 
328  //! @name Constructors and destructor
329  //@{
330 
331  //! Empty constructor for the class.
333  {}
334 
335  //! Full constructor for the class.
336  /*!
337  @param fESpace Finite element space where the field is defined.
338  @param vector vector witch represent the solution.
339  */
340  FEScalarField ( const FESpacePtr_Type& fESpace, const vectorPtr_Type& vector ) :
341  FEField_Type ( fESpace, vector )
342  {}
343 
344  //! Constructor for the class without the vector.
345  /*!
346  Create the field with the input finite element space and a new vector.
347  The type of the map of the vector is Repeated (default value) or Unique.
348  @param fESpace Finite element space where the field is defined.
349  @param mapType Specify wether the map is Unique or Repeated. Default value: Repeated.
350  */
351  FEScalarField ( const FESpacePtr_Type& fESpace, const MapEpetraType& mapType = Repeated ) :
352  FEField_Type ( fESpace, mapType )
353  {}
354 
355  //! Copy constructor.
356  /*!
357  @param field Finite element field to be copied.
358  */
359  FEScalarField ( const FEScalarField& field ) :
360  FEField_Type ( field )
361  {}
362 
363  //! Virtual destructor.
364  virtual ~FEScalarField () {};
365 
366  //@}
367 
368  //! @name Methods
369  //@{
370 
371  //! Eval function.
372  /*!
373  Evaluate the field on a given point in a given element.
374  @param iElem Element id in the mesh.
375  @param point Point where the field is evaluated, vector format.
376  @return The scalar value of the field.
377  */
378  virtual return_Type eval ( const UInt& iElem,
379  const point_Type& P,
380  const Real& time = 0. ) const;
381 
382  //!}
383 
384 };
385 
386 template < typename MeshType, typename MapType >
387 inline Real
388 FEScalarField < MeshType, MapType >::
389 eval ( const UInt& iElem, const point_Type& P, const Real& /*time*/ ) const
390 {
391  // Evaluate the field using a method implemented in FESpace
392  return this->M_FESpace->feInterpolateValue ( iElem, * (this->M_vector), P );
393 } // eval
394 
395 
396 //! FEVectorField - This class gives an abstract implementation of a finite element vector field.
397 /*!
398  @author A. Fumagalli <alessio.fumagalli@mail.polimi.it>
399  @author M. Kern <michel.kern@inria.fr>
400 
401  This class, derived from FEField, implements the concept of a vector field associated to a
402  finite element space.
403 */
404 template < typename MeshType, typename MapType >
406  public FEField < MeshType, MapType, Vector >
407 {
408 
409 public:
410 
411  //! @name Public Types
412  //@{
413 
414  typedef MeshType mesh_Type;
415  typedef MapType map_Type;
416  typedef Vector return_Type;
417 
419 
422 
423  typedef typename FEField_Type::point_Type point_Type;
424 
425  //@}
426 
427  //! @name Constructors and destructor
428  //@{
429 
430  //! Empty constructor for the class.
432  {}
433 
434  //! Full constructor for the class.
435  /*!
436  @param fESpace Finite element space where the field is defined.
437  @param vector vector witch represent the solution.
438  */
439  FEVectorField ( const FESpacePtr_Type& fESpace, const vectorPtr_Type& vector ) :
440  FEField_Type ( fESpace, vector )
441  {}
442 
443  //! Constructor for the class without the vector.
444  /*!
445  Create the field with the input finite element space and a new vector.
446  The type of the map of the vector is Repeated (default value) or Unique.
447  @param fESpace Finite element space where the field is defined.
448  @param mapType Specify wether the map is Unique or Repeated. Default value: Repeated.
449  */
450  FEVectorField ( const FESpacePtr_Type& fESpace, const MapEpetraType& mapType = Repeated ) :
451  FEField_Type ( fESpace, mapType )
452  {}
453 
454  //! Copy constructor.
455  /*!
456  @param field Finite element field to be copied.
457  */
458  FEVectorField ( const FEVectorField& field ) :
459  FEField_Type ( field )
460  {}
461 
462  //! Virtual destructor.
463  virtual ~FEVectorField () {};
464 
465  //@}
466 
467  //! @name Opertors
468  //@{
469 
470  //! Eval function.
471  /*!
472  Evaluate the field on a given point in a given element.
473  @param iElem Element id in the mesh.
474  @param point Point where the field is evaluated, vector format.
475  @return The vector value of the field.
476  */
477  virtual return_Type eval ( const UInt& iElem,
478  const point_Type& P,
479  const Real& time = 0. ) const;
480 
481 };
482 
483 template < typename MeshType, typename MapType >
484 inline Vector
485 FEVectorField < MeshType, MapType >::
486 eval ( const UInt& iElem, const point_Type& P, const Real& /*time*/ ) const
487 {
488  Vector value ( P.size() );
489 
490  // Evaluate each component of the vector field with a method in the class FESpace.
491  for ( UInt i = 0; i < P.size(); ++i )
492  {
493  value (i) = this->M_FESpace->feInterpolateValue ( iElem, * (this->M_vector), P, i );
494  }
495  return value;
496 
497 } // eval
498 
500 
502 
503 } // namespace LifeV
504 
505 #endif
MeshType mesh_Type
Definition: FEField.hpp:83
vector_Type & getVector()
Return the vector where the value are stored.
Definition: FEField.hpp:272
FEField & operator=(const FEField &field)
Definition: FEField.hpp:143
FEVectorField(const FESpacePtr_Type &fESpace, const MapEpetraType &mapType=Repeated)
Constructor for the class without the vector.
Definition: FEField.hpp:450
ReturnType return_Type
Definition: FEField.hpp:85
FEScalarField< RegionMesh< LinearTetra >, MapEpetra > FEScalarFieldTetra
Definition: FEField.hpp:499
FEField - This class gives an abstract implementation of a finite element field.
Definition: FEField.hpp:75
FEVectorField(const FEVectorField &field)
Copy constructor.
Definition: FEField.hpp:458
FESpace - Short description here please!
Definition: FESpace.hpp:78
FEField_Type::point_Type point_Type
Definition: FEField.hpp:324
FEVectorField< RegionMesh< LinearTetra >, MapEpetra > FEVectorFieldTetra
Definition: FEField.hpp:501
FEScalarField(const FEScalarField &field)
Copy constructor.
Definition: FEField.hpp:359
const FESpace_Type & getFESpace() const
Return the finite element space.
Definition: FEField.hpp:236
void cleanField()
Clean the field.
Definition: FEField.hpp:222
virtual return_Type eval(const UInt &iElem, const point_Type &point, const Real &time=0.) const =0
Abstract virtual eval function.
FEField_Type::vectorPtr_Type vectorPtr_Type
Definition: FEField.hpp:322
FEVectorField()
Empty constructor for the class.
Definition: FEField.hpp:431
FEField< mesh_Type, map_Type, return_Type > FEField_Type
Definition: FEField.hpp:418
FEField(const FEField &field)
Copy constructor.
Definition: FEField.hpp:130
FEVectorField(const FESpacePtr_Type &fESpace, const vectorPtr_Type &vector)
Full constructor for the class.
Definition: FEField.hpp:439
virtual return_Type eval(const UInt &iElem, const point_Type &P, const Real &time=0.) const
Eval function.
Definition: FEField.hpp:486
FEScalarField - This class gives an abstract implementation of a finite element scalar field...
Definition: FEField.hpp:307
vectorPtr_Type M_vector
Pointer of a vector where the value are stored.
Definition: FEField.hpp:294
void setUp(const FESpacePtr_Type &fESpace, const vectorPtr_Type &vector)
Set both FESpace and vector.
Definition: FEField.hpp:215
const vector_Type & getVector() const
Return the vector where the value are stored.
Definition: FEField.hpp:281
virtual ~FEVectorField()
Virtual destructor.
Definition: FEField.hpp:463
FEField< mesh_Type, map_Type, return_Type > FEField_Type
Definition: FEField.hpp:319
FEField_Type::point_Type point_Type
Definition: FEField.hpp:423
FEField()
Empty constructor for the class.
Definition: FEField.hpp:101
FEField(const FESpacePtr_Type &fESpace, const vectorPtr_Type &vector)
Full constructor for the class.
Definition: FEField.hpp:109
void setFESpacePtr(const FESpacePtr_Type &fESpace, const bool createVector=false, const MapEpetraType &mapType=Repeated)
Set the FESpace.
Definition: FEField.hpp:180
FEField_Type::FESpacePtr_Type FESpacePtr_Type
Definition: FEField.hpp:321
const FESpacePtr_Type & getFESpacePtr() const
Return the pointer to the finite element space.
Definition: FEField.hpp:245
void setVector(const vector_Type &vector)
Set the epetra vector.
Definition: FEField.hpp:205
FEField_Type::FESpacePtr_Type FESpacePtr_Type
Definition: FEField.hpp:420
virtual ~FEScalarField()
Virtual destructor.
Definition: FEField.hpp:364
double Real
Generic real data.
Definition: LifeV.hpp:175
FEScalarField(const FESpacePtr_Type &fESpace, const MapEpetraType &mapType=Repeated)
Constructor for the class without the vector.
Definition: FEField.hpp:351
FESpace< mesh_Type, map_Type > FESpace_Type
Definition: FEField.hpp:87
VectorEpetra vector_Type
Definition: FEField.hpp:90
FEVectorField - This class gives an abstract implementation of a finite element vector field...
Definition: FEField.hpp:405
FEField_Type::vectorPtr_Type vectorPtr_Type
Definition: FEField.hpp:421
void setVectorPtr(const vectorPtr_Type &vector)
Set the epetra vector.
Definition: FEField.hpp:196
VectorSmall< 3 > Vector3D
std::shared_ptr< vector_Type > vectorPtr_Type
Definition: FEField.hpp:91
FESpacePtr_Type M_FESpace
Reference of the finite element space.
Definition: FEField.hpp:291
Vector3D point_Type
Definition: FEField.hpp:93
FEScalarField()
Empty constructor for the class.
Definition: FEField.hpp:332
MapType map_Type
Definition: FEField.hpp:84
virtual return_Type eval(const UInt &iElem, const point_Type &P, const Real &time=0.) const
Eval function.
Definition: FEField.hpp:389
const vectorPtr_Type & getVectorPtr() const
Return the vector where the value are stored.
Definition: FEField.hpp:263
FEField(const FESpacePtr_Type &fESpace, const MapEpetraType &mapType=Repeated)
Constructor for the class without the vector.
Definition: FEField.hpp:121
std::shared_ptr< FESpace_Type > FESpacePtr_Type
Definition: FEField.hpp:88
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191
FEScalarField(const FESpacePtr_Type &fESpace, const vectorPtr_Type &vector)
Full constructor for the class.
Definition: FEField.hpp:340
FESpace_Type & getFESpace()
Return the finite element space.
Definition: FEField.hpp:254
virtual ~FEField()
Virtual destructor.
Definition: FEField.hpp:136