Dune Core Modules (2.3.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// $Id$
4#ifndef DUNE_SELECTION_HH
5#define DUNE_SELECTION_HH
6
7#include "indexset.hh"
9
10namespace Dune
11{
26 template<typename TS, typename TG, typename TL, int N>
28 {
29 public:
38 typedef TS AttributeSet;
39
44
45 //typedef typename ParallelIndexSet::const_iterator ParallelIndexSetIterator;
46
47 typedef ConstArrayListIterator<IndexPair<TG,TL>, N, std::allocator<Dune::IndexPair<TG,TL> > > ParallelIndexSetIterator;
54 : iter_(iter), end_(end)
55 {
56 // Step to the first valid entry
57 while(iter_!=end_ && !AttributeSet::contains(iter_->local().attribute()))
58 ++iter_;
59 }
60
61 void operator++()
62 {
63 assert(iter_!=end_);
64 for(++iter_; iter_!=end_; ++iter_)
65 if(AttributeSet::contains(iter_->local().attribute()))
66 break;
67 }
68
69
70 uint32_t operator*() const
71 {
72 return iter_->local().local();
73 }
74
75 bool operator==(const SelectionIterator<TS,TG,TL,N>& other) const
76 {
77 return iter_ == other.iter_;
78 }
79
80 bool operator!=(const SelectionIterator<TS,TG,TL,N>& other) const
81 {
82 return iter_ != other.iter_;
83 }
84
85 private:
86 ParallelIndexSetIterator iter_;
87 const ParallelIndexSetIterator end_;
88 };
89
90
94 template<typename TS, typename TG, typename TL, int N>
96 {
97 public:
106 typedef TS AttributeSet;
107
111 typedef TG GlobalIndex;
112
119 typedef TL LocalIndex;
120
125
130
135
137 : indexSet_()
138 {}
139
140 UncachedSelection(const ParallelIndexSet& indexset)
141 : indexSet_(&indexset)
142 {}
147 void setIndexSet(const ParallelIndexSet& indexset);
148
152 //const ParallelIndexSet& indexSet() const;
153
158 const_iterator begin() const;
159
164 const_iterator end() const;
165
166
167 private:
168 const ParallelIndexSet* indexSet_;
169
170 };
171
175 template<typename TS, typename TG, typename TL, int N>
177 {
178 public:
187 typedef TS AttributeSet;
188
192 typedef TG GlobalIndex;
193
200 typedef TL LocalIndex;
201
206
210 typedef uint32_t* iterator;
211
215 typedef uint32_t* const_iterator;
216
217 Selection()
218 : selected_()
219 {}
220
221 Selection(const ParallelIndexSet& indexset)
222 : selected_(), size_(0), built_(false)
223 {
224 setIndexSet(indexset);
225 }
226
227 ~Selection();
228
233 void setIndexSet(const ParallelIndexSet& indexset);
234
238 void free();
239
243 //IndexSet indexSet() const;
244
249 const_iterator begin() const;
250
255 const_iterator end() const;
256
257
258 private:
259 uint32_t* selected_;
260 size_t size_;
261 bool built_;
262
263 };
264
265 template<typename TS, typename TG, typename TL, int N>
267 {
268 if(built_)
269 free();
270
271 // Count the number of entries the selection has to hold
273 const const_iterator end = indexset.end();
274 int entries = 0;
275
276 for(const_iterator index = indexset.begin(); index != end; ++index)
277 if(AttributeSet::contains(index->local().attribute()))
278 ++entries;
279
280 selected_ = new uint32_t[entries];
281 built_ = true;
282
283 entries = 0;
284 for(const_iterator index = indexset.begin(); index != end; ++index)
285 if(AttributeSet::contains(index->local().attribute()))
286 selected_[entries++]= index->local().local();
287
288 size_=entries;
289 built_=true;
290 }
291
292 template<typename TS, typename TG, typename TL, int N>
294 {
295 return selected_;
296 }
297
298 template<typename TS, typename TG, typename TL, int N>
300 {
301 return selected_+size_;
302 }
303
304 template<typename TS, typename TG, typename TL, int N>
306 {
307 delete[] selected_;
308 size_=0;
309 built_=false;
310 }
311
312 template<typename TS, typename TG, typename TL, int N>
314 {
315 if(built_)
316 free();
317 }
318
319 template<typename TS, typename TG, typename TL, int N>
321 {
322 return SelectionIterator<TS,TG,TL,N>(indexSet_->begin(),
323 indexSet_->end());
324 }
325
326 template<typename TS, typename TG, typename TL, int N>
328 {
329 return SelectionIterator<TS,TG,TL,N>(indexSet_->end(),
330 indexSet_->end());
331 }
332 template<typename TS, typename TG, typename TL, int N>
334 {
335 indexSet_ = &indexset;
336 }
337
341}
342#endif
A constant random access iterator for the Dune::ArrayList class.
Definition: arraylist.hh:380
A const iterator over an uncached selection.
Definition: selection.hh:28
TS AttributeSet
The type of the Set of attributes.
Definition: selection.hh:38
Dune::ParallelIndexSet< TG, TL, N > ParallelIndexSet
The type of the underlying index set.
Definition: selection.hh:43
SelectionIterator(const ParallelIndexSetIterator &iter, const ParallelIndexSetIterator &end)
Constructor.
Definition: selection.hh:53
A cached selection of indices.
Definition: selection.hh:177
TG GlobalIndex
The type of the global index of the underlying index set.
Definition: selection.hh:192
TL LocalIndex
The type of the local index of the underlying index set.
Definition: selection.hh:200
TS AttributeSet
The type of the set of attributes.
Definition: selection.hh:187
uint32_t * iterator
The type of the iterator of the selected indices.
Definition: selection.hh:210
uint32_t * const_iterator
The type of the iterator of the selected indices.
Definition: selection.hh:215
Dune::ParallelIndexSet< GlobalIndex, LocalIndex, N > ParallelIndexSet
The type of the underlying index set.
Definition: selection.hh:205
An uncached selection of indices.
Definition: selection.hh:96
SelectionIterator< TS, TG, TL, N > iterator
The type of the iterator of the selected indices.
Definition: selection.hh:129
TS AttributeSet
The type of the Set of attributes.
Definition: selection.hh:106
iterator const_iterator
The type of the iterator of the selected indices.
Definition: selection.hh:134
TG GlobalIndex
The type of the global index of the underlying index set.
Definition: selection.hh:111
Dune::ParallelIndexSet< GlobalIndex, LocalIndex, N > ParallelIndexSet
The type of the underlying index set.
Definition: selection.hh:124
TL LocalIndex
The type of the local index of the underlying index set.
Definition: selection.hh:119
const_iterator end() const
Get an iterator over the selected indices.
Definition: selection.hh:327
void setIndexSet(const ParallelIndexSet &indexset)
Set the index set of the selection.
Definition: selection.hh:266
void setIndexSet(const ParallelIndexSet &indexset)
Set the index set of the selection.
Definition: selection.hh:333
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:299
const_iterator begin() const
Get the index set we are a selection for.
Definition: selection.hh:293
void free()
Free allocated memory.
Definition: selection.hh:305
const_iterator begin() const
Get the index set we are a selection for.
Definition: selection.hh:320
Provides a map between global and local indices.
This file implements iterator facade classes for writing stl conformant iterators.
Dune namespace.
Definition: alignment.hh:14
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)