dune-common  2.2.0
geometrytypeindex.hh
Go to the documentation of this file.
1 // -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=8 sw=2 sts=2:
3 
4 #ifndef DISABLE_GEOMETRYTYPEINDEX_DEPRECATION_WARNING
5 #warning #include <dune/common/geometrytypeindex.hh> is deprecated. Use
6 #warning #include <dune/geometry/typeindex.hh> instead. You may need the new
7 #warning Dune-Geometry core module.
8 #warning NOTE: <dune/common/geometrytypeindex.hh> was never part of a release,
9 #warning so this compatibility mechanism should be removed before the 2.2
10 #warning release.
11 #endif // DISABLE_GEOMETRYTYPEINDEX_DEPRECATION_WARNING
12 
13 #ifndef DUNE_COMMON_GEOMETRYTYPEINDEX_HH
14 #define DUNE_COMMON_GEOMETRYTYPEINDEX_HH
15 
21 #include <cstddef>
22 
23 #define DISABLE_GEOMETRYTYPE_DEPRECATION_WARNING
25 #undef DISABLE_GEOMETRYTYPE_DEPRECATION_WARNING
26 
27 namespace Dune {
28 
32 
36  inline static std::size_t regular_size(std::size_t dim) {
37  // The following expression is derived from the expression for
38  // GlobalGeometryTypeIndex::regular_base(). Substracting
39  // regular_base(dim+1)-regular_base(dim) we get:
40  //
41  // ((1 << dim+1) >> 1) - ((1 << dim) >> 1)
42  //
43  // We always have
44  //
45  // dim >= 0,
46  //
47  // so
48  //
49  // (1 << dim+1) >= 2 and (1 << dim+2) % 2 == 0.
50  //
51  // So if we apply a single right-shift to that, we will never lose any
52  // set bits, thus
53  //
54  // ((1 << dim+1) >> 1) == (1 << dim)
55  return (1 << dim) - ((1 << dim) >> 1);
56  }
57 
58  public:
60 
63  inline static std::size_t size(std::size_t dim) {
64  // one for "none"
65  return regular_size(dim) + 1;
66  }
67 
69 
74  inline static std::size_t index(const GeometryType &gt) {
75  if(gt.isNone())
76  return regular_size(gt.dim());
77  else
78  return gt.id() >> 1;
79  }
80  };
81 
86 
90  inline static std::size_t regular_base(std::size_t dim) {
91  // The number of regular geometry types in a given dimension is
92  // 2^(dim-1). For dim==0 this would yield 1/2 geometry types (which is
93  // obviously bogus, dim==0 has one regular geometry type, the point).
94  // The following expression relies on 1 >> 1 == 0 to treat dim==0
95  // specially.
96  return (1 << dim) >> 1;
97  }
98 
101  inline static std::size_t base(std::size_t dim) {
102  // dim times "none"
103  return regular_base(dim) + dim;
104  }
105 
106  public:
109 
112  inline static std::size_t size(std::size_t maxdim)
113  { return base(maxdim+1); }
114 
116 
122  inline static std::size_t index(const GeometryType &gt) {
123  return base(gt.dim()) + LocalGeometryTypeIndex::index(gt);
124  }
125  };
126 
127 } // namespace Dune
128 
129 #endif // DUNE_COMMON_GEOMETRYTYPEINDEX_HH