16 #ifndef dealii__index_set_h 17 #define dealii__index_set_h 19 #include <deal.II/base/config.h> 20 #include <deal.II/base/utilities.h> 21 #include <deal.II/base/exceptions.h> 22 #include <boost/serialization/vector.hpp> 26 #ifdef DEAL_II_WITH_TRILINOS 27 # include <Epetra_Map.h> 30 #if defined(DEAL_II_WITH_MPI) || defined(DEAL_II_WITH_PETSC) 34 # ifndef MPI_COMM_WORLD 35 # define MPI_COMM_WORLD 0 39 DEAL_II_NAMESPACE_OPEN
109 #ifdef DEAL_II_WITH_TRILINOS 113 explicit IndexSet(
const Epetra_Map &map);
137 size_type
size ()
const;
146 const size_type
end);
162 template <
typename ForwardIterator>
164 const ForwardIterator &
end);
182 const unsigned int offset = 0);
187 bool is_element (
const size_type index)
const;
273 const size_type
end)
const;
299 template <
typename VectorType>
306 template <
class StreamType>
307 void print(StreamType &out)
const;
313 void write(std::ostream &out)
const;
319 void read(std::istream &in);
333 #ifdef DEAL_II_WITH_TRILINOS 363 const bool overlapping =
false)
const;
374 <<
"The global index " << arg1
375 <<
" is not an element of this set.");
381 template <
class Archive>
382 void serialize (Archive &ar,
const unsigned int version);
433 size_type
last()
const;
577 size_type operator* ()
const;
699 Range (
const size_type i1,
704 const Range &range_2)
706 return ((range_1.begin < range_2.begin)
708 ((range_1.begin == range_2.begin)
710 (range_1.end < range_2.end)));
715 return x.end < y.end;
721 return (x.nth_index_in_set+(x.end-x.begin) <
722 y.nth_index_in_set+(y.end-y.begin));
727 const Range &range_2)
729 return ((range_1.begin == range_2.begin)
731 (range_1.end == range_2.end));
736 return sizeof(
Range);
743 template <
class Archive>
744 void serialize (Archive &ar,
const unsigned int version);
823 :
index_set(idxset), range_idx(range_idx)
825 Assert(range_idx < idxset->
n_intervals(), ExcInternalError(
"Invalid range index"));
859 if (range_idx < index_set->
ranges.size()-1)
920 : accessor(idxset, range_idx)
987 return !(*
this == other);
1005 return static_cast<int>(lhs - rhs);
1007 return -
static_cast<int>(rhs - lhs);
1019 (range_idx < index_set->
ranges.size() && idx<index_set->ranges[range_idx].end)
1020 , ExcInternalError(
"Invalid ElementIterator state."));
1022 return range_idx < index_set->ranges.size() && idx<index_set->ranges[range_idx].end;
1027 : index_set(idxset), range_idx(range_idx), idx(index)
1030 ExcMessage(
"Invalid range index for IndexSet::ElementIterator constructor."));
1033 idx < index_set->
ranges[range_idx].end,
1034 ExcInternalError(
"Invalid index argument for IndexSet::ElementIterator constructor."));
1067 if (range_idx < index_set->
ranges.size()-1)
1101 return !(*
this == other);
1117 if (!(*
this < other))
1118 return -(other-*
this);
1133 ExcMessage(
"Inconsistent iterator state. Did you invalidate iterators by modifying the IndexSet?"));
1237 ExcMessage (
"This function can only be called if the current " 1238 "object does not yet contain any elements."));
1273 const Range new_range(index, index+1);
1275 ranges.push_back(new_range);
1276 else if (index ==
ranges.back().end)
1288 template <
typename ForwardIterator>
1292 const ForwardIterator &
end)
1296 for (ForwardIterator p=begin; p!=
end;)
1300 ForwardIterator q = p;
1302 while ((q != end) && (*q == end_index))
1319 if (
ranges.empty() ==
false)
1341 std::vector<Range>::const_iterator
1350 return ((index >= p->begin) && (index < p->end));
1353 ExcInternalError());
1357 Assert (p->begin <= index, ExcInternalError());
1359 return (p->end > index);
1373 return (
ranges.size() <= 1);
1389 v = r.nth_index_in_set + r.end - r.begin;
1394 for (std::vector<Range>::iterator range =
ranges.begin();
1397 s += (range->end - range->begin);
1398 Assert(s==v, ExcInternalError());
1425 return main_range->nth_index_in_set;
1442 if (n>=main_range->nth_index_in_set &&
1444 return main_range->begin + (n-main_range->nth_index_in_set);
1450 r.nth_index_in_set = n;
1451 std::vector<Range>::const_iterator range_begin, range_end;
1454 range_begin =
ranges.begin();
1455 range_end = main_range;
1459 range_begin = main_range + 1;
1460 range_end =
ranges.end();
1463 const std::vector<Range>::const_iterator
1465 Range::nth_index_compare);
1468 return p->begin + (n-p->nth_index_in_set);
1481 Assert (n <
size(), ExcIndexRangeType<size_type> (n, 0,
size()));
1487 if (n >= main_range->begin && n < main_range->
end)
1488 return (n-main_range->begin) + main_range->nth_index_in_set;
1491 std::vector<Range>::const_iterator range_begin, range_end;
1492 if (n<main_range->
begin)
1494 range_begin =
ranges.begin();
1495 range_end = main_range;
1499 range_begin = main_range + 1;
1500 range_end =
ranges.end();
1503 std::vector<Range>::const_iterator
1505 Range::end_compare);
1508 Assert(p->begin<=n, ExcInternalError());
1509 Assert(n<p->end, ExcInternalError());
1510 return (n-p->begin) + p->nth_index_in_set;
1520 ExcDimensionMismatch (
size(), is.
size()));
1535 ExcDimensionMismatch (
size(), is.
size()));
1545 template <
typename Vector>
1550 ExcDimensionMismatch (vector.
size(),
size()));
1554 std::fill (vector.
begin(), vector.
end(), 0);
1558 for (std::vector<Range>::iterator it =
ranges.begin();
1567 template <
class StreamType>
1574 std::vector<Range>::const_iterator p;
1577 if (p->end-p->begin==1)
1580 out <<
"[" << p->begin <<
"," << p->end-1 <<
"]";
1585 out <<
"}" << std::endl;
1590 template <
class Archive>
1600 template <
class Archive>
1608 DEAL_II_NAMESPACE_CLOSE
Iterator lower_bound(Iterator first, Iterator last, const T &val)
void fill_binary_vector(VectorType &vector) const
ElementIterator end() const
void add_index(const size_type index)
IndexSet operator&(const IndexSet &is) const
const IntervalAccessor * operator->() const
const IntervalAccessor & operator*() const
size_type nth_index_in_set(const unsigned int local_index) const
const IndexSet * index_set
void block_read(std::istream &in)
::ExceptionBase & ExcMessage(std::string arg1)
std::ptrdiff_t operator-(const ElementIterator &p) const
void add_indices(const ForwardIterator &begin, const ForwardIterator &end)
unsigned int largest_range_starting_index() const
ElementIterator(const IndexSet *idxset, const size_type range_idx, const size_type index)
bool operator<(const IntervalIterator &) const
std::size_t memory_consumption() const
size_type n_elements() const
size_type index_space_size
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)
IndexSet complete_index_set(const unsigned int N)
void serialize(Archive &ar, const unsigned int version)
void block_write(std::ostream &out) const
IntervalIterator & operator=(const IntervalIterator &other)
std::vector< Range > ranges
#define DeclException1(Exception1, type1, outsequence)
unsigned int global_dof_index
void subtract_set(const IndexSet &other)
#define Assert(cond, exc)
bool operator<(const ElementIterator &) const
size_type index_within_set(const size_type global_index) const
bool operator==(const IndexSet &is) const
IntervalAccessor accessor
IntervalAccessor & operator=(const IntervalAccessor &other)
bool operator==(const IntervalIterator &) const
const IndexSet * index_set
bool operator==(const IntervalAccessor &other) const
unsigned int n_intervals() 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)
void set_size(const size_type size)
ElementIterator & operator++()
IntervalAccessor(const IndexSet *idxset, const size_type range_idx)
IndexSet get_view(const size_type begin, const size_type end) const
ElementIterator end() const
IntervalIterator begin_intervals() const
bool is_contiguous() const
IntervalIterator end_intervals() const
bool operator<(const IntervalAccessor &other) const
bool operator!=(const ElementIterator &) const
ElementIterator begin() const
void write(std::ostream &out) const
bool is_element(const size_type index) const
bool operator==(const ElementIterator &) const
const types::global_dof_index invalid_dof_index
types::global_dof_index size_type
ElementIterator begin() const
void read(std::istream &in)
size_type n_elements() const
IntervalIterator & operator++()
size_type operator*() const
bool operator!=(const IntervalIterator &) const