This file is indexed.

/usr/include/dune/grid/alugrid/3d/datahandle.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
#ifndef DUNE_ALU3DGRIDDATAHANDLE_HH
#define DUNE_ALU3DGRIDDATAHANDLE_HH

//- system includes 
#include <iostream>

#include <dune/grid/common/grid.hh>
#include <dune/grid/common/adaptcallback.hh>

//- local includes 
#include "alu3dinclude.hh"

using std::endl;
using std::cout;
using std::flush;

namespace ALUGridSpace
{

//! the corresponding interface class is defined in bsinclude.hh
template <class GridType, class DataCollectorType, int codim >
class GatherScatterBaseImpl
: public GatherScatter
{
protected:  
  const GridType & grid_;
  typedef typename GridType::template Codim<codim>::Entity EntityType;
  typedef Dune :: MakeableInterfaceObject<
    typename GridType::template Codim<codim>::Entity> MakeableEntityType;
  typedef typename MakeableEntityType :: ImplementationType RealEntityType;

  typedef typename GridType::MPICommunicatorType Comm;
  
  typedef Dune::ALU3dImplTraits< GridType::elementType, Comm > ImplTraits;
  typedef typename ImplTraits::template Codim< codim >::ImplementationType ImplElementType;
  typedef typename ImplTraits::template Codim< codim >::InterfaceType HElementType;

  EntityType  & entity_;
  RealEntityType & realEntity_;

  DataCollectorType & dc_;

  const bool variableSize_;

  typedef typename GatherScatter :: ObjectStreamType ObjectStreamType;

  typedef typename DataCollectorType:: DataType DataType;
public:
  //! Constructor
  GatherScatterBaseImpl(const GridType & grid, MakeableEntityType & en, 
      RealEntityType & realEntity , DataCollectorType & dc) 
    : grid_(grid), entity_(en), realEntity_(realEntity) , dc_(dc)
    , variableSize_( ! dc_.fixedsize(EntityType::dimension,codim) )
  {
  }

  //! returns contains of dc_
  bool contains(int dim, int cd) const { return dc_.contains(dim,cd); }

  // returns true, if element is contained in set of comm interface 
  // this method must be overlaoded by the impl classes 
  virtual bool containsItem (const HElementType & elem) const = 0;

  // set elem to realEntity
  virtual void setElement(const HElementType & elem) = 0;
    
  void setData ( ObjectStreamType & str , HElementType & elem )
  {
    // one of this should be either true 
    assert( this->containsItem( elem ) || elem.isGhost() );

    // set element and then start 
    setElement(elem);

    // make sure partition type is set correct 
    assert( elem.isGhost() == (entity_.partitionType() == Dune :: GhostEntity) );

    size_t size = getSize(str, entity_);
    // use normal scatter method 
    dc_.scatter(str,entity_, size ); 
  }

  //! write Data of one element to stream 
  void sendData ( ObjectStreamType & str , HElementType & elem )
  {
    // make sure element is contained in communication interface
    //assert( this->containsItem( elem ) );
    setElement(elem);

    // if varaible size, also send size 
    if( variableSize_ )
    {
      size_t size = dc_.size( entity_ );
      str.write( size );
    }

    dc_.gather(str, entity_ );
  }

  //! read Data of one element from stream 
  void recvData ( ObjectStreamType & str , HElementType & elem )
  {
    assert( this->containsItem( elem ) );
    setElement( elem );

    size_t size = getSize(str, entity_);
    dc_.scatter(str,entity_, size );
  }

protected:  
  size_t getSize(ObjectStreamType & str, EntityType & en)
  {
    if(variableSize_) 
    {
      size_t size;
      str.read(size);
      return size;
    }
    else 
      return dc_.size(en);
  }
};

//***********************************************************
//
//  --specialisation for codim 0 
//
//***********************************************************

//! the corresponding interface class is defined in bsinclude.hh
template <class GridType, class DataCollectorType >
class GatherScatterBaseImpl<GridType,DataCollectorType,0> : public GatherScatter
{
protected:  
  enum { codim = 0 };
  const GridType & grid_;
  typedef typename GridType::template Codim<0>::Entity EntityType;
  typedef Dune :: MakeableInterfaceObject<
    typename GridType::template Codim<0>::Entity> MakeableEntityType;
  typedef typename MakeableEntityType :: ImplementationType RealEntityType;
  
  typedef typename GridType::MPICommunicatorType Comm;

