DUNE PDELab (git)

utility.hh
1#ifndef DUNE_PDELAB_FINITEELEMENTMAP_UTILITY_HH
2#define DUNE_PDELAB_FINITEELEMENTMAP_UTILITY_HH
3
4#include <cstddef>
5
6#include <dune/common/std/type_traits.hh>
8
10
11namespace Dune {
12 namespace PDELab {
13
15
18 template<typename FEM>
19 using StaticFEMSize = decltype(FEM::size(GeometryTypes::vertex));
20
21#ifndef DOXYGEN
22
23 namespace Impl {
24
25 // This function iterates over all geometry types up to the dimension of the finite element map
26 // and returns the value of FEM::size(gt) iff that number is constant for all geometry types for
27 // which the returned size is > 0. Otherwise it returns 0. As this only works if FEM::size() is
28 // static, we use the additional argument to provide a separate overload if it is not.
29 // Note that as there is no way to easily construct the set of "valid" geometry types for a
30 // given dimension, we manually iterate over all possible topology ids. This creates weird
31 // geometry types, but we just assume that FEM::size() will return 0 for invalid ones.
32 template<typename FEM>
33 constexpr std::size_t _femBlockSize(std::true_type)
34 {
35 constexpr int dim = FEM::dimension;
36 std::size_t size = 0;
37 for (int d = 0 ; d <= dim ; ++d)
38 {
39 std::size_t gt_size = FEM::size(GeometryTypes::none(d));
40 if (gt_size > 0)
41 {
42 if (size > 0 and size != gt_size)
43 return 0;
44 else
45 size = gt_size;
46 }
47 for (unsigned int topology_id = 0 ; topology_id < (1 << dim) ; ++topology_id)
48 {
49 std::size_t gt_size = FEM::size(GeometryType(topology_id,d));
50 if (gt_size > 0)
51 {
52 if (size > 0 and size != gt_size)
53 return 0;
54 else
55 size = gt_size;
56 }
57 }
58 }
59 return size;
60 }
61
62 // fallback version if `FEM::size()` is an instance method.
63 template<typename FEM>
64 constexpr std::size_t _femBlockSize(std::false_type)
65 {
66 return 0;
67 }
68
69 } // namespace Impl
70
71#endif // DOXYGEN
72
74
82 template<typename FEM>
83 constexpr std::size_t finiteElementMapBlockSize()
84 {
85 return Impl::_femBlockSize<FEM>(Std::is_detected<StaticFEMSize,FEM>());
86 }
87
89 template<typename FEM>
90 using FiniteElementMapBlockSize = std::integral_constant<std::size_t,finiteElementMapBlockSize<FEM>()>;
91
92 } // namespace PDELab
93} //namespace Dune
94
95#endif // DUNE_PDELAB_FINITEELEMENTMAP_UTILITY_HH
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:132
constexpr GeometryType none(unsigned int dim)
Returns a GeometryType representing a singular of dimension dim.
Definition: type.hh:471
constexpr GeometryType vertex
GeometryType representing a vertex.
Definition: type.hh:492
Definitions of several macros that conditionally make C++ syntax available.
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
A unique label for each type of element that can occur in a grid.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)