16 #ifndef dealii_index_set_h 17 #define dealii_index_set_h 19 #include <deal.II/base/config.h> 21 #include <deal.II/base/exceptions.h> 22 #include <deal.II/base/thread_management.h> 23 #include <deal.II/base/utilities.h> 25 #include <boost/serialization/vector.hpp> 32 #ifdef DEAL_II_WITH_TRILINOS 33 # include <Epetra_Map.h> 36 #if defined(DEAL_II_WITH_MPI) || defined(DEAL_II_WITH_PETSC) 40 # ifndef MPI_COMM_WORLD 41 # define MPI_COMM_WORLD 0 45 DEAL_II_NAMESPACE_OPEN
138 #ifdef DEAL_II_WITH_TRILINOS 142 explicit IndexSet(
const Epetra_Map &map);
195 template <
typename ForwardIterator>
377 template <
typename VectorType>
385 template <
class StreamType>
387 print(StreamType &out)
const;
394 write(std::ostream &out)
const;
401 read(std::istream &in);
417 #ifdef DEAL_II_WITH_TRILINOS 448 const bool overlapping =
false)
const;
461 <<
"The global index " << arg1
462 <<
" is not an element of this set.");
468 template <
class Archive>
470 serialize(Archive &ar,
const unsigned int version);
659 using difference_type = std::ptrdiff_t;
750 using difference_type = std::ptrdiff_t;
862 (range_1.begin < range_2.begin) ||
863 ((range_1.begin == range_2.begin) && (range_1.end < range_2.end)));
869 return x.end < y.end;
875 return (x.nth_index_in_set + (x.end - x.begin) <
876 y.nth_index_in_set + (y.end - y.begin));
882 return ((range_1.begin == range_2.begin) && (range_1.end == range_2.end));
888 return sizeof(
Range);
895 template <
class Archive>
897 serialize(Archive &ar,
const unsigned int version);
986 , range_idx(range_idx)
1046 if (range_idx < index_set->
ranges.size() - 1)
1084 "Can not compare accessors pointing to different IndexSets"));
1096 "Can not compare accessors pointing to different IndexSets"));
1108 "Impossible to advance an IndexSet::IntervalIterator that is invalid"));
1122 : accessor(idxset, range_idx)
1203 return !(*
this == other);
1223 "Can not compare iterators belonging to different IndexSets"));
1234 return static_cast<int>(lhs - rhs);
1236 return -
static_cast<int>(rhs - lhs);
1248 , range_idx(range_idx)
1253 "Invalid range index for IndexSet::ElementIterator constructor."));
1256 idx < index_set->
ranges[range_idx].end,
1258 "Invalid index argument for IndexSet::ElementIterator constructor."));
1276 (range_idx < index_set->
ranges.size() &&
1280 return (range_idx < index_set->
ranges.size() &&
1291 "Impossible to dereference an IndexSet::ElementIterator that is invalid"));
1303 "Can not compare iterators belonging to different IndexSets"));
1315 "Impossible to advance an IndexSet::ElementIterator that is invalid"));
1322 if (range_idx < index_set->
ranges.size() - 1)
1361 return !(*
this == other);
1372 "Can not compare iterators belonging to different IndexSets"));
1379 inline std::ptrdiff_t
1385 "Can not compare iterators belonging to different IndexSets"));
1388 if (!(*
this < other))
1389 return -(other - *
this);
1410 "Inconsistent iterator state. Did you invalidate iterators by modifying the IndexSet?"));
1434 , nth_index_in_set(
numbers::invalid_dof_index)
1464 is.is_compressed =
true;
1465 is.index_space_size = 0;
1476 ranges = std::move(is.ranges);
1482 is.is_compressed =
true;
1483 is.index_space_size = 0;
1510 ExcIndexRangeType<size_type>(global_index, 0,
size()));
1515 std::vector<Range>::const_iterator main_range =
1518 Range r(global_index, global_index + 1);
1521 std::vector<Range>::const_iterator range_begin, range_end;
1522 if (global_index < main_range->
begin)
1524 range_begin =
ranges.begin();
1525 range_end = main_range;
1529 range_begin = main_range;
1530 range_end =
ranges.end();
1535 const std::vector<Range>::const_iterator p =
1548 if (global_index < p->begin)
1602 ExcMessage(
"This function can only be called if the current " 1603 "object does not yet contain any elements."));
1635 const Range new_range(index, index + 1);
1637 ranges.push_back(new_range);
1638 else if (index ==
ranges.back().end)
1650 template <
typename ForwardIterator>
1656 for (ForwardIterator p = begin; p !=
end;)
1660 ForwardIterator q = p;
1662 while ((q != end) && (*q == end_index))
1678 if (
ranges.empty() ==
false)
1700 std::vector<Range>::const_iterator p = std::upper_bound(
1708 return ((index >= p->begin) && (index < p->end));
1716 return (p->end > index);
1729 return (
ranges.size() <= 1);
1752 v = r.nth_index_in_set + r.end - r.begin;
1757 for (std::vector<Range>::iterator range =
ranges.begin();
1760 s += (range->end - range->begin);
1784 const std::vector<Range>::const_iterator main_range =
1787 return main_range->nth_index_in_set;
1801 std::vector<Range>::const_iterator main_range =
1803 if (n >= main_range->nth_index_in_set &&
1805 return main_range->begin + (n - main_range->nth_index_in_set);
1811 r.nth_index_in_set = n;
1812 std::vector<Range>::const_iterator range_begin, range_end;
1815 range_begin =
ranges.begin();
1816 range_end = main_range;
1820 range_begin = main_range + 1;
1821 range_end =
ranges.end();
1824 const std::vector<Range>::const_iterator p =
1828 return p->begin + (n - p->nth_index_in_set);
1848 std::vector<Range>::const_iterator main_range =
1850 if (n >= main_range->begin && n < main_range->
end)
1851 return (n - main_range->begin) + main_range->nth_index_in_set;
1854 std::vector<Range>::const_iterator range_begin, range_end;
1855 if (n < main_range->
begin)
1857 range_begin =
ranges.begin();
1858 range_end = main_range;
1862 range_begin = main_range + 1;
1863 range_end =
ranges.end();
1866 std::vector<Range>::const_iterator p =
1870 if (p == range_end || p->end == n || p->begin > n)
1876 return (n - p->begin) + p->nth_index_in_set;
1907 template <
typename Vector>
1915 std::fill(vector.begin(), vector.end(), 0);
1919 for (std::vector<Range>::iterator it =
ranges.begin(); it !=
ranges.end();
1927 template <
class StreamType>
1933 std::vector<Range>::const_iterator p;
1936 if (p->end - p->begin == 1)
1939 out <<
"[" << p->begin <<
"," << p->end - 1 <<
"]";
1944 out <<
"}" << std::endl;
1949 template <
class Archive>
1958 template <
class Archive>
1965 DEAL_II_NAMESPACE_CLOSE
Iterator lower_bound(Iterator first, Iterator last, const T &val)
bool operator<(const ElementIterator &) const
static const unsigned int invalid_unsigned_int
void add_index(const size_type index)
IntervalIterator begin_intervals() const
size_type n_elements() const
const IndexSet * index_set
IndexSet & operator=(const IndexSet &)=default
void block_read(std::istream &in)
bool is_ascending_and_one_to_one(const MPI_Comm &communicator) const
size_type n_elements() const
void add_indices(const ForwardIterator &begin, const ForwardIterator &end)
void fill_binary_vector(VectorType &vector) const
bool operator==(const IndexSet &is) const
bool operator==(const IntervalIterator &) const
types::global_dof_index size_type
ElementIterator(const IndexSet *idxset, const size_type range_idx, const size_type index)
std::forward_iterator_tag iterator_category
SymmetricTensor< rank_, dim, Number > operator*(const SymmetricTensor< rank_, dim, Number > &t, const Number &factor)
unsigned long long int global_dof_index
void print(StreamType &out) const
bool operator==(const IntervalAccessor &other) const
size_type index_space_size
ElementIterator begin() const
void block_write(std::ostream &out) const
bool is_contiguous() const
void serialize(Archive &ar, const unsigned int version)
unsigned int n_intervals() const
IndexSet complete_index_set(const unsigned int N)
void serialize(Archive &ar, const unsigned int version)
static::ExceptionBase & ExcMessage(std::string arg1)
void write(std::ostream &out) const
size_type operator*() const
IntervalIterator & operator=(const IntervalIterator &other)
std::vector< Range > ranges
static::ExceptionBase & ExcIndexNotPresent(size_type arg1)
#define DeclException1(Exception1, type1, outsequence)
bool operator!=(const IndexSet &is) const
void subtract_set(const IndexSet &other)
void fill_index_vector(std::vector< size_type > &indices) const
#define Assert(cond, exc)
unsigned int largest_range_starting_index() const
std::forward_iterator_tag iterator_category
static::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
const IntervalAccessor & operator*() const
IntervalAccessor accessor
IndexSet operator&(const IndexSet &is) const
ElementIterator at(const size_type global_index) const
IntervalAccessor & operator=(const IntervalAccessor &other)
IndexSet get_view(const size_type begin, const size_type end) const
bool operator!=(const IntervalIterator &) const
const IndexSet * index_set
Epetra_Map make_trilinos_map(const MPI_Comm &communicator=MPI_COMM_WORLD, const bool overlapping=false) const
ElementIterator begin() const
void add_range(const size_type begin, const size_type end)
void set_size(const size_type size)
ElementIterator & operator++()
IntervalAccessor(const IndexSet *idxset, const size_type range_idx)
bool operator<(const IntervalIterator &) const
ElementIterator end() const
Threads::Mutex compress_mutex
bool operator<(const IntervalAccessor &other) const
bool operator!=(const ElementIterator &) const
size_type index_within_set(const size_type global_index) const
bool is_element(const size_type index) const
std::size_t memory_consumption() const
ElementIterator end() const
const types::global_dof_index invalid_dof_index
size_type nth_index_in_set(const unsigned int local_index) const
bool operator==(const ElementIterator &) const
int operator-(const IntervalIterator &p) const
SymmetricTensor< rank_, dim, typename ProductType< Number, OtherNumber >::type > operator-(const SymmetricTensor< rank_, dim, Number > &left, const SymmetricTensor< rank_, dim, OtherNumber > &right)
void read(std::istream &in)
std::ptrdiff_t operator-(const ElementIterator &p) const
const IntervalAccessor * operator->() const
IntervalIterator & operator++()
IntervalIterator end_intervals() const
static::ExceptionBase & ExcInternalError()