DUNE-FEM (unstable)

commoperations.hh
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>
10 
11 namespace Dune
12 {
13 
14  namespace Fem
15  {
16 
21  // CombinedDataType
22  // ----------------
23 
24  template< class... DataHandle >
25  struct CombinedDataType;
26 
27  template< class DataHandle >
28  struct CombinedDataType< DataHandle >
29  {
30  typedef typename DataHandle::DataType Type;
31  };
32 
33  template< class DataHandle, class... Tail >
34  struct CombinedDataType< DataHandle, Tail... >
35  {
36  typedef typename DataHandle::DataType Type;
37  static_assert( std::is_same< Type, typename CombinedDataType< Tail... >::Type >::value, "Only data handles for the same data type can be combined." );
38  };
39 
40 
41 
42  // CombinedDataHandle
43  // ------------------
44 
48  template< class... DataHandle >
50  : public CommDataHandleIF< CombinedDataHandle< DataHandle... >, typename CombinedDataType< DataHandle... >::Type >
51  {
52  typedef std::tuple< DataHandle... > DataHandlerTupleType;
53  static constexpr std::size_t tupleSize = std::tuple_size< DataHandlerTupleType >::value;
54 
55  public:
56  typedef typename CombinedDataType< DataHandle... >::Type DataType;
57 
58  CombinedDataHandle ( const DataHandle &... handle )
59  : data_( handle... )
60  {}
61 
62  CombinedDataHandle ( const std::tuple< DataHandle... > &data )
63  : data_( data )
64  {}
65 
66  bool contains (int dim, int codim) const
67  {
68  bool value( false );
69  Hybrid::forEach( std::make_index_sequence< tupleSize >{},
70  [ & ]( auto i ){ value = ( value || std::get< i >( data_ ).contains( dim, codim ) ); } );
71  return value;
72  }
73 
74  bool fixedSize (int dim, int codim) const
75  {
76  bool value( true );
77  Hybrid::forEach( std::make_index_sequence< tupleSize >{},
78  [ & ]( auto i ){ value = ( value && std::get< i >( data_ ).fixedSize( dim, codim ) ); } );
79  return value;
80  }
81 
84  template<class MessageBufferImp, class EntityType>
85  void gather (MessageBufferImp& buff, const EntityType& en) const
86  {
87  Hybrid::forEach( std::make_index_sequence< tupleSize >{}, [ & ]( auto i ){ std::get< i >( data_ ).gather( buff, en ); } );
88  }
89 
92  template<class MessageBufferImp, class EntityType>
93  void scatter (MessageBufferImp& buff, const EntityType& en, std::size_t n)
94  {
95  Hybrid::forEach( std::make_index_sequence< tupleSize >{}, [ & ]( auto i ){ std::get< i >( data_ ).scatter( buff, en, n ); } );
96  }
97 
100  template<class EntityType>
101  std::size_t size (const EntityType& en) const
102  {
103  std::size_t value( 0 );
104  Hybrid::forEach( std::make_index_sequence< tupleSize >{}, [ & ]( auto i ){ value += std::get< i >( data_ ).size( en ); } );
105  return value;
106  }
107 
108  private:
109  DataHandlerTupleType data_;
110  };
111 
113  //
114  // --DiscreteFunctionCommunications
115  //
117 
122  {
123  enum dfCommunicationOperation { copy, add, sub, min, max };
124 
126  struct Copy
127  {
128  static const dfCommunicationOperation value = copy;
129  static const char * name ()
130  {
131  return "Copy";
132  }
133 
134  template <class DataType>
135  inline void operator () (const DataType & arg, DataType & dest) const
136  {
137  dest = arg;
138  }
139  };
140 
141 
143  struct Add
144  {
145  static const dfCommunicationOperation value = add;
146  static const char * name ()
147  {
148  return "Add";
149  }
150 
151  template <class DataType>
152  inline void operator () (const DataType & arg, DataType & dest) const
153  {
154  dest += arg;
155  }
156  };
157 
159  struct Sub
160  {
161  static const dfCommunicationOperation value = sub;
162  static const char * name ()
163  {
164  return "Sub";
165  }
166 
167  template <class DataType>
168  inline void operator () (const DataType & arg, DataType & dest) const
169  {
170  dest -= arg;
171  }
172  };
173 
175  struct Min
176  {
177  static const dfCommunicationOperation value = min;
178  static const char * name ()
179  {
180  return "Min";
181  }
182 
183  template <class DataType>
184  inline void operator () (const DataType & arg, DataType & dest) const
185  {
186  dest = std::min(dest,arg);
187  }
188  };
189 
191  struct Max
192  {
193  static const dfCommunicationOperation value = max;
194  static const char * name ()
195  {
196  return "Max";
197  }
198 
199  template <class DataType>
200  inline void operator () (const DataType & arg, DataType & dest) const
201  {
202  dest = std::max(dest,arg);
203  }
204  };
205  };
206 
208  //
209  // --LoadBalanceContainsCheck
210  //
212 
214  template <class DiscreteFunction>
216  {
217  public:
218  typedef DiscreteFunction DiscreteFunctionType ;
220 
221  explicit LoadBalanceLeafData( const DiscreteFunctionType& df ) {}
223  bool contains (const Entity& entity) const
224  {
225  return entity.isLeaf();
226  }
227  };
228 
230 
231  } // namespace Fem
232 
233 } // namespace Dune
234 
235 #endif // #ifndef DUNE_FEM_COMMOPERATIONS_HH
CommDataHandleIF describes the features of a data handle for communication in parallel runs using the...
Definition: datahandleif.hh:78
combine multiple data handles into one
Definition: commoperations.hh:51
check for sets of entities for the load balance procedure
Definition: commoperations.hh:216
Describes the parallel communication interface class for MessageBuffers and DataHandles.
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:101
void gather(MessageBufferImp &buff, const EntityType &en) const
loop over all internal data handlers and call gather for given entity
Definition: commoperations.hh:85
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:93
bool contains(const Entity &entity) const
return true if the data of this entity should be transfered during load balance
Definition: commoperations.hh:223
concept Entity
Model of a grid entity.
Definition: entity.hh:107
constexpr void forEach(Range &&range, F &&f)
Range based for loop.
Definition: hybridutilities.hh:256
constexpr auto max
Function object that returns the greater of the given values.
Definition: hybridutilities.hh:484
constexpr auto min
Function object that returns the smaller of the given values.
Definition: hybridutilities.hh:506
Dune namespace.
Definition: alignedallocator.hh:13
sum up data
Definition: commoperations.hh:144
just copy data
Definition: commoperations.hh:127
keep maximum
Definition: commoperations.hh:192
keep minimum
Definition: commoperations.hh:176
substract data
Definition: commoperations.hh:160
Mathematical operation apply during communication to data that is communicated enum of all avialable ...
Definition: commoperations.hh:122
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 14, 22:30, 2024)