dune-geometry  2.11
referenceelements.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 // SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
4 // SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
5 #ifndef DUNE_GEOMETRY_REFERENCEELEMENTS_HH
6 #define DUNE_GEOMETRY_REFERENCEELEMENTS_HH
7 
8 #include <cassert>
9 
10 #include <algorithm>
11 #include <limits>
12 #include <tuple>
13 #include <utility>
14 #include <vector>
15 #include <array>
16 
17 #include <dune/common/typetraits.hh>
18 #include <dune/common/std/type_traits.hh>
19 #include <dune/common/visibility.hh>
20 
22 #include <dune/geometry/type.hh>
25 
26 namespace Dune
27 {
28 
29  namespace Geo
30  {
31 
32 #ifndef DOXYGEN
33 
34 
35  namespace Impl
36  {
37 
38  // ReferenceElementContainer
39  // -------------------------
40 
41  template< class ctype, int dim >
42  class ReferenceElementContainer
43  {
44  static const unsigned int numTopologies = dim >= 0 ? (1u << dim) : 0;
45 
46  using Implementation = ReferenceElementImplementation< ctype, dim >;
47 
48  public:
49 
51  using value_type = ReferenceElement;
52  using const_iterator = const value_type*;
53 
54  ReferenceElementContainer ()
55  {
56  for( unsigned int topologyId = 0; topologyId < numTopologies; ++topologyId )
57  {
58  implementations_[ topologyId ].initialize( topologyId );
59  reference_elements_[ topologyId ].setImplementation( implementations_[ topologyId ] );
60  }
61  }
62 
63  const ReferenceElement& operator() ( const GeometryType &type ) const
64  {
65  assert( type.dim() == dim );
66  return reference_elements_[ type.id() ];
67  }
68 
69  const ReferenceElement& simplex () const
70  {
71  return reference_elements_[ Dune::GeometryTypes::simplex(dim).id() ];
72  }
73 
74  const ReferenceElement& cube () const
75  {
76  return reference_elements_[ Dune::GeometryTypes::cube(dim).id() ];
77  }
78 
79  const ReferenceElement& pyramid () const
80  {
81  return reference_elements_[ Dune::GeometryTypes::pyramid.id() ];
82  }
83 
84  const ReferenceElement& prism () const
85  {
86  return reference_elements_[ Dune::GeometryTypes::prism.id() ];
87  }
88 
89  const_iterator begin () const
90  {
91  return reference_elements_.data();
92  }
93 
94  const_iterator end () const
95  {
96  return reference_elements_.data() + numTopologies;
97  }
98 
99  private:
100 
101  std::array<Implementation,numTopologies> implementations_;
102  std::array<ReferenceElement,numTopologies> reference_elements_;
103 
104  };
105 
106 
107  } // namespace Impl
108 
109 
110 #endif // DOXYGEN
111 
112 
113  // ReferenceElements
114  // ------------------------
115 
126  template< class ctype_, int dim >
127  struct ReferenceElements
128  {
129 
131  using ctype = ctype_;
132 
135 
137  static constexpr int dimension = dim;
138 
139  private:
140 
141  using Container = Impl::ReferenceElementContainer< ctype, dim >;
142 
143  public:
144 
147 
149  using Iterator = typename Container::const_iterator;
150 
153 
155  static const ReferenceElement&
156  general ( const GeometryType& type )
157  {
158  return container() ( type );
159  }
160 
162  static const ReferenceElement& simplex ()
163  {
164  return container().simplex();
165  }
166 
168  static const ReferenceElement& cube ()
169  {
170  return container().cube();
171  }
172 
173  static Iterator begin ()
174  {
175  return container().begin();
176  }
177 
178  static Iterator end ()
179  {
180  return container().end();
181  }
182 
183  private:
184 
185  DUNE_EXPORT static const Container& container ()
186  {
187  static Container container;
188  return container;
189  }
190  };
191 
192  } // namespace Geo
193 
195  using Geo::ReferenceElements;
196 
197 
198 #ifdef DOXYGEN
199 
201 
244  template<typename... T>
245  unspecified-value-type referenceElement(T&&... t);
246 
247 #endif
248 
249 
251 
264  template<typename T, int dim>
266  {
268  }
269 
270 
272 
284  template<typename T, int dim, std::enable_if_t<IsNumber<std::decay_t<T>>::value, int> = 0>
286  {
288  }
289 
290  template<typename... T>
291  using ReferenceElement = decltype(referenceElement(std::declval<T>()...));
292 
293 } // namespace Dune
294 
295 #endif // #ifndef DUNE_GEOMETRY_REFERENCEELEMENTS_HH
decltype(referenceElement(std::declval< T >()...)) ReferenceElement
Definition: referenceelements.hh:291
This class provides access to geometric and topological properties of a reference element...
Definition: affinegeometry.hh:31
constexpr GeometryType pyramid
GeometryType representing a 3D pyramid.
Definition: type.hh:522
Static tag representing a dimension.
Definition: dimension.hh:14
typename Container::const_iterator Iterator
Iterator over available reference elements.
Definition: referenceelements.hh:149
A unique label for each type of element that can occur in a grid.
ctype CoordinateField
The coordinate field type of the contained reference elements.
Definition: referenceelements.hh:134
static Iterator begin()
Definition: referenceelements.hh:173
ctype_ ctype
The coordinate field type of the contained reference elements.
Definition: referenceelements.hh:131
constexpr GeometryType cube(unsigned int dim)
Returns a GeometryType representing a hypercube of dimension dim.
Definition: type.hh:462
constexpr GeometryType simplex(unsigned int dim)
Returns a GeometryType representing a simplex of dimension dim.
Definition: type.hh:453
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:113
static constexpr int dimension
The dimension of the contained reference elements.
Definition: referenceelements.hh:137
static const ReferenceElement & general(const GeometryType &type)
get general reference elements
Definition: referenceelements.hh:156
constexpr unsigned int id() const
Return the topology id of the type.
Definition: type.hh:365
constexpr GeometryType prism
GeometryType representing a 3D prism.
Definition: type.hh:528
Iterator iterator
Iterator over available reference elements.
Definition: referenceelements.hh:152
typename Container::ReferenceElement ReferenceElement
The reference element type.
Definition: referenceelements.hh:146
static const ReferenceElement & simplex()
get simplex reference elements
Definition: referenceelements.hh:162
static Iterator end()
Definition: referenceelements.hh:178
static const ReferenceElement & cube()
get hypercube reference elements
Definition: referenceelements.hh:168
Definition: affinegeometry.hh:21
unspecified value type referenceElement(T &&... t)
Returns a reference element for the objects t....