Dune Core Modules (2.4.2)

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
8#include <dune/grid/common/gridenums.hh>
9
10namespace 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>
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
154 {
155 return partitions & (1 << pt);
156 }
157
159 template<unsigned int contained_partitions>
161 {
162 return (partitions & contained_partitions) == contained_partitions;
163 }
164
166 template<unsigned int p2>
168 {
169 return partitions == p2;
170 }
171
173 template<unsigned int p2>
175 {
176 return partitions != p2;
177 }
178
179 };
180
182
185 template<PartitionType p>
187 {
188 return PartitionSet<(1 << p)>();
189 }
190
192 namespace Partitions {
193
194
195#ifdef DOXYGEN
196
198 typedef PartitionSet<...> Interior;
199
201 typedef PartitionSet<...> Border;
202
204 typedef PartitionSet<...> Overlap;
205
207 typedef PartitionSet<...> Front;
208
210 typedef PartitionSet<...> Ghost;
211
214
217
220
222 typedef PartitionSet<...> All;
223
224
227
230
233
236
239
242
245
248
251
252#else // DOXYGEN
253
254 // First declare the types and objects for individual partitions
255
256 typedef decltype(partitionSet<InteriorEntity>()) Interior;
257 typedef decltype(partitionSet<BorderEntity>()) Border;
258 typedef decltype(partitionSet<OverlapEntity>()) Overlap;
259 typedef decltype(partitionSet<FrontEntity>()) Front;
260 typedef decltype(partitionSet<GhostEntity>()) Ghost;
261
262 namespace {
263
264 // place global objects in anonymous namespace to ensure that visibility is
265 // restricted to the current translation unit, making it easier for the compiler
266 // to eliminate the actual objects and to avoid linking problems
267
268 const Interior interior = {};
269 const Border border = {};
270 const Overlap overlap = {};
271 const Front front = {};
272 const Ghost ghost = {};
273
274 }
275
276 // Now we can declare the partition sets that are a result of combining partitions
277
278 typedef decltype(interior + border) InteriorBorder;
279 typedef decltype(interior + border + overlap) InteriorBorderOverlap;
281 typedef decltype(interior + border + overlap + front + ghost) All;
282
283 namespace {
284
285 // again, place the global objects in an anonymous namespace
286
290 const All all = {};
291
292 }
293
294#endif // DOXYGEN
295
296 } // namespace Partitions
297
302} // namespace Dune
303
304#endif // DUNE_GRID_COMMON_PARTITIONSET_HH
Definition of the DUNE_CONSTEXPR macro.
#define DUNE_CONSTEXPR
Set method or expression constexpr if supported by the compiler.
Definition: constexpr.hh:21
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:186
@ 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:222
Interior interior
PartitionSet for the interior partition.
Definition: partitionset.hh:226
PartitionSet<... > InteriorBorder
Type of PartitionSet for the interior and border partitions.
Definition: partitionset.hh:213
Overlap overlap
PartitionSet for the overlap partition.
Definition: partitionset.hh:232
PartitionSet<... > Border
Type of PartitionSet for the border partition.
Definition: partitionset.hh:201
All all
PartitionSet for all partitions.
Definition: partitionset.hh:250
PartitionSet<... > Front
Type of PartitionSet for the front partition.
Definition: partitionset.hh:207
InteriorBorder interiorBorder
PartitionSet for the interior and border partitions.
Definition: partitionset.hh:241
PartitionSet<... > Overlap
Type of PartitionSet for the overlap partition.
Definition: partitionset.hh:204
Front front
PartitionSet for the front partition.
Definition: partitionset.hh:235
PartitionSet<... > Interior
Type of PartitionSet for the interior partition.
Definition: partitionset.hh:198
InteriorBorderOverlapFront interiorBorderOverlapFront
PartitionSet for the interior, border, overlap and front partitions.
Definition: partitionset.hh:247
Border border
PartitionSet for the border partition.
Definition: partitionset.hh:229
Ghost ghost
PartitionSet for the ghost partition.
Definition: partitionset.hh:238
InteriorBorderOverlap interiorBorderOverlap
PartitionSet for the interior, border and overlap partitions.
Definition: partitionset.hh:244
PartitionSet<... > Ghost
Type of PartitionSet for the ghost partition.
Definition: partitionset.hh:210
PartitionSet<... > InteriorBorderOverlap
Type of PartitionSet for the interior, border and overlap partitions.
Definition: partitionset.hh:216
PartitionSet<... > InteriorBorderOverlapFront
Type of PartitionSet for the interior, border, overlap and front partitions.
Definition: partitionset.hh:219
Dune namespace.
Definition: alignment.hh:10
A set of PartitionType values.
Definition: partitionset.hh:97
static constexpr PartitionIteratorType partitionIterator()
Returns the PartitionIteratorType that can be used to iterate over the partitions in the set.
Definition: partitionset.hh:145
static DUNE_CONSTEXPR bool contains(PartitionType pt)
Tests whether the given PartitionType is contained in this set.
Definition: partitionset.hh:153
friend std::ostream & operator<<(std::ostream &os, const PartitionSet &)
Writes the PartitionSet to an output stream.
Definition: partitionset.hh:119
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
DUNE_CONSTEXPR bool operator!=(PartitionSet< p2 >) const
Tests whether two PartitionsSet are not equal.
Definition: partitionset.hh:174
DUNE_CONSTEXPR bool operator==(PartitionSet< p2 >) const
Tests whether two PartitionsSet are equal.
Definition: partitionset.hh:167
static DUNE_CONSTEXPR bool contains(PartitionSet< contained_partitions >)
Tests whether the given PartitionSet is contained in this set.
Definition: partitionset.hh:160
Traits for type conversions and type information.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 20, 23:31, 2024)