Dune Core Modules (2.9.0)

tree.hh
1#ifndef DUNE_GRID_SPGRID_TREE_HH
2#define DUNE_GRID_SPGRID_TREE_HH
3
4#include <type_traits>
5
6#include <dune/grid/common/entity.hh>
7#include <dune/grid/common/entityiterator.hh>
8#include <dune/grid/common/intersection.hh>
9#include <dune/grid/common/intersectioniterator.hh>
10
11#include <dune/grid/spgrid/declaration.hh>
12#include <dune/grid/spgrid/entityinfo.hh>
13#include <dune/grid/spgrid/entity.hh>
14#include <dune/grid/spgrid/intersection.hh>
15
16namespace Dune
17{
18
19 // Forward Declarations
20 // --------------------
21
22 template< int codim, class Grid, class IsLeaf >
23 class EntityTree;
24
25 template< class Grid, class IsLeaf >
26 class IntersectionTree;
27
28
29
30 namespace __SPGrid
31 {
32
33 // Internal Forward Declarations
34 // -----------------------------
35
36 template< class, class >
37 class TreeIterator;
38
39
40
41 // TreeIterator for Entity
42 // -----------------------
43
44 template< int codim, int dim, class Grid, template< int, int, class > class EImpl, class IsLeaf >
45 class TreeIterator< Dune::Entity< codim, dim, Grid, EImpl >, IsLeaf >
46 {
47 typedef TreeIterator< Dune::Entity< codim, dim, Grid, EImpl >, IsLeaf > This;
48
49 public:
50 typedef typename std::remove_const< Grid >::type::Traits Traits;
51
52 static const int dimension = Traits::ReferenceCube::dimension;
53 static const int codimension = codim;
54 static const int mydimension = dimension - codimension;
55
56 typedef typename Traits::template Codim< codimension >::Entity Entity;
57
58 private:
59 typedef EImpl< codimension, dimension, Grid > EntityImpl;
60
61 public:
62 typedef typename EntityImpl::EntityInfo EntityInfo;
63 typedef typename EntityImpl::GridLevel GridLevel;
64
65 TreeIterator () = default;
66
67 explicit TreeIterator ( const IsLeaf &isLeaf ) : isLeaf_( isLeaf ) {}
68
69 explicit TreeIterator ( const Entity &entity, const IsLeaf &isLeaf )
70 : entityInfo_( entity.impl().entityInfo() ),
71 rootLevel_( &gridLevel() ),
72 isLeaf_( isLeaf )
73 {}
74
75 Entity dereference () const { return EntityImpl( entityInfo() ); }
76
77 bool equals ( const This &other ) const { return entityInfo().equals( other.entityInfo() ); }
78
79 void increment ()
80 {
81 if( isLeaf_( dereference() ) || (&gridLevel() == &leafLevel()) )
82 {
83 while( !isDone() )
84 {
85 if( entityInfo().nextChild() )
86 return;
87 entityInfo().up();
88 }
89 entityInfo() = EntityInfo();
90 }
91 else
92 entityInfo().down();
93 }
94
95 const EntityInfo &entityInfo () const { return entityInfo_; }
96 EntityInfo &entityInfo () { return entityInfo_; }
97
98 const GridLevel &gridLevel () const { return entityInfo().gridLevel(); }
99
100 private:
101 const GridLevel &leafLevel () const { return gridLevel().grid().leafLevel(); }
102
103 bool isDone () const { return (&gridLevel() == rootLevel_); }
104
105 EntityInfo entityInfo_;
106 const GridLevel *rootLevel_ = nullptr;
107 IsLeaf isLeaf_;
108 };
109
110
111
112 // TreeIterator for Intersection
113 // -----------------------------
114
115 template< class Grid, class IntersectionImpl, class IsLeaf >
116 class TreeIterator< Dune::Intersection< Grid, IntersectionImpl >, IsLeaf >
117 {
118 typedef TreeIterator< Dune::Intersection< Grid, IntersectionImpl >, IsLeaf > This;
119
120 public:
122
123 static const int dimension = Intersection::dimension;
124 static const int codimension = Intersection::codimension;
125 static const int mydimension = Intersection::mydimension;
126
127 typedef typename IntersectionImpl::EntityInfo EntityInfo;
128 typedef typename IntersectionImpl::ElementInfo ElementInfo;
129 typedef typename IntersectionImpl::GridLevel GridLevel;
130
131 TreeIterator () = default;
132
133 explicit TreeIterator ( int face, const IsLeaf &isLeaf )
134 : intersection_( IntersectionImpl( ElementInfo(), face ) )
135 {}
136
137 explicit TreeIterator ( const Intersection &intersection, const IsLeaf &isLeaf )
138 : intersection_( intersection ),
139 rootLevel_( &intersection.impl().gridLevel() ),
140 isLeaf_( isLeaf )
141 {}
142
143 TreeIterator ( const This & ) = default;
144 TreeIterator ( This && ) = default;
145
146 This &operator= ( const This & ) = default;
147 This &operator= ( This && ) = default;
148
149 const Intersection &dereference () const { return intersection_; }
150
151 bool equals ( const This &other ) const
152 {
153 return intersection_.impl().equals( other.intersection_.impl() );
154 }
155
156 void increment ()
157 {
158 if( isLeaf_( intersection_ ) || (&gridLevel() == &leafLevel()) )
159 {
160 EntityInfo info = entityInfo();
161 while( !isDone( info ) )
162 {
163 if( info.nextChild() )
164 {
165 intersection_.impl().setEntityInfo( info );
166 return;
167 }
168 info.up();
169 }
170 intersection_.impl().setInside( ElementInfo() );
171 }
172 else
173 {
174 EntityInfo info = entityInfo();
175 info.down();
176 intersection_.impl().setEntityInfo( info );
177 }
178 }
179
180 private:
181 EntityInfo entityInfo () const { return intersection_.impl().entityInfo(); }
182
183 const GridLevel &gridLevel () const { return entityInfo().gridLevel(); }
184 const GridLevel &leafLevel () const { return gridLevel().grid().leafLevel(); }
185
186 bool isDone ( const EntityInfo &entityInfo ) const { return (&entityInfo.gridLevel() == rootLevel_); }
187
188 Intersection intersection_;
189 const GridLevel *rootLevel_;
190 IsLeaf isLeaf_;
191 };
192
193 } // namespace __SPGrid
194
195
196
197 // EntityTree for SPGrid
198 // ---------------------
199
200 template< int codim, class ct, int dim, template< int > class Ref, class Comm, class IsLeaf >
201 class EntityTree< codim, SPGrid< ct, dim, Ref, Comm >, IsLeaf >
202 {
203 public:
204 typedef SPGrid< ct, dim, Ref, Comm > Grid;
205
208
209 EntityTree ( const Grid &grid, const Entity &entity, const IsLeaf &isLeaf )
210 : entity_( entity ), isLeaf_( isLeaf )
211 {}
212
213 Iterator begin () const { return __SPGrid::TreeIterator< Entity, IsLeaf >( entity_, isLeaf_ ); }
214 Iterator end () const { return __SPGrid::TreeIterator< Entity, IsLeaf >( isLeaf_ ); }
215
216 bool empty () const { return false; }
217
218 private:
219 Entity entity_;
220 IsLeaf isLeaf_;
221 };
222
223
224
225 // IntersectionTree for SPGrid
226 // ---------------------------
227
228 template< class ct, int dim, template< int > class Ref, class Comm, class IsLeaf >
229 class IntersectionTree< SPGrid< ct, dim, Ref, Comm >, IsLeaf >
230 {
231 public:
232 typedef SPGrid< ct, dim, Ref, Comm > Grid;
233
236
237 IntersectionTree ( const Grid &grid, const Intersection &intersection, const IsLeaf &isLeaf )
238 : intersection_( intersection ), isLeaf_( isLeaf )
239 {}
240
241 Iterator begin () const { return __SPGrid::TreeIterator< Intersection, IsLeaf >( intersection_, isLeaf_ ); }
242 Iterator end () const { return __SPGrid::TreeIterator< Intersection, IsLeaf >( intersection_.indexInInside(), isLeaf_ ); }
243
244 bool empty () const { return false; }
245
246 private:
247 Intersection intersection_;
248 IsLeaf isLeaf_;
249 };
250
251} // namespace Dune
252
253#endif // #ifndef DUNE_GRID_SPGRID_TREE_HH
interface class for an iterator over grid entities
Definition: entityiterator.hh:32
Mesh entities of codimension 0 ("elements") allow to visit all intersections with "neighboring" eleme...
Definition: intersectioniterator.hh:83
static constexpr int mydimension
dimension of the intersection
Definition: intersection.hh:207
constexpr auto equals(T1 &&t1, T2 &&t2)
Equality comparison.
Definition: hybridutilities.hh:402
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)