LifeV
MeshEntityContainer.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 The file contains two classes implementing a wrap up
30  of Standard Library vector class to allow indexing from one.
31  *
32  * @date 30-08-1999
33  * @author Luca Formaggia <luca.formaggia@polimi.it>
34  *
35  * @contributor Laura Cattaneo
36  * @mantainer Laura Cattaneo
37  */
38 
39 #ifndef _MESHENTITYCONTAINER_HH_
40 #define _MESHENTITYCONTAINER_HH_
41 
42 #include <algorithm>
43 #include <iterator>
44 
45 #include <lifev/core/LifeV.hpp>
46 #include <lifev/core/mesh/Marker.hpp>
47 #include <lifev/core/mesh/MeshEntity.hpp>
48 
49 namespace LifeV
50 {
51 //! @todo Move to aspecific file meshentityutility
52 
53 namespace Comparers
54 {
55 
56 /** @defgroup ComparisonOperators
57  * They define a comparison operators for mesh entities according to some of
58  * their attributes
59  * The comparison operator is of the form
60  * @code
61  * bool operator(MeshEntity const & a, MeshEntity const & b)
62  * @endcode
63  * and it should generate a well posed comparison.
64  * @{
65  */
66 /** Compare according to local ID.
67  * It compares according to the ID (local ID) of a MeshEntity and it relies on std comparison operators
68  * It defaults to std::less<ID>.
69  * We rely on the fact that std::less<ID>(ID a, ID b) is defined (otherwise the user must supply it).
70  */
71 template < typename MeshEntity,
72  typename Policy = std::function<bool ( ID, ID )> >
74 {
75 public:
76  //! Constructor
77  /**
78  * The constructor can receive anything which is convertible the chosen
79  * policy type. This allows great flexibility (maybe too much!)
80  */
81  CompareAccordingToLocalId ( Policy const& p = std::less<ID>() ) : M_policy ( p ) {}
82 
83  bool operator() ( MeshEntity const& a, MeshEntity const& b )
84  {
85  return M_policy ( a.localId(), b.localId() );
86  }
87 
88 private:
89  const Policy M_policy;
90 };
91 
92 /** Compare according to Marker ID.
93  * It compares according to the Marker of a MeshEntity and it relies on std comparison operators
94  * It defaults to std::less<markerID_Type>. We rely on the fact that less<ID>(ID a, ID b) (otherwise the user must supply it).
95  */
96 template <typename MeshEntity, typename Policy = std::function< bool (markerID_Type, markerID_Type)> >
98 {
99 public:
100  //! Constructor
101  /**
102  * The constructor can receive anything which is convertible the chosen
103  * policy type. This allows great flexibility (maybe too much!)
104  */
105  CompareAccordingToMarker ( Policy const& p = std::less<markerID_Type>() ) : M_policy ( p ) {}
106 
107  bool operator() ( MeshEntity const& a, MeshEntity const& b )
108  {
109  return M_policy ( a.markerID(), b.markerID() );
110  }
111 
112 private:
113  const Policy M_policy;
114 };
115 
116 /** @}*/
117 
118 }
119 
120 namespace Predicates
121 {
122 /** @defgroup Predicates
123  *
124  * Predicates are functors that take MeshEntity as template argument and
125  * implement
126  *
127  * @code
128  * bool operator()(const MeshEntity & entity)const
129  * @endcode
130  * @{
131  */
132 //! A simple predicate to test the boolean flag on a mesh entity
133 /*!
134  @prerequisite MeshEntity must have a method flag_Type flag();
135 
136  The ComparisonPolicy passed as (possible) second template parameter must be a functor
137  capable of being constructed from a bool (*)(flag_Type const&, flag_Type const &)
138  and so that bool operator()(flag_Type const&, flag_Type const &) is defined.
139  By default it is a boost function and the class uses the testOneSet policy by default
140  Usage: if you want a predicate that tests if a boolean flag is equal to a given flag MYFLAG
141  you create a object of type
142 
143 @code
144  EntityFlagInterrogator<faceType> interrogator(MYFLAG,Flags::testAllSet)
145 
146  interrogator(myFace); // true if flags of myface all all equal to MYFLAG
147 @endcode
148 
149  which can now be used on all std algorithms operating on containers of mesh entities
150 
151  @author Luca Formaggia
152  */
153 template < typename MeshEntity,
154  typename ComparisonPolicy = std::function<bool (flag_Type, flag_Type)> >
156 {
157 public:
158  typedef ComparisonPolicy comparisonPolicy_Type;
159 
161  ComparisonPolicy const& p = ComparisonPolicy ( &Flag::testOneSet ) ) :
162  M_flag ( flag ), M_policy ( p ) {}
163 
164  bool operator() ( const MeshEntity& entity ) const
165  {
166  return M_policy ( entity.flag(), M_flag );
167  }
168 
169 private:
171  const ComparisonPolicy M_policy;
172 };
173 
174 //! A simple predicate to test the marker ID flag
175 /*!
176  @prerequisite MeshEntity must have a method markerID_Type markerID();
177 
178  The ComparisonPolicy passed as (possible) second template parameter must be a functor
179  capable of being constructed from a bool (*)(markerID_Type const&, entityflag_Type const &)
180  and so that bool operator()(markerID_Type const&, markerID_Type const &) is defined.
181  By default we use the std::equal_to functor
182 
183  Usage: if you want a predicate that tests if an markerID is equal to a given flag MYFLAG
184  you create a object of type
185 
186 @code
187  EntityMarkerIDInterrogator<face_Type,ComparisonPolicy>(MYFLAG,mycomparisonpolicy())
188 @endcode
189 
190  which can now be used on all std algorithms operating on containers of mesh entities
191 
192  @author Luca Formaggia
193  */
194 template < typename MeshEntity,
195  typename ComparisonPolicy = std::function< bool (markerID_Type, markerID_Type)> >
197 {
198 public:
199  typedef ComparisonPolicy comparisonPolicy_Type;
200 
201  EntityMarkerIDInterrogator ( markerID_Type flag, ComparisonPolicy const& p = std::equal_to<markerID_Type>() ) :
202  M_flag ( flag ), M_policy ( p ) {}
203 
204  bool operator() ( const MeshEntity& entity ) const
205  {
206  return M_policy ( entity.markerID(), M_flag );
207  }
208 
209 private:
211  ComparisonPolicy const M_policy;
212 };
213 /**@} */
214 } // End Predicates
215 
216 // MeshEntityContainer
217 /*!
218  @author Luca Formaggia
219 
220  The class is a wrap up of Standard Library vector class.
221  Its role is to held meshEntities.
222  Its old name VectorSimple has been changed to MeshEntityContainer
223  Any other use of class is deprecated and it should be replaced by std::vector<T>
224 
225  */
226 
227 template <typename DataType, class Allocator = std::allocator<DataType> >
228 class MeshEntityContainer : public std::vector<DataType, Allocator>
229 {
230 public:
231 
232  //! @name Public Types
233  //@{
234 
235  typedef DataType data_Type;
236  typedef std::vector<DataType, Allocator> vector_Type;
237  typedef typename vector_Type::size_type size_type;
238  typedef typename vector_Type::value_type value_type;
239  typedef typename vector_Type::reference reference;
241  typedef typename vector_Type::iterator iterator;
244  typedef typename vector_Type::pointer pointer;
248  //@}
249 
250  //! @name Constructor & Destructor
251  //@{
252 
253  //! Empty Constructor
255 
256  //! Constructor
257  /*!
258  @param vectorSize size of the vector
259  */
260  explicit MeshEntityContainer ( size_type vectorSize ) : vector_Type ( vectorSize ) {}
261 
262  //! Copy constructor
263  /*!
264  @param vector MeshEntityContainer vector to copy
265  */
266  MeshEntityContainer ( const MeshEntityContainer<DataType, Allocator>& vector );
267 
268  //! Constructor
269  /*!
270  Construct by copying a Standard Library vector
271  @param vector Standard Library vector
272  */
273  explicit MeshEntityContainer ( const vector_Type& vector );
274 
275  //! Destructor
277 
278  //@}
279 
280 
281  //! @name Operators
282  //@{
283 
284  //! Assignment operator
285  /*!
286  Copies source MeshEntityContainer vector into "this"
287  @param vector MeshEntityContainer vector
288  @return Reference to a new MeshEntityContainer vector with the same
289  content of MeshEntityContainer vector
290  */
291  MeshEntityContainer<DataType, Allocator>& operator= ( const MeshEntityContainer<DataType, Allocator>& vector );
292 
293  //! Access operator
294  /*!
295  Example: a(10)=90; // a[10] will contain 90.0
296  @param i index of the element of the MeshEntityContainer vector
297  @return a vector reference
298  @note deprecated
299  @todo Eliminate!
300  */
302  {
303  return ( this->operator[] ( i ) );
304  }
305 
306  //! Const access operator
307  /*!
308  Example: a(10)=90; // a[10] will contain 90.0
309  @param i index of the element of the MeshEntityContainer vector
310  @return a vector const reference
311  @note deprecated
312  @todo Eliminate!
313  */
314  const_reference operator() ( size_type const i ) const
315  {
316  return ( this->operator[] ( i ) );
317  }
318 
319  //@}
320 
321 
322  //! @name Methods
323  //@{
324 
325  //! Completely clear out the container, returning memory to the system
326  inline void destroyData();
327 
328  //! trims the container so that capacity almost equals size
329  void trim()
330  {
331  MeshEntityContainer<DataType, Allocator> (*this).swap ( *this );
332  }
333 
334  //! It sets the capacity of the container
335  //! It returns a bool to allow to test whether the container data pool
336  //! has changed
337  //! since in this case pointers to the container elements are invalidated
338  //! It does not change the value of the elements currently stored, nor the container size
339  //! @param size the new capacity of the container
340  //! @return a bool which is true if the data pool has changed
341  bool setMaxNumItems ( UInt size );
342 
343  /** @name Extractors
344  * Utilities to extract from the SimpleVector. They rely on std::algorithms
345  */
346  //@{
347  /** General extractor.
348  * It extracts the a vector of pointers to the stored entities for which a
349  * predicate: i.e. a pointer to function with signature
350  * @code
351  * bool predicate(DataType const &)
352  * @endcode
353  * or functor object with
354  * @code
355  * bool operator()(DataType const &)
356  * @endcode
357  * returns true
358  *
359  * The template parameter is the Predicate type (automatically deduced)
360  * @code
361  * aPredicate p; // A certain predicate
362  * vector<face_Type *> theList=mesh.faceList.extractIdAccordingToPredicate(p);
363  * @endcode
364  *
365  * @param p The predicate
366  * @return A vector of pointers to constant mesh entities of the same type
367  * of those in the container
368  */
369  template<typename Predicate>
370  std::vector<DataType const*> extractAccordingToPredicate ( Predicate const& p ) const;
371 
372  template<typename Predicate>
374 
375  /** Entity Counter.
376  * It returns the number of stored entities for which a predicate
377  * returns true
378  * The template parameter is the Predicate type (automatically deduced): a function object or
379  * a pointer to function taking a constant reference to a mesh entity and returning a bool
380  *
381  * @param p The predicate
382  * @return Number of entities in the container satisfying the predicate
383  */
384 
385  template<typename Predicate>
386  UInt countAccordingToPredicate ( Predicate const& p ) const;
387  /** @brief It extracts all elements that satisfy a condition on the flag
388  *
389  * It operates only container elements where the method
390  * flag_Type flag() is defined.
391  * Examples:
392  *
393  * @code
394  * #include "MeshEntity.hpp"
395  * v=sv.extractElementsWithFlag(PHYSICAL_BOUNDARY,Flag::testOneSet)
396  * @endcode
397  * will extracts all elements in the boundary
398  * @code
399  * v=sv.extractElementsWithFlag(PHYSICAL_BOUNDARY|INTERNAL_INTERFACE, testOneSet)
400  * @endcode
401  * will extracts all elements on the boundary or on an internal interface
402  *
403  * @param refFlag the flag against which the test is made
404  * @param policy. A functor/function pointer which implements
405  * bool policy(const flag_Type & inputFlag, const flag_Type & refFlag)
406  * Available policies are Flag::testOneSet and Flag::testAllSet (defined in Lifev.hpp)
407  * @return a vector containing the pointers to constant mesh entities in the container
408  * whose flag is set as that of refFlag according to the given policy
409  */
410  template<typename Policy>
411  std::vector<DataType const*>
413 
414  /*! @brief It counts all elements that satisfy a condition on the flag
415  *
416  * It only operates on container elements where the method
417  * flag_Type flag() is defined.
418  * Examples:
419  *
420  * @code
421  * #include "MeshEntity.hpp"
422  * Uint i=sv.countElementsWithFlag(PHYSICAL_BOUNDARY,Flag::testOneSet)
423  * @endcode
424  * will count all elements on the boundary
425  *
426  * @param refFlag the flag against which the test is made
427  * @param policy. A functor/function pointer which implements
428  * bool policy(const flag_Type & inputFlag, const flag_Type & refFlag)
429  * Available policies testOneSet and testAllSet (defined in Lifev.hpp)
430  * @return an unsigned integer
431  */
432  template<typename Policy>
433  UInt countElementsWithFlag ( const flag_Type& refFlag,
434  Policy const& policy = &Flag::testOneSet ) const;
435  //@}
436 
437  /*! @brief It counts all elements with a markerID
438  *
439  * @param markerID the markerID against which the test is made
440  * @param policy. A functor/function pointer which implements
441  * bool policy(const markerID_Type & inputMarkerID, const markerID_Type & refMarkerID)
442  * By default it uses std::equal_to
443  * @return an unsigned integer
444  */
445  template<typename Policy>
446  UInt countElementsWithMarkerID ( const markerID_Type& markerID,
447  const Policy& policy = std::equal_to<markerID_Type>() ) const;
448  //@}
449 
450  /** @name Changers
451  * Utilities that change the elements according to policies
452  */
453  //@{
454  /** Set element with certain flag set first
455  *
456  * It reorders the container starting from the given offset up to the end of the container
457  * so that elements with the given flag set are first. A policy must be passed.
458  * Typically either testOneSet or testAllSet. A policy object must have a method
459  * @code
460  * bool operator()(DataType const & i, DataType const & r)
461  * @endcode
462  * which compares the boolean flag i with the reference flag r.
463  * It fixes the id of the stored entities and it returns the newToOld array
464  * in case we need to fix some related id
465  *
466  * @param refFlag the reference flag against which comparison is made.
467  * @param offset We reorder only elements from offset to the end of the container.
468  * @param policy The policy we use for comparing the flag of the mesh entity with the
469  * reference flag.
470  * @return A pair with the new offset, i.e the starting point of the elements for which predicate
471  * was false, and a NewToOld vector with the new->old position. Entity now in position
472  * i was before in NewToOld[i].
473  *
474  */
475  template<typename Policy>
477  Policy const& policy = &Flag::testOneSet,
478  UInt offset = 0 );
479 
480  //! Changes content according to a given functor
481  /*!
482  * This method is here for people which do not remember how std::for_each works.
483  * It takes as argument a functor that must have the method
484  * @code
485  * void operator()(DataType & d)
486  * @endcode
487  * and which changes d according to the user will.
488  * @param fun The functor which implements the change
489  *
490  */
491  template<typename Functor>
492  void changeAccordingToFunctor ( Functor const& fun )
493  {
494  std::for_each ( this->begin(), this->end(), fun );
495  }
496 
497  //! Resets the id of the mesh entities so that it matches the position in the container
498  /**
499  * After its call the id of each mesh entity matches its position in the container.
500  * The mesh entity must have the method ID & id()
501  * @return a vector containing the association new->old. The entity that is now in position id
502  * was originally in position newtoold[id]
503  */
505  {
506  std::vector<ID> newToOld;
507  newToOld.reserve ( this->size() );
508  iterator a ( this->begin() ) ;
509  for ( UInt i = 0; i < this->size(); ++i )
510  {
511  ID old = a->localId();
512  (a++)->setLocalId ( i );
513  newToOld.push_back ( old );
514  }
515  return newToOld;
516  }
517  //@}
518 };
519 
520 namespace Utilities
521 {
522 /** @defgroup Utilities
523  * Some general Utilities on MeshEntityContainer
524  * @{
525  */
526 
527 /** Reorder according to a permutation vector.
528  * We can reorder a MeshEntityContainer by passing a permutation vector
529  * std::vector<ID> newToOld;
530  *
531  * The entity originally in position newtoold[id] will be moved to position id
532  * All ids (local id!) will be renumbered to reflect the new position in the
533  * container.
534  *
535  * @pre The permutation vector must be of the right size
536  * @pre The permutation vector must be a good permutation vector
537  */
538 template <typename EntityContainer >
539 void reorderAccordingToIdPermutation ( EntityContainer& container, std::vector<ID> const& newToOld )
540 {
541  ASSERT_BD ( newToOld.size() >= container.size() );
542  typedef typename EntityContainer::iterator it;
543  typedef typename EntityContainer::value_type meshEntity_Type;
544  std::vector<ID>::const_iterator start = newToOld.begin();
545  // Change the id's
546  for ( it i = container.begin(); i < container.end(); ++i)
547  {
548  i->setLocalId ( * (start++) );
549  }
550  // Fix the ordering
551  std::sort ( container.begin(),
552  container.end(),
553  Comparers::CompareAccordingToLocalId<meshEntity_Type, std::less<ID> >() );
554 }
555 
556 /** Fix pointers after permutation
557  * If a mesh entity contains pointers to other mesh entities (typically Points), after the renumbering of the
558  * referenced mesh entity (for instance using reorderAccordingToPermutation on Points) the address stored in
559  * the pointers will be wrong since it refers to the old numbering! This routine fixes it.
560  * It has to be called AFTER the reordering of the references mesh entities (i.e. the points) and NOT before.
561  *
562  * Example:
563  * @code
564  * reorderAccordingToIdPermutation(mesh.points(),newToOld);
565  * // Now all entities storing pointers to points are invalid!!
566  * fixAfterPermutation(mesh.faces(),mesh.points(),newToOld);
567  * //FIxed!
568 
569  * @endcode
570  */
571 template <typename EntityContainer, typename RefEntityContainer >
572 void fixAfterPermutation ( EntityContainer& container,
573  RefEntityContainer const& refcontainer,
574  std::vector<ID> const& newToOld )
575 {
576  // I need to build the inverse permutation
577  std::vector<ID> oldToNew ( newToOld.size() );
578  for ( UInt i = 0; i < newToOld.size(); ++i )
579  {
580  oldToNew[ newToOld[ i ] ] = i;
581  }
582  typedef typename EntityContainer::iterator it;
583  typedef typename EntityContainer::value_type meshEntity_Type;
584  const UInt numPoints = meshEntity_Type::geoShape_Type::S_numPoints;
585  for ( it i = container.begin(); i < container.end(); ++i )
586  {
587  for ( UInt j = 0; j < numPoints; ++j )
588  {
589  ID oldaddress = i->point ( j ).localId();
590  ID newaddress = oldToNew[ oldaddress ];
591  i->setPoint ( j, & ( refcontainer[ newaddress ] ) );
592  }
593  }
594 }
595 
596 ///! Fix pointers after shallow copy
597 /*!
598  * If a mesh entity contains pointers to other mesh entities (typically Points), after a shallow copy, for instance
599  * by the automatic copy constructor, the pointers may still refer to a wrong list of Points!
600  * This utility allows to change the situation and make the pointers to point to the new list of Points.
601  * By this utility the deep copy of a RegionMesh is now possible!
602  *
603  * Example:
604  * @code
605  * PointList newPoints(mesh.pointList); // deep copy since list stores Point(s)
606  * FaceList newFaces(mesh.faceList); // This is a shallow copy since we store Point*
607  * fixAfterShallowCopy(newFaces,newPoints); now the pointers point to newPoint
608  * @endcode
609  *
610  * @param container the entity container with the wrong pointers to Point
611  * @param newPointContainer the container with the list new Points
612  * @pre container must contain pointers to valid points
613  * @note For efficiency reason no consistency checks are made
614  */
615 template <typename EntityContainer, typename PointContainer >
616 void fixAfterShallowCopy ( EntityContainer& container, PointContainer const& newPointContainer )
617 {
618  typedef typename EntityContainer::iterator it;
619  typedef typename EntityContainer::value_type meshEntity_Type;
620  const UInt numPoints = meshEntity_Type::geoShape_Type::S_numPoints;
621 
622  for ( it i = container.begin(); i < container.end(); ++i )
623  for ( UInt j = 0; j < numPoints; ++j )
624  {
625  i->setPoint ( j, & ( newPointContainer[ i->point ( j ).localId() ] ) );
626  }
627 }
628 /* @}*/
629 }// End namespace Utilities
630 
631 
632 
633 //============================================================================
634 // IMPLEMENTATIONS
635 
636 // Constructors
637 //============================================================================
638 template <typename DataType, class Allocator>
639 MeshEntityContainer<DataType, Allocator>::MeshEntityContainer ( const MeshEntityContainer<DataType, Allocator>& vector )
640  : vector_Type ( vector )
641 {}
642 
643 
644 //============================================================================
645 // Operators
646 //============================================================================
647 template <typename DataType, class Allocator>
648 MeshEntityContainer<DataType, Allocator>&
649 MeshEntityContainer<DataType, Allocator>::operator= ( const MeshEntityContainer<DataType, Allocator>& vector )
650 {
651  vector_Type::operator= ( vector );
652  return *this;
653 }
654 
655 
656 //============================================================================
657 // Methods
658 //============================================================================
659 template <typename DataType, class Allocator>
660 void
661 MeshEntityContainer<DataType, Allocator>::destroyData()
662 {
663  this->clear();
664  this->vector_Type::swap ( vector_Type() );
665 }
666 
667 template<typename DataType, class Allocator>
668 bool MeshEntityContainer<DataType, Allocator>::setMaxNumItems ( UInt size )
669 {
670  bool _check = ( this->capacity() ) < size;
671  this->reserve ( size );
672  return _check;
673 }
674 
675 template<typename DataType, class Allocator>
676 template<typename Predicate>
677 std::vector<DataType const*>
678 MeshEntityContainer<DataType, Allocator>::extractAccordingToPredicate ( Predicate const& p ) const
679 {
680  UInt howmany = this->countAccordingToPredicate ( p );
681  std::vector<DataType const*> tmp;
682  tmp.reserve ( howmany );
683  for ( const_iterator i = this->begin(); i < this->end(); ++i )
684  if ( p (*i) )
685  {
686  tmp.push_back ( & (*i) );
687  }
688  return tmp;
689 }
690 
691 
692 template<typename DataType, class Allocator>
693 template<typename Predicate>
696 {
697  UInt howmany = this->countAccordingToPredicate ( p );
698  std::vector<DataType*> tmp;
699  tmp.reserve ( howmany );
700  indexes.reserve ( howmany );
701  for ( UInt i (0); i < this->size(); i++ )
702  {
703  //Saving the volume and the index if the predicate is true
704  if ( p ( this->at (i) ) )
705  {
706  tmp.push_back ( & (this->at (i) ) );
707  indexes.push_back ( i );
708  }
709  }
710 
711  return tmp;
712 }
713 
714 template<typename DataType, class Allocator>
715 template<typename Predicate>
716 UInt MeshEntityContainer<DataType, Allocator>::countAccordingToPredicate ( Predicate const& p ) const
717 {
718  return std::count_if ( this->begin(), this->end(), p );
719 }
720 
721 template<typename DataType, class Allocator>
722 template<typename Policy>
723 std::vector<DataType const*>
725  const Policy& policy ) const
726 {
727  Predicates::EntityFlagInterrogator<DataType> interrogator ( refFlag, policy );
728  return this->extractAccordingToPredicate ( interrogator );
729 }
730 
731 template<typename DataType, class Allocator>
732 template<typename Policy>
733 UInt MeshEntityContainer<DataType, Allocator>::countElementsWithFlag ( const flag_Type& refFlag,
734  const Policy& policy ) const
735 {
736  Predicates::EntityFlagInterrogator<DataType> interrogator ( refFlag, policy );
737  return this->countAccordingToPredicate ( interrogator );
738 }
739 
740 template<typename DataType, class Allocator>
741 template<typename Policy>
742 UInt MeshEntityContainer<DataType, Allocator>::countElementsWithMarkerID ( const markerID_Type& markerID,
743  const Policy& policy ) const
744 {
745  Predicates::EntityMarkerIDInterrogator<DataType> interrogator ( markerID, policy );
746  return this->countAccordingToPredicate ( interrogator );
747 }
748 
749 template<typename DataType, class Allocator>
750 template<typename Policy>
751 std::pair<UInt, std::vector<ID> >
753  Policy const& policy,
754  UInt offset )
755 {
756  iterator last = std::stable_partition ( this->begin() + offset,
757  this->end(),
758  Predicates::EntityFlagInterrogator<DataType> ( refFlag, policy ) );
759  std::vector<ID> newToOld = this->resetId();
760  return std::make_pair ( std::distance ( this->begin(), last), newToOld );
761 }
762 }/// end of LifeV namespace
763 
764 #endif /* _MESHENTITYCONTAINER_HH_ */
vector_Type::allocator_type allocator_type
std::vector< DataType, Allocator > vector_Type
vector_Type::reference reference
uint32_type flag_Type
bit-flag with up to 32 different flags
Definition: LifeV.hpp:197
#define ASSERT_BD(X)
Definition: LifeAssert.hpp:114
reference operator()(size_type const i)
Access operator.
A simple predicate to test the marker ID flag.
MeshEntityContainer< DataType, Allocator > & operator=(const MeshEntityContainer< DataType, Allocator > &vector)
Assignment operator.
const_reference operator()(size_type const i) const
Const access operator.
A simple predicate to test the boolean flag on a mesh entity.
MeshEntityContainer(size_type vectorSize)
Constructor.
bool operator()(MeshEntity const &a, MeshEntity const &b)
MeshEntityContainer(const MeshEntityContainer< DataType, Allocator > &vector)
Copy constructor.
bool operator()(MeshEntity const &a, MeshEntity const &b)
ID markerID_Type
markerID_Type is the type used to store the geometric entity marker IDs
Definition: Marker.hpp:81
void updateInverseJacobian(const UInt &iQuadPt)
void reorderAccordingToIdPermutation(EntityContainer &container, std::vector< ID > const &newToOld)
Reorder according to a permutation vector.
bool testOneSet(flag_Type const &inputFlag, flag_Type const &refFlag)
returns true if at least one flag set in refFlag is set in inputFlag
Definition: LifeV.hpp:216
EntityFlagInterrogator(flag_Type flag, ComparisonPolicy const &p=ComparisonPolicy(&Flag::testOneSet))
void changeAccordingToFunctor(Functor const &fun)
Changes content according to a given functor.
std::vector< DataType const * > extractAccordingToPredicate(Predicate const &p) const
General extractor.
vector_Type::const_pointer const_pointer
vector_Type::const_reference const_reference
std::vector< DataType * > extractAccordingToPredicateNonConstElement(Predicate const &p, std::vector< UInt > &indexes)
UInt countElementsWithFlag(const flag_Type &refFlag, Policy const &policy=&Flag::testOneSet) const
It counts all elements that satisfy a condition on the flag.
uint32_type ID
IDs.
Definition: LifeV.hpp:194
std::vector< UInt > resetId()
Resets the id of the mesh entities so that it matches the position in the container.
bool operator()(const MeshEntity &entity) const
UInt countElementsWithMarkerID(const markerID_Type &markerID, const Policy &policy=std::equal_to< markerID_Type >()) const
It counts all elements with a markerID.
CompareAccordingToMarker(Policy const &p=std::less< markerID_Type >())
Constructor.
vector_Type::const_reverse_iterator const_reverse_iterator
bool operator()(const MeshEntity &entity) const
std::pair< UInt, std::vector< ID > > reorderAccordingToFlag(const flag_Type &refFlag, Policy const &policy=&Flag::testOneSet, UInt offset=0)
Set element with certain flag set first.
void trim()
trims the container so that capacity almost equals size
flag related free functions and functors
Definition: LifeV.hpp:203
EntityMarkerIDInterrogator(markerID_Type flag, ComparisonPolicy const &p=std::equal_to< markerID_Type >())
MeshEntityContainer(const vector_Type &vector)
Constructor.
void destroyData()
Completely clear out the container, returning memory to the system.
vector_Type::value_type value_type
void fixAfterPermutation(EntityContainer &container, RefEntityContainer const &refcontainer, std::vector< ID > const &newToOld)
Fix pointers after permutation If a mesh entity contains pointers to other mesh entities (typically P...
std::vector< DataType const * > extractElementsWithFlag(const flag_Type &refFlag, Policy const &policy=&Flag::testOneSet) const
It extracts all elements that satisfy a condition on the flag.
UInt countAccordingToPredicate(Predicate const &p) const
Entity Counter.
void fixAfterShallowCopy(EntityContainer &container, PointContainer const &newPointContainer)
! Fix pointers after shallow copy
vector_Type::size_type size_type
vector_Type::iterator iterator
vector_Type::const_iterator const_iterator
MeshEntityContainer()
Empty Constructor.
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191
bool setMaxNumItems(UInt size)
It sets the capacity of the container It returns a bool to allow to test whether the container data p...
CompareAccordingToLocalId(Policy const &p=std::less< ID >())
Constructor.
vector_Type::reverse_iterator reverse_iterator