dune-fem 2.8.0
Loading...
Searching...
No Matches
tuplespace.hh
Go to the documentation of this file.
1#ifndef DUNE_FEM_SPACE_COMBINEDSPACE_TUPLESPACE_HH
2#define DUNE_FEM_SPACE_COMBINEDSPACE_TUPLESPACE_HH
3
4#include <algorithm>
5#include <memory>
6#include <type_traits>
7#include <utility>
8
9#include <dune/common/hybridutilities.hh>
10#include <dune/common/math.hh>
11
12#include <dune/grid/common/grid.hh>
13
24
25namespace Dune
26{
27
28 namespace Fem
29 {
30
31 // forward declaration
32 template< class CombineOp, class ... DiscreteFunctionSpaces >
33 class TupleDiscreteFunctionSpaceImpl;
34
35 // TupleDiscreteFunctionSpaceTraits
36 // --------------------------------
37
38 template< class CombineOp, class ... DiscreteFunctionSpaces >
40 {
41 static_assert( sizeof ... ( DiscreteFunctionSpaces ) > 0,
42 "You should provide at least one space to the TupleDiscreteFunctionSpace" );
43
44 // we need to store pointer to the spaces in the SpaceTuple, since space can not be copied.
45 typedef std::tuple< std::shared_ptr< DiscreteFunctionSpaces > ... > DiscreteFunctionSpaceTupleType;
46
47 public:
48 // helper struct to access contained sub spaces
49 template< int i >
51 {
52 // type of i-th sub space
53 typedef typename std::tuple_element< i, DiscreteFunctionSpaceTupleType >::type::element_type Type;
54
55 // type of i-th sub BlockMapper
56 typedef typename Type::BlockMapperType BlockMapperType;
57
58 // we will unblock all mappers
60
61 // access to a const ref of the i-th subspace
63 {
64 assert( std::get< i >( tuple ) );
65 return *( std::get< i >( tuple ) );
66 }
67
69 {
70 return subDiscreteFunctionSpace( tuple ).blockMapper();
71 }
72
74 {
75 return NonBlockMapperType( subDiscreteFunctionSpace( tuple ).blockMapper() );
76 }
77 };
78
79 public:
81 "TupleDiscreteFunctionSpace works only for GridPart's with the same entity type" );
82
84 "TupleDiscreteFunctionSpace for spaces with different codimensions is not supported" );
86
88 typedef typename GridPartType::GridType GridType;
89 typedef typename GridPartType::IndexSetType IndexSetType;
90 typedef typename GridPartType::template Codim< 0 >::IteratorType IteratorType;
91 typedef typename IteratorType::Entity EntityType;
92 typedef typename GridPartType::IntersectionType IntersectionType;
93
94 // type of this space
95 typedef TupleDiscreteFunctionSpaceImpl< CombineOp, DiscreteFunctionSpaces ... > DiscreteFunctionSpaceType;
96
98 typedef TupleBasisFunctionSet< CombineOp, typename DiscreteFunctionSpaces::BasisFunctionSetType ... > BasisFunctionSetType;
99
100 // mapper
102
103 // in the most general case we will unroll all local blockings
104 typedef std::index_sequence< 0 > LocalBlockIndices;
105
106 // type functionspace
108
109 typedef TupleSpaceInterpolation< CombineOp, DiscreteFunctionSpaces ... > InterpolationImplType;
110
111 // review to make it work for all kind of combinations
112 template< class DiscreteFunction, class Operation = DFCommunicationOperation::Copy >
114 {
118 typedef Operation OperationType;
119 };
120
121 // construct new instance of blockMapper
123 {
124 return getBlockMapper( spaceTuple, std::index_sequence_for< DiscreteFunctionSpaces ... >() );
125 }
126
127 // create Tuple of contained subspaces
128 static DiscreteFunctionSpaceTupleType createSpaces ( GridPartType &gridPart, InterfaceType commInterface,
129 CommunicationDirection commDirection )
130 {
132 Hybrid::forEach( std::make_index_sequence< sizeof ... ( DiscreteFunctionSpaces ) >{},
133 [ & ]( auto i )
134 {
135 typedef typename SubDiscreteFunctionSpace< i >::Type Element;
136 std::get< i >( tuple ) = std::make_shared< Element >( gridPart, commInterface, commDirection );
137 } );
138 return tuple;
139 }
140
141 template< class Entity >
142 static BasisFunctionSetType getBasisFunctionSet ( const Entity &entity, const DiscreteFunctionSpaceTupleType &tuple )
143 {
144 return getBasisFunctionSet( entity, tuple, std::index_sequence_for< DiscreteFunctionSpaces ... >() );
145 }
146
147 template< class T, class F >
148 static T accumulate ( const DiscreteFunctionSpaceTupleType &tuple, T value, F &&f )
149 {
150 Hybrid::forEach( std::index_sequence_for< DiscreteFunctionSpaces... >{}, [ & ] ( auto &&idx ) {
151 const std::size_t i = std::decay_t< decltype( idx ) >::value;
153 } );
154 return value;
155 }
156
157 protected:
158 template< std::size_t ... i >
159 static BlockMapperType *getBlockMapper ( const DiscreteFunctionSpaceTupleType &tuple, std::index_sequence< i ... > )
160 {
163 }
164
165 template< class Entity, std::size_t ... i >
167 std::index_sequence< i ... > )
168 {
169 return BasisFunctionSetType( SubDiscreteFunctionSpace< i >::subDiscreteFunctionSpace( tuple ).basisFunctionSet( entity ) ... );
170 }
171 };
172
173
174
189 template< class CombineOp, class ... DiscreteFunctionSpaces >
191 : public GenericCombinedDiscreteFunctionSpace< TupleDiscreteFunctionSpaceTraits< CombineOp, DiscreteFunctionSpaces ... > >
192 {
193 typedef TupleDiscreteFunctionSpaceImpl< CombineOp, DiscreteFunctionSpaces ... > ThisType;
194 typedef GenericCombinedDiscreteFunctionSpace< TupleDiscreteFunctionSpaceTraits< CombineOp, DiscreteFunctionSpaces ... > > BaseType;
195
196 public:
197 typedef decltype ( std::index_sequence_for< DiscreteFunctionSpaces ... >() ) Sequence;
198 typedef typename BaseType::Traits Traits;
201
202 typedef typename Traits::InterpolationImplType InterpolationImplType;
203
205 typedef typename Traits::DiscreteFunctionSpaceTupleType DiscreteFunctionSpaceTupleType;
206
215 const InterfaceType commInterface = InteriorBorder_All_Interface,
216 const CommunicationDirection commDirection = ForwardCommunication )
217 : BaseType( gridPart, commInterface, commDirection )
218 {}
219
227 TupleDiscreteFunctionSpaceImpl ( DiscreteFunctionSpaces &&... spaces )
228 : BaseType( std::make_tuple( std::make_shared( std::move( spaces ) )... ) )
229 {}
230
238 TupleDiscreteFunctionSpaceImpl ( const DiscreteFunctionSpaces &... spaces )
239 : BaseType( std::make_tuple( referenceToSharedPtr( spaces )... ) )
240 {}
241
249 TupleDiscreteFunctionSpaceImpl ( std::shared_ptr< const DiscreteFunctionSpaces >... spaces )
250 : BaseType( std::make_tuple( std::move( spaces )... ) )
251 {}
252
261 : BaseType( std::move( spaceTuple ) )
262 {}
263
265 ThisType &operator= ( const ThisType & ) = delete;
266
268 std::tuple< const DiscreteFunctionSpaces & ... > spaceTuple () const
269 {
270 return spaceTuple( std::index_sequence_for< DiscreteFunctionSpaces ... >() );
271 }
272
274 {
275 return InterpolationType( *this );
276 }
277
278 [[deprecated]]
280 {
281 return localInterpolation( entity );
282 }
283
285 {
286 return localInterpolation( entity, std::index_sequence_for< DiscreteFunctionSpaces ... >() );
287 }
288
289 protected:
290 template< std::size_t ... i >
291 std::tuple< const DiscreteFunctionSpaces & ... > spaceTuple ( std::index_sequence< i ... > ) const
292 {
293 return std::tuple< const DiscreteFunctionSpaces & ... >( BaseType::template subDiscreteFunctionSpace< i >() ... );
294 }
295
296 template< std::size_t ... i >
297 InterpolationImplType localInterpolation ( const EntityType &entity, std::index_sequence< i ... > ) const
298 {
299 return InterpolationImplType( std::get< i >( spaceTuple() ) ..., entity );
300 }
301 };
302
303
304
305 // DifferentDiscreteFunctionSpace
306 // ------------------------------
307
309 template< class CombineOp, class ... DiscreteFunctionSpaces, class NewFunctionSpace >
310 struct DifferentDiscreteFunctionSpace< TupleDiscreteFunctionSpaceImpl< CombineOp, DiscreteFunctionSpaces... >, NewFunctionSpace >
311 {
312 static_assert( (NewFunctionSpace::dimRange % TupleDiscreteFunctionSpaceImpl< CombineOp, DiscreteFunctionSpaces... >::dimRange == 0),
313 "DifferentDiscreteFunctionSpace can only be applied to TupleFunctionSpace, if new dimRange is a multiple of the original one." );
314
315 private:
316 static const int factor = (NewFunctionSpace::dimRange / TupleDiscreteFunctionSpaceImpl< CombineOp, DiscreteFunctionSpaces... >::dimRange);
317
318 template< class DiscreteFunctionSpace >
320
321 public:
323 };
324
325
326
327 // DefaultLocalRestrictProlong
328 // ---------------------------
329
330 template< class CombineOp, class ... DiscreteFunctionSpaces >
331 class DefaultLocalRestrictProlong< TupleDiscreteFunctionSpaceImpl< CombineOp, DiscreteFunctionSpaces ... > >
332 : public TupleLocalRestrictProlong< DiscreteFunctionSpaces ... >
333 {
334 typedef DefaultLocalRestrictProlong< TupleDiscreteFunctionSpaceImpl< CombineOp, DiscreteFunctionSpaces ... > > ThisType;
335 typedef TupleDiscreteFunctionSpaceImpl< CombineOp, DiscreteFunctionSpaces ... > DiscreteFunctionSpacesType;
336 typedef TupleLocalRestrictProlong< DiscreteFunctionSpaces ... > BaseType;
337
338 public:
340 : BaseType( space.spaceTuple() )
341 {}
342
343 };
344
345 // Creating a space V = V_1 x V_2 x ...
346 template < class ... DiscreteFunctionSpaces >
348
349 // Creating a space V = V_1 + V_2 + ...
350 template < class ... DiscreteFunctionSpaces >
352
353 template < class ... DiscreteFunctionSpaces >
355
356 } // namespace Fem
357
358} // namespace Dune
359
360#endif // #ifndef DUNE_FEM_SPACE_COMBINEDSPACE_TUPLESPACE_HH
STL namespace.
Definition: bindguard.hh:11
static std::shared_ptr< T > referenceToSharedPtr(T &t)
Definition: memory.hh:19
static void forEach(IndexRange< T, sz > range, F &&f)
Definition: hybrid.hh:129
Definition: utility.hh:147
Definition: space/basisfunctionset/tuple.hh:34
Definition: space/basisfunctionset/tuple.hh:35
Definition: space/basisfunctionset/tuple.hh:39
CombinationType::FunctionSpaceType FunctionSpaceType
type of analytical combined function space
Definition: space/basisfunctionset/tuple.hh:195
Definition: combinedspace/generic.hh:23
Definition: combinedspace/interpolation.hh:106
Definition: tuplelocalrestrictprolong.hh:31
mapper allocating one DoF per subentity of a given codimension
Definition: tuplemapper.hh:510
Definition: tuplespace.hh:192
std::tuple< const DiscreteFunctionSpaces &... > spaceTuple() const
return tuple of const References to the contained sub spaces
Definition: tuplespace.hh:268
TupleDiscreteFunctionSpaceImpl(std::shared_ptr< const DiscreteFunctionSpaces >... spaces)
constructor
Definition: tuplespace.hh:249
BaseType::EntityType EntityType
Definition: tuplespace.hh:200
InterpolationImplType interpolation(const EntityType &entity) const
Definition: tuplespace.hh:279
decltype(std::index_sequence_for< DiscreteFunctionSpaces ... >()) Sequence
Definition: tuplespace.hh:197
InterpolationType interpolation() const
Definition: tuplespace.hh:273
Traits::InterpolationImplType InterpolationImplType
Definition: tuplespace.hh:202
LocalInterpolationWrapper< ThisType > InterpolationType
Definition: tuplespace.hh:204
TupleDiscreteFunctionSpaceImpl(DiscreteFunctionSpaces &&... spaces)
constructor
Definition: tuplespace.hh:227
TupleDiscreteFunctionSpaceImpl(const ThisType &)=delete
ThisType & operator=(const ThisType &)=delete
BaseType::Traits Traits
Definition: tuplespace.hh:198
InterpolationImplType localInterpolation(const EntityType &entity) const
Definition: tuplespace.hh:284
Traits::DiscreteFunctionSpaceTupleType DiscreteFunctionSpaceTupleType
Definition: tuplespace.hh:205
TupleDiscreteFunctionSpaceImpl(const DiscreteFunctionSpaces &... spaces)
constructor
Definition: tuplespace.hh:238
BaseType::GridPartType GridPartType
Definition: tuplespace.hh:199
std::tuple< const DiscreteFunctionSpaces &... > spaceTuple(std::index_sequence< i ... >) const
Definition: tuplespace.hh:291
TupleDiscreteFunctionSpaceImpl(GridPartType &gridPart, const InterfaceType commInterface=InteriorBorder_All_Interface, const CommunicationDirection commDirection=ForwardCommunication)
constructor
Definition: tuplespace.hh:214
InterpolationImplType localInterpolation(const EntityType &entity, std::index_sequence< i ... >) const
Definition: tuplespace.hh:297
TupleDiscreteFunctionSpaceImpl(DiscreteFunctionSpaceTupleType spaceTuple)
constructor
Definition: tuplespace.hh:260
TupleSpaceInterpolation< CombineOp, DiscreteFunctionSpaces ... > InterpolationImplType
Definition: tuplespace.hh:109
TupleDiscreteFunctionSpaceImpl< CombineOp, DiscreteFunctionSpaces ... > DiscreteFunctionSpaceType
Definition: tuplespace.hh:95
static const int codimension
Definition: tuplespace.hh:85
TupleBasisFunctionSet< CombineOp, typename DiscreteFunctionSpaces::BasisFunctionSetType ... > BasisFunctionSetType
implementation of basefunction set
Definition: tuplespace.hh:98
SubDiscreteFunctionSpace< 0 >::Type::GridPartType GridPartType
Definition: tuplespace.hh:87
GridPartType::template Codim< 0 >::IteratorType IteratorType
Definition: tuplespace.hh:90
BasisFunctionSetType::FunctionSpaceType FunctionSpaceType
Definition: tuplespace.hh:107
TupleMapper< GridPartType, NonBlockMapper< typename DiscreteFunctionSpaces::BlockMapperType, DiscreteFunctionSpaces::localBlockSize > ... > BlockMapperType
Definition: tuplespace.hh:101
static BlockMapperType * getBlockMapper(const DiscreteFunctionSpaceTupleType &tuple, std::index_sequence< i ... >)
Definition: tuplespace.hh:159
GridPartType::IndexSetType IndexSetType
Definition: tuplespace.hh:89
static BasisFunctionSetType getBasisFunctionSet(const Entity &entity, const DiscreteFunctionSpaceTupleType &tuple)
Definition: tuplespace.hh:142
static BasisFunctionSetType getBasisFunctionSet(const Entity &entity, const DiscreteFunctionSpaceTupleType &tuple, std::index_sequence< i ... >)
Definition: tuplespace.hh:166
GridPartType::GridType GridType
Definition: tuplespace.hh:88
static T accumulate(const DiscreteFunctionSpaceTupleType &tuple, T value, F &&f)
Definition: tuplespace.hh:148
IteratorType::Entity EntityType
Definition: tuplespace.hh:91
std::index_sequence< 0 > LocalBlockIndices
Definition: tuplespace.hh:104
std::tuple< std::shared_ptr< DiscreteFunctionSpaces > ... > DiscreteFunctionSpaceTupleType
Definition: tuplespace.hh:45
GridPartType::IntersectionType IntersectionType
Definition: tuplespace.hh:92
static DiscreteFunctionSpaceTupleType createSpaces(GridPartType &gridPart, InterfaceType commInterface, CommunicationDirection commDirection)
Definition: tuplespace.hh:128
static BlockMapperType * getBlockMapper(const DiscreteFunctionSpaceTupleType &spaceTuple)
Definition: tuplespace.hh:122
static BlockMapperType & subBlockMapper(const DiscreteFunctionSpaceTupleType &tuple)
Definition: tuplespace.hh:68
Type::BlockMapperType BlockMapperType
Definition: tuplespace.hh:56
static NonBlockMapperType subNonBlockMapper(const DiscreteFunctionSpaceTupleType &tuple)
Definition: tuplespace.hh:73
std::tuple_element< i, DiscreteFunctionSpaceTupleType >::type::element_type Type
Definition: tuplespace.hh:53
static const Type & subDiscreteFunctionSpace(const DiscreteFunctionSpaceTupleType &tuple)
Definition: tuplespace.hh:62
NonBlockMapper< BlockMapperType, Type::localBlockSize > NonBlockMapperType
Definition: tuplespace.hh:59
DefaultCommunicationHandler< DiscreteFunction, Operation > Type
type of data handle
Definition: tuplespace.hh:116
Operation OperationType
type of operatation to perform on scatter
Definition: tuplespace.hh:118
TupleDiscreteFunctionSpaceImpl< CombineOp, typename DifferentDiscreteFunctionSpace< DiscreteFunctionSpaces, NewSubFunctionSpace< DiscreteFunctionSpaces > >::Type... > Type
Definition: tuplespace.hh:322
DefaultLocalRestrictProlong(const DiscreteFunctionSpacesType &space)
Definition: tuplespace.hh:339
Default communication handler for discrete functions.
Definition: defaultcommhandler.hh:29
Definition: discretefunctionspace.hh:133
FunctionSpaceTraits Traits
type of traits class
Definition: discretefunctionspace.hh:187
GridPartType::template Codim< Traits::codimension >::EntityType EntityType
type of entity of codimension 0
Definition: discretefunctionspace.hh:223
GridPartType & gridPart() const
Definition: discretefunctionspace.hh:745
convert functions space to space with new dim range
Definition: functionspace.hh:250
Definition: common/localinterpolation.hh:74
Definition: common/localrestrictprolong.hh:16
Definition: nonblockmapper.hh:263