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>
43 template<
class TG,
class TL>
46 template<
class TG,
class TL>
49 template<
class TG,
class TL>
52 template<
class TG,
class TL>
55 template<
class TG,
class TL>
58 template<
class TG,
class TL>
61 template<
class TG,
class TL>
64 template<
class TG,
class TL>
65 bool operator<(const IndexPair<TG,TL>&,
const TG&);
67 template<
class TG,
class TL>
70 template<
class TG,
class TL>
71 bool operator<=(const IndexPair<TG,TL>&,
const TG&);
73 template<
class TG,
class TL>
82 template<
class TG,
class TL>
146 inline const GlobalIndex&
global()
const;
153 inline LocalIndex&
local();
160 inline const LocalIndex&
local()
const;
215 template<
typename TG,
typename TL,
int N=100>
264 : Father(father), indexSet_(&indexSet)
268 : Father(other), indexSet_(other.indexSet_)
274 indexSet_ = other.indexSet_;
288 if(indexSet_->state_ !=
RESIZE)
289 DUNE_THROW(InvalidIndexSetState,
"Indices can only be removed "
290 <<
"while in RESIZE state!");
304 ArrayList<IndexPair,N>::const_iterator
336 inline
void add(const GlobalIndex& global) throw(InvalidIndexSetState);
346 inline
void add(const GlobalIndex& global, const LocalIndex& local)
347 throw(InvalidIndexSetState);
357 throw(InvalidIndexSetState);
371 void endResize() throw(InvalidIndexSetState);
384 operator[](const GlobalIndex& global);
396 at(const GlobalIndex& global);
408 inline const IndexPair&
409 operator[](const GlobalIndex& global) const;
420 inline const IndexPair&
421 at(const GlobalIndex& global) const;
427 inline iterator
begin();
433 inline iterator
end();
464 inline
int seqNo() const;
470 inline
size_t size() const;
482 bool deletedEntries_;
496 template<class TG, class TL,
int N>
536 GlobalLookupIndexSet(
const ParallelIndexSet& indexset, std::size_t
size);
543 GlobalLookupIndexSet(
const ParallelIndexSet& indexset);
548 ~GlobalLookupIndexSet();
559 inline const IndexPair&
565 inline const IndexPair*
566 pair(
const std::size_t& local)
const;
572 inline const_iterator
begin()
const;
578 inline const_iterator
end()
const;
586 inline int seqNo()
const;
592 inline size_t size()
const;
597 const ParallelIndexSet& indexSet_;
607 std::vector<const IndexPair*> indices_;
615 static bool compare(
const T& t1,
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)
766 template<
class TG,
class TL,
int N>
767 void ParallelIndexSet<TG,TL,N>::beginResize() throw(InvalidIndexSetState)
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)
784 throw(InvalidIndexSetState)
789 DUNE_THROW(InvalidIndexSetState,
"Indices can only be added "
790 <<
"while in RESIZE state!");
792 newIndices_.push_back(IndexPair(global));
795 template<
class TG,
class TL,
int N>
796 inline void ParallelIndexSet<TG,TL,N>::add(
const TG& global,
const TL& local)
797 throw(InvalidIndexSetState)
802 DUNE_THROW(InvalidIndexSetState,
"Indices can only be added "
803 <<
"while in RESIZE state!");
805 newIndices_.push_back(IndexPair(global,local));
808 template<
class TG,
class TL,
int N>
809 inline void ParallelIndexSet<TG,TL,N>::markAsDeleted(
const iterator& global)
810 throw(InvalidIndexSetState){
814 DUNE_THROW(InvalidIndexSetState,
"Indices can only be removed "
815 <<
"while in RESIZE state!");
817 deletedEntries_ =
true;
819 global.markAsDeleted();
822 template<
class TG,
class TL,
int N>
823 void ParallelIndexSet<TG,TL,N>::endResize() throw(InvalidIndexSetState){
827 DUNE_THROW(InvalidIndexSetState,
"endResize called while not "
828 <<
"in RESIZE state!");
831 std::sort(newIndices_.begin(), newIndices_.end(), IndexSetSortFunctor<TG,TL>());
838 template<
class TG,
class TL,
int N>
839 inline void ParallelIndexSet<TG,TL,N>::merge(){
840 if(localIndices_.size()==0)
842 localIndices_=newIndices_;
845 else if(newIndices_.size()>0 || deletedEntries_)
847 ArrayList<IndexPair,N> tempPairs;
848 typedef typename ArrayList<IndexPair,N>::iterator iterator;
849 typedef typename ArrayList<IndexPair,N>::const_iterator const_iterator;
851 iterator old=localIndices_.begin();
852 iterator added=newIndices_.begin();
853 const const_iterator endold=localIndices_.end();
854 const const_iterator endadded=newIndices_.end();
856 while(old != endold && added!= endadded)
858 if(old->local().state()==
DELETED) {
863 if(old->global() < added->global() ||
864 (old->global() == added->global()
865 && LocalIndexComparator<TL>::compare(old->local(),added->local())))
867 tempPairs.push_back(*old);
872 tempPairs.push_back(*added);
880 if(old->local().state()!=
DELETED) {
881 tempPairs.push_back(*old);
886 while(added!= endadded)
888 tempPairs.push_back(*added);
891 localIndices_ = tempPairs;
896 template<
class TG,
class TL,
int N>
897 inline const IndexPair<TG,TL>&
898 ParallelIndexSet<TG,TL,N>::at(
const TG& global)
const
901 int low=0, high=localIndices_.size()-1, probe=-1;
905 probe = (high + low) / 2;
906 if(global <= localIndices_[probe].global())
915 if( localIndices_[low].global() != global)
916 DUNE_THROW(RangeError,
"Could not find entry of "<<global);
918 return localIndices_[low];
921 template<
class TG,
class TL,
int N>
922 inline const IndexPair<TG,TL>&
923 ParallelIndexSet<TG,TL,N>::operator[](
const TG& global)
const
926 int low=0, high=localIndices_.size()-1, probe=-1;
930 probe = (high + low) / 2;
931 if(global <= localIndices_[probe].global())
937 return localIndices_[low];
939 template<
class TG,
class TL,
int N>
940 inline IndexPair<TG,TL>& ParallelIndexSet<TG,TL,N>::at(
const TG& global)
943 int low=0, high=localIndices_.size()-1, probe=-1;
947 probe = (high + low) / 2;
948 if(localIndices_[probe].global() >= global)
957 if( localIndices_[low].global() != global)
958 DUNE_THROW(RangeError,
"Could not find entry of "<<global);
960 return localIndices_[low];
963 template<
class TG,
class TL,
int N>
964 inline IndexPair<TG,TL>& ParallelIndexSet<TG,TL,N>::operator[](
const TG& global)
967 int low=0, high=localIndices_.size()-1, probe=-1;
971 probe = (high + low) / 2;
972 if(localIndices_[probe].global() >= global)
978 return localIndices_[low];
980 template<
class TG,
class TL,
int N>
981 inline typename ParallelIndexSet<TG,TL,N>::iterator
982 ParallelIndexSet<TG,TL,N>::begin()
984 return iterator(*
this, localIndices_.begin());
988 template<
class TG,
class TL,
int N>
989 inline typename ParallelIndexSet<TG,TL,N>::iterator
990 ParallelIndexSet<TG,TL,N>::end()
992 return iterator(*
this,localIndices_.end());
995 template<
class TG,
class TL,
int N>
996 inline typename ParallelIndexSet<TG,TL,N>::const_iterator
997 ParallelIndexSet<TG,TL,N>::begin()
const
999 return localIndices_.begin();
1003 template<
class TG,
class TL,
int N>
1004 inline typename ParallelIndexSet<TG,TL,N>::const_iterator
1005 ParallelIndexSet<TG,TL,N>::end()
const
1007 return localIndices_.end();
1010 template<
class TG,
class TL,
int N>
1011 void ParallelIndexSet<TG,TL,N>::renumberLocal(){
1014 DUNE_THROW(InvalidIndexSetState,
"IndexSet has to be in "
1015 <<
"GROUND state for renumberLocal()");
1018 typedef typename ArrayList<IndexPair,N>::iterator iterator;
1019 const const_iterator end_ = end();
1022 for(iterator pair=begin(); pair!=end_; index++, ++pair)
1023 pair->local()=index;
1026 template<
class TG,
class TL,
int N>
1027 inline int ParallelIndexSet<TG,TL,N>::seqNo()
const
1032 template<
class TG,
class TL,
int N>
1033 inline size_t ParallelIndexSet<TG,TL,N>::size()
const
1035 return localIndices_.size();
1039 GlobalLookupIndexSet<I>::GlobalLookupIndexSet(
const I& indexset,
1041 : indexSet_(indexset),
size_(size),
1042 indices_(
size_, static_cast<const IndexPair*>(0))
1044 const_iterator end_ = indexSet_.end();
1046 for(const_iterator pair = indexSet_.begin(); pair!=end_; ++pair) {
1047 assert(pair->local()<
size_);
1048 indices_[pair->local()] = &(*pair);
1053 GlobalLookupIndexSet<I>::GlobalLookupIndexSet(
const I& indexset)
1054 : indexSet_(indexset),
size_(0)
1056 const_iterator end_ = indexSet_.end();
1057 for(const_iterator pair = indexSet_.begin(); pair!=end_; ++pair)
1058 size_=std::max(
size_,static_cast<std::size_t>(pair->local()));
1060 indices_.resize(++
size_, 0);
1062 for(const_iterator pair = indexSet_.begin(); pair!=end_; ++pair)
1063 indices_[pair->local()] = &(*pair);
1067 GlobalLookupIndexSet<I>::~GlobalLookupIndexSet()
1071 inline const IndexPair<typename I::GlobalIndex, typename I::LocalIndex>*
1072 GlobalLookupIndexSet<I>::pair(
const std::size_t& local)
const
1074 return indices_[local];
1078 inline const IndexPair<typename I::GlobalIndex, typename I::LocalIndex>&
1079 GlobalLookupIndexSet<I>::operator[](
const GlobalIndex& global)
const
1081 return indexSet_[global];
1085 typename I::const_iterator GlobalLookupIndexSet<I>::begin()
const
1087 return indexSet_.begin();
1091 typename I::const_iterator GlobalLookupIndexSet<I>::end()
const
1093 return indexSet_.end();
1097 inline size_t GlobalLookupIndexSet<I>::size()
const
1103 inline int GlobalLookupIndexSet<I>::seqNo()
const
1105 return indexSet_.seqNo();
1108 template<
typename TG,
typename TL,
int N,
typename TG1,
typename TL1,
int N1>
1109 bool operator==(
const ParallelIndexSet<TG,TL,N>& idxset,
1110 const ParallelIndexSet<TG1,TL1,N1>& idxset1)
1112 if(idxset.size()!=idxset1.size())
1114 typedef typename ParallelIndexSet<TG,TL,N>::const_iterator Iter;
1115 typedef typename ParallelIndexSet<TG1,TL1,N1>::const_iterator Iter1;
1116 Iter iter=idxset.begin();
1117 for(Iter1 iter1=idxset1.begin(); iter1 != idxset1.end(); ++iter, ++iter1) {
1118 if(iter1->global()!=iter->global())
1120 typedef typename ParallelIndexSet<TG,TL,N>::LocalIndex PI;
1121 const PI& pi=iter->local(), pi1=iter1->local();
1129 template<
typename TG,
typename TL,
int N,
typename TG1,
typename TL1,
int N1>
1130 bool operator!=(
const ParallelIndexSet<TG,TL,N>& idxset,
1131 const ParallelIndexSet<TG1,TL1,N1>& idxset1)
1133 return !(idxset==idxset1);
iterator & operator==(const iterator &other)
Definition: indexset.hh:271
size_t size() const
Get the total number (public and nonpublic) indices.
bool operator!=(const IndexPair< TG, TL > &, const TG &)
Definition: indexset.hh:698
ParallelIndexSetState
The states the index set can be in.
Definition: indexset.hh:179
iterator(ParallelIndexSet< TG, TL, N > &indexSet, const Father &father)
Definition: indexset.hh:263
const GlobalIndex & global() const
Get the global index.
IndexPair & operator[](const GlobalIndex &global)
Find the index pair with a specific global id.
Exception indicating that the index set is not in the expected state.
Definition: indexset.hh:204
TG GlobalIndex
the type of the global index. This type has to provide at least a operator< for sorting.
Definition: indexset.hh:225
A few common exception classes.
The size of the individual arrays in the underlying ArrayList.
Definition: indexset.hh:252
Provides classes for use as the local index in ParallelIndexSet.
Reference operator*() const
Dereferencing operator.
Definition: iteratorfacades.hh:489
void renumberLocal()
Renumbers the local index numbers.
TG GlobalIndex
the type of the global index.
Definition: indexset.hh:106
A random access iterator for the Dune::ArrayList class.
Definition: arraylist.hh:17
TL LocalIndex
The type of the local index, e.g. ParallelLocalIndex.
Definition: indexset.hh:238
IndexPair()
Construct a new Pair.
Definition: indexset.hh:623
Dune::IndexPair< GlobalIndex, LocalIndex > IndexPair
The type of the pair stored.
Definition: indexset.hh:243
void markAsDeleted(const iterator &position)
Mark an index as deleted.
IndexPair & at(const GlobalIndex &global)
Find the index pair with a specific global id.
Indicates that the index set is currently being resized.
Definition: indexset.hh:189
A traits class describing the mapping of types onto MPI_Datatypes.
Definition: bigunsignedint.hh:30
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:672
void endResize()
Indicate that the resizing finishes.
std::size_t size_
The size of the buffer.
Definition: variablesizecommunicator.hh:132
TL LocalIndex
the type of the local index.
Definition: indexset.hh:119
Definition of the DUNE_UNUSED macro for the case that config.h is not available.
Dune namespace.
Definition: alignment.hh:9
Implements a random-access container that can efficiently change size (similar to std::deque) ...
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:230
LocalIndex & local()
Get the local index.
A dynamically growing random access list.
Definition: arraylist.hh:59
The default mode. Indicates that the index set is ready to be used.
Definition: indexset.hh:185
A constant random access iterator for the Dune::ArrayList class.
Definition: arraylist.hh:20
Dune::IndexPair< typename I::GlobalIndex, typename I::LocalIndex > IndexPair
Definition: indexset.hh:528
Default exception if a function was called while the object is not in a valid state for that function...
Definition: exceptions.hh:306
Definition: localindex.hh:26
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:252
iterator(const iterator &other)
Definition: indexset.hh:267
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:694
ParallelIndexSet()
Constructor.
bool operator()(const IndexPair< TG, TL > &i1, const IndexPair< TG, TL > &i2)
Definition: indexset.hh:625
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentional unused function parameters with.
Definition: unused.hh:18
A pair consisting of a global and local index.
Definition: indexset.hh:30
ParallelIndexSet::LocalIndex LocalIndex
The type of the local index.
Definition: indexset.hh:516
bool operator==(const IndexPair< TG, TL > &, const TG &)
Definition: indexset.hh:692
ParallelIndexSet::GlobalIndex GlobalIndex
The type of the global index.
Definition: indexset.hh:521
const ParallelIndexSetState & state()
Get the state the index set is in.
Definition: indexset.hh:316
Definition: indexset.hh:613
iterator end()
Get an iterator over the indices positioned after the last index.
I ParallelIndexSet
The type of the index set.
Definition: indexset.hh:511
Decorates an index set with the possibility to find a global index that is mapped to a specific local...
Definition: indexset.hh:207
int seqNo() const
Get the internal sequence number.
void setLocal(int index)
Set the local index.
void beginResize()
Indicate that the index set is to be resized. If index set was not in ParallelIndexSetState::GROUND m...
The iterator over the pairs.
Definition: indexset.hh:256
static bool compare(const T &t1, const T &t2)
Definition: indexset.hh:615
iterator begin()
Get an iterator over the indices positioned at the first index.
void add(const GlobalIndex &global)
Add an new index to the set.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:243
ArrayList< IndexPair, N >::const_iterator const_iterator
The constant iterator over the pairs.
Definition: indexset.hh:305
ParallelIndexSet::const_iterator const_iterator
The iterator over the index pairs.
Definition: indexset.hh:526
Manager class for the mapping between local indices and globally unique indices.
Definition: indexset.hh:216