dune-grid  2.2.0
albertagrid/entity.hh
Go to the documentation of this file.
1 #ifndef DUNE_ALBERTA_ENTITY_HH
2 #define DUNE_ALBERTA_ENTITY_HH
3 
5 
9 
10 #if HAVE_ALBERTA
11 
12 namespace Dune
13 {
14 
15  // Forward Declarations
16  // --------------------
17 
18  template< int codim, class GridImp >
19  class AlbertaGridEntityPointer;
20 
21  template< int codim, class GridImp, bool leafIterator >
22  class AlbertaGridTreeIterator;
23 
24  template< class GridImp >
25  class AlbertaGridHierarchicIterator;
26 
27  template< class GridImp >
28  class AlbertaGridLeafIntersection;
29 
30  template< class GridImp >
31  class AlbertaGridLeafIntersectionIterator;
32 
33 
34 
35  // AlbertaGridEntity
36  // -----------------
37 
44  template< int codim, int dim, class GridImp >
46  : public EntityDefaultImplementation< codim, dim, GridImp, AlbertaGridEntity >
47  {
49 
50  enum { dimworld = GridImp::dimensionworld };
51  friend class AlbertaGrid< dim , dimworld >;
52  friend class AlbertaGridEntity< 0, dim, GridImp>;
53 
54  template< int, class, bool > friend class AlbertaGridTreeIterator;
55  friend class AlbertaGridEntityPointer< codim, GridImp >;
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 GridImp::template Codim< cd >::EntityPointer EntityPointer;
66  };
67 
68  typedef typename GridImp::template Codim< codim >::Entity Entity;
69  typedef typename GridImp::template Codim< codim >::EntitySeed EntitySeed;
70  typedef typename GridImp::template Codim< codim >::Geometry Geometry;
71  typedef typename GridImp::template Codim< codim >::LevelIterator LevelIterator;
72 
74 
75  private:
76  //typedef MakeableInterfaceObject< Geometry > GeometryObject;
77  //typedef typename GeometryObject::ImplementationType GeometryImp;
78  typedef typename GridImp::Traits::template Codim< codim >::GeometryImpl GeometryImpl;
79 
80  public:
82  explicit AlbertaGridEntity ( const GridImp &grid );
83 
85  AlbertaGridEntity ( const GridImp &grid, const ElementInfo &elementInfo, int subEntity );
86 
88  int level () const;
89 
92 
94  Geometry geometry () const;
95 
97  GeometryType type () const;
98 
100  EntitySeed seed () const { return EntitySeed( elementInfo(), subEntity() ); }
101 
102  //***********************************************
103  // end of interface methods
104  //***********************************************
105 
107  ALBERTA EL_INFO *getElInfo () const;
108 
109  const ElementInfo &elementInfo () const { return elementInfo_; }
110 
112  bool equals ( const This &other ) const;
113 
114  void clearElement ();
115  void setElement ( const ElementInfo &elementInfo, int subEntity );
116 
117  // same as setElInfo just with a entity given
118  void setEntity ( const This &other );
119 
121  const GridImp &grid () const
122  {
123  return *grid_;
124  }
125 
127  int subEntity () const
128  {
129  return subEntity_;
130  }
131 
133  int twist () const
134  {
135  return elementInfo().template twist< codimension >( subEntity() );
136  }
137 
138  private:
139  // grid this entity belong to
140  const GridImp *grid_;
141 
142  // ALBERTA element info
143  ElementInfo elementInfo_;
144 
145  // number of the subentity within the element (in ALBERTA numbering)
146  int subEntity_;
147  };
148 
149 
150 
151  // AlbertaGridEntity for codimension 0
152  // -----------------------------------
153 
167  template< int dim, class GridImp >
168  class AlbertaGridEntity< 0, dim, GridImp >
169  : public EntityDefaultImplementation< 0, dim, GridImp, AlbertaGridEntity >
170  {
172 
173  static const int dimworld = GridImp::dimensionworld;
174 
175  friend class AlbertaGrid< dim, dimworld >;
176  friend class AlbertaGridLeafIntersection< GridImp >;
177  friend class AlbertaGridHierarchicIterator< GridImp >;
178  template< int, class, bool > friend class AlbertaGridTreeIterator;
179  friend class AlbertaGridEntityPointer<0,GridImp>;
180 
181  public:
182  static const int dimension = dim;
183  static const int codimension = 0;
184  static const int mydimension = dimension - codimension;
185 
186  template< int codim >
187  struct Codim
188  {
189  typedef typename GridImp::template Codim< codim >::EntityPointer
191  };
192 
193  typedef typename GridImp::template Codim< 0 >::Entity Entity;
194  typedef typename GridImp::template Codim< 0 >::EntitySeed EntitySeed;
195  typedef typename GridImp::template Codim< 0 >::Geometry Geometry;
196  typedef typename GridImp::template Codim< 0 >::LocalGeometry LocalGeometry;
197  typedef typename GridImp::Traits::template Codim< 0 >::GeometryImpl GeometryImpl;
198 
199  typedef typename GridImp::template Codim<0>::LevelIterator LevelIterator;
200  typedef typename GridImp::HierarchicIterator HierarchicIterator;
201  typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer;
202 
205 
207 
209  explicit AlbertaGridEntity ( const GridImp &grid );
210 
212  AlbertaGridEntity ( const GridImp &grid, const ElementInfo &elementInfo, int subEntity );
213 
215  int level () const;
216 
218  int boundaryId () const;
219 
221  Geometry geometry () const;
222 
224  GeometryType type () const;
225 
227  EntitySeed seed () const { return EntitySeed( elementInfo() ); }
228 
235  template< int codim >
236  int count () const
237  {
238  return Alberta::NumSubEntities< dimension, codim >::value;
239  }
240 
251  template< int codim >
252  typename Codim< codim >::EntityPointer subEntity ( int i ) const;
253 
259  AlbertaGridLeafIntersectionIterator ileafbegin () const;
260 
262  AlbertaGridLeafIntersectionIterator ileafend () const;
263 
265  {
266  if( grid().maxLevel() == 0 )
267  return ileafbegin();
268  else
269  {
270  DUNE_THROW( NotImplemented, "method ilevelbegin not implemented for AlbertaGrid." );
271  return ileafend();
272  }
273  }
274 
276  {
277  return ileafend();
278  }
279 
281  bool isLeaf () const;
282 
285  EntityPointer father () const;
287  bool hasFather () const
288  {
289  return (this->level()>0);
290  }
291 
300  LocalGeometry geometryInFather () const;
301 
306  HierarchicIterator hbegin (int maxlevel) const;
307 
309  HierarchicIterator hend (int maxlevel) const;
310 
312  bool isNew () const;
313 
315  bool mightVanish () const;
316 
319  bool hasBoundaryIntersections () const ;
320 
322  PartitionType partitionType() const;
323 
325  bool equals ( const AlbertaGridEntity<0,dim,GridImp> & i) const;
326 
327  // needed for LevelIterator to compare
328  ALBERTA EL_INFO *getElInfo () const;
329 
330  const ElementInfo &elementInfo () const
331  {
332  return elementInfo_;
333  }
334 
335  void clearElement ();
336  void setElement ( const ElementInfo &elementInfo, int subEntity );
337 
338  // same as setElInfo just with a entity given
339  void setEntity ( const This &other );
340 
342  const GridImp &grid () const
343  {
344  return *grid_;
345  }
346 
348  int subEntity () const
349  {
350  return 0;
351  }
352 
354  int twist () const
355  {
356  return elementInfo().template twist< codimension >( subEntity() );
357  }
358 
360  template< int codim >
361  int twist ( int i ) const
362  {
363  return elementInfo().template twist< codim >( grid().generic2alberta( codim, i ) );
364  }
365 
366  private:
368  int nChild () const;
369 
371  const GridImp *grid_;
372 
373  // Alberta element info
374  ElementInfo elementInfo_;
375 
376  // local coordinates within father
377  typedef MakeableInterfaceObject< Geometry > GeometryObject;
378  };
379 
380 } // namespace Dune
381 
382 #endif // #if HAVE_ALBERTA
383 
384 #endif // #ifndef DUNE_ALBERTA_ENTITY_HH