LifeV
BCInterfaceFunctionUserDefined.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 BCInterfaceFunctionUserDefined class
30  *
31  * @date 25-08-2011
32  * @author Cristiano Malossi <cristiano.malossi@epfl.ch>
33  *
34  * @maintainer Cristiano Malossi <cristiano.malossi@epfl.ch>
35  */
36 
37 #ifndef BCInterfaceFunctionUserDefined_H
38 #define BCInterfaceFunctionUserDefined_H 1
39 
40 // Includes BCInterface classes
41 #include <lifev/bc_interface/core/function/BCInterfaceFunction.hpp>
42 
43 namespace LifeV
44 {
45 
46 //! BCInterfaceFunctionUserDefined - User defined functions for BCInterface
47 /*!
48  * @author Cristiano Malossi
49  *
50  *
51  * The BCInterfaceFunctionUserDefined class provides a set of user defined functions
52  * to be used by the \c BCInterface
53  *
54  * <b>DETAILS:</b> <BR>
55  * The constructor of the class takes a string contains the ID of the boundary condition to impose.
56  * The list of available conditions is given through the \c userDefinedFunctions enum. These are:
57  *
58  * <ol>
59  * <li> Sin
60  * </ol>
61  */
62 template< typename BcHandlerType, typename PhysicalSolverType >
63 class BCInterfaceFunctionUserDefined: public virtual BCInterfaceFunction< BcHandlerType, PhysicalSolverType >
64 {
65 public:
66 
67  //! @name Type definitions
68  //@{
69 
70  typedef BcHandlerType bcHandler_Type;
71  typedef PhysicalSolverType physicalSolver_Type;
72 
77  typedef BCInterfaceData::parametersContainer_Type parametersContainer_Type;
78 
80 
81  typedef typename function_Type::data_Type data_Type;
83 
84  //@}
85 
86 
87  //! @name Constructors & Destructor
88  //@{
89 
91 
93 
94  //@}
95 
96 
97  //! @name Methods
98  //@{
99 
100  //! Assign the function to the base of the \c BCHandler
101  /*!
102  * @param base base of the boundary condition
103  */
104  void assignFunction ( bcBase_Type& base );
105 
106  //! Function of time
107  /*!
108  * @param t time
109  * @param timeStep time step
110  * @return boundary condition value
111  */
112  Real functionTime ( const Real& t )
113  {
114  return functionSelectorTime() ( t );
115  };
116 
117  //! Function of time and time step
118  /*!
119  * @param t time
120  * @param timeStep time step
121  * @return boundary condition value
122  */
123  Real functionTimeTimeStep ( const Real& t, const Real& timeStep )
124  {
125  return functionSelectorTimeTimeStep() ( t, timeStep );
126  };
127 
128  //! Function of time and space
129  /*!
130  * @param t time
131  * @param x x coordinate
132  * @param y y coordinate
133  * @param z z coordinate
134  * @param id id of the boundary condition (not used)
135  * @return boundary condition value
136  */
137  Real functionTimeSpace ( const Real& t, const Real& x, const Real& y, const Real& z, const ID& /*id*/)
138  {
139  return functionSelectorTimeSpaceID() ( t, x, y, z, 0 );
140  };
141 
142  //! Function of time and space with ID
143  /*!
144  * @param t time
145  * @param x x coordinate
146  * @param y y coordinate
147  * @param z z coordinate
148  * @param id id of the boundary condition
149  * @return boundary condition value
150  */
151  Real functionTimeSpaceID ( const Real& t, const Real& x, const Real& y, const Real& z, const ID& id )
152  {
153  return functionSelectorTimeSpaceID() ( t, x, y, z, id );
154  };
155 
156 
157  //@}
158 
159 
160  //! @name Set Methods
161  //@{
162 
163  //! Set data for boundary conditions
164  /*!
165  * @param data boundary condition data loaded from \c GetPot file
166  */
167  void setData ( const dataPtr_Type& data );
168 
169  //@}
170 
171 private:
172 
173  //! @name Unimplemented Methods
174  //@{
175 
177 
179 
180  //@}
181 
182 
183  //! @name Private Methods
184  //@{
185 
186  //! Get the selected function of time
187  /*!
188  * @return boundary function
189  */
191 
192  //! Get the selected function of time and time step
193  /*!
194  * @return boundary function
195  */
197 
198  //! Get the selected function of time and space with ID
199  /*!
200  * @return boundary function
201  */
203 
204  //! Sinusoidal function
205  /*!
206  * @param t time
207  * @param x x coordinate
208  * @param y y coordinate
209  * @param z z coordinate
210  * @param id id of the boundary condition (not used)
211  * @return boundary condition value
212  */
213  Real functionSin ( const Real& t, const Real& /*x*/, const Real& /*y*/, const Real& /*z*/, const ID& /*id*/ );
214 
215  //@}
216 
218  {
220  };
221 
223 
224  parametersContainer_Type M_parameters;
225 
226 };
227 
228 // ===================================================
229 // Factory
230 // ===================================================
231 //! Factory create function
232 template< typename BcHandlerType, typename PhysicalSolverType >
233 inline BCInterfaceFunctionUserDefined< BcHandlerType, PhysicalSolverType >* createBCInterfaceFunctionUserDefined()
234 {
235  return new BCInterfaceFunctionUserDefined< BcHandlerType, PhysicalSolverType > ();
236 }
237 
238 // ===================================================
239 // Constructor
240 // ===================================================
241 template< typename BcHandlerType, typename PhysicalSolverType >
242 BCInterfaceFunctionUserDefined< BcHandlerType, PhysicalSolverType >::BCInterfaceFunctionUserDefined() :
243  function_Type (),
244  M_functionType (),
245  M_parameters ()
246 {
247 
248 #ifdef HAVE_LIFEV_DEBUG
249  debugStream ( 5026 ) << "BCInterfaceFunctionUserDefined::BCInterfaceFunctionUserDefined()" << "\n";
250 #endif
251 
252 }
253 
254 // ===================================================
255 // Private methods
256 // ===================================================
257 template< typename BcHandlerType, typename PhysicalSolverType >
258 void
259 BCInterfaceFunctionUserDefined< BcHandlerType, PhysicalSolverType >::setData ( const dataPtr_Type& data )
260 {
261  //Set mapFunction
262  std::map< std::string, userDefinedFunctions > mapFunction;
263  mapFunction["Sin"] = Sin;
264 
265  // Retrieving the strings
266  M_functionType = mapFunction[ data->baseString() ];
267 
268  // Set parameters
269  M_parameters = data->parameters();
270 }
271 
272 template< typename BcHandlerType, typename PhysicalSolverType >
273 typename BCInterfaceFunctionUserDefined< BcHandlerType, PhysicalSolverType >::boundaryFunctionTime_Type
274 BCInterfaceFunctionUserDefined< BcHandlerType, PhysicalSolverType >::functionSelectorTime()
275 {
276  switch ( M_functionType )
277  {
278  case Sin:
279 
280  return std::bind ( &BCInterfaceFunctionUserDefined< BcHandlerType, PhysicalSolverType >::functionSin, this, std::placeholders::_1, std::placeholders::_1, std::placeholders::_1, std::placeholders::_1, std::placeholders::_1 );
281 
282  default:
283 
284  std::cout << " !!! Warning: user defined function " << M_functionType << " not assigned !!!" << std::endl;
285 
286  return 0;
287  }
288 }
289 
290 template< typename BcHandlerType, typename PhysicalSolverType >
291 typename BCInterfaceFunctionUserDefined< BcHandlerType, PhysicalSolverType >::boundaryFunctionTimeTimeStep_Type
292 BCInterfaceFunctionUserDefined< BcHandlerType, PhysicalSolverType >::functionSelectorTimeTimeStep()
293 {
294  switch ( M_functionType )
295  {
296  case Sin:
297 
298  return std::bind ( &BCInterfaceFunctionUserDefined< BcHandlerType, PhysicalSolverType >::functionSin, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_1, std::placeholders::_1, std::placeholders::_1 );
299 
300  default:
301 
302  std::cout << " !!! Warning: user defined function " << M_functionType << " not assigned !!!" << std::endl;
303 
304  return 0;
305  }
306 }
307 
308 template< typename BcHandlerType, typename PhysicalSolverType >
309 typename BCInterfaceFunctionUserDefined< BcHandlerType, PhysicalSolverType >::boundaryFunctionTimeSpaceID_Type
310 BCInterfaceFunctionUserDefined< BcHandlerType, PhysicalSolverType >::functionSelectorTimeSpaceID()
311 {
312  switch ( M_functionType )
313  {
314  case Sin:
315 
316  return std::bind ( &BCInterfaceFunctionUserDefined< BcHandlerType, PhysicalSolverType >::functionSin, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5 );
317 
318  default:
319 
320  std::cout << " !!! Warning: user defined function " << M_functionType << " not assigned !!!" << std::endl;
321 
322  return 0;
323  }
324 }
325 
326 template< typename BcHandlerType, typename PhysicalSolverType >
327 Real
328 BCInterfaceFunctionUserDefined< BcHandlerType, PhysicalSolverType >::functionSin ( const Real& t, const Real& /*x*/, const Real& /*y*/, const Real& /*z*/, const ID& /*id*/)
329 {
330  return M_parameters[0] + M_parameters[1] * std::sin ( M_parameters[2] + 2 * M_PI * t / M_parameters[3] );
331 }
332 
333 } // Namespace LifeV
334 
335 #endif /* BCInterfaceFunctionUserDefined_H */
BCInterfaceData - The BCInterface data container.
BCInterfaceFunctionUserDefined(const BCInterfaceFunctionUserDefined &function)
boundaryFunctionTimeTimeStep_Type functionSelectorTimeTimeStep()
Get the selected function of time and time step.
function_Type::boundaryFunctionTimeTimeStep_Type boundaryFunctionTimeTimeStep_Type
Real functionSin(const Real &t, const Real &, const Real &, const Real &, const ID &)
Sinusoidal function.
void assignFunction(bcBase_Type &base)
Assign the function to the base of the BCHandler.
#define M_PI
Definition: winmath.h:20
void updateInverseJacobian(const UInt &iQuadPt)
Real functionTimeSpace(const Real &t, const Real &x, const Real &y, const Real &z, const ID &)
Function of time and space.
boundaryFunctionTime_Type functionSelectorTime()
Get the selected function of time.
Real functionTimeTimeStep(const Real &t, const Real &timeStep)
Function of time and time step.
uint32_type ID
IDs.
Definition: LifeV.hpp:194
std::vector< Real > parametersContainer_Type
boundaryFunctionTimeSpaceID_Type functionSelectorTimeSpaceID()
Get the selected function of time and space with ID.
function_Type::boundaryFunctionTimeSpaceID_Type boundaryFunctionTimeSpaceID_Type
Real functionTime(const Real &t)
Function of time.
double Real
Generic real data.
Definition: LifeV.hpp:175
BCInterfaceFunctionUserDefined< BcHandlerType, PhysicalSolverType > * createBCInterfaceFunctionUserDefined()
Factory create function.
Real functionTimeSpaceID(const Real &t, const Real &x, const Real &y, const Real &z, const ID &id)
Function of time and space with ID.
BCInterfaceFunction< bcHandler_Type, physicalSolver_Type > function_Type
void setData(const dataPtr_Type &data)
Set data for boundary conditions.
BCInterfaceFunctionUserDefined - User defined functions for BCInterface.
BCInterfaceFunctionUserDefined & operator=(const BCInterfaceFunctionUserDefined &function)
BCInterfaceFunction - Base class for BCInterface boundary functions.
function_Type::boundaryFunctionTime_Type boundaryFunctionTime_Type