LifeV
BCHandler.cpp
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 BCHandler class for handling boundary conditions
30 
31  @author Miguel Fernandez <miguel.fernandez@inria.fr>
32  @contributor Christophe Prud'homme <christophe.prudhomme@epfl.ch>
33  @contributor Mauro Perego <perego.mauro@gmail.com>
34  @maintainer Mauro Perego <perego.mauro@gmail.com>
35 
36  @date 10-11-2004
37  *///@HEADER
38 
39 #include <sstream>
40 #include <stdexcept>
41 
42 #include <boost/lambda/lambda.hpp>
43 #include <boost/lambda/bind.hpp>
44 #include <boost/lambda/if.hpp>
45 
46 #include <lifev/core/fem/BCHandler.hpp>
47 
48 namespace LifeV
49 {
50 
51 // ===================================================
52 // Constructors & Destructor
53 // ===================================================
55  M_bcUpdateDone ( 0 ),
56  M_offset ( 0 )
57 {
58 }
59 
60 BCHandler::BCHandler ( const BCHandler& BCh ) :
61  M_bcUpdateDone ( false ), //TODO change this! (related with BCBase copy constructor)
62  M_bcList ( BCh.M_bcList ),
63  M_offset ( BCh.M_offset ),
65 {
66 }
67 
68 
70 {
71 
72 }
73 
74 // ===================================================
75 // Operators
76 // ===================================================
77 
78 BCHandler&
79 BCHandler::operator = (const BCHandler& BCh)
80 {
81  if (this != &BCh)
82  {
84  M_bcList = BCh.M_bcList;
85  M_notFoundMarkers = BCh.M_notFoundMarkers;
86  }
87 
88  return *this;
89 }
90 
91 BCBase&
92 BCHandler::operator[] ( const ID& i )
93 {
94  return M_bcList[ i ];
95 }
96 
97 const BCBase&
98 BCHandler::operator[] ( const ID& i ) const
99 {
100  return M_bcList[ i ];
101 }
102 
103 // ===================================================
104 // Methods
105 // ===================================================
106 
107 void
108 BCHandler::addBC ( const bcName_Type& name,
109  const bcFlag_Type& flag,
110  const bcType_Type& type,
111  const bcMode_Type& mode,
112  BCFunctionBase& bcFunction,
113  const bcComponentsVec_Type& components )
114 {
115  M_bcList.push_back ( BCBase ( name, flag, type, mode, bcFunction, components ) );
116  std::sort ( M_bcList.begin(), M_bcList.end() );
117 }
118 
119 
120 void
121 BCHandler::addBC ( const bcName_Type& name,
122  const bcFlag_Type& flag,
123  const bcType_Type& type,
124  const bcMode_Type& mode,
125  BCFunctionBase& bcFunction )
126 {
127  M_bcList.push_back ( BCBase ( name, flag, type, mode, bcFunction ) );
128  std::sort ( M_bcList.begin(), M_bcList.end() );
129 }
130 
131 void
132 BCHandler::addBC ( const bcName_Type& name,
133  const bcFlag_Type& flag,
134  const bcType_Type& type,
135  const bcMode_Type& mode,
136  BCFunctionBase& bcFunction,
137  const UInt& numComponents )
138 {
139  M_bcList.push_back ( BCBase ( name, flag, type, mode, bcFunction, numComponents ) );
140  std::sort ( M_bcList.begin(), M_bcList.end() );
141 }
142 
143 void
144 BCHandler::addBC ( const bcName_Type& name,
145  const bcFlag_Type& flag,
146  const bcType_Type& type,
147  const bcMode_Type& mode,
148  BCVectorBase& bcVector,
149  const bcComponentsVec_Type& numComponents )
150 {
151  M_bcList.push_back ( BCBase ( name, flag, type, mode, bcVector, numComponents ) );
152  std::sort ( M_bcList.begin(), M_bcList.end() );
153 }
154 
155 void
156 BCHandler::addBC ( const bcName_Type& name,
157  const bcFlag_Type& flag,
158  const bcType_Type& type,
159  const bcMode_Type& mode,
160  BCVectorBase& bcVector )
161 {
162  M_bcList.push_back ( BCBase ( name, flag, type, mode, bcVector ) );
163  std::sort ( M_bcList.begin(), M_bcList.end() );
164 }
165 
166 void
167 BCHandler::addBC ( const bcName_Type& name,
168  const bcFlag_Type& flag,
169  const bcType_Type& type,
170  const bcMode_Type& mode,
171  BCVectorBase& bcVector,
172  const UInt& numComponents )
173 {
174  M_bcList.push_back ( BCBase ( name, flag, type, mode, bcVector, numComponents ) );
175  std::sort ( M_bcList.begin(), M_bcList.end() );
176 }
177 
178 void
179 BCHandler::addBC ( const bcName_Type& name,
180  const bcFlag_Type& flag,
181  const bcType_Type& type,
182  const bcMode_Type& mode,
183  BCFunctionUDepBase& bcUDepFunction )
184 {
185  M_bcList.push_back ( BCBase ( name, flag, type, mode, bcUDepFunction ) );
186  std::sort ( M_bcList.begin(), M_bcList.end() );
187 }
188 
189 void
190 BCHandler::addBC ( const BCBase& bcBase )
191 {
192  M_bcList.push_back ( bcBase );
193  std::sort ( M_bcList.begin(), M_bcList.end() );
194 }
195 
196 void
197 BCHandler::modifyBC ( bcName_Type const& name, BCFunctionBase const& bcFunction )
198 {
199  BCBase* bcBasePtr = findBC ( name );
200 
201  bcBasePtr->setBCFunction ( bcFunction );
202 }
203 
204 void
205 BCHandler::modifyBC ( bcName_Type const& name, BCVectorBase const& bcVector )
206 {
207  BCBase* bcBasePtr = findBC ( name );
208 
209  bcBasePtr->setBCVector ( bcVector );
210 }
211 
212 void
213 BCHandler::modifyBC ( std::string const& name, BCFunctionUDepBase const& bcUDepFunction )
214 {
215  BCBase* bcBasePtr = findBC ( name );
216 
217  bcBasePtr->setBCFunction ( bcUDepFunction );
218 }
219 
220 void
221 BCHandler::modifyBC ( bcFlag_Type const& aFlag, BCFunctionBase const& bcFunction )
222 {
223  std::cout << "XXX21" << std::endl;
224  BCBase* bcBasePtr = findBC ( aFlag );
225 
226  bcBasePtr->setBCFunction ( bcFunction );
227  std::cout << "XXX22" << std::endl;
228 }
229 
230 void
231 BCHandler::modifyBC ( bcFlag_Type const& aFlag, BCVectorBase const& bcVector )
232 {
233  BCBase* bcBasePtr = findBC ( aFlag );
234 
235  bcBasePtr->setBCVector ( bcVector );
236 }
237 
238 void
239 BCHandler::modifyBC ( bcFlag_Type const& aFlag, BCFunctionUDepBase const& bcFunction )
240 {
241  BCBase* bcBasePtr = findBC ( aFlag );
242 
243  bcBasePtr->setBCFunction ( bcFunction );
244 }
245 
246 void
247 BCHandler::modifyBC ( bcFlag_Type const& aFlag, bcType_Type const& bcType )
248 {
249  BCBase* bcBasePtr = findBC ( aFlag );
250 
251  bcBasePtr->setType ( bcType );
252 }
253 
254 void
255 BCHandler::merge ( BCHandler& bcHandler )
256 {
258  bcHandler.M_sumOffsets();
259  M_bcList.insert (M_bcList.end(), bcHandler.M_bcList.begin(), bcHandler.M_bcList.end() );
261  M_offset = 0;
262 }
263 
264 void
265 BCHandler::showMe ( bool verbose, std::ostream& out ) const
266 {
267  out << " Boundary Conditions Handler ====>" << std::endl;
268  out << " Number of BC stored " << size() << std::endl;
269 
270  out << " List => " << std::endl;
271  for ( UInt i = 0; i < M_bcList.size(); ++i )
272  {
273  M_bcList[ i ].showMe ( verbose, out );
274  }
275  out << " <===========================>" << std::endl;
276 }
277 
278 // ===================================================
279 // Set Methods
280 // ===================================================
281 void
282 BCHandler::setOffset ( const UInt& offset )
283 {
284  M_offset = offset;
285 }
286 
287 void
288 BCHandler::setOffset ( const bcName_Type& name, Int offset )
289 {
290  BCBase* bc = findBC ( name );
291 
292  if (bc == 0)
293  {
294  std::cout << "BCHandler::setOffset : BC " << name << " not found ... ";
295  }
296  else
297  {
298  bc->setOffset (offset);
299  }
300 }
301 
302 
303 BCBase&
305 {
306  ID i;
307 
308  for (i = 0; i < M_bcList.size(); i++)
309  if (aFlag == M_bcList[i].flag() )
310  {
311  break;
312  }
313 
314  return M_bcList[i];
315 }
316 
317 const BCBase&
318 BCHandler::findBCWithFlag (const bcFlag_Type& aFlag) const
319 {
320  ID i;
321 
322  for (i = 0; i < M_bcList.size(); i++)
323  if (aFlag == M_bcList[i].flag() )
324  {
325  break;
326  }
327 
328  return M_bcList[i];
329 }
330 
333 {
334  std::vector<bcName_Type> vectorName;
335 
336  for ( std::size_t i = 0; i < M_bcList.size(); ++i )
337  if ( M_bcList[i].type() == type)
338  {
339  vectorName.push_back ( M_bcList[i].name() );
340  }
341 
342  return vectorName;
343 }
344 
345 UInt
347 {
348  UInt typeNumber = 0;
349 
350  for ( std::size_t i = 0; i < M_bcList.size(); ++i )
351  if ( M_bcList[i].type() == type)
352  {
353  ++typeNumber;
354  }
355 
356  return typeNumber;
357 }
358 
359 const BCBase*
361 {
362  return &M_bcList[ findBCIndexWithName (name) ];
363 }
364 
365 UInt
367 {
368  UInt iBC ( 0 );
369 
370  for ( ; iBC < M_bcList.size(); iBC++ )
371  if (M_bcList[iBC].name() == name)
372  {
373  break;
374  }
375 
376  if ( iBC == M_bcList.size() )
377  {
378  std::ostringstream __ex;
379  __ex << name << " was not found in this Boundary conditions set\n"
380  << "This set contains \n";
381  for ( UInt i = 0; i < M_bcList.size(); ++i )
382  {
383  M_bcList[ i ].showMe ( true, __ex );
384  }
385  throw std::invalid_argument ( __ex.str() );
386  }
387 
388  return iBC;
389 }
390 
391 
392 
393 bool
395 {
396  std::map<bcFlag_Type, std::set<ID> > nonEssentialConditions;
397  std::set<ID> nonEssentialComponents;
398  for (UInt i = 0; i < nDimensions; i++)
399  {
400  nonEssentialComponents.insert (i);
401  }
402 
403  for ( bcBaseConstIterator_Type it = M_bcList.begin(); it != M_bcList.end(); ++it )
404  {
405  nonEssentialConditions.insert (std::make_pair (it->flag(), nonEssentialComponents) );
406  }
407 
408  for ( bcBaseConstIterator_Type it = begin(); it != end(); ++it )
409  {
410  if ( it->type() == Essential )
411  {
412  switch (it->mode() )
413  {
414  case Full:
415  case Normal:
416  nonEssentialConditions.erase (it->flag() );
417  break;
418  case Scalar:
419  nonEssentialConditions.find (it->flag() )->second.erase (0);
420  break;
421  case Component:
422  for ( UInt iComp = 0; iComp < it->numberOfComponents(); ++iComp )
423  {
424  nonEssentialConditions.find (it->flag() )->second.erase ( it->component (iComp) );
425  }
426  if ( nonEssentialConditions.find (it->flag() )->second.empty() )
427  {
428  nonEssentialConditions.erase (it->flag() );
429  }
430  break;
431  default:
432  break;
433  }
434  }
435  }
436  return ( nonEssentialConditions.empty() );
437 }
438 
439 // ===================================================
440 // Private Methods
441 // ===================================================
442 BCBase*
443 BCHandler::findBC ( bcName_Type const& name )
444 {
445  std::string Pippo = "Pippo";
446  BCBase* bcBasePtr = 0;
447  std::for_each ( M_bcList.begin(),
448  M_bcList.end(),
449  [&name, &bcBasePtr] (LifeV::BCBase i) { if ((std::bind ( &BCBase::name, i ))() == name)
450  bcBasePtr = &i; }
451  );
452 
453  //! handle invalid name case: ie we didnot find the name in the M_bcList
454  if ( !bcBasePtr )
455  {
456  std::ostringstream __ex;
457  __ex << "Invalid name for BC to be modified : " << name << "\n"
458  << "The list of available BCs is:\n";
459  std::for_each ( M_bcList.begin(),
460  M_bcList.end(),
461  [] (BCBase i) { std::cout << (std::bind (
462  &BCBase::name, i ))() << '\n'; }
463  );
464  throw std::invalid_argument ( __ex.str() );
465  }
466  return bcBasePtr;
467 }
468 
469 BCBase*
470 BCHandler::findBC ( bcFlag_Type const& aFlag)
471 {
472  BCBase* bcBasePtr = 0;
473  std::cout << "XXX23" << std::endl;
474  std::for_each ( M_bcList.begin(),
475  M_bcList.end(),
476  [&aFlag, &bcBasePtr] (LifeV::BCBase i) { if ((std::bind ( &BCBase::flag, i ))() == aFlag)
477  bcBasePtr = &i; }
478  );
479  std::cout << "XXX24" << std::endl;
480  return bcBasePtr;
481 }
482 
483 
484 
485 void
487 {
488  for ( bcBaseIterator_Type it = M_bcList.begin(); it != M_bcList.end(); ++it )
489  {
490  it->setOffset (it->offset() + M_offset);
491  }
492 }
493 
494 } // namespace LifeV
void addBC(const std::string &name, const bcFlag_Type &flag, const bcType_Type &type, const bcMode_Type &mode, BCFunctionBase &bcFunction, const UInt &numberOfComponents)
Add new BC to the list for Full mode problems (user defined function case)
Definition: BCHandler.cpp:132
const BCBase & operator[](const ID &) const
Extract a BC in the list, const.
Definition: BCHandler.cpp:98
BCBase & findBCWithFlag(const bcFlag_Type &aFlag)
Extract a BC in the list according to its flag.
Definition: BCHandler.cpp:304
void addBC(const std::string &name, const bcFlag_Type &flag, const bcType_Type &type, const bcMode_Type &mode, BCVectorBase &bcVector)
Add new BC to the list for Scalar, Tangential or Normal mode problems (data vector case) ...
Definition: BCHandler.cpp:156
void addBC(const std::string &name, const bcFlag_Type &flag, const bcType_Type &type, const bcMode_Type &mode, BCVectorBase &bcVector, const UInt &nComp)
Add new BC to the list for Full mode problems (data vector case)
Definition: BCHandler.cpp:167
void addBC(const BCBase &bcBase)
Add new BC to the list using a BCBase object.
Definition: BCHandler.cpp:190
BCFunctionUDepBase - class that holds the function used for prescribing boundary conditions.
Definition: BCFunction.hpp:380
markerID_Type bcFlag_Type
Definition: BCBase.hpp:118
void modifyBC(bcFlag_Type const &aFlag, BCVectorBase const &bcVector)
Modify the boundary condition associated with flag aFlag, assigning the FE vector in bcVector...
Definition: BCHandler.cpp:231
BCHandler - class for handling boundary conditions.
Definition: BCHandler.hpp:100
void modifyBC(bcFlag_Type const &aFlag, bcType_Type const &bcType)
Modify the boundary condition associated with flag aFlag, assigning the type in bcType.
Definition: BCHandler.cpp:247
bcMode_Type
Definition: BCBase.hpp:102
UInt numberOfBCWithType(const bcType_Type &aType) const
Get the number of boundary conditions with type aType.
Definition: BCHandler.cpp:346
int32_type Int
Generic integer data.
Definition: LifeV.hpp:188
std::vector< BCBase >::const_iterator bcBaseConstIterator_Type
Definition: BCHandler.hpp:108
BCBase & operator[](const ID &)
Extract a BC in the list.
Definition: BCHandler.cpp:92
BCBase * findBC(const bcFlag_Type &aFlag)
Find the BC named aFlag.
Definition: BCHandler.cpp:470
void modifyBC(bcFlag_Type const &aFlag, BCFunctionBase const &bcFunction)
Modify the boundary condition associated with flag aFlag, assigning the function in bcFunction...
Definition: BCHandler.cpp:221
void updateInverseJacobian(const UInt &iQuadPt)
bool hasOnlyEssential() const
Determine whether all the stored boundary conditions have EssentialXXX type.
Definition: BCHandler.cpp:394
std::vector< bcName_Type > findAllBCWithType(const bcType_Type &aType) const
Get a vector list of BC with specific type. The list contains the bcName_Type of the BC...
Definition: BCHandler.cpp:332
void addBC(const std::string &name, const bcFlag_Type &flag, const bcType_Type &type, const bcMode_Type &mode, BCFunctionBase &bcFunction, const bcComponentsVec_Type &components)
Add new BC to the list for Component or Directional mode problems (user defined function case) ...
Definition: BCHandler.cpp:108
void showMe(bool verbose=false, std::ostream &out=std::cout) const
Display the content of the variables.
Definition: BCHandler.cpp:265
const BCBase & findBCWithFlag(const bcFlag_Type &aFlag) const
Extract a BC in the list according to its flag (non const)
Definition: BCHandler.cpp:318
BCFunctionBase - class that holds the function used for prescribing boundary conditions.
Definition: BCFunction.hpp:77
void setOffset(const std::string &name, Int offset)
Set offset in boundary conditions name.
Definition: BCHandler.cpp:288
std::vector< ID > bcComponentsVec_Type
Definition: BCBase.hpp:120
BCHandler()
Empty Constructor.
Definition: BCHandler.cpp:54
BCVectorBase - class that holds the FE vectors used for prescribing boundary conditions.
Definition: BCVector.hpp:74
void setOffset(const UInt &offset)
Set offset in all boundary conditions.
Definition: BCHandler.cpp:282
uint32_type ID
IDs.
Definition: LifeV.hpp:194
void setBCFunction(const BCFunctionBase &bcFunction)
set BCFunctionBase boundary condition
Definition: BCBase.cpp:687
void setBCVector(const BCVectorBase &bcVector)
set BCVectorBase boundary condition
Definition: BCBase.cpp:679
void addBC(const std::string &name, const bcFlag_Type &flag, const bcType_Type &type, const bcMode_Type &mode, BCVectorBase &bcVector, const bcComponentsVec_Type &components)
Add new BC to the list for Component or Directional mode problems (data vector case) ...
Definition: BCHandler.cpp:144
UInt M_offset
offset
Definition: BCHandler.hpp:547
bcBaseConstIterator_Type end() const
Definition: BCHandler.hpp:472
void merge(BCHandler &bcHandler)
Merges the boundary condition bcHandler (with its offset) with the stored one.
Definition: BCHandler.cpp:255
void modifyBC(std::string const &name, BCFunctionBase const &bcFunction)
Modify the boundary condition name, assigning the function bcFunction.
Definition: BCHandler.cpp:197
std::string bcName_Type
Definition: BCBase.hpp:116
void modifyBC(std::string const &name, BCVectorBase const &bcVector)
Modify the boundary condition assigning the FE vector in bcVector.
Definition: BCHandler.cpp:205
void setOffset(int bcOffset)
Set the BC offset.
Definition: BCBase.hpp:526
bcBaseConstIterator_Type begin() const
Definition: BCHandler.hpp:458
BCBase * findBC(const std::string &name)
Find the BC named name.
Definition: BCHandler.cpp:443
const BCBase * findBCWithName(const bcName_Type &name) const
Definition: BCHandler.cpp:360
void M_sumOffsets()
Sum the M_offset to boundary conditions offsets.
Definition: BCHandler.cpp:486
bcType_Type
Definition: BCBase.hpp:88
void setType(const bcType_Type &bcType)
Set the BC type.
Definition: BCBase.hpp:535
const UInt nDimensions(NDIM)
ID findBCIndexWithName(const bcName_Type &name) const
Definition: BCHandler.cpp:366
void setBCFunction(const BCFunctionUDepBase &bcFunctionFEVectorDependent)
set BCFunctionUDepBase boundary condition
Definition: BCBase.cpp:695
BCHandler(const BCHandler &bcHandler)
Copy constructor.
Definition: BCHandler.cpp:60
void modifyBC(std::string const &name, BCFunctionUDepBase const &bcFunctionFEVectorDependent)
Modify the boundary condition name, assigning the function in bcFunctionFEVectorDependent.
Definition: BCHandler.cpp:213
~BCHandler()
Destructor.
Definition: BCHandler.cpp:69
void modifyBC(bcFlag_Type const &aFlag, BCFunctionUDepBase const &bcFunctionFEVectorDependent)
Modify the boundary condition associated with flag aFlag, assigning the function in bcFunctionFEVecto...
Definition: BCHandler.cpp:239
bool M_bcUpdateDone
true only if the bcUpdate has been done
Definition: BCHandler.hpp:541
void addBC(const std::string &name, const bcFlag_Type &flag, const bcType_Type &type, const bcMode_Type &mode, BCFunctionBase &bcFunction)
Add new BC to the list for Scalar, Tangential or Normal mode problems (user defined function case) ...
Definition: BCHandler.cpp:121
std::vector< std::shared_ptr< BCIdentifierBase > > M_idVector
container for id&#39;s when the list is finalized
Definition: BCBase.hpp:647
void addBC(const std::string &name, const bcFlag_Type &flag, const bcType_Type &type, const bcMode_Type &mode, BCFunctionUDepBase &bcFunctionFEVectorDependent)
Add new BC to the list for Scalar, Tangential or Normal mode problems (user defined function case...
Definition: BCHandler.cpp:179
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191
BCHandler & operator=(const BCHandler &bcHandler)
Assignment operator.
Definition: BCHandler.cpp:79