17 #ifndef __deal2__index_set_h
18 #define __deal2__index_set_h
20 #include <deal.II/base/config.h>
21 #include <deal.II/base/utilities.h>
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
129 template <
typename ForwardIterator>
131 const ForwardIterator &end);
153 const unsigned int offset = 0);
320 template <
typename Vector>
328 template <
class STREAM>
329 void print(STREAM &out)
const;
336 void write(std::ostream &out)
const;
344 void read(std::istream &in);
362 #ifdef DEAL_II_WITH_TRILINOS
421 const bool overlapping =
false)
const;
433 <<
"The global index " << arg1
434 <<
" is not an element of this set.");
440 template <
class Archive>
441 void serialize (Archive &ar,
const unsigned int version);
487 inline bool operator< (
const Range &range_1,
488 const Range &range_2)
490 return ((range_1.begin < range_2.begin)
492 ((range_1.begin == range_2.begin)
494 (range_1.end < range_2.end)));
499 return x.end < y.end;
505 return (x.nth_index_in_set+(x.end-x.begin) <
506 y.nth_index_in_set+(y.end-y.begin));
510 inline bool operator== (
const Range &range_1,
511 const Range &range_2)
513 return ((range_1.begin == range_2.begin)
515 (range_1.end == range_2.end));
518 std::size_t memory_consumption ()
const
520 return sizeof(
Range);
527 template <
class Archive>
528 void serialize (Archive &ar,
const unsigned int version);
626 begin(numbers::invalid_dof_index),
627 end(numbers::invalid_dof_index)
653 is_compressed (true),
654 index_space_size (size),
655 largest_range (deal_II_numbers::invalid_unsigned_int)
675 ExcMessage (
"This function can only be called if the current "
676 "object does not yet contain any elements."));
716 ExcIndexRangeType<types::global_dof_index> (begin, 0, end));
720 const Range new_range(begin,end);
726 ranges.push_back(new_range);
745 const Range new_range(index, index+1);
747 ranges.push_back(new_range);
748 else if (index ==
ranges.back().end)
760 template <
typename ForwardIterator>
764 const ForwardIterator &end)
770 for (ForwardIterator p=begin; p!=end;)
774 ForwardIterator q = p;
776 while ((q != end) && (*q == end_index))
792 const unsigned int offset)
794 if ((
this == &other) && (offset == 0))
797 for (std::vector<Range>::iterator range = other.
ranges.begin();
798 range != other.
ranges.end();
801 add_range(range->begin+offset, range->end+offset);
813 if (
ranges.empty() ==
false)
849 std::vector<Range>::const_iterator
858 return ((index >= p->begin) && (index < p->end));
868 return (p->end > index);
883 return (
ranges.size() <= 1);
900 v = r.nth_index_in_set + r.end - r.begin;
905 for (std::vector<Range>::iterator range =
ranges.begin();
908 s += (range->end - range->begin);
930 if (n>=main_range->nth_index_in_set &&
932 return main_range->begin + (n-main_range->nth_index_in_set);
940 r.nth_index_in_set = n;
941 std::vector<Range>::const_iterator range_begin, range_end;
944 range_begin =
ranges.begin();
945 range_end = main_range;
949 range_begin = main_range + 1;
953 std::vector<Range>::const_iterator
955 Range::nth_index_compare);
958 return p->begin + (n-p->nth_index_in_set);
976 Assert (n <
size(), ExcIndexRangeType<types::global_dof_index> (n, 0,
size()));
983 if (n >= main_range->begin && n < main_range->end)
984 return (n-main_range->begin) + main_range->nth_index_in_set;
987 std::vector<Range>::const_iterator range_begin, range_end;
988 if (n<main_range->begin)
990 range_begin =
ranges.begin();
991 range_end = main_range;
995 range_begin = main_range + 1;
999 std::vector<Range>::const_iterator
1001 Range::end_compare);
1006 return (n-p->begin) + p->nth_index_in_set;
1041 template <
typename Vector>
1051 std::fill (vector.
begin(), vector.
end(), 0);
1055 for (std::vector<Range>::iterator it =
ranges.begin();
1064 template <
class STREAM>
1071 std::vector<Range>::const_iterator p;
1074 if (p->end-p->begin==1)
1077 out <<
"[" << p->begin <<
"," << p->end-1 <<
"]";
1082 out <<
"}" << std::endl;
1087 template <
class Archive>
1092 ar &begin &end &nth_index_in_set;
1097 template <
class Archive>
1105 DEAL_II_NAMESPACE_CLOSE
Iterator lower_bound(Iterator first, Iterator last, const T &val)
types::global_dof_index index_within_set(const types::global_dof_index global_index) const
types::global_dof_index size() const
void block_read(std::istream &in)
::ExceptionBase & ExcMessage(std::string arg1)
void add_indices(const ForwardIterator &begin, const ForwardIterator &end)
bool operator==(const IndexSet &is) const
types::global_dof_index largest_range
void add_index(const types::global_dof_index index)
void fill_binary_vector(Vector &vector) 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)
void write(std::ostream &out) const
std::vector< Range > ranges
unsigned int global_dof_index
bool operator!=(const IndexSet &is) const
void subtract_set(const IndexSet &other)
#define Assert(cond, exc)
types::global_dof_index nth_index_in_set(const unsigned int local_index) const
types::global_dof_index index_space_size
IndexSet operator&(const IndexSet &is) const
void set_size(const types::global_dof_index size)
void add_range(const types::global_dof_index begin, const types::global_dof_index end)
Epetra_Map make_trilinos_map(const MPI_Comm &communicator=MPI_COMM_WORLD, const bool overlapping=false) const
IndexSet get_view(const types::global_dof_index begin, const types::global_dof_index end) const
void fill_index_vector(std::vector< types::global_dof_index > &indices) const
std::size_t memory_consumption() const
::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
const types::global_dof_index invalid_dof_index
::ExceptionBase & ExcInternalError()
void read(std::istream &in)
void print(STREAM &out) const
bool is_element(const types::global_dof_index index) const
types::global_dof_index n_elements() const