13#ifndef dealii_index_set_h
14#define dealii_index_set_h
27#include <boost/container/small_vector.hpp>
33#ifdef DEAL_II_WITH_TRILINOS
36# ifdef DEAL_II_TRILINOS_WITH_EPETRA
37# 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_TRILINOS_WITH_TPETRA
145 template <
typename NodeType>
148 const Tpetra::Map<int, types::signed_global_dof_index, NodeType>> &map);
151#ifdef DEAL_II_TRILINOS_WITH_EPETRA
155 explicit IndexSet(
const Epetra_BlockMap &map);
228 template <
typename ForwardIterator>
457 std::vector<IndexSet>
459 const std::vector<types::global_dof_index> &n_indices_per_block)
const;
523 std::vector<size_type>
538 template <
typename VectorType>
556 template <
typename StreamType>
558 print(StreamType &out)
const;
565 write(std::ostream &out)
const;
572 read(std::istream &in);
588#ifdef DEAL_II_TRILINOS_WITH_EPETRA
622#ifdef DEAL_II_TRILINOS_WITH_TPETRA
626 Tpetra::Map<int, types::signed_global_dof_index, NodeType>
633 Teuchos::RCP<Tpetra::Map<int, types::signed_global_dof_index, NodeType>>
638#ifdef DEAL_II_WITH_PETSC
653 <<
"The global index " << arg1
654 <<
" is not an element of this set.");
661 template <
class Archive>
663 serialize(Archive &ar,
const unsigned int version);
1084 return sizeof(
Range);
1092 template <
class Archive>
1094 serialize(Archive &ar,
const unsigned int version);
1186 boost::container::small_vector<std::pair<size_type, size_type>, 200>
1188 const bool ranges_are_sorted);
1286 if (range_idx < index_set->
ranges.size() - 1)
1322 "Can not compare accessors pointing to different IndexSets"));
1334 "Can not compare accessors pointing to different IndexSets"));
1346 "Impossible to advance an IndexSet::IntervalIterator that is invalid"));
1425 return !(*
this == other);
1445 "Can not compare iterators belonging to different IndexSets"));
1448 accessor.index_set->ranges.size() :
1452 accessor.index_set->ranges.size() :
1456 return static_cast<int>(lhs - rhs);
1458 return -
static_cast<int>(rhs - lhs);
1475 "Invalid range index for IndexSet::ElementIterator constructor."));
1480 "Invalid index argument for IndexSet::ElementIterator constructor."));
1498 (range_idx < index_set->
ranges.size() &&
1502 return (range_idx < index_set->
ranges.size() &&
1514 "Impossible to dereference an IndexSet::ElementIterator that is invalid"));
1526 "Can not compare iterators belonging to different IndexSets"));
1538 "Impossible to advance an IndexSet::ElementIterator that is invalid"));
1545 if (range_idx < index_set->
ranges.size() - 1)
1584 return !(*
this == other);
1595 "Can not compare iterators belonging to different IndexSets"));
1602inline std::ptrdiff_t
1608 "Can not compare iterators belonging to different IndexSets"));
1611 if (!(*
this < other))
1612 return -(other - *
this);
1633 "Inconsistent iterator state. Did you invalidate iterators by modifying the IndexSet?"));
1681 :
ranges(std::move(is.ranges))
1687 is.is_compressed =
true;
1688 is.index_space_size = 0;
1699 ranges = std::move(is.ranges);
1705 is.is_compressed =
true;
1706 is.index_space_size = 0;
1721 return {
this, 0,
ranges[0].begin};
1774 ExcMessage(
"This function can only be called if the current "
1775 "object does not yet contain any elements."));
1836template <
typename ForwardIterator>
1848 boost::container::small_vector<std::pair<size_type, size_type>, 200>
1850 bool ranges_are_sorted =
true;
1851 for (ForwardIterator p =
begin; p !=
end;)
1863 ForwardIterator q = p;
1865 while ((q !=
end) && (*q == *p))
1873 while ((q !=
end) && (
static_cast<size_type>(*q) == end_index))
1876 while ((q !=
end) && (
static_cast<size_type>(*q) == end_index))
1883 tmp_ranges.emplace_back(begin_index, end_index);
1891 if ((p !=
end) && (
static_cast<size_type>(*p) < end_index))
1892 ranges_are_sorted =
false;
1903 if (
ranges.empty() ==
false)
1912 else if (
ranges.size() > 1)
1927 return (
ranges.size() <= 1);
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
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
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
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
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
#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)