16 #ifndef dealii_chunk_sparsity_pattern_h 17 #define dealii_chunk_sparsity_pattern_h 20 #include <deal.II/base/config.h> 22 #include <deal.II/base/exceptions.h> 23 #include <deal.II/base/subscriptor.h> 25 #include <deal.II/lac/sparsity_pattern.h> 30 DEAL_II_NAMESPACE_OPEN
329 const std::vector<size_type> &row_lengths,
352 const std::vector<size_type> &row_lengths,
399 const std::vector<size_type> &row_lengths,
501 template <
typename ForwardIterator>
505 const ForwardIterator
begin,
506 const ForwardIterator
end,
514 template <
typename SparsityPatternType>
525 template <
typename number>
546 template <
typename Sparsity>
550 const Sparsity &sparsity_pattern_for_chunks,
552 const bool optimize_diagonal =
true);
732 print(std::ostream &out)
const;
766 <<
"The provided number is invalid here: " << arg1);
773 <<
"The given index " << arg1 <<
" should be less than " 781 <<
"Upon entering a new entry to row " << arg1
782 <<
": there was no free entry any more. " << std::endl
783 <<
"(Maximum number of entries for this row: " << arg2
784 <<
"; maybe the matrix is already compressed?)");
791 "The operation you attempted is only allowed after the SparsityPattern " 792 "has been set up and compress() was called.");
799 "The operation you attempted changes the structure of the SparsityPattern " 800 "and is not possible after compress() has been called.");
811 <<
"The iterators denote a range of " << arg1
812 <<
" elements, but the given number of rows was " << arg2);
822 <<
"The number of partitions you gave is " << arg1
823 <<
", but must be greater than zero.");
830 <<
"The array has size " << arg1 <<
" but should have size " 877 : sparsity_pattern(sparsity_pattern)
878 , reduced_accessor(row == sparsity_pattern->n_rows() ?
879 *sparsity_pattern->sparsity_pattern.end() :
880 *sparsity_pattern->sparsity_pattern.begin(
881 row / sparsity_pattern->get_chunk_size()))
882 , chunk_row(row == sparsity_pattern->n_rows() ?
884 row % sparsity_pattern->get_chunk_size())
891 : sparsity_pattern(sparsity_pattern)
892 , reduced_accessor(*sparsity_pattern->sparsity_pattern.end())
900 Accessor::is_valid_entry()
const 902 return reduced_accessor.is_valid_entry() &&
905 sparsity_pattern->n_rows() &&
906 sparsity_pattern->get_chunk_size() * reduced_accessor.column() +
908 sparsity_pattern->n_cols();
913 inline Accessor::size_type
914 Accessor::row()
const 918 return sparsity_pattern->get_chunk_size() * reduced_accessor.row() +
924 inline Accessor::size_type
925 Accessor::column()
const 929 return sparsity_pattern->get_chunk_size() * reduced_accessor.column() +
936 Accessor::reduced_index()
const 940 return reduced_accessor.linear_index;
946 Accessor::operator==(
const Accessor &other)
const 951 return (reduced_accessor == other.reduced_accessor &&
952 chunk_row == other.chunk_row && chunk_col == other.chunk_col);
958 Accessor::operator<(
const Accessor &other)
const 962 if (chunk_row != other.chunk_row)
964 if (reduced_accessor.linear_index ==
965 reduced_accessor.container->n_nonzero_elements())
967 if (other.reduced_accessor.linear_index ==
968 reduced_accessor.container->n_nonzero_elements())
971 const auto global_row = sparsity_pattern->get_chunk_size() *
972 reduced_accessor.row() +
974 other_global_row = sparsity_pattern->get_chunk_size() *
975 other.reduced_accessor.row() +
977 if (global_row < other_global_row)
979 else if (global_row > other_global_row)
984 reduced_accessor.linear_index < other.reduced_accessor.linear_index ||
985 (reduced_accessor.linear_index == other.reduced_accessor.linear_index &&
986 chunk_col < other.chunk_col));
993 const auto chunk_size = sparsity_pattern->get_chunk_size();
994 Assert(chunk_row < chunk_size && chunk_col < chunk_size,
997 sparsity_pattern->n_rows() &&
998 reduced_accessor.column() *
chunk_size + chunk_col <
999 sparsity_pattern->n_cols(),
1001 if (chunk_size == 1)
1003 reduced_accessor.advance();
1010 if (chunk_col == chunk_size ||
1011 reduced_accessor.column() *
chunk_size + chunk_col ==
1012 sparsity_pattern->n_cols())
1014 const auto reduced_row = reduced_accessor.row();
1016 if (reduced_accessor.linear_index + 1 ==
1017 reduced_accessor.container->rowstart[reduced_row + 1])
1024 if (chunk_row == chunk_size ||
1025 (reduced_row * chunk_size + chunk_row ==
1026 sparsity_pattern->n_rows()))
1029 reduced_accessor.advance();
1034 reduced_accessor.linear_index =
1035 reduced_accessor.container->rowstart[reduced_row];
1040 reduced_accessor.advance();
1049 const size_type row)
1050 : accessor(sparsity_pattern, row)
1056 Iterator::operator++()
1065 Iterator::operator++(
int)
1081 inline const Accessor *Iterator::operator->()
const 1088 Iterator::operator==(
const Iterator &other)
const 1090 return (accessor == other.accessor);
1096 Iterator::operator!=(
const Iterator &other)
const 1098 return !(accessor == other.accessor);
1103 Iterator::operator<(
const Iterator &other)
const 1105 return accessor < other.accessor;
1140 return {
this, r + 1};
1176 template <
typename ForwardIterator>
1179 const size_type n_cols,
1180 const ForwardIterator begin,
1181 const ForwardIterator end,
1182 const size_type chunk_size)
1192 std::vector<size_type> row_lengths;
1193 row_lengths.reserve(
n_rows);
1194 for (ForwardIterator i =
begin; i !=
end; ++i)
1195 row_lengths.push_back(std::distance(i->begin(), i->end()) +
1196 (is_square ? 1 : 0));
1201 using inner_iterator =
1202 typename std::iterator_traits<ForwardIterator>::value_type::const_iterator;
1203 for (ForwardIterator i =
begin; i !=
end; ++i, ++row)
1205 const inner_iterator end_of_row = i->end();
1206 for (inner_iterator j = i->begin(); j != end_of_row; ++j)
1209 internal::SparsityPatternTools::get_column_index_from_iterator(*j);
1223 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
types::global_dof_index size_type
static ::ExceptionBase & ExcNotEnoughSpace(size_type arg1, size_type arg2)
types::global_dof_index size_type
void block_read(std::istream &in)
bool operator!=(const Iterator &) const
Iterator(const ChunkSparsityPattern *sp, const size_type row)
bool exists(const size_type i, const size_type j) 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)
const ChunkSparsityPattern * sparsity_pattern
void add(const size_type i, const size_type j)
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
SymmetricTensor< rank_, dim, Number > operator*(const SymmetricTensor< rank_, dim, Number > &t, const Number &factor)
static ::ExceptionBase & ExcInvalidNumber(size_type arg1)
SparsityPattern sparsity_pattern
bool operator<(const Iterator &) const
types::global_dof_index size_type
std::size_t reduced_index() const
static ::ExceptionBase & ExcInvalidIterator()
#define DeclException1(Exception1, type1, outsequence)
Accessor(const ChunkSparsityPattern *matrix, const size_type row)
bool is_compressed() const
#define Assert(cond, exc)
#define DeclExceptionMsg(Exception, defaulttext)
#define DeclException0(Exception0)
size_type row_length(const size_type row) const
static ::ExceptionBase & ExcInvalidNumberOfPartitions(size_type arg1)
size_type n_nonzero_elements() const
const Accessor & operator*() const
static ::ExceptionBase & ExcInvalidArraySize(size_type arg1, size_type arg2)
static ::ExceptionBase & ExcInvalidIndex(size_type arg1, size_type arg2)
ChunkSparsityPattern & operator=(const ChunkSparsityPattern &)
static ::ExceptionBase & ExcIteratorPastEnd()
unsigned int global_dof_index
static ::ExceptionBase & ExcMatrixIsCompressed()
MatrixTableIterators::Iterator< TransposeTable< T >, Constness, MatrixTableIterators::Storage::column_major > Iterator
static ::ExceptionBase & ExcIteratorRange(size_type arg1, size_type arg2)
static ::ExceptionBase & ExcMETISNotInstalled()
size_type bandwidth() const
~ChunkSparsityPattern() override=default
static ::ExceptionBase & ExcNotCompressed()
static const size_type invalid_entry
static const size_type invalid_entry
bool operator<(const Accessor &) const
bool stores_only_added_elements() const
void print(std::ostream &out) const
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