dune-grid  2.3.1-rc1
lbdatahandle.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_ALUGRID_LBDATAHANDLE_HH
4 #define DUNE_ALUGRID_LBDATAHANDLE_HH
5 
7 
9 
10 namespace Dune
11 {
12 
13  template< class Grid, class DataHandleImpl, class Data >
15  {
16  typedef typename Grid :: Traits :: HierarchicIterator HierarchicIterator;
17 
18  public:
19  typedef typename Grid :: ObjectStreamType ObjectStream;
20 
22 
23  static const int dimension = Grid :: dimension;
24 
25  template< int codim >
26  struct Codim
27  {
28  typedef typename Grid :: Traits :: template Codim< codim > :: Entity Entity;
29  typedef typename Grid :: Traits :: template Codim< codim > :: EntityPointer
31  };
32 
33  typedef typename Codim< 0 > :: Entity Element;
34 
35  private:
36  const Grid &grid_;
37  DataHandle &dataHandle_;
38 
39  public:
40  ALUGridLoadBalanceDataHandle ( const Grid &grid, DataHandle &dataHandle )
41  : grid_( grid ),
42  dataHandle_( dataHandle )
43  {}
44 
45  void inlineData ( ObjectStream &stream, const Element &element ) const
46  {
47  inlineElementData( stream, element );
48 
49  const int maxLevel = grid_.maxLevel();
50  const HierarchicIterator end = element.hend( maxLevel );
51  for( HierarchicIterator it = element.hbegin( maxLevel ); it != end; ++it )
52  inlineElementData( stream, *it );
53  }
54 
55  void xtractData ( ObjectStream &stream, const Element &element, size_t newElements )
56  {
57  xtractElementData( stream, element );
58 
59  const int maxLevel = grid_.maxLevel();
60  const HierarchicIterator end = element.hend( maxLevel );
61  for( HierarchicIterator it = element.hbegin( maxLevel ); it != end; ++it )
62  xtractElementData( stream, *it );
63  }
64 
65  void compress ()
66  {}
67 
68  private:
69  void inlineElementData ( ObjectStream &stream, const Element &element ) const
70  {
71  // call element data direct without creating entity pointer
72  if( dataHandle_.contains( dimension, 0 ) )
73  {
74  inlineEntityData<0>( stream, element );
75  }
76 
77  // now call all higher codims
78  inlineCodimData< 1 >( stream, element );
79  inlineCodimData< 2 >( stream, element );
80  inlineCodimData< 3 >( stream, element );
81  }
82 
83  void xtractElementData ( ObjectStream &stream, const Element &element )
84  {
85  // call element data direct without creating entity pointer
86  if( dataHandle_.contains( dimension, 0 ) )
87  {
88  xtractEntityData<0>( stream, element );
89  }
90 
91  // now call all higher codims
92  xtractCodimData< 1 >( stream, element );
93  xtractCodimData< 2 >( stream, element );
94  xtractCodimData< 3 >( stream, element );
95  }
96 
97  template< int codim >
98  void inlineCodimData ( ObjectStream &stream, const Element &element ) const
99  {
100  typedef typename Codim< codim > :: EntityPointer EntityPointer;
101 
102  if( dataHandle_.contains( dimension, codim ) )
103  {
104  const int numSubEntities = element.template count< codim >();
105  for( int i = 0; i < numSubEntities; ++i )
106  {
107  const EntityPointer pEntity = element.template subEntity< codim >( i );
108  inlineEntityData< codim >( stream, *pEntity );
109  }
110  }
111  }
112 
113  template< int codim >
114  void xtractCodimData ( ObjectStream &stream, const Element &element )
115  {
116  typedef typename Codim< codim > :: EntityPointer EntityPointer;
117 
118  if( dataHandle_.contains( dimension, codim ) )
119  {
120  const int numSubEntities = element.template count< codim >();
121  for( int i = 0; i < numSubEntities; ++i )
122  {
123  const EntityPointer pEntity = element.template subEntity< codim >( i );
124  xtractEntityData< codim >( stream, *pEntity );
125  }
126  }
127  }
128 
129  template< int codim >
130  void inlineEntityData ( ObjectStream &stream,
131  const typename Codim< codim > :: Entity &entity ) const
132  {
133  const size_t size = dataHandle_.size( entity );
134  stream.write( size );
135  dataHandle_.gather( stream, entity );
136  }
137 
138  template< int codim >
139  void xtractEntityData ( ObjectStream &stream,
140  const typename Codim< codim > :: Entity &entity )
141  {
142  size_t size = 0;
143  stream.read( size );
144  dataHandle_.scatter( stream, entity, size );
145  }
146  };
147 
148 }
149 
150 #endif
static const int dimension
Definition: lbdatahandle.hh:23
Grid::Traits::template Codim< codim >::Entity Entity
Definition: lbdatahandle.hh:28
Wrapper class for entities.
Definition: common/entity.hh:56
int maxLevel() const
Return maximum level defined in this grid. Levels are numbered 0 ... maxLevel with 0 the coarsest lev...
Definition: common/grid.hh:559
ALUGridLoadBalanceDataHandle(const Grid &grid, DataHandle &dataHandle)
Definition: lbdatahandle.hh:40
void gather(MessageBufferImp &buff, const EntityType &e) const
pack data from user to message buffer
Definition: datahandleif.hh:123
Definition: lbdatahandle.hh:26
Grid::ObjectStreamType ObjectStream
Definition: lbdatahandle.hh:19
void compress()
Definition: lbdatahandle.hh:65
bool contains(int dim, int codim) const
returns true if data for given valid codim should be communicated
Definition: datahandleif.hh:90
void xtractData(ObjectStream &stream, const Element &element, size_t newElements)
Definition: lbdatahandle.hh:55
The dimension of the grid.
Definition: common/grid.hh:400
CommDataHandleIF describes the features of a data handle for communication in parallel runs using the...
Definition: datahandleif.hh:74
void inlineData(ObjectStream &stream, const Element &element) const
Definition: lbdatahandle.hh:45
Grid abstract base classThis class is the base class for all grid implementations. Although no virtual functions are used we call it abstract since its methods do not contain an implementation but forward to the methods of the derived class via the Barton-Nackman trick.
Definition: common/grid.hh:386
Definition: lbdatahandle.hh:14
Grid::Traits::template Codim< codim >::EntityPointer EntityPointer
Definition: lbdatahandle.hh:30
size_t size(const EntityType &e) const
how many objects of type DataType have to be sent for a given entity
Definition: datahandleif.hh:112
Codim< 0 >::Entity Element
Definition: lbdatahandle.hh:33
void scatter(MessageBufferImp &buff, const EntityType &e, size_t n)
unpack data from message buffer to user.
Definition: datahandleif.hh:135
CommDataHandleIF< DataHandleImpl, Data > DataHandle
Definition: lbdatahandle.hh:21
Describes the parallel communication interface class for MessageBuffers and DataHandles.