Loading...
Searching...
No Matches
selection.hh
Go to the documentation of this file.
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
#ifndef DUNE_COMMON_PARALLEL_SELECTION_HH
#define DUNE_COMMON_PARALLEL_SELECTION_HH
#include <cstdint>
#include <dune/common/iteratorfacades.hh>
#include <dune/common/parallel/indexset.hh>
namespace Dune
{
template<typename TS, typename TG, typename TL, int N>
class SelectionIterator
{
public:
typedef TS AttributeSet;
typedef Dune::ParallelIndexSet<TG,TL,N> ParallelIndexSet;
//typedef typename ParallelIndexSet::const_iterator ParallelIndexSetIterator;
typedef ConstArrayListIterator<IndexPair<TG,TL>, N, std::allocator<Dune::IndexPair<TG,TL> > > ParallelIndexSetIterator;
SelectionIterator(const ParallelIndexSetIterator& iter, const ParallelIndexSetIterator& end)
: iter_(iter), end_(end)
{
// Step to the first valid entry
while(iter_!=end_ && !AttributeSet::contains(iter_->local().attribute()))
++iter_;
}
void operator++()
{
assert(iter_!=end_);
for(++iter_; iter_!=end_; ++iter_)
if(AttributeSet::contains(iter_->local().attribute()))
break;
}
uint32_t operator*() const
{
return iter_->local().local();
}
bool operator==(const SelectionIterator<TS,TG,TL,N>& other) const
{
return iter_ == other.iter_;
}
bool operator!=(const SelectionIterator<TS,TG,TL,N>& other) const
{
return iter_ != other.iter_;
}
private:
ParallelIndexSetIterator iter_;
const ParallelIndexSetIterator end_;
};
template<typename TS, typename TG, typename TL, int N>
class UncachedSelection
{
public:
typedef TS AttributeSet;
typedef TG GlobalIndex;
typedef TL LocalIndex;
typedef Dune::ParallelIndexSet<GlobalIndex,LocalIndex,N> ParallelIndexSet;
typedef SelectionIterator<TS,TG,TL,N> iterator;
typedef iterator const_iterator;
UncachedSelection()
: indexSet_()
{}
UncachedSelection(const ParallelIndexSet& indexset)
: indexSet_(&indexset)
{}
void setIndexSet(const ParallelIndexSet& indexset);
//const ParallelIndexSet& indexSet() const;
const_iterator begin() const;
const_iterator end() const;
private:
const ParallelIndexSet* indexSet_;
};
template<typename TS, typename TG, typename TL, int N>
class Selection
{
public:
typedef TS AttributeSet;
typedef TG GlobalIndex;
typedef TL LocalIndex;
typedef Dune::ParallelIndexSet<GlobalIndex,LocalIndex,N> ParallelIndexSet;
typedef uint32_t* iterator;
typedef uint32_t* const_iterator;
Selection()
: selected_()
{}
Selection(const ParallelIndexSet& indexset)
: selected_(), size_(0), built_(false)
{
setIndexSet(indexset);
}
~Selection();
void setIndexSet(const ParallelIndexSet& indexset);
void free();
//IndexSet indexSet() const;
const_iterator begin() const;
const_iterator end() const;
private:
uint32_t* selected_;
size_t size_;
bool built_;
};
template<typename TS, typename TG, typename TL, int N>
inline void Selection<TS,TG,TL,N>::setIndexSet(const ParallelIndexSet& indexset)
{
if(built_)
free();
// Count the number of entries the selection has to hold
typedef typename ParallelIndexSet::const_iterator const_iterator;
const const_iterator end = indexset.end();
int entries = 0;
for(const_iterator index = indexset.begin(); index != end; ++index)
if(AttributeSet::contains(index->local().attribute()))
++entries;
selected_ = new uint32_t[entries];
built_ = true;
entries = 0;
for(const_iterator index = indexset.begin(); index != end; ++index)
if(AttributeSet::contains(index->local().attribute()))
selected_[entries++]= index->local().local();
size_=entries;
built_=true;
}
template<typename TS, typename TG, typename TL, int N>
uint32_t* Selection<TS,TG,TL,N>::begin() const
{
return selected_;
}
template<typename TS, typename TG, typename TL, int N>
uint32_t* Selection<TS,TG,TL,N>::end() const
{
return selected_+size_;
}
template<typename TS, typename TG, typename TL, int N>
inline void Selection<TS,TG,TL,N>::free()
{
delete[] selected_;
size_=0;
built_=false;
}
template<typename TS, typename TG, typename TL, int N>
inline Selection<TS,TG,TL,N>::~Selection()
{
if(built_)
free();
}
template<typename TS, typename TG, typename TL, int N>
SelectionIterator<TS,TG,TL,N> UncachedSelection<TS,TG,TL,N>::begin() const
{
return SelectionIterator<TS,TG,TL,N>(indexSet_->begin(),
indexSet_->end());
}
template<typename TS, typename TG, typename TL, int N>
SelectionIterator<TS,TG,TL,N> UncachedSelection<TS,TG,TL,N>::end() const
{
return SelectionIterator<TS,TG,TL,N>(indexSet_->end(),
indexSet_->end());
}
template<typename TS, typename TG, typename TL, int N>
void UncachedSelection<TS,TG,TL,N>::setIndexSet(const ParallelIndexSet& indexset)
{
indexSet_ = &indexset;
}
}
#endif // DUNE_COMMON_PARALLEL_SELECTION_HH
indexset.hh
Provides a map between global and local indices.
iteratorfacades.hh
This file implements iterator facade classes for writing stl conformant iterators.
Dune::UncachedSelection::end
const_iterator end() const
Get an iterator over the selected indices.
Definition selection.hh:330
Dune::Selection::setIndexSet
void setIndexSet(const ParallelIndexSet &indexset)
Set the index set of the selection.
Definition selection.hh:269
Dune::ParallelIndexSet< GlobalIndex, LocalIndex, N >::const_iterator
ArrayList< IndexPair, N >::const_iterator const_iterator
Definition indexset.hh:296
Dune::UncachedSelection::setIndexSet
void setIndexSet(const ParallelIndexSet &indexset)
Set the index set of the selection.
Definition selection.hh:336
Dune::ParallelIndexSet::begin
iterator begin()
Get an iterator over the indices positioned at the first index.
Dune::ParallelIndexSet::end
iterator end()
Get an iterator over the indices positioned after the last index.
Dune::Selection::end
const_iterator end() const
Get an iterator over the selected indices.
Definition selection.hh:302
Dune::Selection::begin
const_iterator begin() const
Get the index set we are a selection for.
Definition selection.hh:296
Dune::Selection::free
void free()
Free allocated memory.
Definition selection.hh:308
Dune::UncachedSelection::begin
const_iterator begin() const
Get the index set we are a selection for.
Definition selection.hh:323
Dune::Selection::~Selection
~Selection()
Definition selection.hh:316
Dune
Dune namespace
Definition alignedallocator.hh:13
Dune::ConstArrayListIterator
A constant random access iterator for the Dune::ArrayList class.
Definition arraylist.hh:368
Dune::const_iterator
Dune::ParallelIndexSet
Manager class for the mapping between local indices and globally unique indices.
Definition indexset.hh:218
Dune::SelectionIterator
A const iterator over an uncached selection.
Definition selection.hh:31
Dune::SelectionIterator::ParallelIndexSetIterator
ConstArrayListIterator< IndexPair< TG, TL >, N, std::allocator< Dune::IndexPair< TG, TL > > > ParallelIndexSetIterator
Definition selection.hh:50
Dune::SelectionIterator::operator++
void operator++()
Definition selection.hh:64
Dune::SelectionIterator::operator*
uint32_t operator*() const
Definition selection.hh:73
Dune::SelectionIterator::AttributeSet
TS AttributeSet
The type of the Set of attributes.
Definition selection.hh:41
Dune::SelectionIterator::ParallelIndexSet
Dune::ParallelIndexSet< TG, TL, N > ParallelIndexSet
The type of the underlying index set.
Definition selection.hh:46
Dune::SelectionIterator::SelectionIterator
SelectionIterator(const ParallelIndexSetIterator &iter, const ParallelIndexSetIterator &end)
Constructor.
Definition selection.hh:56
Dune::SelectionIterator::operator!=
bool operator!=(const SelectionIterator< TS, TG, TL, N > &other) const
Definition selection.hh:83
Dune::SelectionIterator::operator==
bool operator==(const SelectionIterator< TS, TG, TL, N > &other) const
Definition selection.hh:78
Dune::UncachedSelection::UncachedSelection
UncachedSelection()
Definition selection.hh:139
Dune::UncachedSelection::iterator
SelectionIterator< TS, TG, TL, N > iterator
The type of the iterator of the selected indices.
Definition selection.hh:132
Dune::UncachedSelection::AttributeSet
TS AttributeSet
The type of the Set of attributes.
Definition selection.hh:109
Dune::UncachedSelection::const_iterator
iterator const_iterator
The type of the iterator of the selected indices.
Definition selection.hh:137
Dune::UncachedSelection::GlobalIndex
TG GlobalIndex
The type of the global index of the underlying index set.
Definition selection.hh:114
Dune::UncachedSelection::UncachedSelection
UncachedSelection(const ParallelIndexSet &indexset)
Definition selection.hh:143
Dune::UncachedSelection::ParallelIndexSet
Dune::ParallelIndexSet< GlobalIndex, LocalIndex, N > ParallelIndexSet
The type of the underlying index set.
Definition selection.hh:127
Dune::UncachedSelection::LocalIndex
TL LocalIndex
The type of the local index of the underlying index set.
Definition selection.hh:122
Dune::Selection::GlobalIndex
TG GlobalIndex
The type of the global index of the underlying index set.
Definition selection.hh:195
Dune::Selection::Selection
Selection(const ParallelIndexSet &indexset)
Definition selection.hh:224
Dune::Selection::Selection
Selection()
Definition selection.hh:220
Dune::Selection::LocalIndex
TL LocalIndex
The type of the local index of the underlying index set.
Definition selection.hh:203
Dune::Selection::AttributeSet
TS AttributeSet
The type of the set of attributes.
Definition selection.hh:190
Dune::Selection::iterator
uint32_t * iterator
The type of the iterator of the selected indices.
Definition selection.hh:213
Dune::Selection::const_iterator
uint32_t * const_iterator
The type of the iterator of the selected indices.
Definition selection.hh:218
Dune::Selection::ParallelIndexSet
Dune::ParallelIndexSet< GlobalIndex, LocalIndex, N > ParallelIndexSet
The type of the underlying index set.
Definition selection.hh:208