dune-common 2.9.1
Loading...
Searching...
No Matches
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:
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
63 {
64 assert(iter_!=end_);
65 for(++iter_; iter_!=end_; ++iter_)
66 if(AttributeSet::contains(iter_->local().attribute()))
67 break;
68 }
69
70
72 {
73 return iter_->local().local();
74 }
75
77 {
78 return iter_ == other.iter_;
79 }
80
82 {
83 return iter_ != other.iter_;
84 }
85
86 private:
88 const ParallelIndexSetIterator end_;
89 };
90
91
95 template<typename TS, typename TG, typename TL, int N>
97 {
98 public:
108
113
120 typedef TL LocalIndex;
121
126
131
136
138 : indexSet_()
139 {}
140
142 : indexSet_(&indexset)
143 {}
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:
189
194
201 typedef TL LocalIndex;
202
207
212
217
219 : selected_()
220 {}
221
223 : selected_(), size_(0), built_(false)
224 {
226 }
227
228 ~Selection();
229
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>
338
342}
343#endif
This file implements iterator facade classes for writing stl conformant iterators.
Provides a map between global and local indices.
iterator begin()
Get an iterator that is positioned at the first element.
Definition arraylist.hh:517
ArrayList()
Constructs an Array list with one chunk.
Definition arraylist.hh:457
iterator end()
Get a random access iterator positioned after the last element.
Definition arraylist.hh:529
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
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
~Selection()
Definition selection.hh:314
Dune namespace.
Definition alignedallocator.hh:13
A dynamically growing random access list.
Definition arraylist.hh:62
ConstArrayListIterator< MemberType, N, A > const_iterator
A constant random access iterator.
Definition arraylist.hh:110
Manager class for the mapping between local indices and globally unique indices.
Definition indexset.hh:218
A const iterator over an uncached selection.
Definition selection.hh:29
ConstArrayListIterator< IndexPair< TG, TL >, N, std::allocator< Dune::IndexPair< TG, TL > > > ParallelIndexSetIterator
Definition selection.hh:48
void operator++()
Definition selection.hh:62
uint32_t operator*() const
Definition selection.hh:71
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
bool operator!=(const SelectionIterator< TS, TG, TL, N > &other) const
Definition selection.hh:81
bool operator==(const SelectionIterator< TS, TG, TL, N > &other) const
Definition selection.hh:76
An uncached selection of indices.
Definition selection.hh:97
UncachedSelection()
Definition selection.hh:137
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
UncachedSelection(const ParallelIndexSet &indexset)
Definition selection.hh:141
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
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
Selection(const ParallelIndexSet &indexset)
Definition selection.hh:222
Selection()
Definition selection.hh:218
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