  typedef Dune::ALU3dImplTraits< GridType::elementType, Comm > ImplTraits;
  typedef typename ImplTraits::template Codim< codim >::ImplementationType ImplElementType;
  typedef typename ImplTraits::template Codim< codim >::InterfaceType HElementType;
  
  typedef typename ImplTraits::template Codim< 1 >::InterfaceType HFaceType;
  
  typedef typename ImplTraits::template Codim< codim >::GhostInterfaceType HGhostType;
  typedef typename ImplTraits::template Codim< codim >::GhostImplementationType ImplGhostType;

  typedef typename ImplTraits::PllElementType PllElementType;

  EntityType& entity_;
  RealEntityType & realEntity_;

  // data handle 
  DataCollectorType & dc_;

  const bool variableSize_;

  // used MessageBuffer 
  typedef typename GatherScatter :: ObjectStreamType ObjectStreamType;

public:
  // use all other containsItem from the base class 
  using GatherScatter :: containsItem ;

  //! Constructor
  GatherScatterBaseImpl(const GridType & grid, MakeableEntityType & en, 
      RealEntityType & realEntity , DataCollectorType & dc) 
    : grid_(grid), entity_(en), realEntity_(realEntity) 
    , dc_(dc) , variableSize_ ( ! dc_.fixedsize( EntityType :: dimension, codim ))
  {}

  // return true if dim,codim combination is contained in data set 
  bool contains(int dim, int codim) const 
  {
    return dc_.contains(dim,codim);
  }

  // return true if item might from entity belonging to data set  
  virtual bool containsItem (const HElementType & elem) const 
  {
    return elem.isLeafEntity();
  }

  // return true if item might from entity belonging to data set  
  virtual bool containsItem (const HGhostType & ghost) const = 0; 

  //! write Data of one element to stream 
  void sendData ( ObjectStreamType & str , const HElementType & elem )
  {
    assert( this->containsItem(elem) );
    realEntity_.setElement( const_cast<HElementType &> (elem) );

    // write size in case of variable size 
    writeSize( str, entity_);
    // gather data 
    dc_.gather(str, entity_);
  }
 
  //! write Data of one ghost element to stream 
  void sendData ( ObjectStreamType & str , const HGhostType& ghost)
  {
    assert( this->containsItem( ghost ) );

    // set ghost as entity
    realEntity_.setGhost( const_cast <HGhostType &> (ghost) );

    // write size in case of variable size 
    writeSize( str, entity_);
    // gather data 
    dc_.gather(str, entity_);
  }
 
  //! read Data of one element from stream 
  void recvData ( ObjectStreamType & str , HElementType & elem )
  {
    // assert( this->containsItem( elem ) );
    realEntity_.setElement( elem ); 
    
    size_t size = getSize(str, entity_); 
    dc_.scatter(str, entity_, size);
  }

  //! read Data of one element from stream 
  void recvData ( ObjectStreamType & str , HGhostType & ghost )
  {
    assert( this->containsItem( ghost ) );

    // set ghost as entity
    realEntity_.setGhost( ghost );

    size_t size = getSize(str , entity_ ); 
    dc_.scatter(str, entity_, size );
  }
  
protected:  
  size_t getSize(ObjectStreamType & str, EntityType & en)
  {
    if(variableSize_) 
    {
      size_t size;
      str.read(size);
      return size;
    }
    else 
      return dc_.size(en);
  }
  
