16 #ifndef dealii_index_set_h 17 #define dealii_index_set_h 25 #include <boost/serialization/vector.hpp> 32 #ifdef DEAL_II_WITH_TRILINOS 33 # include <Epetra_Map.h> 34 # ifdef DEAL_II_TRILINOS_WITH_TPETRA 35 # include <Tpetra_Map.hpp> 39 #if defined(DEAL_II_WITH_MPI) || defined(DEAL_II_WITH_PETSC) 43 # ifndef MPI_COMM_WORLD 44 # define MPI_COMM_WORLD 0 141 #ifdef DEAL_II_WITH_TRILINOS 145 explicit IndexSet(
const Epetra_BlockMap &map);
198 template <
typename ForwardIterator>
353 std::vector<IndexSet>
355 const std::vector<types::global_dof_index> &n_indices_per_block)
const;
416 template <
typename VectorType>
424 template <
class StreamType>
426 print(StreamType &out)
const;
433 write(std::ostream &out)
const;
440 read(std::istream &in);
456 #ifdef DEAL_II_WITH_TRILINOS 487 const bool overlapping =
false)
const;
489 # ifdef DEAL_II_TRILINOS_WITH_TPETRA 490 Tpetra::Map<int, types::global_dof_index>
492 const bool overlapping =
false)
const;
506 <<
"The global index " << arg1
507 <<
" is not an element of this set.");
513 template <
class Archive>
515 serialize(Archive &ar,
const unsigned int version);
933 return sizeof(
Range);
940 template <
class Archive>
942 serialize(Archive &ar,
const unsigned int version);
1031 , range_idx(range_idx)
1089 if (range_idx < index_set->
ranges.size() - 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"));
1163 : accessor(idxset, range_idx)
1228 return !(*
this == other);
1248 "Can not compare iterators belonging to different IndexSets"));
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."));
1281 idx < index_set->
ranges[range_idx].end,
1283 "Invalid index argument for IndexSet::ElementIterator constructor."));
1301 (range_idx < index_set->
ranges.size() &&
1305 return (range_idx < index_set->
ranges.size() &&
1316 "Impossible to dereference an IndexSet::ElementIterator that is invalid"));
1328 "Can not compare iterators belonging to different IndexSets"));
1340 "Impossible to advance an IndexSet::ElementIterator that is invalid"));
1347 if (range_idx < index_set->
ranges.size() - 1)
1386 return !(*
this == other);
1397 "Can not compare iterators belonging to different IndexSets"));
1404 inline std::ptrdiff_t
1410 "Can not compare iterators belonging to different IndexSets"));
1413 if (!(*
this < other))
1414 return -(other - *
this);
1435 "Inconsistent iterator state. Did you invalidate iterators by modifying the IndexSet?"));
1483 :
ranges(std::move(is.ranges))
1489 is.is_compressed =
true;
1490 is.index_space_size = 0;
1501 ranges = std::move(is.ranges);
1507 is.is_compressed =
true;
1508 is.index_space_size = 0;
1523 return {
this, 0,
ranges[0].begin};
1539 std::vector<Range>::const_iterator main_range =
1542 Range r(global_index, global_index + 1);
1545 std::vector<Range>::const_iterator range_begin, range_end;
1546 if (global_index < main_range->
begin)
1548 range_begin =
ranges.begin();
1549 range_end = main_range;
1553 range_begin = main_range;
1554 range_end =
ranges.end();
1559 const std::vector<Range>::const_iterator p =
1572 if (global_index < p->begin)
1575 return {
this,
static_cast<size_type>(p -
ranges.begin()), global_index};
1626 ExcMessage(
"This function can only be called if the current " 1627 "object does not yet contain any elements."));
1658 const Range new_range(index, index + 1);
1660 ranges.push_back(new_range);
1661 else if (index ==
ranges.back().end)
1685 const Range new_range(begin, end);
1690 ranges.push_back(new_range);
1702 template <
typename ForwardIterator>
1714 std::vector<std::pair<size_type, size_type>> tmp_ranges;
1715 bool ranges_are_sorted =
true;
1716 for (ForwardIterator p = begin; p !=
end;)
1720 ForwardIterator q = p;
1722 while ((q != end) && (*q == end_index))
1728 tmp_ranges.emplace_back(begin_index, end_index);
1735 if (p != end && *p < end_index)
1736 ranges_are_sorted =
false;
1739 if (!ranges_are_sorted)
1740 std::sort(tmp_ranges.begin(), tmp_ranges.end());
1750 if (tmp_ranges.size() > 9)
1753 tmp_set.
ranges.reserve(tmp_ranges.size());
1754 for (
const auto &i : tmp_ranges)
1759 for (
const auto &i : tmp_ranges)
1768 if (
ranges.empty() ==
false)
1790 std::vector<Range>::const_iterator p = std::upper_bound(
1798 return ((index >= p->begin) && (index < p->end));
1806 return (p->end > index);
1819 return (
ranges.size() <= 1);
1847 for (
const auto &range :
ranges)
1848 s += (range.end - range.begin);
1872 const std::vector<Range>::const_iterator main_range =
1875 return main_range->nth_index_in_set;
1889 std::vector<Range>::const_iterator main_range =
1891 if (n >= main_range->nth_index_in_set &&
1893 return main_range->begin + (n - main_range->nth_index_in_set);
1900 std::vector<Range>::const_iterator range_begin, range_end;
1903 range_begin =
ranges.begin();
1904 range_end = main_range;
1908 range_begin = main_range + 1;
1909 range_end =
ranges.end();
1912 const std::vector<Range>::const_iterator p =
1916 return p->begin + (n - p->nth_index_in_set);
1936 std::vector<Range>::const_iterator main_range =
1938 if (n >= main_range->begin && n < main_range->
end)
1939 return (n - main_range->begin) + main_range->nth_index_in_set;
1942 std::vector<Range>::const_iterator range_begin, range_end;
1943 if (n < main_range->
begin)
1945 range_begin =
ranges.begin();
1946 range_end = main_range;
1950 range_begin = main_range + 1;
1951 range_end =
ranges.end();
1954 std::vector<Range>::const_iterator p =
1958 if (p == range_end || p->end == n || p->begin > n)
1964 return (n - p->begin) + p->nth_index_in_set;
1995 template <
typename Vector>
2003 std::fill(vector.begin(), vector.end(), 0);
2007 for (
const auto &range :
ranges)
2008 for (
size_type i = range.begin; i < range.end; ++i)
2014 template <
class StreamType>
2020 std::vector<Range>::const_iterator p;
2023 if (p->end - p->begin == 1)
2026 out <<
"[" << p->begin <<
"," << p->end - 1 <<
"]";
2031 out <<
"}" << std::endl;
2036 template <
class Archive>
2045 template <
class Archive>
Iterator lower_bound(Iterator first, Iterator last, const T &val)
friend bool operator==(const Range &range_1, const Range &range_2)
void fill_binary_vector(VectorType &vector) const
static const unsigned int invalid_unsigned_int
ElementIterator end() const
void add_index(const size_type index)
const IntervalAccessor * operator->() const
const IntervalAccessor & operator*() const
const IndexSet * index_set
IndexSet & operator=(const IndexSet &)=default
void block_read(std::istream &in)
size_type largest_range_starting_index() const
#define AssertIndexRange(index, range)
std::ptrdiff_t operator-(const ElementIterator &p) const
void add_indices(const ForwardIterator &begin, const ForwardIterator &end)
types::global_dof_index size_type
ElementIterator(const IndexSet *idxset, const size_type range_idx, const size_type index)
bool operator<(const IntervalIterator &) const
std::forward_iterator_tag iterator_category
std::size_t memory_consumption() const
size_type n_elements() const
size_type index_space_size
Tpetra::Map< int, types::global_dof_index > make_tpetra_map(const MPI_Comm &communicator=MPI_COMM_WORLD, const bool overlapping=false) const
bool is_ascending_and_one_to_one(const MPI_Comm &communicator) const
Epetra_Map make_trilinos_map(const MPI_Comm &communicator=MPI_COMM_WORLD, const bool overlapping=false) const
void print(StreamType &out) const
void serialize(Archive &ar, const unsigned int version)
void serialize(Archive &ar, const unsigned int version)
static ::ExceptionBase & ExcMessage(std::string arg1)
void block_write(std::ostream &out) const
std::vector< Range > ranges
static ::ExceptionBase & ExcIndexNotPresent(size_type arg1)
#define DeclException1(Exception1, type1, outsequence)
void subtract_set(const IndexSet &other)
#define Assert(cond, exc)
friend class IntervalIterator
std::forward_iterator_tag iterator_category
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
constexpr SymmetricTensor< rank_, dim, typename ProductType< Number, OtherNumber >::type > operator-(const SymmetricTensor< rank_, dim, Number > &left, const SymmetricTensor< rank_, dim, OtherNumber > &right)
bool operator<(const ElementIterator &) const
size_type index_within_set(const size_type global_index) const
bool operator==(const IndexSet &is) const
IntervalAccessor accessor
#define DEAL_II_NAMESPACE_CLOSE
IntervalAccessor & operator=(const IntervalAccessor &other)
SynchronousIterators< Iterators > operator++(SynchronousIterators< Iterators > &a)
static bool end_compare(const IndexSet::Range &x, const IndexSet::Range &y)
bool operator==(const IntervalIterator &) const
const IndexSet * index_set
bool operator==(const IntervalAccessor &other) const
unsigned int n_intervals() const
IndexSet tensor_product(const IndexSet &other) const
int operator-(const IntervalIterator &p) const
bool operator!=(const IndexSet &is) const
void fill_index_vector(std::vector< size_type > &indices) const
void add_range(const size_type begin, const size_type end)
IndexSet operator &(const IndexSet &is) const
void set_size(const size_type size)
ElementIterator & operator++()
unsigned int global_dof_index
IntervalAccessor(const IndexSet *idxset, const size_type range_idx)
std::vector< IndexSet > split_by_block(const std::vector< types::global_dof_index > &n_indices_per_block) const
IndexSet get_view(const size_type begin, const size_type end) const
ElementIterator end() const
static bool nth_index_compare(const IndexSet::Range &x, const IndexSet::Range &y)
static std::size_t memory_consumption()
IntervalIterator begin_intervals() const
IndexSet complete_index_set(const IndexSet::size_type N)
bool is_contiguous() const
Threads::Mutex compress_mutex
#define DEAL_II_NAMESPACE_OPEN
IntervalIterator end_intervals() const
bool operator<(const IntervalAccessor &other) const
bool operator!=(const ElementIterator &) const
ElementIterator begin() const
TrilinosWrappers::types::int_type global_index(const Epetra_BlockMap &map, const ::types::global_dof_index i)
void write(std::ostream &out) const
bool is_element(const size_type index) const
std::enable_if< std::is_floating_point< T >::value &&std::is_floating_point< U >::value, typename ProductType< std::complex< T >, std::complex< U > >::type >::type operator*(const std::complex< T > &left, const std::complex< U > &right)
bool operator==(const ElementIterator &) const
ElementIterator at(const size_type global_index) const
const types::global_dof_index invalid_dof_index
std::ptrdiff_t difference_type
std::ptrdiff_t difference_type
ElementIterator begin() const
void read(std::istream &in)
size_type n_elements() const
size_type nth_index_in_set(const size_type local_index) const
IntervalIterator & operator++()
size_type nth_index_in_set
static ::ExceptionBase & ExcInternalError()
size_type operator*() const
bool operator!=(const IntervalIterator &) const