dune-fem 2.12-git
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
10#include <dune/common/math.hh>
11
12#include <dune/grid/common/grid.hh>
13
25
26namespace Dune
27{
28
29 namespace Fem
30 {
31
32 // forward declaration
33 template< class CombineOp, class ... DiscreteFunctionSpaces >
34 class TupleDiscreteFunctionSpaceImpl;
35
36 // TupleDiscreteFunctionSpaceTraits
37 // --------------------------------
38
39 template< class CombineOp, class ... DiscreteFunctionSpaces >
41 {
42 static_assert( sizeof ... ( DiscreteFunctionSpaces ) > 0,
43 "You should provide at least one space to the TupleDiscreteFunctionSpace" );
44
45 // we need to store pointer to the spaces in the SpaceTuple, since space can not be copied.
47
48 public:
49 // helper struct to access contained sub spaces
50 template< int i >
52 {
53 // type of i-th sub space
54 typedef typename std::tuple_element< i, DiscreteFunctionSpaceTupleType >::type::element_type Type;
55
56 // type of i-th sub BlockMapper
57 typedef typename Type::BlockMapperType BlockMapperType;
58
59 // we will unblock all mappers
61
62 // access to a const ref of the i-th subspace
64 {
65 assert( std::get< i >( tuple ) );
66 return *( std::get< i >( tuple ) );
67 }
68
70 {
71 return subDiscreteFunctionSpace( tuple ).blockMapper();
72 }
73
75 {
76 return NonBlockMapperType( subDiscreteFunctionSpace( tuple ).blockMapper() );
77 }
78 };
79
80 public:
82 "TupleDiscreteFunctionSpace works only for GridPart's with the same entity type" );
83
85 "TupleDiscreteFunctionSpace for spaces with different codimensions is not supported" );
87
89 typedef typename GridPartType::GridType GridType;
90 typedef typename GridPartType::IndexSetType IndexSetType;
91 typedef typename GridPartType::template Codim< 0 >::IteratorType IteratorType;
92 typedef typename IteratorType::Entity EntityType;
93 typedef typename GridPartType::IntersectionType IntersectionType;
94
95 // type of this space
96 typedef TupleDiscreteFunctionSpaceImpl< CombineOp, DiscreteFunctionSpaces ... > DiscreteFunctionSpaceType;
97
99 typedef TupleBasisFunctionSet< CombineOp, typename DiscreteFunctionSpaces::BasisFunctionSetType ... > BasisFunctionSetType;
100
101 // mapper
103
104 // in the most general case we will unroll all local blockings
106
107 // type functionspace
109
110 typedef TupleSpaceInterpolation< CombineOp, DiscreteFunctionSpaces ... > InterpolationImplType;
111
112 // review to make it work for all kind of combinations
113 template< class DiscreteFunction, class Operation = DFCommunicationOperation::Copy >
121
122 // construct new instance of blockMapper
127
128 // create Tuple of contained subspaces
130 CommunicationDirection commDirection )
131 {
133 Hybrid::forEach( std::make_index_sequence< sizeof ... ( DiscreteFunctionSpaces ) >{},
134 [ & ]( auto i )
135 {
136 typedef typename SubDiscreteFunctionSpace< i >::Type Element;
137 std::get< i >( tuple ) = std::make_shared< Element >( gridPart, commInterface, commDirection );
138 } );
139 return tuple;
140 }
141
142 template< class Entity >
147
148 template< class T, class F >
149 static T accumulate ( const DiscreteFunctionSpaceTupleType &tuple, T value, F &&f )
150 {
152 const std::size_t i = std::decay_t< decltype( idx ) >::value;
154 } );
155 return value;
156 }
157
158 protected:
159 template< std::size_t ... i >
165
166 template< class Entity, std::size_t ... i >
172 };
173
174
175
190 template< class CombineOp, class ... DiscreteFunctionSpaces >
192 : public GenericCombinedDiscreteFunctionSpace< TupleDiscreteFunctionSpaceTraits< CombineOp, DiscreteFunctionSpaces ... > >
193 {
194 typedef TupleDiscreteFunctionSpaceImpl< CombineOp, DiscreteFunctionSpaces ... > ThisType;
195 typedef GenericCombinedDiscreteFunctionSpace< TupleDiscreteFunctionSpaceTraits< CombineOp, DiscreteFunctionSpaces ... > > BaseType;
196
197 public:
198 typedef decltype ( std::index_sequence_for< DiscreteFunctionSpaces ... >() ) Sequence;
199 typedef typename BaseType::Traits Traits;
202
203 typedef typename Traits::InterpolationImplType InterpolationImplType;
204
206 typedef typename Traits::DiscreteFunctionSpaceTupleType DiscreteFunctionSpaceTupleType;
207
215 template <class GP,
216 typename = std::enable_if_t<(... &&
219 const InterfaceType commInterface = InteriorBorder_All_Interface,
220 const CommunicationDirection commDirection = ForwardCommunication )
221 : BaseType( gridPart, commInterface, commDirection )
222 {}
223
231 TupleDiscreteFunctionSpaceImpl ( DiscreteFunctionSpaces &&... spaces )
232 : BaseType( std::make_tuple( std::make_shared( std::move( spaces ) )... ) )
233 {}
234
242 TupleDiscreteFunctionSpaceImpl ( const DiscreteFunctionSpaces &... spaces )
243 : BaseType( std::make_tuple( referenceToSharedPtr( spaces )... ) )
244 {}
245
254 : BaseType( std::make_tuple( std::move( spaces )... ) )
255 {}
256
267
269 ThisType &operator= ( const ThisType & ) = delete;
270
272 std::tuple< const DiscreteFunctionSpaces & ... > spaceTuple () const
273 {
275 }
276
278 {
279 return InterpolationType( *this );
280 }
281
282 [[deprecated]]
284 {
285 return localInterpolation( entity );
286 }
287
292
293 typedef int KeyType;
294 KeyType getMark( const EntityType &entity ) const
295 {
296 DUNE_THROW(NotImplemented,"TupleDiscreteFunctionSpaceImpl::getMark: This method has to be called on the subspaces!");
297 return KeyType(-1);
298 }
299
300 void mark( const KeyType& key, const EntityType &entity ) const
301 {
302 DUNE_THROW(NotImplemented,"TupleDiscreteFunctionSpaceImpl::mark: This method has to be called on the subspaces!");
303 }
304
305 protected:
306 template< std::size_t ... i >
307 std::tuple< const DiscreteFunctionSpaces & ... > spaceTuple ( std::index_sequence< i ... > ) const
308 {
309 return std::tuple< const DiscreteFunctionSpaces & ... >( BaseType::template subDiscreteFunctionSpace< i >() ... );
310 }
311
312 template< std::size_t ... i >
317 };
318
319 namespace Capabilities
320 {
321 namespace detail
322 {
323 template< template <class> class capability, class ... DiscreteFunctionSpaces >
324 struct LogicAnd
325 {
326 typedef std::tuple< DiscreteFunctionSpaces ... > SpaceTuple;
327 static const int length = std::tuple_size< SpaceTuple >::value;
328
329 template < int i, bool prev >
330 static constexpr bool acc()
331 {
332 if constexpr( i >= length )
333 {
334 return prev;
335 }
336 else
337 {
338 return acc< i+1, prev && capability< typename std::tuple_element< i, SpaceTuple >::type >::v >();
339 }
340 }
341
342 static const bool v = acc<0, true>();
343 };
344
345 template< template <class> class capability, class ... DiscreteFunctionSpaces >
346 struct PolOrder
347 {
348 typedef std::tuple< DiscreteFunctionSpaces ... > SpaceTuple;
349 static const int length = std::tuple_size< SpaceTuple >::value;
350
351 template < int i, int p >
352 static constexpr int acc()
353 {
354 if constexpr( i >= length )
355 {
356 return p;
357 }
358 else
359 {
360 return acc< i+1, (p == capability< typename std::tuple_element< i, SpaceTuple >::type >::order) ? p : -1 >();
361 }
362 }
363
364 static const int order = acc<0, capability< typename std::tuple_element< 0, SpaceTuple >::type >::order>();
365 static const bool v = (order >= 0) ? true : false ;
366 };
367 } // end namespace detail
368
369
370 template< class CombineOp, class ... DiscreteFunctionSpaces >
371 struct hasFixedPolynomialOrder< TupleDiscreteFunctionSpaceImpl< CombineOp, DiscreteFunctionSpaces ... > >
372 {
373 static const bool v = detail::LogicAnd< hasFixedPolynomialOrder, DiscreteFunctionSpaces ... >::v;
374 };
375
376 template< class CombineOp, class ... DiscreteFunctionSpaces >
377 struct hasStaticPolynomialOrder< TupleDiscreteFunctionSpaceImpl< CombineOp, DiscreteFunctionSpaces ... > >
378 {
379 typedef detail::PolOrder< hasStaticPolynomialOrder, DiscreteFunctionSpaces ... > PolOrder;
380 static const bool v = PolOrder :: v;
381 static const int order = PolOrder :: order;
382 };
383
384 template< class CombineOp, class ... DiscreteFunctionSpaces >
385 struct isContinuous< TupleDiscreteFunctionSpaceImpl< CombineOp, DiscreteFunctionSpaces ... > >
386 {
387 static const bool v = detail::LogicAnd< isContinuous, DiscreteFunctionSpaces ... >::v;
388 };
389
390 template< class CombineOp, class ... DiscreteFunctionSpaces >
391 struct isLocalized< TupleDiscreteFunctionSpaceImpl< CombineOp, DiscreteFunctionSpaces ... > >
392 {
393 static const bool v = detail::LogicAnd< isLocalized, DiscreteFunctionSpaces ... >::v;
394 };
395
396 template< class CombineOp, class ... DiscreteFunctionSpaces >
397 struct isAdaptive< TupleDiscreteFunctionSpaceImpl< CombineOp, DiscreteFunctionSpaces ... > >
398 {
399 static const bool v = detail::LogicAnd< isAdaptive, DiscreteFunctionSpaces ... >::v;
400 };
401
402 template< class CombineOp, class ... DiscreteFunctionSpaces >
403 struct isPAdaptiveSpace< TupleDiscreteFunctionSpaceImpl< CombineOp, DiscreteFunctionSpaces ... > >
404 {
405 static const bool v = detail::LogicAnd< isPAdaptiveSpace, DiscreteFunctionSpaces ... >::v;
406 };
407
408 template< class CombineOp, class ... DiscreteFunctionSpaces >
409 struct threadSafe< TupleDiscreteFunctionSpaceImpl< CombineOp, DiscreteFunctionSpaces ... > >
410 {
411 static const bool v = detail::LogicAnd< threadSafe, DiscreteFunctionSpaces ... >::v;
412 };
413 }
414
415
416 // DifferentDiscreteFunctionSpace
417 // ------------------------------
418
420 template< class CombineOp, class ... DiscreteFunctionSpaces, class NewFunctionSpace >
421 struct DifferentDiscreteFunctionSpace< TupleDiscreteFunctionSpaceImpl< CombineOp, DiscreteFunctionSpaces... >, NewFunctionSpace >
422 {
423 static_assert( (NewFunctionSpace::dimRange % TupleDiscreteFunctionSpaceImpl< CombineOp, DiscreteFunctionSpaces... >::dimRange == 0),
424 "DifferentDiscreteFunctionSpace can only be applied to TupleFunctionSpace, if new dimRange is a multiple of the original one." );
425
426 private:
427 static const int factor = (NewFunctionSpace::dimRange / TupleDiscreteFunctionSpaceImpl< CombineOp, DiscreteFunctionSpaces... >::dimRange);
428
429 template< class DiscreteFunctionSpace >
431
432 public:
434 };
435
436
437
438 // DefaultLocalRestrictProlong
439 // ---------------------------
440
441 template< class CombineOp, class ... DiscreteFunctionSpaces >
442 class DefaultLocalRestrictProlong< TupleDiscreteFunctionSpaceImpl< CombineOp, DiscreteFunctionSpaces ... > >
443 : public TupleLocalRestrictProlong< DiscreteFunctionSpaces ... >
444 {
445 typedef DefaultLocalRestrictProlong< TupleDiscreteFunctionSpaceImpl< CombineOp, DiscreteFunctionSpaces ... > > ThisType;
446 typedef TupleDiscreteFunctionSpaceImpl< CombineOp, DiscreteFunctionSpaces ... > DiscreteFunctionSpacesType;
447 typedef TupleLocalRestrictProlong< DiscreteFunctionSpaces ... > BaseType;
448
449 public:
451 : BaseType( space.spaceTuple() )
452 {}
453
454 };
455
456 // Creating a space V = V_1 x V_2 x ...
457 template < class ... DiscreteFunctionSpaces >
459
460 // Creating a space V = V_1 + V_2 + ...
461 template < class ... DiscreteFunctionSpaces >
463
464 template < class ... DiscreteFunctionSpaces >
466
467 } // namespace Fem
468
469} // namespace Dune
470
471#endif // #ifndef DUNE_FEM_SPACE_COMBINEDSPACE_TUPLESPACE_HH
constexpr void forEach(Range &&range, F &&f)
#define DUNE_THROW(E,...)
CommunicationDirection
InterfaceType
ForwardCommunication
InteriorBorder_All_Interface
STL namespace.
static std::shared_ptr< T > referenceToSharedPtr(T &t)
Definition memory.hh:19
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:632
Definition tuplespace.hh:193
void mark(const KeyType &key, const EntityType &entity) const
Definition tuplespace.hh:300
int KeyType
Definition tuplespace.hh:293
std::tuple< const DiscreteFunctionSpaces &... > spaceTuple() const
return tuple of const References to the contained sub spaces
Definition tuplespace.hh:272
TupleDiscreteFunctionSpaceImpl(std::shared_ptr< const DiscreteFunctionSpaces >... spaces)
constructor
Definition tuplespace.hh:253
BaseType::EntityType EntityType
Definition tuplespace.hh:201
InterpolationImplType interpolation(const EntityType &entity) const
Definition tuplespace.hh:283
decltype(std::index_sequence_for< DiscreteFunctionSpaces ... >()) Sequence
Definition tuplespace.hh:198
InterpolationType interpolation() const
Definition tuplespace.hh:277
Traits::InterpolationImplType InterpolationImplType
Definition tuplespace.hh:203
LocalInterpolationWrapper< ThisType > InterpolationType
Definition tuplespace.hh:205
TupleDiscreteFunctionSpaceImpl(DiscreteFunctionSpaces &&... spaces)
constructor
Definition tuplespace.hh:231
TupleDiscreteFunctionSpaceImpl(const ThisType &)=delete
ThisType & operator=(const ThisType &)=delete
BaseType::Traits Traits
Definition tuplespace.hh:199
InterpolationImplType localInterpolation(const EntityType &entity) const
Definition tuplespace.hh:288
Traits::DiscreteFunctionSpaceTupleType DiscreteFunctionSpaceTupleType
Definition tuplespace.hh:206
TupleDiscreteFunctionSpaceImpl(const DiscreteFunctionSpaces &... spaces)
constructor
Definition tuplespace.hh:242
KeyType getMark(const EntityType &entity) const
Definition tuplespace.hh:294
BaseType::GridPartType GridPartType
Definition tuplespace.hh:200
std::tuple< const DiscreteFunctionSpaces &... > spaceTuple(std::index_sequence< i ... >) const
Definition tuplespace.hh:307
InterpolationImplType localInterpolation(const EntityType &entity, std::index_sequence< i ... >) const
Definition tuplespace.hh:313
TupleDiscreteFunctionSpaceImpl(DiscreteFunctionSpaceTupleType spaceTuple)
constructor
Definition tuplespace.hh:264
TupleSpaceInterpolation< CombineOp, DiscreteFunctionSpaces ... > InterpolationImplType
Definition tuplespace.hh:110
TupleDiscreteFunctionSpaceImpl< CombineOp, DiscreteFunctionSpaces ... > DiscreteFunctionSpaceType
Definition tuplespace.hh:96
static const int codimension
Definition tuplespace.hh:86
TupleBasisFunctionSet< CombineOp, typename DiscreteFunctionSpaces::BasisFunctionSetType ... > BasisFunctionSetType
implementation of basefunction set
Definition tuplespace.hh:99
SubDiscreteFunctionSpace< 0 >::Type::GridPartType GridPartType
Definition tuplespace.hh:88
GridPartType::template Codim< 0 >::IteratorType IteratorType
Definition tuplespace.hh:91
BasisFunctionSetType::FunctionSpaceType FunctionSpaceType
Definition tuplespace.hh:108
TupleMapper< GridPartType, NonBlockMapper< typename DiscreteFunctionSpaces::BlockMapperType, DiscreteFunctionSpaces::localBlockSize > ... > BlockMapperType
Definition tuplespace.hh:102
static BlockMapperType * getBlockMapper(const DiscreteFunctionSpaceTupleType &tuple, std::index_sequence< i ... >)
Definition tuplespace.hh:160
GridPartType::IndexSetType IndexSetType
Definition tuplespace.hh:90
static BasisFunctionSetType getBasisFunctionSet(const Entity &entity, const DiscreteFunctionSpaceTupleType &tuple)
Definition tuplespace.hh:143
static BasisFunctionSetType getBasisFunctionSet(const Entity &entity, const DiscreteFunctionSpaceTupleType &tuple, std::index_sequence< i ... >)
Definition tuplespace.hh:167
GridPartType::GridType GridType
Definition tuplespace.hh:89
static T accumulate(const DiscreteFunctionSpaceTupleType &tuple, T value, F &&f)
Definition tuplespace.hh:149
IteratorType::Entity EntityType
Definition tuplespace.hh:92
std::index_sequence< 0 > LocalBlockIndices
Definition tuplespace.hh:105
std::tuple< std::shared_ptr< DiscreteFunctionSpaces > ... > DiscreteFunctionSpaceTupleType
Definition tuplespace.hh:46
GridPartType::IntersectionType IntersectionType
Definition tuplespace.hh:93
static DiscreteFunctionSpaceTupleType createSpaces(GridPartType &gridPart, InterfaceType commInterface, CommunicationDirection commDirection)
Definition tuplespace.hh:129
static BlockMapperType * getBlockMapper(const DiscreteFunctionSpaceTupleType &spaceTuple)
Definition tuplespace.hh:123
static BlockMapperType & subBlockMapper(const DiscreteFunctionSpaceTupleType &tuple)
Definition tuplespace.hh:69
Type::BlockMapperType BlockMapperType
Definition tuplespace.hh:57
static NonBlockMapperType subNonBlockMapper(const DiscreteFunctionSpaceTupleType &tuple)
Definition tuplespace.hh:74
std::tuple_element< i, DiscreteFunctionSpaceTupleType >::type::element_type Type
Definition tuplespace.hh:54
static const Type & subDiscreteFunctionSpace(const DiscreteFunctionSpaceTupleType &tuple)
Definition tuplespace.hh:63
NonBlockMapper< BlockMapperType, Type::localBlockSize > NonBlockMapperType
Definition tuplespace.hh:60
DefaultCommunicationHandler< DiscreteFunction, Operation > Type
type of data handle
Definition tuplespace.hh:117
Operation OperationType
type of operatation to perform on scatter
Definition tuplespace.hh:119
detail::PolOrder< hasStaticPolynomialOrder, DiscreteFunctionSpaces ... > PolOrder
Definition tuplespace.hh:379
TupleDiscreteFunctionSpaceImpl< CombineOp, typename DifferentDiscreteFunctionSpace< DiscreteFunctionSpaces, NewSubFunctionSpace< DiscreteFunctionSpaces > >::Type... > Type
Definition tuplespace.hh:433
DefaultLocalRestrictProlong(const DiscreteFunctionSpacesType &space)
Definition tuplespace.hh:450
specialize with true if polynomial order does not depend on the grid (part) entity
Definition space/common/capabilities.hh:24
static const bool v
Definition space/common/capabilities.hh:25
specialize with true if polynomial order fixed and compile time static
Definition space/common/capabilities.hh:37
static const bool v
Definition space/common/capabilities.hh:38
static const int order
Definition space/common/capabilities.hh:39
specialize with true if space is always continuous
Definition space/common/capabilities.hh:50
static const bool v
Definition space/common/capabilities.hh:51
specialize with true if the space is localized, * i.e., the basis function set is based on a shape fu...
Definition space/common/capabilities.hh:68
static const bool v
Definition space/common/capabilities.hh:69
specialize with true if space can be used with AdaptiveDiscreteFunction
Definition space/common/capabilities.hh:81
static const bool v
Definition space/common/capabilities.hh:82
specialize with true if space can be used with p-adaptation
Definition space/common/capabilities.hh:93
static const bool v
Definition space/common/capabilities.hh:94
specialize with true if the space implementation is thread safe
Definition space/common/capabilities.hh:105
static const bool v
Definition space/common/capabilities.hh:106
Default communication handler for discrete functions.
Definition defaultcommhandler.hh:38
Definition discretefunctionspace.hh:134
FunctionSpaceTraits Traits
type of traits class
Definition discretefunctionspace.hh:188
GridPartType::template Codim< Traits::codimension >::EntityType EntityType
type of entity of codimension 0
Definition discretefunctionspace.hh:224
GridPartType & gridPart() const
Definition discretefunctionspace.hh:766
convert functions space to space with new dim range
Definition functionspace.hh:250
Definition common/localinterpolation.hh:75
Definition common/localrestrictprolong.hh:16
Definition nonblockmapper.hh:284
T forward(T... args)