dune-grid  2.3beta2
albertagrid/entity.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_ALBERTA_ENTITY_HH
4 #define DUNE_ALBERTA_ENTITY_HH
5 
7 
11 
12 #if HAVE_ALBERTA
13 
14 namespace Dune
15 {
16 
17  // Forward Declarations
18  // --------------------
19 
20  template< int codim, class Grid >
21  class AlbertaGridEntityPointer;
22 
23  template< int codim, class Grid, bool leafIterator >
24  class AlbertaGridTreeIterator;
25 
26  template< class Grid >
27  class AlbertaGridHierarchicIterator;
28 
29  template< class Grid >
30  class AlbertaGridLeafIntersection;
31 
32  template< class Grid >
33  class AlbertaGridLeafIntersectionIterator;
34 
35 
36 
37  // AlbertaGridEntity
38  // -----------------
39 
44  template< int codim, int dim, class Grid >
46  : public EntityDefaultImplementation< codim, dim, Grid, AlbertaGridEntity >
47  {
49 
50  enum { dimworld = Grid::dimensionworld };
51  friend class AlbertaGrid< dim, dimworld >;
52  friend class AlbertaGridEntity< 0, dim, Grid >;
53 
54  template< int, class, bool > friend class AlbertaGridTreeIterator;
55  friend class AlbertaGridEntityPointer< codim, Grid >;
56 
57  public:
58  static const int dimension = dim;
59  static const int codimension = codim;
60  static const int mydimension = dimension - codimension;
61 
62  template< int cd >
63  struct Codim
64  {
65  typedef typename Grid::template Codim< cd >::EntityPointer EntityPointer;
66  };
67 
68  typedef typename Grid::template Codim< codim >::Entity Entity;
69  typedef typename Grid::template Codim< codim >::EntitySeed EntitySeed;
70  typedef typename Grid::template Codim< codim >::Geometry Geometry;
71 
73 
74  private:
75  typedef typename Grid::Traits::template Codim< codim >::GeometryImpl GeometryImpl;
76 
77  public:
79  explicit AlbertaGridEntity ( const Grid &grid );
80 
83 
85  int level () const;
86 
89 
91  Geometry geometry () const;
92 
94  GeometryType type () const;
95 
97  EntitySeed seed () const { return EntitySeed( AlbertaGridEntitySeed< codim, Grid >( elementInfo(), subEntity() ) ); }
98 
99  //***********************************************
100  // end of interface methods
101  //***********************************************
102 
104  ALBERTA EL_INFO *getElInfo () const;
105 
106  const ElementInfo &elementInfo () const { return elementInfo_; }
107 
109  bool equals ( const This &other ) const;
110 
111  void clearElement ();
112  void setElement ( const ElementInfo &elementInfo, int subEntity );
113 
114  // same as setElInfo just with a entity given
115  void setEntity ( const This &other );
116 
118  const Grid &grid () const
119  {
120  return *grid_;
121  }
122 
124  int subEntity () const
125  {
126  return subEntity_;
127  }
128 
130  int twist () const
131  {
132  return elementInfo().template twist< codimension >( subEntity() );
133  }
134 
135  private:
136  // grid this entity belong to
137  const Grid *grid_;
138 
139  // ALBERTA element info
140  ElementInfo elementInfo_;
141 
142  // number of the subentity within the element (in ALBERTA numbering)
143  int subEntity_;
144  };
145 
146 
147 
148  // AlbertaGridEntity for codimension 0
149  // -----------------------------------
150 
158  template< int dim, class Grid >
159  class AlbertaGridEntity< 0, dim, Grid >
160  : public EntityDefaultImplementation< 0, dim, Grid, AlbertaGridEntity >
161  {
163 
164  static const int dimworld = Grid::dimensionworld;
165 
166  friend class AlbertaGrid< dim, dimworld >;
169  template< int, class, bool > friend class AlbertaGridTreeIterator;
170  friend class AlbertaGridEntityPointer< 0, Grid >;
171 
172  public:
173  static const int dimension = dim;
174  static const int codimension = 0;
175  static const int mydimension = dimension - codimension;
176 
177  template< int codim >
178  struct Codim
179  {
180  typedef typename Grid::template Codim< codim >::EntityPointer
182  };
183 
184  typedef typename Grid::template Codim< 0 >::Entity Entity;
185  typedef typename Grid::template Codim< 0 >::EntitySeed EntitySeed;
186  typedef typename Grid::template Codim< 0 >::Geometry Geometry;
187  typedef typename Grid::template Codim< 0 >::LocalGeometry LocalGeometry;
188  typedef typename Grid::Traits::template Codim< 0 >::GeometryImpl GeometryImpl;
189 
191  typedef typename Grid::template Codim< 0 >::EntityPointer EntityPointer;
192 
195 
197 
199  explicit AlbertaGridEntity ( const Grid &grid );
200 
203 
205  int level () const;
206 
208  int boundaryId () const;
209 
211  Geometry geometry () const;
212 
214  GeometryType type () const;
215 
217  EntitySeed seed () const { return EntitySeed( AlbertaGridEntitySeed< 0, Grid >(elementInfo() )); }
218 
225  template< int codim >
226  int count () const
227  {
228  return Alberta::NumSubEntities< dimension, codim >::value;
229  }
230 
241  template< int codim >
242  typename Codim< codim >::EntityPointer subEntity ( int i ) const;
243 
249  AlbertaGridLeafIntersectionIterator ileafbegin () const;
250 
252  AlbertaGridLeafIntersectionIterator ileafend () const;
253 
255  {
256  if( grid().maxLevel() == 0 )
257  return ileafbegin();
258  else
259  {
260  DUNE_THROW( NotImplemented, "method ilevelbegin not implemented for AlbertaGrid." );
261  return ileafend();
262  }
263  }
264 
266  {
267  return ileafend();
268  }
269 
271  bool isLeaf () const;
272 
275  EntityPointer father () const;
277  bool hasFather () const
278  {
279  return (this->level()>0);
280  }
281 
290  LocalGeometry geometryInFather () const;
291 
296  HierarchicIterator hbegin (int maxlevel) const;
297 
299  HierarchicIterator hend (int maxlevel) const;
300 
302  bool isNew () const;
303 
305  bool mightVanish () const;
306 
309  bool hasBoundaryIntersections () const ;
310 
313 
315  bool equals ( const This &i ) const;
316 
317  // needed for LevelIterator to compare
318  ALBERTA EL_INFO *getElInfo () const;
319 
320  const ElementInfo &elementInfo () const
321  {
322  return elementInfo_;
323  }
324 
325  void clearElement ();
326  void setElement ( const ElementInfo &elementInfo, int subEntity );
327 
328  // same as setElInfo just with a entity given
329  void setEntity ( const This &other );
330 
332  const Grid &grid () const
333  {
334  return *grid_;
335  }
336 
338  int subEntity () const
339  {
340  return 0;
341  }
342 
344  int twist () const
345  {
346  return elementInfo().template twist< codimension >( subEntity() );
347  }
348 
350  template< int codim >
351  int twist ( int i ) const
352  {
353  return elementInfo().template twist< codim >( grid().generic2alberta( codim, i ) );
354  }
355 
356  private:
358  int nChild () const;
359 
361  const Grid *grid_;
362 
363  // Alberta element info
364  ElementInfo elementInfo_;
365  };
366 
367 } // namespace Dune
368 
369 #endif // #if HAVE_ALBERTA
370 
371 #endif // #ifndef DUNE_ALBERTA_ENTITY_HH