LifeV
BCInterfaceFunctionParser.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 LifeV.
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 License
21  along with LifeV. If not, see <http://www.gnu.org/licenses/>.
22 
23 *******************************************************************************
24 */
25 //@HEADER
26 
27 /*!
28  * @file
29  * @brief File containing the BCInterfaceFunctionParser class
30  *
31  * @date 06-04-2009
32  * @author Cristiano Malossi <cristiano.malossi@epfl.ch>
33  *
34  * @maintainer Cristiano Malossi <cristiano.malossi@epfl.ch>
35  */
36 
37 #ifndef BCInterfaceFunctionParser_H
38 #define BCInterfaceFunctionParser_H 1
39 
40 // Includes parser classes
41 #include <lifev/core/util/Parser.hpp>
42 
43 // Includes BCInterface classes
44 #include <lifev/bc_interface/core/function/BCInterfaceFunction.hpp>
45 
46 namespace LifeV
47 {
48 
49 //! BCInterfaceFunctionParser - LifeV boundary condition function wrapper for \c BCInterface
50 /*!
51  * @author Cristiano Malossi
52  *
53  * This class is an interface between the \c BCInterface and the \c Parser. It allows to construct LifeV
54  * function types for boundary conditions, using a function string loaded from a \c GetPot file.
55  *
56  * <b>DETAILS</b> <BR>
57  * By default the string separator is set to semicolon ";".
58  *
59  * The function string has to be in this form:
60  *
61  * <CODE>
62  * function = '[u, v, w]'
63  * </CODE>
64  *
65  * where \f$ u=u(x,y,z,t) \f$, \f$ v=v(x,y,z,t) \f$, and \f$ w=w(x,y,z,t) \f$. They are separated by commas,
66  * as shown in the following example
67  *
68  * <CODE>
69  * function = '[x^2 + y^2, 0, 2*sin(2*pi*t)]'
70  * </CODE>
71  *
72  * It is possible to define constants separated by the string separator before the expression
73  *
74  * <CODE>
75  * function = 'a=5.67436; [x^2+y^2,0,a*sin(2*pi*t)^a]'
76  * </CODE>
77  *
78  * <b>NOTE</b> <BR>
79  * In the boundary condition file, if you have three component with the same expression
80  * (the same function) you can both write:
81  *
82  * <CODE>
83  * function = '[0, 0, 0]'
84  * </CODE>
85  *
86  * or
87  *
88  * <CODE>
89  * function = 0
90  * </CODE>
91  *
92  * However the second way is more efficient during execution.
93  */
94 template< typename BcHandlerType, typename PhysicalSolverType >
95 class BCInterfaceFunctionParser: public virtual BCInterfaceFunction< BcHandlerType, PhysicalSolverType >
96 {
97 public:
98 
99  //! @name Type definitions
100  //@{
101 
102  typedef BcHandlerType bcHandler_Type;
103  typedef PhysicalSolverType physicalSolver_Type;
104 
111 
112  typedef typename function_Type::data_Type data_Type;
114 
116 
117  //@}
118 
119 
120  //! @name Constructors & Destructor
121  //@{
122 
123  //! Empty Constructor
124  explicit BCInterfaceFunctionParser();
125 
126  //! Destructor
128 
129  //@}
130 
131 
132  //! @name Methods
133  //@{
134 
135  //! Assign the function to the base of the \c BCHandler
136  /*!
137  * @param base base of the boundary condition
138  */
139  void assignFunction ( bcBase_Type& base );
140 
141  //! Function of time
142  /*!
143  * @param t time
144  * @return boundary condition value
145  */
146  Real functionTime ( const Real& t );
147 
148  //! Function of time and time step
149  /*!
150  * @param t time
151  * @param timeStep time step
152  * @return boundary condition value
153  */
154  Real functionTimeTimeStep ( const Real& t, const Real& timeStep );
155 
156  //! Function of time and space
157  /*!
158  * @param t time
159  * @param x x coordinate
160  * @param y y coordinate
161  * @param z z coordinate
162  * @param id id of the boundary condition (not used)
163  * @return boundary condition value
164  */
165  Real functionTimeSpace ( const Real& t, const Real& x, const Real& y, const Real& z, const ID& /*id*/);
166 
167  //! Function of time and space with ID
168  /*!
169  * @param t time
170  * @param x x coordinate
171  * @param y y coordinate
172  * @param z z coordinate
173  * @param id id of the boundary condition
174  * @return boundary condition value
175  */
176  Real functionTimeSpaceID ( const Real& t, const Real& x, const Real& y, const Real& z, const ID& id );
177 
178  //@}
179 
180 
181  //! @name Set Methods
182  //@{
183 
184  //! Set data for boundary conditions
185  /*!
186  * @param data boundary condition data loaded from \c GetPot file
187  */
188  virtual void setData ( const dataPtr_Type& data );
189 
190  //@}
191 
192 protected:
193 
194  //! @name Protected Methods
195  //@{
196 
197  //! dataInterpolation
198  virtual void dataInterpolation() {}
199 
200  //@}
201 
203 
204 private:
205 
206  //! @name Unimplemented Methods
207  //@{
208 
210 
212 
213  //@}
214 
215  //! @name Private Methods
216  //@{
217 
218  //! Setup the parser using the data container
219  /*!
220  * @param data boundary condition data loaded from \c GetPot file
221  */
222  void setupParser ( const dataPtr_Type& data );
223 
224  //! Get the selected function of time
225  /*!
226  * @return boundary function
227  */
229 
230  //! Get the selected function of time and time step
231  /*!
232  * @return boundary function
233  */
235 
236  //! Get the selected function of time space and ID.
237  /*!
238  * @return boundary function
239  */
241 
242  //@}
243 
245 
246 };
247 
248 // ===================================================
249 // Factory
250 // ===================================================
251 //! Factory create function
252 template< typename BcHandlerType, typename PhysicalSolverType >
253 inline BCInterfaceFunctionParser< BcHandlerType, PhysicalSolverType >* createBCInterfaceFunctionParser()
254 {
255  return new BCInterfaceFunctionParser< BcHandlerType, PhysicalSolverType > ();
256 }
257 
258 // ===================================================
259 // Constructor
260 // ===================================================
261 template< typename BcHandlerType, typename PhysicalSolverType >
262 BCInterfaceFunctionParser< BcHandlerType, PhysicalSolverType >::BCInterfaceFunctionParser() :
263  function_Type (),
264  M_parser (),
265  M_mapID ()
266 {
267 
268 #ifdef HAVE_LIFEV_DEBUG
269  debugStream ( 5021 ) << "BCInterfaceFunction::BCInterfaceFunction()" << "\n";
270 #endif
271 
272 }
273 
274 // ===================================================
275 // Methods
276 // ===================================================
277 template< typename BcHandlerType, typename PhysicalSolverType >
278 Real
279 BCInterfaceFunctionParser< BcHandlerType, PhysicalSolverType >::functionTime ( const Real& t )
280 {
281 
282 #ifdef HAVE_LIFEV_DEBUG
283  debugStream ( 5021 ) << "BCInterfaceFunction::functionTime: " << "\n";
284  debugStream ( 5021 ) << " t: " << t << "\n";
285 #endif
286 
287  M_parser->setVariable ( "t", t );
288 
289  this->dataInterpolation();
290 
291 #ifdef HAVE_LIFEV_DEBUG
292  debugStream ( 5021 ) << " evaluate( 0 ) : " << M_parser->evaluate ( 0 ) << "\n";
293 #endif
294 
295  return M_parser->evaluate ( 0 );
296 }
297 
298 template< typename BcHandlerType, typename PhysicalSolverType >
299 Real
300 BCInterfaceFunctionParser< BcHandlerType, PhysicalSolverType >::functionTimeTimeStep ( const Real& t, const Real& timeStep )
301 {
302 
303 #ifdef HAVE_LIFEV_DEBUG
304  debugStream ( 5021 ) << "BCInterfaceFunction::functionTime: " << "\n";
305  debugStream ( 5021 ) << " t: " << t << "\n";
306  debugStream ( 5021 ) << " timeStep: " << timeStep << "\n";
307 #endif
308 
309  M_parser->setVariable ( "t", t );
310  M_parser->setVariable ( "timeStep", timeStep );
311 
312  this->dataInterpolation();
313 
314 #ifdef HAVE_LIFEV_DEBUG
315  debugStream ( 5021 ) << " evaluate( 0 ) : " << M_parser->evaluate ( 0 ) << "\n";
316 #endif
317 
318  return M_parser->evaluate ( 0 );
319 }
320 
321 template< typename BcHandlerType, typename PhysicalSolverType >
322 Real
323 BCInterfaceFunctionParser< BcHandlerType, PhysicalSolverType >::functionTimeSpace ( const Real& t, const Real& x, const Real& y, const Real& z, const ID& /*id*/)
324 {
325 
326 #ifdef HAVE_LIFEV_DEBUG
327  debugStream ( 5021 ) << "BCInterfaceFunction::functionTimeSpace: " << "\n";
328  debugStream ( 5021 ) << " x: " << x << "\n";
329  debugStream ( 5021 ) << " y: " << y << "\n";
330  debugStream ( 5021 ) << " z: " << z << "\n";
331  debugStream ( 5021 ) << " t: " << t << "\n";
332 #endif
333 
334  M_parser->setVariable ( "t", t );
335  M_parser->setVariable ( "x", x );
336  M_parser->setVariable ( "y", y );
337  M_parser->setVariable ( "z", z );
338 
339  this->dataInterpolation();
340 
341 #ifdef HAVE_LIFEV_DEBUG
342  debugStream ( 5021 ) << " evaluate( 0 ) : " << M_parser->evaluate ( 0 ) << "\n";
343 #endif
344 
345  return M_parser->evaluate ( 0 );
346 }
347 
348 template< typename BcHandlerType, typename PhysicalSolverType >
349 Real
350 BCInterfaceFunctionParser< BcHandlerType, PhysicalSolverType >::functionTimeSpaceID ( const Real& t, const Real& x, const Real& y, const Real& z, const ID& id )
351 {
352 
353 #ifdef HAVE_LIFEV_DEBUG
354  debugStream ( 5021 ) << "BCInterfaceFunction::functionTimeSpaceID: " << "\n";
355  debugStream ( 5021 ) << " x: " << x << "\n";
356  debugStream ( 5021 ) << " y: " << y << "\n";
357  debugStream ( 5021 ) << " z: " << z << "\n";
358  debugStream ( 5021 ) << " t: " << t << "\n";
359  debugStream ( 5021 ) << " id: " << id << "\n";
360 #endif
361 
362  M_parser->setVariable ( "t", t );
363  M_parser->setVariable ( "x", x );
364  M_parser->setVariable ( "y", y );
365  M_parser->setVariable ( "z", z );
366 
367  this->dataInterpolation();
368 
369 #ifdef HAVE_LIFEV_DEBUG
370  debugStream ( 5021 ) << " evaluate(" << M_mapID[id] << ") : " << M_parser->evaluate ( M_mapID[id] ) << "\n";
371 #endif
372 
373  return M_parser->evaluate ( M_mapID[id] );
374 }
375 
376 // ===================================================
377 // Private Methods
378 // ===================================================
379 template< typename BcHandlerType, typename PhysicalSolverType >
380 void
381 BCInterfaceFunctionParser< BcHandlerType, PhysicalSolverType >::setupParser ( const dataPtr_Type& data )
382 {
383 
384 #ifdef HAVE_LIFEV_DEBUG
385  debugStream ( 5022 ) << "BCInterfaceFunction::setParser" << "\n";
386 #endif
387 
388  if ( M_parser )
389  {
390  M_parser->setString ( data->baseString() );
391  }
392  else
393  {
394  M_parser.reset ( new parser_Type ( data->baseString() ) );
395  }
396 }
397 
398 template< typename BcHandlerType, typename PhysicalSolverType >
399 typename BCInterfaceFunctionParser< BcHandlerType, PhysicalSolverType >::boundaryFunctionTime_Type
400 BCInterfaceFunctionParser< BcHandlerType, PhysicalSolverType >::functionSelectorTime()
401 {
402  return std::bind ( &BCInterfaceFunctionParser< BcHandlerType, PhysicalSolverType >::functionTime, this, std::placeholders::_1 );
403 }
404 
405 template< typename BcHandlerType, typename PhysicalSolverType >
406 typename BCInterfaceFunctionParser< BcHandlerType, PhysicalSolverType >::boundaryFunctionTimeTimeStep_Type
407 BCInterfaceFunctionParser< BcHandlerType, PhysicalSolverType >::functionSelectorTimeTimeStep()
408 {
409  return std::bind ( &BCInterfaceFunctionParser< BcHandlerType, PhysicalSolverType >::functionTimeTimeStep, this, std::placeholders::_1, std::placeholders::_2 );
410 }
411 
412 template< typename BcHandlerType, typename PhysicalSolverType >
413 typename BCInterfaceFunctionParser< BcHandlerType, PhysicalSolverType >::boundaryFunctionTimeSpaceID_Type
414 BCInterfaceFunctionParser< BcHandlerType, PhysicalSolverType >::functionSelectorTimeSpaceID()
415 {
416  if ( M_parser->countSubstring ( "," ) )
417  {
418  return std::bind ( &BCInterfaceFunctionParser< BcHandlerType, PhysicalSolverType >::functionTimeSpaceID, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5 );
419  }
420  else
421  {
422  return std::bind ( &BCInterfaceFunctionParser< BcHandlerType, PhysicalSolverType >::functionTimeSpace, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5 );
423  }
424 }
425 
426 } // Namespace LifeV
427 
428 #endif /* BCInterfaceFunctionParser_H */
Real functionTimeSpace(const Real &t, const Real &x, const Real &y, const Real &z, const ID &)
Function of time and space.
virtual void setData(const dataPtr_Type &data)
Set data for boundary conditions.
Real functionTime(const Real &t)
Function of time.
function_Type::boundaryFunctionTimeTimeStep_Type boundaryFunctionTimeTimeStep_Type
void setupParser(const dataPtr_Type &data)
Setup the parser using the data container.
void updateInverseJacobian(const UInt &iQuadPt)
BCInterfaceFunctionParser< BcHandlerType, PhysicalSolverType > * createBCInterfaceFunctionParser()
Factory create function.
std::shared_ptr< parser_Type > parserPtr_Type
Parser - A string parser for algebraic expressions.
Definition: Parser.hpp:77
Real functionTimeSpaceID(const Real &t, const Real &x, const Real &y, const Real &z, const ID &id)
Function of time and space with ID.
uint32_type ID
IDs.
Definition: LifeV.hpp:194
boundaryFunctionTimeSpaceID_Type functionSelectorTimeSpaceID()
Get the selected function of time space and ID.
boundaryFunctionTimeTimeStep_Type functionSelectorTimeTimeStep()
Get the selected function of time and time step.
BCInterfaceFunctionParser - LifeV boundary condition function wrapper for BCInterface.
virtual void dataInterpolation()
dataInterpolation
boundaryFunctionTime_Type functionSelectorTime()
Get the selected function of time.
BCInterfaceFunction< bcHandler_Type, physicalSolver_Type > function_Type
double Real
Generic real data.
Definition: LifeV.hpp:175
BCInterfaceFunctionParser(const BCInterfaceFunctionParser &function)
BCInterfaceFunctionParser & operator=(const BCInterfaceFunctionParser &function)
Real functionTimeTimeStep(const Real &t, const Real &timeStep)
Function of time and time step.
function_Type::boundaryFunctionTime_Type boundaryFunctionTime_Type
BCInterfaceFunction - Base class for BCInterface boundary functions.
void assignFunction(bcBase_Type &base)
Assign the function to the base of the BCHandler.
function_Type::boundaryFunctionTimeSpaceID_Type boundaryFunctionTimeSpaceID_Type