  // write variable size to stream 
  void writeSize(ObjectStreamType & str, EntityType & en)
  {
    if( variableSize_ )
    {
      size_t size = dc_.size( en );
      str.write( size );
    }
  }
};

#if ALU3DGRID_PARALLEL
//! the corresponding interface class is defined in bsinclude.hh
template< class GridType, class DataCollectorType, int codim >
class GatherScatterLeafData 
: public GatherScatterBaseImpl< GridType, DataCollectorType, codim >
{
  enum { dim = GridType :: dimension };

  typedef GatherScatterBaseImpl<GridType,DataCollectorType,codim> BaseType;
  typedef typename GridType::template Codim<codim>::Entity EntityType;
  typedef Dune :: MakeableInterfaceObject<
    typename GridType::template Codim<codim>::Entity> MakeableEntityType;
  typedef typename MakeableEntityType :: ImplementationType RealEntityType;

  typedef typename GridType::MPICommunicatorType Comm;

  typedef Dune::ALU3dImplTraits< GridType::elementType, Comm > ImplTraits;
  typedef typename ImplTraits::template Codim< codim >::ImplementationType IMPLElementType;
  typedef typename ImplTraits::template Codim< codim >::InterfaceType HElementType;
  
  typedef typename ImplTraits::template Codim< 1 >::InterfaceType HFaceType;
  
  typedef typename ImplTraits::template Codim< 0 >::GhostInterfaceType HGhostType;
  typedef typename ImplTraits::template Codim< 0 >::GhostImplementationType ImplGhostType;

  typedef typename ImplTraits::PllElementType PllElementType;

public:
  // use all other containsItem methods from the base class 
  using BaseType :: containsItem ;

  //! Constructor
  GatherScatterLeafData(const GridType & grid, MakeableEntityType & en, 
      RealEntityType & realEntity , DataCollectorType & dc)
    : BaseType(grid,en,realEntity,dc) 
  {
    // if leaf vertices are communicated, 
    // make sure that vertex list is up2date 
    // but only do this, if vertex data contained,
    // because the list update is expensive  
    if( (codim == 3) && dc.contains(dim,codim) ) 
    {
      // call of this method forces update of list, 
      // if list is not up to date
      grid.getLeafVertexList();
    }
  } 

  // returns true, if element is contained in set of comm interface 
  bool containsItem (const HElementType & elem) const 
  {
    return elem.isLeafEntity();
  }

  // returns true, if element is contained in set of comm interface 
  bool containsItem (const HGhostType & ghost) const 
  {
    return ghost.isLeafEntity();
  }

  // returns true, if interior element is contained in set of comm interface 
  bool containsInterior (const HFaceType & face, PllElementType & pll) const 
  {
    return face.isInteriorLeaf();
  }

  // returns true, if ghost is contianed in set of comm interface 
  bool containsGhost (const HFaceType & face , PllElementType & pll) const 
  {
    return pll.ghostLeaf();
  }

  // set elem to realEntity
  void setElement(const HElementType & elem)
  {
    this->realEntity_.setElement(elem); 
  }
};

//! the corresponding interface class is defined in bsinclude.hh
template <class GridType, class DataCollectorType , int codim >
class GatherScatterLevelData 
: public GatherScatterBaseImpl<GridType,DataCollectorType,codim> 
{
  typedef GatherScatterBaseImpl<GridType,DataCollectorType,codim> BaseType;
  typedef typename GridType::template Codim<codim>::Entity EntityType;
  typedef Dune :: MakeableInterfaceObject<
    typename GridType::template Codim<codim>::Entity> MakeableEntityType;
  typedef typename MakeableEntityType :: ImplementationType RealEntityType;

  typedef typename GridType::MPICommunicatorType Comm;

  typedef Dune::ALU3dImplTraits< GridType::elementType, Comm > ImplTraits;
  typedef typename ImplTraits::template Codim< codim >::ImplementationType IMPLElementType;
  typedef typename ImplTraits::template Codim< codim >::InterfaceType HElementType;
  
  typedef typename ImplTraits::template Codim< 1 >::InterfaceType HFaceType;
  
  typedef typename ImplTraits::template Codim< 0 >::GhostInterfaceType HGhostType;
  typedef typename ImplTraits::template Codim< 0 >::GhostImplementationType ImplGhostType;

  typedef typename ImplTraits::PllElementType PllElementType;

  typedef typename GridType::LevelIndexSetImp LevelIndexSetImp;

  const LevelIndexSetImp & levelSet_;
  const int level_;
public:
  // use containsItem for ghost element from BaseType
  using BaseType :: containsItem ;

  //! Constructor
  GatherScatterLevelData(const GridType & grid, MakeableEntityType & en, 
      RealEntityType & realEntity , DataCollectorType & dc, 
      const LevelIndexSetImp & levelSet, const int level)
    : BaseType(grid,en,realEntity,dc) , levelSet_(levelSet) , level_(level) 
  {
  } 

  // returns true, if element is contained in set of comm interface 
  bool containsItem (const HElementType & elem) const 
  {
    return levelSet_.containsIndex(codim, elem.getIndex() );
  }

  // set elem to realEntity
  void setElement(const HElementType & elem)
  {
    this->realEntity_.setElement(elem,level_); 
  }
    
};


//! the corresponding interface class is defined in bsinclude.hh
template <class GridType, class DataCollectorType>
class GatherScatterLevelData<GridType,DataCollectorType,0>
: public GatherScatterBaseImpl<GridType,DataCollectorType,0> 
{
  enum { codim = 0 };
  typedef GatherScatterBaseImpl<GridType,DataCollectorType,codim> BaseType;
  typedef typename GridType::template Codim<codim>::Entity EntityType;
  typedef Dune :: MakeableInterfaceObject<
    typename GridType::template Codim<codim>::Entity> MakeableEntityType;
  typedef typename MakeableEntityType :: ImplementationType RealEntityType;

  typedef typename GridType::MPICommunicatorType Comm;

  typedef Dune::ALU3dImplTraits< GridType::elementType, Comm > ImplTraits;
  typedef typename ImplTraits::template Codim< codim >::ImplementationType IMPLElementType;
  typedef typename ImplTraits::template Codim< codim >::InterfaceType HElementType;
  
  typedef typename ImplTraits::template Codim< 1 >::InterfaceType HFaceType;
  
  typedef typename ImplTraits::template Codim< 0 >::GhostInterfaceType HGhostType;
  typedef typename ImplTraits::template Codim< 0 >::GhostImplementationType ImplGhostType;

  typedef typename ImplTraits::PllElementType PllElementType;

  typedef typename GridType::LevelIndexSetImp LevelIndexSetImp;

  const LevelIndexSetImp & levelSet_;
  const int level_;
public:
  //! Constructor
  GatherScatterLevelData(const GridType & grid, MakeableEntityType & en, 
      RealEntityType & realEntity , DataCollectorType & dc, 
      const LevelIndexSetImp & levelSet, const int level)
    : BaseType(grid,en,realEntity,dc) , levelSet_(levelSet) , level_(level) {} 

  // returns true, if element is contained in set of comm interface 
  bool containsItem (const HElementType & elem) const 
  {
    return levelSet_.containsIndex(codim, elem.getIndex() );
  }

  // returns true, if element is contained in set of comm interface 
  bool containsItem (const HGhostType & ghost) const 
  {
    assert( ghost.getGhost().first );
    return containsItem( * (ghost.getGhost().first) );
  }
  
  // returns true, if interior element is contained in set of comm interface 
  bool containsInterior (const HFaceType & face, PllElementType & pll) const 
  {
    // if face level is not level_ then interior cannot be contained 
    if(face.level() != level_) return false;

    typedef Gitter::helement_STI HElementType;
    typedef Gitter::hbndseg_STI HBndSegType;

    // check interior element here, might have a coarser level
    pair< HElementType *, HBndSegType * > p( (HElementType *)0, (HBndSegType *)0 );
    pll.getAttachedElement( p );
    assert( p.first );
    // check inside level 
    bool contained = (p.first->level() == level_);
    assert( contained == this->containsItem( *p.first ));
    return contained;
  }

  // returns true, if ghost is contianed in set of comm interface 
  bool containsGhost (const HFaceType & face, PllElementType & pll) const 
  {
    // if face level is not level_ then ghost cannot be contained 
    if(face.level() != level_) return false;
    // otherwise check ghost level 
    return (pll.ghostLevel() == level_);
  }
};
#endif // #if ALU3DGRID_PARALLEL

//! the corresponding interface class is defined in bsinclude.hh
template <class GridType, class DataCollectorType, class IndexOperatorType> 
class GatherScatterLoadBalance : public GatherScatter
{
protected:  
  enum { codim = 0 };
  typedef typename GridType::template Codim<0>::Entity EntityType;
  typedef Dune :: MakeableInterfaceObject<
    typename GridType::template Codim<0>::Entity> MakeableEntityType;
  typedef typename MakeableEntityType :: ImplementationType RealEntityType;

