LifeV
BCInterface1D.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 BCInterface1D 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 BCInterface1D_H
38 #define BCInterface1D_H 1
39 
40 // BCInterface includes
41 #include <lifev/bc_interface/core/bc/BCInterface.hpp>
42 #include <lifev/bc_interface/1D/bc/BCInterfaceData1D.hpp>
43 
44 // Template specializations
45 #include <lifev/bc_interface/1D/function/BCInterfaceFunctionParser1D.hpp>
46 #include <lifev/bc_interface/1D/function/BCInterfaceFunctionParserSolver1D.hpp>
47 #include <lifev/bc_interface/1D/function/BCInterfaceFunctionSolverDefined1D.hpp>
48 #include <lifev/bc_interface/1D/function/BCInterfaceFunctionUserDefined1D.hpp>
49 
50 namespace LifeV
51 {
52 
53 //! BCInterface1D - LifeV interface to load boundary conditions for 1D problems completely from a \c GetPot file
54 /*!
55  * @author Cristiano Malossi
56  *
57  * This class allows to impose boundary conditions for a 1D problem completely from a file.
58  *
59  * <b>EXAMPLE - DATA FILE</b> <BR>
60  * In the GetPot data file, \c BCInterface reads a new section: <CODE> [boundary_conditions] </CODE>.
61  *
62  * Inside the new section there is a list of boundary conditions which correspond to other sub-section
63  * with the same name, for example: <CODE> list = 'InFlow OutFlow' </CODE>
64  *
65  * Each boundary condition has a similar structure. The list of properties depends from the type of the
66  * boundary condition. For example:
67  *
68  * <CODE>
69  * [InFlow] <BR>
70  * side = left <BR>
71  * quantity = Q <BR>
72  * line = first <BR>
73  * function = 'sin(2*pi*t)' <BR>
74  *
75  * [OutFlow] <BR>
76  * side = right <BR>
77  * quantity = W2 <BR>
78  * line = first <BR>
79  * functionSD = Absorbing <BR>
80  * </CODE>
81  *
82  * where \c side, \c quantity, and \c line are the classical parameters for a 1D boundary condition.
83  * The string \c function represents the base module and can be replaced by other derived/alternative modules.
84  * The following functions are available (see the related classes for more information):
85  *
86  * <ol>
87  * <li> \c function, which is implemented in \c BCInterfaceFunctionParser;
88  * <li> \c functionFile, which is implemented in \c BCInterfaceFunctionParserFile;
89  * <li> \c functionSolver, which is implemented in \c BCInterfaceFunctionParserSolver;
90  * <li> \c functionFileSolver, which is implemented in \c BCInterfaceFunctionParserFileSolver;
91  * <li> \c functionUD, which is implemented in \c BCInterfaceFunctionUserDefined;
92  * <li> \c functionSD, which is implemented in \c BCInterfaceFunctionSolverDefined.
93  * </ol>
94  *
95  * All the parameters are case sensitive.
96  *
97  * See \c BCInterface base class for more details.
98  */
99 template< class BcHandler, class PhysicalSolverType >
100 class BCInterface1D : public virtual BCInterface< BcHandler, PhysicalSolverType >
101 {
102 public:
103 
104  //! @name Type definitions
105  //@{
106 
107  typedef BCInterface< BcHandler, PhysicalSolverType > bcInterface_Type;
108 
111 
114 
116 
119 
122 
125 
128 
133 
134  //@}
135 
136 
137  //! @name Constructors & Destructor
138  //@{
139 
140  //! Constructor
141  explicit BCInterface1D() : bcInterface_Type(), M_data ( new data_Type() ) {}
142 
143  //! Destructor
144  virtual ~BCInterface1D() {}
145 
146  //@}
147 
148 
149  //! @name Methods
150  //@{
151 
152  //! Read a specific boundary condition from a file and add it to the data container
153  /*!
154  * @param fileName Name of the data file
155  * @param dataSection section in the data file
156  * @param name name of the boundary condition
157  */
158  void readBC ( const std::string& fileName, const std::string& dataSection, const std::string& name )
159  {
160  M_data->readBC ( fileName, dataSection, name );
161  }
162 
163  //! Insert the current boundary condition in the BChandler
164  void insertBC();
165 
166  //@}
167 
168 
169  //! @name External interface for BCHandler functions
170  //@{
171 
172  //! Add a Boundary Condition using the standard interface of the BCHandler
173  /*!
174  * @param side side of the condition
175  * @param line line of the condition
176  * @param type type of the condition
177  * @param base base of the condition
178  */
179  template< class BCBaseType >
180  void setBC ( const OneDFSI::bcSide_Type& bcSide, const OneDFSI::bcLine_Type& bcLine, const OneDFSI::bcType_Type& bcType, const BCBaseType& base )
181  {
182  this->M_handler->setBC ( bcSide, bcLine, bcType, base );
183  }
184 
185  //@}
186 
187 
188  //! @name Set Methods
189  //@{
190 
191  //! Set the solution for the members that need it
192  /*!
193  * @param flux flux
194  * @param source source
195  */
196  void setFluxSource ( const fluxPtr_Type& flux, const sourcePtr_Type& source );
197 
198  //! Set the solution for the members that need it
199  /*!
200  * @param solution solution
201  */
202  void setSolution ( const solutionPtr_Type& solution );
203 
204  //@}
205 
206 
207  //! @name Get Methods
208  //@{
209 
210  //! Get the data container
211  /*!
212  * @return the data container
213  */
215  {
216  return *M_data;
217  }
218 
219  //@}
220 
221 private:
222 
223  //! @name Unimplemented Methods
224  //@{
225 
226  BCInterface1D ( const BCInterface1D& interface1D );
227 
228  BCInterface1D& operator= ( const BCInterface1D& interface1D );
229 
230  //@}
231 
232 
233  //! @name Private Methods
234  //@{
235 
236  template< class BCInterfaceBaseType >
238 
239  template< class BCBaseType >
240  void addBcToHandler ( BCBaseType& base );
241 
242  //@}
243 
244  // Data
246 };
247 
248 // ===================================================
249 // Methods
250 // ===================================================
251 template< class BcHandler, class PhysicalSolverType >
252 inline void
253 BCInterface1D< BcHandler, PhysicalSolverType >::insertBC()
254 {
255 
256 #ifdef HAVE_LIFEV_DEBUG
257  debugStream ( 5020 ) << "BCInterface1D::insertBC\n";
258 #endif
259 
260  // Definitions
261  factory_Type factory;
262  OneDFSIFunction base;
263 
264  // Define correct BCI type
265  switch ( M_data->base().second )
266  {
267  case BCIFunctionParser:
268  case BCIFunctionParserFile:
269  case BCIFunctionParserSolver:
270  case BCIFunctionParserFileSolver:
271  case BCIFunctionUserDefined:
272  {
273  this->M_vectorFunction.push_back ( factory.createFunctionParser ( M_data ) );
274  this->M_vectorFunction.back()->assignFunction ( base );
275 
276  break;
277  }
278  case BCIFunctionSolverDefined:
279  {
280  this->M_vectorFunctionSolverDefined.push_back ( factory.createFunctionSolverDefined ( M_data ) );
281  this->M_vectorFunctionSolverDefined.back()->assignFunction ( base );
282 
283  break;
284  }
285  default:
286 
287  std::cout << " !!! Error: " << M_data->base().first << " is not valid in BCInterface1D !!!" << std::endl;
288  return;
289  }
290 
291  // Add base to BCHandler
292  addBcToHandler ( base );
293 }
294 
295 // ===================================================
296 // Set Methods
297 // ===================================================
298 template< class BcHandler, class PhysicalSolverType >
299 void
300 BCInterface1D< BcHandler, PhysicalSolverType >::setFluxSource ( const fluxPtr_Type& flux, const sourcePtr_Type& source )
301 {
302  for ( typename vectorFunctionSolverDefined_Type::const_iterator i = this->M_vectorFunctionSolverDefined.begin() ; i < this->M_vectorFunctionSolverDefined.end() ; ++i )
303  {
304  ( *i )->setFluxSource ( flux, source );
305  }
306 
307  this->M_handler->setFluxSource ( flux, source );
308 }
309 
310 template< class BcHandler, class PhysicalSolverType >
311 void
312 BCInterface1D< BcHandler, PhysicalSolverType >::setSolution ( const solutionPtr_Type& solution )
313 {
314  //for ( typename vectorFunction_Type::const_iterator i = M_vectorFunction.begin() ; i < M_vectorFunction.end() ; ++i )
315  for ( UInt i ( 0 ); i < this->M_vectorFunction.size(); ++i )
316  {
317  bcFunctionParserSolverPtr_Type castedFunctionSolver = std::dynamic_pointer_cast< bcFunctionParserSolver_Type > ( this->M_vectorFunction[i] );
318 
319  if ( castedFunctionSolver != 0 )
320  {
321  castedFunctionSolver->setSolution ( solution );
322  }
323  }
324 
325  for ( typename vectorFunctionSolverDefined_Type::const_iterator i = this->M_vectorFunctionSolverDefined.begin() ; i < this->M_vectorFunctionSolverDefined.end() ; ++i )
326  {
327  ( *i )->setSolution ( solution );
328  }
329 
330  this->M_handler->setSolution ( solution );
331 }
332 
333 // ===================================================
334 // Private Methods
335 // ===================================================
336 template< class BcHandler, class PhysicalSolverType > template< class BCInterfaceBaseType >
337 inline void
338 BCInterface1D< BcHandler, PhysicalSolverType >::createFunction ( std::vector< std::shared_ptr< BCInterfaceBaseType > >& baseVector )
339 {
340  std::shared_ptr< BCInterfaceBaseType > function ( new BCInterfaceBaseType() );
341  function->setData ( M_data );
342  baseVector.push_back ( function );
343 }
344 
345 template< class BcHandler, class PhysicalSolverType > template< class BCBaseType >
346 inline void
347 BCInterface1D< BcHandler, PhysicalSolverType >::addBcToHandler ( BCBaseType& base )
348 {
349  if ( !this->M_handler.get() ) // If BCHandler has not been created yet, we do it now
350  {
351  this->createHandler();
352  }
353 
354 #ifdef HAVE_LIFEV_DEBUG
355  debugStream ( 5020 ) << "BCInterface1D::addBCManager" << "\n\n";
356 #endif
357 
358  this->M_handler->setBC ( M_data->side(), M_data->line(), M_data->quantity(), base );
359 }
360 
361 } // Namespace LifeV
362 
363 #endif /* BCInterface1D_H */
data_Type & dataContainer()
Get the data container.
bcHandler_Type::sourcePtr_Type sourcePtr_Type
bcInterface_Type::physicalSolver_Type physicalSolver_Type
BCInterface1D()
Constructor.
bcInterface_Type::bcFunctionSolverDefinedPtr_Type bcFunctionSolverDefinedPtr_Type
bcInterface_Type::vectorFunction_Type vectorFunction_Type
bcInterface_Type::factory_Type factory_Type
BCInterface1D - LifeV interface to load boundary conditions for 1D problems completely from a GetPot ...
void setSolution(const solutionPtr_Type &solution)
Set the solution for the members that need it.
void updateInverseJacobian(const UInt &iQuadPt)
bcInterface_Type::bcHandlerPtr_Type bcHandlerPtr_Type
OneDFSIFunction - Base class for 1D BC Functions.
bcHandler_Type::vectorPtrContainer_Type vectorPtrContainer_Type
bcInterface_Type::bcHandler_Type bcHandler_Type
bcHandler_Type::fluxPtr_Type fluxPtr_Type
void readBC(const std::string &fileName, const std::string &dataSection, const std::string &name)
Read a specific boundary condition from a file and add it to the data container.
bcInterface_Type::bcFunctionParserSolverPtr_Type bcFunctionParserSolverPtr_Type
void createFunction(std::vector< std::shared_ptr< BCInterfaceBaseType > > &baseVector)
void setBC(const OneDFSI::bcSide_Type &bcSide, const OneDFSI::bcLine_Type &bcLine, const OneDFSI::bcType_Type &bcType, const BCBaseType &base)
Add a Boundary Condition using the standard interface of the BCHandler.
void setFluxSource(const fluxPtr_Type &flux, const sourcePtr_Type &source)
Set the solution for the members that need it.
std::shared_ptr< data_Type > dataPtr_Type
BCInterfaceData1D - The BCInterface1D data container.
bcHandler_Type::solutionPtr_Type solutionPtr_Type
void insertBC()
Insert the current boundary condition in the BChandler.
bcInterface_Type::vectorFunctionSolverDefined_Type vectorFunctionSolverDefined_Type
bcInterface_Type::bcFunctionPtr_Type bcFunctionPtr_Type
void addBcToHandler(BCBaseType &base)
BCInterface1D & operator=(const BCInterface1D &interface1D)
bcInterface_Type::physicalSolverPtr_Type physicalSolverPtr_Type
bcInterface_Type::bcFunctionParserSolver_Type bcFunctionParserSolver_Type
virtual ~BCInterface1D()
Destructor.
BCInterfaceData1D data_Type
BCInterface< BcHandler, PhysicalSolverType > bcInterface_Type
BCInterface1D(const BCInterface1D &interface1D)
BCInterface - LifeV interface to load boundary conditions completely from a GetPot file...
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191