dune-fem  2.6-git
commoperations.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_COMMOPERATIONS_HH
2 #define DUNE_FEM_COMMOPERATIONS_HH
3 
4 #include <tuple>
5 #include <type_traits>
6 #include <utility>
7 
8 #include <dune/common/hybridutilities.hh>
9 #include <dune/common/std/utility.hh>
10 #include <dune/grid/common/datahandleif.hh>
11 
12 namespace Dune
13 {
14 
15  namespace Fem
16  {
17 
22  // CombinedDataType
23  // ----------------
24 
25  template< class... DataHandle >
27 
28  template< class DataHandle >
29  struct CombinedDataType< DataHandle >
30  {
31  typedef typename DataHandle::DataType Type;
32  };
33 
34  template< class DataHandle, class... Tail >
35  struct CombinedDataType< DataHandle, Tail... >
36  {
37  typedef typename DataHandle::DataType Type;
38  static_assert( std::is_same< Type, typename CombinedDataType< Tail... >::Type >::value, "Only data handles for the same data type can be combined." );
39  };
40 
41 
42 
43  // CombinedDataHandle
44  // ------------------
45 
49  template< class... DataHandle >
51  : public CommDataHandleIF< CombinedDataHandle< DataHandle... >, typename CombinedDataType< DataHandle... >::Type >
52  {
53  typedef std::tuple< DataHandle... > DataHandlerTupleType;
54  static constexpr std::size_t tupleSize = std::tuple_size< DataHandlerTupleType >::value;
55 
56  public:
57  typedef typename CombinedDataType< DataHandle... >::Type DataType;
58 
59  CombinedDataHandle ( const DataHandle &... handle )
60  : data_( handle... )
61  {}
62 
63  CombinedDataHandle ( const std::tuple< DataHandle... > &data )
64  : data_( data )
65  {}
66 
67  bool contains (int dim, int codim) const
68  {
69  bool value( false );
70  Hybrid::forEach( Std::make_index_sequence< tupleSize >{},
71  [ & ]( auto i ){ value = ( value || std::get< i >( data_ ).contains( dim, codim ) ); } );
72  return value;
73  }
74 
75  bool fixedsize (int dim, int codim) const
76  {
77  bool value( true );
78  Hybrid::forEach( Std::make_index_sequence< tupleSize >{},
79  [ & ]( auto i ){ value = ( value && std::get< i >( data_ ).fixedsize( dim, codim ) ); } );
80  return value;
81  }
82 
85  template<class MessageBufferImp, class EntityType>
86  void gather (MessageBufferImp& buff, const EntityType& en) const
87  {
88  Hybrid::forEach( Std::make_index_sequence< tupleSize >{}, [ & ]( auto i ){ std::get< i >( data_ ).gather( buff, en ); } );
89  }
90 
93  template<class MessageBufferImp, class EntityType>
94  void scatter (MessageBufferImp& buff, const EntityType& en, std::size_t n)
95  {
96  Hybrid::forEach( Std::make_index_sequence< tupleSize >{}, [ & ]( auto i ){ std::get< i >( data_ ).scatter( buff, en, n ); } );
97  }
98 
101  template<class EntityType>
102  std::size_t size (const EntityType& en) const
103  {
104  std::size_t value( 0 );
105  Hybrid::forEach( Std::make_index_sequence< tupleSize >{}, [ & ]( auto i ){ value += std::get< i >( data_ ).size( en ); } );
106  return value;
107  }
108 
109  private:
110  DataHandlerTupleType data_;
111  };
112 
114  //
115  // --DiscreteFunctionCommunications
116  //
118 
123  {
125 
127  struct Copy
128  {
130  static const char * name ()
131  {
132  return "Copy";
133  }
134 
135  template <class DataType>
136  inline void operator () (const DataType & arg, DataType & dest) const
137  {
138  dest = arg;
139  }
140  };
141 
142 
144  struct Add
145  {
147  static const char * name ()
148  {
149  return "Add";
150  }
151 
152  template <class DataType>
153  inline void operator () (const DataType & arg, DataType & dest) const
154  {
155  dest += arg;
156  }
157  };
158 
160  struct Sub
161  {
163  static const char * name ()
164  {
165  return "Sub";
166  }
167 
168  template <class DataType>
169  inline void operator () (const DataType & arg, DataType & dest) const
170  {
171  dest -= arg;
172  }
173  };
174 
176  struct Min
177  {
179  static const char * name ()
180  {
181  return "Min";
182  }
183 
184  template <class DataType>
185  inline void operator () (const DataType & arg, DataType & dest) const
186  {
187  dest = std::min(dest,arg);
188  }
189  };
190 
192  struct Max
193  {
195  static const char * name ()
196  {
197  return "Max";
198  }
199 
200  template <class DataType>
201  inline void operator () (const DataType & arg, DataType & dest) const
202  {
203  dest = std::max(dest,arg);
204  }
205  };
206  };
207 
209  //
210  // --LoadBalanceContainsCheck
211  //
213 
215  template <class DiscreteFunction>
217  {
218  public:
219  typedef DiscreteFunction DiscreteFunctionType ;
220  typedef typename DiscreteFunctionType :: DiscreteFunctionSpaceType :: IteratorType :: Entity Entity;
221 
222  explicit LoadBalanceLeafData( const DiscreteFunctionType& df ) {}
224  bool contains (const Entity& entity) const
225  {
226  return entity.isLeaf();
227  }
228  };
229 
231 
232  } // namespace Fem
233 
234 } // namespace Dune
235 
236 #endif // #ifndef DUNE_FEM_COMMOPERATIONS_HH
LoadBalanceLeafData(const DiscreteFunctionType &df)
Definition: commoperations.hh:222
DiscreteFunctionType ::DiscreteFunctionSpaceType ::IteratorType ::Entity Entity
Definition: commoperations.hh:220
static const char * name()
Definition: commoperations.hh:179
CombinedDataHandle(const std::tuple< DataHandle... > &data)
Definition: commoperations.hh:63
DiscreteFunction DiscreteFunctionType
Definition: commoperations.hh:219
static const dfCommunicationOperation value
Definition: commoperations.hh:178
void operator()(const DataType &arg, DataType &dest) const
Definition: commoperations.hh:201
void operator()(const DataType &arg, DataType &dest) const
Definition: commoperations.hh:153
dfCommunicationOperation
Definition: commoperations.hh:124
std::size_t size(const EntityType &en) const
loop over all internal data handlers and return sum of data size of given entity
Definition: commoperations.hh:102
void gather(MessageBufferImp &buff, const EntityType &en) const
loop over all internal data handlers and call gather for given entity
Definition: commoperations.hh:86
void scatter(MessageBufferImp &buff, const EntityType &en, std::size_t n)
loop over all internal data handlers and call scatter for given entity
Definition: commoperations.hh:94
void operator()(const DataType &arg, DataType &dest) const
Definition: commoperations.hh:169
CombinedDataType< DataHandle... >::Type DataType
Definition: commoperations.hh:57
static const dfCommunicationOperation value
Definition: commoperations.hh:194
static const char * name()
Definition: commoperations.hh:147
DataHandle::DataType Type
Definition: commoperations.hh:37
static const char * name()
Definition: commoperations.hh:130
static const char * name()
Definition: commoperations.hh:163
void operator()(const DataType &arg, DataType &dest) const
Definition: commoperations.hh:136
static const char * name()
Definition: commoperations.hh:195
bool fixedsize(int dim, int codim) const
Definition: commoperations.hh:75
static const dfCommunicationOperation value
Definition: commoperations.hh:146
static const dfCommunicationOperation value
Definition: commoperations.hh:162
bool contains(int dim, int codim) const
Definition: commoperations.hh:67
void operator()(const DataType &arg, DataType &dest) const
Definition: commoperations.hh:185
CombinedDataHandle(const DataHandle &... handle)
Definition: commoperations.hh:59
DataHandle::DataType Type
Definition: commoperations.hh:31
static const dfCommunicationOperation value
Definition: commoperations.hh:129
bool contains(const Entity &entity) const
return true if the data of this entity should be transfered during load balance
Definition: commoperations.hh:224
@ sub
Definition: commoperations.hh:124
@ copy
Definition: commoperations.hh:124
@ max
Definition: commoperations.hh:124
@ min
Definition: commoperations.hh:124
@ add
Definition: commoperations.hh:124
Definition: bindguard.hh:11
static void forEach(IndexRange< T, sz > range, F &&f)
Definition: hybrid.hh:129
static constexpr T max(T a)
Definition: utility.hh:77
static constexpr T min(T a)
Definition: utility.hh:93
Definition: commoperations.hh:26
combine multiple data handles into one
Definition: commoperations.hh:52
Mathematical operation apply during communication to data that is communicated enum of all avialable ...
Definition: commoperations.hh:123
just copy data
Definition: commoperations.hh:128
sum up data
Definition: commoperations.hh:145
substract data
Definition: commoperations.hh:161
keep minimum
Definition: commoperations.hh:177
keep maximum
Definition: commoperations.hh:193
check for sets of entities for the load balance procedure
Definition: commoperations.hh:217