Dune Core Modules (unstable)

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// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
4// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
5#ifndef DUNE_COMMON_PARALLEL_SELECTION_HH
6#define DUNE_COMMON_PARALLEL_SELECTION_HH
7
8#include <cstdint>
9
12
13namespace Dune
14{
29 template<typename TS, typename TG, typename TL, int N>
31 {
32 public:
41 typedef TS AttributeSet;
42
47
48 //typedef typename ParallelIndexSet::const_iterator ParallelIndexSetIterator;
49
50 typedef ConstArrayListIterator<IndexPair<TG,TL>, N, std::allocator<Dune::IndexPair<TG,TL> > > ParallelIndexSetIterator;
57 : iter_(iter), end_(end)
58 {
59 // Step to the first valid entry
60 while(iter_!=end_ && !AttributeSet::contains(iter_->local().attribute()))
61 ++iter_;
62 }
63
64 void operator++()
65 {
66 assert(iter_!=end_);
67 for(++iter_; iter_!=end_; ++iter_)
68 if(AttributeSet::contains(iter_->local().attribute()))
69 break;
70 }
71
72
73 uint32_t operator*() const
74 {
75 return iter_->local().local();
76 }
77
78 bool operator==(const SelectionIterator<TS,TG,TL,N>& other) const
79 {
80 return iter_ == other.iter_;
81 }
82
83 bool operator!=(const SelectionIterator<TS,TG,TL,N>& other) const
84 {
85 return iter_ != other.iter_;
86 }
87
88 private:
89 ParallelIndexSetIterator iter_;
90 const ParallelIndexSetIterator end_;
91 };
92
93
97 template<typename TS, typename TG, typename TL, int N>
99 {
100 public:
109 typedef TS AttributeSet;
110
114 typedef TG GlobalIndex;
115
122 typedef TL LocalIndex;
123
128
133
138
140 : indexSet_()
141 {}
142
143 UncachedSelection(const ParallelIndexSet& indexset)
144 : indexSet_(&indexset)
145 {}
150 void setIndexSet(const ParallelIndexSet& indexset);
151
155 //const ParallelIndexSet& indexSet() const;
156
161 const_iterator begin() const;
162
167 const_iterator end() const;
168
169
170 private:
171 const ParallelIndexSet* indexSet_;
172
173 };
174
178 template<typename TS, typename TG, typename TL, int N>
180 {
181 public:
190 typedef TS AttributeSet;
191
195 typedef TG GlobalIndex;
196
203 typedef TL LocalIndex;
204
209
213 typedef uint32_t* iterator;
214
218 typedef uint32_t* const_iterator;
219
220 Selection()
221 : selected_()
222 {}
223
224 Selection(const ParallelIndexSet& indexset)
225 : selected_(), size_(0), built_(false)
226 {
227 setIndexSet(indexset);
228 }
229
230 ~Selection();
231
236 void setIndexSet(const ParallelIndexSet& indexset);
237
241 void free();
242
246 //IndexSet indexSet() const;
247
252 const_iterator begin() const;
253
258 const_iterator end() const;
259
260
261 private:
262 uint32_t* selected_;
263 size_t size_;
264 bool built_;
265
266 };
267
268 template<typename TS, typename TG, typename TL, int N>
270 {
271 if(built_)
272 free();
273
274 // Count the number of entries the selection has to hold
276 const const_iterator end = indexset.end();
277 int entries = 0;
278
279 for(const_iterator index = indexset.begin(); index != end; ++index)
280 if(AttributeSet::contains(index->local().attribute()))
281 ++entries;
282
283 selected_ = new uint32_t[entries];
284 built_ = true;
285
286 entries = 0;
287 for(const_iterator index = indexset.begin(); index != end; ++index)
288 if(AttributeSet::contains(index->local().attribute()))
289 selected_[entries++]= index->local().local();
290
291 size_=entries;
292 built_=true;
293 }
294
295 template<typename TS, typename TG, typename TL, int N>
297 {
298 return selected_;
299 }
300
301 template<typename TS, typename TG, typename TL, int N>
303 {
304 return selected_+size_;
305 }
306
307 template<typename TS, typename TG, typename TL, int N>
309 {
310 delete[] selected_;
311 size_=0;
312 built_=false;
313 }
314
315 template<typename TS, typename TG, typename TL, int N>
317 {
318 if(built_)
319 free();
320 }
321
322 template<typename TS, typename TG, typename TL, int N>
324 {
325 return SelectionIterator<TS,TG,TL,N>(indexSet_->begin(),
326 indexSet_->end());
327 }
328
329 template<typename TS, typename TG, typename TL, int N>
331 {
332 return SelectionIterator<TS,TG,TL,N>(indexSet_->end(),
333 indexSet_->end());
334 }
335 template<typename TS, typename TG, typename TL, int N>
337 {
338 indexSet_ = &indexset;
339 }
340
344}
345#endif // DUNE_COMMON_PARALLEL_SELECTION_HH
A constant random access iterator for the Dune::ArrayList class.
Definition: arraylist.hh:368
A const iterator over an uncached selection.
Definition: selection.hh:31
TS AttributeSet
The type of the Set of attributes.
Definition: selection.hh:41
Dune::ParallelIndexSet< TG, TL, N > ParallelIndexSet
The type of the underlying index set.
Definition: selection.hh:46
SelectionIterator(const ParallelIndexSetIterator &iter, const ParallelIndexSetIterator &end)
Constructor.
Definition: selection.hh:56
A cached selection of indices.
Definition: selection.hh:180
TG GlobalIndex
The type of the global index of the underlying index set.
Definition: selection.hh:195
TL LocalIndex
The type of the local index of the underlying index set.
Definition: selection.hh:203
TS AttributeSet
The type of the set of attributes.
Definition: selection.hh:190
uint32_t * iterator
The type of the iterator of the selected indices.
Definition: selection.hh:213
uint32_t * const_iterator
The type of the iterator of the selected indices.
Definition: selection.hh:218
Dune::ParallelIndexSet< GlobalIndex, LocalIndex, N > ParallelIndexSet
The type of the underlying index set.
Definition: selection.hh:208
An uncached selection of indices.
Definition: selection.hh:99
SelectionIterator< TS, TG, TL, N > iterator
The type of the iterator of the selected indices.
Definition: selection.hh:132
TS AttributeSet
The type of the Set of attributes.
Definition: selection.hh:109
iterator const_iterator
The type of the iterator of the selected indices.
Definition: selection.hh:137
TG GlobalIndex
The type of the global index of the underlying index set.
Definition: selection.hh:114
Dune::ParallelIndexSet< GlobalIndex, LocalIndex, N > ParallelIndexSet
The type of the underlying index set.
Definition: selection.hh:127
TL LocalIndex
The type of the local index of the underlying index set.
Definition: selection.hh:122
const_iterator end() const
Get an iterator over the selected indices.
Definition: selection.hh:330
void setIndexSet(const ParallelIndexSet &indexset)
Set the index set of the selection.
Definition: selection.hh:269
void setIndexSet(const ParallelIndexSet &indexset)
Set the index set of the selection.
Definition: selection.hh:336
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:302
const_iterator begin() const
Get the index set we are a selection for.
Definition: selection.hh:296
void free()
Free allocated memory.
Definition: selection.hh:308
const_iterator begin() const
Get the index set we are a selection for.
Definition: selection.hh:323
Provides a map between global and local indices.
This file implements iterator facade classes for writing stl conformant iterators.
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 21, 23:30, 2024)