39 #ifndef _MESHENTITYCONTAINER_HH_ 40 #define _MESHENTITYCONTAINER_HH_ 45 #include <lifev/core/LifeV.hpp> 46 #include <lifev/core/mesh/Marker.hpp> 47 #include <lifev/core/mesh/MeshEntity.hpp> 71 template <
typename MeshEntity,
83 bool operator() ( MeshEntity
const& a, MeshEntity
const& b )
107 bool operator() ( MeshEntity
const& a, MeshEntity
const& b )
153 template <
typename MeshEntity,
194 template <
typename MeshEntity,
227 template <
typename DataType,
class Allocator = std::allocator<DataType> >
303 return (
this->operator[] ( i ) );
316 return (
this->operator[] ( i ) );
369 template<
typename Predicate>
372 template<
typename Predicate>
385 template<
typename Predicate>
410 template<
typename Policy>
432 template<
typename Policy>
445 template<
typename Policy>
475 template<
typename Policy>
491 template<
typename Functor>
494 std::for_each (
this->begin(),
this->end(), fun );
506 std::vector<ID> newToOld;
507 newToOld.reserve (
this->size() );
509 for (
UInt i = 0; i <
this->size(); ++i )
511 ID old = a->localId();
512 (a++)->setLocalId ( i );
513 newToOld.push_back ( old );
538 template <
typename EntityContainer >
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();
546 for ( it i = container.begin(); i < container.end(); ++i)
548 i->setLocalId ( * (start++) );
551 std::sort ( container.begin(),
571 template <
typename EntityContainer,
typename RefEntityContainer >
573 RefEntityContainer
const& refcontainer,
574 std::vector<ID>
const& newToOld )
577 std::vector<ID> oldToNew ( newToOld.size() );
578 for ( UInt i = 0; i < newToOld.size(); ++i )
580 oldToNew[ newToOld[ i ] ] = i;
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 )
587 for (
UInt j = 0; j < numPoints; ++j )
589 ID oldaddress = i->point ( j ).localId();
590 ID newaddress = oldToNew[ oldaddress ];
591 i->setPoint ( j, & ( refcontainer[ newaddress ] ) );
615 template <
typename EntityContainer,
typename PointContainer >
618 typedef typename EntityContainer::iterator it;
619 typedef typename EntityContainer::value_type meshEntity_Type;
620 const UInt numPoints = meshEntity_Type::geoShape_Type::S_numPoints;
622 for ( it i = container.begin(); i < container.end(); ++i )
623 for (
UInt j = 0; j < numPoints; ++j )
625 i->setPoint ( j, & ( newPointContainer[ i->point ( j ).localId() ] ) );
638 template <
typename DataType,
class Allocator>
647 template <
typename DataType,
class Allocator>
659 template <
typename DataType,
class Allocator>
667 template<
typename DataType,
class Allocator>
670 bool _check = (
this->capacity() ) < size;
671 this->reserve ( size );
676 template<
typename Predicate>
680 UInt howmany =
this->countAccordingToPredicate ( p );
681 std::vector<DataType
const*> tmp;
682 tmp.reserve ( howmany );
686 tmp.push_back ( & (*i) );
693 template<
typename Predicate>
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++ )
704 if ( p (
this->at (i) ) )
706 tmp.push_back ( & (
this->at (i) ) );
707 indexes.push_back ( i );
715 template<
typename Predicate>
718 return std::count_if (
this->begin(),
this->end(), p );
722 template<
typename Policy>
727 Predicates::EntityFlagInterrogator<DataType> interrogator ( refFlag, policy );
728 return this->extractAccordingToPredicate ( interrogator );
732 template<
typename Policy>
734 const Policy& policy )
const 736 Predicates::EntityFlagInterrogator<DataType> interrogator ( refFlag, policy );
737 return this->countAccordingToPredicate ( interrogator );
741 template<
typename Policy>
743 const Policy& policy )
const 745 Predicates::EntityMarkerIDInterrogator<DataType> interrogator ( markerID, policy );
746 return this->countAccordingToPredicate ( interrogator );
750 template<
typename Policy>
756 iterator last = std::stable_partition (
this->begin() + offset,
758 Predicates::EntityFlagInterrogator<DataType> ( refFlag, policy ) );
759 std::vector<ID> newToOld =
this->resetId();
760 return std::make_pair ( std::distance (
this->begin(), last), newToOld );
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
reference operator()(size_type const i)
Access operator.
Compare according to local ID.
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
ComparisonPolicy comparisonPolicy_Type
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
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
markerID_Type const M_flag
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.
vector_Type::pointer pointer
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.
~MeshEntityContainer()
Destructor.
const ComparisonPolicy M_policy
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
EntityMarkerIDInterrogator(markerID_Type flag, ComparisonPolicy const &p=std::equal_to< markerID_Type >())
Compare according to Marker ID.
ComparisonPolicy const M_policy
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
ComparisonPolicy comparisonPolicy_Type
MeshEntityContainer()
Empty Constructor.
uint32_type UInt
generic unsigned integer (used mainly for addressing)
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