16 #ifndef dealii_index_set_h 17 #define dealii_index_set_h 19 #include <deal.II/base/config.h> 20 #include <deal.II/base/utilities.h> 21 #include <deal.II/base/exceptions.h> 22 #include <deal.II/base/thread_management.h> 23 #include <boost/serialization/vector.hpp> 29 #ifdef DEAL_II_WITH_TRILINOS 30 # include <Epetra_Map.h> 33 #if defined(DEAL_II_WITH_MPI) || defined(DEAL_II_WITH_PETSC) 37 # ifndef MPI_COMM_WORLD 38 # define MPI_COMM_WORLD 0 42 DEAL_II_NAMESPACE_OPEN
133 #ifdef DEAL_II_WITH_TRILINOS 137 explicit IndexSet(
const Epetra_Map &map);
186 template <
typename ForwardIterator>
188 const ForwardIterator &
end);
206 const unsigned int offset = 0);
352 template <
typename VectorType>
359 template <
class StreamType>
360 void print(StreamType &out)
const;
366 void write(std::ostream &out)
const;
372 void read(std::istream &in);
386 #ifdef DEAL_II_WITH_TRILINOS 416 const bool overlapping =
false)
const;
427 <<
"The global index " << arg1
428 <<
" is not an element of this set.");
434 template <
class Archive>
435 void serialize (Archive &ar,
const unsigned int version);
608 typedef std::ptrdiff_t difference_type;
692 typedef std::ptrdiff_t difference_type;
796 inline bool operator< (
const Range &range_1,
797 const Range &range_2)
799 return ((range_1.begin < range_2.begin)
801 ((range_1.begin == range_2.begin)
803 (range_1.end < range_2.end)));
808 return x.end < y.end;
814 return (x.nth_index_in_set+(x.end-x.begin) <
815 y.nth_index_in_set+(y.end-y.begin));
819 inline bool operator== (
const Range &range_1,
820 const Range &range_2)
822 return ((range_1.begin == range_2.begin)
824 (range_1.end == range_2.end));
827 static std::size_t memory_consumption ()
829 return sizeof(
Range);
836 template <
class Archive>
837 void serialize (Archive &ar,
const unsigned int version);
939 range_idx(
numbers::invalid_dof_index)
948 index_set (other.index_set),
949 range_idx(other.range_idx)
962 return index_set->ranges[range_idx].end - index_set->ranges[range_idx].begin;
971 return index_set !=
nullptr && range_idx < index_set->n_intervals();
982 index_set->ranges[range_idx].begin);
994 if (range_idx < index_set->
ranges.size()-1)
997 return index_set->end();
1008 return index_set->ranges[range_idx].end-1;
1031 ExcMessage(
"Can not compare accessors pointing to different IndexSets"));
1042 ExcMessage(
"Can not compare accessors pointing to different IndexSets"));
1052 ExcMessage(
"Impossible to advance an IndexSet::IntervalIterator that is invalid"));
1056 if (range_idx>=index_set->ranges.size())
1067 accessor(idxset, range_idx)
1091 accessor(other.accessor)
1121 accessor.advance ();
1158 return !(*
this == other);
1177 ExcMessage(
"Can not compare iterators belonging to different IndexSets"));
1181 accessor.index_set->ranges.size()
1186 accessor.index_set->ranges.size()
1191 return static_cast<int>(lhs - rhs);
1193 return -
static_cast<int>(rhs - lhs);
1207 range_idx(range_idx),
1211 ExcMessage(
"Invalid range index for IndexSet::ElementIterator constructor."));
1215 ExcInternalError(
"Invalid index argument for IndexSet::ElementIterator constructor."));
1224 range_idx(
numbers::invalid_dof_index),
1225 idx(
numbers::invalid_dof_index)
1236 (range_idx < index_set->
ranges.size() && idx<index_set->ranges[range_idx].end),
1239 return (range_idx < index_set->
ranges.size() &&
1240 idx<index_set->ranges[range_idx].end);
1251 ExcMessage(
"Impossible to dereference an IndexSet::ElementIterator that is invalid"));
1262 ExcMessage(
"Can not compare iterators belonging to different IndexSets"));
1273 ExcMessage(
"Impossible to advance an IndexSet::ElementIterator that is invalid"));
1274 if (idx < index_set->
ranges[range_idx].
end)
1277 if (idx == index_set->ranges[range_idx].end)
1280 if (range_idx < index_set->
ranges.size()-1)
1283 idx = index_set->ranges[range_idx].begin;
1320 return !(*
this == other);
1329 ExcMessage(
"Can not compare iterators belonging to different IndexSets"));
1340 ExcMessage(
"Can not compare iterators belonging to different IndexSets"));
1343 if (!(*
this < other))
1344 return -(other-*
this);
1352 std::ptrdiff_t c = index_set->ranges[range_idx].end-idx;
1355 for (
size_type range=range_idx+1; range<index_set->ranges.size() && range<=other.
range_idx; ++range)
1356 c += index_set->ranges[range].end-index_set->ranges[range].begin;
1359 ExcMessage(
"Inconsistent iterator state. Did you invalidate iterators by modifying the IndexSet?"));
1363 c -= index_set->ranges[other.
range_idx].end - other.
idx;
1407 is_compressed (true),
1408 index_space_size (size),
1409 largest_range (
numbers::invalid_unsigned_int)
1417 ranges (std::move(is.ranges)),
1418 is_compressed (is.is_compressed),
1419 index_space_size (is.index_space_size),
1420 largest_range (is.largest_range)
1423 is.is_compressed =
true;
1424 is.index_space_size = 0;
1435 ranges = std::move (is.ranges);
1436 is_compressed = is.is_compressed;
1437 index_space_size = is.index_space_size;
1438 largest_range = is.largest_range;
1441 is.is_compressed =
true;
1442 is.index_space_size = 0;
1469 ExcIndexRangeType<size_type> (global_index, 0,
size()));
1476 Range r (global_index, global_index+1);
1479 std::vector<Range>::const_iterator range_begin, range_end;
1480 if (global_index<main_range->
begin)
1482 range_begin =
ranges.begin();
1483 range_end = main_range;
1487 range_begin = main_range;
1488 range_end =
ranges.end();
1493 const std::vector<Range>::const_iterator
1506 if (global_index < p->
begin)
1565 ExcMessage (
"This function can only be called if the current " 1566 "object does not yet contain any elements."));
1601 const Range new_range(index, index+1);
1603 ranges.push_back(new_range);
1604 else if (index ==
ranges.back().end)
1616 template <
typename ForwardIterator>
1620 const ForwardIterator &end)
1624 for (ForwardIterator p=
begin; p!=
end;)
1628 ForwardIterator q = p;
1630 while ((q !=
end) && (*q == end_index))
1647 if (
ranges.empty() ==
false)
1669 std::vector<Range>::const_iterator
1678 return ((index >= p->begin) && (index < p->end));
1687 return (p->end > index);
1701 return (
ranges.size() <= 1);
1726 v = r.nth_index_in_set + r.end - r.begin;
1731 for (std::vector<Range>::iterator range =
ranges.begin();
1734 s += (range->end - range->begin);
1762 return main_range->nth_index_in_set;
1778 if (n>=main_range->nth_index_in_set &&
1780 return main_range->begin + (n-main_range->nth_index_in_set);
1786 r.nth_index_in_set = n;
1787 std::vector<Range>::const_iterator range_begin, range_end;
1790 range_begin =
ranges.begin();
1791 range_end = main_range;
1795 range_begin = main_range + 1;
1796 range_end =
ranges.end();
1799 const std::vector<Range>::const_iterator
1801 Range::nth_index_compare);
1804 return p->begin + (n-p->nth_index_in_set);
1816 Assert (n <
size(), ExcIndexRangeType<size_type> (n, 0,
size()));
1826 if (n >= main_range->begin && n < main_range->
end)
1827 return (n-main_range->begin) + main_range->nth_index_in_set;
1830 std::vector<Range>::const_iterator range_begin, range_end;
1831 if (n<main_range->
begin)
1833 range_begin =
ranges.begin();
1834 range_end = main_range;
1838 range_begin = main_range + 1;
1839 range_end =
ranges.end();
1842 std::vector<Range>::const_iterator
1844 Range::end_compare);
1847 if (p==range_end || p->end == n || p->begin > n)
1853 return (n-p->begin) + p->nth_index_in_set;
1888 template <
typename Vector>
1897 std::fill (vector.begin(), vector.end(), 0);
1901 for (std::vector<Range>::iterator it =
ranges.begin();
1910 template <
class StreamType>
1917 std::vector<Range>::const_iterator p;
1920 if (p->end-p->begin==1)
1923 out <<
"[" << p->begin <<
"," << p->end-1 <<
"]";
1928 out <<
"}" << std::endl;
1933 template <
class Archive>
1938 ar &begin &end &nth_index_in_set;
1943 template <
class Archive>
1951 DEAL_II_NAMESPACE_CLOSE
Iterator lower_bound(Iterator first, Iterator last, const T &val)
void fill_binary_vector(VectorType &vector) const
static const unsigned int invalid_unsigned_int
ElementIterator end() const
void add_index(const size_type index)
IndexSet operator&(const IndexSet &is) const
const IntervalAccessor * operator->() const
const IntervalAccessor & operator*() const
size_type nth_index_in_set(const unsigned int local_index) const
const IndexSet * index_set
IndexSet & operator=(const IndexSet &)=default
void block_read(std::istream &in)
std::ptrdiff_t operator-(const ElementIterator &p) const
void add_indices(const ForwardIterator &begin, const ForwardIterator &end)
unsigned int largest_range_starting_index() const
ElementIterator(const IndexSet *idxset, const size_type range_idx, const size_type index)
bool operator<(const IntervalIterator &) const
std::size_t memory_consumption() const
size_type n_elements() const
size_type index_space_size
bool is_ascending_and_one_to_one(const MPI_Comm &communicator) const
Epetra_Map make_trilinos_map(const MPI_Comm &communicator=MPI_COMM_WORLD, const bool overlapping=false) const
void print(StreamType &out) const
void serialize(Archive &ar, const unsigned int version)
IndexSet complete_index_set(const unsigned int N)
void serialize(Archive &ar, const unsigned int version)
static ::ExceptionBase & ExcMessage(std::string arg1)
void block_write(std::ostream &out) const
IntervalIterator & operator=(const IntervalIterator &other)
std::vector< Range > ranges
static ::ExceptionBase & ExcIndexNotPresent(size_type arg1)
#define DeclException1(Exception1, type1, outsequence)
unsigned int global_dof_index
void subtract_set(const IndexSet &other)
#define Assert(cond, exc)
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
bool operator<(const ElementIterator &) const
size_type index_within_set(const size_type global_index) const
bool operator==(const IndexSet &is) const
IntervalAccessor accessor
IntervalAccessor & operator=(const IntervalAccessor &other)
bool operator==(const IntervalIterator &) const
const IndexSet * index_set
bool operator==(const IntervalAccessor &other) const
unsigned int n_intervals() const
int operator-(const IntervalIterator &p) const
bool operator!=(const IndexSet &is) const
void fill_index_vector(std::vector< size_type > &indices) const
void add_range(const size_type begin, const size_type end)
void set_size(const size_type size)
std::forward_iterator_tag iterator_category
ElementIterator & operator++()
IntervalAccessor(const IndexSet *idxset, const size_type range_idx)
IndexSet get_view(const size_type begin, const size_type end) const
ElementIterator end() const
IntervalIterator begin_intervals() const
bool is_contiguous() const
Threads::Mutex compress_mutex
IntervalIterator end_intervals() const
bool operator<(const IntervalAccessor &other) const
bool operator!=(const ElementIterator &) const
ElementIterator begin() const
void write(std::ostream &out) const
bool is_element(const size_type index) const
bool operator==(const ElementIterator &) const
ElementIterator at(const size_type global_index) const
const types::global_dof_index invalid_dof_index
types::global_dof_index size_type
ElementIterator begin() const
void read(std::istream &in)
size_type n_elements() const
IntervalIterator & operator++()
std::forward_iterator_tag iterator_category
static ::ExceptionBase & ExcInternalError()
size_type operator*() const
bool operator!=(const IntervalIterator &) const