15#ifndef dealii_index_set_h
16#define dealii_index_set_h
29#include <boost/container/small_vector.hpp>
35#ifdef DEAL_II_WITH_TRILINOS
38# include <Epetra_Map.h>
39# ifdef DEAL_II_TRILINOS_WITH_TPETRA
40# include <Tpetra_Map.hpp>
46#ifdef DEAL_II_WITH_PETSC
141#ifdef DEAL_II_WITH_TRILINOS
143# ifdef DEAL_II_TRILINOS_WITH_TPETRA
147 template <
typename NodeType>
150 const Tpetra::Map<int, types::signed_global_dof_index, NodeType>> &map);
156 explicit IndexSet(
const Epetra_BlockMap &map);
229 template <
typename ForwardIterator>
458 std::vector<IndexSet>
460 const std::vector<types::global_dof_index> &n_indices_per_block)
const;
497 DEAL_II_DEPRECATED_EARLY
509 DEAL_II_DEPRECATED_EARLY
521 std::vector<size_type>
546 template <
typename VectorType>
564 template <
typename StreamType>
566 print(StreamType &out)
const;
573 write(std::ostream &out)
const;
580 read(std::istream &in);
596#ifdef DEAL_II_WITH_TRILINOS
629# ifdef DEAL_II_TRILINOS_WITH_TPETRA
633 Tpetra::Map<int, types::signed_global_dof_index, NodeType>
640 Teuchos::RCP<Tpetra::Map<int, types::signed_global_dof_index, NodeType>>
646#ifdef DEAL_II_WITH_PETSC
661 <<
"The global index " << arg1
662 <<
" is not an element of this set.");
669 template <
class Archive>
671 serialize(Archive &ar,
const unsigned int version);
1092 return sizeof(
Range);
1100 template <
class Archive>
1102 serialize(Archive &ar,
const unsigned int version);
1194 boost::container::small_vector<std::pair<size_type, size_type>, 200>
1196 const bool ranges_are_sorted);
1294 if (range_idx < index_set->
ranges.size() - 1)
1330 "Can not compare accessors pointing to different IndexSets"));
1342 "Can not compare accessors pointing to different IndexSets"));
1354 "Impossible to advance an IndexSet::IntervalIterator that is invalid"));
1433 return !(*
this == other);
1453 "Can not compare iterators belonging to different IndexSets"));
1456 accessor.index_set->ranges.size() :
1460 accessor.index_set->ranges.size() :
1464 return static_cast<int>(lhs - rhs);
1466 return -
static_cast<int>(rhs - lhs);
1483 "Invalid range index for IndexSet::ElementIterator constructor."));
1488 "Invalid index argument for IndexSet::ElementIterator constructor."));
1506 (range_idx < index_set->
ranges.size() &&
1510 return (range_idx < index_set->
ranges.size() &&
1522 "Impossible to dereference an IndexSet::ElementIterator that is invalid"));
1534 "Can not compare iterators belonging to different IndexSets"));
1546 "Impossible to advance an IndexSet::ElementIterator that is invalid"));
1553 if (range_idx < index_set->
ranges.size() - 1)
1592 return !(*
this == other);
1603 "Can not compare iterators belonging to different IndexSets"));
1610inline std::ptrdiff_t
1616 "Can not compare iterators belonging to different IndexSets"));
1619 if (!(*
this < other))
1620 return -(other - *
this);
1641 "Inconsistent iterator state. Did you invalidate iterators by modifying the IndexSet?"));
1689 :
ranges(std::move(is.ranges))
1695 is.is_compressed =
true;
1696 is.index_space_size = 0;
1707 ranges = std::move(is.ranges);
1713 is.is_compressed =
true;
1714 is.index_space_size = 0;
1729 return {
this, 0,
ranges[0].begin};
1782 ExcMessage(
"This function can only be called if the current "
1783 "object does not yet contain any elements."));
1844template <
typename ForwardIterator>
1856 boost::container::small_vector<std::pair<size_type, size_type>, 200>
1858 bool ranges_are_sorted =
true;
1859 for (ForwardIterator p =
begin; p !=
end;)
1871 ForwardIterator q = p;
1873 while ((q !=
end) && (*q == *p))
1881 while ((q !=
end) && (
static_cast<size_type>(*q) == end_index))
1884 while ((q !=
end) && (
static_cast<size_type>(*q) == end_index))
1891 tmp_ranges.emplace_back(begin_index, end_index);
1899 if ((p !=
end) && (
static_cast<size_type>(*p) < end_index))
1900 ranges_are_sorted =
false;
1911 if (
ranges.empty() ==
false)
1920 else if (
ranges.size() > 1)
1935 return (
ranges.size() <= 1);
1964 for (
const auto &range :
ranges)
1965 s += (range.end - range.begin);
1989 const std::vector<Range>::const_iterator main_range =
1992 return main_range->nth_index_in_set;
2007 if (n >= main_range->nth_index_in_set &&
2009 return main_range->begin + (n - main_range->nth_index_in_set);
2034 else if (
ranges.size() > 1)
2048 return (is.
size() == 0);
2050 return (
size() == 0);
2069 return (is.
size() != 0);
2071 return (
size() != 0);
2084template <
typename Vector>
2092 std::fill(vector.
begin(), vector.
end(), 0);
2096 for (
const auto &range :
ranges)
2097 for (
size_type i = range.begin; i < range.end; ++i)
2103template <
typename StreamType>
2109 std::vector<Range>::const_iterator p;
2112 if (p->end - p->begin == 1)
2115 out <<
'[' << p->begin <<
',' << p->end - 1 <<
']';
2120 out <<
'}' << std::endl;
2125template <
class Archive>
2134template <
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
friend class IntervalIterator
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
IntervalAccessor & reference
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
IntervalAccessor value_type
IntervalIterator & operator++()
const IntervalAccessor * operator->() const
IntervalIterator(const IndexSet *idxset, const size_type range_idx)
IntervalAccessor * pointer
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_DISABLE_EXTRA_DIAGNOSTICS
constexpr bool running_in_debug_mode()
#define DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_ENABLE_EXTRA_DIAGNOSTICS
static ::ExceptionBase & ExcIndexRangeType(T arg1, T arg2, T arg3)
#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
constexpr types::global_dof_index invalid_dof_index
constexpr unsigned int invalid_unsigned_int
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)