LifeV
EvaluationInterpolateValue.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 the LifeV library
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
21  License along with this library; if not, see <http://www.gnu.org/licenses/>
22 
23 
24 *******************************************************************************
25 */
26 //@HEADER
27 
28 /*!
29  * @file
30  @brief This file contains the definition of the EvaluationInterpolateValue class.
31 
32  @date 06/2011
33  @author Samuel Quinodoz <samuel.quinodoz@epfl.ch>
34  */
35 
36 #ifndef EVALUATION_INTERPOLATE_VALUE_HPP
37 #define EVALUATION_INTERPOLATE_VALUE_HPP
38 
39 #include <lifev/core/LifeV.hpp>
40 
41 #include <lifev/core/array/VectorEpetra.hpp>
42 #include <lifev/core/array/VectorSmall.hpp>
43 
44 #include <lifev/eta/fem/ETCurrentFE.hpp>
45 #include <lifev/eta/fem/ETCurrentFlag.hpp>
46 #include <lifev/eta/fem/ETFESpace.hpp>
47 #include <lifev/core/fem/QuadratureRule.hpp>
48 
49 #include <lifev/eta/expression/ExpressionInterpolateValue.hpp>
50 
51 #include <boost/shared_ptr.hpp>
52 
53 
54 namespace LifeV
55 {
56 
57 namespace ExpressionAssembly
58 {
59 
60 //! Evaluation for the interpolation of a FE function
61 /*!
62  @author Samuel Quinodoz <samuel.quinodoz@epfl.ch>
63 
64  This class aims at representing an interpolated FE value.
65 
66  This is the generic implementation, so representing a vectorial FE
67 
68  This class is an Evaluation class, and therefore, has all the methods
69  required to work within the Evaluation trees.
70  */
71 template<typename MeshType, typename MapType, UInt SpaceDim, UInt FieldDim>
72 class EvaluationInterpolateValue
73 {
74 public:
75 
76  //! @name Public Types
77  //@{
78 
79  //! Type of the value returned by this class
80  typedef VectorSmall<FieldDim> return_Type;
81 
82  //! Type of the FESpace that has to be used with this class
83  typedef ETFESpace<MeshType, MapType, SpaceDim, FieldDim> fespace_Type;
84 
85  //! Pointer on the FESpace
86  typedef std::shared_ptr<fespace_Type> fespacePtr_Type;
87 
88  //! Vector of the values
89  typedef VectorEpetra vector_Type;
90 
91  //@}
92 
93 
94  //! @name Static constants
95  //@{
96 
97  //! Flag for the global current FE
98  const static flag_Type S_globalUpdateFlag;
99 
100  //! Flag for the test current FE
101  const static flag_Type S_testUpdateFlag;
102 
103  //! Flag for the solution current FE
104  const static flag_Type S_solutionUpdateFlag;
105 
106  //@}
107 
108 
109  //! @name Constructors, destructor
110  //@{
111 
112  //! Copy constructor
113  EvaluationInterpolateValue (const EvaluationInterpolateValue<MeshType, MapType, SpaceDim, FieldDim>& evaluation)
114  :
115  M_fespace ( evaluation.M_fespace),
116  M_vector ( evaluation.M_vector, Repeated),
117  M_quadrature (0),
118  //M_currentFE(M_fespace->refFE(),M_fespace->geoMap()),
119  M_currentFE (evaluation.M_currentFE),
120  M_interpolatedValues (evaluation.M_interpolatedValues)
121  {
122  if (evaluation.M_quadrature != 0)
123  {
124  M_quadrature = new QuadratureRule (* (evaluation.M_quadrature) );
125  //M_currentFE.setQuadratureRule(*(evaluation.M_quadrature));
126  }
127  }
128 
129  //! Expression-based constructor
130  explicit EvaluationInterpolateValue (const ExpressionInterpolateValue<MeshType, MapType, SpaceDim, FieldDim>& expression)
131  :
132  M_fespace ( expression.fespace() ),
133  M_vector ( expression.vector(), Repeated ),
134  M_quadrature (0),
135  M_currentFE (M_fespace->refFE(), M_fespace->geoMap() ),
136  M_interpolatedValues (0)
137  {}
138 
139  //! Destructor
140  ~EvaluationInterpolateValue()
141  {
142  if (M_quadrature != 0)
143  {
144  delete M_quadrature;
145  }
146  }
147 
148  //@}
149 
150 
151  //! @name Methods
152  //@{
153 
154  //! Interal update, computes the interpolated values.
155  void update (const UInt& iElement)
156  {
157  zero();
158 
159  for (UInt i (0); i < M_fespace->refFE().nbDof(); ++i)
160  {
161  for (UInt q (0); q < M_quadrature->nbQuadPt(); ++q)
162  {
163  for (UInt iDim (0); iDim < FieldDim; ++iDim)
164  {
165  UInt globalID (M_fespace->dof().localToGlobalMap (iElement, i)
166  + iDim * M_fespace->dof().numTotalDof() );
167 
168  M_interpolatedValues[q][iDim] +=
169  M_currentFE.phi (i, q)
170  * M_vector[globalID];
171  }
172  }
173  }
174  }
175 
176  //! Erase all the interpolated values stored internally
177  void zero()
178  {
179  for (UInt q (0); q < M_quadrature->nbQuadPt(); ++q)
180  {
181  for (UInt iDim (0); iDim < FieldDim; ++iDim)
182  {
183  M_interpolatedValues[q][iDim] = 0.0;
184  }
185  }
186  }
187 
188  //! Show the values interpolated
189  void showValues() const
190  {
191  std::cout << " Values : " << std::endl;
192 
193  for (UInt i (0); i < M_quadrature->nbQuadPt(); ++i)
194  {
195  std::cout << M_interpolatedValues[i] << std::endl;
196  }
197  }
198 
199  //! Display method
200  static void display (std::ostream& out = std::cout)
201  {
202  out << "interpolated[" << FieldDim << "]";
203  }
204 
205  //@}
206 
207 
208  //! @name Set Methods
209  //@{
210 
211  //! Do nothing setter for the global current FE
212  template< typename CFEType >
213  void setGlobalCFE (const CFEType* /*globalCFE*/)
214  {}
215 
216  //! Do nothing setter for the test current FE
217  template< typename CFEType >
218  void setTestCFE (const CFEType* /*testCFE*/)
219  {}
220 
221  //! Do nothing setter for the solution current FE
222  template< typename CFEType >
223  void setSolutionCFE (const CFEType* /*solutionCFE*/)
224  {}
225 
226  //! Setter for the quadrature rule (deep copy)
227  void setQuadrature (const QuadratureRule& qr)
228  {
229  if (M_quadrature != 0)
230  {
231  delete M_quadrature;
232  }
233  M_quadrature = new QuadratureRule (qr);
234  M_currentFE.setQuadratureRule (qr);
235  M_interpolatedValues.resize (qr.nbQuadPt() );
236  }
237 
238  //@}
239 
240 
241  //! @name Get Methods
242  //@{
243 
244  //! Getter for a value
245  return_Type value_q (const UInt& q) const
246  {
247  return M_interpolatedValues[q];
248  }
249 
250  //! Getter for the value for a vector
251  return_Type value_qi (const UInt& q, const UInt& /*i*/) const
252  {
253  return M_interpolatedValues[q];
254  }
255 
256  //! Getter for the value for a matrix
257  return_Type value_qij (const UInt& q, const UInt& /*i*/, const UInt& /*j*/) const
258  {
259  return M_interpolatedValues[q];
260  }
261 
262  //@}
263 
264 private:
265 
266  //! @name Private Methods
267  //@{
268 
269  //! No empty constructor
270  EvaluationInterpolateValue();
271 
272  //@}
273 
274  fespacePtr_Type M_fespace;
275  vector_Type M_vector;
276 
277  QuadratureRule* M_quadrature;
278  ETCurrentFE<SpaceDim, 1> M_currentFE;
279 
280  std::vector<return_Type> M_interpolatedValues;
281 };
282 
283 
284 //! Evaluation for the interpolation of a FE function
285 /*!
286  @author Samuel Quinodoz <samuel.quinodoz@epfl.ch>
287 
288  This class aims at representing an interpolated FE value.
289 
290  This is the specialized (partially) implementation representing a scalar FE
291 
292  This class is an Evaluation class, and therefore, has all the methods
293  required to work within the Evaluation trees.
294  */
295 template<typename MeshType, typename MapType, UInt SpaceDim>
296 class EvaluationInterpolateValue<MeshType, MapType, SpaceDim, 1>
297 {
298 
299 public:
300 
301  //! @name Public Types
302  //@{
303 
304  //! Type of the value returned by this class
305  typedef Real return_Type;
306 
307  //! Type of the FESpace to be used in this class
308  typedef ETFESpace<MeshType, MapType, SpaceDim, 1> fespace_Type;
309 
310  //! Type of the pointer on the FESpace
311  typedef std::shared_ptr<fespace_Type> fespacePtr_Type;
312 
313  //! Type of the vector to be used
314  typedef VectorEpetra vector_Type;
315 
316  //@}
317 
318 
319  //! @name Static constants
320  //@{
321 
322  //! Flag for the global current FE
323  const static flag_Type S_globalUpdateFlag;
324 
325  //! Flag for the test current FE
326  const static flag_Type S_testUpdateFlag;
327 
328  //! Flag for the solution current FE
329  const static flag_Type S_solutionUpdateFlag;
330 
331  //@}
332 
333 
334  //! @name Constructors, destructor
335  //@{
336 
337  //! Copy constructor
338  EvaluationInterpolateValue (const EvaluationInterpolateValue<MeshType, MapType, SpaceDim, 1>& evaluation)
339  :
340  M_fespace ( evaluation.M_fespace),
341  M_vector ( evaluation.M_vector, Repeated),
342  M_quadrature (0),
343  //M_currentFE(M_fespace->refFE(),M_fespace->geoMap()),
344  M_currentFE (evaluation.M_currentFE),
345  M_interpolatedValues (evaluation.M_interpolatedValues)
346  {
347  if (evaluation.M_quadrature != 0)
348  {
349  M_quadrature = new QuadratureRule (* (evaluation.M_quadrature) );
350  //M_currentFE.setQuadratureRule(*(evaluation.M_quadrature));
351  }
352  }
353 
354  //! Expression-based constructor
355  explicit EvaluationInterpolateValue (const ExpressionInterpolateValue<MeshType, MapType, SpaceDim, 1>& expression)
356  :
357  M_fespace ( expression.fespace() ),
358  M_vector ( expression.vector(), Repeated ),
359  M_quadrature (0),
360  M_currentFE (M_fespace->refFE(), M_fespace->geoMap() ),
361  M_interpolatedValues (0)
362  {}
363 
364  //! Destructor
365  ~EvaluationInterpolateValue()
366  {
367  if (M_quadrature != 0)
368  {
369  delete M_quadrature;
370  }
371  }
372 
373  //@}
374 
375 
376  //! @name Methods
377  //@{
378 
379  //! Internal update: computes the interpolated value
380  void update (const UInt& iElement)
381  {
382  zero();
383 
384  for (UInt i (0); i < M_fespace->refFE().nbDof(); ++i)
385  {
386  for (UInt q (0); q < M_quadrature->nbQuadPt(); ++q)
387  {
388  UInt globalID (M_fespace->dof().localToGlobalMap (iElement, i) );
389 
390  M_interpolatedValues[q] +=
391  M_currentFE.phi (i, q)
392  * M_vector[globalID];
393  }
394  }
395  }
396 
397  //! Erase the interpolated values stored internally
398  void zero()
399  {
400  for (UInt q (0); q < M_quadrature->nbQuadPt(); ++q)
401  {
402  M_interpolatedValues[q] = 0.0;
403  }
404  }
405 
406  //! Show the values
407  void showValues() const
408  {
409  std::cout << " Values : " << std::endl;
410 
411  for (UInt i (0); i < M_quadrature->nbQuadPt(); ++i)
412  {
413  std::cout << M_interpolatedValues[i] << std::endl;
414  }
415  }
416 
417  //! Display method
418  static void display (std::ostream& out = std::cout)
419  {
420  out << "interpolated[1]";
421  }
422 
423  //@}
424 
425 
426  //! @name Set Methods
427  //@{
428 
429  //! Do nothing setter for the global current FE
430  template< typename CFEType >
431  void setGlobalCFE (const CFEType* /*globalCFE*/)
432  {}
433 
434  //! Do nothing setter for the test current FE
435  template< typename CFEType >
436  void setTestCFE (const CFEType* /*testCFE*/)
437  {}
438 
439  //! Do nothing setter for the solution current FE
440  template< typename CFEType >
441  void setSolutionCFE (const CFEType* /*solutionCFE*/)
442  {}
443 
444  //! Setter for the quadrature rule
445  void setQuadrature (const QuadratureRule& qr)
446  {
447  if (M_quadrature != 0)
448  {
449  delete M_quadrature;
450  }
451  M_quadrature = new QuadratureRule (qr);
452  M_currentFE.setQuadratureRule (qr);
453  M_interpolatedValues.resize (qr.nbQuadPt() );
454  }
455 
456  //@}
457 
458 
459  //! @name Get Methods
460  //@{
461 
462  //! Getter for a value
463  return_Type value_q (const UInt& q) const
464  {
465  return M_interpolatedValues[q];
466  }
467 
468  //! Getter for the value for a vector
469  return_Type value_qi (const UInt& q, const UInt& /*i*/) const
470  {
471  return M_interpolatedValues[q];
472  }
473 
474  //! Getter for the value for a matrix
475  return_Type value_qij (const UInt& q, const UInt& /*i*/, const UInt& /*j*/) const
476  {
477  return M_interpolatedValues[q];
478  }
479 
480  //@}
481 
482 private:
483 
484  //! @name Private Methods
485  //@{
486 
487  //! No empty constructor
488  EvaluationInterpolateValue();
489 
490  //@}
491 
492  //! Data storage
493  fespacePtr_Type M_fespace;
494  vector_Type M_vector;
495  QuadratureRule* M_quadrature;
496 
497  //! Structure for the computations
498  ETCurrentFE<SpaceDim, 1> M_currentFE;
499 
500  //! Storage for the temporary values
501  std::vector<return_Type> M_interpolatedValues;
502 };
503 
504 
505 
506 template<typename MeshType, typename MapType, UInt SpaceDim, UInt FieldDim>
507 const flag_Type
508 EvaluationInterpolateValue<MeshType, MapType, SpaceDim, FieldDim>::
509 S_globalUpdateFlag = ET_UPDATE_NONE;
510 
511 template<typename MeshType, typename MapType, UInt SpaceDim, UInt FieldDim>
512 const flag_Type
513 EvaluationInterpolateValue<MeshType, MapType, SpaceDim, FieldDim>::
514 S_testUpdateFlag = ET_UPDATE_NONE;
515 
516 template<typename MeshType, typename MapType, UInt SpaceDim, UInt FieldDim>
517 const flag_Type
518 EvaluationInterpolateValue<MeshType, MapType, SpaceDim, FieldDim>::
519 S_solutionUpdateFlag = ET_UPDATE_NONE;
520 
521 
522 
523 template<typename MeshType, typename MapType, UInt SpaceDim>
524 const flag_Type
525 EvaluationInterpolateValue<MeshType, MapType, SpaceDim, 1>::
526 S_globalUpdateFlag = ET_UPDATE_NONE;
527 
528 template<typename MeshType, typename MapType, UInt SpaceDim>
529 const flag_Type
530 EvaluationInterpolateValue<MeshType, MapType, SpaceDim, 1>::
531 S_testUpdateFlag = ET_UPDATE_NONE;
532 
533 template<typename MeshType, typename MapType, UInt SpaceDim>
534 const flag_Type
535 EvaluationInterpolateValue<MeshType, MapType, SpaceDim, 1>::
536 S_solutionUpdateFlag = ET_UPDATE_NONE;
537 
538 } // Namespace ExpressionAssembly
539 
540 } // Namespace LifeV
541 #endif
VectorEpetra - The Epetra Vector format Wrapper.
uint32_type flag_Type
bit-flag with up to 32 different flags
Definition: LifeV.hpp:197
QuadratureRule(const QuadratureRule &qr)
Copy constructor.
void updateInverseJacobian(const UInt &iQuadPt)
double Real
Generic real data.
Definition: LifeV.hpp:175
QuadratureRule - The basis class for storing and accessing quadrature rules.
const UInt & nbQuadPt() const
Getter for the number of quadrature points.
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191