Dune Core Modules (2.9.0)

boundarysegmentiterator.hh
1#ifndef DUNE_SPGRID_BOUNDARYSEGMENTITERATOR_HH
2#define DUNE_SPGRID_BOUNDARYSEGMENTITERATOR_HH
3
4//- C++ includes
5#include <cassert>
6#include <type_traits>
7
8//- dune-common includes
11
12//- dune-grid includes
13#include <dune/grid/common/intersection.hh>
14#include <dune/grid/common/intersectioniterator.hh>
15
16//- local includes
17#include <dune/grid/spgrid/intersection.hh>
18#include <dune/grid/spgrid/iterator.hh>
19
20
21namespace Dune
22{
23
24 // SPBoundarySegmentIterator
25 // -------------------------
26
27 template< class Grid >
28 class SPBoundarySegmentIterator
29 {
30 // this type
31 typedef SPBoundarySegmentIterator< Grid > This;
32 // grid traits
33 typedef typename std::remove_const< Grid >::type::Traits Traits;
34
35 // intersection implementation
36 typedef SPIntersection< Grid > IntersectionImpl;
37 // partition iterator for faces
38 typedef SPPartitionIterator< 1, Grid > PartitionIterator;
39
40 public:
43
45 typedef typename Intersection::Entity Entity;
46
48 static const int dimension = IntersectionImpl::dimension;
50 typedef typename IntersectionImpl::ctype ctype;
52 typedef typename IntersectionImpl::EntityInfo EntityInfo;
54 typedef typename IntersectionImpl::GridLevel GridLevel;
56 typedef typename GridLevel::PartitionList PartitionList;
57
58 typedef typename PartitionIterator::Begin Begin;
59 typedef typename PartitionIterator::End End;
60
61 private:
62 // number of faces
63 static const int numFaces = GridLevel::ReferenceCube::numFaces;
64
65 // partition
66 typedef typename PartitionList::Partition Partition;
67 // multi index
68 typedef typename PartitionList::MultiIndex MultiIndex;
69
70 public:
72 SPBoundarySegmentIterator ( const GridLevel &gridLevel, int face, Begin );
73 SPBoundarySegmentIterator ( const GridLevel &gridLevel, int face, End );
74
76 SPBoundarySegmentIterator ( const This &other );
78 const This &operator= ( const This &other );
79
81 bool equals ( const This &other ) const;
82
84 void increment ();
85
87 const Intersection &dereference () const;
88
89 protected:
90 int face () const;
91 const GridLevel &gridLevel () const;
92
93 void init ( int face );
94
95 private:
96 // return intersection implementation
97 IntersectionImpl &intersectionImpl () { return intersection_.impl(); }
98 // return intersection implementation
99 const IntersectionImpl &intersectionImpl () const { return intersection_.impl(); }
100
101 Intersection intersection_;
102 PartitionIterator pit_;
103 };
104
105
106
107 // Implementation of SPBoundarySegmentIterator
108 // -------------------------------------------
109
110 template< class Grid >
111 inline SPBoundarySegmentIterator< Grid >
112 ::SPBoundarySegmentIterator ( const GridLevel &gridLevel, int face, Begin )
113 : intersection_( IntersectionImpl( EntityInfo( gridLevel ), face ) ),
114 pit_( gridLevel, gridLevel.boundaryPartition( face ), Begin() )
115 {
116 init( face );
117 }
118
119
120 template< class Grid >
121 inline SPBoundarySegmentIterator< Grid >
122 ::SPBoundarySegmentIterator ( const GridLevel &gridLevel, int face, End )
123 : intersection_( IntersectionImpl( EntityInfo( gridLevel ), face+1 ) ),
124 pit_( gridLevel, gridLevel.boundaryPartition( face+1 ), Begin() )
125 {}
126
127
128 template< class Grid >
129 inline SPBoundarySegmentIterator< Grid >::SPBoundarySegmentIterator ( const This &other )
130 : intersection_( other.intersectionImpl() ),
131 pit_( other.pit_ )
132 {}
133
134
135 template< class Grid >
136 inline const typename SPBoundarySegmentIterator< Grid >::This &
137 SPBoundarySegmentIterator< Grid >::operator= ( const This &other )
138 {
139 intersectionImpl() = other.intersectionImpl();
140 pit_ = other.pit_;
141 return *this;
142 }
143
144
145 template< class Grid >
146 inline const typename SPBoundarySegmentIterator< Grid >::Intersection &
147 SPBoundarySegmentIterator< Grid >::dereference () const
148 {
149 return intersection_;
150 }
151
152
153 template< class Grid >
154 inline bool SPBoundarySegmentIterator< Grid >::equals ( const This &other ) const
155 {
156 return (pit_ == other.pit_);
157 }
158
159
160 template< class Grid >
161 inline void SPBoundarySegmentIterator< Grid >::increment ()
162 {
163 // get current face
164 int face = This::face();
165
166 // try to increment internal iterator
167 ++pit_;
168 while( !pit_ && (face < numFaces) )
169 pit_ = PartitionIterator( gridLevel(), gridLevel().boundaryPartition( ++face ), Begin() );
170
171 init( face );
172 }
173
174
175 template< class Grid >
176 inline int SPBoundarySegmentIterator< Grid >::face () const
177 {
178 return intersection_.indexInInside();
179 }
180
181
182 template< class Grid >
183 inline const typename SPBoundarySegmentIterator< Grid >::GridLevel &
184 SPBoundarySegmentIterator< Grid >::gridLevel () const
185 {
186 return intersectionImpl().gridLevel();
187 }
188
189
190 template< class Grid >
191 inline void SPBoundarySegmentIterator< Grid >::init ( int face )
192 {
193 if( !pit_ )
194 return;
195
196 // compute id
197 const SPEntity< 1, dimension, Grid > &entityImpl = ( *pit_ ).impl();
198 MultiIndex id = entityImpl.entityInfo().id();
199 const int i = face >> 1;
200 const int j = 2*(face & 1) - 1;
201 id[ i ] -= j;
202
203 // update intersection
204 const unsigned int number = entityImpl.entityInfo().partitionNumber();
205 EntityInfo entityInfo = EntityInfo( gridLevel(), id, number );
206 intersectionImpl() = IntersectionImpl( entityInfo, face );
207 }
208
209} // end namespace Dune
210
211#endif // #ifndef DUNE_SPGRID_BOUNDARYSEGMENTITERATOR_HH
GridImp::template Codim< 0 >::Entity Entity
Type of entity that this Intersection belongs to.
Definition: intersection.hh:192
A few common exception classes.
Traits for type conversions and type information.
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)