Dune Core Modules (2.3.1)

lbdatahandle.hh
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
6#include <dune/grid/alugrid/3d/datahandle.hh>
7
9
10namespace Dune
11{
12
13 template< class Grid, class DataHandleImpl, class Data >
14 class ALUGridLoadBalanceDataHandle
15 {
16 typedef typename Grid :: Traits :: HierarchicIterator HierarchicIterator;
17
18 public:
19 typedef typename Grid :: ObjectStreamType ObjectStream;
20
21 typedef CommDataHandleIF< DataHandleImpl, Data > DataHandle;
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
30 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
@ dimension
The dimension of the grid.
Definition: grid.hh:400
Describes the parallel communication interface class for MessageBuffers and DataHandles.
Dune namespace.
Definition: alignment.hh:14
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)