This file is indexed.

/usr/include/dune/grid/alugrid/3d/entity.hh is in libdune-grid-dev 2.2.1-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
#ifndef DUNE_ALU3DGRIDENTITY_HH
#define DUNE_ALU3DGRIDENTITY_HH

// System includes

// Dune includes
#include <dune/grid/common/entity.hh>
#include <dune/grid/alugrid/common/intersectioniteratorwrapper.hh>

// Local includes
#include "alu3dinclude.hh"
#include "iterator.hh"
#include "entityseed.hh"

namespace Dune
{

  // Forward declarations
  template<int cd, int dim, class GridImp> 
  class ALU3dGridEntity;
  template<int cd, PartitionIteratorType pitype, class GridImp >
  class ALU3dGridLevelIterator;
  template<int cd, class GridImp > 
  class ALU3dGridEntityPointer;
  template<int mydim, int coorddim, class GridImp>
  class ALU3dGridGeometry;
  template<class GridImp> 
  class ALU3dGridHierarchicIterator;
  template<class GridImp>
  class ALU3dGridIntersectionIterator;
  template<int codim, PartitionIteratorType, class GridImp>
  class ALU3dGridLeafIterator;
  template< ALU3dGridElementType, class >
  class ALU3dGrid;

/*! 
  A Grid is a container of grid entities. An entity is parametrized by the codimension.
  An entity of codimension c in dimension d is a d-c dimensional object.

  Here: the general template
 */
template<int cd, int dim, class GridImp>
class ALU3dGridEntity : 
public EntityDefaultImplementation <cd,dim,GridImp,ALU3dGridEntity> 
{
  // default just returns level 
  template <class GridType, int cdim> 
  struct GetLevel 
  {
    template <class ItemType> 
    static int getLevel(const GridType & grid, const ItemType & item )
    {
      return item.level();
    }
  };

  // for leaf vertices the level is somewhat difficult to obtain, because
  // this the maximum of levels of elements that have this vertex as sub
  // entity
  template <class GridType> 
  struct GetLevel<GridType,3>
  {
    template <class ItemType> 
    static int getLevel(const GridType & grid, const ItemType & item)
    {
      return (item.isLeafEntity()) ? grid.getLevelOfLeafVertex(item) : item.level();
    }
  };
  
  enum { dimworld = GridImp::dimensionworld };
   
  typedef typename GridImp::MPICommunicatorType Comm;

  friend class ALU3dGrid< GridImp::elementType, Comm >;
  friend class ALU3dGridEntity < 0, dim, GridImp >;
  friend class ALU3dGridLevelIterator < cd, All_Partition, GridImp >;

  friend class ALU3dGridHierarchicIndexSet< GridImp::elementType, Comm >;

  template< class > friend class ALU3dGridFactory;

  typedef typename GridImp::Traits::template Codim< cd >::GeometryImpl GeometryImpl;

public:
  typedef typename GridImp::GridObjectFactoryType FactoryType;

  typedef ALU3dImplTraits< GridImp::elementType, Comm > ImplTraits;
  typedef typename ImplTraits::template Codim<cd>::InterfaceType      HItemType;
  typedef typename ImplTraits::template Codim<cd>::ImplementationType ItemType;
  typedef typename ImplTraits::VertexType   VertexType; 
  typedef typename ImplTraits::HBndSegType  HBndSegType; 

  typedef typename GridImp::template Codim<cd>::Entity Entity;  
  typedef typename GridImp::template Codim<cd>::Geometry Geometry;
  
  typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer;

  //! typedef of my type 
  typedef typename GridImp::template Codim<cd>::EntitySeed EntitySeed; 

  //! level of this element
  int level () const;

  //! return partition type of this entity ( see grid.hh )
  PartitionType partitionType() const;
  
  //! Constructor 
  ALU3dGridEntity(const FactoryType &factory, int level);

  //! copy Constructor 
  ALU3dGridEntity(const ALU3dGridEntity & org);

  //! geometry of this entity
  Geometry geometry () const;

  //! type of geometry of this entity
  GeometryType type () const;

  // set element as normal entity
  void setElement(const HItemType & item); 
  void setElement(const HItemType & item, const int level, int twist=0, int face = -1); 

  /* set entity from seed */
  void setElement(const EntitySeed& seed);
  
  //! setGhost is not valid for this codim 
  void setGhost(const HBndSegType  &ghost);

  //! reset item pointer to NULL 
  void removeElement (); 
  
  //! reset item pointer to NULL 
  void reset ( int l ); 
  
  //! compare 2 elements by comparing the item pointers 
  bool equals ( const ALU3dGridEntity<cd,dim,GridImp> & org ) const;
  
  //! set item from other entity, mainly for copy constructor of entity pointer
  void setEntity ( const ALU3dGridEntity<cd,dim,GridImp> & org );
  
  // return reference to internal item 
  const ItemType & getItem () const { return *item_; }

  //! return reference to grid 
  const GridImp& grid() const { return factory_.grid(); }

  //! return reference to factory 
  const FactoryType& factory() const { return factory_; }

  //! return seed of entity 
  EntitySeed seed() const 
  { 
    return EntitySeed( getItem(), level(), twist_, face_ );
  }

private: 
  //! index is unique within the grid hierarchy and per codim
  int getIndex () const;

  //! convert ALUGrid partition type to dune partition type
  PartitionType convertBndId(const HItemType & item) const ;

  //! the cuurent geometry
  mutable GeometryImpl geo_;
  
  // the factory that created this entity
  const FactoryType& factory_;

  // corresponding ALU3dGrid item, here face, edge, or vertex 
  const ItemType * item_;
    
  int level_;  //! level of entity
  int gIndex_; //! hierarchic index
  int twist_;  //! twist of the underlying ALU element (with regard to the element that asked for it)
  int face_;   //! for face, know on which face we are 

  mutable PartitionType partitionType_; //!< partition type of this entity
};

/*! 
  A Grid is a container of grid entities. An entity is parametrized by the codimension.
  An entity of codimension c in dimension d is a d-c dimensional object.

  Entities of codimension 0 ("elements") are defined through template specialization. Note
  that this specialization has an extended interface compared to the general case

  Entities of codimension 0  allow to visit all neighbors, where
  a neighbor is an entity of codimension 0 which has a common entity of codimension 1 with the
  These neighbors are accessed via an iterator. This allows the implementation of
  non-matching meshes. The number of neigbors may be different from the number of faces/edges
  of an element!
 */
//***********************
//  
//  --ALU3dGridEntity
//  --0Entity
//
//***********************
template<int dim, class GridImp>
class ALU3dGridEntity<0,dim,GridImp> 
: public EntityDefaultImplementation<0,dim,GridImp,ALU3dGridEntity>
{
  static const int dimworld = remove_const< GridImp >::type::dimensionworld;
  static const ALU3dGridElementType elementType = remove_const< GridImp >::type::elementType;

  typedef typename GridImp::MPICommunicatorType Comm;

  typedef ALU3dImplTraits< elementType, Comm > ImplTraits;
  typedef typename ImplTraits::template Codim<0>::InterfaceType     HElementType;

  typedef typename ImplTraits::GEOElementType  GEOElementType;
  typedef typename ImplTraits::BNDFaceType  BNDFaceType;
  typedef typename ImplTraits::IMPLElementType IMPLElementType;
  typedef typename ImplTraits::HBndSegType     HBndSegType; 

  enum { refine_element_t  = ImplTraits::refine_element_t  };
  enum { bisect_element_t  = ImplTraits::bisect_element_t  };
  enum { coarse_element_t  = ImplTraits::coarse_element_t  };
  enum { nosplit_element_t = ImplTraits::nosplit_element_t };

  typedef typename ImplTraits::MarkRuleType MarkRuleType;

  friend class ALU3dGrid< elementType, Comm >;
  friend class ALU3dGridIntersectionIterator < GridImp >;
  friend class ALU3dGridIntersectionIterator < const GridImp >;
  friend class ALU3dGridHierarchicIterator   < const GridImp >;
  friend class ALU3dGridHierarchicIterator   < GridImp >;
  friend class ALU3dGridLevelIterator <0,All_Partition,GridImp>;
  friend class ALU3dGridLevelIterator <1,All_Partition,GridImp>;
  friend class ALU3dGridLevelIterator <2,All_Partition,GridImp>;
  friend class ALU3dGridLevelIterator <3,All_Partition,GridImp>;
  friend class ALU3dGridLeafIterator <0, All_Partition,GridImp>;
  friend class ALU3dGridLeafIterator <1, All_Partition,GridImp>;
  friend class ALU3dGridLeafIterator <2, All_Partition,GridImp>;
  friend class ALU3dGridLeafIterator <3, All_Partition,GridImp>;

  friend class ALU3dGridHierarchicIndexSet< elementType, Comm >;

  template< class > friend class ALU3dGridFactory;

  // type of reference element 
  typedef typename GridImp :: ReferenceElementType ReferenceElementType;

  typedef typename GridImp::Traits::template Codim< 0 >::GeometryImpl GeometryImpl;
  typedef typename GridImp::Traits::template Codim< 0 >::LocalGeometryImpl LocalGeometryImpl;

public:
  typedef typename GridImp::GridObjectFactoryType FactoryType;

  typedef typename GridImp::template Codim< 0 >::Geometry Geometry;
  typedef typename GridImp::template Codim< 0 >::LocalGeometry LocalGeometry;
  typedef ALU3dGridIntersectionIterator<GridImp> IntersectionIteratorImp; 

  typedef LeafIntersectionIteratorWrapper <GridImp>  ALU3dGridIntersectionIteratorType; 
  typedef LeafIntersectionIteratorWrapper <GridImp>  ALU3dGridLeafIntersectionIteratorType; 
  typedef LevelIntersectionIteratorWrapper<GridImp>  ALU3dGridLevelIntersectionIteratorType; 
  
  typedef typename GridImp::template Codim<0>::Entity        Entity;
  typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer;

  template <int cd>
  struct Codim
  {
    typedef typename GridImp::template Codim<cd>::EntityPointer EntityPointer;
  };
  
  //! typedef of my type 
  typedef typename GridImp::template Codim<0>::EntitySeed  EntitySeed;

  //! Constructor creating empty Entity 
  ALU3dGridEntity(const FactoryType& factory, int level);
  
  //! copy Constructor 
  ALU3dGridEntity(const ALU3dGridEntity & org);

  //! level of this element
  int level () const ;

  //! geometry of this entity
  Geometry geometry () const;

  //! type of geometry of this entity
  GeometryType type () const;

  //! return partition type of this entity ( see grid.hh )
  PartitionType partitionType() const;
  
  /*! Intra-element access to entities of codimension cc > codim. Return number of entities
      with codimension cc.
  */
  template<int cc> int count () const ; 
  
  //! Provide access to mesh entity i of given codimension. Entities
  //!  are numbered 0 ... count<cc>()-1
  template <int codim>
  typename Codim< codim >::EntityPointer entity (int i) const
  {
    typedef GenericGeometry::MapNumberingProvider< GridImp::dimension > Numbering;
    const unsigned int tid = type().id();
    const int j = Numbering::template dune2generic< codim >( tid, i );
    return subEntity< codim >( j );
  }

  template< int codim >
  typename Codim< codim >::EntityPointer subEntity ( int i ) const;

  /*! Access to intersection with neighboring elements that are leaf
   * elements. A neighbor is an entity of codimension 0
    which has an entity of codimension 1 in commen with this entity. Access to neighbors
    is provided using iterators. This allows meshes to be nonmatching. Returns iterator
    referencing the first neighbor. */
  ALU3dGridLeafIntersectionIteratorType ileafbegin () const;

  //! Reference to one past the last intersection with neighbor
  ALU3dGridLeafIntersectionIteratorType ileafend () const;
  
  /*! Intra-level access to intersection with neighboring elements. 
    A neighbor is an entity of codimension 0
    which has an entity of codimension 1 in commen with this entity. Access to neighbors
    is provided using iterators. This allows meshes to be nonmatching. Returns iterator
    referencing the first neighbor. */
  ALU3dGridLevelIntersectionIteratorType ilevelbegin () const;

  //! Reference to one past the last intersection with neighbor
  ALU3dGridLevelIntersectionIteratorType ilevelend () const;
  
  //! returns true if Entity is leaf (i.e. has no children) 
  bool isLeaf () const; 

  //! Inter-level access to father element on coarser grid. 
  //! Assumes that meshes are nested.
  EntityPointer father () const;
  //! returns true if father entity exists
  bool hasFather () const
  {
    return (this->level()>0);
  }

  /*! Location of this element relative to the reference element 
    of the father. This is sufficient to interpolate all 
    dofs in conforming case. Nonconforming may require access to 
    neighbors of father and computations with local coordinates.
    On the fly case is somewhat inefficient since dofs  are visited 
    several times. If we store interpolation matrices, this is tolerable. 
    We assume that on-the-fly implementation of numerical algorithms 
    is only done for simple discretizations. Assumes that meshes are nested.
  */
  LocalGeometry geometryInFather () const;
 
  /*! Inter-level access to son elements on higher levels<=maxlevel.
    This is provided for sparsely stored nested unstructured meshes.
    Returns iterator to first son.
  */
  ALU3dGridHierarchicIterator<GridImp> hbegin (int maxlevel) const;
  
  //! Returns iterator to one past the last son
  ALU3dGridHierarchicIterator<GridImp> hend (int maxlevel) const;

  //***************************************************************
  //  Interface for Adaptation
  //***************************************************************

  //! returns true, if entity was created during last adaptation cycle 
  bool isNew () const; 

  //! returns true, if entity might be coarsened during next adaptation cycle 
  bool mightVanish () const;
 
  //! returns true, if entity has intersections with boundary 
  bool hasBoundaryIntersections () const;
 
  // private method 
  //! marks an element for refCount refines. if refCount is negative the
  //! element is coarsend -refCount times
  //! mark returns true if element was marked, otherwise false
  bool mark( int refCount ) const;

  //! \brief return current adaptation mark for this entity 
  int getMark() const;

  /*! private methods, but public because of datahandle and template
      arguments of these methods
  */
  void setElement(HElementType &element);

  /* set entity from seed */
  void setElement(const EntitySeed& seed);
  
  //! set original element pointer to fake entity
  void setGhost(HBndSegType & ghost);

  //! set actual walk level 
  void reset ( int l );

  //! set item pointer to NULL
  void removeElement();

  //! compare 2 entities, which means compare the item pointers 
  bool equals ( const ALU3dGridEntity<0,dim,GridImp> & org ) const;
  
  void setEntity ( const ALU3dGridEntity<0,dim,GridImp> & org );

  //! return index of sub entity with codim = cc and local number i
  //! i.e. return global number of vertex i
  //! for use in hierarchical index set 
  template<int cc> int getSubIndex (int i) const;

  //! return index of sub entity with codim = cc and local number i
  //! i.e. return global number of vertex i
  //! for use in hierarchical index set 
  int subIndex(int i, unsigned int codim) const;

  // return reference to internal item 
  const IMPLElementType& getItem () const { return *item_; }

  // return reference to internal item 
  const BNDFaceType& getGhost () const 
  { 
    assert( isGhost() );
    return *ghost_; 
  }

  //! return reference to grid 
  const GridImp& grid() const { return factory_.grid(); }

  //! return reference to factory 
  const FactoryType& factory() const { return factory_; }

  //! returns true if entity is ghost 
  bool isGhost () const{ return ImplTraits::isGhost( ghost_ ); }

  //! return key for this entity 
  EntitySeed seed() const 
  { 
    if( isGhost() ) 
      return EntitySeed( getGhost () );
    else 
      return EntitySeed( getItem() );
  }

private:
  //! index is unique within the grid hierachy and per codim
  int getIndex () const;

  //! the entity's geometry
  mutable GeometryImpl geo_;

  // corresponding factory 
  const FactoryType& factory_; 

  // the current element of grid 
  mutable IMPLElementType* item_;
  
  //! not zero if entity is ghost entity
  mutable BNDFaceType*  ghost_; 

  int level_;    //!< level of element 
  bool isLeaf_;  //!< is true if entity is leaf entity 

}; // end of ALU3dGridEntity codim = 0
//**********************************************************************
//
// --ALU3dGridEntityPointer
// --EntityPointer
// --EnPointer
/*!
 Enables iteration over all entities of a given codimension and level of a grid.
 */
template< int codim, class GridImp >
class ALU3dGridEntityPointerBase
//: public EntityPointerDefaultImplementation <codim, GridImp, ALU3dGridEntityPointer<cd,GridImp> >
{
  typedef ALU3dGridEntityPointerBase< codim, GridImp > ThisType;
  enum { dim       = GridImp::dimension };
  enum { dimworld  = GridImp::dimensionworld };
   
  typedef typename GridImp::MPICommunicatorType Comm;

  friend class ALU3dGridEntity<codim,dim,GridImp>;
  friend class ALU3dGridEntity< 0,dim,GridImp>;
  friend class ALU3dGrid < GridImp::elementType, Comm >;

  typedef ALU3dImplTraits<GridImp::elementType, Comm > ImplTraits;
  typedef typename ImplTraits::template Codim<codim>::InterfaceType HElementType;

  typedef typename ImplTraits::HBndSegType  HBndSegType; 
  typedef typename ImplTraits::BNDFaceType BNDFaceType;
public:
  typedef typename GridImp::GridObjectFactoryType FactoryType;

  enum { codimension = codim };

  //! type of Entity 
  typedef typename GridImp::template Codim<codimension>::Entity Entity;
  //! underlying EntityImplementation 
  typedef MakeableInterfaceObject<Entity> EntityObject;
  typedef typename EntityObject :: ImplementationType EntityImp;
  
  //! typedef of my type 
  typedef ThisType ALU3dGridEntityPointerType;

  //! make type of entity pointer implementation available in derived classes
  typedef ALU3dGridEntityPointer<codimension,GridImp> EntityPointerImp;

  //! type of entity seed
  typedef ALU3dGridEntitySeed<codimension, GridImp> ALU3dGridEntitySeedType;
  
  //! Constructor for EntityPointer that points to an element 
  ALU3dGridEntityPointerBase(const FactoryType& factory, 
                             const HElementType & item);

  //! Constructor for EntityPointer that points to an element 
  ALU3dGridEntityPointerBase(const FactoryType& factory,
                             const HElementType & item,
                             const int level, 
                             const int twist,
                             const int duneFace
                            );

  //! Constructor for EntityPointer that points to an ghost 
  ALU3dGridEntityPointerBase(const FactoryType& factory, 
                             const HBndSegType & ghostFace );  

  //! Constructor for EntityPointer that points to an ghost 
  ALU3dGridEntityPointerBase(const FactoryType& factory, 
                             const ALU3dGridEntitySeedType& seed );  

  //! copy constructor 
  ALU3dGridEntityPointerBase(const ALU3dGridEntityPointerType & org);
  
  //! Destructor  
  ~ALU3dGridEntityPointerBase();

  //! equality
  bool equals (const ALU3dGridEntityPointerType& i) const;

  //! assignment operator
  ThisType & operator = (const ThisType & org);

  //! dereferencing
  Entity & dereference () const ;

  //! ask for level of entities 
  int level () const ;

protected:
  // clones object 
  void clone (const ALU3dGridEntityPointerType & org);
  
  // get entity and assign from org.entity  
  void getEntity (const ALU3dGridEntityPointerType & org);
  
  //! has to be called when iterator is finished
  void done (); 

  //! put entity to entity stack 
  void freeEntity ();

  //! return reference to grid 
  const GridImp& grid () const { return factory_.grid(); }

  //! Constructor for EntityPointer init of Level-, and Leaf-, and
  //! HierarchicIterator
  ALU3dGridEntityPointerBase(const FactoryType& factory, int level );

  // update underlying item pointer and set ghost entity
  void updateGhostPointer( HBndSegType & ghostFace );  
  // update underlying item pointer and set entity
  void updateEntityPointer( HElementType * item , int level = -1 );  
  
  // reference to factory  
  const FactoryType& factory_; 

  // key to gererate entity 
  ALU3dGridEntitySeedType seed_;

  // entity that this EntityPointer points to 
  mutable EntityObject * entity_;

  // is true if entity must not be released 
  bool locked_;
  
  // return reference to internal entity implementation 
  EntityImp & entityImp () const { 
    assert( entity_ );
    return GridImp :: getRealImplementation(*entity_); 
  }
};

//! ALUGridEntityPointer points to an entity
//! this class is the specialisation for codim 0, 
//! it has exactly the same functionality as the ALU3dGridEntityPointerBase
template<class GridImp>
class ALU3dGridEntityPointer<0,GridImp> : 
public ALU3dGridEntityPointerBase<0,GridImp> 
{
protected:  
  typedef ALU3dGridEntityPointerBase<0,GridImp> BaseType;

  enum { cd = 0 };
  typedef ALU3dGridEntityPointer <cd,GridImp> ThisType;
  enum { dim       = GridImp::dimension };
  enum { dimworld  = GridImp::dimensionworld };
    
  typedef typename GridImp::MPICommunicatorType Comm;

  friend class ALU3dGridEntity<cd,dim,GridImp>;
  friend class ALU3dGridEntity< 0,dim,GridImp>;
  friend class ALU3dGrid < GridImp::elementType, Comm >;

  typedef ALU3dImplTraits<GridImp::elementType, Comm > ImplTraits;
  typedef typename ImplTraits::template Codim<cd>::InterfaceType HElementType;

  typedef typename ImplTraits::HBndSegType HBndSegType; 
  typedef typename ImplTraits::BNDFaceType BNDFaceType;

  typedef ALU3dGridEntity< 0,dim,GridImp> ALU3dGridEntityType ;

  using BaseType :: seed_;
  using BaseType :: entity_;
  using BaseType :: entityImp;
  using BaseType :: factory_;
public:
  typedef typename GridImp::GridObjectFactoryType FactoryType;

  //! type of entity seed 
  typedef ALU3dGridEntitySeed<cd, GridImp> ALU3dGridEntitySeedType;
  
  //! type of Entity 
  typedef typename GridImp::template Codim<cd>::Entity Entity;
  
  //! typedef of my type 
  typedef ThisType ALU3dGridEntityPointerType;
  
  //! Constructor for EntityPointer that points to an interior element 
  ALU3dGridEntityPointer(const FactoryType& factory, 
                         const HElementType & item)
    : ALU3dGridEntityPointerBase<cd,GridImp> (factory,item) {}

  //! Constructor for EntityPointer that points to an ghost 
  ALU3dGridEntityPointer(const FactoryType& factory, 
                         const HBndSegType & ghostFace )  
    : ALU3dGridEntityPointerBase<cd,GridImp> (factory,ghostFace) {}

  //! Constructor for EntityPointer that points to given entity 
  ALU3dGridEntityPointer(const FactoryType& factory, const ALU3dGridEntitySeedType& seed) 
    : ALU3dGridEntityPointerBase<cd,GridImp> (factory, seed)
  {
    // for ghost entities we have to copy right away 
    if( seed.isGhost() ) 
    {
      assert( entity_ == 0 );
      entity_ = factory_.template getNewEntity<0> ();
      assert( entity_ );
      entityImp().setGhost( *seed.ghost() );

      // don't free on compactify, otherwise ghost info is lost  
      this->locked_ = true ;
    }
  }

  //! Constructor for EntityPointer that points to an entity (interior or ghost) 
  ALU3dGridEntityPointer(const ALU3dGridEntityType& entity) 
    : ALU3dGridEntityPointerBase<cd,GridImp> (entity.factory(),
                                              entity.seed() ) 
  {
    // for ghost entities we have to copy right away 
    if( entity.isGhost() ) 
    {
      assert( entity_ == 0 );
      entity_ = factory_.template getNewEntity<0> ();
      assert( entity_ );
      entityImp().setEntity( entity );

      // don't free on compactify, otherwise ghost info is lost  
      this->locked_ = true ;
    }
  } 
  
  //! copy constructor 
  ALU3dGridEntityPointer(const ALU3dGridEntityPointerType & org)
    : ALU3dGridEntityPointerBase<cd,GridImp> (org) 
  {
  }

protected:
  //! Constructor for EntityPointer init of Level-, and Leaf-, and
  //! HierarchicIterator
  ALU3dGridEntityPointer(const FactoryType& factory, int level )
    : ALU3dGridEntityPointerBase<cd,GridImp> (factory,level) {}
};


template<int cd, class GridImp>
class ALU3dGridEntityPointer : 
public ALU3dGridEntityPointerBase<cd,GridImp>
{
protected:  
  typedef ALU3dGridEntityPointerBase<cd,GridImp> BaseType ;
  typedef ALU3dGridEntityPointer <cd,GridImp> ThisType;
  enum { dim       = GridImp::dimension };
  enum { dimworld  = GridImp::dimensionworld };
    
  typedef typename GridImp::MPICommunicatorType Comm;

  friend class ALU3dGridEntity<cd,dim,GridImp>;
  friend class ALU3dGridEntity< 0,dim,GridImp>;
  friend class ALU3dGrid < GridImp::elementType, Comm >;

  typedef ALU3dImplTraits< GridImp::elementType, Comm > ImplTraits;
  typedef typename ImplTraits::template Codim<cd>::InterfaceType HElementType;

  typedef typename ImplTraits::HBndSegType HBndSegType; 
  typedef typename ImplTraits::BNDFaceType BNDFaceType;
  typedef ALU3dGridEntity<cd,dim,GridImp> ALU3dGridEntityType;

  using BaseType :: seed_;
  using BaseType :: entity_;
  using BaseType :: entityImp;
  using BaseType :: factory_;
  using BaseType :: getEntity;

public:
  typedef typename GridImp::GridObjectFactoryType FactoryType;

  //! type of entity seed
  typedef ALU3dGridEntitySeed<cd, GridImp> ALU3dGridEntitySeedType;
  
  //! type of Entity 
  typedef typename GridImp::template Codim<cd>::Entity Entity;
  
  //! typedef of my type 
  typedef ALU3dGridEntityPointer<cd,GridImp> ALU3dGridEntityPointerType;
  
protected:  
  static const int defaultValue = -665; //ALU3dGridEntityPointerType :: defaultValue;

public:    
  //! Constructor for EntityPointer that points to an element 
  ALU3dGridEntityPointer(const FactoryType& factory, 
                         const int level, 
                         const HElementType & item,
                         const int twist = defaultValue,
                         const int duneFace = defaultValue
                        );

  //! Constructor for EntityPointer that points to given entity 
  ALU3dGridEntityPointer(const ALU3dGridEntityType& entity) 
    : ALU3dGridEntityPointerBase<cd,GridImp> (entity.factory(),
                                              entity.seed())
  {}

  //! Constructor for EntityPointer that points to given entity 
  ALU3dGridEntityPointer(const FactoryType& factory, const ALU3dGridEntitySeedType& seed) 
    : ALU3dGridEntityPointerBase<cd,GridImp> ( factory, seed )
  {}

  //! copy constructor 
  ALU3dGridEntityPointer(const ALU3dGridEntityPointerType & org);
  
  //! dereferencing
  Entity & dereference () const ;

  //! assignment operator
  ThisType & operator = (const ThisType & org);

  //! ask for level of entities 
  int level () const ;

protected:
  // clones object 
  void clone (const ALU3dGridEntityPointerType & org);
  
  void updateEntityPointer( HElementType * item , int level );  

  //! Constructor for EntityPointer init of Level-, and Leaf-, and
  //! HierarchicIterator
  ALU3dGridEntityPointer(const FactoryType& factory, int level ) 
    : ALU3dGridEntityPointerBase<cd,GridImp> (factory,level)
  {}
};

} // end namespace Dune

#include "entity_inline.hh"

#if COMPILE_ALUGRID_INLINE
  #include "entity_imp.cc"
#endif

#endif