Dune Core Modules (unstable)

dependency.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4// vi: set et ts=4 sw=2 sts=2:
5#ifndef DUNE_AMG_DEPENDENCY_HH
6#define DUNE_AMG_DEPENDENCY_HH
7
8
9#include <bitset>
10#include <ostream>
11
12#include "graph.hh"
13#include "properties.hh"
14#include <dune/common/propertymap.hh>
15
16
17namespace Dune
18{
19 namespace Amg
20 {
39 {
40 friend std::ostream& operator<<(std::ostream& os, const EdgeProperties& props);
41 public:
43 enum {INFLUENCE, DEPEND, SIZE};
44
45 private:
46
47 std::bitset<SIZE> flags_;
48 public:
51
53 std::bitset<SIZE>::reference operator[](std::size_t v);
54
56 bool operator[](std::size_t v) const;
57
63 bool depends() const;
64
69 void setDepends();
70
74 void resetDepends();
75
80 bool influences() const;
81
85 void setInfluences();
86
90 void resetInfluences();
91
96 bool isOneWay() const;
97
102 bool isTwoWay() const;
103
108 bool isStrong() const;
109
113 void reset();
114
118 void printFlags() const;
119 };
120
127 friend std::ostream& operator<<(std::ostream& os, const VertexProperties& props);
128 public:
129 enum { ISOLATED, VISITED, FRONT, BORDER, SIZE };
130 private:
131
133 std::bitset<SIZE> flags_;
134
135 public:
138
140 std::bitset<SIZE>::reference operator[](std::size_t v);
141
143 bool operator[](std::size_t v) const;
144
151 void setIsolated();
152
156 bool isolated() const;
157
161 void resetIsolated();
162
166 void setVisited();
167
171 bool visited() const;
172
176 void resetVisited();
177
181 void setFront();
182
186 bool front() const;
187
191 void resetFront();
192
196 void setExcludedBorder();
197
202 bool excludedBorder() const;
203
207 void resetExcludedBorder();
208
212 void reset();
213
214 };
215
216 template<typename G, std::size_t i>
217 class PropertyGraphVertexPropertyMap
218 : public RAPropertyMapHelper<typename std::bitset<VertexProperties::SIZE>::reference,
219 PropertyGraphVertexPropertyMap<G,i> >
220 {
221 public:
222
223 typedef ReadWritePropertyMapTag Category;
224
225 enum {
227 index = i
228 };
229
233 typedef G Graph;
234
238 typedef std::bitset<VertexProperties::SIZE> BitSet;
239
243 typedef typename BitSet::reference Reference;
244
248 typedef bool ValueType;
249
253 typedef typename G::VertexDescriptor Vertex;
254
260 : graph_(&g)
261 {}
262
267 : graph_(0)
268 {}
269
270
276 {
277 return graph_->getVertexProperties(vertex)[index];
278 }
279 private:
280 Graph* graph_;
281 };
282
283 } // end namespace Amg
284
285 template<typename G, typename EP, typename VM, typename EM>
286 struct PropertyMapTypeSelector<Amg::VertexVisitedTag,Amg::PropertiesGraph<G,Amg::VertexProperties,EP,VM,EM> >
287 {
288 typedef Amg::PropertyGraphVertexPropertyMap<Amg::PropertiesGraph<G,Amg::VertexProperties,EP,VM,EM>, Amg::VertexProperties::VISITED> Type;
289 };
290
291 template<typename G, typename EP, typename VM, typename EM>
292 typename PropertyMapTypeSelector<Amg::VertexVisitedTag,Amg::PropertiesGraph<G,Amg::VertexProperties,EP,VM,EM> >::Type
293 get([[maybe_unused]] const Amg::VertexVisitedTag& tag, Amg::PropertiesGraph<G,Amg::VertexProperties,EP,VM,EM>& graph)
294 {
295 return Amg::PropertyGraphVertexPropertyMap<Amg::PropertiesGraph<G,Amg::VertexProperties,EP,VM,EM>, Amg::VertexProperties::VISITED>(graph);
296 }
297
298 namespace Amg
299 {
300 inline std::ostream& operator<<(std::ostream& os, const EdgeProperties& props)
301 {
302 return os << props.flags_;
303 }
304
306 : flags_()
307 {}
308
309 inline std::bitset<EdgeProperties::SIZE>::reference
311 {
312 return flags_[v];
313 }
314
315 inline bool EdgeProperties::operator[](std::size_t i) const
316 {
317 return flags_[i];
318 }
319
321 {
322 flags_.reset();
323 }
324
326 {
327 // Set the INFLUENCE bit
328 //flags_ |= (1<<INFLUENCE);
329 flags_.set(INFLUENCE);
330 }
331
332 inline bool EdgeProperties::influences() const
333 {
334 // Test the INFLUENCE bit
335 return flags_.test(INFLUENCE);
336 }
337
339 {
340 // Set the first bit.
341 //flags_ |= (1<<DEPEND);
342 flags_.set(DEPEND);
343 }
344
346 {
347 // reset the first bit.
348 //flags_ &= ~(1<<DEPEND);
349 flags_.reset(DEPEND);
350 }
351
352 inline bool EdgeProperties::depends() const
353 {
354 // Return the first bit.
355 return flags_.test(DEPEND);
356 }
357
359 {
360 // reset the second bit.
361 flags_ &= ~(1<<INFLUENCE);
362 }
363
364 inline bool EdgeProperties::isOneWay() const
365 {
366 // Test whether only the first bit is set
367 //return isStrong() && !isTwoWay();
368 return ((flags_) & std::bitset<SIZE>((1<<INFLUENCE)|(1<<DEPEND)))==(1<<DEPEND);
369 }
370
371 inline bool EdgeProperties::isTwoWay() const
372 {
373 // Test whether the first and second bit is set
374 return ((flags_) & std::bitset<SIZE>((1<<INFLUENCE)|(1<<DEPEND)))==((1<<INFLUENCE)|(1<<DEPEND));
375 }
376
377 inline bool EdgeProperties::isStrong() const
378 {
379 // Test whether the first or second bit is set
380 return ((flags_) & std::bitset<SIZE>((1<<INFLUENCE)|(1<<DEPEND))).to_ulong();
381 }
382
383
384 inline std::ostream& operator<<(std::ostream& os, const VertexProperties& props)
385 {
386 return os << props.flags_;
387 }
388
390 : flags_()
391 {}
392
393
394 inline std::bitset<VertexProperties::SIZE>::reference
396 {
397 return flags_[v];
398 }
399
400 inline bool VertexProperties::operator[](std::size_t v) const
401 {
402 return flags_[v];
403 }
404
406 {
407 flags_.set(ISOLATED);
408 }
409
410 inline bool VertexProperties::isolated() const
411 {
412 return flags_.test(ISOLATED);
413 }
414
416 {
417 flags_.reset(ISOLATED);
418 }
419
421 {
422 flags_.set(VISITED);
423 }
424
425 inline bool VertexProperties::visited() const
426 {
427 return flags_.test(VISITED);
428 }
429
431 {
432 flags_.reset(VISITED);
433 }
434
436 {
437 flags_.set(FRONT);
438 }
439
440 inline bool VertexProperties::front() const
441 {
442 return flags_.test(FRONT);
443 }
444
446 {
447 flags_.reset(FRONT);
448 }
449
451 {
452 flags_.set(BORDER);
453 }
454
456 {
457 return flags_.test(BORDER);
458 }
459
461 {
462 flags_.reset(BORDER);
463 }
464
466 {
467 flags_.reset();
468 }
469
471 }
472}
473#endif
Class representing the properties of an edge in the matrix graph.
Definition: dependency.hh:39
Class representing a node in the matrix graph.
Definition: dependency.hh:126
Provides classes for building the matrix graph.
constexpr GeometryType vertex
GeometryType representing a vertex.
Definition: type.hh:492
bool depends() const
Checks whether the vertex the edge points to depends on the vertex the edge starts.
Definition: dependency.hh:352
void resetFront()
Resets the front node flag.
Definition: dependency.hh:445
std::bitset< VertexProperties::SIZE > BitSet
The type of the bitset.
Definition: dependency.hh:238
bool isolated() const
Checks whether the node is isolated.
Definition: dependency.hh:410
bool ValueType
The value type.
Definition: dependency.hh:248
BitSet::reference Reference
The reference type.
Definition: dependency.hh:243
bool isTwoWay() const
Checks whether the edge is two way. I.e. both the influence flag and the depends flag are that.
Definition: dependency.hh:371
void setInfluences()
Marks the edge as one of which the start vertex by the end vertex.
Definition: dependency.hh:325
VertexProperties()
Constructor.
Definition: dependency.hh:389
void setDepends()
Marks the edge as one of which the end point depends on the starting point.
Definition: dependency.hh:338
PropertyGraphVertexPropertyMap()
Default constructor.
Definition: dependency.hh:266
PropertyGraphVertexPropertyMap(G &g)
Constructor.
Definition: dependency.hh:259
G::VertexDescriptor Vertex
The vertex descriptor.
Definition: dependency.hh:253
void resetExcludedBorder()
Marks the vertex as included in the aggregation.
Definition: dependency.hh:460
void setFront()
Marks the node as belonging to the current clusters front.
Definition: dependency.hh:435
void reset()
Reset all flags.
Definition: dependency.hh:465
void setVisited()
Mark the node as already visited.
Definition: dependency.hh:420
EdgeProperties()
Constructor.
Definition: dependency.hh:305
void resetInfluences()
Resets the influence flag.
Definition: dependency.hh:358
G Graph
The type of the graph with internal properties.
Definition: dependency.hh:233
std::bitset< SIZE >::reference operator[](std::size_t v)
Access the bits directly.
Definition: dependency.hh:395
void printFlags() const
Prints the attributes of the edge for debugging.
bool influences() const
Checks whether the start vertex is influenced by the end vertex.
Definition: dependency.hh:332
void setIsolated()
Marks that node as being isolated.
Definition: dependency.hh:405
bool excludedBorder() const
Tests whether the vertex is excluded from the aggregation.
Definition: dependency.hh:455
void resetVisited()
Resets the visited flag.
Definition: dependency.hh:430
bool visited() const
Checks whether the node is marked as visited.
Definition: dependency.hh:425
Reference operator[](const Vertex &vertex) const
Get the properties associated to a vertex.
Definition: dependency.hh:275
void reset()
Reset all flags.
Definition: dependency.hh:320
void resetDepends()
Resets the depends flag.
Definition: dependency.hh:345
void resetIsolated()
Resets the isolated flag.
Definition: dependency.hh:415
bool isStrong() const
Checks whether the edge is strong. I.e. the influence or depends flag is set.
Definition: dependency.hh:377
bool front() const
Checks whether the node is marked as a front node.
Definition: dependency.hh:440
std::bitset< SIZE >::reference operator[](std::size_t v)
Access the bits directly.
Definition: dependency.hh:310
void setExcludedBorder()
Marks the vertex as excluded from the aggregation.
Definition: dependency.hh:450
bool isOneWay() const
Checks whether the edge is one way. I.e. either the influence or the depends flag but is set.
Definition: dependency.hh:364
Dune namespace.
Definition: alignedallocator.hh:13
constexpr auto get(std::integer_sequence< T, II... >, std::integral_constant< std::size_t, pos >={})
Return the entry at position pos of the given sequence.
Definition: integersequence.hh:22
Provides classes for handling internal properties in a graph.
Tag for the category of readable and writable property maps.
Definition: propertymap.hh:50
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 21, 23:30, 2024)