3#ifndef DUNE_MMESH_GRID_CONNECTEDCOMPONENT_HH
4#define DUNE_MMESH_GRID_CONNECTEDCOMPONENT_HH
11#include <unordered_map>
19 template<
int codim,
int dim,
class Gr
idImp>
20 class MMeshCachingEntity;
32 template<
class Gr
idImp>
36 static constexpr int dim = GridImp::dimension;
39 using ctype =
typename GridImp::ctype;
42 using Entity =
typename GridImp::template Codim<0>::Entity;
45 using CachingEntity = MMeshCachingEntity< 0, dim, const GridImp >;
48 using IdType = MMeshImpl::MultiId;
55 componentNumber_( entity.impl().hostEntity()->info().componentNumber )
57 entities_.emplace_back( mMesh_, entity.impl().hostEntity() );
58 CachingEntity& cachingEntity = entities_.back();
60 const IdType
id = mMesh_->globalIdSet().id( entity );
61 entityIdToCachingPtr_.insert( std::make_pair(
id, &cachingEntity ) );
63 insertNeighbors_( entity, cachingEntity );
72 entities_ = other.entities_;
73 entityIdToCachingPtr_ = other.entityIdToCachingPtr_;
74 mMesh_ = other.mMesh_;
75 componentNumber_ = other.componentNumber_;
80 void update(
const Entity& entity )
82 entities_.emplace_back( mMesh_, entity.impl().hostEntity() );
83 CachingEntity& cachingEntity = entities_.back();
85 const IdType
id = mMesh_->globalIdSet().id( entity );
86 entityIdToCachingPtr_.insert( std::make_pair(
id, &cachingEntity ) );
88 insertNeighbors_( entity, cachingEntity );
91 const std::list< CachingEntity >& entities()
const
97 const std::list< CachingEntity >&
children()
const
105 return entities_.size();
108 bool hasEntity(
const Entity& entity )
const
110 const IdType&
id = mMesh_->globalIdSet().id( entity );
111 return ( entityIdToCachingPtr_.find(
id ) != entityIdToCachingPtr_.end() );
114 std::size_t componentNumber()
const
116 return componentNumber_;
121 void insertNeighbors_(
const Entity& entity, CachingEntity& cachingEntity)
123 for (
const auto& intersection : intersections( mMesh_->leafGridView(), entity ) )
124 if ( intersection.neighbor() )
126 const Entity& neighbor = intersection.outside();
127 if ( neighbor.impl().hostEntity()->info().componentNumber == componentNumber_ && !neighbor.isNew() )
129 const IdType
id = mMesh_->globalIdSet().id( neighbor );
131 const auto& it = entityIdToCachingPtr_.find(
id );
134 if ( it == entityIdToCachingPtr_.end() )
136 entities_.emplace_back( mMesh_, neighbor.impl().hostEntity() );
137 CachingEntity& cachingNeighbor = entities_.back();
139 entityIdToCachingPtr_.insert( std::make_pair(
id, &cachingNeighbor ) );
141 insertNeighbors_( neighbor, cachingNeighbor );
149 std::list< CachingEntity > entities_;
150 std::unordered_map< IdType, CachingEntity* > entityIdToCachingPtr_;
153 const GridImp* mMesh_;
154 std::size_t componentNumber_;
The implementation of a connected component of entities in MMeshThe connected component stores a list...
Definition: connectedcomponent.hh:34
const std::list< CachingEntity > & children() const
Return list of caching entities in this component.
Definition: connectedcomponent.hh:97
const std::size_t size() const
Return number of caching entities in this component.
Definition: connectedcomponent.hh:103