5#ifndef DUNE_INDEXSET_HH
6#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>
263 :
Father(father), indexSet_(&indexSet)
276 inline void markAsDeleted()
const
279 if(indexSet_->state_ !=
RESIZE)
281 <<
"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_;
616 static bool compare([[maybe_unused]]
const T& t1, [[maybe_unused]]
const T& t2)
622 template<
class TG,
class TL>
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>
658 return a.global_==b.global_;
661 template<
class TG,
class TL>
664 return a.global_!=b.global_;
667 template<
class TG,
class TL>
670 return a.global_<b.global_;
673 template<
class TG,
class TL>
676 return a.global_>b.global_;
679 template<
class TG,
class TL>
682 return a.global_<=b.global_;
685 template<
class TG,
class TL>
688 return a.global_>=b.global_;
691 template<
class TG,
class TL>
697 template<
class TG,
class TL>
703 template<
class TG,
class TL>
709 template<
class TG,
class TL>
715 template<
class TG,
class TL>
721 template<
class TG,
class TL>
729 template<
class TG,
class TL>
731 : global_(global), local_(local){}
733 template<
class TG,
class TL>
735 : global_(global), local_(){}
737 template<
class TG,
class TL>
739 : global_(), local_(){}
741 template<
class TG,
class TL>
746 template<
class TG,
class TL>
751 template<
class TG,
class TL>
756 template<
class TG,
class TL>
761 template<
class TG,
class TL,
int N>
763 : state_(
GROUND), seqNo_(0), deletedEntries_()
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;
847 auto old = localIndices_.begin();
848 auto added = newIndices_.begin();
849 const auto endold = localIndices_.end();
850 const auto endadded = newIndices_.end();
852 while(old != endold && added!= endadded)
854 if(old->local().state()==
DELETED) {
859 if(old->global() < added->global() ||
860 (old->global() == added->global()
863 tempPairs.push_back(*old);
868 tempPairs.push_back(*added);
876 if(old->local().state()!=
DELETED) {
877 tempPairs.push_back(*old);
882 while(added!= endadded)
884 tempPairs.push_back(*added);
887 localIndices_ = tempPairs;
892 template<
class TG,
class TL,
int N>
893 inline const IndexPair<TG,TL>&
897 int low=0, high=localIndices_.size()-1, probe=-1;
901 probe = (high + low) / 2;
902 if(global <= localIndices_[probe].global())
911 if( localIndices_[low].global() != global)
912 DUNE_THROW(RangeError,
"Could not find entry of "<<global);
914 return localIndices_[low];
917 template<
class TG,
class TL,
int N>
918 inline const IndexPair<TG,TL>&
922 int low=0, high=localIndices_.size()-1, probe=-1;
926 probe = (high + low) / 2;
927 if(global <= localIndices_[probe].global())
933 return localIndices_[low];
935 template<
class TG,
class TL,
int N>
939 int low=0, high=localIndices_.size()-1, probe=-1;
943 probe = (high + low) / 2;
944 if(localIndices_[probe].global() >= global)
953 if( localIndices_[low].global() != global)
954 DUNE_THROW(RangeError,
"Could not find entry of "<<global);
956 return localIndices_[low];
959 template<
class TG,
class TL,
int N>
963 int low=0, high=localIndices_.size()-1, probe=-1;
967 probe = (high + low) / 2;
968 if(localIndices_[probe].global() >= global)
977 if( localIndices_[low].global() != global)
982 template<
class TG,
class TL,
int N>
986 int low=0, high=localIndices_.size()-1, probe=-1;
990 probe = (high + low) / 2;
991 if(localIndices_[probe].global() >= global)
997 return localIndices_[low];
999 template<
class TG,
class TL,
int N>
1000 inline typename ParallelIndexSet<TG,TL,N>::iterator
1003 return iterator(*
this, localIndices_.begin());
1007 template<
class TG,
class TL,
int N>
1008 inline typename ParallelIndexSet<TG,TL,N>::iterator
1011 return iterator(*
this,localIndices_.end());
1014 template<
class TG,
class TL,
int N>
1015 inline typename ParallelIndexSet<TG,TL,N>::const_iterator
1018 return localIndices_.begin();
1022 template<
class TG,
class TL,
int N>
1023 inline typename ParallelIndexSet<TG,TL,N>::const_iterator
1026 return localIndices_.end();
1029 template<
class TG,
class TL,
int N>
1033 DUNE_THROW(InvalidIndexSetState,
"IndexSet has to be in "
1034 <<
"GROUND state for renumberLocal()");
1037 const auto end_ = end();
1040 for(
auto pair=begin(); pair!=end_; index++, ++pair)
1041 pair->local()=index;
1044 template<
class TG,
class TL,
int N>
1050 template<
class TG,
class TL,
int N>
1053 return localIndices_.size();
1059 : indexSet_(indexset), size_(size),
1060 indices_(size_, static_cast<const IndexPair*>(0))
1062 const_iterator end_ = indexSet_.end();
1064 for(const_iterator pair = indexSet_.begin(); pair!=end_; ++pair) {
1065 assert(pair->local()<size_);
1066 indices_[pair->local()] = &(*pair);
1072 : indexSet_(indexset), size_(0)
1074 const_iterator end_ = indexSet_.end();
1075 for(const_iterator pair = indexSet_.begin(); pair!=end_; ++pair)
1076 size_=std::max(size_,
static_cast<std::size_t
>(pair->local()));
1078 indices_.resize(++size_, 0);
1080 for(const_iterator pair = indexSet_.begin(); pair!=end_; ++pair)
1081 indices_[pair->local()] = &(*pair);
1089 inline const IndexPair<typename I::GlobalIndex, typename I::LocalIndex>*
1092 return indices_[local];
1096 inline const IndexPair<typename I::GlobalIndex, typename I::LocalIndex>&
1099 return indexSet_[global];
1105 return indexSet_.begin();
1111 return indexSet_.end();
1123 return indexSet_.seqNo();
1126 template<
typename TG,
typename TL,
int N,
typename TG1,
typename TL1,
int N1>
1127 bool operator==(
const ParallelIndexSet<TG,TL,N>& idxset,
1128 const ParallelIndexSet<TG1,TL1,N1>& idxset1)
1130 if(idxset.size()!=idxset1.size())
1132 typedef typename ParallelIndexSet<TG,TL,N>::const_iterator Iter;
1134 Iter iter=idxset.begin();
1135 for(Iter1 iter1=idxset1.begin(); iter1 != idxset1.end(); ++iter, ++iter1) {
1136 if(iter1->global()!=iter->global())
1138 typedef typename ParallelIndexSet<TG,TL,N>::LocalIndex PI;
1139 const PI& pi=iter->local(), pi1=iter1->local();
1147 template<
typename TG,
typename TL,
int N,
typename TG1,
typename TL1,
int N1>
1148 bool operator!=(
const ParallelIndexSet<TG,TL,N>& idxset,
1149 const ParallelIndexSet<TG1,TL1,N1>& idxset1)
1151 return !(idxset==idxset1);
Implements a random-access container that can efficiently change size (similar to std::deque)
A few common exception classes.
Provides classes for use as the local index in ParallelIndexSet.
std::ostream & operator<<(std::ostream &s, const bigunsignedint< k > &x)
Definition bigunsignedint.hh:278
#define DUNE_THROW(E, m)
Definition exceptions.hh:218
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:637
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:683
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:660
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:237
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:705
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:259
IndexPair & operator[](const GlobalIndex &global)
Find the index pair with a specific global id.
static constexpr int arraySize
The size of the individual arrays in the underlying ArrayList.
Definition indexset.hh:252
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.
bool exists(const GlobalIndex &global) const
Find the index pair with a specific global id.
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:296
bool operator()(const IndexPair< TG, TL > &i1, const IndexPair< TG, TL > &i2)
Definition indexset.hh:625
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:120
int seqNo() const
Get the internal sequence number.
static bool compare(const T &t1, const T &t2)
Definition indexset.hh:616
iterator begin()
Get an iterator over the indices positioned at the first index.
Dune::IndexPair< typename I::GlobalIndex, typename I::LocalIndex > IndexPair
Definition indexset.hh:529
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 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:307
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: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.
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:226
TG GlobalIndex
the type of the global index.
Definition indexset.hh:107
int seqNo() const
Get the internal sequence number.
iterator(ParallelIndexSet< TG, TL, N > &indexSet, const Father &father)
Definition indexset.hh:262
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
@ DELETED
Definition localindex.hh:28
Dune namespace.
Definition alignedallocator.hh:13
A random access iterator for the Dune::ArrayList class.
Definition arraylist.hh:255
A constant random access iterator for the Dune::ArrayList class.
Definition arraylist.hh:370
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
A traits class describing the mapping of types onto MPI_Datatypes.
Definition mpitraits.hh:41
Default exception if a function was called while the object is not in a valid state for that function...
Definition exceptions.hh:281
Reference operator*() const
Dereferencing operator.
Definition iteratorfacades.hh:500
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
Decorates an index set with the possibility to find a global index that is mapped to a specific local...
Definition indexset.hh:507
Manager class for the mapping between local indices and globally unique indices.
Definition indexset.hh:218
The iterator over the pairs.
Definition indexset.hh:257
Definition indexset.hh:615
Definition indexset.hh:624