Dune Core Modules (2.9.0)

referenceelements.hh
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 (C) 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
18#include <dune/common/std/type_traits.hh>
20
21#include <dune/geometry/dimension.hh>
22#include <dune/geometry/type.hh>
23#include <dune/geometry/referenceelement.hh>
24#include <dune/geometry/referenceelementimplementation.hh>
25
26namespace Dune
27{
28
29 namespace Geo
30 {
31
32#ifndef DOXYGEN
33
34
35 template<typename ctype, int dim>
36 class DeprecatedReferenceElement
37 : public ReferenceElement<ReferenceElementImplementation<ctype,dim>>
38 {
39
40 protected:
41
42 DeprecatedReferenceElement() = default;
43
44 public:
45
46 DeprecatedReferenceElement(const DeprecatedReferenceElement&) = delete;
47 DeprecatedReferenceElement& operator=(const DeprecatedReferenceElement&) = delete;
48
49 DeprecatedReferenceElement(const ReferenceElementImplementation<ctype,dim>& impl)
50 : ReferenceElement<ReferenceElementImplementation<ctype,dim>>(impl)
51 {}
52
53 };
54
55
56 template<typename ctype, int dim>
57 class ConstructibleDeprecatedReferenceElement
58 : public DeprecatedReferenceElement<ctype,dim>
59 {
60 public:
61 ConstructibleDeprecatedReferenceElement() = default;
62 };
63
64
65 namespace Impl
66 {
67
68 // ReferenceElementContainer
69 // -------------------------
70
71 template< class ctype, int dim >
72 class ReferenceElementContainer
73 {
74 static const unsigned int numTopologies = dim >= 0 ? (1u << dim) : 0;
75
76 using Implementation = ReferenceElementImplementation< ctype, dim >;
77 using ConstructibleDeprecatedReferenceElement = Dune::Geo::ConstructibleDeprecatedReferenceElement<ctype,dim>;
78
79 public:
80
81 using DeprecatedReferenceElement = Dune::Geo::DeprecatedReferenceElement<ctype,dim>;
82
84 using value_type = ReferenceElement;
85 using const_iterator = const value_type*;
86
87 ReferenceElementContainer ()
88 {
89 for( unsigned int topologyId = 0; topologyId < numTopologies; ++topologyId )
90 {
91 implementations_[ topologyId ].initialize( topologyId );
92 reference_elements_[ topologyId ].setImplementation( implementations_[ topologyId ] );
93 }
94 }
95
96 const ReferenceElement& operator() ( const GeometryType &type ) const
97 {
98 assert( type.dim() == dim );
99 return reference_elements_[ type.id() ];
100 }
101
102 const ReferenceElement& simplex () const
103 {
104 return reference_elements_[ Dune::GeometryTypes::simplex(dim).id() ];
105 }
106
107 const ReferenceElement& cube () const
108 {
109 return reference_elements_[ Dune::GeometryTypes::cube(dim).id() ];
110 }
111
112 const ReferenceElement& pyramid () const
113 {
114 return reference_elements_[ Dune::GeometryTypes::pyramid.id() ];
115 }
116
117 const ReferenceElement& prism () const
118 {
119 return reference_elements_[ Dune::GeometryTypes::prism.id() ];
120 }
121
122 const_iterator begin () const
123 {
124 return reference_elements_.data();
125 }
126
127 const_iterator end () const
128 {
129 return reference_elements_.data() + numTopologies;
130 }
131
132 // here, we make sure to actually return a const reference to something
133 // that is guaranteed not to become invalid, as otherwise, we might run
134 // straight into debugging hell when a user binds the return value to a
135 // const ref and the temporary goes out of scope.
136 const DeprecatedReferenceElement& deprecated(const ReferenceElement& v) const
137 {
138 return reference_elements_[v.impl().type(0,0).id()];
139 }
140
141 private:
142
143 std::array<Implementation,numTopologies> implementations_;
144 std::array<ConstructibleDeprecatedReferenceElement,numTopologies> reference_elements_;
145
146 };
147
148
149 } // namespace Impl
150
151
152#endif // DOXYGEN
153
154
155 // ReferenceElements
156 // ------------------------
157
168 template< class ctype_, int dim >
170 {
171
173 using ctype = ctype_;
174
177
179 static constexpr int dimension = dim;
180
181 private:
182
183 using Container = Impl::ReferenceElementContainer< ctype, dim >;
184
185 public:
186
189
191 using Iterator = typename Container::const_iterator;
192
195
197 static const ReferenceElement&
198 general ( const GeometryType& type )
199 {
200 return container() ( type );
201 }
202
204 static const ReferenceElement& simplex ()
205 {
206 return container().simplex();
207 }
208
210 static const ReferenceElement& cube ()
211 {
212 return container().cube();
213 }
214
215 static Iterator begin ()
216 {
217 return container().begin();
218 }
219
220 static Iterator end ()
221 {
222 return container().end();
223 }
224
225#ifndef DOXYGEN
226 static const typename Container::DeprecatedReferenceElement&
227 deprecated(const ReferenceElement& v)
228 {
229 return container().deprecated(v);
230 }
231#endif // DOXYGEN
232
233 private:
234
235 DUNE_EXPORT static const Container& container ()
236 {
237 static Container container;
238 return container;
239 }
240 };
241
242 } // namespace Geo
243
245 using Geo::ReferenceElements;
246
247
248#ifdef DOXYGEN
249
251
294 template<typename... T>
295 unspecified-value-type referenceElement(T&&... t);
296
297#endif
298
299
301
314 template<typename T, int dim>
316 {
318 }
319
320
322
334 template<typename T, int dim, std::enable_if_t<IsNumber<std::decay_t<T>>::value, int> = 0>
336 {
338 }
339
340
341#ifndef DOXYGEN
342
343 // helpers for the ReferenceElement<> meta function
344
345 namespace Impl {
346
347 // Evaluates to the correct reference element iff <T...> matches the pattern <number_type,Dim<int>>
348 // otherwise, it's ill-formed. Should be used with detected_or and friends.
349
350 template<typename... T>
351 struct DefaultReferenceElementExtractor;
352
353 template<typename T, typename std::enable_if<IsNumber<T>::value,int>::type dim>
354 struct DefaultReferenceElementExtractor<T,Dim<dim>>
355 {
357 };
358
359 template<typename... T>
360 using DefaultReferenceElement = typename DefaultReferenceElementExtractor<T...>::type;
361
362 }
363
364 // looks up the type of a reference element by trying to instantiate the correct overload
365 // of referenceElement() for the given arguments. This will fail if there is no valid
366 // overload and should be used with detected_or or some other utility that places the
367 // instantiation in SFINAE context.
368 //
369 // this is placed directly in namespace Dune to avoid any weird surprises
370
371 template<typename... T>
372 using LookupReferenceElement = decltype(referenceElement(std::declval<T>()...));
373
374#endif // DOXYGEN
375
376 namespace Transitional {
377
378#ifndef DOXYGEN
379
380 // this abomination checks whether the template signature matches the special case
381 // ReferenceElement<number_type,Dune::Dim<int>> and otherwise defers the type lookup
382 // to a decltype on a call to referenceElement(std::declval<T>())
383
384 template<typename... T>
386 Std::detected_t<LookupReferenceElement,T...>,
387 Impl::DefaultReferenceElement,
388 T...
389 >;
390
391#else // DOXYGEN
392
394
416 template<typename... T>
417 using ReferenceElement = unspecified-type;
418
419#endif //DOXYGEN
420
421 }
422
423#ifndef DOXYGEN
424
425 namespace Impl {
426
427 // helpers for triggering a deprecation warning for occurrences of the old
428 // ReferenceElement syntax (Dune::ReferenceElement<T,int>)
429
430 // this looks a little weird, encoding the type in the return type of a nested function,
431 // but it was the only reliable way to trigger the warning iff the compiler encounters
432 // an invalid use. Other solutions either miss some (or all) uses or trigger false alarms.
433
434 template<typename T>
435 struct ValidReferenceElementTypeSignature
436 {
438 };
439
440 template<typename T>
441 struct DeprecatedReferenceElementTypeSignature
442 {
443 [[deprecated("Dune::ReferenceElement<T,int> is deprecated, please use Dune::ReferenceElement<Geometry> (if you have a geometry), Dune::ReferenceElements<T,int>::ReferenceElement or Dune::Transitional::ReferenceElement<T,Dune::Dim<int>> instead. After Dune 2.6, you will be able to use Dune::ReferenceElement<T,Dune::Dim<int>>.")]] T check();
444 };
445
446 } // namespace Impl
447
448 // This just makes sure the user doesn't use invalid syntax (by checking against the -1 default for
449 // the dimension, and then either hands back the old-style type along with a deprecation warning or
450 // forwards to the transitional version
451 template<typename T, int dim = -1>
452 using ReferenceElement = decltype(
453 std::declval<
454 typename std::conditional<
455 dim == -1,
456 Impl::ValidReferenceElementTypeSignature<T>,
457 Impl::DeprecatedReferenceElementTypeSignature<Geo::DeprecatedReferenceElement<T,dim>>
458 >::type
459 >().check());
460
461#else // DOXYGEN
462
464
496 template<typename T, int dim>
497 using ReferenceElement = unspecified-type;
498
499#endif // DOXYGEN
500
501
502
503} // namespace Dune
504
505#endif // #ifndef DUNE_GEOMETRY_REFERENCEELEMENTS_HH
This class provides access to geometric and topological properties of a reference element.
Definition: referenceelement.hh:52
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:125
constexpr unsigned int id() const
Return the topology id of the type.
Definition: type.hh:376
Traits for type conversions and type information.
typename detected_or< Default, Op, Args... >::type detected_or_t
Returns Op<Args...> if that is valid; otherwise returns the fallback type Default.
Definition: type_traits.hh:185
typename detected_or< nonesuch, Op, Args... >::type detected_t
Returns Op<Args...> if that is valid; otherwise returns nonesuch.
Definition: type_traits.hh:170
bool gt(const T &first, const T &second, typename EpsilonType< T >::Type epsilon)
test if first greater than second
Definition: float_cmp.cc:158
unspecified-type ReferenceElement
Returns the type of reference element for the argument types T...
Definition: referenceelements.hh:417
unspecified value type referenceElement(T &&... t)
Returns a reference element for the objects t....
unspecified-type ReferenceElement
Returns the type of reference element for the argument type T.
Definition: referenceelements.hh:497
constexpr GeometryType cube(unsigned int dim)
Returns a GeometryType representing a hypercube of dimension dim.
Definition: type.hh:472
constexpr GeometryType prism
GeometryType representing a 3D prism.
Definition: type.hh:542
constexpr GeometryType pyramid
GeometryType representing a 3D pyramid.
Definition: type.hh:536
constexpr GeometryType simplex(unsigned int dim)
Returns a GeometryType representing a simplex of dimension dim.
Definition: type.hh:463
Dune namespace.
Definition: alignedallocator.hh:13
@ simplex
use only simplex elements (i.e., triangles or tetrahedra)
Definition: declaration.hh:18
@ cube
use only cube elements (i.e., quadrilaterals or hexahedra)
Definition: declaration.hh:19
Static tag representing a dimension.
Definition: dimension.hh:16
Class providing access to the singletons of the reference elements.
Definition: referenceelements.hh:170
Iterator iterator
Iterator over available reference elements.
Definition: referenceelements.hh:194
typename Container::ReferenceElement ReferenceElement
The reference element type.
Definition: referenceelements.hh:188
static const ReferenceElement & cube()
get hypercube reference elements
Definition: referenceelements.hh:210
ctype_ ctype
The coordinate field type of the contained reference elements.
Definition: referenceelements.hh:173
static const ReferenceElement & general(const GeometryType &type)
get general reference elements
Definition: referenceelements.hh:198
static const ReferenceElement & simplex()
get simplex reference elements
Definition: referenceelements.hh:204
typename Container::const_iterator Iterator
Iterator over available reference elements.
Definition: referenceelements.hh:191
static constexpr int dimension
The dimension of the contained reference elements.
Definition: referenceelements.hh:179
ctype CoordinateField
The coordinate field type of the contained reference elements.
Definition: referenceelements.hh:176
A unique label for each type of element that can occur in a grid.
Definition of macros controlling symbol visibility at the ABI level.
#define DUNE_EXPORT
Export a symbol as part of the public ABI.
Definition: visibility.hh:20
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 21, 23:30, 2024)