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);
308 const std::vector<size_type> &row_lengths,
331 const std::vector<size_type> &row_lengths,
375 const std::vector<size_type> &row_lengths,
383 const VectorSlice<
const std::vector<size_type> > &row_lengths,
476 template <
typename ForwardIterator>
479 const ForwardIterator
begin,
480 const ForwardIterator
end,
488 template <
typename SparsityPatternType>
489 void copy_from (
const SparsityPatternType &dsp,
499 template <
typename number>
520 template <
typename Sparsity>
522 const unsigned int n,
523 const Sparsity &sparsity_pattern_for_chunks,
525 const bool optimize_diagonal =
true);
687 void print (std::ostream &out)
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?)");
741 "The operation you attempted is only allowed after the SparsityPattern " 742 "has been set up and compress() was called.");
748 "The operation you attempted changes the structure of the SparsityPattern " 749 "and is not possible after compress() has been called.");
759 <<
"The iterators denote a range of " << arg1
760 <<
" elements, but the given number of rows was " << arg2);
770 <<
"The number of partitions you gave is " << arg1
771 <<
", but must be greater than zero.");
777 <<
"The array has size " << arg1 <<
" but should have size " 824 const unsigned int row)
826 sparsity_pattern(sparsity_pattern),
827 reduced_accessor(row==sparsity_pattern->n_rows() ?
828 *sparsity_pattern->sparsity_pattern.end() :
829 *sparsity_pattern->sparsity_pattern.
830 begin(row/sparsity_pattern->get_chunk_size())),
831 chunk_row (row==sparsity_pattern->n_rows() ? 0 :
832 row%sparsity_pattern->get_chunk_size()),
842 sparsity_pattern(sparsity_pattern),
843 reduced_accessor(*sparsity_pattern->sparsity_pattern.end()),
852 Accessor::is_valid_entry ()
const 854 return reduced_accessor.is_valid_entry()
856 sparsity_pattern->
get_chunk_size()*reduced_accessor.row()+chunk_row <
857 sparsity_pattern->n_rows()
859 sparsity_pattern->get_chunk_size()*reduced_accessor.column()+chunk_col <
860 sparsity_pattern->n_cols();
867 Accessor::row()
const 871 return sparsity_pattern->get_chunk_size()*reduced_accessor.row() +
879 Accessor::column()
const 883 return sparsity_pattern->get_chunk_size()*reduced_accessor.column() +
891 Accessor::reduced_index()
const 895 return reduced_accessor.index_within_sparsity;
903 Accessor::operator == (
const Accessor &other)
const 908 return (reduced_accessor == other.reduced_accessor &&
909 chunk_row == other.chunk_row &&
910 chunk_col == other.chunk_col);
917 Accessor::operator < (
const Accessor &other)
const 919 Assert (sparsity_pattern == other.sparsity_pattern,
922 if (chunk_row != other.chunk_row)
924 if (reduced_accessor.index_within_sparsity ==
925 reduced_accessor.sparsity_pattern->n_nonzero_elements())
927 if (other.reduced_accessor.index_within_sparsity ==
928 reduced_accessor.sparsity_pattern->n_nonzero_elements())
932 global_row = sparsity_pattern->get_chunk_size()*reduced_accessor.row()
934 other_global_row = sparsity_pattern->get_chunk_size()*
935 other.reduced_accessor.row()+other.chunk_row;
936 if (global_row < other_global_row)
938 else if (global_row > other_global_row)
942 return (reduced_accessor.index_within_sparsity <
943 other.reduced_accessor.index_within_sparsity ||
944 (reduced_accessor.index_within_sparsity ==
945 other.reduced_accessor.index_within_sparsity &&
946 chunk_col < other.chunk_col));
954 const unsigned int chunk_size = sparsity_pattern->get_chunk_size();
955 Assert (chunk_row < chunk_size && chunk_col < chunk_size,
957 Assert (reduced_accessor.row() * chunk_size + chunk_row <
958 sparsity_pattern->n_rows()
960 reduced_accessor.column() * chunk_size + chunk_col <
961 sparsity_pattern->n_cols(),
965 reduced_accessor.advance();
972 if (chunk_col == chunk_size
974 reduced_accessor.column() * chunk_size + chunk_col ==
975 sparsity_pattern->n_cols())
977 const unsigned int reduced_row = reduced_accessor.row();
979 if (reduced_accessor.index_within_sparsity + 1 ==
980 reduced_accessor.sparsity_pattern->rowstart[reduced_row+1])
987 if (chunk_row == chunk_size ||
988 (reduced_row * chunk_size + chunk_row ==
989 sparsity_pattern->n_rows()))
992 reduced_accessor.advance();
997 reduced_accessor.index_within_sparsity =
998 reduced_accessor.sparsity_pattern->rowstart[reduced_row];
1003 reduced_accessor.advance();
1013 const unsigned int row)
1015 accessor(sparsity_pattern, row)
1022 Iterator::operator++ ()
1024 accessor.advance ();
1032 Iterator::operator++ (
int)
1034 const Iterator iter = *
this;
1035 accessor.advance ();
1043 Iterator::operator* ()
const 1052 Iterator::operator-> ()
const 1060 Iterator::operator == (
const Iterator &other)
const 1062 return (accessor == other.accessor);
1069 Iterator::operator != (
const Iterator &other)
const 1071 return ! (accessor == other.accessor);
1077 Iterator::operator < (
const Iterator &other)
const 1079 return accessor < other.accessor;
1158 template <
typename ForwardIterator>
1162 const ForwardIterator
begin,
1163 const ForwardIterator
end,
1174 std::vector<size_type> row_lengths;
1175 row_lengths.reserve(
n_rows);
1176 for (ForwardIterator i=
begin; i!=
end; ++i)
1177 row_lengths.push_back (std::distance (i->begin(), i->end())
1179 (is_square ? 1 : 0));
1184 typedef typename std::iterator_traits<ForwardIterator>::value_type::const_iterator inner_iterator;
1185 for (ForwardIterator i=
begin; i!=
end; ++i, ++row)
1187 const inner_iterator end_of_row = i->end();
1188 for (inner_iterator j=i->begin(); j!=end_of_row; ++j)
1191 = internal::SparsityPatternTools::get_column_index_from_iterator(*j);
1205 DEAL_II_NAMESPACE_CLOSE
bool operator==(const Iterator &) const
size_type get_chunk_size() const
void block_write(std::ostream &out) 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)
std::size_t memory_consumption() const
static ::ExceptionBase & ExcEmptyObject()
#define DeclException2(Exception2, type1, type2, outsequence)
bool is_valid_entry() const
Iterator(const ChunkSparsityPattern *sp, const unsigned int row)
static ::ExceptionBase & ExcInvalidNumber(int arg1)
static ::ExceptionBase & ExcInvalidIndex(int arg1, int arg2)
static const size_type invalid_entry
ChunkSparsityPatternIterators::Iterator const_iterator
void block_read(std::istream &in)
bool operator!=(const Iterator &) const
bool exists(const size_type i, const size_type j) const
const ChunkSparsityPattern * sparsity_pattern
void add(const size_type i, const size_type j)
static ::ExceptionBase & ExcInvalidArraySize(int arg1, int arg2)
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
unsigned int column() const
SparsityPattern sparsity_pattern
bool operator<(const Iterator &) const
std::size_t reduced_index() const
static ::ExceptionBase & ExcInvalidIterator()
#define DeclException1(Exception1, type1, outsequence)
unsigned int global_dof_index
bool is_compressed() const
ChunkSparsityPatternIterators::Iterator iterator
#define Assert(cond, exc)
#define DeclExceptionMsg(Exception, defaulttext)
#define DeclException0(Exception0)
size_type row_length(const size_type row) const
static ::ExceptionBase & ExcIteratorRange(int arg1, int arg2)
size_type n_nonzero_elements() const
const Accessor & operator*() const
ChunkSparsityPattern & operator=(const ChunkSparsityPattern &)
static ::ExceptionBase & ExcIteratorPastEnd()
types::global_dof_index size_type
Accessor(const ChunkSparsityPattern *matrix, const unsigned int row)
static ::ExceptionBase & ExcMatrixIsCompressed()
static ::ExceptionBase & ExcInvalidNumberOfPartitions(int arg1)
static ::ExceptionBase & ExcMETISNotInstalled()
size_type bandwidth() const
static ::ExceptionBase & ExcNotCompressed()
static const size_type invalid_entry
bool operator<(const Accessor &) const
static ::ExceptionBase & ExcNotEnoughSpace(int arg1, int arg2)
bool stores_only_added_elements() const
void print(std::ostream &out) const
void create_from(const unsigned int m, const unsigned int n, const Sparsity &sparsity_pattern_for_chunks, const unsigned int chunk_size, const bool optimize_diagonal=true)
SparsityPatternIterators::Accessor reduced_accessor
void print_gnuplot(std::ostream &out) const
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
static ::ExceptionBase & ExcInternalError()
const Accessor * operator->() const
size_type max_entries_per_row() const