16#ifndef dealii_index_set_h
17#define dealii_index_set_h
29#ifdef DEAL_II_WITH_TRILINOS
30# include <Epetra_Map.h>
31# ifdef DEAL_II_TRILINOS_WITH_TPETRA
32# include <Tpetra_Map.hpp>
36#if defined(DEAL_II_WITH_MPI) || defined(DEAL_II_WITH_PETSC)
40# ifndef MPI_COMM_WORLD
41# define MPI_COMM_WORLD 0
136#ifdef DEAL_II_WITH_TRILINOS
140 explicit IndexSet(
const Epetra_BlockMap &map);
193 template <
typename ForwardIterator>
348 std::vector<IndexSet>
350 const std::vector<types::global_dof_index> &n_indices_per_block)
const;
411 template <
typename VectorType>
419 template <
class StreamType>
421 print(StreamType &out)
const;
428 write(std::ostream &out)
const;
435 read(std::istream &in);
451#ifdef DEAL_II_WITH_TRILINOS
482 const bool overlapping =
false)
const;
484# ifdef DEAL_II_TRILINOS_WITH_TPETRA
485 Tpetra::Map<int, types::global_dof_index>
487 const bool overlapping =
false)
const;
501 <<
"The global index " << arg1
502 <<
" is not an element of this set.");
509 template <
class Archive>
511 serialize(Archive &ar,
const unsigned int version);
932 return sizeof(
Range);
940 template <
class Archive>
942 serialize(Archive &ar,
const unsigned int version);
1031 , range_idx(range_idx)
1041 , range_idx(
numbers::invalid_dof_index)
1048 : index_set(other.index_set)
1049 , range_idx(other.range_idx)
1061 return index_set->ranges[range_idx].end - index_set->ranges[range_idx].begin;
1069 return index_set !=
nullptr && range_idx < index_set->n_intervals();
1078 return {index_set, range_idx, index_set->ranges[range_idx].begin};
1089 if (range_idx < index_set->
ranges.size() - 1)
1090 return {index_set, range_idx + 1, index_set->ranges[range_idx + 1].begin};
1092 return index_set->end();
1102 return index_set->ranges[range_idx].end - 1;
1125 "Can not compare accessors pointing to different IndexSets"));
1137 "Can not compare accessors pointing to different IndexSets"));
1149 "Impossible to advance an IndexSet::IntervalIterator that is invalid"));
1153 if (range_idx >= index_set->ranges.size())
1163 : accessor(idxset, range_idx)
1228 return !(*
this == other);
1248 "Can not compare iterators belonging to different IndexSets"));
1251 accessor.index_set->ranges.size() :
1255 accessor.index_set->ranges.size() :
1259 return static_cast<int>(lhs - rhs);
1261 return -
static_cast<int>(rhs - lhs);
1273 , range_idx(range_idx)
1278 "Invalid range index for IndexSet::ElementIterator constructor."));
1283 "Invalid index argument for IndexSet::ElementIterator constructor."));
1290 , range_idx(
numbers::invalid_dof_index)
1291 , idx(
numbers::invalid_dof_index)
1301 (range_idx < index_set->
ranges.size() &&
1302 idx < index_set->
ranges[range_idx].end),
1305 return (range_idx < index_set->
ranges.size() &&
1306 idx < index_set->
ranges[range_idx].end);
1317 "Impossible to dereference an IndexSet::ElementIterator that is invalid"));
1329 "Can not compare iterators belonging to different IndexSets"));
1330 return range_idx == other.
range_idx && idx == other.
idx;
1341 "Impossible to advance an IndexSet::ElementIterator that is invalid"));
1342 if (idx < index_set->
ranges[range_idx].
end)
1345 if (idx == index_set->ranges[range_idx].end)
1348 if (range_idx < index_set->
ranges.size() - 1)
1351 idx = index_set->ranges[range_idx].begin;
1387 return !(*
this == other);
1398 "Can not compare iterators belonging to different IndexSets"));
1405inline std::ptrdiff_t
1411 "Can not compare iterators belonging to different IndexSets"));
1414 if (!(*
this < other))
1415 return -(other - *
this);
1424 std::ptrdiff_t c = index_set->ranges[range_idx].end - idx;
1428 range < index_set->ranges.size() && range <= other.
range_idx;
1430 c += index_set->ranges[range].end - index_set->ranges[range].begin;
1433 other.
range_idx < index_set->ranges.size() ||
1436 "Inconsistent iterator state. Did you invalidate iterators by modifying the IndexSet?"));
1441 c -= index_set->ranges[other.
range_idx].end - other.
idx;
1476 : is_compressed(true)
1477 , index_space_size(size)
1478 , largest_range(
numbers::invalid_unsigned_int)
1484 : ranges(std::move(is.ranges))
1485 , is_compressed(is.is_compressed)
1486 , index_space_size(is.index_space_size)
1487 , largest_range(is.largest_range)
1490 is.is_compressed =
true;
1491 is.index_space_size = 0;
1502 ranges = std::move(is.ranges);
1503 is_compressed = is.is_compressed;
1504 index_space_size = is.index_space_size;
1505 largest_range = is.largest_range;
1508 is.is_compressed =
true;
1509 is.index_space_size = 0;
1524 return {
this, 0,
ranges[0].begin};
1540 std::vector<Range>::const_iterator main_range =
1543 Range r(global_index, global_index + 1);
1546 std::vector<Range>::const_iterator range_begin, range_end;
1547 if (global_index < main_range->
begin)
1549 range_begin =
ranges.begin();
1550 range_end = main_range;
1554 range_begin = main_range;
1555 range_end =
ranges.end();
1560 const std::vector<Range>::const_iterator p =
1573 if (global_index < p->
begin)
1576 return {
this,
static_cast<size_type>(p -
ranges.begin()), global_index};
1627 ExcMessage(
"This function can only be called if the current "
1628 "object does not yet contain any elements."));
1659 const Range new_range(index, index + 1);
1661 ranges.push_back(new_range);
1662 else if (index ==
ranges.back().end)
1691 ranges.push_back(new_range);
1703template <
typename ForwardIterator>
1715 std::vector<std::pair<size_type, size_type>> tmp_ranges;
1716 bool ranges_are_sorted =
true;
1717 for (ForwardIterator p =
begin; p !=
end;)
1721 ForwardIterator q = p;
1723 while ((q !=
end) && (
static_cast<size_type>(*q) == end_index))
1729 tmp_ranges.emplace_back(begin_index, end_index);
1736 if (p !=
end &&
static_cast<size_type>(*p) < end_index)
1737 ranges_are_sorted =
false;
1740 if (!ranges_are_sorted)
1741 std::sort(tmp_ranges.begin(), tmp_ranges.end());
1751 if (tmp_ranges.size() > 9)
1754 tmp_set.
ranges.reserve(tmp_ranges.size());
1755 for (
const auto &i : tmp_ranges)
1760 for (
const auto &i : tmp_ranges)
1769 if (
ranges.empty() ==
false)
1791 std::vector<Range>::const_iterator p = std::upper_bound(
1799 return ((index >= p->begin) && (index < p->
end));
1807 return (p->end > index);
1820 return (
ranges.size() <= 1);
1848 for (
const auto &range :
ranges)
1849 s += (range.end - range.begin);
1873 const std::vector<Range>::const_iterator main_range =
1876 return main_range->nth_index_in_set;
1890 std::vector<Range>::const_iterator main_range =
1892 if (n >= main_range->nth_index_in_set &&
1894 return main_range->begin + (n - main_range->nth_index_in_set);
1901 std::vector<Range>::const_iterator range_begin, range_end;
1904 range_begin =
ranges.begin();
1905 range_end = main_range;
1909 range_begin = main_range + 1;
1910 range_end =
ranges.end();
1913 const std::vector<Range>::const_iterator p =
1917 return p->begin + (n - p->nth_index_in_set);
1937 std::vector<Range>::const_iterator main_range =
1939 if (n >= main_range->begin && n < main_range->
end)
1940 return (n - main_range->begin) + main_range->nth_index_in_set;
1943 std::vector<Range>::const_iterator range_begin, range_end;
1944 if (n < main_range->
begin)
1946 range_begin =
ranges.begin();
1947 range_end = main_range;
1951 range_begin = main_range + 1;
1952 range_end =
ranges.end();
1955 std::vector<Range>::const_iterator p =
1959 if (p == range_end || p->end == n || p->begin > n)
1965 return (n - p->begin) + p->nth_index_in_set;
1996template <
typename Vector>
2004 std::fill(vector.
begin(), vector.
end(), 0);
2008 for (
const auto &range :
ranges)
2009 for (
size_type i = range.begin; i < range.end; ++i)
2015template <
class StreamType>
2021 std::vector<Range>::const_iterator p;
2024 if (p->end - p->begin == 1)
2027 out <<
'[' << p->begin <<
',' << p->end - 1 <<
']';
2032 out <<
'}' << std::endl;
2037template <
class Archive>
2046template <
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)
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)