15#ifndef dealii_chunk_sparsity_pattern_h
16#define dealii_chunk_sparsity_pattern_h
326 const std::vector<size_type> &row_lengths,
349 const std::vector<size_type> &row_lengths,
396 const std::vector<size_type> &row_lengths,
498 template <
typename ForwardIterator>
502 const ForwardIterator
begin,
503 const ForwardIterator
end,
511 template <
typename SparsityPatternType>
522 template <
typename number>
543 template <
typename Sparsity>
547 const Sparsity &sparsity_pattern_for_chunks,
549 const bool optimize_diagonal =
true);
729 print(std::ostream &out)
const;
763 <<
"The provided number is invalid here: " << arg1);
770 <<
"The given index " << arg1 <<
" should be less than "
778 <<
"Upon entering a new entry to row " << arg1
779 <<
": there was no free entry any more. " << std::endl
780 <<
"(Maximum number of entries for this row: " << arg2
781 <<
"; maybe the matrix is already compressed?)");
788 "The operation you attempted is only allowed after the SparsityPattern "
789 "has been set up and compress() was called.");
796 "The operation you attempted changes the structure of the SparsityPattern "
797 "and is not possible after compress() has been called.");
808 <<
"The iterators denote a range of " << arg1
809 <<
" elements, but the given number of rows was " << arg2);
819 <<
"The number of partitions you gave is " << arg1
820 <<
", but must be greater than zero.");
827 <<
"The array has size " << arg1 <<
" but should have size "
870 : sparsity_pattern(sparsity_pattern)
871 , reduced_accessor(row == sparsity_pattern->n_rows() ?
872 *sparsity_pattern->sparsity_pattern.end() :
873 *sparsity_pattern->sparsity_pattern.begin(
874 row / sparsity_pattern->get_chunk_size()))
875 , chunk_row(row == sparsity_pattern->n_rows() ?
877 row % sparsity_pattern->get_chunk_size())
884 : sparsity_pattern(sparsity_pattern)
885 , reduced_accessor(*sparsity_pattern->sparsity_pattern.
end())
893 Accessor::is_valid_entry()
const
895 return reduced_accessor.is_valid_entry() &&
898 sparsity_pattern->n_rows() &&
899 sparsity_pattern->get_chunk_size() * reduced_accessor.column() +
901 sparsity_pattern->n_cols();
906 inline Accessor::size_type
907 Accessor::row()
const
911 return sparsity_pattern->get_chunk_size() * reduced_accessor.row() +
917 inline Accessor::size_type
918 Accessor::column()
const
922 return sparsity_pattern->get_chunk_size() * reduced_accessor.column() +
929 Accessor::reduced_index()
const
933 return reduced_accessor.linear_index;
939 Accessor::operator==(
const Accessor &other)
const
944 return (reduced_accessor == other.reduced_accessor &&
945 chunk_row == other.chunk_row && chunk_col == other.chunk_col);
951 Accessor::operator<(
const Accessor &other)
const
955 if (chunk_row != other.chunk_row)
957 if (reduced_accessor.linear_index ==
958 reduced_accessor.container->n_nonzero_elements())
960 if (other.reduced_accessor.linear_index ==
961 reduced_accessor.container->n_nonzero_elements())
964 const auto global_row = sparsity_pattern->get_chunk_size() *
965 reduced_accessor.row() +
967 other_global_row = sparsity_pattern->get_chunk_size() *
968 other.reduced_accessor.row() +
970 if (global_row < other_global_row)
972 else if (global_row > other_global_row)
977 reduced_accessor.linear_index < other.reduced_accessor.linear_index ||
978 (reduced_accessor.linear_index == other.reduced_accessor.linear_index &&
979 chunk_col < other.chunk_col));
986 const auto chunk_size = sparsity_pattern->get_chunk_size();
987 Assert(chunk_row < chunk_size && chunk_col < chunk_size,
989 Assert(reduced_accessor.row() * chunk_size + chunk_row <
990 sparsity_pattern->n_rows() &&
991 reduced_accessor.column() * chunk_size + chunk_col <
992 sparsity_pattern->n_cols(),
996 reduced_accessor.advance();
1003 if (chunk_col == chunk_size ||
1004 reduced_accessor.column() * chunk_size + chunk_col ==
1005 sparsity_pattern->n_cols())
1007 const auto reduced_row = reduced_accessor.row();
1009 if (reduced_accessor.linear_index + 1 ==
1010 reduced_accessor.container->rowstart[reduced_row + 1])
1017 if (chunk_row == chunk_size ||
1018 (reduced_row * chunk_size + chunk_row ==
1019 sparsity_pattern->n_rows()))
1022 reduced_accessor.advance();
1027 reduced_accessor.linear_index =
1028 reduced_accessor.container->rowstart[reduced_row];
1033 reduced_accessor.advance();
1042 const size_type row)
1043 : accessor(sparsity_pattern, row)
1049 Iterator::operator++()
1058 Iterator::operator++(
int)
1060 const Iterator iter = *
this;
1067 inline const Accessor &
1068 Iterator::operator*()
const
1075 inline const Accessor *
1076 Iterator::operator->()
const
1083 Iterator::operator==(
const Iterator &other)
const
1085 return (accessor == other.accessor);
1091 Iterator::operator!=(
const Iterator &other)
const
1093 return !(accessor == other.accessor);
1098 Iterator::operator<(
const Iterator &other)
const
1100 return accessor < other.accessor;
1135 return {
this, r + 1};
1171template <
typename ForwardIterator>
1174 const size_type n_cols,
1175 const ForwardIterator begin,
1176 const ForwardIterator end,
1177 const size_type chunk_size)
1187 std::vector<size_type> row_lengths;
1188 row_lengths.reserve(
n_rows);
1189 for (ForwardIterator i =
begin; i !=
end; ++i)
1190 row_lengths.push_back(std::distance(i->begin(), i->end()) +
1191 (is_square ? 1 : 0));
1196 using inner_iterator =
1197 typename std::iterator_traits<ForwardIterator>::value_type::const_iterator;
1198 for (ForwardIterator i =
begin; i !=
end; ++i, ++row)
1200 const inner_iterator end_of_row = i->end();
1201 for (inner_iterator j = i->begin(); j != end_of_row; ++j)
1204 internal::SparsityPatternTools::get_column_index_from_iterator(*j);
SparsityPatternIterators::Accessor reduced_accessor
bool is_valid_entry() const
Accessor(const ChunkSparsityPattern *matrix, const size_type row)
std::size_t reduced_index() const
bool operator<(const Accessor &) const
Accessor(const ChunkSparsityPattern *matrix)
bool operator==(const Accessor &) const
const ChunkSparsityPattern * sparsity_pattern
bool operator!=(const Iterator &) const
bool operator==(const Iterator &) const
Iterator(const ChunkSparsityPattern *sp, const size_type row)
bool operator<(const Iterator &) const
const Accessor * operator->() const
const Accessor & operator*() const
void create_from(const size_type m, const size_type n, const Sparsity &sparsity_pattern_for_chunks, const size_type chunk_size, const bool optimize_diagonal=true)
void add(const size_type i, const size_type j)
void block_write(std::ostream &out) const
bool stores_only_added_elements() const
~ChunkSparsityPattern() override=default
static const size_type invalid_entry
std::size_t memory_consumption() const
types::global_dof_index size_type
bool exists(const size_type i, const size_type j) const
iterator end(const size_type r) const
void reinit(const size_type m, const size_type n, const size_type max_per_row, const size_type chunk_size)
void print_gnuplot(std::ostream &out) const
void block_read(std::istream &in)
bool is_compressed() const
ChunkSparsityPattern & operator=(const ChunkSparsityPattern &)
size_type max_entries_per_row() const
size_type bandwidth() const
size_type n_nonzero_elements() const
SparsityPattern sparsity_pattern
size_type row_length(const size_type row) const
void print(std::ostream &out) const
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)
iterator begin(const size_type r) const
static constexpr size_type invalid_entry
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
#define DeclException0(Exception0)
static ::ExceptionBase & ExcInvalidIterator()
static ::ExceptionBase & ExcInvalidNumberOfPartitions(size_type arg1)
static ::ExceptionBase & ExcNotEnoughSpace(size_type arg1, size_type arg2)
static ::ExceptionBase & ExcMETISNotInstalled()
#define Assert(cond, exc)
static ::ExceptionBase & ExcNotCompressed()
static ::ExceptionBase & ExcIteratorPastEnd()
static ::ExceptionBase & ExcMatrixIsCompressed()
#define DeclException2(Exception2, type1, type2, outsequence)
#define AssertIndexRange(index, range)
#define DeclExceptionMsg(Exception, defaulttext)
static ::ExceptionBase & ExcInvalidArraySize(size_type arg1, size_type arg2)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcEmptyObject()
#define DeclException1(Exception1, type1, outsequence)
static ::ExceptionBase & ExcInvalidIndex(size_type arg1, size_type arg2)
static ::ExceptionBase & ExcIteratorRange(size_type arg1, size_type arg2)
static ::ExceptionBase & ExcInvalidNumber(size_type arg1)
VectorType::value_type * end(VectorType &V)
unsigned int global_dof_index