dune-grid  2.2.1
lbdatahandle.hh
Go to the documentation of this file.
1 #ifndef DUNE_ALUGRID_LBDATAHANDLE_HH
2 #define DUNE_ALUGRID_LBDATAHANDLE_HH
3 
5 
7 
8 namespace Dune
9 {
10 
11  template< class Grid, class DataHandleImpl, class Data >
13  {
14  typedef typename Grid :: Traits :: HierarchicIterator HierarchicIterator;
15 
16  public:
17  typedef typename Grid :: ObjectStreamType ObjectStream;
18 
20 
21  static const int dimension = Grid :: dimension;
22 
23  template< int codim >
24  struct Codim
25  {
26  typedef typename Grid :: Traits :: template Codim< codim > :: Entity Entity;
27  typedef typename Grid :: Traits :: template Codim< codim > :: EntityPointer
29  };
30 
31  typedef typename Codim< 0 > :: Entity Element;
32 
33  private:
34  const Grid &grid_;
35  DataHandle &dataHandle_;
36 
37  public:
38  ALUGridLoadBalanceDataHandle ( const Grid &grid, DataHandle &dataHandle )
39  : grid_( grid ),
40  dataHandle_( dataHandle )
41  {}
42 
43  void inlineData ( ObjectStream &stream, const Element &element ) const
44  {
45  inlineElementData( stream, element );
46 
47  const int maxLevel = grid_.maxLevel();
48  const HierarchicIterator end = element.hend( maxLevel );
49  for( HierarchicIterator it = element.hbegin( maxLevel ); it != end; ++it )
50  inlineElementData( stream, *it );
51  }
52 
53  void xtractData ( ObjectStream &stream, const Element &element, size_t newElements )
54  {
55  xtractElementData( stream, element );
56 
57  const int maxLevel = grid_.maxLevel();
58  const HierarchicIterator end = element.hend( maxLevel );
59  for( HierarchicIterator it = element.hbegin( maxLevel ); it != end; ++it )
60  xtractElementData( stream, *it );
61  }
62 
63  void compress ()
64  {}
65 
66  private:
67  void inlineElementData ( ObjectStream &stream, const Element &element ) const
68  {
69  // call element data direct without creating entity pointer
70  if( dataHandle_.contains( dimension, 0 ) )
71  {
72  inlineEntityData<0>( stream, element );
73  }
74 
75  // now call all higher codims
76  inlineCodimData< 1 >( stream, element );
77  inlineCodimData< 2 >( stream, element );
78  inlineCodimData< 3 >( stream, element );
79  }
80 
81  void xtractElementData ( ObjectStream &stream, const Element &element )
82  {
83  // call element data direct without creating entity pointer
84  if( dataHandle_.contains( dimension, 0 ) )
85  {
86  xtractEntityData<0>( stream, element );
87  }
88 
89  // now call all higher codims
90  xtractCodimData< 1 >( stream, element );
91  xtractCodimData< 2 >( stream, element );
92  xtractCodimData< 3 >( stream, element );
93  }
94 
95  template< int codim >
96  void inlineCodimData ( ObjectStream &stream, const Element &element ) const
97  {
98  typedef typename Codim< codim > :: EntityPointer EntityPointer;
99 
100  if( dataHandle_.contains( dimension, codim ) )
101  {
102  const int numSubEntities = element.template count< codim >();
103  for( int i = 0; i < numSubEntities; ++i )
104  {
105  const EntityPointer pEntity = element.template subEntity< codim >( i );
106  inlineEntityData< codim >( stream, *pEntity );
107  }
108  }
109  }
110 
111  template< int codim >
112  void xtractCodimData ( ObjectStream &stream, const Element &element )
113  {
114  typedef typename Codim< codim > :: EntityPointer EntityPointer;
115 
116  if( dataHandle_.contains( dimension, codim ) )
117  {
118  const int numSubEntities = element.template count< codim >();
119  for( int i = 0; i < numSubEntities; ++i )
120  {
121  const EntityPointer pEntity = element.template subEntity< codim >( i );
122  xtractEntityData< codim >( stream, *pEntity );
123  }
124  }
125  }
126 
127  template< int codim >
128  void inlineEntityData ( ObjectStream &stream,
129  const typename Codim< codim > :: Entity &entity ) const
130  {
131  const size_t size = dataHandle_.size( entity );
132  stream.write( size );
133  dataHandle_.gather( stream, entity );
134  }
135 
136  template< int codim >
137  void xtractEntityData ( ObjectStream &stream,
138  const typename Codim< codim > :: Entity &entity )
139  {
140  size_t size = 0;
141  stream.read( size );
142  dataHandle_.scatter( stream, entity, size );
143  }
144  };
145 
146 }
147 
148 #endif