Dune Core Modules (2.8.0)

dependency.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_AMG_DEPENDENCY_HH
4#define DUNE_AMG_DEPENDENCY_HH
5
6
7#include <bitset>
8#include <ostream>
9
10#include "graph.hh"
11#include "properties.hh"
12#include <dune/common/propertymap.hh>
13
14
15namespace Dune
16{
17 namespace Amg
18 {
37 {
38 friend std::ostream& operator<<(std::ostream& os, const EdgeProperties& props);
39 public:
41 enum {INFLUENCE, DEPEND, SIZE};
42
43 private:
44
45 std::bitset<SIZE> flags_;
46 public:
49
51 std::bitset<SIZE>::reference operator[](std::size_t v);
52
54 bool operator[](std::size_t v) const;
55
61 bool depends() const;
62
67 void setDepends();
68
72 void resetDepends();
73
78 bool influences() const;
79
83 void setInfluences();
84
88 void resetInfluences();
89
94 bool isOneWay() const;
95
100 bool isTwoWay() const;
101
106 bool isStrong() const;
107
111 void reset();
112
116 void printFlags() const;
117 };
118
125 friend std::ostream& operator<<(std::ostream& os, const VertexProperties& props);
126 public:
127 enum { ISOLATED, VISITED, FRONT, BORDER, SIZE };
128 private:
129
131 std::bitset<SIZE> flags_;
132
133 public:
136
138 std::bitset<SIZE>::reference operator[](std::size_t v);
139
141 bool operator[](std::size_t v) const;
142
149 void setIsolated();
150
154 bool isolated() const;
155
159 void resetIsolated();
160
164 void setVisited();
165
169 bool visited() const;
170
174 void resetVisited();
175
179 void setFront();
180
184 bool front() const;
185
189 void resetFront();
190
194 void setExcludedBorder();
195
200 bool excludedBorder() const;
201
205 void resetExcludedBorder();
206
210 void reset();
211
212 };
213
214 template<typename G, std::size_t i>
215 class PropertyGraphVertexPropertyMap
216 : public RAPropertyMapHelper<typename std::bitset<VertexProperties::SIZE>::reference,
217 PropertyGraphVertexPropertyMap<G,i> >
218 {
219 public:
220
221 typedef ReadWritePropertyMapTag Category;
222
223 enum {
225 index = i
226 };
227
231 typedef G Graph;
232
236 typedef std::bitset<VertexProperties::SIZE> BitSet;
237
241 typedef typename BitSet::reference Reference;
242
246 typedef bool ValueType;
247
251 typedef typename G::VertexDescriptor Vertex;
252
258 : graph_(&g)
259 {}
260
265 : graph_(0)
266 {}
267
268
274 {
275 return graph_->getVertexProperties(vertex)[index];
276 }
277 private:
278 Graph* graph_;
279 };
280
281 } // end namespace Amg
282
283 template<typename G, typename EP, typename VM, typename EM>
284 struct PropertyMapTypeSelector<Amg::VertexVisitedTag,Amg::PropertiesGraph<G,Amg::VertexProperties,EP,VM,EM> >
285 {
286 typedef Amg::PropertyGraphVertexPropertyMap<Amg::PropertiesGraph<G,Amg::VertexProperties,EP,VM,EM>, Amg::VertexProperties::VISITED> Type;
287 };
288
289 template<typename G, typename EP, typename VM, typename EM>
290 typename PropertyMapTypeSelector<Amg::VertexVisitedTag,Amg::PropertiesGraph<G,Amg::VertexProperties,EP,VM,EM> >::Type
291 get([[maybe_unused]] const Amg::VertexVisitedTag& tag, Amg::PropertiesGraph<G,Amg::VertexProperties,EP,VM,EM>& graph)
292 {
293 return Amg::PropertyGraphVertexPropertyMap<Amg::PropertiesGraph<G,Amg::VertexProperties,EP,VM,EM>, Amg::VertexProperties::VISITED>(graph);
294 }
295
296 namespace Amg
297 {
298 inline std::ostream& operator<<(std::ostream& os, const EdgeProperties& props)
299 {
300 return os << props.flags_;
301 }
302
304 : flags_()
305 {}
306
307 inline std::bitset<EdgeProperties::SIZE>::reference
309 {
310 return flags_[v];
311 }
312
313 inline bool EdgeProperties::operator[](std::size_t i) const
314 {
315 return flags_[i];
316 }
317
319 {
320 flags_.reset();
321 }
322
324 {
325 // Set the INFLUENCE bit
326 //flags_ |= (1<<INFLUENCE);
327 flags_.set(INFLUENCE);
328 }
329
330 inline bool EdgeProperties::influences() const
331 {
332 // Test the INFLUENCE bit
333 return flags_.test(INFLUENCE);
334 }
335
337 {
338 // Set the first bit.
339 //flags_ |= (1<<DEPEND);
340 flags_.set(DEPEND);
341 }
342
344 {
345 // reset the first bit.
346 //flags_ &= ~(1<<DEPEND);
347 flags_.reset(DEPEND);
348 }
349
350 inline bool EdgeProperties::depends() const
351 {
352 // Return the first bit.
353 return flags_.test(DEPEND);
354 }
355
357 {
358 // reset the second bit.
359 flags_ &= ~(1<<INFLUENCE);
360 }
361
362 inline bool EdgeProperties::isOneWay() const
363 {
364 // Test whether only the first bit is set
365 //return isStrong() && !isTwoWay();
366 return ((flags_) & std::bitset<SIZE>((1<<INFLUENCE)|(1<<DEPEND)))==(1<<DEPEND);
367 }
368
369 inline bool EdgeProperties::isTwoWay() const
370 {
371 // Test whether the first and second bit is set
372 return ((flags_) & std::bitset<SIZE>((1<<INFLUENCE)|(1<<DEPEND)))==((1<<INFLUENCE)|(1<<DEPEND));
373 }
374
375 inline bool EdgeProperties::isStrong() const
376 {
377 // Test whether the first or second bit is set
378 return ((flags_) & std::bitset<SIZE>((1<<INFLUENCE)|(1<<DEPEND))).to_ulong();
379 }
380
381
382 inline std::ostream& operator<<(std::ostream& os, const VertexProperties& props)
383 {
384 return os << props.flags_;
385 }
386
388 : flags_()
389 {}
390
391
392 inline std::bitset<VertexProperties::SIZE>::reference
394 {
395 return flags_[v];
396 }
397
398 inline bool VertexProperties::operator[](std::size_t v) const
399 {
400 return flags_[v];
401 }
402
404 {
405 flags_.set(ISOLATED);
406 }
407
408 inline bool VertexProperties::isolated() const
409 {
410 return flags_.test(ISOLATED);
411 }
412
414 {
415 flags_.reset(ISOLATED);
416 }
417
419 {
420 flags_.set(VISITED);
421 }
422
423 inline bool VertexProperties::visited() const
424 {
425 return flags_.test(VISITED);
426 }
427
429 {
430 flags_.reset(VISITED);
431 }
432
434 {
435 flags_.set(FRONT);
436 }
437
438 inline bool VertexProperties::front() const
439 {
440 return flags_.test(FRONT);
441 }
442
444 {
445 flags_.reset(FRONT);
446 }
447
449 {
450 flags_.set(BORDER);
451 }
452
454 {
455 return flags_.test(BORDER);
456 }
457
459 {
460 flags_.reset(BORDER);
461 }
462
464 {
465 flags_.reset();
466 }
467
469 }
470}
471#endif
Class representing the properties of an ede in the matrix graph.
Definition: dependency.hh:37
Class representing a node in the matrix graph.
Definition: dependency.hh:124
Provides classes for building the matrix graph.
constexpr GeometryType vertex
GeometryType representing a vertex.
Definition: type.hh:504
bool depends() const
Checks wether the vertex the edge points to depends on the vertex the edge starts.
Definition: dependency.hh:350
void resetFront()
Resets the front node flag.
Definition: dependency.hh:443
std::bitset< VertexProperties::SIZE > BitSet
The type of the bitset.
Definition: dependency.hh:236
bool isolated() const
Checks wether the node is isolated.
Definition: dependency.hh:408
bool ValueType
The value type.
Definition: dependency.hh:246
BitSet::reference Reference
The reference type.
Definition: dependency.hh:241
bool isTwoWay() const
Checks wether the edge is two way. I.e. both the influence flag and the depends flag are that.
Definition: dependency.hh:369
void setInfluences()
Marks the edge as one of which the start vertex by the end vertex.
Definition: dependency.hh:323
VertexProperties()
Constructor.
Definition: dependency.hh:387
void setDepends()
Marks the edge as one of which the end point depends on the starting point.
Definition: dependency.hh:336
PropertyGraphVertexPropertyMap()
Default constructor.
Definition: dependency.hh:264
PropertyGraphVertexPropertyMap(G &g)
Constructor.
Definition: dependency.hh:257
G::VertexDescriptor Vertex
The vertex descriptor.
Definition: dependency.hh:251
void resetExcludedBorder()
Marks the vertex as included in the aggregation.
Definition: dependency.hh:458
void setFront()
Marks the node as belonging to the current clusters front.
Definition: dependency.hh:433
void reset()
Reset all flags.
Definition: dependency.hh:463
void setVisited()
Mark the node as already visited.
Definition: dependency.hh:418
EdgeProperties()
Constructor.
Definition: dependency.hh:303
void resetInfluences()
Resets the influence flag.
Definition: dependency.hh:356
G Graph
The type of the graph with internal properties.
Definition: dependency.hh:231
std::bitset< SIZE >::reference operator[](std::size_t v)
Access the bits directly.
Definition: dependency.hh:393
void printFlags() const
Prints the attributes of the edge for debugging.
bool influences() const
Checks wether the start vertex is influenced by the end vertex.
Definition: dependency.hh:330
void setIsolated()
Marks that node as being isolated.
Definition: dependency.hh:403
bool excludedBorder() const
Tests whether the vertex is excluded from the aggregation.
Definition: dependency.hh:453
void resetVisited()
Resets the visited flag.
Definition: dependency.hh:428
bool visited() const
Checks wether the node is marked as visited.
Definition: dependency.hh:423
Reference operator[](const Vertex &vertex) const
Get the properties associated to a vertex.
Definition: dependency.hh:273
void reset()
Reset all flags.
Definition: dependency.hh:318
void resetDepends()
Resets the depends flag.
Definition: dependency.hh:343
void resetIsolated()
Resets the isolated flag.
Definition: dependency.hh:413
bool isStrong() const
Checks wether the edge is strong. I.e. the influence or depends flag is set.
Definition: dependency.hh:375
bool front() const
Checks wether the node is marked as a front node.
Definition: dependency.hh:438
std::bitset< SIZE >::reference operator[](std::size_t v)
Access the bits directly.
Definition: dependency.hh:308
void setExcludedBorder()
Marks the vertex as excluded from the aggregation.
Definition: dependency.hh:448
bool isOneWay() const
Checks wether the edge is one way. I.e. either the influence or the depends flag but is set.
Definition: dependency.hh:362
Dune namespace.
Definition: alignedallocator.hh:11
Provides classes for handling internal properties in a graph.
Tag for the category of readable and writable property maps.
Definition: propertymap.hh:48
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)