LifeV
BCInterface.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 BCInterface main class
30  *
31  * @date 10-05-2010
32  * @author Cristiano Malossi <cristiano.malossi@epfl.ch>
33  *
34  * @maintainer Cristiano Malossi <cristiano.malossi@epfl.ch>
35  */
36 
37 #ifndef BCInterface_H
38 #define BCInterface_H 1
39 
40 // BCInterface includes
41 #include <lifev/bc_interface/core/bc/BCInterfaceData.hpp>
42 #include <lifev/bc_interface/core/function/BCInterfaceFactory.hpp>
43 
44 namespace LifeV
45 {
46 
47 //! BCInterface - LifeV interface to load boundary conditions completely from a \c GetPot file
48 /*!
49  * @author Cristiano Malossi
50  *
51  * This class allows to impose boundary conditions completely from a \c GetPot file. You can derive a
52  * specific implementation for the BCHandler of your problem. For 0D (\c BCInterface0D), 1D (\c BCInterface1D) and 3D (\c BCInterface3D) problems the derived classes
53  * are already available.
54  *
55  * <b>EXAMPLE - DATA FILE</b> <BR>
56  * In the GetPot data file, \c BCInterface reads a new section: <CODE> [boundary_conditions] </CODE>.
57  *
58  * Inside the new section there is a list of boundary conditions which correspond to other sub-section
59  * with the same name, for example: <CODE> list = 'InFlow OutFlow' </CODE>
60  *
61  * Each boundary condition has a similar structure. The list of properties depends from the type of the
62  * boundary condition (if it is for 1D or 3D solver for example). For example:
63  *
64  * <CODE>
65  * [InFlow] <BR>
66  * ... <BR>
67  * ... <BR>
68  * function = '3*0.03*(1/4-(x^2+y^2)' <BR>
69  *
70  * [OutFlow] <BR>
71  * ... <BR>
72  * ... <BR>
73  * function = '0' <BR>
74  * </CODE>
75  *
76  * The string \c function represents the base module and can be replaced by other derived/alternative modules.
77  * The following functions are available (see the related classes for more information):
78  *
79  * <ol>
80  * <li> \c function, which is implemented in \c BCInterfaceFunctionParser;
81  * <li> \c functionFile, which is implemented in \c BCInterfaceFunctionParserFile;
82  * <li> \c functionSolver, which is implemented in \c BCInterfaceFunctionParserSolver;
83  * <li> \c functionFileSolver, which is implemented in \c BCInterfaceFunctionParserFileSolver;
84  * </ol>
85  *
86  * All the parameters are case sensitive.
87  *
88  * <b>EXAMPLE - HOW TO USE</b> <BR>
89  * Here there is a short guide on how to create and use a BCInterface object.
90  *
91  * <ol>
92  * <li> First of all, you have to define a BCInterface class:
93  *
94  * <CODE>
95  * BCInterface bcInterface;
96  * </CODE>
97  *
98  * <li> You can create an empty handler by calling:
99  *
100  * <CODE>
101  * bcInterface.createHandler()
102  * </CODE>
103  *
104  * or you can set it from outside
105  *
106  * <CODE>
107  * std::shared_ptr< bcHandler_Type > bcHandler( new bcHandler_Type() ); <BR>
108  * bcInterface.setHandler( bcHandler );
109  * </CODE>
110  *
111  * <li> Then you can add all the file boundary condition by calling
112  *
113  * <CODE>
114  * bcInterface.fillHandler( "fileName.dat", "section" );
115  * </CODE>
116  *
117  * Or you can add one specific boundary conditions by calling
118  *
119  * <CODE>
120  * bcInterface.readBC( "fileName.dat", "section", "bcSection" ); <BR>
121  * bcInterface.insertBC();
122  * </CODE>
123  *
124  * Note that between readBC and insertBC you can manipulate the BC parameters by accessing
125  * the data container:
126  *
127  * <CODE>
128  * bcInterface.dataContainer();
129  * </CODE>
130  *
131  * In addition, you can also add BC directly from the code by accessing the bcHandler
132  *
133  * <CODE>
134  * M_bc.handler()->addBC( ... );
135  * </CODE>
136  *
137  * <li> If you are using functions that use solver variables first you have to pass the solver
138  *
139  * <CODE>
140  * M_bc.setPhysicalSolver( physicalSolverPtr );
141  * </CODE>
142  *
143  * Then be sure to update the variable at each time step before using the BCHandler:
144  *
145  * <CODE>
146  * M_bc.updatePhysicalSolverVariables();
147  * </CODE>
148  *
149  * <li> Finally, to get the handler you can use:
150  *
151  * <CODE>
152  * M_bc.handler();
153  * </CODE>
154  *
155  * </ol>
156  */
157 template< class BcHandler, class PhysicalSolverType >
159 {
160 public:
161 
162  //! @name Type definitions
163  //@{
164 
165  typedef BcHandler bcHandler_Type;
167 
168  typedef PhysicalSolverType physicalSolver_Type;
170 
171  typedef BCInterfaceFactory< bcHandler_Type, physicalSolver_Type > factory_Type;
172 
175 
178 
181 
184 
185  //@}
186 
187 
188  //! @name Constructors & Destructor
189  //@{
190 
191  //! Constructor
192  explicit BCInterface();
193 
194  //! Destructor
195  virtual ~BCInterface() {}
196 
197  //@}
198 
199 
200  //! @name Methods
201  //@{
202 
203  //! Create the bcHandler.
205  {
206  M_handler.reset ( new bcHandler_Type() );
207  }
208 
209  //! Fill the bcHandler with the BC provided in the file.
210  /*!
211  * @param fileName Name of the data file
212  * @param dataSection Subsection inside [boundary_conditions]
213  */
214  void fillHandler ( const std::string& fileName, const std::string& dataSection );
215 
216  //! Read a specific boundary condition from a file and add it to the data container
217  /*!
218  * @param fileName Name of the data file
219  * @param dataSection section in the data file
220  * @param name name of the boundary condition
221  */
222  virtual void readBC ( const std::string& fileName, const std::string& dataSection, const std::string& name ) = 0;
223 
224  //! Insert the current boundary condition in the BChandler
225  virtual void insertBC() = 0;
226 
227  //! Update the variables inside the physical solver
228  virtual void updatePhysicalSolverVariables();
229 
230  //@}
231 
232 
233  //! @name Set Methods
234  //@{
235 
236  //! Set a physical solver
237  /*!
238  * @param physicalSolver physical solver
239  */
240  virtual void setPhysicalSolver ( const physicalSolverPtr_Type& physicalSolver );
241 
242  //! Set an Handler
243  /*!
244  * @param handler BCHandler
245  */
246  void setHandler ( const bcHandlerPtr_Type& handler )
247  {
248  M_handler = handler;
249  }
250 
251  //@}
252 
253 
254  //! @name Get Methods
255  //@{
256 
257  //! Get the shared_ptr to the BCHandler
258  /*!
259  * @return the pointer to the BCHandler
260  */
262  {
263  return M_handler;
264  }
265 
266  //! Get the data container
267  /*!
268  * @return the data container
269  */
270  virtual data_Type& dataContainer() = 0;
271 
272  //@}
273 
274 
275 protected:
276 
277  // Handler and parameters
279 
280  // Parser functions
282 
283  // User defined functions
285 
286 private:
287 
288  //! @name Unimplemented Methods
289  //@{
290 
291  BCInterface ( const BCInterface& interface1D );
292 
293  BCInterface& operator= ( const BCInterface& interface1D );
294 
295  //@}
296 };
297 
298 // ===================================================
299 // Constructors & Destructor
300 // ===================================================
301 template< class BcHandler, class PhysicalSolverType >
302 BCInterface< BcHandler, PhysicalSolverType >::BCInterface() :
303  M_handler (),
304  M_vectorFunction (),
306 {
307 
308 #ifdef HAVE_LIFEV_DEBUG
309  debugStream ( 5020 ) << "BCInterface::BCInterface" << "\n";
310 #endif
311 
312 }
313 
314 // ===================================================
315 // Methods
316 // ===================================================
317 template< class BcHandler, class PhysicalSolverType >
318 void
319 BCInterface< BcHandler, PhysicalSolverType >::fillHandler ( const std::string& fileName, const std::string& dataSection )
320 {
321 
322 #ifdef HAVE_LIFEV_DEBUG
323  debugStream ( 5020 ) << "BCInterface::fillHandler\n";
324 #endif
325 
326  GetPot dataFile ( fileName );
327  for ( UInt i ( 0 ); i < dataFile.vector_variable_size ( ( dataSection + "/boundary_conditions/list" ).c_str() ); ++i )
328  {
329  readBC ( fileName, dataSection + "/boundary_conditions/",
330  dataFile ( ( dataSection + "/boundary_conditions/list" ).c_str(), " ", i ) );
331 
332  this->insertBC();
333  }
334 }
335 
336 template< class BcHandler, class PhysicalSolverType >
337 void
338 BCInterface< BcHandler, PhysicalSolverType >::updatePhysicalSolverVariables()
339 {
340 
341 #ifdef HAVE_LIFEV_DEBUG
342  debugStream ( 5020 ) << "BCInterface::updatePhysicalSolverVariables\n";
343 #endif
344 
345  for ( UInt i ( 0 ); i < M_vectorFunction.size(); ++i )
346  {
347  bcFunctionParserSolverPtr_Type castedFunctionSolver = std::dynamic_pointer_cast< bcFunctionParserSolver_Type > ( M_vectorFunction[i] );
348 
349  if ( castedFunctionSolver != 0 )
350  {
351  castedFunctionSolver->updatePhysicalSolverVariables();
352  }
353  }
354 
355  for ( typename vectorFunctionSolverDefined_Type::const_iterator i = M_vectorFunctionSolverDefined.begin() ; i < M_vectorFunctionSolverDefined.end() ; ++i )
356  {
357  ( *i )->updatePhysicalSolverVariables();
358  }
359 }
360 
361 // ===================================================
362 // Set Methods
363 // ===================================================
364 template< class BcHandler, class PhysicalSolverType >
365 void
366 BCInterface< BcHandler, PhysicalSolverType >::setPhysicalSolver ( const physicalSolverPtr_Type& physicalSolver )
367 {
368  //for ( typename vectorFunction_Type::const_iterator i = M_vectorFunction.begin() ; i < M_vectorFunction.end() ; ++i )
369  for ( UInt i ( 0 ); i < M_vectorFunction.size(); ++i )
370  {
371  bcFunctionParserSolverPtr_Type castedFunctionSolver = std::dynamic_pointer_cast< bcFunctionParserSolver_Type > ( M_vectorFunction[i] );
372 
373  if ( castedFunctionSolver != 0 )
374  {
375  castedFunctionSolver->setPhysicalSolver ( physicalSolver );
376  }
377  }
378 
379  for ( typename vectorFunctionSolverDefined_Type::const_iterator i = M_vectorFunctionSolverDefined.begin() ; i < M_vectorFunctionSolverDefined.end() ; ++i )
380  {
381  ( *i )->setPhysicalSolver ( physicalSolver );
382  }
383 }
384 
385 } // Namespace LifeV
386 
387 #endif /* BCInterface_H */
void setHandler(const bcHandlerPtr_Type &handler)
Set an Handler.
vectorFunction_Type M_vectorFunction
virtual void setPhysicalSolver(const physicalSolverPtr_Type &physicalSolver)
Set a physical solver.
BCInterfaceData - The BCInterface data container.
bcHandlerPtr_Type M_handler
PhysicalSolverType physicalSolver_Type
BCInterface & operator=(const BCInterface &interface1D)
std::shared_ptr< data_Type > dataPtr_Type
void updateInverseJacobian(const UInt &iQuadPt)
BcHandler bcHandler_Type
factory_Type::bcFunctionParserSolverPtr_Type bcFunctionParserSolverPtr_Type
BCInterfaceData data_Type
std::vector< bcFunctionPtr_Type > vectorFunction_Type
bcHandlerPtr_Type & handler()
Get the shared_ptr to the BCHandler.
std::shared_ptr< bcHandler_Type > bcHandlerPtr_Type
BCInterface()
Constructor.
vectorFunctionSolverDefined_Type M_vectorFunctionSolverDefined
virtual ~BCInterface()
Destructor.
virtual void insertBC()=0
Insert the current boundary condition in the BChandler.
factory_Type::bcFunctionSolverDefinedPtr_Type bcFunctionSolverDefinedPtr_Type
factory_Type::bcFunctionPtr_Type bcFunctionPtr_Type
BCInterface(const BCInterface &interface1D)
virtual void updatePhysicalSolverVariables()
Update the variables inside the physical solver.
std::shared_ptr< physicalSolver_Type > physicalSolverPtr_Type
virtual data_Type & dataContainer()=0
Get the data container.
BCInterfaceFactory< bcHandler_Type, physicalSolver_Type > factory_Type
GetPot(const STRING_VECTOR &FileNameList)
Definition: GetPot.hpp:645
factory_Type::bcFunctionParserSolver_Type bcFunctionParserSolver_Type
BCInterface - LifeV interface to load boundary conditions completely from a GetPot file...
std::vector< bcFunctionSolverDefinedPtr_Type > vectorFunctionSolverDefined_Type
void createHandler()
Create the bcHandler.