4#ifndef DUNE_INDEXSET_HH
5#define DUNE_INDEXSET_HH
30 template<
class TG,
class TL>
38 template<
class TG,
class TL>
39 std::ostream&
operator<<(std::ostream& os,
const IndexPair<TG,TL>& pair);
41 template<
class TG,
class TL>
42 bool operator==(
const IndexPair<TG,TL>&,
const IndexPair<TG,TL>&);
44 template<
class TG,
class TL>
45 bool operator!=(
const IndexPair<TG,TL>&,
const IndexPair<TG,TL>&);
47 template<
class TG,
class TL>
48 bool operator<(
const IndexPair<TG,TL>&,
const IndexPair<TG,TL>&);
50 template<
class TG,
class TL>
51 bool operator>(
const IndexPair<TG,TL>&,
const IndexPair<TG,TL>&);
53 template<
class TG,
class TL>
54 bool operator<=(
const IndexPair<TG,TL>&,
const IndexPair<TG,TL>&);
56 template<
class TG,
class TL>
57 bool operator >=(
const IndexPair<TG,TL>&,
const IndexPair<TG,TL>&);
59 template<
class TG,
class TL>
60 bool operator==(
const IndexPair<TG,TL>&,
const TG&);
62 template<
class TG,
class TL>
63 bool operator!=(
const IndexPair<TG,TL>&,
const TG&);
65 template<
class TG,
class TL>
66 bool operator<(
const IndexPair<TG,TL>&,
const TG&);
68 template<
class TG,
class TL>
69 bool operator>(
const IndexPair<TG,TL>&,
const TG&);
71 template<
class TG,
class TL>
72 bool operator<=(
const IndexPair<TG,TL>&,
const TG&);
74 template<
class TG,
class TL>
75 bool operator >=(
const IndexPair<TG,TL>&,
const TG&);
83 template<
class TG,
class TL>
216 template<
typename TG,
typename TL,
int N=100>
265 :
Father(father), indexSet_(&indexSet)
269 :
Father(other), indexSet_(other.indexSet_)
274 Father::operator==(other);
275 indexSet_ = other.indexSet_;
289 if(indexSet_->state_ !=
RESIZE)
291 <<
"while in RESIZE state!");
483 bool deletedEntries_;
497 template<class TG, class TL,
int N>
567 pair(
const std::size_t& local)
const;
608 std::vector<const IndexPair*> indices_;
614 struct LocalIndexComparator
616 static bool compare(
const T& t1,
const T& t2){
623 template<
class TG,
class TL>
624 struct IndexSetSortFunctor
626 bool operator()(
const IndexPair<TG,TL>& i1,
const IndexPair<TG,TL>& i2)
628 return i1.global()<i2.global() || (i1.global()==i2.global() &&
629 LocalIndexComparator<TL>::compare(i1.local(),
636 template<
class TG,
class TL>
639 os<<
"{global="<<pair.global_<<
", local="<<pair.local_<<
"}";
643 template<
class TG,
class TL,
int N>
647 Iterator
end = indexSet.
end();
649 for(Iterator index = indexSet.
begin(); index !=
end; ++index)
656 template<
class TG,
class TL>
657 inline bool operator==(
const IndexPair<TG,TL>& a,
const IndexPair<TG,TL>& b)
659 return a.global_==b.global_;
662 template<
class TG,
class TL>
663 inline bool operator!=(
const IndexPair<TG,TL>& a,
const IndexPair<TG,TL>& b)
665 return a.global_!=b.global_;
668 template<
class TG,
class TL>
669 inline bool operator<(
const IndexPair<TG,TL>& a,
const IndexPair<TG,TL>& b)
671 return a.global_<b.global_;
674 template<
class TG,
class TL>
675 inline bool operator>(
const IndexPair<TG,TL>& a,
const IndexPair<TG,TL>& b)
677 return a.global_>b.global_;
680 template<
class TG,
class TL>
681 inline bool operator<=(
const IndexPair<TG,TL>& a,
const IndexPair<TG,TL>& b)
683 return a.global_<=b.global_;
686 template<
class TG,
class TL>
687 inline bool operator >=(
const IndexPair<TG,TL>& a,
const IndexPair<TG,TL>& b)
689 return a.global_>=b.global_;
692 template<
class TG,
class TL>
693 inline bool operator==(
const IndexPair<TG,TL>& a,
const TG& b)
698 template<
class TG,
class TL>
699 inline bool operator!=(
const IndexPair<TG,TL>& a,
const TG& b)
704 template<
class TG,
class TL>
705 inline bool operator<(
const IndexPair<TG,TL>& a,
const TG& b)
710 template<
class TG,
class TL>
711 inline bool operator>(
const IndexPair<TG,TL>& a,
const TG& b)
716 template<
class TG,
class TL>
717 inline bool operator<=(
const IndexPair<TG,TL>& a,
const TG& b)
722 template<
class TG,
class TL>
723 inline bool operator >=(
const IndexPair<TG,TL>& a,
const TG& b)
730 template<
class TG,
class TL>
732 : global_(global), local_(local){}
734 template<
class TG,
class TL>
735 IndexPair<TG,TL>::IndexPair(
const TG& global)
736 : global_(global), local_(){}
738 template<
class TG,
class TL>
739 IndexPair<TG,TL>::IndexPair()
740 : global_(), local_(){}
742 template<
class TG,
class TL>
743 inline const TG& IndexPair<TG,TL>::global()
const {
747 template<
class TG,
class TL>
748 inline TL& IndexPair<TG,TL>::local() {
752 template<
class TG,
class TL>
753 inline const TL& IndexPair<TG,TL>::local()
const {
757 template<
class TG,
class TL>
758 inline void IndexPair<TG,TL>::setLocal(
int local){
762 template<
class TG,
class TL,
int N>
764 : state_(
GROUND), seqNo_(0)
767 template<
class TG,
class TL,
int N>
775 "IndexSet has to be in GROUND state, when "
776 <<
"beginResize() is called!");
780 deletedEntries_ =
false;
783 template<
class TG,
class TL,
int N>
785 throw(InvalidIndexSetState)
790 DUNE_THROW(InvalidIndexSetState,
"Indices can only be added "
791 <<
"while in RESIZE state!");
793 newIndices_.push_back(IndexPair(global));
796 template<
class TG,
class TL,
int N>
798 throw(InvalidIndexSetState)
803 DUNE_THROW(InvalidIndexSetState,
"Indices can only be added "
804 <<
"while in RESIZE state!");
806 newIndices_.push_back(IndexPair(global,local));
809 template<
class TG,
class TL,
int N>
811 throw(InvalidIndexSetState){
815 DUNE_THROW(InvalidIndexSetState,
"Indices can only be removed "
816 <<
"while in RESIZE state!");
818 deletedEntries_ =
true;
820 global.markAsDeleted();
823 template<
class TG,
class TL,
int N>
828 DUNE_THROW(InvalidIndexSetState,
"endResize called while not "
829 <<
"in RESIZE state!");
832 std::sort(newIndices_.begin(), newIndices_.end(), IndexSetSortFunctor<TG,TL>());
839 template<
class TG,
class TL,
int N>
840 inline void ParallelIndexSet<TG,TL,N>::merge(){
841 if(localIndices_.size()==0)
843 localIndices_=newIndices_;
846 else if(newIndices_.size()>0 || deletedEntries_)
848 ArrayList<IndexPair,N> tempPairs;
849 typedef typename ArrayList<IndexPair,N>::iterator iterator;
850 typedef typename ArrayList<IndexPair,N>::const_iterator const_iterator;
852 iterator old=localIndices_.begin();
853 iterator added=newIndices_.begin();
854 const const_iterator endold=localIndices_.end();
855 const const_iterator endadded=newIndices_.end();
857 while(old != endold && added!= endadded)
859 if(old->local().state()==DELETED) {
864 if(old->global() < added->global() ||
865 (old->global() == added->global()
866 && LocalIndexComparator<TL>::compare(old->local(),added->local())))
868 tempPairs.push_back(*old);
873 tempPairs.push_back(*added);
881 if(old->local().state()!=DELETED) {
882 tempPairs.push_back(*old);
887 while(added!= endadded)
889 tempPairs.push_back(*added);
892 localIndices_ = tempPairs;
897 template<
class TG,
class TL,
int N>
898 inline const IndexPair<TG,TL>&
902 int low=0, high=localIndices_.size()-1, probe=-1;
906 probe = (high + low) / 2;
907 if(global <= localIndices_[probe].global())
916 if( localIndices_[low].global() != global)
917 DUNE_THROW(RangeError,
"Could not find entry of "<<global);
919 return localIndices_[low];
922 template<
class TG,
class TL,
int N>
923 inline const IndexPair<TG,TL>&
927 int low=0, high=localIndices_.size()-1, probe=-1;
931 probe = (high + low) / 2;
932 if(global <= localIndices_[probe].global())
938 return localIndices_[low];
940 template<
class TG,
class TL,
int N>
944 int low=0, high=localIndices_.size()-1, probe=-1;
948 probe = (high + low) / 2;
949 if(localIndices_[probe].global() >= global)
958 if( localIndices_[low].global() != global)
959 DUNE_THROW(RangeError,
"Could not find entry of "<<global);
961 return localIndices_[low];
964 template<
class TG,
class TL,
int N>
968 int low=0, high=localIndices_.size()-1, probe=-1;
972 probe = (high + low) / 2;
973 if(localIndices_[probe].global() >= global)
979 return localIndices_[low];
981 template<
class TG,
class TL,
int N>
982 inline typename ParallelIndexSet<TG,TL,N>::iterator
985 return iterator(*
this, localIndices_.begin());
989 template<
class TG,
class TL,
int N>
990 inline typename ParallelIndexSet<TG,TL,N>::iterator
993 return iterator(*
this,localIndices_.end());
996 template<
class TG,
class TL,
int N>
1000 return localIndices_.begin();
1004 template<
class TG,
class TL,
int N>
1008 return localIndices_.end();
1011 template<
class TG,
class TL,
int N>
1015 DUNE_THROW(InvalidIndexSetState,
"IndexSet has to be in "
1016 <<
"GROUND state for renumberLocal()");
1019 typedef typename ArrayList<IndexPair,N>::iterator iterator;
1020 const const_iterator end_ = end();
1023 for(iterator pair=begin(); pair!=end_; index++, ++pair)
1024 pair->local()=index;
1027 template<
class TG,
class TL,
int N>
1033 template<
class TG,
class TL,
int N>
1036 return localIndices_.size();
1040 GlobalLookupIndexSet<I>::GlobalLookupIndexSet(
const I& indexset,
1042 : indexSet_(indexset), size_(size),
1043 indices_(size_, static_cast<const IndexPair*>(0))
1045 const_iterator end_ = indexSet_.end();
1047 for(const_iterator pair = indexSet_.begin(); pair!=end_; ++pair) {
1048 assert(pair->local()<size_);
1049 indices_[pair->local()] = &(*pair);
1054 GlobalLookupIndexSet<I>::GlobalLookupIndexSet(
const I& indexset)
1055 : indexSet_(indexset), size_(0)
1057 const_iterator end_ = indexSet_.end();
1058 for(const_iterator pair = indexSet_.begin(); pair!=end_; ++pair)
1059 size_=std::max(size_,
static_cast<std::size_t
>(pair->local()));
1061 indices_.resize(++size_, 0);
1063 for(const_iterator pair = indexSet_.begin(); pair!=end_; ++pair)
1064 indices_[pair->local()] = &(*pair);
1068 GlobalLookupIndexSet<I>::~GlobalLookupIndexSet()
1072 inline const IndexPair<typename I::GlobalIndex, typename I::LocalIndex>*
1073 GlobalLookupIndexSet<I>::pair(
const std::size_t& local)
const
1075 return indices_[local];
1079 inline const IndexPair<typename I::GlobalIndex, typename I::LocalIndex>&
1080 GlobalLookupIndexSet<I>::operator[](
const GlobalIndex& global)
const
1082 return indexSet_[global];
1086 typename I::const_iterator GlobalLookupIndexSet<I>::begin()
const
1088 return indexSet_.begin();
1092 typename I::const_iterator GlobalLookupIndexSet<I>::end()
const
1094 return indexSet_.end();
1098 inline size_t GlobalLookupIndexSet<I>::size()
const
1104 inline int GlobalLookupIndexSet<I>::seqNo()
const
1106 return indexSet_.seqNo();
1109 template<
typename TG,
typename TL,
int N,
typename TG1,
typename TL1,
int N1>
1110 bool operator==(
const ParallelIndexSet<TG,TL,N>& idxset,
1111 const ParallelIndexSet<TG1,TL1,N1>& idxset1)
1113 if(idxset.size()!=idxset1.size())
1116 typedef typename ParallelIndexSet<TG1,TL1,N1>::const_iterator Iter1;
1117 Iter iter=idxset.begin();
1118 for(Iter1 iter1=idxset1.begin(); iter1 != idxset1.end(); ++iter, ++iter1) {
1119 if(iter1->global()!=iter->global())
1122 const PI& pi=iter->local(), pi1=iter1->local();
1130 template<
typename TG,
typename TL,
int N,
typename TG1,
typename TL1,
int N1>
1131 bool operator!=(
const ParallelIndexSet<TG,TL,N>& idxset,
1132 const ParallelIndexSet<TG1,TL1,N1>& idxset1)
1134 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:259
A dynamically growing random access list.
Definition: arraylist.hh:61
A constant random access iterator for the Dune::ArrayList class.
Definition: arraylist.hh:380
Base class for Dune-Exceptions.
Definition: exceptions.hh:92
Decorates an index set with the possibility to find a global index that is mapped to a specific local...
Definition: indexset.hh:507
A pair consisting of a global and local index.
Definition: indexset.hh:85
Exception indicating that the index set is not in the expected state.
Definition: indexset.hh:205
The iterator over the pairs.
Definition: indexset.hh:259
Manager class for the mapping between local indices and globally unique indices.
Definition: indexset.hh:218
Reference operator*() const
Dereferencing operator.
Definition: iteratorfacades.hh:490
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:181
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:306
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.
GlobalLookupIndexSet(const ParallelIndexSet &indexset)
Constructor.
TL LocalIndex
the type of the local index.
Definition: indexset.hh:120
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:527
const_iterator begin() const
Get an iterator over the indices positioned at the first index.
const ParallelIndexSetState & state()
Get the state the index set is in.
Definition: indexset.hh:317
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:512
TL LocalIndex
The type of the local index, e.g. ParallelLocalIndex.
Definition: indexset.hh:239
void markAsDeleted(const iterator &position)
Mark an index as deleted.
ParallelIndexSet::LocalIndex LocalIndex
The type of the local index.
Definition: indexset.hh:517
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.
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:226
TG GlobalIndex
the type of the global index.
Definition: indexset.hh:107
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:522
Dune::IndexPair< GlobalIndex, LocalIndex > IndexPair
The type of the pair stored.
Definition: indexset.hh:244
@ RESIZE
Indicates that the index set is currently being resized.
Definition: indexset.hh:190
@ GROUND
The default mode. Indicates that the index set is ready to be used.
Definition: indexset.hh:186
@ arraySize
The size of the individual arrays in the underlying ArrayList.
Definition: indexset.hh:253
std::ostream & operator<<(std::ostream &s, const array< T, N > &e)
Output operator for array.
Definition: array.hh:159
#define DUNE_THROW(E, m)
Definition: exceptions.hh:244
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:231
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:253
Provides classes for use as the local index in ParallelIndexSet.
Dune namespace.
Definition: alignment.hh:14
A traits class describing the mapping of types onto MPI_Datatypes.
Definition: mpitraits.hh:37
Definition of the DUNE_UNUSED macro for the case that config.h is not available.
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentional unused function parameters with.
Definition: unused.hh:18