  typedef typename GridType::MPICommunicatorType Comm;

  typedef Dune::ALU3dImplTraits< GridType::elementType, Comm > ImplTraits;
  typedef typename ImplTraits::template Codim< codim >::ImplementationType IMPLElementType;
  typedef typename ImplTraits::template Codim< codim >::InterfaceType HElementType;
  
  typedef typename ImplTraits::template Codim< 1 >::InterfaceType HFaceType;
  
  typedef typename ImplTraits::template Codim< 0 >::GhostInterfaceType HGhostType;
  typedef typename ImplTraits::template Codim< 0 >::GhostImplementationType ImplGhostType;

  typedef typename ImplTraits::PllElementType PllElementType;

  GridType & grid_;

  EntityType     & entity_;
  RealEntityType & realEntity_;

  // data handle 
  DataCollectorType & dc_;
  IndexOperatorType & idxOp_;

  // used MessageBuffer 
  typedef typename GatherScatter :: ObjectStreamType ObjectStreamType;

public:
  //! Constructor
  GatherScatterLoadBalance(GridType & grid, MakeableEntityType & en, 
      RealEntityType & realEntity , DataCollectorType & dc, IndexOperatorType & idxOp ) 
    : grid_(grid), entity_(en), realEntity_(realEntity) 
    , dc_(dc) , idxOp_(idxOp) 
  {}

