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>
7
9
10namespace Dune {
11 namespace PDELab {
12
14
17 template<typename FEM>
18 using StaticFEMSize = decltype(FEM::size(GeometryTypes::vertex));
19
20#ifndef DOXYGEN
21
22 namespace Impl {
23
24 // This function iterates over all geometry types up to the dimension of the finite element map
25 // and returns the value of FEM::size(gt) iff that number is constant for all geometry types for
26 // which the returned size is > 0. Otherwise it returns 0. As this only works if FEM::size() is
27 // static, we use the additional argument to provide a separate overload if it is not.
28 // Note that as there is no way to easily construct the set of "valid" geometry types for a
29 // given dimension, we manually iterate over all possible topology ids. This creates weird
30 // geometry types, but we just assume that FEM::size() will return 0 for invalid ones.
31 template<typename FEM>
32 constexpr std::size_t _femBlockSize(std::true_type)
33 {
34 constexpr int dim = FEM::dimension;
35 std::size_t size = 0;
36 for (int d = 0 ; d <= dim ; ++d)
37 {
38 std::size_t gt_size = FEM::size(GeometryTypes::none(d));
39 if (gt_size > 0)
40 {
41 if (size > 0 and size != gt_size)
42 return 0;
43 else
44 size = gt_size;
45 }
46 for (unsigned int topology_id = 0 ; topology_id < (1 << dim) ; ++topology_id)
47 {
48 std::size_t gt_size = FEM::size(GeometryType(topology_id,d));
49 if (gt_size > 0)
50 {
51 if (size > 0 and size != gt_size)
52 return 0;
53 else
54 size = gt_size;
55 }
56 }
57 }
58 return size;
59 }
60
61 // fallback version if `FEM::size()` is an instance method.
62 template<typename FEM>
63 constexpr std::size_t _femBlockSize(std::false_type)
64 {
65 return 0;
66 }
67
68 } // namespace Impl
69
70#endif // DOXYGEN
71
73
81 template<typename FEM>
82 constexpr std::size_t finiteElementMapBlockSize()
83 {
84 return Impl::_femBlockSize<FEM>(Std::is_detected<StaticFEMSize,FEM>());
85 }
86
88 template<typename FEM>
89 using FiniteElementMapBlockSize = std::integral_constant<std::size_t,finiteElementMapBlockSize<FEM>()>;
90
91 } // namespace PDELab
92} //namespace Dune
93
94#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
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 (Nov 23, 23:29, 2024)