dune-fem  2.6-git
basisfunctionset/hpdg/anisotropic.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_HPDG_SPACE_BASISFUNCTIONSETS_ANISOTROPIC_HH
2 #define DUNE_FEM_HPDG_SPACE_BASISFUNCTIONSETS_ANISOTROPIC_HH
3 
4 #include <cassert>
5 #include <cstddef>
6 
7 #include <algorithm>
8 #include <array>
9 #include <tuple>
10 #include <type_traits>
11 #include <utility>
12 
13 #include <dune/common/fvector.hh>
14 #include <dune/common/power.hh>
15 #include <dune/common/std/utility.hh>
16 
17 #include <dune/geometry/type.hh>
18 
19 #include <dune/grid/common/capabilities.hh>
20 
27 
28 #include "basisfunctionsets.hh"
29 #include "legendre.hh"
30 
31 namespace Dune
32 {
33 
34  namespace Fem
35  {
36 
37  namespace hpDG
38  {
39 
40  // Internal forward declaration
41  // ----------------------------
42 
43  template< class FunctionSpace, class GridPart, int maxOrder, bool caching = true >
45 
46 
47 
48 #ifndef DOXYGEN
49 
50  // LegendreShapeFunctionSetTuple
51  // -----------------------------
52 
53  template< class FunctionSpace, int order, bool caching >
54  class LegendreShapeFunctionSetTuple
55  {
56  // false == no hierarchical ordering
57  using FactoryType = LegendreShapeFunctionSets< typename Dune::Fem::ToNewDimDomainFunctionSpace< FunctionSpace, 1 >::Type, order, false, caching >;
59 
60  template< int i, class MultiIndex >
61  static ElementType get ( const MultiIndex &multiIndex )
62  {
63  return &FactoryType::get( multiIndex[ i ] );
64  }
65 
66  template< class MultiIndex, int... i >
67  static auto get ( const MultiIndex &multiIndex, Dune::Std::integer_sequence< int, i... > )
68  -> decltype( std::make_tuple( get< i, MultiIndex >( multiIndex )... ) )
69  {
70  return std::make_tuple( get< i, MultiIndex >( multiIndex )... );
71  }
72 
73  public:
74  using Type = decltype( get( std::declval< Dune::FieldVector< int, FunctionSpace::dimDomain > >(), Dune::Std::make_integer_sequence< int, FunctionSpace::dimDomain >() ) );
75 
76  template< class MultiIndex >
77  static Type get ( const MultiIndex &multiIndex )
78  {
79  return get( multiIndex, Dune::Std::make_integer_sequence< int, FunctionSpace::dimDomain >() );
80  }
81  };
82 
83 
84 
85  // AnisotropicShapeFunctionSet
86  // ---------------------------
87 
88  template< class FunctionSpace, int order, bool caching >
89  struct AnisotropicShapeFunctionSet
90  : public Dune::Fem::TensorProductShapeFunctionSet< FunctionSpace, typename LegendreShapeFunctionSetTuple< FunctionSpace, order, caching >::Type >
91  {
93 
94  public:
95  AnisotropicShapeFunctionSet ()
96  : AnisotropicShapeFunctionSet( multiIndex() )
97  {}
98 
99  template< class MultiIndex >
100  explicit AnisotropicShapeFunctionSet ( const MultiIndex &multiIndex )
102  {}
103 
104  private:
105  static Dune::FieldVector< int, FunctionSpace::dimDomain > multiIndex ()
106  {
107  return Dune::FieldVector< int, FunctionSpace::dimDomain >( order );
108  }
109  };
110 
111 
112 
113  // AnisotropicBasisFunctionSetsTraits
114  // ----------------------------------
115 
116  template< class FunctionSpace, class GridPart, int maxOrder, bool caching >
117  class AnisotropicBasisFunctionSetsTraits
118  {
119  public:
121 
122  using GridPartType = GridPart;
123  using EntityType = typename GridPartType::template Codim< 0 >::EntityType;
124  using Types = std::array< GeometryType, 1 >;
125 
126  using KeyType = Dune::FieldVector< int, FunctionSpace::dimDomain >;
127 
128  using ScalarFunctionSpaceType = typename Dune::Fem::ToNewDimRangeFunctionSpace< FunctionSpace, 1 >::Type;
129  using ScalarShapeFunctionSetType = AnisotropicShapeFunctionSet< ScalarFunctionSpaceType, maxOrder, caching >;
131 
133 
134  static const int localBlockSize = FunctionSpace::dimRange;
135 
136  using DataType = int;
137  };
138 
139 #endif // ifndef DOXYGEN
140 
141 
142 
143  // AnisotropicBasisFunctionSets
144  // ----------------------------
145 
157  template< class FunctionSpace, class GridPart, int maxOrder, bool caching >
159  : public BasisFunctionSets< AnisotropicBasisFunctionSetsTraits< FunctionSpace, GridPart, maxOrder, caching > >
160  {
162 
163  public:
168 
171 
172  private:
173  using ScalarShapeFunctionSetType = typename BaseType::Traits::ScalarShapeFunctionSetType;
174  using ShapeFunctionSetType = typename BaseType::Traits::ShapeFunctionSetType;
175 
176  public:
178  using KeyType = typename BaseType::KeyType;
180  using DataType = typename BaseType::DataType;
181 
185  typename BaseType::Types types () const noexcept
186  {
187  std::array< GeometryType, 1 > types;
188  types[ 0 ].makeCube( EntityType::mydimension );
189  return std::move( types );
190  }
191 
193  static constexpr std::size_t maxBlocks () noexcept
194  {
195  return Dune::StaticPower< maxOrder+1, FunctionSpace::dimDomain >::power;
196  }
197 
199  static std::size_t maxBlocks ( Dune::GeometryType type ) noexcept
200  {
201  assert( contains( type ) );
202  return maxBlocks();
203  }
204 
206  static std::size_t blocks ( GeometryType type, KeyType key ) noexcept
207  {
208  assert( contains( type ) );
209  std::size_t blocks = 1;
210  auto function = [&blocks]( int order ) -> void
211  {
212  assert( 0 <= order && order <= maxOrder );
213  blocks *= order+1;
214  };
215  std::for_each( key.begin(), key.end(), function );
216  assert( blocks == scalarShapeFunctionSet( key ).size() );
217  return blocks;
218  }
219 
221  static DataType encode ( const KeyType &key ) noexcept
222  {
223  DataType data = 0, factor = 1;
224  for( int i = 0; i < FunctionSpace::dimDomain-1; ++i )
225  {
226  data += key[ i ]*factor;
227  factor *= maxOrder+1;
228  }
229  data += key[ FunctionSpace::dimDomain-1 ]*factor;
230  assert( decode( data ) == key );
231  return data;
232  }
233 
235  static KeyType decode ( DataType data ) noexcept
236  {
237  KeyType key;
238  for( int i = 0; i < FunctionSpace::dimDomain-1; ++i )
239  {
240  key[ i ] = data % (maxOrder+1);
241  data /= (maxOrder+1);
242  }
243  return std::move( key );
244  }
245 
247  static constexpr bool orthogonal () noexcept
248  {
249  using GridType = typename GridPartType::GridType;
250  return Dune::Capabilities::isCartesian< GridType >::v;
251  }
252 
254  static constexpr int order () noexcept { return maxOrder; }
255 
257  static constexpr int order ( Dune::GeometryType type ) noexcept
258  {
259  assert( type == GeometryType( GeometryType::cube, EntityType::mydimension ) );
260  return order();
261  }
262 
264  static int order ( Dune::GeometryType type, KeyType key ) noexcept
265  {
266  assert( type == GeometryType( GeometryType::cube, EntityType::mydimension ) );
267  return *std::max_element( key.begin(), key.end() );
268  }
269 
271  static BasisFunctionSetType basisFunctionSet ( const EntityType &entity, const KeyType &key ) noexcept
272  {
273  assert( entity.type() == GeometryType( Dune::Impl::CubeTopology< EntityType::mydimension >::type::id, EntityType::mydimension ) );
274  return BasisFunctionSetType( entity, shapeFunctionSet( key ) );
275  }
276 
277  private:
278  static bool contains ( Dune::GeometryType type ) noexcept
279  {
280  return (type.isCube() && type.dim() == EntityType::mydimension);
281  }
282 
283  static ScalarShapeFunctionSetType scalarShapeFunctionSet ( const KeyType &key ) noexcept
284  {
285  return ScalarShapeFunctionSetType( key );
286  }
287 
288  static ShapeFunctionSetType shapeFunctionSet ( const KeyType &key ) noexcept
289  {
290  return ShapeFunctionSetType( scalarShapeFunctionSet( key ) );
291  }
292  };
293 
294  } // namespace hpDG
295 
296  } // namespace Fem
297 
298 } // namespace Dune
299 
300 #endif // #ifndef DUNE_FEM_HPDG_SPACE_BASISFUNCTIONSETS_ANISOTROPIC_HH
Definition: bindguard.hh:11
std::tuple_element< i, Tuple >::type & get(Dune::TypeIndexedTuple< Tuple, Types > &tuple)
Definition: typeindexedtuple.hh:122
Definition: basisfunctionset/default.hh:47
A family of anisotropic local product basis function sets.
Definition: basisfunctionset/hpdg/anisotropic.hh:160
typename BaseType::BasisFunctionSetType BasisFunctionSetType
basis function set
Definition: basisfunctionset/hpdg/anisotropic.hh:170
static constexpr bool orthogonal() noexcept
Definition: basisfunctionset/hpdg/anisotropic.hh:247
static constexpr int order(Dune::GeometryType type) noexcept
return maximum order
Definition: basisfunctionset/hpdg/anisotropic.hh:257
typename BaseType::EntityType EntityType
entity type
Definition: basisfunctionset/hpdg/anisotropic.hh:167
static constexpr int order() noexcept
return maximum order
Definition: basisfunctionset/hpdg/anisotropic.hh:254
static int order(Dune::GeometryType type, KeyType key) noexcept
return maximum order
Definition: basisfunctionset/hpdg/anisotropic.hh:264
typename BaseType::GridPartType GridPartType
Definition: basisfunctionset/hpdg/anisotropic.hh:165
static KeyType decode(DataType data) noexcept
Definition: basisfunctionset/hpdg/anisotropic.hh:235
typename BaseType::DataType DataType
Definition: basisfunctionset/hpdg/anisotropic.hh:180
BaseType::Types types() const noexcept
Definition: basisfunctionset/hpdg/anisotropic.hh:185
static std::size_t blocks(GeometryType type, KeyType key) noexcept
Definition: basisfunctionset/hpdg/anisotropic.hh:206
static std::size_t maxBlocks(Dune::GeometryType type) noexcept
Definition: basisfunctionset/hpdg/anisotropic.hh:199
typename BaseType::KeyType KeyType
Definition: basisfunctionset/hpdg/anisotropic.hh:178
static constexpr std::size_t maxBlocks() noexcept
Definition: basisfunctionset/hpdg/anisotropic.hh:193
static BasisFunctionSetType basisFunctionSet(const EntityType &entity, const KeyType &key) noexcept
return basis function set for given entity
Definition: basisfunctionset/hpdg/anisotropic.hh:271
static DataType encode(const KeyType &key) noexcept
Definition: basisfunctionset/hpdg/anisotropic.hh:221
abstract interface class for a family of local basis function sets
Definition: basisfunctionset/hpdg/basisfunctionsets.hh:30
typename Traits::DataType DataType
data type
Definition: basisfunctionset/hpdg/basisfunctionsets.hh:53
typename Traits::Types Types
a range of geometry types
Definition: basisfunctionset/hpdg/basisfunctionsets.hh:47
typename Traits::BasisFunctionSetType BasisFunctionSetType
basis function set type
Definition: basisfunctionset/hpdg/basisfunctionsets.hh:42
typename BasisFunctionSetType::EntityType EntityType
entity type
Definition: basisfunctionset/hpdg/basisfunctionsets.hh:44
typename Traits::KeyType KeyType
key type
Definition: basisfunctionset/hpdg/basisfunctionsets.hh:39
typename Traits::GridPartType GridPartType
grid part type
Definition: basisfunctionset/hpdg/basisfunctionsets.hh:36
convert functions space to space with new dim range
Definition: functionspace.hh:250
@ dimDomain
dimension of domain vector space
Definition: functionspaceinterface.hh:46
@ dimRange
dimension of range vector space
Definition: functionspaceinterface.hh:48
Definition: shapefunctionset/proxy.hh:33
Definition: tensorproduct.hh:28
Definition: shapefunctionset/vectorial.hh:446
Provides a proxy class for pointers to a shape function set.