  // return true if dim,codim combination is contained in data set 
  bool contains(int dim, int codim) const 
  {
    return true; 
  }

  //! this method is called from the dunePackAll method of the corresponding 
  //! Macro element class of the BSGrid, see gitter_dune_pll*.*
  //! here the data is written to the ObjectStream 
  void inlineData ( ObjectStreamType & str , HElementType & elem )
  {
    str.write(grid_.maxLevel());
    // set element and then start 
    assert( elem.level () == 0 );
    realEntity_.setElement(elem);
    dc_.inlineData(str,entity_);
  }

  //! this method is called from the duneUnpackSelf method of the corresponding 
  //! Macro element class of the BSGrid, see gitter_dune_pll*.*
  //! here the data is read from the ObjectStream 
  void xtractData ( ObjectStreamType & str , HElementType & elem )
  {
    assert( elem.level () == 0 );
    int mxl; 
    str.read(mxl);
    // set element and then start 
    grid_.setMaxLevel(mxl);

    // reserve memory for new elements 
    size_t elChunk = idxOp_.newElements();
    assert( elChunk > 0 );
    
    realEntity_.setElement(elem);
    dc_.xtractData(str,entity_, elChunk);
  }

  //! call compress on data 
  void compress () 
  {
    dc_.compress();
  } 
};

/////////////////////////////////////////////////////////////////
//
//  --AdaptRestrictProlong 
//
/////////////////////////////////////////////////////////////////
template< class GridType, class AdaptDataHandle >
class AdaptRestrictProlongImpl
: public AdaptRestrictProlongType
{
  GridType & grid_;
  typedef typename GridType::template Codim<0>::Entity EntityType;
  typedef Dune :: MakeableInterfaceObject<
    typename GridType::template Codim<0>::Entity> MakeableEntityType;
  typedef typename MakeableEntityType :: ImplementationType RealEntityType;
  
  EntityType & reFather_;
  EntityType & reSon_;
  RealEntityType & realFather_;
  RealEntityType & realSon_;
 
  AdaptDataHandle &rp_;

  typedef typename GridType::MPICommunicatorType Comm;

  typedef Dune::ALU3dImplTraits< GridType::elementType, Comm > ImplTraits;
  typedef typename ImplTraits::HElementType HElementType;
  typedef typename ImplTraits::HBndSegType HBndSegType;
  typedef typename ImplTraits::BNDFaceType BNDFaceType;

public:
  //! Constructor
  AdaptRestrictProlongImpl ( GridType &grid,
                             MakeableEntityType &f, RealEntityType &rf,
                             MakeableEntityType &s, RealEntityType &rs,
                             AdaptDataHandle &rp ) 
    : grid_(grid)
    , reFather_(f)
    , reSon_(s)
    , realFather_(rf) 
    , realSon_(rs) 
    , rp_(rp) 
  {
  }

  virtual ~AdaptRestrictProlongImpl () 
  {
  }

  //! restrict data for elements 
  int preCoarsening ( HElementType & father )
  {
    realFather_.setElement( father );
    rp_.preCoarsening( reFather_ );
   
    // reset refinement marker 
    father.resetRefinedTag();
    return 0;
  }

  //! prolong data for elements 
  int postRefinement ( HElementType & father )
  {
    realFather_.setElement( father );
    rp_.postRefinement( reFather_ );

    // resert refinement markers
    father.resetRefinedTag();
    for( HElementType *son = father.down(); son ; son = son->next() )
      son->resetRefinedTag();

    return 0;
  }

  //! restrict data for ghost elements 
  int preCoarsening ( HBndSegType & ghost )
  {
    /*
    assert( ghost.bndtype() == ALU3DSPACE ProcessorBoundary_t );
    realFather_.setGhost( ghost );
    rp_.preCoarsening( reFather_ );
    */
    return 0;
  }


  //! prolong data for ghost elements 
  int postRefinement ( HBndSegType & ghost )
  {
    /*
    assert( ghost.bndtype() == ALU3DSPACE ProcessorBoundary_t );
    realFather_.setGhost( ghost );
    rp_.postRefinement( reFather_ );
    */
    return 0;
  }
};



template< class GridType, class AdaptDataHandle, class GlobalIdSetImp >
class AdaptRestrictProlongGlSet
: public AdaptRestrictProlongImpl< GridType, AdaptDataHandle >
{
  typedef AdaptRestrictProlongImpl< GridType, AdaptDataHandle > BaseType;
  GlobalIdSetImp & set_;
  typedef typename GridType::template Codim<0>::Entity EntityType;
  typedef Dune :: MakeableInterfaceObject<
    typename GridType::template Codim<0>::Entity> MakeableEntityType;
  typedef typename MakeableEntityType :: ImplementationType RealEntityType;
  
  typedef typename GridType::MPICommunicatorType Comm;

  typedef Dune::ALU3dImplTraits< GridType::elementType, Comm > ImplTraits;
  typedef typename ImplTraits::HElementType HElementType;
  typedef typename ImplTraits::HBndSegType HBndSegType;

public:
  //! Constructor
  AdaptRestrictProlongGlSet ( GridType &grid,
                              MakeableEntityType &f, RealEntityType &rf,
                              MakeableEntityType &s, RealEntityType &rs,
                              AdaptDataHandle &rp,
                              GlobalIdSetImp & set )
  : BaseType( grid, f, rf, s, rs, rp ),
    set_( set )
  {}

  virtual ~AdaptRestrictProlongGlSet () {}

  //! prolong data, elem is the father  
  int postRefinement ( HElementType & elem )
  {
    set_.postRefinement( elem );
    return BaseType :: postRefinement(elem );
  }
};

// this class is for counting the tree depth of the 
// element when unpacking data from load balance 
template <class GridType , class DataHandleType>
class LoadBalanceElementCount : public AdaptRestrictProlongType
{
  GridType & grid_;
  typedef typename GridType::template Codim<0>::Entity EntityType;
  typedef Dune :: MakeableInterfaceObject<
    typename GridType::template Codim<0>::Entity> MakeableEntityType;
  typedef typename MakeableEntityType :: ImplementationType RealEntityType;

