All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
entity.hh
1 // -*- mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=2 sw=2 sts=2:
3 #ifndef DUNE_POLYHEDRALGRID_ENTITY_HH
4 #define DUNE_POLYHEDRALGRID_ENTITY_HH
5 
6 //- dune-common includes
7 #include <dune/common/typetraits.hh>
8 
9 //- dune-grid includes
10 #include <dune/grid/common/entity.hh>
11 
12 namespace Dune
13 {
14 
15  // PolyhedralGridEntityBasic
16  // -----------------
17 
22  template< int codim, int dim, class Grid >
24  {
25  protected:
26  typedef typename std::remove_const< Grid >::type::Traits Traits;
27 
28  public:
32  static const int codimension = codim;
35  static const int dimension = Traits::dimension;
37  static const int mydimension = dimension - codimension;
39  static const int dimensionworld = Traits::dimensionworld;
40 
46  typedef typename Traits::ctype ctype;
48 
49  typedef typename Traits::Index Index;
50 
52  typedef typename Grid::template Codim< codimension >::Entity Entity;
53 
55  typedef typename Grid::template Codim< codimension >::EntitySeed EntitySeed;
57  typedef typename Traits::template Codim< codimension >::Geometry Geometry;
58  typedef typename Traits::template Codim< codimension >::GeometryImpl GeometryImpl;
59 
62  protected:
63  // type of extra data, e.g. a pointer to grid (here empty)
64  typedef typename Traits::ExtraData ExtraData;
65 
66  public:
72  : data_( nullptr ),
73  seed_()
74  {}
75 
77  explicit PolyhedralGridEntityBasic ( ExtraData data )
78  : data_( data ),
79  seed_()
80  {}
81 
84  PolyhedralGridEntityBasic ( ExtraData data, const EntitySeed& seed )
85  : data_( data )
86  , seed_( seed )
87  {}
88 
98  GeometryType type () const
99  {
100  return data()->geomTypes(codimension)[0];
101  }
102 
104  int level () const
105  {
106  return 0;
107  }
108 
110  PartitionType partitionType () const
111  {
112  return InteriorEntity; // data()->partitionType( *this );
113  }
114 
117  {
118  return Geometry( GeometryImpl( data(), seed_ ) );
119  }
120 
122  EntitySeed seed () const { return seed_; }
123 
129  ExtraData data() const { return data_; }
130 
131  Index index () const { return seed_.index(); }
132 
135  bool equals(const PolyhedralGridEntityBasic& other) const
136  {
137  return seed_.equals(other.seed_);
138  }
139 
140  protected:
141  ExtraData data_;
142  EntitySeed seed_;
143  };
144 
145 
146 
147  // PolyhedralGridEntity
148  // ------------
149 
150  template< int codim, int dim, class Grid >
151  class PolyhedralGridEntity : public PolyhedralGridEntityBasic< codim, dim, Grid >
152  {
154  protected:
155  typedef typename std::remove_const< Grid >::type::Traits Traits;
156 
157  protected:
158  // type of extra data, e.g. a pointer to grid (here empty)
159  typedef typename Traits::ExtraData ExtraData;
160 
161  using Base::seed_;
162  public:
163  typedef typename Base :: EntitySeed EntitySeed;
164  using Base :: codimension ;
165  using Base :: data ;
166 
168  : Base()
169  {}
170 
171  explicit PolyhedralGridEntity ( ExtraData data )
172  : Base( data )
173  {}
174 
175  PolyhedralGridEntity ( ExtraData data, const EntitySeed& seed )
176  : Base( data, seed )
177  {}
178 
179  unsigned int subEntities( const unsigned int cd ) const
180  {
181  if( cd == Base :: codimension )
182  return 1;
183  else
184  return data()->subEntities( seed_, cd );
185  }
186 
187  template< int cd >
188  typename Grid::template Codim< cd >::EntityPointer
189  subEntity ( int i ) const
190  {
191  typedef typename Traits::template Codim< cd >::EntityPointerImpl EntityPointerImpl;
192  typedef typename Traits::template Codim< cd >::EntityImpl EntityImpl;
193  return EntityPointerImpl( EntityImpl( data(), data()->template subEntitySeed< cd >( seed_, i ) ) );
194  }
195  };
196 
197 
198  // PolyhedralGridEntity for codimension 0
199  // ----------------------------------
200 
205  template< int dim, class Grid >
206  class PolyhedralGridEntity< 0, dim, Grid > : public PolyhedralGridEntityBasic< 0, dim, Grid >
207  {
210 
211  protected:
212  typedef typename Base::Traits Traits;
213 
214  // type of extra data, e.g. a pointer to grid (here empty)
215  typedef typename Base::ExtraData ExtraData;
216 
217  using Base::seed_;
218  public:
219  using Base::codimension ;
220  using Base::data ;
221 
222  protected:
223  typedef typename Traits :: LeafIntersectionIteratorImpl LeafIntersectionIteratorImpl;
224  typedef typename Traits::template Codim< codimension >::LocalGeometryImpl LocalGeometryImpl;
225 
226  public:
230  typedef typename Base :: EntitySeed EntitySeed;
231 
233  typedef typename Traits::template Codim< codimension >::LocalGeometry LocalGeometry;
235  typedef typename Traits::template Codim< codimension >::Entity Entity;
237  typedef typename Traits::template Codim< codimension >::EntityPointer EntityPointer;
238 
240  typedef typename Traits::HierarchicIterator HierarchicIterator;
242  typedef typename Traits::LeafIntersectionIterator LeafIntersectionIterator;
244  typedef typename Traits::LevelIntersectionIterator LevelIntersectionIterator;
245 
253  : Base()
254  {}
255 
257  explicit PolyhedralGridEntity ( ExtraData data )
258  : Base( data )
259  {}
260 
262  PolyhedralGridEntity ( ExtraData data, const EntitySeed& seed )
263  : Base( data, seed )
264  {}
265 
268  const This& dereference() const
269  { return *this; }
270 
271  This& dereference()
272  { return *this; }
273 
274  unsigned int subEntities( const unsigned int codim ) const
275  {
276  if( codim == 0 )
277  return 1;
278  else
279  return data()->subEntities( seed_, codim );
280  }
281 
282  template< int codim >
283  int count () const
284  {
285  return subEntities( codim );
286  }
287 
288  template< int codim >
289  typename Grid::template Codim< codim >::EntityPointer
290  subEntity ( int i ) const
291  {
292  typedef typename Traits::template Codim< codim >::EntityPointerImpl EntityPointerImpl;
293  typedef typename Traits::template Codim< codim >::EntityImpl EntityImpl;
294  return EntityPointerImpl( EntityImpl( data(), data()->template subEntitySeed< codim >( seed_, i ) ) );
295  }
296 
297  bool hasBoundaryIntersections () const
298  {
299  const int faces = subEntities( 1 );
300  for( int i=0; i<faces; ++i )
301  {
302 #if DUNE_VERSION_NEWER(DUNE_GRID,2,4)
303  if( !this->template subEntity< 1 >( i ).seed().isValid() )
304 #else
305  if( !this->template subEntity< 1 >( i )->seed().isValid() )
306 #endif
307  return true;
308  }
309  return false;
310  }
311 
312 #if ! DUNE_VERSION_NEWER(DUNE_GRID,2,4)
313  LeafIntersectionIterator ibegin () const
314  {
315  return LeafIntersectionIterator( LeafIntersectionIteratorImpl( data(), seed_, true ) );
316  }
317 
318  LeafIntersectionIterator iend () const
319  {
320  return LeafIntersectionIterator( LeafIntersectionIteratorImpl( data(), seed_, false ) );
321  }
322 
323  LeafIntersectionIterator ileafbegin () const { return ibegin(); }
324  LevelIntersectionIterator ilevelbegin () const { return ibegin(); }
325 
326  LeafIntersectionIterator ileafend () const { return iend(); }
327  LevelIntersectionIterator ilevelend () const { return iend(); }
328 #endif
329 
330  bool isLeaf () const
331  {
332  return true;
333  }
334 
335  EntityPointer father () const
336  {
337  DUNE_THROW(InvalidStateException,"no father available");
338  typedef typename Traits::template Codim< 0 >::EntityImpl EntityImpl;
339  typedef typename Traits::template Codim< 0 >::EntityPointerImpl EntityPointerImpl;
340  return EntityPointer( EntityPointerImpl( EntityImpl( data() ) ) );
341  }
342 
343  bool hasFather () const
344  {
345  return false;
346  }
347 
348  LocalGeometry geometryInFather () const
349  {
350  DUNE_THROW(InvalidStateException,"no father available");
351  return LocalGeometry( LocalGeometryImpl( data() ) );
352  }
353 
354  HierarchicIterator hbegin ( int maxLevel ) const
355  {
356  return hend( maxLevel );
357  }
358 
359  HierarchicIterator hend ( int ) const
360  {
361  typedef typename Traits :: HierarchicIteratorImpl HierarchicIteratorImpl ;
362  return HierarchicIterator( HierarchicIteratorImpl( data(), false ) );
363  }
364 
365  bool isRegular () const
366  {
367  return true;
368  }
369 
370  bool isNew () const
371  {
372  return false;
373  }
374 
375  bool mightVanish () const
376  {
377  return false;
378  }
379 
382  };
383 
384 
385 } // namespace Dune
386 
387 #endif // #ifndef DUNE_POLYHEDRALGRID_ENTITY_HH
static const int codimension
codimensioon of the entity
Definition: entity.hh:33
EntitySeed seed() const
return EntitySeed
Definition: entity.hh:122
PolyhedralGridEntityBasic(ExtraData data)
construct a null entity with data pointer
Definition: entity.hh:77
Traits::template Codim< codimension >::EntityPointer EntityPointer
type of corresponding entity
Definition: entity.hh:237
Traits::LeafIntersectionIterator LeafIntersectionIterator
type of leaf intersection iterator
Definition: entity.hh:242
Traits::LevelIntersectionIterator LevelIntersectionIterator
type of level intersection iterator
Definition: entity.hh:244
Traits::HierarchicIterator HierarchicIterator
type of hierarchic iterator
Definition: entity.hh:240
static const int dimensionworld
dimension of the world
Definition: entity.hh:39
PolyhedralGridEntity()
construct a null entity
Definition: entity.hh:252
Traits::template Codim< codimension >::Geometry Geometry
type of corresponding geometry
Definition: entity.hh:57
PolyhedralGridEntity(ExtraData data, const EntitySeed &seed)
construct an initialized entity
Definition: entity.hh:262
Definition: entity.hh:23
PolyhedralGridEntityBasic()
construct a null entity
Definition: entity.hh:71
PartitionType partitionType() const
obtain the partition type of this entity
Definition: entity.hh:110
Traits::template Codim< codimension >::Entity Entity
type of corresponding entity
Definition: entity.hh:235
static const int mydimension
dimension of the entity
Definition: entity.hh:37
static const int dimension
dimension of the grid
Definition: entity.hh:35
PolyhedralGridEntityBasic(ExtraData data, const EntitySeed &seed)
construct an initialized entity
Definition: entity.hh:84
Traits::ctype ctype
coordinate type of the grid
Definition: entity.hh:47
Geometry geometry() const
obtain the geometry of this entity
Definition: entity.hh:116
Grid::template Codim< codimension >::EntitySeed EntitySeed
type of corresponding entity seed
Definition: entity.hh:55
Traits::template Codim< codimension >::LocalGeometry LocalGeometry
type of corresponding local geometry
Definition: entity.hh:233
PolyhedralGridEntity(ExtraData data)
construct a null entity with data pointer
Definition: entity.hh:257
construct a null entity
Definition: entity.hh:206
GeometryType type() const
obtain the name of the corresponding reference element
Definition: entity.hh:98
Definition: entity.hh:151
Grid::template Codim< codimension >::Entity Entity
type of entity
Definition: entity.hh:52
int level() const
obtain the level of this entity
Definition: entity.hh:104