5 #ifndef DUNE_COMMON_PARALLEL_INDEXSET_HH 6 #define DUNE_COMMON_PARALLEL_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>
44 template<
class TG,
class TL>
47 template<
class TG,
class TL>
50 template<
class TG,
class TL>
53 template<
class TG,
class TL>
56 template<
class TG,
class TL>
59 template<
class TG,
class TL>
62 template<
class TG,
class TL>
65 template<
class TG,
class TL>
66 bool operator<(const IndexPair<TG,TL>&,
const TG&);
68 template<
class TG,
class TL>
71 template<
class TG,
class TL>
72 bool operator<=(const IndexPair<TG,TL>&,
const TG&);
74 template<
class TG,
class TL>
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!");
428 inline iterator
begin();
434 inline iterator
end();
465 inline int seqNo()
const;
471 inline size_t size()
const;
483 bool deletedEntries_;
497 template<
class TG,
class TL,
int N>
498 std::ostream& operator<<(std::ostream& os, const ParallelIndexSet<TG,TL,N>& indexSet);
506 class GlobalLookupIndexSet
567 pair(
const std::size_t& local)
const;
587 inline int seqNo()
const;
593 inline size_t size()
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>
636 inline std::ostream& operator<<(std::ostream& os, const IndexPair<TG,TL>& pair)
638 os<<
"{global="<<pair.global_<<
", local="<<pair.local_<<
"}";
642 template<
class TG,
class TL,
int N>
643 inline std::ostream& operator<<(std::ostream& os, const ParallelIndexSet<TG,TL,N>& indexSet)
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>
704 inline bool operator<(const IndexPair<TG,TL>& a,
const TG& b)
709 template<
class TG,
class TL>
715 template<
class TG,
class TL>
716 inline bool operator<=(const IndexPair<TG,TL>& a,
const TG& b)
721 template<
class TG,
class TL>
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>
762 ParallelIndexSet<TG,TL,N>::ParallelIndexSet()
763 : state_(
GROUND), seqNo_(0), deletedEntries_()
766 template<
class TG,
class TL,
int N>
767 void ParallelIndexSet<TG,TL,N>::beginResize()
774 "IndexSet has to be in GROUND state, when " 775 <<
"beginResize() is called!");
779 deletedEntries_ =
false;
782 template<
class TG,
class TL,
int N>
783 inline void ParallelIndexSet<TG,TL,N>::add(
const GlobalIndex& global)
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>
795 inline void ParallelIndexSet<TG,TL,N>::add(
const TG& global,
const TL& local)
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>
807 inline void ParallelIndexSet<TG,TL,N>::markAsDeleted(
const iterator& global)
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>
821 void ParallelIndexSet<TG,TL,N>::endResize() {
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()
861 && LocalIndexComparator<TL>::compare(old->local(),added->local())))
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>&
894 ParallelIndexSet<TG,TL,N>::at(
const TG& global)
const 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>&
919 ParallelIndexSet<TG,TL,N>::operator[](
const TG& global)
const 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>
936 inline IndexPair<TG,TL>& ParallelIndexSet<TG,TL,N>::at(
const TG& global)
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>
960 inline bool ParallelIndexSet<TG,TL,N>::exists (
const TG& global)
const 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>
983 inline IndexPair<TG,TL>& ParallelIndexSet<TG,TL,N>::operator[](
const TG& global)
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
1001 ParallelIndexSet<TG,TL,N>::begin()
1003 return iterator(*
this, localIndices_.begin());
1007 template<
class TG,
class TL,
int N>
1008 inline typename ParallelIndexSet<TG,TL,N>::iterator
1009 ParallelIndexSet<TG,TL,N>::end()
1011 return iterator(*
this,localIndices_.end());
1014 template<
class TG,
class TL,
int N>
1015 inline typename ParallelIndexSet<TG,TL,N>::const_iterator
1016 ParallelIndexSet<TG,TL,N>::begin()
const 1018 return localIndices_.begin();
1022 template<
class TG,
class TL,
int N>
1023 inline typename ParallelIndexSet<TG,TL,N>::const_iterator
1024 ParallelIndexSet<TG,TL,N>::end()
const 1026 return localIndices_.end();
1029 template<
class TG,
class TL,
int N>
1030 void ParallelIndexSet<TG,TL,N>::renumberLocal(){
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>
1045 inline int ParallelIndexSet<TG,TL,N>::seqNo()
const 1050 template<
class TG,
class TL,
int N>
1051 inline size_t ParallelIndexSet<TG,TL,N>::size()
const 1053 return localIndices_.size();
1057 GlobalLookupIndexSet<I>::GlobalLookupIndexSet(
const I& indexset,
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);
1071 GlobalLookupIndexSet<I>::GlobalLookupIndexSet(
const I& indexset)
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<std::size_t>(size_,pair->local());
1078 indices_.resize(++size_, 0);
1080 for(const_iterator pair = indexSet_.begin(); pair!=end_; ++pair)
1081 indices_[pair->local()] = &(*pair);
1085 GlobalLookupIndexSet<I>::~GlobalLookupIndexSet()
1089 inline const IndexPair<typename I::GlobalIndex, typename I::LocalIndex>*
1090 GlobalLookupIndexSet<I>::pair(
const std::size_t& local)
const 1092 return indices_[local];
1096 inline const IndexPair<typename I::GlobalIndex, typename I::LocalIndex>&
1097 GlobalLookupIndexSet<I>::operator[](
const GlobalIndex& global)
const 1099 return indexSet_[global];
1103 typename I::const_iterator GlobalLookupIndexSet<I>::begin()
const 1105 return indexSet_.begin();
1109 typename I::const_iterator GlobalLookupIndexSet<I>::end()
const 1111 return indexSet_.end();
1115 inline size_t GlobalLookupIndexSet<I>::size()
const 1121 inline int GlobalLookupIndexSet<I>::seqNo()
const 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;
1133 typedef typename ParallelIndexSet<TG1,TL1,N1>::const_iterator Iter1;
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);
1159 #endif // DUNE_COMMON_PARALLEL_INDEXSET_HH constexpr 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:706
bool operator!=(const IndexPair< TG, TL > &, const TG &)
Definition: indexset.hh:698
ParallelIndexSet::const_iterator const_iterator
The iterator over the index pairs.
Definition: indexset.hh:527
const IndexPair & operator[](const GlobalIndex &global) const
Find the index pair with a specific global id.
const_iterator begin() const
Get an iterator over the indices positioned at the first index.
static bool compare([[maybe_unused]] const T &t1, [[maybe_unused]] const T &t2)
Definition: indexset.hh:616
Dune::IndexPair< typename I::GlobalIndex, typename I::LocalIndex > IndexPair
Definition: indexset.hh:529
const GlobalIndex & global() const
Get the global index.
bool operator==(const IndexPair< TG, TL > &, const TG &)
Definition: indexset.hh:692
bool operator()(const IndexPair< TG, TL > &i1, const IndexPair< TG, TL > &i2)
Definition: indexset.hh:625
constexpr Reference operator*() const
Dereferencing operator.
Definition: iteratorfacades.hh:501
IndexPair & operator[](const GlobalIndex &global)
Find the index pair with a specific global id.
~GlobalLookupIndexSet()
Destructor.
void endResize()
Indicate that the resizing finishes.
int seqNo() const
Get the internal sequence number.
iterator begin()
Get an iterator over the indices positioned at the first index.
const IndexPair * pair(const std::size_t &local) const
Get the index pair corresponding to a local index.
void add(const GlobalIndex &global)
Add an new index to the set.
const ParallelIndexSetState & state()
Get the state the index set is in.
Definition: indexset.hh:307
ParallelIndexSet()
Constructor.
TL LocalIndex
The type of the local index, e.g. ParallelLocalIndex.
Definition: indexset.hh:239
Decorates an index set with the possibility to find a global index that is mapped to a specific local...
Definition: indexset.hh:208
void setLocal(int index)
Set the local index.
ParallelIndexSet::LocalIndex LocalIndex
The type of the local index.
Definition: indexset.hh:517
Provides classes for use as the local index in ParallelIndexSet.
Dune namespace
Definition: alignedallocator.hh:12
void renumberLocal()
Renumbers the local index numbers.
TG GlobalIndex
the type of the global index.
Definition: indexset.hh:107
ParallelIndexSet::GlobalIndex GlobalIndex
The type of the global index.
Definition: indexset.hh:522
ArrayList< IndexPair, N >::const_iterator const_iterator
The constant iterator over the pairs.
Definition: indexset.hh:296
iterator end()
Get an iterator over the indices positioned after the last index.
constexpr 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:684
ConstArrayListIterator< MemberType, N, A > const_iterator
A constant random access iterator.
Definition: arraylist.hh:110
A constant random access iterator for the Dune::ArrayList class.
Definition: arraylist.hh:22
An index present on the local process.
Definition: localindex.hh:34
#define DUNE_THROW(E,...)
Definition: exceptions.hh:314
The iterator over the pairs.
Definition: indexset.hh:255
TL LocalIndex
the type of the local index.
Definition: indexset.hh:120
constexpr auto operator!=(const HybridMultiIndex< S... > &lhs, const HybridMultiIndex< T... > &rhs)
Compare two HybridMultiIndexs for inequality.
Definition: hybridmultiindex.hh:441
constexpr bool operator==(const HybridMultiIndex< S... > &lhs, const HybridMultiIndex< T... > &rhs)
Compare two HybridMultiIndexs for value equality.
Definition: hybridmultiindex.hh:404
static constexpr int arraySize
The size of the individual arrays in the underlying ArrayList.
Definition: indexset.hh:252
I ParallelIndexSet
The type of the index set.
Definition: indexset.hh:512
IndexPair()
Construct a new Pair.
Implements a random-access container that can efficiently change size (similar to std::deque) ...
A few common exception classes.
const_iterator end() const
Get an iterator over the indices positioned after the last index.
int seqNo() const
Get the internal sequence number.
LocalIndex & local()
Get the local index.
size_t size() const
Get the total number (public and nonpublic) indices.
Exception indicating that the index set is not in the expected state.
Definition: indexset.hh:205
The default mode. Indicates that the index set is ready to be used.
Definition: indexset.hh:186
Traits classes for mapping types onto MPI_Datatype.
size_t size() const
Get the total number (public and nonpublic) indices.
iterator(ParallelIndexSet< TG, TL, N > &indexSet, const Father &father)
Definition: indexset.hh:262
ParallelIndexSetState
The states the index set can be in.
Definition: indexset.hh:180
bool exists(const GlobalIndex &global) const
Find the index pair with a specific global id.
A traits class describing the mapping of types onto MPI_Datatypes.
Definition: bigunsignedint.hh:29
void beginResize()
Indicate that the index set is to be resized.
Default exception if a function was called while the object is not in a valid state for that function...
Definition: exceptions.hh:375
void markAsDeleted(const iterator &position)
Mark an index as deleted.
A random access iterator for the Dune::ArrayList class.
Definition: arraylist.hh:19
IndexPair & at(const GlobalIndex &global)
Find the index pair with a specific global id.
Definition: indexset.hh:623
Definition: localindex.hh:28
Dune::IndexPair< GlobalIndex, LocalIndex > IndexPair
The type of the pair stored.
Definition: indexset.hh:244
Manager class for the mapping between local indices and globally unique indices.
Definition: indexset.hh:217
Indicates that the index set is currently being resized.
Definition: indexset.hh:190
A pair consisting of a global and local index.
Definition: indexset.hh:31
TG GlobalIndex
the type of the global index. This type has to provide at least a operator< for sorting.
Definition: indexset.hh:226
GlobalLookupIndexSet(const ParallelIndexSet &indexset, std::size_t size)
Constructor.
A dynamically growing random access list.
Definition: arraylist.hh:61
Definition: indexset.hh:614