  typedef typename GridType::Traits::LeafIndexSet LeafIndexSetType; 

  EntityType & reFather_;
  EntityType & reSon_;
  RealEntityType & realFather_;
  RealEntityType & realSon_;
 
  DataHandleType & dh_;

  typedef typename GridType::MPICommunicatorType Comm;

  typedef Dune::ALU3dImplTraits< GridType::elementType, Comm > ImplTraits;
  typedef typename ImplTraits::HElementType HElementType;
  typedef typename ImplTraits::HBndSegType HBndSegType;

  int newMemSize_;
public:
  //! Constructor
  LoadBalanceElementCount (GridType & grid, 
                           MakeableEntityType & f, RealEntityType & rf, 
                           MakeableEntityType & s, RealEntityType & rs,
                           DataHandleType & dh) 
    : grid_(grid)
    , reFather_(f)
    , reSon_(s)
    , realFather_(rf) 
    , realSon_(rs) 
    , dh_(dh) 
    , newMemSize_ (1) // we have at least one element (the macro element)
  {
  }

  virtual ~LoadBalanceElementCount () {}

  //! restrict data , elem is always the father 
  int postRefinement ( HElementType & elem )
  {
    // when called for a macro element, then a new tree is starting 
    // set to 1 because for only macro elements this method is not called 
    if( elem.level() == 0 ) newMemSize_ = 1;

    for( HElementType * son = elem.down() ; son ; son= son->next()) 
    {
      ++ newMemSize_;
    }
    return 0;
  }

  //! prolong data, elem is the father  
  int preCoarsening ( HElementType & elem )
  {
    return 0;
  }

  //! restrict data , elem is always the father 
  //! this method is for ghost elements 
  int preCoarsening ( HBndSegType & el )
  {
    return 0;
  }

  //! restrict data , elem is always the father 
  //! this method is for ghost elements 
  //! we need the ghost method because data is only inlined for interior
  //! elements, but we have to arange the ghost indices 
  int postRefinement ( HBndSegType & el )
  {
    return 0;
  }

  int newElements () const { return newMemSize_; }
};

} // end namespace ALUGridSpace

#endif // #ifndef DUNE_ALU3DGRIDDATAHANDLE_HH