15#ifndef dealii_index_set_h
16#define dealii_index_set_h
28#include <boost/container/small_vector.hpp>
34#ifdef DEAL_II_WITH_TRILINOS
35# include <Epetra_Map.h>
36# ifdef DEAL_II_TRILINOS_WITH_TPETRA
37# include <Tpetra_Map.hpp>
41#ifdef DEAL_II_WITH_PETSC
136#ifdef DEAL_II_WITH_TRILINOS
138# ifdef DEAL_II_TRILINOS_WITH_TPETRA
142 template <
typename NodeType>
145 const Tpetra::Map<int, types::signed_global_dof_index, NodeType>> &map);
151 explicit IndexSet(
const Epetra_BlockMap &map);
224 template <
typename ForwardIterator>
453 std::vector<IndexSet>
455 const std::vector<types::global_dof_index> &n_indices_per_block)
const;
506 std::vector<size_type>
531 template <
typename VectorType>
549 template <
typename StreamType>
551 print(StreamType &out)
const;
558 write(std::ostream &out)
const;
565 read(std::istream &in);
581#ifdef DEAL_II_WITH_TRILINOS
614# ifdef DEAL_II_TRILINOS_WITH_TPETRA
618 Tpetra::Map<int, types::signed_global_dof_index, NodeType>
625 Teuchos::RCP<Tpetra::Map<int, types::signed_global_dof_index, NodeType>>
631#ifdef DEAL_II_WITH_PETSC
646 <<
"The global index " << arg1
647 <<
" is not an element of this set.");
654 template <
class Archive>
656 serialize(Archive &ar,
const unsigned int version);
1077 return sizeof(
Range);
1085 template <
class Archive>
1087 serialize(Archive &ar,
const unsigned int version);
1179 boost::container::small_vector<std::pair<size_type, size_type>, 200>
1181 const bool ranges_are_sorted);
1221 , range_idx(range_idx)
1231 , range_idx(
numbers::invalid_dof_index)
1238 : index_set(other.index_set)
1239 , range_idx(other.range_idx)
1251 return index_set->ranges[range_idx].end - index_set->ranges[range_idx].begin;
1259 return index_set !=
nullptr && range_idx < index_set->n_intervals();
1268 return {index_set, range_idx, index_set->ranges[range_idx].begin};
1279 if (range_idx < index_set->
ranges.size() - 1)
1280 return {index_set, range_idx + 1, index_set->ranges[range_idx + 1].begin};
1282 return index_set->end();
1292 return index_set->ranges[range_idx].end - 1;
1315 "Can not compare accessors pointing to different IndexSets"));
1327 "Can not compare accessors pointing to different IndexSets"));
1339 "Impossible to advance an IndexSet::IntervalIterator that is invalid"));
1343 if (range_idx >= index_set->ranges.size())
1353 : accessor(idxset, range_idx)
1418 return !(*
this == other);
1438 "Can not compare iterators belonging to different IndexSets"));
1441 accessor.index_set->ranges.size() :
1445 accessor.index_set->ranges.size() :
1449 return static_cast<int>(lhs - rhs);
1451 return -
static_cast<int>(rhs - lhs);
1463 , range_idx(range_idx)
1468 "Invalid range index for IndexSet::ElementIterator constructor."));
1473 "Invalid index argument for IndexSet::ElementIterator constructor."));
1480 , range_idx(
numbers::invalid_dof_index)
1481 , idx(
numbers::invalid_dof_index)
1491 (range_idx < index_set->
ranges.size() &&
1492 idx < index_set->
ranges[range_idx].end),
1495 return (range_idx < index_set->
ranges.size() &&
1496 idx < index_set->
ranges[range_idx].end);
1507 "Impossible to dereference an IndexSet::ElementIterator that is invalid"));
1519 "Can not compare iterators belonging to different IndexSets"));
1520 return range_idx == other.
range_idx && idx == other.
idx;
1531 "Impossible to advance an IndexSet::ElementIterator that is invalid"));
1532 if (idx < index_set->
ranges[range_idx].
end)
1535 if (idx == index_set->ranges[range_idx].end)
1538 if (range_idx < index_set->
ranges.size() - 1)
1541 idx = index_set->ranges[range_idx].begin;
1577 return !(*
this == other);
1588 "Can not compare iterators belonging to different IndexSets"));
1595inline std::ptrdiff_t
1601 "Can not compare iterators belonging to different IndexSets"));
1604 if (!(*
this < other))
1605 return -(other - *
this);
1614 std::ptrdiff_t c = index_set->ranges[range_idx].end - idx;
1618 range < index_set->ranges.size() && range <= other.
range_idx;
1620 c += index_set->ranges[range].end - index_set->ranges[range].begin;
1623 other.
range_idx < index_set->ranges.size() ||
1626 "Inconsistent iterator state. Did you invalidate iterators by modifying the IndexSet?"));
1631 c -= index_set->ranges[other.
range_idx].end - other.
idx;
1666 : is_compressed(true)
1667 , index_space_size(
size)
1668 , largest_range(
numbers::invalid_unsigned_int)
1674 : ranges(std::move(is.ranges))
1675 , is_compressed(is.is_compressed)
1676 , index_space_size(is.index_space_size)
1677 , largest_range(is.largest_range)
1680 is.is_compressed =
true;
1681 is.index_space_size = 0;
1692 ranges = std::move(is.ranges);
1693 is_compressed = is.is_compressed;
1694 index_space_size = is.index_space_size;
1695 largest_range = is.largest_range;
1698 is.is_compressed =
true;
1699 is.index_space_size = 0;
1714 return {
this, 0,
ranges[0].begin};
1767 ExcMessage(
"This function can only be called if the current "
1768 "object does not yet contain any elements."));
1829template <
typename ForwardIterator>
1841 boost::container::small_vector<std::pair<size_type, size_type>, 200>
1843 bool ranges_are_sorted =
true;
1844 for (ForwardIterator p =
begin; p !=
end;)
1856 ForwardIterator q = p;
1858 while ((q !=
end) && (*q == *p))
1866 while ((q !=
end) && (
static_cast<size_type>(*q) == end_index))
1869 while ((q !=
end) && (
static_cast<size_type>(*q) == end_index))
1876 tmp_ranges.emplace_back(begin_index, end_index);
1884 if ((p !=
end) && (
static_cast<size_type>(*p) < end_index))
1885 ranges_are_sorted =
false;
1896 if (
ranges.empty() ==
false)
1905 else if (
ranges.size() > 1)
1920 return (
ranges.size() <= 1);
1948 for (
const auto &range :
ranges)
1949 s += (range.end - range.begin);
1973 const std::vector<Range>::const_iterator main_range =
1976 return main_range->nth_index_in_set;
1991 if (n >= main_range->nth_index_in_set &&
1993 return main_range->begin + (n - main_range->nth_index_in_set);
2018 else if (
ranges.size() > 1)
2032 return (is.
size() == 0);
2034 return (
size() == 0);
2053 return (is.
size() != 0);
2055 return (
size() != 0);
2068template <
typename Vector>
2076 std::fill(vector.
begin(), vector.
end(), 0);
2080 for (
const auto &range :
ranges)
2081 for (
size_type i = range.begin; i < range.end; ++i)
2087template <
typename StreamType>
2093 std::vector<Range>::const_iterator p;
2096 if (p->end - p->begin == 1)
2099 out <<
'[' << p->begin <<
',' << p->end - 1 <<
']';
2104 out <<
'}' << std::endl;
2109template <
class Archive>
2118template <
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_subset_of(const IndexSet &other) 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
IS make_petsc_is(const MPI_Comm communicator=MPI_COMM_WORLD) const
bool is_ascending_and_one_to_one(const MPI_Comm communicator) const
bool is_contiguous() const
unsigned int n_intervals() const
Tpetra::Map< int, types::signed_global_dof_index, NodeType > make_tpetra_map(const MPI_Comm communicator=MPI_COMM_WORLD, const bool overlapping=false) 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
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)
Epetra_Map make_trilinos_map(const MPI_Comm communicator=MPI_COMM_WORLD, const bool overlapping=false) const
size_type largest_range_starting_index() 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
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
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
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
Teuchos::RCP< Tpetra::Map< int, types::signed_global_dof_index, NodeType > > make_tpetra_map_rcp(const MPI_Comm communicator=MPI_COMM_WORLD, const bool overlapping=false) const
types::global_dof_index size_type
void add_indices(const ForwardIterator &begin, const ForwardIterator &end)
IndexSet operator&(const IndexSet &is) const
virtual size_type size() const override
#define DEAL_II_DEPRECATED
#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)
Tpetra::KokkosCompat::KokkosDeviceWrapperNode< typename MemorySpace::kokkos_space::execution_space, typename MemorySpace::kokkos_space > NodeType
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)