dune-fem  2.4.1-rc
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 <type_traits>
6 
7 #include <dune/common/math.hh>
8 #include <dune/common/typetraits.hh>
9 #include <dune/grid/common/grid.hh>
10 
12 
19 
20 namespace Dune
21 {
22 
23  namespace Fem
24  {
25 
26  // forward declaration
27 
28  template< class ... DiscreteFunctionSpaces >
30 
31 
32  // TupleDiscreteFunctionSpaceTraits
33  // --------------------------------
34 
35  template< class ... DiscreteFunctionSpaces >
37  {
38  static_assert( sizeof ... ( DiscreteFunctionSpaces ) > 0,
39  "You should provide at least one space to the TupleDiscreteFunctionSpace" );
40 
41  // we need to store pointer to the spaces in the SpaceTuple, since space can not be copied.
42  typedef std::tuple< DiscreteFunctionSpaces * ... > DiscreteFunctionSpaceTupleType;
43 
44  protected:
45  // helper struct to create and delete each entry in the tuple
46  template< int i >
47  struct Constructor
48  {
49  template< class Tuple, class ... Args >
50  static void apply ( Tuple &tuple, Args && ... args )
51  {
52  typedef typename std::remove_pointer< typename std::tuple_element< i, Tuple >::type >::type Element;
53  std::get< i >( tuple ) = new Element( std::forward< Args >( args ) ... );
54  }
55  };
56 
57  template< int i >
58  struct Deleter
59  {
60  template< class Tuple >
61  static void apply ( Tuple &tuple ) { delete std::get< i >( tuple ); }
62  };
63 
64  public:
65 
66  // helper struct to access contained sub spaces
67  template< int i >
69  {
70  // type of i-th sub space
71  typedef typename std::remove_pointer< typename std::tuple_element< i, DiscreteFunctionSpaceTupleType >::type >::type Type;
72 
73  // type of i-th sub BlockMapper
74  typedef typename Type::BlockMapperType BlockMapperType;
75 
76  // we will unblock all mappers
78 
79  // access to a const ref of the i-th subspace
80  static const Type &subDiscreteFunctionSpace ( const DiscreteFunctionSpaceTupleType &tuple )
81  {
82  assert( std::get< i >( tuple ) );
83  return *( std::get< i >( tuple ) );
84  }
85 
86  static BlockMapperType &subBlockMapper ( const DiscreteFunctionSpaceTupleType &tuple )
87  {
88  return subDiscreteFunctionSpace( tuple ).blockMapper();
89  }
90 
91  static NonBlockMapperType subNonBlockMapper ( const DiscreteFunctionSpaceTupleType &tuple )
92  {
93  return NonBlockMapperType( subDiscreteFunctionSpace( tuple ).blockMapper() );
94  }
95  };
96 
97  static_assert( Std::are_all_same< std::integral_constant< int, DiscreteFunctionSpaces::Traits::codimension > ... >::value,
98  "TupleDiscreteFunctionSpace for spaces with different codimensions is not supported" );
99  static const int codimension = SubDiscreteFunctionSpace< 0 >::Type::Traits::codimension;
100 
102  "TupleDiscreteFunctionSpace works only for common GridPartTypes" );
103  // type of GridPart
104  typedef typename SubDiscreteFunctionSpace< 0 >::Type::GridPartType GridPartType;
105  typedef typename GridPartType::GridType GridType;
106  typedef typename GridPartType::IndexSetType IndexSetType;
107  typedef typename GridPartType::template Codim< 0 >::IteratorType IteratorType;
108  typedef typename IteratorType::Entity EntityType;
109  typedef typename GridPartType::IntersectionType IntersectionType;
110 
111  // type of this space
112  typedef TupleDiscreteFunctionSpace< DiscreteFunctionSpaces ... > DiscreteFunctionSpaceType;
113 
115  typedef TupleBasisFunctionSet< typename DiscreteFunctionSpaces::BasisFunctionSetType ... > BasisFunctionSetType;
116 
117  // mapper
119 
120  // in the most general case we will unroll all local blockings
121  enum { localBlockSize = 1 };
122 
123  // type functionspace
125 
126  static constexpr int polynomialOrder = Std::max( (int)DiscreteFunctionSpaces::polynomialOrder ... );
127 
128  // review to make it work for all kind of combinations
129  template< class DiscreteFunction,
130  class Operation = DFCommunicationOperation::Copy >
132  {
136  typedef Operation OperationType;
137  };
138 
139 
140  // construct new instance of blockMapper
142  {
143  return getBlockMapper( spaceTuple, Std::index_sequence_for< DiscreteFunctionSpaces ... >() );
144  }
145 
146  // delete instance of BlockMapper
147  static void deleteBlockMapper ( BlockMapperType *blockMapper )
148  {
149  delete blockMapper;
150  }
151 
152  // create Tuple of contained subspaces
153  static DiscreteFunctionSpaceTupleType createSpaces ( GridPartType &gridPart, InterfaceType commInterface,
154  CommunicationDirection commDirection )
155  {
157  ForLoop< Constructor, 0, sizeof ... ( DiscreteFunctionSpaces ) -1 >::apply( tuple, gridPart, commInterface, commDirection );
158  return tuple;
159  }
160 
161  // delete Tuple of contained subspaces
163  {
164  ForLoop< Deleter, 0, sizeof ... ( DiscreteFunctionSpaces ) -1 >::apply( tuple );
165  }
166 
167  template< class Entity >
168  static BasisFunctionSetType getBasisFunctionSet ( const Entity &entity, const DiscreteFunctionSpaceTupleType &tuple )
169  {
170  return getBasisFunctionSet( entity, tuple, Std::index_sequence_for< DiscreteFunctionSpaces ... >() );
171  }
172 
173  static bool continuous ( const DiscreteFunctionSpaceTupleType &tuple )
174  {
175  return continuous( tuple, Std::index_sequence_for< DiscreteFunctionSpaces ... >() );
176  }
177 
178  static bool continuous ( const IntersectionType &intersection, const DiscreteFunctionSpaceTupleType &tuple )
179  {
180  return continuous( tuple, intersection, Std::index_sequence_for< DiscreteFunctionSpaces ... >() );
181  }
182 
183  protected:
184  template< std::size_t ... i >
185  static BlockMapperType *getBlockMapper ( const DiscreteFunctionSpaceTupleType &tuple, Std::index_sequence< i ... > )
186  {
189  }
190 
191  template< class Entity, std::size_t ... i >
192  static BasisFunctionSetType getBasisFunctionSet ( const Entity &entity, const DiscreteFunctionSpaceTupleType &tuple,
193  Std::index_sequence< i ... > )
194  {
195  return BasisFunctionSetType( SubDiscreteFunctionSpace< i >::subDiscreteFunctionSpace( tuple ).basisFunctionSet( entity ) ... );
196  }
197 
198  template< std::size_t ... i >
199  static bool continuous ( const DiscreteFunctionSpaceTupleType &tuple, Std::index_sequence< i ... > )
200  {
202  }
203 
204  template< std::size_t ... i >
205  static bool continuous ( const DiscreteFunctionSpaceTupleType &tuple, const IntersectionType &intersection, Std::index_sequence< i ... > )
206  {
207  return Std::And( SubDiscreteFunctionSpace< i >::subDiscreteFunctionSpace( tuple ).continuous( intersection ) ... );
208  }
209  };
210 
211 
212 
225  template< class ... DiscreteFunctionSpaces >
227  : public GenericCombinedDiscreteFunctionSpace< TupleDiscreteFunctionSpaceTraits< DiscreteFunctionSpaces ... > >
228  {
229  typedef TupleDiscreteFunctionSpace< DiscreteFunctionSpaces ... > ThisType;
230  typedef GenericCombinedDiscreteFunctionSpace< TupleDiscreteFunctionSpaceTraits< DiscreteFunctionSpaces ... > > BaseType;
231  typedef TupleDiscreteFunctionSpaceTraits< DiscreteFunctionSpaces ... > Traits;
232 
233  public:
237 
244  TupleDiscreteFunctionSpace ( GridPartType &gridPart,
245  const InterfaceType commInterface = InteriorBorder_All_Interface,
246  const CommunicationDirection commDirection = ForwardCommunication )
247  : BaseType( gridPart, commInterface, commDirection )
248  {}
249 
250  // prohibit copy constructor and copy assignment
251  TupleDiscreteFunctionSpace ( const ThisType & ) = delete;
252  ThisType &operator= ( const ThisType & ) = delete;
253 
255  std::tuple< const DiscreteFunctionSpaces & ... > spaceTuple () const
256  {
257  return spaceTuple( Std::index_sequence_for< DiscreteFunctionSpaces ... >() );
258  }
259 
260  protected:
261  template< std::size_t ... i >
262  std::tuple< const DiscreteFunctionSpaces & ... > spaceTuple ( Std::index_sequence< i ... > ) const
263  {
264  return std::tuple< const DiscreteFunctionSpaces & ... >( BaseType::template subDiscreteFunctionSpace< i >() ... );
265  }
266  };
267 
268 
269  // DefaultLocalRestrictProlong
270  // ---------------------------
271 
272  template< class ... DiscreteFunctionSpaces >
273  class DefaultLocalRestrictProlong< TupleDiscreteFunctionSpace< DiscreteFunctionSpaces ... > >
274  : public TupleLocalRestrictProlong< DiscreteFunctionSpaces ... >
275  {
276  typedef DefaultLocalRestrictProlong< TupleDiscreteFunctionSpace< DiscreteFunctionSpaces ... > > ThisType;
277  typedef TupleDiscreteFunctionSpace< DiscreteFunctionSpaces ... > DiscreteFunctionSpacesType;
278  typedef TupleLocalRestrictProlong< DiscreteFunctionSpaces ... > BaseType;
279 
280  public:
282  : BaseType( space.spaceTuple() )
283  {}
284 
285  };
286 
287 
288  } // namespace Fem
289 
290 } // namespace Dune
291 
292 #endif // #ifndef DUNE_FEM_SPACE_COMBINEDSPACE_TUPLESPACE_HH
static constexpr int polynomialOrder
Definition: tuplespace.hh:126
TupleMapper< GridPartType, NonBlockMapper< typename DiscreteFunctionSpaces::BlockMapperType, DiscreteFunctionSpaces::localBlockSize >... > BlockMapperType
Definition: tuplespace.hh:118
Definition: tuplespace.hh:29
GridPartType::IntersectionType IntersectionType
Definition: tuplespace.hh:109
std::tuple< DiscreteFunctionSpaces *... > DiscreteFunctionSpaceTupleType
Definition: tuplespace.hh:39
static void apply(Tuple &tuple)
Definition: tuplespace.hh:61
Definition: utility.hh:135
static BasisFunctionSetType getBasisFunctionSet(const Entity &entity, const DiscreteFunctionSpaceTupleType &tuple)
Definition: tuplespace.hh:168
A vector valued function space.
Definition: functionspace.hh:16
GridPartType::IndexSetType IndexSetType
Definition: tuplespace.hh:106
Traits::GridPartType GridPartType
Definition: tuplespace.hh:236
Default communication handler for discrete functions.
Definition: defaultcommhandler.hh:23
static constexpr T max(T a)
Definition: utility.hh:65
BasisFunctionSetType::FunctionSpaceType FunctionSpaceType
Definition: tuplespace.hh:124
static void deleteSpaces(DiscreteFunctionSpaceTupleType &tuple)
Definition: tuplespace.hh:162
static NonBlockMapperType subNonBlockMapper(const DiscreteFunctionSpaceTupleType &tuple)
Definition: tuplespace.hh:91
static BlockMapperType * getBlockMapper(const DiscreteFunctionSpaceTupleType &spaceTuple)
Definition: tuplespace.hh:141
static const int codimension
Definition: tuplespace.hh:99
static DiscreteFunctionSpaceTupleType createSpaces(GridPartType &gridPart, InterfaceType commInterface, CommunicationDirection commDirection)
Definition: tuplespace.hh:153
static BlockMapperType * getBlockMapper(const DiscreteFunctionSpaceTupleType &tuple, Std::index_sequence< i... >)
Definition: tuplespace.hh:185
mapper allocating one DoF per subentity of a given codimension
Definition: tuplemapper.hh:28
Operation OperationType
type of operatation to perform on scatter
Definition: tuplespace.hh:136
static BlockMapperType & subBlockMapper(const DiscreteFunctionSpaceTupleType &tuple)
Definition: tuplespace.hh:86
DefaultLocalRestrictProlong(const DiscreteFunctionSpacesType &space)
Definition: tuplespace.hh:281
Definition: nonblockmapper.hh:19
GridPartType::GridType GridType
Definition: tuplespace.hh:105
static bool continuous(const DiscreteFunctionSpaceTupleType &tuple)
Definition: tuplespace.hh:173
static void apply(Tuple &tuple, Args &&...args)
Definition: tuplespace.hh:50
std::tuple< const DiscreteFunctionSpaces &... > spaceTuple(Std::index_sequence< i... >) const
Definition: tuplespace.hh:262
Type::BlockMapperType BlockMapperType
Definition: tuplespace.hh:74
Definition: tuplelocalrestrictprolong.hh:32
Definition: coordinate.hh:4
std::remove_pointer< typename std::tuple_element< i, DiscreteFunctionSpaceTupleType >::type >::type Type
Definition: tuplespace.hh:71
static bool continuous(const IntersectionType &intersection, const DiscreteFunctionSpaceTupleType &tuple)
Definition: tuplespace.hh:178
just copy data
Definition: commoperations.hh:263
Definition: basisfunctionset/tuple.hh:31
IteratorType::Entity EntityType
Definition: tuplespace.hh:108
TupleBasisFunctionSet< typename DiscreteFunctionSpaces::BasisFunctionSetType... > BasisFunctionSetType
implementation of basefunction set
Definition: tuplespace.hh:115
static bool continuous(const DiscreteFunctionSpaceTupleType &tuple, const IntersectionType &intersection, Std::index_sequence< i... >)
Definition: tuplespace.hh:205
SubDiscreteFunctionSpace< 0 >::Type::GridPartType GridPartType
Definition: tuplespace.hh:102
DefaultCommunicationHandler< DiscreteFunction, Operation > Type
type of data handle
Definition: tuplespace.hh:134
static void deleteBlockMapper(BlockMapperType *blockMapper)
Definition: tuplespace.hh:147
static const Type & subDiscreteFunctionSpace(const DiscreteFunctionSpaceTupleType &tuple)
Definition: tuplespace.hh:80
Definition: common/localrestrictprolong.hh:16
GridPartType::template Codim< 0 >::IteratorType IteratorType
Definition: tuplespace.hh:107
static bool continuous(const DiscreteFunctionSpaceTupleType &tuple, Std::index_sequence< i... >)
Definition: tuplespace.hh:199
TupleDiscreteFunctionSpace< DiscreteFunctionSpaces... > DiscreteFunctionSpaceType
Definition: tuplespace.hh:112
std::tuple< const DiscreteFunctionSpaces &... > spaceTuple() const
return tuple of const References to the contained sub spaces
Definition: tuplespace.hh:255
static constexpr bool And(bool a)
Definition: utility.hh:113
TupleDiscreteFunctionSpace(GridPartType &gridPart, const InterfaceType commInterface=InteriorBorder_All_Interface, const CommunicationDirection commDirection=ForwardCommunication)
constructor
Definition: tuplespace.hh:244
NonBlockMapper< BlockMapperType, Type::localBlockSize > NonBlockMapperType
Definition: tuplespace.hh:77
Definition: combinedspace/generic.hh:24
static BasisFunctionSetType getBasisFunctionSet(const Entity &entity, const DiscreteFunctionSpaceTupleType &tuple, Std::index_sequence< i... >)
Definition: tuplespace.hh:192