dune-spgrid  2.7
boundarysegmentiterator.hh
Go to the documentation of this file.
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
9 #include <dune/common/exceptions.hh>
10 #include <dune/common/typetraits.hh>
11 
12 //- dune-grid includes
13 #include <dune/grid/common/intersection.hh>
14 #include <dune/grid/common/intersectioniterator.hh>
15 
16 //- local includes
19 
20 
21 namespace Dune
22 {
23 
24  // SPBoundarySegmentIterator
25  // -------------------------
26 
27  template< class Grid >
29  {
30  // this type
32  // grid traits
33  typedef typename std::remove_const< Grid >::type::Traits Traits;
34 
35  // intersection implementation
37  // partition iterator for faces
39 
40  public:
42  typedef Dune::Intersection< Grid, IntersectionImpl > Intersection;
43 
45  typedef typename Intersection::Entity Entity;
46 
50  typedef typename IntersectionImpl::ctype ctype;
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:
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 >
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 >
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 >
130  : intersection_( other.intersectionImpl() ),
131  pit_( other.pit_ )
132  {}
133 
134 
135  template< class Grid >
136  inline const typename SPBoundarySegmentIterator< Grid >::This &
138  {
139  intersectionImpl() = other.intersectionImpl();
140  pit_ = other.pit_;
141  return *this;
142  }
143 
144 
145  template< class Grid >
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 >
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 >
177  {
178  return intersection_.indexInInside();
179  }
180 
181 
182  template< class Grid >
183  inline const typename SPBoundarySegmentIterator< Grid >::GridLevel &
185  {
186  return intersectionImpl().gridLevel();
187  }
188 
189 
190  template< class Grid >
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
Definition: iostream.hh:7
Definition: boundarysegmentiterator.hh:29
SPBoundarySegmentIterator(const GridLevel &gridLevel, int face, Begin)
constructor
Definition: boundarysegmentiterator.hh:112
Intersection::Entity Entity
entity type
Definition: boundarysegmentiterator.hh:45
const This & operator=(const This &other)
assignment operator
Definition: boundarysegmentiterator.hh:137
IntersectionImpl::EntityInfo EntityInfo
entity info type
Definition: boundarysegmentiterator.hh:52
PartitionIterator::End End
Definition: boundarysegmentiterator.hh:59
const Intersection & dereference() const
dereference intersection
Definition: boundarysegmentiterator.hh:147
void init(int face)
Definition: boundarysegmentiterator.hh:191
Dune::Intersection< Grid, IntersectionImpl > Intersection
intersection type
Definition: boundarysegmentiterator.hh:42
static const int dimension
grid dimension
Definition: boundarysegmentiterator.hh:48
IntersectionImpl::GridLevel GridLevel
grid level
Definition: boundarysegmentiterator.hh:54
IntersectionImpl::ctype ctype
single coordinate type
Definition: boundarysegmentiterator.hh:50
void increment()
iterator increment
Definition: boundarysegmentiterator.hh:161
const GridLevel & gridLevel() const
Definition: boundarysegmentiterator.hh:184
PartitionIterator::Begin Begin
Definition: boundarysegmentiterator.hh:58
GridLevel::PartitionList PartitionList
partition list
Definition: boundarysegmentiterator.hh:56
bool equals(const This &other) const
check for equality
Definition: boundarysegmentiterator.hh:154
int face() const
Definition: boundarysegmentiterator.hh:176
Definition: entity.hh:146
const EntityInfo & entityInfo() const
Definition: entity.hh:127
Definition: entityinfo.hh:24
const MultiIndex & id() const
Definition: entityinfo.hh:68
unsigned int partitionNumber() const
Definition: entityinfo.hh:73
Definition: gridlevel.hh:35
Definition: intersection.hh:37
static const int dimension
Definition: intersection.hh:47
ReferenceCube::ctype ctype
Definition: intersection.hh:45
Definition: partition.hh:79
static const int numFaces
Definition: referencecube.hh:55