Loading [MathJax]/extensions/tex2jax.js

DUNE MultiDomainGrid (2.10)

singlevalueset.hh
1#ifndef DUNE_MULTIDOMAINGRID_SINGLEVALUESET_HH
2#define DUNE_MULTIDOMAINGRID_SINGLEVALUESET_HH
3
4#include <limits>
5#include <cstddef>
6#include <cstdint>
7#include <dune/common/typetraits.hh>
8#include <dune/common/exceptions.hh>
9#include <type_traits>
10#include <cassert>
11#include <strings.h>
12
13namespace Dune {
14
15namespace mdgrid {
16
17template<typename SI>
18class SingleValueSet;
19
20
21template<typename SI>
22bool setContains(const SingleValueSet<SI>& a,
23 const SingleValueSet<SI>& b);
24
25
26template<typename SI>
27void setAdd(SingleValueSet<SI>& a,
28 const SingleValueSet<SI>& b);
29
30
31template<typename SI>
32class SingleValueSet {
33
34 friend bool setContains<>(const SingleValueSet<SI>& a,
35 const SingleValueSet<SI>& b);
36
37 friend void setAdd<>(SingleValueSet<SI>& a,
38 const SingleValueSet<SI>& b);
39
40public:
41
42 typedef SI SubDomainIndex;
43
44 static const std::size_t maxSize = 1;
45 static const SubDomainIndex emptyTag = ~SubDomainIndex(0);
46 typedef const SubDomainIndex* Iterator;
47 typedef SingleValueSet<SubDomainIndex> This;
48
49 enum SetState {emptySet,simpleSet,multipleSet};
50
51 struct DataHandle
52 {
53 typedef SubDomainIndex DataType;
54
55 static bool fixedSize(int dim, int codim)
56 {
57 return true;
58 }
59
60 static std::size_t size(const SingleValueSet& sds)
61 {
62 return 1;
63 }
64
65 template<typename MessageBufferImp>
66 static void gather(MessageBufferImp& buf, const SingleValueSet& sds)
67 {
68 buf.write(sds._set);
69 }
70
71 template<typename MessageBufferImp>
72 static void scatter(MessageBufferImp& buf, SingleValueSet& sds, std::size_t n)
73 {
74 SubDomainIndex i;
75 buf.read(i);
76 assert(sds._set == emptyTag || sds._set == i);
77 sds._set = i;
78 }
79
80 };
81
82 Iterator begin() const {
83 return &_set;
84 }
85
86 Iterator end() const {
87 return &_set + (_set != emptyTag ? 1 : 0);
88 }
89
90 bool contains(SubDomainIndex domain) const {
91 return _set == domain;
92 }
93
94 template<typename Set>
95 bool containsAll(const Set& set) const {
96 return setContains(*this,set);
97 }
98
99 bool simple() const {
100 return _set != emptyTag;
101 }
102
103 bool empty() const {
104 return _set == emptyTag;
105 }
106
107 SetState state() const {
108 return _set == emptyTag ? emptySet : simpleSet;
109 }
110
111 std::size_t size() const {
112 return _set == emptyTag ? 0 : 1;
113 }
114
115 void clear() {
116 _set = emptyTag;
117 }
118
119 void add(SubDomainIndex domain) {
120 assert(_set == emptyTag || _set == domain);
121 _set = domain;
122 }
123
124 void remove(SubDomainIndex domain) {
125 assert(_set == domain);
126 _set = emptyTag;
127 }
128
129 void set(SubDomainIndex domain) {
130 _set = domain;
131 }
132
133 template<typename Set>
134 void addAll(const Set& set) {
135 setAdd(*this,set);
136 }
137
138 int domainOffset(SubDomainIndex domain) const {
139 assert(_set == domain);
140 return 0;
141 }
142
143 SingleValueSet() :
144 _set(emptyTag)
145 {}
146
147private:
148 SubDomainIndex _set;
149
150};
151
152
153template<typename SI>
154inline bool setContains(const SingleValueSet<SI>& a,
155 const SingleValueSet<SI>& b) {
156 return a._set == b._set;
157}
158
159template<typename SI>
160inline void setAdd(SingleValueSet<SI>& a,
161 const SingleValueSet<SI>& b) {
162 assert(a._set == SingleValueSet<SI>::emptyTag || a._set == b._set);
163 a._set = b._set;
164}
165
166} // namespace mdgrid
167
168} // namespace Dune
169
170#endif // DUNE_MULTIDOMAINGRID_SINGLEVALUESET_HH
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Apr 3, 22:46, 2025)