Loading [MathJax]/extensions/tex2jax.js

dune-mmesh (1.4)

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{
18 // Forward declarations
19 template<int codim, int dim, class GridImp>
20 class MMeshCachingEntity;
21
22 //**********************************************************************
23 //
24 // --MMeshConnectedComponent
25 // --Entity
26 //
32 template<class GridImp>
34 {
35 // dimension
36 static constexpr int dim = GridImp::dimension;
37
38 // type of scalars
39 using ctype = typename GridImp::ctype;
40
41 // type of the entity
42 using Entity = typename GridImp::template Codim<0>::Entity;
43
44 // type of the caching entity
45 using CachingEntity = MMeshCachingEntity< 0, dim, const GridImp >;
46
47 //type of ids
48 using IdType = MMeshImpl::MultiId;
49
50 public:
51 MMeshConnectedComponent() : componentNumber_(0) {}
52
53 MMeshConnectedComponent( const GridImp* mMesh, const Entity& entity )
54 : mMesh_( mMesh ),
55 componentNumber_( entity.impl().hostEntity()->info().componentNumber )
56 {
57 entities_.emplace_back( mMesh_, entity.impl().hostEntity() );
58 CachingEntity& cachingEntity = entities_.back();
59
60 const IdType id = mMesh_->globalIdSet().id( entity );
61 entityIdToCachingPtr_.insert( std::make_pair( id, &cachingEntity ) );
62
63 insertNeighbors_( entity, cachingEntity );
64 }
65
67 {
68 // check for self-assignment
69 if(&other == this)
70 return *this;
71
72 entities_ = other.entities_;
73 entityIdToCachingPtr_ = other.entityIdToCachingPtr_;
74 mMesh_ = other.mMesh_;
75 componentNumber_ = other.componentNumber_;
76
77 return *this;
78 }
79
80 void update( const Entity& entity )
81 {
82 entities_.emplace_back( mMesh_, entity.impl().hostEntity() );
83 CachingEntity& cachingEntity = entities_.back();
84
85 const IdType id = mMesh_->globalIdSet().id( entity );
86 entityIdToCachingPtr_.insert( std::make_pair( id, &cachingEntity ) );
87
88 insertNeighbors_( entity, cachingEntity );
89 }
90
91 const std::list< CachingEntity >& entities() const
92 {
93 return entities_;
94 }
95
97 const std::list< CachingEntity >& children() const
98 {
99 return entities();
100 }
101
103 const std::size_t size() const
104 {
105 return entities_.size();
106 }
107
108 bool hasEntity( const Entity& entity ) const
109 {
110 const IdType& id = mMesh_->globalIdSet().id( entity );
111 return ( entityIdToCachingPtr_.find( id ) != entityIdToCachingPtr_.end() );
112 }
113
114 std::size_t componentNumber() const
115 {
116 return componentNumber_;
117 }
118
119 private:
121 void insertNeighbors_(const Entity& entity, CachingEntity& cachingEntity)
122 {
123 for ( const auto& intersection : intersections( mMesh_->leafGridView(), entity ) )
124 if ( intersection.neighbor() )
125 {
126 const Entity& neighbor = intersection.outside();
127 if ( neighbor.impl().hostEntity()->info().componentNumber == componentNumber_ && !neighbor.isNew() )
128 {
129 const IdType id = mMesh_->globalIdSet().id( neighbor );
130
131 const auto& it = entityIdToCachingPtr_.find( id );
132
133 // if not found, add neighbor and start recursion
134 if ( it == entityIdToCachingPtr_.end() )
135 {
136 entities_.emplace_back( mMesh_, neighbor.impl().hostEntity() );
137 CachingEntity& cachingNeighbor = entities_.back();
138
139 entityIdToCachingPtr_.insert( std::make_pair( id, &cachingNeighbor ) );
140
141 insertNeighbors_( neighbor, cachingNeighbor );
142 }
143 }
144 }
145 }
146
149 std::list< CachingEntity > entities_;
150 std::unordered_map< IdType, CachingEntity* > entityIdToCachingPtr_;
151
153 const GridImp* mMesh_;
154 std::size_t componentNumber_;
155
156 }; // end of MMeshConnectedComponent
157
158} // namespace Dune
159
160#endif
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
The multi id class.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Apr 13, 22:42, 2025)