37 , store_diagonal_first_in_row(false)
53 "This constructor can only be called if the provided argument "
54 "is the sparsity pattern for an empty matrix. This constructor can "
55 "not be used to copy-construct a non-empty sparsity pattern."));
64 const unsigned int max_per_row)
74 const std::vector<unsigned int> &row_lengths)
83 const unsigned int max_per_row)
92 const std::vector<unsigned int> &row_lengths)
101 const unsigned int max_per_row,
123 const size_type *
const original_row_start =
127 const size_type *
const original_row_end =
133 const size_type *
const original_last_before_side_diagonals =
134 (row > extra_off_diagonals ?
137 row - extra_off_diagonals) :
140 const size_type *
const original_first_after_side_diagonals =
141 (row <
rows - extra_off_diagonals - 1 ?
142 std::upper_bound(original_row_start,
144 row + extra_off_diagonals) :
152 next_free_slot = std::copy(original_row_start,
153 original_last_before_side_diagonals,
158 ++i, ++next_free_slot)
159 *next_free_slot = row - i;
161 ++i, ++next_free_slot)
162 *next_free_slot = row + i;
165 next_free_slot = std::copy(original_first_after_side_diagonals,
184 "This operator can only be called if the provided argument "
185 "is the sparsity pattern for an empty matrix. This operator can "
186 "not be used to copy a non-empty sparsity pattern."));
189 ExcMessage(
"This operator can only be called if the current object is "
206 if ((m == 0) || (n == 0))
231 std::size_t vec_len = 0;
249 (row_lengths.
empty() ?
252 *std::max_element(row_lengths.
begin(), row_lengths.
end())),
282 std::clamp(
static_cast<size_type>(row_lengths[i - 1]),
307 const std::vector<unsigned int> &row_lengths)
317 const unsigned int max_per_row)
320 const std::vector<unsigned int> row_lengths(m, max_per_row);
321 reinit(m, n, row_lengths);
340 std::size_t next_free_entry = 0, next_row_start = 0,
row_length = 0;
344 const std::size_t nonzero_elements =
349 std::unique_ptr<size_type[]> new_colnums(
new size_type[nonzero_elements]);
379 new_colnums[next_free_entry++] = tmp_entries[j];
383 next_row_start = next_free_entry;
400 (std::find(&new_colnums[
rowstart[line] + 1],
401 &new_colnums[next_row_start],
403 &new_colnums[next_row_start]),
406 (std::adjacent_find(&new_colnums[
rowstart[line] + 1],
407 &new_colnums[next_row_start]) ==
408 &new_colnums[next_row_start]),
420 colnums = std::move(new_colnums);
437 const bool do_diag_optimize = (sp.
n_rows() == sp.
n_cols());
438 std::vector<unsigned int> row_lengths(sp.
n_rows());
442 if (do_diag_optimize && !sp.
exists(i, i))
455 end_row = sp.
end(row);
457 for (; col_num != end_row; ++col_num)
460 if ((col != row) || !do_diag_optimize)
481 const bool do_diag_optimize = (dsp.
n_rows() == dsp.
n_cols());
484 std::vector<unsigned int> row_lengths(dsp.
n_rows());
486 if (row_index_set.size() == 0)
491 if (do_diag_optimize && !dsp.
exists(i, i))
499 if (row_index_set.is_element(i))
502 if (do_diag_optimize && !dsp.
exists(i, i))
511 row_lengths[i] = do_diag_optimize ? 1 : 0;
522 for (
unsigned int index = 0; index <
row_length; ++index)
525 if ((col != row) || !do_diag_optimize)
538template <
typename number>
545 const bool matrix_is_square = (matrix.m() == matrix.n());
547 std::vector<unsigned int> entries_per_row(matrix.m(), 0);
548 for (
size_type row = 0; row < matrix.m(); ++row)
550 for (
size_type col = 0; col < matrix.n(); ++col)
551 if (matrix(row, col) != 0)
552 ++entries_per_row[row];
553 if (matrix_is_square && (matrix(row, row) == 0))
554 ++entries_per_row[row];
557 reinit(matrix.m(), matrix.n(), entries_per_row);
564 std::vector<size_type> column_indices;
565 column_indices.reserve(
566 entries_per_row.size() > 0 ?
567 *std::max_element(entries_per_row.begin(), entries_per_row.end()) :
569 for (
size_type row = 0; row < matrix.m(); ++row)
571 column_indices.resize(entries_per_row[row]);
574 for (
size_type col = 0; col < matrix.n(); ++col)
575 if (matrix(row, col) != 0)
577 column_indices[current_index] = col;
584 if (matrix_is_square && (col == row))
586 column_indices[current_index] = row;
594 add_entries(row, column_indices.begin(), column_indices.end(),
true);
653 Utilities::lower_bound<const size_type *>(sorted_region_start,
682std::pair<SparsityPattern::size_type, SparsityPattern::size_type>
701 return std::make_pair(row, col);
792template <
typename ForwardIterator>
795 ForwardIterator
begin,
797 const bool indices_are_sorted)
800 if (indices_are_sorted ==
true)
804 ForwardIterator it =
begin;
805 bool has_larger_entries =
false;
813 has_larger_entries =
true;
816 if (has_larger_entries ==
false)
817 for (; it !=
end; ++it)
830 for (ForwardIterator p =
begin; p !=
end; ++p)
837 for (ForwardIterator it =
begin; it !=
end; ++it)
847 const bool indices_are_sorted)
930 out <<
']' << std::endl;
951 out <<
colnums[j] <<
" " << -
static_cast<signed int>(i) << std::endl;
961 const unsigned int m = this->
n_rows();
962 const unsigned int n = this->
n_cols();
964 <<
"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" viewBox=\"0 0 "
965 << n + 2 <<
" " << m + 2
967 "<style type=\"text/css\" >\n"
975 << n + 2 <<
"\" height=\"" << m + 2
976 <<
"\" fill=\"rgb(128, 128, 128)\"/>\n"
977 " <rect x=\"1\" y=\"1\" width=\""
978 << n + 0.1 <<
"\" height=\"" << m + 0.1
979 <<
"\" fill=\"rgb(255, 255, 255)\"/>\n\n";
981 for (
const auto &entry : *
this)
983 out <<
" <rect class=\"pixel\" x=\"" << entry.column() + 1 <<
"\" y=\""
984 << entry.row() + 1 <<
"\" width=\".9\" height=\".9\"/>\n";
986 out <<
"</svg>" << std::endl;
1001 out.write(
reinterpret_cast<const char *
>(
rowstart.get()),
1003 reinterpret_cast<const char *
>(
rowstart.get()));
1005 out.write(
reinterpret_cast<const char *
>(
colnums.get()),
1007 reinterpret_cast<const char *
>(
colnums.get()));
1038 in.read(
reinterpret_cast<char *
>(
rowstart.get()),
1040 reinterpret_cast<char *
>(
rowstart.get()));
1045 in.read(
reinterpret_cast<char *
>(
colnums.get()),
1047 reinterpret_cast<char *
>(
colnums.get()));
1071SparsityPattern::add_entries<const SparsityPattern::size_type *>(
1076# ifndef DEAL_II_VECTOR_ITERATOR_IS_POINTER
1079 std::vector<SparsityPattern::size_type>::const_iterator>(
1081 std::vector<size_type>::const_iterator,
1082 std::vector<size_type>::const_iterator,
1086SparsityPattern::add_entries<std::vector<SparsityPattern::size_type>::iterator>(
1088 std::vector<size_type>::iterator,
1089 std::vector<size_type>::iterator,
ArrayView< std::remove_reference_t< typename std::iterator_traits< Iterator >::reference >, MemorySpaceType > make_array_view(const Iterator begin, const Iterator end)
const IndexSet & row_index_set() const
size_type row_length(const size_type row) const
size_type column_number(const size_type row, const size_type index) const
bool exists(const size_type i, const size_type j) const
virtual void resize(const size_type rows, const size_type cols)
std::pair< size_type, size_type > matrix_position(const std::size_t global_index) const
void block_write(std::ostream &out) const
void reinit(const size_type m, const size_type n, const ArrayView< const unsigned int > &row_lengths)
void print_svg(std::ostream &out) const
void add_entries(const size_type row, ForwardIterator begin, ForwardIterator end, const bool indices_are_sorted=false)
size_type bandwidth() const
void print_gnuplot(std::ostream &out) const
virtual void add_row_entries(const size_type &row, const ArrayView< const size_type > &columns, const bool indices_are_sorted=false) override
bool is_compressed() const
SparsityPattern & operator=(const SparsityPattern &)
std::size_t n_nonzero_elements() const
bool exists(const size_type i, const size_type j) const
std::unique_ptr< size_type[]> colnums
void copy_from(const size_type n_rows, const size_type n_cols, const ForwardIterator begin, const ForwardIterator end)
static constexpr size_type invalid_entry
size_type row_position(const size_type i, const size_type j) const
std::unique_ptr< std::size_t[]> rowstart
void print(std::ostream &out) const
void add(const size_type i, const size_type j)
bool store_diagonal_first_in_row
size_type max_entries_per_row() const
unsigned int max_row_length
size_type operator()(const size_type i, const size_type j) const
unsigned int row_length(const size_type row) const
std::size_t memory_consumption() const
bool operator==(const SparsityPattern &) const
void block_read(std::istream &in)
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcIO()
static ::ExceptionBase & ExcEmptyObject()
#define Assert(cond, exc)
static ::ExceptionBase & ExcNotEnoughSpace(int arg1, int arg2)
#define AssertDimension(dim1, dim2)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcMatrixIsCompressed()
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcNotQuadratic()
static ::ExceptionBase & ExcNotCompressed()
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
Iterator lower_bound(Iterator first, Iterator last, const T &val)
constexpr types::global_dof_index invalid_size_type
::VectorizedArray< Number, width > min(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > abs(const ::VectorizedArray< Number, width > &)