Dune Core Modules (2.9.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// SPDX-FileCopyrightInfo: Copyright (C) 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_SELECTION_HH
6#define DUNE_SELECTION_HH
7
8#include "indexset.hh"
10
11namespace Dune
12{
27 template<typename TS, typename TG, typename TL, int N>
29 {
30 public:
39 typedef TS AttributeSet;
40
45
46 //typedef typename ParallelIndexSet::const_iterator ParallelIndexSetIterator;
47
48 typedef ConstArrayListIterator<IndexPair<TG,TL>, N, std::allocator<Dune::IndexPair<TG,TL> > > ParallelIndexSetIterator;
55 : iter_(iter), end_(end)
56 {
57 // Step to the first valid entry
58 while(iter_!=end_ && !AttributeSet::contains(iter_->local().attribute()))
59 ++iter_;
60 }
61
62 void operator++()
63 {
64 assert(iter_!=end_);
65 for(++iter_; iter_!=end_; ++iter_)
66 if(AttributeSet::contains(iter_->local().attribute()))
67 break;
68 }
69
70
71 uint32_t operator*() const
72 {
73 return iter_->local().local();
74 }
75
76 bool operator==(const SelectionIterator<TS,TG,TL,N>& other) const
77 {
78 return iter_ == other.iter_;
79 }
80
81 bool operator!=(const SelectionIterator<TS,TG,TL,N>& other) const
82 {
83 return iter_ != other.iter_;
84 }
85
86 private:
87 ParallelIndexSetIterator iter_;
88 const ParallelIndexSetIterator end_;
89 };
90
91
95 template<typename TS, typename TG, typename TL, int N>
97 {
98 public:
107 typedef TS AttributeSet;
108
112 typedef TG GlobalIndex;
113
120 typedef TL LocalIndex;
121
126
131
136
138 : indexSet_()
139 {}
140
141 UncachedSelection(const ParallelIndexSet& indexset)
142 : indexSet_(&indexset)
143 {}
148 void setIndexSet(const ParallelIndexSet& indexset);
149
153 //const ParallelIndexSet& indexSet() const;
154
159 const_iterator begin() const;
160
165 const_iterator end() const;
166
167
168 private:
169 const ParallelIndexSet* indexSet_;
170
171 };
172
176 template<typename TS, typename TG, typename TL, int N>
178 {
179 public:
188 typedef TS AttributeSet;
189
193 typedef TG GlobalIndex;
194
201 typedef TL LocalIndex;
202
207
211 typedef uint32_t* iterator;
212
216 typedef uint32_t* const_iterator;
217
218 Selection()
219 : selected_()
220 {}
221
222 Selection(const ParallelIndexSet& indexset)
223 : selected_(), size_(0), built_(false)
224 {
225 setIndexSet(indexset);
226 }
227
228 ~Selection();
229
234 void setIndexSet(const ParallelIndexSet& indexset);
235
239 void free();
240
244 //IndexSet indexSet() const;
245
250 const_iterator begin() const;
251
256 const_iterator end() const;
257
258
259 private:
260 uint32_t* selected_;
261 size_t size_;
262 bool built_;
263
264 };
265
266 template<typename TS, typename TG, typename TL, int N>
268 {
269 if(built_)
270 free();
271
272 // Count the number of entries the selection has to hold
274 const const_iterator end = indexset.end();
275 int entries = 0;
276
277 for(const_iterator index = indexset.begin(); index != end; ++index)
278 if(AttributeSet::contains(index->local().attribute()))
279 ++entries;
280
281 selected_ = new uint32_t[entries];
282 built_ = true;
283
284 entries = 0;
285 for(const_iterator index = indexset.begin(); index != end; ++index)
286 if(AttributeSet::contains(index->local().attribute()))
287 selected_[entries++]= index->local().local();
288
289 size_=entries;
290 built_=true;
291 }
292
293 template<typename TS, typename TG, typename TL, int N>
295 {
296 return selected_;
297 }
298
299 template<typename TS, typename TG, typename TL, int N>
301 {
302 return selected_+size_;
303 }
304
305 template<typename TS, typename TG, typename TL, int N>
307 {
308 delete[] selected_;
309 size_=0;
310 built_=false;
311 }
312
313 template<typename TS, typename TG, typename TL, int N>
315 {
316 if(built_)
317 free();
318 }
319
320 template<typename TS, typename TG, typename TL, int N>
322 {
323 return SelectionIterator<TS,TG,TL,N>(indexSet_->begin(),
324 indexSet_->end());
325 }
326
327 template<typename TS, typename TG, typename TL, int N>
329 {
330 return SelectionIterator<TS,TG,TL,N>(indexSet_->end(),
331 indexSet_->end());
332 }
333 template<typename TS, typename TG, typename TL, int N>
335 {
336 indexSet_ = &indexset;
337 }
338
342}
343#endif
A constant random access iterator for the Dune::ArrayList class.
Definition: arraylist.hh:370
A const iterator over an uncached selection.
Definition: selection.hh:29
TS AttributeSet
The type of the Set of attributes.
Definition: selection.hh:39
Dune::ParallelIndexSet< TG, TL, N > ParallelIndexSet
The type of the underlying index set.
Definition: selection.hh:44
SelectionIterator(const ParallelIndexSetIterator &iter, const ParallelIndexSetIterator &end)
Constructor.
Definition: selection.hh:54
A cached selection of indices.
Definition: selection.hh:178
TG GlobalIndex
The type of the global index of the underlying index set.
Definition: selection.hh:193
TL LocalIndex
The type of the local index of the underlying index set.
Definition: selection.hh:201
TS AttributeSet
The type of the set of attributes.
Definition: selection.hh:188
uint32_t * iterator
The type of the iterator of the selected indices.
Definition: selection.hh:211
uint32_t * const_iterator
The type of the iterator of the selected indices.
Definition: selection.hh:216
Dune::ParallelIndexSet< GlobalIndex, LocalIndex, N > ParallelIndexSet
The type of the underlying index set.
Definition: selection.hh:206
An uncached selection of indices.
Definition: selection.hh:97
SelectionIterator< TS, TG, TL, N > iterator
The type of the iterator of the selected indices.
Definition: selection.hh:130
TS AttributeSet
The type of the Set of attributes.
Definition: selection.hh:107
iterator const_iterator
The type of the iterator of the selected indices.
Definition: selection.hh:135
TG GlobalIndex
The type of the global index of the underlying index set.
Definition: selection.hh:112
Dune::ParallelIndexSet< GlobalIndex, LocalIndex, N > ParallelIndexSet
The type of the underlying index set.
Definition: selection.hh:125
TL LocalIndex
The type of the local index of the underlying index set.
Definition: selection.hh:120
const_iterator end() const
Get an iterator over the selected indices.
Definition: selection.hh:328
void setIndexSet(const ParallelIndexSet &indexset)
Set the index set of the selection.
Definition: selection.hh:267
void setIndexSet(const ParallelIndexSet &indexset)
Set the index set of the selection.
Definition: selection.hh:334
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:300
const_iterator begin() const
Get the index set we are a selection for.
Definition: selection.hh:294
void free()
Free allocated memory.
Definition: selection.hh:306
const_iterator begin() const
Get the index set we are a selection for.
Definition: selection.hh:321
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 (Nov 21, 23:30, 2024)