3#ifndef DUNE_MMESH_GRID_CONNECTEDCOMPONENT_HH
4#define DUNE_MMESH_GRID_CONNECTEDCOMPONENT_HH
11#include <unordered_map>
18template <
int codim,
int dim,
class Gr
idImp>
19class MMeshCachingEntity;
32template <
class Gr
idImp>
35 static constexpr int dim = GridImp::dimension;
38 using ctype =
typename GridImp::ctype;
41 using Entity =
typename GridImp::template Codim<0>::Entity;
44 using CachingEntity = MMeshCachingEntity<0, dim, const GridImp>;
47 using IdType = MMeshImpl::MultiId;
54 componentNumber_(entity.impl().hostEntity()->info().componentNumber) {
55 entities_.emplace_back(mMesh_, entity.impl().hostEntity());
56 CachingEntity& cachingEntity = entities_.back();
58 const IdType
id = mMesh_->globalIdSet().id(entity);
59 entityIdToCachingPtr_.insert(std::make_pair(
id, &cachingEntity));
61 insertNeighbors_(entity, cachingEntity);
66 if (&other ==
this)
return *
this;
68 entities_ = other.entities_;
69 entityIdToCachingPtr_ = other.entityIdToCachingPtr_;
70 mMesh_ = other.mMesh_;
71 componentNumber_ = other.componentNumber_;
76 void update(
const Entity& entity) {
77 entities_.emplace_back(mMesh_, entity.impl().hostEntity());
78 CachingEntity& cachingEntity = entities_.back();
80 const IdType
id = mMesh_->globalIdSet().id(entity);
81 entityIdToCachingPtr_.insert(std::make_pair(
id, &cachingEntity));
83 insertNeighbors_(entity, cachingEntity);
86 const std::list<CachingEntity>& entities()
const {
return entities_; }
89 const std::list<CachingEntity>&
children()
const {
return entities(); }
92 const std::size_t
size()
const {
return entities_.size(); }
94 bool hasEntity(
const Entity& entity)
const {
95 const IdType&
id = mMesh_->globalIdSet().id(entity);
96 return (entityIdToCachingPtr_.find(
id) != entityIdToCachingPtr_.end());
99 std::size_t componentNumber()
const {
return componentNumber_; }
104 void insertNeighbors_(
const Entity& entity, CachingEntity& cachingEntity) {
105 for (
const auto& intersection :
106 intersections(mMesh_->leafGridView(), entity))
107 if (intersection.neighbor()) {
108 const Entity& neighbor = intersection.outside();
109 if (neighbor.impl().hostEntity()->info().componentNumber ==
112 const IdType
id = mMesh_->globalIdSet().id(neighbor);
114 const auto& it = entityIdToCachingPtr_.find(
id);
117 if (it == entityIdToCachingPtr_.end()) {
118 entities_.emplace_back(mMesh_, neighbor.impl().hostEntity());
119 CachingEntity& cachingNeighbor = entities_.back();
121 entityIdToCachingPtr_.insert(std::make_pair(
id, &cachingNeighbor));
123 insertNeighbors_(neighbor, cachingNeighbor);
131 std::list<CachingEntity> entities_;
132 std::unordered_map<IdType, CachingEntity*> entityIdToCachingPtr_;
135 const GridImp* mMesh_;
136 std::size_t componentNumber_;
The implementation of a connected component of entities in MMeshThe connected component stores a list...
Definition: connectedcomponent.hh:33
const std::list< CachingEntity > & children() const
Return list of caching entities in this component.
Definition: connectedcomponent.hh:89
const std::size_t size() const
Return number of caching entities in this component.
Definition: connectedcomponent.hh:92