16#ifndef dealii_index_set_h
17#define dealii_index_set_h
25#include <boost/serialization/vector.hpp>
32#ifdef DEAL_II_WITH_TRILINOS
33# include <Epetra_Map.h>
34# ifdef DEAL_II_TRILINOS_WITH_TPETRA
35# include <Tpetra_Map.hpp>
39#if defined(DEAL_II_WITH_MPI) || defined(DEAL_II_WITH_PETSC)
43# ifndef MPI_COMM_WORLD
44# define MPI_COMM_WORLD 0
139#ifdef DEAL_II_WITH_TRILINOS
143 explicit IndexSet(
const Epetra_BlockMap &map);
196 template <
typename ForwardIterator>
350 std::vector<IndexSet>
352 const std::vector<types::global_dof_index> &n_indices_per_block)
const;
413 template <
typename VectorType>
421 template <
class StreamType>
423 print(StreamType &out)
const;
430 write(std::ostream &out)
const;
437 read(std::istream &in);
453#ifdef DEAL_II_WITH_TRILINOS
484 const bool overlapping =
false)
const;
486# ifdef DEAL_II_TRILINOS_WITH_TPETRA
487 Tpetra::Map<int, types::global_dof_index>
489 const bool overlapping =
false)
const;
503 <<
"The global index " << arg1
504 <<
" is not an element of this set.");
511 template <
class Archive>
513 serialize(Archive &ar,
const unsigned int version);
931 return sizeof(
Range);
939 template <
class Archive>
941 serialize(Archive &ar,
const unsigned int version);
1030 , range_idx(range_idx)
1047 : index_set(other.index_set)
1048 , range_idx(other.range_idx)
1060 return index_set->ranges[range_idx].end - index_set->ranges[range_idx].begin;
1068 return index_set !=
nullptr && range_idx < index_set->n_intervals();
1077 return {index_set, range_idx, index_set->ranges[range_idx].begin};
1088 if (range_idx < index_set->
ranges.size() - 1)
1089 return {index_set, range_idx + 1, index_set->ranges[range_idx + 1].begin};
1091 return index_set->end();
1101 return index_set->ranges[range_idx].end - 1;
1124 "Can not compare accessors pointing to different IndexSets"));
1136 "Can not compare accessors pointing to different IndexSets"));
1148 "Impossible to advance an IndexSet::IntervalIterator that is invalid"));
1152 if (range_idx >= index_set->ranges.size())
1162 : accessor(idxset, range_idx)
1227 return !(*
this == other);
1247 "Can not compare iterators belonging to different IndexSets"));
1250 accessor.index_set->ranges.size() :
1254 accessor.index_set->ranges.size() :
1258 return static_cast<int>(lhs - rhs);
1260 return -
static_cast<int>(rhs - lhs);
1272 , range_idx(range_idx)
1277 "Invalid range index for IndexSet::ElementIterator constructor."));
1282 "Invalid index argument for IndexSet::ElementIterator constructor."));
1300 (range_idx < index_set->
ranges.size() &&
1301 idx < index_set->
ranges[range_idx].end),
1304 return (range_idx < index_set->
ranges.size() &&
1305 idx < index_set->
ranges[range_idx].end);
1315 "Impossible to dereference an IndexSet::ElementIterator that is invalid"));
1327 "Can not compare iterators belonging to different IndexSets"));
1328 return range_idx == other.
range_idx && idx == other.
idx;
1339 "Impossible to advance an IndexSet::ElementIterator that is invalid"));
1340 if (idx < index_set->
ranges[range_idx].
end)
1343 if (idx == index_set->ranges[range_idx].end)
1346 if (range_idx < index_set->
ranges.size() - 1)
1349 idx = index_set->ranges[range_idx].begin;
1385 return !(*
this == other);
1396 "Can not compare iterators belonging to different IndexSets"));
1403inline std::ptrdiff_t
1409 "Can not compare iterators belonging to different IndexSets"));
1412 if (!(*
this < other))
1413 return -(other - *
this);
1422 std::ptrdiff_t c = index_set->ranges[range_idx].end - idx;
1426 range < index_set->ranges.size() && range <= other.
range_idx;
1428 c += index_set->ranges[range].end - index_set->ranges[range].begin;
1431 other.
range_idx < index_set->ranges.size() ||
1434 "Inconsistent iterator state. Did you invalidate iterators by modifying the IndexSet?"));
1439 c -= index_set->ranges[other.
range_idx].end - other.
idx;
1474 : is_compressed(true)
1475 , index_space_size(size)
1482 : ranges(std::move(is.ranges))
1483 , is_compressed(is.is_compressed)
1484 , index_space_size(is.index_space_size)
1485 , largest_range(is.largest_range)
1488 is.is_compressed =
true;
1489 is.index_space_size = 0;
1500 ranges = std::move(is.ranges);
1501 is_compressed = is.is_compressed;
1502 index_space_size = is.index_space_size;
1503 largest_range = is.largest_range;
1506 is.is_compressed =
true;
1507 is.index_space_size = 0;
1522 return {
this, 0,
ranges[0].begin};
1538 std::vector<Range>::const_iterator main_range =
1544 std::vector<Range>::const_iterator range_begin, range_end;
1545 if (global_index < main_range->
begin)
1547 range_begin =
ranges.begin();
1548 range_end = main_range;
1552 range_begin = main_range;
1553 range_end =
ranges.end();
1558 const std::vector<Range>::const_iterator p =
1571 if (global_index < p->
begin)
1625 ExcMessage(
"This function can only be called if the current "
1626 "object does not yet contain any elements."));
1657 const Range new_range(index, index + 1);
1659 ranges.push_back(new_range);
1660 else if (index ==
ranges.back().end)
1689 ranges.push_back(new_range);
1701template <
typename ForwardIterator>
1713 std::vector<std::pair<size_type, size_type>> tmp_ranges;
1714 bool ranges_are_sorted =
true;
1715 for (ForwardIterator p =
begin; p !=
end;)
1719 ForwardIterator q = p;
1721 while ((q !=
end) && (*q == end_index))
1727 tmp_ranges.emplace_back(begin_index, end_index);
1734 if (p !=
end && *p < end_index)
1735 ranges_are_sorted =
false;
1738 if (!ranges_are_sorted)
1739 std::sort(tmp_ranges.begin(), tmp_ranges.end());
1749 if (tmp_ranges.size() > 9)
1752 tmp_set.
ranges.reserve(tmp_ranges.size());
1753 for (
const auto &i : tmp_ranges)
1758 for (
const auto &i : tmp_ranges)
1767 if (
ranges.empty() ==
false)
1789 std::vector<Range>::const_iterator p = std::upper_bound(
1797 return ((index >= p->begin) && (index < p->
end));
1805 return (p->end > index);
1818 return (
ranges.size() <= 1);
1846 for (
const auto &range :
ranges)
1847 s += (range.end - range.begin);
1871 const std::vector<Range>::const_iterator main_range =
1874 return main_range->nth_index_in_set;
1888 std::vector<Range>::const_iterator main_range =
1890 if (n >= main_range->nth_index_in_set &&
1892 return main_range->begin + (n - main_range->nth_index_in_set);
1899 std::vector<Range>::const_iterator range_begin, range_end;
1902 range_begin =
ranges.begin();
1903 range_end = main_range;
1907 range_begin = main_range + 1;
1908 range_end =
ranges.end();
1911 const std::vector<Range>::const_iterator p =
1915 return p->begin + (n - p->nth_index_in_set);
1935 std::vector<Range>::const_iterator main_range =
1937 if (n >= main_range->begin && n < main_range->
end)
1938 return (n - main_range->begin) + main_range->nth_index_in_set;
1941 std::vector<Range>::const_iterator range_begin, range_end;
1942 if (n < main_range->
begin)
1944 range_begin =
ranges.begin();
1945 range_end = main_range;
1949 range_begin = main_range + 1;
1950 range_end =
ranges.end();
1953 std::vector<Range>::const_iterator p =
1957 if (p == range_end || p->end == n || p->begin > n)
1963 return (n - p->begin) + p->nth_index_in_set;
1994template <
typename Vector>
2002 std::fill(vector.
begin(), vector.
end(), 0);
2006 for (
const auto &range :
ranges)
2007 for (
size_type i = range.begin; i < range.end; ++i)
2013template <
class StreamType>
2019 std::vector<Range>::const_iterator p;
2022 if (p->end - p->begin == 1)
2025 out <<
"[" << p->begin <<
"," << p->end - 1 <<
"]";
2030 out <<
"}" << std::endl;
2035template <
class Archive>
2044template <
class Archive>
size_type operator*() const
bool operator==(const ElementIterator &) const
ElementIterator(const IndexSet *idxset, const size_type range_idx, const size_type index)
std::ptrdiff_t difference_type
ElementIterator & operator++()
bool operator<(const ElementIterator &) const
bool operator!=(const ElementIterator &) const
std::ptrdiff_t operator-(const ElementIterator &p) const
std::forward_iterator_tag iterator_category
const IndexSet * index_set
ElementIterator end() const
size_type n_elements() const
bool operator==(const IntervalAccessor &other) const
IntervalAccessor & operator=(const IntervalAccessor &other)
bool operator<(const IntervalAccessor &other) const
IntervalAccessor(const IndexSet *idxset, const size_type range_idx)
const IndexSet * index_set
ElementIterator begin() const
std::ptrdiff_t difference_type
const IntervalAccessor & operator*() const
IntervalIterator(const IntervalIterator &other)=default
bool operator==(const IntervalIterator &) const
int operator-(const IntervalIterator &p) const
bool operator<(const IntervalIterator &) const
std::forward_iterator_tag iterator_category
IntervalIterator & operator=(const IntervalIterator &other)=default
IntervalIterator & operator++()
const IntervalAccessor * operator->() const
IntervalAccessor accessor
bool operator!=(const IntervalIterator &) const
bool is_contiguous() const
unsigned int n_intervals() const
IndexSet(const IndexSet &)=default
IntervalIterator end_intervals() const
ElementIterator at(const size_type global_index) const
void fill_index_vector(std::vector< size_type > &indices) const
size_type index_within_set(const size_type global_index) const
std::vector< IndexSet > split_by_block(const std::vector< types::global_dof_index > &n_indices_per_block) const
size_type n_elements() const
bool operator==(const IndexSet &is) const
bool is_element(const size_type index) const
void serialize(Archive &ar, const unsigned int version)
ElementIterator begin() const
void set_size(const size_type size)
bool operator!=(const IndexSet &is) const
void read(std::istream &in)
size_type largest_range_starting_index() const
Tpetra::Map< int, types::global_dof_index > make_tpetra_map(const MPI_Comm &communicator=MPI_COMM_WORLD, const bool overlapping=false) const
IndexSet tensor_product(const IndexSet &other) const
void add_index(const size_type index)
void write(std::ostream &out) const
void block_read(std::istream &in)
IntervalIterator begin_intervals() const
IndexSet & operator=(const IndexSet &)=default
void fill_binary_vector(VectorType &vector) const
std::vector< Range > ranges
void subtract_set(const IndexSet &other)
ElementIterator end() const
Threads::Mutex compress_mutex
IndexSet complete_index_set(const IndexSet::size_type N)
size_type index_space_size
Epetra_Map make_trilinos_map(const MPI_Comm &communicator=MPI_COMM_WORLD, const bool overlapping=false) const
void block_write(std::ostream &out) const
IndexSet get_view(const size_type begin, const size_type end) const
void add_range(const size_type begin, const size_type end)
size_type nth_index_in_set(const size_type local_index) const
bool is_ascending_and_one_to_one(const MPI_Comm &communicator) const
std::size_t memory_consumption() const
void print(StreamType &out) const
types::global_dof_index size_type
void add_indices(const ForwardIterator &begin, const ForwardIterator &end)
IndexSet operator&(const IndexSet &is) const
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
#define Assert(cond, exc)
static ::ExceptionBase & ExcIndexNotPresent(size_type arg1)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
#define DeclException1(Exception1, type1, outsequence)
static ::ExceptionBase & ExcMessage(std::string arg1)
VectorType::value_type * end(VectorType &V)
VectorType::value_type * begin(VectorType &V)
TrilinosWrappers::types::int_type global_index(const Epetra_BlockMap &map, const ::types::global_dof_index i)
std::string compress(const std::string &input)
Iterator lower_bound(Iterator first, Iterator last, const T &val)
static const unsigned int invalid_unsigned_int
const types::global_dof_index invalid_dof_index
unsigned int global_dof_index
static bool end_compare(const IndexSet::Range &x, const IndexSet::Range &y)
static bool nth_index_compare(const IndexSet::Range &x, const IndexSet::Range &y)
friend bool operator==(const Range &range_1, const Range &range_2)
size_type nth_index_in_set
static std::size_t memory_consumption()
void serialize(Archive &ar, const unsigned int version)
friend bool operator<(const Range &range_1, const Range &range_2)
void advance(std::tuple< I1, I2 > &t, const unsigned int n)