16 #ifndef dealii_index_set_h
17 #define dealii_index_set_h
25 #include <boost/container/small_vector.hpp>
31 #ifdef DEAL_II_WITH_TRILINOS
32 # include <Epetra_Map.h>
33 # ifdef DEAL_II_TRILINOS_WITH_TPETRA
34 # include <Tpetra_Map.hpp>
38 #ifdef DEAL_II_WITH_PETSC
133 #ifdef DEAL_II_WITH_TRILINOS
137 explicit IndexSet(
const Epetra_BlockMap &map);
190 template <
typename ForwardIterator>
345 std::vector<IndexSet>
347 const std::vector<types::global_dof_index> &n_indices_per_block)
const;
398 std::vector<size_type>
407 DEAL_II_DEPRECATED_EARLY
423 template <
typename VectorType>
431 template <
class StreamType>
433 print(StreamType &out)
const;
440 write(std::ostream &out)
const;
447 read(std::istream &in);
463 #ifdef DEAL_II_WITH_TRILINOS
494 const bool overlapping =
false)
const;
496 # ifdef DEAL_II_TRILINOS_WITH_TPETRA
497 Tpetra::Map<int, types::signed_global_dof_index>
499 const bool overlapping =
false)
const;
503 #ifdef DEAL_II_WITH_PETSC
505 make_petsc_is(
const MPI_Comm &communicator = MPI_COMM_WORLD)
const;
518 <<
"The global index " << arg1
519 <<
" is not an element of this set.");
526 template <
class Archive>
528 serialize(Archive &ar,
const unsigned int version);
949 return sizeof(
Range);
957 template <
class Archive>
959 serialize(Archive &ar,
const unsigned int version);
1051 boost::container::small_vector<std::pair<size_type, size_type>, 200>
1053 const bool ranges_are_sorted);
1093 , range_idx(range_idx)
1110 : index_set(other.index_set)
1111 , range_idx(other.range_idx)
1123 return index_set->ranges[range_idx].end - index_set->ranges[range_idx].begin;
1131 return index_set !=
nullptr && range_idx < index_set->n_intervals();
1140 return {index_set, range_idx, index_set->ranges[range_idx].begin};
1151 if (range_idx < index_set->
ranges.size() - 1)
1152 return {index_set, range_idx + 1, index_set->ranges[range_idx + 1].begin};
1154 return index_set->end();
1164 return index_set->ranges[range_idx].end - 1;
1187 "Can not compare accessors pointing to different IndexSets"));
1199 "Can not compare accessors pointing to different IndexSets"));
1211 "Impossible to advance an IndexSet::IntervalIterator that is invalid"));
1215 if (range_idx >= index_set->ranges.size())
1225 : accessor(idxset, range_idx)
1290 return !(*
this == other);
1310 "Can not compare iterators belonging to different IndexSets"));
1313 accessor.index_set->ranges.size() :
1317 accessor.index_set->ranges.size() :
1321 return static_cast<int>(lhs - rhs);
1323 return -
static_cast<int>(rhs - lhs);
1335 , range_idx(range_idx)
1340 "Invalid range index for IndexSet::ElementIterator constructor."));
1345 "Invalid index argument for IndexSet::ElementIterator constructor."));
1363 (range_idx < index_set->
ranges.size() &&
1364 idx < index_set->
ranges[range_idx].end),
1367 return (range_idx < index_set->
ranges.size() &&
1368 idx < index_set->
ranges[range_idx].end);
1379 "Impossible to dereference an IndexSet::ElementIterator that is invalid"));
1391 "Can not compare iterators belonging to different IndexSets"));
1392 return range_idx == other.
range_idx && idx == other.
idx;
1403 "Impossible to advance an IndexSet::ElementIterator that is invalid"));
1404 if (idx < index_set->
ranges[range_idx].
end)
1407 if (idx == index_set->ranges[range_idx].end)
1410 if (range_idx < index_set->
ranges.size() - 1)
1413 idx = index_set->ranges[range_idx].begin;
1449 return !(*
this == other);
1460 "Can not compare iterators belonging to different IndexSets"));
1467 inline std::ptrdiff_t
1473 "Can not compare iterators belonging to different IndexSets"));
1476 if (!(*
this < other))
1477 return -(other - *
this);
1486 std::ptrdiff_t c = index_set->ranges[range_idx].end - idx;
1490 range < index_set->ranges.size() && range <= other.
range_idx;
1492 c += index_set->ranges[range].end - index_set->ranges[range].begin;
1495 other.
range_idx < index_set->ranges.size() ||
1498 "Inconsistent iterator state. Did you invalidate iterators by modifying the IndexSet?"));
1503 c -= index_set->ranges[other.
range_idx].end - other.
idx;
1538 : is_compressed(true)
1539 , index_space_size(size)
1546 : ranges(std::move(is.ranges))
1547 , is_compressed(is.is_compressed)
1548 , index_space_size(is.index_space_size)
1549 , largest_range(is.largest_range)
1552 is.is_compressed =
true;
1553 is.index_space_size = 0;
1564 ranges = std::move(is.ranges);
1565 is_compressed = is.is_compressed;
1566 index_space_size = is.index_space_size;
1567 largest_range = is.largest_range;
1570 is.is_compressed =
true;
1571 is.index_space_size = 0;
1586 return {
this, 0,
ranges[0].begin};
1639 ExcMessage(
"This function can only be called if the current "
1640 "object does not yet contain any elements."));
1671 const Range new_range(index, index + 1);
1673 ranges.push_back(new_range);
1674 else if (index ==
ranges.back().end)
1700 ranges.push_back(new_range);
1712 template <
typename ForwardIterator>
1724 boost::container::small_vector<std::pair<size_type, size_type>, 200>
1726 bool ranges_are_sorted =
true;
1727 for (ForwardIterator p =
begin; p !=
end;)
1731 ForwardIterator q = p;
1733 while ((q !=
end) && (
static_cast<size_type>(*q) == end_index))
1739 tmp_ranges.emplace_back(begin_index, end_index);
1746 if (p !=
end &&
static_cast<size_type>(*p) < end_index)
1747 ranges_are_sorted =
false;
1758 if (
ranges.empty() ==
false)
1767 else if (
ranges.size() > 1)
1782 return (
ranges.size() <= 1);
1810 for (
const auto &range :
ranges)
1811 s += (range.end - range.begin);
1835 const std::vector<Range>::const_iterator main_range =
1838 return main_range->nth_index_in_set;
1853 if (n >= main_range->nth_index_in_set &&
1855 return main_range->begin + (n - main_range->nth_index_in_set);
1880 else if (
ranges.size() > 1)
1914 template <
typename Vector>
1922 std::fill(vector.
begin(), vector.
end(), 0);
1926 for (
const auto &range :
ranges)
1927 for (
size_type i = range.begin; i < range.end; ++i)
1933 template <
class StreamType>
1939 std::vector<Range>::const_iterator p;
1942 if (p->end - p->begin == 1)
1945 out <<
'[' << p->begin <<
',' << p->end - 1 <<
']';
1950 out <<
'}' << std::endl;
1955 template <
class Archive>
1964 template <
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++()
IntervalIterator & operator=(const IntervalIterator &other)=default
const IntervalAccessor * operator->() const
IntervalAccessor accessor
bool operator!=(const IntervalIterator &) const
bool is_element_binary_search(const size_type local_index) const
size_type index_within_set_binary_search(const size_type global_index) const
bool is_contiguous() const
unsigned int n_intervals() const
IndexSet(const IndexSet &)=default
IndexSet & operator=(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
IS make_petsc_is(const MPI_Comm &communicator=MPI_COMM_WORLD) 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
void add_range_lower_bound(const Range &range)
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)
Tpetra::Map< int, types::signed_global_dof_index > make_tpetra_map(const MPI_Comm &communicator=MPI_COMM_WORLD, const bool overlapping=false) const
size_type largest_range_starting_index() 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)
void add_ranges_internal(boost::container::small_vector< std::pair< size_type, size_type >, 200 > &tmp_ranges, const bool ranges_are_sorted)
IntervalIterator begin_intervals() const
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
size_type nth_index_in_set_binary_search(const size_type local_index) const
std::vector< size_type > get_index_vector() 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
static ::ExceptionBase & ExcIndexNotPresent(size_type arg1)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
#define Assert(cond, exc)
#define AssertIndexRange(index, range)
#define DeclException1(Exception1, type1, outsequence)
static ::ExceptionBase & ExcMessage(std::string arg1)
VectorType::value_type * begin(VectorType &V)
VectorType::value_type * end(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)
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)