16 #ifndef dealii__chunk_sparsity_pattern_h 17 #define dealii__chunk_sparsity_pattern_h 20 #include <deal.II/base/config.h> 21 #include <deal.II/base/exceptions.h> 22 #include <deal.II/base/subscriptor.h> 23 #include <deal.II/base/vector_slice.h> 25 #include <deal.II/lac/sparsity_pattern.h> 30 DEAL_II_NAMESPACE_OPEN
69 const unsigned int row);
80 unsigned int row ()
const;
91 unsigned int column ()
const;
165 const unsigned int row);
185 const Accessor *operator-> ()
const;
195 bool operator != (
const Iterator &)
const;
296 const size_type max_chunks_per_row,
297 const size_type chunk_size);
308 const std::vector<size_type> &row_lengths,
309 const size_type chunk_size);
320 const size_type max_per_row,
321 const size_type chunk_size);
331 const std::vector<size_type> &row_lengths,
332 const size_type chunk_size);
354 void reinit (
const size_type m,
356 const size_type max_per_row,
357 const size_type chunk_size);
373 void reinit (
const size_type m,
375 const std::vector<size_type> &row_lengths,
376 const size_type chunk_size);
381 void reinit (
const size_type m,
383 const VectorSlice<
const std::vector<size_type> > &row_lengths,
384 const size_type chunk_size);
476 template <
typename ForwardIterator>
477 void copy_from (
const size_type n_rows,
478 const size_type n_cols,
479 const ForwardIterator begin,
480 const ForwardIterator end,
481 const size_type chunk_size);
488 template <
typename SparsityPatternType>
489 void copy_from (
const SparsityPatternType &dsp,
490 const size_type chunk_size);
499 template <
typename number>
501 const size_type chunk_size);
520 template <
typename Sparsity>
521 void create_from (
const unsigned int m,
522 const unsigned int n,
523 const Sparsity &sparsity_pattern_for_chunks,
524 const unsigned int chunk_size,
525 const bool optimize_diagonal =
true);
536 size_type get_chunk_size ()
const;
543 size_type max_entries_per_row ()
const;
551 void add (
const size_type i,
567 inline size_type n_rows ()
const;
573 inline size_type n_cols ()
const;
578 bool exists (
const size_type i,
579 const size_type j)
const;
584 size_type row_length (
const size_type
row)
const;
592 size_type bandwidth ()
const;
602 size_type n_nonzero_elements ()
const;
607 bool is_compressed ()
const;
621 bool stores_only_added_elements ()
const;
628 iterator begin ()
const;
633 iterator end ()
const;
643 iterator begin (
const unsigned int r)
const;
653 iterator end (
const unsigned int r)
const;
665 void block_write (std::ostream &out)
const;
680 void block_read (std::istream &in);
687 void print (std::ostream &out)
const;
702 void print_gnuplot (std::ostream &out)
const;
708 std::size_t memory_consumption ()
const;
719 <<
"The provided number is invalid here: " << arg1);
725 <<
"The given index " << arg1
726 <<
" should be less than " << arg2 <<
".");
732 <<
"Upon entering a new entry to row " << arg1
733 <<
": there was no free entry any more. " << std::endl
734 <<
"(Maximum number of entries for this row: " 735 << arg2 <<
"; maybe the matrix is already compressed?)");
757 <<
"The iterators denote a range of " << arg1
758 <<
" elements, but the given number of rows was " << arg2);
768 <<
"The number of partitions you gave is " << arg1
769 <<
", but must be greater than zero.");
775 <<
"The array has size " << arg1 <<
" but should have size " 822 const unsigned int row)
824 sparsity_pattern(sparsity_pattern),
826 *sparsity_pattern->sparsity_pattern.end() :
827 *sparsity_pattern->sparsity_pattern.
828 begin(row/sparsity_pattern->get_chunk_size())),
829 chunk_row (row==sparsity_pattern->n_rows() ? 0 :
830 row%sparsity_pattern->get_chunk_size()),
840 sparsity_pattern(sparsity_pattern),
841 reduced_accessor(*sparsity_pattern->sparsity_pattern.
end()),
850 Accessor::is_valid_entry ()
const 852 return reduced_accessor.is_valid_entry()
865 Accessor::row()
const 867 Assert (is_valid_entry() ==
true, ExcInvalidIterator());
877 Accessor::column()
const 879 Assert (is_valid_entry() ==
true, ExcInvalidIterator());
889 Accessor::reduced_index()
const 891 Assert (is_valid_entry() ==
true, ExcInvalidIterator());
893 return reduced_accessor.index_within_sparsity;
901 Accessor::operator == (
const Accessor &other)
const 906 return (reduced_accessor == other.reduced_accessor &&
907 chunk_row == other.chunk_row &&
908 chunk_col == other.chunk_col);
915 Accessor::operator < (
const Accessor &other)
const 920 if (chunk_row != other.chunk_row)
922 if (reduced_accessor.index_within_sparsity ==
923 reduced_accessor.sparsity_pattern->n_nonzero_elements())
925 if (other.reduced_accessor.index_within_sparsity ==
926 reduced_accessor.sparsity_pattern->n_nonzero_elements())
933 other.reduced_accessor.row()+other.chunk_row;
934 if (global_row < other_global_row)
936 else if (global_row > other_global_row)
940 return (reduced_accessor.index_within_sparsity <
941 other.reduced_accessor.index_within_sparsity ||
942 (reduced_accessor.index_within_sparsity ==
943 other.reduced_accessor.index_within_sparsity &&
944 chunk_col < other.chunk_col));
953 Assert (chunk_row < chunk_size && chunk_col < chunk_size,
954 ExcIteratorPastEnd());
955 Assert (reduced_accessor.row() * chunk_size + chunk_row <
958 reduced_accessor.column() * chunk_size + chunk_col <
960 ExcIteratorPastEnd());
963 reduced_accessor.advance();
970 if (chunk_col == chunk_size
972 reduced_accessor.column() * chunk_size + chunk_col ==
975 const unsigned int reduced_row = reduced_accessor.row();
977 if (reduced_accessor.index_within_sparsity + 1 ==
978 reduced_accessor.sparsity_pattern->rowstart[reduced_row+1])
985 if (chunk_row == chunk_size ||
986 (reduced_row * chunk_size + chunk_row ==
990 reduced_accessor.advance();
995 reduced_accessor.index_within_sparsity =
996 reduced_accessor.sparsity_pattern->rowstart[reduced_row];
1001 reduced_accessor.advance();
1011 const unsigned int row)
1013 accessor(sparsity_pattern, row)
1020 Iterator::operator++ ()
1022 accessor.advance ();
1030 Iterator::operator++ (
int)
1032 const Iterator iter = *
this;
1033 accessor.advance ();
1041 Iterator::operator* ()
const 1050 Iterator::operator-> ()
const 1058 Iterator::operator == (
const Iterator &other)
const 1060 return (accessor == other.accessor);
1067 Iterator::operator != (
const Iterator &other)
const 1069 return ! (accessor == other.accessor);
1075 Iterator::operator < (
const Iterator &other)
const 1077 return accessor < other.accessor;
1156 template <
typename ForwardIterator>
1160 const ForwardIterator
begin,
1161 const ForwardIterator
end,
1164 Assert (static_cast<size_type>(std::distance (begin, end)) == n_rows,
1165 ExcIteratorRange (std::distance (begin, end), n_rows));
1171 const bool is_square = (n_rows ==
n_cols);
1172 std::vector<size_type> row_lengths;
1173 row_lengths.reserve(n_rows);
1174 for (ForwardIterator i=begin; i!=
end; ++i)
1175 row_lengths.push_back (std::distance (i->begin(), i->end())
1177 (is_square ? 1 : 0));
1178 reinit (n_rows, n_cols, row_lengths, chunk_size);
1182 typedef typename std::iterator_traits<ForwardIterator>::value_type::const_iterator inner_iterator;
1183 for (ForwardIterator i=begin; i!=
end; ++i, ++row)
1185 const inner_iterator end_of_row = i->end();
1186 for (inner_iterator j=i->begin(); j!=end_of_row; ++j)
1189 = internal::SparsityPatternTools::get_column_index_from_iterator(*j);
1190 Assert (col < n_cols, ExcInvalidIndex(col,n_cols));
1203 DEAL_II_NAMESPACE_CLOSE
size_type get_chunk_size() const
void copy_from(const size_type n_rows, const size_type n_cols, const ForwardIterator begin, const ForwardIterator end, const size_type chunk_size)
#define DeclException2(Exception2, type1, type2, outsequence)
bool is_valid_entry() const
static const size_type invalid_entry
ChunkSparsityPatternIterators::Iterator const_iterator
const ChunkSparsityPattern * sparsity_pattern
void add(const size_type i, const size_type j)
unsigned int column() const
SparsityPattern sparsity_pattern
std::size_t reduced_index() const
#define DeclException1(Exception1, type1, outsequence)
unsigned int global_dof_index
bool is_compressed() const
ChunkSparsityPatternIterators::Iterator iterator
#define Assert(cond, exc)
#define DeclException0(Exception0)
types::global_dof_index size_type
Accessor(const ChunkSparsityPattern *matrix, const unsigned int row)
bool operator<(const Accessor &) const
SparsityPatternIterators::Accessor reduced_accessor
void reinit(const size_type m, const size_type n, const size_type max_per_row, const size_type chunk_size)
bool operator==(const Accessor &) const