/usr/include/dune/grid/common/partitionset.hh is in libdune-grid-dev 2.4.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_GRID_COMMON_PARTITIONSET_HH
#define DUNE_GRID_COMMON_PARTITIONSET_HH
#include <dune/common/typetraits.hh>
#include <dune/common/std/constexpr.hh>
#include <dune/grid/common/gridenums.hh>
namespace Dune {
/**
* \addtogroup GIRelatedTypes
* \{
*/
namespace {
// Simple TMP to deduce partition iterator type from set of partitions.
template<unsigned int partitions>
struct derive_partition_iterator_type
{
// We did not match any specialization, bail out...
static_assert(AlwaysFalse<std::integral_constant<unsigned int,partitions> >::value,
"There is no partition iterator for this combination of entity partitions");
};
// specializations of derive_partition_iterator_type for existing PartitionIteratorTypes
template<>
struct derive_partition_iterator_type<
(1 << InteriorEntity)
>
: public std::integral_constant<PartitionIteratorType,Interior_Partition>
{};
template<>
struct derive_partition_iterator_type<
(1 << InteriorEntity) |
(1 << BorderEntity)
>
: public std::integral_constant<PartitionIteratorType,InteriorBorder_Partition>
{};
template<>
struct derive_partition_iterator_type<
(1 << InteriorEntity) |
(1 << BorderEntity) |
(1 << OverlapEntity)
>
: public std::integral_constant<PartitionIteratorType,Overlap_Partition>
{};
template<>
struct derive_partition_iterator_type<
(1 << InteriorEntity) |
(1 << BorderEntity) |
(1 << OverlapEntity) |
(1 << FrontEntity)
>
: public std::integral_constant<PartitionIteratorType,OverlapFront_Partition>
{};
template<>
struct derive_partition_iterator_type<
(1 << InteriorEntity) |
(1 << BorderEntity) |
(1 << OverlapEntity) |
(1 << FrontEntity) |
(1 << GhostEntity)
>
: public std::integral_constant<PartitionIteratorType,All_Partition>
{};
template<>
struct derive_partition_iterator_type<
(1 << GhostEntity)
>
: public std::integral_constant<PartitionIteratorType,Ghost_Partition>
{};
} // anonymous namespace
//! A set of PartitionType values.
/**
* PartitionSet cotains a set of PartitionType values fixed at compile time. The contents
* of the set is encoded in the template parameter partitions, but the exact semantics are
* an implementation detail. PartitionSets can be combined by adding them up. They also support
* removing partitions by subtracting them.
*
* \tparam partitions Implementation-defined representation of the partition set.
*/
template<unsigned int partitions>
struct PartitionSet
{
//! \private The actual representation should not be used outside of the implementation.
static const unsigned int value = partitions;
//! Returns a new PartitionSet that also contains the partitions in set.
template<unsigned int p>
struct PartitionSet<partitions | p>
operator+(const PartitionSet<p>& set) const
{
return PartitionSet<partitions | p>();
}
//! Returns a new PartitionSet that does not contain the partitions in set.
template<unsigned int p>
struct PartitionSet<partitions & ~p>
operator-(const PartitionSet<p>& set) const
{
return PartitionSet<partitions & ~p>();
}
//! Writes the PartitionSet to an output stream.
friend std::ostream& operator<<(std::ostream& os, const PartitionSet&)
{
unsigned int set = partitions;
os << "partition set {";
bool first = true;
for (unsigned int p = 0; set; set &= ~(1 << p++))
{
if (!(set & (1 << p)))
continue;
if (!first)
os << ",";
first = false;
os << static_cast<PartitionType>(p);
}
os << "}";
return os;
}
#if HAVE_CONSTEXPR || DOXYGEN
//! Returns the PartitionIteratorType that can be used to iterate over the partitions in the set.
/**
*
* \throws raises a static assertion if the partitions do not correspond to a valid PartitionIteratorType.
* \since GCC 4.6 (constexpr)
*/
static constexpr PartitionIteratorType partitionIterator()
{
return derive_partition_iterator_type<partitions>::value;
}
#endif // HAVE_CONSTEXPR
//! Tests whether the given PartitionType is contained in this set.
static DUNE_CONSTEXPR bool contains(PartitionType pt)
{
return partitions & (1 << pt);
}
//! Tests whether the given PartitionSet is contained in this set.
template<unsigned int contained_partitions>
static DUNE_CONSTEXPR bool contains(PartitionSet<contained_partitions>)
{
return (partitions & contained_partitions) == contained_partitions;
}
//! Tests whether two PartitionsSet are equal.
template<unsigned int p2>
DUNE_CONSTEXPR bool operator==(PartitionSet<p2>) const
{
return partitions == p2;
}
//! Tests whether two PartitionsSet are not equal.
template<unsigned int p2>
DUNE_CONSTEXPR bool operator!=(PartitionSet<p2>) const
{
return partitions != p2;
}
};
//! Creates a PartitionSet for the given PartitionType.
/**
* \related PartitionSet
*/
template<PartitionType p>
PartitionSet<(1 << p)> partitionSet()
{
return PartitionSet<(1 << p)>();
}
//! Predefined PartitionSets for commonly used combinations of parallel grid PartitionTypes.
namespace Partitions {
#ifdef DOXYGEN
//! Type of PartitionSet for the interior partition.
typedef PartitionSet<...> Interior;
//! Type of PartitionSet for the border partition.
typedef PartitionSet<...> Border;
//! Type of PartitionSet for the overlap partition.
typedef PartitionSet<...> Overlap;
//! Type of PartitionSet for the front partition.
typedef PartitionSet<...> Front;
//! Type of PartitionSet for the ghost partition.
typedef PartitionSet<...> Ghost;
//! Type of PartitionSet for the interior and border partitions.
typedef PartitionSet<...> InteriorBorder;
//! Type of PartitionSet for the interior, border and overlap partitions.
typedef PartitionSet<...> InteriorBorderOverlap;
//! Type of PartitionSet for the interior, border, overlap and front partitions.
typedef PartitionSet<...> InteriorBorderOverlapFront;
//! Type of PartitionSet for all partitions.
typedef PartitionSet<...> All;
//! PartitionSet for the interior partition.
Interior interior;
//! PartitionSet for the border partition.
Border border;
//! PartitionSet for the overlap partition.
Overlap overlap;
//! PartitionSet for the front partition.
Front front;
//! PartitionSet for the ghost partition.
Ghost ghost;
//! PartitionSet for the interior and border partitions.
InteriorBorder interiorBorder;
//! PartitionSet for the interior, border and overlap partitions.
InteriorBorderOverlap interiorBorderOverlap;
//! PartitionSet for the interior, border, overlap and front partitions.
InteriorBorderOverlapFront interiorBorderOverlapFront;
//! PartitionSet for all partitions.
All all;
#else // DOXYGEN
// First declare the types and objects for individual partitions
typedef decltype(partitionSet<InteriorEntity>()) Interior;
typedef decltype(partitionSet<BorderEntity>()) Border;
typedef decltype(partitionSet<OverlapEntity>()) Overlap;
typedef decltype(partitionSet<FrontEntity>()) Front;
typedef decltype(partitionSet<GhostEntity>()) Ghost;
namespace {
// place global objects in anonymous namespace to ensure that visibility is
// restricted to the current translation unit, making it easier for the compiler
// to eliminate the actual objects and to avoid linking problems
const Interior interior = {};
const Border border = {};
const Overlap overlap = {};
const Front front = {};
const Ghost ghost = {};
}
// Now we can declare the partition sets that are a result of combining partitions
typedef decltype(interior + border) InteriorBorder;
typedef decltype(interior + border + overlap) InteriorBorderOverlap;
typedef decltype(interior + border + overlap + front) InteriorBorderOverlapFront;
typedef decltype(interior + border + overlap + front + ghost) All;
namespace {
// again, place the global objects in an anonymous namespace
const InteriorBorder interiorBorder = {};
const InteriorBorderOverlap interiorBorderOverlap = {};
const InteriorBorderOverlapFront interiorBorderOverlapFront = {};
const All all = {};
}
#endif // DOXYGEN
} // namespace Partitions
/**
* \} group Parallel Grid Partitions
*/
} // namespace Dune
#endif // DUNE_GRID_COMMON_PARTITIONSET_HH
|