LifeV
EvaluationFunctor.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 EvaluationFunctor class.
31 
32  @date 06/2011
33  @author Samuel Quinodoz <samuel.quinodoz@epfl.ch>
34  */
35 
36 #ifndef EVALUTATION_FUNCTOR_HPP
37 #define EVALUTATION_FUNCTOR_HPP
38 
39 
40 #include <lifev/core/LifeV.hpp>
41 
42 #include <lifev/eta/expression/ExpressionFunctor.hpp>
43 
44 #include <lifev/core/fem/QuadratureRule.hpp>
45 
46 
47 namespace LifeV
48 {
49 
50 namespace ExpressionAssembly
51 {
52 
53 //! Evaluation for a generic functor with 1 argument
54 /*!
55  @author Samuel Quinodoz <samuel.quinodoz@epfl.ch>
56 
57  This class aims at representing a functor with 1 arguement during the assembly
58 
59  This class is an Evaluation class, and therefore, has all the methods
60  required to work within the Evaluation trees.
61 
62  <b> Template requirement </b>
63 
64  There are two template arguments for this class: The functor and the ArgumentEvaluationType.
65 
66  <i> FunctorType </i> The functor has to be copiable, must implement the operator() const, has
67  a type named ReturnType, the operator() must return a ReturnType.
68 
69  <i> Argument Evaluation </i> It has to be an Evaluation class.
70  */
71 template <typename FunctorType, typename ArgumentEvaluationType>
72 class EvaluationFunctor1
73 {
74 public:
75 
76  //! @name Public Types
77  //@{
78 
79  //! Type of the values returned by this class
80  typedef typename FunctorType::return_Type return_Type;
81 
82  //@}
83 
84 
85  //! @name Static constants
86  //@{
87 
88  //! Flag for the global current FE
89  const static flag_Type S_globalUpdateFlag;
90 
91  //! Flag for the test current FE
92  const static flag_Type S_testUpdateFlag;
93 
94  //! Flag for the solution current FE
95  const static flag_Type S_solutionUpdateFlag;
96 
97  //@}
98 
99 
100  //! @name Constructors, destructor
101  //@{
102 
103  //! Copy constructor
104  EvaluationFunctor1 (const EvaluationFunctor1<FunctorType, ArgumentEvaluationType>& eval)
105  : M_functor (eval.M_functor),
106  M_evaluation (eval.M_evaluation)
107  {}
108 
109  //! Constructor from the corresponding expression
110  template<typename Argument>
111  explicit EvaluationFunctor1 (const ExpressionFunctor1<FunctorType, Argument>& expression)
112  : M_functor (expression.functor() ),
113  M_evaluation (expression.argument() )
114  {}
115 
116  //! Destructor
117  ~EvaluationFunctor1()
118  {}
119 
120  //@}
121 
122 
123  //! @name Methods
124  //@{
125 
126  //! Internal update
127  void update (const UInt& iElement)
128  {
129  M_evaluation.update (iElement);
130  }
131 
132  //! Display method
133  static void display (std::ostream& out = std::cout)
134  {
135  out << "f( ";
136  ArgumentEvaluationType::display (out);
137  out << " )";
138  }
139 
140  //@}
141 
142 
143  //! @name Set Methods
144  //@{
145 
146  //! Setter for the global current FE
147  template< typename CFEType >
148  void setGlobalCFE (const CFEType* globalCFE)
149  {
150  M_evaluation.setGlobalCFE (globalCFE);
151  }
152 
153  //! Setter for the test current FE
154  template< typename CFEType >
155  void setTestCFE (const CFEType* testCFE)
156  {
157  M_evaluation.setTestCFE (testCFE);
158  }
159 
160  //! Setter for the solution current FE
161  template< typename CFEType >
162  void setSolutionCFE (const CFEType* solutionCFE)
163  {
164  M_evaluation.setSolutionCFE (solutionCFE);
165  }
166 
167  //! Setter for the quadrature rule
168  void setQuadrature (const QuadratureRule& qr)
169  {
170  M_evaluation.setQuadrature (qr);
171  }
172 
173  //@}
174 
175 
176  //! @name Get Methods
177  //@{
178 
179  //! Getter for a value
180  return_Type value_q (const UInt& q) const
181  {
182  return (*M_functor) (M_evaluation.value_q (q) );
183  }
184 
185  //! Getter for the value for a vector
186  return_Type value_qi (const UInt& q, const UInt& i) const
187  {
188  return (*M_functor) (M_evaluation.value_qi (q, i) );
189  }
190 
191  //! Getter for the value for a matrix
192  return_Type value_qij (const UInt& q, const UInt& i, const UInt& j) const
193  {
194  return (*M_functor) (M_evaluation.value_qij (q, i, j) );
195  }
196 
197  //@}
198 
199 private:
200 
201  //! @name Private Methods
202  //@{
203 
204  //! No empty constructor
205  EvaluationFunctor1();
206 
207  //@}
208 
209  // Internal storage
210  std::shared_ptr<FunctorType> M_functor;
211  ArgumentEvaluationType M_evaluation;
212 };
213 
214 
215 template<typename FunctorType, typename ArgumentEvaluationType>
216 const flag_Type EvaluationFunctor1<FunctorType, ArgumentEvaluationType>::S_globalUpdateFlag
217  = ArgumentEvaluationType::S_globalUpdateFlag;
218 
219 template<typename FunctorType, typename ArgumentEvaluationType>
220 const flag_Type EvaluationFunctor1<FunctorType, ArgumentEvaluationType>::S_testUpdateFlag
221  = ArgumentEvaluationType::S_testUpdateFlag;
222 
223 template<typename FunctorType, typename ArgumentEvaluationType>
224 const flag_Type EvaluationFunctor1<FunctorType, ArgumentEvaluationType>::S_solutionUpdateFlag
225  = ArgumentEvaluationType::S_solutionUpdateFlag;
226 
227 
228 
229 //! Evaluation for a generic functor with 2 arguments
230 /*!
231  @author Samuel Quinodoz <samuel.quinodoz@epfl.ch>
232 
233  This class aims at representing a functor with 2 arguements during the assembly
234 
235  This class is an Evaluation class, and therefore, has all the methods
236  required to work within the Evaluation trees.
237 
238  <b> Template requirement </b>
239 
240  There are two template arguments for this class: The functor and the ArgumentEvaluationType.
241 
242  <i> FunctorType </i> The functor has to be copiable, must implement the operator() const, has
243  a type named return_Type, the operator() must return a return_Type.
244 
245  <i> Argument1EvaluationType </i> It has to be an Evaluation class.
246 
247  <i> Argument2EvaluationType </i> It has to be an Evaluation class.
248 
249  */
250 template <typename FunctorType, typename Argument1EvaluationType, typename Argument2EvaluationType>
251 class EvaluationFunctor2
252 {
253 public:
254 
255  //! @name Public Types
256  //@{
257 
258  //! Type returned by this class
259  typedef typename FunctorType::return_Type return_Type;
260 
261  //@}
262 
263 
264  //! @name Static constants
265  //@{
266 
267  //! Flag for the global current FE
268  const static flag_Type S_globalUpdateFlag;
269 
270  //! Flag for the test current FE
271  const static flag_Type S_testUpdateFlag;
272 
273  //! Flag for the solution current FE
274  const static flag_Type S_solutionUpdateFlag;
275 
276  //@}
277 
278 
279  //! @name Constructors, destructor
280  //@{
281 
282  //! Copy constructor
283  EvaluationFunctor2 (const EvaluationFunctor2<FunctorType, Argument1EvaluationType, Argument2EvaluationType>& eval)
284  : M_functor (eval.M_functor),
285  M_evaluation1 (eval.M_evaluation1),
286  M_evaluation2 (eval.M_evaluation2)
287  {}
288 
289  //! Constructor from the corresponding expression
290  template<typename Argument1, typename Argument2>
291  explicit EvaluationFunctor2 (const ExpressionFunctor2<FunctorType, Argument1, Argument2>& expression)
292  : M_functor (expression.functor() ),
293  M_evaluation1 (expression.argument1() ),
294  M_evaluation2 (expression.argument2() ) {}
295 
296  //! Destructor
297  ~EvaluationFunctor2()
298  {}
299 
300  //@}
301 
302 
303  //! @name Methods
304  //@{
305 
306  //! Internal update
307  void update (const UInt& iElement)
308  {
309  M_evaluation1.update (iElement);
310  M_evaluation2.update (iElement);
311  }
312 
313  //! Display method
314  static void display (std::ostream& out = std::cout)
315  {
316  out << "f( ";
317  Argument1EvaluationType::display (out);
318  out << " , ";
319  Argument2EvaluationType::display (out);
320  out << " )";
321  }
322 
323  //@}
324 
325 
326  //! @name Set Methods
327  //@{
328 
329  //! Setter for the global current FE
330  template< typename CFEType >
331  void setGlobalCFE (const CFEType* globalCFE)
332  {
333  M_evaluation1.setGlobalCFE (globalCFE);
334  M_evaluation2.setGlobalCFE (globalCFE);
335  }
336 
337  //! Setter for the test current FE
338  template< typename CFEType >
339  void setTestCFE (const CFEType* testCFE)
340  {
341  M_evaluation1.setTestCFE (testCFE);
342  M_evaluation2.setTestCFE (testCFE);
343  }
344 
345  //! Setter for the solution current FE
346  template< typename CFEType >
347  void setSolutionCFE (const CFEType* solutionCFE)
348  {
349  M_evaluation1.setSolutionCFE (solutionCFE);
350  M_evaluation2.setSolutionCFE (solutionCFE);
351  }
352 
353  //! Setter for the quadrature rule
354  void setQuadrature (const QuadratureRule& qr)
355  {
356  M_evaluation1.setQuadrature (qr);
357  M_evaluation2.setQuadrature (qr);
358  }
359 
360  //@}
361 
362 
363  //! @name Get Methods
364  //@{
365 
366  //! Getter for a value
367  return_Type value_q (const UInt& q) const
368  {
369  return (*M_functor) (M_evaluation1.value_q (q), M_evaluation2.value_q (q) );
370  }
371 
372  //! Getter for the value for a vector
373  return_Type value_qi (const UInt& q, const UInt& i) const
374  {
375  return (*M_functor) (M_evaluation1.value_qi (q, i), M_evaluation2.value_qi (q, i) );
376  }
377 
378  //! Getter for the value for a matrix
379  return_Type value_qij (const UInt& q, const UInt& i, const UInt& j) const
380  {
381  return (*M_functor) (M_evaluation1.value_qij (q, i, j), M_evaluation2.value_qij (q, i, j) );
382  }
383 
384  //@}
385 
386 private:
387 
388 
389  //! @name Private Methods
390  //@{
391 
392  //! No empty constructor
393  EvaluationFunctor2();
394 
395  //@}
396 
397  // Internal storage
398  std::shared_ptr<FunctorType> M_functor;
399  Argument1EvaluationType M_evaluation1;
400  Argument2EvaluationType M_evaluation2;
401 };
402 
403 
404 template<typename FunctorType, typename Argument1EvaluationType, typename Argument2EvaluationType>
405 const flag_Type EvaluationFunctor2<FunctorType, Argument1EvaluationType, Argument2EvaluationType>::S_globalUpdateFlag
406  = Argument1EvaluationType::S_globalUpdateFlag | Argument2EvaluationType::S_globalUpdateFlag;
407 
408 template<typename FunctorType, typename Argument1EvaluationType, typename Argument2EvaluationType>
409 const flag_Type EvaluationFunctor2<FunctorType, Argument1EvaluationType, Argument2EvaluationType>::S_testUpdateFlag
410  = Argument1EvaluationType::S_testUpdateFlag | Argument2EvaluationType::S_testUpdateFlag;
411 
412 template<typename FunctorType, typename Argument1EvaluationType, typename Argument2EvaluationType>
413 const flag_Type EvaluationFunctor2<FunctorType, Argument1EvaluationType, Argument2EvaluationType>::S_solutionUpdateFlag
414  = Argument1EvaluationType::S_solutionUpdateFlag | Argument2EvaluationType::S_solutionUpdateFlag;
415 
416 } // Namespace ExpressionAssembly
417 
418 } // Namespace LifeV
419 #endif
uint32_type flag_Type
bit-flag with up to 32 different flags
Definition: LifeV.hpp:197
void updateInverseJacobian(const UInt &iQuadPt)
QuadratureRule - The basis class for storing and accessing quadrature rules.
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191