Dune Core Modules (2.5.0)

partitionset.hh
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
7#include <dune/grid/common/gridenums.hh>
8
9namespace Dune {
10
16 namespace {
17
18 // Simple TMP to deduce partition iterator type from set of partitions.
19 template<unsigned int partitions>
20 struct derive_partition_iterator_type
21 {
22 // We did not match any specialization, bail out...
23 static_assert(AlwaysFalse<std::integral_constant<unsigned int,partitions> >::value,
24 "There is no partition iterator for this combination of entity partitions");
25 };
26
27
28 // specializations of derive_partition_iterator_type for existing PartitionIteratorTypes
29
30 template<>
31 struct derive_partition_iterator_type<
32 (1 << InteriorEntity)
33 >
34 : public std::integral_constant<PartitionIteratorType,Interior_Partition>
35 {};
36
37 template<>
38 struct derive_partition_iterator_type<
39 (1 << InteriorEntity) |
40 (1 << BorderEntity)
41 >
42 : public std::integral_constant<PartitionIteratorType,InteriorBorder_Partition>
43 {};
44
45 template<>
46 struct derive_partition_iterator_type<
47 (1 << InteriorEntity) |
48 (1 << BorderEntity) |
49 (1 << OverlapEntity)
50 >
51 : public std::integral_constant<PartitionIteratorType,Overlap_Partition>
52 {};
53
54 template<>
55 struct derive_partition_iterator_type<
56 (1 << InteriorEntity) |
57 (1 << BorderEntity) |
58 (1 << OverlapEntity) |
59 (1 << FrontEntity)
60 >
61 : public std::integral_constant<PartitionIteratorType,OverlapFront_Partition>
62 {};
63
64 template<>
65 struct derive_partition_iterator_type<
66 (1 << InteriorEntity) |
67 (1 << BorderEntity) |
68 (1 << OverlapEntity) |
69 (1 << FrontEntity) |
70 (1 << GhostEntity)
71 >
72 : public std::integral_constant<PartitionIteratorType,All_Partition>
73 {};
74
75 template<>
76 struct derive_partition_iterator_type<
77 (1 << GhostEntity)
78 >
79 : public std::integral_constant<PartitionIteratorType,Ghost_Partition>
80 {};
81
82 } // anonymous namespace
83
84
86
94 template<unsigned int partitions>
96 {
98 static const unsigned int value = partitions;
99
100
102 template<unsigned int p>
103 struct PartitionSet<partitions | p>
104 operator+(const PartitionSet<p>& set) const
105 {
107 }
108
110 template<unsigned int p>
111 struct PartitionSet<partitions & ~p>
112 operator-(const PartitionSet<p>& set) const
113 {
115 }
116
118 friend std::ostream& operator<<(std::ostream& os, const PartitionSet&)
119 {
120 unsigned int set = partitions;
121 os << "partition set {";
122 bool first = true;
123 for (unsigned int p = 0; set; set &= ~(1 << p++))
124 {
125 if (!(set & (1 << p)))
126 continue;
127 if (!first)
128 os << ",";
129 first = false;
130 os << static_cast<PartitionType>(p);
131 }
132 os << "}";
133 return os;
134 }
135
137
142 {
143 return derive_partition_iterator_type<partitions>::value;
144 }
145
147 static constexpr bool contains(PartitionType pt)
148 {
149 return partitions & (1 << pt);
150 }
151
153 template<unsigned int contained_partitions>
155 {
156 return (partitions & contained_partitions) == contained_partitions;
157 }
158
160 template<unsigned int p2>
161 constexpr bool operator==(PartitionSet<p2>) const
162 {
163 return partitions == p2;
164 }
165
167 template<unsigned int p2>
168 constexpr bool operator!=(PartitionSet<p2>) const
169 {
170 return partitions != p2;
171 }
172
173 };
174
176
179 template<PartitionType p>
181 {
182 return PartitionSet<(1 << p)>();
183 }
184
186 namespace Partitions {
187
188
189#ifdef DOXYGEN
190
192 typedef PartitionSet<...> Interior;
193
195 typedef PartitionSet<...> Border;
196
198 typedef PartitionSet<...> Overlap;
199
201 typedef PartitionSet<...> Front;
202
204 typedef PartitionSet<...> Ghost;
205
208
211
214
216 typedef PartitionSet<...> All;
217
218
221
224
227
230
233
236
239
242
245
246#else // DOXYGEN
247
248 // First declare the types and objects for individual partitions
249
250 typedef decltype(partitionSet<InteriorEntity>()) Interior;
251 typedef decltype(partitionSet<BorderEntity>()) Border;
252 typedef decltype(partitionSet<OverlapEntity>()) Overlap;
253 typedef decltype(partitionSet<FrontEntity>()) Front;
254 typedef decltype(partitionSet<GhostEntity>()) Ghost;
255
256 namespace {
257
258 // place global objects in anonymous namespace to ensure that visibility is
259 // restricted to the current translation unit, making it easier for the compiler
260 // to eliminate the actual objects and to avoid linking problems
261
262 const Interior interior = {};
263 const Border border = {};
264 const Overlap overlap = {};
265 const Front front = {};
266 const Ghost ghost = {};
267
268 }
269
270 // Now we can declare the partition sets that are a result of combining partitions
271
272 typedef decltype(interior + border) InteriorBorder;
273 typedef decltype(interior + border + overlap) InteriorBorderOverlap;
275 typedef decltype(interior + border + overlap + front + ghost) All;
276
277 namespace {
278
279 // again, place the global objects in an anonymous namespace
280
284 const All all = {};
285
286 }
287
288#endif // DOXYGEN
289
290 } // namespace Partitions
291
296} // namespace Dune
297
298#endif // DUNE_GRID_COMMON_PARTITIONSET_HH
PartitionIteratorType
Parameter to be used for the parallel level- and leaf iterators.
Definition: gridenums.hh:134
PartitionType
Attributes used in the generic overlap model.
Definition: gridenums.hh:28
PartitionSet<(1<< p)> partitionSet()
Creates a PartitionSet for the given PartitionType.
Definition: partitionset.hh:180
@ FrontEntity
on boundary between overlap and ghost
Definition: gridenums.hh:32
@ InteriorEntity
all interior entities
Definition: gridenums.hh:29
@ GhostEntity
ghost entities
Definition: gridenums.hh:33
@ BorderEntity
on boundary between interior and overlap
Definition: gridenums.hh:30
@ OverlapEntity
all entities lying in the overlap zone
Definition: gridenums.hh:31
PartitionSet<... > All
Type of PartitionSet for all partitions.
Definition: partitionset.hh:216
Interior interior
PartitionSet for the interior partition.
Definition: partitionset.hh:220
PartitionSet<... > InteriorBorder
Type of PartitionSet for the interior and border partitions.
Definition: partitionset.hh:207
Overlap overlap
PartitionSet for the overlap partition.
Definition: partitionset.hh:226
PartitionSet<... > Border
Type of PartitionSet for the border partition.
Definition: partitionset.hh:195
All all
PartitionSet for all partitions.
Definition: partitionset.hh:244
PartitionSet<... > Front
Type of PartitionSet for the front partition.
Definition: partitionset.hh:201
InteriorBorder interiorBorder
PartitionSet for the interior and border partitions.
Definition: partitionset.hh:235
PartitionSet<... > Overlap
Type of PartitionSet for the overlap partition.
Definition: partitionset.hh:198
Front front
PartitionSet for the front partition.
Definition: partitionset.hh:229
PartitionSet<... > Interior
Type of PartitionSet for the interior partition.
Definition: partitionset.hh:192
InteriorBorderOverlapFront interiorBorderOverlapFront
PartitionSet for the interior, border, overlap and front partitions.
Definition: partitionset.hh:241
Border border
PartitionSet for the border partition.
Definition: partitionset.hh:223
Ghost ghost
PartitionSet for the ghost partition.
Definition: partitionset.hh:232
InteriorBorderOverlap interiorBorderOverlap
PartitionSet for the interior, border and overlap partitions.
Definition: partitionset.hh:238
PartitionSet<... > Ghost
Type of PartitionSet for the ghost partition.
Definition: partitionset.hh:204
PartitionSet<... > InteriorBorderOverlap
Type of PartitionSet for the interior, border and overlap partitions.
Definition: partitionset.hh:210
PartitionSet<... > InteriorBorderOverlapFront
Type of PartitionSet for the interior, border, overlap and front partitions.
Definition: partitionset.hh:213
Dune namespace.
Definition: alignment.hh:11
A set of PartitionType values.
Definition: partitionset.hh:96
static constexpr bool contains(PartitionSet< contained_partitions >)
Tests whether the given PartitionSet is contained in this set.
Definition: partitionset.hh:154
constexpr bool operator==(PartitionSet< p2 >) const
Tests whether two PartitionsSet are equal.
Definition: partitionset.hh:161
static constexpr PartitionIteratorType partitionIterator()
Returns the PartitionIteratorType that can be used to iterate over the partitions in the set.
Definition: partitionset.hh:141
constexpr bool operator!=(PartitionSet< p2 >) const
Tests whether two PartitionsSet are not equal.
Definition: partitionset.hh:168
friend std::ostream & operator<<(std::ostream &os, const PartitionSet &)
Writes the PartitionSet to an output stream.
Definition: partitionset.hh:118
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:112
static constexpr bool contains(PartitionType pt)
Tests whether the given PartitionType is contained in this set.
Definition: partitionset.hh:147
Traits for type conversions and type information.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 23, 23:29, 2024)