dune-grid  2.4
partitionset.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 #ifndef DUNE_GRID_COMMON_PARTITIONSET_HH
4 #define DUNE_GRID_COMMON_PARTITIONSET_HH
5 
6 #include <dune/common/typetraits.hh>
7 #include <dune/common/std/constexpr.hh>
9 
10 namespace Dune {
11 
17  namespace {
18 
19  // Simple TMP to deduce partition iterator type from set of partitions.
20  template<unsigned int partitions>
21  struct derive_partition_iterator_type
22  {
23  // We did not match any specialization, bail out...
24  static_assert(AlwaysFalse<std::integral_constant<unsigned int,partitions> >::value,
25  "There is no partition iterator for this combination of entity partitions");
26  };
27 
28 
29  // specializations of derive_partition_iterator_type for existing PartitionIteratorTypes
30 
31  template<>
32  struct derive_partition_iterator_type<
33  (1 << InteriorEntity)
34  >
35  : public std::integral_constant<PartitionIteratorType,Interior_Partition>
36  {};
37 
38  template<>
39  struct derive_partition_iterator_type<
40  (1 << InteriorEntity) |
41  (1 << BorderEntity)
42  >
43  : public std::integral_constant<PartitionIteratorType,InteriorBorder_Partition>
44  {};
45 
46  template<>
47  struct derive_partition_iterator_type<
48  (1 << InteriorEntity) |
49  (1 << BorderEntity) |
50  (1 << OverlapEntity)
51  >
52  : public std::integral_constant<PartitionIteratorType,Overlap_Partition>
53  {};
54 
55  template<>
56  struct derive_partition_iterator_type<
57  (1 << InteriorEntity) |
58  (1 << BorderEntity) |
59  (1 << OverlapEntity) |
60  (1 << FrontEntity)
61  >
62  : public std::integral_constant<PartitionIteratorType,OverlapFront_Partition>
63  {};
64 
65  template<>
66  struct derive_partition_iterator_type<
67  (1 << InteriorEntity) |
68  (1 << BorderEntity) |
69  (1 << OverlapEntity) |
70  (1 << FrontEntity) |
71  (1 << GhostEntity)
72  >
73  : public std::integral_constant<PartitionIteratorType,All_Partition>
74  {};
75 
76  template<>
77  struct derive_partition_iterator_type<
78  (1 << GhostEntity)
79  >
80  : public std::integral_constant<PartitionIteratorType,Ghost_Partition>
81  {};
82 
83  } // anonymous namespace
84 
85 
87 
95  template<unsigned int partitions>
96  struct PartitionSet
97  {
99  static const unsigned int value = partitions;
100 
101 
103  template<unsigned int p>
104  struct PartitionSet<partitions | p>
105  operator+(const PartitionSet<p>& set) const
106  {
108  }
109 
111  template<unsigned int p>
112  struct PartitionSet<partitions & ~p>
113  operator-(const PartitionSet<p>& set) const
114  {
116  }
117 
119  friend std::ostream& operator<<(std::ostream& os, const PartitionSet&)
120  {
121  unsigned int set = partitions;
122  os << "partition set {";
123  bool first = true;
124  for (unsigned int p = 0; set; set &= ~(1 << p++))
125  {
126  if (!(set & (1 << p)))
127  continue;
128  if (!first)
129  os << ",";
130  first = false;
131  os << static_cast<PartitionType>(p);
132  }
133  os << "}";
134  return os;
135  }
136 
137 #if HAVE_CONSTEXPR || DOXYGEN
138 
140 
146  {
147  return derive_partition_iterator_type<partitions>::value;
148  }
149 
150 #endif // HAVE_CONSTEXPR
151 
153  static DUNE_CONSTEXPR bool contains(PartitionType pt)
154  {
155  return partitions & (1 << pt);
156  }
157 
159  template<unsigned int contained_partitions>
160  static DUNE_CONSTEXPR bool contains(PartitionSet<contained_partitions>)
161  {
162  return (partitions & contained_partitions) == contained_partitions;
163  }
164 
165 
166  };
167 
169 
172  template<PartitionType p>
174  {
175  return PartitionSet<(1 << p)>();
176  }
177 
179  namespace Partitions {
180 
181 
182 #ifdef DOXYGEN
183 
185  typedef PartitionSet<...> Interior;
186 
188  typedef PartitionSet<...> Border;
189 
191  typedef PartitionSet<...> Overlap;
192 
194  typedef PartitionSet<...> Front;
195 
197  typedef PartitionSet<...> Ghost;
198 
201 
204 
207 
209  typedef PartitionSet<...> All;
210 
211 
214 
217 
220 
223 
226 
229 
232 
235 
238 
239 #else // DOXYGEN
240 
241  // First declare the types and objects for individual partitions
242 
243  typedef decltype(partitionSet<InteriorEntity>()) Interior;
244  typedef decltype(partitionSet<BorderEntity>()) Border;
245  typedef decltype(partitionSet<OverlapEntity>()) Overlap;
246  typedef decltype(partitionSet<FrontEntity>()) Front;
247  typedef decltype(partitionSet<GhostEntity>()) Ghost;
248 
249  namespace {
250 
251  // place global objects in anonymous namespace to ensure that visibility is
252  // restricted to the current translation unit, making it easier for the compiler
253  // to eliminate the actual objects and to avoid linking problems
254 
255  const Interior interior = {};
256  const Border border = {};
257  const Overlap overlap = {};
258  const Front front = {};
259  const Ghost ghost = {};
260 
261  }
262 
263  // Now we can declare the partition sets that are a result of combining partitions
264 
265  typedef decltype(interior + border) InteriorBorder;
266  typedef decltype(interior + border + overlap) InteriorBorderOverlap;
267  typedef decltype(interior + border + overlap + front) InteriorBorderOverlapFront;
268  typedef decltype(interior + border + overlap + front + ghost) All;
269 
270  namespace {
271 
272  // again, place the global objects in an anonymous namespace
273 
274  const InteriorBorder interiorBorder = {};
275  const InteriorBorderOverlap interiorBorderOverlap = {};
276  const InteriorBorderOverlapFront interiorBorderOverlapFront = {};
277  const All all = {};
278 
279  }
280 
281 #endif // DOXYGEN
282 
283  } // namespace Partitions
284 
289 } // namespace Dune
290 
291 #endif // DUNE_GRID_COMMON_PARTITIONSET_HH
PartitionSet<...> InteriorBorderOverlap
Type of PartitionSet for the interior, border and overlap partitions.
Definition: partitionset.hh:203
PartitionSet<...> Front
Type of PartitionSet for the front partition.
Definition: partitionset.hh:194
PartitionSet<...> Overlap
Type of PartitionSet for the overlap partition.
Definition: partitionset.hh:191
PartitionSet<...> InteriorBorder
Type of PartitionSet for the interior and border partitions.
Definition: partitionset.hh:200
on boundary between overlap and ghost
Definition: gridenums.hh:32
PartitionSet<...> InteriorBorderOverlapFront
Type of PartitionSet for the interior, border, overlap and front partitions.
Definition: partitionset.hh:206
A set of PartitionType values.
Definition: partitionset.hh:96
Interior interior
PartitionSet for the interior partition.
Definition: partitionset.hh:213
struct PartitionSet< partitions &~p > operator-(const PartitionSet< p > &set) const
Returns a new PartitionSet that does not contain the partitions in set.
Definition: partitionset.hh:113
Include standard header files.
Definition: agrid.hh:59
InteriorBorderOverlapFront interiorBorderOverlapFront
PartitionSet for the interior, border, overlap and front partitions.
Definition: partitionset.hh:234
Ghost ghost
PartitionSet for the ghost partition.
Definition: partitionset.hh:225
PartitionIteratorType
Parameter to be used for the parallel level- and leaf iterators.
Definition: gridenums.hh:134
all interior entities
Definition: gridenums.hh:29
Front front
PartitionSet for the front partition.
Definition: partitionset.hh:222
ghost entities
Definition: gridenums.hh:33
PartitionSet<...> All
Type of PartitionSet for all partitions.
Definition: partitionset.hh:209
on boundary between interior and overlap
Definition: gridenums.hh:30
InteriorBorder interiorBorder
PartitionSet for the interior and border partitions.
Definition: partitionset.hh:228
static DUNE_CONSTEXPR bool contains(PartitionSet< contained_partitions >)
Tests whether the given PartitionSet is contained in this set.
Definition: partitionset.hh:160
PartitionSet<...> Ghost
Type of PartitionSet for the ghost partition.
Definition: partitionset.hh:197
Overlap overlap
PartitionSet for the overlap partition.
Definition: partitionset.hh:219
static DUNE_CONSTEXPR bool contains(PartitionType pt)
Tests whether the given PartitionType is contained in this set.
Definition: partitionset.hh:153
PartitionSet<...> Border
Type of PartitionSet for the border partition.
Definition: partitionset.hh:188
Border border
PartitionSet for the border partition.
Definition: partitionset.hh:216
PartitionSet<...> Interior
Type of PartitionSet for the interior partition.
Definition: partitionset.hh:185
PartitionSet<(1<< p)> partitionSet()
Creates a PartitionSet for the given PartitionType.
Definition: partitionset.hh:173
PartitionType
Attributes used in the generic overlap model.
Definition: gridenums.hh:28
All all
PartitionSet for all partitions.
Definition: partitionset.hh:237
InteriorBorderOverlap interiorBorderOverlap
PartitionSet for the interior, border and overlap partitions.
Definition: partitionset.hh:231
all entities lying in the overlap zone
Definition: gridenums.hh:31
friend std::ostream & operator<<(std::ostream &os, const PartitionSet &)
Writes the PartitionSet to an output stream.
Definition: partitionset.hh:119
static constexpr PartitionIteratorType partitionIterator()
Returns the PartitionIteratorType that can be used to iterate over the partitions in the set...
Definition: partitionset.hh:145