16 #ifndef dealii__dynamic_sparsity_pattern_h 17 #define dealii__dynamic_sparsity_pattern_h 20 #include <deal.II/base/config.h> 21 #include <deal.II/base/subscriptor.h> 22 #include <deal.II/base/utilities.h> 23 #include <deal.II/lac/exceptions.h> 24 #include <deal.II/base/index_set.h> 30 DEAL_II_NAMESPACE_OPEN
73 const unsigned int index_within_row);
83 size_type
row ()
const;
88 size_type
index ()
const;
181 const unsigned int index_within_row);
207 const Accessor *operator-> ()
const;
217 bool operator != (
const Iterator &)
const;
234 int operator - (
const Iterator &p)
const;
368 void reinit (
const size_type m,
389 size_type max_entries_per_row ()
const;
394 void add (
const size_type i,
401 template <
typename ForwardIterator>
402 void add_entries (
const size_type
row,
403 ForwardIterator begin,
405 const bool indices_are_unique_and_sorted =
false);
410 bool exists (
const size_type i,
411 const size_type j)
const;
427 void print (std::ostream &out)
const;
442 void print_gnuplot (std::ostream &out)
const;
447 size_type n_rows ()
const;
453 size_type n_cols ()
const;
459 size_type row_length (
const size_type
row)
const;
465 size_type column_number (
const size_type
row,
466 const size_type
index)
const;
509 iterator begin (
const size_type r)
const;
519 iterator end (
const size_type r)
const;
528 size_type bandwidth ()
const;
534 size_type n_nonzero_elements ()
const;
541 const IndexSet &row_index_set ()
const;
554 bool stores_only_added_elements ();
560 size_type memory_consumption ()
const;
603 void add (
const size_type col_num);
608 template <
typename ForwardIterator>
609 void add_entries (ForwardIterator begin,
611 const bool indices_are_sorted);
616 size_type memory_consumption ()
const;
639 const unsigned int index_within_row)
641 sparsity_pattern(sparsity_pattern),
645 sparsity_pattern->lines[
current_row].entries.begin()
647 sparsity_pattern->lines[sparsity_pattern->rowset.index_within_set(
current_row)].entries.begin())
650 end_of_row((sparsity_pattern->rowset.size()==0)
654 sparsity_pattern->lines[sparsity_pattern->rowset.index_within_set(
current_row)].entries.end())
660 ExcMessage (
"You can't create an iterator into a " 661 "DynamicSparsityPattern's row that is not " 662 "actually stored by that sparsity pattern " 663 "based on the IndexSet argument to it."));
677 sparsity_pattern(sparsity_pattern),
689 Assert (current_row < sparsity_pattern->n_rows(),
700 Assert (current_row < sparsity_pattern->n_rows(),
711 Assert (current_row < sparsity_pattern->n_rows(),
752 Assert (current_row < sparsity_pattern->n_rows(),
773 Assert (current_row < sparsity_pattern->n_rows(),
802 const unsigned int index_within_row)
804 accessor(sparsity_pattern, row, index_within_row)
868 return ! (*
this == other);
887 Assert (
false, ExcNotImplemented());
899 if ( (entries.size()==0) || ( entries.back() < j) )
901 entries.push_back(j);
906 std::vector<size_type>::iterator
917 entries.insert(it, j);
945 Assert (i<rows, ExcIndexRangeType<size_type>(i, 0, rows));
946 Assert (j<cols, ExcIndexRangeType<size_type>(j, 0, cols));
948 if (rowset.size() > 0 && !rowset.is_element(i))
951 const size_type rowindex =
952 rowset.size()==0 ? i : rowset.index_within_set(i);
953 lines[rowindex].add (j);
958 template <
typename ForwardIterator>
962 ForwardIterator begin,
964 const bool indices_are_sorted)
966 Assert (row < rows, ExcIndexRangeType<size_type> (row, 0, rows));
968 if (rowset.size() > 0 && !rowset.is_element(row))
971 const size_type rowindex =
972 rowset.size()==0 ? row : rowset.index_within_set(row);
973 lines[rowindex].add_entries (begin, end, indices_are_sorted);
988 Assert (row < n_rows(), ExcIndexRangeType<size_type> (row, 0, n_rows()));
989 if (rowset.size() > 0 && !rowset.is_element(row))
992 const size_type rowindex =
993 rowset.size()==0 ? row : rowset.index_within_set(row);
994 return lines[rowindex].entries.size();
1002 const size_type index)
const 1004 Assert (row < n_rows(), ExcIndexRangeType<size_type> (row, 0, n_rows()));
1005 Assert( rowset.size() == 0 || rowset.is_element(row), ExcInternalError());
1007 const size_type local_row = rowset.size() ? rowset.index_within_set(row) : row;
1008 Assert (index < lines[local_row].entries.size(),
1009 ExcIndexRangeType<size_type> (index, 0, lines[local_row].entries.size()));
1010 return lines[local_row].entries[index];
1036 Assert (r<n_rows(), ExcIndexRangeType<size_type>(r,0,n_rows()));
1048 while ((row<n_rows())
1050 (row_length(row)==0))
1053 if (row == n_rows())
1065 Assert (r<n_rows(), ExcIndexRangeType<size_type>(r,0,n_rows()));
1073 unsigned int row = r+1;
1074 while ((row<n_rows())
1076 (row_length(row)==0))
1079 if (row == n_rows())
1104 DEAL_II_NAMESPACE_CLOSE
Iterator lower_bound(Iterator first, Iterator last, const T &val)
types::global_dof_index size_type
const types::global_dof_index invalid_size_type
void add_entries(const size_type row, ForwardIterator begin, ForwardIterator end, const bool indices_are_unique_and_sorted=false)
std::vector< size_type >::const_iterator end_of_row
DynamicSparsityPatternIterators::Iterator const_iterator
const DynamicSparsityPattern * sparsity_pattern
std::vector< Line > lines
std::vector< size_type > entries
DynamicSparsityPatternIterators::Iterator iterator
int operator-(const Iterator &p) const
const Accessor & operator*() const
Iterator(const DynamicSparsityPattern *sp, const size_type row, const unsigned int index_within_row)
size_type column_number(const size_type row, const size_type index) const
Accessor(const DynamicSparsityPattern *sparsity_pattern, const size_type row, const unsigned int index_within_row)
void add(const size_type i, const size_type j)
::ExceptionBase & ExcMessage(std::string arg1)
#define AssertIndexRange(index, range)
bool operator<(const Iterator &) const
types::global_dof_index size_type
bool operator==(const Iterator &) const
unsigned int global_dof_index
#define Assert(cond, exc)
size_type index_within_set(const size_type global_index) const
bool operator<(const Accessor &) const
const IndexSet & row_index_set() const
static bool stores_only_added_elements()
const Accessor * operator->() const
std::vector< size_type >::const_iterator current_entry
size_type row_length(const size_type row) const
bool operator==(const Accessor &) const
bool operator!=(const Iterator &) const
bool is_element(const size_type index) const
void add(const size_type col_num)