dune-fem  2.4.1-rc
shapefunctionset/tuple.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_SPACE_SHAPEFUNCTIONSET_TUPLE_HH
2 #define DUNE_FEM_SPACE_SHAPEFUNCTIONSET_TUPLE_HH
3 
4 #include <dune/geometry/type.hh>
5 
6 #include <dune/common/forloop.hh>
7 #include <dune/common/tuples.hh>
8 #include <dune/common/tupleutility.hh>
10 
12 
13 
14 namespace Dune
15 {
16 
17  namespace Fem
18  {
19 
20  // TupleShapeFunctionSet
21  // ---------------------
22 
23  template< class ... ShapeFunctionSets >
25  {
27 
28  template< int ... I >
29  struct RangeOffsets
30  {
31  typedef tuple< std::integral_constant< int, I > ... > RangeSizeTuple;
32 
33  template< int j >
34  static constexpr int size () { return tuple_element< j, RangeSizeTuple >::type::value; }
35 
36  template< int ... j >
37  static constexpr Std::integer_sequence< int, size< j >() ... > sizes ( Std::integer_sequence< int, j ... > )
38  {
39  return Std::integer_sequence< int, size< j >() ... >();
40  }
41 
42  template< int i >
43  static constexpr int offset ()
44  {
45  return sum( sizes( Std::make_integer_sequence< int, i >() ) );
46  }
47 
48  private:
49  template< int ... j >
50  static constexpr int sum ( Std::integer_sequence< int, j ... > )
51  {
52  return Std::sum( j ... );
53  }
54 
55  static constexpr int sum ( Std::integer_sequence< int > ) { return 0; }
56  };
57 
58  typedef std::array< std::size_t, sizeof ... ( ShapeFunctionSets ) +1 > Offset;
59 
60  template< int I > struct Offsets;
61  template< class Functor, class Value, int I > struct FunctorWrapper;
62 
63  template< int I > struct EvaluateEach;
64  template< int I > struct JacobianEach;
65  template< int I > struct HessianEach;
66 
67  static const std::size_t dimRange = Std::sum( static_cast< int >( ShapeFunctionSets::FunctionSpaceType::dimRange ) ... );
68 
69  public:
72 
73  typedef typename FunctionSpaceType::DomainType DomainType;
74  typedef typename FunctionSpaceType::RangeType RangeType;
75  typedef typename FunctionSpaceType::JacobianRangeType JacobianRangeType;
76  typedef typename FunctionSpaceType::HessianRangeType HessianRangeType;
77 
78  static const int numShapeFunctions = Std::sum( static_cast< int >( ShapeFunctionSets::numShapeFunctions ) ... );
79 
80  TupleShapeFunctionSet ( GeometryType type )
81  : shapeFunctionSetTuple_( makeGeometryTypeTuple( type, Std::index_sequence_for< ShapeFunctionSets ... >() ) )
82  {
83  offset_[ 0 ] = 0;
84  ForLoop< Offsets, 0, sizeof ... ( ShapeFunctionSets ) -1 >::apply( shapeFunctionSetTuple_, offset_ );
85  }
86 
87  template< class ... Args >
88  TupleShapeFunctionSet ( Args && ... args )
89  : shapeFunctionSetTuple_( std::forward< Args >( args ) ... )
90  {
91  offset_[ 0 ] = 0;
92  ForLoop< Offsets, 0, sizeof ... ( ShapeFunctionSets ) -1 >::apply( shapeFunctionSetTuple_, offset_ );
93  }
94 
95  explicit TupleShapeFunctionSet ( const ShapeFunctionSetTupleType &shapeFunctionSetTuple = ShapeFunctionSetTupleType() )
96  : shapeFunctionSetTuple_( shapeFunctionSetTuple )
97  {
98  offset_[ 0 ] = 0;
99  ForLoop< Offsets, 0, sizeof ... ( ShapeFunctionSets ) -1 >::apply( shapeFunctionSetTuple_, offset_ );
100  }
101 
102  int order () const { return order( Std::index_sequence_for< ShapeFunctionSets ... >() ); }
103 
104  std::size_t size () const { return size( Std::index_sequence_for< ShapeFunctionSets ... >() ); }
105 
106  template< class Point, class Functor >
107  void evaluateEach ( const Point &x, Functor functor ) const
108  {
109  ForLoop< EvaluateEach, 0, sizeof ... ( ShapeFunctionSets ) -1 >::apply( shapeFunctionSetTuple_, offset_, x, functor );
110  }
111 
112  template< class Point, class Functor >
113  void jacobianEach ( const Point &x, Functor functor ) const
114  {
115  ForLoop< JacobianEach, 0, sizeof ... ( ShapeFunctionSets ) -1 >::apply( shapeFunctionSetTuple_, offset_, x, functor );
116  }
117 
118  template< class Point, class Functor >
119  void hessianEach ( const Point &x, Functor functor ) const
120  {
121  ForLoop< HessianEach, 0, sizeof ... ( ShapeFunctionSets ) -1 >::apply( shapeFunctionSetTuple_, offset_, x, functor );
122  }
123 
124  protected:
125  template< std::size_t ... I >
126  int order ( Std::index_sequence< I ... > ) const
127  {
128  return Std::max( std::get< I >( shapeFunctionSetTuple_ ).order() ... );
129  }
130 
131  template< std::size_t ... I >
132  std::size_t size ( Std::index_sequence< I ... > ) const
133  {
134  return Std::sum( std::get< I >( shapeFunctionSetTuple_ ).size() ... );
135  }
136 
137  template< int >
138  static GeometryType makeGeometryType ( GeometryType type )
139  {
140  return type;
141  }
142 
143  template< std::size_t ... I >
144  static tuple< decltype( makeGeometryType< I >( std::declval< GeometryType >() ) ) ... >
145  makeGeometryTypeTuple ( GeometryType type, Std::index_sequence< I ... > )
146  {
147  return std::make_tuple( makeGeometryType< I >( type ) ... );
148  }
149 
151  Offset offset_;
152  };
153 
154 
155 
156  // TupleShapeFunctionSet::Offsets
157  // ------------------------------
158 
159  template< class ... ShapeFunctionSets >
160  template< int I >
161  struct TupleShapeFunctionSet< ShapeFunctionSets ... >::Offsets
162  {
163  template< class Tuple >
164  static void apply ( const Tuple &tuple, Offset &offset )
165  {
166  offset[ I + 1 ] = offset[ I ] + std::get< I >( tuple ).size();
167  }
168  };
169 
170 
171 
172  // TupleShapeFunctionSet::FunctorWrapper
173  // -------------------------------------
174 
175  template< class ... ShapeFunctionSets >
176  template< class Functor, class Value, int I >
177  struct TupleShapeFunctionSet< ShapeFunctionSets ... >::FunctorWrapper
178  {
179  static const int rangeOffset = RangeOffsets< ShapeFunctionSets::FunctionSpaceType::dimRange ... >::template offset< I >();
180 
181  explicit FunctorWrapper ( const Functor &functor, const Offset &offset )
182  : functor_( functor ), offset_( offset ) {}
183 
184  template< class Scalar >
185  void operator() ( const std::size_t i, const Scalar &subValue )
186  {
187  Value value( typename FieldTraits< Value >::field_type( 0.0 ) );
188  std::copy( subValue.begin(), subValue.end(), value.begin() + rangeOffset );
189  functor_( offset_[ I ] + i, value );
190  }
191 
192  template< class Scalar, class Vectorial >
193  void operator() ( const std::size_t i, const MakeVectorialExpression< Scalar, Vectorial > &subValue )
194  {
195  MakeVectorialExpression< Scalar, Value > value( subValue.component() + rangeOffset, subValue.scalar() );
196  functor_( offset_[ I ] + i, value );
197  }
198 
199  private:
200  Functor functor_;
201  const Offset &offset_;
202  };
203 
204 
205 
206  // TupleShapeFunctionSet::EvaluateEach
207  // -----------------------------------
208 
209  template< class ... ShapeFunctionSets >
210  template< int I >
211  struct TupleShapeFunctionSet< ShapeFunctionSets ... >::EvaluateEach
212  {
213  template< class Tuple, class Point, class Functor >
214  static void apply ( const Tuple &tuple, const Offset &offset, const Point &x, Functor functor )
215  {
216  FunctorWrapper< Functor, RangeType, I > functorWrapper( functor, offset );
217  std::get< I >( tuple ).evaluateEach( x, functorWrapper );
218  }
219  };
220 
221 
222 
223  // TupleShapeFunctionSet::JacobianEach
224  // -----------------------------------
225 
226  template< class ... ShapeFunctionSets >
227  template< int I >
228  struct TupleShapeFunctionSet< ShapeFunctionSets ... >::JacobianEach
229  {
230  template< class Tuple, class Point, class Functor >
231  static void apply ( const Tuple &tuple, const Offset &offset, const Point &x, Functor functor )
232  {
233  FunctorWrapper< Functor, JacobianRangeType, I > functorWrapper( functor, offset );
234  std::get< I >( tuple ).jacobianEach( x, functorWrapper );
235  }
236  };
237 
238 
239 
240  // TupleShapeFunctionSet::HessianEach
241  // ----------------------------------
242 
243  template< class ... ShapeFunctionSets >
244  template< int I >
245  struct TupleShapeFunctionSet< ShapeFunctionSets ... >::HessianEach
246  {
247  template< class Tuple, class Point, class Functor >
248  static void apply ( const Tuple &tuple, const Offset &offset, const Point &x, Functor functor )
249  {
250  FunctorWrapper< Functor, HessianRangeType, I > functorWrapper( functor, offset );
251  std::get< I >( tuple ).hessianEach( x, functorWrapper );
252  }
253  };
254 
255 
256  } // namespace Fem
257 
258 } // namespace Dune
259 
260 #endif // #ifndef DUNE_FEM_SPACE_SHAPEFUNCTIONSET_TUPLE_HH
void jacobianEach(const Point &x, Functor functor) const
Definition: shapefunctionset/tuple.hh:113
FunctionSpaceType::HessianRangeType HessianRangeType
Definition: shapefunctionset/tuple.hh:76
const ComponentType & component() const
Definition: shapefunctionset/vectorial.hh:121
Definition: shapefunctionset/vectorial.hh:137
static constexpr T max(T a)
Definition: utility.hh:65
interface class representing a family of shape function sets
Definition: shapefunctionsets.hh:32
static constexpr T sum(T a)
Definition: utility.hh:33
const ScalarType & scalar() const
Definition: shapefunctionset/vectorial.hh:123
tuple< ShapeFunctionSets... > ShapeFunctionSetTupleType
Definition: shapefunctionset/tuple.hh:70
static const int numShapeFunctions
Definition: shapefunctionset/tuple.hh:78
ShapeFunctionSetTupleType shapeFunctionSetTuple_
Definition: shapefunctionset/tuple.hh:150
Definition: coordinate.hh:4
FunctionSpaceType::DomainType DomainType
Definition: shapefunctionset/tuple.hh:73
std::size_t size(Std::index_sequence< I... >) const
Definition: shapefunctionset/tuple.hh:132
Offset offset_
Definition: shapefunctionset/tuple.hh:151
TupleShapeFunctionSet(Args &&...args)
Definition: shapefunctionset/tuple.hh:88
STL namespace.
int order() const
Definition: shapefunctionset/tuple.hh:102
std::size_t size() const
Definition: shapefunctionset/tuple.hh:104
FunctionSpaceType::JacobianRangeType JacobianRangeType
Definition: shapefunctionset/tuple.hh:75
ToNewDimRangeFunctionSpace< typename tuple_element< 0, ShapeFunctionSetTupleType >::type::FunctionSpaceType, dimRange >::Type FunctionSpaceType
Definition: shapefunctionset/tuple.hh:71
FunctionSpaceType::RangeType RangeType
Definition: shapefunctionset/tuple.hh:74
int order(Std::index_sequence< I... >) const
Definition: shapefunctionset/tuple.hh:126
void hessianEach(const Point &x, Functor functor) const
Definition: shapefunctionset/tuple.hh:119
Definition: shapefunctionset/tuple.hh:24
TupleShapeFunctionSet(GeometryType type)
Definition: shapefunctionset/tuple.hh:80
convert functions space to space with new dim range
Definition: functionspace.hh:246
void evaluateEach(const Point &x, Functor functor) const
Definition: shapefunctionset/tuple.hh:107
static tuple< decltype(makeGeometryType< I > std::declval< GeometryType >)))... > makeGeometryTypeTuple(GeometryType type, Std::index_sequence< I... >)
Definition: shapefunctionset/tuple.hh:145
TupleShapeFunctionSet(const ShapeFunctionSetTupleType &shapeFunctionSetTuple=ShapeFunctionSetTupleType())
Definition: shapefunctionset/tuple.hh:95
static GeometryType makeGeometryType(GeometryType type)
Definition: shapefunctionset/tuple.hh:138