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>
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>
147 inline const GlobalIndex&
global()
const;
154 inline LocalIndex&
local();
161 inline const LocalIndex&
local()
const;
216 template<
typename TG,
typename TL,
int N=100>
265 : Father(father), indexSet_(&indexSet)
269 : Father(other), indexSet_(other.indexSet_)
275 indexSet_ = other.indexSet_;
289 if(indexSet_->state_ !=
RESIZE)
290 DUNE_THROW(InvalidIndexSetState,
"Indices can only be removed "
291 <<
"while in RESIZE state!");
305 ArrayList<IndexPair,N>::const_iterator
337 inline
void add(const GlobalIndex& global) throw(InvalidIndexSetState);
347 inline
void add(const GlobalIndex& global, const LocalIndex& local)
348 throw(InvalidIndexSetState);
358 throw(InvalidIndexSetState);
372 void endResize() throw(InvalidIndexSetState);
385 operator[](const GlobalIndex& global);
397 at(const GlobalIndex& global);
409 inline const IndexPair&
410 operator[](const GlobalIndex& global) const;
421 inline const IndexPair&
422 at(const GlobalIndex& global) const;
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>
537 GlobalLookupIndexSet(
const ParallelIndexSet& indexset, std::size_t
size);
544 GlobalLookupIndexSet(
const ParallelIndexSet& indexset);
549 ~GlobalLookupIndexSet();
560 inline const IndexPair&
566 inline const IndexPair*
567 pair(
const std::size_t& local)
const;
573 inline const_iterator
begin()
const;
579 inline const_iterator
end()
const;
587 inline int seqNo()
const;
593 inline size_t size()
const;
598 const ParallelIndexSet& indexSet_;
608 std::vector<const IndexPair*> indices_;
616 static bool compare(
const T& t1,
const T& t2){
623 template<
class TG,
class TL>
636 template<
class TG,
class TL>
637 inline std::ostream& operator<<(std::ostream& os, const IndexPair<TG,TL>& pair)
639 os<<
"{global="<<pair.global_<<
", local="<<pair.local_<<
"}";
643 template<
class TG,
class TL,
int N>
644 inline std::ostream& operator<<(std::ostream& os, const ParallelIndexSet<TG,TL,N>& indexSet)
647 Iterator
end = indexSet.end();
649 for(Iterator index = indexSet.begin(); index !=
end; ++index)
656 template<
class TG,
class TL>
659 return a.global_==b.global_;
662 template<
class TG,
class TL>
665 return a.global_!=b.global_;
668 template<
class TG,
class TL>
671 return a.global_<b.global_;
674 template<
class TG,
class TL>
677 return a.global_>b.global_;
680 template<
class TG,
class TL>
683 return a.global_<=b.global_;
686 template<
class TG,
class TL>
689 return a.global_>=b.global_;
692 template<
class TG,
class TL>
698 template<
class TG,
class TL>
704 template<
class TG,
class TL>
705 inline bool operator<(const IndexPair<TG,TL>& a,
const TG& b)
710 template<
class TG,
class TL>
716 template<
class TG,
class TL>
717 inline bool operator<=(const IndexPair<TG,TL>& a,
const TG& b)
722 template<
class TG,
class TL>
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>
763 ParallelIndexSet<TG,TL,N>::ParallelIndexSet()
764 : state_(
GROUND), seqNo_(0)
767 template<
class TG,
class TL,
int N>
768 void ParallelIndexSet<TG,TL,N>::beginResize() throw(InvalidIndexSetState)
775 "IndexSet has to be in GROUND state, when "
776 <<
"beginResize() is called!");
780 deletedEntries_ =
false;
783 template<
class TG,
class TL,
int N>
784 inline void ParallelIndexSet<TG,TL,N>::add(
const GlobalIndex& global)
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>
797 inline void ParallelIndexSet<TG,TL,N>::add(
const TG& global,
const TL& local)
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>
810 inline void ParallelIndexSet<TG,TL,N>::markAsDeleted(
const iterator& global)
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>
824 void ParallelIndexSet<TG,TL,N>::endResize() throw(InvalidIndexSetState){
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>&
899 ParallelIndexSet<TG,TL,N>::at(
const TG& global)
const
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>&
924 ParallelIndexSet<TG,TL,N>::operator[](
const TG& global)
const
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>
941 inline IndexPair<TG,TL>& ParallelIndexSet<TG,TL,N>::at(
const TG& global)
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>
965 inline IndexPair<TG,TL>& ParallelIndexSet<TG,TL,N>::operator[](
const TG& global)
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
983 ParallelIndexSet<TG,TL,N>::begin()
985 return iterator(*
this, localIndices_.begin());
989 template<
class TG,
class TL,
int N>
990 inline typename ParallelIndexSet<TG,TL,N>::iterator
991 ParallelIndexSet<TG,TL,N>::end()
993 return iterator(*
this,localIndices_.end());
996 template<
class TG,
class TL,
int N>
997 inline typename ParallelIndexSet<TG,TL,N>::const_iterator
998 ParallelIndexSet<TG,TL,N>::begin()
const
1000 return localIndices_.begin();
1004 template<
class TG,
class TL,
int N>
1005 inline typename ParallelIndexSet<TG,TL,N>::const_iterator
1006 ParallelIndexSet<TG,TL,N>::end()
const
1008 return localIndices_.end();
1011 template<
class TG,
class TL,
int N>
1012 void ParallelIndexSet<TG,TL,N>::renumberLocal(){
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>
1028 inline int ParallelIndexSet<TG,TL,N>::seqNo()
const
1033 template<
class TG,
class TL,
int N>
1034 inline size_t ParallelIndexSet<TG,TL,N>::size()
const
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())
1115 typedef typename ParallelIndexSet<TG,TL,N>::const_iterator Iter;
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())
1121 typedef typename ParallelIndexSet<TG,TL,N>::LocalIndex PI;
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);
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
void markAsDeleted(const iterator &position)
Mark an index as deleted.
IndexPair & at(const GlobalIndex &global)
Find the index pair with a specific global id.
ParallelIndexSet()
Constructor.
Manager class for the mapping between local indices and globally unique indices.
Definition: indexset.hh:217
bool operator()(const IndexPair< TG, TL > &i1, const IndexPair< TG, TL > &i2)
Definition: indexset.hh:626
bool operator==(const IndexPair< TG, TL > &, const TG &)
Definition: indexset.hh:693
void endResize()
Indicate that the resizing finishes.
iterator & operator==(const iterator &other)
Definition: indexset.hh:272
Dune namespace.
Definition: alignment.hh:13
IndexPair & operator[](const GlobalIndex &global)
Find the index pair with a specific global id.
Definition: indexset.hh:624
size_t size() const
Get the total number (public and nonpublic) indices.
A few common exception classes.
IndexPair()
Construct a new Pair.
iterator end()
Get an iterator over the indices positioned after the last index.
The size of the individual arrays in the underlying ArrayList.
Definition: indexset.hh:253
void beginResize()
Indicate that the index set is to be resized. If index set was not in ParallelIndexSetState::GROUND m...
std::size_t size_
The size of the buffer.
Definition: variablesizecommunicator.hh:132
A constant random access iterator for the Dune::ArrayList class.
Definition: arraylist.hh:21
Reference operator*() const
Dereferencing operator.
Definition: iteratorfacades.hh:490
ParallelIndexSetState
The states the index set can be in.
Definition: indexset.hh:180
Exception indicating that the index set is not in the expected state.
Definition: indexset.hh:205
iterator begin()
Get an iterator over the indices positioned at the first index.
Provides classes for use as the local index in ParallelIndexSet.
ParallelIndexSet::const_iterator const_iterator
The iterator over the index pairs.
Definition: indexset.hh:527
ArrayList< IndexPair, N >::const_iterator const_iterator
The constant iterator over the pairs.
Definition: indexset.hh:306
A pair consisting of a global and local index.
Definition: indexset.hh:31
Implements a random-access container that can efficiently change size (similar to std::deque) ...
A traits class describing the mapping of types onto MPI_Datatypes.
Definition: bigunsignedint.hh:29
Definition: localindex.hh:27
bool operator>=(const array< T, N > &a, const array< T, N > &b)
Definition: array.hh:151
Definition: indexset.hh:614
const ParallelIndexSetState & state()
Get the state the index set is in.
Definition: indexset.hh:317
Indicates that the index set is currently being resized.
Definition: indexset.hh:190
iterator(const iterator &other)
Definition: indexset.hh:268
iterator(ParallelIndexSet< TG, TL, N > &indexSet, const Father &father)
Definition: indexset.hh:264
int seqNo() const
Get the internal sequence number.
static bool compare(const T &t1, const T &t2)
Definition: indexset.hh:616
bool operator>(const array< T, N > &a, const array< T, N > &b)
Definition: array.hh:139
ParallelIndexSet::LocalIndex LocalIndex
The type of the local index.
Definition: indexset.hh:517
A random access iterator for the Dune::ArrayList class.
Definition: arraylist.hh:18
void add(const GlobalIndex &global)
Add an new index to the set.
TG GlobalIndex
the type of the global index. This type has to provide at least a operator< for sorting.
Definition: indexset.hh:226
#define DUNE_THROW(E, m)
Definition: exceptions.hh:244
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
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
Definition of the DUNE_UNUSED macro for the case that config.h is not available.
I ParallelIndexSet
The type of the index set.
Definition: indexset.hh:512
Dune::IndexPair< GlobalIndex, LocalIndex > IndexPair
The type of the pair stored.
Definition: indexset.hh:244
The iterator over the pairs.
Definition: indexset.hh:257
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentional unused function parameters with.
Definition: unused.hh:18
Dune::IndexPair< typename I::GlobalIndex, typename I::LocalIndex > IndexPair
Definition: indexset.hh:529
TL LocalIndex
the type of the local index.
Definition: indexset.hh:120
LocalIndex & local()
Get the local index.
A dynamically growing random access list.
Definition: arraylist.hh:60
The default mode. Indicates that the index set is ready to be used.
Definition: indexset.hh:186
void setLocal(int index)
Set the local index.
const GlobalIndex & global() const
Get the global index.
Base class for Dune-Exceptions.
Definition: exceptions.hh:92
bool operator!=(const IndexPair< TG, TL > &, const TG &)
Definition: indexset.hh:699
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