3#ifndef DUNE_INDEXSET_HH
4#define DUNE_INDEXSET_HH
29 template<
class TG,
class TL>
37 template<
class TG,
class TL>
38 std::ostream&
operator<<(std::ostream& os,
const IndexPair<TG,TL>& pair);
40 template<
class TG,
class TL>
41 bool operator==(
const IndexPair<TG,TL>&,
const IndexPair<TG,TL>&);
43 template<
class TG,
class TL>
44 bool operator!=(
const IndexPair<TG,TL>&,
const IndexPair<TG,TL>&);
46 template<
class TG,
class TL>
47 bool operator<(
const IndexPair<TG,TL>&,
const IndexPair<TG,TL>&);
49 template<
class TG,
class TL>
50 bool operator>(
const IndexPair<TG,TL>&,
const IndexPair<TG,TL>&);
52 template<
class TG,
class TL>
53 bool operator<=(
const IndexPair<TG,TL>&,
const IndexPair<TG,TL>&);
55 template<
class TG,
class TL>
56 bool operator >=(
const IndexPair<TG,TL>&,
const IndexPair<TG,TL>&);
58 template<
class TG,
class TL>
59 bool operator==(
const IndexPair<TG,TL>&,
const TG&);
61 template<
class TG,
class TL>
62 bool operator!=(
const IndexPair<TG,TL>&,
const TG&);
64 template<
class TG,
class TL>
65 bool operator<(
const IndexPair<TG,TL>&,
const TG&);
67 template<
class TG,
class TL>
68 bool operator>(
const IndexPair<TG,TL>&,
const TG&);
70 template<
class TG,
class TL>
71 bool operator<=(
const IndexPair<TG,TL>&,
const TG&);
73 template<
class TG,
class TL>
74 bool operator >=(
const IndexPair<TG,TL>&,
const TG&);
82 template<
class TG,
class TL>
215 template<
typename TG,
typename TL,
int N=100>
264 :
Father(father), indexSet_(&indexSet)
268 :
Father(other), indexSet_(other.indexSet_)
273 Father::operator==(other);
274 indexSet_ = other.indexSet_;
287 inline void markAsDeleted()
const
290 if(indexSet_->state_ !=
RESIZE)
292 <<
"while in RESIZE state!");
482 bool deletedEntries_;
496 template<
class TG,
class TL,
int N>
566 pair(
const std::size_t& local)
const;
607 std::vector<const IndexPair*> indices_;
613 struct LocalIndexComparator
615 static bool compare(
const T& t1,
const T& t2){
622 template<
class TG,
class TL>
623 struct IndexSetSortFunctor
625 bool operator()(
const IndexPair<TG,TL>& i1,
const IndexPair<TG,TL>& i2)
627 return i1.global()<i2.global() || (i1.global()==i2.global() &&
628 LocalIndexComparator<TL>::compare(i1.local(),
635 template<
class TG,
class TL>
638 os<<
"{global="<<pair.global_<<
", local="<<pair.local_<<
"}";
642 template<
class TG,
class TL,
int N>
646 Iterator end = indexSet.
end();
648 for(Iterator index = indexSet.
begin(); index != end; ++index)
655 template<
class TG,
class TL>
656 inline bool operator==(
const IndexPair<TG,TL>& a,
const IndexPair<TG,TL>& b)
658 return a.global_==b.global_;
661 template<
class TG,
class TL>
662 inline bool operator!=(
const IndexPair<TG,TL>& a,
const IndexPair<TG,TL>& b)
664 return a.global_!=b.global_;
667 template<
class TG,
class TL>
668 inline bool operator<(
const IndexPair<TG,TL>& a,
const IndexPair<TG,TL>& b)
670 return a.global_<b.global_;
673 template<
class TG,
class TL>
674 inline bool operator>(
const IndexPair<TG,TL>& a,
const IndexPair<TG,TL>& b)
676 return a.global_>b.global_;
679 template<
class TG,
class TL>
680 inline bool operator<=(
const IndexPair<TG,TL>& a,
const IndexPair<TG,TL>& b)
682 return a.global_<=b.global_;
685 template<
class TG,
class TL>
686 inline bool operator >=(
const IndexPair<TG,TL>& a,
const IndexPair<TG,TL>& b)
688 return a.global_>=b.global_;
691 template<
class TG,
class TL>
692 inline bool operator==(
const IndexPair<TG,TL>& a,
const TG& b)
697 template<
class TG,
class TL>
698 inline bool operator!=(
const IndexPair<TG,TL>& a,
const TG& b)
703 template<
class TG,
class TL>
704 inline bool operator<(
const IndexPair<TG,TL>& a,
const TG& b)
709 template<
class TG,
class TL>
710 inline bool operator>(
const IndexPair<TG,TL>& a,
const TG& b)
715 template<
class TG,
class TL>
716 inline bool operator<=(
const IndexPair<TG,TL>& a,
const TG& b)
721 template<
class TG,
class TL>
722 inline bool operator >=(
const IndexPair<TG,TL>& a,
const TG& b)
729 template<
class TG,
class TL>
731 : global_(global), local_(local){}
733 template<
class TG,
class TL>
734 IndexPair<TG,TL>::IndexPair(
const TG& global)
735 : global_(global), local_(){}
737 template<
class TG,
class TL>
738 IndexPair<TG,TL>::IndexPair()
739 : global_(), local_(){}
741 template<
class TG,
class TL>
742 inline const TG& IndexPair<TG,TL>::global()
const {
746 template<
class TG,
class TL>
747 inline TL& IndexPair<TG,TL>::local() {
751 template<
class TG,
class TL>
752 inline const TL& IndexPair<TG,TL>::local()
const {
756 template<
class TG,
class TL>
757 inline void IndexPair<TG,TL>::setLocal(
int local){
761 template<
class TG,
class TL,
int N>
763 : state_(
GROUND), seqNo_(0)
766 template<
class TG,
class TL,
int N>
774 "IndexSet has to be in GROUND state, when "
775 <<
"beginResize() is called!");
779 deletedEntries_ =
false;
782 template<
class TG,
class TL,
int N>
788 DUNE_THROW(InvalidIndexSetState,
"Indices can only be added "
789 <<
"while in RESIZE state!");
791 newIndices_.push_back(IndexPair(global));
794 template<
class TG,
class TL,
int N>
800 DUNE_THROW(InvalidIndexSetState,
"Indices can only be added "
801 <<
"while in RESIZE state!");
803 newIndices_.push_back(IndexPair(global,local));
806 template<
class TG,
class TL,
int N>
812 DUNE_THROW(InvalidIndexSetState,
"Indices can only be removed "
813 <<
"while in RESIZE state!");
815 deletedEntries_ =
true;
817 global.markAsDeleted();
820 template<
class TG,
class TL,
int N>
825 DUNE_THROW(InvalidIndexSetState,
"endResize called while not "
826 <<
"in RESIZE state!");
829 std::sort(newIndices_.begin(), newIndices_.end(), IndexSetSortFunctor<TG,TL>());
836 template<
class TG,
class TL,
int N>
837 inline void ParallelIndexSet<TG,TL,N>::merge(){
838 if(localIndices_.size()==0)
840 localIndices_=newIndices_;
843 else if(newIndices_.size()>0 || deletedEntries_)
845 ArrayList<IndexPair,N> tempPairs;
846 typedef typename ArrayList<IndexPair,N>::iterator iterator;
847 typedef typename ArrayList<IndexPair,N>::const_iterator const_iterator;
849 iterator old=localIndices_.begin();
850 iterator added=newIndices_.begin();
851 const const_iterator endold=localIndices_.end();
852 const const_iterator endadded=newIndices_.end();
854 while(old != endold && added!= endadded)
856 if(old->local().state()==DELETED) {
861 if(old->global() < added->global() ||
862 (old->global() == added->global()
863 && LocalIndexComparator<TL>::compare(old->local(),added->local())))
865 tempPairs.push_back(*old);
870 tempPairs.push_back(*added);
878 if(old->local().state()!=DELETED) {
879 tempPairs.push_back(*old);
884 while(added!= endadded)
886 tempPairs.push_back(*added);
889 localIndices_ = tempPairs;
894 template<
class TG,
class TL,
int N>
895 inline const IndexPair<TG,TL>&
899 int low=0, high=localIndices_.size()-1, probe=-1;
903 probe = (high + low) / 2;
904 if(global <= localIndices_[probe].global())
913 if( localIndices_[low].global() != global)
914 DUNE_THROW(RangeError,
"Could not find entry of "<<global);
916 return localIndices_[low];
919 template<
class TG,
class TL,
int N>
920 inline const IndexPair<TG,TL>&
924 int low=0, high=localIndices_.size()-1, probe=-1;
928 probe = (high + low) / 2;
929 if(global <= localIndices_[probe].global())
935 return localIndices_[low];
937 template<
class TG,
class TL,
int N>
941 int low=0, high=localIndices_.size()-1, probe=-1;
945 probe = (high + low) / 2;
946 if(localIndices_[probe].global() >= global)
955 if( localIndices_[low].global() != global)
956 DUNE_THROW(RangeError,
"Could not find entry of "<<global);
958 return localIndices_[low];
961 template<
class TG,
class TL,
int N>
965 int low=0, high=localIndices_.size()-1, probe=-1;
969 probe = (high + low) / 2;
970 if(localIndices_[probe].global() >= global)
976 return localIndices_[low];
978 template<
class TG,
class TL,
int N>
979 inline typename ParallelIndexSet<TG,TL,N>::iterator
982 return iterator(*
this, localIndices_.begin());
986 template<
class TG,
class TL,
int N>
987 inline typename ParallelIndexSet<TG,TL,N>::iterator
990 return iterator(*
this,localIndices_.end());
993 template<
class TG,
class TL,
int N>
997 return localIndices_.begin();
1001 template<
class TG,
class TL,
int N>
1005 return localIndices_.end();
1008 template<
class TG,
class TL,
int N>
1012 DUNE_THROW(InvalidIndexSetState,
"IndexSet has to be in "
1013 <<
"GROUND state for renumberLocal()");
1016 typedef typename ArrayList<IndexPair,N>::iterator iterator;
1017 const const_iterator end_ = end();
1020 for(iterator pair=begin(); pair!=end_; index++, ++pair)
1021 pair->local()=index;
1024 template<
class TG,
class TL,
int N>
1030 template<
class TG,
class TL,
int N>
1033 return localIndices_.size();
1037 GlobalLookupIndexSet<I>::GlobalLookupIndexSet(
const I& indexset,
1039 : indexSet_(indexset), size_(size),
1040 indices_(size_, static_cast<const IndexPair*>(0))
1042 const_iterator end_ = indexSet_.end();
1044 for(const_iterator pair = indexSet_.begin(); pair!=end_; ++pair) {
1045 assert(pair->local()<size_);
1046 indices_[pair->local()] = &(*pair);
1051 GlobalLookupIndexSet<I>::GlobalLookupIndexSet(
const I& indexset)
1052 : indexSet_(indexset), size_(0)
1054 const_iterator end_ = indexSet_.end();
1055 for(const_iterator pair = indexSet_.begin(); pair!=end_; ++pair)
1056 size_=std::max(size_,
static_cast<std::size_t
>(pair->local()));
1058 indices_.resize(++size_, 0);
1060 for(const_iterator pair = indexSet_.begin(); pair!=end_; ++pair)
1061 indices_[pair->local()] = &(*pair);
1065 GlobalLookupIndexSet<I>::~GlobalLookupIndexSet()
1069 inline const IndexPair<typename I::GlobalIndex, typename I::LocalIndex>*
1070 GlobalLookupIndexSet<I>::pair(
const std::size_t& local)
const
1072 return indices_[local];
1076 inline const IndexPair<typename I::GlobalIndex, typename I::LocalIndex>&
1077 GlobalLookupIndexSet<I>::operator[](
const GlobalIndex& global)
const
1079 return indexSet_[global];
1083 typename I::const_iterator GlobalLookupIndexSet<I>::begin()
const
1085 return indexSet_.begin();
1089 typename I::const_iterator GlobalLookupIndexSet<I>::end()
const
1091 return indexSet_.end();
1095 inline size_t GlobalLookupIndexSet<I>::size()
const
1101 inline int GlobalLookupIndexSet<I>::seqNo()
const
1103 return indexSet_.seqNo();
1106 template<
typename TG,
typename TL,
int N,
typename TG1,
typename TL1,
int N1>
1107 bool operator==(
const ParallelIndexSet<TG,TL,N>& idxset,
1108 const ParallelIndexSet<TG1,TL1,N1>& idxset1)
1110 if(idxset.size()!=idxset1.size())
1113 typedef typename ParallelIndexSet<TG1,TL1,N1>::const_iterator Iter1;
1114 Iter iter=idxset.begin();
1115 for(Iter1 iter1=idxset1.begin(); iter1 != idxset1.end(); ++iter, ++iter1) {
1116 if(iter1->global()!=iter->global())
1119 const PI& pi=iter->local(), pi1=iter1->local();
1127 template<
typename TG,
typename TL,
int N,
typename TG1,
typename TL1,
int N1>
1128 bool operator!=(
const ParallelIndexSet<TG,TL,N>& idxset,
1129 const ParallelIndexSet<TG1,TL1,N1>& idxset1)
1131 return !(idxset==idxset1);
Implements a random-access container that can efficiently change size (similar to std::deque)
A random access iterator for the Dune::ArrayList class.
Definition: arraylist.hh:258
A dynamically growing random access list.
Definition: arraylist.hh:60
A constant random access iterator for the Dune::ArrayList class.
Definition: arraylist.hh:379
Decorates an index set with the possibility to find a global index that is mapped to a specific local...
Definition: indexset.hh:506
A pair consisting of a global and local index.
Definition: indexset.hh:84
Exception indicating that the index set is not in the expected state.
Definition: indexset.hh:204
Default exception if a function was called while the object is not in a valid state for that function...
Definition: exceptions.hh:279
The iterator over the pairs.
Definition: indexset.hh:258
Manager class for the mapping between local indices and globally unique indices.
Definition: indexset.hh:217
Reference operator*() const
Dereferencing operator.
Definition: iteratorfacades.hh:492
A few common exception classes.
IndexPair & operator[](const GlobalIndex &global)
Find the index pair with a specific global id.
void beginResize()
Indicate that the index set is to be resized.
ParallelIndexSetState
The states the index set can be in.
Definition: indexset.hh:180
void renumberLocal()
Renumbers the local index numbers.
size_t size() const
Get the total number (public and nonpublic) indices.
ArrayList< IndexPair, N >::const_iterator const_iterator
The constant iterator over the pairs.
Definition: indexset.hh:307
void add(const GlobalIndex &global)
Add an new index to the set.
const_iterator end() const
Get an iterator over the indices positioned after the last index.
const LocalIndex & local() const
Get the local index.
const IndexPair & at(const GlobalIndex &global) const
Find the index pair with a specific global id.
GlobalLookupIndexSet(const ParallelIndexSet &indexset)
Constructor.
TL LocalIndex
the type of the local index.
Definition: indexset.hh:119
int seqNo() const
Get the internal sequence number.
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.
ParallelIndexSet::const_iterator const_iterator
The iterator over the index pairs.
Definition: indexset.hh:526
const_iterator begin() const
Get an iterator over the indices positioned at the first index.
const IndexPair & operator[](const GlobalIndex &global) const
Find the index pair with a specific global id.
const ParallelIndexSetState & state()
Get the state the index set is in.
Definition: indexset.hh:318
const_iterator begin() const
Get an iterator over the indices positioned at the first index.
const IndexPair & operator[](const GlobalIndex &global) const
Find the index pair with a specific global id.
IndexPair()
Construct a new Pair.
I ParallelIndexSet
The type of the index set.
Definition: indexset.hh:511
TL LocalIndex
The type of the local index, e.g. ParallelLocalIndex.
Definition: indexset.hh:238
void markAsDeleted(const iterator &position)
Mark an index as deleted.
ParallelIndexSet::LocalIndex LocalIndex
The type of the local index.
Definition: indexset.hh:516
IndexPair(const GlobalIndex &global, const LocalIndex &local)
Constructs a new Pair.
void setLocal(int index)
Set the local index.
const GlobalIndex & global() const
Get the global index.
void add(const GlobalIndex &global, const LocalIndex &local)
Add an new index to the set.
const_iterator end() const
Get an iterator over the indices positioned after the last index.
IndexPair & at(const GlobalIndex &global)
Find the index pair with a specific global id.
ParallelIndexSet()
Constructor.
void endResize()
Indicate that the resizing finishes.
~GlobalLookupIndexSet()
Destructor.
const IndexPair * pair(const std::size_t &local) const
Get the index pair corresponding to a local index.
LocalIndex & local()
Get the local index.
size_t size() const
Get the total number (public and nonpublic) indices.
IndexPair(const GlobalIndex &global)
Constructs a new Pair.
TG GlobalIndex
the type of the global index. This type has to provide at least a operator< for sorting.
Definition: indexset.hh:225
std::ostream & operator<<(std::ostream &os, const ParallelIndexSet< TG, TL, N > &indexSet)
Print an index set.
Definition: indexset.hh:643
TG GlobalIndex
the type of the global index.
Definition: indexset.hh:106
int seqNo() const
Get the internal sequence number.
GlobalLookupIndexSet(const ParallelIndexSet &indexset, std::size_t size)
Constructor.
ParallelIndexSet::GlobalIndex GlobalIndex
The type of the global index.
Definition: indexset.hh:521
Dune::IndexPair< GlobalIndex, LocalIndex > IndexPair
The type of the pair stored.
Definition: indexset.hh:243
@ RESIZE
Indicates that the index set is currently being resized.
Definition: indexset.hh:189
@ GROUND
The default mode. Indicates that the index set is ready to be used.
Definition: indexset.hh:185
@ arraySize
The size of the individual arrays in the underlying ArrayList.
Definition: indexset.hh:252
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentionally unused function parameters with.
Definition: unused.hh:25
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
EnableIfInterOperable< T1, T2, bool >::type operator<(const RandomAccessIteratorFacade< T1, V1, R1, D > &lhs, const RandomAccessIteratorFacade< T2, V2, R2, D > &rhs)
Comparison operator.
Definition: iteratorfacades.hh:629
EnableIfInterOperable< T1, T2, bool >::type operator>(const RandomAccessIteratorFacade< T1, V1, R1, D > &lhs, const RandomAccessIteratorFacade< T2, V2, R2, D > &rhs)
Comparison operator.
Definition: iteratorfacades.hh:675
EnableIfInterOperable< T1, T2, bool >::type operator<=(const RandomAccessIteratorFacade< T1, V1, R1, D > &lhs, const RandomAccessIteratorFacade< T2, V2, R2, D > &rhs)
Comparison operator.
Definition: iteratorfacades.hh:652
EnableIfInterOperable< T1, T2, bool >::type operator==(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for equality.
Definition: iteratorfacades.hh:233
EnableIfInterOperable< T1, T2, bool >::type operator>=(const RandomAccessIteratorFacade< T1, V1, R1, D > &lhs, const RandomAccessIteratorFacade< T2, V2, R2, D > &rhs)
Comparison operator.
Definition: iteratorfacades.hh:697
EnableIfInterOperable< T1, T2, bool >::type operator!=(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for inequality.
Definition: iteratorfacades.hh:255
Provides classes for use as the local index in ParallelIndexSet.
Dune namespace.
Definition: alignedallocator.hh:10
A traits class describing the mapping of types onto MPI_Datatypes.
Definition: mpitraits.hh:38
Definition of the DUNE_UNUSED macro for the case that config.h is not available.