Dune Core Modules (2.4.1)

selection.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_SELECTION_HH
4#define DUNE_SELECTION_HH
5
6#include "indexset.hh"
8
9namespace Dune
10{
25 template<typename TS, typename TG, typename TL, int N>
27 {
28 public:
37 typedef TS AttributeSet;
38
43
44 //typedef typename ParallelIndexSet::const_iterator ParallelIndexSetIterator;
45
46 typedef ConstArrayListIterator<IndexPair<TG,TL>, N, std::allocator<Dune::IndexPair<TG,TL> > > ParallelIndexSetIterator;
53 : iter_(iter), end_(end)
54 {
55 // Step to the first valid entry
56 while(iter_!=end_ && !AttributeSet::contains(iter_->local().attribute()))
57 ++iter_;
58 }
59
60 void operator++()
61 {
62 assert(iter_!=end_);
63 for(++iter_; iter_!=end_; ++iter_)
64 if(AttributeSet::contains(iter_->local().attribute()))
65 break;
66 }
67
68
69 uint32_t operator*() const
70 {
71 return iter_->local().local();
72 }
73
74 bool operator==(const SelectionIterator<TS,TG,TL,N>& other) const
75 {
76 return iter_ == other.iter_;
77 }
78
79 bool operator!=(const SelectionIterator<TS,TG,TL,N>& other) const
80 {
81 return iter_ != other.iter_;
82 }
83
84 private:
85 ParallelIndexSetIterator iter_;
86 const ParallelIndexSetIterator end_;
87 };
88
89
93 template<typename TS, typename TG, typename TL, int N>
95 {
96 public:
105 typedef TS AttributeSet;
106
110 typedef TG GlobalIndex;
111
118 typedef TL LocalIndex;
119
124
129
134
136 : indexSet_()
137 {}
138
139 UncachedSelection(const ParallelIndexSet& indexset)
140 : indexSet_(&indexset)
141 {}
146 void setIndexSet(const ParallelIndexSet& indexset);
147
151 //const ParallelIndexSet& indexSet() const;
152
157 const_iterator begin() const;
158
163 const_iterator end() const;
164
165
166 private:
167 const ParallelIndexSet* indexSet_;
168
169 };
170
174 template<typename TS, typename TG, typename TL, int N>
176 {
177 public:
186 typedef TS AttributeSet;
187
191 typedef TG GlobalIndex;
192
199 typedef TL LocalIndex;
200
205
209 typedef uint32_t* iterator;
210
214 typedef uint32_t* const_iterator;
215
216 Selection()
217 : selected_()
218 {}
219
220 Selection(const ParallelIndexSet& indexset)
221 : selected_(), size_(0), built_(false)
222 {
223 setIndexSet(indexset);
224 }
225
226 ~Selection();
227
232 void setIndexSet(const ParallelIndexSet& indexset);
233
237 void free();
238
242 //IndexSet indexSet() const;
243
248 const_iterator begin() const;
249
254 const_iterator end() const;
255
256
257 private:
258 uint32_t* selected_;
259 size_t size_;
260 bool built_;
261
262 };
263
264 template<typename TS, typename TG, typename TL, int N>
266 {
267 if(built_)
268 free();
269
270 // Count the number of entries the selection has to hold
272 const const_iterator end = indexset.end();
273 int entries = 0;
274
275 for(const_iterator index = indexset.begin(); index != end; ++index)
276 if(AttributeSet::contains(index->local().attribute()))
277 ++entries;
278
279 selected_ = new uint32_t[entries];
280 built_ = true;
281
282 entries = 0;
283 for(const_iterator index = indexset.begin(); index != end; ++index)
284 if(AttributeSet::contains(index->local().attribute()))
285 selected_[entries++]= index->local().local();
286
287 size_=entries;
288 built_=true;
289 }
290
291 template<typename TS, typename TG, typename TL, int N>
293 {
294 return selected_;
295 }
296
297 template<typename TS, typename TG, typename TL, int N>
299 {
300 return selected_+size_;
301 }
302
303 template<typename TS, typename TG, typename TL, int N>
305 {
306 delete[] selected_;
307 size_=0;
308 built_=false;
309 }
310
311 template<typename TS, typename TG, typename TL, int N>
313 {
314 if(built_)
315 free();
316 }
317
318 template<typename TS, typename TG, typename TL, int N>
320 {
321 return SelectionIterator<TS,TG,TL,N>(indexSet_->begin(),
322 indexSet_->end());
323 }
324
325 template<typename TS, typename TG, typename TL, int N>
327 {
328 return SelectionIterator<TS,TG,TL,N>(indexSet_->end(),
329 indexSet_->end());
330 }
331 template<typename TS, typename TG, typename TL, int N>
333 {
334 indexSet_ = &indexset;
335 }
336
340}
341#endif
A constant random access iterator for the Dune::ArrayList class.
Definition: arraylist.hh:379
A const iterator over an uncached selection.
Definition: selection.hh:27
TS AttributeSet
The type of the Set of attributes.
Definition: selection.hh:37
Dune::ParallelIndexSet< TG, TL, N > ParallelIndexSet
The type of the underlying index set.
Definition: selection.hh:42
SelectionIterator(const ParallelIndexSetIterator &iter, const ParallelIndexSetIterator &end)
Constructor.
Definition: selection.hh:52
A cached selection of indices.
Definition: selection.hh:176
TG GlobalIndex
The type of the global index of the underlying index set.
Definition: selection.hh:191
TL LocalIndex
The type of the local index of the underlying index set.
Definition: selection.hh:199
TS AttributeSet
The type of the set of attributes.
Definition: selection.hh:186
uint32_t * iterator
The type of the iterator of the selected indices.
Definition: selection.hh:209
uint32_t * const_iterator
The type of the iterator of the selected indices.
Definition: selection.hh:214
Dune::ParallelIndexSet< GlobalIndex, LocalIndex, N > ParallelIndexSet
The type of the underlying index set.
Definition: selection.hh:204
An uncached selection of indices.
Definition: selection.hh:95
SelectionIterator< TS, TG, TL, N > iterator
The type of the iterator of the selected indices.
Definition: selection.hh:128
TS AttributeSet
The type of the Set of attributes.
Definition: selection.hh:105
iterator const_iterator
The type of the iterator of the selected indices.
Definition: selection.hh:133
TG GlobalIndex
The type of the global index of the underlying index set.
Definition: selection.hh:110
Dune::ParallelIndexSet< GlobalIndex, LocalIndex, N > ParallelIndexSet
The type of the underlying index set.
Definition: selection.hh:123
TL LocalIndex
The type of the local index of the underlying index set.
Definition: selection.hh:118
const_iterator end() const
Get an iterator over the selected indices.
Definition: selection.hh:326
void setIndexSet(const ParallelIndexSet &indexset)
Set the index set of the selection.
Definition: selection.hh:265
void setIndexSet(const ParallelIndexSet &indexset)
Set the index set of the selection.
Definition: selection.hh:332
iterator begin()
Get an iterator over the indices positioned at the first index.
iterator end()
Get an iterator over the indices positioned after the last index.
const_iterator end() const
Get an iterator over the selected indices.
Definition: selection.hh:298
const_iterator begin() const
Get the index set we are a selection for.
Definition: selection.hh:292
void free()
Free allocated memory.
Definition: selection.hh:304
const_iterator begin() const
Get the index set we are a selection for.
Definition: selection.hh:319
Provides a map between global and local indices.
This file implements iterator facade classes for writing stl conformant iterators.
Dune namespace.
Definition: alignment.hh:10
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 22, 23:30, 2024)