dune-mmesh 1.4.1-git
Loading...
Searching...
No Matches
grid/connectedcomponent.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_MMESH_GRID_CONNECTEDCOMPONENT_HH
4#define DUNE_MMESH_GRID_CONNECTEDCOMPONENT_HH
5
10#include <memory>
11#include <unordered_map>
12
13// MMesh includes
15
16namespace Dune {
17// Forward declarations
18template <int codim, int dim, class GridImp>
20
21//**********************************************************************
22//
23// --MMeshConnectedComponent
24// --Entity
25//
32template <class GridImp>
34 // dimension
35 static constexpr int dim = GridImp::dimension;
36
37 // type of scalars
38 using ctype = typename GridImp::ctype;
39
40 // type of the entity
41 using Entity = typename GridImp::template Codim<0>::Entity;
42
43 // type of the caching entity
45
46 // type of ids
48
49 public:
50 MMeshConnectedComponent() : componentNumber_(0) {}
51
52 MMeshConnectedComponent(const GridImp* mMesh, const Entity& entity)
53 : mMesh_(mMesh),
54 componentNumber_(entity.impl().hostEntity()->info().componentNumber) {
55 entities_.emplace_back(mMesh_, entity.impl().hostEntity());
56 CachingEntity& cachingEntity = entities_.back();
57
58 const IdType id = mMesh_->globalIdSet().id(entity);
59 entityIdToCachingPtr_.insert(std::make_pair(id, &cachingEntity));
60
61 insertNeighbors_(entity, cachingEntity);
62 }
63
65 // check for self-assignment
66 if (&other == this) return *this;
67
68 entities_ = other.entities_;
69 entityIdToCachingPtr_ = other.entityIdToCachingPtr_;
70 mMesh_ = other.mMesh_;
71 componentNumber_ = other.componentNumber_;
72
73 return *this;
74 }
75
76 void update(const Entity& entity) {
77 entities_.emplace_back(mMesh_, entity.impl().hostEntity());
78 CachingEntity& cachingEntity = entities_.back();
79
80 const IdType id = mMesh_->globalIdSet().id(entity);
81 entityIdToCachingPtr_.insert(std::make_pair(id, &cachingEntity));
82
83 insertNeighbors_(entity, cachingEntity);
84 }
85
86 const std::list<CachingEntity>& entities() const { return entities_; }
87
89 const std::list<CachingEntity>& children() const { return entities(); }
90
92 const std::size_t size() const { return entities_.size(); }
93
94 bool hasEntity(const Entity& entity) const {
95 const IdType& id = mMesh_->globalIdSet().id(entity);
96 return (entityIdToCachingPtr_.find(id) != entityIdToCachingPtr_.end());
97 }
98
99 std::size_t componentNumber() const { return componentNumber_; }
100
101 private:
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 ==
110 componentNumber_ &&
111 !neighbor.isNew()) {
112 const IdType id = mMesh_->globalIdSet().id(neighbor);
113
114 const auto& it = entityIdToCachingPtr_.find(id);
115
116 // if not found, add neighbor and start recursion
117 if (it == entityIdToCachingPtr_.end()) {
118 entities_.emplace_back(mMesh_, neighbor.impl().hostEntity());
119 CachingEntity& cachingNeighbor = entities_.back();
120
121 entityIdToCachingPtr_.insert(std::make_pair(id, &cachingNeighbor));
122
123 insertNeighbors_(neighbor, cachingNeighbor);
124 }
125 }
126 }
127 }
128
131 std::list<CachingEntity> entities_;
132 std::unordered_map<IdType, CachingEntity*> entityIdToCachingPtr_;
133
135 const GridImp* mMesh_;
136 std::size_t componentNumber_;
137
138}; // end of MMeshConnectedComponent
139
140} // namespace Dune
141
142#endif
The multi id class.
Grid< dim, dimworld, ct, GridFamily >::LeafGridView leafGridView(const Grid< dim, dimworld, ct, GridFamily > &grid)
const EntityType & entity() const
Implementation & impl()
StackAllocator< U, S > other
Definition grid/connectedcomponent.hh:19
The implementation of a connected component of entities in MMeshThe connected component stores a list...
Definition grid/connectedcomponent.hh:33
const std::list< CachingEntity > & children() const
Return list of caching entities in this component.
Definition grid/connectedcomponent.hh:89
const std::size_t size() const
Return number of caching entities in this component.
Definition grid/connectedcomponent.hh:92
void update(const Entity &entity)
Definition grid/connectedcomponent.hh:76
MMeshConnectedComponent()
Definition grid/connectedcomponent.hh:50
std::size_t componentNumber() const
Definition grid/connectedcomponent.hh:99
MMeshConnectedComponent & operator=(const MMeshConnectedComponent &other)
Definition grid/connectedcomponent.hh:64
const std::list< CachingEntity > & entities() const
Definition grid/connectedcomponent.hh:86
bool hasEntity(const Entity &entity) const
Definition grid/connectedcomponent.hh:94
MMeshConnectedComponent(const GridImp *mMesh, const Entity &entity)
Definition grid/connectedcomponent.hh:52
Definition multiid.hh:15
T make_pair(T... args)